Skip to content

Commit

Permalink
fix: HashLock.forMultipleFills (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk authored Aug 2, 2024
1 parent 52df217 commit e30ad28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cross-chain-order/hash-lock/hash-lock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('HashLock', () => {

const leaves = HashLock.getMerkleLeaves(secrets)
expect(HashLock.forMultipleFills(leaves).toString()).toEqual(
'0x0006450ad51097012ff74f91e1ff6fb3f5bd8e8e2cd6a91a513f03bcb89a76f7'
'0x0004450ad51097012ff74f91e1ff6fb3f5bd8e8e2cd6a91a513f03bcb89a76f7'
)
})

Expand Down
7 changes: 5 additions & 2 deletions src/cross-chain-order/hash-lock/hash-lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ export class HashLock {
}

public static forMultipleFills(leaves: MerkleLeaf[]): HashLock {
assert(leaves.length > 1, 'leaves array must be greater than 1')
assert(
leaves.length > 2,
'leaves array must be greater than 2. Or use HashLock.forSingleFill'
)
const root = SimpleMerkleTree.of(leaves).root
const rootWithCount = BN.fromHex(root).setMask(
new BitMask(241n, 256n),
BigInt(leaves.length)
BigInt(leaves.length - 1)
)

return new HashLock(rootWithCount.toHex(64))
Expand Down

0 comments on commit e30ad28

Please sign in to comment.