Keystore
Expo adapter
expo-sqlite through sqlite: { expo }, or asyncKvAdapter for small wallet counts.
Overview
On Expo and React Native, pass an expo-sqlite database handle as sqlite: { expo }. The keystore wraps it internally. expo-sqlite is an optional peer dependency, so install it yourself. Bare React Native apps can use it once Expo Modules are installed, or use asyncKvAdapter for small wallet counts.
Install
bash
npx expo install expo-sqlite react-native-get-random-values
npm install @gray3/keystorereact-native-get-random-values must be imported before any @gray3/* module. The full setup, including the entry file and Metro configuration, is in Platforms: Expo.
Signature
js
import * as SQLite from "expo-sqlite";
import { GrayKeystore } from "@gray3/keystore";
await GrayKeystore.create({
sqlite: { expo: SQLite.openDatabaseSync("gray-wallets.db") },
password: pin,
});Parameters
| Field | Required | Description |
|---|---|---|
| sqlite.expo | No | `SQLiteDatabase` from `SQLite.openDatabaseSync(name)` (expo-sqlite 14 or later) |
| adapter | No | Alternative: `asyncKvAdapter({ getItem, setItem, removeItem, getAllKeys? })` over AsyncStorage or another async store |
| password | No | `string` — user PIN when encryption on. scrypt runs in JavaScript on Hermes. |
| encryptionKey | No | `Uint8Array` — 32-byte key kept in secure storage (for example expo-secure-store) instead of a PIN |
Response
Promise<GrayKeystore>
Usage
js
// SQLite (recommended)
const keystore = await GrayKeystore.create({
sqlite: { expo: SQLite.openDatabaseSync("gray-wallets.db") },
password: pin,
});
// Key-value (small wallet counts)
import AsyncStorage from "@react-native-async-storage/async-storage";
import { asyncKvAdapter } from "@gray3/keystore";
const kvKeystore = await GrayKeystore.create({
adapter: asyncKvAdapter({
getItem: (k) => AsyncStorage.getItem(k),
setItem: (k, v) => AsyncStorage.setItem(k, v),
removeItem: (k) => AsyncStorage.removeItem(k),
getAllKeys: () => AsyncStorage.getAllKeys(),
}),
password: pin,
});
const client = await GrayClient.create({ storage: keystore });
await client.wallets.create({ label: "Main", password: pin });Low-level helpers wrapExpoSqlite(db) and openExpoSqliteStore(db) are exported from @gray3/keystore/expo for custom setups.
Throws
| Field | Required | Description |
|---|---|---|
| invalid_argument | No | Store missing methods; encryption option conflicts. |
| unsupported_capability | No | sqlite: { path } or sqlite: { web } in a React Native build. |
| unauthorized | No | Wrong PIN on secret ops. |