10 releases (5 breaking)

new 0.7.0 Dec 3, 2024
0.6.1 Dec 2, 2024
0.6.0 Oct 29, 2024
0.5.2 Oct 21, 2024
0.1.0 Jan 17, 2024

#20 in Magic Beans

Download history 141/week @ 2024-08-20 12/week @ 2024-09-10 17/week @ 2024-09-17 183/week @ 2024-09-24 166/week @ 2024-10-01 181/week @ 2024-10-08 118/week @ 2024-10-15 62/week @ 2024-10-22 121/week @ 2024-10-29 12/week @ 2024-11-05 4/week @ 2024-11-19

137 downloads per month

Apache-2.0

290KB
6K SLoC

Lumina node wasm

A compatibility layer for the Lumina node to work within a browser environment and be operable with javascript.

Example

Starting lumina inside a dedicated worker

import { spawnNode, NodeConfig, Network } 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

Note that spawnNode implicitly calls wasm initialisation code. If you want to set things up manually, make sure to call the default export before using any of the wasm functionality.

import init, { NodeConfig, Network } from "lumina-node";

await init();
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 and celestia-types documentation on docs.rs. You can see there the exact structure of more complex types, such as ExtendedHeader. JavaScript API's goal is to provide similar interface to Rust when possible, e.g. NodeClient mirrors Node.

Dependencies

~0–40MB
~642K SLoC