@sequence0/sdk 0.1.0
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/README.md +154 -0
- package/dist/chains/bitcoin.d.ts +44 -0
- package/dist/chains/bitcoin.d.ts.map +1 -0
- package/dist/chains/bitcoin.js +152 -0
- package/dist/chains/bitcoin.js.map +1 -0
- package/dist/chains/ethereum.d.ts +60 -0
- package/dist/chains/ethereum.d.ts.map +1 -0
- package/dist/chains/ethereum.js +179 -0
- package/dist/chains/ethereum.js.map +1 -0
- package/dist/chains/solana.d.ts +48 -0
- package/dist/chains/solana.d.ts.map +1 -0
- package/dist/chains/solana.js +157 -0
- package/dist/chains/solana.js.map +1 -0
- package/dist/core/client.d.ts +123 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +311 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/types.d.ts +150 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +8 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/errors.d.ts +26 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +53 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/http.d.ts +23 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +64 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/websocket.d.ts +45 -0
- package/dist/utils/websocket.d.ts.map +1 -0
- package/dist/utils/websocket.js +130 -0
- package/dist/utils/websocket.js.map +1 -0
- package/dist/wallet/wallet.d.ts +144 -0
- package/dist/wallet/wallet.d.ts.map +1 -0
- package/dist/wallet/wallet.js +254 -0
- package/dist/wallet/wallet.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Types for Sequence0 SDK
|
|
3
|
+
*
|
|
4
|
+
* Matches the agent-node REST + WebSocket API exactly.
|
|
5
|
+
*/
|
|
6
|
+
export type Chain = 'ethereum' | 'bitcoin' | 'solana' | 'polygon' | 'arbitrum' | 'optimism' | 'base' | 'avalanche' | 'bsc' | 'cosmos' | 'cardano' | 'polkadot' | 'near' | 'tron' | 'sui' | 'aptos';
|
|
7
|
+
export interface NetworkConfig {
|
|
8
|
+
/** Network: 'testnet' or 'mainnet' */
|
|
9
|
+
network: 'testnet' | 'mainnet';
|
|
10
|
+
/** Agent node REST API URL (e.g. http://host:8080) */
|
|
11
|
+
agentUrl?: string;
|
|
12
|
+
/** Custom chain RPC URL override */
|
|
13
|
+
rpcUrl?: string;
|
|
14
|
+
/** API key for rate limiting (future) */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** Request timeout in ms (default: 30000) */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface Threshold {
|
|
20
|
+
/** Signatures required (t) */
|
|
21
|
+
t: number;
|
|
22
|
+
/** Total agents in committee (n) */
|
|
23
|
+
n: number;
|
|
24
|
+
}
|
|
25
|
+
export interface CreateWalletOptions {
|
|
26
|
+
/** Target blockchain */
|
|
27
|
+
chain: Chain;
|
|
28
|
+
/** Threshold (default: 17-of-24) */
|
|
29
|
+
threshold?: Threshold;
|
|
30
|
+
/** Elliptic curve: 'secp256k1' (default) or 'ed25519' */
|
|
31
|
+
curve?: 'secp256k1' | 'ed25519';
|
|
32
|
+
/** Custom wallet ID (auto-generated if omitted) */
|
|
33
|
+
walletId?: string;
|
|
34
|
+
/** Timeout for DKG ceremony in ms (default: 60000) */
|
|
35
|
+
timeout?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface SignOptions {
|
|
38
|
+
/** Raw message bytes to sign (hex-encoded) */
|
|
39
|
+
message: string;
|
|
40
|
+
/** Timeout for signing in ms (default: 30000) */
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface SignedTransaction {
|
|
44
|
+
/** Raw signed transaction (hex-encoded) */
|
|
45
|
+
rawTransaction: string;
|
|
46
|
+
/** Transaction hash */
|
|
47
|
+
hash: string;
|
|
48
|
+
/** Signature components */
|
|
49
|
+
signature: {
|
|
50
|
+
r: string;
|
|
51
|
+
s: string;
|
|
52
|
+
v?: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface EvmTransaction {
|
|
56
|
+
/** Recipient address */
|
|
57
|
+
to: string;
|
|
58
|
+
/** Value in wei (as string or bigint) */
|
|
59
|
+
value?: string | bigint;
|
|
60
|
+
/** Calldata (hex-encoded) */
|
|
61
|
+
data?: string;
|
|
62
|
+
/** Gas limit */
|
|
63
|
+
gasLimit?: string | bigint;
|
|
64
|
+
/** EIP-1559 max fee per gas */
|
|
65
|
+
maxFeePerGas?: string | bigint;
|
|
66
|
+
/** EIP-1559 max priority fee per gas */
|
|
67
|
+
maxPriorityFeePerGas?: string | bigint;
|
|
68
|
+
/** Legacy gas price */
|
|
69
|
+
gasPrice?: string | bigint;
|
|
70
|
+
/** Nonce (auto-fetched if omitted) */
|
|
71
|
+
nonce?: number;
|
|
72
|
+
/** Chain ID (auto-filled from network config) */
|
|
73
|
+
chainId?: number;
|
|
74
|
+
}
|
|
75
|
+
export interface BtcTransaction {
|
|
76
|
+
/** Recipient address */
|
|
77
|
+
to: string;
|
|
78
|
+
/** Amount in satoshis */
|
|
79
|
+
amount: number;
|
|
80
|
+
/** Fee rate in sat/vByte */
|
|
81
|
+
feeRate?: number;
|
|
82
|
+
}
|
|
83
|
+
export interface SolTransaction {
|
|
84
|
+
/** Recipient public key */
|
|
85
|
+
to: string;
|
|
86
|
+
/** Amount in lamports */
|
|
87
|
+
amount: number;
|
|
88
|
+
/** Optional memo */
|
|
89
|
+
memo?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface HealthResponse {
|
|
92
|
+
status: string;
|
|
93
|
+
version: string;
|
|
94
|
+
uptime_secs: number;
|
|
95
|
+
}
|
|
96
|
+
export interface StatusResponse {
|
|
97
|
+
peer_id: string;
|
|
98
|
+
connected_peers: number;
|
|
99
|
+
connected_peer_ids: string[];
|
|
100
|
+
active_dkg_sessions: number;
|
|
101
|
+
active_signing_sessions: number;
|
|
102
|
+
wallets_serving: number;
|
|
103
|
+
wallet_details: WalletDetail[];
|
|
104
|
+
uptime_secs: number;
|
|
105
|
+
}
|
|
106
|
+
export interface WalletDetail {
|
|
107
|
+
wallet_id: string;
|
|
108
|
+
chain: string;
|
|
109
|
+
address: string;
|
|
110
|
+
committee: string[];
|
|
111
|
+
threshold: number;
|
|
112
|
+
size: number;
|
|
113
|
+
epoch: number;
|
|
114
|
+
created_at: number;
|
|
115
|
+
last_activity: number;
|
|
116
|
+
}
|
|
117
|
+
export interface DkgResponse {
|
|
118
|
+
status: string;
|
|
119
|
+
wallet_id: string;
|
|
120
|
+
participants: string[];
|
|
121
|
+
threshold: number;
|
|
122
|
+
}
|
|
123
|
+
export interface SignResponse {
|
|
124
|
+
status: string;
|
|
125
|
+
request_id: string;
|
|
126
|
+
wallet_id: string;
|
|
127
|
+
}
|
|
128
|
+
export interface SignResultResponse {
|
|
129
|
+
request_id: string;
|
|
130
|
+
wallet_id: string;
|
|
131
|
+
status: 'pending' | 'complete';
|
|
132
|
+
signature: string | null;
|
|
133
|
+
}
|
|
134
|
+
export interface WalletsResponse {
|
|
135
|
+
count: number;
|
|
136
|
+
wallets: WalletDetail[];
|
|
137
|
+
}
|
|
138
|
+
export interface ChainAdapter {
|
|
139
|
+
/** Build unsigned transaction for signing */
|
|
140
|
+
buildTransaction(tx: unknown, fromAddress: string): Promise<string>;
|
|
141
|
+
/** Attach signature to unsigned TX and return raw signed TX */
|
|
142
|
+
attachSignature(unsignedTx: string, signature: string): Promise<string>;
|
|
143
|
+
/** Broadcast signed transaction to the chain */
|
|
144
|
+
broadcast(signedTx: string): Promise<string>;
|
|
145
|
+
/** Get address balance */
|
|
146
|
+
getBalance(address: string): Promise<string>;
|
|
147
|
+
/** Get chain-specific RPC URL */
|
|
148
|
+
getRpcUrl(): string;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,MAAM,KAAK,GACX,UAAU,GACV,SAAS,GACT,QAAQ,GACR,SAAS,GACT,UAAU,GACV,UAAU,GACV,MAAM,GACN,WAAW,GACX,KAAK,GACL,QAAQ,GACR,SAAS,GACT,UAAU,GACV,MAAM,GACN,MAAM,GACN,KAAK,GACL,OAAO,CAAC;AAId,MAAM,WAAW,aAAa;IAC1B,sCAAsC;IACtC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAC/B,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACtB,8BAA8B;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,oCAAoC;IACpC,CAAC,EAAE,MAAM,CAAC;CACb;AAID,MAAM,WAAW,mBAAmB;IAChC,wBAAwB;IACxB,KAAK,EAAE,KAAK,CAAC;IACb,oCAAoC;IACpC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,yDAAyD;IACzD,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAChC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,MAAM,WAAW,WAAW;IACxB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM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AgB,CAAC,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACpE,+DAA+D;IAC/D,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxE,gDAAgD;IAChD,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,0BAA0B;IAC1B,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,iCAAiC;IACjC,SAAS,IAAI,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sequence0/sdk
|
|
3
|
+
*
|
|
4
|
+
* The official TypeScript SDK for Sequence0 Network.
|
|
5
|
+
* Create wallets, sign transactions, and broadcast to any blockchain
|
|
6
|
+
* using decentralized threshold signatures.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { Sequence0 } from '@sequence0/sdk';
|
|
11
|
+
*
|
|
12
|
+
* const s0 = new Sequence0({ network: 'testnet' });
|
|
13
|
+
* const wallet = await s0.createWallet({ chain: 'ethereum' });
|
|
14
|
+
* const txHash = await wallet.sendTransaction({ to: '0x...', value: '1000000000' });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export { Sequence0 } from './core/client';
|
|
18
|
+
export { Wallet } from './wallet/wallet';
|
|
19
|
+
export type { WalletConfig } from './wallet/wallet';
|
|
20
|
+
export type { Chain, NetworkConfig, Threshold, CreateWalletOptions, SignOptions, SignedTransaction, EvmTransaction, BtcTransaction, SolTransaction, ChainAdapter, HealthResponse, StatusResponse, WalletDetail, WalletsResponse, DkgResponse, SignResponse, SignResultResponse, } from './core/types';
|
|
21
|
+
export { EthereumAdapter, createEthereumAdapter, createPolygonAdapter, createArbitrumAdapter, createBaseAdapter } from './chains/ethereum';
|
|
22
|
+
export { BitcoinAdapter, createBitcoinAdapter } from './chains/bitcoin';
|
|
23
|
+
export { SolanaAdapter, createSolanaAdapter, createSolanaDevnetAdapter } from './chains/solana';
|
|
24
|
+
export { HttpClient } from './utils/http';
|
|
25
|
+
export type { HttpOptions } from './utils/http';
|
|
26
|
+
export { WsClient } from './utils/websocket';
|
|
27
|
+
export type { WsClientOptions, WsEventType, WsMessage, WsEventHandler } from './utils/websocket';
|
|
28
|
+
export { Sequence0Error, NetworkError, DkgError, SigningError, TimeoutError, ChainError, } from './utils/errors';
|
|
29
|
+
export declare const VERSION = "0.1.0";
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,YAAY,EACR,KAAK,EACL,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,WAAW,EACX,YAAY,EACZ,kBAAkB,GACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3I,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGhG,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGjG,OAAO,EACH,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,GACb,MAAM,gBAAgB,CAAC;AAGxB,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @sequence0/sdk
|
|
4
|
+
*
|
|
5
|
+
* The official TypeScript SDK for Sequence0 Network.
|
|
6
|
+
* Create wallets, sign transactions, and broadcast to any blockchain
|
|
7
|
+
* using decentralized threshold signatures.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { Sequence0 } from '@sequence0/sdk';
|
|
12
|
+
*
|
|
13
|
+
* const s0 = new Sequence0({ network: 'testnet' });
|
|
14
|
+
* const wallet = await s0.createWallet({ chain: 'ethereum' });
|
|
15
|
+
* const txHash = await wallet.sendTransaction({ to: '0x...', value: '1000000000' });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.VERSION = exports.ChainError = exports.TimeoutError = exports.SigningError = exports.DkgError = exports.NetworkError = exports.Sequence0Error = exports.WsClient = exports.HttpClient = exports.createSolanaDevnetAdapter = exports.createSolanaAdapter = exports.SolanaAdapter = exports.createBitcoinAdapter = exports.BitcoinAdapter = exports.createBaseAdapter = exports.createArbitrumAdapter = exports.createPolygonAdapter = exports.createEthereumAdapter = exports.EthereumAdapter = exports.Wallet = exports.Sequence0 = void 0;
|
|
20
|
+
// Core
|
|
21
|
+
var client_1 = require("./core/client");
|
|
22
|
+
Object.defineProperty(exports, "Sequence0", { enumerable: true, get: function () { return client_1.Sequence0; } });
|
|
23
|
+
var wallet_1 = require("./wallet/wallet");
|
|
24
|
+
Object.defineProperty(exports, "Wallet", { enumerable: true, get: function () { return wallet_1.Wallet; } });
|
|
25
|
+
// Chain Adapters
|
|
26
|
+
var ethereum_1 = require("./chains/ethereum");
|
|
27
|
+
Object.defineProperty(exports, "EthereumAdapter", { enumerable: true, get: function () { return ethereum_1.EthereumAdapter; } });
|
|
28
|
+
Object.defineProperty(exports, "createEthereumAdapter", { enumerable: true, get: function () { return ethereum_1.createEthereumAdapter; } });
|
|
29
|
+
Object.defineProperty(exports, "createPolygonAdapter", { enumerable: true, get: function () { return ethereum_1.createPolygonAdapter; } });
|
|
30
|
+
Object.defineProperty(exports, "createArbitrumAdapter", { enumerable: true, get: function () { return ethereum_1.createArbitrumAdapter; } });
|
|
31
|
+
Object.defineProperty(exports, "createBaseAdapter", { enumerable: true, get: function () { return ethereum_1.createBaseAdapter; } });
|
|
32
|
+
var bitcoin_1 = require("./chains/bitcoin");
|
|
33
|
+
Object.defineProperty(exports, "BitcoinAdapter", { enumerable: true, get: function () { return bitcoin_1.BitcoinAdapter; } });
|
|
34
|
+
Object.defineProperty(exports, "createBitcoinAdapter", { enumerable: true, get: function () { return bitcoin_1.createBitcoinAdapter; } });
|
|
35
|
+
var solana_1 = require("./chains/solana");
|
|
36
|
+
Object.defineProperty(exports, "SolanaAdapter", { enumerable: true, get: function () { return solana_1.SolanaAdapter; } });
|
|
37
|
+
Object.defineProperty(exports, "createSolanaAdapter", { enumerable: true, get: function () { return solana_1.createSolanaAdapter; } });
|
|
38
|
+
Object.defineProperty(exports, "createSolanaDevnetAdapter", { enumerable: true, get: function () { return solana_1.createSolanaDevnetAdapter; } });
|
|
39
|
+
// Utilities
|
|
40
|
+
var http_1 = require("./utils/http");
|
|
41
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_1.HttpClient; } });
|
|
42
|
+
var websocket_1 = require("./utils/websocket");
|
|
43
|
+
Object.defineProperty(exports, "WsClient", { enumerable: true, get: function () { return websocket_1.WsClient; } });
|
|
44
|
+
// Errors
|
|
45
|
+
var errors_1 = require("./utils/errors");
|
|
46
|
+
Object.defineProperty(exports, "Sequence0Error", { enumerable: true, get: function () { return errors_1.Sequence0Error; } });
|
|
47
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
|
|
48
|
+
Object.defineProperty(exports, "DkgError", { enumerable: true, get: function () { return errors_1.DkgError; } });
|
|
49
|
+
Object.defineProperty(exports, "SigningError", { enumerable: true, get: function () { return errors_1.SigningError; } });
|
|
50
|
+
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
|
|
51
|
+
Object.defineProperty(exports, "ChainError", { enumerable: true, get: function () { return errors_1.ChainError; } });
|
|
52
|
+
// Version
|
|
53
|
+
exports.VERSION = '0.1.0';
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,OAAO;AACP,wCAA0C;AAAjC,mGAAA,SAAS,OAAA;AAClB,0CAAyC;AAAhC,gGAAA,MAAM,OAAA;AAwBf,iBAAiB;AACjB,8CAA2I;AAAlI,2GAAA,eAAe,OAAA;AAAE,iHAAA,qBAAqB,OAAA;AAAE,gHAAA,oBAAoB,OAAA;AAAE,iHAAA,qBAAqB,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAC/G,4CAAwE;AAA/D,yGAAA,cAAc,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAC7C,0CAAgG;AAAvF,uGAAA,aAAa,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AAAE,mHAAA,yBAAyB,OAAA;AAEtE,YAAY;AACZ,qCAA0C;AAAjC,kGAAA,UAAU,OAAA;AAEnB,+CAA6C;AAApC,qGAAA,QAAQ,OAAA;AAGjB,SAAS;AACT,yCAOwB;AANpB,wGAAA,cAAc,OAAA;AACd,sGAAA,YAAY,OAAA;AACZ,kGAAA,QAAQ,OAAA;AACR,sGAAA,YAAY,OAAA;AACZ,sGAAA,YAAY,OAAA;AACZ,oGAAA,UAAU,OAAA;AAGd,UAAU;AACG,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sequence0 SDK Error Classes
|
|
3
|
+
*/
|
|
4
|
+
export declare class Sequence0Error extends Error {
|
|
5
|
+
code?: string | undefined;
|
|
6
|
+
constructor(message: string, code?: string | undefined);
|
|
7
|
+
}
|
|
8
|
+
export declare class NetworkError extends Sequence0Error {
|
|
9
|
+
statusCode?: number | undefined;
|
|
10
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
11
|
+
}
|
|
12
|
+
export declare class DkgError extends Sequence0Error {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class SigningError extends Sequence0Error {
|
|
16
|
+
requestId?: string | undefined;
|
|
17
|
+
constructor(message: string, requestId?: string | undefined);
|
|
18
|
+
}
|
|
19
|
+
export declare class TimeoutError extends Sequence0Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class ChainError extends Sequence0Error {
|
|
23
|
+
chain?: string | undefined;
|
|
24
|
+
constructor(message: string, chain?: string | undefined);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,cAAe,SAAQ,KAAK;IACD,IAAI,CAAC,EAAE,MAAM;gBAArC,OAAO,EAAE,MAAM,EAAS,IAAI,CAAC,EAAE,MAAM,YAAA;CAIpD;AAED,qBAAa,YAAa,SAAQ,cAAc;IACR,UAAU,CAAC,EAAE,MAAM;gBAA3C,OAAO,EAAE,MAAM,EAAS,UAAU,CAAC,EAAE,MAAM,YAAA;CAI1D;AAED,qBAAa,QAAS,SAAQ,cAAc;gBAC5B,OAAO,EAAE,MAAM;CAI9B;AAED,qBAAa,YAAa,SAAQ,cAAc;IACR,SAAS,CAAC,EAAE,MAAM;gBAA1C,OAAO,EAAE,MAAM,EAAS,SAAS,CAAC,EAAE,MAAM,YAAA;CAIzD;AAED,qBAAa,YAAa,SAAQ,cAAc;gBAChC,OAAO,EAAE,MAAM;CAI9B;AAED,qBAAa,UAAW,SAAQ,cAAc;IACN,KAAK,CAAC,EAAE,MAAM;gBAAtC,OAAO,EAAE,MAAM,EAAS,KAAK,CAAC,EAAE,MAAM,YAAA;CAIrD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sequence0 SDK Error Classes
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ChainError = exports.TimeoutError = exports.SigningError = exports.DkgError = exports.NetworkError = exports.Sequence0Error = void 0;
|
|
7
|
+
class Sequence0Error extends Error {
|
|
8
|
+
constructor(message, code) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.name = 'Sequence0Error';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Sequence0Error = Sequence0Error;
|
|
15
|
+
class NetworkError extends Sequence0Error {
|
|
16
|
+
constructor(message, statusCode) {
|
|
17
|
+
super(message, 'NETWORK_ERROR');
|
|
18
|
+
this.statusCode = statusCode;
|
|
19
|
+
this.name = 'NetworkError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.NetworkError = NetworkError;
|
|
23
|
+
class DkgError extends Sequence0Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message, 'DKG_ERROR');
|
|
26
|
+
this.name = 'DkgError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.DkgError = DkgError;
|
|
30
|
+
class SigningError extends Sequence0Error {
|
|
31
|
+
constructor(message, requestId) {
|
|
32
|
+
super(message, 'SIGNING_ERROR');
|
|
33
|
+
this.requestId = requestId;
|
|
34
|
+
this.name = 'SigningError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.SigningError = SigningError;
|
|
38
|
+
class TimeoutError extends Sequence0Error {
|
|
39
|
+
constructor(message) {
|
|
40
|
+
super(message, 'TIMEOUT');
|
|
41
|
+
this.name = 'TimeoutError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.TimeoutError = TimeoutError;
|
|
45
|
+
class ChainError extends Sequence0Error {
|
|
46
|
+
constructor(message, chain) {
|
|
47
|
+
super(message, 'CHAIN_ERROR');
|
|
48
|
+
this.chain = chain;
|
|
49
|
+
this.name = 'ChainError';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.ChainError = ChainError;
|
|
53
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,MAAa,cAAe,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAS,IAAa;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QADiB,SAAI,GAAJ,IAAI,CAAS;QAE7C,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IACjC,CAAC;CACJ;AALD,wCAKC;AAED,MAAa,YAAa,SAAQ,cAAc;IAC5C,YAAY,OAAe,EAAS,UAAmB;QACnD,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QADA,eAAU,GAAV,UAAU,CAAS;QAEnD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC/B,CAAC;CACJ;AALD,oCAKC;AAED,MAAa,QAAS,SAAQ,cAAc;IACxC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IAC3B,CAAC;CACJ;AALD,4BAKC;AAED,MAAa,YAAa,SAAQ,cAAc;IAC5C,YAAY,OAAe,EAAS,SAAkB;QAClD,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QADA,cAAS,GAAT,SAAS,CAAS;QAElD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC/B,CAAC;CACJ;AALD,oCAKC;AAED,MAAa,YAAa,SAAQ,cAAc;IAC5C,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC/B,CAAC;CACJ;AALD,oCAKC;AAED,MAAa,UAAW,SAAQ,cAAc;IAC1C,YAAY,OAAe,EAAS,KAAc;QAC9C,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QADE,UAAK,GAAL,KAAK,CAAS;QAE9C,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC7B,CAAC;CACJ;AALD,gCAKC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight HTTP client for Sequence0 agent node REST API
|
|
3
|
+
*
|
|
4
|
+
* Uses native fetch — works in Node.js 18+ and all modern browsers.
|
|
5
|
+
*/
|
|
6
|
+
export interface HttpOptions {
|
|
7
|
+
/** Base URL of the agent node (e.g. http://18.220.162.112:8080) */
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
/** Request timeout in ms (default: 30000) */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** Additional headers */
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare class HttpClient {
|
|
15
|
+
private baseUrl;
|
|
16
|
+
private timeout;
|
|
17
|
+
private headers;
|
|
18
|
+
constructor(options: HttpOptions);
|
|
19
|
+
get<T>(path: string): Promise<T>;
|
|
20
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
21
|
+
private request;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,WAAW;IACxB,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,qBAAa,UAAU;IACnB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAyB;gBAE5B,OAAO,EAAE,WAAW;IAS1B,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIhC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;YAIzC,OAAO;CAuCxB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Lightweight HTTP client for Sequence0 agent node REST API
|
|
4
|
+
*
|
|
5
|
+
* Uses native fetch — works in Node.js 18+ and all modern browsers.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.HttpClient = void 0;
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
class HttpClient {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, '');
|
|
13
|
+
this.timeout = options.timeout || 30000;
|
|
14
|
+
this.headers = {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
...options.headers,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async get(path) {
|
|
20
|
+
return this.request('GET', path);
|
|
21
|
+
}
|
|
22
|
+
async post(path, body) {
|
|
23
|
+
return this.request('POST', path, body);
|
|
24
|
+
}
|
|
25
|
+
async request(method, path, body) {
|
|
26
|
+
const url = `${this.baseUrl}${path}`;
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetch(url, {
|
|
31
|
+
method,
|
|
32
|
+
headers: this.headers,
|
|
33
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
34
|
+
signal: controller.signal,
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const errorBody = await response.text().catch(() => '');
|
|
38
|
+
let errorMessage;
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(errorBody);
|
|
41
|
+
errorMessage = parsed.error || errorBody;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
errorMessage = errorBody || `HTTP ${response.status}`;
|
|
45
|
+
}
|
|
46
|
+
throw new errors_1.NetworkError(`${method} ${path} failed: ${errorMessage}`, response.status);
|
|
47
|
+
}
|
|
48
|
+
return (await response.json());
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof errors_1.NetworkError)
|
|
52
|
+
throw error;
|
|
53
|
+
if (error.name === 'AbortError') {
|
|
54
|
+
throw new errors_1.TimeoutError(`Request to ${path} timed out after ${this.timeout}ms`);
|
|
55
|
+
}
|
|
56
|
+
throw new errors_1.NetworkError(`Failed to connect to ${url}: ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.HttpClient = HttpClient;
|
|
64
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCAAsD;AAWtD,MAAa,UAAU;IAKnB,YAAY,OAAoB;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAM,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG;YACX,cAAc,EAAE,kBAAkB;YAClC,GAAG,OAAO,CAAC,OAAO;SACrB,CAAC;IACN,CAAC;IAED,KAAK,CAAC,GAAG,CAAI,IAAY;QACrB,OAAO,IAAI,CAAC,OAAO,CAAI,KAAK,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,IAAI,CAAI,IAAY,EAAE,IAAc;QACtC,OAAO,IAAI,CAAC,OAAO,CAAI,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAEO,KAAK,CAAC,OAAO,CAAI,MAAc,EAAE,IAAY,EAAE,IAAc;QACjE,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjE,IAAI,CAAC;YACD,M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CAAC;gBAAS,CAAC;YACP,YAAY,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;IACL,CAAC;CACJ;AA7DD,gCA6DC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket client for real-time Sequence0 agent events
|
|
3
|
+
*
|
|
4
|
+
* Connects to the agent node's /ws endpoint, receives typed events
|
|
5
|
+
* for signing progress, DKG status, and fee collection.
|
|
6
|
+
*/
|
|
7
|
+
/** WebSocket event types — mirrors agent-node WsEvent enum */
|
|
8
|
+
export type WsEventType = 'SigningStarted' | 'CommitmentReceived' | 'PartialSignatureReceived' | 'SigningComplete' | 'SigningFailed' | 'DkgStarted' | 'DkgRoundProgress' | 'WalletCreated' | 'FeeCollected' | 'FeeCollectionFailed' | 'Heartbeat';
|
|
9
|
+
export interface WsMessage {
|
|
10
|
+
type: WsEventType;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export type WsEventHandler = (event: WsMessage) => void;
|
|
14
|
+
export interface WsClientOptions {
|
|
15
|
+
/** WebSocket URL (e.g. ws://host:8080/ws) */
|
|
16
|
+
url: string;
|
|
17
|
+
/** Filter events by wallet_id (optional) */
|
|
18
|
+
walletId?: string;
|
|
19
|
+
/** Auto-reconnect on disconnect (default: true) */
|
|
20
|
+
autoReconnect?: boolean;
|
|
21
|
+
/** Reconnect delay in ms (default: 3000) */
|
|
22
|
+
reconnectDelay?: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class WsClient {
|
|
25
|
+
private ws;
|
|
26
|
+
private handlers;
|
|
27
|
+
private options;
|
|
28
|
+
private reconnectTimer;
|
|
29
|
+
private _connected;
|
|
30
|
+
constructor(options: WsClientOptions);
|
|
31
|
+
get connected(): boolean;
|
|
32
|
+
/** Connect to the agent WebSocket */
|
|
33
|
+
connect(): Promise<void>;
|
|
34
|
+
/** Disconnect and stop reconnecting */
|
|
35
|
+
disconnect(): void;
|
|
36
|
+
/** Subscribe to a specific event type, or '*' for all */
|
|
37
|
+
on(event: WsEventType | 'connected' | 'disconnected' | '*', handler: WsEventHandler): void;
|
|
38
|
+
/** Remove an event handler */
|
|
39
|
+
off(event: string, handler: WsEventHandler): void;
|
|
40
|
+
/** Wait for a specific event matching a predicate (with timeout) */
|
|
41
|
+
waitFor(eventType: WsEventType, predicate: (event: WsMessage) => boolean, timeoutMs?: number): Promise<WsMessage>;
|
|
42
|
+
private emit;
|
|
43
|
+
private scheduleReconnect;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/utils/websocket.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,8DAA8D;AAC9D,MAAM,MAAM,WAAW,GACjB,gBAAgB,GAChB,oBAAoB,GACpB,0BAA0B,GAC1B,iBAAiB,GACjB,eAAe,GACf,YAAY,GACZ,kBAAkB,GAClB,eAAe,GACf,cAAc,GACd,qBAAqB,GACrB,WAAW,CAAC;AAElB,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AAExD,MAAM,WAAW,eAAe;IAC5B,6CAA6C;IAC7C,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,4CAA4C;IAC5C,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,QAAQ;IACjB,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,QAAQ,CAA4C;IAC5D,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,EAAE,eAAe;IASpC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,qCAAqC;IAC/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA0C9B,uCAAuC;IACvC,UAAU,IAAI,IAAI;IAalB,yDAAyD;IACzD,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,GAAG,cAAc,GAAG,GAAG,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI;IAM1F,8BAA8B;IAC9B,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI;IAKjD,oEAAoE;IACpE,OAAO,CACH,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,EACxC,SAAS,SAAS,GACnB,OAAO,CAAC,SAAS,CAAC;IAkBrB,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,iBAAiB;CAO5B"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* WebSocket client for real-time Sequence0 agent events
|
|
4
|
+
*
|
|
5
|
+
* Connects to the agent node's /ws endpoint, receives typed events
|
|
6
|
+
* for signing progress, DKG status, and fee collection.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WsClient = void 0;
|
|
10
|
+
const errors_1 = require("./errors");
|
|
11
|
+
class WsClient {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.ws = null;
|
|
14
|
+
this.handlers = new Map();
|
|
15
|
+
this.reconnectTimer = null;
|
|
16
|
+
this._connected = false;
|
|
17
|
+
this.options = {
|
|
18
|
+
autoReconnect: true,
|
|
19
|
+
reconnectDelay: 3000,
|
|
20
|
+
walletId: '',
|
|
21
|
+
...options,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
get connected() {
|
|
25
|
+
return this._connected;
|
|
26
|
+
}
|
|
27
|
+
/** Connect to the agent WebSocket */
|
|
28
|
+
async connect() {
|
|
29
|
+
const url = this.options.walletId
|
|
30
|
+
? `${this.options.url}?wallet_id=${this.options.walletId}`
|
|
31
|
+
: this.options.url;
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
try {
|
|
34
|
+
this.ws = new WebSocket(url);
|
|
35
|
+
this.ws.onopen = () => {
|
|
36
|
+
this._connected = true;
|
|
37
|
+
this.emit('connected', { type: 'connected' });
|
|
38
|
+
resolve();
|
|
39
|
+
};
|
|
40
|
+
this.ws.onmessage = (event) => {
|
|
41
|
+
try {
|
|
42
|
+
const data = JSON.parse(event.data);
|
|
43
|
+
this.emit(data.type, data);
|
|
44
|
+
this.emit('*', data); // wildcard for all events
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// ignore parse errors
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this.ws.onclose = () => {
|
|
51
|
+
this._connected = false;
|
|
52
|
+
this.emit('disconnected', { type: 'disconnected' });
|
|
53
|
+
if (this.options.autoReconnect) {
|
|
54
|
+
this.scheduleReconnect();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.ws.onerror = (err) => {
|
|
58
|
+
if (!this._connected)
|
|
59
|
+
reject(new errors_1.NetworkError('WebSocket connection failed'));
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
reject(e);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Disconnect and stop reconnecting */
|
|
68
|
+
disconnect() {
|
|
69
|
+
this.options.autoReconnect = false;
|
|
70
|
+
if (this.reconnectTimer) {
|
|
71
|
+
clearTimeout(this.reconnectTimer);
|
|
72
|
+
this.reconnectTimer = null;
|
|
73
|
+
}
|
|
74
|
+
if (this.ws) {
|
|
75
|
+
this.ws.close();
|
|
76
|
+
this.ws = null;
|
|
77
|
+
}
|
|
78
|
+
this._connected = false;
|
|
79
|
+
}
|
|
80
|
+
/** Subscribe to a specific event type, or '*' for all */
|
|
81
|
+
on(event, handler) {
|
|
82
|
+
const list = this.handlers.get(event) || [];
|
|
83
|
+
list.push(handler);
|
|
84
|
+
this.handlers.set(event, list);
|
|
85
|
+
}
|
|
86
|
+
/** Remove an event handler */
|
|
87
|
+
off(event, handler) {
|
|
88
|
+
const list = this.handlers.get(event) || [];
|
|
89
|
+
this.handlers.set(event, list.filter(h => h !== handler));
|
|
90
|
+
}
|
|
91
|
+
/** Wait for a specific event matching a predicate (with timeout) */
|
|
92
|
+
waitFor(eventType, predicate, timeoutMs = 60000) {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
const timer = setTimeout(() => {
|
|
95
|
+
this.off(eventType, handler);
|
|
96
|
+
reject(new Error(`Timed out waiting for ${eventType}`));
|
|
97
|
+
}, timeoutMs);
|
|
98
|
+
const handler = (event) => {
|
|
99
|
+
if (predicate(event)) {
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
this.off(eventType, handler);
|
|
102
|
+
resolve(event);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
this.on(eventType, handler);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
emit(event, data) {
|
|
109
|
+
const handlers = this.handlers.get(event) || [];
|
|
110
|
+
for (const handler of handlers) {
|
|
111
|
+
try {
|
|
112
|
+
handler(data);
|
|
113
|
+
}
|
|
114
|
+
catch { /* ignore */ }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
scheduleReconnect() {
|
|
118
|
+
if (this.reconnectTimer)
|
|
119
|
+
return;
|
|
120
|
+
this.reconnectTimer = setTimeout(async () => {
|
|
121
|
+
this.reconnectTimer = null;
|
|
122
|
+
try {
|
|
123
|
+
await this.connect();
|
|
124
|
+
}
|
|
125
|
+
catch { /* will retry */ }
|
|
126
|
+
}, this.options.reconnectDelay);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.WsClient = WsClient;
|
|
130
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../src/utils/websocket.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAwC;AAkCxC,MAAa,QAAQ;IAOjB,YAAY,OAAwB;QAN5B,OAAE,GAAqB,IAAI,CAAC;QAC5B,aAAQ,GAAkC,IAAI,GAAG,EAAE,CAAC;QAEpD,mBAAc,GAAyC,IAAI,CAAC;QAC5D,eAAU,GAAG,KAAK,CAAC;QAGvB,IAAI,CAAC,OAAO,GAAG;YACX,aAAa,EAAE,IAAI;YACnB,cAAc,EAAE,IAAI;YACpB,QAAQ,EAAE,EAAE;YACZ,GAAG,OAAO;SACb,CAAC;IACN,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,OAAO;QACT,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC7B,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,cAAc,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YAC1D,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;QAEvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAI,CAAC;gBACD,IAAI,CAAC,EAAE,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;gBAE7B,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,GAAG,EAAE;oBAClB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;oBACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,WAAkB,EAAE,CAAC,CAAC;oBACrD,OAAO,EAAE,CAAC;gBACd,CAAC,CAAC;gBAEF,IAAI,CAAC,EAAE,CAAC,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