navio-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 +758 -0
- package/dist/index.d.mts +2500 -0
- package/dist/index.d.ts +2500 -0
- package/dist/index.js +5050 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5002 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +77 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2500 @@
|
|
|
1
|
+
import * as blsctModule from 'navio-blsct';
|
|
2
|
+
export { BlsctChain, getChain, setChain } from 'navio-blsct';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type definitions for KeyManager
|
|
6
|
+
* These types represent the BLS CT key structures from navio-blsct
|
|
7
|
+
* Replicates types from navio-core's blsct::keyman
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Secret key type (opaque type from navio-blsct)
|
|
11
|
+
* This represents a BLS secret key (MclScalar)
|
|
12
|
+
*/
|
|
13
|
+
type SecretKey = unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Public key type (opaque type from navio-blsct)
|
|
16
|
+
* This represents a BLS public key (MclG1Point)
|
|
17
|
+
*/
|
|
18
|
+
type PublicKey$1 = unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Sub-address identifier
|
|
21
|
+
* Replicates SubAddressIdentifier from navio-core
|
|
22
|
+
*/
|
|
23
|
+
interface SubAddressIdentifier {
|
|
24
|
+
/** Account number (0 = main, -1 = change, -2 = staking) */
|
|
25
|
+
account: number;
|
|
26
|
+
/** Address index within the account */
|
|
27
|
+
address: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sub-address type
|
|
31
|
+
* Replicates SubAddress from navio-core
|
|
32
|
+
*/
|
|
33
|
+
type SubAddress = unknown;
|
|
34
|
+
/**
|
|
35
|
+
* HD Chain structure
|
|
36
|
+
* Replicates HDChain from navio-core
|
|
37
|
+
*/
|
|
38
|
+
interface HDChain {
|
|
39
|
+
/** Chain version */
|
|
40
|
+
version: number;
|
|
41
|
+
/** Seed ID (hash160 of seed public key) */
|
|
42
|
+
seedId: Uint8Array;
|
|
43
|
+
/** Spend key ID */
|
|
44
|
+
spendId: Uint8Array;
|
|
45
|
+
/** View key ID */
|
|
46
|
+
viewId: Uint8Array;
|
|
47
|
+
/** Token key ID */
|
|
48
|
+
tokenId: Uint8Array;
|
|
49
|
+
/** Blinding key ID */
|
|
50
|
+
blindingId: Uint8Array;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Seed type for import
|
|
54
|
+
* Replicates SeedType enum from navio-core
|
|
55
|
+
*/
|
|
56
|
+
type SeedType = 'IMPORT_MASTER_KEY' | 'IMPORT_VIEW_KEY';
|
|
57
|
+
/**
|
|
58
|
+
* Key storage interface for persistent storage
|
|
59
|
+
*/
|
|
60
|
+
interface KeyStorage {
|
|
61
|
+
/** Save a key pair with a label */
|
|
62
|
+
save(label: string, secretKey: SecretKey, publicKey: PublicKey$1): Promise<void>;
|
|
63
|
+
/** Load a key pair by label */
|
|
64
|
+
load(label: string): Promise<{
|
|
65
|
+
secretKey: SecretKey;
|
|
66
|
+
publicKey: PublicKey$1;
|
|
67
|
+
} | null>;
|
|
68
|
+
/** Delete a key pair by label */
|
|
69
|
+
delete(label: string): Promise<boolean>;
|
|
70
|
+
/** List all stored key labels */
|
|
71
|
+
list(): Promise<string[]>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* BLS CT transaction output data
|
|
75
|
+
* Replicates CTxOutBLSCTData from navio-core
|
|
76
|
+
*/
|
|
77
|
+
interface CTxOutBLSCTData {
|
|
78
|
+
/** Spending public key */
|
|
79
|
+
spendingKey: unknown;
|
|
80
|
+
/** Ephemeral public key */
|
|
81
|
+
ephemeralKey: unknown;
|
|
82
|
+
/** Blinding public key */
|
|
83
|
+
blindingKey: unknown;
|
|
84
|
+
/** Range proof */
|
|
85
|
+
rangeProof: unknown;
|
|
86
|
+
/** View tag (16-bit) */
|
|
87
|
+
viewTag: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Transaction output
|
|
91
|
+
* Replicates CTxOut from navio-core
|
|
92
|
+
*/
|
|
93
|
+
interface CTxOut {
|
|
94
|
+
/** Value (amount) */
|
|
95
|
+
nValue: bigint;
|
|
96
|
+
/** Script public key */
|
|
97
|
+
scriptPubKey: Uint8Array;
|
|
98
|
+
/** BLS CT data */
|
|
99
|
+
blsctData: CTxOutBLSCTData;
|
|
100
|
+
/** Token ID */
|
|
101
|
+
tokenId: Uint8Array;
|
|
102
|
+
/** Predicate (optional) */
|
|
103
|
+
predicate?: unknown;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Transaction destination
|
|
107
|
+
* Replicates CTxDestination from navio-core
|
|
108
|
+
*/
|
|
109
|
+
type CTxDestination = unknown;
|
|
110
|
+
/**
|
|
111
|
+
* Amount recovery result
|
|
112
|
+
* Replicates AmountRecoveryResult from navio-core
|
|
113
|
+
*/
|
|
114
|
+
interface AmountRecoveryResult {
|
|
115
|
+
/** Success flag */
|
|
116
|
+
success: boolean;
|
|
117
|
+
/** Recovered amounts */
|
|
118
|
+
amounts: bigint[];
|
|
119
|
+
/** Indices of outputs that were recovered */
|
|
120
|
+
indices: number[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* KeyManager - Replicates blsct::keyman functionality from navio-core
|
|
125
|
+
* Uses low-level functions from navio-blsct library
|
|
126
|
+
*
|
|
127
|
+
* Based on navio-blsct documentation: https://nav-io.github.io/libblsct-bindings/ts/
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
declare const Scalar: typeof blsctModule.Scalar;
|
|
131
|
+
declare const PublicKey: typeof blsctModule.PublicKey;
|
|
132
|
+
declare const SubAddr: typeof blsctModule.SubAddr;
|
|
133
|
+
type ScalarType = InstanceType<typeof Scalar>;
|
|
134
|
+
type ViewKeyType = ScalarType;
|
|
135
|
+
type PublicKeyType = InstanceType<typeof PublicKey>;
|
|
136
|
+
type SubAddrType = InstanceType<typeof SubAddr>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* KeyManager class for managing BLS CT keys.
|
|
140
|
+
* Replicates functionality from navio-core's blsct::keyman.
|
|
141
|
+
*
|
|
142
|
+
* Handles HD key derivation, sub-address generation, output detection,
|
|
143
|
+
* and amount recovery for BLSCT confidential transactions.
|
|
144
|
+
*
|
|
145
|
+
* @category Keys
|
|
146
|
+
*/
|
|
147
|
+
declare class KeyManager {
|
|
148
|
+
private hdChain;
|
|
149
|
+
private viewKey;
|
|
150
|
+
private spendPublicKey;
|
|
151
|
+
private masterSeed;
|
|
152
|
+
private spendKeyId;
|
|
153
|
+
private viewKeyId;
|
|
154
|
+
private tokenKeyId;
|
|
155
|
+
private blindingKeyId;
|
|
156
|
+
private seedId;
|
|
157
|
+
private keys;
|
|
158
|
+
private outKeys;
|
|
159
|
+
private cryptedKeys;
|
|
160
|
+
private cryptedOutKeys;
|
|
161
|
+
private keyMetadata;
|
|
162
|
+
private subAddressCounter;
|
|
163
|
+
private subAddresses;
|
|
164
|
+
private subAddressesStr;
|
|
165
|
+
private subAddressPool;
|
|
166
|
+
private subAddressPoolTime;
|
|
167
|
+
private timeFirstKey;
|
|
168
|
+
private fViewKeyDefined;
|
|
169
|
+
private fSpendKeyDefined;
|
|
170
|
+
/**
|
|
171
|
+
* Check if HD is enabled (has a seed)
|
|
172
|
+
* @returns True if HD is enabled
|
|
173
|
+
*/
|
|
174
|
+
isHDEnabled(): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Check if the wallet can generate new keys
|
|
177
|
+
* @returns True if HD is enabled
|
|
178
|
+
*/
|
|
179
|
+
canGenerateKeys(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Generate a new random seed
|
|
182
|
+
* @returns A new random Scalar (seed)
|
|
183
|
+
*/
|
|
184
|
+
generateNewSeed(): ScalarType;
|
|
185
|
+
/**
|
|
186
|
+
* Set the HD seed and derive all master keys
|
|
187
|
+
* This replicates SetHDSeed from keyman.cpp
|
|
188
|
+
* Uses navio-blsct API: ChildKey(seed).toTxKey().toViewKey() etc.
|
|
189
|
+
* @param seed - The master seed Scalar
|
|
190
|
+
*/
|
|
191
|
+
setHDSeed(seed: ScalarType): void;
|
|
192
|
+
/**
|
|
193
|
+
* Setup key generation from a seed
|
|
194
|
+
* Replicates SetupGeneration from keyman.cpp
|
|
195
|
+
* @param seedBytes - The seed bytes (32 bytes for master key, 80 bytes for view/spend keys)
|
|
196
|
+
* @param type - The type of seed being imported
|
|
197
|
+
* @param force - Force setup even if HD is already enabled
|
|
198
|
+
* @returns True if setup was successful
|
|
199
|
+
*/
|
|
200
|
+
setupGeneration(seedBytes: Uint8Array, type?: SeedType, force?: boolean): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Get the master seed key
|
|
203
|
+
* @returns The master seed Scalar
|
|
204
|
+
*/
|
|
205
|
+
getMasterSeedKey(): ScalarType;
|
|
206
|
+
/**
|
|
207
|
+
* Get the private view key
|
|
208
|
+
* @returns The view key
|
|
209
|
+
*/
|
|
210
|
+
getPrivateViewKey(): ViewKeyType;
|
|
211
|
+
/**
|
|
212
|
+
* Get the public spending key
|
|
213
|
+
* @returns The public spending key
|
|
214
|
+
*/
|
|
215
|
+
getPublicSpendingKey(): PublicKeyType;
|
|
216
|
+
/**
|
|
217
|
+
* Get a sub-address for the given identifier
|
|
218
|
+
* Uses navio-blsct SubAddr.generate() method
|
|
219
|
+
* @param id - The sub-address identifier (defaults to account 0, address 0)
|
|
220
|
+
* @returns The sub-address (SubAddr)
|
|
221
|
+
*/
|
|
222
|
+
getSubAddress(id?: SubAddressIdentifier): SubAddrType;
|
|
223
|
+
/**
|
|
224
|
+
* Generate a new sub-address for the given account
|
|
225
|
+
* @param account - The account number (0 for main, -1 for change, -2 for staking)
|
|
226
|
+
* @returns The generated sub-address and its identifier
|
|
227
|
+
*/
|
|
228
|
+
generateNewSubAddress(account: number): {
|
|
229
|
+
subAddress: SubAddrType;
|
|
230
|
+
id: SubAddressIdentifier;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Get a new destination (sub-address) from the pool or generate one
|
|
234
|
+
* @param account - The account number
|
|
235
|
+
* @returns The sub-address destination (SubAddr)
|
|
236
|
+
*/
|
|
237
|
+
getNewDestination(account?: number): SubAddrType;
|
|
238
|
+
/**
|
|
239
|
+
* Create a new sub-address pool for an account
|
|
240
|
+
* @param account - The account number
|
|
241
|
+
* @returns True if successful
|
|
242
|
+
*/
|
|
243
|
+
newSubAddressPool(account: number): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Top up all sub-address pools
|
|
246
|
+
* @param size - Target size for pools (0 = use default)
|
|
247
|
+
* @returns True if successful
|
|
248
|
+
*/
|
|
249
|
+
topUp(size?: number): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Top up a specific account's sub-address pool
|
|
252
|
+
* @param account - The account number
|
|
253
|
+
* @param size - Target size (0 = use default)
|
|
254
|
+
* @returns True if successful
|
|
255
|
+
*/
|
|
256
|
+
topUpAccount(account: number, size?: number): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Get the size of the sub-address pool for an account
|
|
259
|
+
* @param account - The account number
|
|
260
|
+
* @returns The pool size
|
|
261
|
+
*/
|
|
262
|
+
getSubAddressPoolSize(account: number): number;
|
|
263
|
+
/**
|
|
264
|
+
* Calculate hash ID from blinding and spending keys
|
|
265
|
+
* Uses HashId.generate() from navio-blsct
|
|
266
|
+
* @param blindingKey - The blinding public key
|
|
267
|
+
* @param spendingKey - The spending public key
|
|
268
|
+
* @returns The hash ID (20 bytes)
|
|
269
|
+
*/
|
|
270
|
+
calculateHashId(blindingKey: PublicKeyType, spendingKey: PublicKeyType): Uint8Array;
|
|
271
|
+
/**
|
|
272
|
+
* Calculate view tag for output detection
|
|
273
|
+
* Uses ViewTag from navio-blsct
|
|
274
|
+
* @param blindingKey - The blinding public key
|
|
275
|
+
* @returns The view tag (16-bit number)
|
|
276
|
+
*/
|
|
277
|
+
calculateViewTag(blindingKey: PublicKeyType): number;
|
|
278
|
+
/**
|
|
279
|
+
* Calculate nonce for range proof recovery
|
|
280
|
+
* Uses calcNonce from navio-blsct
|
|
281
|
+
* @param blindingKey - The blinding public key
|
|
282
|
+
* @returns The nonce (Point)
|
|
283
|
+
*/
|
|
284
|
+
calculateNonce(blindingKey: PublicKeyType): any;
|
|
285
|
+
/**
|
|
286
|
+
* Get the HD chain information
|
|
287
|
+
* @returns The HD chain or null if not set
|
|
288
|
+
*/
|
|
289
|
+
getHDChain(): HDChain | null;
|
|
290
|
+
/**
|
|
291
|
+
* Load a key pair from storage into memory (used by LoadWallet)
|
|
292
|
+
* Replicates LoadKey from keyman.cpp
|
|
293
|
+
* @param secretKey - The secret key
|
|
294
|
+
* @param publicKey - The public key
|
|
295
|
+
* @returns True if successful
|
|
296
|
+
*/
|
|
297
|
+
loadKey(secretKey: ScalarType, publicKey: PublicKeyType): boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Load a view key from storage into memory
|
|
300
|
+
* Replicates LoadViewKey from keyman.cpp
|
|
301
|
+
* @param viewKey - The view key
|
|
302
|
+
* @param publicKey - The view key's public key
|
|
303
|
+
* @returns True if successful
|
|
304
|
+
*/
|
|
305
|
+
loadViewKey(viewKey: ViewKeyType): boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Load a spend key from storage into memory
|
|
308
|
+
* Replicates LoadSpendKey from keyman.cpp
|
|
309
|
+
* @param publicKey - The spending public key
|
|
310
|
+
* @returns True if successful
|
|
311
|
+
*/
|
|
312
|
+
loadSpendKey(publicKey: PublicKeyType): boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Load an output key from storage into memory
|
|
315
|
+
* Replicates LoadOutKey from keyman.cpp
|
|
316
|
+
* @param secretKey - The secret key for the output
|
|
317
|
+
* @param outId - The output ID (uint256)
|
|
318
|
+
* @returns True if successful
|
|
319
|
+
*/
|
|
320
|
+
loadOutKey(secretKey: ScalarType, outId: Uint8Array): boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Load an encrypted key from storage into memory
|
|
323
|
+
* Replicates LoadCryptedKey from keyman.cpp
|
|
324
|
+
* @param publicKey - The public key
|
|
325
|
+
* @param encryptedSecret - The encrypted secret key
|
|
326
|
+
* @param checksumValid - Whether the checksum is valid
|
|
327
|
+
* @returns True if successful
|
|
328
|
+
*/
|
|
329
|
+
loadCryptedKey(publicKey: PublicKeyType, encryptedSecret: Uint8Array, checksumValid: boolean): boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Load an encrypted output key from storage into memory
|
|
332
|
+
* Replicates LoadCryptedOutKey from keyman.cpp
|
|
333
|
+
* @param outId - The output ID
|
|
334
|
+
* @param publicKey - The public key
|
|
335
|
+
* @param encryptedSecret - The encrypted secret key
|
|
336
|
+
* @param checksumValid - Whether the checksum is valid
|
|
337
|
+
* @returns True if successful
|
|
338
|
+
*/
|
|
339
|
+
loadCryptedOutKey(outId: Uint8Array, publicKey: PublicKeyType, encryptedSecret: Uint8Array, checksumValid: boolean): boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Load HD chain from storage
|
|
342
|
+
* Replicates LoadHDChain from keyman.cpp
|
|
343
|
+
* @param chain - The HD chain to load
|
|
344
|
+
*/
|
|
345
|
+
loadHDChain(chain: HDChain): void;
|
|
346
|
+
/**
|
|
347
|
+
* Load key metadata from storage
|
|
348
|
+
* Replicates LoadKeyMetadata from keyman.cpp
|
|
349
|
+
* @param keyId - The key ID
|
|
350
|
+
* @param metadata - The key metadata
|
|
351
|
+
*/
|
|
352
|
+
loadKeyMetadata(keyId: Uint8Array, metadata: {
|
|
353
|
+
nCreateTime: number;
|
|
354
|
+
}): void;
|
|
355
|
+
/**
|
|
356
|
+
* Add a key pair and save to database
|
|
357
|
+
* Replicates AddKeyPubKey from keyman.cpp
|
|
358
|
+
* @param secretKey - The secret key
|
|
359
|
+
* @param publicKey - The public key
|
|
360
|
+
* @returns True if successful
|
|
361
|
+
*/
|
|
362
|
+
addKeyPubKey(secretKey: ScalarType, publicKey: PublicKeyType): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Add an output key and save to database
|
|
365
|
+
* Replicates AddKeyOutKey from keyman.cpp
|
|
366
|
+
* @param secretKey - The secret key
|
|
367
|
+
* @param outId - The output ID
|
|
368
|
+
* @returns True if successful
|
|
369
|
+
*/
|
|
370
|
+
addKeyOutKey(secretKey: ScalarType, outId: Uint8Array): boolean;
|
|
371
|
+
/**
|
|
372
|
+
* Add a view key and save to database
|
|
373
|
+
* Replicates AddViewKey from keyman.cpp
|
|
374
|
+
* @param viewKey - The view key
|
|
375
|
+
* @param publicKey - The view key's public key
|
|
376
|
+
* @returns True if successful
|
|
377
|
+
*/
|
|
378
|
+
addViewKey(viewKey: ViewKeyType, _publicKey: PublicKeyType): boolean;
|
|
379
|
+
/**
|
|
380
|
+
* Add a spend key and save to database
|
|
381
|
+
* Replicates AddSpendKey from keyman.cpp
|
|
382
|
+
* @param publicKey - The spending public key
|
|
383
|
+
* @returns True if successful
|
|
384
|
+
*/
|
|
385
|
+
addSpendKey(publicKey: PublicKeyType): boolean;
|
|
386
|
+
/**
|
|
387
|
+
* Add an encrypted key and save to database
|
|
388
|
+
* Replicates AddCryptedKey from keyman.cpp
|
|
389
|
+
* @param publicKey - The public key
|
|
390
|
+
* @param encryptedSecret - The encrypted secret key
|
|
391
|
+
* @returns True if successful
|
|
392
|
+
*/
|
|
393
|
+
addCryptedKey(publicKey: PublicKeyType, encryptedSecret: Uint8Array): boolean;
|
|
394
|
+
/**
|
|
395
|
+
* Add an encrypted output key and save to database
|
|
396
|
+
* Replicates AddCryptedOutKey from keyman.cpp
|
|
397
|
+
* @param outId - The output ID
|
|
398
|
+
* @param publicKey - The public key
|
|
399
|
+
* @param encryptedSecret - The encrypted secret key
|
|
400
|
+
* @returns True if successful
|
|
401
|
+
*/
|
|
402
|
+
addCryptedOutKey(outId: Uint8Array, publicKey: PublicKeyType, encryptedSecret: Uint8Array): boolean;
|
|
403
|
+
/**
|
|
404
|
+
* Add HD chain and save to database
|
|
405
|
+
* Replicates AddHDChain from keyman.cpp
|
|
406
|
+
* @param chain - The HD chain to add
|
|
407
|
+
*/
|
|
408
|
+
addHDChain(chain: HDChain): void;
|
|
409
|
+
/**
|
|
410
|
+
* Check if a key exists
|
|
411
|
+
* Replicates HaveKey from keyman.cpp
|
|
412
|
+
* @param keyId - The key ID (hash160 of public key)
|
|
413
|
+
* @returns True if the key exists
|
|
414
|
+
*/
|
|
415
|
+
haveKey(keyId: Uint8Array): boolean;
|
|
416
|
+
/**
|
|
417
|
+
* Get a key by key ID
|
|
418
|
+
* Replicates GetKey from keyman.cpp
|
|
419
|
+
* @param keyId - The key ID
|
|
420
|
+
* @returns The secret key or null if not found
|
|
421
|
+
*/
|
|
422
|
+
getKey(keyId: Uint8Array): ScalarType | null;
|
|
423
|
+
/**
|
|
424
|
+
* Get an output key by output ID
|
|
425
|
+
* Replicates GetOutKey from keyman.cpp
|
|
426
|
+
* @param outId - The output ID
|
|
427
|
+
* @returns The secret key or null if not found
|
|
428
|
+
*/
|
|
429
|
+
getOutKey(outId: Uint8Array): ScalarType | null;
|
|
430
|
+
/**
|
|
431
|
+
* Internal method to add a key pair (used by both Load and Add methods)
|
|
432
|
+
*/
|
|
433
|
+
private addKeyPubKeyInner;
|
|
434
|
+
/**
|
|
435
|
+
* Internal method to add an output key (used by both Load and Add methods)
|
|
436
|
+
*/
|
|
437
|
+
private addKeyOutKeyInner;
|
|
438
|
+
/**
|
|
439
|
+
* Internal method to add an encrypted key (used by both Load and Add methods)
|
|
440
|
+
*/
|
|
441
|
+
private addCryptedKeyInner;
|
|
442
|
+
/**
|
|
443
|
+
* Internal method to add an encrypted output key (used by both Load and Add methods)
|
|
444
|
+
*/
|
|
445
|
+
private addCryptedOutKeyInner;
|
|
446
|
+
/**
|
|
447
|
+
* Update the time of the first key
|
|
448
|
+
* Replicates UpdateTimeFirstKey from keyman.cpp
|
|
449
|
+
*/
|
|
450
|
+
private updateTimeFirstKey;
|
|
451
|
+
private getPublicKeyFromScalar;
|
|
452
|
+
private getPublicKeyFromViewKey;
|
|
453
|
+
private getPublicKeyBytes;
|
|
454
|
+
private createScalarFromBytes;
|
|
455
|
+
private createViewKeyFromBytes;
|
|
456
|
+
private createPublicKeyFromBytes;
|
|
457
|
+
/**
|
|
458
|
+
* Compute hash160 (SHA256 followed by RIPEMD160)
|
|
459
|
+
* This is the standard hash function used in Bitcoin-like systems
|
|
460
|
+
* @param data - The data to hash
|
|
461
|
+
* @returns The hash160 result (20 bytes)
|
|
462
|
+
*/
|
|
463
|
+
private hash160;
|
|
464
|
+
private bytesToHex;
|
|
465
|
+
/**
|
|
466
|
+
* Get the private spending key
|
|
467
|
+
* Replicates GetSpendingKey from keyman.cpp
|
|
468
|
+
* @returns The private spending key (Scalar)
|
|
469
|
+
*/
|
|
470
|
+
getSpendingKey(): ScalarType;
|
|
471
|
+
/**
|
|
472
|
+
* Get spending key for a transaction output
|
|
473
|
+
* Replicates GetSpendingKeyForOutput from keyman.cpp
|
|
474
|
+
* @param out - The transaction output
|
|
475
|
+
* @param key - Output parameter for the spending key
|
|
476
|
+
* @returns True if successful
|
|
477
|
+
*/
|
|
478
|
+
getSpendingKeyForOutput(out: CTxOut, key: {
|
|
479
|
+
value: ScalarType | null;
|
|
480
|
+
}): boolean;
|
|
481
|
+
/**
|
|
482
|
+
* Get spending key for a transaction output by hash ID
|
|
483
|
+
* @param out - The transaction output
|
|
484
|
+
* @param hashId - The hash ID
|
|
485
|
+
* @param key - Output parameter for the spending key
|
|
486
|
+
* @returns True if successful
|
|
487
|
+
*/
|
|
488
|
+
getSpendingKeyForOutputById(out: CTxOut, hashId: Uint8Array, key: {
|
|
489
|
+
value: ScalarType | null;
|
|
490
|
+
}): boolean;
|
|
491
|
+
/**
|
|
492
|
+
* Get spending key for a transaction output by sub-address identifier
|
|
493
|
+
* @param out - The transaction output
|
|
494
|
+
* @param id - The sub-address identifier
|
|
495
|
+
* @param key - Output parameter for the spending key
|
|
496
|
+
* @returns True if successful
|
|
497
|
+
*/
|
|
498
|
+
getSpendingKeyForOutputBySubAddress(out: CTxOut, id: SubAddressIdentifier, key: {
|
|
499
|
+
value: ScalarType | null;
|
|
500
|
+
}): boolean;
|
|
501
|
+
/**
|
|
502
|
+
* Get spending key for output with caching
|
|
503
|
+
* Replicates GetSpendingKeyForOutputWithCache from keyman.cpp
|
|
504
|
+
* @param out - The transaction output
|
|
505
|
+
* @param key - Output parameter for the spending key
|
|
506
|
+
* @returns True if successful
|
|
507
|
+
*/
|
|
508
|
+
getSpendingKeyForOutputWithCache(out: CTxOut, key: {
|
|
509
|
+
value: ScalarType | null;
|
|
510
|
+
}): boolean;
|
|
511
|
+
/**
|
|
512
|
+
* Get spending key for output with caching by hash ID
|
|
513
|
+
* @param out - The transaction output
|
|
514
|
+
* @param hashId - The hash ID
|
|
515
|
+
* @param key - Output parameter for the spending key
|
|
516
|
+
* @returns True if successful
|
|
517
|
+
*/
|
|
518
|
+
getSpendingKeyForOutputWithCacheById(out: CTxOut, hashId: Uint8Array, key: {
|
|
519
|
+
value: ScalarType | null;
|
|
520
|
+
}): boolean;
|
|
521
|
+
/**
|
|
522
|
+
* Get spending key for output with caching by sub-address
|
|
523
|
+
* @param out - The transaction output
|
|
524
|
+
* @param id - The sub-address identifier
|
|
525
|
+
* @param key - Output parameter for the spending key
|
|
526
|
+
* @returns True if successful
|
|
527
|
+
*/
|
|
528
|
+
getSpendingKeyForOutputWithCacheBySubAddress(out: CTxOut, id: SubAddressIdentifier, key: {
|
|
529
|
+
value: ScalarType | null;
|
|
530
|
+
}): boolean;
|
|
531
|
+
/**
|
|
532
|
+
* Check if a transaction output belongs to this wallet
|
|
533
|
+
* Replicates IsMine(txout) from keyman.cpp
|
|
534
|
+
* @param txout - The transaction output
|
|
535
|
+
* @returns True if the output belongs to this wallet
|
|
536
|
+
*/
|
|
537
|
+
isMine(txout: CTxOut): boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Check if output belongs to wallet by keys
|
|
540
|
+
* Replicates IsMine(blindingKey, spendingKey, viewTag) from keyman.cpp
|
|
541
|
+
* @param blindingKey - The blinding public key
|
|
542
|
+
* @param spendingKey - The spending public key
|
|
543
|
+
* @param viewTag - The view tag
|
|
544
|
+
* @returns True if the output belongs to this wallet
|
|
545
|
+
*/
|
|
546
|
+
isMineByKeys(blindingKey: PublicKeyType, spendingKey: PublicKeyType, viewTag: number): boolean;
|
|
547
|
+
/**
|
|
548
|
+
* Check if a script belongs to this wallet
|
|
549
|
+
* Replicates IsMine(script) from keyman.cpp
|
|
550
|
+
* @param script - The script
|
|
551
|
+
* @returns True if the script belongs to this wallet
|
|
552
|
+
*/
|
|
553
|
+
isMineByScript(_script: Uint8Array): boolean;
|
|
554
|
+
/**
|
|
555
|
+
* Get hash ID from transaction output
|
|
556
|
+
* Replicates GetHashId(txout) from keyman.cpp
|
|
557
|
+
* @param txout - The transaction output
|
|
558
|
+
* @returns The hash ID (20 bytes) or empty if not valid
|
|
559
|
+
*/
|
|
560
|
+
getHashIdFromTxOut(txout: CTxOut): Uint8Array;
|
|
561
|
+
/**
|
|
562
|
+
* Get hash ID from keys (public API)
|
|
563
|
+
* Replicates GetHashId(blindingKey, spendingKey) from keyman.cpp
|
|
564
|
+
* @param blindingKey - The blinding public key
|
|
565
|
+
* @param spendingKey - The spending public key
|
|
566
|
+
* @returns The hash ID (20 bytes)
|
|
567
|
+
*/
|
|
568
|
+
getHashId(blindingKey: PublicKeyType, spendingKey: PublicKeyType): Uint8Array;
|
|
569
|
+
/**
|
|
570
|
+
* Get destination from transaction output
|
|
571
|
+
* Replicates GetDestination from keyman.cpp
|
|
572
|
+
* @param txout - The transaction output
|
|
573
|
+
* @returns The destination (SubAddress keys) or null
|
|
574
|
+
*/
|
|
575
|
+
getDestination(txout: CTxOut): CTxDestination | null;
|
|
576
|
+
/**
|
|
577
|
+
* Check if output is a change output
|
|
578
|
+
* Replicates OutputIsChange from keyman.cpp
|
|
579
|
+
* @param out - The transaction output
|
|
580
|
+
* @returns True if it's a change output (account -1)
|
|
581
|
+
*/
|
|
582
|
+
outputIsChange(out: CTxOut): boolean;
|
|
583
|
+
/**
|
|
584
|
+
* Get master token key
|
|
585
|
+
* Replicates GetMasterTokenKey from keyman.cpp
|
|
586
|
+
* @returns The master token key (Scalar)
|
|
587
|
+
*/
|
|
588
|
+
getMasterTokenKey(): ScalarType;
|
|
589
|
+
/**
|
|
590
|
+
* Recover amounts from transaction outputs
|
|
591
|
+
* Replicates RecoverOutputs from keyman.cpp
|
|
592
|
+
* Uses navio-blsct recoverAmount function
|
|
593
|
+
* Reference: https://nav-io.github.io/libblsct-bindings/ts/functions/recoverAmount.html
|
|
594
|
+
* @param outs - Array of transaction outputs
|
|
595
|
+
* @returns Recovery result with amounts and indices
|
|
596
|
+
*/
|
|
597
|
+
recoverOutputs(outs: CTxOut[]): AmountRecoveryResult;
|
|
598
|
+
/**
|
|
599
|
+
* Recover amounts from transaction outputs with nonce
|
|
600
|
+
* Replicates RecoverOutputsWithNonce from keyman.cpp
|
|
601
|
+
* @param outs - Array of transaction outputs
|
|
602
|
+
* @param nonce - The nonce (PublicKey)
|
|
603
|
+
* @returns Recovery result with amounts and indices
|
|
604
|
+
*/
|
|
605
|
+
recoverOutputsWithNonce(outs: CTxOut[], nonce: PublicKeyType): AmountRecoveryResult;
|
|
606
|
+
/**
|
|
607
|
+
* Load sub-address mapping from storage
|
|
608
|
+
* Replicates LoadSubAddress from keyman.cpp
|
|
609
|
+
* @param hashId - The hash ID
|
|
610
|
+
* @param index - The sub-address identifier
|
|
611
|
+
*/
|
|
612
|
+
loadSubAddress(hashId: Uint8Array, index: SubAddressIdentifier): void;
|
|
613
|
+
/**
|
|
614
|
+
* Add sub-address mapping and save to database
|
|
615
|
+
* Replicates AddSubAddress from keyman.cpp
|
|
616
|
+
* @param hashId - The hash ID
|
|
617
|
+
* @param index - The sub-address identifier
|
|
618
|
+
* @returns True if successful
|
|
619
|
+
*/
|
|
620
|
+
addSubAddress(hashId: Uint8Array, index: SubAddressIdentifier): boolean;
|
|
621
|
+
/**
|
|
622
|
+
* Check if sub-address exists by hash ID
|
|
623
|
+
* Replicates HaveSubAddress from keyman.cpp
|
|
624
|
+
* @param hashId - The hash ID
|
|
625
|
+
* @returns True if the sub-address exists
|
|
626
|
+
*/
|
|
627
|
+
haveSubAddress(hashId: Uint8Array): boolean;
|
|
628
|
+
/**
|
|
629
|
+
* Get sub-address by hash ID
|
|
630
|
+
* Replicates GetSubAddress(hashId) from keyman.cpp
|
|
631
|
+
* @param hashId - The hash ID
|
|
632
|
+
* @param address - Output parameter for the sub-address
|
|
633
|
+
* @returns True if successful
|
|
634
|
+
*/
|
|
635
|
+
getSubAddressByHashId(hashId: Uint8Array, address: {
|
|
636
|
+
value: SubAddrType | null;
|
|
637
|
+
}): boolean;
|
|
638
|
+
/**
|
|
639
|
+
* Get sub-address identifier from hash ID
|
|
640
|
+
* Replicates GetSubAddressId from keyman.cpp
|
|
641
|
+
* @param hashId - The hash ID
|
|
642
|
+
* @param id - Output parameter for the sub-address identifier
|
|
643
|
+
* @returns True if successful
|
|
644
|
+
*/
|
|
645
|
+
getSubAddressId(hashId: Uint8Array, id: SubAddressIdentifier): boolean;
|
|
646
|
+
/**
|
|
647
|
+
* Load sub-address string mapping from storage
|
|
648
|
+
* Replicates LoadSubAddressStr from keyman.cpp
|
|
649
|
+
* @param subAddress - The sub-address
|
|
650
|
+
* @param hashId - The hash ID
|
|
651
|
+
*/
|
|
652
|
+
loadSubAddressStr(subAddress: SubAddrType, hashId: Uint8Array): void;
|
|
653
|
+
/**
|
|
654
|
+
* Add sub-address string mapping and save to database
|
|
655
|
+
* Replicates AddSubAddressStr from keyman.cpp
|
|
656
|
+
* @param subAddress - The sub-address
|
|
657
|
+
* @param hashId - The hash ID
|
|
658
|
+
* @returns True if successful
|
|
659
|
+
*/
|
|
660
|
+
addSubAddressStr(subAddress: SubAddrType, hashId: Uint8Array): boolean;
|
|
661
|
+
/**
|
|
662
|
+
* Check if sub-address string exists
|
|
663
|
+
* Replicates HaveSubAddressStr from keyman.cpp
|
|
664
|
+
* @param subAddress - The sub-address
|
|
665
|
+
* @returns True if the sub-address string exists
|
|
666
|
+
*/
|
|
667
|
+
haveSubAddressStr(subAddress: SubAddrType): boolean;
|
|
668
|
+
/**
|
|
669
|
+
* Reserve sub-address from pool
|
|
670
|
+
* Replicates ReserveSubAddressFromPool from keyman.cpp
|
|
671
|
+
* @param account - The account number
|
|
672
|
+
* @param nIndex - Output parameter for the address index
|
|
673
|
+
* @param keypool - Output parameter for the keypool entry
|
|
674
|
+
*/
|
|
675
|
+
reserveSubAddressFromPool(account: number, nIndex: {
|
|
676
|
+
value: number;
|
|
677
|
+
}, keypool: {
|
|
678
|
+
value: {
|
|
679
|
+
id: SubAddressIdentifier;
|
|
680
|
+
subAddress: SubAddrType;
|
|
681
|
+
} | null;
|
|
682
|
+
}): void;
|
|
683
|
+
/**
|
|
684
|
+
* Keep a sub-address (mark as used)
|
|
685
|
+
* Replicates KeepSubAddress from keyman.cpp
|
|
686
|
+
* @param id - The sub-address identifier
|
|
687
|
+
*/
|
|
688
|
+
keepSubAddress(id: SubAddressIdentifier): void;
|
|
689
|
+
/**
|
|
690
|
+
* Return sub-address to pool
|
|
691
|
+
* Replicates ReturnSubAddress from keyman.cpp
|
|
692
|
+
* @param id - The sub-address identifier
|
|
693
|
+
*/
|
|
694
|
+
returnSubAddress(id: SubAddressIdentifier): void;
|
|
695
|
+
/**
|
|
696
|
+
* Get sub-address from pool
|
|
697
|
+
* Replicates GetSubAddressFromPool from keyman.cpp
|
|
698
|
+
* @param account - The account number
|
|
699
|
+
* @param result - Output parameter for the hash ID
|
|
700
|
+
* @param id - Output parameter for the sub-address identifier
|
|
701
|
+
* @returns True if successful
|
|
702
|
+
*/
|
|
703
|
+
getSubAddressFromPool(account: number, result: {
|
|
704
|
+
value: Uint8Array | null;
|
|
705
|
+
}, id: {
|
|
706
|
+
value: SubAddressIdentifier | null;
|
|
707
|
+
}): boolean;
|
|
708
|
+
/**
|
|
709
|
+
* Get oldest sub-address pool time
|
|
710
|
+
* Replicates GetOldestSubAddressPoolTime from keyman.cpp
|
|
711
|
+
* @param account - The account number
|
|
712
|
+
* @returns The oldest time or 0 if pool is empty
|
|
713
|
+
*/
|
|
714
|
+
getOldestSubAddressPoolTime(account: number): number;
|
|
715
|
+
/**
|
|
716
|
+
* Add inactive HD chain
|
|
717
|
+
* Replicates AddInactiveHDChain from keyman.cpp
|
|
718
|
+
* @param chain - The HD chain to add
|
|
719
|
+
*/
|
|
720
|
+
addInactiveHDChain(_chain: HDChain): void;
|
|
721
|
+
/**
|
|
722
|
+
* Get time of first key
|
|
723
|
+
* Replicates GetTimeFirstKey from keyman.cpp
|
|
724
|
+
* @returns The creation time of the first key
|
|
725
|
+
*/
|
|
726
|
+
getTimeFirstKey(): number;
|
|
727
|
+
/**
|
|
728
|
+
* Extract spending key from script
|
|
729
|
+
* Replicates ExtractSpendingKeyFromScript from keyman.cpp
|
|
730
|
+
* @param script - The script
|
|
731
|
+
* @param spendingKey - Output parameter for the spending key
|
|
732
|
+
* @returns True if successful
|
|
733
|
+
*/
|
|
734
|
+
extractSpendingKeyFromScript(_script: Uint8Array, _spendingKey: {
|
|
735
|
+
value: PublicKeyType | null;
|
|
736
|
+
}): boolean;
|
|
737
|
+
/**
|
|
738
|
+
* Check if public key is zero
|
|
739
|
+
*/
|
|
740
|
+
private isPublicKeyZero;
|
|
741
|
+
/**
|
|
742
|
+
* Get scalar from ViewKey
|
|
743
|
+
*/
|
|
744
|
+
private getScalarFromViewKey;
|
|
745
|
+
/**
|
|
746
|
+
* Get scalar from Scalar (identity function, but ensures type)
|
|
747
|
+
*/
|
|
748
|
+
private getScalarFromScalar;
|
|
749
|
+
/**
|
|
750
|
+
* Get bytes from Scalar
|
|
751
|
+
*/
|
|
752
|
+
private getScalarBytes;
|
|
753
|
+
/**
|
|
754
|
+
* Serialize SubAddress to string for map key
|
|
755
|
+
*/
|
|
756
|
+
private serializeSubAddress;
|
|
757
|
+
/**
|
|
758
|
+
* Get hash ID from SubAddress
|
|
759
|
+
* Uses DoublePublicKey.deserialize(subaddress.serialize()) to extract keys
|
|
760
|
+
*/
|
|
761
|
+
private getHashIdFromSubAddress;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* WalletDB - Database persistence layer for KeyManager
|
|
766
|
+
* Uses SQL.js (SQLite compiled to WebAssembly) for cross-platform compatibility
|
|
767
|
+
* Works on web browsers, Node.js, and mobile platforms
|
|
768
|
+
*
|
|
769
|
+
* Database schema replicates navio-core wallet database structure
|
|
770
|
+
*/
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Wallet output structure returned by getUnspentOutputs and getAllOutputs
|
|
774
|
+
*/
|
|
775
|
+
interface WalletOutput {
|
|
776
|
+
outputHash: string;
|
|
777
|
+
txHash: string;
|
|
778
|
+
outputIndex: number;
|
|
779
|
+
blockHeight: number;
|
|
780
|
+
amount: bigint;
|
|
781
|
+
memo: string | null;
|
|
782
|
+
tokenId: string | null;
|
|
783
|
+
blindingKey: string;
|
|
784
|
+
spendingKey: string;
|
|
785
|
+
isSpent: boolean;
|
|
786
|
+
spentTxHash: string | null;
|
|
787
|
+
spentBlockHeight: number | null;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* WalletDB - Manages wallet database persistence.
|
|
791
|
+
*
|
|
792
|
+
* Uses SQL.js (SQLite compiled to WebAssembly) for cross-platform compatibility.
|
|
793
|
+
* Works on web browsers, Node.js, and mobile platforms.
|
|
794
|
+
*
|
|
795
|
+
* @category Wallet
|
|
796
|
+
*/
|
|
797
|
+
declare class WalletDB {
|
|
798
|
+
private db;
|
|
799
|
+
private dbPath;
|
|
800
|
+
private keyManager;
|
|
801
|
+
private isOpen;
|
|
802
|
+
/**
|
|
803
|
+
* Create a new WalletDB instance
|
|
804
|
+
* @param dbPath - Path to the database file (or name for in-memory)
|
|
805
|
+
* @param createIfNotExists - Create database if it doesn't exist
|
|
806
|
+
*/
|
|
807
|
+
constructor(dbPath?: string, _createIfNotExists?: boolean);
|
|
808
|
+
/**
|
|
809
|
+
* Initialize the database connection and schema
|
|
810
|
+
*/
|
|
811
|
+
private initDatabase;
|
|
812
|
+
/**
|
|
813
|
+
* Get file system interface (Node.js only)
|
|
814
|
+
*/
|
|
815
|
+
private getFileSystem;
|
|
816
|
+
/**
|
|
817
|
+
* Create database schema
|
|
818
|
+
* Replicates navio-core wallet database structure
|
|
819
|
+
*/
|
|
820
|
+
private createSchema;
|
|
821
|
+
/**
|
|
822
|
+
* Load wallet from database
|
|
823
|
+
* @returns The loaded KeyManager instance
|
|
824
|
+
* @throws Error if no wallet exists in the database
|
|
825
|
+
*/
|
|
826
|
+
loadWallet(): Promise<KeyManager>;
|
|
827
|
+
/**
|
|
828
|
+
* Create a new wallet
|
|
829
|
+
* @param creationHeight - Optional block height when wallet was created (for sync optimization)
|
|
830
|
+
* @returns The new KeyManager instance
|
|
831
|
+
*/
|
|
832
|
+
createWallet(creationHeight?: number): Promise<KeyManager>;
|
|
833
|
+
/**
|
|
834
|
+
* Restore wallet from seed
|
|
835
|
+
* @param seedHex - The seed as hex string
|
|
836
|
+
* @param creationHeight - Optional block height to start scanning from (for faster restore)
|
|
837
|
+
* @returns The restored KeyManager instance
|
|
838
|
+
*/
|
|
839
|
+
restoreWallet(seedHex: string, creationHeight?: number): Promise<KeyManager>;
|
|
840
|
+
/**
|
|
841
|
+
* Save wallet metadata to database
|
|
842
|
+
*/
|
|
843
|
+
private saveWalletMetadata;
|
|
844
|
+
/**
|
|
845
|
+
* Persist database to disk (if not in-memory)
|
|
846
|
+
*/
|
|
847
|
+
private persistToDisk;
|
|
848
|
+
/**
|
|
849
|
+
* Get wallet metadata from database
|
|
850
|
+
* @returns Wallet metadata or null if not found
|
|
851
|
+
*/
|
|
852
|
+
getWalletMetadata(): Promise<{
|
|
853
|
+
creationHeight: number;
|
|
854
|
+
creationTime: number;
|
|
855
|
+
restoredFromSeed: boolean;
|
|
856
|
+
version: number;
|
|
857
|
+
} | null>;
|
|
858
|
+
/**
|
|
859
|
+
* Get the wallet creation height (block height to start scanning from)
|
|
860
|
+
* @returns Creation height or 0 if not set
|
|
861
|
+
*/
|
|
862
|
+
getCreationHeight(): Promise<number>;
|
|
863
|
+
/**
|
|
864
|
+
* Set the wallet creation height
|
|
865
|
+
* @param height - Block height
|
|
866
|
+
*/
|
|
867
|
+
setCreationHeight(height: number): Promise<void>;
|
|
868
|
+
/**
|
|
869
|
+
* Save wallet to database
|
|
870
|
+
* @param keyManager - The KeyManager instance to save (optional, uses stored instance if not provided)
|
|
871
|
+
*/
|
|
872
|
+
saveWallet(keyManager?: KeyManager): Promise<void>;
|
|
873
|
+
/**
|
|
874
|
+
* Get the current KeyManager instance
|
|
875
|
+
*/
|
|
876
|
+
getKeyManager(): KeyManager | null;
|
|
877
|
+
/**
|
|
878
|
+
* Get the database instance (for use by sync modules)
|
|
879
|
+
* @internal
|
|
880
|
+
*/
|
|
881
|
+
getDatabase(): any;
|
|
882
|
+
/**
|
|
883
|
+
* Get the database path
|
|
884
|
+
* @internal
|
|
885
|
+
*/
|
|
886
|
+
getDatabasePath(): string;
|
|
887
|
+
/**
|
|
888
|
+
* Save database to disk (if not in-memory)
|
|
889
|
+
*/
|
|
890
|
+
saveDatabase(): Promise<void>;
|
|
891
|
+
/**
|
|
892
|
+
* Close the database connection
|
|
893
|
+
*/
|
|
894
|
+
close(): void;
|
|
895
|
+
private deserializeScalar;
|
|
896
|
+
private serializeViewKey;
|
|
897
|
+
private deserializeViewKey;
|
|
898
|
+
private serializePublicKey;
|
|
899
|
+
private deserializePublicKey;
|
|
900
|
+
private getPublicKeyFromViewKey;
|
|
901
|
+
private bytesToHex;
|
|
902
|
+
private hexToBytes;
|
|
903
|
+
/**
|
|
904
|
+
* Get wallet balance (sum of unspent output amounts)
|
|
905
|
+
* @param tokenId - Optional token ID to filter by (null for NAV)
|
|
906
|
+
* @returns Balance in satoshis
|
|
907
|
+
*/
|
|
908
|
+
getBalance(tokenId?: string | null): Promise<bigint>;
|
|
909
|
+
/**
|
|
910
|
+
* Get unspent outputs (UTXOs)
|
|
911
|
+
* @param tokenId - Optional token ID to filter by (null for NAV)
|
|
912
|
+
* @returns Array of unspent outputs
|
|
913
|
+
*/
|
|
914
|
+
getUnspentOutputs(tokenId?: string | null): Promise<WalletOutput[]>;
|
|
915
|
+
/**
|
|
916
|
+
* Get all outputs (spent and unspent)
|
|
917
|
+
* @returns Array of all wallet outputs
|
|
918
|
+
*/
|
|
919
|
+
getAllOutputs(): Promise<WalletOutput[]>;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Electrum Client - Connect and interact with Electrum servers
|
|
924
|
+
*
|
|
925
|
+
* Supports WebSocket and TCP connections
|
|
926
|
+
* Implements Electrum protocol for fetching transaction keys and blockchain data
|
|
927
|
+
*
|
|
928
|
+
* Based on electrumx server implementation and Navio-specific extensions
|
|
929
|
+
*/
|
|
930
|
+
/**
|
|
931
|
+
* Electrum server connection options
|
|
932
|
+
*/
|
|
933
|
+
interface ElectrumOptions {
|
|
934
|
+
/** Server host (default: localhost) */
|
|
935
|
+
host?: string;
|
|
936
|
+
/** Server port (default: 50001) */
|
|
937
|
+
port?: number;
|
|
938
|
+
/** Use SSL/TLS (default: false) */
|
|
939
|
+
ssl?: boolean;
|
|
940
|
+
/** Connection timeout in milliseconds (default: 30000) */
|
|
941
|
+
timeout?: number;
|
|
942
|
+
/** Client name for server.version (default: 'navio-sdk') */
|
|
943
|
+
clientName?: string;
|
|
944
|
+
/** Client version for server.version (default: '1.4') */
|
|
945
|
+
clientVersion?: string;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Transaction keys structure
|
|
949
|
+
* Represents the keys associated with a transaction
|
|
950
|
+
*/
|
|
951
|
+
interface TransactionKeys {
|
|
952
|
+
/** Transaction hash */
|
|
953
|
+
txHash: string;
|
|
954
|
+
/** Transaction keys (structure depends on coin implementation) */
|
|
955
|
+
keys: any;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Block transaction keys
|
|
959
|
+
* Contains all transaction keys for a block
|
|
960
|
+
*/
|
|
961
|
+
interface BlockTransactionKeys {
|
|
962
|
+
/** Block height */
|
|
963
|
+
height: number;
|
|
964
|
+
/** Transaction keys for this block */
|
|
965
|
+
txKeys: TransactionKeys[];
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Range result for block transaction keys
|
|
969
|
+
*/
|
|
970
|
+
interface BlockTransactionKeysRange {
|
|
971
|
+
/** Blocks with their transaction keys */
|
|
972
|
+
blocks: BlockTransactionKeys[];
|
|
973
|
+
/** Next height to query (for pagination) */
|
|
974
|
+
nextHeight: number;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Block header information
|
|
978
|
+
*/
|
|
979
|
+
interface BlockHeader {
|
|
980
|
+
/** Block height */
|
|
981
|
+
height: number;
|
|
982
|
+
/** Block hash */
|
|
983
|
+
hash: string;
|
|
984
|
+
/** Previous block hash */
|
|
985
|
+
prevHash: string;
|
|
986
|
+
/** Merkle root */
|
|
987
|
+
merkleRoot: string;
|
|
988
|
+
/** Block timestamp */
|
|
989
|
+
timestamp: number;
|
|
990
|
+
/** Block version */
|
|
991
|
+
version: number;
|
|
992
|
+
/** Difficulty target */
|
|
993
|
+
bits: number;
|
|
994
|
+
/** Nonce */
|
|
995
|
+
nonce: number;
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Electrum RPC error
|
|
999
|
+
*/
|
|
1000
|
+
declare class ElectrumError extends Error {
|
|
1001
|
+
code?: number | undefined;
|
|
1002
|
+
data?: any | undefined;
|
|
1003
|
+
constructor(message: string, code?: number | undefined, data?: any | undefined);
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Electrum Client - Connects to Electrum servers.
|
|
1007
|
+
*
|
|
1008
|
+
* Low-level client for the Electrum protocol. For most use cases,
|
|
1009
|
+
* use NavioClient with the 'electrum' backend instead.
|
|
1010
|
+
*
|
|
1011
|
+
* @category Protocol
|
|
1012
|
+
*/
|
|
1013
|
+
declare class ElectrumClient {
|
|
1014
|
+
private ws;
|
|
1015
|
+
private requestId;
|
|
1016
|
+
private pendingRequests;
|
|
1017
|
+
private connected;
|
|
1018
|
+
private options;
|
|
1019
|
+
private reconnectAttempts;
|
|
1020
|
+
constructor(options?: ElectrumOptions);
|
|
1021
|
+
/**
|
|
1022
|
+
* Connect to the Electrum server
|
|
1023
|
+
*/
|
|
1024
|
+
connect(): Promise<void>;
|
|
1025
|
+
/**
|
|
1026
|
+
* Handle incoming response from server
|
|
1027
|
+
*/
|
|
1028
|
+
private handleResponse;
|
|
1029
|
+
/**
|
|
1030
|
+
* Make an RPC call to the Electrum server
|
|
1031
|
+
* @param method - RPC method name
|
|
1032
|
+
* @param params - Method parameters
|
|
1033
|
+
* @returns Promise resolving to the result
|
|
1034
|
+
*/
|
|
1035
|
+
call(method: string, ...params: any[]): Promise<any>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Disconnect from the server
|
|
1038
|
+
*/
|
|
1039
|
+
disconnect(): void;
|
|
1040
|
+
/**
|
|
1041
|
+
* Check if connected to server
|
|
1042
|
+
*/
|
|
1043
|
+
isConnected(): boolean;
|
|
1044
|
+
/**
|
|
1045
|
+
* Get server version
|
|
1046
|
+
* @returns Server version information
|
|
1047
|
+
*/
|
|
1048
|
+
getServerVersion(): Promise<[string, string]>;
|
|
1049
|
+
/**
|
|
1050
|
+
* Get block header for a given height
|
|
1051
|
+
* @param height - Block height
|
|
1052
|
+
* @returns Block header
|
|
1053
|
+
*/
|
|
1054
|
+
getBlockHeader(height: number): Promise<string>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Get block headers for a range of heights
|
|
1057
|
+
* @param startHeight - Starting block height
|
|
1058
|
+
* @param count - Number of headers to fetch
|
|
1059
|
+
* @returns Block headers
|
|
1060
|
+
*/
|
|
1061
|
+
getBlockHeaders(startHeight: number, count: number): Promise<{
|
|
1062
|
+
count: number;
|
|
1063
|
+
hex: string;
|
|
1064
|
+
max: number;
|
|
1065
|
+
}>;
|
|
1066
|
+
/**
|
|
1067
|
+
* Subscribe to block headers
|
|
1068
|
+
* @param callback - Callback function for new headers
|
|
1069
|
+
*/
|
|
1070
|
+
subscribeBlockHeaders(callback: (header: any) => void): Promise<void>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Get chain tip height
|
|
1073
|
+
* @returns Current chain tip height
|
|
1074
|
+
*/
|
|
1075
|
+
getChainTipHeight(): Promise<number>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Get transaction keys for a specific transaction
|
|
1078
|
+
* @param txHash - Transaction hash (hex string)
|
|
1079
|
+
* @returns Transaction keys
|
|
1080
|
+
*/
|
|
1081
|
+
getTransactionKeys(txHash: string): Promise<any>;
|
|
1082
|
+
/**
|
|
1083
|
+
* Get all transaction keys for a block
|
|
1084
|
+
* @param height - Block height
|
|
1085
|
+
* @returns Array of transaction keys for the block
|
|
1086
|
+
*/
|
|
1087
|
+
getBlockTransactionKeys(height: number): Promise<any[]>;
|
|
1088
|
+
/**
|
|
1089
|
+
* Get transaction keys for a range of blocks (paginated)
|
|
1090
|
+
* @param startHeight - Starting block height
|
|
1091
|
+
* @returns Range result with blocks and next height
|
|
1092
|
+
*/
|
|
1093
|
+
getBlockTransactionKeysRange(startHeight: number): Promise<BlockTransactionKeysRange>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Fetch all transaction keys from genesis to chain tip
|
|
1096
|
+
* @param progressCallback - Optional callback for progress updates
|
|
1097
|
+
* @returns Array of all block transaction keys
|
|
1098
|
+
*/
|
|
1099
|
+
fetchAllTransactionKeys(progressCallback?: (height: number, totalHeight: number, blocksProcessed: number) => void): Promise<BlockTransactionKeys[]>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Get serialized transaction output by output hash (Navio-specific)
|
|
1102
|
+
* @param outputHash - Output hash (hex string)
|
|
1103
|
+
* @returns Serialized output (hex string)
|
|
1104
|
+
*/
|
|
1105
|
+
getTransactionOutput(outputHash: string): Promise<string>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Get raw transaction
|
|
1108
|
+
* @param txHash - Transaction hash (hex string)
|
|
1109
|
+
* @param verbose - Return verbose transaction data
|
|
1110
|
+
* @param blockHash - Optional block hash for context
|
|
1111
|
+
* @returns Raw transaction or verbose transaction data
|
|
1112
|
+
*/
|
|
1113
|
+
getRawTransaction(txHash: string, verbose?: boolean, blockHash?: string): Promise<string | any>;
|
|
1114
|
+
/**
|
|
1115
|
+
* Broadcast a transaction
|
|
1116
|
+
* @param rawTx - Raw transaction (hex string)
|
|
1117
|
+
* @returns Transaction hash if successful
|
|
1118
|
+
*/
|
|
1119
|
+
broadcastTransaction(rawTx: string): Promise<string>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Get transaction history for a script hash
|
|
1122
|
+
* @param scriptHash - Script hash (hex string, reversed)
|
|
1123
|
+
* @returns Transaction history
|
|
1124
|
+
*/
|
|
1125
|
+
getHistory(scriptHash: string): Promise<any[]>;
|
|
1126
|
+
/**
|
|
1127
|
+
* Get unspent transaction outputs for a script hash
|
|
1128
|
+
* @param scriptHash - Script hash (hex string, reversed)
|
|
1129
|
+
* @returns Unspent outputs
|
|
1130
|
+
*/
|
|
1131
|
+
getUnspent(scriptHash: string): Promise<any[]>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Subscribe to script hash updates
|
|
1134
|
+
* @param scriptHash - Script hash (hex string, reversed)
|
|
1135
|
+
* @param callback - Callback for status updates
|
|
1136
|
+
*/
|
|
1137
|
+
subscribeScriptHash(scriptHash: string, callback: (status: string) => void): Promise<void>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Calculate script hash from address (for Electrum protocol)
|
|
1140
|
+
* @param address - Address string
|
|
1141
|
+
* @returns Script hash (hex string, reversed for Electrum)
|
|
1142
|
+
*/
|
|
1143
|
+
static calculateScriptHash(address: string): string;
|
|
1144
|
+
/**
|
|
1145
|
+
* Reverse a hex string (for Electrum protocol hash format)
|
|
1146
|
+
* @param hex - Hex string
|
|
1147
|
+
* @returns Reversed hex string
|
|
1148
|
+
*/
|
|
1149
|
+
static reverseHex(hex: string): string;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Sync Provider Interface
|
|
1154
|
+
*
|
|
1155
|
+
* Abstract interface for blockchain synchronization providers.
|
|
1156
|
+
* Supports multiple backends: Electrum, P2P, or custom implementations.
|
|
1157
|
+
*/
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* Block header information (for sync provider)
|
|
1161
|
+
*/
|
|
1162
|
+
interface SyncBlockHeader {
|
|
1163
|
+
/** Block height */
|
|
1164
|
+
height: number;
|
|
1165
|
+
/** Block hash (hex string, little-endian display format) */
|
|
1166
|
+
hash: string;
|
|
1167
|
+
/** Previous block hash */
|
|
1168
|
+
prevHash: string;
|
|
1169
|
+
/** Merkle root */
|
|
1170
|
+
merkleRoot: string;
|
|
1171
|
+
/** Block timestamp */
|
|
1172
|
+
timestamp: number;
|
|
1173
|
+
/** Block version */
|
|
1174
|
+
version: number;
|
|
1175
|
+
/** Difficulty target (bits) */
|
|
1176
|
+
bits: number;
|
|
1177
|
+
/** Nonce */
|
|
1178
|
+
nonce: number;
|
|
1179
|
+
/** Raw header hex (80 bytes) */
|
|
1180
|
+
rawHex?: string;
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Block headers result (for batch fetches)
|
|
1184
|
+
*/
|
|
1185
|
+
interface BlockHeadersResult {
|
|
1186
|
+
/** Number of headers returned */
|
|
1187
|
+
count: number;
|
|
1188
|
+
/** Concatenated headers hex */
|
|
1189
|
+
hex: string;
|
|
1190
|
+
/** Maximum headers the server can return */
|
|
1191
|
+
max?: number;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Chain tip information
|
|
1195
|
+
*/
|
|
1196
|
+
interface ChainTip {
|
|
1197
|
+
/** Current chain height */
|
|
1198
|
+
height: number;
|
|
1199
|
+
/** Block hash at tip */
|
|
1200
|
+
hash: string;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Sync provider options
|
|
1204
|
+
*/
|
|
1205
|
+
interface SyncProviderOptions {
|
|
1206
|
+
/** Connection timeout in milliseconds */
|
|
1207
|
+
timeout?: number;
|
|
1208
|
+
/** Enable debug logging */
|
|
1209
|
+
debug?: boolean;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Abstract sync provider interface
|
|
1213
|
+
*
|
|
1214
|
+
* Implementations must provide methods for:
|
|
1215
|
+
* - Connecting/disconnecting
|
|
1216
|
+
* - Fetching block headers
|
|
1217
|
+
* - Fetching transaction keys for wallet scanning
|
|
1218
|
+
* - Fetching transaction outputs by hash
|
|
1219
|
+
* - Broadcasting transactions
|
|
1220
|
+
*
|
|
1221
|
+
* @category Sync
|
|
1222
|
+
*/
|
|
1223
|
+
interface SyncProvider {
|
|
1224
|
+
/**
|
|
1225
|
+
* Provider type identifier
|
|
1226
|
+
*/
|
|
1227
|
+
readonly type: 'electrum' | 'p2p' | 'custom';
|
|
1228
|
+
/**
|
|
1229
|
+
* Connect to the provider
|
|
1230
|
+
*/
|
|
1231
|
+
connect(): Promise<void>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Disconnect from the provider
|
|
1234
|
+
*/
|
|
1235
|
+
disconnect(): void;
|
|
1236
|
+
/**
|
|
1237
|
+
* Check if connected
|
|
1238
|
+
*/
|
|
1239
|
+
isConnected(): boolean;
|
|
1240
|
+
/**
|
|
1241
|
+
* Get the current chain tip height
|
|
1242
|
+
*/
|
|
1243
|
+
getChainTipHeight(): Promise<number>;
|
|
1244
|
+
/**
|
|
1245
|
+
* Get the current chain tip
|
|
1246
|
+
*/
|
|
1247
|
+
getChainTip(): Promise<ChainTip>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Get a single block header
|
|
1250
|
+
* @param height - Block height
|
|
1251
|
+
* @returns Block header hex (80 bytes)
|
|
1252
|
+
*/
|
|
1253
|
+
getBlockHeader(height: number): Promise<string>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Get multiple block headers
|
|
1256
|
+
* @param startHeight - Starting block height
|
|
1257
|
+
* @param count - Number of headers to fetch
|
|
1258
|
+
* @returns Block headers result
|
|
1259
|
+
*/
|
|
1260
|
+
getBlockHeaders(startHeight: number, count: number): Promise<BlockHeadersResult>;
|
|
1261
|
+
/**
|
|
1262
|
+
* Get transaction keys for a range of blocks
|
|
1263
|
+
* Used for wallet scanning - extracts keys needed for output detection
|
|
1264
|
+
* @param startHeight - Starting block height
|
|
1265
|
+
* @returns Block transaction keys with next height for pagination
|
|
1266
|
+
*/
|
|
1267
|
+
getBlockTransactionKeysRange(startHeight: number): Promise<{
|
|
1268
|
+
blocks: BlockTransactionKeys[];
|
|
1269
|
+
nextHeight: number;
|
|
1270
|
+
}>;
|
|
1271
|
+
/**
|
|
1272
|
+
* Get transaction keys for a single block
|
|
1273
|
+
* @param height - Block height
|
|
1274
|
+
* @returns Array of transaction keys
|
|
1275
|
+
*/
|
|
1276
|
+
getBlockTransactionKeys(height: number): Promise<TransactionKeys[]>;
|
|
1277
|
+
/**
|
|
1278
|
+
* Get serialized transaction output by output hash
|
|
1279
|
+
* @param outputHash - Output hash (hex string)
|
|
1280
|
+
* @returns Serialized output (hex string)
|
|
1281
|
+
*/
|
|
1282
|
+
getTransactionOutput(outputHash: string): Promise<string>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Broadcast a transaction
|
|
1285
|
+
* @param rawTx - Raw transaction (hex string)
|
|
1286
|
+
* @returns Transaction hash if successful
|
|
1287
|
+
*/
|
|
1288
|
+
broadcastTransaction(rawTx: string): Promise<string>;
|
|
1289
|
+
/**
|
|
1290
|
+
* Get raw transaction
|
|
1291
|
+
* @param txHash - Transaction hash (hex string)
|
|
1292
|
+
* @param verbose - Return verbose data
|
|
1293
|
+
* @returns Raw transaction hex or verbose object
|
|
1294
|
+
*/
|
|
1295
|
+
getRawTransaction(txHash: string, verbose?: boolean): Promise<string | unknown>;
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Base class for sync providers with common utility methods.
|
|
1299
|
+
*
|
|
1300
|
+
* @category Sync
|
|
1301
|
+
*/
|
|
1302
|
+
declare abstract class BaseSyncProvider implements SyncProvider {
|
|
1303
|
+
abstract readonly type: 'electrum' | 'p2p' | 'custom';
|
|
1304
|
+
protected debug: boolean;
|
|
1305
|
+
protected timeout: number;
|
|
1306
|
+
constructor(options?: SyncProviderOptions);
|
|
1307
|
+
protected log(...args: unknown[]): void;
|
|
1308
|
+
/**
|
|
1309
|
+
* Extract block hash from raw block header (80 bytes hex)
|
|
1310
|
+
* Block hash is double SHA256 of header, reversed for display
|
|
1311
|
+
*/
|
|
1312
|
+
protected extractBlockHash(headerHex: string): string;
|
|
1313
|
+
/**
|
|
1314
|
+
* Parse a raw block header into structured format
|
|
1315
|
+
*/
|
|
1316
|
+
protected parseBlockHeader(headerHex: string, height: number): SyncBlockHeader;
|
|
1317
|
+
abstract connect(): Promise<void>;
|
|
1318
|
+
abstract disconnect(): void;
|
|
1319
|
+
abstract isConnected(): boolean;
|
|
1320
|
+
abstract getChainTipHeight(): Promise<number>;
|
|
1321
|
+
abstract getChainTip(): Promise<ChainTip>;
|
|
1322
|
+
abstract getBlockHeader(height: number): Promise<string>;
|
|
1323
|
+
abstract getBlockHeaders(startHeight: number, count: number): Promise<BlockHeadersResult>;
|
|
1324
|
+
abstract getBlockTransactionKeysRange(startHeight: number): Promise<{
|
|
1325
|
+
blocks: BlockTransactionKeys[];
|
|
1326
|
+
nextHeight: number;
|
|
1327
|
+
}>;
|
|
1328
|
+
abstract getBlockTransactionKeys(height: number): Promise<TransactionKeys[]>;
|
|
1329
|
+
abstract getTransactionOutput(outputHash: string): Promise<string>;
|
|
1330
|
+
abstract broadcastTransaction(rawTx: string): Promise<string>;
|
|
1331
|
+
abstract getRawTransaction(txHash: string, verbose?: boolean): Promise<string | unknown>;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
/**
|
|
1335
|
+
* Transaction Keys Sync Module
|
|
1336
|
+
*
|
|
1337
|
+
* Synchronizes transaction keys from a sync provider to wallet database
|
|
1338
|
+
* - Supports multiple backends: Electrum, P2P, or custom providers
|
|
1339
|
+
* - Tracks sync progress and resumes from last state
|
|
1340
|
+
* - Handles block reorganizations
|
|
1341
|
+
* - Persists sync state in wallet database
|
|
1342
|
+
*/
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* Sync state stored in database
|
|
1346
|
+
*/
|
|
1347
|
+
interface SyncState {
|
|
1348
|
+
/** Last synced block height */
|
|
1349
|
+
lastSyncedHeight: number;
|
|
1350
|
+
/** Last synced block hash */
|
|
1351
|
+
lastSyncedHash: string;
|
|
1352
|
+
/** Total transaction keys synced */
|
|
1353
|
+
totalTxKeysSynced: number;
|
|
1354
|
+
/** Last sync timestamp */
|
|
1355
|
+
lastSyncTime: number;
|
|
1356
|
+
/** Chain tip at last sync */
|
|
1357
|
+
chainTipAtLastSync: number;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Sync progress callback
|
|
1361
|
+
*/
|
|
1362
|
+
type SyncProgressCallback = (currentHeight: number, chainTip: number, blocksProcessed: number, txKeysProcessed: number, isReorg: boolean) => void;
|
|
1363
|
+
/**
|
|
1364
|
+
* Sync options
|
|
1365
|
+
*/
|
|
1366
|
+
interface SyncOptions {
|
|
1367
|
+
/** Start height (default: last synced height + 1) */
|
|
1368
|
+
startHeight?: number;
|
|
1369
|
+
/** End height (default: chain tip) */
|
|
1370
|
+
endHeight?: number;
|
|
1371
|
+
/** Progress callback */
|
|
1372
|
+
onProgress?: SyncProgressCallback;
|
|
1373
|
+
/** Stop on reorganization (default: true) */
|
|
1374
|
+
stopOnReorg?: boolean;
|
|
1375
|
+
/** Verify block hashes (default: true) */
|
|
1376
|
+
verifyHashes?: boolean;
|
|
1377
|
+
/** Save database after N blocks (default: 100) - 0 to save only at end */
|
|
1378
|
+
saveInterval?: number;
|
|
1379
|
+
/** Keep transaction keys in database after processing (default: false) */
|
|
1380
|
+
keepTxKeys?: boolean;
|
|
1381
|
+
/** Keep block hashes for last N blocks only (default: 10000) - 0 to keep all */
|
|
1382
|
+
blockHashRetention?: number;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Background sync options for continuous synchronization
|
|
1386
|
+
*/
|
|
1387
|
+
interface BackgroundSyncOptions extends SyncOptions {
|
|
1388
|
+
/**
|
|
1389
|
+
* Polling interval in milliseconds
|
|
1390
|
+
* @default 10000 (10 seconds)
|
|
1391
|
+
*/
|
|
1392
|
+
pollInterval?: number;
|
|
1393
|
+
/**
|
|
1394
|
+
* Callback when a new block is detected
|
|
1395
|
+
*/
|
|
1396
|
+
onNewBlock?: (height: number, hash: string) => void;
|
|
1397
|
+
/**
|
|
1398
|
+
* Callback when new transactions are detected for the wallet
|
|
1399
|
+
*/
|
|
1400
|
+
onNewTransaction?: (txHash: string, outputHash: string, amount: bigint) => void;
|
|
1401
|
+
/**
|
|
1402
|
+
* Callback when balance changes
|
|
1403
|
+
*/
|
|
1404
|
+
onBalanceChange?: (newBalance: bigint, oldBalance: bigint) => void;
|
|
1405
|
+
/**
|
|
1406
|
+
* Callback on sync error (background sync continues after errors)
|
|
1407
|
+
*/
|
|
1408
|
+
onError?: (error: Error) => void;
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Reorganization information
|
|
1412
|
+
*/
|
|
1413
|
+
interface ReorganizationInfo {
|
|
1414
|
+
/** Height where reorganization occurred */
|
|
1415
|
+
height: number;
|
|
1416
|
+
/** Old block hash */
|
|
1417
|
+
oldHash: string;
|
|
1418
|
+
/** New block hash */
|
|
1419
|
+
newHash: string;
|
|
1420
|
+
/** Number of blocks to revert */
|
|
1421
|
+
blocksToRevert: number;
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Transaction Keys Sync Manager
|
|
1425
|
+
*
|
|
1426
|
+
* Can be initialized with either:
|
|
1427
|
+
* - A SyncProvider (recommended) - works with Electrum, P2P, or custom backends
|
|
1428
|
+
* - An ElectrumClient (legacy) - for backwards compatibility
|
|
1429
|
+
*
|
|
1430
|
+
* @category Sync
|
|
1431
|
+
*/
|
|
1432
|
+
declare class TransactionKeysSync {
|
|
1433
|
+
private walletDB;
|
|
1434
|
+
private syncProvider;
|
|
1435
|
+
private keyManager;
|
|
1436
|
+
private syncState;
|
|
1437
|
+
private blockHashRetention;
|
|
1438
|
+
/**
|
|
1439
|
+
* Create a new TransactionKeysSync instance
|
|
1440
|
+
* @param walletDB - The wallet database
|
|
1441
|
+
* @param provider - A SyncProvider or ElectrumClient instance
|
|
1442
|
+
*/
|
|
1443
|
+
constructor(walletDB: WalletDB, provider: SyncProvider | ElectrumClient);
|
|
1444
|
+
/**
|
|
1445
|
+
* Wrap an ElectrumClient as a SyncProvider for backwards compatibility
|
|
1446
|
+
*/
|
|
1447
|
+
private wrapElectrumClient;
|
|
1448
|
+
/**
|
|
1449
|
+
* Get the sync provider being used
|
|
1450
|
+
*/
|
|
1451
|
+
getSyncProvider(): SyncProvider;
|
|
1452
|
+
/**
|
|
1453
|
+
* Get the provider type (electrum, p2p, or custom)
|
|
1454
|
+
*/
|
|
1455
|
+
getProviderType(): 'electrum' | 'p2p' | 'custom';
|
|
1456
|
+
/**
|
|
1457
|
+
* Set the KeyManager instance for output detection
|
|
1458
|
+
* @param keyManager - The KeyManager instance
|
|
1459
|
+
*/
|
|
1460
|
+
setKeyManager(keyManager: KeyManager): void;
|
|
1461
|
+
/**
|
|
1462
|
+
* Initialize sync manager
|
|
1463
|
+
* Loads sync state from database
|
|
1464
|
+
*/
|
|
1465
|
+
initialize(): Promise<void>;
|
|
1466
|
+
/**
|
|
1467
|
+
* Get current sync state
|
|
1468
|
+
*/
|
|
1469
|
+
getSyncState(): SyncState | null;
|
|
1470
|
+
/**
|
|
1471
|
+
* Get last synced height
|
|
1472
|
+
*/
|
|
1473
|
+
getLastSyncedHeight(): number;
|
|
1474
|
+
/**
|
|
1475
|
+
* Check if sync is needed
|
|
1476
|
+
*/
|
|
1477
|
+
isSyncNeeded(): Promise<boolean>;
|
|
1478
|
+
/**
|
|
1479
|
+
* Synchronize transaction keys from Electrum server
|
|
1480
|
+
* @param options - Sync options
|
|
1481
|
+
* @returns Number of transaction keys synced
|
|
1482
|
+
*/
|
|
1483
|
+
sync(options?: SyncOptions): Promise<number>;
|
|
1484
|
+
/**
|
|
1485
|
+
* Check for chain reorganization
|
|
1486
|
+
* @param height - Height to check
|
|
1487
|
+
* @returns Reorganization info if detected, null otherwise
|
|
1488
|
+
*/
|
|
1489
|
+
private checkReorganization;
|
|
1490
|
+
/**
|
|
1491
|
+
* Handle chain reorganization
|
|
1492
|
+
* @param reorgInfo - Reorganization information
|
|
1493
|
+
*/
|
|
1494
|
+
private handleReorganization;
|
|
1495
|
+
/**
|
|
1496
|
+
* Process block transactions to detect spent outputs
|
|
1497
|
+
* @param block - Block transaction keys
|
|
1498
|
+
* @param _blockHash - Block hash (for reference)
|
|
1499
|
+
*/
|
|
1500
|
+
private processBlockForSpentOutputs;
|
|
1501
|
+
/**
|
|
1502
|
+
* Revert blocks from database
|
|
1503
|
+
* @param startHeight - Start height to revert from
|
|
1504
|
+
* @param endHeight - End height to revert to
|
|
1505
|
+
*/
|
|
1506
|
+
private revertBlocks;
|
|
1507
|
+
/**
|
|
1508
|
+
* Store transaction keys for a block
|
|
1509
|
+
* @param block - Block transaction keys
|
|
1510
|
+
* @param blockHash - Block hash
|
|
1511
|
+
* @param keepTxKeys - Whether to keep transaction keys in database after processing
|
|
1512
|
+
* @returns Number of transaction keys stored
|
|
1513
|
+
*/
|
|
1514
|
+
private storeBlockTransactionKeys;
|
|
1515
|
+
/**
|
|
1516
|
+
* Process transaction keys to detect and store wallet outputs
|
|
1517
|
+
* @param txHash - Transaction hash
|
|
1518
|
+
* @param keys - Transaction keys data
|
|
1519
|
+
* @param blockHeight - Block height
|
|
1520
|
+
* @param _blockHash - Block hash (for reference, currently unused)
|
|
1521
|
+
*/
|
|
1522
|
+
private processTransactionKeys;
|
|
1523
|
+
/**
|
|
1524
|
+
* Extract range proof from serialized CTxOut data
|
|
1525
|
+
* @param outputHex - Serialized output data (hex)
|
|
1526
|
+
* @returns Object containing rangeProofHex and tokenIdHex
|
|
1527
|
+
*/
|
|
1528
|
+
private extractRangeProofFromOutput;
|
|
1529
|
+
/**
|
|
1530
|
+
* Store wallet output in database
|
|
1531
|
+
* @param outputHash - Output hash
|
|
1532
|
+
* @param txHash - Transaction hash
|
|
1533
|
+
* @param outputIndex - Output index
|
|
1534
|
+
* @param blockHeight - Block height
|
|
1535
|
+
* @param outputData - Serialized output data (hex)
|
|
1536
|
+
* @param amount - Recovered amount in satoshis
|
|
1537
|
+
* @param memo - Recovered memo/message
|
|
1538
|
+
* @param tokenId - Token ID (hex)
|
|
1539
|
+
* @param blindingKey - Blinding public key (hex)
|
|
1540
|
+
* @param spendingKey - Spending public key (hex)
|
|
1541
|
+
* @param isSpent - Whether output is spent
|
|
1542
|
+
* @param spentTxHash - Transaction hash that spent this output (if spent)
|
|
1543
|
+
* @param spentBlockHeight - Block height where output was spent (if spent)
|
|
1544
|
+
*/
|
|
1545
|
+
private storeWalletOutput;
|
|
1546
|
+
/**
|
|
1547
|
+
* Extract block hash from block header
|
|
1548
|
+
* @param headerHex - Block header in hex
|
|
1549
|
+
* @returns Block hash (hex string)
|
|
1550
|
+
*/
|
|
1551
|
+
private extractBlockHash;
|
|
1552
|
+
/**
|
|
1553
|
+
* Get stored block hash from database
|
|
1554
|
+
* @param height - Block height
|
|
1555
|
+
* @returns Block hash or null if not found
|
|
1556
|
+
*/
|
|
1557
|
+
private getStoredBlockHash;
|
|
1558
|
+
/**
|
|
1559
|
+
* Store block hash in database
|
|
1560
|
+
* Only stores if within retention window (if retention is enabled)
|
|
1561
|
+
* @param height - Block height
|
|
1562
|
+
* @param hash - Block hash
|
|
1563
|
+
* @param chainTip - Current chain tip (optional, to avoid repeated fetches)
|
|
1564
|
+
*/
|
|
1565
|
+
private storeBlockHash;
|
|
1566
|
+
/**
|
|
1567
|
+
* Load sync state from database
|
|
1568
|
+
* @returns Sync state or null if not found
|
|
1569
|
+
*/
|
|
1570
|
+
private loadSyncState;
|
|
1571
|
+
/**
|
|
1572
|
+
* Update sync state in database
|
|
1573
|
+
* @param state - Sync state to update
|
|
1574
|
+
*/
|
|
1575
|
+
private updateSyncState;
|
|
1576
|
+
/**
|
|
1577
|
+
* Get transaction keys for a specific transaction
|
|
1578
|
+
* @param txHash - Transaction hash
|
|
1579
|
+
* @returns Transaction keys or null if not found
|
|
1580
|
+
*/
|
|
1581
|
+
getTransactionKeys(txHash: string): Promise<any | null>;
|
|
1582
|
+
/**
|
|
1583
|
+
* Get transaction keys for a block
|
|
1584
|
+
* @param height - Block height
|
|
1585
|
+
* @returns Array of transaction keys
|
|
1586
|
+
*/
|
|
1587
|
+
getBlockTransactionKeys(height: number): Promise<TransactionKeys[]>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Reset sync state (for testing or full resync)
|
|
1590
|
+
*/
|
|
1591
|
+
resetSyncState(): Promise<void>;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
/**
|
|
1595
|
+
* P2P Protocol Implementation for Navio
|
|
1596
|
+
*
|
|
1597
|
+
* Implements the Navio P2P protocol for direct node communication.
|
|
1598
|
+
* Supports connection handshake, message framing, and core protocol messages.
|
|
1599
|
+
*/
|
|
1600
|
+
/**
|
|
1601
|
+
* Network magic bytes for different chains
|
|
1602
|
+
*/
|
|
1603
|
+
declare const NetworkMagic: {
|
|
1604
|
+
readonly MAINNET: Buffer<ArrayBuffer>;
|
|
1605
|
+
readonly TESTNET: Buffer<ArrayBuffer>;
|
|
1606
|
+
readonly REGTEST: Buffer<ArrayBuffer>;
|
|
1607
|
+
};
|
|
1608
|
+
/**
|
|
1609
|
+
* Default ports for different chains
|
|
1610
|
+
*/
|
|
1611
|
+
declare const DefaultPorts: {
|
|
1612
|
+
readonly MAINNET: 44440;
|
|
1613
|
+
readonly TESTNET: 33670;
|
|
1614
|
+
readonly REGTEST: 18444;
|
|
1615
|
+
};
|
|
1616
|
+
/**
|
|
1617
|
+
* P2P message types
|
|
1618
|
+
*/
|
|
1619
|
+
declare const MessageType: {
|
|
1620
|
+
readonly VERSION: "version";
|
|
1621
|
+
readonly VERACK: "verack";
|
|
1622
|
+
readonly PING: "ping";
|
|
1623
|
+
readonly PONG: "pong";
|
|
1624
|
+
readonly GETADDR: "getaddr";
|
|
1625
|
+
readonly ADDR: "addr";
|
|
1626
|
+
readonly INV: "inv";
|
|
1627
|
+
readonly GETDATA: "getdata";
|
|
1628
|
+
readonly NOTFOUND: "notfound";
|
|
1629
|
+
readonly GETBLOCKS: "getblocks";
|
|
1630
|
+
readonly GETHEADERS: "getheaders";
|
|
1631
|
+
readonly HEADERS: "headers";
|
|
1632
|
+
readonly BLOCK: "block";
|
|
1633
|
+
readonly TX: "tx";
|
|
1634
|
+
readonly GETOUTPUTDATA: "getoutputdata";
|
|
1635
|
+
readonly MEMPOOL: "mempool";
|
|
1636
|
+
readonly REJECT: "reject";
|
|
1637
|
+
readonly SENDHEADERS: "sendheaders";
|
|
1638
|
+
readonly SENDCMPCT: "sendcmpct";
|
|
1639
|
+
readonly CMPCTBLOCK: "cmpctblock";
|
|
1640
|
+
readonly GETBLOCKTXN: "getblocktxn";
|
|
1641
|
+
readonly BLOCKTXN: "blocktxn";
|
|
1642
|
+
};
|
|
1643
|
+
/**
|
|
1644
|
+
* Service flags
|
|
1645
|
+
*/
|
|
1646
|
+
declare const ServiceFlags: {
|
|
1647
|
+
readonly NODE_NONE: 0n;
|
|
1648
|
+
readonly NODE_NETWORK: bigint;
|
|
1649
|
+
readonly NODE_BLOOM: bigint;
|
|
1650
|
+
readonly NODE_WITNESS: bigint;
|
|
1651
|
+
readonly NODE_COMPACT_FILTERS: bigint;
|
|
1652
|
+
readonly NODE_NETWORK_LIMITED: bigint;
|
|
1653
|
+
readonly NODE_P2P_V2: bigint;
|
|
1654
|
+
};
|
|
1655
|
+
/**
|
|
1656
|
+
* Inventory types for getdata/inv messages
|
|
1657
|
+
*/
|
|
1658
|
+
declare const InvType: {
|
|
1659
|
+
readonly ERROR: 0;
|
|
1660
|
+
readonly MSG_TX: 1;
|
|
1661
|
+
readonly MSG_BLOCK: 2;
|
|
1662
|
+
readonly MSG_FILTERED_BLOCK: 3;
|
|
1663
|
+
readonly MSG_CMPCT_BLOCK: 4;
|
|
1664
|
+
readonly MSG_WTX: 5;
|
|
1665
|
+
readonly MSG_DTX: 6;
|
|
1666
|
+
readonly MSG_DWTX: 7;
|
|
1667
|
+
readonly MSG_OUTPUT_HASH: 8;
|
|
1668
|
+
readonly MSG_WITNESS_FLAG: number;
|
|
1669
|
+
readonly MSG_WITNESS_BLOCK: number;
|
|
1670
|
+
readonly MSG_WITNESS_TX: number;
|
|
1671
|
+
};
|
|
1672
|
+
/**
|
|
1673
|
+
* Protocol version
|
|
1674
|
+
*/
|
|
1675
|
+
declare const PROTOCOL_VERSION = 70016;
|
|
1676
|
+
/**
|
|
1677
|
+
* P2P connection options
|
|
1678
|
+
*/
|
|
1679
|
+
interface P2PConnectionOptions {
|
|
1680
|
+
/** Host to connect to */
|
|
1681
|
+
host: string;
|
|
1682
|
+
/** Port (default based on network) */
|
|
1683
|
+
port?: number;
|
|
1684
|
+
/** Network type */
|
|
1685
|
+
network?: 'mainnet' | 'testnet' | 'regtest';
|
|
1686
|
+
/** Connection timeout in ms */
|
|
1687
|
+
timeout?: number;
|
|
1688
|
+
/** User agent string */
|
|
1689
|
+
userAgent?: string;
|
|
1690
|
+
/** Enable debug logging */
|
|
1691
|
+
debug?: boolean;
|
|
1692
|
+
/** Services to advertise */
|
|
1693
|
+
services?: bigint;
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Message header structure
|
|
1697
|
+
*/
|
|
1698
|
+
interface MessageHeader {
|
|
1699
|
+
magic: Buffer;
|
|
1700
|
+
command: string;
|
|
1701
|
+
length: number;
|
|
1702
|
+
checksum: Buffer;
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Parsed P2P message
|
|
1706
|
+
*/
|
|
1707
|
+
interface P2PMessage {
|
|
1708
|
+
command: string;
|
|
1709
|
+
payload: Buffer;
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Version message payload
|
|
1713
|
+
*/
|
|
1714
|
+
interface VersionPayload {
|
|
1715
|
+
version: number;
|
|
1716
|
+
services: bigint;
|
|
1717
|
+
timestamp: bigint;
|
|
1718
|
+
addrRecv: {
|
|
1719
|
+
services: bigint;
|
|
1720
|
+
ip: Buffer;
|
|
1721
|
+
port: number;
|
|
1722
|
+
};
|
|
1723
|
+
addrFrom: {
|
|
1724
|
+
services: bigint;
|
|
1725
|
+
ip: Buffer;
|
|
1726
|
+
port: number;
|
|
1727
|
+
};
|
|
1728
|
+
nonce: bigint;
|
|
1729
|
+
userAgent: string;
|
|
1730
|
+
startHeight: number;
|
|
1731
|
+
relay: boolean;
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Inventory vector
|
|
1735
|
+
*/
|
|
1736
|
+
interface InvVector {
|
|
1737
|
+
type: number;
|
|
1738
|
+
hash: Buffer;
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Block locator for getheaders/getblocks
|
|
1742
|
+
*/
|
|
1743
|
+
interface BlockLocator {
|
|
1744
|
+
version: number;
|
|
1745
|
+
hashes: Buffer[];
|
|
1746
|
+
hashStop: Buffer;
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* P2P Protocol Client
|
|
1750
|
+
*
|
|
1751
|
+
* Low-level P2P protocol implementation for connecting to Navio nodes.
|
|
1752
|
+
*
|
|
1753
|
+
* @category Protocol
|
|
1754
|
+
*/
|
|
1755
|
+
declare class P2PClient {
|
|
1756
|
+
private socket;
|
|
1757
|
+
private options;
|
|
1758
|
+
private magic;
|
|
1759
|
+
private connected;
|
|
1760
|
+
private handshakeComplete;
|
|
1761
|
+
private receiveBuffer;
|
|
1762
|
+
private pendingMessages;
|
|
1763
|
+
private messageHandlers;
|
|
1764
|
+
private messageQueue;
|
|
1765
|
+
private nonce;
|
|
1766
|
+
private peerVersion;
|
|
1767
|
+
private _peerServices;
|
|
1768
|
+
private peerStartHeight;
|
|
1769
|
+
constructor(options: P2PConnectionOptions);
|
|
1770
|
+
private log;
|
|
1771
|
+
/**
|
|
1772
|
+
* Connect to the peer and complete handshake
|
|
1773
|
+
*/
|
|
1774
|
+
connect(): Promise<void>;
|
|
1775
|
+
/**
|
|
1776
|
+
* Disconnect from the peer
|
|
1777
|
+
*/
|
|
1778
|
+
disconnect(): void;
|
|
1779
|
+
/**
|
|
1780
|
+
* Check if connected and handshake complete
|
|
1781
|
+
*/
|
|
1782
|
+
isConnected(): boolean;
|
|
1783
|
+
/**
|
|
1784
|
+
* Get peer's advertised start height
|
|
1785
|
+
*/
|
|
1786
|
+
getPeerStartHeight(): number;
|
|
1787
|
+
/**
|
|
1788
|
+
* Get peer's protocol version
|
|
1789
|
+
*/
|
|
1790
|
+
getPeerVersion(): number;
|
|
1791
|
+
/**
|
|
1792
|
+
* Get peer's advertised services
|
|
1793
|
+
*/
|
|
1794
|
+
getPeerServices(): bigint;
|
|
1795
|
+
/**
|
|
1796
|
+
* Handle incoming data
|
|
1797
|
+
*/
|
|
1798
|
+
private handleData;
|
|
1799
|
+
/**
|
|
1800
|
+
* Parse message header
|
|
1801
|
+
*/
|
|
1802
|
+
private parseHeader;
|
|
1803
|
+
/**
|
|
1804
|
+
* Calculate message checksum (first 4 bytes of double SHA256)
|
|
1805
|
+
*/
|
|
1806
|
+
private calculateChecksum;
|
|
1807
|
+
/**
|
|
1808
|
+
* Dispatch message to handlers
|
|
1809
|
+
*/
|
|
1810
|
+
private dispatchMessage;
|
|
1811
|
+
/**
|
|
1812
|
+
* Register a message handler
|
|
1813
|
+
*/
|
|
1814
|
+
onMessage(command: string, handler: (msg: P2PMessage) => void): void;
|
|
1815
|
+
/**
|
|
1816
|
+
* Send a raw message
|
|
1817
|
+
*/
|
|
1818
|
+
private sendMessage;
|
|
1819
|
+
/**
|
|
1820
|
+
* Send a message and wait for a specific response
|
|
1821
|
+
*/
|
|
1822
|
+
sendAndWait(command: string, payload: Buffer, responseCommand: string, timeout?: number): Promise<P2PMessage>;
|
|
1823
|
+
/**
|
|
1824
|
+
* Wait for a specific message
|
|
1825
|
+
*/
|
|
1826
|
+
waitForMessage(command: string, timeout?: number): Promise<P2PMessage>;
|
|
1827
|
+
/**
|
|
1828
|
+
* Send version message
|
|
1829
|
+
*/
|
|
1830
|
+
private sendVersion;
|
|
1831
|
+
/**
|
|
1832
|
+
* Build version message payload
|
|
1833
|
+
*/
|
|
1834
|
+
private buildVersionPayload;
|
|
1835
|
+
/**
|
|
1836
|
+
* Wait for handshake completion
|
|
1837
|
+
*/
|
|
1838
|
+
private waitForHandshake;
|
|
1839
|
+
/**
|
|
1840
|
+
* Parse version message
|
|
1841
|
+
*/
|
|
1842
|
+
private parseVersionMessage;
|
|
1843
|
+
/**
|
|
1844
|
+
* Handle ping message
|
|
1845
|
+
*/
|
|
1846
|
+
private handlePing;
|
|
1847
|
+
/**
|
|
1848
|
+
* Send getheaders message
|
|
1849
|
+
*/
|
|
1850
|
+
getHeaders(locatorHashes: Buffer[], hashStop?: Buffer): Promise<Buffer[]>;
|
|
1851
|
+
/**
|
|
1852
|
+
* Build block locator payload for getheaders/getblocks
|
|
1853
|
+
*/
|
|
1854
|
+
private buildBlockLocatorPayload;
|
|
1855
|
+
/**
|
|
1856
|
+
* Parse headers message
|
|
1857
|
+
*
|
|
1858
|
+
* Note: Navio's headers message format differs from Bitcoin's.
|
|
1859
|
+
* Bitcoin includes a varint tx_count (always 0) after each 80-byte header.
|
|
1860
|
+
* Navio sends just the raw 80-byte headers with no tx_count.
|
|
1861
|
+
*/
|
|
1862
|
+
private parseHeadersMessage;
|
|
1863
|
+
/**
|
|
1864
|
+
* Send getdata message
|
|
1865
|
+
*/
|
|
1866
|
+
getData(inventory: InvVector[]): Promise<void>;
|
|
1867
|
+
/**
|
|
1868
|
+
* Build inventory payload for inv/getdata
|
|
1869
|
+
*/
|
|
1870
|
+
private buildInvPayload;
|
|
1871
|
+
/**
|
|
1872
|
+
* Request a block by hash
|
|
1873
|
+
*/
|
|
1874
|
+
getBlock(blockHash: Buffer): Promise<P2PMessage>;
|
|
1875
|
+
/**
|
|
1876
|
+
* Request transaction outputs by output hash (Navio-specific)
|
|
1877
|
+
*/
|
|
1878
|
+
getOutputData(outputHashes: Buffer[]): Promise<P2PMessage>;
|
|
1879
|
+
/**
|
|
1880
|
+
* Send sendheaders message to prefer headers announcements
|
|
1881
|
+
*/
|
|
1882
|
+
sendSendHeaders(): void;
|
|
1883
|
+
/**
|
|
1884
|
+
* Encode a variable-length integer
|
|
1885
|
+
*/
|
|
1886
|
+
encodeVarInt(value: number | bigint): Buffer;
|
|
1887
|
+
/**
|
|
1888
|
+
* Decode a variable-length integer
|
|
1889
|
+
*/
|
|
1890
|
+
decodeVarInt(buffer: Buffer): {
|
|
1891
|
+
value: bigint;
|
|
1892
|
+
bytesRead: number;
|
|
1893
|
+
};
|
|
1894
|
+
/**
|
|
1895
|
+
* Reverse a hash for display (Bitcoin uses little-endian internally, big-endian for display)
|
|
1896
|
+
*/
|
|
1897
|
+
static reverseHash(hash: Buffer): Buffer;
|
|
1898
|
+
/**
|
|
1899
|
+
* Convert display hash to internal format
|
|
1900
|
+
*/
|
|
1901
|
+
static hashFromDisplay(hexHash: string): Buffer;
|
|
1902
|
+
/**
|
|
1903
|
+
* Convert internal hash to display format
|
|
1904
|
+
*/
|
|
1905
|
+
static hashToDisplay(hash: Buffer): string;
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
/**
|
|
1909
|
+
* Network type for Navio
|
|
1910
|
+
*/
|
|
1911
|
+
type NetworkType = 'mainnet' | 'testnet' | 'signet' | 'regtest';
|
|
1912
|
+
/**
|
|
1913
|
+
* Backend type for NavioClient
|
|
1914
|
+
*/
|
|
1915
|
+
type BackendType = 'electrum' | 'p2p';
|
|
1916
|
+
/**
|
|
1917
|
+
* P2P connection options for NavioClient
|
|
1918
|
+
*/
|
|
1919
|
+
interface P2POptions extends P2PConnectionOptions {
|
|
1920
|
+
/** Maximum headers to fetch per request */
|
|
1921
|
+
maxHeadersPerRequest?: number;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Configuration for NavioClient
|
|
1925
|
+
*/
|
|
1926
|
+
interface NavioClientConfig {
|
|
1927
|
+
/** Path to wallet database file */
|
|
1928
|
+
walletDbPath: string;
|
|
1929
|
+
/**
|
|
1930
|
+
* Backend type to use for synchronization
|
|
1931
|
+
* - 'electrum': Connect to an Electrum server (recommended for wallets)
|
|
1932
|
+
* - 'p2p': Connect directly to a Navio full node
|
|
1933
|
+
* @default 'electrum'
|
|
1934
|
+
*/
|
|
1935
|
+
backend?: BackendType;
|
|
1936
|
+
/**
|
|
1937
|
+
* Electrum server connection options
|
|
1938
|
+
* Required when backend is 'electrum'
|
|
1939
|
+
*/
|
|
1940
|
+
electrum?: ElectrumOptions;
|
|
1941
|
+
/**
|
|
1942
|
+
* P2P connection options
|
|
1943
|
+
* Required when backend is 'p2p'
|
|
1944
|
+
*/
|
|
1945
|
+
p2p?: P2POptions;
|
|
1946
|
+
/** Create wallet if it doesn't exist (default: false) */
|
|
1947
|
+
createWalletIfNotExists?: boolean;
|
|
1948
|
+
/** Restore wallet from seed (hex string) */
|
|
1949
|
+
restoreFromSeed?: string;
|
|
1950
|
+
/**
|
|
1951
|
+
* Block height to start scanning from when restoring a wallet from seed.
|
|
1952
|
+
* This is the height when the wallet was originally created.
|
|
1953
|
+
* Setting this avoids scanning blocks before the wallet existed.
|
|
1954
|
+
*
|
|
1955
|
+
* Note: This option is only used when `restoreFromSeed` is provided.
|
|
1956
|
+
* For newly created wallets, the creation height is automatically set
|
|
1957
|
+
* to the current chain tip minus a safety margin (100 blocks).
|
|
1958
|
+
*
|
|
1959
|
+
* @default 0 (scan from genesis when restoring)
|
|
1960
|
+
*/
|
|
1961
|
+
restoreFromHeight?: number;
|
|
1962
|
+
/**
|
|
1963
|
+
* Override the creation height for newly created wallets.
|
|
1964
|
+
* By default, new wallets use `chainTip - 100` to avoid scanning old blocks.
|
|
1965
|
+
* Set this to 0 to sync from genesis (useful for testing).
|
|
1966
|
+
*
|
|
1967
|
+
* Note: This is only used when `createWalletIfNotExists` is true and
|
|
1968
|
+
* no wallet exists. It does NOT override `restoreFromHeight` when
|
|
1969
|
+
* restoring from seed.
|
|
1970
|
+
*/
|
|
1971
|
+
creationHeight?: number;
|
|
1972
|
+
/**
|
|
1973
|
+
* Network to use for address encoding/decoding and cryptographic operations.
|
|
1974
|
+
* This configures the navio-blsct library to use the correct chain parameters.
|
|
1975
|
+
*
|
|
1976
|
+
* @default 'mainnet'
|
|
1977
|
+
*/
|
|
1978
|
+
network?: NetworkType;
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* Navio SDK Client
|
|
1982
|
+
* Main client for wallet operations and blockchain synchronization.
|
|
1983
|
+
*
|
|
1984
|
+
* Supports two backend types:
|
|
1985
|
+
* - Electrum: Connect to an Electrum server (recommended for light wallets)
|
|
1986
|
+
* - P2P: Connect directly to a Navio full node (for advanced use cases)
|
|
1987
|
+
*
|
|
1988
|
+
* @example
|
|
1989
|
+
* // Using Electrum backend (recommended)
|
|
1990
|
+
* const client = new NavioClient({
|
|
1991
|
+
* walletDbPath: './wallet.db',
|
|
1992
|
+
* backend: 'electrum',
|
|
1993
|
+
* electrum: { host: 'electrum.example.com', port: 50001, ssl: true }
|
|
1994
|
+
* });
|
|
1995
|
+
*
|
|
1996
|
+
* @example
|
|
1997
|
+
* // Using P2P backend
|
|
1998
|
+
* const client = new NavioClient({
|
|
1999
|
+
* walletDbPath: './wallet.db',
|
|
2000
|
+
* backend: 'p2p',
|
|
2001
|
+
* p2p: { host: '127.0.0.1', port: 44440, network: 'mainnet' }
|
|
2002
|
+
* });
|
|
2003
|
+
*
|
|
2004
|
+
* @category Client
|
|
2005
|
+
*/
|
|
2006
|
+
declare class NavioClient {
|
|
2007
|
+
private walletDB;
|
|
2008
|
+
private syncProvider;
|
|
2009
|
+
private syncManager;
|
|
2010
|
+
private keyManager;
|
|
2011
|
+
private config;
|
|
2012
|
+
private initialized;
|
|
2013
|
+
private electrumClient;
|
|
2014
|
+
private backgroundSyncTimer;
|
|
2015
|
+
private backgroundSyncOptions;
|
|
2016
|
+
private isBackgroundSyncing;
|
|
2017
|
+
private isSyncInProgress;
|
|
2018
|
+
private lastKnownBalance;
|
|
2019
|
+
/**
|
|
2020
|
+
* Create a new NavioClient instance
|
|
2021
|
+
* @param config - Client configuration
|
|
2022
|
+
*/
|
|
2023
|
+
constructor(config: NavioClientConfig);
|
|
2024
|
+
/**
|
|
2025
|
+
* Configure the navio-blsct library for the specified network
|
|
2026
|
+
*/
|
|
2027
|
+
private static configureNetwork;
|
|
2028
|
+
/**
|
|
2029
|
+
* Get the current network configuration
|
|
2030
|
+
*/
|
|
2031
|
+
getNetwork(): NetworkType;
|
|
2032
|
+
/**
|
|
2033
|
+
* Safety margin (in blocks) when setting creation height for new wallets.
|
|
2034
|
+
* This ensures we don't miss any transactions that might be in recent blocks.
|
|
2035
|
+
*/
|
|
2036
|
+
private static readonly CREATION_HEIGHT_MARGIN;
|
|
2037
|
+
/**
|
|
2038
|
+
* Initialize the client
|
|
2039
|
+
* Loads or creates wallet, connects to backend, and initializes sync manager
|
|
2040
|
+
*/
|
|
2041
|
+
initialize(): Promise<void>;
|
|
2042
|
+
/**
|
|
2043
|
+
* Get the backend type being used
|
|
2044
|
+
*/
|
|
2045
|
+
getBackendType(): BackendType;
|
|
2046
|
+
/**
|
|
2047
|
+
* Get the sync provider
|
|
2048
|
+
*/
|
|
2049
|
+
getSyncProvider(): SyncProvider;
|
|
2050
|
+
/**
|
|
2051
|
+
* Get the KeyManager instance
|
|
2052
|
+
* @returns KeyManager instance
|
|
2053
|
+
*/
|
|
2054
|
+
getKeyManager(): KeyManager;
|
|
2055
|
+
/**
|
|
2056
|
+
* Get the WalletDB instance
|
|
2057
|
+
* @returns WalletDB instance
|
|
2058
|
+
*/
|
|
2059
|
+
getWalletDB(): WalletDB;
|
|
2060
|
+
/**
|
|
2061
|
+
* Get the ElectrumClient instance (only available when using electrum backend)
|
|
2062
|
+
* @returns ElectrumClient instance or null if using P2P backend
|
|
2063
|
+
* @deprecated Use getSyncProvider() instead for backend-agnostic code
|
|
2064
|
+
*/
|
|
2065
|
+
getElectrumClient(): ElectrumClient | null;
|
|
2066
|
+
/**
|
|
2067
|
+
* Get the TransactionKeysSync instance
|
|
2068
|
+
* @returns TransactionKeysSync instance
|
|
2069
|
+
*/
|
|
2070
|
+
getSyncManager(): TransactionKeysSync;
|
|
2071
|
+
/**
|
|
2072
|
+
* Synchronize transaction keys from the backend.
|
|
2073
|
+
*
|
|
2074
|
+
* By default, syncs once to the current chain tip and returns.
|
|
2075
|
+
* Use `startBackgroundSync()` to enable continuous synchronization.
|
|
2076
|
+
*
|
|
2077
|
+
* @param options - Sync options
|
|
2078
|
+
* @returns Number of transaction keys synced
|
|
2079
|
+
*/
|
|
2080
|
+
sync(options?: SyncOptions): Promise<number>;
|
|
2081
|
+
/**
|
|
2082
|
+
* Start continuous background synchronization.
|
|
2083
|
+
*
|
|
2084
|
+
* The client will poll for new blocks and automatically sync new transactions.
|
|
2085
|
+
* Callbacks are invoked for new blocks, transactions, and balance changes.
|
|
2086
|
+
*
|
|
2087
|
+
* @param options - Background sync options
|
|
2088
|
+
*
|
|
2089
|
+
* @example
|
|
2090
|
+
* ```typescript
|
|
2091
|
+
* await client.startBackgroundSync({
|
|
2092
|
+
* pollInterval: 10000, // Check every 10 seconds
|
|
2093
|
+
* onNewBlock: (height) => console.log(`New block: ${height}`),
|
|
2094
|
+
* onBalanceChange: (newBal, oldBal) => {
|
|
2095
|
+
* console.log(`Balance changed: ${Number(oldBal)/1e8} -> ${Number(newBal)/1e8} NAV`);
|
|
2096
|
+
* },
|
|
2097
|
+
* onError: (err) => console.error('Sync error:', err),
|
|
2098
|
+
* });
|
|
2099
|
+
* ```
|
|
2100
|
+
*/
|
|
2101
|
+
startBackgroundSync(options?: BackgroundSyncOptions): Promise<void>;
|
|
2102
|
+
/**
|
|
2103
|
+
* Stop background synchronization.
|
|
2104
|
+
*/
|
|
2105
|
+
stopBackgroundSync(): void;
|
|
2106
|
+
/**
|
|
2107
|
+
* Check if background sync is running.
|
|
2108
|
+
* @returns True if background sync is active
|
|
2109
|
+
*/
|
|
2110
|
+
isBackgroundSyncActive(): boolean;
|
|
2111
|
+
/**
|
|
2112
|
+
* Perform a single background sync cycle.
|
|
2113
|
+
* Called by the polling timer.
|
|
2114
|
+
*/
|
|
2115
|
+
private performBackgroundSync;
|
|
2116
|
+
/**
|
|
2117
|
+
* Check if synchronization is needed
|
|
2118
|
+
* @returns True if sync is needed
|
|
2119
|
+
*/
|
|
2120
|
+
isSyncNeeded(): Promise<boolean>;
|
|
2121
|
+
/**
|
|
2122
|
+
* Get last synced block height
|
|
2123
|
+
* @returns Last synced height, or -1 if never synced
|
|
2124
|
+
*/
|
|
2125
|
+
getLastSyncedHeight(): number;
|
|
2126
|
+
/**
|
|
2127
|
+
* Get sync state
|
|
2128
|
+
* @returns Current sync state
|
|
2129
|
+
*/
|
|
2130
|
+
getSyncState(): SyncState | null;
|
|
2131
|
+
/**
|
|
2132
|
+
* Get the wallet creation height (block height to start scanning from)
|
|
2133
|
+
* @returns Creation height or 0 if not set
|
|
2134
|
+
*/
|
|
2135
|
+
getCreationHeight(): Promise<number>;
|
|
2136
|
+
/**
|
|
2137
|
+
* Set the wallet creation height
|
|
2138
|
+
* @param height - Block height when wallet was created
|
|
2139
|
+
*/
|
|
2140
|
+
setCreationHeight(height: number): Promise<void>;
|
|
2141
|
+
/**
|
|
2142
|
+
* Get wallet metadata
|
|
2143
|
+
* @returns Wallet metadata or null if not available
|
|
2144
|
+
*/
|
|
2145
|
+
getWalletMetadata(): Promise<{
|
|
2146
|
+
creationHeight: number;
|
|
2147
|
+
creationTime: number;
|
|
2148
|
+
restoredFromSeed: boolean;
|
|
2149
|
+
version: number;
|
|
2150
|
+
} | null>;
|
|
2151
|
+
/**
|
|
2152
|
+
* Get chain tip from the backend
|
|
2153
|
+
* @returns Current chain tip height and hash
|
|
2154
|
+
*/
|
|
2155
|
+
getChainTip(): Promise<{
|
|
2156
|
+
height: number;
|
|
2157
|
+
hash: string;
|
|
2158
|
+
}>;
|
|
2159
|
+
/**
|
|
2160
|
+
* Disconnect from backend and close database
|
|
2161
|
+
*/
|
|
2162
|
+
disconnect(): Promise<void>;
|
|
2163
|
+
/**
|
|
2164
|
+
* Get the current configuration
|
|
2165
|
+
*/
|
|
2166
|
+
getConfig(): NavioClientConfig;
|
|
2167
|
+
/**
|
|
2168
|
+
* Check if client is connected to the backend
|
|
2169
|
+
*/
|
|
2170
|
+
isConnected(): boolean;
|
|
2171
|
+
/**
|
|
2172
|
+
* Hash a block header to get block hash
|
|
2173
|
+
*/
|
|
2174
|
+
private hashBlockHeader;
|
|
2175
|
+
/**
|
|
2176
|
+
* Get wallet balance in satoshis
|
|
2177
|
+
* @param tokenId - Optional token ID to filter by (null for NAV)
|
|
2178
|
+
* @returns Balance in satoshis as bigint
|
|
2179
|
+
*/
|
|
2180
|
+
getBalance(tokenId?: string | null): Promise<bigint>;
|
|
2181
|
+
/**
|
|
2182
|
+
* Get wallet balance in NAV (with decimals)
|
|
2183
|
+
* @param tokenId - Optional token ID to filter by (null for NAV)
|
|
2184
|
+
* @returns Balance as a number with 8 decimal places
|
|
2185
|
+
*/
|
|
2186
|
+
getBalanceNav(tokenId?: string | null): Promise<number>;
|
|
2187
|
+
/**
|
|
2188
|
+
* Get unspent outputs (UTXOs)
|
|
2189
|
+
* @param tokenId - Optional token ID to filter by (null for NAV)
|
|
2190
|
+
* @returns Array of unspent wallet outputs
|
|
2191
|
+
*/
|
|
2192
|
+
getUnspentOutputs(tokenId?: string | null): Promise<WalletOutput[]>;
|
|
2193
|
+
/**
|
|
2194
|
+
* Get all wallet outputs (spent and unspent)
|
|
2195
|
+
* @returns Array of all wallet outputs
|
|
2196
|
+
*/
|
|
2197
|
+
getAllOutputs(): Promise<WalletOutput[]>;
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
/**
|
|
2201
|
+
* Type definitions for Navio SDK
|
|
2202
|
+
*/
|
|
2203
|
+
/**
|
|
2204
|
+
* Network type for Navio
|
|
2205
|
+
*/
|
|
2206
|
+
type NavioNetwork = 'mainnet' | 'testnet' | 'regtest';
|
|
2207
|
+
/**
|
|
2208
|
+
* Generic hex string type
|
|
2209
|
+
*/
|
|
2210
|
+
type HexString = string;
|
|
2211
|
+
/**
|
|
2212
|
+
* Transaction hash (64-character hex string)
|
|
2213
|
+
*/
|
|
2214
|
+
type TxHash = HexString;
|
|
2215
|
+
/**
|
|
2216
|
+
* Block hash (64-character hex string)
|
|
2217
|
+
*/
|
|
2218
|
+
type BlockHash = HexString;
|
|
2219
|
+
/**
|
|
2220
|
+
* Output hash (64-character hex string, Navio-specific)
|
|
2221
|
+
*/
|
|
2222
|
+
type OutputHash = HexString;
|
|
2223
|
+
|
|
2224
|
+
/**
|
|
2225
|
+
* Electrum Sync Provider
|
|
2226
|
+
*
|
|
2227
|
+
* Implements the SyncProvider interface using an Electrum server connection.
|
|
2228
|
+
* This is a wrapper around ElectrumClient that provides the standardized sync interface.
|
|
2229
|
+
*/
|
|
2230
|
+
|
|
2231
|
+
/**
|
|
2232
|
+
* Electrum sync provider options
|
|
2233
|
+
*/
|
|
2234
|
+
interface ElectrumSyncOptions extends SyncProviderOptions, ElectrumOptions {
|
|
2235
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* Electrum Sync Provider
|
|
2238
|
+
*
|
|
2239
|
+
* Uses an Electrum server for blockchain synchronization.
|
|
2240
|
+
* Provides efficient transaction key fetching through Electrum's preprocessed data.
|
|
2241
|
+
*
|
|
2242
|
+
* @category Sync
|
|
2243
|
+
*/
|
|
2244
|
+
declare class ElectrumSyncProvider extends BaseSyncProvider {
|
|
2245
|
+
readonly type: "electrum";
|
|
2246
|
+
private client;
|
|
2247
|
+
private chainTipHeight;
|
|
2248
|
+
private chainTipHash;
|
|
2249
|
+
constructor(options?: ElectrumSyncOptions);
|
|
2250
|
+
/**
|
|
2251
|
+
* Get the underlying ElectrumClient for direct access to additional methods
|
|
2252
|
+
*/
|
|
2253
|
+
getClient(): ElectrumClient;
|
|
2254
|
+
/**
|
|
2255
|
+
* Connect to the Electrum server
|
|
2256
|
+
*/
|
|
2257
|
+
connect(): Promise<void>;
|
|
2258
|
+
/**
|
|
2259
|
+
* Disconnect from the Electrum server
|
|
2260
|
+
*/
|
|
2261
|
+
disconnect(): void;
|
|
2262
|
+
/**
|
|
2263
|
+
* Check if connected
|
|
2264
|
+
*/
|
|
2265
|
+
isConnected(): boolean;
|
|
2266
|
+
/**
|
|
2267
|
+
* Get current chain tip height
|
|
2268
|
+
*/
|
|
2269
|
+
getChainTipHeight(): Promise<number>;
|
|
2270
|
+
/**
|
|
2271
|
+
* Get current chain tip
|
|
2272
|
+
*/
|
|
2273
|
+
getChainTip(): Promise<ChainTip>;
|
|
2274
|
+
/**
|
|
2275
|
+
* Get a single block header
|
|
2276
|
+
*/
|
|
2277
|
+
getBlockHeader(height: number): Promise<string>;
|
|
2278
|
+
/**
|
|
2279
|
+
* Get multiple block headers
|
|
2280
|
+
*/
|
|
2281
|
+
getBlockHeaders(startHeight: number, count: number): Promise<BlockHeadersResult>;
|
|
2282
|
+
/**
|
|
2283
|
+
* Get transaction keys for a range of blocks
|
|
2284
|
+
*/
|
|
2285
|
+
getBlockTransactionKeysRange(startHeight: number): Promise<{
|
|
2286
|
+
blocks: BlockTransactionKeys[];
|
|
2287
|
+
nextHeight: number;
|
|
2288
|
+
}>;
|
|
2289
|
+
/**
|
|
2290
|
+
* Get transaction keys for a single block
|
|
2291
|
+
*/
|
|
2292
|
+
getBlockTransactionKeys(height: number): Promise<TransactionKeys[]>;
|
|
2293
|
+
/**
|
|
2294
|
+
* Get serialized transaction output by output hash
|
|
2295
|
+
*/
|
|
2296
|
+
getTransactionOutput(outputHash: string): Promise<string>;
|
|
2297
|
+
/**
|
|
2298
|
+
* Broadcast a transaction
|
|
2299
|
+
*/
|
|
2300
|
+
broadcastTransaction(rawTx: string): Promise<string>;
|
|
2301
|
+
/**
|
|
2302
|
+
* Get raw transaction
|
|
2303
|
+
*/
|
|
2304
|
+
getRawTransaction(txHash: string, verbose?: boolean): Promise<string | unknown>;
|
|
2305
|
+
/**
|
|
2306
|
+
* Get server version
|
|
2307
|
+
*/
|
|
2308
|
+
getServerVersion(): Promise<[string, string]>;
|
|
2309
|
+
/**
|
|
2310
|
+
* Subscribe to block headers
|
|
2311
|
+
*/
|
|
2312
|
+
subscribeBlockHeaders(callback: (header: any) => void): Promise<void>;
|
|
2313
|
+
/**
|
|
2314
|
+
* Get transaction keys for a specific transaction
|
|
2315
|
+
*/
|
|
2316
|
+
getTransactionKeys(txHash: string): Promise<any>;
|
|
2317
|
+
/**
|
|
2318
|
+
* Fetch all transaction keys from genesis to chain tip
|
|
2319
|
+
*/
|
|
2320
|
+
fetchAllTransactionKeys(progressCallback?: (height: number, totalHeight: number, blocksProcessed: number) => void): Promise<BlockTransactionKeys[]>;
|
|
2321
|
+
/**
|
|
2322
|
+
* Get transaction history for a script hash
|
|
2323
|
+
*/
|
|
2324
|
+
getHistory(scriptHash: string): Promise<any[]>;
|
|
2325
|
+
/**
|
|
2326
|
+
* Get unspent transaction outputs for a script hash
|
|
2327
|
+
*/
|
|
2328
|
+
getUnspent(scriptHash: string): Promise<any[]>;
|
|
2329
|
+
/**
|
|
2330
|
+
* Subscribe to script hash updates
|
|
2331
|
+
*/
|
|
2332
|
+
subscribeScriptHash(scriptHash: string, callback: (status: string) => void): Promise<void>;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
/**
|
|
2336
|
+
* P2P Sync Provider
|
|
2337
|
+
*
|
|
2338
|
+
* Implements the SyncProvider interface using direct P2P connections
|
|
2339
|
+
* to Navio full nodes. Parses blocks using navio-blsct for transaction
|
|
2340
|
+
* key extraction.
|
|
2341
|
+
*/
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
* P2P sync provider options
|
|
2345
|
+
*/
|
|
2346
|
+
interface P2PSyncOptions extends SyncProviderOptions {
|
|
2347
|
+
/** Host to connect to */
|
|
2348
|
+
host: string;
|
|
2349
|
+
/** Port (default based on network) */
|
|
2350
|
+
port?: number;
|
|
2351
|
+
/** Network type */
|
|
2352
|
+
network?: 'mainnet' | 'testnet' | 'regtest';
|
|
2353
|
+
/** User agent string */
|
|
2354
|
+
userAgent?: string;
|
|
2355
|
+
/** Maximum blocks to fetch per request */
|
|
2356
|
+
maxBlocksPerRequest?: number;
|
|
2357
|
+
/** Maximum headers to fetch per request */
|
|
2358
|
+
maxHeadersPerRequest?: number;
|
|
2359
|
+
}
|
|
2360
|
+
/**
|
|
2361
|
+
* P2P Sync Provider
|
|
2362
|
+
*
|
|
2363
|
+
* Connects directly to a Navio full node via P2P protocol.
|
|
2364
|
+
* Fetches blocks and extracts transaction keys for wallet scanning.
|
|
2365
|
+
*
|
|
2366
|
+
* @category Sync
|
|
2367
|
+
*/
|
|
2368
|
+
declare class P2PSyncProvider extends BaseSyncProvider {
|
|
2369
|
+
readonly type: "p2p";
|
|
2370
|
+
private client;
|
|
2371
|
+
private options;
|
|
2372
|
+
private headersByHash;
|
|
2373
|
+
private headersByHeight;
|
|
2374
|
+
private chainTipHeight;
|
|
2375
|
+
private chainTipHash;
|
|
2376
|
+
private genesisHash;
|
|
2377
|
+
private blockCache;
|
|
2378
|
+
private maxBlockCacheSize;
|
|
2379
|
+
private pendingBlocks;
|
|
2380
|
+
constructor(options: P2PSyncOptions);
|
|
2381
|
+
/**
|
|
2382
|
+
* Connect to the P2P node
|
|
2383
|
+
*/
|
|
2384
|
+
connect(): Promise<void>;
|
|
2385
|
+
/**
|
|
2386
|
+
* Disconnect from the P2P node
|
|
2387
|
+
*/
|
|
2388
|
+
disconnect(): void;
|
|
2389
|
+
/**
|
|
2390
|
+
* Check if connected
|
|
2391
|
+
*/
|
|
2392
|
+
isConnected(): boolean;
|
|
2393
|
+
/**
|
|
2394
|
+
* Get current chain tip height
|
|
2395
|
+
*/
|
|
2396
|
+
getChainTipHeight(): Promise<number>;
|
|
2397
|
+
/**
|
|
2398
|
+
* Get current chain tip
|
|
2399
|
+
*/
|
|
2400
|
+
getChainTip(): Promise<ChainTip>;
|
|
2401
|
+
/**
|
|
2402
|
+
* Get a single block header
|
|
2403
|
+
*/
|
|
2404
|
+
getBlockHeader(height: number): Promise<string>;
|
|
2405
|
+
/**
|
|
2406
|
+
* Get multiple block headers
|
|
2407
|
+
*/
|
|
2408
|
+
getBlockHeaders(startHeight: number, count: number): Promise<BlockHeadersResult>;
|
|
2409
|
+
/**
|
|
2410
|
+
* Sync headers from the network
|
|
2411
|
+
*/
|
|
2412
|
+
private syncHeaders;
|
|
2413
|
+
/**
|
|
2414
|
+
* Get transaction keys for a range of blocks
|
|
2415
|
+
*/
|
|
2416
|
+
getBlockTransactionKeysRange(startHeight: number): Promise<{
|
|
2417
|
+
blocks: BlockTransactionKeys[];
|
|
2418
|
+
nextHeight: number;
|
|
2419
|
+
}>;
|
|
2420
|
+
/**
|
|
2421
|
+
* Get transaction keys for a single block
|
|
2422
|
+
*/
|
|
2423
|
+
getBlockTransactionKeys(height: number): Promise<TransactionKeys[]>;
|
|
2424
|
+
/**
|
|
2425
|
+
* Ensure headers are synced up to the specified height
|
|
2426
|
+
*/
|
|
2427
|
+
private ensureHeadersSyncedTo;
|
|
2428
|
+
/**
|
|
2429
|
+
* Fetch a block by hash
|
|
2430
|
+
*/
|
|
2431
|
+
private fetchBlock;
|
|
2432
|
+
/**
|
|
2433
|
+
* Handle incoming block message
|
|
2434
|
+
*/
|
|
2435
|
+
private handleBlockMessage;
|
|
2436
|
+
/**
|
|
2437
|
+
* Parse block data and extract transaction keys
|
|
2438
|
+
*
|
|
2439
|
+
* Parses all transactions in the block and extracts BLSCT output keys
|
|
2440
|
+
* for wallet output detection.
|
|
2441
|
+
*/
|
|
2442
|
+
private parseBlockTransactionKeys;
|
|
2443
|
+
/**
|
|
2444
|
+
* Skip PoS proof in block data
|
|
2445
|
+
*/
|
|
2446
|
+
private skipPoSProof;
|
|
2447
|
+
private static readonly G1_POINT_SIZE;
|
|
2448
|
+
private static readonly SCALAR_SIZE;
|
|
2449
|
+
private static readonly MAX_AMOUNT;
|
|
2450
|
+
private static readonly BLSCT_MARKER;
|
|
2451
|
+
private static readonly TOKEN_MARKER;
|
|
2452
|
+
private static readonly PREDICATE_MARKER;
|
|
2453
|
+
private static readonly TRANSPARENT_VALUE_MARKER;
|
|
2454
|
+
/**
|
|
2455
|
+
* Parse a BLSCT transaction and extract output keys
|
|
2456
|
+
*/
|
|
2457
|
+
private parseBlsctTransaction;
|
|
2458
|
+
/**
|
|
2459
|
+
* Parse a BLSCT output and extract keys
|
|
2460
|
+
*/
|
|
2461
|
+
private parseBlsctOutput;
|
|
2462
|
+
/**
|
|
2463
|
+
* Parse BLSCT data from output
|
|
2464
|
+
*/
|
|
2465
|
+
private parseBlsctData;
|
|
2466
|
+
/**
|
|
2467
|
+
* Parse bulletproofs_plus range proof
|
|
2468
|
+
*/
|
|
2469
|
+
private parseRangeProof;
|
|
2470
|
+
/**
|
|
2471
|
+
* Calculate BLSCT transaction hash
|
|
2472
|
+
*/
|
|
2473
|
+
private calculateBlsctTxHash;
|
|
2474
|
+
/**
|
|
2475
|
+
* Hash a buffer using SHA256
|
|
2476
|
+
*/
|
|
2477
|
+
private hashBuffer;
|
|
2478
|
+
/**
|
|
2479
|
+
* Format output keys for the sync interface
|
|
2480
|
+
*/
|
|
2481
|
+
private formatOutputKeys;
|
|
2482
|
+
/**
|
|
2483
|
+
* Get serialized transaction output by output hash
|
|
2484
|
+
*/
|
|
2485
|
+
getTransactionOutput(outputHash: string): Promise<string>;
|
|
2486
|
+
/**
|
|
2487
|
+
* Broadcast a transaction
|
|
2488
|
+
*/
|
|
2489
|
+
broadcastTransaction(rawTx: string): Promise<string>;
|
|
2490
|
+
/**
|
|
2491
|
+
* Get raw transaction
|
|
2492
|
+
*/
|
|
2493
|
+
getRawTransaction(txHash: string, _verbose?: boolean): Promise<string>;
|
|
2494
|
+
/**
|
|
2495
|
+
* Decode variable-length integer from buffer
|
|
2496
|
+
*/
|
|
2497
|
+
private decodeVarInt;
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
export { type AmountRecoveryResult, type BackendType, type BackgroundSyncOptions, BaseSyncProvider, type BlockHash, type BlockHeader, type BlockHeadersResult, type BlockLocator, type BlockTransactionKeys, type BlockTransactionKeysRange, type CTxDestination, type CTxOut, type CTxOutBLSCTData, type ChainTip, DefaultPorts, ElectrumClient, ElectrumError, type ElectrumOptions, type ElectrumSyncOptions, ElectrumSyncProvider, type HDChain, type HexString, InvType, type InvVector, KeyManager, type KeyStorage, type MessageHeader, MessageType, NavioClient, type NavioClientConfig, type NavioNetwork, NetworkMagic, type NetworkType, type OutputHash, P2PClient, type P2PConnectionOptions, type P2PMessage, type P2POptions, type P2PSyncOptions, P2PSyncProvider, PROTOCOL_VERSION, type PublicKey$1 as PublicKey, type ReorganizationInfo, type SecretKey, type SeedType, ServiceFlags, type SubAddress, type SubAddressIdentifier, type SyncBlockHeader, type SyncOptions, type SyncProgressCallback, type SyncProvider, type SyncProviderOptions, type SyncState, type TransactionKeys, TransactionKeysSync, type TxHash, type VersionPayload, WalletDB, type WalletOutput };
|