Beispiel #1
0
        public async Task RegisterOutputAsync(
            uint256 roundId,
            Script scriptPubKey,
            IEnumerable <Credential> amountCredentialsToPresent,
            IEnumerable <Credential> vsizeCredentialsToPresent,
            CancellationToken cancellationToken)
        {
            Guard.InRange(nameof(amountCredentialsToPresent), amountCredentialsToPresent, 0, AmountCredentialClient.NumberOfCredentials);
            Guard.InRange(nameof(vsizeCredentialsToPresent), vsizeCredentialsToPresent, 0, VsizeCredentialClient.NumberOfCredentials);

            var presentedAmount = amountCredentialsToPresent.Sum(x => x.Value);

            var(realAmountCredentialRequest, realAmountCredentialResponseValidation) = AmountCredentialClient.CreateRequest(
                amountCredentialsToPresent,
                cancellationToken);

            var presentedVsize = vsizeCredentialsToPresent.Sum(x => x.Value);

            var(realVsizeCredentialRequest, realVsizeCredentialResponseValidation) = VsizeCredentialClient.CreateRequest(
                vsizeCredentialsToPresent,
                cancellationToken);

            await RequestHandler.RegisterOutputAsync(
                new OutputRegistrationRequest(
                    roundId,
                    scriptPubKey,
                    realAmountCredentialRequest,
                    realVsizeCredentialRequest),
                cancellationToken).ConfigureAwait(false);
        }
Beispiel #2
0
    public async Task <ArenaResponse> ReissueCredentialAsync(
        uint256 roundId,
        IEnumerable <long> amountsToRequest,
        IEnumerable <long> vsizesToRequest,
        IEnumerable <Credential> amountCredentialsToPresent,
        IEnumerable <Credential> vsizeCredentialsToPresent,
        CancellationToken cancellationToken)
    {
        Guard.InRange(nameof(amountCredentialsToPresent), amountCredentialsToPresent, 0, AmountCredentialClient.NumberOfCredentials);

        var presentedAmount = amountCredentialsToPresent.Sum(x => x.Value);

        if (amountsToRequest.Sum() != presentedAmount)
        {
            throw new InvalidOperationException($"Reissuance amounts sum must equal the sum of the presented ones.");
        }

        var presentedVsize = vsizeCredentialsToPresent.Sum(x => x.Value);

        if (vsizesToRequest.Sum() > presentedVsize)
        {
            throw new InvalidOperationException($"Reissuance vsizes sum can not be greater than the sum of the presented ones.");
        }

        var(realVsizeCredentialRequest, realVsizeCredentialResponseValidation) = VsizeCredentialClient.CreateRequest(
            vsizesToRequest,
            vsizeCredentialsToPresent,
            cancellationToken);

        var(realAmountCredentialRequest, realAmountCredentialResponseValidation) = AmountCredentialClient.CreateRequest(
            amountsToRequest,
            amountCredentialsToPresent,
            cancellationToken);

        var zeroAmountCredentialRequestData = AmountCredentialClient.CreateRequestForZeroAmount();
        var zeroVsizeCredentialRequestData  = VsizeCredentialClient.CreateRequestForZeroAmount();

        var reissuanceResponse = await RequestHandler.ReissuanceAsync(
            new ReissueCredentialRequest(
                roundId,
                realAmountCredentialRequest,
                realVsizeCredentialRequest,
                zeroAmountCredentialRequestData.CredentialsRequest,
                zeroVsizeCredentialRequestData.CredentialsRequest),
            cancellationToken).ConfigureAwait(false);

        var realAmountCredentials = AmountCredentialClient.HandleResponse(reissuanceResponse.RealAmountCredentials, realAmountCredentialResponseValidation);
        var realVsizeCredentials  = VsizeCredentialClient.HandleResponse(reissuanceResponse.RealVsizeCredentials, realVsizeCredentialResponseValidation);
        var zeroAmountCredentials = AmountCredentialClient.HandleResponse(reissuanceResponse.ZeroAmountCredentials, zeroAmountCredentialRequestData.CredentialsResponseValidation);
        var zeroVsizeCredentials  = VsizeCredentialClient.HandleResponse(reissuanceResponse.ZeroVsizeCredentials, zeroVsizeCredentialRequestData.CredentialsResponseValidation);

        return(new(realAmountCredentials.Concat(zeroAmountCredentials), realVsizeCredentials.Concat(zeroVsizeCredentials)));
    }
