Skip to content

Commit

Permalink
Partial support for non-English mnemonics for encrypted JSON wallets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 16, 2020
1 parent 748f896 commit 9947acc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src.ts/utils/secret-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));

Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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); }
Expand Down

0 comments on commit 9947acc

Please sign in to comment.