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 (3–32 characters) 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 | The default network slug. Has a getter and a public sync set defaultNetwork(value: NetworkLike), but the setter's persistence is best-effort (fire-and-forget); prefer the awaitable setDefaultNetwork(), which surfaces errors. |
locked | boolean | Read-only getter. true until the account is unlocked. |
wallets | WalletCollection | Read-only. The account's raw wallet collection (see below). For an enabled-only, natural-id view use getWalletList(). |
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.
Rotating a shared-password account (hasOwnPassword: false) also converts it to its own password: afterward hasOwnPassword is true and the account unlocks only with the new password — a no-argument tryUnlock() (which uses the workspace password) no longer opens it.
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 (3–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
Disabling a wallet slot is a soft, reversible marker on a BIP-32 derivation index. It does not change which indices deriveWallets produces and does not touch keys — it hides the wallet from getWalletList() (unless you ask for all) and blocks that wallet's use for signing, sending, and dumping its private key (they throw WALLET_DISABLED). All of these are HD-only and throw UNSUPPORTED_OP on a PK account.
| Method | Signature | Notes |
|---|---|---|
disableAddressNos | disableAddressNos(addressNos: ReadonlyArray<number>): Promise<void> | Mark the given indices disabled; merges with the current set. Each index is >= 1. |
disableSlots | disableSlots(slots: ReadonlyArray<{ from: number; to: number }>): Promise<void> | Mark index ranges disabled, e.g. [{ from: 14, to: 50 }]. |
enableAddressNos | enableAddressNos(addressNos: ReadonlyArray<number>): Promise<void> | Clear the marker on the given indices. |
enableSlots | enableSlots(slots: ReadonlyArray<{ from: number; to: number }>): Promise<void> | Clear the marker on the given ranges. |
getDisabledSlots | getDisabledSlots(): { from: number; to: number }[] | The current markers as a sorted array of disjoint { from, to } ranges; [] when none. |
await acc.disableSlots([{ from: 14, to: 50 }]);
await acc.disableAddressNos([2, 10, 80]);
acc.getDisabledSlots();
// [{ from: 2, to: 2 }, { from: 10, to: 10 }, { from: 14, to: 50 }, { from: 80, to: 80 }]
await acc.enableSlots([{ from: 20, to: 30 }]);
acc.getDisabledSlots();
// [{ from: 2, to: 2 }, { from: 10, to: 10 }, { from: 14, to: 19 }, { from: 31, to: 50 }, { from: 80, to: 80 }]A disabled marker is a list filter and a use-gate, not a derivation guard. deriveWallets ignores it, and sliceWallets clears the marker on any index it frees, so a freed index resets to fresh and can be re-derived.
Listing wallets
getWalletList(force?: boolean): Wallet[]Returns the account's wallets. By default only the enabled ones, each keeping its natural id — a disabled id is skipped, never renumbered, so disabling id 3 leaves the list as …, 2, 4, …. Pass force: true to include disabled wallets too, each carrying its wallet.disabled flag. account.wallets remains the raw, unfiltered collection.
await acc.disableAddressNos([2, 4]);
acc.getWalletList().map((w) => w.id); // [0, 1, 3, 5] — enabled only, natural ids
acc.getWalletList(true).map((w) => w.disabled); // [false, false, true, false, true, false]
acc.wallets.length; // 6 — raw, unaffected by the markersTypes
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 is private-key-only: on an HD account it throws UNSUPPORTED_OP (shorten the account with sliceWallets, or hide an index with disableSlots), and on a PK account it 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 read — it cannot be decrypted, or its stored name is no longer valid (for example a name from an older version that exceeds the 32-character limit) — is withheld from ws.accounts so one unreadable 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.