UNPKG

lumina-node-wasm

Version:

Browser compatibility layer for the Lumina node

55 lines (36 loc) 2.12 kB
# Lumina node wasm A compatibility layer for the [`Lumina`](https://github.com/eigerco/lumina) node to work within a browser environment and be operable with javascript. # Changelog You can find about the latest changes [here](https://github.com/eigerco/lumina/blob/main/node-wasm/CHANGELOG.md). # Example Starting lumina inside a dedicated worker ```javascript import { spawnNode, Network, NodeConfig } from "lumina-node"; const node = await spawnNode(); const mainnetConfig = NodeConfig.default(Network.Mainnet); await node.start(mainnetConfig); await node.waitConnected(); await node.requestHeadHeader(); ``` ## Manual setup `spawnNode` sets up a `DedicatedWorker` instance and runs `NodeWorker` there. If you want to set things up manually you need to connect client and worker using objects that have `MessagePort` interface. ```javascript import { Network, NodeClient, NodeConfig, NodeWorker } from "lumina-node"; const config = NodeConfig.default(Network.Mainnet); // client and worker accept any object with MessagePort like interface e.g. Worker const channel = new MessageChannel(); const worker = new NodeWorker(channel.port1); // note that this runs lumina in the current context (and doesn't create a new web-worker). Promise created with `.run()` never completes. const worker_promise = worker.run(); // client port can be used locally or transferred like any plain MessagePort const client = await new NodeClient(channel.port2); await client.waitConnected(); await client.requestHeadHeader(); ``` ## Rust API For comprehensive and fully typed interface documentation, see [lumina-node](https://docs.rs/lumina-node/latest/lumina_node/) and [celestia-types](https://docs.rs/celestia-types/latest/celestia_types/) documentation on docs.rs. You can see there the exact structure of more complex types, such as [`ExtendedHeader`](https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html). JavaScript API's goal is to provide similar interface to Rust when possible, e.g. `NodeClient` mirrors [`Node`](https://docs.rs/lumina-node/latest/lumina_node/node/struct.Node.html).