1 |
|
2 |
|
3 | import { assert, stringToU8a } from '@polkadot/util';
|
4 | import { bip39ToMiniSecret, isReady } from '@polkadot/wasm-crypto';
|
5 | import { pbkdf2Encode } from "../pbkdf2/index.js";
|
6 | import { mnemonicToEntropy } from "./toEntropy.js";
|
7 | import { mnemonicValidate } from "./validate.js";
|
8 | export function mnemonicToMiniSecret(mnemonic, password = '', onlyJs) {
|
9 | assert(mnemonicValidate(mnemonic), 'Invalid bip39 mnemonic specified');
|
10 |
|
11 | if (!onlyJs && isReady()) {
|
12 | return bip39ToMiniSecret(mnemonic, password);
|
13 | }
|
14 |
|
15 | const entropy = mnemonicToEntropy(mnemonic);
|
16 | const salt = stringToU8a(`mnemonic${password}`);
|
17 |
|
18 | return pbkdf2Encode(entropy, salt).password.slice(0, 32);
|
19 | } |
\ | No newline at end of file |