diff --git a/package.json b/package.json index bf59002..a00f1ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.9-dev.1", + "version": "0.20.9-dev.2", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/crypt/hashCrossChainOrder.ts b/src/crypt/hashCrossChainOrder.ts new file mode 100644 index 0000000..371c016 --- /dev/null +++ b/src/crypt/hashCrossChainOrder.ts @@ -0,0 +1,40 @@ +import { ethers } from "ethers"; +import type { CrossChainOrder } from "../types.js"; + +const hashCrossChainOrder = (order: CrossChainOrder) => + ethers.solidityPackedKeccak256( + [ + "uint8", + "address", + "address", + "address", + "address", + "address", + "uint64", + "uint64", + "uint64", + "uint64", + "uint64", + "uint8", + "bytes32", + "uint24", + ], + [ + "0x03", + order.senderAddress, + order.matcherAddress, + order.baseAsset, + order.quoteAsset, + order.matcherFeeAsset, + order.amount, + order.price, + order.matcherFee, + order.nonce, + order.expiration, + order.buySide === 1 ? "0x01" : "0x00", + order.secretHash, + order.targetChainId, + ] + ); + +export default hashCrossChainOrder; diff --git a/src/crypt/sign-cross-chain-order.ts b/src/crypt/sign-cross-chain-order.ts index 3952aee..58b794a 100644 --- a/src/crypt/sign-cross-chain-order.ts +++ b/src/crypt/sign-cross-chain-order.ts @@ -9,8 +9,8 @@ import type { } from "../types.js"; import normalizeNumber from "../utils/normalizeNumber.js"; import getDomainData from "./getDomainData.js"; -import hashOrder from "./hashOrder.js"; import signOrderPersonal from "./signOrderPersonal.js"; +import hashCrossChainOrder from "./hashCrossChainOrder.js"; const DEFAULT_EXPIRATION = 29 * 24 * 60 * 60 * 1000; // 29 days @@ -25,13 +25,14 @@ export const signCrossChainOrder = async ( matcherAddress: string, serviceFeeAssetAddr: string, usePersonalSign: boolean, - secretHash: string, + secret: string, targetChainId: number, signer: ethers.Signer, chainId: SupportedChainId ) => { const nonce = Date.now(); const expiration = nonce + DEFAULT_EXPIRATION; + const secretHash = ethers.keccak256(secret); const order: CrossChainOrder = { senderAddress, @@ -60,6 +61,7 @@ export const signCrossChainOrder = async ( expiration, buySide: side === "BUY" ? 1 : 0, isPersonalSign: usePersonalSign, + secret, secretHash, targetChainId, }; @@ -80,7 +82,7 @@ export const signCrossChainOrder = async ( const signedOrder: SignedCrossChainOrder = { ...order, - id: hashOrder(order), + id: hashCrossChainOrder(order), signature: fixedSignature, }; return signedOrder; diff --git a/src/types.ts b/src/types.ts index d1db27e..5abdb1c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -52,6 +52,7 @@ export type Order = { } export type CrossChainOrder = Order & { + secret: string // not signed secretHash: string // bytes32 targetChainId: number // uint24 }