From 95f781560e3fc701df90c0503ad3049d4f81596e Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Thu, 19 Jan 2023 12:48:19 +0200 Subject: [PATCH 01/11] feat: return APIResponse instead of raw response data, to include headers in response BREAKING CHANGE: changed response type for all of API methods, and removed deprecated transfer-assist operations --- src/api-client.ts | 63 ++++++--- src/fireblocks-sdk.ts | 289 ++++++++++++++++++------------------------ src/types.ts | 29 ++++- 3 files changed, 188 insertions(+), 193 deletions(-) diff --git a/src/api-client.ts b/src/api-client.ts index 83cc51d5..b522037d 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -1,7 +1,7 @@ import os from "os"; import platform from "platform"; import { IAuthProvider } from "./iauth-provider"; -import { RequestOptions } from "./types"; +import { APIResponse, RequestOptions, TransactionPageResponse } from "./types"; import { SDKOptions } from "./fireblocks-sdk"; import axios, { AxiosInstance } from "axios"; @@ -28,51 +28,78 @@ export class ApiClient { return userAgent; } - public async issueGetRequest(path: string, pageMode: boolean = false) { + public async issueGetRequestForTransactionPages(path: string): Promise> { const token = this.authProvider.signJwt(path); const res = await this.axiosInstance.get(path, { headers: {"Authorization": `Bearer ${token}`} }); - if (pageMode) { - return { + return { + data: { transactions: res.data, pageDetails: { prevPage: res.headers["prev-page"] ? res.headers["prev-page"].toString() : "", nextPage: res.headers["next-page"] ? res.headers["next-page"].toString() : "", } - }; - } - return res.data; + }, + headers: res.headers + }; + } + + public async issueGetRequest(path: string): Promise> { + const token = this.authProvider.signJwt(path); + const res = await this.axiosInstance.get(path, { + headers: {"Authorization": `Bearer ${token}`} + }); + return { + data: res.data, + headers: res.headers + }; } - public async issuePostRequest(path: string, body: any, requestOptions?: RequestOptions) { + public async issuePostRequest(path: string, body: any, requestOptions?: RequestOptions): Promise> { const token = this.authProvider.signJwt(path, body); const headers: any = {"Authorization": `Bearer ${token}`}; const idempotencyKey = requestOptions?.idempotencyKey; if (idempotencyKey) { headers["Idempotency-Key"] = idempotencyKey; } - return (await this.axiosInstance.post(path, body, {headers})).data; + const response = await this.axiosInstance.post(path, body, {headers}); + return { + data: response.data, + headers: response.headers + }; } - public async issuePutRequest(path: string, body: any) { + public async issuePutRequest(path: string, body: any): Promise> { const token = this.authProvider.signJwt(path, body); - return (await this.axiosInstance.put(path, body, { + const res = (await this.axiosInstance.put(path, body, { headers: {"Authorization": `Bearer ${token}`} - })).data; + })); + return { + data: res.data, + headers: res.headers, + }; } - public async issuePatchRequest(path: string, body: any) { + public async issuePatchRequest(path: string, body: any): Promise> { const token = this.authProvider.signJwt(path, body); - return (await this.axiosInstance.patch(path, body, { + const res = (await this.axiosInstance.patch(path, body, { headers: {"Authorization": `Bearer ${token}`} - })).data; + })); + return { + data: res.data, + headers: res.headers + }; } - public async issueDeleteRequest(path: string) { + public async issueDeleteRequest(path: string): Promise> { const token = this.authProvider.signJwt(path); - return (await this.axiosInstance.delete(path, { + const res = (await this.axiosInstance.delete(path, { headers: {"Authorization": `Bearer ${token}`} - })).data; + })); + return { + data: res.data, + headers: res.headers + }; } } diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index d5aa098d..50a19d2a 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -60,13 +60,13 @@ import { NFTOwnershipFilter, Token, TokenWithBalance, - APIPagedResponse, + Web3PagedResponse, CreateWalletConnectPayload, Web3ConnectionType, GetWeb3ConnectionsPayload, PublicKeyResponse, AllocateFundsResponse, - SettleOffExchangeAccountResponse, + SettleOffExchangeAccountResponse, APIResponse, PublicKeyInformation, DropTransactionResponse, } from "./types"; import { AxiosProxyConfig } from "axios"; @@ -79,8 +79,8 @@ export interface SDKOptions { } export class FireblocksSDK { - private authProvider: IAuthProvider; - private apiBaseUrl: string; + private readonly authProvider: IAuthProvider; + private readonly apiBaseUrl: string; private apiClient: ApiClient; /** @@ -104,7 +104,7 @@ export class FireblocksSDK { /** * Gets all assets that are currently supported by Fireblocks */ - public async getSupportedAssets(): Promise { + public async getSupportedAssets(): Promise> { return await this.apiClient.issueGetRequest("/v1/supported_assets"); } @@ -112,7 +112,7 @@ export class FireblocksSDK { * @deprecated this method is deprecated and will be removed in the future. Please use getVaultAccountsWithPageInfo instead. * Gets all vault accounts for your tenant */ - public async getVaultAccounts(filter?: VaultAccountsFilter): Promise { + public async getVaultAccounts(filter?: VaultAccountsFilter): Promise> { const url = `/v1/vault/accounts?${queryString.stringify(filter)}`; return await this.apiClient.issueGetRequest(url); } @@ -121,7 +121,7 @@ export class FireblocksSDK { * Gets a list of vault accounts per page matching the given filter or path * @param pagedVaultAccountsRequestFilters Filters for the first request */ - public async getVaultAccountsWithPageInfo(pagedVaultAccountsRequestFilters: PagedVaultAccountsRequestFilters): Promise { + public async getVaultAccountsWithPageInfo(pagedVaultAccountsRequestFilters: PagedVaultAccountsRequestFilters): Promise> { return await this.apiClient.issueGetRequest(`/v1/vault/accounts_paged?${queryString.stringify(pagedVaultAccountsRequestFilters)}`); } @@ -130,7 +130,7 @@ export class FireblocksSDK { * Gets a single vault account * @param vaultAccountId The vault account ID */ - public async getVaultAccount(vaultAccountId: string): Promise { + public async getVaultAccount(vaultAccountId: string): Promise> { return await this.getVaultAccountById(vaultAccountId); } @@ -138,7 +138,7 @@ export class FireblocksSDK { * Gets a single vault account * @param vaultAccountId The vault account ID */ - public async getVaultAccountById(vaultAccountId: string): Promise { + public async getVaultAccountById(vaultAccountId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}`); } @@ -147,7 +147,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param assetId The ID of the asset to get */ - public async getVaultAccountAsset(vaultAccountId: string, assetId: string): Promise { + public async getVaultAccountAsset(vaultAccountId: string, assetId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`); } @@ -157,7 +157,7 @@ export class FireblocksSDK { * @param assetId The ID of the asset to get * @param requestOptions */ - public async refreshVaultAssetBalance(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise { + public async refreshVaultAssetBalance(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/balance`, "{}", requestOptions); } @@ -166,7 +166,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param assetId The ID of the asset for which to get the deposit address */ - public async getDepositAddresses(vaultAccountId: string, assetId: string): Promise { + public async getDepositAddresses(vaultAccountId: string, assetId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`); } @@ -175,7 +175,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param assetId The ID of the asset for which to get the utxo list */ - public async getUnspentInputs(vaultAccountId: string, assetId: string): Promise { + public async getUnspentInputs(vaultAccountId: string, assetId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/unspent_inputs`); } @@ -187,7 +187,7 @@ export class FireblocksSDK { * @param customerRefId A customer reference ID * @param requestOptions */ - public async generateNewAddress(vaultAccountId: string, assetId: string, description?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise { + public async generateNewAddress(vaultAccountId: string, assetId: string, description?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`, { description, customerRefId @@ -202,7 +202,7 @@ export class FireblocksSDK { * @param tag The XRP tag, or EOS memo, for which to set the description * @param description The description to set */ - public async setAddressDescription(vaultAccountId: string, assetId: string, address: string, tag?: string, description?: string): Promise { + public async setAddressDescription(vaultAccountId: string, assetId: string, address: string, tag?: string, description?: string): Promise> { let addressId = address; if (tag && tag.length > 0) { addressId = `${address}:${tag}`; @@ -217,7 +217,7 @@ export class FireblocksSDK { * Gets all network connections * @returns NetworkConnectionResponse */ - public async getNetworkConnections(): Promise { + public async getNetworkConnections(): Promise> { return await this.apiClient.issueGetRequest("/v1/network_connections"); } @@ -228,7 +228,7 @@ export class FireblocksSDK { * @param routingPolicy The desired routing policy for the connection * @returns NetworkConnectionResponse */ - public async createNetworkConnection(localNetworkId: string, remoteNetworkId: string, routingPolicy?: NetworkConnectionRoutingPolicy): Promise { + public async createNetworkConnection(localNetworkId: string, remoteNetworkId: string, routingPolicy?: NetworkConnectionRoutingPolicy): Promise> { const body = { localNetworkId, remoteNetworkId, routingPolicy }; return await this.apiClient.issuePostRequest(`/v1/network_connections`, body); } @@ -238,7 +238,7 @@ export class FireblocksSDK { * @param connectionId The network connection's id * @returns NetworkConnectionResponse */ - public async getNetworkConnectionById(connectionId: string): Promise { + public async getNetworkConnectionById(connectionId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/network_connections/${connectionId}`); } @@ -247,7 +247,7 @@ export class FireblocksSDK { * @param connectionId The network connection's id * @returns OperationSuccessResponse */ - public async removeNetworkConnection(connectionId: string): Promise { + public async removeNetworkConnection(connectionId: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/network_connections/${connectionId}`); } @@ -256,7 +256,7 @@ export class FireblocksSDK { * @param connectionId The network connection's id * @param routingPolicy The desired routing policy */ - public async setNetworkConnectionRoutingPolicy(connectionId: string, routingPolicy: NetworkConnectionRoutingPolicy) { + public async setNetworkConnectionRoutingPolicy(connectionId: string, routingPolicy: NetworkConnectionRoutingPolicy): Promise> { const body = { routingPolicy }; return await this.apiClient.issuePatchRequest(`/v1/network_connections/${connectionId}/set_routing_policy`, body); } @@ -265,7 +265,7 @@ export class FireblocksSDK { * Gets all discoverable network profiles * @returns NetworkIdResponse */ - public async getDiscoverableNetworkIds(): Promise { + public async getDiscoverableNetworkIds(): Promise> { return await this.apiClient.issueGetRequest(`/v1/network_ids`); } @@ -275,7 +275,7 @@ export class FireblocksSDK { * @param routingPolicy The desired routing policy for the network * @returns NetworkConnectionResponse */ - public async createNetworkId(name: string, routingPolicy?: NetworkIdRoutingPolicy): Promise { + public async createNetworkId(name: string, routingPolicy?: NetworkIdRoutingPolicy): Promise> { const body = { name, routingPolicy }; return await this.apiClient.issuePostRequest(`/v1/network_ids`, body); } @@ -285,7 +285,7 @@ export class FireblocksSDK { * @param networkId The network profile's id * @returns NetworkIdResponse */ - public async getNetworkId(networkId: string): Promise { + public async getNetworkId(networkId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/network_ids/${networkId}`); } @@ -295,7 +295,7 @@ export class FireblocksSDK { * @param isDiscoverable The desired discoverability to set * @returns OperationSuccessResponse */ - public async setNetworkIdDiscoverability(networkId: string, isDiscoverable: boolean): Promise { + public async setNetworkIdDiscoverability(networkId: string, isDiscoverable: boolean): Promise> { const body = { isDiscoverable }; return await this.apiClient.issuePatchRequest(`/v1/network_ids/${networkId}/set_discoverability`, body); } @@ -306,7 +306,7 @@ export class FireblocksSDK { * @param routingPolicy The desired routing policy * @returns OperationSuccessResponse */ - public async setNetworkIdRoutingPolicy(networkId: string, routingPolicy: NetworkIdRoutingPolicy) { + public async setNetworkIdRoutingPolicy(networkId: string, routingPolicy: NetworkIdRoutingPolicy): Promise> { const body = { routingPolicy }; return await this.apiClient.issuePatchRequest(`/v1/network_ids/${networkId}/set_routing_policy`, body); } @@ -314,7 +314,7 @@ export class FireblocksSDK { /** * Gets all exchange accounts for your tenant */ - public async getExchangeAccounts(): Promise { + public async getExchangeAccounts(): Promise> { return await this.apiClient.issueGetRequest("/v1/exchange_accounts"); } @@ -323,7 +323,7 @@ export class FireblocksSDK { * Gets a single exchange account by ID * @param exchangeAccountId The exchange account ID */ - public async getExchangeAccount(exchangeAccountId: string): Promise { + public async getExchangeAccount(exchangeAccountId: string): Promise> { return await this.getExchangeAccount(exchangeAccountId); } @@ -331,7 +331,7 @@ export class FireblocksSDK { * Gets a single exchange account by ID * @param exchangeAccountId The exchange account ID */ - public async getExchangeAccountById(exchangeAccountId: string): Promise { + public async getExchangeAccountById(exchangeAccountId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/exchange_accounts/${exchangeAccountId}`); } @@ -340,7 +340,7 @@ export class FireblocksSDK { * @param exchangeAccountId The exchange account ID * @param assetId The ID of the asset */ - public async getExchangeAsset(exchangeAccountId: string, assetId: string): Promise { + public async getExchangeAsset(exchangeAccountId: string, assetId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/exchange_accounts/${exchangeAccountId}/${assetId}`); } @@ -351,7 +351,7 @@ export class FireblocksSDK { * @param destAsset The destination asset to convert to * @param amount The amount to convert */ - public async convertExchangeAsset(exchangeAccountId: string, srcAsset: string, destAsset: string, amount: number, requestOptions?: RequestOptions): Promise { + public async convertExchangeAsset(exchangeAccountId: string, srcAsset: string, destAsset: string, amount: number, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/exchange_accounts/${exchangeAccountId}/convert`, { srcAsset, destAsset, amount }, requestOptions); @@ -365,7 +365,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async transferToSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise { + public async transferToSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise> { const body = { subaccountId, amount @@ -382,7 +382,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async transferFromSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise { + public async transferFromSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise> { const body = { subaccountId, amount @@ -394,7 +394,7 @@ export class FireblocksSDK { /** * Gets all fiat accounts for your tenant */ - public async getFiatAccounts(): Promise { + public async getFiatAccounts(): Promise> { return await this.apiClient.issueGetRequest("/v1/fiat_accounts"); } @@ -402,7 +402,7 @@ export class FireblocksSDK { * Gets a single fiat account by ID * @param accountId The fiat account ID */ - public async getFiatAccountById(accountId: string): Promise { + public async getFiatAccountById(accountId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/fiat_accounts/${accountId}`); } @@ -412,7 +412,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async redeemToLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise { + public async redeemToLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise> { const body = { amount }; @@ -426,7 +426,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async depositFromLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise { + public async depositFromLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise> { const body = { amount }; @@ -442,7 +442,7 @@ export class FireblocksSDK { * @param filter.limit Limit the amount of returned results. If not specified, a limit of 200 results will be used * @param filter.orderBy Determines the order of the results */ - public async getTransactions(filter: TransactionFilter): Promise { + public async getTransactions(filter: TransactionFilter): Promise> { return await this.apiClient.issueGetRequest(`/v1/transactions?${queryString.stringify(filter)}`); } @@ -451,30 +451,32 @@ export class FireblocksSDK { * @param pageFilter Get transactions matching pageFilter params * @param nextOrPreviousPath Get transactions from each of pageDetails paths */ - public async getTransactionsWithPageInfo(pageFilter?: TransactionPageFilter, nextOrPreviousPath?: string): Promise { + public async getTransactionsWithPageInfo(pageFilter?: TransactionPageFilter, nextOrPreviousPath?: string): Promise> { if (pageFilter) { - return await this.apiClient.issueGetRequest(`/v1/transactions?${queryString.stringify(pageFilter)}`, true); + return await this.apiClient.issueGetRequestForTransactionPages(`/v1/transactions?${queryString.stringify(pageFilter)}`); } else if (nextOrPreviousPath) { const index = nextOrPreviousPath.indexOf("/v1/"); const path = nextOrPreviousPath.substring(index, nextOrPreviousPath.length); - return await this.apiClient.issueGetRequest(path, true); + return await this.apiClient.issueGetRequestForTransactionPages(path); } - return {transactions: [], pageDetails: { prevPage: "", nextPage: "" }}; + return { + data: {transactions: [], pageDetails: { prevPage: "", nextPage: "" }}, + }; } /** * Gets a transaction matching the external transaction id provided * @param externalTxId */ - public async getTransactionByExternalTxId(externalTxId: string): Promise { + public async getTransactionByExternalTxId(externalTxId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/transactions/external_tx_id/${externalTxId}`); } /** * Gets all internal wallets for your tenant */ - public async getInternalWallets(): Promise[]> { + public async getInternalWallets(): Promise[]>> { return await this.apiClient.issueGetRequest("/v1/internal_wallets"); } @@ -482,7 +484,7 @@ export class FireblocksSDK { * Gets a single internal wallet * @param walletId The internal wallet ID */ - public async getInternalWallet(walletId: string): Promise> { + public async getInternalWallet(walletId: string): Promise>> { return await this.apiClient.issueGetRequest(`/v1/internal_wallets/${walletId}`); } @@ -491,14 +493,14 @@ export class FireblocksSDK { * @param walletId The internal wallet ID * @param assetId The asset ID */ - public async getInternalWalletAsset(walletId: string, assetId: string): Promise { + public async getInternalWalletAsset(walletId: string, assetId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/internal_wallets/${walletId}/${assetId}`); } /** * Gets all external wallets for your tenant */ - public async getExternalWallets(): Promise[]> { + public async getExternalWallets(): Promise[]>> { return await this.apiClient.issueGetRequest("/v1/external_wallets"); } @@ -506,7 +508,7 @@ export class FireblocksSDK { * Gets a single external wallet * @param walletId The external wallet ID */ - public async getExternalWallet(walletId: string): Promise> { + public async getExternalWallet(walletId: string): Promise>> { return await this.apiClient.issueGetRequest(`/v1/external_wallets/${walletId}`); } @@ -515,14 +517,14 @@ export class FireblocksSDK { * @param walletId The external wallet ID * @param assetId The asset ID */ - public async getExternalWalletAsset(walletId: string, assetId: string): Promise { + public async getExternalWalletAsset(walletId: string, assetId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/external_wallets/${walletId}/${assetId}`); } /** * Gets all contract wallets for your tenant */ - public async getContractWallets(): Promise[]> { + public async getContractWallets(): Promise[]>> { return await this.apiClient.issueGetRequest("/v1/contracts"); } @@ -530,7 +532,7 @@ export class FireblocksSDK { * Gets a single contract wallet * @param walletId The contract wallet ID */ - public async getContractWallet(walletId: string): Promise> { + public async getContractWallet(walletId: string): Promise>> { return await this.apiClient.issueGetRequest(`/v1/contracts/${walletId}`); } @@ -539,7 +541,7 @@ export class FireblocksSDK { * @param walletId The contract wallet ID * @param assetId The asset ID */ - public async getContractWalletAsset(walletId: string, assetId: string): Promise { + public async getContractWalletAsset(walletId: string, assetId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/contracts/${walletId}/${assetId}`); } @@ -547,7 +549,7 @@ export class FireblocksSDK { * Gets detailed information for a single transaction * @param txId The transaction id to query */ - public async getTransactionById(txId: string): Promise { + public async getTransactionById(txId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/transactions/${txId}`); } @@ -556,7 +558,7 @@ export class FireblocksSDK { * @param txId The transaction id to cancel * @param requestOptions */ - public async cancelTransactionById(txId: string, requestOptions?: RequestOptions): Promise { + public async cancelTransactionById(txId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/transactions/${txId}/cancel`, {}, requestOptions); } @@ -570,7 +572,7 @@ export class FireblocksSDK { * @param autoFuel * @param requestOptions */ - public async createVaultAccount(name: string, hiddenOnUI?: boolean, customerRefId?: string, autoFuel?: boolean, requestOptions?: RequestOptions): Promise { + public async createVaultAccount(name: string, hiddenOnUI?: boolean, customerRefId?: string, autoFuel?: boolean, requestOptions?: RequestOptions): Promise> { const body = { name, customerRefId, @@ -586,7 +588,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param requestOptions */ - public async hideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise { + public async hideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/hide`, {}, requestOptions); } @@ -595,7 +597,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param requestOptions */ - public async unhideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise { + public async unhideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/unhide`, {}, requestOptions); } @@ -605,7 +607,7 @@ export class FireblocksSDK { * @param autoFuel The new value for the autoFuel flag * @param requestOptions */ - public async setAutoFuel(vaultAccountId: string, autoFuel: boolean, requestOptions?: RequestOptions): Promise { + public async setAutoFuel(vaultAccountId: string, autoFuel: boolean, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/set_auto_fuel`, {autoFuel}, requestOptions); } @@ -614,7 +616,7 @@ export class FireblocksSDK { * @param vaultAccountId * @param name A new name for the vault account */ - public async updateVaultAccount(vaultAccountId: string, name: string): Promise { + public async updateVaultAccount(vaultAccountId: string, name: string): Promise> { const body = { name: name }; @@ -628,7 +630,7 @@ export class FireblocksSDK { * @param assetId The asset to add * @param requestOptions */ - public async createVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise { + public async createVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`, {}, requestOptions); } @@ -638,7 +640,7 @@ export class FireblocksSDK { * @param assetId The asset to add * @param requestOptions */ - public async activateVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise { + public async activateVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/activate`, {} , requestOptions); } @@ -648,7 +650,7 @@ export class FireblocksSDK { * @param customerRefId A customer reference ID * @param requestOptions */ - public async createExternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { + public async createExternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise>> { const body = { name, customerRefId @@ -663,7 +665,7 @@ export class FireblocksSDK { * @param customerRefId A customer reference ID * @param requestOptions */ - public async createInternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { + public async createInternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise>> { const body = { name, customerRefId @@ -676,7 +678,7 @@ export class FireblocksSDK { * Creates a new contract wallet * @param name A name for the new contract wallet */ - public async createContractWallet(name: string, requestOptions?: RequestOptions): Promise> { + public async createContractWallet(name: string, requestOptions?: RequestOptions): Promise>> { const body = { name, }; @@ -692,7 +694,7 @@ export class FireblocksSDK { * @param tag (for ripple only) The ripple account tag * @param requestOptions */ - public async createExternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise { + public async createExternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise> { const path = `/v1/external_wallets/${walletId}/${assetId}`; const body = { @@ -710,7 +712,7 @@ export class FireblocksSDK { * @param tag (for ripple only) The ripple account tag * @param requestOptions */ - public async createInternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise { + public async createInternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise> { const path = `/v1/internal_wallets/${walletId}/${assetId}`; const body = { @@ -727,7 +729,7 @@ export class FireblocksSDK { * @param address The wallet address * @param tag (for ripple only) The ripple account tag */ - public async createContractWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise { + public async createContractWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise> { const path = `/v1/contracts/${walletId}/${assetId}`; const body = { @@ -740,81 +742,29 @@ export class FireblocksSDK { /** * Creates a new transaction with the specified options */ - public async createTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise { + public async createTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest("/v1/transactions", transactionArguments, requestOptions); } /** * Estimates the fee for a transaction request */ - public async estimateFeeForTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise { + public async estimateFeeForTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest("/v1/transactions/estimate_fee", transactionArguments, requestOptions); } /** * Gets the estimated fees for an asset */ - public async getFeeForAsset(asset: string): Promise { + public async getFeeForAsset(asset: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/estimate_network_fee?assetId=${asset}`); } - /** - * Creates a new transfer ticket - */ - public async createTransferTicket(options: CreateTransferTicketArgs, requestOptions?: RequestOptions): Promise { - return await this.apiClient.issuePostRequest("/v1/transfer_tickets", options, requestOptions); - } - - /** - * Gets all transfer tickets - */ - public async getTransferTickets(): Promise { - return await this.apiClient.issueGetRequest("/v1/transfer_tickets"); - } - - /** - * Get a transfer ticket by ticket ID - * @param ticketId - */ - public async getTransferTicketById(ticketId: string): Promise { - return await this.apiClient.issueGetRequest(`/v1/transfer_tickets/${ticketId}`); - } - - /** - * Get a term of transfer ticket - * @param ticketId - * @param termId - */ - public async getTransferTicketTerm(ticketId: string, termId: string): Promise { - return await this.apiClient.issueGetRequest(`/v1/transfer_tickets/${ticketId}/${termId}`); - } - - /** - * Cancel the transfer ticket - * @param ticketId - * @param requestOptions - */ - public async cancelTransferTicket(ticketId: string, requestOptions?: RequestOptions) { - return await this.apiClient.issuePostRequest(`/v1/transfer_tickets/${ticketId}/cancel`, {}, requestOptions); - } - - /** - * Executes a transaction for a single term of a transfer ticket - * @param ticketId - * @param termId - * @param options - * @param requestOptions - */ - public async executeTransferTicketTerm(ticketId: string, termId: string, options: ExecuteTermArgs, requestOptions?: RequestOptions) { - return await this.apiClient.issuePostRequest(`/v1/transfer_tickets/${ticketId}/${termId}/transfer`, - options, requestOptions); - } - /** * Deletes a single internal wallet * @param walletId The internal wallet ID */ - public async deleteInternalWallet(walletId: string): Promise { + public async deleteInternalWallet(walletId: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/internal_wallets/${walletId}`); } @@ -823,7 +773,7 @@ export class FireblocksSDK { * @param walletId The internal wallet ID * @param assetId The asset ID */ - public async deleteInternalWalletAsset(walletId: string, assetId: string): Promise { + public async deleteInternalWalletAsset(walletId: string, assetId: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/internal_wallets/${walletId}/${assetId}`); } @@ -831,7 +781,7 @@ export class FireblocksSDK { * Deletes a single external wallet * @param walletId The external wallet ID */ - public async deleteExternalWallet(walletId: string): Promise { + public async deleteExternalWallet(walletId: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/external_wallets/${walletId}`); } @@ -840,7 +790,7 @@ export class FireblocksSDK { * @param walletId The external wallet ID * @param assetId The asset ID */ - public async deleteExternalWalletAsset(walletId: string, assetId: string): Promise { + public async deleteExternalWalletAsset(walletId: string, assetId: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/external_wallets/${walletId}/${assetId}`); } @@ -848,7 +798,7 @@ export class FireblocksSDK { * Deletes a single contract wallet * @param walletId The contract wallet ID */ - public async deleteContractWallet(walletId: string): Promise { + public async deleteContractWallet(walletId: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/contracts/${walletId}`); } @@ -857,7 +807,7 @@ export class FireblocksSDK { * @param walletId The contract wallet ID * @param assetId The asset ID */ - public async deleteContractWalletAsset(walletId: string, assetId: string): Promise { + public async deleteContractWalletAsset(walletId: string, assetId: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/contracts/${walletId}/${assetId}`); } @@ -867,7 +817,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForVaultAccount(vaultAccountId: string, customerRefId: string, requestOptions?: RequestOptions): Promise { + public async setCustomerRefIdForVaultAccount(vaultAccountId: string, customerRefId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/set_customer_ref_id`, {customerRefId}, requestOptions); } @@ -877,7 +827,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForInternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise { + public async setCustomerRefIdForInternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/internal_wallets/${walletId}/set_customer_ref_id`, {customerRefId}, requestOptions); } @@ -887,7 +837,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForExternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise { + public async setCustomerRefIdForExternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/external_wallets/${walletId}/set_customer_ref_id`, {customerRefId}, requestOptions); } @@ -900,7 +850,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForAddress(vaultAccountId: string, assetId: string, address: string, tag?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise { + public async setCustomerRefIdForAddress(vaultAccountId: string, assetId: string, address: string, tag?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { let addressId = address; if (tag && tag.length > 0) { addressId = `${address}:${tag}`; @@ -915,7 +865,7 @@ export class FireblocksSDK { * @param requiredConfirmationsNumber * @param requestOptions */ - public async setConfirmationThresholdForTxId(txId: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise { + public async setConfirmationThresholdForTxId(txId: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/transactions/${txId}/set_confirmation_threshold`, {numOfConfirmations: requiredConfirmationsNumber}, requestOptions); } @@ -925,7 +875,7 @@ export class FireblocksSDK { * @param requiredConfirmationsNumber * @param requestOptions */ - public async setConfirmationThresholdForTxHash(txHash: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise { + public async setConfirmationThresholdForTxHash(txHash: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/txHash/${txHash}/set_confirmation_threshold`, {numOfConfirmations: requiredConfirmationsNumber}, requestOptions); } @@ -933,7 +883,7 @@ export class FireblocksSDK { * Get the public key information * @param args */ - public async getPublicKeyInfo(args: PublicKeyInfoArgs) { + public async getPublicKeyInfo(args: PublicKeyInfoArgs): Promise> { let url = `/v1/vault/public_key_info`; if (args.algorithm) { url += `?algorithm=${args.algorithm}`; @@ -956,7 +906,7 @@ export class FireblocksSDK { * @param args * @param requestOptions */ - public async allocateFundsToPrivateLedger(vaultAccountId: string, asset: string, args: AllocateFundsRequest, requestOptions?: RequestOptions): Promise { + public async allocateFundsToPrivateLedger(vaultAccountId: string, asset: string, args: AllocateFundsRequest, requestOptions?: RequestOptions): Promise> { const url = `/v1/vault/accounts/${vaultAccountId}/${asset}/lock_allocation`; return await this.apiClient.issuePostRequest(url, args, requestOptions); } @@ -968,7 +918,7 @@ export class FireblocksSDK { * @param args * @param requestOptions */ - public async deallocateFundsFromPrivateLedger(vaultAccountId: string, asset: string, args: DeallocateFundsRequest, requestOptions?: RequestOptions): Promise { + public async deallocateFundsFromPrivateLedger(vaultAccountId: string, asset: string, args: DeallocateFundsRequest, requestOptions?: RequestOptions): Promise> { const url = `/v1/vault/accounts/${vaultAccountId}/${asset}/release_allocation`; return await this.apiClient.issuePostRequest(url, args, requestOptions); } @@ -977,7 +927,7 @@ export class FireblocksSDK { * Get the public key information for a vault account * @param args */ - public async getPublicKeyInfoForVaultAccount(args: PublicKeyInfoForVaultAccountArgs): Promise { + public async getPublicKeyInfoForVaultAccount(args: PublicKeyInfoForVaultAccountArgs): Promise> { let url = `/v1/vault/accounts/${args.vaultAccountId}/${args.assetId}/${args.change}/${args.addressIndex}/public_key_info`; if (args.compressed) { url += `?compressed=${args.compressed}`; @@ -988,7 +938,7 @@ export class FireblocksSDK { /** * Get configuration and status of the Gas Station account */ - public async getGasStationInfo(assetId?: string): Promise { + public async getGasStationInfo(assetId?: string): Promise> { let url = `/v1/gas_station`; if (assetId) { @@ -1001,7 +951,7 @@ export class FireblocksSDK { /** * Set configuration of the Gas Station account */ - public async setGasStationConfiguration(gasThreshold: string, gasCap: string, maxGasPrice?: string, assetId?: string): Promise { + public async setGasStationConfiguration(gasThreshold: string, gasCap: string, maxGasPrice?: string, assetId?: string): Promise> { let url = `/v1/gas_station/configuration`; if (assetId) { @@ -1016,7 +966,7 @@ export class FireblocksSDK { /** * Drop an ETH based transaction */ - public async dropTransaction(txId: string, feeLevel?: string, requestedFee?: string, requestOptions?: RequestOptions) { + public async dropTransaction(txId: string, feeLevel?: string, requestedFee?: string, requestOptions?: RequestOptions): Promise> { const url = `/v1/transactions/${txId}/drop`; const body = {feeLevel, requestedFee}; @@ -1027,7 +977,7 @@ export class FireblocksSDK { /** * Get max spendable amount per asset and vault */ - public async getMaxSpendableAmount(vaultAccountId: string, assetId: string, manualSigning?: Boolean): Promise { + public async getMaxSpendableAmount(vaultAccountId: string, assetId: string, manualSigning?: Boolean): Promise> { let url = `/v1/vault/accounts/${vaultAccountId}/${assetId}/max_spendable_amount`; if (manualSigning) { @@ -1040,7 +990,7 @@ export class FireblocksSDK { /** * Get all vault assets balance overview */ - public async getVaultAssetsBalance(filter: VaultBalancesFilter): Promise { + public async getVaultAssetsBalance(filter: VaultBalancesFilter): Promise> { const url = `/v1/vault/assets?${queryString.stringify(filter)}`; return await this.apiClient.issueGetRequest(url); @@ -1049,7 +999,7 @@ export class FireblocksSDK { /** * Get vault balance overview per asset */ - public async getVaultBalanceByAsset(assetId: string): Promise { + public async getVaultBalanceByAsset(assetId: string): Promise> { const url = `/v1/vault/assets/${assetId}`; return await this.apiClient.issueGetRequest(url); } @@ -1057,7 +1007,7 @@ export class FireblocksSDK { /** * Get address validation info */ - public async validateAddress(assetId: string, address: string): Promise { + public async validateAddress(assetId: string, address: string): Promise> { const url = `/v1/transactions/validate_address/${assetId}/${address}`; return await this.apiClient.issueGetRequest(url); } @@ -1067,7 +1017,7 @@ export class FireblocksSDK { * @param txId The transaction id to unfreeze * @param requestOptions */ - public async unfreezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise { + public async unfreezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise> { return this.apiClient.issuePostRequest(`/v1/transactions/${txId}/unfreeze`, {}, requestOptions); } @@ -1076,14 +1026,14 @@ export class FireblocksSDK { * @param txId The transaction id to freeze * @param requestOptions */ - public async freezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise { + public async freezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise> { return this.apiClient.issuePostRequest(`/v1/transactions/${txId}/freeze`, {}, requestOptions); } /** * Resend failed webhooks */ - public async resendWebhooks(requestOptions?: RequestOptions): Promise { + public async resendWebhooks(requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest("/v1/webhooks/resend", {}, requestOptions); } @@ -1094,7 +1044,7 @@ export class FireblocksSDK { * @param resendStatusUpdated If true a webhook will be sent for the status of the transaction * @param requestOptions */ - public async resendTransactionWebhooksById(txId: string, resendCreated?: boolean, resendStatusUpdated?: boolean, requestOptions?: RequestOptions): Promise { + public async resendTransactionWebhooksById(txId: string, resendCreated?: boolean, resendStatusUpdated?: boolean, requestOptions?: RequestOptions): Promise> { const body = { resendCreated, resendStatusUpdated }; return await this.apiClient.issuePostRequest(`/v1/webhooks/resend/${txId}`, body, requestOptions); } @@ -1102,14 +1052,14 @@ export class FireblocksSDK { /** * Gets all Users for your tenant */ - public async getUsers(): Promise { + public async getUsers(): Promise> { return await this.apiClient.issueGetRequest("/v1/users"); } /** * Get off exchange accounts */ - public async getOffExchangeAccounts(): Promise { + public async getOffExchangeAccounts(): Promise> { return await this.apiClient.issueGetRequest(`/v1/off_exchange_accounts`); } @@ -1117,7 +1067,7 @@ export class FireblocksSDK { * Get off exchange account by virtual account id * @param id the ID of the off exchange */ - public async getOffExchangeAccountById(id: string): Promise { + public async getOffExchangeAccountById(id: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/off_exchange_accounts/${id}`); } @@ -1126,7 +1076,7 @@ export class FireblocksSDK { * @param id the ID of the off exchange * @param requestOptions */ - public async settleOffExchangeAccountById(id: string, requestOptions?: RequestOptions): Promise { + public async settleOffExchangeAccountById(id: string, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/off_exchange_accounts/${id}/settle`, {}, requestOptions); } @@ -1136,7 +1086,7 @@ export class FireblocksSDK { * @param baseAsset * @param requestOptions */ - public async setFeePayerConfiguration(baseAsset: string, feePayerConfiguration: SetFeePayerConfiguration, requestOptions?: RequestOptions): Promise { + public async setFeePayerConfiguration(baseAsset: string, feePayerConfiguration: SetFeePayerConfiguration, requestOptions?: RequestOptions): Promise> { return await this.apiClient.issuePostRequest(`/v1/fee_payer/${baseAsset}`, feePayerConfiguration, requestOptions); } @@ -1144,7 +1094,7 @@ export class FireblocksSDK { * Get Fee Payer Configuration * @param baseAsset */ - public async getFeePayerConfiguration(baseAsset: string): Promise { + public async getFeePayerConfiguration(baseAsset: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/fee_payer/${baseAsset}`); } @@ -1152,11 +1102,11 @@ export class FireblocksSDK { * Delete Fee Payer Configuration * @param baseAsset */ - public async removeFeePayerConfiguration(baseAsset: string): Promise { + public async removeFeePayerConfiguration(baseAsset: string): Promise> { return await this.apiClient.issueDeleteRequest(`/v1/fee_payer/${baseAsset}`); } - private getWeb3ConnectionPath(type: Web3ConnectionType) { + private getWeb3ConnectionPath(type: Web3ConnectionType): string { const basePath = `/v1/connections`; switch (type) { @@ -1186,7 +1136,7 @@ export class FireblocksSDK { sort, filter, order - }: GetWeb3ConnectionsPayload = {}): Promise> { + }: GetWeb3ConnectionsPayload = {}): Promise>> { const params = new URLSearchParams({ ...(pageCursor && { next: pageCursor }), ...(pageSize && { pageSize: pageSize.toString() }), @@ -1202,6 +1152,7 @@ export class FireblocksSDK { * Initiate a new web3 connection * @param type The type of the connection * @param payload The payload for creating a new web3 connection + * @param requestOptions * @param payload.vaultAccountId The vault account to link with the dapp * @param payload.feeLevel The fee level for the connection * @param payload.uri The WalletConnect URI, as provided by the dapp @@ -1216,8 +1167,8 @@ export class FireblocksSDK { * chainIds: ["ETH", "ETH_TEST"] * } */ - public async createWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, payload: CreateWalletConnectPayload, requestOptions?: RequestOptions): Promise; - public async createWeb3Connection(type: Web3ConnectionType, payload: CreateWeb3ConnectionPayload, requestOptions?: RequestOptions): Promise { + public async createWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, payload: CreateWalletConnectPayload, requestOptions?: RequestOptions): Promise>; + public async createWeb3Connection(type: Web3ConnectionType, payload: CreateWeb3ConnectionPayload, requestOptions?: RequestOptions): Promise> { const path = this.getWeb3ConnectionPath(type); return await this.apiClient.issuePostRequest(path, payload, requestOptions); @@ -1229,8 +1180,8 @@ export class FireblocksSDK { * @param sessionId The ID of the session * @param approve Whether you approve the connection or not */ - public async submitWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string, approve: boolean): Promise; - public async submitWeb3Connection(type: Web3ConnectionType, sessionId: string, approve: boolean): Promise { + public async submitWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string, approve: boolean): Promise>; + public async submitWeb3Connection(type: Web3ConnectionType, sessionId: string, approve: boolean): Promise> { const path = this.getWeb3ConnectionPath(type); return await this.apiClient.issuePutRequest(`${path}/${sessionId}`, {approve}); @@ -1241,8 +1192,8 @@ export class FireblocksSDK { * @param type The type of the connection * @param sessionId The ID of the session */ - public async removeWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string): Promise; - public async removeWeb3Connection(type: Web3ConnectionType, sessionId: string): Promise { + public async removeWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string): Promise>; + public async removeWeb3Connection(type: Web3ConnectionType, sessionId: string): Promise> { const path = this.getWeb3ConnectionPath(type); return await this.apiClient.issueDeleteRequest(`${path}/${sessionId}`); @@ -1252,7 +1203,7 @@ export class FireblocksSDK { * Gets all audits for selected time period * @param timePeriod */ - public async getAudits(timePeriod?: TimePeriod): Promise { + public async getAudits(timePeriod?: TimePeriod): Promise> { let url = `/v1/audits`; if (timePeriod) { url += `?timePeriod=${timePeriod}`; @@ -1264,7 +1215,7 @@ export class FireblocksSDK { * * @param id */ - public async getNFT(id: string): Promise { + public async getNFT(id: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/nfts/tokens/${id}`); } @@ -1274,7 +1225,7 @@ export class FireblocksSDK { * @param pageCursor * @param pageSize */ - public async getNFTs(ids: string[], pageCursor?: string, pageSize?: number): Promise> { + public async getNFTs(ids: string[], pageCursor?: string, pageSize?: number): Promise>> { const queryParams = { pageCursor, pageSize, @@ -1291,7 +1242,7 @@ export class FireblocksSDK { * @param filter.blockchainDescriptor The blockchain descriptor (based on legacy asset) * @param filter.ids List of token ids to fetch */ - public async getOwnedNFTs(filter?: NFTOwnershipFilter): Promise> { + public async getOwnedNFTs(filter?: NFTOwnershipFilter): Promise>> { let url = "/v1/nfts/ownership/tokens"; if (filter) { const { blockchainDescriptor, vaultAccountId, ids, pageCursor, pageSize } = filter; @@ -1311,7 +1262,7 @@ export class FireblocksSDK { * * @param id */ - public async refreshNFTMetadata(id: string): Promise { + public async refreshNFTMetadata(id: string): Promise> { return await this.apiClient.issuePutRequest(`/v1/nfts/tokens/${id}`, undefined); } @@ -1320,7 +1271,7 @@ export class FireblocksSDK { * @param vaultAccountId * @param blockchainDescriptor */ - public async refreshNFTOwnershipByVault(vaultAccountId: string, blockchainDescriptor: string): Promise { + public async refreshNFTOwnershipByVault(vaultAccountId: string, blockchainDescriptor: string): Promise> { return await this.apiClient.issuePutRequest( `/v1/nfts/ownership/tokens?vaultAccountId=${vaultAccountId}&blockchainDescriptor=${blockchainDescriptor}`, undefined); diff --git a/src/types.ts b/src/types.ts index dbe6aeb1..101b8e9a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,15 @@ +import { AxiosResponseHeaders } from "axios"; + +export interface Web3PagedResponse { + data: T[]; + paging?: Paging; +} + +export interface APIResponse { + data: T; + headers?: AxiosResponseHeaders; +} + export interface VaultAccountResponse { id: string; name: string; @@ -487,7 +499,6 @@ export interface NFTOwnershipFilter { pageSize?: number; } - class MediaEntity { url: string; contentType: string; @@ -503,11 +514,6 @@ export interface Paging { next: string; } -export interface APIPagedResponse { - data: T[]; - paging?: Paging; -} - export interface Token { id: string; tokenId: string; @@ -714,6 +720,17 @@ export interface PublicKeyResponse { publicKey: string; } +export interface PublicKeyInformation { + algorithm: string; + derivationPath: number[]; + publicKey: String; +} + +export interface DropTransactionResponse { + success: boolean; + transactions?: string[]; +} + export interface MaxSpendableAmountResponse { maxSpendableAmount: string; } From e9d257486f004cae4b40e42f6c1d0721e36125a6 Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Mon, 6 Feb 2023 15:50:41 +0200 Subject: [PATCH 02/11] readme: add reamde indication for the v4 migration, also add type for the response header --- README.md | 24 ++++++++++++++++++++++++ src/types.ts | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d66c7339..254e2268 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,30 @@ This repository contains the official Javascript & Typescript SDK for Fireblocks API. For the complete API reference, go to [API reference](https://docs.fireblocks.com/api/swagger-ui/). +## V4 Migration +In v4 we changed all the sdk response types to return the `APIResponse` object, which is defined as: +```ts +export interface APIResponse { + data: T; // http response body + headers?: AxiosResponseHeaders; // http response headers +} +``` + +This means that if you previously fetched data in the following way: +```ts +const exchangeAccounts: ExchangeResponse = await sdk.getExchangeAccount(exchangeAccountId); +``` + +It should be transformed to: +```ts +const {data: exchangeAccounts, responseHeaders: headers} = (await sdk.getExchangeAccount(exchangeAccountId)); +``` + +### `X-REQUEST-ID` Response Header +Using v4 you can now use the response header `x-request-id` which correlates the request to the Fireblocks operation. + +You can provide the value of this header in case you have support tickets related to an API operation, or a Github issue. + ## Usage #### Before You Begin Make sure you have the credentials for Fireblocks API Services. Otherwise, please contact Fireblocks support for further instructions on how to obtain your API credentials. diff --git a/src/types.ts b/src/types.ts index 08a3cf7b..2fc67417 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,9 +5,11 @@ export interface Web3PagedResponse { paging?: Paging; } +export type APIResponseHeaders = AxiosResponseHeaders & {"x-request-id"?: string}; + export interface APIResponse { data: T; - headers?: AxiosResponseHeaders; + headers?: APIResponseHeaders; } export interface VaultAccountResponse { From f3473990595be21477fbfa58719f15ca0fed0bf7 Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Thu, 9 Feb 2023 13:54:59 +0200 Subject: [PATCH 03/11] add status code to response --- src/api-client.ts | 13 +++++++++---- src/types.ts | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/api-client.ts b/src/api-client.ts index 24bc3fd0..0cb82d3d 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -56,7 +56,8 @@ export class ApiClient { }); return { data: res.data, - headers: res.headers + headers: res.headers, + status: res.status, }; } @@ -70,7 +71,8 @@ export class ApiClient { const response = await this.axiosInstance.post(path, body, {headers}); return { data: response.data, - headers: response.headers + headers: response.headers, + status: response.status, }; } @@ -82,6 +84,7 @@ export class ApiClient { return { data: res.data, headers: res.headers, + status: res.status, }; } @@ -92,7 +95,8 @@ export class ApiClient { })); return { data: res.data, - headers: res.headers + headers: res.headers, + status: res.status, }; } @@ -103,7 +107,8 @@ export class ApiClient { })); return { data: res.data, - headers: res.headers + headers: res.headers, + status: res.status, }; } } diff --git a/src/types.ts b/src/types.ts index 2fc67417..7da3d037 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,6 +9,7 @@ export type APIResponseHeaders = AxiosResponseHeaders & {"x-request-id"?: string export interface APIResponse { data: T; + status?: number; headers?: APIResponseHeaders; } From ecf96e386f1739b9a02491db57cac5995ad50a60 Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Fri, 10 Feb 2023 17:17:28 +0200 Subject: [PATCH 04/11] feat: remove deprecated methods BREAKING CHANGE: getVaultAccounts, getVaultAccount, getExchangeAccount methods were removed and replaced by getVaultAccountsWithPageInfo, getVaultAccountById, getExchangeAccountById - check the migration guide in README.md --- README.md | 5 +++++ src/fireblocks-sdk.ts | 28 ---------------------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 254e2268..318a0760 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,11 @@ Using v4 you can now use the response header `x-request-id` which correlates the You can provide the value of this header in case you have support tickets related to an API operation, or a Github issue. +### Removed deprecated methods +- `getVaultAccounts` method was removed. It is replaced by the `getVaultAccountsWithPageInfo` method +- `getVaultAccount` method was removed. It is replaced by the `getVaultAccountById` method +- `getExchangeAccount` was removed in favour of `getExchangeAccountById` + ## Usage #### Before You Begin Make sure you have the credentials for Fireblocks API Services. Otherwise, please contact Fireblocks support for further instructions on how to obtain your API credentials. diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index 0dc40ff7..4bdce3de 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -116,16 +116,6 @@ export class FireblocksSDK { public async getSupportedAssets(): Promise> { return await this.apiClient.issueGetRequest("/v1/supported_assets"); } - - /** - * @deprecated this method is deprecated and will be removed in the future. Please use getVaultAccountsWithPageInfo instead. - * Gets all vault accounts for your tenant - */ - public async getVaultAccounts(filter?: VaultAccountsFilter): Promise> { - const url = `/v1/vault/accounts?${queryString.stringify(filter)}`; - return await this.apiClient.issueGetRequest(url); - } - /** * Gets a list of vault accounts per page matching the given filter or path * @param pagedVaultAccountsRequestFilters Filters for the first request @@ -133,16 +123,6 @@ export class FireblocksSDK { public async getVaultAccountsWithPageInfo(pagedVaultAccountsRequestFilters: PagedVaultAccountsRequestFilters): Promise> { return await this.apiClient.issueGetRequest(`/v1/vault/accounts_paged?${queryString.stringify(pagedVaultAccountsRequestFilters)}`); } - - /** - * @deprecated Replaced by getVaultAccountById. - * Gets a single vault account - * @param vaultAccountId The vault account ID - */ - public async getVaultAccount(vaultAccountId: string): Promise> { - return await this.getVaultAccountById(vaultAccountId); - } - /** * Gets a single vault account * @param vaultAccountId The vault account ID @@ -327,14 +307,6 @@ export class FireblocksSDK { return await this.apiClient.issueGetRequest("/v1/exchange_accounts"); } - /** - * @deprecated Replaced by getExchangeAccountById - * Gets a single exchange account by ID - * @param exchangeAccountId The exchange account ID - */ - public async getExchangeAccount(exchangeAccountId: string): Promise> { - return await this.getExchangeAccount(exchangeAccountId); - } /** * Gets a single exchange account by ID From 9ccdccb64d4b3951297e5d7465173303da8fca1a Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Fri, 10 Feb 2023 17:20:07 +0200 Subject: [PATCH 05/11] add status to readme under APIResponse type --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 318a0760..4cfde0d8 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ In v4 we changed all the sdk response types to return the `APIResponse` object, ```ts export interface APIResponse { data: T; // http response body + status?: number; // http status code headers?: AxiosResponseHeaders; // http response headers } ``` From 6d0691589361155df0f651440cfb290469f461b2 Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Fri, 10 Feb 2023 17:21:32 +0200 Subject: [PATCH 06/11] fix headers in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cfde0d8..e78b66b8 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ const exchangeAccounts: ExchangeResponse = await sdk.getExchangeAccount(exchange It should be transformed to: ```ts -const {data: exchangeAccounts, responseHeaders: headers} = (await sdk.getExchangeAccount(exchangeAccountId)); +const {data: exchangeAccounts, headers} = (await sdk.getExchangeAccount(exchangeAccountId)); ``` ### `X-REQUEST-ID` Response Header From 7c8ee6f40fda1379c27f3589a9c2b0bca5522f9c Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Fri, 10 Feb 2023 17:28:31 +0200 Subject: [PATCH 07/11] support and maintenance for nodejs 12 + --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e78b66b8..81c16588 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ You can provide the value of this header in case you have support tickets relate Make sure you have the credentials for Fireblocks API Services. Otherwise, please contact Fireblocks support for further instructions on how to obtain your API credentials. #### Requirements -- [node.js](https://nodejs.org) v6.3.1 or newer +- [node.js](https://nodejs.org) v12 or newer #### Installation `npm install fireblocks-sdk --save` From cbd227999e474c70e664abdc0d5687f77c9ac0f4 Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Tue, 14 Feb 2023 18:13:48 +0200 Subject: [PATCH 08/11] add support for axios response interceptor --- README.md | 45 +++++--- src/api-client.ts | 69 +++++------- src/fireblocks-sdk.ts | 236 ++++++++++++++++++++++-------------------- src/types.ts | 6 -- 4 files changed, 174 insertions(+), 182 deletions(-) diff --git a/README.md b/README.md index 81c16588..f50efcb9 100644 --- a/README.md +++ b/README.md @@ -6,29 +6,40 @@ This repository contains the official Javascript & Typescript SDK for Fireblocks For the complete API reference, go to [API reference](https://docs.fireblocks.com/api/swagger-ui/). ## V4 Migration -In v4 we changed all the sdk response types to return the `APIResponse` object, which is defined as: -```ts -export interface APIResponse { - data: T; // http response body - status?: number; // http status code - headers?: AxiosResponseHeaders; // http response headers -} -``` +### `X-REQUEST-ID` Response Header +Using v4 you can now use the response header `x-request-id` which correlates the request to the Fireblocks operation. -This means that if you previously fetched data in the following way: -```ts -const exchangeAccounts: ExchangeResponse = await sdk.getExchangeAccount(exchangeAccountId); -``` +You can provide the value of this header in case you have support tickets related to an API operation, or a Github issue. -It should be transformed to: +In case of API request failures the SDK throws an AxiosError that contains the following fields: ```ts -const {data: exchangeAccounts, headers} = (await sdk.getExchangeAccount(exchangeAccountId)); + error.response.data; // the error body + error.response.status; // the error status code + error.response.headers; // the error headers ``` -### `X-REQUEST-ID` Response Header -Using v4 you can now use the response header `x-request-id` which correlates the request to the Fireblocks operation. +- You can get the request-id by using the `error.response.headers['x-request-id']` field +- Another way of getting the request-id for successful operations as well, will be to provide an axios response interceptor -You can provide the value of this header in case you have support tickets related to an API operation, or a Github issue. +For example, you can provide the sdk options with an axios response interceptor: +```ts +new FireblocksSDK(privateKey, userId, serverAddress, undefined, { + customAxiosOptions: { + interceptors: { + response: { + onFulfilled: (response) => { + console.log(`Request ID: ${response.headers["x-request-id"]}`); + return response; + }, + onRejected: (error) => { + console.log(`Request ID: ${error.response.headers["x-request-id"]}`); + throw error; + } + } + } + } + }); +``` ### Removed deprecated methods - `getVaultAccounts` method was removed. It is replaced by the `getVaultAccountsWithPageInfo` method diff --git a/src/api-client.ts b/src/api-client.ts index 0cb82d3d..c32608a5 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -1,7 +1,7 @@ import os from "os"; import platform from "platform"; import { IAuthProvider } from "./iauth-provider"; -import { APIResponse, RequestOptions, TransactionPageResponse } from "./types"; +import { RequestOptions, TransactionPageResponse } from "./types"; import { SDKOptions } from "./fireblocks-sdk"; import axios, { AxiosInstance } from "axios"; import { version as SDK_VERSION } from "../package.json"; @@ -19,6 +19,10 @@ export class ApiClient { "User-Agent": this.getUserAgent() } }); + + if (options.customAxiosOptions?.interceptors?.response) { + this.axiosInstance.interceptors.response.use(options.customAxiosOptions.interceptors.response.onFulfilled, options.customAxiosOptions.interceptors.response.onRejected); + } } private getUserAgent(): string { @@ -32,83 +36,60 @@ export class ApiClient { return userAgent; } - public async issueGetRequestForTransactionPages(path: string): Promise> { + public async issueGetRequestForTransactionPages(path: string): Promise { const token = this.authProvider.signJwt(path); const res = await this.axiosInstance.get(path, { headers: {"Authorization": `Bearer ${token}`} }); return { - data: { - transactions: res.data, - pageDetails: { - prevPage: res.headers["prev-page"] ? res.headers["prev-page"].toString() : "", - nextPage: res.headers["next-page"] ? res.headers["next-page"].toString() : "", - } - }, - headers: res.headers + transactions: res.data, + pageDetails: { + prevPage: res.headers["prev-page"] ? res.headers["prev-page"].toString() : "", + nextPage: res.headers["next-page"] ? res.headers["next-page"].toString() : "", + } }; } - public async issueGetRequest(path: string): Promise> { + public async issueGetRequest(path: string): Promise { const token = this.authProvider.signJwt(path); const res = await this.axiosInstance.get(path, { headers: {"Authorization": `Bearer ${token}`} }); - return { - data: res.data, - headers: res.headers, - status: res.status, - }; + return res.data; } - public async issuePostRequest(path: string, body: any, requestOptions?: RequestOptions): Promise> { + public async issuePostRequest(path: string, body: any, requestOptions?: RequestOptions): Promise { const token = this.authProvider.signJwt(path, body); const headers: any = {"Authorization": `Bearer ${token}`}; const idempotencyKey = requestOptions?.idempotencyKey; if (idempotencyKey) { headers["Idempotency-Key"] = idempotencyKey; } - const response = await this.axiosInstance.post(path, body, {headers}); - return { - data: response.data, - headers: response.headers, - status: response.status, - }; + const response = await this.axiosInstance.post(path, body, {headers}); + return response.data; } - public async issuePutRequest(path: string, body: any): Promise> { + public async issuePutRequest(path: string, body: any): Promise { const token = this.authProvider.signJwt(path, body); - const res = (await this.axiosInstance.put(path, body, { + const res = (await this.axiosInstance.put(path, body, { headers: {"Authorization": `Bearer ${token}`} })); - return { - data: res.data, - headers: res.headers, - status: res.status, - }; + return res.data; } - public async issuePatchRequest(path: string, body: any): Promise> { + public async issuePatchRequest(path: string, body: any): Promise { const token = this.authProvider.signJwt(path, body); - const res = (await this.axiosInstance.patch(path, body, { + const res = (await this.axiosInstance.patch(path, body, { headers: {"Authorization": `Bearer ${token}`} })); - return { - data: res.data, - headers: res.headers, - status: res.status, - }; + return res.data; } - public async issueDeleteRequest(path: string): Promise> { + public async issueDeleteRequest(path: string): Promise { const token = this.authProvider.signJwt(path); - const res = (await this.axiosInstance.delete(path, { + const res = (await this.axiosInstance.delete(path, { headers: {"Authorization": `Bearer ${token}`} })); - return { - data: res.data, - headers: res.headers, - status: res.status, - }; + return res.data; } } diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index 4bdce3de..ee65965f 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -10,14 +10,11 @@ import { CancelTransactionResponse, ConvertExchangeAssetResponse, CreateTransactionResponse, - CreateTransferTicketArgs, - CreateTransferTicketResponse, DeallocateFundsRequest, DepositAddressResponse, EstimateFeeResponse, EstimateTransactionFeeResponse, ExchangeResponse, - ExecuteTermArgs, ExternalWalletAsset, FiatAccountResponse, GasStationInfo, @@ -33,17 +30,14 @@ import { PublicKeyInfoForVaultAccountArgs, RequestOptions, ResendWebhooksResponse, - TermResponse, TransactionArguments, TransactionFilter, TransactionPageFilter, TransactionPageResponse, TransactionResponse, - TransferTicketResponse, User, ValidateAddressResponse, VaultAccountResponse, - VaultAccountsFilter, VaultAssetResponse, VaultBalancesFilter, WalletContainerResponse, @@ -67,9 +61,9 @@ import { PublicKeyResponse, AllocateFundsResponse, GetNFTsFilter, - SettleOffExchangeAccountResponse, APIResponse, PublicKeyInformation, DropTransactionResponse, + SettleOffExchangeAccountResponse, PublicKeyInformation, DropTransactionResponse, } from "./types"; -import { AxiosProxyConfig } from "axios"; +import { AxiosInterceptorOptions, AxiosProxyConfig, AxiosResponse } from "axios"; export * from "./types"; @@ -85,6 +79,18 @@ export interface SDKOptions { /** Additional product identifier to be prepended to the User-Agent header */ userAgent?: string; + + /** + * Providing custom axios options including a response interceptor (https://axios-http.com/docs/interceptors) + */ + customAxiosOptions?: { + interceptors?: { + response?: { + onFulfilled: (value: AxiosResponse) => AxiosResponse | Promise>; + onRejected: (error: any) => any; + }; + } + }; } export class FireblocksSDK { @@ -113,21 +119,21 @@ export class FireblocksSDK { /** * Gets all assets that are currently supported by Fireblocks */ - public async getSupportedAssets(): Promise> { + public async getSupportedAssets(): Promise { return await this.apiClient.issueGetRequest("/v1/supported_assets"); } /** * Gets a list of vault accounts per page matching the given filter or path * @param pagedVaultAccountsRequestFilters Filters for the first request */ - public async getVaultAccountsWithPageInfo(pagedVaultAccountsRequestFilters: PagedVaultAccountsRequestFilters): Promise> { + public async getVaultAccountsWithPageInfo(pagedVaultAccountsRequestFilters: PagedVaultAccountsRequestFilters): Promise { return await this.apiClient.issueGetRequest(`/v1/vault/accounts_paged?${queryString.stringify(pagedVaultAccountsRequestFilters)}`); } /** * Gets a single vault account * @param vaultAccountId The vault account ID */ - public async getVaultAccountById(vaultAccountId: string): Promise> { + public async getVaultAccountById(vaultAccountId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}`); } @@ -136,7 +142,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param assetId The ID of the asset to get */ - public async getVaultAccountAsset(vaultAccountId: string, assetId: string): Promise> { + public async getVaultAccountAsset(vaultAccountId: string, assetId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`); } @@ -146,7 +152,7 @@ export class FireblocksSDK { * @param assetId The ID of the asset to get * @param requestOptions */ - public async refreshVaultAssetBalance(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise> { + public async refreshVaultAssetBalance(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/balance`, "{}", requestOptions); } @@ -155,7 +161,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param assetId The ID of the asset for which to get the deposit address */ - public async getDepositAddresses(vaultAccountId: string, assetId: string): Promise> { + public async getDepositAddresses(vaultAccountId: string, assetId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`); } @@ -164,7 +170,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param assetId The ID of the asset for which to get the utxo list */ - public async getUnspentInputs(vaultAccountId: string, assetId: string): Promise> { + public async getUnspentInputs(vaultAccountId: string, assetId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/unspent_inputs`); } @@ -176,7 +182,7 @@ export class FireblocksSDK { * @param customerRefId A customer reference ID * @param requestOptions */ - public async generateNewAddress(vaultAccountId: string, assetId: string, description?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { + public async generateNewAddress(vaultAccountId: string, assetId: string, description?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`, { description, customerRefId @@ -191,7 +197,7 @@ export class FireblocksSDK { * @param tag The XRP tag, or EOS memo, for which to set the description * @param description The description to set */ - public async setAddressDescription(vaultAccountId: string, assetId: string, address: string, tag?: string, description?: string): Promise> { + public async setAddressDescription(vaultAccountId: string, assetId: string, address: string, tag?: string, description?: string): Promise { let addressId = address; if (tag && tag.length > 0) { addressId = `${address}:${tag}`; @@ -206,7 +212,7 @@ export class FireblocksSDK { * Gets all network connections * @returns NetworkConnectionResponse */ - public async getNetworkConnections(): Promise> { + public async getNetworkConnections(): Promise { return await this.apiClient.issueGetRequest("/v1/network_connections"); } @@ -217,7 +223,7 @@ export class FireblocksSDK { * @param routingPolicy The desired routing policy for the connection * @returns NetworkConnectionResponse */ - public async createNetworkConnection(localNetworkId: string, remoteNetworkId: string, routingPolicy?: NetworkConnectionRoutingPolicy): Promise> { + public async createNetworkConnection(localNetworkId: string, remoteNetworkId: string, routingPolicy?: NetworkConnectionRoutingPolicy): Promise { const body = { localNetworkId, remoteNetworkId, routingPolicy }; return await this.apiClient.issuePostRequest(`/v1/network_connections`, body); } @@ -227,7 +233,7 @@ export class FireblocksSDK { * @param connectionId The network connection's id * @returns NetworkConnectionResponse */ - public async getNetworkConnectionById(connectionId: string): Promise> { + public async getNetworkConnectionById(connectionId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/network_connections/${connectionId}`); } @@ -236,7 +242,7 @@ export class FireblocksSDK { * @param connectionId The network connection's id * @returns OperationSuccessResponse */ - public async removeNetworkConnection(connectionId: string): Promise> { + public async removeNetworkConnection(connectionId: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/network_connections/${connectionId}`); } @@ -245,7 +251,7 @@ export class FireblocksSDK { * @param connectionId The network connection's id * @param routingPolicy The desired routing policy */ - public async setNetworkConnectionRoutingPolicy(connectionId: string, routingPolicy: NetworkConnectionRoutingPolicy): Promise> { + public async setNetworkConnectionRoutingPolicy(connectionId: string, routingPolicy: NetworkConnectionRoutingPolicy): Promise { const body = { routingPolicy }; return await this.apiClient.issuePatchRequest(`/v1/network_connections/${connectionId}/set_routing_policy`, body); } @@ -254,7 +260,7 @@ export class FireblocksSDK { * Gets all discoverable network profiles * @returns NetworkIdResponse */ - public async getDiscoverableNetworkIds(): Promise> { + public async getDiscoverableNetworkIds(): Promise { return await this.apiClient.issueGetRequest(`/v1/network_ids`); } @@ -264,7 +270,7 @@ export class FireblocksSDK { * @param routingPolicy The desired routing policy for the network * @returns NetworkConnectionResponse */ - public async createNetworkId(name: string, routingPolicy?: NetworkIdRoutingPolicy): Promise> { + public async createNetworkId(name: string, routingPolicy?: NetworkIdRoutingPolicy): Promise { const body = { name, routingPolicy }; return await this.apiClient.issuePostRequest(`/v1/network_ids`, body); } @@ -274,7 +280,7 @@ export class FireblocksSDK { * @param networkId The network profile's id * @returns NetworkIdResponse */ - public async getNetworkId(networkId: string): Promise> { + public async getNetworkId(networkId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/network_ids/${networkId}`); } @@ -284,7 +290,7 @@ export class FireblocksSDK { * @param isDiscoverable The desired discoverability to set * @returns OperationSuccessResponse */ - public async setNetworkIdDiscoverability(networkId: string, isDiscoverable: boolean): Promise> { + public async setNetworkIdDiscoverability(networkId: string, isDiscoverable: boolean): Promise { const body = { isDiscoverable }; return await this.apiClient.issuePatchRequest(`/v1/network_ids/${networkId}/set_discoverability`, body); } @@ -295,7 +301,7 @@ export class FireblocksSDK { * @param routingPolicy The desired routing policy * @returns OperationSuccessResponse */ - public async setNetworkIdRoutingPolicy(networkId: string, routingPolicy: NetworkIdRoutingPolicy): Promise> { + public async setNetworkIdRoutingPolicy(networkId: string, routingPolicy: NetworkIdRoutingPolicy): Promise { const body = { routingPolicy }; return await this.apiClient.issuePatchRequest(`/v1/network_ids/${networkId}/set_routing_policy`, body); } @@ -303,7 +309,7 @@ export class FireblocksSDK { /** * Gets all exchange accounts for your tenant */ - public async getExchangeAccounts(): Promise> { + public async getExchangeAccounts(): Promise { return await this.apiClient.issueGetRequest("/v1/exchange_accounts"); } @@ -312,7 +318,7 @@ export class FireblocksSDK { * Gets a single exchange account by ID * @param exchangeAccountId The exchange account ID */ - public async getExchangeAccountById(exchangeAccountId: string): Promise> { + public async getExchangeAccountById(exchangeAccountId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/exchange_accounts/${exchangeAccountId}`); } @@ -321,7 +327,7 @@ export class FireblocksSDK { * @param exchangeAccountId The exchange account ID * @param assetId The ID of the asset */ - public async getExchangeAsset(exchangeAccountId: string, assetId: string): Promise> { + public async getExchangeAsset(exchangeAccountId: string, assetId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/exchange_accounts/${exchangeAccountId}/${assetId}`); } @@ -332,7 +338,7 @@ export class FireblocksSDK { * @param destAsset The destination asset to convert to * @param amount The amount to convert */ - public async convertExchangeAsset(exchangeAccountId: string, srcAsset: string, destAsset: string, amount: number, requestOptions?: RequestOptions): Promise> { + public async convertExchangeAsset(exchangeAccountId: string, srcAsset: string, destAsset: string, amount: number, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/exchange_accounts/${exchangeAccountId}/convert`, { srcAsset, destAsset, amount }, requestOptions); @@ -346,7 +352,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async transferToSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise> { + public async transferToSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise { const body = { subaccountId, amount @@ -363,7 +369,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async transferFromSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise> { + public async transferFromSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number, requestOptions?: RequestOptions): Promise { const body = { subaccountId, amount @@ -375,7 +381,7 @@ export class FireblocksSDK { /** * Gets all fiat accounts for your tenant */ - public async getFiatAccounts(): Promise> { + public async getFiatAccounts(): Promise { return await this.apiClient.issueGetRequest("/v1/fiat_accounts"); } @@ -383,7 +389,7 @@ export class FireblocksSDK { * Gets a single fiat account by ID * @param accountId The fiat account ID */ - public async getFiatAccountById(accountId: string): Promise> { + public async getFiatAccountById(accountId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/fiat_accounts/${accountId}`); } @@ -393,7 +399,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async redeemToLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise> { + public async redeemToLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise { const body = { amount }; @@ -407,7 +413,7 @@ export class FireblocksSDK { * @param amount The amount to transfer * @param requestOptions */ - public async depositFromLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise> { + public async depositFromLinkedDDA(accountId: string, amount: number, requestOptions?: RequestOptions): Promise { const body = { amount }; @@ -423,7 +429,7 @@ export class FireblocksSDK { * @param filter.limit Limit the amount of returned results. If not specified, a limit of 200 results will be used * @param filter.orderBy Determines the order of the results */ - public async getTransactions(filter: TransactionFilter): Promise> { + public async getTransactions(filter: TransactionFilter): Promise { return await this.apiClient.issueGetRequest(`/v1/transactions?${queryString.stringify(filter)}`); } @@ -432,7 +438,7 @@ export class FireblocksSDK { * @param pageFilter Get transactions matching pageFilter params * @param nextOrPreviousPath Get transactions from each of pageDetails paths */ - public async getTransactionsWithPageInfo(pageFilter?: TransactionPageFilter, nextOrPreviousPath?: string): Promise> { + public async getTransactionsWithPageInfo(pageFilter?: TransactionPageFilter, nextOrPreviousPath?: string): Promise { if (pageFilter) { return await this.apiClient.issueGetRequestForTransactionPages(`/v1/transactions?${queryString.stringify(pageFilter)}`); } else if (nextOrPreviousPath) { @@ -442,7 +448,7 @@ export class FireblocksSDK { } return { - data: {transactions: [], pageDetails: { prevPage: "", nextPage: "" }}, + transactions: [], pageDetails: { prevPage: "", nextPage: "" }, }; } @@ -450,14 +456,14 @@ export class FireblocksSDK { * Gets a transaction matching the external transaction id provided * @param externalTxId */ - public async getTransactionByExternalTxId(externalTxId: string): Promise> { + public async getTransactionByExternalTxId(externalTxId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/transactions/external_tx_id/${externalTxId}`); } /** * Gets all internal wallets for your tenant */ - public async getInternalWallets(): Promise[]>> { + public async getInternalWallets(): Promise[]> { return await this.apiClient.issueGetRequest("/v1/internal_wallets"); } @@ -465,7 +471,7 @@ export class FireblocksSDK { * Gets a single internal wallet * @param walletId The internal wallet ID */ - public async getInternalWallet(walletId: string): Promise>> { + public async getInternalWallet(walletId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/internal_wallets/${walletId}`); } @@ -474,14 +480,14 @@ export class FireblocksSDK { * @param walletId The internal wallet ID * @param assetId The asset ID */ - public async getInternalWalletAsset(walletId: string, assetId: string): Promise> { + public async getInternalWalletAsset(walletId: string, assetId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/internal_wallets/${walletId}/${assetId}`); } /** * Gets all external wallets for your tenant */ - public async getExternalWallets(): Promise[]>> { + public async getExternalWallets(): Promise[]> { return await this.apiClient.issueGetRequest("/v1/external_wallets"); } @@ -489,7 +495,7 @@ export class FireblocksSDK { * Gets a single external wallet * @param walletId The external wallet ID */ - public async getExternalWallet(walletId: string): Promise>> { + public async getExternalWallet(walletId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/external_wallets/${walletId}`); } @@ -498,14 +504,14 @@ export class FireblocksSDK { * @param walletId The external wallet ID * @param assetId The asset ID */ - public async getExternalWalletAsset(walletId: string, assetId: string): Promise> { + public async getExternalWalletAsset(walletId: string, assetId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/external_wallets/${walletId}/${assetId}`); } /** * Gets all contract wallets for your tenant */ - public async getContractWallets(): Promise[]>> { + public async getContractWallets(): Promise[]> { return await this.apiClient.issueGetRequest("/v1/contracts"); } @@ -513,7 +519,7 @@ export class FireblocksSDK { * Gets a single contract wallet * @param walletId The contract wallet ID */ - public async getContractWallet(walletId: string): Promise>> { + public async getContractWallet(walletId: string): Promise> { return await this.apiClient.issueGetRequest(`/v1/contracts/${walletId}`); } @@ -522,7 +528,7 @@ export class FireblocksSDK { * @param walletId The contract wallet ID * @param assetId The asset ID */ - public async getContractWalletAsset(walletId: string, assetId: string): Promise> { + public async getContractWalletAsset(walletId: string, assetId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/contracts/${walletId}/${assetId}`); } @@ -530,7 +536,7 @@ export class FireblocksSDK { * Gets detailed information for a single transaction * @param txId The transaction id to query */ - public async getTransactionById(txId: string): Promise> { + public async getTransactionById(txId: string): Promise { return await this.apiClient.issueGetRequest(`/v1/transactions/${txId}`); } @@ -539,7 +545,7 @@ export class FireblocksSDK { * @param txId The transaction id to cancel * @param requestOptions */ - public async cancelTransactionById(txId: string, requestOptions?: RequestOptions): Promise> { + public async cancelTransactionById(txId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/transactions/${txId}/cancel`, {}, requestOptions); } @@ -553,7 +559,7 @@ export class FireblocksSDK { * @param autoFuel * @param requestOptions */ - public async createVaultAccount(name: string, hiddenOnUI?: boolean, customerRefId?: string, autoFuel?: boolean, requestOptions?: RequestOptions): Promise> { + public async createVaultAccount(name: string, hiddenOnUI?: boolean, customerRefId?: string, autoFuel?: boolean, requestOptions?: RequestOptions): Promise { const body = { name, customerRefId, @@ -569,7 +575,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param requestOptions */ - public async hideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise> { + public async hideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/hide`, {}, requestOptions); } @@ -578,7 +584,7 @@ export class FireblocksSDK { * @param vaultAccountId The vault account ID * @param requestOptions */ - public async unhideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise> { + public async unhideVaultAccount(vaultAccountId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/unhide`, {}, requestOptions); } @@ -588,7 +594,7 @@ export class FireblocksSDK { * @param autoFuel The new value for the autoFuel flag * @param requestOptions */ - public async setAutoFuel(vaultAccountId: string, autoFuel: boolean, requestOptions?: RequestOptions): Promise> { + public async setAutoFuel(vaultAccountId: string, autoFuel: boolean, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/set_auto_fuel`, {autoFuel}, requestOptions); } @@ -597,7 +603,7 @@ export class FireblocksSDK { * @param vaultAccountId * @param name A new name for the vault account */ - public async updateVaultAccount(vaultAccountId: string, name: string): Promise> { + public async updateVaultAccount(vaultAccountId: string, name: string): Promise { const body = { name: name }; @@ -611,7 +617,7 @@ export class FireblocksSDK { * @param assetId The asset to add * @param requestOptions */ - public async createVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise> { + public async createVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`, {}, requestOptions); } @@ -621,7 +627,7 @@ export class FireblocksSDK { * @param assetId The asset to add * @param requestOptions */ - public async activateVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise> { + public async activateVaultAsset(vaultAccountId: string, assetId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/activate`, {} , requestOptions); } @@ -631,7 +637,7 @@ export class FireblocksSDK { * @param customerRefId A customer reference ID * @param requestOptions */ - public async createExternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise>> { + public async createExternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { const body = { name, customerRefId @@ -646,7 +652,7 @@ export class FireblocksSDK { * @param customerRefId A customer reference ID * @param requestOptions */ - public async createInternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise>> { + public async createInternalWallet(name: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { const body = { name, customerRefId @@ -659,7 +665,7 @@ export class FireblocksSDK { * Creates a new contract wallet * @param name A name for the new contract wallet */ - public async createContractWallet(name: string, requestOptions?: RequestOptions): Promise>> { + public async createContractWallet(name: string, requestOptions?: RequestOptions): Promise> { const body = { name, }; @@ -675,7 +681,7 @@ export class FireblocksSDK { * @param tag (for ripple only) The ripple account tag * @param requestOptions */ - public async createExternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise> { + public async createExternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise { const path = `/v1/external_wallets/${walletId}/${assetId}`; const body = { @@ -693,7 +699,7 @@ export class FireblocksSDK { * @param tag (for ripple only) The ripple account tag * @param requestOptions */ - public async createInternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise> { + public async createInternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise { const path = `/v1/internal_wallets/${walletId}/${assetId}`; const body = { @@ -710,7 +716,7 @@ export class FireblocksSDK { * @param address The wallet address * @param tag (for ripple only) The ripple account tag */ - public async createContractWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise> { + public async createContractWalletAsset(walletId: string, assetId: string, address: string, tag?: string, requestOptions?: RequestOptions): Promise { const path = `/v1/contracts/${walletId}/${assetId}`; const body = { @@ -723,21 +729,21 @@ export class FireblocksSDK { /** * Creates a new transaction with the specified options */ - public async createTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise> { + public async createTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest("/v1/transactions", transactionArguments, requestOptions); } /** * Estimates the fee for a transaction request */ - public async estimateFeeForTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise> { + public async estimateFeeForTransaction(transactionArguments: TransactionArguments, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest("/v1/transactions/estimate_fee", transactionArguments, requestOptions); } /** * Gets the estimated fees for an asset */ - public async getFeeForAsset(asset: string): Promise> { + public async getFeeForAsset(asset: string): Promise { return await this.apiClient.issueGetRequest(`/v1/estimate_network_fee?assetId=${asset}`); } @@ -745,7 +751,7 @@ export class FireblocksSDK { * Deletes a single internal wallet * @param walletId The internal wallet ID */ - public async deleteInternalWallet(walletId: string): Promise> { + public async deleteInternalWallet(walletId: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/internal_wallets/${walletId}`); } @@ -754,7 +760,7 @@ export class FireblocksSDK { * @param walletId The internal wallet ID * @param assetId The asset ID */ - public async deleteInternalWalletAsset(walletId: string, assetId: string): Promise> { + public async deleteInternalWalletAsset(walletId: string, assetId: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/internal_wallets/${walletId}/${assetId}`); } @@ -762,7 +768,7 @@ export class FireblocksSDK { * Deletes a single external wallet * @param walletId The external wallet ID */ - public async deleteExternalWallet(walletId: string): Promise> { + public async deleteExternalWallet(walletId: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/external_wallets/${walletId}`); } @@ -771,7 +777,7 @@ export class FireblocksSDK { * @param walletId The external wallet ID * @param assetId The asset ID */ - public async deleteExternalWalletAsset(walletId: string, assetId: string): Promise> { + public async deleteExternalWalletAsset(walletId: string, assetId: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/external_wallets/${walletId}/${assetId}`); } @@ -779,7 +785,7 @@ export class FireblocksSDK { * Deletes a single contract wallet * @param walletId The contract wallet ID */ - public async deleteContractWallet(walletId: string): Promise> { + public async deleteContractWallet(walletId: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/contracts/${walletId}`); } @@ -788,7 +794,7 @@ export class FireblocksSDK { * @param walletId The contract wallet ID * @param assetId The asset ID */ - public async deleteContractWalletAsset(walletId: string, assetId: string): Promise> { + public async deleteContractWalletAsset(walletId: string, assetId: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/contracts/${walletId}/${assetId}`); } @@ -798,7 +804,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForVaultAccount(vaultAccountId: string, customerRefId: string, requestOptions?: RequestOptions): Promise> { + public async setCustomerRefIdForVaultAccount(vaultAccountId: string, customerRefId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/set_customer_ref_id`, {customerRefId}, requestOptions); } @@ -808,7 +814,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForInternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise> { + public async setCustomerRefIdForInternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/internal_wallets/${walletId}/set_customer_ref_id`, {customerRefId}, requestOptions); } @@ -818,7 +824,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForExternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise> { + public async setCustomerRefIdForExternalWallet(walletId: string, customerRefId: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/external_wallets/${walletId}/set_customer_ref_id`, {customerRefId}, requestOptions); } @@ -831,7 +837,7 @@ export class FireblocksSDK { * @param customerRefId The customer reference ID to set * @param requestOptions */ - public async setCustomerRefIdForAddress(vaultAccountId: string, assetId: string, address: string, tag?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise> { + public async setCustomerRefIdForAddress(vaultAccountId: string, assetId: string, address: string, tag?: string, customerRefId?: string, requestOptions?: RequestOptions): Promise { let addressId = address; if (tag && tag.length > 0) { addressId = `${address}:${tag}`; @@ -846,7 +852,7 @@ export class FireblocksSDK { * @param requiredConfirmationsNumber * @param requestOptions */ - public async setConfirmationThresholdForTxId(txId: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise> { + public async setConfirmationThresholdForTxId(txId: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/transactions/${txId}/set_confirmation_threshold`, {numOfConfirmations: requiredConfirmationsNumber}, requestOptions); } @@ -856,7 +862,7 @@ export class FireblocksSDK { * @param requiredConfirmationsNumber * @param requestOptions */ - public async setConfirmationThresholdForTxHash(txHash: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise> { + public async setConfirmationThresholdForTxHash(txHash: string, requiredConfirmationsNumber: number, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/txHash/${txHash}/set_confirmation_threshold`, {numOfConfirmations: requiredConfirmationsNumber}, requestOptions); } @@ -864,7 +870,7 @@ export class FireblocksSDK { * Get the public key information * @param args */ - public async getPublicKeyInfo(args: PublicKeyInfoArgs): Promise> { + public async getPublicKeyInfo(args: PublicKeyInfoArgs): Promise { let url = `/v1/vault/public_key_info`; if (args.algorithm) { url += `?algorithm=${args.algorithm}`; @@ -887,7 +893,7 @@ export class FireblocksSDK { * @param args * @param requestOptions */ - public async allocateFundsToPrivateLedger(vaultAccountId: string, asset: string, args: AllocateFundsRequest, requestOptions?: RequestOptions): Promise> { + public async allocateFundsToPrivateLedger(vaultAccountId: string, asset: string, args: AllocateFundsRequest, requestOptions?: RequestOptions): Promise { const url = `/v1/vault/accounts/${vaultAccountId}/${asset}/lock_allocation`; return await this.apiClient.issuePostRequest(url, args, requestOptions); } @@ -899,7 +905,7 @@ export class FireblocksSDK { * @param args * @param requestOptions */ - public async deallocateFundsFromPrivateLedger(vaultAccountId: string, asset: string, args: DeallocateFundsRequest, requestOptions?: RequestOptions): Promise> { + public async deallocateFundsFromPrivateLedger(vaultAccountId: string, asset: string, args: DeallocateFundsRequest, requestOptions?: RequestOptions): Promise { const url = `/v1/vault/accounts/${vaultAccountId}/${asset}/release_allocation`; return await this.apiClient.issuePostRequest(url, args, requestOptions); } @@ -908,7 +914,7 @@ export class FireblocksSDK { * Get the public key information for a vault account * @param args */ - public async getPublicKeyInfoForVaultAccount(args: PublicKeyInfoForVaultAccountArgs): Promise> { + public async getPublicKeyInfoForVaultAccount(args: PublicKeyInfoForVaultAccountArgs): Promise { let url = `/v1/vault/accounts/${args.vaultAccountId}/${args.assetId}/${args.change}/${args.addressIndex}/public_key_info`; if (args.compressed) { url += `?compressed=${args.compressed}`; @@ -919,7 +925,7 @@ export class FireblocksSDK { /** * Get configuration and status of the Gas Station account */ - public async getGasStationInfo(assetId?: string): Promise> { + public async getGasStationInfo(assetId?: string): Promise { let url = `/v1/gas_station`; if (assetId) { @@ -932,7 +938,7 @@ export class FireblocksSDK { /** * Set configuration of the Gas Station account */ - public async setGasStationConfiguration(gasThreshold: string, gasCap: string, maxGasPrice?: string, assetId?: string): Promise> { + public async setGasStationConfiguration(gasThreshold: string, gasCap: string, maxGasPrice?: string, assetId?: string): Promise { let url = `/v1/gas_station/configuration`; if (assetId) { @@ -947,7 +953,7 @@ export class FireblocksSDK { /** * Drop an ETH based transaction */ - public async dropTransaction(txId: string, feeLevel?: string, requestedFee?: string, requestOptions?: RequestOptions): Promise> { + public async dropTransaction(txId: string, feeLevel?: string, requestedFee?: string, requestOptions?: RequestOptions): Promise { const url = `/v1/transactions/${txId}/drop`; const body = {feeLevel, requestedFee}; @@ -958,7 +964,7 @@ export class FireblocksSDK { /** * Get max spendable amount per asset and vault */ - public async getMaxSpendableAmount(vaultAccountId: string, assetId: string, manualSigning?: Boolean): Promise> { + public async getMaxSpendableAmount(vaultAccountId: string, assetId: string, manualSigning?: Boolean): Promise { let url = `/v1/vault/accounts/${vaultAccountId}/${assetId}/max_spendable_amount`; if (manualSigning) { @@ -971,7 +977,7 @@ export class FireblocksSDK { /** * Get all vault assets balance overview */ - public async getVaultAssetsBalance(filter: VaultBalancesFilter): Promise> { + public async getVaultAssetsBalance(filter: VaultBalancesFilter): Promise { const url = `/v1/vault/assets?${queryString.stringify(filter)}`; return await this.apiClient.issueGetRequest(url); @@ -980,7 +986,7 @@ export class FireblocksSDK { /** * Get vault balance overview per asset */ - public async getVaultBalanceByAsset(assetId: string): Promise> { + public async getVaultBalanceByAsset(assetId: string): Promise { const url = `/v1/vault/assets/${assetId}`; return await this.apiClient.issueGetRequest(url); } @@ -988,7 +994,7 @@ export class FireblocksSDK { /** * Get address validation info */ - public async validateAddress(assetId: string, address: string): Promise> { + public async validateAddress(assetId: string, address: string): Promise { const url = `/v1/transactions/validate_address/${assetId}/${address}`; return await this.apiClient.issueGetRequest(url); } @@ -998,7 +1004,7 @@ export class FireblocksSDK { * @param txId The transaction id to unfreeze * @param requestOptions */ - public async unfreezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise> { + public async unfreezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise { return this.apiClient.issuePostRequest(`/v1/transactions/${txId}/unfreeze`, {}, requestOptions); } @@ -1007,14 +1013,14 @@ export class FireblocksSDK { * @param txId The transaction id to freeze * @param requestOptions */ - public async freezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise> { + public async freezeTransactionById(txId: string, requestOptions?: RequestOptions): Promise { return this.apiClient.issuePostRequest(`/v1/transactions/${txId}/freeze`, {}, requestOptions); } /** * Resend failed webhooks */ - public async resendWebhooks(requestOptions?: RequestOptions): Promise> { + public async resendWebhooks(requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest("/v1/webhooks/resend", {}, requestOptions); } @@ -1025,7 +1031,7 @@ export class FireblocksSDK { * @param resendStatusUpdated If true a webhook will be sent for the status of the transaction * @param requestOptions */ - public async resendTransactionWebhooksById(txId: string, resendCreated?: boolean, resendStatusUpdated?: boolean, requestOptions?: RequestOptions): Promise> { + public async resendTransactionWebhooksById(txId: string, resendCreated?: boolean, resendStatusUpdated?: boolean, requestOptions?: RequestOptions): Promise { const body = { resendCreated, resendStatusUpdated }; return await this.apiClient.issuePostRequest(`/v1/webhooks/resend/${txId}`, body, requestOptions); } @@ -1033,14 +1039,14 @@ export class FireblocksSDK { /** * Gets all Users for your tenant */ - public async getUsers(): Promise> { + public async getUsers(): Promise { return await this.apiClient.issueGetRequest("/v1/users"); } /** * Get off exchange accounts */ - public async getOffExchangeAccounts(): Promise> { + public async getOffExchangeAccounts(): Promise { return await this.apiClient.issueGetRequest(`/v1/off_exchange_accounts`); } @@ -1048,7 +1054,7 @@ export class FireblocksSDK { * Get off exchange account by virtual account id * @param id the ID of the off exchange */ - public async getOffExchangeAccountById(id: string): Promise> { + public async getOffExchangeAccountById(id: string): Promise { return await this.apiClient.issueGetRequest(`/v1/off_exchange_accounts/${id}`); } @@ -1057,7 +1063,7 @@ export class FireblocksSDK { * @param id the ID of the off exchange * @param requestOptions */ - public async settleOffExchangeAccountById(id: string, requestOptions?: RequestOptions): Promise> { + public async settleOffExchangeAccountById(id: string, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/off_exchange_accounts/${id}/settle`, {}, requestOptions); } @@ -1067,7 +1073,7 @@ export class FireblocksSDK { * @param baseAsset * @param requestOptions */ - public async setFeePayerConfiguration(baseAsset: string, feePayerConfiguration: SetFeePayerConfiguration, requestOptions?: RequestOptions): Promise> { + public async setFeePayerConfiguration(baseAsset: string, feePayerConfiguration: SetFeePayerConfiguration, requestOptions?: RequestOptions): Promise { return await this.apiClient.issuePostRequest(`/v1/fee_payer/${baseAsset}`, feePayerConfiguration, requestOptions); } @@ -1075,7 +1081,7 @@ export class FireblocksSDK { * Get Fee Payer Configuration * @param baseAsset */ - public async getFeePayerConfiguration(baseAsset: string): Promise> { + public async getFeePayerConfiguration(baseAsset: string): Promise { return await this.apiClient.issueGetRequest(`/v1/fee_payer/${baseAsset}`); } @@ -1083,7 +1089,7 @@ export class FireblocksSDK { * Delete Fee Payer Configuration * @param baseAsset */ - public async removeFeePayerConfiguration(baseAsset: string): Promise> { + public async removeFeePayerConfiguration(baseAsset: string): Promise { return await this.apiClient.issueDeleteRequest(`/v1/fee_payer/${baseAsset}`); } @@ -1117,7 +1123,7 @@ export class FireblocksSDK { sort, filter, order - }: GetWeb3ConnectionsPayload = {}): Promise>> { + }: GetWeb3ConnectionsPayload = {}): Promise> { const params = new URLSearchParams({ ...(pageCursor && { next: pageCursor }), ...(pageSize && { pageSize: pageSize.toString() }), @@ -1148,8 +1154,8 @@ export class FireblocksSDK { * chainIds: ["ETH", "ETH_TEST"] * } */ - public async createWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, payload: CreateWalletConnectPayload, requestOptions?: RequestOptions): Promise>; - public async createWeb3Connection(type: Web3ConnectionType, payload: CreateWeb3ConnectionPayload, requestOptions?: RequestOptions): Promise> { + public async createWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, payload: CreateWalletConnectPayload, requestOptions?: RequestOptions): Promise; + public async createWeb3Connection(type: Web3ConnectionType, payload: CreateWeb3ConnectionPayload, requestOptions?: RequestOptions): Promise { const path = this.getWeb3ConnectionPath(type); return await this.apiClient.issuePostRequest(path, payload, requestOptions); @@ -1161,8 +1167,8 @@ export class FireblocksSDK { * @param sessionId The ID of the session * @param approve Whether you approve the connection or not */ - public async submitWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string, approve: boolean): Promise>; - public async submitWeb3Connection(type: Web3ConnectionType, sessionId: string, approve: boolean): Promise> { + public async submitWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string, approve: boolean): Promise; + public async submitWeb3Connection(type: Web3ConnectionType, sessionId: string, approve: boolean): Promise { const path = this.getWeb3ConnectionPath(type); return await this.apiClient.issuePutRequest(`${path}/${sessionId}`, {approve}); @@ -1173,8 +1179,8 @@ export class FireblocksSDK { * @param type The type of the connection * @param sessionId The ID of the session */ - public async removeWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string): Promise>; - public async removeWeb3Connection(type: Web3ConnectionType, sessionId: string): Promise> { + public async removeWeb3Connection(type: Web3ConnectionType.WALLET_CONNECT, sessionId: string): Promise; + public async removeWeb3Connection(type: Web3ConnectionType, sessionId: string): Promise { const path = this.getWeb3ConnectionPath(type); return await this.apiClient.issueDeleteRequest(`${path}/${sessionId}`); @@ -1184,7 +1190,7 @@ export class FireblocksSDK { * Gets all audits for selected time period * @param timePeriod */ - public async getAudits(timePeriod?: TimePeriod): Promise> { + public async getAudits(timePeriod?: TimePeriod): Promise { let url = `/v1/audits`; if (timePeriod) { url += `?timePeriod=${timePeriod}`; @@ -1196,7 +1202,7 @@ export class FireblocksSDK { * * @param id */ - public async getNFT(id: string): Promise> { + public async getNFT(id: string): Promise { return await this.apiClient.issueGetRequest(`/v1/nfts/tokens/${id}`); } @@ -1207,7 +1213,7 @@ export class FireblocksSDK { * @param filter.ids * @param filter.order */ - public async getNFTs(filter: GetNFTsFilter): Promise>> { + public async getNFTs(filter: GetNFTsFilter): Promise> { const { pageCursor, pageSize, ids, order } = filter; const queryParams = { pageCursor, @@ -1229,7 +1235,7 @@ export class FireblocksSDK { * @param filter.sort Sort by value * @param filter.order Order value */ - public async getOwnedNFTs(filter?: NFTOwnershipFilter): Promise>> { + public async getOwnedNFTs(filter?: NFTOwnershipFilter): Promise> { let url = "/v1/nfts/ownership/tokens"; if (filter) { const { blockchainDescriptor, vaultAccountIds, collectionIds, ids, pageCursor, pageSize, sort, order } = filter; @@ -1252,7 +1258,7 @@ export class FireblocksSDK { * * @param id */ - public async refreshNFTMetadata(id: string): Promise> { + public async refreshNFTMetadata(id: string): Promise { return await this.apiClient.issuePutRequest(`/v1/nfts/tokens/${id}`, undefined); } @@ -1261,7 +1267,7 @@ export class FireblocksSDK { * @param vaultAccountId * @param blockchainDescriptor */ - public async refreshNFTOwnershipByVault(vaultAccountId: string, blockchainDescriptor: string): Promise> { + public async refreshNFTOwnershipByVault(vaultAccountId: string, blockchainDescriptor: string): Promise { return await this.apiClient.issuePutRequest( `/v1/nfts/ownership/tokens?vaultAccountId=${vaultAccountId}&blockchainDescriptor=${blockchainDescriptor}`, undefined); diff --git a/src/types.ts b/src/types.ts index 7da3d037..b7c1ba12 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,12 +7,6 @@ export interface Web3PagedResponse { export type APIResponseHeaders = AxiosResponseHeaders & {"x-request-id"?: string}; -export interface APIResponse { - data: T; - status?: number; - headers?: APIResponseHeaders; -} - export interface VaultAccountResponse { id: string; name: string; From cab27d06fc64e6269f89470bc1f0b7ce68e0bb2d Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Tue, 14 Feb 2023 18:16:48 +0200 Subject: [PATCH 09/11] add node 18 validation to build CI --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 56478007..da0521ed 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 18.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: From 9de5bdee82217d58e5056654120cc59726806877 Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Thu, 16 Feb 2023 17:35:30 +0200 Subject: [PATCH 10/11] update readme for v4 migration --- README.md | 64 +++++++++++++++++--------------------------- docs/V4-MIGRATION.md | 40 +++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 docs/V4-MIGRATION.md diff --git a/README.md b/README.md index f50efcb9..6e6d34cf 100644 --- a/README.md +++ b/README.md @@ -6,45 +6,7 @@ This repository contains the official Javascript & Typescript SDK for Fireblocks For the complete API reference, go to [API reference](https://docs.fireblocks.com/api/swagger-ui/). ## V4 Migration -### `X-REQUEST-ID` Response Header -Using v4 you can now use the response header `x-request-id` which correlates the request to the Fireblocks operation. - -You can provide the value of this header in case you have support tickets related to an API operation, or a Github issue. - -In case of API request failures the SDK throws an AxiosError that contains the following fields: -```ts - error.response.data; // the error body - error.response.status; // the error status code - error.response.headers; // the error headers -``` - -- You can get the request-id by using the `error.response.headers['x-request-id']` field -- Another way of getting the request-id for successful operations as well, will be to provide an axios response interceptor - -For example, you can provide the sdk options with an axios response interceptor: -```ts -new FireblocksSDK(privateKey, userId, serverAddress, undefined, { - customAxiosOptions: { - interceptors: { - response: { - onFulfilled: (response) => { - console.log(`Request ID: ${response.headers["x-request-id"]}`); - return response; - }, - onRejected: (error) => { - console.log(`Request ID: ${error.response.headers["x-request-id"]}`); - throw error; - } - } - } - } - }); -``` - -### Removed deprecated methods -- `getVaultAccounts` method was removed. It is replaced by the `getVaultAccountsWithPageInfo` method -- `getVaultAccount` method was removed. It is replaced by the `getVaultAccountById` method -- `getExchangeAccount` was removed in favour of `getExchangeAccountById` +Please read the [following](./docs/V4-MIGRATION.md) guide for migration ## Usage #### Before You Begin @@ -95,3 +57,27 @@ interface SDKOptions { userAgent?: string; } ``` + +#### Axios Interceptor +You can provide the sdk options with an [axios response interceptor](https://axios-http.com/docs/interceptors): +```ts +new FireblocksSDK(privateKey, userId, serverAddress, undefined, { + customAxiosOptions: { + interceptors: { + response: { + onFulfilled: (response) => { + console.log(`Request ID: ${response.headers["x-request-id"]}`); + return response; + }, + onRejected: (error) => { + console.log(`Request ID: ${error.response.headers["x-request-id"]}`); + throw error; + } + } + } + } +}); +``` + + + diff --git a/docs/V4-MIGRATION.md b/docs/V4-MIGRATION.md new file mode 100644 index 00000000..90b0c661 --- /dev/null +++ b/docs/V4-MIGRATION.md @@ -0,0 +1,40 @@ +## V4 Migration +### `X-REQUEST-ID` Response Header +Using v4 you can now use the response header `x-request-id` which correlates the request to the Fireblocks operation. + +You can provide the value of this header in case you have support tickets related to an API operation, or a Github issue. + +In case of API request failures the SDK throws an AxiosError that contains the following fields: +```ts + error.response.data; // the error body + error.response.status; // the error status code + error.response.headers; // the error headers +``` + +- You can get the request-id by using the `error.response.headers['x-request-id']` field +- Another way of getting the request-id for successful operations as well, will be to provide an axios response interceptor + +For example, you can provide the sdk options with an axios response interceptor: +```ts +new FireblocksSDK(privateKey, userId, serverAddress, undefined, { + customAxiosOptions: { + interceptors: { + response: { + onFulfilled: (response) => { + console.log(`Request ID: ${response.headers["x-request-id"]}`); + return response; + }, + onRejected: (error) => { + console.log(`Request ID: ${error.response.headers["x-request-id"]}`); + throw error; + } + } + } + } + }); +``` + +### Removed deprecated methods +- `getVaultAccounts` method was removed. It is replaced by the `getVaultAccountsWithPageInfo` method +- `getVaultAccount` method was removed. It is replaced by the `getVaultAccountById` method +- `getExchangeAccount` was removed in favour of `getExchangeAccountById` From 0f27495b953c153bfff22de4d87ad009280992a9 Mon Sep 17 00:00:00 2001 From: Yarin Vaknin Date: Thu, 16 Feb 2023 17:38:59 +0200 Subject: [PATCH 11/11] add error handling section and explanation --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 6e6d34cf..f76c1869 100644 --- a/README.md +++ b/README.md @@ -79,5 +79,17 @@ new FireblocksSDK(privateKey, userId, serverAddress, undefined, { }); ``` +#### Error Handling +The SDK throws `AxiosError` upon http errors for API requests. + +You can read more about axios error handling [here](https://axios-http.com/docs/handling_errors). + +You can get more data on the Fireblocks error using the following fields: + +- `error.response.data.code`: The Fireblocks error code, should be provided on support tickets +- `error.response.data.message`: Explanation of the Fireblocks error +- `error.response.headers['x-request-id']`: The request ID correlated to the API request, should be provided on support tickets / Github issues + +