Add tests for empty message case (#138)

This commit is contained in:
Lion - dapplion 2022-10-07 18:05:58 +02:00 committed by GitHub
parent 710e7f9f5e
commit c4ea70afd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

@ -63,6 +63,13 @@ export function runIndexTests(bls: IBls): void {
const isValid = bls.verify(pk2.toBytes(), msg, sig.toBytes()); const isValid = bls.verify(pk2.toBytes(), msg, sig.toBytes());
expect(isValid).to.be.false; expect(isValid).to.be.false;
}); });
it("should fail verify empty message", () => {
const emptyMsg = new Uint8Array(0);
const {pk, sig} = getRandomData();
const isValid = sig.verify(pk, emptyMsg);
expect(isValid).equals(false);
});
}); });
describe("verify multiple", () => { describe("verify multiple", () => {
@ -109,6 +116,18 @@ export function runIndexTests(bls: IBls): void {
const isValid = bls.verifyMultiple([], [msg2, msg1], sig); const isValid = bls.verifyMultiple([], [msg2, msg1], sig);
expect(isValid).to.be.false; expect(isValid).to.be.false;
}); });
it("should fail verify empty message", () => {
const sks = getN(2, () => bls.SecretKey.fromKeygen());
const msgs = getN(2, () => randomMessage());
const pks = sks.map((sk) => sk.toPublicKey());
const sigs = [sks[0].sign(msgs[0]), sks[1].sign(msgs[1])];
const aggSig = bls.Signature.aggregate(sigs);
const emptyMsgs = msgs.map(() => new Uint8Array(0));
const isValid = aggSig.verifyMultiple(pks, emptyMsgs);
expect(isValid).equals(false);
});
}); });
describe("verifyMultipleSignatures", () => { describe("verifyMultipleSignatures", () => {
@ -167,6 +186,22 @@ export function runIndexTests(bls: IBls): void {
"Malicous signature should not validate with bls.verifyMultipleSignatures" "Malicous signature should not validate with bls.verifyMultipleSignatures"
); );
}); });
it("should fail verify empty message", () => {
const n = 4;
const sets = getN(n, () => {
const sk = bls.SecretKey.fromKeygen();
const publicKey = sk.toPublicKey();
const message = randomMessage();
const signature = sk.sign(message);
return {publicKey, message, signature};
});
const setsWithEmptyMsgs = sets.map((set) => ({...set, message: new Uint8Array(0)}));
const isValid = bls.Signature.verifyMultipleSignatures(setsWithEmptyMsgs);
expect(isValid).equals(false);
});
}); });
describe("serialize deserialize", () => { describe("serialize deserialize", () => {