UNPKG

@arkade-os/sdk

Version:

Bitcoin wallet SDK with Taproot and Ark integration

88 lines (87 loc) 3.97 kB
import type { BatchStartedEvent, BatchFinalizedEvent, BatchFailedEvent, TreeTxEvent, TreeSignatureEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchFinalizationEvent, SettlementEvent } from "../providers/ark"; import { TxTree } from "../tree/txTree"; /** * Batch namespace provides utilities for joining and processing batch session. * The batch settlement process involves multiple events, this namespace provides abstractions and types to handle them. * @see https://docs.arkadeos.com/learn/pillars/batch-swaps * @example * ```typescript * // use wallet handler or create a custom one * const handler = wallet.createBatchHandler(intentId, inputs, musig2session); * * const abortController = new AbortController(); * // Get event stream from Ark provider * const eventStream = arkProvider.getEventStream( * abortController.signal, * ['your-topic-1', 'your-topic-2'] * ); * * // Join the batch and process events * try { * const commitmentTxid = await Batch.join(eventStream, handler); * console.log('Batch completed with commitment:', commitmentTxid); * } catch (error) { * console.error('Batch processing failed:', error); * } finally { * abortController.abort(); * } * ``` */ export declare namespace Batch { interface Handler { /** * Called on BatchStarted event. * @returns { skip: boolean } indicating whether the batch should be skipped or not. */ onBatchStarted(event: BatchStartedEvent): Promise<{ skip: boolean; }>; /** * Called when tree signing starts. * @param event The tree signing started event. * @param vtxoTree The unsigned VTXO tree, reconstructed from the TreeTxEvent events. * @returns Promise resolving to a boolean indicating whether to continue processing. */ onTreeSigningStarted(event: TreeSigningStartedEvent, vtxoTree: TxTree): Promise<{ skip: boolean; }>; /** * Called when tree nonces are received. * @param event The tree nonces event. * @returns Promise resolving to a boolean indicating whether signing is complete. */ onTreeNonces(event: TreeNoncesEvent): Promise<{ fullySigned: boolean; }>; /** * Called during batch finalization. * @param event The batch finalization event. * @param vtxoTree The signed VTXO tree, reconstructed from the TreeTxEvent events. * @param connectorTree The connector transaction tree, reconstructed from the TreeTxEvent events. */ onBatchFinalization(event: BatchFinalizationEvent, vtxoTree?: TxTree, connectorTree?: TxTree): Promise<void>; onBatchFinalized?(event: BatchFinalizedEvent): Promise<void>; onBatchFailed?(event: BatchFailedEvent): Promise<void>; onTreeTxEvent?(event: TreeTxEvent): Promise<void>; onTreeSignatureEvent?(event: TreeSignatureEvent): Promise<void>; } /** * Options for the join function. * @param @optional abortController - The abort controller to use to abort the operation. * @param @optional skipVtxoTreeSigning - ignore events related to vtxo tree musig2 signing session. * @param @optional eventCallback - A callback to be called for each event. * @param eventCallback - A callback to be called for each event. */ type JoinOptions = Partial<{ abortController: AbortController; skipVtxoTreeSigning: boolean; eventCallback: (event: SettlementEvent) => Promise<void>; }>; /** * Start the state machine that will process the batch events and join a batch. * @param eventIterator - The events stream to process. * @param handler - How to react to events. * @param options - Options. */ function join(eventIterator: AsyncIterableIterator<SettlementEvent>, handler: Handler, options?: JoinOptions): Promise<string>; }