コード例 #1
0
        public AuthKeyNegotiator(
            [NotNull] IClientTransportConfig clientTransportConfig,
            [NotNull] IMTProtoClientBuilder mtProtoBuilder,
            [NotNull] TLRig tlRig,
            [NotNull] INonceGenerator nonceGenerator,
            [NotNull] IHashServices hashServices,
            [NotNull] IEncryptionServices encryptionServices,
            [NotNull] IKeyChain keyChain)
        {
            Argument.IsNotNull(() => clientTransportConfig);
            Argument.IsNotNull(() => mtProtoBuilder);
            Argument.IsNotNull(() => tlRig);
            Argument.IsNotNull(() => nonceGenerator);
            Argument.IsNotNull(() => hashServices);
            Argument.IsNotNull(() => encryptionServices);
            Argument.IsNotNull(() => keyChain);

            _clientTransportConfig = clientTransportConfig;
            _mtProtoBuilder        = mtProtoBuilder;
            _tlRig              = tlRig;
            _nonceGenerator     = nonceGenerator;
            _hashServices       = hashServices;
            _encryptionServices = encryptionServices;
            _keyChain           = keyChain;
        }
コード例 #2
0
    CreateRoundWithOutputsReadyToSignAsync(Arena arena, IKeyChain keyChain, SmartCoin coin1, SmartCoin coin2)
    {
        // Create the round.
        await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

        var round = Assert.Single(arena.Rounds);

        round.MaxVsizeAllocationPerAlice = 11 + 31 + MultipartyTransactionParameters.SharedOverhead;
        var arenaClient = WabiSabiFactory.CreateArenaClient(arena);

        // Register Alices.
        using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), arena);
        await roundStateUpdater.StartAsync(CancellationToken.None);

        var task1 = AliceClient.CreateRegisterAndConfirmInputAsync(RoundState.FromRound(round), arenaClient, coin1, keyChain, roundStateUpdater, CancellationToken.None);
        var task2 = AliceClient.CreateRegisterAndConfirmInputAsync(RoundState.FromRound(round), arenaClient, coin2, keyChain, roundStateUpdater, CancellationToken.None);

        while (Phase.OutputRegistration != round.Phase)
        {
            await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
        }

        await Task.WhenAll(task1, task2);

        var aliceClient1 = task1.Result;
        var aliceClient2 = task2.Result;

        // Register outputs.
        var bobClient = new BobClient(round.Id, arenaClient);

        using var destKey1 = new Key();
        using var destKey2 = new Key();
        await bobClient.RegisterOutputAsync(
            destKey1.PubKey.WitHash.ScriptPubKey,
            aliceClient1.IssuedAmountCredentials.Take(ProtocolConstants.CredentialNumber),
            aliceClient1.IssuedVsizeCredentials.Take(ProtocolConstants.CredentialNumber),
            CancellationToken.None).ConfigureAwait(false);

        await bobClient.RegisterOutputAsync(
            destKey1.PubKey.WitHash.ScriptPubKey,
            aliceClient2.IssuedAmountCredentials.Take(ProtocolConstants.CredentialNumber),
            aliceClient2.IssuedVsizeCredentials.Take(ProtocolConstants.CredentialNumber),
            CancellationToken.None).ConfigureAwait(false);

        await roundStateUpdater.StopAsync(CancellationToken.None);

        return(round, aliceClient1, aliceClient2);
    }
コード例 #3
0
 public AuthKeyNegotiator(
     [NotNull] IClientTransportConfig clientTransportConfig,
     [NotNull] IMTProtoClientBuilder mtProtoBuilder,
     [NotNull] TLRig tlRig,
     [NotNull] INonceGenerator nonceGenerator,
     [NotNull] IHashServices hashServices,
     [NotNull] IEncryptionServices encryptionServices,
     [NotNull] IKeyChain keyChain)
 {
     _clientTransportConfig = clientTransportConfig;
     _mtProtoBuilder = mtProtoBuilder;
     _tlRig = tlRig;
     _nonceGenerator = nonceGenerator;
     _hashServices = hashServices;
     _encryptionServices = encryptionServices;
     _keyChain = keyChain;
 }
コード例 #4
0
 /// <param name="minAnonScoreTarget">Coins those have reached anonymity target, but still can be mixed if desired.</param>
 /// <param name="consolidationMode">If true, then aggressively try to consolidate as many coins as it can.</param>
 public CoinJoinClient(
     IWasabiHttpClientFactory httpClientFactory,
     IKeyChain keyChain,
     IDestinationProvider destinationProvider,
     RoundStateUpdater roundStatusUpdater,
     int minAnonScoreTarget = int.MaxValue,
     bool consolidationMode = false,
     TimeSpan doNotRegisterInLastMinuteTimeLimit = default)
 {
     HttpClientFactory   = httpClientFactory;
     KeyChain            = keyChain;
     DestinationProvider = destinationProvider;
     RoundStatusUpdater  = roundStatusUpdater;
     MinAnonScoreTarget  = minAnonScoreTarget;
     ConsolidationMode   = consolidationMode;
     SecureRandom        = new SecureRandom();
     DoNotRegisterInLastMinuteTimeLimit = doNotRegisterInLastMinuteTimeLimit;
 }
