# react-native-bip39

> ReactNative-ready Bitcoin BIP39: Mnemonic code for generating deterministic keys

Latest version **2.3.0** (published 2017-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-bip39
pnpm add react-native-bip39
yarn add react-native-bip39
bun add react-native-bip39
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2017-03-18 |
| First published | 2017-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Alberto Dallaporta |
| Maintainers | albertodallaporta |

## Links

- npm: https://www.npmjs.com/package/react-native-bip39
- Repository: https://github.com/39otrebla/react-native-bip39
- Homepage: https://github.com/39otrebla/react-native-bip39#readme
- Issues: https://github.com/39otrebla/react-native-bip39/issues
- npm.io page: https://npm.io/package/react-native-bip39

## Dependencies (3)

- [unorm](https://npm.io/package/unorm.md) ^1.3.3
- [react-native-crypto](https://npm.io/package/react-native-crypto.md) ^2.0.1
- [react-native-randombytes](https://npm.io/package/react-native-randombytes.md) ^2.2.0

## Recent versions

- 2.3.0 (latest) — 2017-03-18
- 2.2.0 — 2017-03-04

## README

# ReactNative BIP39 (react-native-bip39)

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)


ReactNative-ready fork of the [original Javascript implementation of Bitcoin BIP39](https://github.com/bitcoinjs/bip39): Mnemonic code for generating deterministic keys

## Features
- Native generation of random bytes using [react-native-randombytes](https://github.com/mvayngrib/react-native-randombytes)
- Partial implementation of node's `crypto` for react-native, using [react-native-crypto](https://github.com/mvayngrib/react-native-crypto)

## Reminder for developers

***Please remember to allow recovery from mnemonic phrases that have invalid checksums (or that you don't have the wordlist)***

When a checksum is invalid, warn the user that the phrase is not something generated by your app, and ask if they would like to use it anyway. This way, your app only needs to hold the wordlists for your supported languages, but you can recover phrases made by other apps in other languages.

However, there should be other checks in place, such as checking to make sure the user is inputting 12 words or more separated by a space. ie. `phrase.trim().split(/\s+/g).length >= 12`


## Examples
``` js

import bip39 from 'react-native-bip39'

// Generate a random mnemonic (uses react-native-randombytes under the hood), defaults to 128-bits of entropy

// NOTE: react-native-bip39's generateMnemonic in async, while original bip39's is sync
// this is due to react-native-randombytes which is forced to return natively generated 
// bytes with a callback
static generateMnemonic = async () => {
  try {
    return await bip39.generateMnemonic(256) // default to 128
  } catch(e) {
    return false
  }
}
// => 'reveal man culture nominee tag abuse keen behave refuse warfare crisp thunder valve knock unique try fold energy torch news thought access hawk table'

bip39.mnemonicToSeedHex('basket actual')
// => '5cf2d4a8b0355e90295bdfc565a022a409af063d5365bb57bf74d9528f494bfa4400f53d8349b80fdae44082d7f9541e1dba2b003bcfec9d0d53781ca676651f'

bip39.mnemonicToSeed('basket actual')
// => <Buffer 5c f2 d4 a8 b0 35 5e 90 29 5b df c5 65 a0 22 a4 09 af 06 3d 53 65 bb 57 bf 74 d9 52 8f 49 4b fa 44 00 f5 3d 83 49 b8 0f da e4 40 82 d7 f9 54 1e 1d ba 2b ...>

bip39.validateMnemonic(myMnemonic)
// => true

bip39.validateMnemonic('basket actual')
// => false
```


``` js
import bip39 from 'react-native-bip39'

// defaults to BIP39 English word list
// uses HEX strings for entropy
const mnemonic = bip39.entropyToMnemonic('133755ff')
// => basket rival lemon

// reversible
bip39.mnemonicToEntropy(mnemonic)
// => '133755ff'
```

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