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