Exemple #1
0
        public void TestValidateCommitmentValid()
        {
            var signatureService = new MultiSignature(_sepSecp256K1);
            var commitment       = signatureService.ComputeCommitment(signatureService.ComputeCommitmentSecret());
            var commitmentHash   = signatureService.ComputeCommitmentHash(commitment);

            Assert.IsTrue(signatureService.ValidateCommitment(commitment, commitmentHash));
        }
Exemple #2
0
        public void TestComputeCommitmentHash()
        {
            var signatureService = new MultiSignature(_sepSecp256K1);
            var commitment       = signatureService.ComputeCommitment(signatureService.ComputeCommitmentSecret());
            var commitmentHash   = signatureService.ComputeCommitmentHash(commitment);

            Assert.AreNotEqual(commitment, commitmentHash);
        }
Exemple #3
0
        public void TestComputeCommitmentEmptySecret()
        {
            var signatureService = new MultiSignature(_sepSecp256K1);
            var commitmentSecret = new byte[0];
            var exception        = Assert.Throws <ArgumentOutOfRangeException>(() => signatureService.ComputeCommitment(commitmentSecret));

            Assert.IsTrue(exception.Message.StartsWith("[commitmentSecret] cannot be less than or equal to 0."));
        }
Exemple #4
0
        public void TestComputeCommitmentNullSecret()
        {
            var signatureService = new MultiSignature(_sepSecp256K1);

            byte[] commitmentSecret = null;

            var exception =
                // ReSharper disable once ExpressionIsAlwaysNull
                Assert.Throws <ArgumentNullException>(() => signatureService.ComputeCommitment(commitmentSecret));

            Assert.IsTrue(exception.Message.StartsWith("[commitmentSecret] cannot be Null."));
        }
Exemple #5
0
        public void TestVerifySignatureShareOk()
        {
            var signatureService  = new MultiSignature(_sepSecp256K1);
            var signers           = new List <byte[]>();
            var commitmentSecrets = new List <byte[]>();
            var commitments       = new List <byte[]>();

            var alice = new Participant("Alice");
            var bob   = new Participant("Bob");
            var carol = new Participant("Carol");

            long bitmap  = 0;
            var  message = "The quick brown fox jumps over the lazy dog.".ToHexEncodedByteArray();

            signers.Add(alice.PublicKey);
            signers.Add(bob.PublicKey);
            signers.Add(carol.PublicKey);

            for (var i = 0; i < signers.Count; i++)
            {
                bitmap = (bitmap << 1) | 1;
                commitmentSecrets.Add(signatureService.ComputeCommitmentSecret());
                commitments.Add(signatureService.ComputeCommitment(commitmentSecrets[i]));
            }

            var aggregatedCommitment = signatureService.AggregateCommitments(commitments, bitmap);
            var challenge            =
                signatureService.ComputeChallenge(signers, alice.PublicKey, aggregatedCommitment, message, bitmap);
            var signature = signatureService.ComputeSignatureShare(challenge, alice.PrivateKey, commitmentSecrets[0]);

            Assert.IsTrue(signatureService.VerifySignatureShare(
                              signers,
                              alice.PublicKey,
                              signature,
                              aggregatedCommitment,
                              commitments[0],
                              message,
                              bitmap));
        }