react-native-nitro-ark
Version:
Pure C++ Nitro Modules for Ark client
191 lines (167 loc) • 5.62 kB
text/typescript
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 {
asp?: string;
esplora?: string;
bitcoind?: string;
bitcoind_cookie?: string;
bitcoind_user?: string;
bitcoind_pass?: string;
vtxo_refresh_expiry_threshold?: number;
fallback_fee_rate?: number;
}
export interface BarkCreateOpts {
regtest?: boolean;
signet?: boolean;
bitcoin?: boolean;
mnemonic: string;
birthday_height?: number;
config?: BarkConfigOpts;
}
export interface BarkArkInfo {
network: string;
asp_pubkey: string;
round_interval_secs: number; // u64
vtxo_exit_delta: number; // u16
vtxo_expiry_delta: number; // u16
htlc_expiry_delta: number; // u16
max_vtxo_amount_sat: number; // u64
}
// Helper interface for sendManyOnchain
export interface BarkSendManyOutput {
destination: string;
amountSat: number; // uint64_t -> number
}
export interface BarkVtxo {
amount: number; // u64
expiry_height: number; // u32
exit_delta: number; // u16
anchor_point: string;
}
export type PaymentTypes = 'Bolt11' | 'Lnurl' | 'Arkoor' | 'Onchain';
export interface ArkoorPaymentResult {
amount_sat: number; // u64
destination_pubkey: string;
vtxos: BarkVtxo[];
payment_type: PaymentTypes; // 'Arkoor'
}
export interface LightningPaymentResult {
bolt11_invoice: string;
preimage: string;
payment_type: PaymentTypes; // 'Lightning'
}
export interface LnurlPaymentResult {
lnurl: string;
bolt11_invoice: string;
preimage: string;
payment_type: PaymentTypes; // 'Lnurl'
}
export interface OnchainPaymentResult {
txid: string; // Transaction ID
amount_sat: number; // Amount in satoshis
destination_address: string; // Destination address
payment_type: PaymentTypes; // 'Onchain'
}
export interface OffchainBalanceResult {
spendable: number; // u64
pending_lightning_send: number; // u64
pending_exit: number; // u64
}
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;
}
// --- Nitro Module Interface ---
export interface NitroArk extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
// --- Management ---
createMnemonic(): Promise<string>;
createWallet(datadir: string, opts: BarkCreateOpts): Promise<void>;
loadWallet(datadir: string, mnemonic: string): Promise<void>;
isWalletLoaded(): Promise<boolean>;
closeWallet(): Promise<void>;
persistConfig(opts: BarkConfigOpts): Promise<void>;
maintenance(): Promise<void>;
sync(): Promise<void>;
syncExits(): Promise<void>;
syncRounds(): Promise<void>;
// --- Wallet Info ---
getArkInfo(): Promise<BarkArkInfo>;
offchainBalance(): Promise<OffchainBalanceResult>;
deriveStoreNextKeypair(): Promise<KeyPairResult>;
peakKeyPair(index: number): Promise<KeyPairResult>;
newAddress(): Promise<NewAddressResult>;
signMessage(message: string, index: number): Promise<string>;
verifyMessage(
message: string,
signature: string,
publicKey: string
): Promise<boolean>;
getVtxos(): Promise<BarkVtxo[]>; // Returns JSON string
// --- Onchain Operations ---
onchainBalance(): Promise<OnchainBalanceResult>;
onchainSync(): Promise<void>;
onchainListUnspent(): Promise<string>; // Returns JSON string
onchainUtxos(): Promise<string>; // Returns JSON string
onchainAddress(): Promise<string>; // Returns address string
onchainSend(
destination: string,
amountSat: number,
feeRate?: number // Optional fee rate in sat/vB
): Promise<OnchainPaymentResult>; // 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<string>; // 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<string>; // Returns txid
// Note: feeRate is optional, if not provided, default fee rate will be used
// --- Ark & Lightning Payments ---
boardAmount(amountSat: number): Promise<string>; // Returns JSON status
boardAll(): Promise<string>; // Returns JSON status
sendArkoorPayment(
destination: string,
amountSat: number
): Promise<ArkoorPaymentResult>;
sendLightningPayment(
destination: string,
amountSat?: number
): Promise<LightningPaymentResult>;
sendLnaddr(
addr: string,
amountSat: number,
comment: string
): Promise<LnurlPaymentResult>;
sendRoundOnchainPayment(
destination: string,
amountSat: number
): Promise<string>; // Returns JSON status
// --- Lightning Invoicing ---
bolt11Invoice(amountMsat: number): Promise<string>; // Returns invoice string
finishLightningReceive(bolt11: string): Promise<void>; // Throws on error
// --- Offboarding / Exiting ---
offboardSpecific(
vtxoIds: string[],
destinationAddress: string
): Promise<string>; // Returns JSON result
offboardAll(destinationAddress: string): Promise<string>; // Returns JSON result
}