Skip to content

Commit

Permalink
Add API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomer Vilensky committed Sep 29, 2019
1 parent b7510cc commit 4efe26c
Showing 1 changed file with 82 additions and 70 deletions.
152 changes: 82 additions & 70 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export class FireblocksSDK {
private apiClient: ApiClient;

/**
* Creates a new Fireblocks API Client.
* @param privateKey A string representation of your private key.
* @param apiKey Your api key. This is a uuid you received from Fireblocks.
* @param apiBaseUrl The fireblocks server URL. Leave empty to use the default server.
* Creates a new Fireblocks API Client
* @param privateKey A string representation of your private key
* @param apiKey Your api key. This is a uuid you received from Fireblocks
* @param apiBaseUrl The fireblocks server URL. Leave empty to use the default server
*/
constructor(privateKey: string, apiKey: string, apiBaseUrl: string = "https://api.fireblocks.io") {
this.authProvider = new ApiTokenProvider(privateKey, apiKey);
Expand All @@ -28,75 +28,87 @@ export class FireblocksSDK {
}

/**
* Gets all assets that are currently supported by Fireblocks.
* Gets all assets that are currently supported by Fireblocks
*/
public async getSupportedAssets(): Promise<VaultAccountResponse[]> {
return await this.apiClient.issueGetRequest("/v1/supported_assets");
}

/**
* Gets all vault accounts for your tenant.
* Gets all vault accounts for your tenant
*/
public async getVaultAccounts(): Promise<VaultAccountResponse[]> {
return await this.apiClient.issueGetRequest("/v1/vault/accounts");
}

/**
* Gets a single vault account.
* @param vaultAccountId The vault account ID.
* Gets a single vault account
* @param vaultAccountId The vault account ID
*/
public async getVaultAccount(vaultAccountId: string): Promise<VaultAccountResponse> {
return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}`);
}

/**
* Gets a single vault account asset.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset to get.
* Gets a single vault account asset
* @param vaultAccountId The vault account ID
* @param assetId The ID of the asset to get
*/
public async getVaultAccountAsset(vaultAccountId: string, assetId: string): Promise<AssetResponse> {
return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`);
}

/**
* Gets deposit addresses for an asset in a vault account.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset for which to get the deposit address.
* Gets deposit addresses for an asset in a vault account
* @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<DepositAddressResponse[]> {
return await this.apiClient.issueGetRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`);
}

/**
* Generates a new address for an asset in a vault account.
* @param vaultAccountId The vault account ID.
* @param assetId The ID of the asset for which to get the deposit address.
* Generates a new address for an asset in a vault account
* @param vaultAccountId The vault account ID
* @param assetId The ID of the asset for which to get the deposit address
*/
public async generateNewAddress(vaultAccountId: string, assetId: string, description?: string): Promise<GenerateAddressResponse> {
return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses`, { description });
}

/**
* Gets all exchange accounts for your tenant.
* Sets the description of an existing address
* @param vaultAccountId The vault account ID
* @param assetId The ID of the asset for which to get the deposit address
* @param address The ID of the asset for which to get the deposit address
* @param tag The ID of the asset for which to get the deposit address
* @param description The description to set
*/
public async setAddressDescription(vaultAccountId: string, assetId: string, address: string, tag?: string, description?: string): Promise<GenerateAddressResponse> {
return await this.apiClient.issuePutRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}/addresses/${address}:${tag || ""}`, { description: description || "" });
}

/**
* Gets all exchange accounts for your tenant
*/
public async getExchangeAccounts(): Promise<ExchangeResponse[]> {
return await this.apiClient.issueGetRequest("/v1/exchange_accounts");
}

/**
* Gets a single exchange account by ID.
* @param exchangeAccountId The exchange account ID.
* Gets a single exchange account by ID
* @param exchangeAccountId The exchange account ID
*/
public async getExchangeAccount(exchangeAccountId: string): Promise<ExchangeResponse> {
return await this.apiClient.issueGetRequest(`/v1/exchange_accounts/${exchangeAccountId}`);
}

