Skip to content
Docs

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-sqlite3

Signature

js
await GrayKeystore.create({
  sqlite: { path: "./gray-wallets.db" },
  password: pin,
})

// Low-level, Node.js only
import { openSqliteStore, wrapBetterSqlite3 } from "@gray3/keystore/node";

Parameters

FieldRequiredDescription
sqlite.pathNo`string` — filesystem path for the DB file (WAL journal mode)
sqlite.driverNo`SqliteDriver` instead of path: `{ exec(sql), prepare(sql) → { run, get, all }, transaction?(fn) }`. `wrapBetterSqlite3(db)` builds one from your own better-sqlite3 handle.
passwordNo`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 → unauthorized

Prefer client APIs (wallet.renameLabel, client.wallets.reset) in apps.

Throws

FieldRequiredDescription
unauthorizedNoWrong PIN on reset / secret ops.
not_foundNorenameWallet / get paths on missing id.
invalid_argumentNoBad sqlite options.
unsupported_capabilityNosqlite: { path } used outside Node.js (browser or React Native build).