/* 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 { BadRequestError, InternalServerError, InvoiceInfo, LightningInvoiceForAddressRequest, LightningInvoiceRequest, LightningPayRequest, LightningPayResponse, LightningReceiveInfo, NotFoundError, } from '../models/index'; import { BadRequestErrorFromJSON, BadRequestErrorToJSON, InternalServerErrorFromJSON, InternalServerErrorToJSON, InvoiceInfoFromJSON, InvoiceInfoToJSON, LightningInvoiceForAddressRequestFromJSON, LightningInvoiceForAddressRequestToJSON, LightningInvoiceRequestFromJSON, LightningInvoiceRequestToJSON, LightningPayRequestFromJSON, LightningPayRequestToJSON, LightningPayResponseFromJSON, LightningPayResponseToJSON, LightningReceiveInfoFromJSON, LightningReceiveInfoToJSON, NotFoundErrorFromJSON, NotFoundErrorToJSON, } from '../models/index'; export interface CancelReceiveRequest { identifier: string; } export interface GenerateInvoiceRequest { lightningInvoiceRequest: LightningInvoiceRequest; } export interface GenerateInvoiceForAddressRequest { lightningInvoiceForAddressRequest: LightningInvoiceForAddressRequest; } export interface GetReceiveStatusRequest { identifier: string; } export interface PayRequest { lightningPayRequest: LightningPayRequest; } /** * */ export class LightningApi extends runtime.BaseAPI { /** * Creates request options for cancelReceive without sending the request */ async cancelReceiveRequestOpts(requestParameters: CancelReceiveRequest): Promise { if (requestParameters['identifier'] == null) { throw new runtime.RequiredError( 'identifier', 'Required parameter "identifier" was null or undefined when calling cancelReceive().' ); } 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/lightning/receives/{identifier}`; urlPath = urlPath.replace(`{${"identifier"}}`, encodeURIComponent(String(requestParameters['identifier']))); return { path: urlPath, method: 'DELETE', headers: headerParameters, query: queryParameters, }; } /** * Cancels a pending Lightning receive identified by its payment hash or invoice string. The server will refuse cancellation if HTLC-recv VTXOs have already been granted. Bark also prevents cancellation when the preimage has been revealed. * Cancel a pending receive */ async cancelReceiveRaw(requestParameters: CancelReceiveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.cancelReceiveRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.VoidApiResponse(response); } /** * Cancels a pending Lightning receive identified by its payment hash or invoice string. The server will refuse cancellation if HTLC-recv VTXOs have already been granted. Bark also prevents cancellation when the preimage has been revealed. * Cancel a pending receive */ async cancelReceive(requestParameters: CancelReceiveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { await this.cancelReceiveRaw(requestParameters, initOverrides); } /** * Creates request options for generateInvoice without sending the request */ async generateInvoiceRequestOpts(requestParameters: GenerateInvoiceRequest): Promise { if (requestParameters['lightningInvoiceRequest'] == null) { throw new runtime.RequiredError( 'lightningInvoiceRequest', 'Required parameter "lightningInvoiceRequest" was null or undefined when calling generateInvoice().' ); } 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/lightning/receives/invoice`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, body: LightningInvoiceRequestToJSON(requestParameters['lightningInvoiceRequest']), }; } /** * Generates a new BOLT11 invoice for the specified amount via the Ark server, creating a pending Lightning receive. * Create a BOLT11 invoice */ async generateInvoiceRaw(requestParameters: GenerateInvoiceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.generateInvoiceRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => InvoiceInfoFromJSON(jsonValue)); } /** * Generates a new BOLT11 invoice for the specified amount via the Ark server, creating a pending Lightning receive. * Create a BOLT11 invoice */ async generateInvoice(requestParameters: GenerateInvoiceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.generateInvoiceRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for generateInvoiceForAddress without sending the request */ async generateInvoiceForAddressRequestOpts(requestParameters: GenerateInvoiceForAddressRequest): Promise { if (requestParameters['lightningInvoiceForAddressRequest'] == null) { throw new runtime.RequiredError( 'lightningInvoiceForAddressRequest', 'Required parameter "lightningInvoiceForAddressRequest" was null or undefined when calling generateInvoiceForAddress().' ); } 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/lightning/receives/invoice/for-address`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, body: LightningInvoiceForAddressRequestToJSON(requestParameters['lightningInvoiceForAddressRequest']), }; } /** * Generates a new BOLT11 invoice. When paid, the wallet claims the Lightning receive and forwards the resulting Ark VTXO to the supplied Ark address mailbox. * Create a BOLT11 invoice for an Ark address */ async generateInvoiceForAddressRaw(requestParameters: GenerateInvoiceForAddressRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.generateInvoiceForAddressRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => InvoiceInfoFromJSON(jsonValue)); } /** * Generates a new BOLT11 invoice. When paid, the wallet claims the Lightning receive and forwards the resulting Ark VTXO to the supplied Ark address mailbox. * Create a BOLT11 invoice for an Ark address */ async generateInvoiceForAddress(requestParameters: GenerateInvoiceForAddressRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.generateInvoiceForAddressRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for getReceiveStatus without sending the request */ async getReceiveStatusRequestOpts(requestParameters: GetReceiveStatusRequest): Promise { if (requestParameters['identifier'] == null) { throw new runtime.RequiredError( 'identifier', 'Required parameter "identifier" was null or undefined when calling getReceiveStatus().' ); } 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/lightning/receives/{identifier}`; urlPath = urlPath.replace(`{${"identifier"}}`, encodeURIComponent(String(requestParameters['identifier']))); return { path: urlPath, method: 'GET', headers: headerParameters, query: queryParameters, }; } /** * Returns the status of a specified Lightning receive, identified by its payment hash, invoice string, or preimage. The response tracks progress through timestamps: `htlc_vtxos` is populated once HTLCs are created by the Ark server, `preimage_revealed_at` records when the preimage was sent, and `finished_at` indicates the receive has settled or been canceled. * Get receive status */ async getReceiveStatusRaw(requestParameters: GetReceiveStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.getReceiveStatusRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => LightningReceiveInfoFromJSON(jsonValue)); } /** * Returns the status of a specified Lightning receive, identified by its payment hash, invoice string, or preimage. The response tracks progress through timestamps: `htlc_vtxos` is populated once HTLCs are created by the Ark server, `preimage_revealed_at` records when the preimage was sent, and `finished_at` indicates the receive has settled or been canceled. * Get receive status */ async getReceiveStatus(requestParameters: GetReceiveStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.getReceiveStatusRaw(requestParameters, initOverrides); return await response.value(); } /** * Creates request options for listReceiveStatuses without sending the request */ async listReceiveStatusesRequestOpts(): 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/lightning/receives`; return { path: urlPath, method: 'GET', headers: headerParameters, query: queryParameters, }; } /** * Returns the statuses of all pending Lightning receives, ordered from oldest to newest. A receive is pending until its `finished_at` timestamp is set, indicating it has settled or been canceled. * List all pending receive statuses */ async listReceiveStatusesRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>> { const requestOptions = await this.listReceiveStatusesRequestOpts(); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(LightningReceiveInfoFromJSON)); } /** * Returns the statuses of all pending Lightning receives, ordered from oldest to newest. A receive is pending until its `finished_at` timestamp is set, indicating it has settled or been canceled. * List all pending receive statuses */ async listReceiveStatuses(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const response = await this.listReceiveStatusesRaw(initOverrides); return await response.value(); } /** * Creates request options for pay without sending the request */ async payRequestOpts(requestParameters: PayRequest): Promise { if (requestParameters['lightningPayRequest'] == null) { throw new runtime.RequiredError( 'lightningPayRequest', 'Required parameter "lightningPayRequest" was null or undefined when calling pay().' ); } 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/lightning/pay`; return { path: urlPath, method: 'POST', headers: headerParameters, query: queryParameters, body: LightningPayRequestToJSON(requestParameters['lightningPayRequest']), }; } /** * Sends a payment to a Lightning destination. Accepts a BOLT11 invoice, BOLT12 offer, or Lightning address. The `amount_sat` field is required for Lightning addresses but optional for invoices and offers. Comments are only supported for Lightning addresses. * Send a Lightning payment */ async payRaw(requestParameters: PayRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { const requestOptions = await this.payRequestOpts(requestParameters); const response = await this.request(requestOptions, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => LightningPayResponseFromJSON(jsonValue)); } /** * Sends a payment to a Lightning destination. Accepts a BOLT11 invoice, BOLT12 offer, or Lightning address. The `amount_sat` field is required for Lightning addresses but optional for invoices and offers. Comments are only supported for Lightning addresses. * Send a Lightning payment */ async pay(requestParameters: PayRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { const response = await this.payRaw(requestParameters, initOverrides); return await response.value(); } }