add set function to Base58

This commit is contained in:
Ryan X. Charles 2014-08-28 15:27:58 -07:00
parent 6b7592d67b
commit da8989b649
2 changed files with 19 additions and 5 deletions

View File

@ -1,9 +1,15 @@
var bs58 = require('bs58');
var Base58 = function Base58(buf) {
var Base58 = function Base58(obj) {
if (!(this instanceof Base58))
return new Base58(buf);
this.buf = buf;
return new Base58(obj);
if (obj)
this.set(obj);
};
Base58.prototype.set = function(obj) {
this.buf = obj.buf || this.buf || undefined;
return this;
};
Base58.encode = function(buf) {

View File

@ -15,6 +15,14 @@ describe('Base58', function() {
should.exist(b58);
});
describe('#set', function() {
it('should set a blank buffer', function() {
Base58().set({buf: new Buffer([])});
});
});
describe('@encode', function() {
it('should encode the buffer accurately', function() {
@ -67,7 +75,7 @@ describe('Base58', function() {
describe('#toBuffer', function() {
it('should return the buffer', function() {
var b58 = Base58(buf);
var b58 = Base58({buf: buf});
b58.buf.toString('hex').should.equal(buf.toString('hex'));
});
@ -76,7 +84,7 @@ describe('Base58', function() {
describe('#toString', function() {
it('should return the buffer', function() {
var b58 = Base58(buf);
var b58 = Base58({buf: buf});
b58.toString().should.equal(enc);
});