@n1xyz/nord-ts 0.1.7 → 0.1.8

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.
Files changed (84) hide show
  1. package/dist/actions.js +39 -82
  2. package/dist/bundle.js +79181 -0
  3. package/dist/client/Nord.d.ts +2 -2
  4. package/dist/client/Nord.js +46 -78
  5. package/dist/client/NordAdmin.d.ts +2 -2
  6. package/dist/client/NordAdmin.js +57 -89
  7. package/dist/client/NordUser.js +118 -147
  8. package/dist/const.js +5 -8
  9. package/dist/error.js +7 -5
  10. package/dist/gen/nord_pb.js +88 -92
  11. package/dist/gen/openapi.d.ts +5 -6
  12. package/dist/gen/openapi.js +1 -2
  13. package/dist/index.js +10 -49
  14. package/dist/types.d.ts +1 -0
  15. package/dist/types.js +21 -60
  16. package/dist/utils.js +38 -86
  17. package/dist/websocket/NordWebSocketClient.js +12 -17
  18. package/dist/websocket/Subscriber.js +6 -7
  19. package/dist/websocket/events.js +1 -2
  20. package/dist/websocket/index.js +10 -15
  21. package/package.json +2 -3
  22. package/dist/api/client.d.ts +0 -14
  23. package/dist/api/client.js +0 -45
  24. package/dist/bridge/client.d.ts +0 -151
  25. package/dist/bridge/client.js +0 -434
  26. package/dist/bridge/const.d.ts +0 -23
  27. package/dist/bridge/const.js +0 -47
  28. package/dist/bridge/index.d.ts +0 -4
  29. package/dist/bridge/index.js +0 -23
  30. package/dist/bridge/types.d.ts +0 -120
  31. package/dist/bridge/types.js +0 -18
  32. package/dist/bridge/utils.d.ts +0 -64
  33. package/dist/bridge/utils.js +0 -131
  34. package/dist/gen/common.d.ts +0 -68
  35. package/dist/gen/common.js +0 -215
  36. package/dist/gen/nord.d.ts +0 -882
  37. package/dist/gen/nord.js +0 -6520
  38. package/dist/idl/bridge.d.ts +0 -569
  39. package/dist/idl/bridge.js +0 -8
  40. package/dist/idl/bridge.json +0 -1506
  41. package/dist/idl/index.d.ts +0 -607
  42. package/dist/idl/index.js +0 -8
  43. package/dist/nord/api/actions.d.ts +0 -126
  44. package/dist/nord/api/actions.js +0 -397
  45. package/dist/nord/api/core.d.ts +0 -16
  46. package/dist/nord/api/core.js +0 -81
  47. package/dist/nord/api/market.d.ts +0 -36
  48. package/dist/nord/api/market.js +0 -96
  49. package/dist/nord/api/metrics.d.ts +0 -67
  50. package/dist/nord/api/metrics.js +0 -229
  51. package/dist/nord/api/queries.d.ts +0 -46
  52. package/dist/nord/api/queries.js +0 -109
  53. package/dist/nord/api/triggers.d.ts +0 -7
  54. package/dist/nord/api/triggers.js +0 -38
  55. package/dist/nord/client/Nord.d.ts +0 -396
  56. package/dist/nord/client/Nord.js +0 -747
  57. package/dist/nord/client/NordAdmin.d.ts +0 -259
  58. package/dist/nord/client/NordAdmin.js +0 -395
  59. package/dist/nord/client/NordClient.d.ts +0 -33
  60. package/dist/nord/client/NordClient.js +0 -45
  61. package/dist/nord/client/NordUser.d.ts +0 -362
  62. package/dist/nord/client/NordUser.js +0 -781
  63. package/dist/nord/index.d.ts +0 -11
  64. package/dist/nord/index.js +0 -36
  65. package/dist/nord/models/Subscriber.d.ts +0 -37
  66. package/dist/nord/models/Subscriber.js +0 -25
  67. package/dist/nord/utils/NordError.d.ts +0 -35
  68. package/dist/nord/utils/NordError.js +0 -49
  69. package/src/actions.ts +0 -333
  70. package/src/client/Nord.ts +0 -934
  71. package/src/client/NordAdmin.ts +0 -484
  72. package/src/client/NordUser.ts +0 -1122
  73. package/src/const.ts +0 -34
  74. package/src/error.ts +0 -76
  75. package/src/gen/.gitkeep +0 -0
  76. package/src/gen/nord_pb.ts +0 -5053
  77. package/src/gen/openapi.ts +0 -2904
  78. package/src/index.ts +0 -11
  79. package/src/types.ts +0 -327
  80. package/src/utils.ts +0 -266
  81. package/src/websocket/NordWebSocketClient.ts +0 -316
  82. package/src/websocket/Subscriber.ts +0 -56
  83. package/src/websocket/events.ts +0 -31
  84. package/src/websocket/index.ts +0 -105
