diff --git a/lib/base58check.js b/lib/base58check.js index d211c39..9bc78ee 100644 --- a/lib/base58check.js +++ b/lib/base58check.js @@ -1,10 +1,16 @@ var base58 = require('./base58'); var sha256sha256 = require('./hash').sha256sha256; -var Base58Check = function Base58Check(buf) { +var Base58Check = function Base58Check(obj) { if (!(this instanceof Base58Check)) - return new Base58Check(buf); - this.buf = buf; + return new Base58Check(obj); + if (obj) + this.set(obj); +}; + +Base58Check.prototype.set = function(obj) { + this.buf = obj.buf || this.buf || undefined; + return this; }; Base58Check.decode = function(s) { diff --git a/test/test.base58check.js b/test/test.base58check.js index 58e2bb6..635198c 100644 --- a/test/test.base58check.js +++ b/test/test.base58check.js @@ -16,6 +16,14 @@ describe('Base58Check', function() { should.exist(b58); }); + describe('#set', function() { + + it('should set a buf', function() { + should.exist(Base58Check().set({buf: buf}).buf); + }); + + }); + describe('@encode', function() { it('should encode the buffer accurately', function() { @@ -83,7 +91,7 @@ describe('Base58Check', function() { describe('#toBuffer', function() { it('should return the buffer', function() { - var b58 = Base58Check(buf); + var b58 = Base58Check({buf: buf}); b58.buf.toString('hex').should.equal(buf.toString('hex')); }); @@ -92,7 +100,7 @@ describe('Base58Check', function() { describe('#toString', function() { it('should return the buffer', function() { - var b58 = Base58Check(buf); + var b58 = Base58Check({buf: buf}); b58.toString().should.equal(enc); });