Exemple #1
0
        public void InitializeUtxoExecutionServices(ulong accountId, byte[] secretSpendKey, byte[] secretViewKey, byte[] pwdSecretKey)
        {
            if (_utxoPersistencyItems.ContainsKey(accountId))
            {
                return;
            }

            IPacketsProvider         packetsProvider     = ServiceLocator.Current.GetInstance <IPacketsProvider>();
            IUtxoTransactionsService transactionsService = ServiceLocator.Current.GetInstance <UtxoTransactionsService>();
            IUtxoClientCryptoService clientCryptoService = ServiceLocator.Current.GetInstance <UtxoClientCryptoService>();
            UtxoWalletSynchronizer   walletSynchronizer  = ServiceLocator.Current.GetInstance <UtxoWalletSynchronizer>();

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            packetsProvider.Initialize(accountId, cancellationTokenSource.Token);
            clientCryptoService.Initialize(secretSpendKey, secretViewKey, pwdSecretKey);
            transactionsService.Initialize(clientCryptoService);
            transactionsService.PipeOutTransactions.LinkTo(_gatewayService.PipeInTransactions);
            transactionsService.PipeOutKeyImages.LinkTo(walletSynchronizer.PipeInKeyImages);

            UserIdentitiesUpdater userIdentitiesUpdater = new UserIdentitiesUpdater(accountId, clientCryptoService, _assetsService, _dataAccessService, _identitiesHubContext, _relationsProofsValidationService, _trackingService);

            walletSynchronizer.Initialize(accountId, clientCryptoService, _gatewayService, cancellationTokenSource.Token);

            packetsProvider.PipeOut.LinkTo(walletSynchronizer.PipeIn);
            walletSynchronizer.PipeOut.LinkTo(userIdentitiesUpdater.PipeIn);

            walletSynchronizer.Start();
            packetsProvider.Start();

            AddSubscriberToDictionary(accountId, walletSynchronizer.Subscribe(userIdentitiesUpdater));

            var state = new UtxoPersistency
            {
                AccountId               = accountId,
                PacketsProvider         = packetsProvider,
                TransactionsService     = transactionsService,
                ClientCryptoService     = clientCryptoService,
                WalletSynchronizer      = walletSynchronizer,
                CancellationTokenSource = cancellationTokenSource
            };

            _utxoPersistencyItems.Add(accountId, state);
        }
Exemple #2
0
        public void InitializeUtxoExecutionServices(long accountId, byte[] secretSpendKey, byte[] secretViewKey, byte[] pwdSecretKey, Func <long, IUtxoClientCryptoService, CancellationToken, IUpdater> updaterFactory = null)
        {
            lock (_utxoPersistencyItems)
            {
                if (_utxoPersistencyItems.ContainsKey(accountId))
                {
                    _logger.Info($"[{accountId}]: account already registered at UtxoPersistency");
                    return;
                }

                _logger.Info($"[{accountId}]: {nameof(InitializeUtxoExecutionServices)}");

                try
                {
                    IWitnessPackagesProvider   packetsProvider            = _witnessPackagesProviderRepository.GetInstance(_restApiConfiguration.WitnessProviderName);
                    IUtxoTransactionsService   transactionsService        = ActivatorUtilities.CreateInstance <UtxoTransactionsService>(_serviceProvider);
                    IUtxoClientCryptoService   clientCryptoService        = ActivatorUtilities.CreateInstance <UtxoClientCryptoService>(_serviceProvider);
                    IRelationsBindingService   relationsBindingService    = ActivatorUtilities.CreateInstance <RelationsBindingService>(_serviceProvider);
                    UtxoWalletSynchronizer     walletSynchronizer         = ActivatorUtilities.CreateInstance <UtxoWalletSynchronizer>(_serviceProvider);
                    UtxoWalletPacketsExtractor utxoWalletPacketsExtractor = ActivatorUtilities.CreateInstance <UtxoWalletPacketsExtractor>(_serviceProvider);

                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

                    packetsProvider.Initialize(accountId, cancellationTokenSource.Token);
                    clientCryptoService.Initialize(secretSpendKey, secretViewKey);

                    TaskCompletionSource <byte[]> pwdSource = new TaskCompletionSource <byte[]>();
                    if (pwdSecretKey != null)
                    {
                        pwdSource.SetResult(pwdSecretKey);
                    }
                    relationsBindingService.Initialize(pwdSource);

                    transactionsService.AccountId = accountId;
                    transactionsService.Initialize(clientCryptoService, relationsBindingService);
                    utxoWalletPacketsExtractor.AccountId = accountId;
                    utxoWalletPacketsExtractor.Initialize(clientCryptoService);
                    transactionsService.PipeOutTransactions.LinkTo(_gatewayService.PipeInTransactions);
                    transactionsService.PipeOutKeyImages.LinkTo(utxoWalletPacketsExtractor.PipeInKeyImages);

                    IUpdater userIdentitiesUpdater = updaterFactory != null?updaterFactory(accountId, clientCryptoService, cancellationTokenSource.Token) : CreateUtxoUpdater(accountId, clientCryptoService, cancellationTokenSource.Token);

                    walletSynchronizer.Initialize(accountId, clientCryptoService);

                    packetsProvider.PipeOut.LinkTo(utxoWalletPacketsExtractor.PipeIn);
                    utxoWalletPacketsExtractor.PipeOutPackets.LinkTo(walletSynchronizer.PipeInPackets);
                    utxoWalletPacketsExtractor.PipeOutProcessed.LinkTo(walletSynchronizer.PipeInPackage);
                    utxoWalletPacketsExtractor.PipeOutNotifications.LinkTo(userIdentitiesUpdater.PipInNotifications);

                    walletSynchronizer.PipeOutPackets.LinkTo(userIdentitiesUpdater.PipeIn);
                    walletSynchronizer.PipeOutNotifications.LinkTo(userIdentitiesUpdater.PipInNotifications);

                    packetsProvider.Start();

                    var state = new UtxoPersistency
                    {
                        AccountId               = accountId,
                        PacketsProvider         = packetsProvider,
                        TransactionsService     = transactionsService,
                        ClientCryptoService     = clientCryptoService,
                        RelationsBindingService = relationsBindingService,
                        PacketsExtractor        = utxoWalletPacketsExtractor,
                        WalletSynchronizer      = walletSynchronizer,
                        CancellationTokenSource = cancellationTokenSource,
                        BindingKeySource        = pwdSource
                    };
                    _utxoPersistencyItems.Add(accountId, state);
                }
                catch (Exception ex)
                {
                    _logger.Error($"[{accountId}]: Failure during {nameof(InitializeUtxoExecutionServices)}", ex);

                    throw;
                }
            }
        }
