⚡️ react-native-quick-bip39
A fast implementation of bip39
using react-native-quick-crypto
All methods are sync, as react-native-quick-crypto
uses JSI under the hood.
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
Installation
yarn add react-native-quick-bip39
Drop-in replacement for bip39
This library exposes all the same methods from the original JavaScript implementation. If your react-native project depends on that, you can modify your metro.config.js
to replace all calls with a fully native implementation:
Use the resolveRequest
configuration option in your metro.config.js
config.resolver.resolveRequest = (context, moduleName, platform) => {
if (moduleName === 'bip39') {
return context.resolveRequest(
context,
'react-native-quick-bip39',
platform,
)
}
return context.resolveRequest(context, moduleName, platform)
}
Then restart your bundler using yarn start --reset-cache
.
💡 Since react-native-quick-crypto
depends on stream
and buffer
, we can optionally resolve those to stream-browserify
and @craftzdog's react-native-buffer
. See documentation.
Examples
import {
generateMnemonic,
mnemonicToSeed,
validateMnemonic,
entropyToMnemonic,
mnemonicToEntropy,
wordlists,
} from "react-native-quick-bip39";
generateMnemonic(256);
generateMnemonic(256, wordlists.korean);
mnemonicToSeed("basket actual");
validateMnemonic(myMnemonic);
validateMnemonic("basket actual");
Credits