|
|
@ -68,10 +68,10 @@ BIP32.prototype.initFromBytes = function(bytes) { |
|
|
|
if (bytes.length != 78) |
|
|
|
throw new Error('not enough data'); |
|
|
|
|
|
|
|
this.version = u32(bytes.slice(0, 4)); |
|
|
|
this.depth = u8(bytes.slice(4, 5)); |
|
|
|
this.version = bytes.slice(0, 4).readUInt32BE(0); |
|
|
|
this.depth = bytes.slice(4, 5).readUInt8(0); |
|
|
|
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); |
|
|
|
|
|
|
|
var keyBytes = bytes.slice(45, 78); |
|
|
@ -303,31 +303,4 @@ BIP32.prototype.toString = function() { |
|
|
|
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; |
|
|
|