-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
export type MerkleLeaf = string & { _tag: "MerkleLeaf" };
This is an issue specifically when using viem when building the hashLock:
import { encodePacked } from "viem";
const hashLock = secretsCount === 1
? HashLock.forSingleFill(secrets[0]!)
: HashLock.forMultipleFills(
secretHashes.map(
(secretHash, i) =>
encodePacked(
["uint64", "bytes32"],
[BigInt(i), secretHash],
) as MerkleLeaf,
),
);Realistically, it would be nice if there were be a buildHackLock utility function that handles this logic.
Sample implementation:
export function buildSecretData(secrets: Hex[], secretsCount: number): SecretData {
const secretHashes = secrets.map((x) => HashLock.hashSecret(x) as Hex);
const hashLock =
secretsCount === 1
? HashLock.forSingleFill(secrets[0]!)
: HashLock.forMultipleFills(
secretHashes.map(
(secretHash, i) =>
encodePacked(
["uint64", "bytes32"],
[BigInt(i), secretHash],
) as MerkleLeaf,
),
);
return {
secrets,
secretHashes,
hashLock,
};
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels