Getting Started2
The default export of veilid_wasm.js
is bound to an async function called __wbg_init
. Await this to initialize the wasm runtime, but don’t use its return value.
First, call initialize_veilid_wasm
to set the panic hook - if veilid explodes, the output will go to the browser console.
Second, call initialize_veilid_core
. This sets up logging, and takes a serialized (stringified) json config. Here’s a typedef:
type VeilidLogLevel =
| 'Off'
| 'Error'
| 'Warn'
| 'Info'
| 'Debug'
| 'Trace';
type VeilidWASMConfig = {
logging: {
performance: {
enabled: boolean;
level: VeilidLogLevel;
logs_in_timings: boolean;
logs_in_console: boolean;
};
api: {
enabled: boolean;
level: VeilidLogLevel;
};
};
};
Third, await the async function startup_veilid_core
. This takes a callback, and another serialized config. The config is huge, so store it in a separate file. The callback receives serialized json events - typedef below.
Fourth - call attach
. This is non-async, non-blocking, and takes no parameters. This lets the core start talking on the network to find peers and do its thing.
When you’re done, it is polite, but not required, to call detach
.
Events Typedef
type Event = LogEvent | ConfigEvent | AttachmentEvent | NetworkEvent;
type LogEvent = {
kind: "Log";
log_level: VeilidLogLevel;
message: string;
backtrace: string | null;
};
// ConfigEvents just mirror your config back at you
type AttachmentEvent = {
kind: "Attachment";
state: "Attached" | "Detached";
public_internet_ready: boolean;
local_network_ready: boolean;
};
type TransferStats = {
// Numbers (bytes (per second)) as strings
total: string;
maximum: string;
average: string;
minimum: string;
};
type NetworkEvent = {
kind: "Network";
started: boolean;
bps_down: string; // number as a string
bps_up: string; // number as a string
peers: {
node_ids: string[];
peer_address: string; // protocol:address:port
peer_stats: {
time_added: string; // microseconds
rpc_stats: {
messages_sent: number;
messages_rcvd: number;
questions_in_flight: number;
last_question_ts: string; // microseconds
last_seen_ts: string // microseconds
first_consecutive_seen_ts: string;
recent_lost_answers: number;
failed_to_send: number;
};
latency: {
// All Microseconds
fastest: string;
average: string;
slowest: string;
};
transfer: {
up: TransferStats;
down: TransferStats;
};
}
}[];
};
Endpoints
Exports start around line 240
initialize_veilid_wasm
- Startup 1. Sets console panic hooks.initialize_veilid_core
- Startup 2. Sets up logging. Covered above.change_log_level
- Takes a string -VeilidLogLevel
from abovestartup_veilid_core
- Documented as aboveget_veilid_state
- looks interestingattach
- Attach to the networkdetach
- Get off the network without shutting downshutdown_veilid_core
- I assume this frees all allocated memory
Routing Contexts and DHT
There are a bunch of routing context functions. Looks like we need them for DHT.
- async
routing_context
- smells like a constructor, returns a number called “id” release_routing_context
: number - Takes an ID - releases it?routing_context_with_privacy
: number - who needs thatrouting_context_with_custom_privacy
: number looks complicatedrouting_context_with_sequencing
: number - not sure- async
routing_context_app_call
- RPC APPCALLid
: the id of a routing context; returned fromrouting_context
target
- Either a route id or a node idrequest
- B64 encoded, no padding, raw bytes to send
- async
routing_context_app_message
- RPC MESSAGEid
- routing context of choicetarget
- route id or node idmessage
- b64 nopadded message to yeet
- async
routing_context_create_dht_record
- This makes senseid
- routing contextschema
- string - json?kind
- hmmmm
- async
routing_context_open_dht_record
- What does this do?id
- routing contextkey
- string?writer
- string or undefined?
- async
routing_context_close_dht_record
- Why do I need to call this?id
key
- async
routing_context_delete_dht_record
- I have assumptionsid
key
- async
routing_context_get_dht_value
- DHT READ. Presumably you have to open first? - async
routing_context_set_dht_value
- DHT WRITE - async
routing_context_watch_dht_values
- async
routing_context_cancel_dht_watch
Private Routes
- new_private_route
- new_custom_private_route
- import_remote_private_route
- release_private_route
App call reply?
- app_call_reply
Table DB stuff
- open
- release
- delete
- get column count
- get keys
- transact
- release transaction
- commit transaction
- rollback transaction
- store transaction
- delete transaction
- store - just like, in general (id, column, key, value)
- load
- delete
Crypto Kinds
- valid_crypto_kinds - no args, returns a string?
- best_crypto_kind - no args, returns a number!
- verify_signatures
- generate_signatures
- generate_key_pair
- crypto_cached_dh - diffie hellman?
- crypto_compute_dh
- crypto_random_bytes
- number (kind) and number (length) params, returns a promise tho
- crypto_default_salt_length
- crypto_hash_password
- crypto_verify_password
- crypto_derive_shared_secret
- crypto_random_nonce:: number -> Promise
- crypto_random_shared_secret :: number -> promise
- crypto_generate_key_pair - difference from generate_key_pair???
- crypto_generate_hash : kind, string -> Promise
- this is probably b64 isn’t it
- crypto_validate_key_pair
- crypto_validate_hash
- crypto_distance
- crypto_sign
- crypto_verify - verifies a signature
- crypto_aead_overhead - need to learn what aead is
- crypto_decrypt_aead
- crypto_encrypt_aead
- crypto_crypt_no_auth - what it do?
Meta Functions
- debug : This is a big one! Takes a string (command), promise resolves to … idk
- veilid_version_string() -> string; its empty tho :(
- veilid_version -> any ???