Merge pull request #282 from dcousens/nobuff

Deprecate Buffer interop in preparation for 2.0.0
This commit is contained in:
Wei Lu 2014-09-22 20:50:49 +08:00
commit 6cd8fc3fe0

View file

@ -72,10 +72,15 @@ HDNode.fromSeedHex = function(hex, network) {
} }
HDNode.fromBase58 = function(string) { HDNode.fromBase58 = function(string) {
return HDNode.fromBuffer(base58check.decode(string)) return HDNode.fromBuffer(base58check.decode(string), true)
} }
HDNode.fromBuffer = function(buffer) { // FIXME: remove in 2.x.y
HDNode.fromBuffer = function(buffer, __ignoreDeprecation) {
if (!__ignoreDeprecation) {
console.warn('HDNode.fromBuffer() is deprecated for removal in 2.x.y, use fromBase58 instead')
}
assert.strictEqual(buffer.length, HDNode.LENGTH, 'Invalid buffer length') assert.strictEqual(buffer.length, HDNode.LENGTH, 'Invalid buffer length')
// 4 byte: version bytes // 4 byte: version bytes
@ -127,6 +132,7 @@ HDNode.fromBuffer = function(buffer) {
return hd return hd
} }
// FIXME: remove in 2.x.y
HDNode.fromHex = function(hex) { HDNode.fromHex = function(hex) {
return HDNode.fromBuffer(new Buffer(hex, 'hex')) return HDNode.fromBuffer(new Buffer(hex, 'hex'))
} }
@ -153,10 +159,11 @@ HDNode.prototype.neutered = function() {
} }
HDNode.prototype.toBase58 = function(isPrivate) { HDNode.prototype.toBase58 = function(isPrivate) {
return base58check.encode(this.toBuffer(isPrivate)) return base58check.encode(this.toBuffer(isPrivate, true))
} }
HDNode.prototype.toBuffer = function(isPrivate) { // FIXME: remove in 2.x.y
HDNode.prototype.toBuffer = function(isPrivate, __ignoreDeprecation) {
if (isPrivate == undefined) { if (isPrivate == undefined) {
isPrivate = !!this.privKey isPrivate = !!this.privKey
@ -165,6 +172,10 @@ HDNode.prototype.toBuffer = function(isPrivate) {
console.warn('isPrivate flag is deprecated, please use the .neutered() method instead') console.warn('isPrivate flag is deprecated, please use the .neutered() method instead')
} }
if (!__ignoreDeprecation) {
console.warn('HDNode.toBuffer() is deprecated for removal in 2.x.y, use toBase58 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
var buffer = new Buffer(HDNode.LENGTH) var buffer = new Buffer(HDNode.LENGTH)
@ -204,6 +215,7 @@ HDNode.prototype.toBuffer = function(isPrivate) {
return buffer return buffer
} }
// FIXME: remove in 2.x.y
HDNode.prototype.toHex = function(isPrivate) { HDNode.prototype.toHex = function(isPrivate) {
return this.toBuffer(isPrivate).toString('hex') return this.toBuffer(isPrivate).toString('hex')
} }