Audited & minimal implementation of BIP39 mnemonic phrases

Overview

scure-bip39

Secure, audited & minimal implementation of BIP39 mnemonic phrases.

Developed for js-ethereum-cryptography. Check out scure-bip32 if you need hierarchical deterministic wallets ("HD Wallets").

The library has been audited by Cure53 on Jan 5, 2022. Check out the audit PDF & URL. Before the audit it was called micro-base39.

Usage

npm install @scure/bip39

Or

yarn add @scure/bip39

API

import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
// Generate 12 random words
const mn = bip39.generateMnemonic(wordlist);
console.log(mn);

// Reversible; convert mnemonic to byte array
bip39.entropyToMnemonic(bip39.mnemonicToEntropy(mn, wordlist));

// Validate
bip39.validateMnemonic(mn, wordlist);

// Irreversible, there is no seedToMnemonic
bip39.mnemonicToSeedSync(mn, 'password');

This submodule contains the word lists defined by BIP39 for Czech, English, French, Italian, Japanese, Korean, 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 } from '@scure/bip39/wordlists/czech';
import { wordlist } from '@scure/bip39/wordlists/english';
import { wordlist } from '@scure/bip39/wordlists/french';
import { wordlist } from '@scure/bip39/wordlists/italian';
import { wordlist } from '@scure/bip39/wordlists/japanese';
import { wordlist } from '@scure/bip39/wordlists/korean';
import { wordlist } from '@scure/bip39/wordlists/simplified-chinese';
import { wordlist } from '@scure/bip39/wordlists/spanish';
import { wordlist } from '@scure/bip39/wordlists/traditional-chinese';

License

MIT License

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

You might also like...

Minimal Typescript / NextJS dApp template bootstrapped with wagmi Ethereum react hooks library.

Welcome to the NextJS wagmi starter template 👋 Looking to get up and running with a Typescript / NextJS dApp as quickly as possible? You're in the ri

Jan 4, 2023

Absolutely minimal view layer for building web interfaces.

Superfine Superfine is a minimal view layer for building web interfaces. Think Hyperapp without the framework—no state machines, effects, or subscript

Dec 29, 2022

Verbosely Documented, Minimal Starknet Contract Examples.

cairo-by-example • Verbosely Documented, Minimal Starknet Contract Examples. Cairo By Example deployed to https://cairo-by-example.xyz Developing Clon

Dec 6, 2022

A minimal, modern, generic, hot-reloading local web server to help web developers

eleventy-dev-server 🕚 ⚡️ 🎈 🐀 A minimal, modern, generic, hot-reloading local web server to help web developers. ➡ Documentation Please star Elevent

Dec 31, 2022

A minimal Node.js restarter.

minimon A minimal Node.js restarter based on zx. A modest nodemon replacement. Check out the blog post covering how it was written. Install npm i mini

Aug 9, 2022

Chronos is an ML Scheduler Tool, helping students to block and manage time with minimal manual intervention.

Chronos is an ML Scheduler Tool, helping students to block and manage time with minimal manual intervention.

Chronos (Currently in progress) Chronos is an ML Scheduler Tool, helping students to block and manage time with minimal manual intervention. It adapts

Aug 17, 2022

A minimal & self-hostable alternative to pastebin intended for code

minBin A minimal & self-hostable alternative to pastebin intended for code Use ⌨️ A public instance is available at https://bin.kio.dev/ Building 🔨 n

Dec 29, 2022

Minimal E-Commerce Store built with NextJS using Shopify Storefront API

NextJS Shopify Store Minimal E-Commerce Store built with NextJS using Shopify Storefront API Usage: run: npm install && npm run dev OR If you have doc

Nov 29, 2022

This the minimal to do list done using JavaScript, HTML and CSS.

This the minimal to do list done using JavaScript, HTML and CSS.

To_DO_List This the minimal to do list done using JavaScript, html and CSS In this project, we built a basic to do list website: plain JavaScript with

