Browse Source

lib/hdkey: cleaned up serialize()

master
JP Richardson 11 years ago
parent
commit
be23e91803
  1. 38
      lib/hdkey.js

38
lib/hdkey.js

@ -182,30 +182,20 @@ HDKey.fromMasterSeed = function(seedBuffer, versions) {
}
function serialize(hdkey, version, key) {
var buffer = new Buffer(LEN)
// 4 bytes: version bytes
buffer.writeUInt32BE(version, 0)
// Depth
// 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ....
buffer.writeUInt8(hdkey.depth, 4)
// 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
var fingerprint = hdkey.depth ? hdkey.parentFingerprint : 0x00000000
buffer.writeUInt32BE(fingerprint, 5)
// 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
// This is encoded in Big endian. (0x00000000 if master key)
buffer.writeUInt32BE(hdkey.index, 9)
// 32 bytes: the chain code
hdkey.chainCode.copy(buffer, 13)
// 0x00 + k for private keys
key.copy(buffer, 45)
return buffer
// => version(4) || depth(1) || fingerprint(4) || index(4) || chain(32) || key(33)
var buffer = new Buffer(LEN)
buffer.writeUInt32BE(version, 0)
buffer.writeUInt8(hdkey.depth, 4)
var fingerprint = hdkey.depth ? hdkey.parentFingerprint : 0x00000000
buffer.writeUInt32BE(fingerprint, 5)
buffer.writeUInt32BE(hdkey.index, 9)
hdkey.chainCode.copy(buffer, 13)
key.copy(buffer, 45)
return buffer
}
function hash160(buf) {

Loading…
Cancel
Save