@evedex/exchange-crypto 1.0.12 → 1.0.14

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.
@@ -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,6 +16,8 @@ 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;
package/dist/cjs/index.js CHANGED
@@ -41,8 +41,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
41
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
42
  });
43
43
  };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
44
47
  Object.defineProperty(exports, "__esModule", { value: true });
45
48
  exports.utils = void 0;
49
+ exports.getAuthSiweMessagePayload = getAuthSiweMessagePayload;
50
+ exports.signAuthMessage = signAuthMessage;
46
51
  exports.signAuth = signAuth;
47
52
  exports.signLimitOrder = signLimitOrder;
48
53
  exports.signMarketOrder = signMarketOrder;
@@ -52,10 +57,41 @@ exports.signReplaceLimitOrder = signReplaceLimitOrder;
52
57
  exports.signReplaceStopLimitOrder = signReplaceStopLimitOrder;
53
58
  exports.signTradingBalanceWithdraw = signTradingBalanceWithdraw;
54
59
  exports.signTpSl = signTpSl;
60
+ const big_js_1 = __importDefault(require("big.js"));
61
+ const siwe_1 = require("siwe");
55
62
  const crypto_1 = require("./utils/crypto");
56
63
  const numeric_1 = require("./utils/numeric");
57
64
  const validate_1 = require("./utils/validate");
65
+ const utils_1 = require("./utils");
58
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
59
95
  function signAuth(signer, payload) {
60
96
  return __awaiter(this, void 0, void 0, function* () {
61
97
  const address = yield signer.getAddress();
@@ -167,7 +203,7 @@ function signTradingBalanceWithdraw(signer, withdraw) {
167
203
  (0, validate_1.validatePayload)(withdraw, crypto_1.EIP721Schemas.withdraw);
168
204
  const normalize = {
169
205
  recipient: withdraw.recipient,
170
- amount: (0, numeric_1.toMatcherNumber)(withdraw.amount),
206
+ amount: (0, big_js_1.default)(withdraw.amount).round(utils_1.MATCHER_PRECISION, big_js_1.default.roundDown).toString(),
171
207
  };
172
208
  const signature = yield signer.signTypedData((0, crypto_1.getDomainData)(yield signer.getChainId()), crypto_1.EIP721Schemas.withdraw, {
173
209
  recipient: withdraw.recipient,
@@ -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,6 +16,8 @@ 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;
package/dist/mjs/index.js CHANGED
@@ -1,7 +1,36 @@
1
+ import Big from "big.js";
2
+ import { SiweMessage } from "siwe";
1
3
  import { EIP721Schemas, getDomainData, toEthNumber, } from "./utils/crypto";
2
4
  import { toMatcherNumber } from "./utils/numeric";
3
5
  import { validatePayload } from "./utils/validate";
6
+ import { MATCHER_PRECISION } from "./utils";
4
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
5
34
  export async function signAuth(signer, payload) {
6
35
  const address = await signer.getAddress();
7
36
  const signature = await signer.signMessage(payload.message);
@@ -140,7 +169,7 @@ export async function signTradingBalanceWithdraw(signer, withdraw) {
140
169
  validatePayload(withdraw, EIP721Schemas.withdraw);
141
170
  const normalize = {
142
171
  recipient: withdraw.recipient,
143
- amount: toMatcherNumber(withdraw.amount),
172
+ amount: Big(withdraw.amount).round(MATCHER_PRECISION, Big.roundDown).toString(),
144
173
  };
145
174
  const signature = await signer.signTypedData(getDomainData(await signer.getChainId()), EIP721Schemas.withdraw, {
146
175
  recipient: withdraw.recipient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evedex/exchange-crypto",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
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",