# @metamask/scure-bip39

> MetaMask fork of @scure/bip39: a secure, audited & minimal implementation of BIP39 mnemonic phrases

Latest version **2.1.1** (published 2023-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @metamask/scure-bip39
pnpm add @metamask/scure-bip39
yarn add @metamask/scure-bip39
bun add @metamask/scure-bip39
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2023-10-03 |
| First published | 2022-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | ^16.20 \|\| ^18.16 \|\| >=20 |
| Dependencies | 2 |
| Unpacked size | 170.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Paul Miller |
| Maintainers | lgbot, naugtur, ritave, danfinlay, kumavis, rekmarks, metamaskbot, gudahtt, brad.decker, sethkfman |
| Keywords | bip39, mnemonic, phrase, code, bip0039, bip-39, micro, scure, wordlist, noble |

## Links

- npm: https://www.npmjs.com/package/@metamask/scure-bip39
- Repository: https://github.com/MetaMask/scure-bip39
- Homepage: https://github.com/MetaMask/scure-bip39#readme
- Issues: https://github.com/MetaMask/scure-bip39/issues
- npm.io page: https://npm.io/package/@metamask/scure-bip39

## Dependencies (2)

- [@scure/base](https://npm.io/package/@scure/base.md) ~1.1.3
- [@noble/hashes](https://npm.io/package/@noble/hashes.md) ~1.3.2

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 2.1.1 (latest) — 2023-10-03
- 2.1.0 — 2023-01-06
- 2.0.4 — 2023-01-04
- 2.0.3 — 2022-09-13
- 2.0.1 — 2022-09-13

## README

## MetaMask fork

This is a temporary fork of the `@scure/bip39` package created by the MetaMask team. Please do not use this package for other projects, use `@scure/bip39` directly instead. We are not interested in maintaining this long-term. We will not be accepting community issues or PRs.

# scure-bip39

Secure, [audited](#security) & minimal implementation of BIP39 mnemonic phrases.

Compared to popular `bip39` package, scure-bip39:

- Is 491KB all-bundled instead of 1.3MB
- Uses 2 dependencies instead of 15
- Wordlists are 157KB instead of 315KB
- Had an external security [audit](#security) by Cure53 on Jan 5, 2022

Check out [scure-bip32](https://github.com/paulmillr/scure-bip32) if you need
hierarchical deterministic wallets ("HD Wallets").

### This library belongs to *scure*

> **scure** — secure audited packages for every use case.

- Independent security audits
- All releases are signed with PGP keys
- Check out all libraries:
  [base](https://github.com/paulmillr/scure-base),
  [bip32](https://github.com/paulmillr/scure-bip32),
  [bip39](https://github.com/paulmillr/scure-bip39)

## Usage

> npm install @metamask/scure-bip39

Or

> yarn add @metamask/scure-bip39

```js
import * as bip39 from '@metamask/scure-bip39';
import { wordlist } from '@metamask/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, 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.

```typescript
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:

```typescript
import { wordlist } from '@metamask/scure-bip39/wordlists/czech';
import { wordlist } from '@metamask/scure-bip39/wordlists/english';
import { wordlist } from '@metamask/scure-bip39/wordlists/french';
import { wordlist } from '@metamask/scure-bip39/wordlists/italian';
import { wordlist } from '@metamask/scure-bip39/wordlists/japanese';
import { wordlist } from '@metamask/scure-bip39/wordlists/korean';
import { wordlist } from '@metamask/scure-bip39/wordlists/simplified-chinese';
import { wordlist } from '@metamask/scure-bip39/wordlists/spanish';
import { wordlist } from '@metamask/scure-bip39/wordlists/traditional-chinese';
```

## Security

The library has been audited by Cure53 on Jan 5, 2022. Check out the audit [PDF](./audit/2022-01-05-cure53-audit-nbl2.pdf) & [URL](https://cure53.de/pentest-report_hashing-libs.pdf). See [changes since audit](https://github.com/paulmillr/scure-bip39/compare/1.0.0..main).

1. The library was initially developed for [js-ethereum-cryptography](https://github.com/ethereum/js-ethereum-cryptography)
2. At commit [ae00e6d7](https://github.com/ethereum/js-ethereum-cryptography/commit/ae00e6d7d24fb3c76a1c7fe10039f6ecd120b77e), it
  was extracted to a separate package called `micro-bip39`
3. After the audit we've decided to use NPM namespace for security. Since `@micro` namespace was taken, we've renamed the package to `@scure/bip39`
4. As a modified fork for use by MetaMask, the package name is changed to `@metamask/scure-bip39`.

## License

[MIT License](./LICENSE)

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

---
_Source: https://npm.io/package/@metamask/scure-bip39 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
