Browse Source

Base58Check.prototype.set

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

12
lib/base58check.js

@ -1,10 +1,16 @@
var base58 = require('./base58');
var sha256sha256 = require('./hash').sha256sha256;
var Base58Check = function Base58Check(buf) {
var Base58Check = function Base58Check(obj) {
if (!(this instanceof Base58Check))
return new Base58Check(buf);
this.buf = buf;
return new Base58Check(obj);
if (obj)
this.set(obj);
};
Base58Check.prototype.set = function(obj) {
this.buf = obj.buf || this.buf || undefined;
return this;
};
Base58Check.decode = function(s) {

12
test/test.base58check.js

@ -16,6 +16,14 @@ describe('Base58Check', function() {
should.exist(b58);
});
describe('#set', function() {
it('should set a buf', function() {
should.exist(Base58Check().set({buf: buf}).buf);
});
});
describe('@encode', function() {
it('should encode the buffer accurately', function() {
@ -83,7 +91,7 @@ describe('Base58Check', function() {
describe('#toBuffer', function() {
it('should return the buffer', function() {
var b58 = Base58Check(buf);
var b58 = Base58Check({buf: buf});
b58.buf.toString('hex').should.equal(buf.toString('hex'));
});
@ -92,7 +100,7 @@ describe('Base58Check', function() {
describe('#toString', function() {
it('should return the buffer', function() {
var b58 = Base58Check(buf);
var b58 = Base58Check({buf: buf});
b58.toString().should.equal(enc);
});

Loading…
Cancel
Save