API reference › @evolu/common › Type › Mnemonic

type Mnemonic = string &
  Brand<"Trimmed"> &
  Brand<"MinLength1"> &
  Brand<"Mnemonic">;

Defined in: packages/common/src/Type.ts:9943

A valid English BIP39 mnemonic in its canonical spelling.

It accepts only lowercase ASCII words separated by single spaces, so each mnemonic has one spelling and is also a NonEmptyTrimmedString. Other spellings, such as words separated by no-break spaces or written with fullwidth letters, are rejected; convert such input to NFKD and separate its words with single spaces before validating it.

A mnemonic is a secret, so every rejected string fails with a MnemonicError that omits it. A non-string fails with the String error, which keeps the input, so pass only strings.

Only this Type's own error omits the input. Types built around it keep the input in their own errors: a refinement such as regex applied to it, or the Null member of nullOr when all errors are collected, as with { errors: "all" } and always with Standard Schema validation.

Example

import { assertErr, assertOk, Mnemonic } from "@evolu/common";

const mnemonic =
  "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";

assertOk(Mnemonic.fromUnknown(mnemonic), mnemonic);
assertErr(Mnemonic.fromUnknown(`${mnemonic}\n`), { type: "Mnemonic" });