- Lumina node wasm
- Example
- Classes
- Enumerations
- Functions
- @fl0rek/lumina-node-wasm
@fl0rek/lumina-node-wasm • Docs
A compatibility layer for the Lumina
node to
work within a browser environment and be operable with javascript.
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();
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();
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / BlockRange
new BlockRange():
BlockRange
end:
bigint
lumina_node_wasm.d.ts:42
start:
bigint
lumina_node_wasm.d.ts:45
free():
void
void
lumina_node_wasm.d.ts:39
toJSON():
Object
- Return copy of self without private attributes.
Object
lumina_node_wasm.d.ts:34
toString():
string
Return stringified version of self.
string
lumina_node_wasm.d.ts:38
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / ConnectionCountersSnapshot
new ConnectionCountersSnapshot():
ConnectionCountersSnapshot
num_connections:
number
lumina_node_wasm.d.ts:61
num_established:
number
lumina_node_wasm.d.ts:64
num_established_incoming:
number
lumina_node_wasm.d.ts:67
num_established_outgoing:
number
lumina_node_wasm.d.ts:70
num_pending:
number
lumina_node_wasm.d.ts:73
num_pending_incoming:
number
lumina_node_wasm.d.ts:76
num_pending_outgoing:
number
lumina_node_wasm.d.ts:79
free():
void
void
lumina_node_wasm.d.ts:58
toJSON():
Object
- Return copy of self without private attributes.
Object
lumina_node_wasm.d.ts:53
toString():
string
Return stringified version of self.
string
lumina_node_wasm.d.ts:57
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NetworkInfoSnapshot
new NetworkInfoSnapshot():
NetworkInfoSnapshot
connection_counters:
ConnectionCountersSnapshot
lumina_node_wasm.d.ts:95
num_peers:
number
lumina_node_wasm.d.ts:98
free():
void
void
lumina_node_wasm.d.ts:92
toJSON():
Object
- Return copy of self without private attributes.
Object
lumina_node_wasm.d.ts:87
toString():
string
Return stringified version of self.
string
lumina_node_wasm.d.ts:91
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NodeClient
NodeClient
is responsible for steering NodeWorker
by sending it commands and receiving
responses over the provided port.
new NodeClient(
port
):NodeClient
Create a new connection to a Lumina node running in NodeWorker
. Provided port
is
expected to have MessagePort
-like interface for sending and receiving messages.
• port: any
lumina_node_wasm.d.ts:113
addConnectionToWorker(
port
):Promise
<void
>
Establish a new connection to the existing worker over provided port
• port: any
Promise
<void
>
lumina_node_wasm.d.ts:119
close():
Promise
<void
>
Requests SharedWorker running lumina to close. Any events received afterwards wont be processed and new NodeClient needs to be created to restart a node.
Promise
<void
>
lumina_node_wasm.d.ts:282
connectedPeers():
Promise
<any
[]>
Get all the peers that node is connected to.
Promise
<any
[]>
lumina_node_wasm.d.ts:165
eventsChannel():
Promise
<BroadcastChannel
>
Returns a [BroadcastChannel
] for events generated by [Node
].
Promise
<BroadcastChannel
>
lumina_node_wasm.d.ts:287
free():
void
void
lumina_node_wasm.d.ts:107
getHeaderByHash(
hash
):Promise
<any
>
Get a synced header for the block with a given hash.
Returns a javascript object with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
• hash: string
Promise
<any
>
lumina_node_wasm.d.ts:240
getHeaderByHeight(
height
):Promise
<any
>
Get a synced header for the block with a given height.
Returns a javascript object with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
• height: bigint
Promise
<any
>
lumina_node_wasm.d.ts:249
getHeaders(
start_height
?,end_height
?):Promise
<any
[]>
Get synced headers from the given heights range.
If start of the range is undefined (None), the first returned header will be of height 1. If end of the range is undefined (None), the last returned header will be the last header in the store.
If range contains a height of a header that is not found in the store.
Returns an array of javascript objects with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
• start_height?: bigint
• end_height?: bigint
Promise
<any
[]>
lumina_node_wasm.d.ts:267
getLocalHeadHeader():
Promise
<any
>
Get the latest locally synced header.
Returns a javascript object with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
Promise
<any
>
lumina_node_wasm.d.ts:231
getNetworkHeadHeader():
Promise
<any
>
Get the latest header announced in the network.
Returns a javascript object with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
Promise
<any
>
lumina_node_wasm.d.ts:223
getSamplingMetadata(
height
):Promise
<any
>
Get data sampling metadata of an already sampled height.
Returns a javascript object with given structure: https://docs.rs/lumina-node/latest/lumina_node/store/struct.SamplingMetadata.html
• height: bigint
Promise
<any
>
lumina_node_wasm.d.ts:276
isRunning():
Promise
<boolean
>
Check whether Lumina is currently running
Promise
<boolean
>
lumina_node_wasm.d.ts:124
listeners():
Promise
<any
[]>
Get all the multiaddresses on which the node listens.
Promise
<any
[]>
lumina_node_wasm.d.ts:160
localPeerId():
Promise
<string
>
Get node's local peer ID.
Promise
<string
>
lumina_node_wasm.d.ts:135
networkInfo():
Promise
<NetworkInfoSnapshot
>
Get current network info.
Promise
<NetworkInfoSnapshot
>
lumina_node_wasm.d.ts:155
peerTrackerInfo():
Promise
<PeerTrackerInfoSnapshot
>
Get current [PeerTracker
] info.
Promise
<PeerTrackerInfoSnapshot
>
lumina_node_wasm.d.ts:140
requestHeaderByHash(
hash
):Promise
<any
>
Request a header for the block with a given hash from the network.
Returns a javascript object with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
• hash: string
Promise
<any
>
lumina_node_wasm.d.ts:189
requestHeaderByHeight(
height
):Promise
<any
>
Request a header for the block with a given height from the network.
Returns a javascript object with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
• height: bigint
Promise
<any
>
lumina_node_wasm.d.ts:198
requestHeadHeader():
Promise
<any
>
Request the head header from the network.
Returns a javascript object with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
Promise
<any
>
lumina_node_wasm.d.ts:180
requestVerifiedHeaders(
from_header
,amount
):Promise
<any
[]>
Request headers in range (from, from + amount] from the network.
The headers will be verified with the from
header.
Returns an array of javascript objects with given structure: https://docs.rs/celestia-types/latest/celestia_types/struct.ExtendedHeader.html
• from_header: any
• amount: bigint
Promise
<any
[]>
lumina_node_wasm.d.ts:210
setPeerTrust(
peer_id
,is_trusted
):Promise
<void
>
Trust or untrust the peer with a given ID.
• peer_id: string
• is_trusted: boolean
Promise
<void
>
lumina_node_wasm.d.ts:172
start(
config
):Promise
<void
>
Start a node with the provided config, if it's not running
• config: NodeConfig
Promise
<void
>
lumina_node_wasm.d.ts:130
syncerInfo():
Promise
<SyncingInfoSnapshot
>
Get current header syncing info.
Promise
<SyncingInfoSnapshot
>
lumina_node_wasm.d.ts:215
waitConnected():
Promise
<void
>
Wait until the node is connected to at least 1 peer.
Promise
<void
>
lumina_node_wasm.d.ts:145
waitConnectedTrusted():
Promise
<void
>
Wait until the node is connected to at least 1 trusted peer.
Promise
<void
>
lumina_node_wasm.d.ts:150
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NodeConfig
Config for the lumina wasm node.
new NodeConfig():
NodeConfig
bootnodes:
string
[]
A list of bootstrap peers to connect to.
lumina_node_wasm.d.ts:311
network:
Network
A network to connect to.
lumina_node_wasm.d.ts:315
free():
void
void
lumina_node_wasm.d.ts:301
toJSON():
Object
- Return copy of self without private attributes.
Object
lumina_node_wasm.d.ts:296
toString():
string
Return stringified version of self.
string
lumina_node_wasm.d.ts:300
static
default(network
):NodeConfig
Get the configuration with default bootnodes for provided network
• network: Network
lumina_node_wasm.d.ts:307
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NodeWorker
new NodeWorker(
port_like_object
):NodeWorker
• port_like_object: any
lumina_node_wasm.d.ts:324
free():
void
void
lumina_node_wasm.d.ts:320
run():
Promise
<void
>
Promise
<void
>
lumina_node_wasm.d.ts:328
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / PeerTrackerInfoSnapshot
new PeerTrackerInfoSnapshot():
PeerTrackerInfoSnapshot
num_connected_peers:
bigint
lumina_node_wasm.d.ts:344
num_connected_trusted_peers:
bigint
lumina_node_wasm.d.ts:347
free():
void
void
lumina_node_wasm.d.ts:341
toJSON():
Object
- Return copy of self without private attributes.
Object
lumina_node_wasm.d.ts:336
toString():
string
Return stringified version of self.
string
lumina_node_wasm.d.ts:340
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / SyncingInfoSnapshot
new SyncingInfoSnapshot():
SyncingInfoSnapshot
stored_headers:
BlockRange
[]
lumina_node_wasm.d.ts:363
subjective_head:
bigint
lumina_node_wasm.d.ts:366
free():
void
void
lumina_node_wasm.d.ts:360
toJSON():
Object
- Return copy of self without private attributes.
Object
lumina_node_wasm.d.ts:355
toString():
string
Return stringified version of self.
string
lumina_node_wasm.d.ts:359
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / Network
Supported Celestia networks.
Arabica:
1
Arabica testnet.
lumina_node_wasm.d.ts:18
Mainnet:
0
Celestia mainnet.
lumina_node_wasm.d.ts:14
Mocha:
2
Mocha testnet.
lumina_node_wasm.d.ts:22
Private:
3
Private local network.
lumina_node_wasm.d.ts:26
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / setup_logging
setup_logging():
void
Set up a logging layer that direct logs to the browser's console.
void
lumina_node_wasm.d.ts:6
@fl0rek/lumina-node-wasm • Docs