mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
feat: added secret
This commit is contained in:
@@ -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",
|
||||
|
||||
40
src/crypt/hashCrossChainOrder.ts
Normal file
40
src/crypt/hashCrossChainOrder.ts
Normal 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;
|
||||
@@ -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;
|
||||
|
||||
@@ -52,6 +52,7 @@ export type Order = {
|
||||
}
|
||||
|
||||
export type CrossChainOrder = Order & {
|
||||
secret: string // not signed
|
||||
secretHash: string // bytes32
|
||||
targetChainId: number // uint24
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user