ethers.js/packages/wordlists/lib/wordlist.js

57 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2019-05-14 18:48:48 -04:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2021-03-07 18:24:04 -05:00
exports.Wordlist = exports.logger = void 0;
// This gets overridden by rollup
2019-05-14 18:48:48 -04:00
var exportWordlist = false;
var hash_1 = require("@ethersproject/hash");
var properties_1 = require("@ethersproject/properties");
2019-08-02 02:10:58 -04:00
var logger_1 = require("@ethersproject/logger");
var _version_1 = require("./_version");
exports.logger = new logger_1.Logger(_version_1.version);
2019-05-14 18:48:48 -04:00
var Wordlist = /** @class */ (function () {
function Wordlist(locale) {
var _newTarget = this.constructor;
exports.logger.checkAbstract(_newTarget, Wordlist);
2021-10-16 02:29:27 -04:00
(0, properties_1.defineReadOnly)(this, "locale", locale);
2019-05-14 18:48:48 -04:00
}
// Subclasses may override this
Wordlist.prototype.split = function (mnemonic) {
return mnemonic.toLowerCase().split(/ +/g);
};
// Subclasses may override this
Wordlist.prototype.join = function (words) {
return words.join(" ");
};
Wordlist.check = function (wordlist) {
var words = [];
for (var i = 0; i < 2048; i++) {
var word = wordlist.getWord(i);
2020-07-13 08:03:56 -04:00
/* istanbul ignore if */
if (i !== wordlist.getWordIndex(word)) {
return "0x";
}
words.push(word);
2019-05-14 18:48:48 -04:00
}
2021-10-16 02:29:27 -04:00
return (0, hash_1.id)(words.join("\n") + "\n");
};
Wordlist.register = function (lang, name) {
if (!name) {
name = lang.locale;
2019-05-14 18:48:48 -04:00
}
2020-07-13 08:03:56 -04:00
/* istanbul ignore if */
if (exportWordlist) {
2019-11-24 19:13:37 +09:00
try {
var anyGlobal = window;
if (anyGlobal._ethers && anyGlobal._ethers.wordlists) {
if (!anyGlobal._ethers.wordlists[name]) {
2021-10-16 02:29:27 -04:00
(0, properties_1.defineReadOnly)(anyGlobal._ethers.wordlists, name, lang);
2019-11-24 19:13:37 +09:00
}
}
2019-05-14 18:48:48 -04:00
}
2019-11-25 00:02:22 +09:00
catch (error) { }
2019-05-14 18:48:48 -04:00
}
};
return Wordlist;
}());
exports.Wordlist = Wordlist;
2020-07-13 08:03:56 -04:00
//# sourceMappingURL=wordlist.js.map