import type { HybridObject } from 'react-native-nitro-modules'; // --- Interfaces matching C structs --- // Note: BarkError is handled via Promise rejection, not exposed directly. export interface BarkConfigOpts { ark: string; /** Client identifier sent as `x-user-agent`, formatted as `/`. */ user_agent?: string; esplora?: string; bitcoind?: string; bitcoind_cookie?: string; bitcoind_user?: string; bitcoind_pass?: string; /** Number of blocks before expiry to refresh VTXOs (0–65535). */ vtxo_refresh_expiry_threshold: number; /** Unused VTXO key indices to scan during recovery. Default: 250; integer from 0 to 100000. */ vtxo_key_gap_limit?: number; fallback_fee_rate: number; htlc_recv_claim_delta: number; vtxo_exit_margin: number; /** Required round confirmations (0–65535). */ round_tx_required_confirmations: number; } export interface BarkCreateOpts { regtest?: boolean; signet?: boolean; bitcoin?: boolean; mnemonic: string; birthday_height?: number; config?: BarkConfigOpts; } export interface RecoveryGroup { vtxo_ids: string[]; /** Sum of known amounts; failed fetches may have no known amount. */ known_amount_sat: number; } export interface RecoveryReport { /** False when the scan has failed or foreign candidates. */ is_complete: boolean; recovered: RecoveryGroup; skipped: RecoveryGroup; exited: RecoveryGroup; failed: RecoveryGroup; /** Keys not found within the configured VTXO key gap. */ foreign: RecoveryGroup; /** VTXO ids the Ark server reported as unknown; recovery does not retry them. */ not_found: RecoveryGroup; } export interface RestoreWalletResult { status: string; report?: RecoveryReport; error?: string; } export interface BarkArkInfo { network: string; server_pubkey: string; mailbox_pubkey: string; round_interval: number; // u64 nb_round_nonces: number; // u16 vtxo_exit_delta: number; // u16 vtxo_lifetime: number; // u16 htlc_send_expiry_delta: number; // u16 max_vtxo_amount: number; // u64 required_board_confirmations: number; // u8 min_board_amount: number; // u64 ln_receive_anti_dos_required: boolean; } /** Public identity information for diagnosing a loaded wallet. */ export interface WalletDebugInfo { network: string; mailbox_id: string; vtxo_xpub: string; // Base58 extended public key for VTXO derivation } // Helper interface for sendManyOnchain export interface BarkSendManyOutput { destination: string; amountSat: number; // uint64_t -> number } interface BarkVtxo { id: string; amount: number; // u64 expiry_height: number; // u32 server_pubkey: string; exit_delta: number; // u16 anchor_point: string; point: string; state: string; } export interface BoardResult { funding_txid: string; vtxos: string[]; } export interface Bolt11Invoice { payment_request: string; payment_secret: string; payment_hash: string; } export interface ArkoorPaymentResult { amount_sat: number; // u64 destination_pubkey: string; movement_id: number; // u32, history entry of this payment } /** Result of an offboard or an on-chain send from Ark funds. */ export interface OffboardResult { txid: string; movement_id: number; // u32, history entry of this offboard } export interface PaymentRequestOption { /** Same values as a movement's payment_method: ark, bitcoin, output-script, invoice, offer, lightning-address, lnurl, custom. */ method_type: string; value: string; /** Validation problems, e.g. network mismatch. Non-empty means the option should not be paid. */ errors: string[]; } export interface ParsedPaymentRequest { amount_sat?: number; // u64 label?: string; message?: string; options: PaymentRequestOption[]; /** Bark's pick among error-free options: Ark, then Lightning, then on-chain. */ default_option_index?: number; } export interface BarkFeeEstimate { gross_amount_sat: number; // u64 fee_sat: number; // u64 net_amount_sat: number; // u64 vtxos_spent: string[]; } export interface ExitFeeEstimate { exit_broadcast_fee_sat: number; // Upfront funding from confirmed onchain funds, including margin claim_fee_sat: number; // Later claim fee deducted from recovered funds total_fee_sat: number; // Broadcast + claim fees fee_rate_sat_per_vb: number; // Base broadcast rate in sat/vB, before margin; may be fractional txs_to_broadcast: number; // Transactions still requiring broadcast/CPFP } export interface BarkFeeRates { fast: number; // sat/vB regular: number; // sat/vB slow: number; // sat/vB } export interface OnchainTransactionInfo { txid: string; tx_hex: string; has_onchain_fee: boolean; onchain_fee_sat: number; // u64 balance_change_sat: number; // i64 has_confirmation: boolean; confirmation_height: number; // u32 confirmation_hash: string; } export interface ExitBlockRefResult { height: number; hash: string; } export interface ExitTxOriginResult { kind: string; confirmed_in?: ExitBlockRefResult; } export interface ExitTxStatusResult { kind: string; txids?: string[]; child_txid?: string; origin?: ExitTxOriginResult; block?: ExitBlockRefResult; } export interface ExitTxResult { txid: string; status: ExitTxStatusResult; } export interface ExitStateDetailsResult { kind: string; tip_height: number; /** Present for vtxo-swept; spent exit-chain inputs formatted as txid:vout. */ spent_inputs?: string[]; transactions?: ExitTxResult[]; confirmed_block?: ExitBlockRefResult; claimable_height?: number; claimable_since?: ExitBlockRefResult; last_scanned_block?: ExitBlockRefResult; claim_txid?: string; txid?: string; block?: ExitBlockRefResult; } export interface ExitProgressStatusResult { vtxo_id: string; state: string; state_details: ExitStateDetailsResult; error?: string; } export interface ExitVtxoResult { vtxo_id: string; amount_sat: number; state: string; state_details: ExitStateDetailsResult; history: string[]; history_details: ExitStateDetailsResult[]; txids: string[]; is_claimable: boolean; is_initialized: boolean; } export interface ExitTransactionPackageResult { exit_txid: string; exit_tx_hex: string; child_txid: string; child_tx_hex: string; child_origin: string; has_child: boolean; } export interface ExitStatusResult { vtxo_id: string; state: string; state_details: ExitStateDetailsResult; history: string[]; history_details: ExitStateDetailsResult[]; transactions: ExitTransactionPackageResult[]; } export interface LightningPaymentResult { state: string; invoice?: string; payment_hash: string; amount?: number; // u64 htlc_vtxos: BarkVtxo[]; movement_id?: number; // u32 preimage?: string; } export type LightningPaymentOriginMethod = | 'lightning-address' | 'lnurl' | 'custom'; /** * The original user-facing destination that was resolved to a Lightning * invoice outside Bark. Only origin kinds that Bark can persist through this * API are accepted; Rust validates the value again at the native boundary. */ export interface LightningPaymentOrigin { method: LightningPaymentOriginMethod; value: string; } export interface OnchainPaymentResult { txid: string; // Transaction ID amount_sat: number; // Amount in satoshis destination_address: string; // Destination address } /** All amounts are integer satoshis. Summary fields overlap the breakdown. */ export interface OffchainBalanceResult { spendable: number; // Available to pay now needs_refresh: number; // Expired or at the server's exit-depth limit pending: number; // Sum of the seven pending categories below total: number; // spendable + needs_refresh + pending pending_arkoor_send: number; // Held by outgoing Ark payments, including change pending_lightning_send: number; // Held by outgoing Lightning payments claimable_lightning_receive: number; // Preimage revealed; awaiting spendable VTXOs pending_in_round: number; // Locked round inputs pending_board: number; // Awaiting board confirmations pending_offboard: number; // Held until offboard broadcast, including change pending_exit: number; // Exit committed onchain; awaiting claim } export interface OnchainBalanceResult { // All coinbase outputs not yet matured immature: number; // Unconfirmed UTXOs generated by a wallet tx trusted_pending: number; // Unconfirmed UTXOs received from an external wallet untrusted_pending: number; // Confirmed and immediately spendable balance confirmed: number; } export interface NewAddressResult { user_pubkey: string; ark_id: string; address: string; } export interface KeyPairResult { public_key: string; secret_key: string; } export interface MailboxAuthorizationResult { mailbox_id: string; expiry: number; // i64 unix timestamp encoded: string; // hex-encoded full protocol encoding } export interface LightningReceive { state: string; phase?: string; payment_hash: string; payment_preimage: string; invoice: string; htlc_vtxo_ids: string[]; movement_id?: number; amount_sat?: number; settled_at?: number; } export interface BarkMovementSubsystem { name: string; kind: string; } export interface BarkMovementDestination { destination: string; payment_method: string; amount_sat: number; } export interface BarkMovement { id: number; status: string; // 'pending' | 'successful' | 'failed' | 'canceled' subsystem: BarkMovementSubsystem; metadata_json: string; intended_balance_sat: number; effective_balance_sat: number; offchain_fee_sat: number; sent_to: BarkMovementDestination[]; received_on: BarkMovementDestination[]; input_vtxos: string[]; output_vtxos: string[]; exited_vtxos: string[]; created_at: string; updated_at: string; completed_at?: string; } export interface PendingRoundStatus { round_id: number; // u32 status: string; // 'pending' | 'unconfirmed' | 'confirmed' | 'failed' | 'canceled' funding_txid: string; unsigned_funding_txids: string[]; error: string; is_final: boolean; is_success: boolean; } export interface DelegatedRoundState { round_id: number; // u32 } export interface BarkNotificationEvent { kind: string; // 'movementCreated' | 'movementUpdated' | 'channelLagging' movement?: BarkMovement; } export interface BarkNotificationSubscription extends HybridObject<{ ios: 'c++'; android: 'c++' }> { stop(): void; isActive(): boolean; } export interface WalletSnapshotInfo { path: string; sizeBytes: number; sha256: string; network: string; walletFingerprint: string; serverPubkey?: string; mailboxPubkey?: string; schemaVersion: number; } export interface WalletSnapshotExpectation { network?: string; walletFingerprint?: string; serverPubkey?: string; } export interface WalletStateChangeEvent { sequence: number; reason: string; // 'initial' | 'databaseChanged' | 'resyncRequired' } export interface WalletStateChangeSubscription extends HybridObject<{ ios: 'c++'; android: 'c++' }> { stop(): void; isActive(): boolean; } // --- Nitro Module Interface --- export interface NitroArk extends HybridObject<{ ios: 'c++'; android: 'c++' }> { // --- Management --- getBarkVersion(): string; createMnemonic(): Promise; createWallet(datadir: string, opts: BarkCreateOpts): Promise; loadWallet(datadir: string, config: BarkCreateOpts): Promise; restoreWalletFromArkServer( datadir: string, opts: BarkCreateOpts ): Promise; isWalletLoaded(): Promise; closeWallet(): Promise; createWalletSnapshot(destinationPath: string): Promise; validateWalletSnapshot( path: string, expected?: WalletSnapshotExpectation ): Promise; subscribeWalletStateChanges( onEvent: (event: WalletStateChangeEvent) => void ): WalletStateChangeSubscription; refreshServer(): Promise; syncPendingBoards(): Promise; maintenance(): Promise; maintenanceDelegated(): Promise; maintenanceRefresh(): Promise; sync(): Promise; // --- Exits --- startExitForEntireWallet(): Promise; startExitForVtxos(vtxoIds: string[]): Promise; cancelExit(vtxoId: string): Promise; syncExit(): Promise; progressExits(feeRateSatPerKvb?: number): Promise; estimateEmergencyExitFee( vtxoIds: string[], feeRateSatPerKvb?: number, destinationAddress?: string, feeMargin?: number ): Promise; getExitVtxos(): Promise; listClaimable(): Promise; getExitStatus( vtxoId: string, includeHistory?: boolean, includeTransactions?: boolean ): Promise; hasPendingExits(): Promise; pendingExitTotal(): Promise; allClaimableAtHeight(): Promise; drainExits( vtxoIds: string[], destinationAddress: string, feeRateSatPerKvb?: number ): Promise; extractTransaction(psbt: string): Promise; broadcastTransaction(txHex: string): Promise; syncPendingRounds(): Promise; // --- Wallet Info --- getArkInfo(): Promise; debugInfo(): Promise; offchainBalance(): Promise; deriveStoreNextKeypair(): Promise; peekKeyPair(index: number): Promise; peekAddress(index: number): Promise; newAddress(): Promise; signMessage(message: string, index: number): Promise; signMesssageWithMnemonic( message: string, mnemonic: string, network: string, index: number ): Promise; deriveKeypairFromMnemonic( mnemonic: string, network: string, index: number ): Promise; verifyMessage( message: string, signature: string, publicKey: string ): Promise; mailboxKeypair(): Promise; mailboxAuthorization( authorizationExpiry: number ): Promise; subscribeNotifications( onEvent: (event: BarkNotificationEvent) => void ): BarkNotificationSubscription; subscribeArkoorAddressMovements( address: string, onEvent: (event: BarkNotificationEvent) => void ): BarkNotificationSubscription; subscribeLightningPaymentMovements( paymentHash: string, onEvent: (event: BarkNotificationEvent) => void ): BarkNotificationSubscription; history(): Promise; vtxos(): Promise; updateHistoryMetadata(movementId: number, patchJson: string): Promise; decodeVtxoHex(vtxoHex: string): Promise; importVtxo(vtxoHex: string): Promise; dangerousDropVtxo(vtxoId: string): Promise; unlockVtxos(vtxoIds: string[]): Promise; refreshVtxosDelegated( vtxoIds: string[] ): Promise; getFirstExpiringVtxoBlockheight(): Promise; getNextRequiredRefreshBlockheight(): Promise; getExpiringVtxos(threshold: number): Promise; // --- Onchain Operations --- onchainBalance(): Promise; onchainSync(): Promise; onchainIsMine(address: string): Promise; // Check if an address belongs to this wallet onchainListUnspent(): Promise; // Returns JSON string onchainUtxos(): Promise; // Returns JSON string onchainFeeRates(): Promise; // Returns fast/regular/slow fee rates in sat/vB onchainTransactions(): Promise; // Returns BDK onchain wallet transactions onchainAddress(): Promise; // Returns address string onchainSend( destination: string, amountSat: number, feeRate?: number // Optional fee rate in sat/vB ): Promise; // Returns txid and details // Note: feeRate is optional, if not provided, default fee rate will be used onchainDrain( destination: string, feeRate?: number // Optional fee rate in sat/vB ): Promise; // Returns txid // Note: feeRate is optional, if not provided, default fee rate will be used onchainSendMany( outputs: BarkSendManyOutput[], feeRate?: number // Optional fee rate in sat/vB ): Promise; // Returns txid // Note: feeRate is optional, if not provided, default fee rate will be used // --- Ark & Lightning Payments --- boardAmount(amountSat: number): Promise; // Returns JSON status boardAll(): Promise; // Returns JSON status validateArkoorAddress(address: string): Promise; sendArkoorPayment( destination: string, amountSat: number ): Promise; /** * Parses anything a user may paste: BIP 321 and lightning: URIs, BOLT11 * invoices, BOLT12 offers, lightning addresses, LNURL-pay links, Ark and * bitcoin addresses. Throws when no payment option is found. */ parsePaymentRequest(payment: string): Promise; estimateArkoorPaymentFee(amountSat: number): Promise; estimateBoardOffchainFee(amountSat: number): Promise; estimateRefreshFee(vtxoIds: string[]): Promise; payLightningInvoice( destination: string, wait: boolean, amountSat?: number, retryForSeconds?: number ): Promise; /** * Pays an invoice already resolved by the caller while preserving the * original user-facing destination in Bark's movement history. */ payLightningInvoiceWithOrigin( invoice: string, origin: LightningPaymentOrigin, wait: boolean, retryForSeconds?: number ): Promise; payLightningOffer( offer: string, wait: boolean, amountSat?: number, retryForSeconds?: number ): Promise; payLightningAddress( addr: string, amountSat: number, comment: string, wait: boolean, retryForSeconds?: number ): Promise; estimateLightningSendFee(amountSat: number): Promise; sendOnchain(destination: string, amountSat: number): Promise; estimateSendOnchain( destination: string, amountSat: number ): Promise; // --- Lightning Invoicing --- bolt11Invoice( amountSat: number, description?: string, token?: string ): Promise; lightningReceiveStatus(paymentHash: string): Promise; checkLightningPayment( paymentHash: string, wait: boolean ): Promise; tryClaimLightningReceive( paymentHash: string, wait: boolean ): Promise; // Throws on error tryClaimAllLightningReceives(wait: boolean): Promise; // Throws on error // --- Offboarding / Exiting --- offboardSpecific( vtxoIds: string[], destinationAddress: string ): Promise; offboardAll(destinationAddress: string): Promise; estimateOffboardAll(destinationAddress: string): Promise; }