Refactored wordlist exports to export Wordlist directly.

This commit is contained in:
Richard Moore 2019-06-12 09:35:44 -04:00
parent 8a3397dedb
commit 746d255b74
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
4 changed files with 29 additions and 34 deletions

@ -11,19 +11,16 @@ import * as constants from "@ethersproject/constants";
import * as errors from "@ethersproject/errors"; import * as errors from "@ethersproject/errors";
import * as providers from "@ethersproject/providers"; import * as providers from "@ethersproject/providers";
import * as wordlists from "@ethersproject/wordlists"; import { Wordlist, wordlists} from "@ethersproject/wordlists";
import * as utils from "./utils"; import * as utils from "./utils";
import { version } from "./_version";
//////////////////////// ////////////////////////
// Types // Types
import { BigNumberish } from "@ethersproject/bignumber"; import { BigNumberish } from "@ethersproject/bignumber";
import { Bytes, BytesLike, Signature } from "@ethersproject/bytes"; import { Bytes, BytesLike, Signature } from "@ethersproject/bytes";
import { Transaction, UnsignedTransaction } from "@ethersproject/transactions"; import { Transaction, UnsignedTransaction } from "@ethersproject/transactions";
import { Wordlist } from "@ethersproject/wordlists/wordlist";
//////////////////////// ////////////////////////
@ -33,7 +30,7 @@ import { Wordlist } from "@ethersproject/wordlists/wordlist";
import { platform } from "./platform"; import { platform } from "./platform";
// This is generated by "npm run dist" // This is generated by "npm run dist"
//import { version } from "./_version"; import { version } from "./_version";
//////////////////////// ////////////////////////

@ -4,10 +4,6 @@
// See: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki // See: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
// The English language word list.
// For additional word lists, please see @ethersproject//wordlists
import { langEn } from "@ethersproject/wordlists/lang-en";
import { ExternallyOwnedAccount } from "@ethersproject/abstract-signer"; import { ExternallyOwnedAccount } from "@ethersproject/abstract-signer";
import { Base58 } from "@ethersproject/basex"; import { Base58 } from "@ethersproject/basex";
import * as errors from "@ethersproject/errors"; import * as errors from "@ethersproject/errors";
@ -19,11 +15,10 @@ import { defineReadOnly } from "@ethersproject/properties";
import { SigningKey } from "@ethersproject/signing-key"; import { SigningKey } from "@ethersproject/signing-key";
import { computeHmac, ripemd160, sha256, SupportedAlgorithms } from "@ethersproject/sha2"; import { computeHmac, ripemd160, sha256, SupportedAlgorithms } from "@ethersproject/sha2";
import { computeAddress } from "@ethersproject/transactions"; import { computeAddress } from "@ethersproject/transactions";
import { Wordlist, wordlists } from "@ethersproject/wordlists";
const N = BigNumber.from("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); const N = BigNumber.from("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
import { Wordlist } from "@ethersproject/wordlists/wordlist";
// "Bitcoin seed" // "Bitcoin seed"
const MasterSecret = toUtf8Bytes("Bitcoin seed"); const MasterSecret = toUtf8Bytes("Bitcoin seed");
@ -271,7 +266,7 @@ export function mnemonicToSeed(mnemonic: string, password?: string): string {
} }
export function mnemonicToEntropy(mnemonic: string, wordlist?: Wordlist): string { export function mnemonicToEntropy(mnemonic: string, wordlist?: Wordlist): string {
if (!wordlist) { wordlist = langEn; } if (!wordlist) { wordlist = wordlists["en"]; }
errors.checkNormalize(); errors.checkNormalize();
@ -348,7 +343,7 @@ export function entropyToMnemonic(entropy: BytesLike, wordlist?: Wordlist): stri
indices[indices.length - 1] <<= checksumBits; indices[indices.length - 1] <<= checksumBits;
indices[indices.length - 1] |= (checksum >> (8 - checksumBits)); indices[indices.length - 1] |= (checksum >> (8 - checksumBits));
if (!wordlist) { wordlist = langEn; } if (!wordlist) { wordlist = wordlists["en"]; }
return wordlist.join(indices.map((index) => wordlist.getWord(index))); return wordlist.join(indices.map((index) => wordlist.getWord(index)));
} }

@ -6,10 +6,11 @@
import { Wordlist } from "./wordlist"; import { Wordlist } from "./wordlist";
import { langEn as _en } from "./lang-en"; import { langEn as en } from "./lang-en";
const en: Wordlist = _en; const wordlists: { en: Wordlist } = { en: en };
export { export {
en Wordlist,
wordlists
} }

@ -3,27 +3,29 @@
// Wordlists // Wordlists
// See: https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md // See: https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md
import { Wordlist } from "./wordlist"; import { Wordlist } from "./wordlist";
import { langEn as _en } from "./lang-en"; import { langEn as en } from "./lang-en";
import { langEs as _es } from "./lang-es"; import { langEs as es } from "./lang-es";
import { langFr as _fr } from "./lang-fr"; import { langFr as fr } from "./lang-fr";
import { langJa as _ja } from "./lang-ja"; import { langJa as ja } from "./lang-ja";
import { langKo as _ko } from "./lang-ko"; import { langKo as ko } from "./lang-ko";
import { langIt as _it } from "./lang-it"; import { langIt as it } from "./lang-it";
import { langZhCn as _zh_cn, langZhTw as _zh_tw } from "./lang-zh"; import { langZhCn as zh_cn, langZhTw as zh_tw } from "./lang-zh";
const en: Wordlist = _en; const wordlists: { [ locale: string ]: Wordlist } = {
const es: Wordlist = _es; en: en,
const fr: Wordlist = _fr; es: es,
const it: Wordlist = _it; fr: fr,
const ja: Wordlist = _ja; it: it,
const ko: Wordlist = _ko; ja: ja,
const zh: Wordlist = _zh_cn; ko: ko,
const zh_cn: Wordlist = _zh_cn; zh: zh_cn,
const zh_tw: Wordlist = _zh_tw; zh_cn: zh_cn,
zh_tw: zh_tw
};
export { export {
en, es, fr, it, ja, ko, zh, zh_cn, zh_tw Wordlist,
wordlists
} }