From fcc30178ab6184561bb4cf6e337a99b7fd7ad571 Mon Sep 17 00:00:00 2001 From: TheJuze Date: Fri, 19 Jan 2024 12:27:19 +0300 Subject: [PATCH] make fields in signOrder optional --- package-lock.json | 4 ++-- package.json | 2 +- src/crypt/signLockOrder.ts | 2 +- src/crypt/signOrder.ts | 8 +++++--- src/types.ts | 6 +++--- tsconfig.json | 3 ++- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index a96aa45..eb858ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.42-rc5", + "version": "0.20.42-rc6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.42-rc5", + "version": "0.20.42-rc6", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 66512fb..c0e12f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.42-rc5", + "version": "0.20.42-rc6", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/crypt/signLockOrder.ts b/src/crypt/signLockOrder.ts index b70c3ea..a04a29d 100644 --- a/src/crypt/signLockOrder.ts +++ b/src/crypt/signLockOrder.ts @@ -14,10 +14,10 @@ export type LockOrderProps = { senderAddress: string // broker asset: string amount: ethers.BigNumberish - targetChainId: ethers.BigNumberish sign: string // подпись юзера signer: ethers.Signer chainId: SupportedChainId + targetChainId: SupportedChainId } export const signLockOrder = async ({ diff --git a/src/crypt/signOrder.ts b/src/crypt/signOrder.ts index 013841b..04ce158 100644 --- a/src/crypt/signOrder.ts +++ b/src/crypt/signOrder.ts @@ -25,13 +25,15 @@ export const signOrder = async ( serviceFeeAssetAddr: string, signer: ethers.Signer, chainId: SupportedChainId, - targetChainId?: ethers.BigNumberish, + targetChainId?: SupportedChainId, ) => { const nonce = Date.now(); const expiration = nonce + DEFAULT_EXPIRATION; const secret = generateSecret(); const secretHash = ethers.keccak256(secret); + const isCrossChain = targetChainId === undefined || targetChainId === chainId; + const order: Order = { senderAddress, matcherAddress, @@ -55,7 +57,7 @@ export const signOrder = async ( )), nonce, expiration, - ...(targetChainId !== undefined + ...(isCrossChain ? { secretHash, targetChainId @@ -83,7 +85,7 @@ export const signOrder = async ( ...order, id: hashOrder(order), signature: fixedSignature, - secret + ...(isCrossChain ? { secret } : {}) }; return signedOrder; }; diff --git a/src/types.ts b/src/types.ts index 8de284a..304315b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,7 +51,7 @@ export type Order = { expiration: number // uint64 buySide: 0 | 1 // uint8, 1=buy, 0=sell secretHash?: string // uint64 - targetChainId?: ethers.BigNumberish // uint64 + targetChainId?: SupportedChainId // uint64 } export type LockOrder = { @@ -60,14 +60,14 @@ export type LockOrder = { expiration: ethers.BigNumberish // uint64 asset: string // address(?) amount: ethers.BigNumberish // uint64 - targetChainId: ethers.BigNumberish // uint64 + targetChainId: SupportedChainId // uint64 secretHash: string // uint64 sign: string // uint64 // подпись юзера } type SignedOrderAdditionalProps = { signature: string // bytes - secret: string + secret?: string needWithdraw?: boolean // bool (not supported yet by smart-contract) } diff --git a/tsconfig.json b/tsconfig.json index 2bbded1..6b2298e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,8 @@ "noUnusedLocals": true /* Enable error reporting when a local variables aren't read. */, "noUnusedParameters": true /* Raise an error when a function parameter isn't read */, "noUncheckedIndexedAccess": true, - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "exactOptionalPropertyTypes": false, /* allow ? in interfaces */ }, "ts-node": { // Tell ts-node CLI to install the --loader automatically, explained below