@@ -1253,10 +1253,7 @@ export interface paths {
1253
1253
  [name: string]: unknown;
1254
1254
  };
1255
1255
  content: {
1256
- "application/json": [
1257
- string,
1258
- components["schemas"]["AclRole"]
1259
- ][];
1256
+ "application/json": components["schemas"]["AdminInfo"][];
1260
1257
  };
1261
1258
  };
1262
1259
  };
@@ -2726,8 +2723,10 @@ export interface components {
2726
2723
  accountId: number;
2727
2724
  feeTier: components["schemas"]["FeeTierId"];
2728
2725
  };
2729
- /** Format: uint32 */
2730
- AclRole: number;
2726
+ AdminInfo: {
2727
+ key: string;
2728
+ roles: string[];
2729
+ };
2731
2730
  /** @description TV config query response https://www.tradingview.com/charting-library-docs/latest/connecting_data/UDF/#data-feed-configuration-data */
2732
2731
  TvConfigResponse: {
2733
2732
  supported_resolutions: components["schemas"]["Resolution"][];
@@ -1,6 +1,5 @@
1
- "use strict";
2
1
  /**
3
2
  * This file was auto-generated by openapi-typescript.
4
3
  * Do not make direct changes to the file.
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
5
+ export {};
package/dist/index.js CHANGED
@@ -1,49 +1,10 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
19
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
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
- })();
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.openapi = exports.proto = void 0;
40
- __exportStar(require("./types"), exports);
41
- __exportStar(require("./utils"), exports);
42
- __exportStar(require("./const"), exports);
43
- __exportStar(require("./error"), exports);
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"));
1
+ export * from "./types";
2
+ export * from "./utils";
3
+ export * from "./const";
4
+ export * from "./error";
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/types.d.ts CHANGED
@@ -70,6 +70,7 @@ export type FeeTierId = components["schemas"]["FeeTierId"];
70
70
  export type TokenStats = components["schemas"]["TokenStats"];
71
71
  export type AccountFeeTier = components["schemas"]["AccountFeeTier"];
72
72
  export type AccountFeeTierPage = components["schemas"]["PageResult_for_uint32_and_AccountFeeTier"];
73
+ export type AdminInfo = components["schemas"]["AdminInfo"];
73
74
  /**
74
75
  * Configuration options for the Nord client
75
76
  */
package/dist/types.js CHANGED
@@ -1,70 +1,30 @@
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
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.QuoteSize = exports.WebSocketMessageType = exports.TriggerStatus = exports.TriggerKind = exports.FillMode = exports.Side = void 0;
40
- exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
41
- const proto = __importStar(require("./gen/nord_pb"));
42
- const decimal_js_1 = __importDefault(require("decimal.js"));
43
- const utils_1 = require("./utils");
44
- var Side;
1
+ import * as proto from "./gen/nord_pb";
2
+ import Decimal from "decimal.js";
3
+ import { toScaledU64 } from "./utils";
4
+ export var Side;
45
5
  (function (Side) {
46
6
  Side["Ask"] = "ask";
47
7
  Side["Bid"] = "bid";
48
- })(Side || (exports.Side = Side = {}));
49
- var FillMode;
8
+ })(Side || (Side = {}));
9
+ export var FillMode;
50
10
  (function (FillMode) {
51
11
  FillMode[FillMode["Limit"] = 0] = "Limit";
52
12
  FillMode[FillMode["PostOnly"] = 1] = "PostOnly";
53
13
  FillMode[FillMode["ImmediateOrCancel"] = 2] = "ImmediateOrCancel";
54
14
  FillMode[FillMode["FillOrKill"] = 3] = "FillOrKill";
55
- })(FillMode || (exports.FillMode = FillMode = {}));
56
- var TriggerKind;
15
+ })(FillMode || (FillMode = {}));
16
+ export var TriggerKind;
57
17
  (function (TriggerKind) {
58
18
  TriggerKind[TriggerKind["StopLoss"] = 0] = "StopLoss";
59
19
  TriggerKind[TriggerKind["TakeProfit"] = 1] = "TakeProfit";
60
- })(TriggerKind || (exports.TriggerKind = TriggerKind = {}));
61
- var TriggerStatus;
20
+ })(TriggerKind || (TriggerKind = {}));
21
+ export var TriggerStatus;
62
22
  (function (TriggerStatus) {
63
23
  TriggerStatus[TriggerStatus["Active"] = 0] = "Active";
64
24
  TriggerStatus[TriggerStatus["Success"] = 1] = "Success";
65
25
  TriggerStatus[TriggerStatus["Cancel"] = 2] = "Cancel";
66
26
  TriggerStatus[TriggerStatus["Remove"] = 4] = "Remove";
67
- })(TriggerStatus || (exports.TriggerStatus = TriggerStatus = {}));
27
+ })(TriggerStatus || (TriggerStatus = {}));
68
28
  /**
69
29
  * Converts a `FillMode` enum to its corresponding protobuf representation.
70
30
  *
@@ -72,7 +32,7 @@ var TriggerStatus;
72
32
  * @returns The corresponding protobuf fill mode.
73
33
  * @throws Will throw an error if provided with an invalid fill mode.
74
34
  */
