From 49b9def3716132f9dc563716b7ec51933c3e57ef Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 15 Apr 2024 18:51:16 +0300 Subject: [PATCH] fix(limit-order): correct salt check (#28) --- src/limit-order/extension-builder.ts | 2 ++ src/limit-order/limit-order.spec.ts | 4 +++- src/limit-order/limit-order.ts | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/limit-order/extension-builder.ts b/src/limit-order/extension-builder.ts index b754cfd..91a2d0c 100644 --- a/src/limit-order/extension-builder.ts +++ b/src/limit-order/extension-builder.ts @@ -97,6 +97,8 @@ export class ExtensionBuilder implements IExtensionBuilder { public withCustomData(data: string): this { assert(isHexString(data), 'Custom data must be valid hex string') + this.customData = data + return this } diff --git a/src/limit-order/limit-order.spec.ts b/src/limit-order/limit-order.spec.ts index cde08bf..2e6753b 100644 --- a/src/limit-order/limit-order.spec.ts +++ b/src/limit-order/limit-order.spec.ts @@ -61,6 +61,8 @@ describe('Limit Order', () => { ext ) - expect(LimitOrder.fromCalldata(order.toCalldata())).toEqual(order) + expect(LimitOrder.fromDataAndExtension(order.build(), ext)).toEqual( + order + ) }) }) diff --git a/src/limit-order/limit-order.ts b/src/limit-order/limit-order.ts index 5fd633b..9f4a19b 100644 --- a/src/limit-order/limit-order.ts +++ b/src/limit-order/limit-order.ts @@ -96,8 +96,9 @@ export class LimitOrder { } const hash = salt & UINT_160_MAX + const expectedHash = extension.keccak256() & UINT_160_MAX assert( - hash === extension.keccak256(), + hash === expectedHash, 'invalid salt: lowest 160 bits should be extension hash' )