diff --git a/lib/base58.js b/lib/base58.js index da977ca3c..cf1357314 100644 --- a/lib/base58.js +++ b/lib/base58.js @@ -3,8 +3,15 @@ var bs58 = require('bs58'); var Base58 = function Base58(obj) { if (!(this instanceof Base58)) return new Base58(obj); - if (obj) + if (Buffer.isBuffer(obj)) { + var buf = obj; + this.fromBuffer(buf); + } else if (typeof obj === 'string') { + var str = obj; + this.fromString(str); + } else if (obj) { this.set(obj); + } }; Base58.prototype.set = function(obj) { diff --git a/test/base58.js b/test/base58.js index fca7d9a32..11fe97607 100644 --- a/test/base58.js +++ b/test/base58.js @@ -15,6 +15,11 @@ describe('Base58', function() { should.exist(b58); }); + it('should allow this handy syntax', function() { + Base58(buf).toString().should.equal(enc); + Base58(enc).toBuffer().toString('hex').should.equal(buf.toString('hex')) + }); + describe('#set', function() { it('should set a blank buffer', function() {