Files
nym/nym-browser-extension
mfahampshire cf3fd00350 Max/crates io prep v2 (#6270)
* - standardise versions for all nym-sdk workspace dependencies
- prepend sqlx-pool-guard with 'nym-'

* Test remove nym-api from deps

* Add oneliner to client_pool doc comments

* Add note to commented out docs.rs link in sdk

* remove nym-api from script

* add publishing file

* bring non-binary / contract / tools into workspace version

* added more info to publishing.md

* make deps workspace version

* remove uploaded sphinx-types crate from script

* remove erroueously included ignore-defaults

* add zeroise to feature

* chore: Release

* add topology to batch

* more cargo versioning

* more cargo versioning - wasm utils

* more cargo versioning - wasm utils

* Add publish=false to manifest for cargo workspaces / crates.io
publishing exclusion

* remove script now switched to manifest based exclusion

* rename import based on rename of contracts-common dep

* Making workspace versions for publication + removing unnecessary crates
from publication

* Remove OOD info from publishing sdk guide

* rename contract imports + remove package

* temp commit: continuing with removal of path from cargo manifest and
replacing with workspace version import for publication

* continuing with cargo.toml updates

* dryrun only erroring on known version problem crates

* remove old published-crates file

* Minor comment change

* remove default features warning

* Additional info on workspace dep comment re publish list

* Add missing description to cargo.toml

* Fix missing feature flags

* Add missing descriptions

* Fix remaining path import

* Add workspace repo / homepage / documentation links to cargo.toml files

* remove workspace version from excluded crate

* Remove todo descriptions

* Minor comment change

* add homepage etc

* move from bls git import to nym_bls_fork crate

* Modify rest of imports from path to workspace import, excluding binaries

* add directory/homepage info

* fix cargo fmt

* add notes to gitignore

* better solution to contracts/ experiment

* wasm -> nym_wasm crate renaming

* fix fatfinger

* add metadata to ecash cargo.toml

* stub publishing guide

* fix misrevolved netlink- version

* Fixes and block publication of rebase re: LP

* first pass @ workflows
2026-01-19 13:19:45 +00:00
..
2026-01-19 13:19:45 +00:00
2025-06-11 17:15:20 +02:00
2025-06-11 17:15:20 +02:00

Nym Browser Extension Storage

A WebAssembly-based storage component for securely managing mnemonics in extensions. This component provides encrypted storage functionality using IndexedDB with password-based encryption.

Overview

This storage component is built in Rust and compiled to WebAssembly, providing:

  • Secure mnemonic storage: Password-encrypted storage of BIP39 mnemonics
  • IndexedDB integration: Browser-native persistent storage
  • Multiple account support: Store and manage multiple mnemonic phrases with custom names
  • Type-safe API: Promise-based JavaScript API with proper error handling

Getting Started

Prerequisites

  • Rust (latest stable)
  • wasm-pack tool for building WebAssembly
  • Node.js (for the demo server)

Building

cd storage
make wasm-pack

This will compile the Rust code to WebAssembly and generate the necessary JavaScript bindings.

Example Usage

See the internal-dev example for complete usage examples.

Basic usage:

import init, { ExtensionStorage, set_panic_hook } from "@nymproject/extension-storage"

// Initialize the WASM module first
await init();

// Set up better error handling
set_panic_hook();

// Create storage instance with password
const storage = await new ExtensionStorage("your-secure-password");

// Store a mnemonic
const mnemonic = "your twenty four word mnemonic phrase goes here...";
await storage.store_mnemonic("my-wallet", mnemonic);

// Read a mnemonic
const retrievedMnemonic = await storage.read_mnemonic("my-wallet");

// Check if a mnemonic exists
const exists = await storage.has_mnemonic("my-wallet");

// Get all stored mnemonic keys
const allKeys = await storage.get_all_mnemonic_keys();

// Remove a mnemonic
await storage.remove_mnemonic("my-wallet");

Development

To run the internal development example:

cd storage

make demo

# Option 2: Manual server setup
cd internal-dev && node serve.js

# Then open http://localhost:8000 in your browser

Note: The demo requires a server that properly serves WASM files with application/wasm MIME type. The Node.js server is recommended as it handles MIME types more reliably.

API Reference

Initialization

  • init() - Required: Initialize the WASM module before using other functions

Constructor

  • new ExtensionStorage(password: string) - Creates a new storage instance with the given password

Static Methods

  • ExtensionStorage.exists() - Check if storage database exists

Instance Methods

  • store_mnemonic(name: string, mnemonic: string) - Store a mnemonic with the given name
  • read_mnemonic(name: string) - Retrieve a mnemonic by name (returns null if not found)
  • has_mnemonic(name: string) - Check if a mnemonic with the given name exists
  • get_all_mnemonic_keys() - Get all stored mnemonic names
  • remove_mnemonic(name: string) - Remove a mnemonic by name

Error Handling

  • set_panic_hook() - Set up better stack traces for Rust panics in development

Security Features

  • Password-based encryption: All data is encrypted using the provided password
  • BIP39 validation: Mnemonics are validated before storage
  • Secure memory handling: Sensitive data is zeroed from memory when no longer needed
  • Browser sandbox: Runs within the browser's security model

Architecture

The storage component consists of:

  • Rust core (src/storage.rs): Main storage implementation with encryption
  • WASM bindings (src/lib.rs): WebAssembly interface layer
  • Error handling (src/error.rs): Comprehensive error types
  • Build configuration (Cargo.toml, Makefile): Build and dependency management

Important Notes

  1. WASM Initialization: Always call await init() before using any other functions
  2. MIME Types: The demo requires a server that properly serves WASM files
  3. Browser Compatibility: Requires modern browsers with WebAssembly support
  4. Module Loading: Uses ES modules - ensure your build system supports them