Skip to content

Commit

Permalink
feat(typescript-sdk): randomize salt
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed Jan 7, 2025
1 parent d9ae5fe commit 9616eb0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions typescript-sdk/src/evm/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { err, ok, type Result } from "neverthrow"
import type { Hex, HexAddress } from "../types.ts"
import { bech32AddressToHex } from "../convert.ts"
import { simulateTransaction } from "../query/offchain/tenderly.ts"
import { erc20Abi, getAddress, type Account, type WalletClient, type PublicActions } from "viem"
import {
erc20Abi,
getAddress,
type Account,
type WalletClient,
type PublicActions,
toHex
} from "viem"

export type EvmTransferParams = {
memo?: string
Expand Down Expand Up @@ -66,8 +73,11 @@ export async function transferAssetFromEvm(

memo ??= timestamp()

// const salt = new Uint8Array(32) // Create a buffer of 32 bytes (256 bits)
// crypto.getRandomValues(salt)
// add a salt to each transfer to prevent hash collisions
// important because ibc-union does not use sequence numbers
// such that intents are possible based on deterministic packet hashes
const salt = new Uint8Array(32)
crypto.getRandomValues(salt)
/**
* @dev
* `UCS03` zkgm contract `transfer` function:
Expand Down Expand Up @@ -95,8 +105,7 @@ export async function transferAssetFromEvm(
Number(sourceChannel), // TODO: make typesafe
0n, // TODO: customize timeoutheight
"0x000000000000000000000000000000000000000000000000fffffffffffffffa", // TODO: make non-hexencoded timestamp
"0x000000000000000000000000000000000000000000000000000000000000fffe",
// "0x153919669edc8a5d0c8d1e4507c9ce60435a1177", // TODO: customize receiver
toHex(salt),
receiver.startsWith("0x") ? getAddress(receiver) : bech32AddressToHex({ address: receiver }),
denomAddress, // TODO: customize sentToken
amount,
Expand Down

0 comments on commit 9616eb0

Please sign in to comment.