@n1xyz/nord-ts 0.1.6 → 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 (85) hide show
  1. package/dist/actions.d.ts +57 -0
  2. package/dist/actions.js +186 -0
  3. package/dist/bundle.js +79181 -0
  4. package/dist/{nord/client → client}/Nord.d.ts +90 -107
  5. package/dist/{nord/client → client}/Nord.js +157 -218
  6. package/dist/{nord/client → client}/NordAdmin.d.ts +68 -102
  7. package/dist/{nord/client → client}/NordAdmin.js +109 -140
  8. package/dist/{nord/client → client}/NordUser.d.ts +86 -98
  9. package/dist/{nord/client → client}/NordUser.js +204 -271
  10. package/dist/const.js +5 -8
  11. package/dist/{nord/utils/NordError.js → error.js} +7 -5
  12. package/dist/gen/nord_pb.js +88 -92
  13. package/dist/gen/openapi.d.ts +39 -0
  14. package/dist/gen/openapi.js +1 -2
  15. package/dist/index.d.ts +6 -1
  16. package/dist/index.js +10 -21
  17. package/dist/types.d.ts +5 -50
  18. package/dist/types.js +21 -83
  19. package/dist/utils.d.ts +8 -11
  20. package/dist/utils.js +55 -90
  21. package/dist/websocket/NordWebSocketClient.js +12 -17
  22. package/dist/{nord/models → websocket}/Subscriber.d.ts +1 -1
  23. package/dist/{nord/models → websocket}/Subscriber.js +6 -7
  24. package/dist/websocket/events.js +1 -2
  25. package/dist/websocket/index.d.ts +19 -2
  26. package/dist/websocket/index.js +80 -5
  27. package/package.json +2 -3
  28. package/dist/api/client.d.ts +0 -14
  29. package/dist/api/client.js +0 -45
  30. package/dist/bridge/client.d.ts +0 -151
  31. package/dist/bridge/client.js +0 -434
  32. package/dist/bridge/const.d.ts +0 -23
  33. package/dist/bridge/const.js +0 -47
  34. package/dist/bridge/index.d.ts +0 -4
  35. package/dist/bridge/index.js +0 -23
  36. package/dist/bridge/types.d.ts +0 -120
  37. package/dist/bridge/types.js +0 -18
  38. package/dist/bridge/utils.d.ts +0 -64
  39. package/dist/bridge/utils.js +0 -131
  40. package/dist/gen/common.d.ts +0 -68
  41. package/dist/gen/common.js +0 -215
  42. package/dist/gen/nord.d.ts +0 -882
  43. package/dist/gen/nord.js +0 -6520
  44. package/dist/idl/bridge.d.ts +0 -569
  45. package/dist/idl/bridge.js +0 -8
  46. package/dist/idl/bridge.json +0 -1506
  47. package/dist/idl/index.d.ts +0 -607
  48. package/dist/idl/index.js +0 -8
  49. package/dist/nord/api/actions.d.ts +0 -126
  50. package/dist/nord/api/actions.js +0 -397
  51. package/dist/nord/api/core.d.ts +0 -16
  52. package/dist/nord/api/core.js +0 -81
  53. package/dist/nord/api/market.d.ts +0 -36
  54. package/dist/nord/api/market.js +0 -96
  55. package/dist/nord/api/metrics.d.ts +0 -67
  56. package/dist/nord/api/metrics.js +0 -229
  57. package/dist/nord/api/queries.d.ts +0 -46
  58. package/dist/nord/api/queries.js +0 -109
  59. package/dist/nord/api/triggers.d.ts +0 -7
  60. package/dist/nord/api/triggers.js +0 -38
  61. package/dist/nord/client/NordClient.d.ts +0 -33
  62. package/dist/nord/client/NordClient.js +0 -45
  63. package/dist/nord/index.d.ts +0 -11
  64. package/dist/nord/index.js +0 -36
  65. package/src/const.ts +0 -34
  66. package/src/gen/.gitkeep +0 -0
  67. package/src/gen/nord_pb.ts +0 -5053
  68. package/src/gen/openapi.ts +0 -2864
  69. package/src/index.ts +0 -5
  70. package/src/nord/api/actions.ts +0 -648
  71. package/src/nord/api/core.ts +0 -96
  72. package/src/nord/api/metrics.ts +0 -269
  73. package/src/nord/client/Nord.ts +0 -937
  74. package/src/nord/client/NordAdmin.ts +0 -514
  75. package/src/nord/client/NordClient.ts +0 -79
  76. package/src/nord/client/NordUser.ts +0 -1211
  77. package/src/nord/index.ts +0 -25
  78. package/src/nord/models/Subscriber.ts +0 -56
  79. package/src/nord/utils/NordError.ts +0 -76
  80. package/src/types.ts +0 -377
  81. package/src/utils.ts +0 -269
  82. package/src/websocket/NordWebSocketClient.ts +0 -316
  83. package/src/websocket/events.ts +0 -31
  84. package/src/websocket/index.ts +0 -2
  85. /package/dist/{nord/utils/NordError.d.ts → error.d.ts} +0 -0
