@n1xyz/nord-ts 0.1.6 → 0.1.7
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/actions.d.ts +57 -0
- package/dist/actions.js +229 -0
- package/dist/client/Nord.d.ts +379 -0
- package/dist/client/Nord.js +718 -0
- package/dist/client/NordAdmin.d.ts +225 -0
- package/dist/client/NordAdmin.js +394 -0
- package/dist/client/NordUser.d.ts +350 -0
- package/dist/client/NordUser.js +743 -0
- package/dist/error.d.ts +35 -0
- package/dist/error.js +49 -0
- package/dist/gen/openapi.d.ts +40 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +29 -1
- package/dist/nord/client/NordAdmin.js +2 -0
- package/dist/types.d.ts +4 -50
- package/dist/types.js +1 -24
- package/dist/utils.d.ts +8 -11
- package/dist/utils.js +54 -41
- package/dist/websocket/Subscriber.d.ts +37 -0
- package/dist/websocket/Subscriber.js +25 -0
- package/dist/websocket/index.d.ts +19 -2
- package/dist/websocket/index.js +82 -2
- package/package.json +1 -1
- package/src/actions.ts +333 -0
- package/src/{nord/client → client}/Nord.ts +207 -210
- package/src/{nord/client → client}/NordAdmin.ts +123 -153
- package/src/{nord/client → client}/NordUser.ts +216 -305
- package/src/gen/openapi.ts +40 -0
- package/src/index.ts +7 -1
- package/src/types.ts +4 -54
- package/src/utils.ts +44 -47
- package/src/{nord/models → websocket}/Subscriber.ts +2 -2
- package/src/websocket/index.ts +105 -2
- package/src/nord/api/actions.ts +0 -648
- package/src/nord/api/core.ts +0 -96
- package/src/nord/api/metrics.ts +0 -269
- package/src/nord/client/NordClient.ts +0 -79
- package/src/nord/index.ts +0 -25
- /package/src/{nord/utils/NordError.ts → error.ts} +0 -0
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a NordError
|
|
3
|
+
*/
|
|
4
|
+
export interface NordErrorOptions {
|
|
5
|
+
/** The original error that caused this error */
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
/** HTTP status code (if applicable) */
|
|
8
|
+
statusCode?: number;
|
|
9
|
+
/** Additional error details */
|
|
10
|
+
details?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Custom error class for Nord-related errors
|
|
14
|
+
*/
|
|
15
|
+
export declare class NordError extends Error {
|
|
16
|
+
/** The original error that caused this error */
|
|
17
|
+
readonly cause?: unknown;
|
|
18
|
+
/** HTTP status code (if applicable) */
|
|
19
|
+
readonly statusCode?: number;
|
|
20
|
+
/** Additional error details */
|
|
21
|
+
readonly details?: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new NordError
|
|
24
|
+
*
|
|
25
|
+
* @param message - Error message
|
|
26
|
+
* @param options - Error options
|
|
27
|
+
*/
|
|
28
|
+
constructor(message: string, options?: NordErrorOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Convert the error to a string representation
|
|
31
|
+
*
|
|
32
|
+
* @returns String representation of the error
|
|
33
|
+
*/
|
|
34
|
+
toString(): string;
|
|
35
|
+
}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NordError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class for Nord-related errors
|
|
6
|
+
*/
|
|
7
|
+
class NordError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new NordError
|
|
10
|
+
*
|
|
11
|
+
* @param message - Error message
|
|
12
|
+
* @param options - Error options
|
|
13
|
+
*/
|
|
14
|
+
constructor(message, options = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "NordError";
|
|
17
|
+
this.cause = options.cause;
|
|
18
|
+
this.statusCode = options.statusCode;
|
|
19
|
+
this.details = options.details;
|
|
20
|
+
// Capture stack trace
|
|
21
|
+
if (Error.captureStackTrace) {
|
|
22
|
+
Error.captureStackTrace(this, NordError);
|
|
23
|
+
}
|
|
24
|
+
// Handle nested errors
|
|
25
|
+
if (this.cause instanceof Error) {
|
|
26
|
+
this.stack =
|
|
27
|
+
this.stack + "\nCaused by: " + (this.cause.stack || this.cause.message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert the error to a string representation
|
|
32
|
+
*
|
|
33
|
+
* @returns String representation of the error
|
|
34
|
+
*/
|
|
35
|
+
toString() {
|
|
36
|
+
let result = `${this.name}: ${this.message}`;
|
|
37
|
+
if (this.statusCode) {
|
|
38
|
+
result += ` \nstatus: ${this.statusCode}`;
|
|
39
|
+
}
|
|
40
|
+
if (this.details && Object.keys(this.details).length > 0) {
|
|
41
|
+
result += ` \ndetails: ${JSON.stringify(this.details, null, 2)}`;
|
|
42
|
+
}
|
|
43
|
+
if (this.cause) {
|
|
44
|
+
result += ` \ncause: ${this.cause.toString()}`;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.NordError = NordError;
|
package/dist/gen/openapi.d.ts
CHANGED
|
@@ -1231,6 +1231,44 @@ export interface paths {
|
|
|
1231
1231
|
patch?: never;
|
|
1232
1232
|
trace?: never;
|
|
1233
1233
|
};
|
|
1234
|
+
"/admin": {
|
|
1235
|
+
parameters: {
|
|
1236
|
+
query?: never;
|
|
1237
|
+
header?: never;
|
|
1238
|
+
path?: never;
|
|
1239
|
+
cookie?: never;
|
|
1240
|
+
};
|
|
1241
|
+
/** @description List of assigned admins. */
|
|
1242
|
+
get: {
|
|
1243
|
+
parameters: {
|
|
1244
|
+
query?: never;
|
|
1245
|
+
header?: never;
|
|
1246
|
+
path?: never;
|
|
1247
|
+
cookie?: never;
|
|
1248
|
+
};
|
|
1249
|
+
requestBody?: never;
|
|
1250
|
+
responses: {
|
|
1251
|
+
200: {
|
|
1252
|
+
headers: {
|
|
1253
|
+
[name: string]: unknown;
|
|
1254
|
+
};
|
|
1255
|
+
content: {
|
|
1256
|
+
"application/json": [
|
|
1257
|
+
string,
|
|
1258
|
+
components["schemas"]["AclRole"]
|
|
1259
|
+
][];
|
|
1260
|
+
};
|
|
1261
|
+
};
|
|
1262
|
+
};
|
|
1263
|
+
};
|
|
1264
|
+
put?: never;
|
|
1265
|
+
post?: never;
|
|
1266
|
+
delete?: never;
|
|
1267
|
+
options?: never;
|
|
1268
|
+
head?: never;
|
|
1269
|
+
patch?: never;
|
|
1270
|
+
trace?: never;
|
|
1271
|
+
};
|
|
1234
1272
|
"/tv": {
|
|
1235
1273
|
parameters: {
|
|
1236
1274
|
query?: never;
|
|
@@ -2688,6 +2726,8 @@ export interface components {
|
|
|
2688
2726
|
accountId: number;
|
|
2689
2727
|
feeTier: components["schemas"]["FeeTierId"];
|
|
2690
2728
|
};
|
|
2729
|
+
/** Format: uint32 */
|
|
2730
|
+
AclRole: number;
|
|
2691
2731
|
/** @description TV config query response https://www.tradingview.com/charting-library-docs/latest/connecting_data/UDF/#data-feed-configuration-data */
|
|
2692
2732
|
TvConfigResponse: {
|
|
2693
2733
|
supported_resolutions: components["schemas"]["Resolution"][];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export * from "./types";
|
|
2
2
|
export * from "./utils";
|
|
3
3
|
export * from "./const";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./error";
|
|
5
5
|
export * from "./websocket/index";
|
|
6
|
+
export * from "./client/Nord";
|
|
7
|
+
export * from "./client/NordUser";
|
|
8
|
+
export * from "./client/NordAdmin";
|
|
9
|
+
export * as proto from "./gen/nord_pb";
|
|
10
|
+
export * as openapi from "./gen/openapi";
|
package/dist/index.js
CHANGED
|
@@ -10,12 +10,40 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
16
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.openapi = exports.proto = void 0;
|
|
17
40
|
__exportStar(require("./types"), exports);
|
|
18
41
|
__exportStar(require("./utils"), exports);
|
|
19
42
|
__exportStar(require("./const"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
43
|
+
__exportStar(require("./error"), exports);
|
|
21
44
|
__exportStar(require("./websocket/index"), exports);
|
|
45
|
+
__exportStar(require("./client/Nord"), exports);
|
|
46
|
+
__exportStar(require("./client/NordUser"), exports);
|
|
47
|
+
__exportStar(require("./client/NordAdmin"), exports);
|
|
48
|
+
exports.proto = __importStar(require("./gen/nord_pb"));
|
|
49
|
+
exports.openapi = __importStar(require("./gen/openapi"));
|
|
@@ -130,6 +130,8 @@ class NordAdmin {
|
|
|
130
130
|
value: (0, protobuf_1.create)(proto.Action_UpdateAclSchema, {
|
|
131
131
|
aclPubkey: this.admin.toBytes(),
|
|
132
132
|
targetPubkey: target.toBytes(),
|
|
133
|
+
rolesValue: values,
|
|
134
|
+
rolesMask: mask,
|
|
133
135
|
}),
|
|
134
136
|
});
|
|
135
137
|
(0, actions_1.expectReceiptKind)(receipt, "aclUpdated", "update acl");
|
package/dist/types.d.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import * as proto from "./gen/nord_pb";
|
|
2
2
|
import type { components } from "./gen/openapi.ts";
|
|
3
3
|
import Decimal from "decimal.js";
|
|
4
|
-
|
|
5
|
-
* The peak TPS rate is queried over the specified period.
|
|
6
|
-
* The period is specified in units of: {hour, day, week, month, year}.
|
|
7
|
-
* Example inputs:
|
|
8
|
-
* 1. AggregateMetrics.txPeakTpsPeriod = 3,
|
|
9
|
-
* AggregateMetrics.txPeakTpsPeriodUnit = "d" => Peak TPS over last 3 days.
|
|
10
|
-
* 1. AggregateMetrics.txPeakTpsPeriod = 1,
|
|
11
|
-
* AggregateMetrics.txPeakTpsPeriodUnit = "w" => Peak TPS over last week.
|
|
12
|
-
*/
|
|
13
|
-
export declare enum PeakTpsPeriodUnit {
|
|
14
|
-
Hour = "h",
|
|
15
|
-
Day = "d",
|
|
16
|
-
Week = "w",
|
|
17
|
-
Month = "m",
|
|
18
|
-
Year = "y"
|
|
19
|
-
}
|
|
4
|
+
import { Connection } from "@solana/web3.js";
|
|
20
5
|
/**
|
|
21
6
|
* Nord subscription type for trades or deltas
|
|
22
7
|
*/
|
|
@@ -35,8 +20,8 @@ export interface NordConfig {
|
|
|
35
20
|
webServerUrl: string;
|
|
36
21
|
/** App address */
|
|
37
22
|
app: string;
|
|
38
|
-
/** Solana
|
|
39
|
-
|
|
23
|
+
/** Solana connection */
|
|
24
|
+
solanaConnection: Connection;
|
|
40
25
|
/** Proton URL, defaults to webServerUrl */
|
|
41
26
|
protonUrl?: string;
|
|
42
27
|
/**
|
|
@@ -101,11 +86,6 @@ export interface Order {
|
|
|
101
86
|
price: number;
|
|
102
87
|
marketId: number;
|
|
103
88
|
}
|
|
104
|
-
export declare enum KeyType {
|
|
105
|
-
Ed25519 = 0,
|
|
106
|
-
Secp256k1 = 1,
|
|
107
|
-
Bls12_381 = 2
|
|
108
|
-
}
|
|
109
89
|
export declare enum Side {
|
|
110
90
|
Ask = "ask",
|
|
111
91
|
Bid = "bid"
|
|
@@ -165,32 +145,6 @@ export interface ActionResponse {
|
|
|
165
145
|
action: proto.Action;
|
|
166
146
|
physicalExecTime: Date;
|
|
167
147
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Block summary.
|
|
170
|
-
* block_number Block number.
|
|
171
|
-
* from_action_id First action_id in the block.
|
|
172
|
-
* to_action_id Last action_id in the block.
|
|
173
|
-
*/
|
|
174
|
-
export interface BlockSummary {
|
|
175
|
-
block_number: number;
|
|
176
|
-
from_action_id: number;
|
|
177
|
-
to_action_id: number;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Aggregate metrics
|
|
181
|
-
* blocks_total: Total number of L2 blocks.
|
|
182
|
-
* tx_total: Total number of transactions.
|
|
183
|
-
* tx_tps: Transaction throughput.
|
|
184
|
-
* tx_tps_peak: Peak transaction throughput.
|
|
185
|
-
* request_latency_average: Average request latency.
|
|
186
|
-
*/
|
|
187
|
-
export interface AggregateMetrics {
|
|
188
|
-
blocks_total: number;
|
|
189
|
-
tx_total: number;
|
|
190
|
-
tx_tps: number;
|
|
191
|
-
tx_tps_peak: number;
|
|
192
|
-
request_latency_average: number;
|
|
193
|
-
}
|
|
194
148
|
/**
|
|
195
149
|
* Converts a `FillMode` enum to its corresponding protobuf representation.
|
|
196
150
|
*
|
|
@@ -214,7 +168,7 @@ export interface OrderbookEntry {
|
|
|
214
168
|
*/
|
|
215
169
|
export interface OrderbookQuery {
|
|
216
170
|
symbol?: string;
|
|
217
|
-
|
|
171
|
+
marketId?: number;
|
|
218
172
|
}
|
|
219
173
|
/**
|
|
220
174
|
* Response for timestamp query
|
package/dist/types.js
CHANGED
|
@@ -36,34 +36,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.QuoteSize = exports.WebSocketMessageType = exports.TriggerStatus = exports.TriggerKind = exports.FillMode = exports.Side =
|
|
39
|
+
exports.QuoteSize = exports.WebSocketMessageType = exports.TriggerStatus = exports.TriggerKind = exports.FillMode = exports.Side = void 0;
|
|
40
40
|
exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
|
|
41
41
|
const proto = __importStar(require("./gen/nord_pb"));
|
|
42
42
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
43
43
|
const utils_1 = require("./utils");
|
|
44
|
-
/**
|
|
45
|
-
* The peak TPS rate is queried over the specified period.
|
|
46
|
-
* The period is specified in units of: {hour, day, week, month, year}.
|
|
47
|
-
* Example inputs:
|
|
48
|
-
* 1. AggregateMetrics.txPeakTpsPeriod = 3,
|
|
49
|
-
* AggregateMetrics.txPeakTpsPeriodUnit = "d" => Peak TPS over last 3 days.
|
|
50
|
-
* 1. AggregateMetrics.txPeakTpsPeriod = 1,
|
|
51
|
-
* AggregateMetrics.txPeakTpsPeriodUnit = "w" => Peak TPS over last week.
|
|
52
|
-
*/
|
|
53
|
-
var PeakTpsPeriodUnit;
|
|
54
|
-
(function (PeakTpsPeriodUnit) {
|
|
55
|
-
PeakTpsPeriodUnit["Hour"] = "h";
|
|
56
|
-
PeakTpsPeriodUnit["Day"] = "d";
|
|
57
|
-
PeakTpsPeriodUnit["Week"] = "w";
|
|
58
|
-
PeakTpsPeriodUnit["Month"] = "m";
|
|
59
|
-
PeakTpsPeriodUnit["Year"] = "y";
|
|
60
|
-
})(PeakTpsPeriodUnit || (exports.PeakTpsPeriodUnit = PeakTpsPeriodUnit = {}));
|
|
61
|
-
var KeyType;
|
|
62
|
-
(function (KeyType) {
|
|
63
|
-
KeyType[KeyType["Ed25519"] = 0] = "Ed25519";
|
|
64
|
-
KeyType[KeyType["Secp256k1"] = 1] = "Secp256k1";
|
|
65
|
-
KeyType[KeyType["Bls12_381"] = 2] = "Bls12_381";
|
|
66
|
-
})(KeyType || (exports.KeyType = KeyType = {}));
|
|
67
44
|
var Side;
|
|
68
45
|
(function (Side) {
|
|
69
46
|
Side["Ask"] = "ask";
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Decimal } from "decimal.js";
|
|
2
|
-
import {
|
|
2
|
+
import { type Market, type Token } from "./types";
|
|
3
3
|
import { type Message } from "@bufbuild/protobuf";
|
|
4
4
|
import type { GenMessage } from "@bufbuild/protobuf/codegenv2";
|
|
5
5
|
import { ethers } from "ethers";
|
|
6
6
|
import { RequestInfo, RequestInit, Response } from "node-fetch";
|
|
7
7
|
import { Keypair } from "@solana/web3.js";
|
|
8
|
+
import * as solana from "@solana/web3.js";
|
|
8
9
|
export declare const SESSION_TTL: bigint;
|
|
9
10
|
export declare const ZERO_DECIMAL: Decimal;
|
|
10
11
|
export declare const MAX_BUFFER_LEN = 10000;
|
|
@@ -12,7 +13,7 @@ export declare const MAX_BUFFER_LEN = 10000;
|
|
|
12
13
|
export type BigIntValue = bigint | number | string;
|
|
13
14
|
export declare function panic(message: string): never;
|
|
14
15
|
export declare function isRfc3339(s: string): boolean;
|
|
15
|
-
export declare function assert(predicate: boolean, message?: string):
|
|
16
|
+
export declare function assert(predicate: boolean, message?: string): asserts predicate;
|
|
16
17
|
/**
|
|
17
18
|
* Extracts value out of optional if it's defined, or throws error if it's not
|
|
18
19
|
* @param value Optional value to unwrap
|
|
@@ -28,14 +29,6 @@ export declare function optExpect<T>(value: T | undefined, message: string): T;
|
|
|
28
29
|
* @throws If response wasn't Ok
|
|
29
30
|
*/
|
|
30
31
|
export declare function checkedFetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
31
|
-
/**
|
|
32
|
-
* Signs an action using the specified secret key and key type.
|
|
33
|
-
* @param action - The action data to be signed.
|
|
34
|
-
* @param sk - Secret key used for signing the action.
|
|
35
|
-
* @param keyType - Type of the key used for signing.
|
|
36
|
-
* @returns A new Uint8Array containing the action followed by its signature.
|
|
37
|
-
*/
|
|
38
|
-
export declare function signAction(action: Uint8Array, sk: Uint8Array, keyType: KeyType): Uint8Array;
|
|
39
32
|
/**
|
|
40
33
|
* Constructs wallet signing function, usable with `NordUser` type
|
|
41
34
|
*
|
|
@@ -78,8 +71,12 @@ export declare const toScaledU128: (x: Decimal.Value, decimals: number) => bigin
|
|
|
78
71
|
* @returns Decoded message
|
|
79
72
|
*/
|
|
80
73
|
export declare function decodeLengthDelimited<T extends Message>(bytes: Uint8Array, schema: GenMessage<T>): T;
|
|
81
|
-
export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
|
|
82
74
|
export declare function decodeHex(value: string): Uint8Array;
|
|
83
75
|
export declare function findMarket(markets: Market[], marketId: number): Market;
|
|
84
76
|
export declare function findToken(tokens: Token[], tokenId: number): Token;
|
|
85
77
|
export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
|
|
78
|
+
export declare function signUserPayload({ payload, user, signTransaction, }: Readonly<{
|
|
79
|
+
payload: Uint8Array;
|
|
80
|
+
user: solana.PublicKey;
|
|
81
|
+
signTransaction: (tx: solana.Transaction) => Promise<solana.Transaction>;
|
|
82
|
+
}>): Promise<Uint8Array>;
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -9,26 +42,21 @@ exports.isRfc3339 = isRfc3339;
|
|
|
9
42
|
exports.assert = assert;
|
|
10
43
|
exports.optExpect = optExpect;
|
|
11
44
|
exports.checkedFetch = checkedFetch;
|
|
12
|
-
exports.signAction = signAction;
|
|
13
45
|
exports.makeWalletSignFn = makeWalletSignFn;
|
|
14
46
|
exports.decodeLengthDelimited = decodeLengthDelimited;
|
|
15
|
-
exports.checkPubKeyLength = checkPubKeyLength;
|
|
16
47
|
exports.decodeHex = decodeHex;
|
|
17
48
|
exports.findMarket = findMarket;
|
|
18
49
|
exports.findToken = findToken;
|
|
19
50
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
51
|
+
exports.signUserPayload = signUserPayload;
|
|
20
52
|
const decimal_js_1 = require("decimal.js");
|
|
21
|
-
const ed25519_1 = require("@noble/curves/ed25519");
|
|
22
|
-
const bls12_381_1 = require("@noble/curves/bls12-381");
|
|
23
|
-
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
24
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
25
|
-
const types_1 = require("./types");
|
|
26
53
|
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
27
54
|
const protobuf_1 = require("@bufbuild/protobuf");
|
|
28
55
|
const ethers_1 = require("ethers");
|
|
29
56
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
30
57
|
const web3_js_1 = require("@solana/web3.js");
|
|
31
58
|
const bs58_1 = __importDefault(require("bs58"));
|
|
59
|
+
const solana = __importStar(require("@solana/web3.js"));
|
|
32
60
|
exports.SESSION_TTL = 60n * 60n * 24n * 30n;
|
|
33
61
|
exports.ZERO_DECIMAL = new decimal_js_1.Decimal(0);
|
|
34
62
|
exports.MAX_BUFFER_LEN = 10000;
|
|
@@ -68,29 +96,6 @@ async function checkedFetch(url, init) {
|
|
|
68
96
|
assert(resp.ok, `Request failed with ${resp.status}: ${resp.statusText}`);
|
|
69
97
|
return resp;
|
|
70
98
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Signs an action using the specified secret key and key type.
|
|
73
|
-
* @param action - The action data to be signed.
|
|
74
|
-
* @param sk - Secret key used for signing the action.
|
|
75
|
-
* @param keyType - Type of the key used for signing.
|
|
76
|
-
* @returns A new Uint8Array containing the action followed by its signature.
|
|
77
|
-
*/
|
|
78
|
-
function signAction(action, sk, keyType) {
|
|
79
|
-
let sig;
|
|
80
|
-
if (keyType === types_1.KeyType.Ed25519) {
|
|
81
|
-
sig = ed25519_1.ed25519.sign(action, sk);
|
|
82
|
-
}
|
|
83
|
-
else if (keyType === types_1.KeyType.Bls12_381) {
|
|
84
|
-
sig = bls12_381_1.bls12_381.sign(action, sk);
|
|
85
|
-
}
|
|
86
|
-
else if (keyType === types_1.KeyType.Secp256k1) {
|
|
87
|
-
sig = secp256k1_1.secp256k1.sign((0, sha256_1.sha256)(action), sk).toCompactRawBytes();
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw new Error("Invalid key type");
|
|
91
|
-
}
|
|
92
|
-
return new Uint8Array([...action, ...sig]);
|
|
93
|
-
}
|
|
94
99
|
/**
|
|
95
100
|
* Constructs wallet signing function, usable with `NordUser` type
|
|
96
101
|
*
|
|
@@ -185,17 +190,6 @@ function decodeLengthDelimited(bytes, schema) {
|
|
|
185
190
|
// decode the message using the offset and size from peek
|
|
186
191
|
return (0, protobuf_1.fromBinary)(schema, bytes.slice(peekResult.offset, peekResult.offset + peekResult.size));
|
|
187
192
|
}
|
|
188
|
-
function checkPubKeyLength(keyType, len) {
|
|
189
|
-
if (keyType === types_1.KeyType.Bls12_381) {
|
|
190
|
-
throw new Error("Cannot create a user using Bls12_381, use Ed25119 or Secp256k1 instead.");
|
|
191
|
-
}
|
|
192
|
-
if (len !== 32 && keyType === types_1.KeyType.Ed25519) {
|
|
193
|
-
throw new Error("Ed25519 pubkeys must be 32 length.");
|
|
194
|
-
}
|
|
195
|
-
if (len !== 33 && keyType === types_1.KeyType.Secp256k1) {
|
|
196
|
-
throw new Error("Secp256k1 pubkeys must be 33 length.");
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
193
|
function decodeHex(value) {
|
|
200
194
|
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
201
195
|
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
@@ -223,3 +217,22 @@ function keypairFromPrivateKey(privateKey) {
|
|
|
223
217
|
}
|
|
224
218
|
return web3_js_1.Keypair.fromSecretKey(privateKey);
|
|
225
219
|
}
|
|
220
|
+
async function signUserPayload({ payload, user, signTransaction, }) {
|
|
221
|
+
const tx = new solana.Transaction({
|
|
222
|
+
blockhash: bs58_1.default.encode(new Uint8Array(32)),
|
|
223
|
+
lastValidBlockHeight: 0,
|
|
224
|
+
feePayer: user,
|
|
225
|
+
});
|
|
226
|
+
tx.add(new solana.TransactionInstruction({
|
|
227
|
+
keys: [],
|
|
228
|
+
programId: user,
|
|
229
|
+
data: Buffer.from(payload),
|
|
230
|
+
}));
|
|
231
|
+
const signedTx = await signTransaction(tx);
|
|
232
|
+
const sig = signedTx.signatures[0];
|
|
233
|
+
assert(sig.signature !== null, "signature must be non-null; check your signTransaction function");
|
|
234
|
+
assert(sig.signature.length === 64, //.
|
|
235
|
+
"signature must be 64 bytes");
|
|
236
|
+
assert(sig.publicKey.equals(user), `signature is for ${sig.publicKey}, expected ${user}`);
|
|
237
|
+
return sig.signature;
|
|
238
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { Account, DeltaEvent, OrderbookResponse, SubscriberConfig, StreamTrade, Trades } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Subscriber class for handling WebSocket subscriptions
|
|
5
|
+
*/
|
|
6
|
+
export declare class Subscriber {
|
|
7
|
+
streamURL: string;
|
|
8
|
+
buffer: (DeltaEvent | Trades | Account)[];
|
|
9
|
+
maxBufferLen: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new Subscriber instance
|
|
12
|
+
* @param config Subscriber configuration
|
|
13
|
+
*/
|
|
14
|
+
constructor(config: SubscriberConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Subscribe to WebSocket events
|
|
17
|
+
*/
|
|
18
|
+
subscribe(): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Interface for orderbook subscription
|
|
22
|
+
*/
|
|
23
|
+
export interface OrderbookSubscription extends EventEmitter {
|
|
24
|
+
on(event: "message", listener: (data: OrderbookResponse) => void): this;
|
|
25
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
26
|
+
close(): void;
|
|
27
|
+
removeAllListeners(event?: string): this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface for trade subscription
|
|
31
|
+
*/
|
|
32
|
+
export interface TradeSubscription extends EventEmitter {
|
|
33
|
+
on(event: "message", listener: (data: StreamTrade[]) => void): this;
|
|
34
|
+
on(event: "error", listener: (error: Error) => void): this;
|
|
35
|
+
close(): void;
|
|
36
|
+
removeAllListeners(event?: string): this;
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subscriber = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
/**
|
|
6
|
+
* Subscriber class for handling WebSocket subscriptions
|
|
7
|
+
*/
|
|
8
|
+
class Subscriber {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new Subscriber instance
|
|
11
|
+
* @param config Subscriber configuration
|
|
12
|
+
*/
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.streamURL = config.streamURL;
|
|
15
|
+
this.buffer = [];
|
|
16
|
+
this.maxBufferLen = config.maxBufferLen ?? utils_1.MAX_BUFFER_LEN;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to WebSocket events
|
|
20
|
+
*/
|
|
21
|
+
subscribe() {
|
|
22
|
+
// TODO: Implement subscription logic
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Subscriber = Subscriber;
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { NordWebSocketClient } from "./NordWebSocketClient";
|
|
2
|
+
import type { SubscriptionPattern } from "../types";
|
|
3
|
+
import type { NordWebSocketEvents, NordWebSocketClientEvents } from "./events";
|
|
4
|
+
import { Subscriber } from "./Subscriber";
|
|
5
|
+
export { NordWebSocketClient, NordWebSocketEvents, NordWebSocketClientEvents, Subscriber, };
|
|
6
|
+
/**
|
|
7
|
+
* Initialize a WebSocket client for Nord
|
|
8
|
+
*
|
|
9
|
+
* Connects to the Nord WebSocket endpoint with support for multiple subscription types:
|
|
10
|
+
* - trades@SYMBOL - For trade updates
|
|
11
|
+
* - deltas@SYMBOL - For orderbook delta updates
|
|
12
|
+
* - account@ACCOUNT_ID - For user-specific updates
|
|
13
|
+
*
|
|
14
|
+
* @param webServerUrl - Base URL for the Nord web server
|
|
15
|
+
* @param subscriptions - Array of subscriptions (e.g., ["trades@BTCUSDC", "deltas@BTCUSDC", "account@42"])
|
|
16
|
+
* @returns WebSocket client
|
|
17
|
+
* @throws {NordError} If initialization fails or invalid subscription is provided
|
|
18
|
+
*/
|
|
19
|
+
export declare function initWebSocketClient(webServerUrl: string, subscriptions?: SubscriptionPattern[] | "trades" | "delta" | "account"): NordWebSocketClient;
|