コード例 #5
0
 public MTProtoClientBuilder(
     [NotNull] IClientTransportFactory clientTransportFactory,
     [NotNull] TLRig tlRig,
     [NotNull] IMessageIdGenerator messageIdGenerator,
     [NotNull] IMessageCodec messageCodec,
     [NotNull] IHashServices hashServices,
     [NotNull] IEncryptionServices encryptionServices,
     [NotNull] INonceGenerator nonceGenerator,
     [NotNull] IKeyChain keyChain)
 {
     _clientTransportFactory = clientTransportFactory;
     _tlRig = tlRig;
     _messageIdGenerator = messageIdGenerator;
     _messageCodec = messageCodec;
     _hashServices = hashServices;
     _encryptionServices = encryptionServices;
     _nonceGenerator = nonceGenerator;
     _keyChain = keyChain;
 }
コード例 #6
0
 public MTProtoClientBuilder(
     [NotNull] IClientTransportFactory clientTransportFactory,
     [NotNull] TLRig tlRig,
     [NotNull] IMessageIdGenerator messageIdGenerator,
     [NotNull] IMessageCodec messageCodec,
     [NotNull] IHashServices hashServices,
     [NotNull] IEncryptionServices encryptionServices,
     [NotNull] INonceGenerator nonceGenerator,
     [NotNull] IKeyChain keyChain)
 {
     _clientTransportFactory = clientTransportFactory;
     _tlRig = tlRig;
     _messageIdGenerator = messageIdGenerator;
     _messageCodec = messageCodec;
     _hashServices = hashServices;
     _encryptionServices = encryptionServices;
     _nonceGenerator = nonceGenerator;
     _keyChain = keyChain;
 }
コード例 #7
0
        public AuthKeyNegotiator([NotNull] IMTProtoConnectionFactory connectionFactory, [NotNull] TLRig tlRig, [NotNull] INonceGenerator nonceGenerator,
                                 [NotNull] IHashServices hashServices, [NotNull] IEncryptionServices encryptionServices, [NotNull] IKeyChain keyChain,
                                 [NotNull] ITransportConfigProvider transportConfigProvider)
        {
            Argument.IsNotNull(() => connectionFactory);
            Argument.IsNotNull(() => tlRig);
            Argument.IsNotNull(() => nonceGenerator);
            Argument.IsNotNull(() => hashServices);
            Argument.IsNotNull(() => encryptionServices);
            Argument.IsNotNull(() => keyChain);
            Argument.IsNotNull(() => transportConfigProvider);

            _connectionFactory       = connectionFactory;
            _tlRig                   = tlRig;
            _nonceGenerator          = nonceGenerator;
            _hashServices            = hashServices;
            _encryptionServices      = encryptionServices;
            _keyChain                = keyChain;
            _transportConfigProvider = transportConfigProvider;
        }
コード例 #8
0
ファイル: AliceClient.cs プロジェクト: soosr/WalletWasabi
    public static async Task <AliceClient> CreateRegisterAndConfirmInputAsync(
        RoundState roundState,
        ArenaClient arenaClient,
        SmartCoin coin,
        IKeyChain keyChain,
        RoundStateUpdater roundStatusUpdater,
        CancellationToken cancellationToken)
    {
        AliceClient?aliceClient = null;

        try
        {
            aliceClient = await RegisterInputAsync(roundState, arenaClient, coin, keyChain, cancellationToken).ConfigureAwait(false);

            await aliceClient.ConfirmConnectionAsync(roundStatusUpdater, cancellationToken).ConfigureAwait(false);

            Logger.LogInfo($"Round ({aliceClient.RoundId}), Alice ({aliceClient.AliceId}): Connection was confirmed.");
        }
        catch (OperationCanceledException)
        {
            if (aliceClient is { })
コード例 #9
0
    CreateRoundWithTwoConfirmedConnectionsAsync(Arena arena, IKeyChain keyChain, SmartCoin coin1, SmartCoin coin2)
    {
        // Get the round.
        await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

        var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
        var round       = Assert.Single(arena.Rounds);

        // Refresh the Arena States because of vsize manipulation.
        await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

        using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), arena);
        await roundStateUpdater.StartAsync(CancellationToken.None);

        var task1 = AliceClient.CreateRegisterAndConfirmInputAsync(RoundState.FromRound(round), arenaClient, coin1, keyChain, roundStateUpdater, CancellationToken.None);
        var task2 = AliceClient.CreateRegisterAndConfirmInputAsync(RoundState.FromRound(round), arenaClient, coin2, keyChain, roundStateUpdater, CancellationToken.None);

        while (Phase.ConnectionConfirmation != round.Phase)
        {
            await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
        }
        await Task.WhenAll(task1, task2);

        var aliceClient1 = await task1;
        var aliceClient2 = await task2;

        await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

        Assert.Equal(Phase.OutputRegistration, round.Phase);

        await roundStateUpdater.StopAsync(CancellationToken.None);

        return(round,
               arenaClient,
               new[]
        {
            aliceClient1,
            aliceClient2
        });
    }