@@ -1,514 +0,0 @@
1
- import { create } from "@bufbuild/protobuf";
2
- import { PublicKey } from "@solana/web3.js";
3
- import * as proto from "../../gen/nord_pb";
4
- import { decodeHex } from "../../utils";
5
- import { createAction, sendAction, expectReceiptKind } from "../api/actions";
6
- import { NordError } from "../utils/NordError";
7
- import { Nord } from "./Nord";
8
- import { FeeTierConfig } from "../../gen/nord_pb";
9
-
10
- // NOTE: keep in sync with `acl.rs`.
11
- // NOTE: don't forget `number` as int is internally a u32.
12
- export enum AclRole {
13
- FEE_MANAGER = 1 << 0,
14
- MARKET_MANAGER = 1 << 1,
15
- // TODO: unsure about this?
16
- ADMIN = 1 << 31,
17
- }
18
-
19
- /**
20
- * Parameters required to register a new token via the admin API.
21
- */
22
- export interface CreateTokenParams {
23
- tokenDecimals: number;
24
- weightBps: number;
25
- viewSymbol: string;
26
- oracleSymbol: string;
27
- mintAddr: PublicKey;
28
- }
29
-
30
- /**
31
- * Parameters used when creating a new market.
32
- */
33
- export interface CreateMarketParams {
34
- sizeDecimals: number;
35
- priceDecimals: number;
36
- imfBps: number;
37
- cmfBps: number;
38
- mmfBps: number;
39
- marketType: proto.MarketType;
40
- viewSymbol: string;
41
- oracleSymbol: string;
42
- baseTokenId: number;
43
- }
44
-
45
- /**
46
- * Configuration for updating the Wormhole guardian set on the oracle.
47
- */
48
- export interface PythSetWormholeGuardiansParams {
49
- guardianSetIndex: number;
50
- addresses: string[];
51
- }
52
-
53
- /**
54
- * Parameters required to link an oracle symbol to a Pyth price feed.
55
- */
56
- export interface PythSetSymbolFeedParams {
57
- oracleSymbol: string;
58
- priceFeedId: string;
59
- }
60
-
61
- /**
62
- * Identifies a market that should be frozen.
63
- */
64
- export interface FreezeMarketParams {
65
- marketId: number;
66
- }
67
-
68
- /**
69
- * Identifies a market that should be unfrozen.
70
- */
71
- export interface UnfreezeMarketParams {
72
- marketId: number;
73
- }
74
-
75
- /**
76
- * Parameters for adding a new fee tier.
77
- */
78
- export interface AddFeeTierParams {
79
- config: FeeTierConfig;
80
- }
81
-
82
- /**
83
- * Parameters for updating an existing fee tier.
84
- */
85
- export interface UpdateFeeTierParams {
86
- tierId: number;
87
- config: FeeTierConfig;
88
- }
89
-
90
- /**
91
- * Administrative client capable of submitting privileged configuration actions.
92
- */
93
- export class NordAdmin {
94
- private readonly nord: Nord;
95
- private readonly admin: PublicKey;
96
- private readonly signFn: (x: Uint8Array) => Promise<Uint8Array>;
97
-
98
- private constructor({
99
- nord,
100
- admin,
101
- signFn,
102
- }: {
103
- nord: Nord;
104
- admin: PublicKey;
105
- signFn: (x: Uint8Array) => Promise<Uint8Array>;
106
- }) {
107
- this.nord = nord;
108
- this.admin = admin;
109
- this.signFn = signFn;
110
- }
111
-
112
- /** Create a new admin client.
113
- *
114
- * @param nord - Nord instance
115
- * @param admin - The user that will be signing actions.
116
- * @param signFn - Function to sign messages with the admin's wallet.
117
- *
118
- * `signFn` must sign the _hex-encoded_ message, not the raw message itself, for
119
- * the purpose of being compatible with Solana wallets.
120
- *
121
- * In practice, you will do something along the lines of:
122
- *
123
- * ```typescript
124
- * (x) => wallet.signMessage(new TextEncoder().encode(x.toHex()));
125
- * ```
126
- *
127
- * For a software signing key, this might look more like:
128
- *
129
- * ```typescript
130
- * (x) => nacl.sign.detached(new TextEncoder().encode(x.toHex()), sk);
131
- * ``
132
- *
133
- * where `nacl` is the tweetnacl library.
134
- */
135
- public static new({
136
- nord,
137
- admin,
138
- signFn,
139
- }: Readonly<{
140
- nord: Nord;
141
- admin: PublicKey;
142
- signFn: (m: Uint8Array) => Promise<Uint8Array>;
143
- }>): NordAdmin {
144
- return new NordAdmin({
145
- nord,
146
- admin,
147
- signFn,
148
- });
149
- }
150
-
151
- /**
152
- * Submit an action and append the admin signature before sending it to Nord.
153
- *
154
- * @param kind - Action payload describing the admin request
155
- * @throws {NordError} If signing or submission fails
156
- */
157
- private async submitAction(
158
- kind: proto.Action["kind"],
159
- ): Promise<proto.Receipt> {
160
- const timestamp = await this.nord.getTimestamp();
161
- const action = createAction(timestamp, 0, kind);
162
- return sendAction(
163
- this.nord.webServerUrl,
164
- async (xs: Uint8Array) => {
165
- const signature = await this.signFn(xs);
166
- if (signature.length !== 64) {
167
- throw new NordError("invalid signature length; must be 64 bytes");
168
- }
169
- return Uint8Array.from([...xs, ...signature]);
170
- },
171
- action,
172
- );
173
- }
174
-
175
- /** Set acl permissions for a given user.
176
- *
177
- * If all roles are removed, the user is removed from the acl.
178
- *
179
- * @param target - User to update.
180
- * @param addRoles - Roles to add to the user.
181
- * @param removeRoles - Reles to remove from the user.
182
- */
183
- async updateAcl({
184
- target,
185
- addRoles,
186
- removeRoles,
187
- }: Readonly<{
188
- target: PublicKey;
189
- addRoles: AclRole[];
190
- removeRoles: AclRole[];
191
- }>): Promise<{ actionId: bigint } & proto.Receipt_AclUpdated> {
192
- const allRoles = addRoles.concat(removeRoles);
193
- if (allRoles.length !== new Set(allRoles).size) {
194
- throw new NordError("duplicate roles in acl update; must be unique");
195
- }
196
-
197
- let mask = 0;
198
- let values = 0;
199
- for (const role of allRoles) {
200
- mask |= role;
201
- }
202
- for (const role of addRoles) {
203
- values |= role;
204
- }
205
-
206
- const receipt = await this.submitAction({
207
- case: "updateAcl",
208
- value: create(proto.Action_UpdateAclSchema, {
209
- aclPubkey: this.admin.toBytes(),
210
- targetPubkey: target.toBytes(),
211
- }),
212
- });
213
- expectReceiptKind(receipt, "aclUpdated", "update acl");
214
-
215
- return { ...receipt.kind.value, actionId: receipt.actionId };
216
- }
217
-
218
- /**
219
- * Register a new token that can be listed on Nord.
220
- *
221
- * @param params - Token configuration values
222
- * @returns Action identifier and resulting token metadata
223
- * @throws {NordError} If the action submission fails
224
- */
225
- async createToken({
226
- tokenDecimals,
227
- weightBps,
228
- viewSymbol,
229
- oracleSymbol,
230
- mintAddr,
231
- }: CreateTokenParams): Promise<
232
- { actionId: bigint } & proto.Receipt_InsertTokenResult
233
- > {
234
- const receipt = await this.submitAction({
235
- case: "createToken",
236
- value: create(proto.Action_CreateTokenSchema, {
237
- aclPubkey: this.admin.toBytes(),
238
- tokenDecimals,
239
- weightBps,
240
- viewSymbol,
241
- oracleSymbol,
242
- solAddr: mintAddr.toBytes(),
243
- }),
244
- });
245
- expectReceiptKind(receipt, "insertTokenResult", "create token");
246
- return { actionId: receipt.actionId, ...receipt.kind.value };
247
- }
248
-
249
- /**
250
- * Open a new market with the provided trading parameters.
251
- *
252
- * @param params - Market configuration to apply
253
- * @returns Action identifier and resulting market metadata
254
- * @throws {NordError} If the action submission fails
255
- */
256
- async createMarket(
257
- params: CreateMarketParams,
258
- ): Promise<{ actionId: bigint } & proto.Receipt_InsertMarketResult> {
259
- const receipt = await this.submitAction({
260
- case: "createMarket",
261
- value: create(proto.Action_CreateMarketSchema, {
262
- aclPubkey: this.admin.toBytes(),
263
- sizeDecimals: params.sizeDecimals,
264
- priceDecimals: params.priceDecimals,
265
- imfBps: params.imfBps,
266
- cmfBps: params.cmfBps,
267
- mmfBps: params.mmfBps,
268
- marketType: params.marketType,
269
- viewSymbol: params.viewSymbol,
270
- oracleSymbol: params.oracleSymbol,
271
- baseTokenId: params.baseTokenId,
272
- }),
273
- });
274
- expectReceiptKind(receipt, "insertMarketResult", "create market");
275
- return { actionId: receipt.actionId, ...receipt.kind.value };
276
- }
277
-
278
- /**
279
- * Update the Pyth guardian set used for verifying Wormhole messages.
280
- *
281
- * Each address must decode from a 20-byte hex string (with or without a
282
- * leading `0x` prefix). The engine validates the supplied guardian set index
283
- * before applying the update.
284
- *
285
- * @param params - Guardian set index and guardian addresses
286
- * @returns Action identifier and guardian update receipt
287
- * @throws {NordError} If the action submission fails
288
- */
289
- async pythSetWormholeGuardians(
290
- params: PythSetWormholeGuardiansParams,
291
- ): Promise<{ actionId: bigint } & proto.Receipt_UpdateGuardianSetResult> {
292
- const addresses = params.addresses.map((address) => {
293
- try {
294
- const decoded = decodeHex(address);
295
- if (decoded.length !== 20) {
296
- throw new Error("guardian address must be 20 bytes");
297
- }
298
- return decoded;
299
- } catch (e) {
300
- throw new NordError(
301
- "invalid guardian address; must be a 20 byte hex address",
302
- { cause: e },
303
- );
304
- }
305
- });
306
-
307
- const receipt = await this.submitAction({
308
- case: "pythSetWormholeGuardians",
309
- value: create(proto.Action_PythSetWormholeGuardiansSchema, {
310
- aclPubkey: this.admin.toBytes(),
311
- guardianSetIndex: params.guardianSetIndex,
312
- addresses,
313
- }),
314
- });
315
- expectReceiptKind(
316
- receipt,
317
- "updateGuardianSetResult",
318
- "update wormhole guardians",
319
- );
320
- return { actionId: receipt.actionId, ...receipt.kind.value };
321
- }
322
-
323
- /**
324
- * Link an oracle symbol to a specific Pyth price feed.
325
- *
326
- * The price feed identifier must decode to 32 bytes (with or without a
327
- * leading `0x` prefix). Use this call to create or update the mapping used
328
- * by the oracle integration.
329
- *
330
- * @param params - Oracle symbol and price feed identifier
331
- * @returns Action identifier and symbol feed receipt
332
- * @throws {NordError} If the action submission fails
333
- */
334
- async pythSetSymbolFeed(
335
- params: PythSetSymbolFeedParams,
336
- ): Promise<{ actionId: bigint } & proto.Receipt_OracleSymbolFeedResult> {
337
- let priceFeedId: Uint8Array;
338
- try {
339
- priceFeedId = decodeHex(params.priceFeedId);
340
- if (priceFeedId.length !== 32) {
341
- throw new Error("price feed id must be 32 bytes");
342
- }
343
- } catch (e) {
344
- throw new NordError("invalid price feed id; must be a 32 byte hex id", {
345
- cause: e,
346
- });
347
- }
348
-
349
- const receipt = await this.submitAction({
350
- case: "pythSetSymbolFeed",
351
- value: create(proto.Action_PythSetSymbolFeedSchema, {
352
- aclPubkey: this.admin.toBytes(),
353
- oracleSymbol: params.oracleSymbol,
354
- priceFeedId,
355
- }),
356
- });
357
- expectReceiptKind(receipt, "oracleSymbolFeedResult", "set symbol feed");
358
- return { actionId: receipt.actionId, ...receipt.kind.value };
359
- }
360
-
361
- /**
362
- * Pause all trading activity on the exchange.
363
- *
364
- * @returns Action identifier confirming the pause
365
- * @throws {NordError} If the action submission fails
366
- */
367
- async pause(): Promise<{ actionId: bigint }> {
368
- const receipt = await this.submitAction({
369
- case: "pause",
370
- value: create(proto.Action_PauseSchema, {
371
- aclPubkey: this.admin.toBytes(),
372
- }),
373
- });
374
- expectReceiptKind(receipt, "paused", "pause");
375
- return { actionId: receipt.actionId };
376
- }
377
-
378
- /**
379
- * Resume trading activity after a pause.
380
- *
381
- * @returns Action identifier confirming the unpause
382
- * @throws {NordError} If the action submission fails
383
- */
384
- async unpause(): Promise<{ actionId: bigint }> {
385
- const receipt = await this.submitAction({
386
- case: "unpause",
387
- value: create(proto.Action_UnpauseSchema, {
388
- aclPubkey: this.admin.toBytes(),
389
- }),
390
- });
391
- expectReceiptKind(receipt, "unpaused", "unpause");
392
- return { actionId: receipt.actionId };
393
- }
394
-
395
- /**
396
- * Freeze an individual market, preventing new trades and orders.
397
- *
398
- * @param params - Target market identifier
399
- * @returns Action identifier and freeze receipt
400
- * @throws {NordError} If the action submission fails
401
- */
402
- async freezeMarket(
403
- params: FreezeMarketParams,
404
- ): Promise<{ actionId: bigint } & proto.Receipt_MarketFreezeUpdated> {
405
- const receipt = await this.submitAction({
406
- case: "freezeMarket",
407
- value: create(proto.Action_FreezeMarketSchema, {
408
- marketId: params.marketId,
409
- aclPubkey: this.admin.toBytes(),
410
- }),
411
- });
412
- expectReceiptKind(receipt, "marketFreezeUpdated", "freeze market");
413
- return { actionId: receipt.actionId, ...receipt.kind.value };
414
- }
415
-
416
- /**
417
- * Unfreeze a market that was previously halted.
418
- *
419
- * @param params - Target market identifier
420
- * @returns Action identifier and freeze receipt
421
- * @throws {NordError} If the action submission fails
422
- */
423
- async unfreezeMarket(
424
- params: UnfreezeMarketParams,
425
- ): Promise<{ actionId: bigint } & proto.Receipt_MarketFreezeUpdated> {
426
- const receipt = await this.submitAction({
427
- case: "unfreezeMarket",
428
- value: create(proto.Action_UnfreezeMarketSchema, {
429
- marketId: params.marketId,
430
- aclPubkey: this.admin.toBytes(),
431
- }),
432
- });
433
- expectReceiptKind(receipt, "marketFreezeUpdated", "unfreeze market");
434
- return { actionId: receipt.actionId, ...receipt.kind.value };
435
- }
436
-
437
- /**
438
- * Append a new fee tier to the account bracket configuration.
439
- *
440
- * - The engine supports at most 16 tiers (ids 0–15). Tier 0 is reserved for
441
- * the default Nord fees; use `updateFeeTier` if you need to change it.
442
- * - The first appended tier receives id 1, and subsequent tiers increment the id.
443
- *
444
- * @param params - Fee tier configuration to insert
445
- * @returns Action identifier and fee tier addition receipt
446
- * @throws {NordError} If the action submission fails or the new tier exceeds the maximum range (0-15).
447
- */
448
- async addFeeTier(
449
- params: AddFeeTierParams,
450
- ): Promise<{ actionId: bigint } & proto.Receipt_FeeTierAdded> {
451
- const receipt = await this.submitAction({
452
- case: "addFeeTier",
453
- value: create(proto.Action_AddFeeTierSchema, {
454
- aclPubkey: this.admin.toBytes(),
455
- config: create(proto.FeeTierConfigSchema, params.config),
456
- }),
457
- });
458
- expectReceiptKind(receipt, "feeTierAdded", "add fee tier");
459
- return { actionId: receipt.actionId, ...receipt.kind.value };
460
- }
461
-
462
- /**
463
- * Update an existing fee tier with new maker/taker rates.
464
- *
465
- * Tier identifiers must already exist; attempting to update a missing tier
466
- * causes the action to fail.
467
- *
468
- * @param params - Fee tier identifier and updated configuration
469
- * @returns Action identifier and fee tier update receipt
470
- * @throws {NordError} If the action submission fails or the tier ID exceeds the configured range.
471
- */
472
- async updateFeeTier(
473
- params: UpdateFeeTierParams,
474
- ): Promise<{ actionId: bigint } & proto.Receipt_FeeTierUpdated> {
475
- const receipt = await this.submitAction({
476
- case: "updateFeeTier",
477
- value: create(proto.Action_UpdateFeeTierSchema, {
478
- aclPubkey: this.admin.toBytes(),
479
- id: params.tierId,
480
- config: create(proto.FeeTierConfigSchema, params.config),
481
- }),
482
- });
483
- expectReceiptKind(receipt, "feeTierUpdated", "update fee tier");
484
- return { actionId: receipt.actionId, ...receipt.kind.value };
485
- }
486
-
487
- /**
488
- * Assign a fee tier to one or more accounts.
489
- *
490
- * The tier id must be within the configured range (0–15). Every account starts
491
- * on tier 0; assigning it to another tier requires that tier to exist already.
492
- * Invalid account ids or tier ids cause the action to fail.
493
- *
494
- * @param accounts - Account IDs to update
495
- * @param tierId - Target fee tier identifier
496
- * @returns Action identifier and accounts-tier receipt
497
- * @throws {NordError} If the tier id exceeds the configured range or an account id is invalid.
498
- */
499
- async updateAccountsTier(
500
- accounts: number[],
501
- tierId: number,
502
- ): Promise<{ actionId: bigint } & proto.Receipt_AccountsTierUpdated> {
503
- const receipt = await this.submitAction({
504
- case: "updateAccountsTier",
505
- value: create(proto.Action_UpdateAccountsTierSchema, {
506
- aclPubkey: this.admin.toBytes(),
507
- accounts,
508
- tierId,
509
- }),
510
- });
511
- expectReceiptKind(receipt, "accountsTierUpdated", "update accounts tier");
512
- return { actionId: receipt.actionId, ...receipt.kind.value };
513
- }
514
- }
@@ -1,79 +0,0 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
2
- import type { Transaction } from "@solana/web3.js";
3
- import * as proto from "../../gen/nord_pb";
4
- import { createAction, sendAction } from "../api/actions";
5
- import { Nord } from "./Nord";
6
-
7
- export interface NordClientParams {
8
- nord: Nord;
9
- address: PublicKey;
10
- walletSignFn: (message: Uint8Array | string) => Promise<Uint8Array>;
11
- sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
12
- transactionSignFn: <T extends Transaction>(tx: T) => Promise<T>;
13
- connection?: Connection;
14
- sessionId?: bigint;
15
- sessionPubKey: Uint8Array;
16
- publicKey: PublicKey;
17
- }
18
-
19
- export abstract class NordClient {
20
- public readonly nord: Nord;
21
- public readonly address: PublicKey;
22
- public readonly walletSignFn: (
23
- message: Uint8Array | string,
24
- ) => Promise<Uint8Array>;
25
- public readonly sessionSignFn: (message: Uint8Array) => Promise<Uint8Array>;
26
- public readonly transactionSignFn: <T extends Transaction>(
27
- tx: T,
28
- ) => Promise<T>;
29
- public connection: Connection;
30
- public sessionId?: bigint;
31
- public sessionPubKey: Uint8Array;
32
- public publicKey: PublicKey;
33
- public lastTs = 0;
34
-
35
- protected actionNonce = 0;
36
-
37
- protected constructor(params: NordClientParams) {
38
- this.nord = params.nord;
39
- this.address = params.address;
40
- this.walletSignFn = params.walletSignFn;
41
- this.sessionSignFn = params.sessionSignFn;
42
- this.transactionSignFn = params.transactionSignFn;
43
- this.connection =
44
- params.connection ??
45
- new Connection(params.nord.solanaUrl, {
46
- commitment: "confirmed",
47
- });
48
- this.sessionId = params.sessionId;
49
- this.sessionPubKey = new Uint8Array(params.sessionPubKey);
50
- this.publicKey = params.publicKey;
51
- }
52
-
53
- protected async submitSignedAction(
54
- kind: proto.Action["kind"],
55
- makeSignedMessage: (message: Uint8Array) => Promise<Uint8Array>,
56
- ): Promise<proto.Receipt> {
57
- const nonce = this.nextActionNonce();
58
- const currentTimestamp = await this.nord.getTimestamp();
59
- const action = createAction(currentTimestamp, nonce, kind);
60
- return sendAction(this.nord.webServerUrl, makeSignedMessage, action);
61
- }
62
-
63
- protected nextActionNonce(): number {
64
- return ++this.actionNonce;
65
- }
66
-
67
- protected cloneClientState(target: NordClient): void {
68
- target.connection = this.connection;
69
- target.sessionId = this.sessionId;
70
- target.sessionPubKey = new Uint8Array(this.sessionPubKey);
71
- target.publicKey = this.publicKey;
72
- target.lastTs = this.lastTs;
73
- target.actionNonce = this.actionNonce;
74
- }
75
-
76
- getSolanaPublicKey(): PublicKey {
77
- return this.address;
78
- }
79
- }