Skip to content

Commit 6cd8fc3

Browse files
committed
Merge pull request #282 from dcousens/nobuff
Deprecate Buffer interop in preparation for 2.0.0
2 parents 1dad7b6 + a580887 commit 6cd8fc3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/hdnode.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ HDNode.fromSeedHex = function(hex, network) {
7272
}
7373

7474
HDNode.fromBase58 = function(string) {
75-
return HDNode.fromBuffer(base58check.decode(string))
75+
return HDNode.fromBuffer(base58check.decode(string), true)
7676
}
7777

78-
HDNode.fromBuffer = function(buffer) {
78+
// FIXME: remove in 2.x.y
79+
HDNode.fromBuffer = function(buffer, __ignoreDeprecation) {
80+
if (!__ignoreDeprecation) {
81+
console.warn('HDNode.fromBuffer() is deprecated for removal in 2.x.y, use fromBase58 instead')
82+
}
83+
7984
assert.strictEqual(buffer.length, HDNode.LENGTH, 'Invalid buffer length')
8085

8186
// 4 byte: version bytes
@@ -127,6 +132,7 @@ HDNode.fromBuffer = function(buffer) {
127132
return hd
128133
}
129134

135+
// FIXME: remove in 2.x.y
130136
HDNode.fromHex = function(hex) {
131137
return HDNode.fromBuffer(new Buffer(hex, 'hex'))
132138
}
@@ -153,10 +159,11 @@ HDNode.prototype.neutered = function() {
153159
}
154160

155161
HDNode.prototype.toBase58 = function(isPrivate) {
156-
return base58check.encode(this.toBuffer(isPrivate))
162+
return base58check.encode(this.toBuffer(isPrivate, true))
157163
}
158164

159-
HDNode.prototype.toBuffer = function(isPrivate) {
165+
// FIXME: remove in 2.x.y
166+
HDNode.prototype.toBuffer = function(isPrivate, __ignoreDeprecation) {
160167
if (isPrivate == undefined) {
161168
isPrivate = !!this.privKey
162169

@@ -165,6 +172,10 @@ HDNode.prototype.toBuffer = function(isPrivate) {
165172
console.warn('isPrivate flag is deprecated, please use the .neutered() method instead')
166173
}
167174

175+
if (!__ignoreDeprecation) {
176+
console.warn('HDNode.toBuffer() is deprecated for removal in 2.x.y, use toBase58 instead')
177+
}
178+
168179
// Version
169180
var version = isPrivate ? this.network.bip32.private : this.network.bip32.public
170181
var buffer = new Buffer(HDNode.LENGTH)
@@ -204,6 +215,7 @@ HDNode.prototype.toBuffer = function(isPrivate) {
204215
return buffer
205216
}
206217

218+
// FIXME: remove in 2.x.y
207219
HDNode.prototype.toHex = function(isPrivate) {
208220
return this.toBuffer(isPrivate).toString('hex')
209221
}

0 commit comments

Comments
 (0)