Exemple #3
0
        private void SendEmployeeRequest(UserAttributeTransferDto userAttributeTransfer, IUtxoTransactionsService transactionsService, AssociatedProofPreparation[] associatedProofPreparations = null)
        {
            byte[] target  = userAttributeTransfer.Target.HexStringToByteArray();
            byte[] issuer  = userAttributeTransfer.Source.HexStringToByteArray();
            byte[] payload = userAttributeTransfer.Payload.HexStringToByteArray();
            byte[] assetId = userAttributeTransfer.AssetId.HexStringToByteArray();
            byte[] originalBlindingFactor = userAttributeTransfer.OriginalBlindingFactor.HexStringToByteArray();
            byte[] originalCommitment     = userAttributeTransfer.OriginalCommitment.HexStringToByteArray();
            byte[] lastTransactionKey     = userAttributeTransfer.LastTransactionKey.HexStringToByteArray();
            byte[] lastBlindingFactor     = userAttributeTransfer.LastBlindingFactor.HexStringToByteArray();
            byte[] lastCommitment         = userAttributeTransfer.LastCommitment.HexStringToByteArray();
            byte[] lastDestinationKey     = userAttributeTransfer.LastDestinationKey.HexStringToByteArray();

            string[] categoryEntries = userAttributeTransfer.ExtraInfo.Split("/");
            foreach (string categoryEntry in categoryEntries)
            {
                string groupName    = categoryEntry.Split("|")[1];
                bool   isRegistered = "true".Equals(categoryEntry.Split("|")[2], StringComparison.InvariantCultureIgnoreCase);

                if (!isRegistered)
                {
                    byte[] groupAssetId = _assetsService.GenerateAssetId(AttributeType.EmployeeGroup, userAttributeTransfer.Target + groupName);
                    EmployeeRequestInput requestInput = new EmployeeRequestInput
                    {
                        AssetId = assetId,
                        EligibilityBlindingFactor = originalBlindingFactor,
                        EligibilityCommitment     = originalCommitment,
                        Issuer = issuer,
                        PrevAssetCommitment = lastCommitment,
                        PrevBlindingFactor  = lastBlindingFactor,
                        PrevDestinationKey  = lastDestinationKey,
                        PrevTransactionKey  = lastTransactionKey,
                        Target       = target,
                        Payload      = payload,
                        GroupAssetId = groupAssetId
                    };

                    OutputModel[] outputModels        = _gatewayService.GetOutputs(_portalConfiguration.RingSize + 1);
                    byte[][]      issuanceCommitments = _gatewayService.GetIssuanceCommitments(issuer, _portalConfiguration.RingSize + 1);
                    RequestResult requestResult       = transactionsService.SendEmployeeRegistrationRequest(requestInput, associatedProofPreparations, outputModels, issuanceCommitments).Result;
                }
            }
        }
