@fl0rek/lumina-node v0.3.0
- Lumina node wasm
- Example
- Classes
- Enumerations
- Functions
- @fl0rek/lumina-node-wasm
@fl0rek/lumina-node-wasm • Docs
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();
Classes
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / BlockRange
Class: BlockRange
Constructors
new BlockRange()
new BlockRange():
BlockRange
Returns
Properties
end
end:
bigint
Defined in
lumina_node_wasm.d.ts:42
start
start:
bigint
Defined in
lumina_node_wasm.d.ts:45
Methods
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:39
toJSON()
toJSON():
Object
- Return copy of self without private attributes.
Returns
Object
Defined in
lumina_node_wasm.d.ts:34
toString()
toString():
string
Return stringified version of self.
Returns
string
Defined in
lumina_node_wasm.d.ts:38
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / ConnectionCountersSnapshot
Class: ConnectionCountersSnapshot
Constructors
new ConnectionCountersSnapshot()
new ConnectionCountersSnapshot():
ConnectionCountersSnapshot
Returns
Properties
num_connections
num_connections:
number
Defined in
lumina_node_wasm.d.ts:61
num_established
num_established:
number
Defined in
lumina_node_wasm.d.ts:64
num_established_incoming
num_established_incoming:
number
Defined in
lumina_node_wasm.d.ts:67
num_established_outgoing
num_established_outgoing:
number
Defined in
lumina_node_wasm.d.ts:70
num_pending
num_pending:
number
Defined in
lumina_node_wasm.d.ts:73
num_pending_incoming
num_pending_incoming:
number
Defined in
lumina_node_wasm.d.ts:76
num_pending_outgoing
num_pending_outgoing:
number
Defined in
lumina_node_wasm.d.ts:79
Methods
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:58
toJSON()
toJSON():
Object
- Return copy of self without private attributes.
Returns
Object
Defined in
lumina_node_wasm.d.ts:53
toString()
toString():
string
Return stringified version of self.
Returns
string
Defined in
lumina_node_wasm.d.ts:57
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NetworkInfoSnapshot
Class: NetworkInfoSnapshot
Constructors
new NetworkInfoSnapshot()
new NetworkInfoSnapshot():
NetworkInfoSnapshot
Returns
Properties
connection_counters
connection_counters:
ConnectionCountersSnapshot
Defined in
lumina_node_wasm.d.ts:95
num_peers
num_peers:
number
Defined in
lumina_node_wasm.d.ts:98
Methods
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:92
toJSON()
toJSON():
Object
- Return copy of self without private attributes.
Returns
Object
Defined in
lumina_node_wasm.d.ts:87
toString()
toString():
string
Return stringified version of self.
Returns
string
Defined in
lumina_node_wasm.d.ts:91
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NodeClient
Class: NodeClient
NodeClient
is responsible for steering NodeWorker
by sending it commands and receiving
responses over the provided port.
Constructors
new NodeClient()
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.
Parameters
• port: any
Returns
Defined in
lumina_node_wasm.d.ts:113
Methods
addConnectionToWorker()
addConnectionToWorker(
port
):Promise
\<void
>
Establish a new connection to the existing worker over provided port
Parameters
• port: any
Returns
Promise
\<void
>
Defined in
lumina_node_wasm.d.ts:119
close()
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.
Returns
Promise
\<void
>
Defined in
lumina_node_wasm.d.ts:282
connectedPeers()
connectedPeers():
Promise
\<any
[]>
Get all the peers that node is connected to.
Returns
Promise
\<any
[]>
Defined in
lumina_node_wasm.d.ts:165
eventsChannel()
eventsChannel():
Promise
\<BroadcastChannel
>
Returns a BroadcastChannel
for events generated by Node
.
Returns
Promise
\<BroadcastChannel
>
Defined in
lumina_node_wasm.d.ts:287
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:107
getHeaderByHash()
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
Parameters
• hash: string
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:240
getHeaderByHeight()
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
Parameters
• height: bigint
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:249
getHeaders()
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.
Errors
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
Parameters
• start_height?: bigint
• end_height?: bigint
Returns
Promise
\<any
[]>
Defined in
lumina_node_wasm.d.ts:267
getLocalHeadHeader()
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
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:231
getNetworkHeadHeader()
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
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:223
getSamplingMetadata()
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
Parameters
• height: bigint
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:276
isRunning()
isRunning():
Promise
\<boolean
>
Check whether Lumina is currently running
Returns
Promise
\<boolean
>
Defined in
lumina_node_wasm.d.ts:124
listeners()
listeners():
Promise
\<any
[]>
Get all the multiaddresses on which the node listens.
Returns
Promise
\<any
[]>
Defined in
lumina_node_wasm.d.ts:160
localPeerId()
localPeerId():
Promise
\<string
>
Get node's local peer ID.
Returns
Promise
\<string
>
Defined in
lumina_node_wasm.d.ts:135
networkInfo()
networkInfo():
Promise
\<NetworkInfoSnapshot
>
Get current network info.
Returns
Promise
\<NetworkInfoSnapshot
>
Defined in
lumina_node_wasm.d.ts:155
peerTrackerInfo()
peerTrackerInfo():
Promise
\<PeerTrackerInfoSnapshot
>
Get current PeerTracker
info.
Returns
Promise
\<PeerTrackerInfoSnapshot
>
Defined in
lumina_node_wasm.d.ts:140
requestHeaderByHash()
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
Parameters
• hash: string
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:189
requestHeaderByHeight()
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
Parameters
• height: bigint
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:198
requestHeadHeader()
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
Returns
Promise
\<any
>
Defined in
lumina_node_wasm.d.ts:180
requestVerifiedHeaders()
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
Parameters
• from_header: any
• amount: bigint
Returns
Promise
\<any
[]>
Defined in
lumina_node_wasm.d.ts:210
setPeerTrust()
setPeerTrust(
peer_id
,is_trusted
):Promise
\<void
>
Trust or untrust the peer with a given ID.
Parameters
• peer_id: string
• is_trusted: boolean
Returns
Promise
\<void
>
Defined in
lumina_node_wasm.d.ts:172
start()
start(
config
):Promise
\<void
>
Start a node with the provided config, if it's not running
Parameters
• config: NodeConfig
Returns
Promise
\<void
>
Defined in
lumina_node_wasm.d.ts:130
syncerInfo()
syncerInfo():
Promise
\<SyncingInfoSnapshot
>
Get current header syncing info.
Returns
Promise
\<SyncingInfoSnapshot
>
Defined in
lumina_node_wasm.d.ts:215
waitConnected()
waitConnected():
Promise
\<void
>
Wait until the node is connected to at least 1 peer.
Returns
Promise
\<void
>
Defined in
lumina_node_wasm.d.ts:145
waitConnectedTrusted()
waitConnectedTrusted():
Promise
\<void
>
Wait until the node is connected to at least 1 trusted peer.
Returns
Promise
\<void
>
Defined in
lumina_node_wasm.d.ts:150
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NodeConfig
Class: NodeConfig
Config for the lumina wasm node.
Constructors
new NodeConfig()
new NodeConfig():
NodeConfig
Returns
Properties
bootnodes
bootnodes:
string
[]
A list of bootstrap peers to connect to.
Defined in
lumina_node_wasm.d.ts:311
network
network:
Network
A network to connect to.
Defined in
lumina_node_wasm.d.ts:315
Methods
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:301
toJSON()
toJSON():
Object
- Return copy of self without private attributes.
Returns
Object
Defined in
lumina_node_wasm.d.ts:296
toString()
toString():
string
Return stringified version of self.
Returns
string
Defined in
lumina_node_wasm.d.ts:300
default()
static
default(network
):NodeConfig
Get the configuration with default bootnodes for provided network
Parameters
• network: Network
Returns
Defined in
lumina_node_wasm.d.ts:307
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / NodeWorker
Class: NodeWorker
Constructors
new NodeWorker()
new NodeWorker(
port_like_object
):NodeWorker
Parameters
• port_like_object: any
Returns
Defined in
lumina_node_wasm.d.ts:324
Methods
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:320
run()
run():
Promise
\<void
>
Returns
Promise
\<void
>
Defined in
lumina_node_wasm.d.ts:328
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / PeerTrackerInfoSnapshot
Class: PeerTrackerInfoSnapshot
Constructors
new PeerTrackerInfoSnapshot()
new PeerTrackerInfoSnapshot():
PeerTrackerInfoSnapshot
Returns
Properties
num_connected_peers
num_connected_peers:
bigint
Defined in
lumina_node_wasm.d.ts:344
num_connected_trusted_peers
num_connected_trusted_peers:
bigint
Defined in
lumina_node_wasm.d.ts:347
Methods
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:341
toJSON()
toJSON():
Object
- Return copy of self without private attributes.
Returns
Object
Defined in
lumina_node_wasm.d.ts:336
toString()
toString():
string
Return stringified version of self.
Returns
string
Defined in
lumina_node_wasm.d.ts:340
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / SyncingInfoSnapshot
Class: SyncingInfoSnapshot
Constructors
new SyncingInfoSnapshot()
new SyncingInfoSnapshot():
SyncingInfoSnapshot
Returns
Properties
stored_headers
stored_headers:
BlockRange
[]
Defined in
lumina_node_wasm.d.ts:363
subjective_head
subjective_head:
bigint
Defined in
lumina_node_wasm.d.ts:366
Methods
free()
free():
void
Returns
void
Defined in
lumina_node_wasm.d.ts:360
toJSON()
toJSON():
Object
- Return copy of self without private attributes.
Returns
Object
Defined in
lumina_node_wasm.d.ts:355
toString()
toString():
string
Return stringified version of self.
Returns
string
Defined in
lumina_node_wasm.d.ts:359
Enumerations
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / Network
Enumeration: Network
Supported Celestia networks.
Enumeration Members
Arabica
Arabica:
1
Arabica testnet.
Defined in
lumina_node_wasm.d.ts:18
Mainnet
Mainnet:
0
Celestia mainnet.
Defined in
lumina_node_wasm.d.ts:14
Mocha
Mocha:
2
Mocha testnet.
Defined in
lumina_node_wasm.d.ts:22
Private
Private:
3
Private local network.
Defined in
lumina_node_wasm.d.ts:26
Functions
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm / setup_logging
Function: setup_logging()
setup_logging():
void
Set up a logging layer that direct logs to the browser's console.
Returns
void
Defined in
lumina_node_wasm.d.ts:6
@fl0rek/lumina-node-wasm • Docs
@fl0rek/lumina-node-wasm
Enumerations
Classes
- BlockRange
- ConnectionCountersSnapshot
- NetworkInfoSnapshot
- NodeClient
- NodeConfig
- NodeWorker
- PeerTrackerInfoSnapshot
- SyncingInfoSnapshot