2019-08-25 09:39:20 +03:00
|
|
|
"use strict";
|
2019-11-23 15:38:13 +03:00
|
|
|
// This gets overridden by rollup
|
|
|
|
const exportWordlist = false;
|
2019-08-25 09:39:20 +03:00
|
|
|
import { id } from "@ethersproject/hash";
|
|
|
|
import { defineReadOnly } from "@ethersproject/properties";
|
|
|
|
import { Logger } from "@ethersproject/logger";
|
|
|
|
import { version } from "./_version";
|
2019-11-23 15:38:13 +03:00
|
|
|
export const logger = new Logger(version);
|
2019-08-25 09:39:20 +03:00
|
|
|
export class Wordlist {
|
|
|
|
constructor(locale) {
|
|
|
|
logger.checkAbstract(new.target, Wordlist);
|
|
|
|
defineReadOnly(this, "locale", locale);
|
|
|
|
}
|
|
|
|
// Subclasses may override this
|
|
|
|
split(mnemonic) {
|
|
|
|
return mnemonic.toLowerCase().split(/ +/g);
|
|
|
|
}
|
|
|
|
// Subclasses may override this
|
|
|
|
join(words) {
|
|
|
|
return words.join(" ");
|
|
|
|
}
|
2019-11-23 15:38:13 +03:00
|
|
|
static check(wordlist) {
|
|
|
|
const words = [];
|
|
|
|
for (let i = 0; i < 2048; i++) {
|
|
|
|
const word = wordlist.getWord(i);
|
|
|
|
if (i !== wordlist.getWordIndex(word)) {
|
|
|
|
return "0x";
|
|
|
|
}
|
|
|
|
words.push(word);
|
2019-08-25 09:39:20 +03:00
|
|
|
}
|
2019-11-23 15:38:13 +03:00
|
|
|
return id(words.join("\n") + "\n");
|
|
|
|
}
|
|
|
|
static register(lang, name) {
|
|
|
|
if (!name) {
|
|
|
|
name = lang.locale;
|
2019-08-25 09:39:20 +03:00
|
|
|
}
|
2019-11-23 15:38:13 +03:00
|
|
|
if (exportWordlist) {
|
|
|
|
const g = global;
|
|
|
|
if (g._ethers && g._ethers.wordlists) {
|
|
|
|
if (!g._ethers.wordlists[name]) {
|
|
|
|
defineReadOnly(g._ethers.wordlists, name, lang);
|
|
|
|
}
|
2019-08-25 09:39:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|