Пример #1
0
        public IActionResult BindingKey([FromBody] BindingKeyRequestDto bindingKeyRequest)
        {
            var accountDescriptor = _accountsService.Authenticate(bindingKeyRequest.AccountId, bindingKeyRequest.Password);

            if (accountDescriptor == null)
            {
                throw new AccountAuthenticationFailedException(bindingKeyRequest.AccountId);
            }

            var persistency = _executionContextManager.ResolveUtxoExecutionServices(bindingKeyRequest.AccountId);

            persistency.BindingKeySource.SetResult(ConfidentialAssetsHelper.PasswordHash(bindingKeyRequest.Password));

            return(Ok());
        }
Пример #2
0
        public IActionResult Authenticate([FromBody] AccountDto accountDto)
        {
            _logger.LogIfDebug(() => $"[{accountDto.AccountId}]: Started authentication of the account {JsonConvert.SerializeObject(accountDto)}");

            var accountDescriptor = _accountsService.Authenticate(accountDto.AccountId, accountDto.Password);

            if (accountDescriptor == null)
            {
                throw new AccountAuthenticationFailedException(accountDto.AccountId);
            }

            if (accountDescriptor.AccountType == AccountType.User)
            {
                _executionContextManager.InitializeUtxoExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey, accountDescriptor.SecretViewKey, accountDescriptor.PwdHash);
                var persistency = _executionContextManager.ResolveUtxoExecutionServices(accountDto.AccountId);
                if (!persistency.BindingKeySource.Task.IsCompleted)
                {
                    persistency.BindingKeySource.SetResult(ConfidentialAssetsHelper.PasswordHash(accountDto.Password));
                }
            }
            else
            {
                _executionContextManager.InitializeStateExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey);
            }

            var forLog = new
            {
                accountDescriptor.AccountId,
                accountDescriptor.AccountType,
                accountDescriptor.AccountInfo,
                SecretSpendKey = accountDescriptor.SecretSpendKey.ToHexString(),
                PublicSpendKey = accountDescriptor.PublicSpendKey.ToHexString(),
                SecretViewKey  = accountDescriptor.SecretViewKey.ToHexString(),
                PublicViewKey  = accountDescriptor.PublicViewKey.ToHexString()
            };

            _logger.LogIfDebug(() => $"[{accountDto.AccountId}]: Authenticated account {JsonConvert.SerializeObject(forLog)}");

            return(Ok(_translatorsRepository.GetInstance <AccountDescriptor, AccountDto>().Translate(accountDescriptor)));
        }