public void VerifyThrowsIfInvalidSignature() { var blsKeyPair = BbsProvider.GenerateBlsKey(); var bbsKeyPair = blsKeyPair.GeyBbsKeyPair(1); Assert.Throws <BbsException>(() => BbsProvider.Verify(new VerifyRequest(blsKeyPair, Array.Empty <byte>(), new[] { "message_0" })), "Signature cannot be empty array"); }
public void SignMultipleeMessages() { var keyPair = BbsProvider.GenerateBlsKey(); var signature = BbsProvider.Sign(new SignRequest(keyPair, new[] { "message_1", "message_2" })); Assert.NotNull(signature); Assert.AreEqual(BbsProvider.SignatureSize, signature.Length); }
public void SignSingleMessageUsingApi() { var myKey = BbsProvider.GenerateBlsKey(); var signature = BbsProvider.Sign(new SignRequest(myKey, new[] { "message" })); Assert.NotNull(signature); Assert.AreEqual(signature.Length, Native.bbs_signature_size()); }
public void SignAndVerifyDifferentKeys() { var keyPair = BbsProvider.GenerateBlsKey(); var messages = new[] { "message_1", "message_2" }; var signature = BbsProvider.Sign(new SignRequest(keyPair, messages)); var result = BbsProvider.Verify(new VerifyRequest(keyPair.GeyBbsKeyPair(2), signature, messages)); Assert.True(result); }
public void CreateBbsKeyFromBlsSecretKey() { var secretKey = BbsProvider.GenerateBlsKey(); var publicKey = secretKey.GeyBbsKeyPair(1); Assert.NotNull(secretKey); Assert.NotNull(publicKey); Assert.NotNull(secretKey.SecretKey); Assert.AreEqual(196, publicKey.PublicKey.Count); Assert.AreEqual(32, secretKey.SecretKey.Count); }
public void GenerateBlsKeyWithoutSeed() { var blsKeyPair = BbsProvider.GenerateBlsKey(); var dPublicKey = blsKeyPair.PublicKey; Assert.NotNull(blsKeyPair); Assert.NotNull(dPublicKey); Assert.NotNull(blsKeyPair.SecretKey); Assert.AreEqual(96, dPublicKey.Count); Assert.AreEqual(32, blsKeyPair.SecretKey.Count); }
public void GenerateKeyWithSeed() { var seed = new byte[] { 1, 2, 3 }; var actual = BbsProvider.GenerateBlsKey(seed); Assert.NotNull(actual); Assert.NotNull(actual.SecretKey); Assert.NotNull(actual.PublicKey); Assert.AreEqual(32, actual.SecretKey.Count); Assert.AreEqual(96, actual.PublicKey.Count); }
public void SignVerifiableCredential() { var keyPair = BbsProvider.GenerateBlsKey(); var document = Utilities.LoadJson("Data/test_vc.json"); var proof = LdProofService.CreateProof(new CreateProofOptions { Document = document, LdSuiteType = BbsBlsSignature2020.Name, ProofPurpose = ProofPurposeNames.AssertionMethod, VerificationMethod = keyPair.ToVerificationMethod("did:example:12345#test") }); proof.Should().NotBeNull(); proof["proofValue"].Should().NotBeNull(); }
public void BlindCommitmentSingleMessageUsingApi() { var myKey = BbsProvider.GenerateBlsKey(); var publicKey = myKey.GeyBbsKeyPair(1); var commitment = BbsProvider.CreateBlindedCommitment(new CreateBlindedCommitmentRequest( publicKey: publicKey, messages: new[] { new IndexedMessage { Index = 0, Message = "message_0" } }, nonce: "123")); Assert.NotNull(commitment); Assert.NotNull(commitment.BlindingFactor); Assert.NotNull(commitment.BlindSignContext); Assert.NotNull(commitment.Commitment); }
public void CreateBbsKeyFromBlsPublicKey() { var blsKeypair = BbsProvider.GenerateBlsKey(); var bbsKeyPair = new BlsKeyPair(blsKeypair.PublicKey.ToArray()); Assert.IsNull(bbsKeyPair.SecretKey); var publicKey = bbsKeyPair.GeyBbsKeyPair(1); Assert.NotNull(blsKeypair.SecretKey); Assert.NotNull(publicKey); Assert.NotNull(bbsKeyPair.PublicKey); Assert.IsNull(bbsKeyPair.SecretKey); Assert.AreEqual(196, publicKey.PublicKey.Count); Assert.AreEqual(32, blsKeypair.SecretKey.Count); }
public void SignDocumentRevealAll() { var keyPair = BbsProvider.GenerateBlsKey(); var document = Utilities.LoadJson("Data/test_signed_document.json"); var proofRequest = Utilities.LoadJson("Data/test_reveal_all_document.json"); var proof = LdProofService.CreateProof(new CreateProofOptions { Document = document, ProofRequest = proofRequest, LdSuiteType = BbsBlsSignatureProof2020.Name, ProofPurpose = ProofPurposeNames.AssertionMethod, VerificationMethod = keyPair.ToVerificationMethod("did:example:123#key", "did:example:123") }); proof.Should().NotBeNull(); proof["proof"].Should().NotBeNull(); proof["proof"]["proofValue"].Should().NotBeNull(); }
public void BlindSignSingleMessageUsingApi() { var myKey = BbsProvider.GenerateBlsKey(); var publicKey = myKey.GeyBbsKeyPair(2); var messages = new[] { new IndexedMessage { Index = 0, Message = "message_0" }, new IndexedMessage { Index = 1, Message = "message_1" } }; var nonce = "123"; var commitment = BbsProvider.CreateBlindedCommitment(new CreateBlindedCommitmentRequest(publicKey, messages, nonce)); var blindSign = BbsProvider.BlindSign(new BlindSignRequest(myKey, publicKey, commitment.Commitment.ToArray(), messages)); Assert.NotNull(blindSign); }
public void UnblindSignatureUsingApi() { var myKey = BbsProvider.GenerateBlsKey(); var publicKey = myKey.GeyBbsKeyPair(2); var messages = new[] { new IndexedMessage { Index = 0, Message = "message_0" }, new IndexedMessage { Index = 1, Message = "message_1" } }; var nonce = "123"; var commitment = BbsProvider.CreateBlindedCommitment(new CreateBlindedCommitmentRequest(publicKey, messages, nonce)); var blindedSignature = BbsProvider.BlindSign(new BlindSignRequest(myKey, publicKey, commitment.Commitment.ToArray(), messages)); var result = BbsProvider.UnblindSignature(new UnblindSignatureRequest(blindedSignature, commitment.BlindingFactor.ToArray())); Assert.NotNull(result); }
public void FullDemoTest() { var key = BbsProvider.GenerateBlsKey(); var publicKey = key.GeyBbsKeyPair(5); var nonce = "123"; var messages = new[] { "message_1", "message_2", "message_3", "message_4", "message_5" }; { // Sign messages var signature = BbsProvider.Sign(new SignRequest(key, messages)); Assert.NotNull(signature); Assert.AreEqual(BbsProvider.SignatureSize, signature.Length); // Verify messages var verifySignatureResult = BbsProvider.Verify(new VerifyRequest(key, signature, messages)); Assert.True(verifySignatureResult); // Create proof var proofMessages1 = new[] { new ProofMessage { Message = messages[0], ProofType = ProofMessageType.Revealed }, new ProofMessage { Message = messages[1], ProofType = ProofMessageType.Revealed }, new ProofMessage { Message = messages[2], ProofType = ProofMessageType.Revealed }, new ProofMessage { Message = messages[3], ProofType = ProofMessageType.Revealed }, new ProofMessage { Message = messages[4], ProofType = ProofMessageType.Revealed } }; var proofResult = BbsProvider.CreateProof(new CreateProofRequest(publicKey, proofMessages1, signature, null, nonce)); Assert.NotNull(proofResult); // Verify proof of revealed messages var indexedMessages1 = new[] { new IndexedMessage { Message = messages[0], Index = 0u }, new IndexedMessage { Message = messages[1], Index = 1u }, new IndexedMessage { Message = messages[2], Index = 2u }, new IndexedMessage { Message = messages[3], Index = 3u }, new IndexedMessage { Message = messages[4], Index = 4u } }; var verifyResult1 = BbsProvider.VerifyProof(new VerifyProofRequest(publicKey, proofResult, indexedMessages1, nonce)); Assert.AreEqual(SignatureProofStatus.Success, verifyResult1); } // Create blinded commitment var blindedMessages = new[] { new IndexedMessage { Index = 0, Message = messages[0] } }; var commitment = BbsProvider.CreateBlindedCommitment(new CreateBlindedCommitmentRequest(publicKey, blindedMessages, nonce)); Assert.NotNull(commitment); // Verify blinded commitment var verifyResult = BbsProvider.VerifyBlindedCommitment(new VerifyBlindedCommitmentRequest(publicKey, commitment.BlindSignContext.ToArray(), new [] { 0u }, nonce)); Assert.AreEqual(SignatureProofStatus.Success, verifyResult); // Blind sign var messagesToSign = new[] { new IndexedMessage { Index = 1, Message = messages[1] }, new IndexedMessage { Index = 2, Message = messages[2] }, new IndexedMessage { Index = 3, Message = messages[3] }, new IndexedMessage { Index = 4, Message = messages[4] } }; var blindedSignature = BbsProvider.BlindSign(new BlindSignRequest(key, publicKey, commitment.Commitment.ToArray(), messagesToSign)); Assert.NotNull(blindedSignature); Assert.AreEqual(BbsProvider.BlindSignatureSize, blindedSignature.Length); // Unblind signature var unblindedSignature = BbsProvider.UnblindSignature(new UnblindSignatureRequest(blindedSignature, commitment.BlindingFactor.ToArray())); Assert.NotNull(unblindedSignature); Assert.AreEqual(BbsProvider.SignatureSize, unblindedSignature.Length); // Verify signature var verifyUnblindedSignatureResult = BbsProvider.Verify(new VerifyRequest(key, unblindedSignature, messages)); Assert.True(verifyUnblindedSignatureResult); // Create proof var proofMessages = new[] { new ProofMessage { Message = messages[0], ProofType = ProofMessageType.Revealed }, new ProofMessage { Message = messages[1], ProofType = ProofMessageType.Revealed }, new ProofMessage { Message = messages[2], ProofType = ProofMessageType.HiddenExternalBlinding }, new ProofMessage { Message = messages[3], ProofType = ProofMessageType.HiddenExternalBlinding }, new ProofMessage { Message = messages[4], ProofType = ProofMessageType.HiddenExternalBlinding } }; var proof = BbsProvider.CreateProof(new CreateProofRequest( publicKey: publicKey, messages: proofMessages, signature: unblindedSignature, blindingFactor: commitment.BlindingFactor.ToArray(), nonce: nonce)); Assert.NotNull(proof); Assert.True(proof.Length > 0); // Verify proof var indexedMessages = new[] { new IndexedMessage { Message = messages[0], Index = 0u }, new IndexedMessage { Message = messages[1], Index = 1u } }; var verifyProofResult = BbsProvider.VerifyProof(new VerifyProofRequest(publicKey, proof, indexedMessages, nonce)); Assert.AreEqual(SignatureProofStatus.Success, verifyProofResult); }