Keystore
Node adapter
File SQLite keystore for Node and large wallet counts.
Overview
Recommended Node.js backend: a SQLite file via sqlite: { path }, backed by better-sqlite3. The driver is an optional peer dependency, so install it yourself.
Install
bash
npm install @gray3/keystore better-sqlite3Signature
js
await GrayKeystore.create({
sqlite: { path: "./gray-wallets.db" },
password: pin,
})
// Low-level, Node.js only
import { openSqliteStore, wrapBetterSqlite3 } from "@gray3/keystore/node";Parameters
| Field | Required | Description |
|---|---|---|
| sqlite.path | No | `string` — filesystem path for the DB file (WAL journal mode) |
| sqlite.driver | No | `SqliteDriver` instead of path: `{ exec(sql), prepare(sql) → { run, get, all }, transaction?(fn) }`. `wrapBetterSqlite3(db)` builds one from your own better-sqlite3 handle. |
| password | No | `string` — when encryption enabled (default) |
Response
Promise<GrayKeystore> implementing GrayStorage (listWallets, getWallet, putWallet, deleteWallet, …).
Usage
js
import { GrayKeystore } from "@gray3/keystore";
import { GrayClient } from "@gray3/client";
const keystore = await GrayKeystore.create({
sqlite: { path: "./gray-wallets.db" },
password: pin,
});
const client = await GrayClient.create({ storage: keystore });
// Your own better-sqlite3 handle
import Database from "better-sqlite3";
import { wrapBetterSqlite3 } from "@gray3/keystore/node";
const keystore = await GrayKeystore.create({
sqlite: { driver: wrapBetterSqlite3(new Database("./gray-wallets.db")) },
password: pin,
});Storage methods
js
await ks.listWallets() // GrayWalletMeta[] — ok while locked
await ks.listAccounts(walletId) // plaintext account rows — no decrypt
await ks.getWallet(id) // full snapshot — needs unlock (via client password)
await ks.putWallet(snapshot)
await ks.deleteWallet(id)
await ks.renameWallet(walletId, label) // throws not_found
await ks.reset({ password }) // wipe all; wrong PIN → unauthorizedPrefer client APIs (wallet.renameLabel, client.wallets.reset) in apps.
Throws
| Field | Required | Description |
|---|---|---|
| unauthorized | No | Wrong PIN on reset / secret ops. |
| not_found | No | renameWallet / get paths on missing id. |
| invalid_argument | No | Bad sqlite options. |
| unsupported_capability | No | sqlite: { path } used outside Node.js (browser or React Native build). |