Skip to content

Commit

Permalink
Refactored wordlist exports to export Wordlist directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jun 12, 2019
1 parent 8a3397d commit 746d255
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
7 changes: 2 additions & 5 deletions packages/ethers/src.ts/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import * as constants from "@ethersproject/constants";
import * as errors from "@ethersproject/errors";

import * as providers from "@ethersproject/providers";
import * as wordlists from "@ethersproject/wordlists";
import { Wordlist, wordlists} from "@ethersproject/wordlists";

import * as utils from "./utils";

import { version } from "./_version";

////////////////////////
// Types

import { BigNumberish } from "@ethersproject/bignumber";
import { Bytes, BytesLike, Signature } from "@ethersproject/bytes";
import { Transaction, UnsignedTransaction } from "@ethersproject/transactions";
import { Wordlist } from "@ethersproject/wordlists/wordlist";


////////////////////////
Expand All @@ -33,7 +30,7 @@ import { Wordlist } from "@ethersproject/wordlists/wordlist";
import { platform } from "./platform";

// This is generated by "npm run dist"
//import { version } from "./_version";
import { version } from "./_version";


////////////////////////
Expand Down
11 changes: 3 additions & 8 deletions packages/hdnode/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
// 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 { Base58 } from "@ethersproject/basex";
import * as errors from "@ethersproject/errors";
Expand All @@ -19,11 +15,10 @@ import { defineReadOnly } from "@ethersproject/properties";
import { SigningKey } from "@ethersproject/signing-key";
import { computeHmac, ripemd160, sha256, SupportedAlgorithms } from "@ethersproject/sha2";
import { computeAddress } from "@ethersproject/transactions";
import { Wordlist, wordlists } from "@ethersproject/wordlists";

const N = BigNumber.from("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");

import { Wordlist } from "@ethersproject/wordlists/wordlist";


// "Bitcoin seed"
const MasterSecret = toUtf8Bytes("Bitcoin seed");
Expand Down Expand Up @@ -271,7 +266,7 @@ export function mnemonicToSeed(mnemonic: string, password?: string): string {
}

export function mnemonicToEntropy(mnemonic: string, wordlist?: Wordlist): string {
if (!wordlist) { wordlist = langEn; }
if (!wordlist) { wordlist = wordlists["en"]; }

errors.checkNormalize();

Expand Down Expand Up @@ -348,7 +343,7 @@ export function entropyToMnemonic(entropy: BytesLike, wordlist?: Wordlist): stri
indices[indices.length - 1] <<= 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)));
}
Expand Down
7 changes: 4 additions & 3 deletions packages/wordlists/src.ts/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

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 {
en
Wordlist,
wordlists
}
38 changes: 20 additions & 18 deletions packages/wordlists/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
// Wordlists
// See: https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md


import { Wordlist } from "./wordlist";

import { langEn as _en } from "./lang-en";
import { langEs as _es } from "./lang-es";
import { langFr as _fr } from "./lang-fr";
import { langJa as _ja } from "./lang-ja";
import { langKo as _ko } from "./lang-ko";
import { langIt as _it } from "./lang-it";
import { langZhCn as _zh_cn, langZhTw as _zh_tw } from "./lang-zh";
import { langEn as en } from "./lang-en";
import { langEs as es } from "./lang-es";
import { langFr as fr } from "./lang-fr";
import { langJa as ja } from "./lang-ja";
import { langKo as ko } from "./lang-ko";
import { langIt as it } from "./lang-it";
import { langZhCn as zh_cn, langZhTw as zh_tw } from "./lang-zh";

const en: Wordlist = _en;
const es: Wordlist = _es;
const fr: Wordlist = _fr;
const it: Wordlist = _it;
const ja: Wordlist = _ja;
const ko: Wordlist = _ko;
const zh: Wordlist = _zh_cn;
const zh_cn: Wordlist = _zh_cn;
const zh_tw: Wordlist = _zh_tw;
const wordlists: { [ locale: string ]: Wordlist } = {
en: en,
es: es,
fr: fr,
it: it,
ja: ja,
ko: ko,
zh: zh_cn,
zh_cn: zh_cn,
zh_tw: zh_tw
};

export {
en, es, fr, it, ja, ko, zh, zh_cn, zh_tw
Wordlist,
wordlists
}

0 comments on commit 746d255

Please sign in to comment.