lumina-node-wasm 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Lumina node wasm
2
+
3
+ A compatibility layer for the [`Lumina`](https://github.com/eigerco/lumina) node to
4
+ work within a browser environment and be operable with javascript.
5
+
6
+ ```javascript
7
+ import init, { Node, NodeConfig, Network } from "/wasm/lumina_node_wasm.js";
8
+
9
+ await init();
10
+
11
+ const config = NodeConfig.default(Network.Mainnet);
12
+ const node = await new Node(config);
13
+
14
+ await node.wait_connected();
15
+ await node.request_head_header();
16
+ ```
@@ -0,0 +1,251 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Set up a logging layer that direct logs to the browser's console.
5
+ */
6
+ export function setup_logging(): void;
7
+ /**
8
+ * Supported Celestia networks.
9
+ */
10
+ export enum Network {
11
+ /**
12
+ * Celestia mainnet.
13
+ */
14
+ Mainnet = 0,
15
+ /**
16
+ * Arabica testnet.
17
+ */
18
+ Arabica = 1,
19
+ /**
20
+ * Mocha testnet.
21
+ */
22
+ Mocha = 2,
23
+ /**
24
+ * Private local network.
25
+ */
26
+ Private = 3,
27
+ }
28
+ /**
29
+ */
30
+ export class ConnectionCountersSnapshot {
31
+ free(): void;
32
+ /**
33
+ */
34
+ num_connections: number;
35
+ /**
36
+ */
37
+ num_established: number;
38
+ /**
39
+ */
40
+ num_established_incoming: number;
41
+ /**
42
+ */
43
+ num_established_outgoing: number;
44
+ /**
45
+ */
46
+ num_pending: number;
47
+ /**
48
+ */
49
+ num_pending_incoming: number;
50
+ /**
51
+ */
52
+ num_pending_outgoing: number;
53
+ }
54
+ /**
55
+ */
56
+ export class NetworkInfoSnapshot {
57
+ free(): void;
58
+ /**
59
+ */
60
+ num_peers: number;
61
+ }
62
+ /**
63
+ * `NodeDriver` is responsible for steering [`NodeWorker`] by sending it commands and receiving
64
+ * responses over the provided port.
65
+ *
66
+ * [`NodeWorker`]: crate::worker::NodeWorker
67
+ */
68
+ export class NodeClient {
69
+ free(): void;
70
+ /**
71
+ * Create a new connection to a Lumina node running in [`NodeWorker`]. Provided `port` is
72
+ * expected to have `MessagePort`-like interface for sending and receiving messages.
73
+ * @param {any} port
74
+ */
75
+ constructor(port: any);
76
+ /**
77
+ * Check whether Lumina is currently running
78
+ * @returns {Promise<boolean>}
79
+ */
80
+ is_running(): Promise<boolean>;
81
+ /**
82
+ * Start a node with the provided config, if it's not running
83
+ * @param {NodeConfig} config
84
+ * @returns {Promise<void>}
85
+ */
86
+ start(config: NodeConfig): Promise<void>;
87
+ /**
88
+ * Get node's local peer ID.
89
+ * @returns {Promise<string>}
90
+ */
91
+ local_peer_id(): Promise<string>;
92
+ /**
93
+ * Get current [`PeerTracker`] info.
94
+ * @returns {Promise<any>}
95
+ */
96
+ peer_tracker_info(): Promise<any>;
97
+ /**
98
+ * Wait until the node is connected to at least 1 peer.
99
+ * @returns {Promise<void>}
100
+ */
101
+ wait_connected(): Promise<void>;
102
+ /**
103
+ * Wait until the node is connected to at least 1 trusted peer.
104
+ * @returns {Promise<void>}
105
+ */
106
+ wait_connected_trusted(): Promise<void>;
107
+ /**
108
+ * Get current network info.
109
+ * @returns {Promise<NetworkInfoSnapshot>}
110
+ */
111
+ network_info(): Promise<NetworkInfoSnapshot>;
112
+ /**
113
+ * Get all the multiaddresses on which the node listens.
114
+ * @returns {Promise<Array<any>>}
115
+ */
116
+ listeners(): Promise<Array<any>>;
117
+ /**
118
+ * Get all the peers that node is connected to.
119
+ * @returns {Promise<Array<any>>}
120
+ */
121
+ connected_peers(): Promise<Array<any>>;
122
+ /**
123
+ * Trust or untrust the peer with a given ID.
124
+ * @param {string} peer_id
125
+ * @param {boolean} is_trusted
126
+ * @returns {Promise<void>}
127
+ */
128
+ set_peer_trust(peer_id: string, is_trusted: boolean): Promise<void>;
129
+ /**
130
+ * Request the head header from the network.
131
+ * @returns {Promise<any>}
132
+ */
133
+ request_head_header(): Promise<any>;
134
+ /**
135
+ * Request a header for the block with a given hash from the network.
136
+ * @param {string} hash
137
+ * @returns {Promise<any>}
138
+ */
139
+ request_header_by_hash(hash: string): Promise<any>;
140
+ /**
141
+ * Request a header for the block with a given height from the network.
142
+ * @param {bigint} height
143
+ * @returns {Promise<any>}
144
+ */
145
+ request_header_by_height(height: bigint): Promise<any>;
146
+ /**
147
+ * Request headers in range (from, from + amount] from the network.
148
+ *
149
+ * The headers will be verified with the `from` header.
150
+ * @param {any} from_header
151
+ * @param {bigint} amount
152
+ * @returns {Promise<Array<any>>}
153
+ */
154
+ request_verified_headers(from_header: any, amount: bigint): Promise<Array<any>>;
155
+ /**
156
+ * Get current header syncing info.
157
+ * @returns {Promise<any>}
158
+ */
159
+ syncer_info(): Promise<any>;
160
+ /**
161
+ * Get the latest header announced in the network.
162
+ * @returns {Promise<any>}
163
+ */
164
+ get_network_head_header(): Promise<any>;
165
+ /**
166
+ * Get the latest locally synced header.
167
+ * @returns {Promise<any>}
168
+ */
169
+ get_local_head_header(): Promise<any>;
170
+ /**
171
+ * Get a synced header for the block with a given hash.
172
+ * @param {string} hash
173
+ * @returns {Promise<any>}
174
+ */
175
+ get_header_by_hash(hash: string): Promise<any>;
176
+ /**
177
+ * Get a synced header for the block with a given height.
178
+ * @param {bigint} height
179
+ * @returns {Promise<any>}
180
+ */
181
+ get_header_by_height(height: bigint): Promise<any>;
182
+ /**
183
+ * Get synced headers from the given heights range.
184
+ *
185
+ * If start of the range is undefined (None), the first returned header will be of height 1.
186
+ * If end of the range is undefined (None), the last returned header will be the last header in the
187
+ * store.
188
+ *
189
+ * # Errors
190
+ *
191
+ * If range contains a height of a header that is not found in the store.
192
+ * @param {bigint | undefined} [start_height]
193
+ * @param {bigint | undefined} [end_height]
194
+ * @returns {Promise<Array<any>>}
195
+ */
196
+ get_headers(start_height?: bigint, end_height?: bigint): Promise<Array<any>>;
197
+ /**
198
+ * Get data sampling metadata of an already sampled height.
199
+ * @param {bigint} height
200
+ * @returns {Promise<any>}
201
+ */
202
+ get_sampling_metadata(height: bigint): Promise<any>;
203
+ /**
204
+ * Requests SharedWorker running lumina to close. Any events received afterwards wont
205
+ * be processed and new NodeClient needs to be created to restart a node.
206
+ * @returns {Promise<void>}
207
+ */
208
+ close(): Promise<void>;
209
+ /**
210
+ * Returns a [`BroadcastChannel`] for events generated by [`Node`].
211
+ * @returns {Promise<BroadcastChannel>}
212
+ */
213
+ events_channel(): Promise<BroadcastChannel>;
214
+ }
215
+ /**
216
+ * Config for the lumina wasm node.
217
+ */
218
+ export class NodeConfig {
219
+ free(): void;
220
+ /**
221
+ * Get the configuration with default bootnodes for provided network
222
+ * @param {Network} network
223
+ * @returns {NodeConfig}
224
+ */
225
+ static default(network: Network): NodeConfig;
226
+ /**
227
+ * A list of bootstrap peers to connect to.
228
+ */
229
+ bootnodes: (string)[];
230
+ /**
231
+ * A network to connect to.
232
+ */
233
+ network: Network;
234
+ }
235
+ /**
236
+ */
237
+ export class NodeWorker {
238
+ free(): void;
239
+ /**
240
+ */
241
+ constructor();
242
+ /**
243
+ * @param {any} port
244
+ * @returns {Promise<void>}
245
+ */
246
+ connect(port: any): Promise<void>;
247
+ /**
248
+ * @returns {Promise<void>}
249
+ */
250
+ poll(): Promise<void>;
251
+ }
@@ -0,0 +1,7 @@
1
+
2
+ import * as wasm from "./lumina_node_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./lumina_node_wasm_bg.js";
4
+ __wbg_set_wasm(wasm);
5
+ export * from "./lumina_node_wasm_bg.js";
6
+
7
+ wasm.__wbindgen_start();