@synchronic/bip39
v1.0.2
Published
Synchronic copy @scure/bip39. Secure, audited & minimal implementation of BIP39
Downloads
1
Readme
scure-bip39
Current version: https://github.com/paulmillr/scure-bip39/releases/tag/1.2.1
Synchronic fork @scure/bip39.
Difference from the original library:
- ESM JavaScript Code Format
- The function response format has been changed from Uint8Array to Buffer
- Added wordlist function
- The fork is designed to use all 10 dictionaries in supported languages
Usage
npm install @synchronic/bip39
import * as bip39 from '@synchronic/bip39';
// Get a dictionary of 2048 words in the language you need
// english, chinese_simplified, chinese_traditional, czech, french, italian, japanese, korean, portuguese, spanish
const wordlist = bip39.wordlist('english')
console.log(wordlist); // ['abandon', 'ability', 'able', 'about', 'above' ... 2043 more items]
// Generate mnemonic (128 = 12 words, 256 = 24 words). Uses Cryptographically-Secure Random Generator.
const mnemonic = bip39.generateMnemonic(128, wordlist);
console.log(mnemonic); // rice blast wife alert include spring sign flash brisk awake clap holiday
// Reversible: Converts mnemonic string to entropy in Buffer format.
const entropy = bip39.mnemonicToEntropy(mnemonic, wordlist)
console.log(entropy.toString('hex')); // b922efeb831727a67212c31c4204a736
// Reversible: Converts Uint8Array, Buffer, Hex entropy to mnemonic string.
const mnemonic1 = bip39.entropyToMnemonic(entropy, wordlist);
console.log(mnemonic1); // rice blast wife alert include spring sign flash brisk awake clap holiday
// Validates mnemonic for being 12-24 words contained in `wordlist`.
const valid = bip39.validateMnemonic(mnemonic, wordlist);
console.log(valid); // true
// Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
const seed = bip39.mnemonicToSeedSync(mnemonic)
console.log(seed.toString('hex')); // dca898a1b2dcbae0a78b889319e76c43f4fa5f491726faf9120d42068f0d46e9a30844dbb1fbd7c3b841ed46a899f403d024b6bfcc02a79d4458c771be757c75
const seedAsync = await bip39.mnemonicToSeed(mnemonic, 'password');
console.log(seedAsync); // <Buffer 24 43 42 21 54 3a 61 3b 59 87 a2 0d 31 86 1f 8b 03 b2 23 51 3b 11 0f 6c f6 a7 c8 1a db ab 04 56 71 f7 f1 2d ba 92 cb 99 22 9a cf 5b 20 5f 59 2a 1a 57 ... 14 more bytes>
MIT License
Copyright (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com)