@evedex/exchange-crypto 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +32 -10
- package/dist/cjs/utils/exchange.d.ts +1 -0
- package/dist/mjs/index.d.ts +9 -0
- package/dist/mjs/index.js +28 -0
- package/dist/mjs/utils/exchange.d.ts +1 -0
- package/package.json +3 -2
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import Big from "big.js";
|
|
|
2
2
|
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
3
|
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl } from "./utils/exchange";
|
|
4
4
|
export * as utils from "./utils";
|
|
5
|
+
export interface AuthMessage {
|
|
6
|
+
nonce: string;
|
|
7
|
+
address: string;
|
|
8
|
+
chainId: string;
|
|
9
|
+
expirationTime?: string;
|
|
10
|
+
}
|
|
5
11
|
export interface AuthPayload {
|
|
6
12
|
message: string;
|
|
7
13
|
}
|
|
@@ -10,10 +16,13 @@ export interface NormalizeAuthPayload extends AuthPayload {
|
|
|
10
16
|
}
|
|
11
17
|
export interface SignedAuth extends NormalizeAuthPayload, SignedPayload {
|
|
12
18
|
}
|
|
19
|
+
export declare function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }: AuthMessage): AuthPayload;
|
|
20
|
+
export declare function signAuthMessage(signer: WalletClient, messagePayload: AuthMessage): Promise<SignedAuth>;
|
|
13
21
|
export declare function signAuth(signer: WalletClient, payload: AuthPayload): Promise<SignedAuth>;
|
|
14
22
|
export interface NormalizeLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
15
23
|
quantity: string;
|
|
16
24
|
limitPrice: string;
|
|
25
|
+
postOnly?: "yes";
|
|
17
26
|
}
|
|
18
27
|
export interface SignedLimitOrder extends NormalizeLimitOrder, SignedPayload {
|
|
19
28
|
quantity: string;
|
package/dist/cjs/index.js
CHANGED
|
@@ -46,6 +46,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.utils = void 0;
|
|
49
|
+
exports.getAuthSiweMessagePayload = getAuthSiweMessagePayload;
|
|
50
|
+
exports.signAuthMessage = signAuthMessage;
|
|
49
51
|
exports.signAuth = signAuth;
|
|
50
52
|
exports.signLimitOrder = signLimitOrder;
|
|
51
53
|
exports.signMarketOrder = signMarketOrder;
|
|
@@ -56,11 +58,40 @@ exports.signReplaceStopLimitOrder = signReplaceStopLimitOrder;
|
|
|
56
58
|
exports.signTradingBalanceWithdraw = signTradingBalanceWithdraw;
|
|
57
59
|
exports.signTpSl = signTpSl;
|
|
58
60
|
const big_js_1 = __importDefault(require("big.js"));
|
|
61
|
+
const siwe_1 = require("siwe");
|
|
59
62
|
const crypto_1 = require("./utils/crypto");
|
|
60
63
|
const numeric_1 = require("./utils/numeric");
|
|
61
64
|
const validate_1 = require("./utils/validate");
|
|
62
65
|
const utils_1 = require("./utils");
|
|
63
66
|
exports.utils = __importStar(require("./utils"));
|
|
67
|
+
function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }) {
|
|
68
|
+
return {
|
|
69
|
+
message: new siwe_1.SiweMessage({
|
|
70
|
+
scheme: "https",
|
|
71
|
+
domain: "evedex.com",
|
|
72
|
+
uri: "https://evedex.com",
|
|
73
|
+
address,
|
|
74
|
+
statement: "Sign in to evedex.com",
|
|
75
|
+
nonce,
|
|
76
|
+
expirationTime,
|
|
77
|
+
chainId: Number(chainId),
|
|
78
|
+
version: "1",
|
|
79
|
+
}).prepareMessage(),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function signAuthMessage(signer, messagePayload) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const address = yield signer.getAddress();
|
|
85
|
+
const { message } = getAuthSiweMessagePayload(messagePayload);
|
|
86
|
+
const signature = yield signer.signMessage(message);
|
|
87
|
+
return {
|
|
88
|
+
address,
|
|
89
|
+
message,
|
|
90
|
+
signature,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// @deprecated use signAuthMessage instead
|
|
64
95
|
function signAuth(signer, payload) {
|
|
65
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
97
|
const address = yield signer.getAddress();
|
|
@@ -76,16 +107,7 @@ function signLimitOrder(signer, order) {
|
|
|
76
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
108
|
const chainId = yield signer.getChainId();
|
|
78
109
|
(0, validate_1.validatePayload)(Object.assign(Object.assign({}, order), { chainId }), crypto_1.EIP721Schemas.createLimitOrder);
|
|
79
|
-
const normalize = {
|
|
80
|
-
id: order.id,
|
|
81
|
-
instrument: order.instrument,
|
|
82
|
-
side: order.side,
|
|
83
|
-
leverage: order.leverage,
|
|
84
|
-
quantity: (0, numeric_1.toMatcherNumber)(order.quantity),
|
|
85
|
-
limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice),
|
|
86
|
-
tpsl: order.tpsl,
|
|
87
|
-
chainId,
|
|
88
|
-
};
|
|
110
|
+
const normalize = Object.assign({ id: order.id, instrument: order.instrument, side: order.side, leverage: order.leverage, quantity: (0, numeric_1.toMatcherNumber)(order.quantity), limitPrice: (0, numeric_1.toMatcherNumber)(order.limitPrice), tpsl: order.tpsl, chainId }, (order.postOnly && { postOnly: "yes" }));
|
|
89
111
|
const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(chainId), crypto_1.EIP721Schemas.createLimitOrder, Object.assign(Object.assign({}, normalize), { quantity: (0, crypto_1.toEthNumber)(normalize.quantity), limitPrice: (0, crypto_1.toEthNumber)(normalize.limitPrice) }));
|
|
90
112
|
return Object.assign(Object.assign({}, normalize), { signature: signer.serializeSignature(signature) });
|
|
91
113
|
});
|
|
@@ -30,6 +30,7 @@ export interface CreateBaseOrder {
|
|
|
30
30
|
export interface LimitOrder extends CreateBaseOrder {
|
|
31
31
|
quantity: Big.BigSource;
|
|
32
32
|
limitPrice: Big.BigSource;
|
|
33
|
+
postOnly: boolean;
|
|
33
34
|
}
|
|
34
35
|
export interface MarketOrder extends CreateBaseOrder {
|
|
35
36
|
timeInForce: TimeInForce;
|
package/dist/mjs/index.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import Big from "big.js";
|
|
|
2
2
|
import { SignedPayload, WalletClient, NetworkChain } from "./utils/crypto";
|
|
3
3
|
import { CreateBaseOrder, LimitOrder, MarketOrder, PositionCloseOrder, ReplaceBaseOrder, ReplaceLimitOrder, ReplaceStopLimitOrder, StopLimitOrder, TpSl } from "./utils/exchange";
|
|
4
4
|
export * as utils from "./utils";
|
|
5
|
+
export interface AuthMessage {
|
|
6
|
+
nonce: string;
|
|
7
|
+
address: string;
|
|
8
|
+
chainId: string;
|
|
9
|
+
expirationTime?: string;
|
|
10
|
+
}
|
|
5
11
|
export interface AuthPayload {
|
|
6
12
|
message: string;
|
|
7
13
|
}
|
|
@@ -10,10 +16,13 @@ export interface NormalizeAuthPayload extends AuthPayload {
|
|
|
10
16
|
}
|
|
11
17
|
export interface SignedAuth extends NormalizeAuthPayload, SignedPayload {
|
|
12
18
|
}
|
|
19
|
+
export declare function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }: AuthMessage): AuthPayload;
|
|
20
|
+
export declare function signAuthMessage(signer: WalletClient, messagePayload: AuthMessage): Promise<SignedAuth>;
|
|
13
21
|
export declare function signAuth(signer: WalletClient, payload: AuthPayload): Promise<SignedAuth>;
|
|
14
22
|
export interface NormalizeLimitOrder extends CreateBaseOrder, NetworkChain {
|
|
15
23
|
quantity: string;
|
|
16
24
|
limitPrice: string;
|
|
25
|
+
postOnly?: "yes";
|
|
17
26
|
}
|
|
18
27
|
export interface SignedLimitOrder extends NormalizeLimitOrder, SignedPayload {
|
|
19
28
|
quantity: string;
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
|
+
import { SiweMessage } from "siwe";
|
|
2
3
|
import { EIP721Schemas, getDomainData, toEthNumber, } from "./utils/crypto";
|
|
3
4
|
import { toMatcherNumber } from "./utils/numeric";
|
|
4
5
|
import { validatePayload } from "./utils/validate";
|
|
5
6
|
import { MATCHER_PRECISION } from "./utils";
|
|
6
7
|
export * as utils from "./utils";
|
|
8
|
+
export function getAuthSiweMessagePayload({ nonce, address, chainId, expirationTime, }) {
|
|
9
|
+
return {
|
|
10
|
+
message: new SiweMessage({
|
|
11
|
+
scheme: "https",
|
|
12
|
+
domain: "evedex.com",
|
|
13
|
+
uri: "https://evedex.com",
|
|
14
|
+
address,
|
|
15
|
+
statement: "Sign in to evedex.com",
|
|
16
|
+
nonce,
|
|
17
|
+
expirationTime,
|
|
18
|
+
chainId: Number(chainId),
|
|
19
|
+
version: "1",
|
|
20
|
+
}).prepareMessage(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export async function signAuthMessage(signer, messagePayload) {
|
|
24
|
+
const address = await signer.getAddress();
|
|
25
|
+
const { message } = getAuthSiweMessagePayload(messagePayload);
|
|
26
|
+
const signature = await signer.signMessage(message);
|
|
27
|
+
return {
|
|
28
|
+
address,
|
|
29
|
+
message,
|
|
30
|
+
signature,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// @deprecated use signAuthMessage instead
|
|
7
34
|
export async function signAuth(signer, payload) {
|
|
8
35
|
const address = await signer.getAddress();
|
|
9
36
|
const signature = await signer.signMessage(payload.message);
|
|
@@ -25,6 +52,7 @@ export async function signLimitOrder(signer, order) {
|
|
|
25
52
|
limitPrice: toMatcherNumber(order.limitPrice),
|
|
26
53
|
tpsl: order.tpsl,
|
|
27
54
|
chainId,
|
|
55
|
+
...(order.postOnly && { postOnly: "yes" }),
|
|
28
56
|
};
|
|
29
57
|
const signature = await signer.signTypedData(getDomainData(chainId), EIP721Schemas.createLimitOrder, {
|
|
30
58
|
...normalize,
|
|
@@ -30,6 +30,7 @@ export interface CreateBaseOrder {
|
|
|
30
30
|
export interface LimitOrder extends CreateBaseOrder {
|
|
31
31
|
quantity: Big.BigSource;
|
|
32
32
|
limitPrice: Big.BigSource;
|
|
33
|
+
postOnly: boolean;
|
|
33
34
|
}
|
|
34
35
|
export interface MarketOrder extends CreateBaseOrder {
|
|
35
36
|
timeInForce: TimeInForce;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evedex/exchange-crypto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"license": "ISC",
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"big.js": "^6.2.2",
|
|
60
|
-
"ethers": "^6.13.5"
|
|
60
|
+
"ethers": "^6.13.5",
|
|
61
|
+
"siwe": "^3.0.0"
|
|
61
62
|
},
|
|
62
63
|
"publishConfig": {
|
|
63
64
|
"access": "public",
|