1.3.0 â€Ē Published 1 month ago

@scure/bip39 v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

scure-bip39

Audited & minimal JS implementation of BIP39 mnemonic phrases.

  • 🔒 Audited by an independent security firm
  • ðŸ”ŧ Tree-shaking-friendly: use only what's necessary, other code won't be included
  • ðŸ“Ķ ESM and common.js
  • ➰ Only 2 audited dependencies by the same author: noble-hashes and scure-base
  • ðŸŠķ 37KB with all deps bundled and 279KB with wordlists: much smaller than similar libraries

Check out scure-bip32 if you need hierarchical deterministic wallets ("HD Wallets").

This library belongs to scure

scure — audited micro-libraries.

Usage

npm install @scure/bip39

import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';

// Generate x random words. Uses Cryptographically-Secure Random Number Generator.
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);

// Reversible: Converts mnemonic string to raw entropy in form of byte array.
const ent = bip39.mnemonicToEntropy(mn, wordlist)

// Reversible: Converts raw entropy in form of byte array to mnemonic string.
bip39.entropyToMnemonic(ent, wordlist);

// Validates mnemonic for being 12-24 words contained in `wordlist`.
bip39.validateMnemonic(mn, wordlist);

// Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
await bip39.mnemonicToSeed(mn, 'password');
bip39.mnemonicToSeedSync(mn, 'password');

This submodule contains the word lists defined by BIP39 for Czech, English, French, Italian, Japanese, Korean, Portuguese, Simplified and Traditional Chinese, and Spanish. These are not imported by default, as that would increase bundle sizes too much. Instead, you should import and use them explicitly.

function generateMnemonic(wordlist: string[], strength?: number): string;
function mnemonicToEntropy(mnemonic: string, wordlist: string[]): Uint8Array;
function entropyToMnemonic(entropy: Uint8Array, wordlist: string[]): string;
function validateMnemonic(mnemonic: string, wordlist: string[]): boolean;
function mnemonicToSeed(mnemonic: string, passphrase?: string): Promise<Uint8Array>;
function mnemonicToSeedSync(mnemonic: string, passphrase?: string): Uint8Array;

All wordlists:

import { wordlist as czech } from '@scure/bip39/wordlists/czech';
import { wordlist as english } from '@scure/bip39/wordlists/english';
import { wordlist as french } from '@scure/bip39/wordlists/french';
import { wordlist as italian } from '@scure/bip39/wordlists/italian';
import { wordlist as japanese } from '@scure/bip39/wordlists/japanese';
import { wordlist as korean } from '@scure/bip39/wordlists/korean';
import { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese';
import { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist as spanish } from '@scure/bip39/wordlists/spanish';
import { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese';

Security

To audit wordlist content, run node scripts/fetch-wordlist.js.

The library has been independently audited:

The library was initially developed for js-ethereum-cryptography. At commit ae00e6d7, it was extracted to a separate package called micro-bip39. After the audit we've decided to use @scure NPM namespace for security.

License

MIT License

Copyright (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com)

@btq-js/keyring@kin-kinetic/keypair@kin-kinetic/sdk@stacks/clicasper-js-sdk-test-h2@mysten/sui.js@mogami/keypair@mogami/sdk@mogami/solanadb3js@infinitebrahmanuniverse/nolb-_scu@aldea/sdk-js@cdn-test/keypairviem-alphaviem-bundle-testviem-testviem-test-bundleviem-test10viem-test11viem-test12viem-test15viem-test16viem-test18viem-test19viem-test2viem-test20viem-test21viem-test22viem-test23viem-test24viem-test3viem-test4viem-test5viem-test6viem-test7viem-test8viem-test9viem@everything-registry/sub-chunk-814iso-filecoinharummolestiaejazz-browserjazz-browser-auth-passphrasejazz-react-auth-passphrasehsuijsmainnet-jsindora@b2network/viem@benfen/bfc.js@asoltys/nostr-tools@arcadecity/nostr-utils@aladas-org/cryptocalc0xweb@aptos-labs/ts-sdk@cashu/cashu-ts@cashu/crypto@chainsafe/bls-keygen@biteine/stacks-vanity@btq-js/btq-cli@btq-js/simple-wallet@btq-js/web3-provider@umb-network/concordium-web-sdk@thorswap-lib/toolbox-utxo@atala/prism-wallet-sdk@concordium/common-sdk@concordium/web-sdk@cmdcode/signer@cmdcode/use-signer@coinmasters/toolbox-utxo@curra/sdk@davidthegardens/vi3m@darthgus/viem@deliquid/crypto@designstringstudio/sui.js@djack-sdk/server@dolu/nostr-tools@evmts/viem@evolu/common@dzdidi_restored/nostr-tools@dydxprotocol/v4-client-js@dwallet-network/dwallet.js@gandlaf21/cashu-crypto@goalist/evolu-common@heemale/mango.js@heguro/nostr-tools-ws@fission-codes/ucan@fetcch/loyalty@fetcch/points@fleet-sdk/wallet@fewcha/aptos@flashbots/suave-viem@futpib/nostr-tools@fubhy/viem-test-bundle@hackbg/formati@hackbg/secretjs-esm@hackbg/4mat@izumuru/test-sdk@yubing744/rooch-sdk@xyo-network/cli@iyonger/aptos-web3-bip44.js
1.3.0

1 month ago

1.2.2

5 months ago

1.2.1

10 months ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago

1.0.0-rc1

2 years ago