HDNode: add neuter functionality
This commit is contained in:
parent
e69ba7ce76
commit
9d92b6a1a8
@ -143,6 +143,15 @@ HDNode.prototype.getAddress = function() {
|
|||||||
return this.pubKey.getAddress(this.network)
|
return this.pubKey.getAddress(this.network)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HDNode.prototype.neutered = function() {
|
||||||
|
var neutered = new HDNode(this.pubKey.Q, this.chainCode, this.network)
|
||||||
|
neutered.depth = this.depth
|
||||||
|
neutered.index = this.index
|
||||||
|
neutered.parentFingerprint = this.parentFingerprint
|
||||||
|
|
||||||
|
return neutered
|
||||||
|
}
|
||||||
|
|
||||||
HDNode.prototype.toBase58 = function(isPrivate) {
|
HDNode.prototype.toBase58 = function(isPrivate) {
|
||||||
return base58check.encode(this.toBuffer(isPrivate))
|
return base58check.encode(this.toBuffer(isPrivate))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -226,6 +226,21 @@ describe('HDNode', function() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('neutered', function() {
|
||||||
|
var f = fixtures.valid[0]
|
||||||
|
|
||||||
|
it('strips all private information', function() {
|
||||||
|
var hd = HDNode.fromBase58(f.master.base58)
|
||||||
|
var hdn = hd.neutered()
|
||||||
|
|
||||||
|
assert.equal(hdn.privKey, undefined)
|
||||||
|
assert.equal(hdn.pubKey.toHex(), hd.pubKey.toHex())
|
||||||
|
assert.equal(hdn.chainCode, hd.chainCode)
|
||||||
|
assert.equal(hdn.depth, hd.depth)
|
||||||
|
assert.equal(hdn.index, hd.index)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('derive', function() {
|
describe('derive', function() {
|
||||||
function verifyVector(hd, v, depth) {
|
function verifyVector(hd, v, depth) {
|
||||||
assert.equal(hd.privKey.toWIF(), v.wif)
|
assert.equal(hd.privKey.toWIF(), v.wif)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user