hdnode: add deprecation message for isPrivate

This commit is contained in:
Daniel Cousens 2014-07-30 18:00:20 +10:00
parent 2fbd9449f5
commit 6b429493f8
2 changed files with 16 additions and 7 deletions

View file

@ -157,7 +157,13 @@ HDNode.prototype.toBase58 = function(isPrivate) {
} }
HDNode.prototype.toBuffer = function(isPrivate) { HDNode.prototype.toBuffer = function(isPrivate) {
if (isPrivate == undefined) isPrivate = !!this.privKey if (isPrivate == undefined) {
isPrivate = !!this.privKey
// FIXME: remove in 2.x.y
} else {
console.warn('isPrivate flag is deprecated, please use the .neutered() method instead')
}
// Version // Version
var version = isPrivate ? this.network.bip32.private : this.network.bip32.public var version = isPrivate ? this.network.bip32.private : this.network.bip32.public
@ -183,6 +189,7 @@ HDNode.prototype.toBuffer = function(isPrivate) {
// 33 bytes: the public key or private key data // 33 bytes: the public key or private key data
if (isPrivate) { if (isPrivate) {
// FIXME: remove in 2.x.y
assert(this.privKey, 'Missing private key') assert(this.privKey, 'Missing private key')
// 0x00 + k for private keys // 0x00 + k for private keys

View file

@ -88,9 +88,9 @@ describe('HDNode', function() {
describe('toBase58', function() { describe('toBase58', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
it('exports ' + f.master.base58 + ' (public) correctly', function() { it('exports ' + f.master.base58 + ' (public) correctly', function() {
var hd = HDNode.fromSeedHex(f.master.seed) var hd = HDNode.fromSeedHex(f.master.seed).neutered()
assert.equal(hd.toBase58(false), f.master.base58) assert.equal(hd.toBase58(), f.master.base58)
}) })
}) })
@ -98,10 +98,11 @@ describe('HDNode', function() {
it('exports ' + f.master.base58Priv + ' (private) correctly', function() { it('exports ' + f.master.base58Priv + ' (private) correctly', function() {
var hd = HDNode.fromSeedHex(f.master.seed) var hd = HDNode.fromSeedHex(f.master.seed)
assert.equal(hd.toBase58(true), f.master.base58Priv) assert.equal(hd.toBase58(), f.master.base58Priv)
}) })
}) })
// FIXME: remove in 2.x.y
it('fails when there is no private key', function() { it('fails when there is no private key', function() {
var hd = HDNode.fromBase58(fixtures.valid[0].master.base58) var hd = HDNode.fromBase58(fixtures.valid[0].master.base58)
@ -166,9 +167,9 @@ describe('HDNode', function() {
describe('toBuffer/toHex', function() { describe('toBuffer/toHex', function() {
fixtures.valid.forEach(function(f) { fixtures.valid.forEach(function(f) {
it('exports ' + f.master.hex + ' (public) correctly', function() { it('exports ' + f.master.hex + ' (public) correctly', function() {
var hd = HDNode.fromSeedHex(f.master.seed) var hd = HDNode.fromSeedHex(f.master.seed).neutered()
assert.equal(hd.toHex(false), f.master.hex) assert.equal(hd.toHex(), f.master.hex)
}) })
}) })
@ -176,10 +177,11 @@ describe('HDNode', function() {
it('exports ' + f.master.hexPriv + ' (private) correctly', function() { it('exports ' + f.master.hexPriv + ' (private) correctly', function() {
var hd = HDNode.fromSeedHex(f.master.seed) var hd = HDNode.fromSeedHex(f.master.seed)
assert.equal(hd.toHex(true), f.master.hexPriv) assert.equal(hd.toHex(), f.master.hexPriv)
}) })
}) })
// FIXME: remove in 2.x.y
it('fails when there is no private key', function() { it('fails when there is no private key', function() {
var hd = HDNode.fromHex(fixtures.valid[0].master.hex) var hd = HDNode.fromHex(fixtures.valid[0].master.hex)