Example #1
0
        public PacketBase Get(IDataKey key)
        {
            if (key is DoubleHeightKey heightKey)
            {
                TransactionsRegistryBlock transactionsRegistryBlock = DataAccessService.Instance.GetTransactionsRegistryBlock(heightKey.Height1, heightKey.Height2);

                PacketBase blockBase = _translatorsRepository.GetInstance <TransactionsRegistryBlock, PacketBase>().Translate(transactionsRegistryBlock);

                return(blockBase);
            }
            else if (key is SyncHashKey syncTransactionKey)
            {
                List <TransactionsRegistryBlock> transactionsRegistryBlocks = DataAccessService.Instance.GetTransactionsRegistryBlocks(syncTransactionKey.SyncBlockHeight);

                TransactionsRegistryBlock transactionsRegistryBlock = transactionsRegistryBlocks.FirstOrDefault(t => syncTransactionKey.Hash.Equals32(t.Hash));

                if (transactionsRegistryBlock == null)
                {
                    transactionsRegistryBlocks = DataAccessService.Instance.GetTransactionsRegistryBlocks(syncTransactionKey.SyncBlockHeight - 1);
                    transactionsRegistryBlock  = transactionsRegistryBlocks.FirstOrDefault(t => syncTransactionKey.Hash.Equals32(t.Hash));
                }

                PacketBase blockBase = null;

                if (transactionsRegistryBlock != null)
                {
                    blockBase = _translatorsRepository.GetInstance <TransactionsRegistryBlock, PacketBase>().Translate(transactionsRegistryBlock);
                }

                return(blockBase);
            }

            return(null);
        }
Example #2
0
        public IEnumerable <BlockBase> GetAll(IDataKey key)
        {
            if (key is BlockTypeLowHeightKey blockTypeLowHeightKey)
            {
                if (blockTypeLowHeightKey.BlockType == BlockTypes.Synchronization_ConfirmedBlock)
                {
                    return(DataAccessService.Instance.GetAllLastSynchronizationBlocks(blockTypeLowHeightKey.Height).Select(b => _translatorsRepository.GetInstance <SynchronizationBlock, BlockBase>().Translate(b)));
                }
                else if (blockTypeLowHeightKey.BlockType == BlockTypes.Synchronization_RegistryCombinationBlock)
                {
                    return(DataAccessService.Instance.GetAllLastRegistryCombinedBlocks(blockTypeLowHeightKey.Height).Select(b => _translatorsRepository.GetInstance <RegistryCombinedBlock, BlockBase>().Translate(b)));
                }
            }
            else if (key is BlockTypeKey blockTypeKey)
            {
                if (blockTypeKey.BlockType == BlockTypes.Synchronization_ConfirmedBlock)
                {
                    return(DataAccessService.Instance.GetAllSynchronizationBlocks().Select(b => _translatorsRepository.GetInstance <SynchronizationBlock, BlockBase>().Translate(b)));
                }
                else if (blockTypeKey.BlockType == BlockTypes.Synchronization_RegistryCombinationBlock)
                {
                    return(DataAccessService.Instance.GetAllRegistryCombinedBlocks().Select(b => _translatorsRepository.GetInstance <RegistryCombinedBlock, BlockBase>().Translate(b)));
                }
            }

            return(null);
        }
Example #3
0
        public Candidate AddCandidateToPoll(long pollId, string name)
        {
            IKey assetId = _identityKeyProvider.GetKey(ConfidentialAssetsHelper.GetRandomSeed());

            var id = _dataAccessService.AddCandidateToPoll(pollId, name, assetId.ToString());

            return(_translatorsRepository.GetInstance <EcCandidateRecord, Candidate>().Translate(_dataAccessService.GetCandidateRecord(id)));
        }
