Quick Start
Get encrypted local storage working in minutes.
Install
npm install @p47h/vault-js
Usage
import { VaultService } from "@p47h/vault-js";
// 1. Initialize (loads WASM engine)
const vault = new VaultService();
await vault.init();
// 2. Authenticate
// First time: Register (returns a recovery code - SAVE IT!)
const { did, recoveryCode } = await vault.register(
"correct horse battery staple"
);
console.log("⚠️ Save this recovery code:", recoveryCode);
// Returning user: Login
// await vault.login("correct horse battery staple");
// 3. Store & Retrieve Secrets
await vault.saveSecret("api_key", "sk-live-12345");
const key = await vault.getSecret("api_key");
console.log(key); // "sk-live-12345"
// 4. Lock when done
vault.lock();
API
| Method | Description |
|---|---|
vault.init() | Load WASM engine |
vault.register(password) | Create identity (returns recovery code) |
vault.login(password) | Unlock existing identity |
vault.saveSecret(key, value) | Store encrypted secret |
vault.getSecret(key) | Retrieve decrypted secret |
vault.lock() | Zeroize memory, end session |
vault.recoverAccount(options) | Restore access with recovery code |