lumina-node-wasm 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,170 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
- * Set up a logging layer that direct logs to the browser's console.
5
- */
4
+ * Set up a logging layer that direct logs to the browser's console.
5
+ */
6
6
  export function setup_logging(): void;
7
7
  /**
8
- * Supported Celestia networks.
9
- */
10
- export enum Network {
8
+ * A helper to encode the SignDoc with protobuf to get bytes to sign directly.
9
+ */
10
+ export function protoEncodeSignDoc(sign_doc: SignDoc): Uint8Array;
11
11
  /**
12
- * Celestia mainnet.
13
- */
12
+ * Supported Celestia networks.
13
+ */
14
+ export enum Network {
15
+ /**
16
+ * Celestia mainnet.
17
+ */
14
18
  Mainnet = 0,
15
- /**
16
- * Arabica testnet.
17
- */
19
+ /**
20
+ * Arabica testnet.
21
+ */
18
22
  Arabica = 1,
19
- /**
20
- * Mocha testnet.
21
- */
23
+ /**
24
+ * Mocha testnet.
25
+ */
22
26
  Mocha = 2,
23
- /**
24
- * Private local network.
25
- */
27
+ /**
28
+ * Private local network.
29
+ */
26
30
  Private = 3,
27
31
  }
28
32
  /**
29
- * A range of blocks between `start` and `end` height, inclusive
30
- */
31
- export class BlockRange {
33
+ * Sampling status for a block.
34
+ */
35
+ export enum SamplingStatus {
36
+ /**
37
+ * Sampling is not done.
38
+ */
39
+ Unknown = 0,
40
+ /**
41
+ * Sampling is done and block is accepted.
42
+ */
43
+ Accepted = 1,
44
+ /**
45
+ * Sampling is done and block is rejected.
46
+ */
47
+ Rejected = 2,
48
+ }
49
+ /**
50
+ * The `ReadableStreamType` enum.
51
+ *
52
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
53
+ */
54
+ type ReadableStreamType = "bytes";
55
+
56
+ /**
57
+ * Public key
58
+ */
59
+ export interface PublicKey {
60
+ type: "ed25519" | "secp256k1",
61
+ value: Uint8Array
62
+ }
63
+
64
+ /**
65
+ * Common data of all account types
66
+ */
67
+ export interface BaseAccount {
68
+ address: string,
69
+ pubkey?: PublicKey,
70
+ accountNumber: bigint,
71
+ sequence: bigint
72
+ }
73
+
74
+ /**
75
+ * Auth module parameters
76
+ */
77
+ export interface AuthParams {
78
+ maxMemoCharacters: bigint,
79
+ txSigLimit: bigint,
80
+ txSizeCostPerByte: bigint,
81
+ sigVerifyCostEd25519: bigint,
82
+ sigVerifyCostSecp256k1: bigint
83
+ }
84
+
85
+
86
+
87
+ /**
88
+ * Coin
89
+ */
90
+ export interface Coin {
91
+ denom: string,
92
+ amount: bigint
93
+ }
94
+
95
+
96
+
97
+ /**
98
+ * Transaction info
99
+ */
100
+ export interface TxInfo {
101
+ hash: string;
102
+ height: bigint;
103
+ }
104
+
105
+ /**
106
+ * Transaction config.
107
+ */
108
+ export interface TxConfig {
109
+ gasLimit?: bigint; // utia
110
+ gasPrice?: number;
111
+ }
112
+
113
+
114
+
115
+ /**
116
+ * A payload to be signed
117
+ */
118
+ export interface SignDoc {
119
+ bodyBytes: Uint8Array;
120
+ authInfoBytes: Uint8Array;
121
+ chainId: string;
122
+ accountNumber: bigint;
123
+ }
124
+
125
+ /**
126
+ * A function that produces a signature of a payload
127
+ */
128
+ export type SignerFn = ((arg: SignDoc) => Uint8Array) | ((arg: SignDoc) => Promise<Uint8Array>);
129
+
130
+
131
+
132
+ /**
133
+ * Protobuf Any type
134
+ */
135
+ export interface ProtoAny {
136
+ typeUrl: string;
137
+ value: Uint8Array;
138
+ }
139
+
140
+
141
+ /**
142
+ * Version of the App
143
+ */
144
+ export class AppVersion {
145
+ private constructor();
146
+ free(): void;
147
+ /**
148
+ * Latest App version variant.
149
+ */
150
+ static latest(): AppVersion;
151
+ /**
152
+ * App v1
153
+ */
154
+ static readonly V1: AppVersion;
155
+ /**
156
+ * App v2
157
+ */
158
+ static readonly V2: AppVersion;
159
+ /**
160
+ * App v3
161
+ */
162
+ static readonly V3: AppVersion;
163
+ }
164
+ /**
165
+ * Arbitrary data that can be stored in the network within certain [`Namespace`].
166
+ */
167
+ export class Blob {
32
168
  /**
33
169
  ** Return copy of self without private attributes.
34
170
  */
@@ -38,18 +174,104 @@ export class BlockRange {
38
174
  */
39
175
  toString(): string;
40
176
  free(): void;
177
+ /**
178
+ * Create a new blob with the given data within the [`Namespace`].
179
+ */
180
+ constructor(namespace: Namespace, data: Uint8Array, app_version: AppVersion);
181
+ /**
182
+ * Clone a blob creating a new deep copy of it.
183
+ */
184
+ clone(): Blob;
185
+ /**
186
+ * A [`Namespace`] the [`Blob`] belongs to.
187
+ */
188
+ namespace: Namespace;
189
+ /**
190
+ * Data stored within the [`Blob`].
191
+ */
192
+ data: Uint8Array;
193
+ /**
194
+ * Version indicating the format in which [`Share`]s should be created from this [`Blob`].
195
+ *
196
+ * [`Share`]: crate::share::Share
197
+ */
198
+ share_version: number;
199
+ /**
200
+ * A [`Commitment`] computed from the [`Blob`]s data.
201
+ */
202
+ commitment: Commitment;
203
+ /**
204
+ * Index of the blob's first share in the EDS. Only set for blobs retrieved from chain.
205
+ */
206
+ get index(): bigint | undefined;
207
+ /**
208
+ * Index of the blob's first share in the EDS. Only set for blobs retrieved from chain.
209
+ */
210
+ set index(value: bigint | null | undefined);
211
+ }
41
212
  /**
42
- * Last block height in range
213
+ * A range of blocks between `start` and `end` height, inclusive
214
+ */
215
+ export class BlockRange {
216
+ private constructor();
217
+ /**
218
+ ** Return copy of self without private attributes.
43
219
  */
44
- end: bigint;
220
+ toJSON(): Object;
45
221
  /**
46
- * First block height in range
222
+ * Return stringified version of self.
47
223
  */
224
+ toString(): string;
225
+ free(): void;
226
+ /**
227
+ * First block height in range
228
+ */
48
229
  start: bigint;
230
+ /**
231
+ * Last block height in range
232
+ */
233
+ end: bigint;
49
234
  }
50
235
  /**
51
- */
52
- export class ConnectionCountersSnapshot {
236
+ * A merkle hash used to identify the [`Blob`]s data.
237
+ *
238
+ * In Celestia network, the transaction which pays for the blob's inclusion
239
+ * is separated from the data itself. The reason for that is to allow verifying
240
+ * the blockchain's state without the need to pull the actual data which got stored.
241
+ * To achieve that, the [`MsgPayForBlobs`] transaction only includes the [`Commitment`]s
242
+ * of the blobs it is paying for, not the data itself.
243
+ *
244
+ * The algorithm of computing the [`Commitment`] of the [`Blob`]'s [`Share`]s is
245
+ * designed in a way to allow easy and cheap proving of the [`Share`]s inclusion in the
246
+ * block. It is computed as a [`merkle hash`] of all the [`Nmt`] subtree roots created from
247
+ * the blob shares included in the [`ExtendedDataSquare`] rows. Assuming the `s1` and `s2`
248
+ * are the only shares of some blob posted to the celestia, they'll result in a single subtree
249
+ * root as shown below:
250
+ *
251
+ * ```text
252
+ * NMT: row root
253
+ * / \
254
+ * o subtree root
255
+ * / \ / \
256
+ * _________________
257
+ * EDS row: | s | s | s1 | s2 |
258
+ * ```
259
+ *
260
+ * Using subtree roots as a base for [`Commitment`] computation allows for much smaller
261
+ * inclusion proofs than when the [`Share`]s would be used directly, but it imposes some
262
+ * constraints on how the [`Blob`]s can be placed in the [`ExtendedDataSquare`]. You can
263
+ * read more about that in the [`share commitment rules`].
264
+ *
265
+ * [`Blob`]: crate::Blob
266
+ * [`Share`]: crate::share::Share
267
+ * [`MsgPayForBlobs`]: celestia_proto::celestia::blob::v1::MsgPayForBlobs
268
+ * [`merkle hash`]: tendermint::merkle::simple_hash_from_byte_vectors
269
+ * [`Nmt`]: crate::nmt::Nmt
270
+ * [`ExtendedDataSquare`]: crate::ExtendedDataSquare
271
+ * [`share commitment rules`]: https://github.com/celestiaorg/celestia-app/blob/main/specs/src/specs/data_square_layout.md#blob-share-commitment-rules
272
+ */
273
+ export class Commitment {
274
+ private constructor();
53
275
  /**
54
276
  ** Return copy of self without private attributes.
55
277
  */
@@ -59,39 +281,305 @@ export class ConnectionCountersSnapshot {
59
281
  */
60
282
  toString(): string;
61
283
  free(): void;
284
+ /**
285
+ * Hash of the commitment
286
+ */
287
+ hash(): Uint8Array;
288
+ }
289
+ export class ConnectionCountersSnapshot {
290
+ private constructor();
62
291
  /**
63
- * The total number of connections, both pending and established.
292
+ ** Return copy of self without private attributes.
64
293
  */
65
- num_connections: number;
294
+ toJSON(): Object;
66
295
  /**
67
- * The number of outgoing connections being established.
296
+ * Return stringified version of self.
68
297
  */
298
+ toString(): string;
299
+ free(): void;
300
+ /**
301
+ * The total number of connections, both pending and established.
302
+ */
303
+ num_connections: number;
304
+ /**
305
+ * The total number of pending connections, both incoming and outgoing.
306
+ */
307
+ num_pending: number;
308
+ /**
309
+ * The total number of pending connections, both incoming and outgoing.
310
+ */
311
+ num_pending_incoming: number;
312
+ /**
313
+ * The number of outgoing connections being established.
314
+ */
315
+ num_pending_outgoing: number;
316
+ /**
317
+ * The number of outgoing connections being established.
318
+ */
69
319
  num_established: number;
70
- /**
71
- * The number of established incoming connections.
72
- */
320
+ /**
321
+ * The number of established incoming connections.
322
+ */
73
323
  num_established_incoming: number;
324
+ /**
325
+ * The number of established outgoing connections.
326
+ */
327
+ num_established_outgoing: number;
328
+ }
329
+ /**
330
+ * Header with commitments of the data availability.
331
+ *
332
+ * It consists of the root hashes of the merkle trees created from each
333
+ * row and column of the [`ExtendedDataSquare`]. Those are used to prove
334
+ * the inclusion of the data in a block.
335
+ *
336
+ * The hash of this header is a hash of all rows and columns and thus a
337
+ * data commitment of the block.
338
+ *
339
+ * # Example
340
+ *
341
+ * ```no_run
342
+ * # use celestia_types::{ExtendedHeader, Height, Share};
343
+ * # use celestia_types::nmt::{Namespace, NamespaceProof};
344
+ * # fn extended_header() -> ExtendedHeader {
345
+ * # unimplemented!();
346
+ * # }
347
+ * # fn shares_with_proof(_: Height, _: &Namespace) -> (Vec<Share>, NamespaceProof) {
348
+ * # unimplemented!();
349
+ * # }
350
+ * // fetch the block header and data for your namespace
351
+ * let namespace = Namespace::new_v0(&[1, 2, 3, 4]).unwrap();
352
+ * let eh = extended_header();
353
+ * let (shares, proof) = shares_with_proof(eh.height(), &namespace);
354
+ *
355
+ * // get the data commitment for a given row
356
+ * let dah = eh.dah;
357
+ * let root = dah.row_root(0).unwrap();
358
+ *
359
+ * // verify a proof of the inclusion of the shares
360
+ * assert!(proof.verify_complete_namespace(&root, &shares, *namespace).is_ok());
361
+ * ```
362
+ *
363
+ * [`ExtendedDataSquare`]: crate::eds::ExtendedDataSquare
364
+ */
365
+ export class DataAvailabilityHeader {
366
+ private constructor();
74
367
  /**
75
- * The number of established outgoing connections.
368
+ ** Return copy of self without private attributes.
76
369
  */
77
- num_established_outgoing: number;
370
+ toJSON(): Object;
78
371
  /**
79
- * The total number of pending connections, both incoming and outgoing.
372
+ * Return stringified version of self.
80
373
  */
81
- num_pending: number;
374
+ toString(): string;
375
+ free(): void;
376
+ /**
377
+ * Merkle roots of the [`ExtendedDataSquare`] rows.
378
+ */
379
+ rowRoots(): Array<any>;
380
+ /**
381
+ * Merkle roots of the [`ExtendedDataSquare`] columns.
382
+ */
383
+ columnRoots(): Array<any>;
384
+ /**
385
+ * Get a root of the row with the given index.
386
+ */
387
+ rowRoot(row: number): any;
388
+ /**
389
+ * Get the a root of the column with the given index.
390
+ */
391
+ columnRoot(column: number): any;
392
+ /**
393
+ * Compute the combined hash of all rows and columns.
394
+ *
395
+ * This is the data commitment for the block.
396
+ */
397
+ hash(): any;
398
+ /**
399
+ * Get the size of the [`ExtendedDataSquare`] for which this header was built.
400
+ */
401
+ squareWidth(): number;
402
+ }
82
403
  /**
83
- * The total number of pending connections, both incoming and outgoing.
404
+ * Block header together with the relevant Data Availability metadata.
405
+ *
406
+ * [`ExtendedHeader`]s are used to announce and describe the blocks
407
+ * in the Celestia network.
408
+ *
409
+ * Before being used, each header should be validated and verified with a header you trust.
410
+ *
411
+ * # Example
412
+ *
413
+ * ```
414
+ * # use celestia_types::ExtendedHeader;
415
+ * # fn trusted_genesis_header() -> ExtendedHeader {
416
+ * # let s = include_str!("../test_data/chain1/extended_header_block_1.json");
417
+ * # serde_json::from_str(s).unwrap()
418
+ * # }
419
+ * # fn some_untrusted_header() -> ExtendedHeader {
420
+ * # let s = include_str!("../test_data/chain1/extended_header_block_27.json");
421
+ * # serde_json::from_str(s).unwrap()
422
+ * # }
423
+ * let genesis_header = trusted_genesis_header();
424
+ *
425
+ * // fetch new header
426
+ * let fetched_header = some_untrusted_header();
427
+ *
428
+ * fetched_header.validate().expect("Invalid block header");
429
+ * genesis_header.verify(&fetched_header).expect("Malicious header received");
430
+ * ```
431
+ */
432
+ export class ExtendedHeader {
433
+ private constructor();
434
+ /**
435
+ ** Return copy of self without private attributes.
84
436
  */
85
- num_pending_incoming: number;
437
+ toJSON(): Object;
86
438
  /**
87
- * The number of outgoing connections being established.
439
+ * Return stringified version of self.
88
440
  */
89
- num_pending_outgoing: number;
441
+ toString(): string;
442
+ free(): void;
443
+ /**
444
+ * Clone a header producing a deep copy of it.
445
+ */
446
+ clone(): ExtendedHeader;
447
+ /**
448
+ * Get the block height.
449
+ */
450
+ height(): bigint;
451
+ /**
452
+ * Get the block time.
453
+ */
454
+ time(): number;
455
+ /**
456
+ * Get the block hash.
457
+ */
458
+ hash(): string;
459
+ /**
460
+ * Get the hash of the previous header.
461
+ */
462
+ previousHeaderHash(): string;
463
+ /**
464
+ * Decode protobuf encoded header and then validate it.
465
+ */
466
+ validate(): void;
467
+ /**
468
+ * Verify a chain of adjacent untrusted headers and make sure
469
+ * they are adjacent to `self`.
470
+ *
471
+ * # Errors
472
+ *
473
+ * If verification fails, this function will return an error with a reason of failure.
474
+ * This function will also return an error if untrusted headers and `self` don't form contiguous range
475
+ */
476
+ verify(untrusted: ExtendedHeader): void;
477
+ /**
478
+ * Verify a chain of adjacent untrusted headers.
479
+ *
480
+ * # Note
481
+ *
482
+ * Provided headers will be consumed by this method, meaning
483
+ * they will no longer be accessible. If this behavior is not desired,
484
+ * consider using `ExtendedHeader.clone()`.
485
+ *
486
+ * ```js
487
+ * const genesis = hdr0;
488
+ * const headers = [hrd1, hdr2, hdr3];
489
+ * genesis.verifyRange(headers.map(h => h.clone()));
490
+ * ```
491
+ *
492
+ * # Errors
493
+ *
494
+ * If verification fails, this function will return an error with a reason of failure.
495
+ * This function will also return an error if untrusted headers are not adjacent
496
+ * to each other.
497
+ */
498
+ verifyRange(untrusted: ExtendedHeader[]): void;
499
+ /**
500
+ * Verify a chain of adjacent untrusted headers and make sure
501
+ * they are adjacent to `self`.
502
+ *
503
+ * # Note
504
+ *
505
+ * Provided headers will be consumed by this method, meaning
506
+ * they will no longer be accessible. If this behavior is not desired,
507
+ * consider using `ExtendedHeader.clone()`.
508
+ *
509
+ * ```js
510
+ * const genesis = hdr0;
511
+ * const headers = [hrd1, hdr2, hdr3];
512
+ * genesis.verifyAdjacentRange(headers.map(h => h.clone()));
513
+ * ```
514
+ *
515
+ * # Errors
516
+ *
517
+ * If verification fails, this function will return an error with a reason of failure.
518
+ * This function will also return an error if untrusted headers and `self` don't form contiguous range
519
+ */
520
+ verifyAdjacentRange(untrusted: ExtendedHeader[]): void;
521
+ /**
522
+ * Header of the block data availability.
523
+ */
524
+ dah: DataAvailabilityHeader;
525
+ /**
526
+ * Tendermint block header.
527
+ */
528
+ readonly header: any;
529
+ /**
530
+ * Commit metadata and signatures from validators committing the block.
531
+ */
532
+ readonly commit: any;
533
+ /**
534
+ * Information about the set of validators commiting the block.
535
+ */
536
+ readonly validatorSet: any;
537
+ }
538
+ export class IntoUnderlyingByteSource {
539
+ private constructor();
540
+ free(): void;
541
+ start(controller: ReadableByteStreamController): void;
542
+ pull(controller: ReadableByteStreamController): Promise<any>;
543
+ cancel(): void;
544
+ readonly type: ReadableStreamType;
545
+ readonly autoAllocateChunkSize: number;
546
+ }
547
+ export class IntoUnderlyingSink {
548
+ private constructor();
549
+ free(): void;
550
+ write(chunk: any): Promise<any>;
551
+ close(): Promise<any>;
552
+ abort(reason: any): Promise<any>;
553
+ }
554
+ export class IntoUnderlyingSource {
555
+ private constructor();
556
+ free(): void;
557
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
558
+ cancel(): void;
90
559
  }
91
560
  /**
92
- * Information about the connections
93
- */
94
- export class NetworkInfoSnapshot {
561
+ * Namespace of the data published to the celestia network.
562
+ *
563
+ * The [`Namespace`] is a single byte defining the version
564
+ * followed by 28 bytes specifying concrete ID of the namespace.
565
+ *
566
+ * Currently there are two versions of namespaces:
567
+ *
568
+ * - version `0` - the one allowing for the custom namespace ids. It requires an id to start
569
+ * with 18 `0x00` bytes followed by a user specified suffix (except reserved ones, see below).
570
+ * - version `255` - for secondary reserved namespaces. It requires an id to start with 27
571
+ * `0xff` bytes followed by a single byte indicating the id.
572
+ *
573
+ * Some namespaces are reserved for the block creation purposes and cannot be used
574
+ * when submitting the blobs to celestia. Those fall into one of the two categories:
575
+ *
576
+ * - primary reserved namespaces - those use version `0` and have id lower or equal to `0xff`
577
+ * so they are always placed in blocks before user-submitted data.
578
+ * - secondary reserved namespaces - those use version `0xff` so they are always placed after
579
+ * user-submitted data.
580
+ */
581
+ export class Namespace {
582
+ private constructor();
95
583
  /**
96
584
  ** Return copy of self without private attributes.
97
585
  */
@@ -101,206 +589,233 @@ export class NetworkInfoSnapshot {
101
589
  */
102
590
  toString(): string;
103
591
  free(): void;
592
+ /**
593
+ * Create a new [`Namespace`] version `0` with given id.
594
+ *
595
+ * Check [`Namespace::new_v0`] for more details.
596
+ *
597
+ * [`Namespace::new_v0`]: https://docs.rs/celestia-types/latest/celestia_types/nmt/struct.Namespace.html#method.new_v0
598
+ */
599
+ static newV0(id: Uint8Array): Namespace;
600
+ /**
601
+ * Create a new [`Namespace`] from the raw bytes.
602
+ *
603
+ * # Errors
604
+ *
605
+ * This function will return an error if the slice length is different than
606
+ * [`NS_SIZE`] or if the namespace is invalid. If you are constructing the
607
+ * version `0` namespace, check [`newV0`].
608
+ */
609
+ static fromRaw(raw: Uint8Array): Namespace;
610
+ /**
611
+ * Converts the [`Namespace`] to a byte slice.
612
+ */
613
+ asBytes(): Uint8Array;
614
+ /**
615
+ * Namespace size in bytes.
616
+ */
617
+ static readonly NS_SIZE: number;
618
+ /**
619
+ * Primary reserved [`Namespace`] for the compact `Share`s with `cosmos SDK` transactions.
620
+ */
621
+ static readonly TRANSACTION: Namespace;
622
+ /**
623
+ * Primary reserved [`Namespace`] for the compact Shares with MsgPayForBlobs transactions.
624
+ */
625
+ static readonly PAY_FOR_BLOB: Namespace;
626
+ /**
627
+ * Primary reserved [`Namespace`] for the `Share`s used for padding.
628
+ *
629
+ * `Share`s with this namespace are inserted after other shares from primary reserved namespace
630
+ * so that user-defined namespaces are correctly aligned in `ExtendedDataSquare`
631
+ */
632
+ static readonly PRIMARY_RESERVED_PADDING: Namespace;
633
+ /**
634
+ * Maximal primary reserved [`Namespace`].
635
+ *
636
+ * Used to indicate the end of the primary reserved group.
637
+ */
638
+ static readonly MAX_PRIMARY_RESERVED: Namespace;
639
+ /**
640
+ * Minimal secondary reserved [`Namespace`].
641
+ *
642
+ * Used to indicate the beginning of the secondary reserved group.
643
+ */
644
+ static readonly MIN_SECONDARY_RESERVED: Namespace;
645
+ /**
646
+ * Secondary reserved [`Namespace`] used for padding after the blobs.
647
+ *
648
+ * It is used to fill up the `original data square` after all user-submitted
649
+ * blobs before the parity data is generated for the `ExtendedDataSquare`.
650
+ */
651
+ static readonly TAIL_PADDING: Namespace;
652
+ /**
653
+ * The [`Namespace`] for `parity shares`.
654
+ *
655
+ * It is the namespace with which all the `parity shares` from
656
+ * `ExtendedDataSquare` are inserted to the `Nmt` when computing
657
+ * merkle roots.
658
+ */
659
+ static readonly PARITY_SHARE: Namespace;
660
+ /**
661
+ * Returns the first byte indicating the version of the [`Namespace`].
662
+ */
663
+ readonly version: number;
664
+ /**
665
+ * Returns the trailing 28 bytes indicating the id of the [`Namespace`].
666
+ */
667
+ readonly id: Uint8Array;
668
+ }
104
669
  /**
105
- * Gets counters for ongoing network connections.
670
+ * Information about the connections
671
+ */
672
+ export class NetworkInfoSnapshot {
673
+ private constructor();
674
+ /**
675
+ ** Return copy of self without private attributes.
106
676
  */
107
- connection_counters: ConnectionCountersSnapshot;
677
+ toJSON(): Object;
108
678
  /**
109
- * The number of connected peers, i.e. peers with whom at least one established connection exists.
679
+ * Return stringified version of self.
110
680
  */
681
+ toString(): string;
682
+ free(): void;
683
+ /**
684
+ * The number of connected peers, i.e. peers with whom at least one established connection exists.
685
+ */
111
686
  num_peers: number;
687
+ /**
688
+ * Gets counters for ongoing network connections.
689
+ */
690
+ connection_counters: ConnectionCountersSnapshot;
112
691
  }
113
692
  /**
114
- * `NodeClient` is responsible for steering [`NodeWorker`] by sending it commands and receiving
115
- * responses over the provided port.
116
- *
117
- * [`NodeWorker`]: crate::worker::NodeWorker
118
- */
693
+ * `NodeClient` is responsible for steering [`NodeWorker`] by sending it commands and receiving
694
+ * responses over the provided port.
695
+ *
696
+ * [`NodeWorker`]: crate::worker::NodeWorker
697
+ */
119
698
  export class NodeClient {
120
699
  free(): void;
121
- /**
122
- * Create a new connection to a Lumina node running in [`NodeWorker`]. Provided `port` is
123
- * expected to have `MessagePort`-like interface for sending and receiving messages.
124
- * @param {any} port
125
- */
700
+ /**
701
+ * Create a new connection to a Lumina node running in [`NodeWorker`]. Provided `port` is
702
+ * expected to have `MessagePort`-like interface for sending and receiving messages.
703
+ */
126
704
  constructor(port: any);
127
- /**
128
- * Establish a new connection to the existing worker over provided port
129
- * @param {any} port
130
- * @returns {Promise<void>}
131
- */
705
+ /**
706
+ * Establish a new connection to the existing worker over provided port
707
+ */
132
708
  addConnectionToWorker(port: any): Promise<void>;
133
- /**
134
- * Check whether Lumina is currently running
135
- * @returns {Promise<boolean>}
136
- */
709
+ /**
710
+ * Check whether Lumina is currently running
711
+ */
137
712
  isRunning(): Promise<boolean>;
138
- /**
139
- * Start a node with the provided config, if it's not running
140
- * @param {NodeConfig} config
141
- * @returns {Promise<void>}
142
- */
713
+ /**
714
+ * Start a node with the provided config, if it's not running
715
+ */
143
716
  start(config: NodeConfig): Promise<void>;
144
- /**
145
- * @returns {Promise<void>}
146
- */
147
717
  stop(): Promise<void>;
148
- /**
149
- * Get node's local peer ID.
150
- * @returns {Promise<string>}
151
- */
718
+ /**
719
+ * Get node's local peer ID.
720
+ */
152
721
  localPeerId(): Promise<string>;
153
- /**
154
- * Get current [`PeerTracker`] info.
155
- * @returns {Promise<PeerTrackerInfoSnapshot>}
156
- */
722
+ /**
723
+ * Get current [`PeerTracker`] info.
724
+ */
157
725
  peerTrackerInfo(): Promise<PeerTrackerInfoSnapshot>;
158
- /**
159
- * Wait until the node is connected to at least 1 peer.
160
- * @returns {Promise<void>}
161
- */
726
+ /**
727
+ * Wait until the node is connected to at least 1 peer.
728
+ */
162
729
  waitConnected(): Promise<void>;
163
- /**
164
- * Wait until the node is connected to at least 1 trusted peer.
165
- * @returns {Promise<void>}
166
- */
730
+ /**
731
+ * Wait until the node is connected to at least 1 trusted peer.
732
+ */
167
733
  waitConnectedTrusted(): Promise<void>;
168
- /**
169
- * Get current network info.
170
- * @returns {Promise<NetworkInfoSnapshot>}
171
- */
734
+ /**
735
+ * Get current network info.
736
+ */
172
737
  networkInfo(): Promise<NetworkInfoSnapshot>;
173
- /**
174
- * Get all the multiaddresses on which the node listens.
175
- * @returns {Promise<Array<any>>}
176
- */
738
+ /**
739
+ * Get all the multiaddresses on which the node listens.
740
+ */
177
741
  listeners(): Promise<Array<any>>;
178
- /**
179
- * Get all the peers that node is connected to.
180
- * @returns {Promise<Array<any>>}
181
- */
742
+ /**
743
+ * Get all the peers that node is connected to.
744
+ */
182
745
  connectedPeers(): Promise<Array<any>>;
183
- /**
184
- * Trust or untrust the peer with a given ID.
185
- * @param {string} peer_id
186
- * @param {boolean} is_trusted
187
- * @returns {Promise<void>}
188
- */
746
+ /**
747
+ * Trust or untrust the peer with a given ID.
748
+ */
189
749
  setPeerTrust(peer_id: string, is_trusted: boolean): Promise<void>;
190
- /**
191
- * Request the head header from the network.
192
- *
193
- * Returns a javascript object with given structure:
194
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
195
- * @returns {Promise<any>}
196
- */
197
- requestHeadHeader(): Promise<any>;
198
- /**
199
- * Request a header for the block with a given hash from the network.
200
- *
201
- * Returns a javascript object with given structure:
202
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
203
- * @param {string} hash
204
- * @returns {Promise<any>}
205
- */
206
- requestHeaderByHash(hash: string): Promise<any>;
207
- /**
208
- * Request a header for the block with a given height from the network.
209
- *
210
- * Returns a javascript object with given structure:
211
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
212
- * @param {bigint} height
213
- * @returns {Promise<any>}
214
- */
215
- requestHeaderByHeight(height: bigint): Promise<any>;
216
- /**
217
- * Request headers in range (from, from + amount] from the network.
218
- *
219
- * The headers will be verified with the `from` header.
220
- *
221
- * Returns an array of javascript objects with given structure:
222
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
223
- * @param {any} from_header
224
- * @param {bigint} amount
225
- * @returns {Promise<Array<any>>}
226
- */
227
- requestVerifiedHeaders(from_header: any, amount: bigint): Promise<Array<any>>;
228
- /**
229
- * Get current header syncing info.
230
- * @returns {Promise<SyncingInfoSnapshot>}
231
- */
750
+ /**
751
+ * Request the head header from the network.
752
+ */
753
+ requestHeadHeader(): Promise<ExtendedHeader>;
754
+ /**
755
+ * Request a header for the block with a given hash from the network.
756
+ */
757
+ requestHeaderByHash(hash: string): Promise<ExtendedHeader>;
758
+ /**
759
+ * Request a header for the block with a given height from the network.
760
+ */
761
+ requestHeaderByHeight(height: bigint): Promise<ExtendedHeader>;
762
+ /**
763
+ * Request headers in range (from, from + amount] from the network.
764
+ *
765
+ * The headers will be verified with the `from` header.
766
+ */
767
+ requestVerifiedHeaders(from: ExtendedHeader, amount: bigint): Promise<ExtendedHeader[]>;
768
+ /**
769
+ * Request all blobs with provided namespace in the block corresponding to this header
770
+ * using bitswap protocol.
771
+ */
772
+ requestAllBlobs(header: ExtendedHeader, namespace: Namespace, timeout_secs?: number | null): Promise<Blob[]>;
773
+ /**
774
+ * Get current header syncing info.
775
+ */
232
776
  syncerInfo(): Promise<SyncingInfoSnapshot>;
233
- /**
234
- * Get the latest header announced in the network.
235
- *
236
- * Returns a javascript object with given structure:
237
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
238
- * @returns {Promise<any>}
239
- */
240
- getNetworkHeadHeader(): Promise<any>;
241
- /**
242
- * Get the latest locally synced header.
243
- *
244
- * Returns a javascript object with given structure:
245
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
246
- * @returns {Promise<any>}
247
- */
248
- getLocalHeadHeader(): Promise<any>;
249
- /**
250
- * Get a synced header for the block with a given hash.
251
- *
252
- * Returns a javascript object with given structure:
253
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
254
- * @param {string} hash
255
- * @returns {Promise<any>}
256
- */
257
- getHeaderByHash(hash: string): Promise<any>;
258
- /**
259
- * Get a synced header for the block with a given height.
260
- *
261
- * Returns a javascript object with given structure:
262
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
263
- * @param {bigint} height
264
- * @returns {Promise<any>}
265
- */
266
- getHeaderByHeight(height: bigint): Promise<any>;
267
- /**
268
- * Get synced headers from the given heights range.
269
- *
270
- * If start of the range is undefined (None), the first returned header will be of height 1.
271
- * If end of the range is undefined (None), the last returned header will be the last header in the
272
- * store.
273
- *
274
- * # Errors
275
- *
276
- * If range contains a height of a header that is not found in the store.
277
- *
278
- * Returns an array of javascript objects with given structure:
279
- * https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
280
- * @param {bigint | undefined} [start_height]
281
- * @param {bigint | undefined} [end_height]
282
- * @returns {Promise<Array<any>>}
283
- */
284
- getHeaders(start_height?: bigint, end_height?: bigint): Promise<Array<any>>;
285
- /**
286
- * Get data sampling metadata of an already sampled height.
287
- *
288
- * Returns a javascript object with given structure:
289
- * https://docs.rs/lumina-node/latest/lumina_node/store/struct.SamplingMetadata.html
290
- * @param {bigint} height
291
- * @returns {Promise<any>}
292
- */
293
- getSamplingMetadata(height: bigint): Promise<any>;
294
- /**
295
- * Returns a [`BroadcastChannel`] for events generated by [`Node`].
296
- * @returns {Promise<BroadcastChannel>}
297
- */
777
+ /**
778
+ * Get the latest header announced in the network.
779
+ */
780
+ getNetworkHeadHeader(): Promise<ExtendedHeader | undefined>;
781
+ /**
782
+ * Get the latest locally synced header.
783
+ */
784
+ getLocalHeadHeader(): Promise<ExtendedHeader>;
785
+ /**
786
+ * Get a synced header for the block with a given hash.
787
+ */
788
+ getHeaderByHash(hash: string): Promise<ExtendedHeader>;
789
+ /**
790
+ * Get a synced header for the block with a given height.
791
+ */
792
+ getHeaderByHeight(height: bigint): Promise<ExtendedHeader>;
793
+ /**
794
+ * Get synced headers from the given heights range.
795
+ *
796
+ * If start of the range is undefined (None), the first returned header will be of height 1.
797
+ * If end of the range is undefined (None), the last returned header will be the last header in the
798
+ * store.
799
+ *
800
+ * # Errors
801
+ *
802
+ * If range contains a height of a header that is not found in the store.
803
+ */
804
+ getHeaders(start_height?: bigint | null, end_height?: bigint | null): Promise<ExtendedHeader[]>;
805
+ /**
806
+ * Get data sampling metadata of an already sampled height.
807
+ */
808
+ getSamplingMetadata(height: bigint): Promise<SamplingMetadata | undefined>;
809
+ /**
810
+ * Returns a [`BroadcastChannel`] for events generated by [`Node`].
811
+ */
298
812
  eventsChannel(): Promise<BroadcastChannel>;
299
813
  }
300
814
  /**
301
- * Config for the lumina wasm node.
302
- */
815
+ * Config for the lumina wasm node.
816
+ */
303
817
  export class NodeConfig {
818
+ private constructor();
304
819
  /**
305
820
  ** Return copy of self without private attributes.
306
821
  */
@@ -310,43 +825,87 @@ export class NodeConfig {
310
825
  */
311
826
  toString(): string;
312
827
  free(): void;
313
- /**
314
- * Get the configuration with default bootnodes for provided network
315
- * @param {Network} network
316
- * @returns {NodeConfig}
317
- */
828
+ /**
829
+ * Get the configuration with default bootnodes for provided network
830
+ */
318
831
  static default(network: Network): NodeConfig;
319
- /**
320
- * A list of bootstrap peers to connect to.
321
- */
322
- bootnodes: (string)[];
323
- /**
324
- * Syncing window size, defines maximum age of headers considered for syncing and sampling.
325
- * Headers older than syncing window by more than an hour are eligible for pruning.
326
- */
327
- custom_syncing_window_secs?: number;
328
- /**
329
- * A network to connect to.
330
- */
832
+ /**
833
+ * A network to connect to.
834
+ */
331
835
  network: Network;
836
+ /**
837
+ * A list of bootstrap peers to connect to.
838
+ */
839
+ bootnodes: string[];
840
+ /**
841
+ * Whether to store data in persistent memory or not.
842
+ *
843
+ * **Default value:** true
844
+ */
845
+ usePersistentMemory: boolean;
846
+ /**
847
+ * Sampling window defines maximum age of a block considered for syncing and sampling.
848
+ *
849
+ * If this is not set, then default value will apply:
850
+ *
851
+ * * If `use_persistent_memory == true`, default value is 30 days.
852
+ * * If `use_persistent_memory == false`, default value is 60 seconds.
853
+ *
854
+ * The minimum value that can be set is 60 seconds.
855
+ */
856
+ get customSamplingWindowSecs(): number | undefined;
857
+ /**
858
+ * Sampling window defines maximum age of a block considered for syncing and sampling.
859
+ *
860
+ * If this is not set, then default value will apply:
861
+ *
862
+ * * If `use_persistent_memory == true`, default value is 30 days.
863
+ * * If `use_persistent_memory == false`, default value is 60 seconds.
864
+ *
865
+ * The minimum value that can be set is 60 seconds.
866
+ */
867
+ set customSamplingWindowSecs(value: number | null | undefined);
868
+ /**
869
+ * Pruning delay defines how much time the pruner should wait after sampling window in
870
+ * order to prune the block.
871
+ *
872
+ * If this is not set, then default value will apply:
873
+ *
874
+ * * If `use_persistent_memory == true`, default value is 1 hour.
875
+ * * If `use_persistent_memory == false`, default value is 60 seconds.
876
+ *
877
+ * The minimum value that can be set is 60 seconds.
878
+ */
879
+ get customPruningDelaySecs(): number | undefined;
880
+ /**
881
+ * Pruning delay defines how much time the pruner should wait after sampling window in
882
+ * order to prune the block.
883
+ *
884
+ * If this is not set, then default value will apply:
885
+ *
886
+ * * If `use_persistent_memory == true`, default value is 1 hour.
887
+ * * If `use_persistent_memory == false`, default value is 60 seconds.
888
+ *
889
+ * The minimum value that can be set is 60 seconds.
890
+ */
891
+ set customPruningDelaySecs(value: number | null | undefined);
332
892
  }
333
893
  /**
334
- */
894
+ * `NodeWorker` is responsible for receiving commands from connected [`NodeClient`]s, executing
895
+ * them and sending a response back, as well as accepting new `NodeClient` connections.
896
+ *
897
+ * [`NodeClient`]: crate::client::NodeClient
898
+ */
335
899
  export class NodeWorker {
336
900
  free(): void;
337
- /**
338
- * @param {any} port_like_object
339
- */
340
901
  constructor(port_like_object: any);
341
- /**
342
- * @returns {Promise<void>}
343
- */
344
902
  run(): Promise<void>;
345
903
  }
346
904
  /**
347
- * Statistics of the connected peers
348
- */
905
+ * Statistics of the connected peers
906
+ */
349
907
  export class PeerTrackerInfoSnapshot {
908
+ private constructor();
350
909
  /**
351
910
  ** Return copy of self without private attributes.
352
911
  */
@@ -356,19 +915,37 @@ export class PeerTrackerInfoSnapshot {
356
915
  */
357
916
  toString(): string;
358
917
  free(): void;
359
- /**
360
- * Number of the connected peers.
361
- */
918
+ /**
919
+ * Number of the connected peers.
920
+ */
362
921
  num_connected_peers: bigint;
363
- /**
364
- * Number of the connected trusted peers.
365
- */
922
+ /**
923
+ * Number of the connected trusted peers.
924
+ */
366
925
  num_connected_trusted_peers: bigint;
367
926
  }
368
927
  /**
369
- * Status of the synchronization.
370
- */
928
+ * Sampling metadata for a block.
929
+ *
930
+ * This struct persists DAS-ing information in a header store for future reference.
931
+ */
932
+ export class SamplingMetadata {
933
+ private constructor();
934
+ free(): void;
935
+ /**
936
+ * Indicates whether this node was able to successfuly sample the block
937
+ */
938
+ status: SamplingStatus;
939
+ /**
940
+ * Return Array of cids
941
+ */
942
+ readonly cids: Uint8Array[];
943
+ }
944
+ /**
945
+ * Status of the synchronization.
946
+ */
371
947
  export class SyncingInfoSnapshot {
948
+ private constructor();
372
949
  /**
373
950
  ** Return copy of self without private attributes.
374
951
  */
@@ -378,12 +955,149 @@ export class SyncingInfoSnapshot {
378
955
  */
379
956
  toString(): string;
380
957
  free(): void;
381
- /**
382
- * Ranges of headers that are already synchronised
383
- */
384
- stored_headers: (BlockRange)[];
385
- /**
386
- * Syncing target. The latest height seen in the network that was successfully verified.
387
- */
958
+ /**
959
+ * Ranges of headers that are already synchronised
960
+ */
961
+ stored_headers: BlockRange[];
962
+ /**
963
+ * Syncing target. The latest height seen in the network that was successfully verified.
964
+ */
388
965
  subjective_head: bigint;
389
966
  }
967
+ /**
968
+ * Celestia grpc transaction client.
969
+ */
970
+ export class TxClient {
971
+ free(): void;
972
+ /**
973
+ * Create a new transaction client with the specified account.
974
+ *
975
+ * Url must point to a [grpc-web proxy](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md).
976
+ *
977
+ * # Example with noble/curves
978
+ * ```js
979
+ * import { secp256k1 } from "@noble/curves/secp256k1";
980
+ *
981
+ * const address = "celestia169s50psyj2f4la9a2235329xz7rk6c53zhw9mm";
982
+ * const privKey = "fdc8ac75dfa1c142dbcba77938a14dd03078052ce0b49a529dcf72a9885a3abb";
983
+ * const pubKey = secp256k1.getPublicKey(privKey);
984
+ *
985
+ * const signer = (signDoc) => {
986
+ * const bytes = protoEncodeSignDoc(signDoc);
987
+ * const sig = secp256k1.sign(bytes, privKey, { prehash: true });
988
+ * return sig.toCompactRawBytes();
989
+ * };
990
+ *
991
+ * const txClient = await new TxClient("http://127.0.0.1:18080", address, pubKey, signer);
992
+ * ```
993
+ *
994
+ * # Example with leap wallet
995
+ * ```js
996
+ * await window.leap.enable("mocha-4")
997
+ * const keys = await window.leap.getKey("mocha-4")
998
+ *
999
+ * const signer = (signDoc) => {
1000
+ * return window.leap.signDirect("mocha-4", keys.bech32Address, signDoc, { preferNoSetFee: true })
1001
+ * .then(sig => Uint8Array.from(atob(sig.signature.signature), c => c.charCodeAt(0)))
1002
+ * }
1003
+ *
1004
+ * const tx_client = await new TxClient("http://127.0.0.1:18080", keys.bech32Address, keys.pubKey, signer)
1005
+ * ```
1006
+ */
1007
+ constructor(url: string, bech32_address: string, pubkey: Uint8Array, signer_fn: SignerFn);
1008
+ /**
1009
+ * Last gas price fetched by the client
1010
+ */
1011
+ lastSeenGasPrice(): number;
1012
+ /**
1013
+ * Submit blobs to the celestia network.
1014
+ *
1015
+ * When no `TxConfig` is provided, client will automatically calculate needed
1016
+ * gas and update the `gasPrice`, if network agreed on a new minimal value.
1017
+ * To enforce specific values use a `TxConfig`.
1018
+ *
1019
+ * # Example
1020
+ * ```js
1021
+ * const ns = Namespace.newV0(new Uint8Array([97, 98, 99]));
1022
+ * const data = new Uint8Array([100, 97, 116, 97]);
1023
+ * const blob = new Blob(ns, data, AppVersion.latest());
1024
+ *
1025
+ * const txInfo = await txClient.submitBlobs([blob]);
1026
+ * await txClient.submitBlobs([blob], { gasLimit: 100000n, gasPrice: 0.02 });
1027
+ * ```
1028
+ *
1029
+ * # Note
1030
+ *
1031
+ * Provided blobs will be consumed by this method, meaning
1032
+ * they will no longer be accessible. If this behavior is not desired,
1033
+ * consider using `Blob.clone()`.
1034
+ *
1035
+ * ```js
1036
+ * const blobs = [blob1, blob2, blob3];
1037
+ * await txClient.submitBlobs(blobs.map(b => b.clone()));
1038
+ * ```
1039
+ */
1040
+ submitBlobs(blobs: Blob[], tx_config?: TxConfig | null): Promise<TxInfo>;
1041
+ /**
1042
+ * Submit message to the celestia network.
1043
+ *
1044
+ * When no `TxConfig` is provided, client will automatically calculate needed
1045
+ * gas and update the `gasPrice`, if network agreed on a new minimal value.
1046
+ * To enforce specific values use a `TxConfig`.
1047
+ *
1048
+ * # Example
1049
+ * ```js
1050
+ * import { Registry } from "@cosmjs/proto-signing";
1051
+ *
1052
+ * const registry = new Registry();
1053
+ * const sendMsg = {
1054
+ * typeUrl: "/cosmos.bank.v1beta1.MsgSend",
1055
+ * value: {
1056
+ * fromAddress: "celestia169s50psyj2f4la9a2235329xz7rk6c53zhw9mm",
1057
+ * toAddress: "celestia1t52q7uqgnjfzdh3wx5m5phvma3umrq8k6tq2p9",
1058
+ * amount: [{ denom: "utia", amount: "10000" }],
1059
+ * },
1060
+ * };
1061
+ * const sendMsgAny = registry.encodeAsAny(sendMsg);
1062
+ *
1063
+ * const txInfo = await txClient.submitMessage(sendMsgAny);
1064
+ * ```
1065
+ */
1066
+ submitMessage(message: ProtoAny, tx_config?: TxConfig | null): Promise<TxInfo>;
1067
+ /**
1068
+ * Get auth params
1069
+ */
1070
+ getAuthParams(): Promise<AuthParams>;
1071
+ /**
1072
+ * Get account
1073
+ */
1074
+ getAccount(account: string): Promise<BaseAccount>;
1075
+ /**
1076
+ * Get accounts
1077
+ */
1078
+ getAccounts(): Promise<BaseAccount[]>;
1079
+ /**
1080
+ * Get balance of coins with given denom
1081
+ */
1082
+ getBalance(address: string, denom: string): Promise<Coin>;
1083
+ /**
1084
+ * Get balance of all coins
1085
+ */
1086
+ getAllBalances(address: string): Promise<Coin[]>;
1087
+ /**
1088
+ * Get balance of all spendable coins
1089
+ */
1090
+ getSpendableBalances(address: string): Promise<Coin[]>;
1091
+ /**
1092
+ * Get total supply
1093
+ */
1094
+ getTotalSupply(): Promise<Coin[]>;
1095
+ /**
1096
+ * Chain id of the client
1097
+ */
1098
+ readonly chainId: string;
1099
+ /**
1100
+ * AppVersion of the client
1101
+ */
1102
+ readonly appVersion: AppVersion;
1103
+ }