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
| Property | Type | Notes |
|---|---|---|
slug | Slug | Read-only. Derived from displayName at creation and never renamed. Also the on-disk record name. |
displayName | string | The human name. Change it with rename() / setDisplayName(). |
organizationType | AccountOrgType | Read-only. "HD" or "PK". |
hasOwnPassword | boolean | Read-only. true if the account has its own password; false if it shares the workspace password. |
defaultNetwork | Slug | Read-only getter. The default network slug. Change it with setDefaultNetwork(). |
locked | boolean | Read-only getter. true until the account is unlocked. |
wallets | WalletCollection | Read-only. The account's wallets (see below). |
disabledSlots | ReadonlyArray<{ from: number; to: number }> | HD only. Retired BIP-32 index ranges; undefined when none. |
encryptionAlgorithm | string | The seal algorithm for this record (e.g. aes-gcm). |
signature | string | A 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.
| Mode | hasOwnPassword | Created with | Unlocked with |
|---|---|---|---|
| Own password | true (default) | any password you choose | tryUnlock(itsPassword) |
| Shared | false | the workspace password (required) | tryUnlock() — falls back to the workspace password |
A hasOwnPassword: false account must be created with the workspace password, because its secrets are sealed under that password. Passing a different one is rejected with PARAMETER_ERROR.
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.
sub.lock();
sub.locked; // true
await sub.tryUnlock("wrong"); // → WativeError { code: "BAD_PASSWORD" }
await sub.tryUnlock("sub-pwd"); // resolves; sub.locked === falsecheckPassword
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.
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"); // resolvesresetPassword is safe to call on a locked account — it unlocks internally, rotates, and re-locks. A wrong oldPassword rejects with BAD_PASSWORD and changes nothing.
lock
lock(): voidSynchronous. 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:
| Form | Example | Resolves to (defaultNetwork) |
|---|---|---|
| Slug | "base" | "base" |
| Chain id | 8453 | "base" |
| Hex chain id | "0xa" | "optimism" |
Network instance | Network.Arbitrum | "arbitrum" |
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
| Method | Signature | Notes |
|---|---|---|
rename | rename(displayName: string): Promise<void> | Changes the display name (4–64 chars). The slug is fixed and does not change. |
setDisplayName | setDisplayName(displayName: string): Promise<void> | Alias of rename. |
drop | drop(): Promise<void> | Removes the whole account from the workspace and wipes its keys. |
filterAddress | filterAddress(network?: NetworkLike, addr?: string): Address | null | In-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;
}addadopts an existingAccountinto 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.dropremoves an account this workspace holds and wipes its keys.bySlugreturns the live account for a slug, ornull.
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>This getter lives on Workspace (ws.damagedAccountSlugs), not on an individual Account. It is deliberately read-only — the library reports the withheld names and the caller decides what to do, because deleting such a record is exactly the outcome withholding exists to prevent.
Errors thrown across this surface use WativeError with a .code — see Errors.