commit
41fb2eee57
|
@ -95,7 +95,7 @@ var base58Check = {
|
||||||
var hash = doubleSHA256(data);
|
var hash = doubleSHA256(data);
|
||||||
var hash4 = hash.slice(0, 4);
|
var hash4 = hash.slice(0, 4);
|
||||||
|
|
||||||
if (csum.toString() != hash4.toString()) {
|
if (csum.toString('hex') !== hash4.toString('hex')) {
|
||||||
throw new Error("checksum mismatch");
|
throw new Error("checksum mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ describe('Address', function() {
|
||||||
['11111111111111111111111111122222234', false], // totally invalid
|
['11111111111111111111111111122222234', false], // totally invalid
|
||||||
['32QBdjycLwbDTuGafUwaU5p5GxzSLPYoF6', true],
|
['32QBdjycLwbDTuGafUwaU5p5GxzSLPYoF6', true],
|
||||||
['1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9', true],
|
['1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9', true],
|
||||||
|
['1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', true],
|
||||||
|
['1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNb', false], //bad checksum ... thanks @wtogami
|
||||||
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i', true],
|
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i', true],
|
||||||
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW600', false], // bad checksum
|
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW600', false], // bad checksum
|
||||||
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW620', false], // bad checksum
|
['1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW620', false], // bad checksum
|
||||||
|
@ -225,5 +227,5 @@ describe('Address', function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
|
var should = chai.should();
|
||||||
var assert = chai.assert;
|
var assert = chai.assert;
|
||||||
var bitcore = bitcore || require('../bitcore');
|
var bitcore = bitcore || require('../bitcore');
|
||||||
var base58 = bitcore.Base58.base58;
|
var base58 = bitcore.Base58.base58;
|
||||||
|
@ -50,4 +51,13 @@ describe('Base58', function() {
|
||||||
base58Check.decodeTest(raw, b58Check);
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue