From 9947acc349691734bce8b33d870ab48944a7962f Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Sun, 16 Feb 2020 16:13:24 -0500 Subject: [PATCH] Partial support for non-English mnemonics for encrypted JSON wallets (#685). --- src.ts/utils/secret-storage.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src.ts/utils/secret-storage.ts b/src.ts/utils/secret-storage.ts index d075571da1..3e1c85cb3b 100644 --- a/src.ts/utils/secret-storage.ts +++ b/src.ts/utils/secret-storage.ts @@ -26,6 +26,7 @@ export type EncryptOptions = { entropy?: Arrayish; mnemonic?: string; path?: string; + wordlist?: any; // Should be a wordlist, but don't want to create the dependency client?: string; salt?: Arrayish; uuid?: string; @@ -177,7 +178,8 @@ export function decrypt(json: string, password: Arrayish, progressCallback?: Pro } // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase - if (searchPath(data, 'x-ethers/version') === '0.1') { + const locale = searchPath(data, 'x-ethers/locale'); + if (searchPath(data, 'x-ethers/version') === '0.1' && (locale == null || locale === "en")) { var mnemonicCiphertext = looseArrayify(searchPath(data, 'x-ethers/mnemonicCiphertext')); var mnemonicIv = looseArrayify(searchPath(data, 'x-ethers/mnemonicCounter')); @@ -318,7 +320,7 @@ export function encrypt(privateKey: Arrayish | SigningKey, password: Arrayish | throw new Error('entropy and mnemonic mismatch'); } } else { - entropy = arrayify(HDNode.mnemonicToEntropy(options.mnemonic)); + entropy = arrayify(HDNode.mnemonicToEntropy(options.mnemonic, options.wordlist)); } } @@ -441,6 +443,9 @@ export function encrypt(privateKey: Arrayish | SigningKey, password: Arrayish | path: path, version: "0.1" }; + if (options.wordlist && typeof(options.wordlist.locale) === "string") { + data['x-ethers'].locale = options.wordlist.locale; + } } if (progressCallback) { progressCallback(1); }