@bubolabs/wallet-wasm
v0.1.6
Published
Browser WASM SDK for bubo wallet offline chain adapters
Readme
@bubolabs/wallet-wasm
Browser WASM package for the bubo wallet offline chain adapters.
This package is intentionally separate from @bubolabs/wallet-rn-sdk.
The chain implementation is shared in Rust, while this package only owns the
browser binding and distribution layer.
Current browser targets: ETH, BTC, Solana, TON, TRON, NEAR, Cosmos, Cardano, Aptos, Polkadot, Dogecoin, Starknet, Stellar, Sui, and XRPL.
Install
For a browser app, install the published npm package:
npm install @bubolabs/wallet-wasmor:
yarn add @bubolabs/wallet-wasm
pnpm add @bubolabs/wallet-wasmConsumers do not need to compile Rust or run wasm-pack. The published package
already includes the generated .wasm files.
Usage
Use the package from a browser bundler that supports WebAssembly assets, such as Vite, Webpack, or Rollup.
import { init, eth, ton, tron } from "@bubolabs/wallet-wasm";
await init();
const mnemonic =
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
const ethWallet = eth.deriveWallet({
mnemonic,
account: 0,
index: 0,
});
const tonAddress = ton.deriveAddress({
mnemonic,
account: 0,
index: 0,
walletVersion: "v5r1",
});
const tronAddress = tron.deriveAddress({
mnemonic,
account: 0,
index: 0,
});
console.log({ ethWallet, tonAddress, tronAddress });All supported chains are exported as namespaces:
import {
aptos,
btc,
cardano,
cosmos,
dogecoin,
eth,
near,
polkadot,
solana,
starknet,
stellar,
sui,
ton,
tron,
xrpl,
} from "@bubolabs/wallet-wasm";Most chains support the same core calls where available:
const wallet = solana.deriveWallet({ mnemonic, account: 0, index: 0 });
const walletByPath = solana.deriveWalletWithPath({
mnemonic,
derivationPath: "m/44'/501'/0'/0'",
});
const signature = solana.signBytes({
mnemonic,
account: 0,
index: 0,
bytes: "00112233445566778899aabbccddeeff",
bytesEncoding: "hex",
});Use deriveAddressWithPath / deriveWalletWithPath when your app stores full
HD paths instead of { account, index }. Transaction helpers also expose
buildAndSignWithPath and signTxWithPath where the chain supports those
flows.
const tronOwner = tron.deriveAddressWithPath({
mnemonic,
derivationPath: "m/44'/195'/1'/0/0",
});
const signed = tron.signTxWithPath({
unsignedTx,
unsignedTxEncoding: "utf8",
mnemonic,
derivationPath: "m/44'/195'/1'/0/0",
});TON has two mnemonic modes. TON-native mnemonics do not have HD path semantics;
path-based TON derivation uses BIP-39 and hardened TON paths such as
m/44'/607'/0'.
Build From Source
Only build from source when developing this repository or changing Rust chain
code. From packages/wasm-sdk:
npm install
npm run buildThe build writes generated WASM artifacts to:
pkg/for the core module: all supported browser chains except Cardanopkg-cardano/for Cardano
Cardano is packaged as a separate WASM module because upstream
cardano-serialization-lib and Solana's wasm-enabled crates both export a
Transaction class through wasm-bindgen, which causes duplicate linker
symbols when they are placed in one .wasm file. The JavaScript wrapper keeps
one public API and routes Cardano calls to the Cardano module internally.
BTC support uses the bitcoin crate's secp256k1 backend. On macOS, install
LLVM via Homebrew if Apple's clang cannot compile wasm32-unknown-unknown:
brew install llvmThe package build script automatically uses /opt/homebrew/opt/llvm/bin/clang
or /usr/local/opt/llvm/bin/clang when present.
Example Project
This repository includes a browser example in example-wasm.
For local repository development, the example uses a file dependency:
{
"dependencies": {
"@bubolabs/wallet-wasm": "file:../packages/wasm-sdk"
}
}That lets the example consume the local package output. Build the WASM package first, then run the example:
cd packages/wasm-sdk
npm install
npm run build
cd ../../example-wasm
npm install
npm run devOpen:
http://127.0.0.1:4180/In a real app, use the published package instead:
npm install @bubolabs/wallet-wasmBoundary
- In scope: offline derivation, signing, transaction payload helpers, and inspection helpers exposed by the shared Rust adapters.
- Out of scope: RPC reads, transaction broadcast, online dApp/session orchestration.
- RN native packaging remains in
packages/rn-sdkand is not affected by this package.
