/* tslint:disable */ /* eslint-disable */ /** * barkd REST API * A simple REST API for barkd, a wallet daemon for integrating bitcoin payments into your app over HTTP. Supports self-custodial Lightning, Ark, and on-chain out of the box. barkd is a long-running daemon best suited for always-on or high-connectivity environments like nodes, servers, desktops, and point-of-sale terminals. All endpoints return JSON. Amounts are denominated in satoshis. * * The version of the OpenAPI document: 0.6.1 * Contact: hello@second.tech * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ import * as runtime from '../runtime'; import type { Address, BadRequestError, InternalServerError, OnchainBalance, OnchainDrainRequest, OnchainSendManyRequest, OnchainSendRequest, Send, UtxoInfo, WalletTxInfo, } from '../models/index'; import { AddressFromJSON, AddressToJSON, BadRequestErrorFromJSON, BadRequestErrorToJSON, InternalServerErrorFromJSON, InternalServerErrorToJSON, OnchainBalanceFromJSON, OnchainBalanceToJSON, OnchainDrainRequestFromJSON, OnchainDrainRequestToJSON, OnchainSendManyRequestFromJSON, OnchainSendManyRequestToJSON, OnchainSendRequestFromJSON, OnchainSendRequestToJSON, SendFromJSON, SendToJSON, UtxoInfoFromJSON, UtxoInfoToJSON, WalletTxInfoFromJSON, WalletTxInfoToJSON, } from '../models/index'; export interface OnchainDrainOperationRequest { onchainDrainRequest: OnchainDrainRequest; } export interface OnchainSendOperationRequest { onchainSendRequest: OnchainSendRequest; } export interface OnchainSendManyOperationRequest { onchainSendManyRequest: OnchainSendManyRequest; } /** * */ export class OnchainApi extends runtime.BaseAPI { /** * Creates request options for onchainAddress without sending the request */ async onchainAddressRequestOpts(): Promise { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/addresses/next`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, }; } /** * Generates a new on-chain receiving address. Each call returns the next unused address from the wallet\'s HD keychain. * Generate on-chain address */ async onchainAddressRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.onchainAddressRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => AddressFromJSON(jsonValue)); } /** * Generates a new on-chain receiving address. Each call returns the next unused address from the wallet\'s HD keychain. * Generate on-chain address */ async onchainAddress(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise
{ const response = await this.onchainAddressRaw(initOverrides); return await response.value(); } /** * Creates request options for onchainBalance without sending the request */ async onchainBalanceRequestOpts(): Promise { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/balance`; return { path: urlPath, method: 'GET', headers: headerParameters, query: queryParameters, }; } /** * Returns the current on-chain wallet balance, broken down by confirmation status. The `trusted_spendable_sat` field is the sum of `confirmed_sat` and `trusted_pending_sat`—the balance that can be safely spent without risk of double-spend. * Get on-chain balance */ async onchainBalanceRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.onchainBalanceRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => OnchainBalanceFromJSON(jsonValue)); } /** * Returns the current on-chain wallet balance, broken down by confirmation status. The `trusted_spendable_sat` field is the sum of `confirmed_sat` and `trusted_pending_sat`—the balance that can be safely spent without risk of double-spend. * Get on-chain balance */ async onchainBalance(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.onchainBalanceRaw(initOverrides); return await response.value(); } /** * Creates request options for onchainDrain without sending the request */ async onchainDrainRequestOpts(requestParameters: OnchainDrainOperationRequest): Promise { if (requestParameters['onchainDrainRequest'] == null) { throw new runtime.RequiredError( 'onchainDrainRequest', 'Required parameter "onchainDrainRequest" was null or undefined when calling onchainDrain().' ); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/drain`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, body: OnchainDrainRequestToJSON(requestParameters['onchainDrainRequest']), }; } /** * Sends the entire on-chain wallet balance to the specified address. The recipient receives the full balance minus transaction fees. Broadcasts immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID. * Drain on-chain wallet */ async onchainDrainRaw(requestParameters: OnchainDrainOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.onchainDrainRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => SendFromJSON(jsonValue)); } /** * Sends the entire on-chain wallet balance to the specified address. The recipient receives the full balance minus transaction fees. Broadcasts immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID. * Drain on-chain wallet */ async onchainDrain(requestParameters: OnchainDrainOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.onchainDrainRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for onchainSend without sending the request */ async onchainSendRequestOpts(requestParameters: OnchainSendOperationRequest): Promise { if (requestParameters['onchainSendRequest'] == null) { throw new runtime.RequiredError( 'onchainSendRequest', 'Required parameter "onchainSendRequest" was null or undefined when calling onchainSend().' ); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/send`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, body: OnchainSendRequestToJSON(requestParameters['onchainSendRequest']), }; } /** * Sends the specified amount to an on-chain address. Broadcasts the transaction immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID. * Send on-chain payment */ async onchainSendRaw(requestParameters: OnchainSendOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.onchainSendRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => SendFromJSON(jsonValue)); } /** * Sends the specified amount to an on-chain address. Broadcasts the transaction immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID. * Send on-chain payment */ async onchainSend(requestParameters: OnchainSendOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.onchainSendRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for onchainSendMany without sending the request */ async onchainSendManyRequestOpts(requestParameters: OnchainSendManyOperationRequest): Promise { if (requestParameters['onchainSendManyRequest'] == null) { throw new runtime.RequiredError( 'onchainSendManyRequest', 'Required parameter "onchainSendManyRequest" was null or undefined when calling onchainSendMany().' ); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/send-many`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, body: OnchainSendManyRequestToJSON(requestParameters['onchainSendManyRequest']), }; } /** * Batches multiple payments into a single on-chain transaction. Each destination is formatted as `address:amount`. Broadcasts the transaction immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID. * Send to multiple addresses */ async onchainSendManyRaw(requestParameters: OnchainSendManyOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.onchainSendManyRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => SendFromJSON(jsonValue)); } /** * Batches multiple payments into a single on-chain transaction. Each destination is formatted as `address:amount`. Broadcasts the transaction immediately at a fee rate targeting confirmation within three blocks and returns the transaction ID. * Send to multiple addresses */ async onchainSendMany(requestParameters: OnchainSendManyOperationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.onchainSendManyRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for onchainSync without sending the request */ async onchainSyncRequestOpts(): Promise { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/sync`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, }; } /** * Syncs the on-chain wallet state with the chain source. Fetches new blocks and transactions, updates the UTXO set, and re-submits any stale unconfirmed transactions to the mempool. * Sync on-chain wallet */ async onchainSyncRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.onchainSyncRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new runtime.VoidApiResponse(response); } /** * Syncs the on-chain wallet state with the chain source. Fetches new blocks and transactions, updates the UTXO set, and re-submits any stale unconfirmed transactions to the mempool. * Sync on-chain wallet */ async onchainSync(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { await this.onchainSyncRaw(initOverrides); } /** * Creates request options for onchainTransactions without sending the request */ async onchainTransactionsRequestOpts(): Promise { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/transactions`; return { path: urlPath, method: 'GET', headers: headerParameters, query: queryParameters, }; } /** * Returns all on-chain wallet transactions, ordered from oldest to newest. Each entry includes the raw transaction, its fee (when known), the wallet\'s net balance change, and confirmation status. The fee is `null` for inbound or collaboratively-funded transactions whose foreign prevouts BDK has not indexed. * List on-chain transactions */ async onchainTransactionsRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>> { const requestOptions = await this.onchainTransactionsRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(WalletTxInfoFromJSON)); } /** * Returns all on-chain wallet transactions, ordered from oldest to newest. Each entry includes the raw transaction, its fee (when known), the wallet\'s net balance change, and confirmation status. The fee is `null` for inbound or collaboratively-funded transactions whose foreign prevouts BDK has not indexed. * List on-chain transactions */ async onchainTransactions(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const response = await this.onchainTransactionsRaw(initOverrides); return await response.value(); } /** * Creates request options for onchainUtxos without sending the request */ async onchainUtxosRequestOpts(): Promise { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } let urlPath = `/api/v1/onchain/utxos`; return { path: urlPath, method: 'GET', headers: headerParameters, query: queryParameters, }; } /** * Returns all UTXOs in the on-chain wallet. Each entry includes the outpoint, amount, and confirmation height (if confirmed). * List on-chain UTXOs */ async onchainUtxosRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>> { const requestOptions = await this.onchainUtxosRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(UtxoInfoFromJSON)); } /** * Returns all UTXOs in the on-chain wallet. Each entry includes the outpoint, amount, and confirmation height (if confirmed). * List on-chain UTXOs */ async onchainUtxos(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const response = await this.onchainUtxosRaw(initOverrides); return await response.value(); } }