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

new-mnemonic.ts
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): string

wordCount 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.

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.

mnemonic-to-account.ts
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)

Once the account exists, derive more wallets with deriveWallets(n) — see HD Accounts.

Last updated on