From ad8ccc493033f2affade8e576f04a0ffe4ecbd5a Mon Sep 17 00:00:00 2001 From: Stephen Pair Date: Sun, 7 Jul 2013 15:52:37 -0400 Subject: [PATCH] make binary conversion copy the buffer to avoid overwrite issues --- BitcoinAddress.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BitcoinAddress.js b/BitcoinAddress.js index 88d472a..ea2340d 100644 --- a/BitcoinAddress.js +++ b/BitcoinAddress.js @@ -90,6 +90,11 @@ function ClassSpec(b) { var encodings = { 'binary': { converters: { + 'binary': function() { + var answer = new Buffer(this.data.length); + this.data.copy(answer); + return answer; + }, 'base58': function() { return base58.encode(this.data); }, @@ -127,7 +132,8 @@ function ClassSpec(b) { }; for(var k in encodings) { - encodings[k].converters[k] = function() {return this.data;}; + if(!encodings[k].converters[k]) + encodings[k].converters[k] = function() {return this.data;}; encodings[k]._encoding = k; encodings[k].__proto__ = BitcoinAddress.prototype; };