public IActionResult RegisterTransactionForConsent([FromBody] TransactionConsentRequest consentRequest) { _consentManagementService.RegisterTransactionForConsent(consentRequest); _hubContext.Clients.Group(consentRequest.RegistrationCommitment).SendAsync("ConsentRequest", consentRequest); return(Ok()); }
public void RegisterTransactionForConsent(TransactionConsentRequest consentRequest) { _consentRequests.AddOrUpdate(consentRequest.TransactionId, consentRequest, (k, v) => consentRequest); byte[] confirmHash = _hashCalculation.CalculateHash(Encoding.UTF8.GetBytes(consentRequest.TransactionId)); byte[] declineHash = _hashCalculation.CalculateHash(confirmHash); _consentRequestsByConfirmKey.AddOrUpdate(confirmHash.ToHexString(), consentRequest.TransactionId, (k, v) => confirmHash.ToHexString()); _consentRequestsByDeclineKey.AddOrUpdate(declineHash.ToHexString(), consentRequest.TransactionId, (k, v) => declineHash.ToHexString()); _consentsPerRegistration.AddOrUpdate(consentRequest.RegistrationCommitment, new List <string> { consentRequest.TransactionId }, (k, v) => { v.Add(consentRequest.TransactionId); return(v); }); }
public async Task <IActionResult> PushUserTransaction(long accountId, [FromBody] SpUserTransactionRequestDto spUserTransactionRequest) { AccountDescriptor account = _accountsService.GetById(accountId); string transactionId = Guid.NewGuid().ToString(); long registrationId = long.Parse(spUserTransactionRequest.RegistrationId); long userTransactionId = _dataAccessService.AddSpUserTransaction(accountId, registrationId, transactionId, spUserTransactionRequest.Description); var registration = _dataAccessService.GetServiceProviderRegistration(registrationId); TransactionConsentRequest consentRequest = new TransactionConsentRequest { RegistrationCommitment = registration.Commitment.ToHexString(), TransactionId = transactionId, WithKnowledgeProof = true, Description = spUserTransactionRequest.Description, PublicSpendKey = account.PublicSpendKey.ToHexString(), PublicViewKey = account.PublicViewKey?.ToHexString() }; await _restApiConfiguration.ConsentManagementUri .AppendPathSegments("ConsentManagement", "TransactionForConsent") .PostJsonAsync(consentRequest).ContinueWith(t => { if (!t.IsCompletedSuccessfully) { _logger.Error($"Failed to register transaction for consent. {JsonConvert.SerializeObject(consentRequest)}", t.Exception); } }, TaskScheduler.Current).ConfigureAwait(false); return(Ok(new SpUserTransactionDto { SpUserTransactionId = userTransactionId.ToString(), TransactionId = transactionId, RegistrationId = spUserTransactionRequest.RegistrationId.ToString(), Description = spUserTransactionRequest.Description })); }