Web Assembly Node (Browser/Deno etc.)

How to set up and run a node embedded within the WASM SDK.

Example


Node Configuration

The configuration for the node is almost the same as for an ordinary BV node, but with a few special considerations.

  1. An embedded node only works with direct communication using WebSockets.
  2. The embedded node will not have an address
  3. The database driver name has to be set to "sqlite3JS", in order to use the SQLite DB compiled to WASM.

Here you can see the relevant parts of the configuration file for the embedded node:

...
[Players.0]
  PublicKey = "local base64 encoded public key"
  
[Players.1]
  Address = "ws://localhost:9130"
  PublicKey = "remote base64 encoded public key"

[Database]
  DriverName = "sqlite3JS"
  DataSourceName = "test6.db"
  EncryptorMasterPassword = "master password for db encryption"
  
[MPCDirectServer]

...

Like wise the backend nodes need to be configured like this:


...
[Players.0]
PublicKey = "embedded node base64 encoded public key"

[Players.1]
Address = "ws://localhost:9013"
PublicKey = "server base64 encoded public key"

...

[MPCTCPServer]
Port = 9013

[MPCWebSocketServer]
Port = 9130

[SDKServer]
Port = 8093

Using the Configuration

When creating a client for interacting with the embedded node, you need to supply the node configuration, and optionally, the log configuration in string format.

let embeddedClient = await new TSM.EmbeddedClient(nodeConfig, logConfig);

If the log configuration is specified as the empty string, the log configuration will be read from the node configuration.

📘

CAVEAT

Be careful how you handle the node configuration, as it contains the master encryption password for the database.


Database

Only SQLite compiled to WASM is supported in the embedded node SQLite WASM/JS Subproject.

Browser

To use the SQLite DB in a browser, the most convenient way is to install it as an NPM package:

npm i @sqlite.org/sqlite-wasm

And then use a front end build tool like Vite.

Importing the DB:

import sqlite3InitModule from '@sqlite.org/sqlite-wasm';

Deno

Using Deno you need to download the files from https://sqlite.org/download.html (e.g. https://sqlite.org/2025/sqlite-wasm-3510100.zip), unpack them, and import as:

import * as sqlite3 from "../path-to-your-download/jswasm/sqlite3-bundler-friendly.mjs"

Backup/Restore and Storage

Since storage in the browser is volatile, you should make sure to always keep a backup of your local key shares.