Account Reference

The full Account surface — per-account vs workspace-shared passwords, tryUnlock/resetPassword, setDefaultNetwork, lock/drop — plus the AccountOrgType, AccountCollection and WalletCollection types.

This page documents the whole Account surface shared by both kinds. The kind-specific methods — deriveWallets / sliceWallets / dumpMnemonic (HD) and importPrivateKey (PK) — are covered in HD Accounts and PK Accounts.

Properties

PropertyTypeNotes
slugSlugRead-only. Derived from displayName at creation and never renamed. Also the on-disk record name.
displayNamestringThe human name. Change it with rename() / setDisplayName().
organizationTypeAccountOrgTypeRead-only. "HD" or "PK".
hasOwnPasswordbooleanRead-only. true if the account has its own password; false if it shares the workspace password.
defaultNetworkSlugRead-only getter. The default network slug. Change it with setDefaultNetwork().
lockedbooleanRead-only getter. true until the account is unlocked.
walletsWalletCollectionRead-only. The account's wallets (see below).
disabledSlotsReadonlyArray<{ from: number; to: number }>HD only. Retired BIP-32 index ranges; undefined when none.
encryptionAlgorithmstringThe seal algorithm for this record (e.g. aes-gcm).
signaturestringA persisted-shape field kept for backward compatibility; new records write an empty marker.

Sessions and passwords

Passwords: per-account vs shared

Each account carries its own encryption password by default (hasOwnPassword: true, the default in accounts.create). Set hasOwnPassword: false at creation to share the workspace password instead.

ModehasOwnPasswordCreated withUnlocked with
Own passwordtrue (default)any password you choosetryUnlock(itsPassword)
Sharedfalsethe workspace password (required)tryUnlock() — falls back to the workspace password

tryUnlock

tryUnlock(password?: string): Promise<this>

Unlocks the account and returns it. A wrong password rejects with BAD_PASSWORD. For a shared-password account, calling tryUnlock() with no argument uses the workspace password. Concurrent calls with the same password share one derivation.

unlock.ts
sub.lock();
sub.locked; // true

await sub.tryUnlock("wrong");   // → WativeError { code: "BAD_PASSWORD" }
await sub.tryUnlock("sub-pwd"); // resolves; sub.locked === false

checkPassword

checkPassword(password: string): Promise<boolean>

Verifies a password without changing the lock state. Returns false for a wrong password (rather than throwing).

resetPassword

resetPassword(oldPassword: string, newPassword: string): Promise<this>

Re-seals the mnemonic and every address ciphertext under a new password. After it resolves, the old password no longer opens the account.

reset-password.ts
await sub.resetPassword("sub-pwd", "new-sub-pwd");
sub.lock();

await sub.tryUnlock("sub-pwd");     // → WativeError { code: "BAD_PASSWORD" }
await sub.tryUnlock("new-sub-pwd"); // resolves

lock

lock(): void

Synchronous. Wipes in-memory secrets immediately. After lock(), account.locked is true. Locking the whole workspace with ws.lock() locks every account it holds.

Default network

setDefaultNetwork(value: NetworkLike): Promise<void>

NetworkLike accepts several forms, all resolved to the network's slug:

FormExampleResolves to (defaultNetwork)
Slug"base""base"
Chain id8453"base"
Hex chain id"0xa""optimism"
Network instanceNetwork.Arbitrum"arbitrum"
default-network.ts
import { Network } from "wative-core";

await acc.setDefaultNetwork("base");        acc.defaultNetwork; // "base"
await acc.setDefaultNetwork(8453);          acc.defaultNetwork; // "base"
await acc.setDefaultNetwork("0xa");         acc.defaultNetwork; // "optimism"
await acc.setDefaultNetwork(Network.Solana); acc.defaultNetwork; // "solana"

An unknown network — a slug not registered with the workspace, or an unknown chain id — rejects with UNSUPPORTED_NETWORK. The choice persists across lock and reopen. See Networks for the resolver and built-in networks.

Renaming and dropping

MethodSignatureNotes
renamerename(displayName: string): Promise<void>Changes the display name (4–64 chars). The slug is fixed and does not change.
setDisplayNamesetDisplayName(displayName: string): Promise<void>Alias of rename.
dropdrop(): Promise<void>Removes the whole account from the workspace and wipes its keys.
filterAddressfilterAddress(network?: NetworkLike, addr?: string): Address | nullIn-memory lookup. Requires at least one argument; an empty-string argument is a PARAMETER_ERROR.

HD-only disabled slots

On HD accounts, setDisabledAddressNos(addressNos) and setDisabledSlots(slots) retire BIP-32 indices so deriveWallets never re-derives them. Both are additive (they only extend the retired set) and throw UNSUPPORTED_OP on a PK account.

setDisabledAddressNos(addressNos: ReadonlyArray<number>): Promise<void>
setDisabledSlots(slots: ReadonlyArray<{ from: number; to: number }>): Promise<void>

Types

AccountOrgType

type AccountOrgType = "HD" | "PK";

AccountCollection

ws.accounts is an AccountCollection — a read-only array of Account with extra methods.

interface AccountCollection extends ReadonlyArray<Account> {
  create(
    displayName: string,
    password: string,
    secret: string,
    defaultNetwork?: NetworkLike,
    opts?: { kind?: AccountOrgType; hasOwnPassword?: boolean },
  ): Promise<Account>;
  add(account: Account): Promise<Account>;
  drop(account: Account): Promise<void>;
  bySlug(slug: Slug): Account | null;
}
  • add adopts an existing Account into this workspace (a copy-in); the account's networks must exist here, and a shared-password account's secrets must open with this workspace's password.
  • drop removes an account this workspace holds and wipes its keys.
  • bySlug returns the live account for a slug, or null.

WalletCollection

account.wallets is a WalletCollection.

interface WalletCollection extends ReadonlyArray<Wallet> {
  add(wallet: Wallet): Promise<Wallet>;
  drop(wallet: Wallet): Promise<void>;
  byId(id: number): Wallet | null;
}

drop refuses the account's last wallet with UNSUPPORTED_OP. See Wallets & Addresses for the Wallet and Address surface.

Damaged records

A record that is on disk but cannot be decrypted is withheld from ws.accounts so one corrupt file cannot deny access to every other account. Those names are still reported — as a read-only list on the workspace, not the account:

ws.damagedAccountSlugs; // ReadonlyArray<string>

Errors thrown across this surface use WativeError with a .code — see Errors.

Last updated on