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(): string

Takes no arguments and returns a 12-word English BIP-39 mnemonic as a single space-separated string.

Entropy

The phrase is drawn from 16 bytes (128 bits) of entropy from the platform CSPRNG (crypto.getRandomValues), encoded to 12 words. 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