Exemple #4
0
        private void SendDocumentSignRequest(UserAttributeTransferDto userAttributeTransfer, IUtxoTransactionsService transactionsService, AssociatedProofPreparation[] associatedProofPreparations = null)
        {
            byte[]   target  = userAttributeTransfer.Target.HexStringToByteArray();
            byte[]   issuer  = userAttributeTransfer.Source.HexStringToByteArray();
            byte[]   payload = userAttributeTransfer.Payload.HexStringToByteArray();
            byte[]   assetId = userAttributeTransfer.AssetId.HexStringToByteArray();
            byte[]   originalBlindingFactor = userAttributeTransfer.OriginalBlindingFactor.HexStringToByteArray();
            byte[]   originalCommitment     = userAttributeTransfer.OriginalCommitment.HexStringToByteArray();
            byte[]   lastTransactionKey     = userAttributeTransfer.LastTransactionKey.HexStringToByteArray();
            byte[]   lastBlindingFactor     = userAttributeTransfer.LastBlindingFactor.HexStringToByteArray();
            byte[]   lastCommitment         = userAttributeTransfer.LastCommitment.HexStringToByteArray();
            byte[]   lastDestinationKey     = userAttributeTransfer.LastDestinationKey.HexStringToByteArray();
            string[] extraInfo            = userAttributeTransfer.ExtraInfo.Split('|');
            byte[]   groupIssuer          = extraInfo[0].HexStringToByteArray();
            byte[]   groupAssetId         = _assetsService.GenerateAssetId(AttributeType.EmployeeGroup, extraInfo[0] + extraInfo[1]);
            byte[]   documentHash         = extraInfo[2].HexStringToByteArray();
            ulong    documentRecordHeight = ulong.Parse(extraInfo[3]);

            DocumentSignRequestInput requestInput = new DocumentSignRequestInput
            {
                AssetId = assetId,
                EligibilityBlindingFactor = originalBlindingFactor,
                EligibilityCommitment     = originalCommitment,
                Issuer = issuer,
                PrevAssetCommitment = lastCommitment,
                PrevBlindingFactor  = lastBlindingFactor,
                PrevDestinationKey  = lastDestinationKey,
                PrevTransactionKey  = lastTransactionKey,
                Target               = target,
                Payload              = payload,
                GroupIssuer          = groupIssuer,
                GroupAssetId         = groupAssetId,
                DocumentHash         = documentHash,
                DocumentRecordHeight = documentRecordHeight
            };

            OutputModel[] outputModels        = _gatewayService.GetOutputs(_portalConfiguration.RingSize + 1);
            byte[][]      issuanceCommitments = _gatewayService.GetIssuanceCommitments(issuer, _portalConfiguration.RingSize + 1);
            RequestResult requestResult       = transactionsService.SendDocumentSignRequest(requestInput, associatedProofPreparations, outputModels, issuanceCommitments).Result;
        }
Exemple #5
0
        private void SendOnboardingRequest(UserAttributeTransferDto userAttributeTransfer, IUtxoTransactionsService transactionsService, AssociatedProofPreparation[] associatedProofPreparations = null)
        {
            byte[] target  = userAttributeTransfer.Target.HexStringToByteArray();
            byte[] issuer  = userAttributeTransfer.Source.HexStringToByteArray();
            byte[] payload = userAttributeTransfer.Payload.HexStringToByteArray();
            byte[] assetId = userAttributeTransfer.AssetId.HexStringToByteArray();
            byte[] originalBlindingFactor = userAttributeTransfer.OriginalBlindingFactor.HexStringToByteArray();
            byte[] originalCommitment     = userAttributeTransfer.OriginalCommitment.HexStringToByteArray();
            byte[] lastTransactionKey     = userAttributeTransfer.LastTransactionKey.HexStringToByteArray();
            byte[] lastBlindingFactor     = userAttributeTransfer.LastBlindingFactor.HexStringToByteArray();
            byte[] lastCommitment         = userAttributeTransfer.LastCommitment.HexStringToByteArray();
            byte[] lastDestinationKey     = userAttributeTransfer.LastDestinationKey.HexStringToByteArray();

            RequestInput requestInput = new RequestInput
            {
                AssetId = assetId,
                EligibilityBlindingFactor = originalBlindingFactor,
                EligibilityCommitment     = originalCommitment,
                Issuer = issuer,
                PrevAssetCommitment = lastCommitment,
                PrevBlindingFactor  = lastBlindingFactor,
                PrevDestinationKey  = lastDestinationKey,
                PrevTransactionKey  = lastTransactionKey,
                Target  = target,
                Payload = payload
            };

            OutputModel[] outputModels        = _gatewayService.GetOutputs(_portalConfiguration.RingSize + 1);
            byte[][]      issuanceCommitments = _gatewayService.GetIssuanceCommitments(issuer, _portalConfiguration.RingSize + 1);
            RequestResult requestResult       = transactionsService.SendOnboardingRequest(requestInput, associatedProofPreparations, outputModels, issuanceCommitments).Result;
        }