diff --git a/lib/base58check.js b/lib/base58check.js index 9bc78ee19..7b5fb954b 100644 --- a/lib/base58check.js +++ b/lib/base58check.js @@ -4,8 +4,15 @@ var sha256sha256 = require('./hash').sha256sha256; var Base58Check = function Base58Check(obj) { if (!(this instanceof Base58Check)) return new Base58Check(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); + } }; Base58Check.prototype.set = function(obj) { diff --git a/test/base58check.js b/test/base58check.js index 635198cf7..bc7081fac 100644 --- a/test/base58check.js +++ b/test/base58check.js @@ -16,6 +16,11 @@ describe('Base58Check', function() { should.exist(b58); }); + it('should allow this handy syntax', function() { + Base58Check(buf).toString().should.equal(enc); + Base58Check(enc).toBuffer().toString('hex').should.equal(buf.toString('hex')); + }); + describe('#set', function() { it('should set a buf', function() {