feat: added secret

This commit is contained in:
Alex Kraiz
2023-10-16 17:09:35 +04:00
parent 0869aa6e2a
commit e2c1dd07ad
4 changed files with 47 additions and 4 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -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;

View File

@@ -52,6 +52,7 @@ export type Order = {
}
export type CrossChainOrder = Order & {
secret: string // not signed
secretHash: string // bytes32
targetChainId: number // uint24
}