Example #4
0
        public PacketBase GetLastBlock(IKey key)
        {
            TransactionalBlock transactionalBlock = DataAccessService.Instance.GetLastTransactionalBlock(key);

            if (transactionalBlock != null)
            {
                ITranslator <TransactionalBlock, PacketBase> mapper = _mapperFactory.GetInstance <TransactionalBlock, PacketBase>();

                PacketBase block = mapper?.Translate(transactionalBlock);

                return(block);
            }

            return(null);
        }
Example #5
0
        public BlockBase Get(IDataKey key)
        {
            if (key is SyncHashKey syncHashKey)
            {
                UtxoConfidentialBlock utxoConfidential = DataAccessService.Instance.GetUtxoConfidentialBySyncAndHash(syncHashKey.SyncBlockHeight, syncHashKey.Hash);

                return _mapperFactory.GetInstance<UtxoConfidentialBlock, BlockBase>().Translate(utxoConfidential);
            }

            return null;
        }
Example #6
0
        public PacketBase Get(IDataKey key)
        {
            if (key is SyncHashKey syncHashKey)
            {
                UtxoConfidentialBlock utxoConfidential = DataAccessService.Instance.GetUtxoConfidentialBySyncAndHash(syncHashKey.SyncBlockHeight, syncHashKey.Hash);

                if (utxoConfidential != null)
                {
                    return(_mapperFactory.GetInstance <UtxoConfidentialBlock, PacketBase>().Translate(utxoConfidential));
                }
            }

            return(null);
        }
Example #7
0
        public BlockBase Get(IDataKey key)
        {
            if (key is DoubleHeightKey heightKey)
            {
                TransactionsRegistryBlock transactionsRegistryBlock = DataAccessService.Instance.GetTransactionsRegistryBlock(heightKey.Height1, heightKey.Height2);

                BlockBase blockBase = _translatorsRepository.GetInstance <TransactionsRegistryBlock, BlockBase>().Translate(transactionsRegistryBlock);

                return(blockBase);
            }
            else if (key is SyncHashKey syncTransactionKey)
            {
                List <TransactionsRegistryBlock> transactionsRegistryBlocks = DataAccessService.Instance.GetTransactionsRegistryBlocks(syncTransactionKey.SyncBlockHeight);

                //TODO: !!! move storing default hash into database for reducing computational costs
                TransactionsRegistryBlock transactionsRegistryBlock = transactionsRegistryBlocks.FirstOrDefault(t => syncTransactionKey.Hash.Equals32(_defaultHashCalculation.CalculateHash(t.Content)));

                BlockBase blockBase = _translatorsRepository.GetInstance <TransactionsRegistryBlock, BlockBase>().Translate(transactionsRegistryBlock);

                return(blockBase);
            }

            return(null);
        }
Example #8
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)));
        }
Example #9
0
        public ActionResult <TranslationResponse> TranslateToAttributes(string issuerName, [FromBody] object json)
        {
            var provider = _dataAccessService.GetExternalIdentityProvider(issuerName);
            AccountDescriptor account = _accountsService.GetById(provider.AccountId);

            var validator = _externalIdpDataValidatorsRepository.GetInstance(issuerName);

            if (validator == null)
            {
                throw new Exception($"No validator found for {issuerName}");
            }

            TranslationResponse response = new TranslationResponse
            {
                Issuer    = account.PublicSpendKey.ToHexString(),
                ActionUri = $"{Request.Scheme}://{Request.Host}".AppendPathSegments("IdentityProvider", "IssueExternalIdpAttributes", account.PublicSpendKey.ToHexString()).ToString()
            };

            string jsonString = json?.ToString();

            switch (issuerName)
            {
            case "BlinkID-DrivingLicense":
            case "BlinkID-Passport":
                var request = JsonConvert.DeserializeObject <BlinkIdIdentityRequest>(jsonString);
                validator.Validate(request);
                var translator = _translatorsRepository.GetInstance <BlinkIdIdentityRequest, Dictionary <string, string> >();
                var attributes = translator.Translate(request);
                response.Attributes = attributes;
                break;

            default:
                return(BadRequest("unknown issuer name"));
            }

            return(Ok(response));
        }