From 0d8cf151efdc135759b44bd5407e7e3caa1f3575 Mon Sep 17 00:00:00 2001 From: morizon Date: Wed, 11 Oct 2023 21:04:36 +0800 Subject: [PATCH] fix: generateMnemonic words length (#3630) --- packages/engine/src/index.ts | 12 +++++++++--- packages/engine/src/secret/index.test.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/engine/src/index.ts b/packages/engine/src/index.ts index 92931aa0cf7..a7407e9ba5c 100644 --- a/packages/engine/src/index.ts +++ b/packages/engine/src/index.ts @@ -145,11 +145,11 @@ import type { import type { Token } from './types/token'; import type { Wallet } from './types/wallet'; import type { IUnsignedMessageBtc } from './vaults/impl/btc/types'; +import type VaultEvm from './vaults/impl/evm/Vault'; import type { IEncodedTxEvm, IUnsignedMessageEvm, } from './vaults/impl/evm/Vault'; -import type VaultEvm from './vaults/impl/evm/Vault'; import type VaultSol from './vaults/impl/sol/Vault'; import type { IClientEndpointStatus, @@ -206,7 +206,11 @@ class Engine { @backgroundMethod() generateMnemonic(): Promise { - return Promise.resolve(bip39.generateMnemonic(256)); + // 24 words + // return Promise.resolve(bip39.generateMnemonic(256)); + + // 12 words + return Promise.resolve(bip39.generateMnemonic()); } @backgroundMethod() @@ -372,7 +376,9 @@ class Engine { await this.validator.validatePasswordStrength(password); const [usedMnemonic] = await Promise.all([ - this.validator.validateMnemonic(mnemonic || bip39.generateMnemonic(256)), + this.validator.validateMnemonic( + mnemonic || (await this.generateMnemonic()), + ), this.validator.validateHDWalletNumber(), ]); diff --git a/packages/engine/src/secret/index.test.ts b/packages/engine/src/secret/index.test.ts index 3f8efff0926..a3f781ec1f4 100644 --- a/packages/engine/src/secret/index.test.ts +++ b/packages/engine/src/secret/index.test.ts @@ -781,7 +781,7 @@ test('Basic mnemonic & seed tests', () => { }); test('Mnemonic generation', () => { - const mnemonic = bip39.generateMnemonic(256); + const mnemonic = bip39.generateMnemonic(); const rs = revealableSeedFromMnemonic(mnemonic, password); expect( mnemonicFromEntropy(rs.entropyWithLangPrefixed, password),