@uledgerinc/typescript-sdk
v2.0.3
Published
ULedger TypeScript SDK - Built on Go SDK compiled to WebAssembly
Maintainers
Readme
ULedger TypeScript SDK
A high-performance WASM-powered SDK built on the ULedger Go SDK
The ULedger TypeScript SDK provides a modern, browser-safe and Node-compatible interface to ULedger cryptographic functions, wallet utilities, BIP-39 mnemonic tools, and transaction signing.
All cryptography is executed inside a WebAssembly module compiled from the official ULedger Go SDK, ensuring correctness, security, and identical behavior across environments.
Installation
npm install @uledgerinc/typescript-sdkThe SDK provides both ESM and CommonJS builds. You can import it in any environment:
ESM
import { getULedgerSDK } from "@uledgerinc/typescript-sdk";CommonJS
const { getULedgerSDK } = require("@uledgerinc/typescript-sdk");Initialization
Before calling any wallet, crypto, or transaction functions, you must initialize the WASM runtime.
This is done automatically by calling:
const sdk = await getULedgerSDK();This will:
Load the Go WebAssembly binary
Load the Go WASM runtime (wasm_exec.js)
Initialize exported functions
Return a fully-configured SDK instance
● Basic Usage Example import { getULedgerSDK } from "@uledgerinc/typescript-sdk";
async function main() { // Initialize the WASM-backed SDK const sdk = await getULedgerSDK();
// Get SDK metadata console.log(sdk.getInfo());
// Generate a new random wallet const wallet = sdk.generateWallet(); console.log("Wallet:", wallet.toJson(true));
// Generate a BIP39 mnemonic const mnemonic = sdk.generateMnemonic(); console.log("Mnemonic:", mnemonic);
// Restore a wallet from mnemonic const restored = sdk.walletFromMnemonic(mnemonic.mnemonic); console.log("Restored wallet:", restored.toJson(true));
// Sign a message const sig = sdk.signWithWallet(restored, "hello world"); console.log("Signature:", sig);
// Verify signature const verify = sdk.verifySignature(restored.publicKeyHex, "hello world", sig.signatureHex); console.log("Verified:", verify.valid); }
main();
● API Overview Initialization await getULedgerSDK(): ULedgerWASM
Loads WASM and returns an initialized instance.
Wallet Functions sdk.generateWallet(options?)
Generate a new wallet with optional parameters:
const wallet = sdk.generateWallet({ keyType: "secp256k1", // secp256k1 | ed25519 | mldsa87 | bls12377 entropy: 256, // 128–256 bits password: "", parent: "", });
sdk.walletFromMnemonic(mnemonic, options?)
Restore from BIP-39 phrase.
const wallet = sdk.walletFromMnemonic(mnemonic, { keyType: "secp256k1" });
sdk.walletFromHex(publicKeyHex, privateKeyHex)
Create a wallet from existing raw keys.
wallet.toJson(includePrivate = false)
Export wallet to JSON.
BIP-39 Utilities sdk.generateMnemonic(entropyBits?)
Returns:
{ mnemonic: string }
sdk.validateMnemonic(mnemonic)
Returns:
{ valid: boolean }
sdk.mnemonicToSeed(mnemonic, passphrase?)
Returns:
{ seedHex: string }
Crypto Functions sdk.signMessage(publicKeyHex, privateKeyHex, message)
Returns signature + hash.
sdk.signWithWallet(wallet, message)
Convenience wrapper.
sdk.verifySignature(publicKeyHex, message, signatureHex)
Returns:
{ valid: boolean }
sdk.hashMessage(message)
Returns:
{ hashHex: string }
Transaction Functions sdk.signTransactionInput(transactionInput, wallet, password?)
Signs a transaction input using Go’s internal hashing and commitment logic.
const signed = sdk.signTransactionInput(tx, wallet);
● Runtime Details Dual-module output
The package ships:
dist/esm → ESM modules dist/cjs → CommonJS modules dist/wasm → Shared wasm_exec.js + uledger-sdk.wasm
Both runtimes load the same WASM files from dist/wasm/.
Node, Bun, and Browser Support Environment Supported Notes Node ≥ 16 ✔ Full WASM + crypto support Bun ✔ Works in CJS or ESM mode Browser ✔ Requires bundler copying WASM assets Deno Partial Needs adapted WASM loader ● Error Handling
Most SDK functions throw a standard JavaScript Error when the underlying Go function returns { success: false, error: "..." }.
Always wrap calls in try/catch when handling user input.
● Contributing
This SDK is autogenerated from the ULedger Go SDK using WebAssembly. For development:
npm install npm run build
