17 lines
820 B
JavaScript
17 lines
820 B
JavaScript
|
|
import { generateMnemonic, validateMnemonic, mnemonicToSeed, wordlists, } from 'bip39';
|
||
|
|
// Word count → entropy strength for BIP39.
|
||
|
|
// 12 → 128, 15 → 160, 18 → 192, 21 → 224, 24 → 256.
|
||
|
|
export function generateSeedPhrase(strength = 128) {
|
||
|
|
return generateMnemonic(strength);
|
||
|
|
}
|
||
|
|
// BIP39 checksum + wordlist validation. Returns false for typos, bad
|
||
|
|
// word counts, and out-of-wordlist words.
|
||
|
|
export function validateSeedPhrase(phrase, wordlist = wordlists.english) {
|
||
|
|
return validateMnemonic(phrase.trim(), wordlist);
|
||
|
|
}
|
||
|
|
// BIP39 seed derivation. Passphrase is the optional "25th word";
|
||
|
|
// changing it produces a different wallet from the same mnemonic.
|
||
|
|
export async function seedFromPhrase(phrase, passphrase = '') {
|
||
|
|
return mnemonicToSeed(phrase.trim(), passphrase);
|
||
|
|
}
|
||
|
|
//# sourceMappingURL=seed.js.map
|