From d2c11ed16ca415c758578ce7ef9cb22cf36714d8 Mon Sep 17 00:00:00 2001 From: dapplion Date: Wed, 2 Dec 2020 23:32:42 +0000 Subject: [PATCH] Use class interface for more transparent errors --- test/unit/index.test.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index 9cc1672..47d6074 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -107,6 +107,8 @@ export function runIndexTests(bls: IBls): void { const msgs = dataArr.map((data) => data.msg); const sigs = dataArr.map((data) => data.sig); + expect(bls.Signature.verifyMultipleSignatures(pks, msgs, sigs)).to.equal(true, "class interface failed"); + expect( bls.verifyMultipleSignatures( pks.map((pk) => pk.toBytes()), @@ -114,31 +116,30 @@ export function runIndexTests(bls: IBls): void { sigs.map((sig) => sig.toBytes()) ) ).to.equal(true, "functional (bytes serialized) interface failed"); - - expect(bls.Signature.verifyMultipleSignatures(pks, msgs, sigs)).to.equal(true, "class interface failed"); }); it("Test fails correctly against a malicous signature", async () => { - const pks = maliciousVerifyMultipleSignaturesData.pks.map(hexToBytes); + const pks = maliciousVerifyMultipleSignaturesData.pks.map(bls.PublicKey.fromHex); const msgs = maliciousVerifyMultipleSignaturesData.msgs.map(hexToBytes); - const sigs = maliciousVerifyMultipleSignaturesData.sigs.map(hexToBytes); + const sigs = maliciousVerifyMultipleSignaturesData.sigs.map(bls.Signature.fromHex); maliciousVerifyMultipleSignaturesData.manipulated.forEach((isManipulated, i) => { - expect(bls.verify(pks[i], msgs[i], sigs[i])).to.equal( + expect(sigs[i].verify(pks[i], msgs[i])).to.equal( !isManipulated, isManipulated ? "Manipulated signature should not verify" : "Ok signature should verify" ); }); // This method (AggregateVerify in BLS spec lingo) should verify - const dangerousAggSig = bls.aggregateSignatures(sigs); - expect(bls.verifyMultiple(pks, msgs, dangerousAggSig)).to.equal( + + const dangerousAggSig = bls.Signature.aggregate(sigs); + expect(dangerousAggSig.verifyMultiple(pks, msgs)).to.equal( true, "Malicious signature should be validated with bls.verifyMultiple" ); // This method is expected to catch the malicious signature and not verify - expect(bls.verifyMultipleSignatures(pks, msgs, sigs)).to.equal( + expect(bls.Signature.verifyMultipleSignatures(pks, msgs, sigs)).to.equal( false, "Malicous signature should not validate with bls.verifyMultipleSignatures" );