parent
5da964739d
commit
c41419b6ef
33
lib/bip32.js
33
lib/bip32.js
|
@ -68,10 +68,10 @@ BIP32.prototype.initFromBytes = function(bytes) {
|
||||||
if (bytes.length != 78)
|
if (bytes.length != 78)
|
||||||
throw new Error('not enough data');
|
throw new Error('not enough data');
|
||||||
|
|
||||||
this.version = u32(bytes.slice(0, 4));
|
this.version = bytes.slice(0, 4).readUInt32BE(0);
|
||||||
this.depth = u8(bytes.slice(4, 5));
|
this.depth = bytes.slice(4, 5).readUInt8(0);
|
||||||
this.parentFingerprint = bytes.slice(5, 9);
|
this.parentFingerprint = bytes.slice(5, 9);
|
||||||
this.childIndex = u32(bytes.slice(9, 13));
|
this.childIndex = bytes.slice(9, 13).readUInt32BE(0);
|
||||||
this.chainCode = bytes.slice(13, 45);
|
this.chainCode = bytes.slice(13, 45);
|
||||||
|
|
||||||
var keyBytes = bytes.slice(45, 78);
|
var keyBytes = bytes.slice(45, 78);
|
||||||
|
@ -303,31 +303,4 @@ BIP32.prototype.toString = function() {
|
||||||
return this.extendedPublicKeyString();
|
return this.extendedPublicKeyString();
|
||||||
};
|
};
|
||||||
|
|
||||||
function uint(f, size) {
|
|
||||||
if (f.length < size)
|
|
||||||
throw new Error('not enough data');
|
|
||||||
var n = 0;
|
|
||||||
for (var i = 0; i < size; i++) {
|
|
||||||
n *= 256;
|
|
||||||
n += f[i];
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
function u8(f) {
|
|
||||||
return uint(f, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function u16(f) {
|
|
||||||
return uint(f, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function u32(f) {
|
|
||||||
return uint(f, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
function u64(f) {
|
|
||||||
return uint(f, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = BIP32;
|
module.exports = BIP32;
|
||||||
|
|
|
@ -324,7 +324,6 @@ describe('BIP32', function() {
|
||||||
tip32b.toString().slice(0, 4).should.equal('tpub');
|
tip32b.toString().slice(0, 4).should.equal('tpub');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue