Skip to content

Commit

Permalink
Merge 76804be into 3842ed6
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan X. Charles committed Jul 3, 2014
2 parents 3842ed6 + 76804be commit f58dc81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Base58.js
Expand Up @@ -95,7 +95,7 @@ var base58Check = {
var hash = doubleSHA256(data);
var hash4 = hash.slice(0, 4);

if (csum.toString() != hash4.toString()) {
if (csum.toString('hex') !== hash4.toString('hex')) {
throw new Error("checksum mismatch");
}

Expand Down
4 changes: 3 additions & 1 deletion test/test.Address.js
Expand Up @@ -22,6 +22,8 @@ describe('Address', function() {
['11111111111111111111111111122222234', false], // totally invalid
['32QBdjycLwbDTuGafUwaU5p5GxzSLPYoF6', true],
['1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9', true],
['1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', true],
['1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNb', false], //bad checksum ... thanks @wtogami
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i', true],
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW600', false], // bad checksum
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW620', false], // bad checksum
Expand Down Expand Up @@ -225,5 +227,5 @@ describe('Address', function() {
});
}
});

});
10 changes: 10 additions & 0 deletions test/test.Base58.js
@@ -1,4 +1,5 @@
var chai = chai || require('chai');
var should = chai.should();
var assert = chai.assert;
var bitcore = bitcore || require('../bitcore');
var base58 = bitcore.Base58.base58;
Expand Down Expand Up @@ -50,4 +51,13 @@ describe('Base58', function() {
base58Check.decodeTest(raw, b58Check);
});
});

describe('base58Check', function() {
it('should throw a checksum error on this invalid string', function() {
var str1 = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa";
var str2 = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNb"; //note last character
base58Check.decode(str1).length.should.be.greaterThan(0);
(function(){base58Check.decode(str2)}).should.throw('checksum mismatch');
});
});
});

0 comments on commit f58dc81

Please sign in to comment.