/**
* Transfer from a main exchange account to a subaccount.
* @param exchangeAccountId The exchange ID in Fireblocks.
* @param subaccountId The ID of the subaccount in the exchange.
* @param assetId The asset to transfer.
* @param amount The amount to transfer.
* Transfer from a main exchange account to a subaccount
* @param exchangeAccountId The exchange ID in Fireblocks
* @param subaccountId The ID of the subaccount in the exchange
* @param assetId The asset to transfer
* @param amount The amount to transfer
*/
public async transferToSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number): Promise<OperationSuccessResponse> {
const body = {
Expand All @@ -108,11 +120,11 @@ export class FireblocksSDK {
}

/**
* Transfer from a subaccount to a main exchange account.
* @param exchangeAccountId The exchange ID in Fireblocks.
* @param subaccountId The ID of the subaccount in the exchange.
* @param assetId The asset to transfer.
* @param amount The amount to transfer.
* Transfer from a subaccount to a main exchange account
* @param exchangeAccountId The exchange ID in Fireblocks
* @param subaccountId The ID of the subaccount in the exchange
* @param assetId The asset to transfer
* @param amount The amount to transfer
*/
public async transferFromSubaccount(exchangeAccountId: string, subaccountId: string, assetId: string, amount: number): Promise<OperationSuccessResponse> {
const body = {
Expand All @@ -124,82 +136,82 @@ export class FireblocksSDK {
}

/**
* Gets a list of transactions matching the given filter.
* @param filter.before Only gets transactions created before a given timestamp (in seconds).
* @param filter.after Only gets transactions created after a given timestamp (in seconds).
* @param filter.status Only gets transactions with the spcified status.
* Gets a list of transactions matching the given filter
* @param filter.before Only gets transactions created before a given timestamp (in seconds)
* @param filter.after Only gets transactions created after a given timestamp (in seconds)
* @param filter.status Only gets transactions with the spcified status
*/
public async getTransactions(filter: TransactionFilter): Promise<TransactionResponse[]> {
return await this.apiClient.issueGetRequest(`/v1/transactions?${queryString.stringify(filter)}`);
}

/**
* Gets all internal wallets for your tenant.
* Gets all internal wallets for your tenant
*/
public async getInternalWallets(): Promise<WalletContainerResponse[]> {
return await this.apiClient.issueGetRequest("/v1/internal_wallets");
}

/**
* Gets a single internal wallet.
* @param walletId The internal wallet ID.
* Gets a single internal wallet
* @param walletId The internal wallet ID
*/
public async getInternalWallet(walletId: string): Promise<WalletContainerResponse> {
return await this.apiClient.issueGetRequest(`/v1/internal_wallets/${walletId}`);
}

/**
* Gets a single internal wallet asset.
* @param walletId The internal wallet ID.
* @param assetId The asset ID.
* Gets a single internal wallet asset
* @param walletId The internal wallet ID
* @param assetId The asset ID
*/
public async getInternalWalletAsset(walletId: string, assetId: string): Promise<WalletAssetResponse> {
return await this.apiClient.issueGetRequest(`/v1/internal_wallets/${walletId}/${assetId}`);
}

/**
* Gets all external wallets for your tenant.
* Gets all external wallets for your tenant
*/
public async getExternalWallets(): Promise<WalletContainerResponse[]> {
return await this.apiClient.issueGetRequest("/v1/external_wallets");
}

/**
* Gets a single external wallet.
* @param walletId The external wallet ID.
* Gets a single external wallet
* @param walletId The external wallet ID
*/
public async getExternalWallet(walletId: string): Promise<WalletContainerResponse> {
return await this.apiClient.issueGetRequest(`/v1/external_wallets/${walletId}`);
}

/**
* Gets a single external wallet asset.
* @param walletId The external wallet ID.
* @param assetId The asset ID.
* Gets a single external wallet asset
* @param walletId The external wallet ID
* @param assetId The asset ID
*/
public async getExternalWalletAsset(walletId: string, assetId: string): Promise<WalletAssetResponse> {
return await this.apiClient.issueGetRequest(`/v1/external_wallets/${walletId}/${assetId}`);
}

/**
* Gets detailed information for a single transaction.
* @param txId The transaction id to query.
* Gets detailed information for a single transaction
* @param txId The transaction id to query
*/
public async getTransactionById(txId: string): Promise<TransactionResponse> {
return await this.apiClient.issueGetRequest(`/v1/transactions/${txId}`);
}

/**
* Cancels the selected transaction.
* @param txId The transaction id to cancel.
* Cancels the selected transaction
* @param txId The transaction id to cancel
*/
public async cancelTransactionById(txId: string): Promise<CancelTransactionResponse> {
return await this.apiClient.issuePostRequest(`/v1/transactions/${txId}/cancel`, {});
}

/**
* Creates a new vault account.
* @param name A name for the new vault account.
* Creates a new vault account
* @param name A name for the new vault account
*/
public async createVaultAccount(name: string): Promise<VaultAccountResponse> {
const body = {
Expand All @@ -210,8 +222,8 @@ export class FireblocksSDK {
}

/**
* Updates a vault account.
* @param name A new name for the vault account.
* Updates a vault account
* @param name A new name for the vault account
*/
public async updateVaultAccount(vaultAccountId: string, name: string): Promise<VaultAccountResponse> {
const body = {
Expand All @@ -222,9 +234,9 @@ export class FireblocksSDK {
}

/**
* Creates a new asset within an existing vault account.
* @param vaultAccountId The vault account ID.
* @param assetId The asset to add.
* Creates a new asset within an existing vault account
* @param vaultAccountId The vault account ID
* @param assetId The asset to add
*/
public async createVaultAsset(vaultAccountId: string, assetId: string): Promise<AssetResponse> {
return await this.apiClient.issuePostRequest(`/v1/vault/accounts/${vaultAccountId}/${assetId}`, {});
Expand All @@ -239,8 +251,8 @@ export class FireblocksSDK {
}

/**
* Creates a new internal wallet.
* @param name A name for the new internal wallet.
* Creates a new internal wallet
* @param name A name for the new internal wallet
*/
public async createInternalWallet(name: string): Promise<WalletContainerResponse> {
const body = {
Expand All @@ -251,11 +263,11 @@ export class FireblocksSDK {
}

/**
* Creates a new asset within an exiting external wallet.
* @param walletId The wallet id.
* @param assetId The asset to add.
* @param address The wallet address.
* @param tag (for ripple only) The ripple account tag.
* Creates a new asset within an exiting external wallet
* @param walletId The wallet id
* @param assetId The asset to add
* @param address The wallet address
* @param tag (for ripple only) The ripple account tag
*/
public async createExternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string): Promise<WalletAssetResponse> {
const path = `/v1/external_wallets/${walletId}/${assetId}`;
Expand All @@ -268,11 +280,11 @@ export class FireblocksSDK {
}

/**
* Creates a new asset within an exiting internal wallet.
* @param walletId The wallet id.
* @param assetId The asset to add.
* @param address The wallet address.
* @param tag (for ripple only) The ripple account tag.
* Creates a new asset within an exiting internal wallet
* @param walletId The wallet id
* @param assetId The asset to add
* @param address The wallet address
* @param tag (for ripple only) The ripple account tag
*/
public async createInternalWalletAsset(walletId: string, assetId: string, address: string, tag?: string): Promise<WalletAssetResponse> {
const path = `/v1/internal_wallets/${walletId}/${assetId}`;
Expand All @@ -285,7 +297,7 @@ export class FireblocksSDK {
}

/**
* Creates a new transaction with the specified options.
* Creates a new transaction with the specified options
*/
public async createTransaction(options: TransactionArguments): Promise<CreateTransactionResponse> {
return await this.apiClient.issuePostRequest("/v1/transactions", options);
Expand Down

0 comments on commit 4efe26c

Please sign in to comment.