@timestope-official/bitcoinkrypton-browser 0.0.1-0.0.2

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/types.d.ts ADDED
@@ -0,0 +1,4353 @@
1
+ export function load(path?: string): Promise<void>;
2
+
3
+ export let _path: string | undefined;
4
+
5
+ export class Class {
6
+ public static scope: any;
7
+ public static register(cls: any): void;
8
+ }
9
+
10
+ /* Client API */
11
+
12
+ declare type Handle = number;
13
+ declare type BlockListener = (blockHash: Hash) => Promise<any> | any;
14
+ declare type ConsensusChangedListener = (consensusState: Client.ConsensusState) => Promise<any> | any;
15
+ declare type HeadChangedListener = (blockHash: Hash, reason: string, revertedBlocks: Hash[], adoptedBlocks: Hash[]) => Promise<any> | any;
16
+ declare type TransactionListener = (transaction: Client.TransactionDetails) => Promise<any> | any;
17
+ declare type MempoolListener = (transactionHash: Hash) => Promise<any> | any;
18
+
19
+ export class Client {
20
+ public static Configuration: typeof ClientConfiguration;
21
+ public static ConfigurationBuilder: typeof ClientConfigurationBuilder;
22
+ public static Mempool: typeof ClientMempool;
23
+ public static MempoolStatistics: typeof ClientMempoolStatistics;
24
+ public static Network: typeof ClientNetwork;
25
+ public static BasicAddress: typeof ClientBasicAddress;
26
+ public static AddressInfo: typeof ClientAddressInfo;
27
+ public static PeerInfo: typeof ClientPeerInfo;
28
+ public static NetworkStatistics: typeof ClientNetworkStatistics;
29
+ public static TransactionDetails: typeof ClientTransactionDetails;
30
+ public static TransactionState: {
31
+ NEW: 'new';
32
+ PENDING: 'pending';
33
+ MINED: 'mined';
34
+ INVALIDATED: 'invalidated';
35
+ EXPIRED: 'expired';
36
+ CONFIRMED: 'confirmed';
37
+ };
38
+ public static Feature: {
39
+ MINING: 'MINING';
40
+ LOCAL_HISTORY: 'LOCAL_HISTORY';
41
+ MEMPOOL: 'MEMPOOL';
42
+ PASSIVE: 'PASSIVE';
43
+ };
44
+ public static ConsensusState: {
45
+ CONNECTING: 'connecting';
46
+ SYNCING: 'syncing';
47
+ ESTABLISHED: 'established';
48
+ };
49
+ public network: Client.Network;
50
+ public mempool: Client.Mempool;
51
+ public _consensusState: Client.ConsensusState;
52
+ constructor(config: Client.Configuration | object, consensus?: Promise<BaseConsensus>);
53
+ public resetConsensus(): Promise<void>;
54
+ public getHeadHash(): Promise<Hash>;
55
+ public getHeadHeight(): Promise<number>;
56
+ public getHeadBlock(includeBody?: boolean): Promise<Block>;
57
+ public getBlock(hash: Hash | string, includeBody?: boolean): Promise<Block>;
58
+ public getBlockAt(height: number, includeBody?: boolean): Promise<Block>;
59
+ public getBlockTemplate(minerAddress: Address | string, extraData?: Uint8Array | string): Promise<Block>;
60
+ public submitBlock(block: Block): Promise<boolean>;
61
+ public getAccount(address: Address | string): Promise<Account>;
62
+ public getAccounts(addresses: Array<Address | string>): Promise<Account[]>;
63
+ public getTransaction(hash: Hash | string, blockHash?: Hash | string, blockHeight?: number): Promise<Client.TransactionDetails>;
64
+ public getTransactionReceipt(hash: Hash | string): Promise<TransactionReceipt | undefined>;
65
+ public getTransactionReceiptsByAddress(address: Address | string, limit?: number): Promise<TransactionReceipt[]>;
66
+ public getTransactionReceiptsByHashes(hashes: Array<Hash | string>): Promise<TransactionReceipt[]>;
67
+ public getTransactionsByAddress(address: Address | string, sinceBlockHeight?: number, knownTransactionDetails?: Client.TransactionDetails[] | Array<ReturnType<Client.TransactionDetails['toPlain']>>, limit?: number): Promise<Client.TransactionDetails[]>;
68
+ public sendTransaction(tx: Transaction | object | string): Promise<Client.TransactionDetails>;
69
+ public addBlockListener(listener: BlockListener): Promise<Handle>;
70
+ public addConsensusChangedListener(listener: ConsensusChangedListener): Promise<Handle>;
71
+ public addHeadChangedListener(listner: HeadChangedListener): Promise<Handle>;
72
+ public addTransactionListener(listener: TransactionListener, addresses: Array<Address | string>): Promise<Handle>;
73
+ public removeListener(handle: Handle): Promise<void>;
74
+ public waitForConsensusEstablished(): Promise<void>;
75
+ }
76
+
77
+ export namespace Client {
78
+ type ConsensusState = ConsensusState.CONNECTING | ConsensusState.SYNCING | ConsensusState.ESTABLISHED;
79
+ namespace ConsensusState {
80
+ type CONNECTING = 'connecting';
81
+ type SYNCING = 'syncing';
82
+ type ESTABLISHED = 'established';
83
+ }
84
+ type Configuration = ClientConfiguration;
85
+ type ConfigurationBuilder = ClientConfigurationBuilder;
86
+ type Feature = Feature.MINING | Feature.LOCAL_HISTORY | Feature.MEMPOOL | Feature.PASSIVE;
87
+ namespace Feature {
88
+ type MINING = 'MINING';
89
+ type LOCAL_HISTORY = 'LOCAL_HISTORY';
90
+ type MEMPOOL = 'MEMPOOL';
91
+ type PASSIVE = 'PASSIVE';
92
+ }
93
+ type Mempool = ClientMempool;
94
+ type MempoolStatistics = ClientMempoolStatistics;
95
+ type Network = ClientNetwork;
96
+ type BasicAddress = ClientBasicAddress;
97
+ type AddressInfo = ClientAddressInfo;
98
+ type PeerInfo = ClientPeerInfo;
99
+ type NetworkStatistics = ClientNetworkStatistics;
100
+ type TransactionDetails = ClientTransactionDetails;
101
+ type TransactionState = TransactionState.NEW | TransactionState.PENDING | TransactionState.MINED | TransactionState.INVALIDATED | TransactionState.EXPIRED | TransactionState.CONFIRMED;
102
+ namespace TransactionState {
103
+ type NEW = 'new';
104
+ type PENDING = 'pending';
105
+ type MINED = 'mined';
106
+ type INVALIDATED = 'invalidated';
107
+ type EXPIRED = 'expired';
108
+ type CONFIRMED = 'confirmed';
109
+ }
110
+ }
111
+
112
+ declare class ClientConfiguration {
113
+ public static builder(): Client.ConfigurationBuilder;
114
+ public features: Client.Feature[];
115
+ public requiredBlockConfirmations: number;
116
+ public networkConfig: NetworkConfig;
117
+ constructor(networkConfig: NetworkConfig, features?: Client.Feature[], useVolatileStorage?: boolean, requiredBlockConfirmations?: number);
118
+ public createConsensus(): Promise<BaseConsensus>;
119
+ public hasFeature(feature: Client.Feature): boolean;
120
+ public requireFeatures(...features: Client.Feature[]): void;
121
+ public instantiateClient(): Client;
122
+ }
123
+
124
+ declare class ClientConfigurationBuilder {
125
+ constructor();
126
+ public dumb(): this;
127
+ public rtc(): this;
128
+ public ws(host: string, port?: number): this;
129
+ public wss(host: string, port: number, tlsKey: string, tlsCert: string): this;
130
+ public protocol(protocol: 'dumb' | 'rtc' | 'ws' | 'wss', host: string, port: number, tlsKey: string, tlsCert: string): this;
131
+ public volatile(volatile?: boolean): this;
132
+ public blockConfirmations(confirmations: number): this;
133
+ public feature(...feature: Client.Feature[]): this;
134
+ public reverseProxy(port: number, header: string, ...addresses: string[]): this;
135
+ public build(): Client.Configuration;
136
+ public instantiateClient(): Client;
137
+ }
138
+
139
+ declare class ClientNetwork {
140
+ constructor(client: Client);
141
+ public getPeers(): Promise<Client.PeerInfo[]>;
142
+ public getPeer(address: PeerAddress | Client.AddressInfo | string): Promise<Client.PeerInfo | null>;
143
+ public getAddresses(): Promise<Client.AddressInfo[]>;
144
+ public getAddress(address: PeerAddress | Client.AddressInfo | string): Promise<Client.AddressInfo | null>;
145
+ public getOwnAddress(): Promise<Client.BasicAddress>;
146
+ public getStatistics(): Promise<Client.NetworkStatistics>;
147
+ public connect(address: PeerAddress | Client.BasicAddress | string): Promise<void>;
148
+ public disconnect(address: PeerAddress | Client.BasicAddress | string): Promise<void>;
149
+ public ban(address: PeerAddress | Client.BasicAddress | string): Promise<void>;
150
+ public unban(address: PeerAddress | Client.BasicAddress | string): Promise<void>;
151
+ }
152
+
153
+ declare class ClientBasicAddress {
154
+ public peerAddress: PeerAddress;
155
+ public peerId: PeerId;
156
+ public services: string[];
157
+ public netAddress: NetAddress | null;
158
+ constructor(address: PeerAddress);
159
+ public toPlain(): {
160
+ peerAddress: string,
161
+ peerId: string,
162
+ services: string[],
163
+ netAddress: {
164
+ ip: Uint8Array,
165
+ reliable: boolean,
166
+ } | null,
167
+ };
168
+ }
169
+
170
+ declare class ClientAddressInfo extends ClientBasicAddress {
171
+ public banned: boolean;
172
+ public connected: boolean;
173
+ public state: number;
174
+ constructor(addressState: PeerAddressState);
175
+ public toPlain(): {
176
+ peerAddress: string,
177
+ peerId: string,
178
+ services: string[],
179
+ netAddress: {
180
+ ip: Uint8Array,
181
+ reliable: boolean,
182
+ } | null,
183
+ banned: boolean,
184
+ connected: boolean,
185
+ };
186
+ }
187
+
188
+ declare class ClientPeerInfo extends ClientBasicAddress {
189
+ public connectionSince: number;
190
+ public bytesReceived: number;
191
+ public bytesSent: number;
192
+ public latency: number;
193
+ public version: number;
194
+ public state: number;
195
+ public timeOffset: number;
196
+ public headHash: Hash;
197
+ public userAgent: string;
198
+ constructor(connection: PeerConnection);
199
+ public toPlain(): {
200
+ peerAddress: string,
201
+ peerId: string,
202
+ services: string[],
203
+ netAddress: {
204
+ ip: Uint8Array,
205
+ reliable: boolean,
206
+ } | null,
207
+ connectionSince: number,
208
+ bytesReceived: number,
209
+ bytesSent: number,
210
+ latency: number,
211
+ version: number,
212
+ state: number,
213
+ timeOffset: number,
214
+ headHash: string,
215
+ userAgent: string,
216
+ };
217
+ }
218
+
219
+ declare class ClientNetworkStatistics {
220
+ public bytesReceived: number;
221
+ public bytesSent: number;
222
+ public totalPeerCount: number;
223
+ public peerCountsByType: {
224
+ total: number,
225
+ connecting: number,
226
+ dumb: number,
227
+ rtc: number,
228
+ ws: number,
229
+ wss: number,
230
+ };
231
+ public totalKnownAddresses: number;
232
+ public knownAddressesByType: {
233
+ total: number,
234
+ rtc: number,
235
+ ws: number,
236
+ wss: number,
237
+ };
238
+ public timeOffset: number;
239
+ constructor(network: Network);
240
+ public toPlain(): {
241
+ bytesReceived: number,
242
+ bytesSent: number,
243
+ totalPeerCount: number,
244
+ peerCountsByType: {
245
+ total: number,
246
+ connecting: number,
247
+ dumb: number,
248
+ rtc: number,
249
+ ws: number,
250
+ wss: number,
251
+ },
252
+ totalKnownAddresses: number,
253
+ knownAddressesByType: {
254
+ total: number,
255
+ rtc: number,
256
+ ws: number,
257
+ wss: number,
258
+ },
259
+ timeOffset: number,
260
+ };
261
+ }
262
+
263
+ declare class ClientMempool {
264
+ constructor(client: Client);
265
+ public getTransactions(): Promise<Hash[]>;
266
+ public getStatistics(): Promise<Client.MempoolStatistics>;
267
+ public addTransactionAddedListener(listener: MempoolListener): Promise<Handle>;
268
+ public addTransactionRemovedListener(listener: MempoolListener): Promise<Handle>;
269
+ public removeListener(handle: Handle): void;
270
+ }
271
+
272
+ declare class ClientMempoolStatistics {
273
+ public count: number;
274
+ public size: number;
275
+ public countInBuckets: {buckets: []} | any;
276
+ public sizeInBuckets: {buckets: []} | any;
277
+ constructor(mempoolContents: Transaction[]);
278
+ }
279
+
280
+ declare class ClientTransactionDetails {
281
+ public static fromPlain(o: object): Client.TransactionDetails;
282
+ public transactionHash: Hash;
283
+ public format: Transaction.Format;
284
+ public sender: Address;
285
+ public senderType: Account.Type;
286
+ public recipient: Address;
287
+ public recipientType: Account.Type;
288
+ public value: BigNumber;
289
+ public fee: BigNumber;
290
+ public feePerByte: BigNumber;
291
+ public validityStartHeight: number;
292
+ public network: number;
293
+ public flags: number;
294
+ public data: {raw: Uint8Array};
295
+ public proof: {raw: Uint8Array};
296
+ public size: number;
297
+ public valid: boolean;
298
+ public transaction: Transaction;
299
+ public state: Client.TransactionState;
300
+ public blockHash: Hash;
301
+ public blockHeight: number;
302
+ public confirmations: number;
303
+ public timestamp: number;
304
+ constructor(
305
+ transaction: Transaction,
306
+ state: Client.TransactionState,
307
+ blockHash?: Hash,
308
+ blockHeight?: number,
309
+ confirmations?: number,
310
+ timestamp?: number,
311
+ );
312
+ public toPlain(): {
313
+ transactionHash: string,
314
+ format: string;
315
+ sender: string;
316
+ senderType: string;
317
+ recipient: string;
318
+ recipientType: string;
319
+ value: string;
320
+ fee: string;
321
+ feePerByte: string;
322
+ validityStartHeight: number;
323
+ network: string;
324
+ flags: number;
325
+ data: {raw: string};
326
+ proof: {
327
+ raw: string,
328
+ signature?: string,
329
+ publicKey?: string,
330
+ signer?: string,
331
+ pathLength?: number,
332
+ };
333
+ size: number;
334
+ valid: boolean;
335
+ state: Client.TransactionState;
336
+ blockHash?: string;
337
+ blockHeight?: number;
338
+ confirmations?: number;
339
+ timestamp?: number;
340
+ };
341
+ }
342
+
343
+ export class LogNative {
344
+ constructor()
345
+ public isLoggable(tag: string, level: number): boolean;
346
+ public setLoggable(tag: string, level: number): void;
347
+ public msg(level: number, tag: string | { name: string }, args: any[]): void;
348
+ }
349
+
350
+ export class Log {
351
+ public static instance: Log;
352
+ public static TRACE: Log.Level.TRACE;
353
+ public static VERBOSE: Log.Level.VERBOSE;
354
+ public static DEBUG: Log.Level.DEBUG;
355
+ public static INFO: Log.Level.INFO;
356
+ public static WARNING: Log.Level.WARNING;
357
+ public static ERROR: Log.Level.ERROR;
358
+ public static ASSERT: Log.Level.ASSERT;
359
+ public static Level: {
360
+ TRACE: 1;
361
+ VERBOSE: 2;
362
+ DEBUG: 3;
363
+ INFO: 4;
364
+ WARNING: 5;
365
+ ERROR: 6;
366
+ ASSERT: 7;
367
+ toStringTag(level: Log.Level): string;
368
+ toString(level: Log.Level): string;
369
+ get(v: string | number | Log.Level): Log.Level;
370
+ };
371
+ public level: Log.Level;
372
+ constructor(native: LogNative);
373
+ public setLoggable(tag: string, level: Log.Level): void;
374
+ public msg(level: Log.Level, tag: string | { name: string }, args: any[]): void;
375
+ public d(tag: string | { name: string }, message: string | (() => string), args: any[]): void;
376
+ public e(tag: string | { name: string }, message: string | (() => string), args: any[]): void;
377
+ public i(tag: string | { name: string }, message: string | (() => string), args: any[]): void;
378
+ public v(tag: string | { name: string }, message: string | (() => string), args: any[]): void;
379
+ public w(tag: string | { name: string }, message: string | (() => string), args: any[]): void;
380
+ public t(tag: string | { name: string }, message: string | (() => string), args: any[]): void;
381
+ }
382
+
383
+ export namespace Log {
384
+ type Level = Level.TRACE | Level.VERBOSE | Level.DEBUG | Level.INFO | Level.WARNING | Level.ERROR | Level.ASSERT;
385
+ namespace Level {
386
+ type TRACE = 1;
387
+ type VERBOSE = 2;
388
+ type DEBUG = 3;
389
+ type INFO = 4;
390
+ type WARNING = 5;
391
+ type ERROR = 6;
392
+ type ASSERT = 7;
393
+ }
394
+ }
395
+
396
+ export class Observable {
397
+ public on(type: string, callback: (...args: any[]) => any): number;
398
+ public off(type: string, id: number): void;
399
+ public fire(type: string, ...args: any[]): (Promise<any> | null);
400
+ }
401
+
402
+ export abstract class DataChannel extends Observable {
403
+ public static CHUNK_SIZE_MAX: 16384; // 16 kb
404
+ public static MESSAGE_SIZE_MAX: 10485760; // 10 mb
405
+ public static CHUNK_TIMEOUT: 5000; // 5 seconds
406
+ public static MESSAGE_TIMEOUT: 3200000;
407
+ public static ReadyState: {
408
+ CONNECTING: 0;
409
+ OPEN: 1;
410
+ CLOSING: 2;
411
+ CLOSED: 3;
412
+ fromString(str: string): DataChannel.ReadyState;
413
+ };
414
+ public abstract readyState: DataChannel.ReadyState;
415
+ public lastMessageReceivedAt: number;
416
+ constructor();
417
+ public isExpectingMessage(type: Message.Type): boolean;
418
+ public confirmExpectedMessage(type: Message.Type, success: boolean): void;
419
+ public expectMessage(types: Message.Type | Message.Type[], timeoutCallback: () => any, msgTimeout?: number, chunkTimeout?: number): void;
420
+ public close(): void;
421
+ public send(msg: Uint8Array): void;
422
+ public abstract sendChunk(msg: Uint8Array): void;
423
+ }
424
+
425
+ export namespace DataChannel {
426
+ type ReadyState = ReadyState.CONNECTING | ReadyState.OPEN | ReadyState.CLOSING | ReadyState.CLOSED;
427
+ namespace ReadyState {
428
+ type CONNECTING = 0;
429
+ type OPEN = 1;
430
+ type CLOSING = 2;
431
+ type CLOSED = 3;
432
+ }
433
+ }
434
+
435
+ export class ExpectedMessage {
436
+ constructor(
437
+ types: Message.Type[],
438
+ timeoutCallback: () => any,
439
+ msgTimeout: number,
440
+ chunkTimeout: number,
441
+ );
442
+ }
443
+
444
+ export class CryptoLib {
445
+ public static instance: { getRandomValues(buf: Uint8Array): Uint8Array };
446
+ }
447
+
448
+ export class WebRtcFactory {
449
+ public static newPeerConnection(configuration?: RTCConfiguration): RTCPeerConnection;
450
+ public static newSessionDescription(rtcSessionDescriptionInit: any): RTCSessionDescription;
451
+ public static newIceCandidate(rtcIceCandidateInit: any): RTCIceCandidate;
452
+ }
453
+
454
+ export class WebSocketFactory {
455
+ public static newWebSocketServer(networkConfig: WsNetworkConfig | WssNetworkConfig): any;
456
+ public static newWebSocket(url: string, [options]: any): WebSocket;
457
+ }
458
+
459
+ export class WebSocketServer {
460
+ public static UPGRADE_TIMEOUT: 3000; // 3 seconds
461
+ public static TLS_HANDSHAKE_TIMEOUT: 3000; // 3 seconds
462
+ public static PAYLOAD_MAX: number;
463
+ public static PENDING_UPGRADES_MAX: 1000;
464
+ public static PENDING_UPGRADES_PER_IP_MAX: 2;
465
+ public static PENDING_UPGRADES_PER_SUBNET_MAX: 6;
466
+ public static CONNECTION_RATE_LIMIT_PER_IP: 10; // per minute
467
+ public static CONNECTION_RATE_LIMIT_PER_SUBNET: 30; // per minute
468
+ public static LIMIT_TRACKING_AGE_MAX: 120000; // 2 minutes
469
+ public static HOUSEKEEPING_INTERVAL: 300000; // 5 minutes
470
+ constructor(
471
+ networkConfig: WsNetworkConfig | WssNetworkConfig,
472
+ );
473
+ }
474
+
475
+ export class ConstantHelper {
476
+ public static instance: ConstantHelper;
477
+ constructor();
478
+ public isConstant(constant: string): boolean;
479
+ public get(constant: string): number;
480
+ public set(constant: string, value: number): void;
481
+ public reset(constant: string): void;
482
+ public resetAll(): void;
483
+ }
484
+
485
+ export class Services {
486
+ public static NONE: 0;
487
+ public static FLAG_NANO: 1;
488
+ public static FLAG_LIGHT: 2;
489
+ public static FLAG_FULL: 4;
490
+ public static ALL_LEGACY: 7;
491
+ public static FULL_BLOCKS: number;
492
+ public static BLOCK_HISTORY: number;
493
+ public static BLOCK_PROOF: number;
494
+ public static CHAIN_PROOF: number;
495
+ public static ACCOUNTS_PROOF: number;
496
+ public static ACCOUNTS_CHUNKS: number;
497
+ public static MEMPOOL: number;
498
+ public static TRANSACTION_INDEX: number;
499
+ public static BODY_PROOF: number;
500
+ public static ALL_CURRENT: number;
501
+ public static NAMES: {[name: number]: string};
502
+ public static PROVIDES_FULL: number;
503
+ public static PROVIDES_LIGHT: number;
504
+ public static PROVIDES_NANO: number;
505
+ public static PROVIDES_PICO: number;
506
+ public static ACCEPTS_FULL: number;
507
+ public static ACCEPTS_LIGHT: number;
508
+ public static ACCEPTS_NANO: number;
509
+ public static ACCEPTS_PICO: number;
510
+ public static ACCEPTS_SPV: number;
511
+ public static isFullNode(services: number): boolean;
512
+ public static isLightNode(services: number): boolean;
513
+ public static isNanoNode(services: number): boolean;
514
+ public static providesServices(flags: number, ...services: number[]): boolean;
515
+ public static legacyProvideToCurrent(flags: number): number;
516
+ public static toNameArray(flags: number): string[];
517
+ public provided: number;
518
+ public accepted: number;
519
+ constructor(provided?: number, accepted?: number);
520
+ }
521
+
522
+ export class Timers {
523
+ constructor();
524
+ public setTimeout(key: any, fn: () => any, waitTime: number): void;
525
+ public clearTimeout(key: any): void;
526
+ public resetTimeout(key: any, fn: () => any, waitTime: number): void;
527
+ public timeoutExists(key: any): boolean;
528
+ public setInterval(key: any, fn: () => any, intervalTime: number): void;
529
+ public clearInterval(key: any): void;
530
+ public resetInterval(key: any, fn: () => any, intervalTime: number): void;
531
+ public intervalExists(key: any): boolean;
532
+ public clearAll(): void;
533
+ }
534
+
535
+ export class Version {
536
+ public static CODE: 2;
537
+ public static CORE_JS_VERSION: string;
538
+ public static isCompatible(code: number): boolean;
539
+ public static createUserAgent(appAgent?: string): string;
540
+ }
541
+
542
+ export class Time {
543
+ public offset: number;
544
+ constructor(offset?: number);
545
+ public now(): number;
546
+ }
547
+
548
+ export class EventLoopHelper {
549
+ public static webYield(): Promise<void>;
550
+ public static yield(): Promise<void>;
551
+ }
552
+
553
+ export class IteratorUtils {
554
+ public static alternate<T>(...iterators: Array<Iterator<T>>): Iterable<T>;
555
+ }
556
+
557
+ export class ArrayUtils {
558
+ public static randomElement(arr: any[]): any;
559
+ public static subarray(uintarr: Uint8Array, begin?: number, end?: number): Uint8Array;
560
+ public static k_combinations(list: any[], k: number): Generator;
561
+ }
562
+
563
+ export class HashMap<K, V> {
564
+ public length: number;
565
+ constructor(fnHash?: (o: object) => string);
566
+ public get(key: K): V | undefined;
567
+ public put(key: K, value: V): void;
568
+ public remove(key: K): void;
569
+ public clear(): void;
570
+ public contains(key: K): boolean;
571
+ public keys(): K[];
572
+ public keyIterator(): Iterator<K>;
573
+ public values(): V[];
574
+ public valueIterator(): Iterator<V>;
575
+ public entries(): Array<[K, V]>;
576
+ public entryIterator(): Iterator<[K, V]>;
577
+ public isEmpty(): boolean;
578
+ }
579
+
580
+ export class HashSet<V> {
581
+ public [Symbol.iterator]: Iterator<V>;
582
+ public length: number;
583
+ constructor(fnHash?: (o: object) => string);
584
+ public add(value: V): void;
585
+ public addAll(collection: Iterable<V>): void;
586
+ public get(value: V): V | undefined;
587
+ public remove(value: V): void;
588
+ public removeAll(collection: V[]): void;
589
+ public clear(): void;
590
+ public contains(value: V): boolean;
591
+ public values(): V[];
592
+ public valueIterator(): Iterator<V>;
593
+ public isEmpty(): boolean;
594
+ }
595
+
596
+ export class LimitHashSet {
597
+ public [Symbol.iterator]: Iterator<any>;
598
+ public length: number;
599
+ constructor(limit: number, fnHash?: (o: object) => string);
600
+ public add(value: any): void;
601
+ public addAll(collection: Iterable<any>): void;
602
+ public get(value: any): any;
603
+ public remove(value: any): void;
604
+ public removeAll(collection: any[]): void;
605
+ public clear(): void;
606
+ public contains(value: any): boolean;
607
+ public values(): any[];
608
+ public valueIterator(): Iterator<any>;
609
+ public isEmpty(): boolean;
610
+ }
611
+
612
+ export class InclusionHashSet<V> {
613
+ public [Symbol.iterator]: Iterator<string>;
614
+ public length: number;
615
+ constructor(fnHash?: (o: object) => string);
616
+ public add(value: V): void;
617
+ public addAll(collection: Iterable<V>): void;
618
+ public remove(value: V): void;
619
+ public removeAll(collection: V[]): void;
620
+ public clear(): void;
621
+ public contains(value: V): boolean;
622
+ public values(): string[];
623
+ public valueIterator(): Iterator<string>;
624
+ public isEmpty(): boolean;
625
+ public clone(): InclusionHashSet<V>;
626
+ }
627
+
628
+ export class LimitInclusionHashSet {
629
+ public [Symbol.iterator]: Iterator<any>;
630
+ public length: number;
631
+ constructor(limit: number, fnHash?: (o: object) => string);
632
+ public add(value: any): void;
633
+ public addAll(collection: Iterable<any>): void;
634
+ public remove(value: any): void;
635
+ public removeAll(collection: any[]): void;
636
+ public clear(): void;
637
+ public contains(value: any): boolean;
638
+ public values(): any[];
639
+ public valueIterator(): Iterator<any>;
640
+ public isEmpty(): boolean;
641
+ public clone(): LimitInclusionHashSet;
642
+ }
643
+
644
+ export class LimitIterable<T> {
645
+ public static iterator<V>(iterator: Iterator<V>, limit: number): { next: () => object };
646
+ constructor(it: Iterable<T> | Iterator<T>, limit: number);
647
+ public [Symbol.iterator](): { next: () => object };
648
+ }
649
+
650
+ export class LinkedList {
651
+ public first: any;
652
+ public last: any;
653
+ public length: number;
654
+ constructor(...args: any[]);
655
+ public push(value: any): void;
656
+ public unshift(value: any): void;
657
+ public pop(): any;
658
+ public shift(): any;
659
+ public clear(): void;
660
+ public [Symbol.iterator](): Iterator<any>;
661
+ public iterator(): Iterator<any>;
662
+ public isEmpty(): boolean;
663
+ }
664
+
665
+ export class UniqueLinkedList extends LinkedList {
666
+ constructor(fnHash: (o: object) => string);
667
+ public push(value: any, moveBack?: boolean): void;
668
+ public unshift(value: any): void;
669
+ public pop(): any;
670
+ public shift(): any;
671
+ public clear(): void;
672
+ public get(value: any): any;
673
+ public contains(value: any): boolean;
674
+ public remove(value: any): void;
675
+ public moveBack(value: any): void;
676
+ }
677
+
678
+ export class Queue {
679
+ public length: number;
680
+ constructor(...args: any[]);
681
+ public enqueue(value: any): void;
682
+ public enqueueAll(values: any[]): void;
683
+ public dequeue(): any;
684
+ public dequeueMulti(count: number): any[];
685
+ public peek(): any;
686
+ public clear(): void;
687
+ public isEmpty(): boolean;
688
+ }
689
+
690
+ export class UniqueQueue extends Queue {
691
+ constructor(fnHash: (o: object) => string);
692
+ public contains(value: any): boolean;
693
+ public remove(value: any): void;
694
+ public requeue(value: any): void;
695
+ }
696
+
697
+ export class ThrottledQueue extends UniqueQueue {
698
+ public available: number;
699
+ constructor(
700
+ maxAtOnce?: number,
701
+ allowanceNum?: number,
702
+ allowanceInterval?: number,
703
+ maxSize?: number,
704
+ allowanceCallback?: () => any,
705
+ );
706
+ public stop(): void;
707
+ public enqueue(value: any): void;
708
+ public dequeue(): any;
709
+ public dequeueMulti(count: number): any[];
710
+ public isAvailable(): boolean;
711
+ }
712
+
713
+ export class SortedList {
714
+ public length: number;
715
+ constructor([sortedList]: any[], compare?: (a: any, b: any) => -1 | 0 | 1);
716
+ public indexOf(o: any): number;
717
+ public add(value: any): void;
718
+ public shift(): any;
719
+ public pop(): any;
720
+ public peekFirst(): any;
721
+ public peekLast(): any;
722
+ public remove(value: any): void;
723
+ public clear(): void;
724
+ public values(): any[];
725
+ public [Symbol.iterator](): Iterator<any>;
726
+ public copy(): SortedList;
727
+ }
728
+
729
+ export class Assert {
730
+ public static that(condition: boolean, message?: string): void;
731
+ }
732
+
733
+ export class CryptoUtils {
734
+ public static SHA512_BLOCK_SIZE: 128;
735
+ public static computeHmacSha512(key: Uint8Array, data: Uint8Array): Uint8Array;
736
+ public static computePBKDF2sha512(password: Uint8Array, salt: Uint8Array, iterations: number, derivedKeyLength: number): SerialBuffer;
737
+ public static otpKdfLegacy(message: Uint8Array, key: Uint8Array, salt: Uint8Array, iterations: number): Promise<Uint8Array>;
738
+ public static otpKdf(message: Uint8Array, key: Uint8Array, salt: Uint8Array, iterations: number): Promise<Uint8Array>;
739
+ }
740
+
741
+ export class BufferUtils {
742
+ public static BASE64_ALPHABET: string;
743
+ public static BASE32_ALPHABET: {
744
+ RFC4648: string;
745
+ RFC4648_HEX: string;
746
+ KRYPTON: string;
747
+ };
748
+ public static HEX_ALPHABET: string;
749
+ public static toAscii(buffer: Uint8Array): string;
750
+ public static fromAscii(string: string): SerialBuffer;
751
+ public static toBase64(buffer: Uint8Array): string;
752
+ public static fromBase64(base64: string, length?: number): SerialBuffer;
753
+ public static toBase64Url(buffer: Uint8Array): string;
754
+ public static fromBase64Url(base64: string, length?: number): SerialBuffer;
755
+ public static toBase32(buf: Uint8Array, alphabet?: string): string;
756
+ public static fromBase32(base32: string, alphabet?: string): Uint8Array;
757
+ public static toHex(buffer: Uint8Array): string;
758
+ public static fromHex(hex: string, length?: number): SerialBuffer;
759
+ public static toBinary(buffer: Uint8Array): string;
760
+ public static fromUtf8(str: string): Uint8Array;
761
+ public static fromAny(o: Uint8Array | string, length?: number): SerialBuffer;
762
+ public static concatTypedArrays(a: Uint8Array | Uint16Array | Uint32Array, b: Uint8Array | Uint16Array | Uint32Array): Uint8Array | Uint16Array | Uint32Array;
763
+ public static equals(a: Uint8Array | Uint16Array | Uint32Array, b: Uint8Array | Uint16Array | Uint32Array): boolean;
764
+ public static compare(a: Uint8Array | Uint16Array | Uint32Array, b: Uint8Array | Uint16Array | Uint32Array): -1 | 0 | 1;
765
+ public static xor(a: Uint8Array, b: Uint8Array): Uint8Array;
766
+ }
767
+
768
+ export class SerialBuffer extends Uint8Array {
769
+ public static EMPTY: SerialBuffer;
770
+ public static varUintSize(value: number): number;
771
+ public static varLengthStringSize(value: string): number;
772
+ public readPos: number;
773
+ public writePos: number;
774
+ constructor(bufferOrArrayOrLength: any)
775
+ public subarray(start?: number, end?: number): Uint8Array;
776
+ public reset(): void;
777
+ public read(length: number): Uint8Array;
778
+ public write(array: any): void;
779
+ public readUint8(): number;
780
+ public writeUint8(value: number): void;
781
+ public readUint16(): number;
782
+ public writeUint16(value: number): void;
783
+ public readUint32(): number;
784
+ public writeUint32(value: number): void;
785
+ public readUint64(): number;
786
+ public writeUint64(value: number): void;
787
+ public readUint128(): BigNumber;
788
+ public writeUint128(value: BigNumber): void;
789
+ public readVarUint(): number;
790
+ public writeVarUint(value: number): void;
791
+ public readFloat64(): number;
792
+ public writeFloat64(value: number): void;
793
+ public readString(length: number): string;
794
+ public writeString(value: string, length: number): void;
795
+ public readPaddedString(length: number): string;
796
+ public writePaddedString(value: string, length: number): void;
797
+ public readVarLengthString(): string;
798
+ public writeVarLengthString(value: string): void;
799
+ }
800
+
801
+ export class Synchronizer extends Observable {
802
+ public working: boolean;
803
+ public length: number;
804
+ public totalElapsed: number;
805
+ public totalJobs: number;
806
+ public totalThrottles: number;
807
+ constructor(throttleAfter?: number, throttleWait?: number);
808
+ public push<T>(fn: () => T): Promise<T>;
809
+ public clear(): void;
810
+ }
811
+
812
+ export class MultiSynchronizer extends Observable {
813
+ constructor(throttleAfter?: number, throttleWait?: number);
814
+ public push<T>(tag: string, fn: () => T): Promise<T>;
815
+ public clear(): void;
816
+ public isWorking(tag: string): boolean;
817
+ }
818
+
819
+ export class PrioritySynchronizer extends Observable {
820
+ public working: boolean;
821
+ public length: number;
822
+ public totalElapsed: number;
823
+ public totalJobs: number;
824
+ public totalThrottles: number;
825
+ constructor(
826
+ numPriorities: number,
827
+ throttleAfter?: number,
828
+ throttleWait?: number,
829
+ );
830
+ public push<T>(priority: number, fn: () => T): Promise<T>;
831
+ public clear(): void;
832
+ }
833
+
834
+ export class RateLimit {
835
+ public lastReset: number;
836
+ constructor(allowedOccurrences: number, timeRange?: number);
837
+ public note(number?: number): boolean;
838
+ }
839
+
840
+ export class IWorker {
841
+ public static areWorkersAsync: boolean;
842
+ public static createProxy(clazz: any, name: string, worker: Worker): IWorker.Proxy;
843
+ public static startWorkerForProxy(clazz: any, name: string, workerScript: string): IWorker.Proxy;
844
+ public static stubBaseOnMessage(msg: { data: { command: string, args: any[], id: number | string } }): Promise<void>;
845
+ public static prepareForWorkerUse(baseClazz: any, impl: any): void;
846
+ }
847
+
848
+ export namespace IWorker {
849
+ type Proxy = (clazz: any) => any;
850
+ function Stub(clazz: any): any;
851
+ function Pool(clazz: any): any;
852
+ }
853
+
854
+ export class WasmHelper {
855
+ public static doImport(): Promise<void>;
856
+ public static importWasm(wasm: string, module?: string): Promise<boolean>;
857
+ public static importScript(script: string, module?: string): Promise<boolean>;
858
+ public static fireModuleLoaded(module?: string): void;
859
+ }
860
+
861
+ export class CryptoWorker {
862
+ public static lib: CryptoLib;
863
+ public static getInstanceAsync(): Promise<CryptoWorkerImpl>;
864
+ public computeArgon2d(input: Uint8Array): Promise<Uint8Array>;
865
+ public computeArgon2dBatch(input: Uint8Array[]): Promise<Uint8Array[]>;
866
+ public kdfLegacy(key: Uint8Array, salt: Uint8Array, iterations: number, outputSize: number): Promise<Uint8Array>;
867
+ public kdf(key: Uint8Array, salt: Uint8Array, iterations: number, outputSize: number): Promise<Uint8Array>;
868
+ public blockVerify(block: Uint8Array, transactionValid: boolean[], timeNow: number, genesisHash: Uint8Array, networkId: number): Promise<{ valid: boolean, pow: SerialBuffer, interlinkHash: SerialBuffer, bodyHash: SerialBuffer }>;
869
+ }
870
+
871
+ export class CryptoWorkerImpl extends IWorker.Stub(CryptoWorker) {
872
+ constructor();
873
+ public init(name: string): Promise<void>;
874
+ public computeArgon2d(input: Uint8Array): Uint8Array;
875
+ public computeArgon2dBatch(input: Uint8Array[]): Uint8Array[];
876
+ public kdfLegacy(key: Uint8Array, salt: Uint8Array, iterations: number, outputSize: number): Uint8Array;
877
+ public kdf(key: Uint8Array, salt: Uint8Array, iterations: number, outputSize: number): Uint8Array;
878
+ public blockVerify(block: Uint8Array, transactionValid: boolean[], timeNow: number, genesisHash: Uint8Array, networkId: number): Promise<{ valid: boolean, pow: SerialBuffer, interlinkHash: SerialBuffer, bodyHash: SerialBuffer }>;
879
+ }
880
+
881
+ export class CRC8 {
882
+ public static compute(buf: Uint8Array): number;
883
+ }
884
+
885
+ export class CRC32 {
886
+ public static compute(buf: Uint8Array): number;
887
+ }
888
+
889
+ export class BigNumber {
890
+ constructor(n: number | string | BigNumber, b?: number);
891
+ public CloseEvent(configObject: any): BigNumber;
892
+ public config(obj: any): any;
893
+ public set(obj: any): any;
894
+ public isBigNumber(v: any): boolean;
895
+ public maximum(...args: BigNumber[]): BigNumber;
896
+ public max(...args: BigNumber[]): BigNumber;
897
+ public minimum(...args: BigNumber[]): BigNumber;
898
+ public min(...args: BigNumber[]): BigNumber;
899
+ public random(db: number): BigNumber;
900
+ public plus(n: number | string | BigNumber): BigNumber;
901
+ public minus(n: number | string | BigNumber): BigNumber;
902
+ public times(n: number | string | BigNumber): BigNumber;
903
+ public div(n: number | string | BigNumber): BigNumber;
904
+ public idiv(n: number | string | BigNumber): BigNumber;
905
+ public pow(n: number, m?: number): BigNumber;
906
+ public mod(n: number | string | BigNumber, b?: number): BigNumber;
907
+ public integerValue(rm?: number): BigNumber;
908
+ public eq(n: number | string | BigNumber, b?: number): boolean;
909
+ public gt(n: number | string | BigNumber, b?: number): boolean;
910
+ public gte(n: number | string | BigNumber, b?: number): boolean;
911
+ public lt(n: number | string | BigNumber, b?: number): boolean;
912
+ public lte(n: number | string | BigNumber, b?: number): boolean;
913
+ public toNumber(): number;
914
+ public toString(): string;
915
+ public toFixed(n: number, rm?: number): string;
916
+ }
917
+
918
+ export class NumberUtils {
919
+ public static UINT8_MAX: 255;
920
+ public static UINT16_MAX: 65535;
921
+ public static UINT32_MAX: 4294967295;
922
+ public static UINT64_MAX: number;
923
+ public static UINT128_MAX: BigNumber;
924
+ public static isUint8(val: unknown): boolean;
925
+ public static isUint16(val: unknown): boolean;
926
+ public static isUint32(val: unknown): boolean;
927
+ public static isUint64(val: unknown): boolean;
928
+ public static isUint128(val: BigNumber): boolean;
929
+ public static randomUint32(): number;
930
+ public static randomUint64(): number;
931
+ public static fromBinary(bin: string): number;
932
+ }
933
+
934
+ export class MerkleTree {
935
+ public static computeRoot(values: any[], fnHash?: (o: any) => Hash): Hash;
936
+ }
937
+
938
+ export class MerklePath {
939
+ public static compute(values: any[], leafValue: any, fnHash?: (o: any) => Hash): MerklePath;
940
+ public static unserialize(buf: SerialBuffer): MerklePath;
941
+ public serializedSize: number;
942
+ public nodes: MerklePathNode[];
943
+ constructor(nodes: MerklePathNode[]);
944
+ public computeRoot(leafValue: any, fnHash?: (o: any) => Hash): Hash;
945
+ public serialize(buf?: SerialBuffer): SerialBuffer;
946
+ public equals(o: MerklePath): boolean;
947
+ }
948
+
949
+ export class MerklePathNode {
950
+ public hash: Hash;
951
+ public left: boolean;
952
+ constructor(hash: Hash, left: boolean);
953
+ public equals(o: MerklePathNode): boolean;
954
+ }
955
+
956
+ export class MerkleProof {
957
+ public static Operation: {
958
+ CONSUME_PROOF: 0;
959
+ CONSUME_INPUT: 1;
960
+ HASH: 2;
961
+ };
962
+ public static compute(values: any[], leafValues: any[], fnHash?: (o: any) => Hash): MerkleProof;
963
+ public static computeWithAbsence(values: any[], leafValues: any[], fnCompare: (a: any, b: any) => number, fnHash?: (o: any) => Hash): MerkleProof;
964
+ public static unserialize(buf: SerialBuffer): MerkleProof;
965
+ public serializedSize: number;
966
+ public nodes: Hash[];
967
+ constructor(hashes: any[], operations: MerkleProof.Operation[]);
968
+ public computeRoot(leafValues: any[], fnHash?: (o: any) => Hash): Hash;
969
+ public serialize(buf?: SerialBuffer): SerialBuffer;
970
+ public equals(o: MerkleProof): boolean;
971
+ }
972
+
973
+ export namespace MerkleProof {
974
+ type Operation = Operation.CONSUME_PROOF | Operation.CONSUME_INPUT | Operation.HASH;
975
+ namespace Operation {
976
+ type CONSUME_PROOF = 0;
977
+ type CONSUME_INPUT = 1;
978
+ type HASH = 2;
979
+ }
980
+ }
981
+
982
+ export class PlatformUtils {
983
+ public static readonly userAgentString: string;
984
+ public static readonly hardwareConcurrency: number;
985
+ public static isBrowser(): boolean;
986
+ public static isWeb(): boolean;
987
+ public static isNodeJs(): boolean;
988
+ public static supportsWebRTC(): boolean;
989
+ public static supportsWS(): boolean;
990
+ public static isOnline(): boolean;
991
+ public static isWindows(): boolean;
992
+ }
993
+
994
+ export class StringUtils {
995
+ public static isMultibyte(str: string): boolean;
996
+ public static isHex(str: string): boolean;
997
+ public static isHexBytes(str: string, length?: number): boolean;
998
+ public static commonPrefix(str1: string, str2: string): string;
999
+ public static lpad(str: string, padString: string, length: number): string;
1000
+ }
1001
+
1002
+ export class Policy {
1003
+ public static BLOCK_TARGET_MAX: BigNumber;
1004
+ public static DIFFICULTY_BLOCK_WINDOW: 120;
1005
+ public static DIFFICULTY_MAX_ADJUSTMENT_FACTOR: 2;
1006
+ public static TRANSACTION_VALIDITY_WINDOW: 120;
1007
+ public static SATOSHIS_PER_COIN: 1e11;
1008
+ public static INITIAL_SUPPLY: 0;
1009
+ public static INITIAL_BLOCK_REWARD: 5e11;
1010
+ public static HALVING_TARGET_MAX: 21;
1011
+ public static HALVING_INTERVAL: 21e5;
1012
+ public static NUM_BLOCKS_VERIFICATION: 250;
1013
+ public static coinsToSatoshis(coins: BigNumber | number | string): BigNumber;
1014
+ public static satoshisToCoins(satoshis: BigNumber | number | string): BigNumber;
1015
+ public static blockRewardAt(blockHeight: number): BigNumber;
1016
+ public static blockTime(blockHeight: number): number;
1017
+ public static txFee(blockHeight: number): BigNumber;
1018
+ public static difficultyBlockWindow(blockHeight: number): number;
1019
+ }
1020
+
1021
+ export abstract class Serializable {
1022
+ public equals(o: Serializable): boolean;
1023
+ public compare(o: Serializable): number;
1024
+ public hashCode(): string;
1025
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1026
+ public toString(): string;
1027
+ public toBase64(): string;
1028
+ public toHex(): string;
1029
+ }
1030
+
1031
+ export class Hash extends Serializable {
1032
+ public static SIZE: Map<Hash.Algorithm, number>;
1033
+ public static NULL: Hash;
1034
+ public static Algorithm: {
1035
+ BLAKE2B: 1,
1036
+ ARGON2D: 2,
1037
+ SHA256: 3,
1038
+ SHA512: 4,
1039
+ RIPEMD160: 5,
1040
+ KECCAK256: 6
1041
+ toString(hashAlgorithm: Hash.Algorithm): string;
1042
+ fromAny(algorithm: Hash.Algorithm | string): Hash.Algorithm;
1043
+ };
1044
+ public static light(arr: Uint8Array): Hash;
1045
+ public static blake2b(arr: Uint8Array): Hash;
1046
+ public static hard(arr: Uint8Array): Promise<Hash>;
1047
+ public static argon2d(arr: Uint8Array): Promise<Hash>;
1048
+ public static sha256(arr: Uint8Array): Hash;
1049
+ public static sha512(arr: Uint8Array): Hash;
1050
+ public static compute(arr: Uint8Array, algorithm: Hash.Algorithm.BLAKE2B | Hash.Algorithm.SHA256): Hash;
1051
+ public static unserialize(buf: SerialBuffer, algorithm?: Hash.Algorithm): Hash;
1052
+ public static fromAny(hash: Hash | Uint8Array | string, algorithm?: Hash.Algorithm): Hash;
1053
+ public static fromBase64(base64: string): Hash;
1054
+ public static fromHex(hex: string): Hash;
1055
+ public static fromPlain(str: string): Hash;
1056
+ public static fromString(str: string): Hash;
1057
+ public static isHash(o: any): boolean;
1058
+ public static getSize(algorithm: Hash.Algorithm): number;
1059
+ public static computeBlake2b(input: Uint8Array): Uint8Array;
1060
+ public static computeSha256(input: Uint8Array): Uint8Array;
1061
+ public static computeSha512(input: Uint8Array): Uint8Array;
1062
+ public static computeRipemd160(input: Uint8Array): Uint8Array;
1063
+ public static computeKeccak256(input: Uint8Array): Uint8Array;
1064
+ public serializedSize: number;
1065
+ public array: Uint8Array;
1066
+ public algorithm: Hash.Algorithm;
1067
+ constructor(arg?: Uint8Array, algorithm?: Hash.Algorithm);
1068
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1069
+ public subarray(begin?: number, end?: number): Uint8Array;
1070
+ public toPlain(): string;
1071
+ public equals(o: Serializable): boolean;
1072
+ }
1073
+
1074
+ export namespace Hash {
1075
+ type Algorithm = Algorithm.BLAKE2B | Algorithm.ARGON2D | Algorithm.SHA256 | Algorithm.SHA512 | Algorithm.RIPEMD160 | Algorithm.KECCAK256;
1076
+ namespace Algorithm {
1077
+ type BLAKE2B = 1;
1078
+ type ARGON2D = 2;
1079
+ type SHA256 = 3;
1080
+ type SHA512 = 4;
1081
+ type RIPEMD160 = 5;
1082
+ type KECCAK256 = 6;
1083
+ }
1084
+ }
1085
+
1086
+ export class PrivateKey extends Secret {
1087
+ public static SIZE: 32;
1088
+ public static PURPOSE_ID: number;
1089
+ public static generate(): PrivateKey;
1090
+ public static unserialize(buf: SerialBuffer): PrivateKey;
1091
+ public serializedSize: number;
1092
+ constructor(arg: Uint8Array);
1093
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1094
+ public overwrite(privateKey: PrivateKey): void;
1095
+ public equals(o: any): boolean;
1096
+ }
1097
+
1098
+ export class PublicKey extends Serializable {
1099
+ public static SIZE: 65;
1100
+ public static COMPRESSED_SIZE: 33;
1101
+ public static copy(o: PublicKey): PublicKey;
1102
+ public static derive(privateKey: PrivateKey): PublicKey;
1103
+ public static sum(publicKeys: PublicKey[]): PublicKey;
1104
+ public static unserialize(buf: SerialBuffer): PublicKey;
1105
+ public static fromAny(o: PublicKey | Uint8Array | string): PublicKey;
1106
+ public serializedSize: number;
1107
+ constructor(arg: Uint8Array);
1108
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1109
+ public equals(o: any): boolean;
1110
+ public hash(): Hash;
1111
+ public compare(o: PublicKey): number;
1112
+ public toAddress(): Address;
1113
+ public toPeerId(): PeerId;
1114
+ }
1115
+
1116
+ export class KeyPair extends Serializable {
1117
+ public static LOCK_KDF_ROUNDS: 256;
1118
+ public static generate(): KeyPair;
1119
+ public static derive(privateKey: PrivateKey): KeyPair;
1120
+ public static fromHex(hexBuf: string): KeyPair;
1121
+ public static fromEncrypted(buf: SerialBuffer, key: Uint8Array): Promise<KeyPair>;
1122
+ public static unserialize(buf: SerialBuffer): KeyPair;
1123
+ public privateKey: PrivateKey;
1124
+ public publicKey: PublicKey;
1125
+ public serializedSize: number;
1126
+ public encryptedSize: number;
1127
+ public isLocked: boolean;
1128
+ constructor(
1129
+ privateKey: PrivateKey,
1130
+ publicKey: PublicKey,
1131
+ locked?: boolean,
1132
+ lockSalt?: Uint8Array,
1133
+ );
1134
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1135
+ public exportEncrypted(key: Uint8Array): Promise<SerialBuffer>;
1136
+ public lock(key: string | Uint8Array): Promise<void>;
1137
+ public unlock(key: string | Uint8Array): Promise<void>;
1138
+ public relock(): void;
1139
+ public equals(o: any): boolean;
1140
+ }
1141
+
1142
+ export class Secret extends Serializable {
1143
+ public static SIZE: 32;
1144
+ public static ENCRYPTION_SALT_SIZE: 16;
1145
+ public static ENCRYPTION_KDF_ROUNDS: 256;
1146
+ public static ENCRYPTION_CHECKSUM_SIZE: 4;
1147
+ public static ENCRYPTION_CHECKSUM_SIZE_V3: 2;
1148
+ public static Type: {
1149
+ PRIVATE_KEY: 1,
1150
+ ENTROPY: 2,
1151
+ };
1152
+ public static fromEncrypted(buf: SerialBuffer, key: Uint8Array): Promise<PrivateKey|Entropy>;
1153
+ public encryptedSize: number;
1154
+ public type: Secret.Type;
1155
+ constructor(type: Secret.Type, purposeId: number);
1156
+ public exportEncrypted(key: Uint8Array): Promise<SerialBuffer>;
1157
+ }
1158
+
1159
+ export namespace Secret {
1160
+ type Type = Type.PRIVATE_KEY|Type.ENTROPY;
1161
+ namespace Type {
1162
+ type PRIVATE_KEY = 1;
1163
+ type ENTROPY = 2;
1164
+ }
1165
+ }
1166
+
1167
+ export class Entropy extends Secret {
1168
+ public static SIZE: 32;
1169
+ public static PURPOSE_ID: number;
1170
+ public static generate(): Entropy;
1171
+ public static unserialize(buf: SerialBuffer): Entropy;
1172
+ public serializedSize: number;
1173
+ constructor(arg: Uint8Array);
1174
+ public toExtendedPrivateKey(password?: string, wordlist?: string[]): ExtendedPrivateKey;
1175
+ public toMnemonic(wordlist?: string[]): string[];
1176
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1177
+ public overwrite(entropy: Entropy): void;
1178
+ public equals(o: any): boolean;
1179
+ }
1180
+
1181
+ export class ExtendedPrivateKey extends Serializable {
1182
+ public static CHAIN_CODE_SIZE: 32;
1183
+ public static generateMasterKey(seed: Uint8Array): ExtendedPrivateKey;
1184
+ public static isValidPath(path: string): boolean;
1185
+ public static derivePathFromSeed(path: string, seed: Uint8Array): ExtendedPrivateKey;
1186
+ public static unserialize(buf: SerialBuffer): ExtendedPrivateKey;
1187
+ public serializedSize: number;
1188
+ public privateKey: PrivateKey;
1189
+ constructor(key: PrivateKey, chainCode: Uint8Array);
1190
+ public derive(index: number): ExtendedPrivateKey;
1191
+ public derivePath(path: string): ExtendedPrivateKey;
1192
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1193
+ public equals(o: any): boolean;
1194
+ public toAddress(): Address;
1195
+ }
1196
+
1197
+ export class RandomSecret extends Serializable {
1198
+ public static SIZE: 32;
1199
+ public static unserialize(buf: SerialBuffer): RandomSecret;
1200
+ public serializedSize: number;
1201
+ constructor(arg: Uint8Array);
1202
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1203
+ public equals(o: any): boolean;
1204
+ }
1205
+
1206
+ export class Signature extends Serializable {
1207
+ public static SIZE: 64;
1208
+ public static copy(o: Signature): Signature;
1209
+ public static create(privateKey: PrivateKey, publicKey: PublicKey, data: Uint8Array): Signature;
1210
+ public static fromPartialSignatures(commitment: Commitment, signatures: PartialSignature[]): Signature;
1211
+ public static unserialize(buf: SerialBuffer): Signature;
1212
+ public static fromAny(o: Signature | Uint8Array | string): Signature;
1213
+ public serializedSize: number;
1214
+ constructor(args: Uint8Array);
1215
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1216
+ public verify(publicKey: PublicKey, data: Uint8Array): boolean;
1217
+ public equals(o: any): boolean;
1218
+ }
1219
+
1220
+ export class Commitment extends Serializable {
1221
+ public static SIZE: 65;
1222
+ public static COMPRESSED_SIZE: 33;
1223
+ public static copy(o: Commitment): Commitment;
1224
+ public static sum(commitments: Commitment[]): Commitment;
1225
+ public static unserialize(buf: SerialBuffer): Commitment;
1226
+ public serializedSize: number;
1227
+ constructor(arg: Uint8Array);
1228
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1229
+ public equals(o: any): boolean;
1230
+ }
1231
+
1232
+ export class CommitmentPair extends Serializable {
1233
+ public static SERIALIZED_SIZE: 96;
1234
+ public static RANDOMNESS_SIZE: 32;
1235
+ public static generate(): CommitmentPair;
1236
+ public static unserialize(buf: SerialBuffer): CommitmentPair;
1237
+ public static fromHex(hexBuf: string): CommitmentPair;
1238
+ public secret: RandomSecret;
1239
+ public commitment: Commitment;
1240
+ public serializedSize: number;
1241
+ constructor(secret: RandomSecret, commitment: Commitment);
1242
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1243
+ public equals(o: any): boolean;
1244
+ }
1245
+
1246
+ export class PartialSignature extends Serializable {
1247
+ public static SIZE: 64;
1248
+ public static HALF_SIZE: 32;
1249
+ public static create(privateKey: PrivateKey, publicKey: PublicKey, publicKeys: PublicKey[], secret: RandomSecret, aggregateCommitment: Commitment, data: Uint8Array): PartialSignature;
1250
+ public static unserialize(buf: SerialBuffer): PartialSignature;
1251
+ public serializedSize: number;
1252
+ constructor(arg: Uint8Array);
1253
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1254
+ public equals(o: any): boolean;
1255
+ }
1256
+
1257
+ export class MnemonicUtils {
1258
+ public static ENGLISH_WORDLIST: string[];
1259
+ public static DEFAULT_WORDLIST: string[];
1260
+ public static MnemonicType: {
1261
+ UNKNOWN: -1;
1262
+ LEGACY: 0;
1263
+ BIP39: 1;
1264
+ };
1265
+ public static entropyToMnemonic(entropy: string | ArrayBuffer | Uint8Array | Entropy, wordlist?: string[]): string[];
1266
+ public static entropyToLegacyMnemonic(entropy: string | ArrayBuffer | Uint8Array | Entropy, wordlist?: string[]): string[];
1267
+ public static mnemonicToEntropy(mnemonic: string | string[], wordlist?: string[]): Entropy;
1268
+ public static legacyMnemonicToEntropy(mnemonic: string | string[], wordlist?: string[]): Entropy;
1269
+ public static mnemonicToSeed(mnemonic: string | string[], password?: string): SerialBuffer;
1270
+ public static mnemonicToExtendedPrivateKey(mnemonic: string | string[], password?: string): ExtendedPrivateKey;
1271
+ public static isCollidingChecksum(entropy: Entropy): boolean;
1272
+ public static getMnemonicType(mnemonic: string | string[], wordlist?: string[]): MnemonicUtils.MnemonicType;
1273
+ }
1274
+
1275
+ export namespace MnemonicUtils {
1276
+ type MnemonicType = MnemonicType.LEGACY | MnemonicType.BIP39 | MnemonicType.UNKNOWN;
1277
+ namespace MnemonicType {
1278
+ type UNKNOWN = -1;
1279
+ type LEGACY = 0;
1280
+ type BIP39 = 1;
1281
+ }
1282
+ }
1283
+
1284
+ export class Address extends Serializable {
1285
+ public static SERIALIZED_SIZE: 20;
1286
+ public static HEX_SIZE: 40;
1287
+ public static NULL: Address;
1288
+ public static CONTRACT_CREATION: Address;
1289
+ public static copy(o: Address): Address;
1290
+ public static fromHash(hash: Hash): Address;
1291
+ public static unserialize(buf: SerialBuffer): Address;
1292
+ public static fromString(str: string): Address;
1293
+ public static fromBase64(base64: string): Address;
1294
+ public static fromHex(hex: string): Address;
1295
+ public static fromUserFriendlyAddress(str: string): Address;
1296
+ public static fromAny(addr: Address | string): Address;
1297
+ public serializedSize: number;
1298
+ constructor(arg: Uint8Array);
1299
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1300
+ public subarray(begin?: number, end?: number): Uint8Array;
1301
+ public equals(o: Address): boolean;
1302
+ public toPlain(): string;
1303
+ public toUserFriendlyAddress(withSpaces?: boolean): string;
1304
+ }
1305
+
1306
+ export abstract class Account {
1307
+ public static Type: {
1308
+ BASIC: 0;
1309
+ VESTING: 1;
1310
+ HTLC: 2;
1311
+ toString(type: Account.Type): string;
1312
+ fromAny(type: Account.Type | string): Account.Type;
1313
+ };
1314
+ public static TYPE_MAP: Map<Account.Type, typeof Account>;
1315
+ public static BalanceError: Error;
1316
+ public static DoubleTransactionError: Error;
1317
+ public static ProofError: Error;
1318
+ public static ValidityError: Error;
1319
+ public static unserialize(buf: SerialBuffer): Account;
1320
+ public static dataToPlain(data: Uint8Array): {};
1321
+ public static proofToPlain(proof: Uint8Array): {};
1322
+ public static fromAny(o: Account | {type: Account.Type | string, balance: string}): Account;
1323
+ public static fromPlain(plain: {type: Account.Type | string, balance: string}): Account;
1324
+ public serializedSize: number;
1325
+ public balance: BigNumber;
1326
+ public type: Account.Type;
1327
+ constructor(type: Account.Type, balance: BigNumber | number | string);
1328
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1329
+ public equals(o: any): boolean;
1330
+ public toString(): string;
1331
+ public toPlain(): {
1332
+ type: string,
1333
+ balance: string,
1334
+ };
1335
+ public withBalance(balance: BigNumber | number | string): Account;
1336
+ public withOutgoingTransaction(transaction: Transaction, blockHeight: number, transactionCache: TransactionCache, revert?: boolean): Account;
1337
+ public withIncomingTransaction(transaction: Transaction, blockHeight: number, revert?: boolean): Account;
1338
+ public withContractCommand(transaction: Transaction, blockHeight: number, revert?: boolean): Account;
1339
+ public isInitial(): boolean;
1340
+ public isToBePruned(): boolean;
1341
+ }
1342
+
1343
+ export namespace Account {
1344
+ type Type = Type.BASIC | Type.VESTING | Type.HTLC;
1345
+ namespace Type {
1346
+ type BASIC = 0;
1347
+ type VESTING = 1;
1348
+ type HTLC = 2;
1349
+ }
1350
+ }
1351
+
1352
+ export class PrunedAccount {
1353
+ public static unserialize(buf: SerialBuffer): PrunedAccount;
1354
+ public static fromAny(o: PrunedAccount | object): PrunedAccount;
1355
+ public static fromPlain(plain: object): PrunedAccount;
1356
+ public address: Address;
1357
+ public account: Account;
1358
+ public serializedSize: number;
1359
+ constructor(address: Address, account: Account);
1360
+ public compare(o: PrunedAccount): number;
1361
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1362
+ public hashCode(): string;
1363
+ public toPlain(): {
1364
+ address: string,
1365
+ account: object,
1366
+ };
1367
+ }
1368
+
1369
+ export class BasicAccount extends Account {
1370
+ public static INITIAL: BasicAccount;
1371
+ public static copy(o: BasicAccount): BasicAccount;
1372
+ public static unserialize(buf: SerialBuffer): BasicAccount;
1373
+ public static fromPlain(o: {balance: BigNumber | number | string}): BasicAccount;
1374
+ public static verifyOutgoingTransaction(transaction: Transaction): boolean;
1375
+ public static verifyIncomingTransaction(transaction: Transaction): boolean;
1376
+ public static proofToPlain(proof: Uint8Array): {
1377
+ signature: string,
1378
+ publicKey: string,
1379
+ signer: string,
1380
+ pathLength: number,
1381
+ } | {};
1382
+ public static dataToPlain(data: Uint8Array): {};
1383
+ constructor(balance?: BigNumber | number | string);
1384
+ public equals(o: any): boolean;
1385
+ public toString(): string;
1386
+ public withBalance(balance: BigNumber | number | string): Account;
1387
+ public withIncomingTransaction(transaction: Transaction, blockHeight: number, revert?: boolean): Account;
1388
+ public withContractCommand(transaction: Transaction, blockHeight: number, revert?: boolean): Account;
1389
+ public isInitial(): boolean;
1390
+ }
1391
+
1392
+ export class Contract extends Account {
1393
+ public static verifyIncomingTransaction(transaction: Transaction): boolean;
1394
+ constructor(type: Account.Type, balance: BigNumber | number | string);
1395
+ public withIncomingTransaction(transaction: Transaction, blockHeight: number, revert?: boolean): Account;
1396
+ public withContractCommand(transaction: Transaction, blockHeight: number, revert?: boolean): BasicAccount | Contract;
1397
+ }
1398
+
1399
+ export class HashedTimeLockedContract extends Contract {
1400
+ public static ProofType: {
1401
+ REGULAR_TRANSFER: 1;
1402
+ EARLY_RESOLVE: 2;
1403
+ TIMEOUT_RESOLVE: 3;
1404
+ toString(proofType: HashedTimeLockedContract.ProofType): string;
1405
+ };
1406
+ public static create(balance: BigNumber | number | string, blockHeight: number, transaction: Transaction): HashedTimeLockedContract;
1407
+ public static unserialize(buf: SerialBuffer): HashedTimeLockedContract;
1408
+ public static fromPlain(plain: object): HashedTimeLockedContract;
1409
+ public static verifyOutgoingTransaction(transaction: Transaction): boolean;
1410
+ public static verifyIncomingTransaction(transaction: Transaction): boolean;
1411
+ public static dataToPlain(data: Uint8Array): {
1412
+ sender: string,
1413
+ recipient: string,
1414
+ hashAlgorithm: string,
1415
+ hashRoot: string,
1416
+ hashCount: number,
1417
+ timeout: number,
1418
+ } | {};
1419
+ public static proofToPlain(proof: Uint8Array): {
1420
+ type: 'regular-transfer',
1421
+ hashAlgorithm: string,
1422
+ hashDepth: number,
1423
+ hashRoot: string,
1424
+ preImage: string,
1425
+ signer: string,
1426
+ signature: string,
1427
+ publicKey: string,
1428
+ pathLength: number,
1429
+ } | {
1430
+ type: 'early-resolve',
1431
+ signer: string,
1432
+ signature: string,
1433
+ publicKey: string,
1434
+ pathLength: number,
1435
+ creator: string,
1436
+ creatorSignature: string,
1437
+ creatorPublicKey: string,
1438
+ creatorPathLength: number,
1439
+ } | {
1440
+ type: 'timeout-resolve',
1441
+ creator: string,
1442
+ creatorSignature: string,
1443
+ creatorPublicKey: string,
1444
+ creatorPathLength: number,
1445
+ } | {};
1446
+ public serializedSize: number;
1447
+ public sender: Address;
1448
+ public recipient: Address;
1449
+ public hashRoot: Hash;
1450
+ public hashCount: number;
1451
+ public timeout: number;
1452
+ public totalAmount: BigNumber;
1453
+ constructor(
1454
+ balance?: BigNumber | number | string,
1455
+ sender?: Address,
1456
+ recipient?: Address,
1457
+ hashRoot?: Hash,
1458
+ hashCount?: number,
1459
+ timeout?: number,
1460
+ totalAmount?: BigNumber | number | string,
1461
+ );
1462
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1463
+ public toString(): string;
1464
+ public toPlain(): {
1465
+ type: string,
1466
+ balance: string,
1467
+ sender: string,
1468
+ recipient: string,
1469
+ hashAlgorithm: string,
1470
+ hashRoot: string,
1471
+ hashCount: number,
1472
+ timeout: number,
1473
+ totalAmount: string,
1474
+ };
1475
+ public equals(o: any): boolean;
1476
+ public withBalance(balance: BigNumber | number | string): Account;
1477
+ public withOutgoingTransaction(transaction: Transaction, blockHeight: number, transactionCache: TransactionCache, revert?: boolean): Account;
1478
+ public withIncomingTransaction(transaction: Transaction, blockHeight: number, revert?: boolean): Account;
1479
+ }
1480
+
1481
+ export namespace HashedTimeLockedContract {
1482
+ type ProofType = ProofType.REGULAR_TRANSFER | ProofType.EARLY_RESOLVE | ProofType.TIMEOUT_RESOLVE;
1483
+ namespace ProofType {
1484
+ type REGULAR_TRANSFER = 1;
1485
+ type EARLY_RESOLVE = 2;
1486
+ type TIMEOUT_RESOLVE = 3;
1487
+ }
1488
+ }
1489
+
1490
+ export class VestingContract extends Contract {
1491
+ public static create(balance: BigNumber | number | string, blockHeight: number, transaction: Transaction): VestingContract;
1492
+ public static unserialize(buf: SerialBuffer): VestingContract;
1493
+ public static fromPlain(plain: object): VestingContract;
1494
+ public static verifyOutgoingTransaction(transaction: Transaction): boolean;
1495
+ public static verifyIncomingTransaction(transaction: Transaction): boolean;
1496
+ public static dataToPlain(data: Uint8Array): {
1497
+ owner: string,
1498
+ vestingStart: number,
1499
+ vestingStepBlocks: number,
1500
+ vestingStepAmount: string,
1501
+ vestingTotalAmount: string,
1502
+ } | {};
1503
+ public static proofToPlain(proof: Uint8Array): {
1504
+ signature: string,
1505
+ publicKey: string,
1506
+ signer: string,
1507
+ pathLength: number,
1508
+ };
1509
+ public serializedSize: number;
1510
+ public owner: Address;
1511
+ public vestingStart: number;
1512
+ public vestingStepBlocks: number;
1513
+ public vestingStepAmount: BigNumber;
1514
+ public vestingTotalAmount: BigNumber;
1515
+ constructor(
1516
+ balance?: BigNumber | number | string,
1517
+ owner?: Address,
1518
+ vestingStart?: number,
1519
+ vestingStepBlocks?: number,
1520
+ vestingStepAmount?: BigNumber | number | string,
1521
+ vestingTotalAmount?: BigNumber | number | string,
1522
+ );
1523
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1524
+ public toString(): string;
1525
+ public toPlain(): {
1526
+ type: string,
1527
+ balance: string,
1528
+ owner: string,
1529
+ vestingStart: number,
1530
+ vestingStepBlocks: number,
1531
+ vestingStepAmount: string,
1532
+ vestingTotalAmount: string,
1533
+ };
1534
+ public equals(o: any): boolean;
1535
+ public withBalance(balance: BigNumber | number | string): Account;
1536
+ public withOutgoingTransaction(transaction: Transaction, blockHeight: number, transactionCache: TransactionCache, revert?: boolean): Account;
1537
+ public withIncomingTransaction(transaction: Transaction, blockHeight: number, revert?: boolean): Account;
1538
+ public getMinCap(blockHeight: number): number;
1539
+ }
1540
+
1541
+ export class AccountsTreeNode {
1542
+ public static BRANCH: 0x00;
1543
+ public static TERMINAL: 0xff;
1544
+ public static terminalNode(prefix: string, account: Account): AccountsTreeNode;
1545
+ public static branchNode(prefix: string, childrenSuffixes?: string[], childrenHashes?: Hash[]): AccountsTreeNode;
1546
+ public static isTerminalType(type: number): boolean;
1547
+ public static isBranchType(type: number): boolean;
1548
+ public static unserialize(buf: SerialBuffer): AccountsTreeNode;
1549
+ public serializedSize: number;
1550
+ public account: Account;
1551
+ public prefix: string;
1552
+ constructor(
1553
+ type: number,
1554
+ prefix: string,
1555
+ arg: Account | string[],
1556
+ arg2?: Hash[],
1557
+ );
1558
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1559
+ public getChildHash(prefix: string): false | Hash;
1560
+ public getChild(prefix: string): false | string;
1561
+ public withChild(prefix: string, childHash: Hash): AccountsTreeNode;
1562
+ public withoutChild(prefix: string): AccountsTreeNode;
1563
+ public hasChildren(): boolean;
1564
+ public hasSingleChild(): boolean;
1565
+ public getFirstChild(): undefined | string;
1566
+ public getLastChild(): undefined | string;
1567
+ public getChildren(): undefined | string[];
1568
+ public withAccount(account: Account): AccountsTreeNode;
1569
+ public hash(): Hash;
1570
+ public isChildOf(parent: AccountsTreeNode): boolean;
1571
+ public isTerminal(): boolean;
1572
+ public isBranch(): boolean;
1573
+ public equals(o: any): boolean;
1574
+ }
1575
+
1576
+ export class AccountsTreeStore {
1577
+ public static initPersistent(jdb: any): void;
1578
+ public static getPersistent(jdb: any): AccountsTreeStore;
1579
+ public static createVolatile(): AccountsTreeStore;
1580
+ public tx: any;
1581
+ constructor(store: any);
1582
+ public get(key: string): Promise<AccountsTreeNode>;
1583
+ public put(node: AccountsTreeNode): Promise<string>;
1584
+ public remove(node: AccountsTreeNode): Promise<string>;
1585
+ public getRootNode(): Promise<AccountsTreeNode>;
1586
+ public getTerminalNodes(startPrefix: string, size: number): Promise<AccountsTreeNode[]>;
1587
+ public snapshot(tx?: AccountsTreeStore): AccountsTreeStore;
1588
+ public transaction(enableWatchdog?: boolean): AccountsTreeStore;
1589
+ public synchronousTransaction(enableWatchdog?: boolean): SynchronousAccountsTreeStore;
1590
+ public truncate(): Promise<void>;
1591
+ public commit(): Promise<boolean>;
1592
+ public abort(): Promise<void>;
1593
+ }
1594
+
1595
+ export class AccountsTreeStoreCodec {
1596
+ public valueEncoding: { encode: (val: any) => any, decode: (val: any) => any, buffer: boolean, type: string } | void;
1597
+ public encode(obj: any): any;
1598
+ public decode(obj: any, key: string): any;
1599
+ }
1600
+
1601
+ export class SynchronousAccountsTreeStore extends AccountsTreeStore {
1602
+ constructor(store: any);
1603
+ public preload(keys: string[]): void;
1604
+ public getSync(key: string, expectedToBePresent?: boolean): AccountsTreeNode;
1605
+ public putSync(node: AccountsTreeNode): string;
1606
+ public removeSync(node: AccountsTreeNode): string;
1607
+ public getRootNodeSync(): AccountsTreeNode;
1608
+ }
1609
+
1610
+ export class AccountsProof {
1611
+ public static unserialize(buf: SerialBuffer): AccountsProof;
1612
+ public serializedSize: number;
1613
+ public length: number;
1614
+ public nodes: AccountsTreeNode[];
1615
+ constructor(nodes: AccountsTreeNode[]);
1616
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1617
+ public verify(): boolean;
1618
+ public getAccount(address: Address): Account;
1619
+ public toString(): string;
1620
+ public root(): Hash;
1621
+ }
1622
+
1623
+ export class AccountsTreeChunk {
1624
+ public static SIZE_MAX: number;
1625
+ public static EMPTY: AccountsTreeChunk;
1626
+ public static unserialize(buf: SerialBuffer): AccountsTreeChunk;
1627
+ public serializedSize: number;
1628
+ public terminalNodes: AccountsTreeNode[];
1629
+ public proof: AccountsProof;
1630
+ public head: AccountsTreeNode;
1631
+ public tail: AccountsTreeNode;
1632
+ public length: number;
1633
+ constructor(nodes: AccountsTreeNode[], proof: AccountsProof);
1634
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1635
+ public verify(): boolean;
1636
+ public toString(): string;
1637
+ public root(): Hash;
1638
+ }
1639
+
1640
+ export class AccountsTree extends Observable {
1641
+ public static getPersistent(jdb: any): Promise<AccountsTree>;
1642
+ public static createVolatile(): Promise<AccountsTree>;
1643
+ public tx: any;
1644
+ constructor(store: AccountsTreeStore);
1645
+ public put(address: Address, account: Account): Promise<void>;
1646
+ public get(address: Address): Promise<null | Account>;
1647
+ public getAccountsProof(addresses: Address[]): Promise<AccountsProof>;
1648
+ public getChunk(startPrefix: string, size: number): Promise<AccountsTreeChunk>;
1649
+ public transaction(enableWatchdog?: boolean): Promise<AccountsTree>;
1650
+ public synchronousTransaction(enableWatchdog?: boolean): Promise<SynchronousAccountsTree>;
1651
+ public partialTree(): Promise<PartialAccountsTree>;
1652
+ public snapshot(tx?: AccountsTree): Promise<AccountsTree>;
1653
+ public commit(): Promise<boolean>;
1654
+ public abort(): Promise<void>;
1655
+ public root(): Promise<Hash>;
1656
+ public isEmpty(): Promise<boolean>;
1657
+ }
1658
+
1659
+ export class SynchronousAccountsTree extends AccountsTree {
1660
+ constructor(store: SynchronousAccountsTreeStore);
1661
+ public preloadAddresses(addresses: Address[]): Promise<void>;
1662
+ public putSync(address: Address, account: Account): void;
1663
+ public getSync(address: Address, expectedToBePresent?: boolean): null | Account;
1664
+ public rootSync(): Hash;
1665
+ }
1666
+
1667
+ // @ts-ignore
1668
+ export class PartialAccountsTree extends SynchronousAccountsTree {
1669
+ public static Status: {
1670
+ ERR_HASH_MISMATCH: -3;
1671
+ ERR_INCORRECT_PROOF: -2;
1672
+ ERR_UNMERGEABLE: -1;
1673
+ OK_COMPLETE: 0;
1674
+ OK_UNFINISHED: 1;
1675
+ };
1676
+ public complete: boolean;
1677
+ public missingPrefix: string;
1678
+ constructor(store: SynchronousAccountsTreeStore);
1679
+ public pushChunk(chunk: AccountsTreeChunk): Promise<PartialAccountsTree.Status>;
1680
+ // @ts-ignore
1681
+ public synchronousTransaction(enableWatchdog?: boolean): PartialAccountsTree;
1682
+ // @ts-ignore
1683
+ public transaction(enableWatchdog?: boolean): AccountsTree;
1684
+ public commit(): Promise<boolean>;
1685
+ public abort(): Promise<void>;
1686
+ }
1687
+
1688
+ export namespace PartialAccountsTree {
1689
+ type Status = Status.ERR_HASH_MISMATCH | Status.ERR_INCORRECT_PROOF | Status.ERR_UNMERGEABLE | Status.OK_COMPLETE | Status.OK_UNFINISHED;
1690
+ namespace Status {
1691
+ type ERR_HASH_MISMATCH = -3;
1692
+ type ERR_INCORRECT_PROOF = -2;
1693
+ type ERR_UNMERGEABLE = -1;
1694
+ type OK_COMPLETE = 0;
1695
+ type OK_UNFINISHED = 1;
1696
+ }
1697
+ }
1698
+
1699
+ export class Accounts extends Observable {
1700
+ public static getPersistent(jdb: any): Promise<Accounts>;
1701
+ public static createVolatile(): Promise<Accounts>;
1702
+ public tx: any;
1703
+ constructor(accountsTree: AccountsTree);
1704
+ public initialize(genesisBlock: Block, encodedAccounts: string): Promise<void>;
1705
+ public getAccountsProof(addresses: Address[]): Promise<AccountsProof>;
1706
+ public getAccountsTreeChunk(startPrefix: string): Promise<AccountsTreeChunk>;
1707
+ public commitBlock(block: Block, transactionCache: TransactionCache): Promise<void>;
1708
+ public commitBlockBody(body: BlockBody, blockHeight: number, transactionCache: TransactionCache): Promise<void>;
1709
+ public gatherToBePrunedAccounts(transactions: Transaction[], blockHeight: number, transactionCache: TransactionCache): Promise<PrunedAccount[]>;
1710
+ public revertBlock(block: Block, transactionCache: TransactionCache): Promise<void>;
1711
+ public revertBlockBody(body: BlockBody, blockHeight: number, transactionCache: TransactionCache): Promise<void>;
1712
+ public get(address: Address, accountType?: Account.Type, tree?: AccountsTree): Promise<Account>;
1713
+ public transaction(enableWatchdog?: boolean): Promise<Accounts>;
1714
+ public snapshot(tx: Accounts): Promise<Accounts>;
1715
+ public partialAccountsTree(): Promise<PartialAccountsTree>;
1716
+ public commit(): Promise<void>;
1717
+ public abort(): Promise<void>;
1718
+ public hash(): Promise<Hash>;
1719
+ }
1720
+
1721
+ export class BlockHeader {
1722
+ public static CURRENT_VERSION: number;
1723
+ public static SUPPORTED_VERSIONS: number[];
1724
+ public static SERIALIZED_SIZE: 146;
1725
+ public static Version: {
1726
+ V1: 1;
1727
+ };
1728
+ public static unserialize(buf: SerialBuffer): BlockHeader;
1729
+ public serializedSize: number;
1730
+ public version: number;
1731
+ public prevHash: Hash;
1732
+ public interlinkHash: Hash;
1733
+ public bodyHash: Hash;
1734
+ public accountsHash: Hash;
1735
+ public nBits: number;
1736
+ public target: BigNumber;
1737
+ public difficulty: BigNumber;
1738
+ public height: number;
1739
+ public timestamp: number;
1740
+ public nonce: number;
1741
+ constructor(
1742
+ prevHash: Hash,
1743
+ interlinkHash: Hash,
1744
+ bodyHash: Hash,
1745
+ accountsHash: Hash,
1746
+ nBits: number,
1747
+ height: number,
1748
+ timestamp: number,
1749
+ nonce: number,
1750
+ version?: number,
1751
+ );
1752
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1753
+ public verifyProofOfWork(buf?: SerialBuffer): Promise<boolean>;
1754
+ public isImmediateSuccessorOf(prevHeader: BlockHeader): boolean;
1755
+ public hash(buf?: SerialBuffer): Hash;
1756
+ public pow(buf?: SerialBuffer): Promise<Hash>;
1757
+ public equals(o: any): boolean;
1758
+ public toString(): string;
1759
+ }
1760
+
1761
+ export namespace BlockHeader {
1762
+ type Version = Version.V1;
1763
+ namespace Version {
1764
+ type V1 = 1;
1765
+ }
1766
+ }
1767
+
1768
+ export class BlockInterlink {
1769
+ public static unserialize(buf: SerialBuffer): BlockInterlink;
1770
+ public serializedSize: number;
1771
+ public hashes: Hash[];
1772
+ public length: number;
1773
+ constructor(
1774
+ hashes: Hash[],
1775
+ prevHash?: Hash,
1776
+ repeatBits?: Uint8Array,
1777
+ compressed?: Hash[],
1778
+ );
1779
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1780
+ public equals(o: any): boolean;
1781
+ public hash(): Hash;
1782
+ }
1783
+
1784
+ export class BlockBody {
1785
+ public static getMetadataSize(extraData: Uint8Array): number;
1786
+ public static unserialize(buf: SerialBuffer): BlockBody;
1787
+ public serializedSize: number;
1788
+ public extraData: Uint8Array;
1789
+ public minerAddr: Address;
1790
+ public transactions: Transaction[];
1791
+ public transactionCount: number;
1792
+ public prunedAccounts: PrunedAccount[];
1793
+ constructor(
1794
+ minerAddr: Address,
1795
+ transactions: Transaction[],
1796
+ extraData?: Uint8Array,
1797
+ prunedAccounts?: PrunedAccount[],
1798
+ );
1799
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1800
+ public verify(): boolean;
1801
+ public getMerkleLeafs(): any[];
1802
+ public hash(): Hash;
1803
+ public equals(o: any): boolean;
1804
+ public getAddresses(): Address[];
1805
+ }
1806
+
1807
+ export class BlockUtils {
1808
+ public static compactToTarget(compact: number): BigNumber;
1809
+ public static targetToCompact(target: BigNumber): number;
1810
+ public static getTargetHeight(target: BigNumber): number;
1811
+ public static getTargetDepth(target: BigNumber): number;
1812
+ public static compactToDifficulty(compact: number): BigNumber;
1813
+ public static difficultyToCompact(difficulty: BigNumber): number;
1814
+ public static difficultyToTarget(difficulty: BigNumber): BigNumber;
1815
+ public static targetToDifficulty(target: BigNumber): BigNumber;
1816
+ public static hashToTarget(hash: Hash): BigNumber;
1817
+ public static realDifficulty(hash: Hash): BigNumber;
1818
+ public static getHashDepth(hash: Hash): number;
1819
+ public static isProofOfWork(hash: Hash, target: BigNumber): boolean;
1820
+ public static isValidCompact(compact: number): boolean;
1821
+ public static isValidTarget(target: BigNumber): boolean;
1822
+ public static getNextTarget(headBlock: BlockHeader, tailBlock: BlockHeader, deltaTotalDifficulty: BigNumber): BigNumber;
1823
+ }
1824
+
1825
+ export class Subscription {
1826
+ public static NONE: Subscription;
1827
+ public static BLOCKS_ONLY: Subscription;
1828
+ public static ANY: Subscription;
1829
+ public static Type: {
1830
+ NONE: 0;
1831
+ ANY: 1;
1832
+ ADDRESSES: 2;
1833
+ };
1834
+ public static fromAddresses(addresses: Address[]): Subscription;
1835
+ public static unserialize(buf: SerialBuffer): Subscription;
1836
+ public serializedSize: number;
1837
+ public type: Subscription.Type;
1838
+ public addresses: Address[];
1839
+ constructor(type: Subscription.Type, filter?: Address[] | number);
1840
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1841
+ public matchesBlock(block: Block): boolean;
1842
+ public matchesTransaction(transaction: Transaction): boolean;
1843
+ public isSubsetOf(other: Subscription): boolean;
1844
+ public toString(): string;
1845
+ }
1846
+
1847
+ export namespace Subscription {
1848
+ type Type = Type.NONE | Type.ANY | Type.ADDRESSES;
1849
+ namespace Type {
1850
+ type NONE = 0;
1851
+ type ANY = 1;
1852
+ type ADDRESSES = 2;
1853
+ }
1854
+ }
1855
+
1856
+ export abstract class Transaction {
1857
+ public static Format: {
1858
+ BASIC: 0;
1859
+ EXTENDED: 1;
1860
+ toString(format: Transaction.Format): string;
1861
+ fromAny(format: Transaction.Format | string): Transaction.Format;
1862
+ };
1863
+ public static Flag: {
1864
+ NONE: 0;
1865
+ CONTRACT_CREATION: 0b1;
1866
+ };
1867
+ public static FORMAT_MAP: Map<Transaction.Format, {unserialize: (buf: SerialBuffer) => Transaction, fromPlain: (plain: object) => Transaction}>;
1868
+ public static unserialize(buf: SerialBuffer): Transaction;
1869
+ public static fromPlain(plain: object): Transaction;
1870
+ public static fromAny(tx: Transaction | string | object): Transaction;
1871
+ public serializedContentSize: number;
1872
+ public serializedSize: number;
1873
+ public format: Transaction.Format;
1874
+ public sender: Address;
1875
+ public senderType: Account.Type;
1876
+ public recipient: Address;
1877
+ public recipientType: Account.Type;
1878
+ public value: BigNumber;
1879
+ public fee: BigNumber;
1880
+ public feePerByte: BigNumber;
1881
+ public networkId: number;
1882
+ public validityStartHeight: number;
1883
+ public flags: Transaction.Flag;
1884
+ public data: Uint8Array;
1885
+ public proof: Uint8Array;
1886
+ constructor(
1887
+ format: Transaction.Format,
1888
+ sender: Address,
1889
+ senderType: Account.Type,
1890
+ recipient: Address,
1891
+ recipientType: Account.Type,
1892
+ value: BigNumber | number | string,
1893
+ validityStartHeight: number,
1894
+ flags: Transaction.Flag | any,
1895
+ data: Uint8Array,
1896
+ proof?: Uint8Array,
1897
+ networkId?: number,
1898
+ );
1899
+ public serializeContent(buf?: SerialBuffer): SerialBuffer;
1900
+ public verify(networkId?: number): boolean;
1901
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1902
+ public hash(): Hash;
1903
+ public compare(o: Transaction): -1 | 0 | 1;
1904
+ public compareBlockOrder(o: Transaction): -1 | 0 | 1;
1905
+ public equals(o: any): boolean;
1906
+ public toString(): string;
1907
+ public getContractCreationAddress(): Address;
1908
+ public hasFlag(flag: number): boolean;
1909
+ public toPlain(): {
1910
+ transactionHash: string,
1911
+ format: string;
1912
+ sender: string;
1913
+ senderType: string;
1914
+ recipient: string;
1915
+ recipientType: string;
1916
+ value: string;
1917
+ fee: string;
1918
+ feePerByte: string;
1919
+ validityStartHeight: number;
1920
+ network: string;
1921
+ flags: number;
1922
+ data: {raw: string};
1923
+ proof: {
1924
+ raw: string,
1925
+ signature?: string,
1926
+ publicKey?: string,
1927
+ signer?: string,
1928
+ pathLength?: number,
1929
+ };
1930
+ size: number;
1931
+ valid: boolean;
1932
+ };
1933
+ }
1934
+
1935
+ export namespace Transaction {
1936
+ type Format = Format.BASIC | Format.EXTENDED;
1937
+ namespace Format {
1938
+ type BASIC = 0;
1939
+ type EXTENDED = 1;
1940
+ }
1941
+ type Flag = Flag.NONE | Flag.CONTRACT_CREATION;
1942
+ namespace Flag {
1943
+ type NONE = 0;
1944
+ type CONTRACT_CREATION = 0b1;
1945
+ }
1946
+ }
1947
+
1948
+ export class SignatureProof {
1949
+ public static SINGLE_SIG_SIZE: number;
1950
+ public static verifyTransaction(transaction: Transaction): boolean;
1951
+ public static singleSig(publicKey: PublicKey, signature: Signature): SignatureProof;
1952
+ public static multiSig(signerKey: PublicKey, publicKeys: PublicKey[], signature: Signature): SignatureProof;
1953
+ public static unserialize(buf: SerialBuffer): SignatureProof;
1954
+ public serializedSize: number;
1955
+ public publicKey: PublicKey;
1956
+ public merklePath: MerklePath;
1957
+ public signature: Signature;
1958
+ constructor(
1959
+ publicKey: PublicKey,
1960
+ merklePath: MerklePath,
1961
+ signature: Signature,
1962
+ );
1963
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1964
+ public equals(o: any): boolean;
1965
+ public verify(address: Address | null, data: Uint8Array): boolean;
1966
+ public isSignedBy(sender: Address): boolean;
1967
+ }
1968
+
1969
+ export class BasicTransaction extends Transaction {
1970
+ public static unserialize(buf: SerialBuffer): BasicTransaction;
1971
+ public static fromPlain(plain: object): BasicTransaction;
1972
+ public serializedSize: number;
1973
+ public senderPubKey: PublicKey;
1974
+ public signature: Signature;
1975
+ constructor(
1976
+ senderPublicKey: PublicKey,
1977
+ recipient: Address,
1978
+ value: BigNumber | number | string,
1979
+ validityStartHeight: number,
1980
+ signature?: Signature,
1981
+ networkId?: number,
1982
+ );
1983
+ public serialize(buf?: SerialBuffer): SerialBuffer;
1984
+ }
1985
+
1986
+ export class ExtendedTransaction extends Transaction {
1987
+ public static unserialize(buf: SerialBuffer): ExtendedTransaction;
1988
+ public static fromPlain(plain: object): ExtendedTransaction;
1989
+ public serializedSize: number;
1990
+ constructor(
1991
+ sender: Address,
1992
+ senderType: Account.Type,
1993
+ recipient: Address,
1994
+ recipientType: Account.Type,
1995
+ value: BigNumber | number | string,
1996
+ validityStartHeight: number,
1997
+ flags: Transaction.Flag | number,
1998
+ data: Uint8Array,
1999
+ proof?: Uint8Array,
2000
+ networkId?: number,
2001
+ );
2002
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2003
+ }
2004
+
2005
+ export class TransactionsProof {
2006
+ public static unserialize(buf: SerialBuffer): TransactionsProof;
2007
+ public serializedSize: number;
2008
+ public length: number;
2009
+ public transactions: Transaction[];
2010
+ public proof: MerkleProof;
2011
+ constructor(transactions: Transaction[], proof: MerkleProof);
2012
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2013
+ public toString(): string;
2014
+ public root(): Hash;
2015
+ }
2016
+
2017
+ export type BlockDescriptor = object;
2018
+
2019
+ export class TransactionCache {
2020
+ public missingBlocks: number;
2021
+ public transactions: InclusionHashSet<Hash>;
2022
+ public head: null | BlockDescriptor;
2023
+ public tail: null | BlockDescriptor;
2024
+ constructor(transactionHashes?: InclusionHashSet<Hash>, blockOrder?: BlockDescriptor[]);
2025
+ public containsTransaction(transaction: Transaction): boolean;
2026
+ public pushBlock(block: Block): void;
2027
+ public shiftBlock(): void;
2028
+ public revertBlock(block: Block): number;
2029
+ public prependBlocks(blocks: Block[]): void;
2030
+ public clone(): TransactionCache;
2031
+ public isEmpty(): boolean;
2032
+ }
2033
+
2034
+ export class TransactionStoreEntry {
2035
+ public static fromBlock(block: Block): TransactionStoreEntry[];
2036
+ public static fromJSON(id: string, o: { transactionHashBuffer: Uint8Array, senderBuffer: Uint8Array, recipientBuffer: Uint8Array, blockHeight: number, blockHash: string, index: number }): TransactionStoreEntry;
2037
+ public transactionHash: Hash;
2038
+ public sender: Address;
2039
+ public recipient: Address;
2040
+ public blockHeight: number;
2041
+ public blockHash: Hash;
2042
+ public index: number;
2043
+ constructor(
2044
+ transactionHash: Hash,
2045
+ sender: Address,
2046
+ recipient: Address,
2047
+ blockHeight: number,
2048
+ blockHash: Hash,
2049
+ index: number,
2050
+ );
2051
+ public toJSON(): { transactionHashBuffer: Uint8Array, senderBuffer: Uint8Array, recipientBuffer: Uint8Array, blockHeight: number, blockHash: string, index: number };
2052
+ }
2053
+
2054
+ export class TransactionStore {
2055
+ public static CURRENT_ID_KEY: number;
2056
+ public static initPersistent(jdb: any): void;
2057
+ public static getPersistent(jdb: any): TransactionStore;
2058
+ public static createVolatile(): TransactionStore;
2059
+ public tx: any;
2060
+ constructor(store: any);
2061
+ public get(transactionHash: Hash): Promise<TransactionStoreEntry>;
2062
+ public getBySender(sender: Address, limit?: number): Promise<TransactionStoreEntry[]>;
2063
+ public getByRecipient(recipient: Address, limit?: number): Promise<TransactionStoreEntry[]>;
2064
+ public put(block: Block): Promise<void>;
2065
+ public remove(block: Block): Promise<void>;
2066
+ public snapshot(tx: TransactionStore): TransactionStore;
2067
+ public transaction(enableWatchdog?: boolean): TransactionStore;
2068
+ public truncate(): Promise<void>;
2069
+ public commit(): Promise<boolean>;
2070
+ public abort(): Promise<void>;
2071
+ }
2072
+
2073
+ export class TransactionStoreCodec {
2074
+ public valueEncoding: { encode: (val: any) => any, decode: (val: any) => any, buffer: boolean, type: string } | void;
2075
+ public encode(obj: any): any;
2076
+ public decode(obj: any, key: string): any;
2077
+ }
2078
+
2079
+ export class TransactionReceipt {
2080
+ public static unserialize(buf: SerialBuffer): TransactionReceipt;
2081
+ public static fromPlain(o: object): TransactionReceipt;
2082
+ public static fromAny(o: TransactionReceipt | object | string): TransactionReceipt;
2083
+ public serializedSize: number;
2084
+ public transactionHash: Hash;
2085
+ public blockHash: Hash;
2086
+ public blockHeight: number;
2087
+ constructor(
2088
+ transactionHash: Hash,
2089
+ blockHash: Hash,
2090
+ blockHeight: number,
2091
+ );
2092
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2093
+ public equals(o: any): boolean;
2094
+ public toPlain(): {
2095
+ transactionHash: string,
2096
+ blockHash: string,
2097
+ blockHeight: number,
2098
+ };
2099
+ }
2100
+
2101
+ export class Block {
2102
+ public static TIMESTAMP_DRIFT_MAX: 600 /* seconds */; // 10 minutes
2103
+ public static unserialize(buf: SerialBuffer): Block;
2104
+ public static fromAny(block: Block | object | string): Block;
2105
+ public static fromPlain(o: object): Block;
2106
+ public serializedSize: number;
2107
+ public header: BlockHeader;
2108
+ public interlink: BlockInterlink;
2109
+ public body: BlockBody;
2110
+ public version: number;
2111
+ public prevHash: Hash;
2112
+ public interlinkHash: Hash;
2113
+ public bodyHash: Hash;
2114
+ public accountsHash: Hash;
2115
+ public nBits: number;
2116
+ public target: BigNumber;
2117
+ public difficulty: BigNumber;
2118
+ public height: number;
2119
+ public timestamp: number;
2120
+ public nonce: number;
2121
+ public minerAddr: Address | undefined;
2122
+ public transactions: Transaction[] | undefined;
2123
+ public extraData: Uint8Array | undefined;
2124
+ public prunedAccounts: PrunedAccount[] | undefined;
2125
+ public transactionCount: number | undefined;
2126
+ constructor(
2127
+ header: BlockHeader,
2128
+ interlink: BlockInterlink,
2129
+ body?: BlockBody,
2130
+ );
2131
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2132
+ public verify(time: Time): Promise<boolean>;
2133
+ public isImmediateSuccessorOf(predecessor: Block): Promise<boolean>;
2134
+ public isInterlinkSuccessorOf(predecessor: Block): Promise<boolean>;
2135
+ public isSuccessorOf(predecessor: Block): Promise<boolean>;
2136
+ public getNextInterlink(nextTarget: BigNumber, nextVersion?: number): Promise<BlockInterlink>;
2137
+ public shallowCopy(): Block;
2138
+ public equals(o: any): boolean;
2139
+ public isLight(): boolean;
2140
+ public isFull(): boolean;
2141
+ public toLight(): Block;
2142
+ public toFull(body: BlockBody): Block;
2143
+ public hash(buf?: SerialBuffer): Hash;
2144
+ public pow(buf?: SerialBuffer): Promise<Hash>;
2145
+ public toString(): string;
2146
+ public toPlain(): {
2147
+ version: number,
2148
+ hash: string,
2149
+ prevHash: string,
2150
+ interlinkHash: string,
2151
+ bodyHash: string,
2152
+ accountsHash: string,
2153
+ nBits: number,
2154
+ difficulty: string,
2155
+ height: number,
2156
+ timestamp: number,
2157
+ nonce: number,
2158
+ interlink: string[],
2159
+ minerAddr?: string,
2160
+ transactions?: object[],
2161
+ extraData?: string,
2162
+ prunedAccounts?: object[],
2163
+ };
2164
+ }
2165
+
2166
+ export class BlockProducer {
2167
+ constructor(blockchain: BaseChain, accounts: Accounts, mempool: Mempool, time: Time);
2168
+ public getNextBlock(address: Address, extraData?: Uint8Array): Promise<Block>;
2169
+ }
2170
+
2171
+ export abstract class IBlockchain extends Observable {
2172
+ public abstract head: Block;
2173
+ public abstract headHash: Hash;
2174
+ public abstract height: number;
2175
+ }
2176
+
2177
+ export abstract class BaseChain extends IBlockchain {
2178
+ public static MULTILEVEL_STRATEGY: BaseChain.MultilevelStrategy.MODERATE;
2179
+ public static MultilevelStrategy: {
2180
+ STRICT: 1;
2181
+ MODERATE: 2;
2182
+ RELAXED: 3;
2183
+ };
2184
+ public static manyPow(headers: BlockHeader[]): Promise<void>;
2185
+ constructor(store: ChainDataStore);
2186
+ public getBlock(hash: Hash, includeForks?: boolean, includeBody?: boolean): Promise<null | Block>;
2187
+ public getRawBlock(hash: Hash, includeForks?: boolean): Promise<null | Uint8Array>;
2188
+ public getBlockAt(height: number, includeBody?: boolean): Promise<null | Block>;
2189
+ public getNearestBlockAt(height: number, lower?: boolean): Promise<null | Block>;
2190
+ public getSuccessorBlocks(block: Block): Promise<Block[]>;
2191
+ public getBlockLocators(): Promise<Hash[]>;
2192
+ public getNextTarget(block?: Block, next?: Block): Promise<BigNumber>;
2193
+ public isBetterProof(proof1: ChainProof, proof2: ChainProof, m: number): Promise<boolean>;
2194
+ }
2195
+
2196
+ export namespace BaseChain {
2197
+ type MultilevelStrategy = BaseChain.MultilevelStrategy.STRICT | BaseChain.MultilevelStrategy.MODERATE | BaseChain.MultilevelStrategy.RELAXED;
2198
+ namespace MultilevelStrategy {
2199
+ type STRICT = 1;
2200
+ type MODERATE = 2;
2201
+ type RELAXED = 3;
2202
+ }
2203
+ }
2204
+
2205
+ export class BlockChain {
2206
+ public static merge(chain1: BlockChain, chain2: BlockChain): BlockChain;
2207
+ public static lowestCommonAncestor(chain1: BlockChain, chain2: BlockChain): undefined | Block;
2208
+ public static unserialize(buf: SerialBuffer): BlockChain;
2209
+ public serializedSize: number;
2210
+ public length: number;
2211
+ public blocks: Block[];
2212
+ public head: Block;
2213
+ public tail: Block;
2214
+ constructor(blocks: Block[], superChains?: BlockChain[]);
2215
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2216
+ public verify(): Promise<boolean>;
2217
+ public denseSuffix(): Block[];
2218
+ public getSuperChains(): Promise<BlockChain[]>;
2219
+ public isAnchored(): boolean;
2220
+ public toString(): string;
2221
+ public totalDifficulty(): number;
2222
+ }
2223
+
2224
+ export class HeaderChain {
2225
+ public static unserialize(buf: SerialBuffer): HeaderChain;
2226
+ public serializedSize: number;
2227
+ public length: number;
2228
+ public headers: BlockHeader[];
2229
+ public head: BlockHeader;
2230
+ public tail: BlockHeader;
2231
+ constructor(headers: BlockHeader[]);
2232
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2233
+ public verify(): Promise<boolean>;
2234
+ public toString(): string;
2235
+ public totalDifficulty(): BigNumber;
2236
+ }
2237
+
2238
+ export class ChainProof {
2239
+ public static unserialize(buf: SerialBuffer): ChainProof;
2240
+ public serializedSize: number;
2241
+ public prefix: BlockChain;
2242
+ public suffix: HeaderChain;
2243
+ public head: BlockHeader;
2244
+ constructor(prefix: BlockChain, suffix: HeaderChain);
2245
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2246
+ public verify(): Promise<boolean>;
2247
+ public toString(): string;
2248
+ }
2249
+
2250
+ export class ChainData {
2251
+ public static initial(block: Block, superBlockCounts: SuperBlockCounts): Promise<ChainData>;
2252
+ public static fromObj(obj: { _head: Uint8Array, _totalDifficulty: string, _totalWork: string, _superBlockCounts: number[], _onMainChain: boolean, _mainChainSuccessor: null | Uint8Array, _height: number, _pow: Uint8Array }, hashBase64?: string): ChainData;
2253
+ public head: Block;
2254
+ public totalDifficulty: BigNumber;
2255
+ public totalWork: BigNumber;
2256
+ public superBlockCounts: SuperBlockCounts;
2257
+ public onMainChain: boolean;
2258
+ public mainChainSuccessor: Hash;
2259
+ constructor(
2260
+ head: Block,
2261
+ totalDifficulty: BigNumber,
2262
+ totalWork: BigNumber,
2263
+ superBlockCounts: SuperBlockCounts,
2264
+ onMainChain?: boolean,
2265
+ mainChainSuccessor?: Hash,
2266
+ );
2267
+ public toObj(): { _head: SerialBuffer, _totalDifficulty: string, _totalWork: string, _superBlockCounts: number[], _onMainChain: boolean, _mainChainSuccessor: null | SerialBuffer, _height: number, _pow: SerialBuffer };
2268
+ public shallowCopy(): ChainData;
2269
+ public nextChainData(block: Block): Promise<ChainData>;
2270
+ public previousChainData(block: Block): Promise<ChainData>;
2271
+ }
2272
+
2273
+ export class SuperBlockCounts {
2274
+ public length: number;
2275
+ public array: number[];
2276
+ constructor(array: number[]);
2277
+ public add(depth: number): void;
2278
+ public subtract(depth: number): void;
2279
+ public copyAndAdd(depth: number): SuperBlockCounts;
2280
+ public copyAndSubtract(depth: number): SuperBlockCounts;
2281
+ public get(depth: number): number;
2282
+ public getCandidateDepth(m: number): number;
2283
+ }
2284
+
2285
+ export class ChainDataStore {
2286
+ public static CHAINDATA_CACHING_ENABLED: true;
2287
+ public static CHAINDATA_CACHE_SIZE: 5000;
2288
+ public static BLOCKS_CACHING_ENABLED: true;
2289
+ public static BLOCKS_CACHE_SIZE: 0;
2290
+ public static BLOCKS_RAW_CACHE_SIZE: 500;
2291
+ public static initPersistent(jdb: any): void;
2292
+ public static getPersistent(jdb: any): ChainDataStore;
2293
+ public static createVolatile(): ChainDataStore;
2294
+ public txs: any[];
2295
+ constructor(chainStore: any, blockStore: any);
2296
+ public getChainData(key: Hash, includeBody?: boolean): Promise<null | ChainData>;
2297
+ public putChainData(key: Hash, chainData: ChainData, includeBody?: boolean): Promise<void>;
2298
+ public putChainDataSync(key: Hash, chainData: ChainData, includeBody?: boolean): void;
2299
+ public removeChainDataSync(key: Hash): void;
2300
+ public getBlock(key: Hash, includeBody?: boolean): null | Block;
2301
+ public getRawBlock(key: Hash, includeForks?: boolean): Promise<null | Uint8Array>;
2302
+ public getChainDataCandidatesAt(height: number): Promise<ChainData[]>;
2303
+ public getChainDataAt(height: number, includeBody?: boolean): Promise<undefined | null | ChainData>;
2304
+ public getBlockAt(height: number, includeBody?: boolean): Promise<null | Block>;
2305
+ public getSuccessorBlocks(block: Block): Promise<Block[]>;
2306
+ public getNearestBlockAt(height: number, lower?: boolean): Promise<undefined | null | Block>;
2307
+ public getBlocks(startBlockHash: Hash, count?: number, forward?: boolean): Promise<Block[]>;
2308
+ public getBlocksForward(startBlockHash: Hash, count?: number): Promise<Block[]>;
2309
+ public getBlocksBackward(startBlockHash: Hash, count?: number, includeBody?: boolean): Promise<Block[]>;
2310
+ public getHead(): Promise<undefined | Hash>;
2311
+ public setHead(key: Hash): Promise<void>;
2312
+ public setHeadSync(key: Hash): void;
2313
+ public transaction(enableWatchdog?: boolean): ChainDataStore;
2314
+ public synchronousTransaction(enableWatchdog?: boolean): ChainDataStore;
2315
+ public commit(): Promise<void>;
2316
+ public abort(): Promise<void>;
2317
+ public snapshot(): ChainDataStore;
2318
+ public truncate(): Promise<void>;
2319
+ }
2320
+
2321
+ export class ChainDataStoreCodec {
2322
+ public valueEncoding: { encode: (val: any) => any, decode: (val: any) => any, buffer: boolean, type: string } | void;
2323
+ public encode(obj: any): any;
2324
+ public decode(obj: any, key: string): any;
2325
+ }
2326
+
2327
+ export class BlockStoreCodec {
2328
+ public valueEncoding: { encode: (val: any) => any, decode: (val: any) => any, buffer: boolean, type: string } | void;
2329
+ public encode(obj: any): any;
2330
+ public decode(obj: any, key: string): any;
2331
+ }
2332
+
2333
+ export class MempoolTransactionSet {
2334
+ public transactions: Transaction[];
2335
+ public sender: Address;
2336
+ public senderType: undefined | Account.Type;
2337
+ public length: number;
2338
+ constructor(sortedTransactions: Transaction[]);
2339
+ public add(transaction: Transaction): MempoolTransactionSet;
2340
+ public remove(transaction: Transaction): MempoolTransactionSet;
2341
+ public copyAndAdd(transaction: Transaction): MempoolTransactionSet;
2342
+ public numBelowFeePerByte(feePerByte: BigNumber | number | string): number;
2343
+ public toString(): string;
2344
+ }
2345
+
2346
+ export class MempoolFilter {
2347
+ public static BLACKLIST_SIZE: number;
2348
+ public static FEE: number;
2349
+ public static VALUE: number;
2350
+ public static TOTAL_VALUE: number;
2351
+ public static RECIPIENT_BALANCE: number;
2352
+ public static SENDER_BALANCE: number;
2353
+ public static CREATION_FEE: number;
2354
+ public static CREATION_FEE_PER_BYTE: number;
2355
+ public static CREATION_VALUE: number;
2356
+ public static CONTRACT_FEE: number;
2357
+ public static CONTRACT_FEE_PER_BYTE: number;
2358
+ public static CONTRACT_VALUE: number;
2359
+ constructor();
2360
+ public acceptsTransaction(tx: Transaction): boolean;
2361
+ public acceptsRecipientAccount(tx: Transaction, oldAccount: Account, newAccount: Account): boolean;
2362
+ public acceptsSenderAccount(tx: Transaction, oldAccount: Account, newAccount: Account): boolean;
2363
+ public blacklist(hash: Hash): void;
2364
+ public isBlacklisted(hash: Hash): boolean;
2365
+ }
2366
+
2367
+ export class Mempool extends Observable {
2368
+ public static TRANSACTION_RELAY_FEE_MIN: 1;
2369
+ public static TRANSACTIONS_PER_SENDER_MAX: 500;
2370
+ public static FREE_TRANSACTIONS_PER_SENDER_MAX: 10;
2371
+ public static SIZE_MAX: number;
2372
+ public static ReturnCode: {
2373
+ EXPIRED: -5;
2374
+ MINED: -4;
2375
+ FILTERED: -3;
2376
+ FEE_TOO_LOW: -2;
2377
+ INVALID: -1;
2378
+ ACCEPTED: 1;
2379
+ KNOWN: 2;
2380
+ };
2381
+ public length: number;
2382
+ public queue: Synchronizer;
2383
+ constructor(blockchain: IBlockchain, accounts: Accounts);
2384
+ public pushTransaction(transaction: Transaction): Promise<Mempool.ReturnCode>;
2385
+ public getTransaction(hash: Hash): Transaction;
2386
+ // public *transactionGenerator(maxSize?: number, minFeePerByte?: number): IterableIterator<Transaction>;
2387
+ public getTransactions(maxSize?: number): Transaction[];
2388
+ public getTransactionsForBlock(maxSize: number): Promise<Transaction[]>;
2389
+ public getPendingTransactions(address: Address): Transaction[];
2390
+ public getTransactionsBySender(address: Address): Transaction[];
2391
+ public getTransactionsByRecipient(address: Address): Transaction[];
2392
+ public getTransactionsByAddresses(addresses: Address[], maxTransactions?: number): Transaction[];
2393
+ public isFiltered(txHash: Hash): boolean;
2394
+ }
2395
+
2396
+ export namespace Mempool {
2397
+ type ReturnCode = ReturnCode.FEE_TOO_LOW | ReturnCode.INVALID | ReturnCode.ACCEPTED | ReturnCode.KNOWN;
2398
+ namespace ReturnCode {
2399
+ type EXPIRED = -5;
2400
+ type MINED = -4;
2401
+ type FILTERED = -3;
2402
+ type FEE_TOO_LOW = -2;
2403
+ type INVALID = -1;
2404
+ type ACCEPTED = 1;
2405
+ type KNOWN = 2;
2406
+ }
2407
+ }
2408
+
2409
+ export class InvRequestManager {
2410
+ public static MAX_TIME_PER_VECTOR: 10000;
2411
+ public static MAX_INV_MANAGED: 10000;
2412
+ constructor();
2413
+ public askToRequestVector(agent: BaseConsensusAgent, vector: InvVector): void;
2414
+ public noteVectorNotReceived(agent: BaseConsensusAgent, vector: InvVector): void;
2415
+ public noteVectorReceived(vector: InvVector): void;
2416
+ }
2417
+
2418
+ export class BaseConsensusAgent extends Observable {
2419
+ public static REQUEST_THRESHOLD: 50;
2420
+ public static REQUEST_THROTTLE: 500;
2421
+ public static REQUEST_TIMEOUT: 10000;
2422
+ public static REQUEST_TRANSACTIONS_WAITING_MAX: 5000;
2423
+ public static REQUEST_BLOCKS_WAITING_MAX: 5000;
2424
+ public static BLOCK_PROOF_REQUEST_TIMEOUT: 10000;
2425
+ public static TRANSACTIONS_PROOF_REQUEST_TIMEOUT: 10000;
2426
+ public static TRANSACTION_RECEIPTS_REQUEST_TIMEOUT: 15000;
2427
+ public static TRANSACTION_RELAY_INTERVAL: 5000;
2428
+ public static TRANSACTIONS_AT_ONCE: 100;
2429
+ public static TRANSACTIONS_PER_SECOND: 10;
2430
+ public static FREE_TRANSACTION_RELAY_INTERVAL: 6000;
2431
+ public static FREE_TRANSACTIONS_AT_ONCE: 10;
2432
+ public static FREE_TRANSACTIONS_PER_SECOND: 1;
2433
+ public static FREE_TRANSACTION_SIZE_PER_INTERVAL: 15000; // ~100 legacy transactions
2434
+ public static TRANSACTION_RELAY_FEE_MIN: 1;
2435
+ public static SUBSCRIPTION_CHANGE_GRACE_PERIOD: 3000;
2436
+ public static HEAD_REQUEST_INTERVAL: 100000; // 100 seconds, give client time to announce new head without request
2437
+ public static KNOWS_OBJECT_AFTER_INV_DELAY: 3000;
2438
+ public static KNOWN_OBJECTS_COUNT_MAX: 40000;
2439
+ public peer: Peer;
2440
+ public synced: boolean;
2441
+ public syncing: boolean;
2442
+ constructor(
2443
+ time: Time,
2444
+ peer: Peer,
2445
+ invRequestManager: InvRequestManager,
2446
+ targetSubscription?: Subscription,
2447
+ );
2448
+ public providesServices(...services: number[]): boolean;
2449
+ public onHeadUpdated(): void;
2450
+ public subscribe(subscription: Subscription): void;
2451
+ public relayBlock(block: Block): boolean;
2452
+ public requestBlock(hash: Hash): Promise<Block | null>;
2453
+ public requestTransaction(hash: Hash): Promise<Transaction | null>;
2454
+ public relayTransaction(transaction: Transaction): boolean;
2455
+ public removeTransaction(transaction: Transaction): void;
2456
+ public knowsBlock(blockHash: Hash): boolean;
2457
+ public knowsTransaction(txHash: Hash): boolean;
2458
+ public requestVector(...vector: InvVector[]): void;
2459
+ public getBlockProof(blockHashToProve: Hash, knownBlock: Block): Promise<Block>;
2460
+ public getBlockProofAt(blockHeightToProve: number, knownBlock: Block): Promise<Block>;
2461
+ public getTransactionProof(block: Block, addresses: Address[]): Promise<Transaction[]>;
2462
+ public getTransactionsProofByAddresses(block: Block, addresses: Address[]): Promise<Transaction[]>;
2463
+ public getTransactionsProofByHashes(block: Block, hashes: Hash[]): Promise<Transaction[]>;
2464
+ public getTransactionReceipts(address: Address): Promise<TransactionReceipt[]>;
2465
+ public getTransactionReceiptsByAddress(address: Address, limit?: number): Promise<TransactionReceipt[]>;
2466
+ public getTransactionReceiptsByHashes(hashes: Hash[]): Promise<TransactionReceipt[]>;
2467
+ public shutdown(): void;
2468
+ }
2469
+
2470
+ // Not registered globally
2471
+ // export class FreeTransactionVector {
2472
+ // constructor(inv: InvVector, serializedSize: number);
2473
+ // public hashCode(): string;
2474
+ // public toString(): string;
2475
+ // public inv: InvVector;
2476
+ // public serializedSize: number;
2477
+ // }
2478
+
2479
+ export class BaseConsensus extends Observable {
2480
+ public static MAX_ATTEMPTS_TO_FETCH: 5;
2481
+ public static SYNC_THROTTLE: 1500; // ms
2482
+ public static MIN_FULL_NODES: 1;
2483
+ public static TRANSACTION_RELAY_TIMEOUT: 10000;
2484
+ public static SendTransactionResult: {
2485
+ REJECTED_LOCAL: -4,
2486
+ EXPIRED: -3,
2487
+ ALREADY_MINED: -2,
2488
+ INVALID: -1,
2489
+ NONE: 0,
2490
+ RELAYED: 1,
2491
+ KNOWN: 2,
2492
+ PENDING_LOCAL: 3,
2493
+ };
2494
+ public established: boolean;
2495
+ public network: Network;
2496
+ public invRequestManager: InvRequestManager;
2497
+ constructor(
2498
+ blockchain: BaseChain,
2499
+ mempool: Observable,
2500
+ network: Network,
2501
+ );
2502
+ public getHeadHash(): Promise<Hash>;
2503
+ public getHeadHeight(): Promise<number>;
2504
+ public getBlock(hash: Hash, includeBody?: boolean, includeBodyFromLocal?: boolean, blockHeight?: number): Promise<Block>;
2505
+ public getBlockAt(height: number, includeBody?: boolean): Promise<Block>;
2506
+ public getPendingTransactions(hashes: Hash[]): Promise<Transaction[]>;
2507
+ public getTransactionsFromBlock(hashes: Hash[], blockHash: Hash, blockHeight?: number, block?: Block): Promise<Transaction[]>;
2508
+ public getTransactionsFromBlockByAddresses(addresses: Address[], blockHash: Hash, blockHeight?: number): Promise<Transaction[]>;
2509
+ public getTransactionReceiptsByAddress(address: Address, limit?: number): Promise<TransactionReceipt[]>;
2510
+ public getTransactionReceiptsByHashes(hashes: Hash[]): Promise<TransactionReceipt[]>;
2511
+ public getMempoolContents(): Transaction[];
2512
+ public handoverTo(consensus: BaseConsensus): BaseConsensus;
2513
+ public subscribe(subscription: Subscription): void;
2514
+ public getSubscription(): Subscription;
2515
+ }
2516
+
2517
+ export namespace BaseConsensus {
2518
+ type SendTransactionResult = SendTransactionResult.REJECTED_LOCAL | SendTransactionResult.EXPIRED | SendTransactionResult.ALREADY_MINED | SendTransactionResult.INVALID | SendTransactionResult.NONE | SendTransactionResult.RELAYED | SendTransactionResult.KNOWN | SendTransactionResult.PENDING_LOCAL;
2519
+ namespace SendTransactionResult {
2520
+ type REJECTED_LOCAL = -4;
2521
+ type EXPIRED = -3;
2522
+ type ALREADY_MINED = -2;
2523
+ type INVALID = -1;
2524
+ type NONE = 0;
2525
+ type RELAYED = 1;
2526
+ type KNOWN = 2;
2527
+ type PENDING_LOCAL = 3;
2528
+ }
2529
+ }
2530
+
2531
+ export class FullChain extends BaseChain {
2532
+ public static ERR_ORPHAN: -2;
2533
+ public static ERR_INVALID: -1;
2534
+ public static OK_KNOWN: 0;
2535
+ public static OK_EXTENDED: 1;
2536
+ public static OK_REBRANCHED: 2;
2537
+ public static OK_FORKED: 3;
2538
+ public static SYNCHRONIZER_THROTTLE_AFTER: 500; // ms
2539
+ public static SYNCHRONIZER_THROTTLE_WAIT: 30; // ms
2540
+ public static getPersistent(jdb: any, accounts: Accounts, time: Time, transactionStore?: TransactionStore): Promise<FullChain>;
2541
+ public static createVolatile(accounts: Accounts, time: Time, transactionStore?: TransactionStore): Promise<FullChain>;
2542
+ public head: Block;
2543
+ public headHash: Hash;
2544
+ public height: number;
2545
+ public totalDifficulty: BigNumber;
2546
+ public totalWork: BigNumber;
2547
+ public accounts: Accounts;
2548
+ public transactionCache: TransactionCache;
2549
+ public blockForkedCount: number;
2550
+ public blockRebranchedCount: number;
2551
+ public blockExtendedCount: number;
2552
+ public blockOrphanCount: number;
2553
+ public blockInvalidCount: number;
2554
+ public blockKnownCount: number;
2555
+ constructor(
2556
+ store: ChainDataStore,
2557
+ accounts: Accounts,
2558
+ time: Time,
2559
+ transactionStore?: TransactionStore,
2560
+ );
2561
+ public pushBlock(block: Block): Promise<number>;
2562
+ public getBlocks(startBlockHash: Hash, count?: number, forward?: boolean): Promise<Block[]>;
2563
+ public getChainProof(): Promise<ChainProof>;
2564
+ public getBlockProof(blockToProve: Block, knownBlock: Block): Promise<null | BlockChain>;
2565
+ public getAccountsTreeChunk(blockHash: Hash, startPrefix: string): Promise<null | AccountsTreeChunk>;
2566
+ public getAccountsProof(blockHash: Hash, addresses: Address[]): Promise<null | AccountsProof>;
2567
+ public getTransactionsProof(blockHash: Hash, addresses: Address[]): Promise<null | TransactionsProof>;
2568
+ public getTransactionsProofByAddresses(blockHash: Hash, addresses: Address[]): Promise<TransactionsProof | null>;
2569
+ public getTransactionsProofByHashes(blockHash: Hash, hashes: Hash[]): Promise<TransactionsProof | null>;
2570
+ public getTransactionReceiptsByAddress(address: Address, limit?: number): Promise<TransactionReceipt[] | null>;
2571
+ public getTransactionReceiptsByHashes(hashes: Hash[], limit?: number): Promise<TransactionReceipt[] | null>;
2572
+ public getTransactionInfoByHash(transactionHash: Hash): Promise<null | TransactionStoreEntry>;
2573
+ public accountsHash(): Promise<Hash>;
2574
+ public queue(): PrioritySynchronizer;
2575
+ }
2576
+
2577
+ export class FullConsensusAgent extends BaseConsensusAgent {
2578
+ public static SYNC_ATTEMPTS_MAX: number;
2579
+ public static GETBLOCKS_VECTORS_MAX: 500;
2580
+ public static RESYNC_THROTTLE: 3000; // 3 seconds
2581
+ public static MEMPOOL_DELAY_MIN: 2000; // 2 seconds
2582
+ public static MEMPOOL_DELAY_MAX: 20000; // 20 seconds
2583
+ public static MEMPOOL_THROTTLE: 1000;
2584
+ public static MEMPOOL_ENTRIES_MAX: 10000;
2585
+ public static CHAIN_PROOF_RATE_LIMIT: 3; // per minute
2586
+ public static ACCOUNTS_PROOF_RATE_LIMIT: 60; // per minute
2587
+ public static ACCOUNTS_TREE_CHUNK_RATE_LIMIT: 300; // per minute
2588
+ public static TRANSACTION_PROOF_RATE_LIMIT: 60; // per minute
2589
+ public static TRANSACTION_RECEIPTS_RATE_LIMIT: 30; // per minute
2590
+ public static BLOCK_PROOF_RATE_LIMIT: 60; // per minute
2591
+ public static GET_BLOCKS_RATE_LIMIT: 30; // per minute
2592
+ public syncing: boolean;
2593
+ constructor(
2594
+ blockchain: FullChain,
2595
+ mempool: Mempool,
2596
+ time: Time,
2597
+ peer: Peer,
2598
+ invRequestManager: InvRequestManager,
2599
+ targetSubscription: Subscription,
2600
+ );
2601
+ public syncBlockchain(): void;
2602
+ }
2603
+
2604
+ export class FullConsensus extends BaseConsensus {
2605
+ public blockchain: FullChain;
2606
+ public mempool: Mempool;
2607
+ constructor(
2608
+ blockchain: FullChain,
2609
+ mempool: Mempool,
2610
+ network: Network,
2611
+ );
2612
+ public getBlock(hash: Hash, includeBody?: boolean, includeBodyFromLocal?: boolean, blockHeight?: number): Promise<Block>;
2613
+ public getBlockAt(height: number, includeBody?: boolean): Promise<Block>;
2614
+ public getBlockTemplate(minerAddress: Address, extraData?: Uint8Array): Promise<Block>;
2615
+ public submitBlock(block: Block): Promise<boolean>;
2616
+ public getAccounts(addresses: Address[]): Promise<Account[]>;
2617
+ public getPendingTransactions(hashes: Hash[]): Promise<Transaction[]>;
2618
+ public getPendingTransactionsByAddress(address: Address, limit?: number): Promise<Transaction[]>;
2619
+ public getTransactionsFromBlock(hashes: Hash[], blockHash: Hash, blockHeight?: number, block?: Block): Promise<Transaction[]>;
2620
+ public getTransactionReceiptsByAddress(address: Address, limit?: number): Promise<TransactionReceipt[]>;
2621
+ public getTransactionReceiptsByHashes(hashes: Hash[]): Promise<TransactionReceipt[]>;
2622
+ public sendTransaction(tx: Transaction): Promise<BaseConsensus.SendTransactionResult>;
2623
+ public getMempoolContents(): Transaction[];
2624
+ }
2625
+
2626
+ export class LightChain extends FullChain {
2627
+ public static getPersistent(jdb: any, accounts: Accounts, time: Time): Promise<LightChain>;
2628
+ public static createVolatile(accounts: Accounts, time: Time): Promise<LightChain>;
2629
+ constructor(
2630
+ store: ChainDataStore,
2631
+ accounts: Accounts,
2632
+ time: Time,
2633
+ );
2634
+ public partialChain(): PartialLightChain;
2635
+ }
2636
+
2637
+ export class LightConsensusAgent extends FullConsensusAgent {
2638
+ public static CHAINPROOF_REQUEST_TIMEOUT: 45000;
2639
+ public static CHAINPROOF_CHUNK_TIMEOUT: 10000;
2640
+ public static ACCOUNTS_TREE_CHUNK_REQUEST_TIMEOUT: 8000;
2641
+ public static SYNC_ATTEMPTS_MAX: number;
2642
+ public static GETBLOCKS_VECTORS_MAX: 500;
2643
+ public static WEAK_PROOFS_MAX: 3;
2644
+ public syncing: boolean;
2645
+ constructor(
2646
+ blockchain: LightChain,
2647
+ mempool: Mempool,
2648
+ time: Time,
2649
+ peer: Peer,
2650
+ invRequestManager: InvRequestManager,
2651
+ targetSubscription: Subscription,
2652
+ );
2653
+ public syncBlockchain(): Promise<void>;
2654
+ public getHeader(hash: Hash): Promise<BlockHeader>;
2655
+ }
2656
+
2657
+ export class LightConsensus extends BaseConsensus {
2658
+ public blockchain: LightChain;
2659
+ public mempool: Mempool;
2660
+ constructor(
2661
+ blockchain: LightChain,
2662
+ mempool: Mempool,
2663
+ network: Network,
2664
+ );
2665
+ public getBlockTemplate(minerAddress: Address, extraData?: Uint8Array): Promise<Block>;
2666
+ public submitBlock(block: Block): Promise<boolean>;
2667
+ public getAccounts(addresses: Address[]): Promise<Account[]>;
2668
+ public getPendingTransactions(hashes: Hash[]): Promise<Transaction[]>;
2669
+ public getPendingTransactionsByAddress(address: Address, limit?: number): Promise<Transaction[]>;
2670
+ public sendTransaction(tx: Transaction): Promise<BaseConsensus.SendTransactionResult>;
2671
+ public getMempoolContents(): Transaction[];
2672
+ }
2673
+
2674
+ export class PartialLightChain extends LightChain {
2675
+ public static State: {
2676
+ WEAK_PROOF: -2;
2677
+ ABORTED: -1;
2678
+ PROVE_CHAIN: 0;
2679
+ PROVE_ACCOUNTS_TREE: 1;
2680
+ PROVE_BLOCKS: 2;
2681
+ COMPLETE: 3;
2682
+ };
2683
+ public state: PartialLightChain.State;
2684
+ public proofHeadHeight: number;
2685
+ constructor(
2686
+ store: ChainDataStore,
2687
+ accounts: Accounts,
2688
+ time: Time,
2689
+ proof: ChainProof,
2690
+ commitSynchronizer: PrioritySynchronizer,
2691
+ );
2692
+ public pushProof(proof: ChainProof): Promise<boolean>;
2693
+ public pushAccountsTreeChunk(chunk: AccountsTreeChunk): Promise<PartialAccountsTree.Status>;
2694
+ public commit(): Promise<boolean>;
2695
+ public abort(): Promise<void>;
2696
+ public getMissingAccountsPrefix(): string;
2697
+ // @ts-ignore
2698
+ public getBlockLocators(): Hash[];
2699
+ public numBlocksNeeded(): number;
2700
+ public needsMoreBlocks(): boolean;
2701
+ }
2702
+
2703
+ export namespace PartialLightChain {
2704
+ type State = State.WEAK_PROOF | State.ABORTED | State.PROVE_CHAIN | State.PROVE_ACCOUNTS_TREE | State.PROVE_BLOCKS | State.COMPLETE;
2705
+ namespace State {
2706
+ type WEAK_PROOF = -2;
2707
+ type ABORTED = -1;
2708
+ type PROVE_CHAIN = 0;
2709
+ type PROVE_ACCOUNTS_TREE = 1;
2710
+ type PROVE_BLOCKS = 2;
2711
+ type COMPLETE = 3;
2712
+ }
2713
+ }
2714
+
2715
+ export class BaseMiniConsensusAgent extends BaseConsensusAgent {
2716
+ public static ACCOUNTSPROOF_REQUEST_TIMEOUT: 5000;
2717
+ public static MEMPOOL_DELAY_MIN: 500;
2718
+ public static MEMPOOL_DELAY_MAX: 5000;
2719
+ public static MEMPOOL_ENTRIES_MAX: 1000;
2720
+ constructor(
2721
+ blockchain: BaseChain,
2722
+ mempool: NanoMempool,
2723
+ time: Time,
2724
+ peer: Peer,
2725
+ invRequestManager: InvRequestManager,
2726
+ targetSubscription: Subscription,
2727
+ );
2728
+ public requestMempool(): void;
2729
+ public getAccounts(blockHash: Hash, addresses: Address[]): Promise<Account[]>;
2730
+ }
2731
+
2732
+ export class BaseMiniConsensus extends BaseConsensus {
2733
+ public static MempoolRejectedError: BaseMiniConsensusMempoolRejectedError;
2734
+ constructor(blockchain: BaseChain, mempool: Observable, network: Network);
2735
+ public subscribeAccounts(addresses: Address[]): void;
2736
+ public subscribe(subscription: Subscription): void;
2737
+ public addSubscriptions(newAddresses: Address[] | Address): void;
2738
+ public removeSubscriptions(addressesToRemove: Address[] | Address): void;
2739
+ public getAccount(address: Address, blockHash?: Hash): Promise<Account>;
2740
+ public getAccounts(addresses: Address[], blockHash?: Hash): Promise<Account[]>;
2741
+ public sendTransaction(tx: Transaction): Promise<BaseConsensus.SendTransactionResult>;
2742
+ public getPendingTransactions(hashes: Hash[]): Promise<Transaction[]>;
2743
+ public getPendingTransactionsByAddress(address: Address, limit?: number): Promise<Transaction[]>;
2744
+ public relayTransaction(transaction: Transaction): Promise<void>;
2745
+ }
2746
+
2747
+ declare class BaseMiniConsensusMempoolRejectedError extends Error {
2748
+ public mempoolReturnCode: Mempool.ReturnCode;
2749
+ constructor(mempoolCode: Mempool.ReturnCode);
2750
+ }
2751
+
2752
+ export class NanoChain extends BaseChain {
2753
+ public static ERR_ORPHAN: -2;
2754
+ public static ERR_INVALID: -1;
2755
+ public static OK_KNOWN: 0;
2756
+ public static OK_EXTENDED: 1;
2757
+ public static OK_REBRANCHED: 2;
2758
+ public static OK_FORKED: 3;
2759
+ public static SYNCHRONIZER_THROTTLE_AFTER: 500; // ms
2760
+ public static SYNCHRONIZER_THROTTLE_WAIT: 30; // ms
2761
+ public head: Block;
2762
+ public headHash: Hash;
2763
+ public height: number;
2764
+ constructor(time: Time);
2765
+ public pushProof(proof: ChainProof): Promise<boolean>;
2766
+ public pushHeader(header: BlockHeader): Promise<number>;
2767
+ public getChainProof(): Promise<ChainProof>;
2768
+ }
2769
+
2770
+ export class NanoConsensusAgent extends BaseMiniConsensusAgent {
2771
+ public static CHAINPROOF_REQUEST_TIMEOUT: 45000;
2772
+ public static CHAINPROOF_CHUNK_TIMEOUT: 10000;
2773
+ public syncing: boolean;
2774
+ constructor(
2775
+ blockchain: NanoChain,
2776
+ mempool: NanoMempool,
2777
+ time: Time,
2778
+ peer: Peer,
2779
+ invRequestManager: InvRequestManager,
2780
+ targetSubscription: Subscription,
2781
+ );
2782
+ public syncBlockchain(): Promise<void>;
2783
+ }
2784
+
2785
+ export class NanoConsensus extends BaseMiniConsensus {
2786
+ public blockchain: NanoChain;
2787
+ public mempool: NanoMempool;
2788
+ constructor(
2789
+ blockchain: NanoChain,
2790
+ mempool: NanoMempool,
2791
+ network: Network,
2792
+ );
2793
+ }
2794
+
2795
+ export class NanoMempool extends Observable {
2796
+ public length: number;
2797
+ constructor(blockchain: IBlockchain);
2798
+ public pushTransaction(transaction: Transaction): Promise<Mempool.ReturnCode>;
2799
+ public getTransaction(hash: Hash): undefined | Transaction;
2800
+ public getTransactions(maxCount?: number): Transaction[];
2801
+ public getPendingTransactions(address: Address): Transaction[];
2802
+ public getTransactionsBySender(address: Address): Transaction[];
2803
+ public getTransactionsByRecipient(address: Address): Transaction[];
2804
+ public getTransactionsByAddresses(addresses: Address[], maxTransactions?: number): Transaction[];
2805
+ public changeHead(block: Block, transactions: Transaction[]): Promise<void>;
2806
+ public removeTransaction(transaction: Transaction): void;
2807
+ public evictExceptAddresses(addresses: Address[]): void;
2808
+ }
2809
+
2810
+ export class PicoChain extends BaseChain {
2811
+ public static ERR_INCONSISTENT: -2;
2812
+ public static ERR_INVALID: -1;
2813
+ public static OK_KNOWN: 0;
2814
+ public static OK_EXTENDED: 1;
2815
+ public static OK_REBRANCHED: 2;
2816
+ public static OK_FORKED: 3;
2817
+ public head: Block;
2818
+ public headHash: Hash;
2819
+ public height: number;
2820
+ constructor(time: Time);
2821
+ public reset(): Promise<void>;
2822
+ public pushBlock(block: Block): Promise<number>;
2823
+ }
2824
+
2825
+ export class PicoConsensusAgent extends BaseMiniConsensusAgent {
2826
+ constructor(consensus: PicoConsensus, peer: Peer, targetSubscription: Subscription);
2827
+ public syncBlockchain(): Promise<void>;
2828
+ }
2829
+
2830
+ export class PicoConsensus extends BaseMiniConsensus {
2831
+ public static MIN_SYNCED_NODES: 3;
2832
+ public blockchain: PicoChain;
2833
+ public mempool: NanoMempool;
2834
+ constructor(blockchain: PicoChain, mempool: NanoMempool, network: Network);
2835
+ }
2836
+
2837
+ export class ConsensusDB /* extends JDB.JungleDB */ {
2838
+ public static VERSION: number;
2839
+ public static INITIAL_DB_SIZE: number;
2840
+ public static MIN_RESIZE: number;
2841
+ public static getFull(dbPrefix?: string): Promise<ConsensusDB>;
2842
+ public static getLight(dbPrefix?: string): Promise<ConsensusDB>;
2843
+ public static restoreTransactions(jdb: ConsensusDB): Promise<void>;
2844
+ constructor(dbPrefix: string, light?: boolean);
2845
+ }
2846
+
2847
+ // Not registered globally
2848
+ // export class UpgradeHelper {
2849
+ // public static recomputeTotals(jdb: ConsensusDB): Promise<void>;
2850
+ // }
2851
+
2852
+ export class Consensus {
2853
+ public static full(netconfig?: NetworkConfig): Promise<FullConsensus>;
2854
+ public static light(netconfig?: NetworkConfig): Promise<LightConsensus>;
2855
+ public static nano(netconfig?: NetworkConfig): Promise<NanoConsensus>;
2856
+ public static pico(netconfig?: NetworkConfig): Promise<PicoConsensus>;
2857
+ public static volatileFull(netconfig?: NetworkConfig): Promise<FullConsensus>;
2858
+ public static volatileLight(netconfig?: NetworkConfig): Promise<LightConsensus>;
2859
+ public static volatileNano(netconfig?: NetworkConfig): Promise<NanoConsensus>;
2860
+ public static volatilePico(netconfig?: NetworkConfig): Promise<PicoConsensus>;
2861
+ }
2862
+
2863
+ export class Protocol {
2864
+ public static DUMB: 0;
2865
+ public static WSS: 1;
2866
+ public static RTC: 2;
2867
+ public static WS: 4;
2868
+ }
2869
+
2870
+ export class Message {
2871
+ public static MAGIC: 0x42042042;
2872
+ public static Type: {
2873
+ VERSION: 0;
2874
+ INV: 1;
2875
+ GET_DATA: 2;
2876
+ GET_HEADER: 3;
2877
+ NOT_FOUND: 4;
2878
+ GET_BLOCKS: 5;
2879
+ BLOCK: 6;
2880
+ HEADER: 7;
2881
+ TX: 8;
2882
+ MEMPOOL: 9;
2883
+ REJECT: 10;
2884
+ SUBSCRIBE: 11;
2885
+
2886
+ ADDR: 20;
2887
+ GET_ADDR: 21;
2888
+ PING: 22;
2889
+ PONG: 23;
2890
+
2891
+ SIGNAL: 30;
2892
+
2893
+ GET_CHAIN_PROOF: 40;
2894
+ CHAIN_PROOF: 41;
2895
+ GET_ACCOUNTS_PROOF: 42;
2896
+ ACCOUNTS_PROOF: 43;
2897
+ GET_ACCOUNTS_TREE_CHUNK: 44;
2898
+ ACCOUNTS_TREE_CHUNK: 45;
2899
+ GET_TRANSACTIONS_PROOF: 47;
2900
+ GET_TRANSACTIONS_PROOF_BY_ADDRESSES: 47;
2901
+ TRANSACTIONS_PROOF: 48;
2902
+ GET_TRANSACTION_RECEIPTS: 49;
2903
+ GET_TRANSACTION_RECEIPTS_BY_ADDRESS: 49;
2904
+ TRANSACTION_RECEIPTS: 50;
2905
+ GET_BLOCK_PROOF: 51;
2906
+ BLOCK_PROOF: 52;
2907
+ GET_TRANSACTIONS_PROOF_BY_HASHES: 53;
2908
+ GET_TRANSACTION_RECEIPTS_BY_HASHES: 54;
2909
+ GET_BLOCK_PROOF_AT: 55;
2910
+
2911
+ GET_HEAD: 60;
2912
+ HEAD: 61;
2913
+
2914
+ VERACK: 90;
2915
+ };
2916
+ public static peekType(buf: SerialBuffer): Message.Type;
2917
+ public static peekLength(buf: SerialBuffer): number;
2918
+ public static unserialize(buf: SerialBuffer): Message;
2919
+ public serializedSize: number;
2920
+ public type: Message.Type;
2921
+ constructor(type: Message.Type);
2922
+ public serialize(buf?: SerialBuffer): SerialBuffer;
2923
+ public toString(): string;
2924
+ }
2925
+
2926
+ export namespace Message {
2927
+ type Type = Type.VERSION | Type.INV | Type.GET_DATA | Type.GET_HEADER | Type.NOT_FOUND | Type.GET_BLOCKS | Type.BLOCK | Type.HEADER | Type.TX | Type.MEMPOOL | Type.REJECT | Type.SUBSCRIBE | Type.ADDR | Type.GET_ADDR | Type.PING | Type.PONG | Type.SIGNAL | Type.GET_CHAIN_PROOF | Type.CHAIN_PROOF | Type.GET_ACCOUNTS_PROOF | Type.ACCOUNTS_PROOF | Type.GET_ACCOUNTS_TREE_CHUNK | Type.ACCOUNTS_TREE_CHUNK | Type.GET_TRANSACTIONS_PROOF | Type.GET_TRANSACTIONS_PROOF_BY_ADDRESSES | Type.TRANSACTIONS_PROOF | Type.GET_TRANSACTION_RECEIPTS | Type.GET_TRANSACTION_RECEIPTS_BY_ADDRESS | Type.TRANSACTION_RECEIPTS | Type.GET_BLOCK_PROOF | Type.BLOCK_PROOF | Type.GET_TRANSACTIONS_PROOF_BY_HASHES | Type.GET_TRANSACTION_RECEIPTS_BY_HASHES | Type.GET_BLOCK_PROOF_AT | Type.GET_HEAD | Type.HEAD | Type.VERACK;
2928
+ namespace Type {
2929
+ type VERSION = 0;
2930
+ type INV = 1;
2931
+ type GET_DATA = 2;
2932
+ type GET_HEADER = 3;
2933
+ type NOT_FOUND = 4;
2934
+ type GET_BLOCKS = 5;
2935
+ type BLOCK = 6;
2936
+ type HEADER = 7;
2937
+ type TX = 8;
2938
+ type MEMPOOL = 9;
2939
+ type REJECT = 10;
2940
+ type SUBSCRIBE = 11;
2941
+
2942
+ type ADDR = 20;
2943
+ type GET_ADDR = 21;
2944
+ type PING = 22;
2945
+ type PONG = 23;
2946
+
2947
+ type SIGNAL = 30;
2948
+
2949
+ type GET_CHAIN_PROOF = 40;
2950
+ type CHAIN_PROOF = 41;
2951
+ type GET_ACCOUNTS_PROOF = 42;
2952
+ type ACCOUNTS_PROOF = 43;
2953
+ type GET_ACCOUNTS_TREE_CHUNK = 44;
2954
+ type ACCOUNTS_TREE_CHUNK = 45;
2955
+ type GET_TRANSACTIONS_PROOF = 47;
2956
+ type GET_TRANSACTIONS_PROOF_BY_ADDRESSES = 47;
2957
+ type TRANSACTIONS_PROOF = 48;
2958
+ type GET_TRANSACTION_RECEIPTS = 49;
2959
+ type GET_TRANSACTION_RECEIPTS_BY_ADDRESS = 49;
2960
+ type TRANSACTION_RECEIPTS = 50;
2961
+ type GET_BLOCK_PROOF = 51;
2962
+ type BLOCK_PROOF = 52;
2963
+ type GET_TRANSACTIONS_PROOF_BY_HASHES = 53;
2964
+ type GET_TRANSACTION_RECEIPTS_BY_HASHES = 54;
2965
+ type GET_BLOCK_PROOF_AT = 55;
2966
+
2967
+ type GET_HEAD = 60;
2968
+ type HEAD = 61;
2969
+
2970
+ type VERACK = 90;
2971
+ }
2972
+ }
2973
+
2974
+ export class AddrMessage extends Message {
2975
+ public static ADDRESSES_MAX_COUNT: 1000;
2976
+ public static unserialize(buf: SerialBuffer): AddrMessage;
2977
+ public addresses: PeerAddress[];
2978
+ constructor(addresses: PeerAddress[]);
2979
+ }
2980
+
2981
+ export class BlockMessage extends Message {
2982
+ public static unserialize(buf: SerialBuffer): BlockMessage;
2983
+ public block: Block;
2984
+ constructor(block: Block);
2985
+ }
2986
+
2987
+ export class RawBlockMessage extends Message {
2988
+ public static unserialize(buf: SerialBuffer): RawBlockMessage;
2989
+ public block: Block;
2990
+ constructor(block: Uint8Array);
2991
+ }
2992
+
2993
+ export class GetAddrMessage extends Message {
2994
+ public static unserialize(buf: SerialBuffer): GetAddrMessage;
2995
+ public protocolMask: number;
2996
+ public serviceMask: number;
2997
+ public maxResults: number;
2998
+ constructor(
2999
+ protocolMask: number,
3000
+ serviceMask: number,
3001
+ maxResults: number,
3002
+ );
3003
+ }
3004
+
3005
+ export class GetBlocksMessage extends Message {
3006
+ public static LOCATORS_MAX_COUNT: 128;
3007
+ public static Direction: {
3008
+ FORWARD: 0x1;
3009
+ BACKWARD: 0x2;
3010
+ };
3011
+ public static unserialize(buf: SerialBuffer): GetBlocksMessage;
3012
+ public locators: Hash[];
3013
+ public direction: GetBlocksMessage.Direction;
3014
+ public maxInvSize: number;
3015
+ constructor(
3016
+ locators: Hash[],
3017
+ maxInvSize?: number,
3018
+ direction?: GetBlocksMessage.Direction,
3019
+ );
3020
+ }
3021
+
3022
+ export namespace GetBlocksMessage {
3023
+ type Direction = Direction.FORWARD | Direction.BACKWARD;
3024
+ namespace Direction {
3025
+ type FORWARD = 0x1;
3026
+ type BACKWARD = 0x2;
3027
+ }
3028
+ }
3029
+
3030
+ export class HeaderMessage extends Message {
3031
+ public static unserialize(buf: SerialBuffer): HeaderMessage;
3032
+ public header: BlockHeader;
3033
+ constructor(header: BlockHeader);
3034
+ }
3035
+
3036
+ export class InvVector {
3037
+ public static Type: {
3038
+ ERROR: 0;
3039
+ TRANSACTION: 1;
3040
+ BLOCK: 2;
3041
+ unserialize(buf: SerialBuffer): InvVector.Type;
3042
+ };
3043
+ public static fromBlock(block: Block): InvVector;
3044
+ public static fromHeader(header: BlockHeader): InvVector;
3045
+ public static fromTransaction(tx: Transaction): InvVector;
3046
+ public static unserialize(buf: SerialBuffer): InvVector;
3047
+ public serializedSize: number;
3048
+ public type: InvVector.Type;
3049
+ public hash: Hash;
3050
+ constructor(type: InvVector.Type, hash: Hash);
3051
+ public serialize(buf?: SerialBuffer): SerialBuffer;
3052
+ public equals(o: any): boolean;
3053
+ public hashCode(): string;
3054
+ public toString(): string;
3055
+ }
3056
+
3057
+ export namespace InvVector {
3058
+ type Type = Type.ERROR | Type.TRANSACTION | Type.BLOCK;
3059
+ namespace Type {
3060
+ type ERROR = 0;
3061
+ type TRANSACTION = 1;
3062
+ type BLOCK = 2;
3063
+ }
3064
+ }
3065
+
3066
+ export class BaseInventoryMessage extends Message {
3067
+ public static VECTORS_MAX_COUNT: 1000;
3068
+ public vectors: InvVector[];
3069
+ constructor(type: Message.Type, vectors: InvVector[]);
3070
+ }
3071
+
3072
+ export class InvMessage extends BaseInventoryMessage {
3073
+ public static unserialize(buf: SerialBuffer): InvMessage;
3074
+ constructor(vectors: InvVector[]);
3075
+ }
3076
+
3077
+ export class GetDataMessage extends BaseInventoryMessage {
3078
+ public static unserialize(buf: SerialBuffer): GetDataMessage;
3079
+ constructor(vectors: InvVector[]);
3080
+ }
3081
+
3082
+ export class GetHeaderMessage extends BaseInventoryMessage {
3083
+ public static unserialize(buf: SerialBuffer): GetHeaderMessage;
3084
+ constructor(vectors: InvVector[]);
3085
+ }
3086
+
3087
+ export class NotFoundMessage extends BaseInventoryMessage {
3088
+ public static unserialize(buf: SerialBuffer): NotFoundMessage;
3089
+ constructor(vectors: InvVector[]);
3090
+ }
3091
+
3092
+ export class MempoolMessage extends Message {
3093
+ public static unserialize(buf: SerialBuffer): MempoolMessage;
3094
+ constructor();
3095
+ }
3096
+
3097
+ export class PingMessage extends Message {
3098
+ public static unserialize(buf: SerialBuffer): PingMessage;
3099
+ public nonce: number;
3100
+ constructor(nonce: number);
3101
+ }
3102
+
3103
+ export class PongMessage extends Message {
3104
+ public static unserialize(buf: SerialBuffer): PongMessage;
3105
+ public nonce: number;
3106
+ constructor(nonce: number);
3107
+ }
3108
+
3109
+ export class RejectMessage extends Message {
3110
+ public static Code: {
3111
+ REJECT_MALFORMED: 0x01;
3112
+ REJECT_INVALID: 0x10;
3113
+ REJECT_OBSOLETE: 0x11;
3114
+ REJECT_DOUBLE: 0x12;
3115
+ REJECT_DUST: 0x41;
3116
+ REJECT_INSUFFICIENT_FEE: 0x42;
3117
+ };
3118
+ public static unserialize(buf: SerialBuffer): RejectMessage;
3119
+ public messageType: Message.Type;
3120
+ public code: RejectMessage.Code;
3121
+ public reason: string;
3122
+ public extraData: Uint8Array;
3123
+ constructor(
3124
+ messageType: Message.Type,
3125
+ code: RejectMessage.Code,
3126
+ reason: string,
3127
+ extraData?: Uint8Array,
3128
+ );
3129
+ }
3130
+
3131
+ export namespace RejectMessage {
3132
+ type Code = Code.REJECT_MALFORMED | Code.REJECT_INVALID | Code.REJECT_OBSOLETE | Code.REJECT_DOUBLE | Code.REJECT_DUST | Code.REJECT_INSUFFICIENT_FEE;
3133
+ namespace Code {
3134
+ type REJECT_MALFORMED = 0x01;
3135
+ type REJECT_INVALID = 0x10;
3136
+ type REJECT_OBSOLETE = 0x11;
3137
+ type REJECT_DOUBLE = 0x12;
3138
+ type REJECT_DUST = 0x41;
3139
+ type REJECT_INSUFFICIENT_FEE = 0x42;
3140
+ }
3141
+ }
3142
+
3143
+ export class SignalMessage extends Message {
3144
+ public static Flag: {
3145
+ UNROUTABLE: 0x1;
3146
+ TTL_EXCEEDED: 0x2;
3147
+ };
3148
+ public static unserialize(buf: SerialBuffer): SignalMessage;
3149
+ public senderId: PeerId;
3150
+ public recipientId: PeerId;
3151
+ public nonce: number;
3152
+ public ttl: number;
3153
+ public flags: SignalMessage.Flag | number;
3154
+ public payload: Uint8Array;
3155
+ public signature: Signature;
3156
+ public senderPubKey: PublicKey;
3157
+ constructor(
3158
+ senderId: PeerId,
3159
+ recipientId: PeerId,
3160
+ nonce: number,
3161
+ ttl: number,
3162
+ flags?: SignalMessage.Flag | number,
3163
+ payload?: Uint8Array,
3164
+ senderPubKey?: PublicKey,
3165
+ signature?: Signature,
3166
+ );
3167
+ public verifySignature(): boolean;
3168
+ public hasPayload(): boolean;
3169
+ public isUnroutable(): boolean;
3170
+ public isTtlExceeded(): boolean;
3171
+ }
3172
+
3173
+ export namespace SignalMessage {
3174
+ type Flag = Flag.UNROUTABLE | Flag.TTL_EXCEEDED;
3175
+ namespace Flag {
3176
+ type UNROUTABLE = 0x1;
3177
+ type TTL_EXCEEDED = 0x2;
3178
+ }
3179
+ }
3180
+
3181
+ export class SubscribeMessage extends Message {
3182
+ public static unserialize(buf: SerialBuffer): SubscribeMessage;
3183
+ public subscription: Subscription;
3184
+ constructor(subscription: Subscription);
3185
+ }
3186
+
3187
+ export class TxMessage extends Message {
3188
+ public static unserialize(buf: SerialBuffer): TxMessage;
3189
+ public transaction: Transaction;
3190
+ public hasAccountsProof: boolean;
3191
+ public accountsProof: AccountsProof;
3192
+ constructor(transaction: Transaction, accountsProof?: AccountsProof);
3193
+ }
3194
+
3195
+ export class VersionMessage extends Message {
3196
+ public static CHALLENGE_SIZE: 32;
3197
+ public static unserialize(buf: SerialBuffer): VersionMessage;
3198
+ public version: number;
3199
+ public peerAddress: PeerAddress;
3200
+ public genesisHash: Hash;
3201
+ public headHadh: Hash;
3202
+ public challengeNonce: Uint8Array;
3203
+ public userAgent?: string;
3204
+ constructor(
3205
+ version: number,
3206
+ peerAddress: PeerAddress,
3207
+ genesisHash: Hash,
3208
+ headHash: Hash,
3209
+ challengeNonce: Uint8Array,
3210
+ userAgent?: string,
3211
+ );
3212
+ }
3213
+
3214
+ export class VerAckMessage extends Message {
3215
+ public static unserialize(buf: SerialBuffer): VerAckMessage;
3216
+ public publicKey: PublicKey;
3217
+ public signature: Signature;
3218
+ constructor(publicKey: PublicKey, signature: Signature);
3219
+ }
3220
+
3221
+ export class AccountsProofMessage extends Message {
3222
+ public static unserialize(buf: SerialBuffer): AccountsProofMessage;
3223
+ public blockHash: Hash;
3224
+ public proof: AccountsProof;
3225
+ constructor(blockHash: Hash, accountsProof?: AccountsProof);
3226
+ public hasProof(): boolean;
3227
+ }
3228
+
3229
+ export class GetAccountsProofMessage extends Message {
3230
+ public static ADDRESSES_MAX_COUNT: 256;
3231
+ public static unserialize(buf: SerialBuffer): GetAccountsProofMessage;
3232
+ public addresses: Address[];
3233
+ public blockHash: Hash;
3234
+ constructor(blockHash: Hash, addresses: Address[]);
3235
+ }
3236
+
3237
+ export class ChainProofMessage extends Message {
3238
+ public static unserialize(buf: SerialBuffer): ChainProofMessage;
3239
+ public proof: ChainProof;
3240
+ constructor(proof: ChainProof);
3241
+ }
3242
+
3243
+ export class GetChainProofMessage extends Message {
3244
+ public static unserialize(buf: SerialBuffer): GetChainProofMessage;
3245
+ constructor();
3246
+ }
3247
+
3248
+ export class AccountsTreeChunkMessage extends Message {
3249
+ public static unserialize(buf: SerialBuffer): AccountsTreeChunkMessage;
3250
+ public blockHash: Hash;
3251
+ public chunk: AccountsTreeChunk;
3252
+ constructor(blockHash: Hash, accountsTreeChunk?: AccountsTreeChunk);
3253
+ public hasChunk(): boolean;
3254
+ }
3255
+
3256
+ export class GetAccountsTreeChunkMessage extends Message {
3257
+ public static unserialize(buf: SerialBuffer): GetAccountsTreeChunkMessage;
3258
+ public blockHash: Hash;
3259
+ public startPrefix: string;
3260
+ constructor(blockHash: Hash, startPrefix: string);
3261
+ }
3262
+
3263
+ export class TransactionsProofMessage extends Message {
3264
+ public static unserialize(buf: SerialBuffer): TransactionsProofMessage;
3265
+ public blockHash: Hash;
3266
+ public proof: TransactionsProof;
3267
+ constructor(blockHash: Hash, proof?: TransactionsProof);
3268
+ public hasProof(): boolean;
3269
+ }
3270
+
3271
+ export class GetTransactionsProofByAddressMessage extends Message {
3272
+ public static ADDRESSES_MAX_COUNT: 256;
3273
+ public static unserialize(buf: SerialBuffer): GetTransactionsProofByAddressMessage;
3274
+ public addresses: Address[];
3275
+ public blockHash: Hash;
3276
+ constructor(blockHash: Hash, addresses: Address[]);
3277
+ }
3278
+
3279
+ export class GetTransactionReceiptsByAddressMessage extends Message {
3280
+ public static unserialize(buf: SerialBuffer): GetTransactionReceiptsByAddressMessage;
3281
+ public address: Address;
3282
+ public offset: number;
3283
+ constructor(address: Address, offset?: number);
3284
+ }
3285
+
3286
+ export class TransactionReceiptsMessage extends Message {
3287
+ public static RECEIPTS_MAX_COUNT: 500;
3288
+ public static unserialize(buf: SerialBuffer): TransactionReceiptsMessage;
3289
+ public receipts: TransactionReceipt[];
3290
+ constructor(receipts?: TransactionReceipt[]);
3291
+ public hasReceipts(): boolean;
3292
+ }
3293
+
3294
+ export class GetBlockProofMessage extends Message {
3295
+ public static unserialize(buf: SerialBuffer): GetBlockProofMessage;
3296
+ public blockHashToProve: Hash;
3297
+ public knownBlockHash: Hash;
3298
+ constructor(blockHashToProve: Hash, knownBlockHash: Hash);
3299
+ }
3300
+
3301
+ export class BlockProofMessage extends Message {
3302
+ public static unserialize(buf: SerialBuffer): BlockProofMessage;
3303
+ public proof: BlockChain;
3304
+ constructor(proof?: BlockChain);
3305
+ public hasProof(): boolean;
3306
+ }
3307
+
3308
+ export class GetHeadMessage extends Message {
3309
+ public static unserialize(buf: SerialBuffer): GetHeadMessage;
3310
+ constructor();
3311
+ }
3312
+
3313
+ export class HeadMessage extends Message {
3314
+ public static unserialize(buf: SerialBuffer): HeadMessage;
3315
+ public header: BlockHeader;
3316
+ constructor(header: BlockHeader);
3317
+ }
3318
+
3319
+ export class GetBlockProofAtMessage extends Message {} // TODO
3320
+
3321
+ export class GetTransactionReceiptsByHashesMessage extends Message {} // TODO
3322
+
3323
+ export class GetTransactionsProofByAddressesMessage extends Message {} // TODO
3324
+
3325
+ export class GetTransactionsProofByHashesMessage extends Message {} // TODO
3326
+
3327
+ export class MessageFactory {
3328
+ public static CLASSES: { [messageType: number]: Message };
3329
+ public static peekType(buf: SerialBuffer): Message.Type;
3330
+ public static parse(buf: SerialBuffer): Message;
3331
+ }
3332
+
3333
+ export class WebRtcConnector extends Observable {
3334
+ public static CONNECT_TIMEOUT: 8000;
3335
+ public static CONNECTORS_MAX: 6;
3336
+ public static INBOUND_CONNECTORS_MAX: 3;
3337
+ constructor(networkConfig: NetworkConfig);
3338
+ public connect(peerAddress: PeerAddress, signalChannel: PeerChannel): boolean;
3339
+ public isValidSignal(msg: { senderId: any, nonce: any }): boolean;
3340
+ public onSignal(channel: PeerChannel, msg: SignalMessage): void;
3341
+ }
3342
+
3343
+ export class PeerConnector extends Observable {
3344
+ public static ICE_GATHERING_TIMEOUT: 1000;
3345
+ public static CONNECTION_OPEN_DELAY: 200;
3346
+ public nonce: any;
3347
+ public peerAddress: PeerAddress;
3348
+ public rtcConnection: RTCPeerConnection;
3349
+ constructor(
3350
+ networkConfig: NetworkConfig,
3351
+ signalChannel: PeerChannel,
3352
+ peerId: PeerId,
3353
+ peerAddress: PeerAddress,
3354
+ );
3355
+ public onSignal(signal: any): void;
3356
+ public close(): void;
3357
+ }
3358
+
3359
+ export class OutboundPeerConnector extends PeerConnector {
3360
+ constructor(
3361
+ webRtcConfig: NetworkConfig,
3362
+ peerAddress: PeerAddress,
3363
+ signalChannel: PeerChannel,
3364
+ );
3365
+ public close(): void;
3366
+ }
3367
+
3368
+ export class InboundPeerConnector extends PeerConnector {
3369
+ constructor(webRtcConfig: NetworkConfig, signalChannel: PeerChannel, peerId: PeerId, offer: any);
3370
+ }
3371
+
3372
+ export class WebRtcDataChannel extends DataChannel {
3373
+ public readyState: DataChannel.ReadyState;
3374
+ constructor(nativeChannel: any);
3375
+ public sendChunk(msg: any): void;
3376
+ }
3377
+
3378
+ export class WebRtcUtils {
3379
+ public static candidateToNetAddress(candidate: RTCIceCandidate): NetAddress;
3380
+ }
3381
+
3382
+ export class WebSocketConnector extends Observable {
3383
+ public static CONNECT_TIMEOUT: 5000;
3384
+ constructor(
3385
+ protocol: number,
3386
+ protocolPrefix: string,
3387
+ networkConfig: NetworkConfig,
3388
+ );
3389
+ public connect(peerAddress: PeerAddress): boolean;
3390
+ public abort(peerAddress: PeerAddress): void;
3391
+ }
3392
+
3393
+ export class WebSocketDataChannel extends DataChannel {
3394
+ public readyState: DataChannel.ReadyState;
3395
+ constructor(ws: WebSocket);
3396
+ public sendChunk(msg: any): void;
3397
+ }
3398
+
3399
+ export class NetAddress {
3400
+ public static UNSPECIFIED: NetAddress;
3401
+ public static UNKNOWN: NetAddress;
3402
+ public static Type: {
3403
+ IPv4: 0;
3404
+ IPv6: 1;
3405
+ UNSPECIFIED: 2;
3406
+ UNKNOWN: 3;
3407
+ };
3408
+ public static fromIP(ip: string, reliable?: boolean): NetAddress;
3409
+ public static unserialize(buf: SerialBuffer): NetAddress;
3410
+ public serializedSize: number;
3411
+ public ip: Uint8Array;
3412
+ public type: NetAddress.Type;
3413
+ public reliable: boolean;
3414
+ constructor(type: NetAddress.Type, ipArray?: Uint8Array, reliable?: boolean);
3415
+ public serialize(buf?: SerialBuffer): SerialBuffer;
3416
+ public equals(o: any): boolean;
3417
+ public hashCode(): string;
3418
+ public toString(): string;
3419
+ public isPseudo(): boolean;
3420
+ public isPrivate(): boolean;
3421
+ public isIPv6(): boolean;
3422
+ public isIPv4(): boolean;
3423
+ public subnet(bitCount: number): NetAddress;
3424
+ }
3425
+
3426
+ export namespace NetAddress {
3427
+ type Type = Type.IPv4 | Type.IPv6 | Type.UNSPECIFIED | Type.UNKNOWN;
3428
+ namespace Type {
3429
+ type IPv4 = 0;
3430
+ type IPv6 = 1;
3431
+ type UNSPECIFIED = 2;
3432
+ type UNKNOWN = 3;
3433
+ }
3434
+ }
3435
+
3436
+ export class PeerId extends Serializable {
3437
+ public static SERIALIZED_SIZE: 16;
3438
+ public static copy(o: PeerId): PeerId;
3439
+ public static unserialize(buf: SerialBuffer): PeerId;
3440
+ public static fromBase64(base64: string): PeerId;
3441
+ public static fromHex(hex: string): PeerId;
3442
+ public serializedSize: number;
3443
+ constructor(arg: Uint8Array);
3444
+ public serialize(buf?: SerialBuffer): SerialBuffer;
3445
+ public subarray(begin?: number, end?: number): Uint8Array;
3446
+ public equals(o: any): boolean;
3447
+ public toString(): string;
3448
+ }
3449
+
3450
+ export class PeerAddress {
3451
+ public static unserialize(buf: SerialBuffer): PeerAddress;
3452
+ public serializedSize: number;
3453
+ public serializedContentSize: number;
3454
+ public protocol: number;
3455
+ public services: number;
3456
+ public timestamp: number;
3457
+ public netAddress: NetAddress | null;
3458
+ public publicKey: PublicKey;
3459
+ public peerId: PeerId;
3460
+ public distance: number;
3461
+ public signature: Signature;
3462
+ constructor(
3463
+ protocol: number,
3464
+ services: number,
3465
+ timestamp: number,
3466
+ netAddress: NetAddress,
3467
+ publicKey: PublicKey,
3468
+ distance: number,
3469
+ signature?: Signature,
3470
+ );
3471
+ public serialize(buf?: SerialBuffer): SerialBuffer;
3472
+ public serializeContent(buf?: SerialBuffer): SerialBuffer;
3473
+ public equals(o: any): boolean;
3474
+ public hashCode(): string;
3475
+ public verifySignature(): boolean;
3476
+ public isSeed(): boolean;
3477
+ public exceedsAge(): boolean;
3478
+ }
3479
+
3480
+ export class WsBasePeerAddress extends PeerAddress {
3481
+ public static fromSeedString(str: string): WsPeerAddress | WssPeerAddress;
3482
+ public host: string;
3483
+ public port: number;
3484
+ public protocolPrefix: string;
3485
+ constructor(
3486
+ protocol: number,
3487
+ services: number,
3488
+ timestamp: number,
3489
+ netAddress: NetAddress,
3490
+ publicKey: PublicKey,
3491
+ distance: number,
3492
+ host: string,
3493
+ port: number,
3494
+ signature?: Signature,
3495
+ );
3496
+ public toSeedString(): string;
3497
+ public globallyReachable(): boolean;
3498
+ public hashCode(): string;
3499
+ public toString(): string;
3500
+ }
3501
+
3502
+ export class WssPeerAddress extends WsBasePeerAddress {
3503
+ public static seed(host: string, port: number, publicKeyHex?: string): WssPeerAddress;
3504
+ public static unserialize(buf: SerialBuffer): WssPeerAddress;
3505
+ constructor(
3506
+ services: number,
3507
+ timestamp: number,
3508
+ netAddress: NetAddress,
3509
+ publicKey: PublicKey,
3510
+ distance: number,
3511
+ host: string,
3512
+ port: number,
3513
+ signature?: Signature,
3514
+ );
3515
+ public withoutId(): WssPeerAddress;
3516
+ }
3517
+
3518
+ export class WsPeerAddress extends WsBasePeerAddress {
3519
+ public static seed(host: string, port: number, publicKeyHex?: string): WsPeerAddress;
3520
+ public static unserialize(buf: SerialBuffer): WsPeerAddress;
3521
+ constructor(
3522
+ services: number,
3523
+ timestamp: number,
3524
+ netAddress: NetAddress,
3525
+ publicKey: PublicKey,
3526
+ distance: number,
3527
+ host: string,
3528
+ port: number,
3529
+ signature?: Signature,
3530
+ );
3531
+ public globallyReachable(): boolean;
3532
+ public withoutId(): WsPeerAddress;
3533
+ }
3534
+
3535
+ export class RtcPeerAddress extends PeerAddress {
3536
+ public static unserialize(buf: SerialBuffer): RtcPeerAddress;
3537
+ constructor(
3538
+ services: number,
3539
+ timestamp: number,
3540
+ netAddress: NetAddress,
3541
+ publicKey: PublicKey,
3542
+ distance: number,
3543
+ signature?: Signature,
3544
+ );
3545
+ public hashCode(): string;
3546
+ public toString(): string;
3547
+ }
3548
+
3549
+ export class DumbPeerAddress extends PeerAddress {
3550
+ public static unserialize(buf: SerialBuffer): DumbPeerAddress;
3551
+ constructor(
3552
+ services: number,
3553
+ timestamp: number,
3554
+ netAddress: NetAddress,
3555
+ publicKey: PublicKey,
3556
+ distance: number,
3557
+ signature?: Signature,
3558
+ );
3559
+ public hashCode(): string;
3560
+ public toString(): string;
3561
+ }
3562
+
3563
+ export class PeerAddressState {
3564
+ public static NEW: 1;
3565
+ public static ESTABLISHED: 2;
3566
+ public static TRIED: 3;
3567
+ public static FAILED: 4;
3568
+ public static BANNED: 5;
3569
+ public signalRouter: SignalRouter;
3570
+ public maxFailedAttempts: number;
3571
+ public failedAttempts: number;
3572
+ constructor(peerAddress: PeerAddress);
3573
+ public close(type: number): void;
3574
+ public equals(o: any): boolean;
3575
+ public hashCode(): string;
3576
+ public toString(): string;
3577
+ }
3578
+
3579
+ export class SignalRouter {
3580
+ constructor(peerAddress: PeerAddress);
3581
+ public bestRoute(): SignalRoute;
3582
+ public addRoute(signalChannel: PeerChannel, distance: number, timestamp: number): boolean;
3583
+ public deleteBestRoute(): void;
3584
+ public deleteRoute(signalChannel: PeerChannel): void;
3585
+ public deleteAllRoutes(): void;
3586
+ public hasRoute(): boolean;
3587
+ public equals(o: any): boolean;
3588
+ public hashCode(): string;
3589
+ public toString(): string;
3590
+ }
3591
+
3592
+ export class SignalRoute {
3593
+ public signalChannel: PeerChannel;
3594
+ public distance: number;
3595
+ public score: number;
3596
+ constructor(
3597
+ signalChannel: PeerChannel,
3598
+ distance: number,
3599
+ timestamp: number,
3600
+ );
3601
+ public equals(o: any): boolean;
3602
+ public hashCode(): string;
3603
+ public toString(): string;
3604
+ }
3605
+
3606
+ export class SeedList {
3607
+ public static MAX_SIZE: number;
3608
+ public static REQUEST_TIMEOUT: number;
3609
+ public static retrieve(url: string, publicKey?: PublicKey): Promise<SeedList>;
3610
+ public static parse(listStr: string, publicKey?: PublicKey): SeedList;
3611
+ public seeds: PeerAddress[];
3612
+ public publicKey: PublicKey;
3613
+ public signature: Signature;
3614
+ constructor(
3615
+ seeds: PeerAddress[],
3616
+ publicKey?: PublicKey,
3617
+ signature?: Signature,
3618
+ );
3619
+ public serializeContent(): Uint8Array;
3620
+ }
3621
+
3622
+ export class SeedListUrl {
3623
+ public url: string;
3624
+ public publicKey: PublicKey;
3625
+ constructor(url: string, publicKeyHex?: string);
3626
+ }
3627
+
3628
+ export class PeerAddressSeeder extends Observable {
3629
+ public collect(): Promise<void>;
3630
+ }
3631
+
3632
+ export class PeerAddressBook extends Observable {
3633
+ public static MAX_AGE_WEBSOCKET: number;
3634
+ public static MAX_AGE_WEBRTC: number;
3635
+ public static MAX_AGE_DUMB: number;
3636
+ public static MAX_DISTANCE: number;
3637
+ public static MAX_FAILED_ATTEMPTS_WS: number;
3638
+ public static MAX_FAILED_ATTEMPTS_RTC: number;
3639
+ public static MAX_TIMESTAMP_DRIFT: number;
3640
+ public static HOUSEKEEPING_INTERVAL: number;
3641
+ public static DEFAULT_BAN_TIME: number;
3642
+ public static INITIAL_FAILED_BACKOFF: number;
3643
+ public static MAX_FAILED_BACKOFF: number;
3644
+ public static MAX_SIZE_WS: number;
3645
+ public static MAX_SIZE_WSS: number;
3646
+ public static MAX_SIZE_RTC: number;
3647
+ public static MAX_SIZE: number;
3648
+ public static MAX_SIZE_PER_IP: number;
3649
+ public static SEEDING_TIMEOUT: number;
3650
+ public knownAddressesCount: number;
3651
+ public knownWsAddressesCount: number;
3652
+ public knownWssAddressesCount: number;
3653
+ public knownRtcAddressesCount: number;
3654
+ public seeded: boolean;
3655
+ constructor(netconfig: NetworkConfig);
3656
+ public iterator(): Iterator<PeerAddressState>;
3657
+ public wsIterator(): Iterator<PeerAddressState>;
3658
+ public wssIterator(): Iterator<PeerAddressState>;
3659
+ public rtcIterator(): Iterator<PeerAddressState>;
3660
+ public getState(peerAddress: PeerAddress): undefined | PeerAddressState;
3661
+ public get(peerAddress: PeerAddress): null | PeerAddress;
3662
+ public getByPeerId(peerId: PeerId): null | PeerAddress;
3663
+ public getChannelByPeerId(peedId: PeerId): null | PeerChannel;
3664
+ public query(protocolMask: number, serviceMask: number, maxAddresses: number): PeerAddress[];
3665
+ public add(channel: PeerChannel, arg: PeerAddress | PeerAddress[]): void;
3666
+ public established(channel: PeerChannel, peerAddress: PeerAddress | RtcPeerAddress): void;
3667
+ public close(channel: PeerChannel, peerAddress: PeerAddress, type?: number): void;
3668
+ public unroutable(channel: PeerChannel, peerAddress: PeerAddress): void;
3669
+ public isBanned(peerAddress: PeerAddress): boolean;
3670
+ }
3671
+
3672
+ export class GenesisConfig {
3673
+ public static NETWORK_ID: number;
3674
+ public static NETWORK_NAME: string;
3675
+ public static GENESIS_BLOCK: Block;
3676
+ public static GENESIS_HASH: Hash;
3677
+ public static GENESIS_ACCOUNTS: string;
3678
+ public static SEED_PEERS: PeerAddress[];
3679
+ public static SEED_LISTS: SeedList[];
3680
+ public static CONFIGS: { [key: string]: { NETWORK_ID: number, NETWORK_NAME: string, SEED_PEERS: PeerAddress[], SEED_LISTS: SeedListUrl, GENESIS_BLOCK: Block, GENESIS_ACCOUNTS: string } };
3681
+ public static main(): void;
3682
+ public static test(): void;
3683
+ public static dev(): void;
3684
+ public static init(config: { NETWORK_ID: number, NETWORK_NAME: string, GENESIS_BLOCK: Block, GENESIS_ACCOUNTS: string, SEED_PEERS: PeerAddress[] }): void;
3685
+ public static networkIdToNetworkName(networkId: number): string;
3686
+ public static networkIdFromAny(networkId: number | string): number;
3687
+ }
3688
+
3689
+ export class CloseType {
3690
+ // Regular Close Types
3691
+
3692
+ public static GET_BLOCKS_TIMEOUT: 1;
3693
+ public static GET_HEADER_TIMEOUT: 2;
3694
+ public static GET_CHAIN_PROOF_TIMEOUT: 3;
3695
+ public static GET_ACCOUNTS_PROOF_TIMEOUT: 4;
3696
+ public static GET_ACCOUNTS_TREE_CHUNK_TIMEOUT: 5;
3697
+ public static GET_TRANSACTIONS_PROOF_TIMEOUT: 6;
3698
+ public static GET_TRANSACTION_RECEIPTS_TIMEOUT: 7;
3699
+
3700
+ public static SENDING_PING_MESSAGE_FAILED: 10;
3701
+ public static SENDING_OF_VERSION_MESSAGE_FAILED: 11;
3702
+
3703
+ public static SIMULTANEOUS_CONNECTION: 20;
3704
+ public static DUPLICATE_CONNECTION: 21;
3705
+ public static INVALID_CONNECTION_STATE: 22;
3706
+
3707
+ public static PEER_BANNED: 30;
3708
+ public static IP_BANNED: 31;
3709
+
3710
+ public static MAX_PEER_COUNT_REACHED: 40;
3711
+ public static PEER_CONNECTION_RECYCLED: 41;
3712
+ public static PEER_CONNECTION_RECYCLED_INBOUND_EXCHANGE: 42;
3713
+ public static INBOUND_CONNECTIONS_BLOCKED: 43;
3714
+
3715
+ public static MANUAL_NETWORK_DISCONNECT: 50;
3716
+ public static MANUAL_WEBSOCKET_DISCONNECT: 51;
3717
+ public static MANUAL_PEER_DISCONNECT: 52;
3718
+
3719
+ // Ban Close Types
3720
+
3721
+ public static INCOMPATIBLE_VERSION: 100;
3722
+ public static DIFFERENT_GENESIS_BLOCK: 101;
3723
+ public static INVALID_PEER_ADDRESS_IN_VERSION_MESSAGE: 102;
3724
+ public static UNEXPECTED_PEER_ADDRESS_IN_VERSION_MESSAGE: 103;
3725
+ public static INVALID_PUBLIC_KEY_IN_VERACK_MESSAGE: 104;
3726
+ public static INVALID_SIGNATURE_IN_VERACK_MESSAGE: 105;
3727
+
3728
+ public static ADDR_MESSAGE_TOO_LARGE: 110;
3729
+ public static ADDR_NOT_GLOBALLY_REACHABLE: 111;
3730
+ public static INVALID_ADDR: 112;
3731
+ public static INVALID_SIGNAL_TTL: 113;
3732
+
3733
+ public static INVALID_BLOCK: 120;
3734
+ public static INVALID_HEADER: 121;
3735
+ public static INVALID_ACCOUNTS_TREE_CHUNCK: 122;
3736
+ public static INVALID_ACCOUNTS_PROOF: 123;
3737
+ public static INVALID_CHAIN_PROOF: 124;
3738
+ public static INVALID_TRANSACTION_PROOF: 125;
3739
+ public static INVALID_BLOCK_PROOF: 126;
3740
+
3741
+ public static RATE_LIMIT_EXCEEDED: 130;
3742
+
3743
+ public static BLOCKCHAIN_SYNC_FAILED: 140;
3744
+
3745
+ public static MANUAL_PEER_BAN: 150;
3746
+
3747
+ // Fail Close Types
3748
+
3749
+ public static CONNECTION_FAILED: 200;
3750
+ public static CLOSED_BY_REMOTE: 201;
3751
+ public static NETWORK_ERROR: 202;
3752
+ public static CHANNEL_CLOSING: 203;
3753
+
3754
+ public static VERSION_TIMEOUT: 210;
3755
+ public static VERACK_TIMEOUT: 211;
3756
+ public static PING_TIMEOUT: 212;
3757
+
3758
+ public static CONNECTION_LIMIT_PER_IP: 220;
3759
+ public static CONNECTION_LIMIT_DUMB: 221;
3760
+
3761
+ public static FAILED_TO_PARSE_MESSAGE_TYPE: 230;
3762
+ public static UNEXPECTED_ACCOUNTS_TREE_CHUNK: 231;
3763
+ public static UNEXPECTED_HEADER: 232;
3764
+ public static TRANSACTION_NOT_MATCHING_SUBSCRIPTION: 233;
3765
+
3766
+ public static ABORTED_SYNC: 240;
3767
+
3768
+ public static MANUAL_PEER_FAIL: 250;
3769
+
3770
+ public static isBanningType(closeType: number): boolean;
3771
+ public static isFailingType(closeType: number): boolean;
3772
+ }
3773
+
3774
+ export class NetworkConnection extends Observable {
3775
+ public id: number;
3776
+ public protocol: number;
3777
+ public peerAddress: PeerAddress;
3778
+ public netAddress: NetAddress;
3779
+ public bytesSent: number;
3780
+ public bytesReceived: number;
3781
+ public inbound: boolean;
3782
+ public outbound: boolean;
3783
+ public closed: boolean;
3784
+ public lastMessageReceivedAt: number;
3785
+ constructor(
3786
+ channel: DataChannel,
3787
+ protocol: number,
3788
+ netAddress: NetAddress,
3789
+ peerAddress: PeerAddress,
3790
+ );
3791
+ public send(msg: Uint8Array): boolean;
3792
+ public expectMessage(types: Message.Type | Message.Type[], timeoutCallback: () => any, msgTimeout?: number, chunkTimeout?: number): void;
3793
+ public isExpectingMessage(type: Message.Type): boolean;
3794
+ public confirmExpectedMessage(type: Message.Type, success: boolean): void;
3795
+ public close(type?: number, reason?: string): void;
3796
+ public equals(o: any): boolean;
3797
+ public hashCode(): string;
3798
+ public toString(): string;
3799
+ }
3800
+
3801
+ export class PeerChannel extends Observable {
3802
+ public connection: NetworkConnection;
3803
+ public id: number;
3804
+ public protocol: number;
3805
+ public peerAddress: PeerAddress;
3806
+ public netAddress: NetAddress;
3807
+ public closed: boolean;
3808
+ public lastMessageReceivedAt: number;
3809
+ public Event: { [messageType: number]: string };
3810
+ constructor(connection: NetworkConnection);
3811
+ public expectMessage(types: Message.Type | Message.Type[], timeoutCallback: () => any, msgTimeout?: number, chunkTimeout?: number): void;
3812
+ public isExpectingMessage(type: Message.Type): boolean;
3813
+ public close(type?: number, reason?: string): void;
3814
+ public version(peerAddress: PeerAddress, headHash: Hash, challengeNonce: Uint8Array, appAgent?: string): boolean;
3815
+ public verack(publicKey: PublicKey, signature: Signature): boolean;
3816
+ public inv(vectors: InvVector[]): boolean;
3817
+ public notFound(vectors: InvVector[]): boolean;
3818
+ public getData(vectors: InvVector[]): boolean;
3819
+ public getHeader(vectors: InvVector[]): boolean;
3820
+ public block(block: Block): boolean;
3821
+ public rawBlock(block: Uint8Array): boolean;
3822
+ public header(header: BlockHeader): boolean;
3823
+ public tx(transaction: Transaction, accountsProof?: AccountsProof): boolean;
3824
+ public getBlocks(locators: Hash[], maxInvSize: number, ascending?: boolean): boolean;
3825
+ public mempool(): boolean;
3826
+ public reject(messageType: Message.Type, code: RejectMessage.Code, reason: string, extraData?: Uint8Array): boolean;
3827
+ public subscribe(subscription: Subscription): boolean;
3828
+ public addr(addresses: PeerAddress[]): boolean;
3829
+ public getAddr(protocolMask: number, serviceMask: number, maxResults: number): boolean;
3830
+ public ping(nonce: number): boolean;
3831
+ public pong(nonce: number): boolean;
3832
+ public signal(senderId: PeerId, recipientId: PeerId, nonce: number, ttl: number, flags: SignalMessage.Flag | number, payload?: Uint8Array, senderPubKey?: PublicKey, signature?: Signature): boolean;
3833
+ public getAccountsProof(blockHash: Hash, addresses: Address[]): boolean;
3834
+ public accountsProof(blockHash: Hash, proof?: AccountsProof): boolean;
3835
+ public getChainProof(): boolean;
3836
+ public chainProof(proof: ChainProof): boolean;
3837
+ public getAccountsTreeChunk(blockHash: Hash, startPrefix: string): boolean;
3838
+ public accountsTreeChunk(blockHash: Hash, chunk?: AccountsTreeChunk): boolean;
3839
+ public getTransactionsProof(blockHash: Hash, addresses: Address[]): boolean;
3840
+ public getTransactionsProofByAddresses(blockHash: Hash, addresses: Address[]): boolean;
3841
+ public getTransactionsProofByHashes(blockHash: Hash, hashes: Hash[]): boolean;
3842
+ public transactionsProof(blockHash: Hash, proof?: TransactionsProof): boolean;
3843
+ public getTransactionReceipts(address: Address): boolean;
3844
+ public getTransactionReceiptsByAddress(address: Address): boolean;
3845
+ public getTransactionReceiptsByHashes(hashes: Hash[]): boolean;
3846
+ public transactionReceipts(transactionReceipts?: TransactionReceipt[]): boolean;
3847
+ public getBlockProof(blockHashToProve: Hash, knownBlockHash: Hash): boolean;
3848
+ public getBlockProofAt(blockHeightToProve: number, knownBlockHash: Hash): boolean;
3849
+ public blockProof(proof?: BlockChain): boolean;
3850
+ public getHead(): boolean;
3851
+ public head(header: BlockHeader): boolean;
3852
+ public equals(o: any): boolean;
3853
+ public hashCode(): string;
3854
+ public toString(): string;
3855
+ }
3856
+
3857
+ export class NetworkAgent {
3858
+ public static HANDSHAKE_TIMEOUT: 4000; // 4 seconds
3859
+ public static PING_TIMEOUT: 10000; // 10 seconds
3860
+ public static CONNECTIVITY_CHECK_INTERVAL: 60000; // 1 minute
3861
+ public static ANNOUNCE_ADDR_INTERVAL: 600000; // 10 minutes
3862
+ public static VERSION_ATTEMPTS_MAX: 10;
3863
+ public static VERSION_RETRY_DELAY: 500; // 500 ms
3864
+ public static GETADDR_RATE_LIMIT: 3; // per minute
3865
+ public static MAX_ADDR_PER_MESSAGE: 1000;
3866
+ public static MAX_ADDR_PER_REQUEST: 500;
3867
+ public static NUM_ADDR_PER_REQUEST: 200;
3868
+ public channel: PeerChannel;
3869
+ public peer: Peer;
3870
+ constructor(
3871
+ blockchain: IBlockchain,
3872
+ addresses: PeerAddressBook,
3873
+ networkConfig: NetworkConfig,
3874
+ channel: PeerChannel,
3875
+ );
3876
+ public handshake(): void;
3877
+ public requestAddresses(maxResults?: number): void;
3878
+ }
3879
+
3880
+ export class PeerConnectionStatistics {
3881
+ public latencyMedian: number;
3882
+ constructor();
3883
+ public reset(): void;
3884
+ public addLatency(latency: number): void;
3885
+ public addMessage(msg: Message): void;
3886
+ public getMessageCount(msgType: number): number;
3887
+ }
3888
+
3889
+ export class PeerConnection {
3890
+ public static getOutbound(peerAddress: PeerAddress): PeerConnection;
3891
+ public static getInbound(networkConnection: NetworkConnection): PeerConnection;
3892
+ public id: number;
3893
+ public state: number;
3894
+ public peerAddress: PeerAddress;
3895
+ public networkConnection: NetworkConnection;
3896
+ public peerChannel: PeerChannel;
3897
+ public networkAgent: NetworkAgent;
3898
+ public peer: Peer;
3899
+ public score: number;
3900
+ public establishedSince: number;
3901
+ public ageEstablished: number;
3902
+ public statistics: PeerConnectionStatistics;
3903
+ constructor();
3904
+ public negotiating(): void;
3905
+ public close(): void;
3906
+ }
3907
+
3908
+ export class PeerConnectionState {
3909
+ public static NEW: 1;
3910
+ public static CONNECTING: 2;
3911
+ public static CONNECTED: 3;
3912
+ public static NEGOTIATING: 4;
3913
+ public static ESTABLISHED: 5;
3914
+ public static CLOSED: 6;
3915
+ }
3916
+
3917
+ export class SignalProcessor {
3918
+ constructor(
3919
+ peerAddress: PeerAddressBook,
3920
+ networkConfig: NetworkConfig,
3921
+ rtcConnector: WebRtcConnector,
3922
+ );
3923
+ public onSignal(channel: PeerChannel, msg: SignalMessage): void;
3924
+ }
3925
+
3926
+ export class SignalStore {
3927
+ public static SIGNAL_MAX_AGE: 10 /* seconds */;
3928
+ public length: number;
3929
+ constructor(maxSize?: number);
3930
+ public add(senderId: PeerId, recipientId: PeerId, nonce: number): void;
3931
+ public contains(senderId: PeerId, recipientId: PeerId, nonce: number): boolean;
3932
+ public signalForwarded(senderId: PeerId, recipientId: PeerId, nonce: number): boolean;
3933
+ }
3934
+
3935
+ export class ForwardedSignal {
3936
+ constructor(
3937
+ senderId: PeerId,
3938
+ recipientId: PeerId,
3939
+ nonce: number,
3940
+ );
3941
+ public equals(o: any): boolean;
3942
+ public hashCode(): string;
3943
+ public toString(): string;
3944
+ }
3945
+
3946
+ export class ConnectionPool {
3947
+ public static DEFAULT_BAN_TIME: 600000;
3948
+ public static UNBAN_IPS_INTERVAL: 60000;
3949
+ public peerCountWs: number;
3950
+ public peerCountWss: number;
3951
+ public peerCountRtc: number;
3952
+ public peerCountDumb: number;
3953
+ public peerCount: number;
3954
+ public peerCountFull: number;
3955
+ public peerCountLight: number;
3956
+ public peerCountNano: number;
3957
+ public peerCountOutbound: number;
3958
+ public peerCountFullWsOutbound: number;
3959
+ public connectingCount: number;
3960
+ public count: number;
3961
+ public bytesSent: number;
3962
+ public bytesReceived: number;
3963
+ public allowInboundExchange: boolean;
3964
+ public allowInboundConnections: boolean;
3965
+ constructor(
3966
+ peerAddresses: PeerAddressBook,
3967
+ networkConfig: NetworkConfig,
3968
+ blockchain: IBlockchain,
3969
+ );
3970
+ public values(): PeerConnection[];
3971
+ public valueIterator(): Iterator<PeerConnection>;
3972
+ public getConnectionByPeerAddress(peerAddress: PeerAddress): null | PeerConnection;
3973
+ public getConnectionsByNetAddress(netAddress: NetAddress): PeerConnection[];
3974
+ public getConnectionsBySubnet(netAddress: NetAddress): PeerConnection[];
3975
+ public getOutboundConnectionsBySubnet(netAddress: NetAddress): PeerConnection[];
3976
+ public connectOutbound(peerAddress: PeerAddress): boolean;
3977
+ public disconnect(reason: string | any): void;
3978
+ }
3979
+
3980
+ export class PeerScorer {
3981
+ public static PEER_COUNT_MIN_FULL_WS_OUTBOUND: number;
3982
+ public static PEER_COUNT_MIN_OUTBOUND: number;
3983
+ public static PICK_SELECTION_SIZE: 100;
3984
+ public static MIN_AGE_FULL: number;
3985
+ public static BEST_AGE_FULL: number;
3986
+ public static MIN_AGE_LIGHT: number;
3987
+ public static BEST_AGE_LIGHT: number;
3988
+ public static MAX_AGE_LIGHT: number;
3989
+ public static MIN_AGE_NANO: number;
3990
+ public static BEST_AGE_NANO: number;
3991
+ public static MAX_AGE_NANO: number;
3992
+ public static BEST_PROTOCOL_WS_DISTRIBUTION: 0.15; // 15%
3993
+ public lowestConnectionScore: number;
3994
+ public connectionScores: PeerConnection[];
3995
+ constructor(
3996
+ networkConfig: NetworkConfig,
3997
+ addresses: PeerAddressBook,
3998
+ connections: ConnectionPool,
3999
+ );
4000
+ public pickAddress(): null | PeerAddress;
4001
+ public isGoodPeerSet(): boolean;
4002
+ public needsGoodPeers(): boolean;
4003
+ public needsMorePeers(): boolean;
4004
+ public isGoodPeer(): boolean;
4005
+ public scoreConnections(): void;
4006
+ public recycleConnections(count: number, type: number, reason: string): void;
4007
+ }
4008
+
4009
+ export class NetworkConfig {
4010
+ public static getDefault(): NetworkConfig;
4011
+ public protocol: number;
4012
+ public protocolMask: number;
4013
+ public keyPair: KeyPair;
4014
+ public publicKey: PublicKey;
4015
+ public peerId: PeerId;
4016
+ public services: Services;
4017
+ public peerAddress: PeerAddress;
4018
+ public appAgent: string;
4019
+ constructor(protocolMask: number);
4020
+ public initPersistent(): Promise<void>;
4021
+ public initVolatile(): Promise<void>;
4022
+ public canConnect(protocol: number): boolean;
4023
+ }
4024
+
4025
+ export class WsNetworkConfig extends NetworkConfig {
4026
+ public protocol: number;
4027
+ public port: number;
4028
+ public reverseProxy: { enabled: boolean, port: number, addresses: string[], header: string };
4029
+ public peerAddress: WsPeerAddress | WssPeerAddress;
4030
+ public secure: boolean;
4031
+ constructor(
4032
+ host: string,
4033
+ port: number,
4034
+ reverseProxy: { enabled: boolean, port: number, addresses: string[], header: string },
4035
+ );
4036
+ }
4037
+
4038
+ export class WssNetworkConfig extends WsNetworkConfig {
4039
+ public ssl: { key: string, cert: string };
4040
+ constructor(
4041
+ host: string,
4042
+ port: number,
4043
+ key: string,
4044
+ cert: string,
4045
+ reverseProxy: { enabled: boolean, port: number, addresses: string[], header: string },
4046
+ );
4047
+ }
4048
+
4049
+ export class RtcNetworkConfig extends NetworkConfig {
4050
+ public rtcConfig: RTCConfiguration;
4051
+ public peerAddress: RtcPeerAddress;
4052
+ constructor();
4053
+ }
4054
+
4055
+ export class DumbNetworkConfig extends NetworkConfig {
4056
+ public peerAddress: DumbPeerAddress;
4057
+ constructor();
4058
+ }
4059
+
4060
+ export class Network extends Observable {
4061
+ public static PEER_COUNT_MAX: number;
4062
+ public static INBOUND_PEER_COUNT_PER_SUBNET_MAX: number;
4063
+ public static OUTBOUND_PEER_COUNT_PER_SUBNET_MAX: 2;
4064
+ public static PEER_COUNT_PER_IP_MAX: number;
4065
+ public static PEER_COUNT_DUMB_MAX: 1000;
4066
+ public static IPV4_SUBNET_MASK: 24;
4067
+ public static IPV6_SUBNET_MASK: 96;
4068
+ public static PEER_COUNT_RECYCLING_ACTIVE: number;
4069
+ public static RECYCLING_PERCENTAGE_MIN: 0.01;
4070
+ public static RECYCLING_PERCENTAGE_MAX: 0.20;
4071
+ public static CONNECTING_COUNT_MAX: 2;
4072
+ public static SIGNAL_TTL_INITIAL: 3;
4073
+ public static CONNECT_BACKOFF_INITIAL: 2000; // 2 seconds
4074
+ public static CONNECT_BACKOFF_MAX: 600000; // 10 minutes
4075
+ public static TIME_OFFSET_MAX: number; // 10 minutes
4076
+ public static HOUSEKEEPING_INTERVAL: number; // 5 minutes
4077
+ public static SCORE_INBOUND_EXCHANGE: 0.5;
4078
+ public static CONNECT_THROTTLE: 500; // 0.5 seconds
4079
+ public static ADDRESS_REQUEST_CUTOFF: 250;
4080
+ public static ADDRESS_REQUEST_PEERS: 2;
4081
+ public static SIGNALING_ENABLED: 1;
4082
+ public time: Time;
4083
+ public peerCount: number;
4084
+ public peerCountWebSocket: number;
4085
+ public peerCountWebSocketSecure: number;
4086
+ public peerCountWebRtc: number;
4087
+ public peerCountDumb: number;
4088
+ public peerCountConnecting: number;
4089
+ public knownAddressesCount: number;
4090
+ public bytesSent: number;
4091
+ public bytesReceived: number;
4092
+ public allowInboundConnections: boolean;
4093
+ public addresses: PeerAddressBook;
4094
+ public connections: ConnectionPool;
4095
+ public config: NetworkConfig;
4096
+ constructor(
4097
+ blockchain: IBlockchain,
4098
+ networkConfig: NetworkConfig,
4099
+ time: Time,
4100
+ );
4101
+ public connect(): void;
4102
+ public disconnect(reason: string | any): void;
4103
+ }
4104
+
4105
+ export class NetUtils {
4106
+ public static IPv4_LENGTH: 4;
4107
+ public static IPv6_LENGTH: 16;
4108
+ public static IPv4_PRIVATE_NETWORK: string[];
4109
+ public static isPrivateIP(ip: string | Uint8Array): boolean;
4110
+ public static isLocalIP(ip: string | Uint8Array): boolean;
4111
+ public static isIPv4inSubnet(ip: string | Uint8Array, subnet: string): boolean;
4112
+ public static isIPv4Address(ip: string | Uint8Array): boolean;
4113
+ public static isIPv6Address(ip: string | Uint8Array): boolean;
4114
+ public static hostGloballyReachable(host: string): boolean;
4115
+ public static ipToBytes(ip: string): Uint8Array;
4116
+ public static bytesToIp(ip: Uint8Array): string;
4117
+ public static ipToSubnet(ip: string | Uint8Array, bitCount: number): string | Uint8Array;
4118
+ }
4119
+
4120
+ export class PeerKeyStore {
4121
+ public static VERSION: number;
4122
+ public static KEY_DATABASE: string;
4123
+ public static INITIAL_DB_SIZE: number;
4124
+ public static getPersistent(): Promise<PeerKeyStore>;
4125
+ public static createVolatile(): PeerKeyStore;
4126
+ constructor(store: any);
4127
+ public get(key: string): Promise<KeyPair>;
4128
+ public put(key: string, keyPair: KeyPair): Promise<void>;
4129
+ }
4130
+
4131
+ export class PeerKeyStoreCodec {
4132
+ public leveldbValueEncoding: string;
4133
+ public lmdbValueEncoding: object;
4134
+ public encode(obj: any): any;
4135
+ public decode(buf: any, key: string): any;
4136
+ }
4137
+
4138
+ export class Peer {
4139
+ public channel: PeerChannel;
4140
+ public version: number;
4141
+ public headHash: Hash;
4142
+ public head: BlockHeader;
4143
+ public timeOffset: number;
4144
+ public id: number;
4145
+ public peerAddress: PeerAddress;
4146
+ public netAddress: NetAddress;
4147
+ public userAgent?: string;
4148
+ constructor(
4149
+ channel: PeerChannel,
4150
+ version: number,
4151
+ headHash: Hash,
4152
+ timeOffset: number,
4153
+ userAgent?: string,
4154
+ );
4155
+ public equals(o: any): boolean;
4156
+ public hashCode(): string;
4157
+ public toString(): string;
4158
+ }
4159
+
4160
+ export class Miner extends Observable {
4161
+ public static MIN_TIME_ON_BLOCK: 10000;
4162
+ public static MOVING_AVERAGE_MAX_SIZE: 10;
4163
+ public address: Address;
4164
+ public working: boolean;
4165
+ public hashrate: number;
4166
+ public threads: number;
4167
+ public throttleWait: number;
4168
+ public throttleAfter: number;
4169
+ public extraData: Uint8Array;
4170
+ public shareCompact: number;
4171
+ public numBlocksMined: number;
4172
+ constructor(
4173
+ blockchain: BaseChain,
4174
+ accounts: Accounts,
4175
+ mempool: Mempool,
4176
+ time: Time,
4177
+ minerAddress: Address,
4178
+ extraData?: Uint8Array,
4179
+ );
4180
+ public startWork(): void;
4181
+ public onWorkerShare(obj: {hash: Hash, nonce: number, block: Block}): void;
4182
+ public getNextBlock(address?: Address, extraData?: Uint8Array): Promise<Block>;
4183
+ public stopWork(): void;
4184
+ public startConfigChanges(): void;
4185
+ public finishConfigChanges(): void;
4186
+ }
4187
+
4188
+ export abstract class BasePoolMiner extends Miner {
4189
+ public static PAYOUT_NONCE_PREFIX: 'POOL_PAYOUT';
4190
+ public static RECONNECT_TIMEOUT: 3000;
4191
+ public static RECONNECT_TIMEOUT_MAX: 30000;
4192
+ public static ConnectionState: {
4193
+ CONNECTED: 0;
4194
+ CONNECTING: 1;
4195
+ CLOSED: 2;
4196
+ };
4197
+ public static Mode: {
4198
+ NANO: 'nano';
4199
+ SMART: 'smart';
4200
+ };
4201
+ public static generateDeviceId(networkConfig: NetworkConfig): number;
4202
+ public host: string;
4203
+ public port: number;
4204
+ public address: Address;
4205
+ constructor(
4206
+ mode: BasePoolMiner.Mode,
4207
+ blockchain: BaseChain,
4208
+ accounts: Accounts,
4209
+ mempool: Mempool,
4210
+ time: Time,
4211
+ address: Address,
4212
+ deviceId: number,
4213
+ deviceData: object | null,
4214
+ extraData?: Uint8Array,
4215
+ );
4216
+ public requestPayout(): void;
4217
+ public connect(host: string, port: number): void;
4218
+ public disconnect(): void;
4219
+ public isConnected(): boolean;
4220
+ public isDisconnected(): boolean;
4221
+ }
4222
+
4223
+ export namespace BasePoolMiner {
4224
+ type ConnectionState = ConnectionState.CONNECTED | ConnectionState.CONNECTING | ConnectionState.CLOSED;
4225
+ namespace ConnectionState {
4226
+ type CONNECTED = 0;
4227
+ type CONNECTING = 1;
4228
+ type CLOSED = 2;
4229
+ }
4230
+ type Mode = Mode.NANO | Mode.SMART;
4231
+ namespace Mode {
4232
+ type NANO = 'nano';
4233
+ type SMART = 'smart';
4234
+ }
4235
+ }
4236
+
4237
+ export class SmartPoolMiner extends BasePoolMiner {
4238
+ constructor(
4239
+ blockchain: BaseChain,
4240
+ accounts: Accounts,
4241
+ mempool: Mempool,
4242
+ time: Time,
4243
+ address: Address,
4244
+ deviceId: number,
4245
+ deviceData: object | null,
4246
+ extraData?: Uint8Array,
4247
+ );
4248
+ }
4249
+
4250
+ export class NanoPoolMiner extends BasePoolMiner {
4251
+ constructor(
4252
+ blockchain: BaseChain,
4253
+ time: Time,
4254
+ address: Address,
4255
+ deviceId: number,
4256
+ deviceData: object | null,
4257
+ );
4258
+ // @ts-ignore
4259
+ public getNextBlock(): Block;
4260
+ }
4261
+
4262
+ export class Wallet {
4263
+ public static generate(): Wallet;
4264
+ public static loadPlain(buf: Uint8Array | string): Wallet;
4265
+ public static loadEncrypted(buf: Uint8Array | string, key: Uint8Array | string): Promise<Wallet>;
4266
+ public isLocked: boolean;
4267
+ public address: Address;
4268
+ public publicKey: PublicKey;
4269
+ public keyPair: KeyPair;
4270
+ constructor(keyPair: KeyPair);
4271
+ public createTransaction(recipient: Address, value: BigNumber | number | string, validityStartHeight: number): BasicTransaction;
4272
+ public signTransaction(transaction: Transaction): SignatureProof;
4273
+ public exportPlain(): Uint8Array;
4274
+ public exportEncrypted(key: Uint8Array|string): Promise<SerialBuffer>;
4275
+ public lock(key: Uint8Array | string): Promise<void>;
4276
+ public relock(): void;
4277
+ public unlock(key: Uint8Array | string): Promise<void>;
4278
+ public equals(o: any): boolean;
4279
+ }
4280
+
4281
+ // @ts-ignore
4282
+ export class MultiSigWallet extends Wallet {
4283
+ public static fromPublicKeys(keyPair: KeyPair, minSignatures: number, publicKeys: PublicKey[]): MultiSigWallet;
4284
+ public static loadPlain(buf: Uint8Array | string): MultiSigWallet;
4285
+ public static loadEncrypted(buf: Uint8Array | string, key: Uint8Array | string): Promise<MultiSigWallet>;
4286
+ public encryptedSize: number;
4287
+ public exportedSize: number;
4288
+ public minSignatures: number;
4289
+ public publicKeys: PublicKey[];
4290
+ constructor(
4291
+ keyPair: KeyPair,
4292
+ minSignatures: number,
4293
+ publicKeys: PublicKey[],
4294
+ );
4295
+ public exportEncrypted(key: Uint8Array|string): Promise<SerialBuffer>;
4296
+ public exportPlain(): Uint8Array;
4297
+ // @ts-ignore
4298
+ public createTransaction(recipientAddr: Address, value: BigNumber | number | string, validityStartHeight: number): ExtendedTransaction;
4299
+ public createCommitment(): CommitmentPair;
4300
+ public partiallySignTransaction(transaction: Transaction, publicKeys: PublicKey[], aggregatedCommitment: Commitment, secret: RandomSecret): PartialSignature;
4301
+ // @ts-ignore
4302
+ public signTransaction(transaction: Transaction, aggregatedPublicKey: PublicKey, aggregatedCommitment: Commitment, signatures: PartialSignature[]): SignatureProof;
4303
+ public completeTransaction(transaction: Transaction, aggregatedPublicKey: PublicKey, aggregatedCommitment: Commitment, signatures: PartialSignature[]): Transaction;
4304
+ }
4305
+
4306
+ export class WalletStore {
4307
+ public static VERSION: number;
4308
+ public static INITIAL_DB_SIZE: number; // 10 MB initially
4309
+ public static MIN_RESIZE: number; // 10 MB
4310
+ public static WALLET_DATABASE: string;
4311
+ public static MULTISIG_WALLET_DATABASE: string;
4312
+ constructor(dbName?: string);
4313
+ public hasDefault(): Promise<boolean>;
4314
+ public getDefault(key?: Uint8Array | string): Promise<Wallet>;
4315
+ public setDefault(address: Address): Promise<void>;
4316
+ public get(address: Address, key?: Uint8Array | string): Promise<null | Wallet>;
4317
+ public put(wallet: Wallet, key?: Uint8Array | string, unlockKey?: Uint8Array | string): Promise<void>;
4318
+ public remove(address: Address): Promise<void>;
4319
+ public list(): Promise<Address[]>;
4320
+ public getMultiSig(address: Address, key?: Uint8Array | string): Promise<null | MultiSigWallet>;
4321
+ public putMultiSig(wallet: MultiSigWallet, key?: Uint8Array | string, unlockKey?: Uint8Array | string): Promise<void>;
4322
+ public removeMultiSig(address: Address): Promise<void>;
4323
+ public listMultiSig(): Promise<Address[]>;
4324
+ public close(): void;
4325
+ }
4326
+
4327
+ export class WalletStoreCodec {
4328
+ public leveldbValueEncoding: string;
4329
+ public lmdbValueEncoding: object;
4330
+ public encode(obj: any): any;
4331
+ public decode(buf: any, key: string): any;
4332
+ }
4333
+
4334
+ export abstract class MinerWorker {
4335
+ public multiMine(blockHeader: Uint8Array, compact: number, minNonce: number, maxNonce: number): Promise<{ hash: Uint8Array, nonce: number } | boolean>;
4336
+ }
4337
+
4338
+ export class MinerWorkerImpl extends IWorker.Stub(MinerWorker) {
4339
+ constructor();
4340
+ public init(name: string): void;
4341
+ public multiMine(input: Uint8Array, compact: number, minNonce: number, maxNonce: number): Promise<{ hash: Uint8Array, nonce: number } | boolean>;
4342
+ }
4343
+
4344
+ export class MinerWorkerPool extends IWorker.Pool(MinerWorker) {
4345
+ public noncesPerRun: number;
4346
+ public runsPerCycle: number;
4347
+ public cycleWait: number;
4348
+ constructor(size?: number);
4349
+ public on(type: string, callback: () => any): number;
4350
+ public off(type: string, id: number): void;
4351
+ public startMiningOnBlock(block: Block, shareCompact?: number): Promise<void>;
4352
+ public stop(): void;
4353
+ }