Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binary string comparison failure #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base58.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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
19 changes: 18 additions & 1 deletion test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ var testData = [
["ecac89cad93923c02321", "EJDM8drfXA6uyA", "2W1Yd5Zu6WGyKVtHGMrH"],
["10c8511e", "Rt5zm", "3op3iuGMmhs"],
["00000000000000000000", "1111111111", "111111111146Momb"],
["", "", "3QJmnh"]
["", "", "3QJmnh"],
["0062e907b15cbf27d5425399ebf6f0fb50ebb88f18", "12NvYg7CXwVYtMDYia7n9viekJ6d5", "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"]
];

var invalidTestData = [
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNb"
];

suite('basic');
Expand Down Expand Up @@ -46,4 +51,16 @@ test('allData', function() {
base58Check.encodeTest(raw, b58Check);
base58Check.decodeTest(raw, b58Check);
});

base58Check.invalidDecodeTest = function(b58str) {
assert.throws(function(){
base58Check.decode(b58str);
},
/checksum mismatch/
);
};

invalidTestData.forEach(function(datum) {
base58Check.invalidDecodeTest(datum);
});
});