Mar 9, 2022
Comments
  • Can we override the random source?

    Can we override the random source?

    The official bip39 in JS supports overriding the random source. Can we override it here too?

    This can help use this library in environments where neither node crypto nor webcrypto is available.

    opened by CMCDragonkai 2
  • randomBytes error React Native

    randomBytes error React Native

    Hello! I am getting an error when I try to use this package on React Native 0.7 generating the mnemonic seed: image Using react-native-random-bytes instead of the one provided with the package kinda solves the issue, but that's of course something I really don't want to do.

    Am I missing something obvious here? :sweat_smile:

    opened by Skarsh 1
  • Update @noble/hashes

    Update @noble/hashes

    I'm not sure about why JavaScript package managers are so bad or maybe I'm missing something, but it seems that this package uses @noble/hashes 0.5.5 while other packages of the same suite are using @noble/hashes 0.5.7, which means the dependency is fetched and bundled twice?

    opened by fiatjaf 1
  •  Unexpected token * error

    Unexpected token * error

    Hi, I am trying to do truffle compile on my linux machine but i am getting below error. I tried reinstalling node modules and also tried reinstalling bip39 separaeltely but it didn't worked.

    /home/ubuntu///node_modules/@scure/bip39/index.js:54 if (!Array.isArray(wordlist) || wordlist.length !== 2 ** 11 || typeof wordlist[0] !== 'string') ^

    SyntaxError: Unexpected token * at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (/home/ubuntu///node_modules/@truffle/hdwallet-provider/node_modules/ethereum-cryptography/bip39/index.js:4:15)

    opened by NehaSaini100 0
Releases(1.1.0)
Owner
Paul Miller
Paul Miller
Please do not use this tracker to scam anyone! This is free and will be forever free. This tracking will never ask for seed phrases nor private keys. Keep safe!

CryptoBlades Tracker Related modules express - web application framework for node pug - template engine stylus - pre-processor CSS mongoose - nodejs o

null 355 Oct 13, 2022
This Plugin adds shortcodes with various prewritten phrases to improve quality and productivity of your writing.

Obsidian Phrasebank This Plugin adds shortcodes with various prewritten phrases to improve quality and productivity of your writing. Example :intro_pr

Viktor Bezdek 9 Jan 1, 2023
Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics.

Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics. Includes tags/categories support and extensive features for code blocks such as live preview, line numbers, and line highlighting.

Priya Chakraborty 0 Jan 29, 2022
Fast & minimal implementation of bech32, base64, base32, base16 & base58

micro-base Fast and minimal implementation of bech32, base64, base58, base32 & base16. Matches following specs: Bech32, Bech32m: BIP173, BIP350 Base16

Paul Miller 45 Jan 4, 2023
Minimal web3 implementation: call eth contracts directly from JS

micro-web3 Minimal web3 implementation: call eth contracts directly from JS Connect to any web3 server: host your own with execution layer client, or

Paul Miller 46 Dec 29, 2022
Minimal implementation of SLIP-0010 hierarchical deterministic (HD) wallets

micro-ed25519-hdkey Secure, minimal implementation of SLIP-0010 hierarchical deterministic (HD) wallets. Uses audited @noble/ed25519 under the hood. B

Paul Miller 11 Dec 25, 2022
Quickly create an interactive HTML mock-up by auto sourcing lorem ipsum/images generators, with minimal html markup, and no server side code

RoughDraft.js v0.1.5 Quickly mockup / prototype HTML pages with auto-generated content, without additional JavaScript or server side code. <section>

Nick Dreckshage 464 Dec 21, 2022
A minimal norui portfolio example built with NextJS and powered by Notion 🚀.

Minimal Norui A minimal norui portfolio example built with NextJS and powered by Notion ?? . Links Demo Site Documentation Minimal Norui Notion Databa

Joeylene Rivera 4 Nov 13, 2022
Minimal Phaser3 + Create React App template

Phaser 3 + Create React App template This project was bootstrapped with Create React App. What's included? - Check the preview Phaser 3 - overlaid can

Kuan-Hsuan (Kevin) Shen 53 Dec 26, 2022
Minimal template engine with compiled output for JavaScript.

@fnando/seagull Minimal template engine with compiled output for JavaScript. Installation This package is available as a NPM package. To install it, u

Nando Vieira 5 Mar 1, 2022