Partial support for non-English mnemonics for encrypted JSON wallets (#685).

This commit is contained in:
Richard Moore 2020-02-16 16:13:24 -05:00
parent 748f89660a
commit 9947acc349
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651

@ -26,6 +26,7 @@ export type EncryptOptions = {
entropy?: Arrayish; entropy?: Arrayish;
mnemonic?: string; mnemonic?: string;
path?: string; path?: string;
wordlist?: any; // Should be a wordlist, but don't want to create the dependency
client?: string; client?: string;
salt?: Arrayish; salt?: Arrayish;
uuid?: string; 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 // 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 mnemonicCiphertext = looseArrayify(searchPath(data, 'x-ethers/mnemonicCiphertext'));
var mnemonicIv = looseArrayify(searchPath(data, 'x-ethers/mnemonicCounter')); 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'); throw new Error('entropy and mnemonic mismatch');
} }
} else { } 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, path: path,
version: "0.1" version: "0.1"
}; };
if (options.wordlist && typeof(options.wordlist.locale) === "string") {
data['x-ethers'].locale = options.wordlist.locale;
}
} }
if (progressCallback) { progressCallback(1); } if (progressCallback) { progressCallback(1); }