2022-09-05 23:57:11 +03:00
|
|
|
// Use the encode-latin.js script to create the necessary
|
|
|
|
// data files to be consumed by this class
|
2022-09-16 05:58:45 +03:00
|
|
|
import { id } from "../hash/index.js";
|
|
|
|
import { throwArgumentError } from "../utils/index.js";
|
2022-09-05 23:57:11 +03:00
|
|
|
import { decodeOwl } from "./decode-owl.js";
|
|
|
|
import { Wordlist } from "./wordlist.js";
|
|
|
|
export class WordlistOwl extends Wordlist {
|
|
|
|
#data;
|
|
|
|
#checksum;
|
|
|
|
constructor(locale, data, checksum) {
|
|
|
|
super(locale);
|
|
|
|
this.#data = data;
|
|
|
|
this.#checksum = checksum;
|
|
|
|
this.#words = null;
|
|
|
|
}
|
|
|
|
get _data() { return this.#data; }
|
|
|
|
_decodeWords() {
|
|
|
|
return decodeOwl(this.#data);
|
|
|
|
}
|
|
|
|
#words;
|
|
|
|
#loadWords() {
|
|
|
|
if (this.#words == null) {
|
|
|
|
const words = this._decodeWords();
|
|
|
|
// Verify the computed list matches the official list
|
|
|
|
const checksum = id(words.join("\n") + "\n");
|
|
|
|
/* c8 ignore start */
|
|
|
|
if (checksum !== this.#checksum) {
|
|
|
|
throw new Error(`BIP39 Wordlist for ${this.locale} FAILED`);
|
|
|
|
}
|
|
|
|
/* c8 ignore stop */
|
|
|
|
this.#words = words;
|
|
|
|
}
|
|
|
|
return this.#words;
|
|
|
|
}
|
|
|
|
getWord(index) {
|
|
|
|
const words = this.#loadWords();
|
|
|
|
if (index < 0 || index >= words.length) {
|
2022-09-16 05:58:45 +03:00
|
|
|
throwArgumentError(`invalid word index: ${index}`, "index", index);
|
2022-09-05 23:57:11 +03:00
|
|
|
}
|
|
|
|
return words[index];
|
|
|
|
}
|
|
|
|
getWordIndex(word) {
|
|
|
|
return this.#loadWords().indexOf(word);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=wordlist-owl.js.map
|