|
|
@ -67,6 +67,38 @@ Object.defineProperty(HDKey.prototype, 'private', { |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
Object.defineProperty(HDKey.prototype, 'public', { |
|
|
|
get: function() { |
|
|
|
// Version
|
|
|
|
var version = VERSIONS.public |
|
|
|
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(this.depth, 4) |
|
|
|
|
|
|
|
// 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
|
|
|
|
var fingerprint = this.depth ? this.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(this.index, 9) |
|
|
|
|
|
|
|
// 32 bytes: the chain code
|
|
|
|
this.chaincode.copy(buffer, 13) |
|
|
|
|
|
|
|
// X9.62 encoding for public keys
|
|
|
|
var buf = new Buffer(this.pub.getEncoded(true)) |
|
|
|
buf.copy(buffer, 45) |
|
|
|
|
|
|
|
return buffer |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
HDKey.prototype.getIdentifier = function() { |
|
|
|
//just computing pubKeyHash here
|
|
|
|
var buf = new Buffer(this.pub.getEncoded(true)) |
|
|
|