toip.tools

type · Browser

Vault

@toip-tools/web-vaultView source
TypeScriptImport
import { type Vault } from "@toip-tools/web-vault";

Declaration

TypeScripttype
type Vault = ReturnType<typeof createVault>;

Properties

prefixrequired
string

Methods

accounts

TypeScriptSignature
accounts(): Account[];

No parameters.

Returns

Account[]

Stored accounts, or an empty list when the account record cannot be read or decoded.

removeAccount

TypeScriptSignature
removeAccount(id: string): Promise<void>;

Parameters

idrequired
string

Saved account ID to remove; an unknown ID is a no-op.

Returns

Promise<void>

Completion of attempted CryptoKey deletion. IndexedDB cleanup failures are swallowed.

createAccount

TypeScriptSignature
createAccount(name: string, how: Protection, seed?: Uint8Array): Promise<Unlocked>;

Parameters

namerequired
string

Display name, trimmed and limited to 60 characters.

howrequired
Protection

Passkey protection or a passphrase of at least eight characters.

seedoptional
Uint8Array<ArrayBufferLike>

Identity seed to restore, normally decoded with seedFromBackup; defaults to 32 random bytes.

Default: random(32)

Returns

Promise<Unlocked>

The account metadata, plaintext seed, and derived sealing key.

unlock

TypeScriptSignature
unlock(a: Account, passphrase?: string): Promise<Unlocked>;

Parameters

arequired
Account

Saved account metadata from accounts().

passphraseoptional
string | undefined

Required to decrypt a passphrase-protected account; unused for passkey protection.

Returns

Promise<Unlocked>

The account's plaintext seed and sealing key, also retained in the unlocked cache.

unlockedAccount

TypeScriptSignature
unlockedAccount(id: string): Unlocked | undefined;

Parameters

idrequired
string

Account ID to look up.

Returns

Unlocked | undefined

protect

TypeScriptSignature
protect(u: Unlocked, how: Protection): Promise<Unlocked>;

Parameters

urequired
Unlocked

Unlocked account whose seed will be protected.

howrequired
Protection

New passkey or passphrase protection.

Returns

Promise<Unlocked>

An updated saved account and cached unlocked handle with its sealing key.

lockAll

TypeScriptSignature
lockAll(): void;

No parameters.

Returns

void

passkeysAvailable

TypeScriptSignature
passkeysAvailable(): boolean;

No parameters.

Returns

boolean

readBlob

TypeScriptSignature
readBlob(u: Unlocked, name: string): Promise<Uint8Array | null>;

Parameters

urequired
Unlocked

Protected, unlocked account whose key decrypts the blob.

namerequired
string

Lowercase letters, digits, and dashes; seed, accounts, and keys are reserved.

Returns

Promise<Uint8Array<ArrayBufferLike> | null>

Decrypted bytes, or null when the blob is absent.

writeBlob

TypeScriptSignature
writeBlob(u: Unlocked, name: string, bytes: Uint8Array): Promise<void>;

Parameters

urequired
Unlocked

Protected, unlocked account whose key seals the blob.

namerequired
string

Valid nonreserved blob name, as required by readBlob.

bytesrequired
Uint8Array<ArrayBufferLike>

Plaintext bytes to save.

Returns

Promise<void>

Completion of encryption and storage.

readJson

TypeScriptSignature
readJson<T>(u: Unlocked, name: string): Promise<T | null>;

Parameters

urequired
Unlocked

Unlocked account; a sealing key is required when the stored value is encrypted.

namerequired
string

Valid nonreserved blob name.

Returns

Promise<T | null>

The parsed value, or null when absent. The generic type does not validate stored data.

writeJson

TypeScriptSignature
writeJson(u: Unlocked, name: string, value: unknown): Promise<void>;

Parameters

urequired
Unlocked

Unlocked account; call protect first when encryption is required.

namerequired
string

Valid nonreserved blob name.

valuerequired
unknown

JSON-serializable value to save.

Returns

Promise<void>

Completion of serialization, optional encryption, and storage.

removeBlob

TypeScriptSignature
removeBlob(a: Account, name: string): void;

Parameters

arequired
Account
namerequired
string

Returns

void

readState

TypeScriptSignature
readState<T>(u: Unlocked): Promise<T | null>;

Parameters

urequired
Unlocked

Unlocked account whose state is requested.

Returns

Promise<T | null>

Parsed state, or null when missing, unreadable, or unavailable without a sealing key.

writeState

TypeScriptSignature
writeState(u: Unlocked, value: unknown): Promise<void>;

Parameters

urequired
Unlocked
valuerequired
unknown

Returns

Promise<void>

putCryptoKey

TypeScriptSignature
putCryptoKey(a: Account, name: string, key: CryptoKey): Promise<void>;

Parameters

arequired
Account

Account that owns the key.

namerequired
string

Valid nonreserved key name.

keyrequired
CryptoKey

Browser CryptoKey to persist.

Returns

Promise<void>

Completion of the IndexedDB write transaction.

getCryptoKey

TypeScriptSignature
getCryptoKey(a: Account, name: string): Promise<CryptoKey | null>;

Parameters

arequired
Account

Account that owns the key.

namerequired
string

Valid nonreserved key name.

Returns

Promise<CryptoKey | null>

The stored key, or null when absent.

backupCode

TypeScriptSignature
backupCode(u: Unlocked): string;

Parameters

urequired
Unlocked

Unlocked account to back up.

Returns

string

seedFromBackup

TypeScriptSignature
seedFromBackup(code: string): Uint8Array | null;

Parameters

coderequired
string

Backup text, with optional surrounding whitespace.

Returns

Uint8Array<ArrayBufferLike> | null

A 32-byte seed, or null for another prefix or invalid seed encoding/length.

storageKey

The storage key of a blob, for data an app keeps outside the vault but wants removed with the account.

TypeScriptSignature
storageKey(name: string, did: string): string;

Parameters

namerequired
string
didrequired
string

Returns

string