add set function to Base58
This commit is contained in:
parent
6b7592d67b
commit
da8989b649
|
@ -1,9 +1,15 @@
|
||||||
var bs58 = require('bs58');
|
var bs58 = require('bs58');
|
||||||
|
|
||||||
var Base58 = function Base58(buf) {
|
var Base58 = function Base58(obj) {
|
||||||
if (!(this instanceof Base58))
|
if (!(this instanceof Base58))
|
||||||
return new Base58(buf);
|
return new Base58(obj);
|
||||||
this.buf = buf;
|
if (obj)
|
||||||
|
this.set(obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
Base58.prototype.set = function(obj) {
|
||||||
|
this.buf = obj.buf || this.buf || undefined;
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Base58.encode = function(buf) {
|
Base58.encode = function(buf) {
|
||||||
|
|
|
@ -15,6 +15,14 @@ describe('Base58', function() {
|
||||||
should.exist(b58);
|
should.exist(b58);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#set', function() {
|
||||||
|
|
||||||
|
it('should set a blank buffer', function() {
|
||||||
|
Base58().set({buf: new Buffer([])});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('@encode', function() {
|
describe('@encode', function() {
|
||||||
|
|
||||||
it('should encode the buffer accurately', function() {
|
it('should encode the buffer accurately', function() {
|
||||||
|
@ -67,7 +75,7 @@ describe('Base58', function() {
|
||||||
describe('#toBuffer', function() {
|
describe('#toBuffer', function() {
|
||||||
|
|
||||||
it('should return the buffer', 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'));
|
b58.buf.toString('hex').should.equal(buf.toString('hex'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -76,7 +84,7 @@ describe('Base58', function() {
|
||||||
describe('#toString', function() {
|
describe('#toString', function() {
|
||||||
|
|
||||||
it('should return the buffer', function() {
|
it('should return the buffer', function() {
|
||||||
var b58 = Base58(buf);
|
var b58 = Base58({buf: buf});
|
||||||
b58.toString().should.equal(enc);
|
b58.toString().should.equal(enc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue