Browse Source

add set function to Base58

patch-2
Ryan X. Charles 11 years ago
parent
commit
da8989b649
  1. 12
      lib/base58.js
  2. 12
      test/test.base58.js

12
lib/base58.js

@ -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) {

12
test/test.base58.js

@ -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);
});

Loading…
Cancel
Save