Beispiel #3
0
        public async Task <ArenaResponse <bool> > ConfirmConnectionAsync(
            uint256 roundId,
            Guid aliceId,
            IEnumerable <long> amountsToRequest,
            IEnumerable <long> vsizesToRequest,
            IEnumerable <Credential> amountCredentialsToPresent,
            IEnumerable <Credential> vsizeCredentialsToPresent,
            CancellationToken cancellationToken)
        {
            Guard.InRange(nameof(amountsToRequest), amountsToRequest, 1, ProtocolConstants.CredentialNumber);
            Guard.InRange(nameof(amountCredentialsToPresent), amountCredentialsToPresent, 0, ProtocolConstants.CredentialNumber);
            Guard.InRange(nameof(vsizeCredentialsToPresent), vsizeCredentialsToPresent, 0, ProtocolConstants.CredentialNumber);
            Guard.InRange(nameof(vsizesToRequest), vsizesToRequest, 1, VsizeCredentialClient.NumberOfCredentials);

            var realAmountCredentialRequestData = AmountCredentialClient.CreateRequest(
                amountsToRequest,
                amountCredentialsToPresent,
                cancellationToken);

            var realVsizeCredentialRequestData = VsizeCredentialClient.CreateRequest(
                vsizesToRequest,
                vsizeCredentialsToPresent,
                cancellationToken);

            var zeroAmountCredentialRequestData = AmountCredentialClient.CreateRequestForZeroAmount();
            var zeroVsizeCredentialRequestData  = VsizeCredentialClient.CreateRequestForZeroAmount();

            var confirmConnectionResponse = await RequestHandler.ConfirmConnectionAsync(
                new ConnectionConfirmationRequest(
                    roundId,
                    aliceId,
                    zeroAmountCredentialRequestData.CredentialsRequest,
                    realAmountCredentialRequestData.CredentialsRequest,
                    zeroVsizeCredentialRequestData.CredentialsRequest,
                    realVsizeCredentialRequestData.CredentialsRequest),
                cancellationToken).ConfigureAwait(false);

            var zeroAmountCredentials = AmountCredentialClient.HandleResponse(confirmConnectionResponse.ZeroAmountCredentials, zeroAmountCredentialRequestData.CredentialsResponseValidation);
            var zeroVsizeCredentials  = VsizeCredentialClient.HandleResponse(confirmConnectionResponse.ZeroVsizeCredentials, zeroVsizeCredentialRequestData.CredentialsResponseValidation);

            if (confirmConnectionResponse is { RealAmountCredentials : { }, RealVsizeCredentials : { } })
Beispiel #4
0
        public async Task <ArenaResponse> RegisterOutputAsync(
            uint256 roundId,
            long amount,
            Script scriptPubKey,
            IEnumerable <Credential> amountCredentialsToPresent,
            IEnumerable <Credential> vsizeCredentialsToPresent,
            CancellationToken cancellationToken)
        {
            Guard.InRange(nameof(amountCredentialsToPresent), amountCredentialsToPresent, 0, AmountCredentialClient.NumberOfCredentials);
            Guard.InRange(nameof(vsizeCredentialsToPresent), vsizeCredentialsToPresent, 0, VsizeCredentialClient.NumberOfCredentials);

            var presentedAmount = amountCredentialsToPresent.Sum(x => x.Value);

            var(realAmountCredentialRequest, realAmountCredentialResponseValidation) = AmountCredentialClient.CreateRequest(
                new[] { presentedAmount - amount },                 // FIXME remove
                amountCredentialsToPresent,
                cancellationToken);

            var presentedVsize = vsizeCredentialsToPresent.Sum(x => x.Value);

            var(realVsizeCredentialRequest, realVsizeCredentialResponseValidation) = VsizeCredentialClient.CreateRequest(
                new[] { presentedVsize - scriptPubKey.EstimateOutputVsize() },                 // FIXME remove
                vsizeCredentialsToPresent,
                cancellationToken);

            var outputRegistrationResponse = await RequestHandler.RegisterOutputAsync(
                new OutputRegistrationRequest(
                    roundId,
                    scriptPubKey,
                    realAmountCredentialRequest,
                    realVsizeCredentialRequest),
                cancellationToken).ConfigureAwait(false);

            var realAmountCredentials = AmountCredentialClient.HandleResponse(outputRegistrationResponse.AmountCredentials, realAmountCredentialResponseValidation);
            var realVsizeCredentials  = VsizeCredentialClient.HandleResponse(outputRegistrationResponse.VsizeCredentials, realVsizeCredentialResponseValidation);

            return(new(realAmountCredentials, realVsizeCredentials));
        }