75
- function fillModeToProtoFillMode(x) {
35
+ export function fillModeToProtoFillMode(x) {
76
36
  if (x === FillMode.Limit)
77
37
  return proto.FillMode.LIMIT;
78
38
  if (x === FillMode.PostOnly)
@@ -87,12 +47,12 @@ function fillModeToProtoFillMode(x) {
87
47
  /**
88
48
  * WebSocket message types
89
49
  */
90
- var WebSocketMessageType;
50
+ export var WebSocketMessageType;
91
51
  (function (WebSocketMessageType) {
92
52
  WebSocketMessageType["TradeUpdate"] = "trades";
93
53
  WebSocketMessageType["DeltaUpdate"] = "delta";
94
54
  WebSocketMessageType["AccountUpdate"] = "account";
95
- })(WebSocketMessageType || (exports.WebSocketMessageType = WebSocketMessageType = {}));
55
+ })(WebSocketMessageType || (WebSocketMessageType = {}));
96
56
  // Positive decimal price and size.
97
57
  // Example:
98
58
  // ```
@@ -105,11 +65,13 @@ var WebSocketMessageType;
105
65
  // If you want to get smaller tick on client (on server it will not change),
106
66
  // do `new QuoteSize(new Decimal(114000/2), new Decimal(0.00070))`.
107
67
  // It will be 40$ limit, but may help if BTC suddently moves fast.
108
- class QuoteSize {
68
+ export class QuoteSize {
69
+ price;
70
+ size;
109
71
  /// Input can be only positive values.
110
72
  constructor(quotePrice, quoteSize) {
111
- const p = new decimal_js_1.default(quotePrice);
112
- const s = new decimal_js_1.default(quoteSize);
73
+ const p = new Decimal(quotePrice);
74
+ const s = new Decimal(quoteSize);
113
75
  if (!p.isPositive() || !s.isPositive()) {
114
76
  throw new Error("quotePrice and quoteSize must be positive");
115
77
  }
@@ -123,9 +85,8 @@ class QuoteSize {
123
85
  // Converts to wire format to be send to server, scaling price and size according to market decimals.
124
86
  toWire(marketPriceDecimals, marketSizeDecimals) {
125
87
  return {
126
- price: (0, utils_1.toScaledU64)(this.price, marketPriceDecimals),
127
- size: (0, utils_1.toScaledU64)(this.size, marketSizeDecimals),
88
+ price: toScaledU64(this.price, marketPriceDecimals),
89
+ size: toScaledU64(this.size, marketSizeDecimals),
128
90
  };
129
91
  }
130
92
  }
131
- exports.QuoteSize = QuoteSize;
package/dist/utils.js CHANGED
@@ -1,75 +1,25 @@
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
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.toScaledU128 = exports.toScaledU64 = exports.MAX_BUFFER_LEN = exports.ZERO_DECIMAL = exports.SESSION_TTL = void 0;
40
- exports.panic = panic;
41
- exports.isRfc3339 = isRfc3339;
42
- exports.assert = assert;
43
- exports.optExpect = optExpect;
44
- exports.checkedFetch = checkedFetch;
45
- exports.makeWalletSignFn = makeWalletSignFn;
46
- exports.decodeLengthDelimited = decodeLengthDelimited;
47
- exports.decodeHex = decodeHex;
48
- exports.findMarket = findMarket;
49
- exports.findToken = findToken;
50
- exports.keypairFromPrivateKey = keypairFromPrivateKey;
51
- exports.signUserPayload = signUserPayload;
52
- const decimal_js_1 = require("decimal.js");
53
- const wire_1 = require("@bufbuild/protobuf/wire");
54
- const protobuf_1 = require("@bufbuild/protobuf");
55
- const ethers_1 = require("ethers");
56
- const node_fetch_1 = __importDefault(require("node-fetch"));
57
- const web3_js_1 = require("@solana/web3.js");
58
- const bs58_1 = __importDefault(require("bs58"));
59
- const solana = __importStar(require("@solana/web3.js"));
60
- exports.SESSION_TTL = 60n * 60n * 24n * 30n;
61
- exports.ZERO_DECIMAL = new decimal_js_1.Decimal(0);
62
- exports.MAX_BUFFER_LEN = 10000;
1
+ import { Decimal } from "decimal.js";
2
+ import { sizeDelimitedPeek } from "@bufbuild/protobuf/wire";
3
+ import { fromBinary } from "@bufbuild/protobuf";
4
+ import { ethers } from "ethers";
5
+ import fetch from "node-fetch";
6
+ import { Keypair } from "@solana/web3.js";
7
+ import bs58 from "bs58";
8
+ import * as solana from "@solana/web3.js";
9
+ import { Buffer } from "buffer";
10
+ export const SESSION_TTL = 60n * 60n * 24n * 30n;
11
+ export const ZERO_DECIMAL = new Decimal(0);
12
+ export const MAX_BUFFER_LEN = 10_000;
63
13
  // Max size of data returned from Nord endpoints
64
14
  const MAX_PAYLOAD_SIZE = 100 * 1024; // 100 kB
65
- function panic(message) {
15
+ export function panic(message) {
66
16
  throw new Error(message);
67
17
  }
68
- function isRfc3339(s) {
18
+ export function isRfc3339(s) {
69
19
  const REGEX = /^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:\d{2})?)$/;
70
20
  return REGEX.test(s);
71
21
  }
72
- function assert(predicate, message) {
22
+ export function assert(predicate, message) {
73
23
  if (!predicate)
74
24
  panic(message ?? "Assertion violated");
75
25
  }
@@ -79,7 +29,7 @@ function assert(predicate, message) {
79
29
  * @param message Error message
80
30
  * @returns Unwrapped value
81
31
  */
82
- function optExpect(value, message) {
32
+ export function optExpect(value, message) {
83
33
  if (value === undefined)
84
34
  throw new Error(message);
85
35
  return value;
@@ -91,8 +41,8 @@ function optExpect(value, message) {
91
41
  * @returns Raw response if fetch succeeded
92
42
  * @throws If response wasn't Ok
93
43
  */
94
- async function checkedFetch(url, init) {
95
- const resp = await (0, node_fetch_1.default)(url, init);
44
+ export async function checkedFetch(url, init) {
45
+ const resp = await fetch(url, init);
96
46
  assert(resp.ok, `Request failed with ${resp.status}: ${resp.statusText}`);
97
47
  return resp;
98
48
  }
@@ -104,13 +54,13 @@ async function checkedFetch(url, init) {
104
54
  * then signs it with provided user wallet key and returns signature
105
55
  * as hex string prefixed with `"0x"`
106
56
  */
107
- function makeWalletSignFn(walletKey) {
108
- const signingKey = new ethers_1.ethers.SigningKey(walletKey);
109
- return async (message) => signingKey.sign(ethers_1.ethers.hashMessage(message)).serialized;
57
+ export function makeWalletSignFn(walletKey) {
58
+ const signingKey = new ethers.SigningKey(walletKey);
59
+ return async (message) => signingKey.sign(ethers.hashMessage(message)).serialized;
110
60
  }
111
61
  // Returned numbers do fit into specified bits range, or error is thrown.
112
62
  function makeToScaledBigUint(params) {
113
- const Dec = decimal_js_1.Decimal.clone({
63
+ const Dec = Decimal.clone({
114
64
  precision: params.precision,
115
65
  toExpPos: params.exponent,
116
66
  toExpNeg: -params.exponent,
@@ -146,7 +96,7 @@ function makeToScaledBigUint(params) {
146
96
  * @param decimals Number of decimal digits
147
97
  * @returns Rescaled unsigned integer
148
98
  */
149
- exports.toScaledU64 = makeToScaledBigUint({
99
+ export const toScaledU64 = makeToScaledBigUint({
150
100
  bits: 64,
151
101
  precision: 20,
152
102
  exponent: 28,
@@ -162,7 +112,7 @@ exports.toScaledU64 = makeToScaledBigUint({
162
112
  * @param decimals Number of decimal digits
163
113
  * @returns Rescaled unsigned integer
164
114
  */
165
- exports.toScaledU128 = makeToScaledBigUint({
115
+ export const toScaledU128 = makeToScaledBigUint({
166
116
  bits: 128,
167
117
  precision: 40,
168
118
  exponent: 56,
@@ -175,9 +125,9 @@ exports.toScaledU128 = makeToScaledBigUint({
175
125
  * @param schema Message schema for decoding
176
126
  * @returns Decoded message
177
127
  */
178
- function decodeLengthDelimited(bytes, schema) {
128
+ export function decodeLengthDelimited(bytes, schema) {
179
129
  // use sizeDelimitedPeek to extract the message length and offset
180
- const peekResult = (0, wire_1.sizeDelimitedPeek)(bytes);
130
+ const peekResult = sizeDelimitedPeek(bytes);
181
131
  if (peekResult.size === null || peekResult.offset === null) {
182
132
  throw new Error("Failed to parse size-delimited message");
183
133
  }
@@ -188,38 +138,38 @@ function decodeLengthDelimited(bytes, schema) {
188
138
  throw new Error(`Encoded message size (${peekResult.size} bytes) is greater than remaining buffer size (${bytes.length - peekResult.offset} bytes).`);
189
139
  }
190
140
  // decode the message using the offset and size from peek
191
- return (0, protobuf_1.fromBinary)(schema, bytes.slice(peekResult.offset, peekResult.offset + peekResult.size));
141
+ return fromBinary(schema, bytes.slice(peekResult.offset, peekResult.offset + peekResult.size));
192
142
  }
193
- function decodeHex(value) {
143
+ export function decodeHex(value) {
194
144
  const hex = value.startsWith("0x") ? value.slice(2) : value;
195
145
  return Uint8Array.from(Buffer.from(hex, "hex"));
196
146
  }
197
- function findMarket(markets, marketId) {
147
+ export function findMarket(markets, marketId) {
198
148
  if (marketId < 0 || markets.length - 1 < marketId) {
199
149
  throw new Error(`The market with marketId=${marketId} not found`);
200
150
  }
201
151
  return markets[marketId];
202
152
  }
203
- function findToken(tokens, tokenId) {
153
+ export function findToken(tokens, tokenId) {
204
154
  if (tokenId < 0 || tokens.length - 1 < tokenId) {
205
155
  throw new Error(`The token with tokenId=${tokenId} not found`);
206
156
  }
207
157
  return tokens[tokenId];
208
158
  }
209
- function keypairFromPrivateKey(privateKey) {
159
+ export function keypairFromPrivateKey(privateKey) {
210
160
  if (typeof privateKey === "string") {
211
161
  if (!privateKey.startsWith("0x")) {
212
- return web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(privateKey));
162
+ return Keypair.fromSecretKey(bs58.decode(privateKey));
213
163
  }
214
164
  const hex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
215
165
  const bytes = new Uint8Array(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
216
- return web3_js_1.Keypair.fromSecretKey(bytes);
166
+ return Keypair.fromSecretKey(bytes);
217
167
  }
218
- return web3_js_1.Keypair.fromSecretKey(privateKey);
168
+ return Keypair.fromSecretKey(privateKey);
219
169
  }
220
- async function signUserPayload({ payload, user, signTransaction, }) {
170
+ export async function signUserPayload({ payload, user, signTransaction, }) {
221
171
  const tx = new solana.Transaction({
222
- blockhash: bs58_1.default.encode(new Uint8Array(32)),
172
+ blockhash: bs58.encode(new Uint8Array(32)),
223
173
  lastValidBlockHeight: 0,
224
174
  feePayer: user,
225
175
  });
@@ -230,6 +180,8 @@ async function signUserPayload({ payload, user, signTransaction, }) {
230
180
  }));
231
181
  const signedTx = await signTransaction(tx);
232
182
  const sig = signedTx.signatures[0];
183
+ assert(sig !== undefined, //.
184
+ "signed transaction must have a signature");
233
185
  assert(sig.signature !== null, "signature must be non-null; check your signTransaction function");
234
186
  assert(sig.signature.length === 64, //.
235
187
  "signature must be 64 bytes");
@@ -1,11 +1,5 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NordWebSocketClient = void 0;
7
- const events_1 = require("events");
8
- const ws_1 = __importDefault(require("ws"));
1
+ import { EventEmitter } from "events";
2
+ import WebSocket from "ws";
9
3
  const VALID_STREAM_TYPES = ["trades", "delta", "account"];
10
4
  /**
11
5
  * WebSocket client for Nord exchange
@@ -16,19 +10,21 @@ const VALID_STREAM_TYPES = ["trades", "delta", "account"];
16
10
  * the endpoint type (e.g., only 'trades@BTCUSDC' subscriptions are valid on
17
11
  * the /ws/trades endpoint).
18
12
  */
19
- class NordWebSocketClient extends events_1.EventEmitter {
13
+ export class NordWebSocketClient extends EventEmitter {
14
+ ws = null;
15
+ url;
16
+ reconnectAttempts = 0;
17
+ maxReconnectAttempts = 5;
18
+ reconnectDelay = 1000;
19
+ pingInterval = null;
20
+ pingTimeout = null;
21
+ isBrowser;
20
22
  /**
21
23
  * Create a new NordWebSocketClient
22
24
  * @param url WebSocket server URL
23
25
  */
24
26
  constructor(url) {
25
27
  super();
26
- this.ws = null;
27
- this.reconnectAttempts = 0;
28
- this.maxReconnectAttempts = 5;
29
- this.reconnectDelay = 1000;
30
- this.pingInterval = null;
31
- this.pingTimeout = null;
32
28
  this.url = url;
33
29
  // Check if we're in a browser environment
34
30
  // The most reliable way is to check for Node.js process
@@ -101,7 +97,7 @@ class NordWebSocketClient extends events_1.EventEmitter {
101
97
  }
102
98
  else {
103
99
  // In Node.js
104
- return ws_1.default;
100
+ return WebSocket;
105
101
  }
106
102
  }
107
103
  /**
@@ -244,4 +240,3 @@ class NordWebSocketClient extends events_1.EventEmitter {
244
240
  }, this.reconnectDelay);
245
241
  }
246
242
  }
247
- exports.NordWebSocketClient = NordWebSocketClient;
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Subscriber = void 0;
4
- const utils_1 = require("../utils");
1
+ import { MAX_BUFFER_LEN } from "../utils";
5
2
  /**
6
3
  * Subscriber class for handling WebSocket subscriptions
7
4
  */
8
- class Subscriber {
5
+ export class Subscriber {
6
+ streamURL;
7
+ buffer;
8
+ maxBufferLen;
9
9
  /**
10
10
  * Create a new Subscriber instance
11
11
  * @param config Subscriber configuration
@@ -13,7 +13,7 @@ class Subscriber {
13
13
  constructor(config) {
14
14
  this.streamURL = config.streamURL;
15
15
  this.buffer = [];
16
- this.maxBufferLen = config.maxBufferLen ?? utils_1.MAX_BUFFER_LEN;
16
+ this.maxBufferLen = config.maxBufferLen ?? MAX_BUFFER_LEN;
17
17
  }
18
18
  /**
19
19
  * Subscribe to WebSocket events
@@ -22,4 +22,3 @@ class Subscriber {
22
22
  // TODO: Implement subscription logic
23
23
  }
24
24
  }
25
- exports.Subscriber = Subscriber;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,12 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Subscriber = exports.NordWebSocketClient = void 0;
4
- exports.initWebSocketClient = initWebSocketClient;
5
- const NordWebSocketClient_1 = require("./NordWebSocketClient");
6
- Object.defineProperty(exports, "NordWebSocketClient", { enumerable: true, get: function () { return NordWebSocketClient_1.NordWebSocketClient; } });
7
- const error_1 = require("../error");
8
- const Subscriber_1 = require("./Subscriber");
9
- Object.defineProperty(exports, "Subscriber", { enumerable: true, get: function () { return Subscriber_1.Subscriber; } });
1
+ import { NordWebSocketClient } from "./NordWebSocketClient";
2
+ import { NordError } from "../error";
3
+ import { Subscriber } from "./Subscriber";
4
+ export { NordWebSocketClient, Subscriber, };
10
5
  /**
11
6
  * Initialize a WebSocket client for Nord
12
7
  *
@@ -20,7 +15,7 @@ Object.defineProperty(exports, "Subscriber", { enumerable: true, get: function (
20
15
  * @returns WebSocket client
21
16
  * @throws {NordError} If initialization fails or invalid subscription is provided
22
17
  */
23
- function initWebSocketClient(webServerUrl, subscriptions) {
18
+ export function initWebSocketClient(webServerUrl, subscriptions) {
24
19
  try {
25
20
  // Determine URL and subscriptions based on parameters
26
21
  let wsUrl = webServerUrl.replace(/^http/, "ws") + `/ws`;
@@ -33,7 +28,7 @@ function initWebSocketClient(webServerUrl, subscriptions) {
33
28
  wsUrl += `/${subscriptions}`;
34
29
  }
35
30
  else {
36
- throw new error_1.NordError(`Invalid endpoint: ${subscriptions}. Must be "trades", "deltas", or "account".`);
31
+ throw new NordError(`Invalid endpoint: ${subscriptions}. Must be "trades", "deltas", or "account".`);
37
32
  }
38
33
  }
39
34
  else if (Array.isArray(subscriptions) && subscriptions.length > 0) {
@@ -47,7 +42,7 @@ function initWebSocketClient(webServerUrl, subscriptions) {
47
42
  }
48
43
  console.log(`Initializing WebSocket client with URL: ${wsUrl}`);
49
44
  // Create and connect the WebSocket client
50
- const ws = new NordWebSocketClient_1.NordWebSocketClient(wsUrl);
45
+ const ws = new NordWebSocketClient(wsUrl);
51
46
  // Add error handler
52
47
  ws.on("error", (error) => {
53
48
  console.error("Nord WebSocket error:", error);
@@ -62,7 +57,7 @@ function initWebSocketClient(webServerUrl, subscriptions) {
62
57
  }
63
58
  catch (error) {
64
59
  console.error("Failed to initialize WebSocket client:", error);
65
- throw new error_1.NordError("Failed to initialize WebSocket client", {
60
+ throw new NordError("Failed to initialize WebSocket client", {
66
61
  cause: error,
67
62
  });
68
63
  }
@@ -76,10 +71,10 @@ function initWebSocketClient(webServerUrl, subscriptions) {
76
71
  function validateSubscription(subscription) {
77
72
  const [type, param] = subscription.split("@");
78
73
  if (!type || !param || !["trades", "deltas", "account"].includes(type)) {
79
- throw new error_1.NordError(`Invalid subscription format: ${subscription}. Expected format: "trades@SYMBOL", "deltas@SYMBOL", or "account@ID"`);
74
+ throw new NordError(`Invalid subscription format: ${subscription}. Expected format: "trades@SYMBOL", "deltas@SYMBOL", or "account@ID"`);
80
75
  }
81
76
  // Additional validation for account subscriptions
82
77
  if (type === "account" && isNaN(Number(param))) {
83
- throw new error_1.NordError(`Invalid account ID in subscription: ${subscription}. Account ID must be a number.`);
78
+ throw new NordError(`Invalid account ID in subscription: ${subscription}. Account ID must be a number.`);
84
79
  }
85
80
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@n1xyz/nord-ts",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Typescript for Nord",
5
5
  "keywords": [],
6
6
  "author": "",
7
7
  "license": "ISC",
8
+ "type": "module",
8
9
  "main": "dist/index.js",
9
10
  "types": "dist/index.d.ts",
10
11
  "files": [
11
12
  "dist/",
12
- "src/",
13
13
  "package.json",
14
14
  "README.md"
15
15
  ],
@@ -30,7 +30,6 @@
30
30
  "@bufbuild/protoplugin": "^2.6.3",
31
31
  "@types/bun": "latest",
32
32
  "@types/google-protobuf": "^3.15.12",
33
- "@types/node": "^22.17.1",
34
33
  "@types/node-fetch": "^2.6.13",
35
34
  "@types/ws": "^8.18.1",
36
35
  "@typescript-eslint/eslint-plugin": "^8.39.1",
@@ -1,14 +0,0 @@
1
- import type { paths } from "../gen/openapi";
2
- export interface ClientConfig {
3
- baseUrl: string;
4
- }
5
- export declare function createApiClient(config: ClientConfig): import("openapi-fetch").Client<paths, `${string}/${string}`>;
6
- export declare function handleApiResponse<T>(response: Promise<{
7
- data: T;
8
- error?: unknown;
9
- response: Response;
10
- } | {
11
- data?: never;
12
- error?: unknown;
13
- response: Response;
14
- }>): Promise<T>;