Beispiel #1
0
        public SignedEcCommitment GenerateDerivedCommitment(long pollId, SelectionCommitmentRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            EcPollRecord poll = _dataAccessService.GetEcPoll(pollId);

            byte[][] assetIds = poll.Candidates.Select(c => c.AssetId.HexStringToByteArray()).ToArray();

            bool res1 = ConfidentialAssetsHelper.VerifySurjectionProof(request.CandidateCommitmentProofs, request.Commitment);

            if (!res1)
            {
                throw new ArgumentException("Verification to candidate commitments failed");
            }

            foreach (var candidateCommitment in request.CandidateCommitments)
            {
                bool res2 = ConfidentialAssetsHelper.VerifyIssuanceSurjectionProof(candidateCommitment.IssuanceProof, candidateCommitment.Commitment, assetIds);
                if (!res2)
                {
                    throw new ArgumentException($"Verification of candidate's {candidateCommitment.Commitment.ToHexString()} issuance proof failed");
                }
            }

            byte[] ecBlindingFactor = ConfidentialAssetsHelper.GetRandomSeed();
            byte[] ecCommitment     = ConfidentialAssetsHelper.BlindAssetCommitment(request.Commitment, ecBlindingFactor);

            _dataAccessService.AddPollSelection(pollId, ecCommitment.ToHexString(), ecBlindingFactor.ToHexString());

            var persistency = _executionContextManager.ResolveStateExecutionServices(poll.AccountId);
            var signature   = persistency.ClientCryptoService.Sign(ecCommitment);

            return(new SignedEcCommitment
            {
                EcCommitment = ecCommitment,
                Signature = signature
            });
        }