@n1xyz/nord-ts 0.1.3 → 0.1.5

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.
@@ -40,14 +40,17 @@ const ed = __importStar(require("@noble/ed25519"));
40
40
  const sha512_1 = require("@noble/hashes/sha512");
41
41
  ed.etc.sha512Sync = sha512_1.sha512;
42
42
  const proton_1 = require("@n1xyz/proton");
43
+ const types_1 = require("../../types");
44
+ const proto = __importStar(require("../../gen/nord_pb"));
43
45
  const utils_1 = require("../../utils");
46
+ const protobuf_1 = require("@bufbuild/protobuf");
44
47
  const actions_1 = require("../api/actions");
45
- const triggers_1 = require("../api/triggers");
46
48
  const NordError_1 = require("../utils/NordError");
49
+ const NordClient_1 = require("./NordClient");
47
50
  /**
48
51
  * User class for interacting with the Nord protocol
49
52
  */
50
- class NordUser {
53
+ class NordUser extends NordClient_1.NordClient {
51
54
  /**
52
55
  * Create a new NordUser instance
53
56
  *
@@ -55,18 +58,6 @@ class NordUser {
55
58
  * @throws {NordError} If required parameters are missing
56
59
  */
57
60
  constructor({ address, nord, publicKey, sessionPubKey, sessionSignFn, transactionSignFn, walletSignFn, connection, sessionId, }) {
58
- /** User balances by token symbol */
59
- this.balances = {};
60
- /** User positions by account ID */
61
- this.positions = {};
62
- /** User margins by account ID */
63
- this.margins = {};
64
- /** Last timestamp used */
65
- this.lastTs = 0;
66
- /** Last nonce used */
67
- this.lastNonce = 0;
68
- /** SPL token information */
69
- this.splTokenInfos = [];
70
61
  if (!walletSignFn) {
71
62
  throw new NordError_1.NordError("Wallet sign function is required");
72
63
  }
@@ -76,27 +67,32 @@ class NordUser {
76
67
  if (!sessionPubKey) {
77
68
  throw new NordError_1.NordError("Session public key is required");
78
69
  }
70
+ let parsedAddress;
79
71
  try {
80
- this.address = new web3_js_1.PublicKey(address);
72
+ parsedAddress = new web3_js_1.PublicKey(address);
81
73
  }
82
74
  catch (error) {
83
75
  throw new NordError_1.NordError("Invalid Solana address", { cause: error });
84
76
  }
85
- this.nord = nord;
86
- this.walletSignFn = walletSignFn;
87
- this.sessionSignFn = sessionSignFn;
88
- this.transactionSignFn = transactionSignFn;
89
- this.sessionPubKey = sessionPubKey;
90
- this.publicKey = publicKey;
91
- this.connection =
92
- connection ||
93
- new web3_js_1.Connection(nord.solanaUrl, {
94
- commitment: "confirmed",
95
- });
96
- // Set sessionId if provided
97
- if (sessionId !== undefined) {
98
- this.sessionId = sessionId;
99
- }
77
+ super({
78
+ nord,
79
+ address: parsedAddress,
80
+ walletSignFn,
81
+ sessionSignFn,
82
+ transactionSignFn,
83
+ connection,
84
+ sessionId,
85
+ sessionPubKey,
86
+ publicKey,
87
+ });
88
+ /** User balances by token symbol */
89
+ this.balances = {};
90
+ /** User positions by account ID */
91
+ this.positions = {};
92
+ /** User margins by account ID */
93
+ this.margins = {};
94
+ /** SPL token information */
95
+ this.splTokenInfos = [];
100
96
  // Convert tokens from info endpoint to SPLTokenInfo
101
97
  if (this.nord.tokens && this.nord.tokens.length > 0) {
102
98
  this.splTokenInfos = this.nord.tokens.map((token) => ({
@@ -120,19 +116,17 @@ class NordUser {
120
116
  sessionSignFn: this.sessionSignFn,
121
117
  transactionSignFn: this.transactionSignFn,
122
118
  connection: this.connection,
123
- sessionPubKey: this.sessionPubKey,
119
+ sessionPubKey: new Uint8Array(this.sessionPubKey),
124
120
  publicKey: this.publicKey,
121
+ sessionId: this.sessionId,
125
122
  });
126
123
  // Copy other properties
127
124
  cloned.balances = { ...this.balances };
128
125
  cloned.positions = { ...this.positions };
129
126
  cloned.margins = { ...this.margins };
130
127
  cloned.accountIds = this.accountIds ? [...this.accountIds] : undefined;
131
- cloned.sessionId = this.sessionId;
132
- cloned.publicKey = this.publicKey;
133
- cloned.lastTs = this.lastTs;
134
- cloned.lastNonce = this.lastNonce;
135
128
  cloned.splTokenInfos = [...this.splTokenInfos];
129
+ this.cloneClientState(cloned);
136
130
  return cloned;
137
131
  }
138
132
  /**
@@ -225,7 +219,7 @@ class NordUser {
225
219
  }
226
220
  }
227
221
  /**
228
- * Deposit SPL tokens to the bridge
222
+ * Deposit SPL tokens to the app
229
223
  *
230
224
  * @param amount - Amount to deposit
231
225
  * @param tokenId - Token ID
@@ -238,7 +232,7 @@ class NordUser {
238
232
  return this.deposit({ amount, tokenId, recipient });
239
233
  }
240
234
  /**
241
- * Deposit SPL tokens to the bridge
235
+ * Deposit SPL tokens to the app
242
236
  *
243
237
  * @param amount - Amount to deposit
244
238
  * @param tokenId - Token ID
@@ -284,7 +278,16 @@ class NordUser {
284
278
  * @returns Nonce as number
285
279
  */
286
280
  getNonce() {
287
- return ++this.lastNonce;
281
+ return this.nextActionNonce();
282
+ }
283
+ async submitSessionAction(kind) {
284
+ return this.submitSignedAction(kind, async (message) => {
285
+ const signature = await this.sessionSignFn(message);
286
+ const signed = new Uint8Array(message.length + signature.length);
287
+ signed.set(message);
288
+ signed.set(signature, message.length);
289
+ return signed;
290
+ });
288
291
  }
289
292
  /**
290
293
  * Update account IDs for this user
@@ -391,13 +394,21 @@ class NordUser {
391
394
  async withdraw({ amount, tokenId, }) {
392
395
  try {
393
396
  this.checkSessionValidity();
394
- const { actionId } = await (0, actions_1.withdraw)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
395
- sizeDecimals: (0, utils_1.findToken)(this.nord.tokens, tokenId).decimals,
396
- sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
397
- tokenId: tokenId,
398
- amount,
397
+ const token = (0, utils_1.findToken)(this.nord.tokens, tokenId);
398
+ const scaledAmount = (0, utils_1.toScaledU64)(amount, token.decimals);
399
+ if (scaledAmount <= 0n) {
400
+ throw new NordError_1.NordError("Withdraw amount must be positive");
401
+ }
402
+ const receipt = await this.submitSessionAction({
403
+ case: "withdraw",
404
+ value: (0, protobuf_1.create)(proto.Action_WithdrawSchema, {
405
+ sessionId: BigInt((0, utils_1.optExpect)(this.sessionId, "No session")),
406
+ tokenId,
407
+ amount: scaledAmount,
408
+ }),
399
409
  });
400
- return { actionId };
410
+ (0, actions_1.expectReceiptKind)(receipt, "withdrawResult", "withdraw");
411
+ return { actionId: receipt.actionId };
401
412
  }
402
413
  catch (error) {
403
414
  throw new NordError_1.NordError(`Failed to withdraw ${amount} of token ID ${tokenId}`, { cause: error });
@@ -417,20 +428,42 @@ class NordUser {
417
428
  if (!market) {
418
429
  throw new NordError_1.NordError(`Market with ID ${params.marketId} not found`);
419
430
  }
420
- const result = await (0, actions_1.placeOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
421
- sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
422
- senderId: params.accountId,
423
- sizeDecimals: market.sizeDecimals,
424
- priceDecimals: market.priceDecimals,
425
- marketId: params.marketId,
426
- side: params.side,
427
- fillMode: params.fillMode,
428
- isReduceOnly: params.isReduceOnly,
429
- size: params.size,
430
- price: params.price,
431
- quoteSize: params.quoteSize,
431
+ const sessionId = (0, utils_1.optExpect)(this.sessionId, "No session");
432
+ const price = (0, utils_1.toScaledU64)(params.price ?? 0, market.priceDecimals);
433
+ const size = (0, utils_1.toScaledU64)(params.size ?? 0, market.sizeDecimals);
434
+ const scaledQuote = params.quoteSize
435
+ ? params.quoteSize.toWire(market.priceDecimals, market.sizeDecimals)
436
+ : undefined;
437
+ (0, utils_1.assert)(price > 0n || size > 0n || scaledQuote !== undefined, "OrderLimit must include at least one of: size, price, or quoteSize");
438
+ const receipt = await this.submitSessionAction({
439
+ case: "placeOrder",
440
+ value: (0, protobuf_1.create)(proto.Action_PlaceOrderSchema, {
441
+ sessionId: BigInt(sessionId),
442
+ senderAccountId: params.accountId,
443
+ marketId: params.marketId,
444
+ side: params.side === types_1.Side.Bid ? proto.Side.BID : proto.Side.ASK,
445
+ fillMode: (0, types_1.fillModeToProtoFillMode)(params.fillMode),
446
+ isReduceOnly: params.isReduceOnly,
447
+ price,
448
+ size,
449
+ quoteSize: scaledQuote === undefined
450
+ ? undefined
451
+ : (0, protobuf_1.create)(proto.QuoteSizeSchema, {
452
+ size: scaledQuote.size,
453
+ price: scaledQuote.price,
454
+ }),
455
+ clientOrderId: params.clientOrderId === undefined
456
+ ? undefined
457
+ : BigInt(params.clientOrderId),
458
+ }),
432
459
  });
433
- return result;
460
+ (0, actions_1.expectReceiptKind)(receipt, "placeOrderResult", "place order");
461
+ const result = receipt.kind.value;
462
+ return {
463
+ actionId: receipt.actionId,
464
+ orderId: result.posted?.orderId,
465
+ fills: result.fills,
466
+ };
434
467
  }
435
468
  catch (error) {
436
469
  throw new NordError_1.NordError("Failed to place order", { cause: error });
@@ -448,12 +481,20 @@ class NordUser {
448
481
  const accountId = providedAccountId != null ? providedAccountId : this.accountIds?.[0];
449
482
  try {
450
483
  this.checkSessionValidity();
451
- const result = await (0, actions_1.cancelOrder)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
452
- sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
453
- senderId: accountId,
454
- orderId,
484
+ const receipt = await this.submitSessionAction({
485
+ case: "cancelOrderById",
486
+ value: (0, protobuf_1.create)(proto.Action_CancelOrderByIdSchema, {
487
+ orderId: BigInt(orderId),
488
+ sessionId: BigInt((0, utils_1.optExpect)(this.sessionId, "No session")),
489
+ senderAccountId: accountId,
490
+ }),
455
491
  });
456
- return result;
492
+ (0, actions_1.expectReceiptKind)(receipt, "cancelOrderResult", "cancel order");
493
+ return {
494
+ actionId: receipt.actionId,
495
+ orderId: receipt.kind.value.orderId,
496
+ accountId: receipt.kind.value.accountId,
497
+ };
457
498
  }
458
499
  catch (error) {
459
500
  throw new NordError_1.NordError(`Failed to cancel order ${orderId}`, {
@@ -475,17 +516,36 @@ class NordUser {
475
516
  if (!market) {
476
517
  throw new NordError_1.NordError(`Market with ID ${params.marketId} not found`);
477
518
  }
478
- const result = await (0, actions_1.addTrigger)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
479
- sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
480
- marketId: params.marketId,
481
- side: params.side,
482
- kind: params.kind,
483
- priceDecimals: market.priceDecimals,
484
- triggerPrice: params.triggerPrice,
485
- limitPrice: params.limitPrice,
486
- accountId: params.accountId,
519
+ const triggerPrice = (0, utils_1.toScaledU64)(params.triggerPrice, market.priceDecimals);
520
+ (0, utils_1.assert)(triggerPrice > 0n, "Trigger price must be positive");
521
+ const limitPrice = params.limitPrice === undefined
522
+ ? undefined
523
+ : (0, utils_1.toScaledU64)(params.limitPrice, market.priceDecimals);
524
+ if (limitPrice !== undefined) {
525
+ (0, utils_1.assert)(limitPrice > 0n, "Limit price must be positive");
526
+ }
527
+ const key = (0, protobuf_1.create)(proto.TriggerKeySchema, {
528
+ kind: params.kind === types_1.TriggerKind.StopLoss
529
+ ? proto.TriggerKind.STOP_LOSS
530
+ : proto.TriggerKind.TAKE_PROFIT,
531
+ side: params.side === types_1.Side.Bid ? proto.Side.BID : proto.Side.ASK,
487
532
  });
488
- return result;
533
+ const prices = (0, protobuf_1.create)(proto.Action_TriggerPricesSchema, {
534
+ triggerPrice,
535
+ limitPrice,
536
+ });
537
+ const receipt = await this.submitSessionAction({
538
+ case: "addTrigger",
539
+ value: (0, protobuf_1.create)(proto.Action_AddTriggerSchema, {
540
+ sessionId: BigInt((0, utils_1.optExpect)(this.sessionId, "No session")),
541
+ marketId: params.marketId,
542
+ key,
543
+ prices,
544
+ accountId: params.accountId,
545
+ }),
546
+ });
547
+ (0, actions_1.expectReceiptKind)(receipt, "triggerAdded", "add trigger");
548
+ return { actionId: receipt.actionId };
489
549
  }
490
550
  catch (error) {
491
551
  throw new NordError_1.NordError("Failed to add trigger", { cause: error });
@@ -505,58 +565,28 @@ class NordUser {
505
565
  if (!market) {
506
566
  throw new NordError_1.NordError(`Market with ID ${params.marketId} not found`);
507
567
  }
508
- const result = await (0, actions_1.removeTrigger)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
509
- sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
510
- marketId: params.marketId,
511
- side: params.side,
512
- kind: params.kind,
513
- accountId: params.accountId,
568
+ const key = (0, protobuf_1.create)(proto.TriggerKeySchema, {
569
+ kind: params.kind === types_1.TriggerKind.StopLoss
570
+ ? proto.TriggerKind.STOP_LOSS
571
+ : proto.TriggerKind.TAKE_PROFIT,
572
+ side: params.side === types_1.Side.Bid ? proto.Side.BID : proto.Side.ASK,
514
573
  });
515
- return result;
574
+ const receipt = await this.submitSessionAction({
575
+ case: "removeTrigger",
576
+ value: (0, protobuf_1.create)(proto.Action_RemoveTriggerSchema, {
577
+ sessionId: BigInt((0, utils_1.optExpect)(this.sessionId, "No session")),
578
+ marketId: params.marketId,
579
+ key,
580
+ accountId: params.accountId,
581
+ }),
582
+ });
583
+ (0, actions_1.expectReceiptKind)(receipt, "triggerRemoved", "remove trigger");
584
+ return { actionId: receipt.actionId };
516
585
  }
517
586
  catch (error) {
518
587
  throw new NordError_1.NordError("Failed to remove trigger", { cause: error });
519
588
  }
520
589
  }
521
- /**
522
- * Fetch active triggers for an account.
523
- *
524
- * @param params Optional parameters containing an explicit account id.
525
- * @throws {NordError} If no account can be resolved or the request fails.
526
- */
527
- async getAccountTriggers(params) {
528
- const accountId = params?.accountId ?? this.accountIds?.[0];
529
- if (accountId == null) {
530
- throw new NordError_1.NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting triggers.");
531
- }
532
- try {
533
- return await (0, triggers_1.getAccountTriggers)(this.nord.webServerUrl, accountId);
534
- }
535
- catch (error) {
536
- throw new NordError_1.NordError("Failed to fetch account triggers", { cause: error });
537
- }
538
- }
539
- /**
540
- * Fetch trigger history for an account.
541
- *
542
- * @param params Optional parameters with account id and history query filters.
543
- * @throws {NordError} If no account can be resolved or the request fails.
544
- */
545
- async getAccountTriggerHistory(params) {
546
- const { accountId: providedAccountId, ...query } = params;
547
- const accountId = providedAccountId ?? this.accountIds?.[0];
548
- if (accountId == null) {
549
- throw new NordError_1.NordError("Account ID is undefined. Make sure to call updateAccountId() before requesting trigger history.");
550
- }
551
- try {
552
- return await (0, triggers_1.getAccountTriggerHistory)(this.nord.webServerUrl, accountId, query);
553
- }
554
- catch (error) {
555
- throw new NordError_1.NordError("Failed to fetch account trigger history", {
556
- cause: error,
557
- });
558
- }
559
- }
560
590
  /**
561
591
  * Transfer tokens to another account
562
592
  *
@@ -567,14 +597,21 @@ class NordUser {
567
597
  try {
568
598
  this.checkSessionValidity();
569
599
  const token = (0, utils_1.findToken)(this.nord.tokens, params.tokenId);
570
- await (0, actions_1.transfer)(this.nord.webServerUrl, this.sessionSignFn, await this.nord.getTimestamp(), this.getNonce(), {
571
- sessionId: (0, utils_1.optExpect)(this.sessionId, "No session"),
572
- fromAccountId: (0, utils_1.optExpect)(params.fromAccountId, "No source account"),
573
- toAccountId: (0, utils_1.optExpect)(params.toAccountId, "No target account"),
574
- tokenId: params.tokenId,
575
- tokenDecimals: token.decimals,
576
- amount: params.amount,
600
+ const amount = (0, utils_1.toScaledU64)(params.amount, token.decimals);
601
+ if (amount <= 0n) {
602
+ throw new NordError_1.NordError("Transfer amount must be positive");
603
+ }
604
+ const receipt = await this.submitSessionAction({
605
+ case: "transfer",
606
+ value: (0, protobuf_1.create)(proto.Action_TransferSchema, {
607
+ sessionId: BigInt((0, utils_1.optExpect)(this.sessionId, "No session")),
608
+ fromAccountId: (0, utils_1.optExpect)(params.fromAccountId, "No source account"),
609
+ toAccountId: (0, utils_1.optExpect)(params.toAccountId, "No target account"),
610
+ tokenId: params.tokenId,
611
+ amount,
612
+ }),
577
613
  });
614
+ (0, actions_1.expectReceiptKind)(receipt, "transferred", "transfer tokens");
578
615
  }
579
616
  catch (error) {
580
617
  throw new NordError_1.NordError("Failed to transfer tokens", { cause: error });
@@ -740,13 +777,5 @@ class NordUser {
740
777
  });
741
778
  }
742
779
  }
743
- /**
744
- * Get the Solana public key derived from the address
745
- *
746
- * @returns The Solana public key
747
- */
748
- getSolanaPublicKey() {
749
- return this.address;
750
- }
751
780
  }
752
781
  exports.NordUser = NordUser;
@@ -1,5 +1,9 @@
1
1
  export { Nord } from "./client/Nord";
2
2
  export { NordUser } from "./client/NordUser";
3
+ export { NordAdmin } from "./client/NordAdmin";
4
+ export { NordClient } from "./client/NordClient";
5
+ export type { NordClientParams } from "./client/NordClient";
6
+ export type { CreateTokenParams, CreateMarketParams, PythSetWormholeGuardiansParams, PythSetSymbolFeedParams, FreezeMarketParams, UnfreezeMarketParams, } from "./client/NordAdmin";
3
7
  export { NordError } from "./utils/NordError";
4
8
  export * from "./api/core";
5
9
  export * from "./api/metrics";
@@ -14,12 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.NordError = exports.NordUser = exports.Nord = void 0;
17
+ exports.NordError = exports.NordClient = exports.NordAdmin = exports.NordUser = exports.Nord = void 0;
18
18
  // Export main client classes
19
19
  var Nord_1 = require("./client/Nord");
20
20
  Object.defineProperty(exports, "Nord", { enumerable: true, get: function () { return Nord_1.Nord; } });
21
21
  var NordUser_1 = require("./client/NordUser");
22
22
  Object.defineProperty(exports, "NordUser", { enumerable: true, get: function () { return NordUser_1.NordUser; } });
23
+ var NordAdmin_1 = require("./client/NordAdmin");
24
+ Object.defineProperty(exports, "NordAdmin", { enumerable: true, get: function () { return NordAdmin_1.NordAdmin; } });
25
+ var NordClient_1 = require("./client/NordClient");
26
+ Object.defineProperty(exports, "NordClient", { enumerable: true, get: function () { return NordClient_1.NordClient; } });
23
27
  // Export utility classes
24
28
  var NordError_1 = require("./utils/NordError");
25
29
  Object.defineProperty(exports, "NordError", { enumerable: true, get: function () { return NordError_1.NordError; } });
package/dist/types.d.ts CHANGED
@@ -33,8 +33,8 @@ export type SubscriptionPattern = `${SubscriptionType}@${string}` | string;
33
33
  export interface NordConfig {
34
34
  /** Base URL for the Nord web server */
35
35
  webServerUrl: string;
36
- /** Bridge verification key */
37
- bridgeVk: string;
36
+ /** App address */
37
+ app: string;
38
38
  /** Solana cluster URL */
39
39
  solanaUrl: string;
40
40
  /**
@@ -43,9 +43,9 @@ export interface NordConfig {
43
43
  */
44
44
  initWebSockets?: boolean;
45
45
  }
46
- export type Info = components["schemas"]["Info2"];
47
- export type Market = Info["markets"][number];
48
- export type Token = Info["tokens"][number];
46
+ export type MarketsInfo = components["schemas"]["MarketsInfo"];
47
+ export type Market = MarketsInfo["markets"][number];
48
+ export type Token = MarketsInfo["tokens"][number];
49
49
  export type Account = components["schemas"]["Account"];
50
50
  export type TradesResponse = components["schemas"]["PageResult_for_String_and_Trade"];
51
51
  export type User = components["schemas"]["User"];
@@ -75,6 +75,14 @@ export type FinalizationReason = components["schemas"]["FinalizationReason"];
75
75
  export type AccountPnlQuery = components["schemas"]["AccountPnlQuery"];
76
76
  export type AccountPnl = components["schemas"]["AccountPnl"];
77
77
  export type AccountPnlPage = components["schemas"]["PageResult_for_uint64_and_AccountPnl"];
78
+ export type AccountTriggerInfo = components["schemas"]["AccountTriggerInfo"];
79
+ export type TriggerHistoryPage = components["schemas"]["PageResult_for_uint64_and_HistoryTriggerInfo"];
80
+ export type HistoryTriggerQuery = components["schemas"]["AccountTriggersQuery"];
81
+ export type FeeTierConfig = components["schemas"]["FeeTierConfig"];
82
+ export type FeeTierId = components["schemas"]["FeeTierId"];
83
+ export type TokenStats = components["schemas"]["TokenStats"];
84
+ export type AccountFeeTier = components["schemas"]["AccountFeeTier"];
85
+ export type AccountFeeTierPage = components["schemas"]["PageResult_for_uint32_and_AccountFeeTier"];
78
86
  /**
79
87
  * Configuration options for the Nord client
80
88
  */
package/dist/utils.d.ts CHANGED
@@ -79,6 +79,7 @@ export declare const toScaledU128: (x: Decimal.Value, decimals: number) => bigin
79
79
  */
80
80
  export declare function decodeLengthDelimited<T extends Message>(bytes: Uint8Array, schema: GenMessage<T>): T;
81
81
  export declare function checkPubKeyLength(keyType: KeyType, len: number): void;
82
+ export declare function decodeHex(value: string): Uint8Array;
82
83
  export declare function findMarket(markets: Market[], marketId: number): Market;
83
84
  export declare function findToken(tokens: Token[], tokenId: number): Token;
84
85
  export declare function keypairFromPrivateKey(privateKey: string | Uint8Array): Keypair;
package/dist/utils.js CHANGED
@@ -13,6 +13,7 @@ exports.signAction = signAction;
13
13
  exports.makeWalletSignFn = makeWalletSignFn;
14
14
  exports.decodeLengthDelimited = decodeLengthDelimited;
15
15
  exports.checkPubKeyLength = checkPubKeyLength;
16
+ exports.decodeHex = decodeHex;
16
17
  exports.findMarket = findMarket;
17
18
  exports.findToken = findToken;
18
19
  exports.keypairFromPrivateKey = keypairFromPrivateKey;
@@ -195,6 +196,10 @@ function checkPubKeyLength(keyType, len) {
195
196
  throw new Error("Secp256k1 pubkeys must be 33 length.");
196
197
  }
197
198
  }
199
+ function decodeHex(value) {
200
+ const hex = value.startsWith("0x") ? value.slice(2) : value;
201
+ return Uint8Array.from(Buffer.from(hex, "hex"));
202
+ }
198
203
  function findMarket(markets, marketId) {
199
204
  if (marketId < 0 || markets.length - 1 < marketId) {
200
205
  throw new Error(`The market with marketId=${marketId} not found`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1xyz/nord-ts",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Typescript for Nord",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@bufbuild/protobuf": "^2.6.3",
48
- "@n1xyz/proton": "0.0.4",
48
+ "@n1xyz/proton": "0.0.6",
49
49
  "@noble/curves": "^1.9.6",
50
50
  "@noble/ed25519": "^2.3.0",
51
51
  "@noble/hashes": "^1.8.0",