mnemonic: better parsing.

This commit is contained in:
Christopher Jeffrey 2017-08-10 06:22:33 -07:00
parent bff9e25796
commit 50b8dd2b2c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -475,17 +475,21 @@ Mnemonic.prototype.toRaw = function toRaw(writer) {
*/
Mnemonic.prototype.fromReader = function fromReader(br) {
this.bits = br.readU16();
this.language = Mnemonic.languages[br.readU8()];
this.entropy = br.readBytes(this.bits / 8);
const bits = br.readU16();
assert(bits >= common.MIN_ENTROPY);
assert(bits <= common.MAX_ENTROPY);
assert(bits % 32 === 0);
const language = Mnemonic.languages[br.readU8()];
assert(language);
this.bits = bits;
this.language = language;
this.entropy = br.readBytes(bits / 8);
this.phrase = br.readVarString('utf8');
this.passphrase = br.readVarString('utf8');
assert(this.language);
assert(this.bits >= common.MIN_ENTROPY);
assert(this.bits <= common.MAX_ENTROPY);
assert(this.bits % 32 === 0);
return this;
};