1 | import { hasBigInt } from '@polkadot/util';
|
2 | import { bip39ToSeed, isReady } from '@polkadot/wasm-crypto';
|
3 | import { mnemonicToSeedSync } from './bip39.js';
|
4 | import { mnemonicValidate } from './validate.js';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export function mnemonicToLegacySeed(mnemonic, password = '', onlyJs, byteLength = 32) {
|
23 | if (!mnemonicValidate(mnemonic)) {
|
24 | throw new Error('Invalid bip39 mnemonic specified');
|
25 | }
|
26 | else if (![32, 64].includes(byteLength)) {
|
27 | throw new Error(`Invalid seed length ${byteLength}, expected 32 or 64`);
|
28 | }
|
29 | return byteLength === 32
|
30 | ? !hasBigInt || (!onlyJs && isReady())
|
31 | ? bip39ToSeed(mnemonic, password)
|
32 | : mnemonicToSeedSync(mnemonic, password).subarray(0, 32)
|
33 | : mnemonicToSeedSync(mnemonic, password);
|
34 | }
|