mnemonic: fix an error for certain languages.
This commit is contained in:
parent
ed4ce0f032
commit
9f3a040758
@ -245,7 +245,7 @@ Mnemonic.prototype.fromPhrase = function fromPhrase(phrase) {
|
||||
// Rebuild entropy bytes.
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
const word = words[i];
|
||||
const index = util.binarySearch(wordlist, word, util.strcmp);
|
||||
const index = wordlist.indexOf(word);
|
||||
|
||||
if (index === -1)
|
||||
throw new Error('Could not find word.');
|
||||
@ -338,7 +338,7 @@ Mnemonic.fromEntropy = function fromEntropy(entropy, lang) {
|
||||
Mnemonic.getLanguage = function getLanguage(word) {
|
||||
for (const lang of Mnemonic.languages) {
|
||||
const wordlist = Mnemonic.getWordlist(lang);
|
||||
if (util.binarySearch(wordlist, word, util.strcmp) !== -1)
|
||||
if (wordlist.indexOf(word) !== -1)
|
||||
return lang;
|
||||
}
|
||||
|
||||
|
||||
@ -13,8 +13,8 @@ const tests = {
|
||||
};
|
||||
|
||||
describe('Mnemonic', function() {
|
||||
for (const lang of Object.keys(tests)) {
|
||||
const test = tests[lang];
|
||||
for (const language of Object.keys(tests)) {
|
||||
const test = tests[language];
|
||||
let i = 0;
|
||||
|
||||
for (const data of test) {
|
||||
@ -23,19 +23,38 @@ describe('Mnemonic', function() {
|
||||
const passphrase = data[2];
|
||||
const seed = Buffer.from(data[3], 'hex');
|
||||
const xpriv = data[4];
|
||||
it(`should create a ${lang} mnemonic (${i++})`, () => {
|
||||
|
||||
it(`should create a ${language} mnemonic from entropy (${i})`, () => {
|
||||
const mnemonic = new Mnemonic({
|
||||
language: lang,
|
||||
entropy: entropy,
|
||||
passphrase: passphrase
|
||||
language,
|
||||
entropy,
|
||||
passphrase
|
||||
});
|
||||
|
||||
assert.strictEqual(mnemonic.getPhrase(), phrase);
|
||||
assert.deepStrictEqual(mnemonic.getEntropy(), entropy);
|
||||
assert.deepStrictEqual(mnemonic.toSeed(), seed);
|
||||
|
||||
const key = HDPrivateKey.fromMnemonic(mnemonic);
|
||||
assert.strictEqual(key.toBase58(), xpriv);
|
||||
});
|
||||
|
||||
it(`should create a ${language} mnemonic from phrase (${i})`, () => {
|
||||
const mnemonic = new Mnemonic({
|
||||
language,
|
||||
phrase,
|
||||
passphrase
|
||||
});
|
||||
|
||||
assert.strictEqual(mnemonic.getPhrase(), phrase);
|
||||
assert.deepStrictEqual(mnemonic.getEntropy(), entropy);
|
||||
assert.deepStrictEqual(mnemonic.toSeed(), seed);
|
||||
|
||||
const key = HDPrivateKey.fromMnemonic(mnemonic);
|
||||
assert.strictEqual(key.toBase58(), xpriv);
|
||||
});
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user