@n1xyz/nord-ts 0.1.7 → 0.1.9

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 +13 -2
  4. package/dist/client/Nord.js +68 -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 +83 -6
  12. package/dist/gen/openapi.js +1 -2
  13. package/dist/index.js +10 -49
  14. package/dist/types.d.ts +3 -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 +3 -4
  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
@@ -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.9",
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",
@@ -45,7 +44,7 @@
45
44
  },
46
45
  "dependencies": {
47
46
  "@bufbuild/protobuf": "^2.6.3",
48
- "@n1xyz/proton": "0.0.6",
47
+ "@n1xyz/proton": "0.0.7",
49
48
  "@noble/curves": "^1.9.6",
50
49
  "@noble/ed25519": "^2.3.0",
51
50
  "@noble/hashes": "^1.8.0",
@@ -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>;
@@ -1,45 +0,0 @@
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.createApiClient = createApiClient;
7
- exports.handleApiResponse = handleApiResponse;
8
- const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
- const NordError_1 = require("../nord/utils/NordError");
10
- function createApiClient(config) {
11
- const client = (0, openapi_fetch_1.default)({
12
- baseUrl: config.baseUrl,
13
- });
14
- client.use({
15
- onResponse({ response }) {
16
- if (!response.ok) {
17
- throw new NordError_1.NordError(`HTTP ${response.status}: ${response.statusText}`, {
18
- statusCode: response.status,
19
- details: { url: response.url }
20
- });
21
- }
22
- return response;
23
- },
24
- });
25
- return client;
26
- }
27
- async function handleApiResponse(response) {
28
- const result = await response;
29
- if (result.error || !result.response.ok) {
30
- const errorMessage = result.error
31
- ? `HTTP ${result.response.status}: ${result.response.statusText}`
32
- : `Request failed: ${result.response.statusText}`;
33
- throw new NordError_1.NordError(errorMessage, {
34
- statusCode: result.response.status,
35
- details: { url: result.response.url }
36
- });
37
- }
38
- if (!('data' in result)) {
39
- throw new NordError_1.NordError("No data in response", {
40
- statusCode: 500,
41
- details: { url: result.response.url }
42
- });
43
- }
44
- return result.data;
45
- }
@@ -1,151 +0,0 @@
1
- import * as anchor from "@coral-xyz/anchor";
2
- import { AnchorProvider } from "@coral-xyz/anchor";
3
- import { Connection, Keypair, PublicKey } from "@solana/web3.js";
4
- import { BlockFacts, DepositSplParams, PdaSeedType, SolanaBridgeConfig, WithdrawalParams } from "./types";
5
- /**
6
- * Solana Bridge Client for interacting with the bridge program
7
- */
8
- export declare class SolanaBridgeClient {
9
- /** Anchor program instance */
10
- program: any;
11
- /** Solana connection */
12
- connection: Connection;
13
- /** Program ID */
14
- programId: PublicKey;
15
- /** Configuration */
16
- config: SolanaBridgeConfig;
17
- /** Anchor provider */
18
- provider: AnchorProvider;
19
- bridge: PublicKey;
20
- /**
21
- * Create a new Solana Bridge Client
22
- *
23
- * @param config Bridge configuration
24
- * @param wallet Anchor wallet for signing transactions
25
- */
26
- constructor(config: SolanaBridgeConfig, wallet: anchor.Wallet);
27
- /**
28
- * Derive a PDA (Program Derived Address) for the given seeds
29
- *
30
- * Seeds can be of type:
31
- * - Buffer: raw bytes
32
- * - PublicKey: Solana public key
33
- * - string: string encoded as UTF-8 bytes
34
- * - number: u64 encoded as little-endian 8 bytes
35
- *
36
- * @param type PDA seed type
37
- * @param seeds Additional seeds
38
- * @returns [PDA, bump]
39
- */
40
- findPda(type: PdaSeedType, ...seeds: any[]): Promise<[PublicKey, number]>;
41
- /**
42
- * Find the asset config PDA for a token mint
43
- *
44
- * @param mint Token mint address
45
- * @returns [PDA, bump]
46
- */
47
- findAssetConfigPda(mint: PublicKey): Promise<[PublicKey, number]>;
48
- /**
49
- * Find the deposit storage PDA for a deposit index
50
- *
51
- * @param depositIndex Deposit index
52
- * @returns [PDA, bump]
53
- */
54
- findDepositStoragePda(depositIndex: number): Promise<[PublicKey, number]>;
55
- /**
56
- * Find the block storage PDA for a block ID
57
- *
58
- * @param blockId Block ID
59
- * @returns [PDA, bump]
60
- */
61
- findBlockStoragePda(blockId: number): Promise<[PublicKey, number]>;
62
- /**
63
- * Find the withdrawal nullifier PDA
64
- *
65
- * @param blockId Block ID
66
- * @param leafIndex Leaf index
67
- * @returns [PDA, bump]
68
- */
69
- findWithdrawalNullifierPda(blockId: number, leafIndex: number): Promise<[PublicKey, number]>;
70
- /**
71
- * Find the authority PDA
72
- *
73
- * @returns [PDA, bump]
74
- */
75
- findAuthorityPda(): Promise<[PublicKey, number]>;
76
- /**
77
- * Helper method to sign and send a transaction
78
- *
79
- * @param transaction Transaction to sign and send
80
- * @param signers Additional signers (beyond the provider's wallet)
81
- * @returns Transaction signature
82
- */
83
- private signAndSendTransaction;
84
- /**
85
- * Deposit SPL tokens to the bridge
86
- *
87
- * @param params Deposit parameters
88
- * @param signer Signer keypair
89
- * @returns Transaction signature
90
- */
91
- depositSpl(params: DepositSplParams): Promise<string>;
92
- /**
93
- * Withdraw tokens from the bridge
94
- *
95
- * @param params Withdrawal parameters
96
- * @param signer Signer keypair
97
- * @returns Transaction signature
98
- */
99
- withdraw(params: WithdrawalParams, signer: Keypair): Promise<string>;
100
- /**
101
- * Whitelist an asset (token) for use with the bridge
102
- *
103
- * @param mint Token mint address
104
- * @param signer Operator keypair
105
- * @returns Transaction signature
106
- */
107
- whitelistAsset(mint: PublicKey, signer: Keypair): Promise<string>;
108
- /**
109
- * Propose a new block
110
- *
111
- * @param facts Block facts
112
- * @param signer Operator keypair
113
- * @returns Transaction signature
114
- */
115
- proposeBlock(facts: BlockFacts, signer: Keypair): Promise<string>;
116
- /**
117
- * Finalize a block
118
- *
119
- * @param blockId Block ID
120
- * @param stateUpdateId State update ID
121
- * @param signer Payer keypair
122
- * @returns Transaction signature
123
- */
124
- finalizeBlock(blockId: number, stateUpdateId: number, signer: Keypair): Promise<string>;
125
- /**
126
- * Finalize a DA fact
127
- *
128
- * @param fact DA fact (32-byte array)
129
- * @param signer Payer keypair
130
- * @returns Transaction signature
131
- */
132
- finalizeDaFact(fact: Buffer, signer: Keypair): Promise<string>;
133
- /**
134
- * Initialize the bridge contract
135
- *
136
- * @param operator Operator public key
137
- * @param initialAppStateCommitment Initial app state commitment (32-byte array)
138
- * @param signer Payer keypair
139
- * @returns Transaction signature
140
- */
141
- initialize(operator: PublicKey, initialAppStateCommitment: Buffer, signer: Keypair): Promise<string>;
142
- /**
143
- * Create an associated token account if it doesn't exist
144
- *
145
- * @param mint Token mint
146
- * @param owner Account owner
147
- * @param payer Transaction payer
148
- * @returns Associated token account address
149
- */
150
- createTokenAccountIfNeeded(mint: PublicKey, owner: PublicKey, payer: Keypair): Promise<PublicKey>;
151
- }