コード例 #1
0
        public async Task <IActionResult> RegenerateKey([FromBody] RegenerateKeyRequestModel request)
        {
            var check2FaResult = await _google2FaService.Check2FaAsync <CreateApiKeyResponse>(_requestContext.ClientId, request.Code);

            if (check2FaResult != null)
            {
                return(Ok(check2FaResult));
            }

            var clientKeys = await _hftInternalService.Keys.GetKeys(_requestContext.ClientId);

            var existingApiKey = clientKeys.FirstOrDefault(x => x.WalletId == request.Id);

            if (existingApiKey != null)
            {
                var apiKey = await _hftInternalService.Keys.UpdateKey(new UpdateApiKeyModel
                {
                    ClientId  = _requestContext.ClientId,
                    WalletId  = existingApiKey.WalletId,
                    Apiv2Only = request.Apiv2Only
                });

                var result = new CreateApiKeyResponse {
                    ApiKey = apiKey.ApiKey, WalletId = apiKey.WalletId, Apiv2Only = request.Apiv2Only
                };
                return(Ok(Google2FaResultModel <CreateApiKeyResponse> .Success(result)));
            }

            return(NotFound());
        }
コード例 #2
0
        public async Task <Google2FaResultModel <T> > Check2FaAsync <T>(string clientId, string code)
        {
            try
            {
                bool codeIsValid = await _confirmationCodesClient.Google2FaCheckCodeAsync(clientId, code);

                if (!codeIsValid)
                {
                    return(Google2FaResultModel <T> .Fail(
                               LykkeApiErrorCodes.Service.SecondFactorCodeIncorrect.Name,
                               LykkeApiErrorCodes.Service.SecondFactorCodeIncorrect.DefaultMessage));
                }

                return(null);
            }
            catch (ApiException e)
            {
                switch (e.StatusCode)
                {
                case HttpStatusCode.BadRequest:
                    return(Google2FaResultModel <T> .Fail(
                               LykkeApiErrorCodes.Service.TwoFactorRequired.Name,
                               LykkeApiErrorCodes.Service.TwoFactorRequired.DefaultMessage));

                case HttpStatusCode.Forbidden:
                    return(Google2FaResultModel <T> .Fail(
                               LykkeApiErrorCodes.Service.SecondFactorCheckForbiden.Name,
                               LykkeApiErrorCodes.Service.SecondFactorCheckForbiden.DefaultMessage));
                }

                throw;
            }
        }
コード例 #3
0
        public async Task <IActionResult> DeleteWhitelistingAsync([FromRoute] long id,
                                                                  [FromBody] DeleteWhitelistingRequest request)
        {
            var check2FaResult = await _google2FaService.Check2FaAsync <string>(_requestContext.ClientId, request.Code2Fa);

            if (check2FaResult != null)
            {
                return(Ok(check2FaResult));
            }

            var deleteResponse = await _siriusWalletsService.DeleteWhitelistItemsAsync(id);

            if (deleteResponse == null || !deleteResponse.IsRemoved)
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.WhitelistingDeleteError);
            }

            return(Ok(Google2FaResultModel <string> .Success(id.ToString())));
        }
コード例 #4
0
        public async Task <IActionResult> Transfer([FromBody] CreateTransferRequest cmd, [FromQuery] Guid?id)
        {
            var check2FaResult = await _google2FaService.Check2FaAsync <string>(_requestContext.ClientId, cmd.Code2Fa);

            if (check2FaResult != null)
            {
                return(Ok(check2FaResult));
            }

            var operationId = id ?? Guid.NewGuid();

            await _operationsClient.Transfer(operationId,
                                             new CreateTransferCommand
            {
                ClientId       = new Guid(_requestContext.ClientId),
                Amount         = cmd.Amount,
                SourceWalletId =
                    cmd.SourceWalletId,
                WalletId = cmd.WalletId,
                AssetId  = cmd.AssetId
            });

            return(Ok(Google2FaResultModel <string> .Success(id.ToString())));
        }
