Generating Mnemonics
newMnemonic() for producing a fresh BIP-39 recovery phrase to back a new HD account before it is created.
newMnemonic() produces a fresh BIP-39 recovery phrase for backing a new HD account. Generate the phrase, show it to the user to write down, then pass it to accounts.create as the account's secret.
Usage
import { newMnemonic } from "wative-core";
const phrase = newMnemonic();
// e.g. "legal winner thank year wave sausage worth useful legal winner thank yellow"Signature
newMnemonic(wordCount?: 12 | 15 | 18 | 21 | 24): stringwordCount selects the BIP-39 phrase length and defaults to 12. Returns an English BIP-39 mnemonic as a single space-separated string. A non-standard count is a PARAMETER_ERROR.
Entropy
The phrase is drawn from platform-CSPRNG entropy (crypto.getRandomValues) — 16 bytes (128 bits) for the default 12 words, scaling to 32 bytes (256 bits) for 24 — encoded to the requested word count. The source is resolved per-runtime, so the function is isomorphic — it works the same in Node, the browser, and Edge runtimes.
The returned phrase is the only way to recover the account's keys. Capture it once, offer it to the user to record offline, and do not log or persist it in plaintext. Once the account exists, read the phrase back with dumpMnemonic() on the unlocked account, or export a portable, password-protected copy with sealMnemonic().
Backing a new HD account
Pass the phrase as the secret to accounts.create. A valid mnemonic is inferred as an HD account, so opts.kind is optional.
import { Workspace, newMnemonic } from "wative-core";
const ws = await Workspace.open({ path: "./my-wallet", password: "wsp-pwd" });
const phrase = newMnemonic();
const acc = await ws.accounts.create("Desk", "wsp-pwd", phrase);
acc.organizationType; // "HD"
acc.dumpMnemonic(); // === phrase (account must be unlocked)accounts.create validates the mnemonic checksum before sealing it. A malformed phrase is rejected with INVALID_MNEMONIC at create time rather than failing later at unlock. A phrase pasted with surrounding quotes or trailing punctuation — for example copied from a JSON line or a quoted note — is unwrapped before validation, so a wrapped-but-valid phrase is accepted.
Once the account exists, derive more wallets with deriveWallets(n) — see HD Accounts.