WIP: No support for sha256 signatures #2

Draft
lee.miller wants to merge 2 commits from lee.miller/bitmessage-js:sha256 into master

31
test.js
View File

@ -34,6 +34,13 @@ var UserAgent = bitmessage.UserAgent;
var skipPow = {skipPow: true};
describe("Crypto", function() {
// The samples are from PyBitmessage's tests
var samplePublicKey = bmcrypto.getPublic(Buffer.from(
"93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665", "hex")),
sampleSigSHA1 = Buffer.from("30460221008ad234687d1bdc259932e28ea6ee091b88b0900d8134902aa8c2fd7f016b96ed022100dafb94e28322c2fa88878f9dcbf0c2d33270466ab3bbffaec3dca0a2d1ef9354", "hex"),
sampleSigSHA256 = Buffer.from("304402202302475351db6b822de15d922e29397541f10d8a19780ba2ca4a920b1035f07502205e5bba40d5f07a24c23a89ba5f01a3828371dfbb685dd5375fa1c29095fd232b", "hex"),
sampleMessage = Buffer.from("0592a10584ffabf96539f3d780d776828c67da1ab5b169e9e8aed838aaecc9ed36d49ff1423c55f019e050c66c6324f53588be88894fef4dcffdb74b98e2b200", "hex");
it("should implement SHA-1 hash", function() {
expect(bmcrypto.sha1(Buffer.from("test")).toString("hex")).to.equal("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3");
});
@ -101,6 +108,30 @@ describe("Crypto", function() {
});
});
it("should verify sha1 signatures", function() {
return bmcrypto.verify(samplePublicKey, sampleMessage, sampleSigSHA1);
});
it("should verify sha256 signatures", function() {
return bmcrypto.verify(samplePublicKey, sampleMessage, sampleSigSHA256);
});
it("should throw on a bad signature", function(done) {
bmcrypto.verify(
samplePublicKey, sampleMessage, sampleSigSHA1.slice(0, 40)
).catch(function() {
done();
});
});
it("should throw trying to verify a signature with bad pubkey", function(done) {
bmcrypto.verify(
samplePublicKey.slice(2), sampleMessage, sampleSigSHA1
).catch(function() {
done();
});
});
it("should allow to encrypt and decrypt message", function() {
var privateKeyA = bmcrypto.getPrivate();
var publicKeyA = bmcrypto.getPublic(privateKeyA);