diff --git a/packages/mask/src/extension/background-script/BackupService.ts b/packages/mask/src/extension/background-script/BackupService.ts index ecf3e613ea27..0eb61ddcd522 100644 --- a/packages/mask/src/extension/background-script/BackupService.ts +++ b/packages/mask/src/extension/background-script/BackupService.ts @@ -33,6 +33,7 @@ import { isSecp256k1Point, isSecp256k1PrivateKey, } from '@masknet/shared-base' +import { INTERNAL_getPasswordRequired } from '../../plugins/Wallet/services/wallet/password' delegatePluginBackup(backupAllPlugins) delegatePluginRestore(async function (backup) { @@ -71,12 +72,13 @@ delegateWalletBackup(async function () { return wallet.flat() }) delegateWalletRestore(async function (backup) { + const password = await INTERNAL_getPasswordRequired() for (const wallet of backup) { try { const name = wallet.name if (wallet.privateKey.some) - await recoverWalletFromPrivateKey(name, await JWKToKey(wallet.privateKey.val, 'private')) + await recoverWalletFromPrivateKey(name, await JWKToKey(wallet.privateKey.val, 'private'), password) else if (wallet.mnemonic.some) { // fix a backup bug of pre-v2.2.2 versions const accounts = await getDerivableAccounts(wallet.mnemonic.val.words, 1, 5) @@ -85,6 +87,7 @@ delegateWalletRestore(async function (backup) { name, wallet.mnemonic.val.words, index > -1 ? `${HD_PATH_WITHOUT_INDEX_ETHEREUM}/${index}` : wallet.mnemonic.val.path, + password, ) } } catch (error) { diff --git a/packages/mask/src/plugins/Wallet/services/wallet/index.ts b/packages/mask/src/plugins/Wallet/services/wallet/index.ts index 400e24ebac66..693f1b4df439 100644 --- a/packages/mask/src/plugins/Wallet/services/wallet/index.ts +++ b/packages/mask/src/plugins/Wallet/services/wallet/index.ts @@ -295,8 +295,9 @@ export async function recoverWalletFromMnemonic( name: string, mnemonic: string, derivationPath = `${HD_PATH_WITHOUT_INDEX_ETHEREUM}/0`, + initialPassword?: string, ) { - const password_ = await password.INTERNAL_getPasswordRequired() + const password_ = initialPassword ?? (await password.INTERNAL_getPasswordRequired()) const imported = await Mask.importMnemonic({ mnemonic, password: password_, @@ -325,8 +326,8 @@ export async function recoverWalletFromMnemonic( } } -export async function recoverWalletFromPrivateKey(name: string, privateKey: string) { - const password_ = await password.INTERNAL_getPasswordRequired() +export async function recoverWalletFromPrivateKey(name: string, privateKey: string, initialPassword_?: string) { + const password_ = initialPassword_ ?? (await password.INTERNAL_getPasswordRequired()) const imported = await Mask.importPrivateKey({ coin: api.Coin.Ethereum, name,