ethers.js/src.ts/wordlists/wordlist.ts
2018-06-22 02:13:34 -04:00

34 lines
854 B
TypeScript

// This gets overriddenby gulp during bip39-XX
var exportWordlist = false;
import { defineReadOnly } from '../utils/properties';
export abstract class Wordlist {
locale: string;
constructor(locale: string) {
defineReadOnly(this, 'locale', locale);
}
abstract getWord(index: number): string;
abstract getWordIndex(word: string): number;
// Subclasses may override this
split(mnemonic: string): Array<string> {
return mnemonic.toLowerCase().split(/ +/g)
}
// Subclasses may override this
join(words: Array<string>): string {
return words.join(' ');
}
}
export function register(lang: Wordlist): void {
if (exportWordlist) {
if (!global['wordlists']) { defineReadOnly(global, 'wordlists', { }); }
defineReadOnly(global['wordlists'], lang.locale, lang);
}
}