Beispiel #1
0
        public IEnumerable <PollResult> CalculateResults(long pollId)
        {
            var poll = _dataAccessService.GetEcPoll(pollId, true, true);
            Dictionary <byte[], PollResult> votes = new Dictionary <byte[], PollResult>(new Byte32EqualityComparer());

            foreach (var candidate in poll.Candidates)
            {
                byte[] assetId    = candidate.AssetId.HexStringToByteArray();
                byte[] commitment = ConfidentialAssetsHelper.GetNonblindedAssetCommitment(assetId);
                votes.Add(commitment, new PollResult
                {
                    Candidate = _translatorsRepository.GetInstance <EcCandidateRecord, Candidate>().Translate(candidate),
                    Votes     = 0
                });
            }

            foreach (var vote in poll.PollSelections.Where(s => !string.IsNullOrEmpty(s.VoterBlindingFactor)))
            {
                byte[] ecCommitment  = vote.EcCommitment.HexStringToByteArray();
                byte[] ecBf          = vote.EcBlindingFactor.HexStringToByteArray();
                byte[] voterBf       = vote.VoterBlindingFactor.HexStringToByteArray();
                byte[] bf            = ConfidentialAssetsHelper.SumScalars(ecBf, voterBf);
                byte[] blindingPoint = ConfidentialAssetsHelper.GetPublicKey(bf);
                byte[] commitment    = ConfidentialAssetsHelper.SubCommitments(ecCommitment, blindingPoint);

                if (votes.ContainsKey(commitment))
                {
                    votes[commitment].Votes++;
                }
            }

            return(votes.Select(d => d.Value));
        }
Beispiel #2
0
        public SurjectionProof CalculateEcCommitmentProof(long pollId, EcSurjectionProofRequest proofRequest)
        {
            if (proofRequest is null)
            {
                throw new ArgumentNullException(nameof(proofRequest));
            }

            string ecCommitment  = proofRequest.EcCommitment.ToHexString();
            var    pollSelection = _dataAccessService.GetPollSelection(pollId, ecCommitment);

            byte[] ecBf = pollSelection.EcBlindingFactor.HexStringToByteArray();
            byte[] bf   = ConfidentialAssetsHelper.SumScalars(ecBf, proofRequest.PartialBlindingFactor);
            var    sp   = ConfidentialAssetsHelper.CreateSurjectionProof(proofRequest.EcCommitment, proofRequest.CandidateCommitments, proofRequest.Index, bf);

            return(sp);
        }