import { W as WalletRepository, x as ExtendedVirtualCoin, y as VtxoRepositoryKey, E as ExtendedCoin, A as ArkTransaction, z as WalletState, C as ContractRepository, B as ContractFilter, w as Contract, D as IntentRepository, F as ArkIntent, H as IntentFilter, O as Outpoint, J as VirtualTxRepository, K as VirtualTx, L as VtxoBranch } from '../../index-Ctul0N3Y.js'; export { M as ChainedTxType } from '../../index-Ctul0N3Y.js'; import '@scure/btc-signer/utils.js'; import '@scure/btc-signer'; import '@scure/btc-signer/transaction.js'; import '@scure/btc-signer/psbt.js'; /** * Minimal SQL execution interface that consumers implement * to connect their SQLite (or any SQL) database to the SDK. * * Example for expo-sqlite: * ``` * const executor: SQLExecutor = { * run: (sql, params) => db.runAsync(sql, params ?? []), * get: (sql, params) => db.getFirstAsync(sql, params ?? []), * all: (sql, params) => db.getAllAsync(sql, params ?? []), * }; * ``` */ interface SQLExecutor { run(sql: string, params?: unknown[]): Promise; get>(sql: string, params?: unknown[]): Promise; all>(sql: string, params?: unknown[]): Promise; } interface SQLiteWalletRepositoryOptions { /** Table name prefix (default: "ark_") */ prefix?: string; } /** * SQLite-based implementation of WalletRepository. * * Uses the SQLExecutor interface so consumers can plug in any SQLite driver * (expo-sqlite, better-sqlite3, etc.). * * Tables are created lazily on first operation via `ensureInit()`. * The consumer owns the SQLExecutor lifecycle — `[Symbol.asyncDispose]` is a no-op. */ declare class SQLiteWalletRepository implements WalletRepository { private readonly db; readonly version: 1; private initPromise; private readonly prefix; private readonly tables; constructor(db: SQLExecutor, options?: SQLiteWalletRepositoryOptions); private ensureInit; private init; /** * Bring the `vtxos` table to the current schema (v1 = `script` NOT NULL). * * Three cases: * - Fresh install: create the v1 schema directly. * - Legacy install without a `script` column: add it, backfill from * `address`, then rebuild the table with NOT NULL (SQLite cannot add * the NOT NULL constraint in place). * - Legacy install with a nullable `script` column: backfill the NULLs * and rebuild. * * The backfill derives `script` from the Ark address, matching what the * indexer would have returned — new rows from the indexer always carry a * populated `script`, so the migration is idempotent. * * The whole check-and-migrate runs inside one transaction, not just the * rebuild: the schema inspection is the decision point, so a second * concurrent init on the same connection must not read a pre-migration * schema and then re-run `ADD COLUMN` (duplicate column) after the first * migration already committed. It also guards the crash window between the * `DROP TABLE vtxos` and the `RENAME tmp → vtxos`, which would otherwise * leave the next startup seeing no `vtxos` table. */ private migrateVtxosTable; private vtxosCreateSql; [Symbol.asyncDispose](): Promise; clear(): Promise; getVtxos(address: string): Promise; saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise; deleteVtxos(address: string): Promise; getVtxosForScript(script: string): Promise; getVtxosForScripts(scripts: string[], options?: { unspentOnly?: boolean; }): Promise; saveVtxosForScript(key: VtxoRepositoryKey, vtxos: ExtendedVirtualCoin[]): Promise; deleteVtxosForScript(script: string): Promise; getUtxos(address: string): Promise; saveUtxos(address: string, utxos: ExtendedCoin[]): Promise; deleteUtxos(address: string): Promise; getTransactionHistory(address: string): Promise; saveTransactions(address: string, txs: ArkTransaction[]): Promise; deleteTransactions(address: string): Promise; getWalletState(): Promise; saveWalletState(state: WalletState): Promise; } interface SQLiteContractRepositoryOptions { /** Table name prefix (default: "ark_") */ prefix?: string; } /** * SQLite-based implementation of ContractRepository. * * Uses the SQLExecutor interface so consumers can plug in any SQLite driver * (expo-sqlite, better-sqlite3, etc.). * * Tables are created lazily on first operation via `ensureInit()`. * The consumer owns the SQLExecutor lifecycle — `[Symbol.asyncDispose]` is a no-op. */ declare class SQLiteContractRepository implements ContractRepository { private readonly db; readonly version: 2; private initPromise; private readonly prefix; private readonly table; constructor(db: SQLExecutor, options?: SQLiteContractRepositoryOptions); private ensureInit; private init; private addColumnIfMissing; [Symbol.asyncDispose](): Promise; clear(): Promise; getContracts(filter?: ContractFilter): Promise; saveContract(contract: Contract): Promise; deleteContract(script: string): Promise; private addFilterCondition; /** * Same as {@link addFilterCondition}, except a row predating the * column stores NULL and must match `"watched"`. */ private addWatchCondition; } declare class SQLiteIntentRepository implements IntentRepository { private readonly db; readonly version: 1; private initPromise; private readonly prefix; private readonly t; constructor(db: SQLExecutor, options?: { prefix?: string; }); private ensureInit; private init; private withTx; clear(): Promise; saveIntent(intent: ArkIntent): Promise; getIntents(filter?: IntentFilter): Promise; getLockedVtxoOutpoints(): Promise; [Symbol.asyncDispose](): Promise; } declare class SQLiteVirtualTxRepository implements VirtualTxRepository { private readonly db; readonly version: 1; private initPromise; private readonly prefix; private readonly tTx; private readonly tBranch; constructor(db: SQLExecutor, options?: { prefix?: string; }); private ensureInit; private init; private tx; clear(): Promise; upsertVirtualTxs(txs: VirtualTx[]): Promise; getVirtualTx(txid: string): Promise; setBranch(vtxo: Outpoint, branch: VtxoBranch[]): Promise; getBranch(vtxo: Outpoint): Promise; hasBranch(vtxo: Outpoint): Promise; pruneForSpentVtxo(vtxo: Outpoint): Promise; [Symbol.asyncDispose](): Promise; } /** * Run `fn` inside a serialized `BEGIN IMMEDIATE` / `COMMIT` on `db`. * * `fn` must issue only raw `db.run`/`db.all` calls: calling `runInTransaction` * again on the same `db` from within `fn` would wait on the chain it is part of * and deadlock. */ declare function runInTransaction(db: SQLExecutor, fn: () => Promise): Promise; /** * Validate a SQLite table prefix and return it unchanged. * * Rejects a leading digit as well as punctuation: `1_vtxos` is not a valid SQL * identifier either. */ declare function sanitizeTablePrefix(p: string): string; export { type SQLExecutor, SQLiteContractRepository, SQLiteIntentRepository, SQLiteVirtualTxRepository, SQLiteWalletRepository, VirtualTx, VirtualTxRepository, VtxoBranch, runInTransaction, sanitizeTablePrefix };