ReactNative BIP39 (react-native-bip39)
ReactNative-ready fork of the original Javascript implementation of Bitcoin BIP39: Mnemonic code for generating deterministic keys
Installation
yarn add \
@mfellner/react-native-bip39 \
@mfellner/react-native-fast-create-hash \
react-native-fast-crypto \
react-native-securerandom
Features
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
import bip39 from '@mfellner/react-native-bip39'
static generateMnemonic = async () => {
try {
return await bip39.generateMnemonic(256)
} catch(e) {
return false
}
}
bip39.mnemonicToSeedHex('basket actual')
bip39.mnemonicToSeed('basket actual')
bip39.validateMnemonic(myMnemonic)
bip39.validateMnemonic('basket actual')
import bip39 from '@mfellner/react-native-bip39';
const mnemonic = bip39.entropyToMnemonic('133755ff');
bip39.mnemonicToEntropy(mnemonic);