コード例 #5
0
        public async Task <IActionResult> CreateWhitelistingAsync([FromBody] CreateWhitelistingRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.AddressBase))
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InvalidInput);
            }

            var check2FaResult = await _google2FaService.Check2FaAsync <string>(_requestContext.ClientId, request.Code2Fa);

            if (check2FaResult != null)
            {
                return(Ok(check2FaResult));
            }

            var asset = await _assetsHelper.GetAssetAsync(request.AssetId);

            var assetsAvailableToUser = await _assetsHelper.GetSetOfAssetsAvailableToClientAsync(_requestContext.ClientId, _requestContext.PartnerId, true);

            if (asset == null || asset.BlockchainIntegrationType != BlockchainIntegrationType.Sirius && assetsAvailableToUser.Contains(asset.Id))
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.AssetUnavailable);
            }

            var wallets = (await _clientAccountService.Wallets.GetClientWalletsFilteredAsync(_requestContext.ClientId,
                                                                                             owner: OwnerType.Spot, walletType: WalletType.Trusted)).ToList();

            if (wallets.All(x => x.Id != request.WalletId))
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InvalidInput);
            }

            var siriusAsset = await _siriusWalletsService.GetAssetByIdAsync(asset.SiriusAssetId);

            if (siriusAsset == null)
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.AssetUnavailable);
            }

            var siriusAccount = await _siriusWalletsService.SearchAccountAsync(_requestContext.ClientId, request.WalletId);

            if (siriusAccount == null)
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.BlockchainWalletDepositAddressNotGenerated);
            }

            var whitelistedItems = await _siriusWalletsService.GetWhitelistItemsAsync(siriusAccount.Body.Items.First().Id);

            if (whitelistedItems.Any(x => x.Details.Address == request.AddressBase && x.Details.Tag == request.AddressExtension))
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.AddressAlreadyWhitelisted);
            }

            var requestId = $"lykke:hft:withdrawals:{request.WalletId}:{request.Name}:{request.AssetId}:{request.AddressBase}:{request.AddressExtension ?? string.Empty}";

            var whitelistItemRequest = new WhitelistItemCreateRequest
            {
                Name  = request.Name,
                Scope = new WhitelistItemScope {
                    BrokerAccountId = _siriusApiServiceClientSettings.BrokerAccountId,
                    AccountId       = siriusAccount.Body.Items.First().Id,
                    UserNativeId    = _requestContext.ClientId
                },
                Details = new WhitelistItemDetails
                {
                    AssetId      = siriusAsset.Id,
                    BlockchainId = siriusAsset.BlockchainId,
                    Address      = request.AddressBase,
                    Tag          = request.AddressExtension,
                    TagType      =
                        new NullableWhitelistItemTagType
                    {
                        TagType = WhitelistItemTagType.Number     //TODO: specify tag type depending on the blockchain
                    },
                    TransactionType = WhitelistTransactionType.Withdrawal
                },
                Lifespan = new WhitelistItemLifespan {
                    StartsAt = Timestamp.FromDateTime(DateTime.UtcNow.Add(_whitelistingSettings.WaitingPeriod))
                },
                RequestId = requestId
            };

            var result = await _siriusWalletsService.CreateWhitelistItemAsync(whitelistItemRequest);

            if (result == null)
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.WhitelistingError);
            }

            await SendWhitelistEmail(_requestContext.ClientId, asset.DisplayId, request.AddressBase,
                                     request.AddressExtension);

            return(Ok(Google2FaResultModel <WhitelistingResponseModel> .Success(new WhitelistingResponseModel
            {
                Id = result.WhitelistItem.Id.ToString(),
                WalletName = wallets.Single(y => y.Id == request.WalletId).Name,
                AssetName = asset.DisplayId,
                Status = WhitelistingStatus.Pending,
                AddressBase = request.AddressBase,
                AddressExtension = request.AddressExtension,
                StartsAt = result.WhitelistItem.Lifespan.StartsAt.ToDateTime(),
                CreatedAt = result.WhitelistItem.CreatedAt.ToDateTime(),
                Name = request.Name
            })));
        }