@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.
- package/dist/actions.js +39 -82
- package/dist/bundle.js +79181 -0
- package/dist/client/Nord.d.ts +13 -2
- package/dist/client/Nord.js +68 -78
- package/dist/client/NordAdmin.d.ts +2 -2
- package/dist/client/NordAdmin.js +57 -89
- package/dist/client/NordUser.js +118 -147
- package/dist/const.js +5 -8
- package/dist/error.js +7 -5
- package/dist/gen/nord_pb.js +88 -92
- package/dist/gen/openapi.d.ts +83 -6
- package/dist/gen/openapi.js +1 -2
- package/dist/index.js +10 -49
- package/dist/types.d.ts +3 -0
- package/dist/types.js +21 -60
- package/dist/utils.js +38 -86
- package/dist/websocket/NordWebSocketClient.js +12 -17
- package/dist/websocket/Subscriber.js +6 -7
- package/dist/websocket/events.js +1 -2
- package/dist/websocket/index.js +10 -15
- package/package.json +3 -4
- package/dist/api/client.d.ts +0 -14
- package/dist/api/client.js +0 -45
- package/dist/bridge/client.d.ts +0 -151
- package/dist/bridge/client.js +0 -434
- package/dist/bridge/const.d.ts +0 -23
- package/dist/bridge/const.js +0 -47
- package/dist/bridge/index.d.ts +0 -4
- package/dist/bridge/index.js +0 -23
- package/dist/bridge/types.d.ts +0 -120
- package/dist/bridge/types.js +0 -18
- package/dist/bridge/utils.d.ts +0 -64
- package/dist/bridge/utils.js +0 -131
- package/dist/gen/common.d.ts +0 -68
- package/dist/gen/common.js +0 -215
- package/dist/gen/nord.d.ts +0 -882
- package/dist/gen/nord.js +0 -6520
- package/dist/idl/bridge.d.ts +0 -569
- package/dist/idl/bridge.js +0 -8
- package/dist/idl/bridge.json +0 -1506
- package/dist/idl/index.d.ts +0 -607
- package/dist/idl/index.js +0 -8
- package/dist/nord/api/actions.d.ts +0 -126
- package/dist/nord/api/actions.js +0 -397
- package/dist/nord/api/core.d.ts +0 -16
- package/dist/nord/api/core.js +0 -81
- package/dist/nord/api/market.d.ts +0 -36
- package/dist/nord/api/market.js +0 -96
- package/dist/nord/api/metrics.d.ts +0 -67
- package/dist/nord/api/metrics.js +0 -229
- package/dist/nord/api/queries.d.ts +0 -46
- package/dist/nord/api/queries.js +0 -109
- package/dist/nord/api/triggers.d.ts +0 -7
- package/dist/nord/api/triggers.js +0 -38
- package/dist/nord/client/Nord.d.ts +0 -396
- package/dist/nord/client/Nord.js +0 -747
- package/dist/nord/client/NordAdmin.d.ts +0 -259
- package/dist/nord/client/NordAdmin.js +0 -395
- package/dist/nord/client/NordClient.d.ts +0 -33
- package/dist/nord/client/NordClient.js +0 -45
- package/dist/nord/client/NordUser.d.ts +0 -362
- package/dist/nord/client/NordUser.js +0 -781
- package/dist/nord/index.d.ts +0 -11
- package/dist/nord/index.js +0 -36
- package/dist/nord/models/Subscriber.d.ts +0 -37
- package/dist/nord/models/Subscriber.js +0 -25
- package/dist/nord/utils/NordError.d.ts +0 -35
- package/dist/nord/utils/NordError.js +0 -49
- package/src/actions.ts +0 -333
- package/src/client/Nord.ts +0 -934
- package/src/client/NordAdmin.ts +0 -484
- package/src/client/NordUser.ts +0 -1122
- package/src/const.ts +0 -34
- package/src/error.ts +0 -76
- package/src/gen/.gitkeep +0 -0
- package/src/gen/nord_pb.ts +0 -5053
- package/src/gen/openapi.ts +0 -2904
- package/src/index.ts +0 -11
- package/src/types.ts +0 -327
- package/src/utils.ts +0 -266
- package/src/websocket/NordWebSocketClient.ts +0 -316
- package/src/websocket/Subscriber.ts +0 -56
- package/src/websocket/events.ts +0 -31
- package/src/websocket/index.ts +0 -105
package/dist/websocket/index.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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",
|
package/dist/api/client.d.ts
DELETED
|
@@ -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>;
|
package/dist/api/client.js
DELETED
|
@@ -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
|
-
}
|
package/dist/bridge/client.d.ts
DELETED
|
@@ -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
|
-
}
|