コード例 #10
0
    CreateRoundWithTwoConfirmedConnectionsAsync(Arena arena, IKeyChain keyChain, SmartCoin coin1, SmartCoin coin2)
    {
        // Create the round.
        await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

        var arenaClient = WabiSabiFactory.CreateArenaClient(arena);
        var round       = Assert.Single(arena.Rounds);

        round.MaxVsizeAllocationPerAlice = 11 + 31 + MultipartyTransactionParameters.SharedOverhead;

        using RoundStateUpdater roundStateUpdater = new(TimeSpan.FromSeconds(2), arena);
        await roundStateUpdater.StartAsync(CancellationToken.None);

        var task1 = AliceClient.CreateRegisterAndConfirmInputAsync(RoundState.FromRound(round), arenaClient, coin1, keyChain, roundStateUpdater, CancellationToken.None);
        var task2 = AliceClient.CreateRegisterAndConfirmInputAsync(RoundState.FromRound(round), arenaClient, coin2, keyChain, roundStateUpdater, CancellationToken.None);

        while (Phase.ConnectionConfirmation != round.Phase)
        {
            await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
        }
        await Task.WhenAll(task1, task2);

        var aliceClient1 = task1.Result;
        var aliceClient2 = task2.Result;

        await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));

        Assert.Equal(Phase.OutputRegistration, round.Phase);

        await roundStateUpdater.StopAsync(CancellationToken.None);

        return(round,
               arenaClient,
               new[]
        {
            aliceClient1,
            aliceClient2
        });
    }
コード例 #11
0
    public async Task StartOutputRegistrationsAsync(IEnumerable <TxOut> txOuts, BobClient bobClient, IKeyChain keyChain, ImmutableList <DateTimeOffset> outputRegistrationScheduledDates, CancellationToken cancellationToken)
    {
        using CancellationTokenSource ctsOnError = new();
        using CancellationTokenSource linkedCts  = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, ctsOnError.Token);

        var nodes = Graph.Outputs.Select(node =>
        {
            var amountCredsToPresentTasks = Graph.InEdges(node, CredentialType.Amount).Select(edge => DependencyTasks[edge].Task);
            var vsizeCredsToPresentTasks  = Graph.InEdges(node, CredentialType.Vsize).Select(edge => DependencyTasks[edge].Task);

            SmartRequestNode smartRequestNode = new(
                amountCredsToPresentTasks,
                vsizeCredsToPresentTasks,
                Array.Empty <TaskCompletionSource <Credential> >(),
                Array.Empty <TaskCompletionSource <Credential> >());
            return(smartRequestNode);
        });

        var tasks = txOuts.Zip(nodes, outputRegistrationScheduledDates,
                               async(txOut, smartRequestNode, scheduledDate) =>
        {
            try
            {
                var delay = scheduledDate - DateTimeOffset.UtcNow;
                if (delay > TimeSpan.Zero)
                {
                    await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
                }
                await smartRequestNode.StartOutputRegistrationAsync(bobClient, txOut.ScriptPubKey, cancellationToken).ConfigureAwait(false);
            }
            catch (WabiSabiProtocolException ex) when(ex.ErrorCode == WabiSabiProtocolErrorCode.AlreadyRegisteredScript)
            {
                Logger.LogDebug($"Output registration error, code:'{ex.ErrorCode}' message:'{ex.Message}'.");
                if (keyChain is KeyChain {
                    KeyManager: var keyManager
                } &&
                    keyManager.TryGetKeyForScriptPubKey(txOut.ScriptPubKey, out var hdPubKey))
                {
                    hdPubKey.SetKeyState(KeyState.Used);
                }
            }
コード例 #12
0
ファイル: OwnerAuthService.cs プロジェクト: anyarik/Seller
 public OwnerAuthService(IUserController userController, IKeyChain keyChain) : base(userController, keyChain)
 {
 }
コード例 #13
0
ファイル: BaseAuthService.cs プロジェクト: anyarik/Seller
 /// <summary>Initializes a new instance of the <see cref="LoginService"/> class.</summary>
 public BaseAuthService(IUserController userController, IKeyChain keyChain)
 {
     this._userController = userController;
     this._keyChain       = keyChain;
 }