@arkade-os/sdk 0.4.47 → 0.4.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{ark-CoJgwTi_.d.cts → ark-CjE0KkGp.d.cts} +405 -250
- package/dist/{ark-CoJgwTi_.d.ts → ark-CjE0KkGp.d.ts} +405 -250
- package/dist/{asyncStorageTaskQueue-Dowyo59a.d.cts → asyncStorageTaskQueue-CeLZhZFU.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-Z3aFoXCl.d.ts → asyncStorageTaskQueue-D9SOPMPC.d.ts} +2 -2
- package/dist/{chunk-XN3554FT.js → chunk-4VVTRPH3.js} +4 -4
- package/dist/chunk-4VVTRPH3.js.map +1 -0
- package/dist/{chunk-RQSA7ADZ.cjs → chunk-5XMVTK5S.cjs} +37 -37
- package/dist/chunk-5XMVTK5S.cjs.map +1 -0
- package/dist/{chunk-L5ND2FJJ.cjs → chunk-7TXSPRN5.cjs} +161 -2
- package/dist/chunk-7TXSPRN5.cjs.map +1 -0
- package/dist/{chunk-CDDWXBEM.js → chunk-BHHLRZCS.js} +169 -42
- package/dist/chunk-BHHLRZCS.js.map +1 -0
- package/dist/{chunk-HHV5FPC6.cjs → chunk-EB3ALGTM.cjs} +178 -50
- package/dist/chunk-EB3ALGTM.cjs.map +1 -0
- package/dist/{chunk-JAYOXOLT.cjs → chunk-ENDNQPZA.cjs} +17 -44
- package/dist/chunk-ENDNQPZA.cjs.map +1 -0
- package/dist/{chunk-WTTLIFS7.cjs → chunk-ENZ4YPR2.cjs} +944 -544
- package/dist/chunk-ENZ4YPR2.cjs.map +1 -0
- package/dist/{chunk-3N5I6GT6.js → chunk-G6J6AEMH.js} +5 -4
- package/dist/chunk-G6J6AEMH.js.map +1 -0
- package/dist/{chunk-OCS5S3L3.js → chunk-NYR5H6GR.js} +685 -284
- package/dist/chunk-NYR5H6GR.js.map +1 -0
- package/dist/{chunk-VE67GMGM.cjs → chunk-SYDANBJI.cjs} +9 -8
- package/dist/chunk-SYDANBJI.cjs.map +1 -0
- package/dist/{chunk-AJQ4AOT3.js → chunk-XFMGIFBL.js} +4 -31
- package/dist/chunk-XFMGIFBL.js.map +1 -0
- package/dist/{chunk-C7TXXTMS.js → chunk-ZDDBTFVO.js} +146 -3
- package/dist/chunk-ZDDBTFVO.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +8 -8
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-Dl87_zMA.d.cts → delegate-D3dY-2vS.d.cts} +1 -1
- package/dist/{delegate-CuaDqqQi.d.ts → delegate-DhGZk1r2.d.ts} +1 -1
- package/dist/{index-BC_G0VTh.d.cts → index-D6RQROds.d.cts} +2 -2
- package/dist/{index-CKwpZEpw.d.ts → index-DK4_iWYy.d.ts} +2 -2
- package/dist/index.cjs +211 -183
- package/dist/index.d.cts +61 -11
- package/dist/index.d.ts +61 -11
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +19 -19
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +5 -5
- package/dist/repositories/sqlite/index.cjs +18 -18
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +5 -5
- package/dist/{taskRunner-Dz-TI4Rb.d.ts → taskRunner-B-2MHCYG.d.ts} +2 -2
- package/dist/{taskRunner-Dz47k0lp.d.cts → taskRunner-Brnak0Rc.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +14 -14
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +5 -5
- package/dist/wallet/expo/index.d.ts +5 -5
- package/dist/wallet/expo/index.js +5 -5
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/{wallet-Oxz_wLxo.d.cts → wallet-B5bwixQa.d.ts} +130 -7
- package/dist/{wallet-x7egmXq6.d.ts → wallet-DiOrtYic.d.cts} +130 -7
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +5 -5
- package/package.json +3 -2
- package/dist/chunk-3N5I6GT6.js.map +0 -1
- package/dist/chunk-AJQ4AOT3.js.map +0 -1
- package/dist/chunk-C7TXXTMS.js.map +0 -1
- package/dist/chunk-CDDWXBEM.js.map +0 -1
- package/dist/chunk-HHV5FPC6.cjs.map +0 -1
- package/dist/chunk-JAYOXOLT.cjs.map +0 -1
- package/dist/chunk-L5ND2FJJ.cjs.map +0 -1
- package/dist/chunk-OCS5S3L3.js.map +0 -1
- package/dist/chunk-RQSA7ADZ.cjs.map +0 -1
- package/dist/chunk-VE67GMGM.cjs.map +0 -1
- package/dist/chunk-WTTLIFS7.cjs.map +0 -1
- package/dist/chunk-XN3554FT.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/wallet/expo/wallet.ts"],"names":[],"mappings":";;;;;;;;AA+DO,SAAS,8BAA8B,EAAA,EAAmB;AAC7D,EAAA,IAAI,CAAC,EAAA,IAAM,OAAO,EAAA,KAAO,QAAA,EAAU;AACnC,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,IAAI,UAAA,IAAc,EAAA,EAAI,OAAA,CAAQ,IAAA,CAAK,UAAU,CAAA;AAC7C,EAAA,IAAI,+BA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AA,CAAO,IAAA,CAAK,GAAG,UAAU,CAAA;AAAA,EACzC;AAAA,EAEA,IAAI,YAAA,GAA8B;AAC9B,IAAA,OAAO,KAAK,MAAA,CAAO,YAAA;AAAA,EACvB;AACJ","file":"index.js","sourcesContent":["import { hex } from \"@scure/base\";\nimport { Wallet, type ProviderConnectionState } from \"../wallet\";\nimport type { Activity, ActivityRegistry } from \"../activity\";\nimport { RestArkProvider } from \"../../providers/ark\";\nimport type {\n IWallet,\n IAssetManager,\n WalletBalance,\n WalletConfig,\n SendBitcoinParams,\n SettleParams,\n GetVtxosFilter,\n ArkTransaction,\n ExtendedCoin,\n ExtendedVirtualCoin,\n Recipient,\n} from \"..\";\nimport type { SettlementEvent } from \"../../providers/ark\";\nimport type { Identity } from \"../../identity\";\nimport type { IContractManager } from \"../../contracts/contractManager\";\nimport type { IDelegateManager } from \"../delegate\";\nimport type { TaskQueue, TaskItem } from \"../../worker/expo/taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../../worker/expo/taskRunner\";\nimport { runTasks } from \"../../worker/expo/taskRunner\";\nimport { contractPollProcessor, CONTRACT_POLL_TASK_TYPE } from \"../../worker/expo/processors\";\nimport { extendVirtualCoinForContract, getRandomId } from \"../utils\";\nimport type { PersistedBackgroundConfig } from \"./background\";\nimport type { AsyncStorageTaskQueue } from \"../../worker/expo/asyncStorageTaskQueue\";\n\n/**\n * Background processing configuration for @see ExpoWallet.\n *\n * OS-level task registration is **not** part of this config — call\n * `registerExpoBackgroundTask` from `@arkade-os/sdk/wallet/expo/background`\n * explicitly. Splitting that step out keeps `/wallet/expo` free of the\n * `expo-task-manager` / `expo-background-task` dependencies, so\n * react-native-web and Node consumers can use `ExpoWallet` without\n * those native packages. See\n * https://github.com/arkade-os/ts-sdk/issues/486 for details.\n */\nexport interface ExpoBackgroundConfig {\n /** Persistence layer for foreground ↔ background handoff. */\n taskQueue: TaskQueue;\n /** Processors to run on each tick. Defaults to `[contractPollProcessor]`. */\n processors?: TaskProcessor[];\n /** If set, automatically polls at this interval (ms) while the app is in the foreground. */\n foregroundIntervalMs?: number;\n}\n\n/**\n * Configuration for @see ExpoWallet.setup.\n */\nexport interface ExpoWalletConfig extends WalletConfig {\n background: ExpoBackgroundConfig;\n}\n\n/**\n * Catches JS callers still passing the pre-fix-#486 fields: TypeScript\n * blocks these at compile time, but compiled JS silently dropped them\n * and consumers would never realize the OS task wasn't scheduled.\n *\n * @internal Exported for tests; not part of the public API surface.\n */\nexport function warnOnRemovedBackgroundFields(bg: unknown): void {\n if (!bg || typeof bg !== \"object\") return;\n const removed: string[] = [];\n if (\"taskName\" in bg) removed.push(\"taskName\");\n if (\"minimumBackgroundInterval\" in bg) {\n removed.push(\"minimumBackgroundInterval\");\n }\n if (removed.length === 0) return;\n console.warn(\n `[ark-sdk] ExpoWallet.setup: ignoring removed background field(s): ${removed.join(\", \")}. ` +\n 'OS-task registration moved to \"@arkade-os/sdk/wallet/expo/background\". ' +\n \"See https://github.com/arkade-os/ts-sdk/issues/486\",\n );\n}\n\n/**\n * Expo/React Native wallet with built-in background task processing.\n *\n * Wraps a standard @see Wallet and adds a lightweight task queue\n * for keeping contract/VTXO state fresh while the app is active and\n * across Expo BackgroundTask wakes.\n *\n * OS-level task registration is the consumer's responsibility — call\n * `registerExpoBackgroundTask` from\n * `@arkade-os/sdk/wallet/expo/background` after `setup()`. Keeping\n * registration out of `setup()` lets this entrypoint avoid pulling\n * `expo-task-manager` / `expo-background-task` into the `/wallet/expo`\n * bundle.\n *\n * @example\n * ```ts\n * import { ExpoWallet } from \"@arkade-os/sdk/wallet/expo\";\n * import { registerExpoBackgroundTask } from \"@arkade-os/sdk/wallet/expo/background\";\n * import { AsyncStorageTaskQueue } from \"@arkade-os/sdk/worker/expo\";\n *\n * const wallet = await ExpoWallet.setup({\n * identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),\n * arkProvider: new RestArkProvider(),\n * onchainProvider: new EsploraProvider(),\n * storage: { ... },\n * background: {\n * taskQueue: new AsyncStorageTaskQueue(AsyncStorage),\n * foregroundIntervalMs: 20_000,\n * },\n * });\n *\n * // Activate the OS scheduler (Expo Android/iOS only)\n * await registerExpoBackgroundTask(\"ark-background-poll\", { minimumInterval: 15 });\n *\n * const balance = await wallet.getBalance();\n * ```\n */\nexport class ExpoWallet implements IWallet {\n readonly identity: Identity;\n readonly arkProvider: Wallet[\"arkProvider\"];\n readonly indexerProvider: Wallet[\"indexerProvider\"];\n\n private foregroundIntervalId?: ReturnType<typeof setInterval>;\n private foregroundPollChain: Promise<void> = Promise.resolve();\n private cleared = false;\n\n private constructor(\n private readonly wallet: Wallet,\n private readonly taskQueue: TaskQueue,\n private readonly processors: TaskProcessor[],\n private readonly deps: TaskDependencies,\n foregroundIntervalMs?: number,\n ) {\n this.identity = wallet.identity;\n this.arkProvider = wallet.arkProvider;\n this.indexerProvider = wallet.indexerProvider;\n\n if (foregroundIntervalMs && foregroundIntervalMs > 0) {\n this.startForegroundPolling(foregroundIntervalMs);\n }\n }\n\n /**\n * Create an ExpoWallet with foreground/background queue handoff.\n *\n * 1. Creates the inner @see Wallet via `Wallet.create()`.\n * 2. Wires up processors (defaults to @see contractPollProcessor).\n * 3. Persists background config for the background handler (if the queue supports it).\n * 4. Seeds the task queue with a `contract-poll` task.\n * 5. Starts the foreground interval if `foregroundIntervalMs` is set.\n *\n * OS-level scheduling lives in\n * `@arkade-os/sdk/wallet/expo/background` and is invoked separately\n * by the consumer.\n */\n static async setup(config: ExpoWalletConfig): Promise<ExpoWallet> {\n warnOnRemovedBackgroundFields(config.background);\n\n const wallet = await Wallet.create(config);\n\n const processors = config.background.processors ?? [contractPollProcessor];\n\n const deps: TaskDependencies = {\n walletRepository: wallet.walletRepository,\n contractRepository: wallet.contractRepository,\n indexerProvider: wallet.indexerProvider,\n arkProvider: wallet.arkProvider,\n extendVtxo: (vtxo, contract) => extendVirtualCoinForContract(vtxo, contract),\n };\n\n const { taskQueue } = config.background;\n\n // Persist wallet params so the background handler can rehydrate\n // without a network call. Only works with AsyncStorageTaskQueue.\n if (\"persistConfig\" in taskQueue) {\n const arkServerUrl =\n config.arkServerUrl ||\n (wallet.arkProvider instanceof RestArkProvider\n ? wallet.arkProvider.serverUrl\n : undefined);\n\n if (arkServerUrl) {\n const timelock = wallet.offchainTapscript.options.csvTimelock;\n\n const bgConfig: PersistedBackgroundConfig = {\n arkServerUrl,\n pubkeyHex: hex.encode(wallet.offchainTapscript.options.pubKey),\n serverPubKeyHex: hex.encode(wallet.offchainTapscript.options.serverPubKey),\n exitTimelockValue: timelock.value.toString(),\n exitTimelockType: timelock.type,\n };\n\n await (taskQueue as AsyncStorageTaskQueue).persistConfig(bgConfig);\n }\n }\n\n const expoWallet = new ExpoWallet(\n wallet,\n taskQueue,\n processors,\n deps,\n config.background.foregroundIntervalMs,\n );\n\n // Seed the queue so the first tick (or background wake) has work to do\n await expoWallet.seedContractPollTask();\n\n return expoWallet;\n }\n\n // ── Foreground polling ───────────────────────────────────────────\n\n private startForegroundPolling(intervalMs: number): void {\n this.foregroundIntervalId = setInterval(() => {\n // Serialize polls so clear() can await the in-flight one before wiping.\n this.foregroundPollChain = this.foregroundPollChain\n .then(() => this.runForegroundPoll())\n .catch(console.error);\n }, intervalMs);\n }\n\n private async runForegroundPoll(): Promise<void> {\n if (this.cleared) return;\n\n await runTasks(this.taskQueue, this.processors, this.deps);\n\n // Consume results immediately (no background handoff needed)\n const results = await this.taskQueue.getResults();\n if (results.length > 0) {\n await this.taskQueue.acknowledgeResults(results.map((r) => r.id));\n }\n\n if (this.cleared) return;\n\n // Re-seed for the next tick\n await this.seedContractPollTask();\n }\n\n private async seedContractPollTask(): Promise<void> {\n const existing = await this.taskQueue.getTasks(CONTRACT_POLL_TASK_TYPE);\n if (existing.length > 0) return;\n\n const task: TaskItem = {\n id: getRandomId(),\n type: CONTRACT_POLL_TASK_TYPE,\n data: {},\n createdAt: Date.now(),\n };\n await this.taskQueue.addTask(task);\n }\n\n private async removeContractPollTasks(): Promise<void> {\n const tasks = await this.taskQueue.getTasks(CONTRACT_POLL_TASK_TYPE);\n for (const task of tasks) {\n await this.taskQueue.removeTask(task.id);\n }\n }\n\n // ── Lifecycle ────────────────────────────────────────────────────\n\n /**\n * Stop foreground polling and dispose the inner wallet.\n *\n * Does **not** unregister the OS background task — call\n * `unregisterExpoBackgroundTask` from\n * `@arkade-os/sdk/wallet/expo/background` yourself, matching the\n * explicit `register` step.\n */\n async dispose(): Promise<void> {\n if (this.foregroundIntervalId) {\n clearInterval(this.foregroundIntervalId);\n this.foregroundIntervalId = undefined;\n }\n\n await this.wallet.dispose();\n }\n\n /**\n * Stop foreground polling and wipe all locally persisted wallet data.\n * Does not unregister the OS background task or persisted queue config.\n */\n async clear(): Promise<void> {\n this.cleared = true;\n\n if (this.foregroundIntervalId) {\n clearInterval(this.foregroundIntervalId);\n this.foregroundIntervalId = undefined;\n }\n\n await this.foregroundPollChain;\n await this.wallet.clear();\n await this.removeContractPollTasks();\n }\n\n // ── IWallet delegation ───────────────────────────────────────────\n\n getAddress(): Promise<string> {\n return this.wallet.getAddress();\n }\n\n getBoardingAddress(): Promise<string> {\n return this.wallet.getBoardingAddress();\n }\n\n getBalance(): Promise<WalletBalance> {\n return this.wallet.getBalance();\n }\n\n getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]> {\n return this.wallet.getVtxos(filter);\n }\n\n getBoardingUtxos(): Promise<ExtendedCoin[]> {\n return this.wallet.getBoardingUtxos();\n }\n\n getTransactionHistory(): Promise<ArkTransaction[]> {\n return this.wallet.getTransactionHistory();\n }\n\n get activity(): ActivityRegistry {\n return this.wallet.activity;\n }\n\n getActivityHistory(): Promise<Activity[]> {\n return this.wallet.getActivityHistory();\n }\n\n getContractManager(): Promise<IContractManager> {\n return this.wallet.getContractManager();\n }\n\n /**\n * Wallet-level provider-connection freshness, delegated to the wrapped\n * in-process wallet. Synchronous because the Expo foreground wallet is\n * in-process (no worker boundary). Foreground-only: it does not imply any\n * background task can read live foreground state.\n */\n getProviderConnectionState(): ProviderConnectionState {\n return this.wallet.getProviderConnectionState();\n }\n\n getDelegateManager(): Promise<IDelegateManager | undefined> {\n return this.wallet.getDelegateManager();\n }\n\n /** @deprecated alias for @see ExpoWallet.getDelegateManager */\n getDelegatorManager(): Promise<IDelegateManager | undefined> {\n return this.wallet.getDelegateManager();\n }\n\n sendBitcoin(params: SendBitcoinParams): Promise<string> {\n return this.wallet.sendBitcoin(params);\n }\n\n settle(\n params?: SettleParams,\n eventCallback?: (event: SettlementEvent) => void,\n ): Promise<string> {\n return this.wallet.settle(params, eventCallback);\n }\n\n send(...recipients: [Recipient, ...Recipient[]]): Promise<string> {\n return this.wallet.send(...recipients);\n }\n\n get assetManager(): IAssetManager {\n return this.wallet.assetManager;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/wallet/expo/wallet.ts"],"names":[],"mappings":";;;;;;;;AA+DO,SAAS,8BAA8B,EAAA,EAAmB;AAC7D,EAAA,IAAI,CAAC,EAAA,IAAM,OAAO,EAAA,KAAO,QAAA,EAAU;AACnC,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,IAAI,UAAA,IAAc,EAAA,EAAI,OAAA,CAAQ,IAAA,CAAK,UAAU,CAAA;AAC7C,EAAA,IAAI,+BAA+B,EAAA,EAAI;AACnC,IAAA,OAAA,CAAQ,KAAK,2BAA2B,CAAA;AAAA,EAC5C;AACA,EAAA,IAAI,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC1B,EAAA,OAAA,CAAQ,IAAA;AAAA,IACJ,CAAA,kEAAA,EAAqE,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,2HAAA;AAAA,GAG3F;AACJ;AAuCO,IAAM,UAAA,GAAN,MAAM,WAAA,CAA8B;AAAA,EAS/B,WAAA,CACa,MAAA,EACA,SAAA,EACA,UAAA,EACA,MACjB,oBAAA,EACF;AALmB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAA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AEA,kBAAA,GAA0C;AACtC,IAAA,OAAO,IAAA,CAAK,OAAO,kBAAA,EAAmB;AAAA,EAC1C;AAAA,EAEA,kBAAA,GAAgD;AAC5C,IAAA,OAAO,IAAA,CAAK,OAAO,kBAAA,EAAmB;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,0BAAA,GAAsD;AAClD,IAAA,OAAO,IAAA,CAAK,OAAO,0BAAA,EAA2B;AAAA,EAClD;AAAA,EAEA,kBAAA,GAA4D;AACxD,IAAA,OAAO,IAAA,CAAK,OAAO,kBAAA,EAAmB;AAAA,EAC1C;AAAA;AAAA,EAGA,mBAAA,GAA6D;AACzD,IAAA,OAAO,IAAA,CAAK,OAAO,kBAAA,EAAmB;AAAA,EAC1C;AAAA,EAEA,YAAY,MAAA,EAA4C;AACpD,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,WAAA,CAAY,MAAM,CAAA;AAAA,EACzC;AAAA,EAEA,MAAA,CACI,QACA,aAAA,EACe;AACf,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO,MAAA,EAAQ,aAAa,CAAA;AAAA,EACnD;AAAA,EAEA,QAAQ,UAAA,EAA0D;AAC9D,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,GAAG,UAAU,CAAA;AAAA,EACzC;AAAA,EAEA,IAAI,YAAA,GAA8B;AAC9B,IAAA,OAAO,KAAK,MAAA,CAAO,YAAA;AAAA,EACvB;AACJ","file":"index.js","sourcesContent":["import { hex } from \"@scure/base\";\nimport { Wallet, type ProviderConnectionState } from \"../wallet\";\nimport type { Activity, ActivityRegistry } from \"../activity\";\nimport { RestArkProvider } from \"../../providers/ark\";\nimport type {\n IWallet,\n IAssetManager,\n WalletBalance,\n WalletConfig,\n SendBitcoinParams,\n SettleParams,\n GetVtxosFilter,\n ArkTransaction,\n ExtendedCoin,\n Recipient,\n} from \"..\";\nimport type { SettlementEvent } from \"../../providers/ark\";\nimport type { Identity } from \"../../identity\";\nimport type { IContractManager } from \"../../contracts/contractManager\";\nimport type { IDelegateManager } from \"../delegate\";\nimport type { TaskQueue, TaskItem } from \"../../worker/expo/taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../../worker/expo/taskRunner\";\nimport { runTasks } from \"../../worker/expo/taskRunner\";\nimport { contractPollProcessor, CONTRACT_POLL_TASK_TYPE } from \"../../worker/expo/processors\";\nimport { extendVirtualCoinForContract, getRandomId } from \"../utils\";\nimport type { PersistedBackgroundConfig } from \"./background\";\nimport type { AsyncStorageTaskQueue } from \"../../worker/expo/asyncStorageTaskQueue\";\nimport type { NormalizedExtendedVirtualCoin } from \"../vtxo\";\n\n/**\n * Background processing configuration for @see ExpoWallet.\n *\n * OS-level task registration is **not** part of this config — call\n * `registerExpoBackgroundTask` from `@arkade-os/sdk/wallet/expo/background`\n * explicitly. Splitting that step out keeps `/wallet/expo` free of the\n * `expo-task-manager` / `expo-background-task` dependencies, so\n * react-native-web and Node consumers can use `ExpoWallet` without\n * those native packages. See\n * https://github.com/arkade-os/ts-sdk/issues/486 for details.\n */\nexport interface ExpoBackgroundConfig {\n /** Persistence layer for foreground ↔ background handoff. */\n taskQueue: TaskQueue;\n /** Processors to run on each tick. Defaults to `[contractPollProcessor]`. */\n processors?: TaskProcessor[];\n /** If set, automatically polls at this interval (ms) while the app is in the foreground. */\n foregroundIntervalMs?: number;\n}\n\n/**\n * Configuration for @see ExpoWallet.setup.\n */\nexport interface ExpoWalletConfig extends WalletConfig {\n background: ExpoBackgroundConfig;\n}\n\n/**\n * Catches JS callers still passing the pre-fix-#486 fields: TypeScript\n * blocks these at compile time, but compiled JS silently dropped them\n * and consumers would never realize the OS task wasn't scheduled.\n *\n * @internal Exported for tests; not part of the public API surface.\n */\nexport function warnOnRemovedBackgroundFields(bg: unknown): void {\n if (!bg || typeof bg !== \"object\") return;\n const removed: string[] = [];\n if (\"taskName\" in bg) removed.push(\"taskName\");\n if (\"minimumBackgroundInterval\" in bg) {\n removed.push(\"minimumBackgroundInterval\");\n }\n if (removed.length === 0) return;\n console.warn(\n `[ark-sdk] ExpoWallet.setup: ignoring removed background field(s): ${removed.join(\", \")}. ` +\n 'OS-task registration moved to \"@arkade-os/sdk/wallet/expo/background\". ' +\n \"See https://github.com/arkade-os/ts-sdk/issues/486\",\n );\n}\n\n/**\n * Expo/React Native wallet with built-in background task processing.\n *\n * Wraps a standard @see Wallet and adds a lightweight task queue\n * for keeping contract/VTXO state fresh while the app is active and\n * across Expo BackgroundTask wakes.\n *\n * OS-level task registration is the consumer's responsibility — call\n * `registerExpoBackgroundTask` from\n * `@arkade-os/sdk/wallet/expo/background` after `setup()`. Keeping\n * registration out of `setup()` lets this entrypoint avoid pulling\n * `expo-task-manager` / `expo-background-task` into the `/wallet/expo`\n * bundle.\n *\n * @example\n * ```ts\n * import { ExpoWallet } from \"@arkade-os/sdk/wallet/expo\";\n * import { registerExpoBackgroundTask } from \"@arkade-os/sdk/wallet/expo/background\";\n * import { AsyncStorageTaskQueue } from \"@arkade-os/sdk/worker/expo\";\n *\n * const wallet = await ExpoWallet.setup({\n * identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),\n * arkProvider: new RestArkProvider(),\n * onchainProvider: new EsploraProvider(),\n * storage: { ... },\n * background: {\n * taskQueue: new AsyncStorageTaskQueue(AsyncStorage),\n * foregroundIntervalMs: 20_000,\n * },\n * });\n *\n * // Activate the OS scheduler (Expo Android/iOS only)\n * await registerExpoBackgroundTask(\"ark-background-poll\", { minimumInterval: 15 });\n *\n * const balance = await wallet.getBalance();\n * ```\n */\nexport class ExpoWallet implements IWallet {\n readonly identity: Identity;\n readonly arkProvider: Wallet[\"arkProvider\"];\n readonly indexerProvider: Wallet[\"indexerProvider\"];\n\n private foregroundIntervalId?: ReturnType<typeof setInterval>;\n private foregroundPollChain: Promise<void> = Promise.resolve();\n private cleared = false;\n\n private constructor(\n private readonly wallet: Wallet,\n private readonly taskQueue: TaskQueue,\n private readonly processors: TaskProcessor[],\n private readonly deps: TaskDependencies,\n foregroundIntervalMs?: number,\n ) {\n this.identity = wallet.identity;\n this.arkProvider = wallet.arkProvider;\n this.indexerProvider = wallet.indexerProvider;\n\n if (foregroundIntervalMs && foregroundIntervalMs > 0) {\n this.startForegroundPolling(foregroundIntervalMs);\n }\n }\n\n /**\n * Create an ExpoWallet with foreground/background queue handoff.\n *\n * 1. Creates the inner @see Wallet via `Wallet.create()`.\n * 2. Wires up processors (defaults to @see contractPollProcessor).\n * 3. Persists background config for the background handler (if the queue supports it).\n * 4. Seeds the task queue with a `contract-poll` task.\n * 5. Starts the foreground interval if `foregroundIntervalMs` is set.\n *\n * OS-level scheduling lives in\n * `@arkade-os/sdk/wallet/expo/background` and is invoked separately\n * by the consumer.\n */\n static async setup(config: ExpoWalletConfig): Promise<ExpoWallet> {\n warnOnRemovedBackgroundFields(config.background);\n\n const wallet = await Wallet.create(config);\n\n const processors = config.background.processors ?? [contractPollProcessor];\n\n const deps: TaskDependencies = {\n walletRepository: wallet.walletRepository,\n contractRepository: wallet.contractRepository,\n indexerProvider: wallet.indexerProvider,\n arkProvider: wallet.arkProvider,\n extendVtxo: (vtxo, contract) => extendVirtualCoinForContract(vtxo, contract),\n };\n\n const { taskQueue } = config.background;\n\n // Persist wallet params so the background handler can rehydrate\n // without a network call. Only works with AsyncStorageTaskQueue.\n if (\"persistConfig\" in taskQueue) {\n const arkServerUrl =\n config.arkServerUrl ||\n (wallet.arkProvider instanceof RestArkProvider\n ? wallet.arkProvider.serverUrl\n : undefined);\n\n if (arkServerUrl) {\n const timelock = wallet.offchainTapscript.options.csvTimelock;\n\n const bgConfig: PersistedBackgroundConfig = {\n arkServerUrl,\n pubkeyHex: hex.encode(wallet.offchainTapscript.options.pubKey),\n serverPubKeyHex: hex.encode(wallet.offchainTapscript.options.serverPubKey),\n exitTimelockValue: timelock.value.toString(),\n exitTimelockType: timelock.type,\n };\n\n await (taskQueue as AsyncStorageTaskQueue).persistConfig(bgConfig);\n }\n }\n\n const expoWallet = new ExpoWallet(\n wallet,\n taskQueue,\n processors,\n deps,\n config.background.foregroundIntervalMs,\n );\n\n // Seed the queue so the first tick (or background wake) has work to do\n await expoWallet.seedContractPollTask();\n\n return expoWallet;\n }\n\n // ── Foreground polling ───────────────────────────────────────────\n\n private startForegroundPolling(intervalMs: number): void {\n this.foregroundIntervalId = setInterval(() => {\n // Serialize polls so clear() can await the in-flight one before wiping.\n this.foregroundPollChain = this.foregroundPollChain\n .then(() => this.runForegroundPoll())\n .catch(console.error);\n }, intervalMs);\n }\n\n private async runForegroundPoll(): Promise<void> {\n if (this.cleared) return;\n\n await runTasks(this.taskQueue, this.processors, this.deps);\n\n // Consume results immediately (no background handoff needed)\n const results = await this.taskQueue.getResults();\n if (results.length > 0) {\n await this.taskQueue.acknowledgeResults(results.map((r) => r.id));\n }\n\n if (this.cleared) return;\n\n // Re-seed for the next tick\n await this.seedContractPollTask();\n }\n\n private async seedContractPollTask(): Promise<void> {\n const existing = await this.taskQueue.getTasks(CONTRACT_POLL_TASK_TYPE);\n if (existing.length > 0) return;\n\n const task: TaskItem = {\n id: getRandomId(),\n type: CONTRACT_POLL_TASK_TYPE,\n data: {},\n createdAt: Date.now(),\n };\n await this.taskQueue.addTask(task);\n }\n\n private async removeContractPollTasks(): Promise<void> {\n const tasks = await this.taskQueue.getTasks(CONTRACT_POLL_TASK_TYPE);\n for (const task of tasks) {\n await this.taskQueue.removeTask(task.id);\n }\n }\n\n // ── Lifecycle ────────────────────────────────────────────────────\n\n /**\n * Stop foreground polling and dispose the inner wallet.\n *\n * Does **not** unregister the OS background task — call\n * `unregisterExpoBackgroundTask` from\n * `@arkade-os/sdk/wallet/expo/background` yourself, matching the\n * explicit `register` step.\n */\n async dispose(): Promise<void> {\n if (this.foregroundIntervalId) {\n clearInterval(this.foregroundIntervalId);\n this.foregroundIntervalId = undefined;\n }\n\n await this.wallet.dispose();\n }\n\n /**\n * Stop foreground polling and wipe all locally persisted wallet data.\n * Does not unregister the OS background task or persisted queue config.\n */\n async clear(): Promise<void> {\n this.cleared = true;\n\n if (this.foregroundIntervalId) {\n clearInterval(this.foregroundIntervalId);\n this.foregroundIntervalId = undefined;\n }\n\n await this.foregroundPollChain;\n await this.wallet.clear();\n await this.removeContractPollTasks();\n }\n\n // ── IWallet delegation ───────────────────────────────────────────\n\n getAddress(): Promise<string> {\n return this.wallet.getAddress();\n }\n\n getBoardingAddress(): Promise<string> {\n return this.wallet.getBoardingAddress();\n }\n\n getBalance(): Promise<WalletBalance> {\n return this.wallet.getBalance();\n }\n\n getVtxos(filter?: GetVtxosFilter): Promise<NormalizedExtendedVirtualCoin[]> {\n return this.wallet.getVtxos(filter);\n }\n\n getBoardingUtxos(): Promise<ExtendedCoin[]> {\n return this.wallet.getBoardingUtxos();\n }\n\n getTransactionHistory(): Promise<ArkTransaction[]> {\n return this.wallet.getTransactionHistory();\n }\n\n get activity(): ActivityRegistry {\n return this.wallet.activity;\n }\n\n getActivityHistory(): Promise<Activity[]> {\n return this.wallet.getActivityHistory();\n }\n\n getContractManager(): Promise<IContractManager> {\n return this.wallet.getContractManager();\n }\n\n /**\n * Wallet-level provider-connection freshness, delegated to the wrapped\n * in-process wallet. Synchronous because the Expo foreground wallet is\n * in-process (no worker boundary). Foreground-only: it does not imply any\n * background task can read live foreground state.\n */\n getProviderConnectionState(): ProviderConnectionState {\n return this.wallet.getProviderConnectionState();\n }\n\n getDelegateManager(): Promise<IDelegateManager | undefined> {\n return this.wallet.getDelegateManager();\n }\n\n /** @deprecated alias for @see ExpoWallet.getDelegateManager */\n getDelegatorManager(): Promise<IDelegateManager | undefined> {\n return this.wallet.getDelegateManager();\n }\n\n sendBitcoin(params: SendBitcoinParams): Promise<string> {\n return this.wallet.sendBitcoin(params);\n }\n\n settle(\n params?: SettleParams,\n eventCallback?: (event: SettlementEvent) => void,\n ): Promise<string> {\n return this.wallet.settle(params, eventCallback);\n }\n\n send(...recipients: [Recipient, ...Recipient[]]): Promise<string> {\n return this.wallet.send(...recipients);\n }\n\n get assetManager(): IAssetManager {\n return this.wallet.assetManager;\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Transaction } from '@scure/btc-signer';
|
|
2
2
|
import { Bytes } from '@scure/btc-signer/utils.js';
|
|
3
|
-
import { J as BatchStartedEvent, K as TreeSigningStartedEvent, L as TxTree, M as TreeNoncesEvent,
|
|
3
|
+
import { J as BatchStartedEvent, K as TreeSigningStartedEvent, L as TxTree, M as TreeNoncesEvent, P as BatchFinalizationEvent, Q as BatchFinalizedEvent, U as BatchFailedEvent, X as TreeTxEvent, Y as TreeSignatureEvent, i as SettlementEvent, b as WalletConfig, W as WalletRepository, C as ContractRepository, Z as DescriptorProvider, f as IContractManager, _ as IReadonlyWallet, $ as ReadonlyIdentity, a0 as Network, a1 as OnchainProvider, o as IndexerProvider, a2 as DelegateProvider, a3 as ReadonlyWalletConfig, x as IntentRepository, B as VirtualTxRepository, a4 as ExitCaptureMode, a5 as ExitDataSource, p as RelativeTimelock, d as ActivityRegistry, a6 as IReadonlyAssetManager, a7 as ContractSyncState, n as ArkProvider, a8 as NetworkName, a9 as ArkInfo, aa as ArkAddress, c as WalletBalance, G as GetVtxosFilter, N as NormalizedExtendedVirtualCoin, A as ArkTransaction, e as Activity, E as ExtendedCoin, ab as Coin, t as ExtendedVirtualCoin, ac as ContractManager, I as IWallet, a as Identity, ad as CSVMultisigTapscript, ae as SettlementConfig, j as IAssetManager, af as VtxoManager, g as IDelegateManager, S as SendBitcoinParams, h as SettleParams, R as Recipient, ag as SignerSession, ah as SignedIntent, ai as Intent, aj as TimeHeight } from './ark-CjE0KkGp.js';
|
|
4
4
|
import { TransactionOutput } from '@scure/btc-signer/psbt.js';
|
|
5
|
-
import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-
|
|
5
|
+
import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-DhGZk1r2.js';
|
|
6
6
|
|
|
7
7
|
declare class ArkError extends Error {
|
|
8
8
|
readonly code: number;
|
|
@@ -486,6 +486,62 @@ interface BoardingUtxoGroup {
|
|
|
486
486
|
csvTimelock: RelativeTimelock;
|
|
487
487
|
coins: ExtendedCoin[];
|
|
488
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Why a VTXO at an arkadeCash address could not be swept by {@link Wallet.claimCash}.
|
|
491
|
+
*
|
|
492
|
+
* - `swept` — the server swept the batch at expiry. Recoverable in principle,
|
|
493
|
+
* but only through a settlement, which the thin sweep cannot do.
|
|
494
|
+
* - `subdust` — below dust, so it sits at an OP_RETURN script with no spendable
|
|
495
|
+
* leaf. Unspendable as cash; `createCash` prevents minting these.
|
|
496
|
+
* - `already-spent` — someone else claimed it first.
|
|
497
|
+
* - `has-assets` — asset-bearing; the BTC-only sweep would burn the assets.
|
|
498
|
+
* - `sweep-failed` — spendable, but its own sweep was rejected.
|
|
499
|
+
*/
|
|
500
|
+
type ArkadeCashUnclaimedReason = "swept" | "subdust" | "already-spent" | "has-assets" | "sweep-failed";
|
|
501
|
+
/** A VTXO {@link Wallet.claimCash} left behind, with the reason why. */
|
|
502
|
+
interface ArkadeCashUnclaimedVtxo {
|
|
503
|
+
txid: string;
|
|
504
|
+
vout: number;
|
|
505
|
+
/** Value in satoshis. */
|
|
506
|
+
value: number;
|
|
507
|
+
reason: ArkadeCashUnclaimedReason;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Outcome of {@link Wallet.claimCash}: what was swept, and what was not.
|
|
511
|
+
*
|
|
512
|
+
* The shape is open — further buckets may be added alongside `unclaimed` as
|
|
513
|
+
* more of the non-sweepable states become claimable.
|
|
514
|
+
*/
|
|
515
|
+
interface ArkadeCashClaimResult {
|
|
516
|
+
/** Satoshis swept to this wallet. */
|
|
517
|
+
swept: number;
|
|
518
|
+
unclaimed: {
|
|
519
|
+
/** Satoshis left behind. */
|
|
520
|
+
amount: number;
|
|
521
|
+
vtxos: ArkadeCashUnclaimedVtxo[];
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Thrown when {@link Wallet.createCash} funds the note but its `send` call
|
|
526
|
+
* fails after the transaction may already have been submitted.
|
|
527
|
+
*
|
|
528
|
+
* The whole value of the note lives in `cash`: it carries the private key that
|
|
529
|
+
* controls the funded output. If `send` committed and this error is discarded,
|
|
530
|
+
* the sats are stranded at an address only this token can reach. Callers that
|
|
531
|
+
* cannot rule out a post-submit failure must persist `cash` — passing it to
|
|
532
|
+
* {@link Wallet.claimCash} recovers the funds whether or not the send landed.
|
|
533
|
+
*/
|
|
534
|
+
declare class ArkadeCashCreateError extends Error {
|
|
535
|
+
/** The encoded arkadeCash token controlling the funded output. */
|
|
536
|
+
readonly cash: string;
|
|
537
|
+
/** The original failure from `send`. */
|
|
538
|
+
readonly cause: unknown;
|
|
539
|
+
constructor(
|
|
540
|
+
/** The encoded arkadeCash token controlling the funded output. */
|
|
541
|
+
cash: string,
|
|
542
|
+
/** The original failure from `send`. */
|
|
543
|
+
cause: unknown);
|
|
544
|
+
}
|
|
489
545
|
/**
|
|
490
546
|
* Freshness of the wallet's provider-backed sync, composed from the boot
|
|
491
547
|
* server-info source and the contract-manager's indexer-sync health. It
|
|
@@ -737,7 +793,7 @@ declare class ReadonlyWallet implements IReadonlyWallet {
|
|
|
737
793
|
*
|
|
738
794
|
* @param filter - Optional flags controlling whether recoverable or unrolled VTXOs are included
|
|
739
795
|
*/
|
|
740
|
-
getVtxos(filter?: GetVtxosFilter): Promise<
|
|
796
|
+
getVtxos(filter?: GetVtxosFilter): Promise<NormalizedExtendedVirtualCoin[]>;
|
|
741
797
|
/**
|
|
742
798
|
* Outpoints of VTXOs whose deprecated signer is past its cutoff (EXPIRED) and
|
|
743
799
|
* which have not yet been swept — unspendable until they recover. Offline:
|
|
@@ -1200,9 +1256,9 @@ declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
1200
1256
|
* renewal / offboard) is not a board and leaves the boarding address
|
|
1201
1257
|
* untouched.
|
|
1202
1258
|
*
|
|
1203
|
-
* Boarding inputs are the non-VTXO coins (no `
|
|
1259
|
+
* Boarding inputs are the non-VTXO coins (no `script`), the same
|
|
1204
1260
|
* discriminator {@link handleSettlementFinalizationEvent} uses; the
|
|
1205
|
-
* `typeof` guard skips arknote
|
|
1261
|
+
* `typeof` guard skips the arknote strings settle also accepts.
|
|
1206
1262
|
*
|
|
1207
1263
|
* No-ops for static / `auto` wallets (no descriptor provider — boarding
|
|
1208
1264
|
* stays on its fixed index-0 address). Best-effort and non-fatal: the
|
|
@@ -1264,6 +1320,73 @@ declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
1264
1320
|
}>;
|
|
1265
1321
|
private hasPendingTxFlag;
|
|
1266
1322
|
private setPendingTxFlag;
|
|
1323
|
+
/**
|
|
1324
|
+
* Create an ArkadeCash bearer instrument.
|
|
1325
|
+
*
|
|
1326
|
+
* Generates a fresh keypair, sends the specified amount to a DefaultVtxo
|
|
1327
|
+
* controlled by the new key, and returns the encoded arkadeCash string.
|
|
1328
|
+
* The receiver can claim the funds using `claimCash()` without ever
|
|
1329
|
+
* sharing their address.
|
|
1330
|
+
*
|
|
1331
|
+
* ArkadeCash is a short-lived instrument: it carries a private key, so it is
|
|
1332
|
+
* meant to be handed over and claimed promptly, not held. A note left
|
|
1333
|
+
* unclaimed past its batch expiry is swept by the server and `claimCash`
|
|
1334
|
+
* can only report it, not move it.
|
|
1335
|
+
*
|
|
1336
|
+
* @param amount - Amount in satoshis to send. Must be a whole number of
|
|
1337
|
+
* sats at or above the dust threshold — a below-dust amount would mint an
|
|
1338
|
+
* OP_RETURN output that is unspendable as cash.
|
|
1339
|
+
* @returns The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
1340
|
+
*/
|
|
1341
|
+
createCash(amount: number): Promise<string>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Claim an ArkadeCash bearer instrument: sweep what can be swept, report the
|
|
1344
|
+
* rest.
|
|
1345
|
+
*
|
|
1346
|
+
* Every spendable VTXO at the arkadeCash address is swept to this wallet in
|
|
1347
|
+
* its own offchain transaction, signed with the key carried by the arkadeCash
|
|
1348
|
+
* string. Nothing is ever persisted: no contract is imported, and the
|
|
1349
|
+
* arkadeCash key is not stored. Anything that cannot be swept — server-swept,
|
|
1350
|
+
* subdust, already claimed, or asset-bearing — is returned in `unclaimed`
|
|
1351
|
+
* with a per-VTXO reason and otherwise ignored.
|
|
1352
|
+
*
|
|
1353
|
+
* The arkadeCash string is the recovery token: a claim interrupted between
|
|
1354
|
+
* submit and finalize is completed by simply re-running `claimCash`, which
|
|
1355
|
+
* drains any pending arkadeCash transaction on the server before sweeping.
|
|
1356
|
+
*
|
|
1357
|
+
* @param cashStr - The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
1358
|
+
* @returns The swept total and the report of what was left behind. The
|
|
1359
|
+
* shape is open: further buckets may be added alongside `unclaimed`.
|
|
1360
|
+
*/
|
|
1361
|
+
claimCash(cashStr: string): Promise<ArkadeCashClaimResult>;
|
|
1362
|
+
/**
|
|
1363
|
+
* Split the VTXOs at an arkadeCash address into the ones the thin sweep can
|
|
1364
|
+
* move and the ones it can only report.
|
|
1365
|
+
*/
|
|
1366
|
+
private classifyCashVtxos;
|
|
1367
|
+
/** Read every page of an unfiltered VTXO query for the given scripts. */
|
|
1368
|
+
private fetchAllVtxos;
|
|
1369
|
+
/**
|
|
1370
|
+
* Complete any sweep a previous `claimCash` registered but never finalized.
|
|
1371
|
+
* A thin variant of {@link finalizePendingTxs}, scoped to the arkadeCash key:
|
|
1372
|
+
* the intent is signed with it, and so are the returned checkpoints.
|
|
1373
|
+
*
|
|
1374
|
+
* A drained sweep is not automatically *ours*. Whoever registered it chose
|
|
1375
|
+
* the destination, so a tx a different claimer left half-finished pays that
|
|
1376
|
+
* claimer — finalizing it is still right (the input is spent either way, and
|
|
1377
|
+
* completing it unsticks the funds), but only the value it actually pays to
|
|
1378
|
+
* `myPkScript` may be counted as claimed here.
|
|
1379
|
+
*
|
|
1380
|
+
* @param vtxos - VTXOs at the arkadeCash contract's own pkScript, spent ones
|
|
1381
|
+
* included (a registered sweep marks its input spent). Any other outpoint —
|
|
1382
|
+
* subdust above all — would make the proof invalid, since it describes every
|
|
1383
|
+
* input by that pkScript.
|
|
1384
|
+
* @returns The number of pending txs finalized, the sats among them paid to
|
|
1385
|
+
* this wallet, and the outpoints those txs consumed to pay it.
|
|
1386
|
+
*/
|
|
1387
|
+
private finalizePendingCashTxs;
|
|
1388
|
+
/** Sum the outputs of an ark tx PSBT that pay the given scriptPubKey. */
|
|
1389
|
+
private arkTxAmountPaidTo;
|
|
1267
1390
|
/**
|
|
1268
1391
|
* Send BTC and/or assets to one or more recipients.
|
|
1269
1392
|
*
|
|
@@ -1306,7 +1429,7 @@ declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
1306
1429
|
* there is no separate change output. It records no `TxSent` history — the
|
|
1307
1430
|
* funds never leave the wallet.
|
|
1308
1431
|
*/
|
|
1309
|
-
sendSelectedVtxosToSelf(inputs: ExtendedVirtualCoin[]): Promise<string>;
|
|
1432
|
+
sendSelectedVtxosToSelf(inputs: ExtendedVirtualCoin[], now?: TimeHeight): Promise<string>;
|
|
1310
1433
|
/**
|
|
1311
1434
|
* Build an offchain transaction from the given inputs and outputs,
|
|
1312
1435
|
* sign it, submit to the Arkade provider, and finalize.
|
|
@@ -1336,4 +1459,4 @@ declare function selectVirtualCoins(coins: ExtendedVirtualCoin[], targetAmount:
|
|
|
1336
1459
|
*/
|
|
1337
1460
|
declare function waitForIncomingFunds(wallet: Wallet): Promise<IncomingFunds>;
|
|
1338
1461
|
|
|
1339
|
-
export { ArkError as A, Batch as B, type IncomingFunds as I, type ProviderConnectionState as P, ReadonlyWallet as R, type ServerInfoSource as S, Wallet as W, type ReceiveRotatorFactory as a, type ReceiveRotatorBootOpts as b, type ReceiveRotatorBoot as c, ArkErrorName as d, type
|
|
1462
|
+
export { ArkError as A, Batch as B, type IncomingFunds as I, type ProviderConnectionState as P, ReadonlyWallet as R, type ServerInfoSource as S, Wallet as W, type ReceiveRotatorFactory as a, type ReceiveRotatorBootOpts as b, type ReceiveRotatorBoot as c, ArkErrorName as d, type ArkadeCashClaimResult as e, ArkadeCashCreateError as f, type ArkadeCashUnclaimedReason as g, type ArkadeCashUnclaimedVtxo as h, type BoardingUtxoGroup as i, type ProviderKind as j, ProviderUnavailableError as k, isArkError as l, maybeArkError as m, selectVirtualCoins as s, waitForIncomingFunds as w };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Transaction } from '@scure/btc-signer';
|
|
2
2
|
import { Bytes } from '@scure/btc-signer/utils.js';
|
|
3
|
-
import { J as BatchStartedEvent, K as TreeSigningStartedEvent, L as TxTree, M as TreeNoncesEvent,
|
|
3
|
+
import { J as BatchStartedEvent, K as TreeSigningStartedEvent, L as TxTree, M as TreeNoncesEvent, P as BatchFinalizationEvent, Q as BatchFinalizedEvent, U as BatchFailedEvent, X as TreeTxEvent, Y as TreeSignatureEvent, i as SettlementEvent, b as WalletConfig, W as WalletRepository, C as ContractRepository, Z as DescriptorProvider, f as IContractManager, _ as IReadonlyWallet, $ as ReadonlyIdentity, a0 as Network, a1 as OnchainProvider, o as IndexerProvider, a2 as DelegateProvider, a3 as ReadonlyWalletConfig, x as IntentRepository, B as VirtualTxRepository, a4 as ExitCaptureMode, a5 as ExitDataSource, p as RelativeTimelock, d as ActivityRegistry, a6 as IReadonlyAssetManager, a7 as ContractSyncState, n as ArkProvider, a8 as NetworkName, a9 as ArkInfo, aa as ArkAddress, c as WalletBalance, G as GetVtxosFilter, N as NormalizedExtendedVirtualCoin, A as ArkTransaction, e as Activity, E as ExtendedCoin, ab as Coin, t as ExtendedVirtualCoin, ac as ContractManager, I as IWallet, a as Identity, ad as CSVMultisigTapscript, ae as SettlementConfig, j as IAssetManager, af as VtxoManager, g as IDelegateManager, S as SendBitcoinParams, h as SettleParams, R as Recipient, ag as SignerSession, ah as SignedIntent, ai as Intent, aj as TimeHeight } from './ark-CjE0KkGp.cjs';
|
|
4
4
|
import { TransactionOutput } from '@scure/btc-signer/psbt.js';
|
|
5
|
-
import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-
|
|
5
|
+
import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-D3dY-2vS.cjs';
|
|
6
6
|
|
|
7
7
|
declare class ArkError extends Error {
|
|
8
8
|
readonly code: number;
|
|
@@ -486,6 +486,62 @@ interface BoardingUtxoGroup {
|
|
|
486
486
|
csvTimelock: RelativeTimelock;
|
|
487
487
|
coins: ExtendedCoin[];
|
|
488
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Why a VTXO at an arkadeCash address could not be swept by {@link Wallet.claimCash}.
|
|
491
|
+
*
|
|
492
|
+
* - `swept` — the server swept the batch at expiry. Recoverable in principle,
|
|
493
|
+
* but only through a settlement, which the thin sweep cannot do.
|
|
494
|
+
* - `subdust` — below dust, so it sits at an OP_RETURN script with no spendable
|
|
495
|
+
* leaf. Unspendable as cash; `createCash` prevents minting these.
|
|
496
|
+
* - `already-spent` — someone else claimed it first.
|
|
497
|
+
* - `has-assets` — asset-bearing; the BTC-only sweep would burn the assets.
|
|
498
|
+
* - `sweep-failed` — spendable, but its own sweep was rejected.
|
|
499
|
+
*/
|
|
500
|
+
type ArkadeCashUnclaimedReason = "swept" | "subdust" | "already-spent" | "has-assets" | "sweep-failed";
|
|
501
|
+
/** A VTXO {@link Wallet.claimCash} left behind, with the reason why. */
|
|
502
|
+
interface ArkadeCashUnclaimedVtxo {
|
|
503
|
+
txid: string;
|
|
504
|
+
vout: number;
|
|
505
|
+
/** Value in satoshis. */
|
|
506
|
+
value: number;
|
|
507
|
+
reason: ArkadeCashUnclaimedReason;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Outcome of {@link Wallet.claimCash}: what was swept, and what was not.
|
|
511
|
+
*
|
|
512
|
+
* The shape is open — further buckets may be added alongside `unclaimed` as
|
|
513
|
+
* more of the non-sweepable states become claimable.
|
|
514
|
+
*/
|
|
515
|
+
interface ArkadeCashClaimResult {
|
|
516
|
+
/** Satoshis swept to this wallet. */
|
|
517
|
+
swept: number;
|
|
518
|
+
unclaimed: {
|
|
519
|
+
/** Satoshis left behind. */
|
|
520
|
+
amount: number;
|
|
521
|
+
vtxos: ArkadeCashUnclaimedVtxo[];
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Thrown when {@link Wallet.createCash} funds the note but its `send` call
|
|
526
|
+
* fails after the transaction may already have been submitted.
|
|
527
|
+
*
|
|
528
|
+
* The whole value of the note lives in `cash`: it carries the private key that
|
|
529
|
+
* controls the funded output. If `send` committed and this error is discarded,
|
|
530
|
+
* the sats are stranded at an address only this token can reach. Callers that
|
|
531
|
+
* cannot rule out a post-submit failure must persist `cash` — passing it to
|
|
532
|
+
* {@link Wallet.claimCash} recovers the funds whether or not the send landed.
|
|
533
|
+
*/
|
|
534
|
+
declare class ArkadeCashCreateError extends Error {
|
|
535
|
+
/** The encoded arkadeCash token controlling the funded output. */
|
|
536
|
+
readonly cash: string;
|
|
537
|
+
/** The original failure from `send`. */
|
|
538
|
+
readonly cause: unknown;
|
|
539
|
+
constructor(
|
|
540
|
+
/** The encoded arkadeCash token controlling the funded output. */
|
|
541
|
+
cash: string,
|
|
542
|
+
/** The original failure from `send`. */
|
|
543
|
+
cause: unknown);
|
|
544
|
+
}
|
|
489
545
|
/**
|
|
490
546
|
* Freshness of the wallet's provider-backed sync, composed from the boot
|
|
491
547
|
* server-info source and the contract-manager's indexer-sync health. It
|
|
@@ -737,7 +793,7 @@ declare class ReadonlyWallet implements IReadonlyWallet {
|
|
|
737
793
|
*
|
|
738
794
|
* @param filter - Optional flags controlling whether recoverable or unrolled VTXOs are included
|
|
739
795
|
*/
|
|
740
|
-
getVtxos(filter?: GetVtxosFilter): Promise<
|
|
796
|
+
getVtxos(filter?: GetVtxosFilter): Promise<NormalizedExtendedVirtualCoin[]>;
|
|
741
797
|
/**
|
|
742
798
|
* Outpoints of VTXOs whose deprecated signer is past its cutoff (EXPIRED) and
|
|
743
799
|
* which have not yet been swept — unspendable until they recover. Offline:
|
|
@@ -1200,9 +1256,9 @@ declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
1200
1256
|
* renewal / offboard) is not a board and leaves the boarding address
|
|
1201
1257
|
* untouched.
|
|
1202
1258
|
*
|
|
1203
|
-
* Boarding inputs are the non-VTXO coins (no `
|
|
1259
|
+
* Boarding inputs are the non-VTXO coins (no `script`), the same
|
|
1204
1260
|
* discriminator {@link handleSettlementFinalizationEvent} uses; the
|
|
1205
|
-
* `typeof` guard skips arknote
|
|
1261
|
+
* `typeof` guard skips the arknote strings settle also accepts.
|
|
1206
1262
|
*
|
|
1207
1263
|
* No-ops for static / `auto` wallets (no descriptor provider — boarding
|
|
1208
1264
|
* stays on its fixed index-0 address). Best-effort and non-fatal: the
|
|
@@ -1264,6 +1320,73 @@ declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
1264
1320
|
}>;
|
|
1265
1321
|
private hasPendingTxFlag;
|
|
1266
1322
|
private setPendingTxFlag;
|
|
1323
|
+
/**
|
|
1324
|
+
* Create an ArkadeCash bearer instrument.
|
|
1325
|
+
*
|
|
1326
|
+
* Generates a fresh keypair, sends the specified amount to a DefaultVtxo
|
|
1327
|
+
* controlled by the new key, and returns the encoded arkadeCash string.
|
|
1328
|
+
* The receiver can claim the funds using `claimCash()` without ever
|
|
1329
|
+
* sharing their address.
|
|
1330
|
+
*
|
|
1331
|
+
* ArkadeCash is a short-lived instrument: it carries a private key, so it is
|
|
1332
|
+
* meant to be handed over and claimed promptly, not held. A note left
|
|
1333
|
+
* unclaimed past its batch expiry is swept by the server and `claimCash`
|
|
1334
|
+
* can only report it, not move it.
|
|
1335
|
+
*
|
|
1336
|
+
* @param amount - Amount in satoshis to send. Must be a whole number of
|
|
1337
|
+
* sats at or above the dust threshold — a below-dust amount would mint an
|
|
1338
|
+
* OP_RETURN output that is unspendable as cash.
|
|
1339
|
+
* @returns The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
1340
|
+
*/
|
|
1341
|
+
createCash(amount: number): Promise<string>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Claim an ArkadeCash bearer instrument: sweep what can be swept, report the
|
|
1344
|
+
* rest.
|
|
1345
|
+
*
|
|
1346
|
+
* Every spendable VTXO at the arkadeCash address is swept to this wallet in
|
|
1347
|
+
* its own offchain transaction, signed with the key carried by the arkadeCash
|
|
1348
|
+
* string. Nothing is ever persisted: no contract is imported, and the
|
|
1349
|
+
* arkadeCash key is not stored. Anything that cannot be swept — server-swept,
|
|
1350
|
+
* subdust, already claimed, or asset-bearing — is returned in `unclaimed`
|
|
1351
|
+
* with a per-VTXO reason and otherwise ignored.
|
|
1352
|
+
*
|
|
1353
|
+
* The arkadeCash string is the recovery token: a claim interrupted between
|
|
1354
|
+
* submit and finalize is completed by simply re-running `claimCash`, which
|
|
1355
|
+
* drains any pending arkadeCash transaction on the server before sweeping.
|
|
1356
|
+
*
|
|
1357
|
+
* @param cashStr - The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
1358
|
+
* @returns The swept total and the report of what was left behind. The
|
|
1359
|
+
* shape is open: further buckets may be added alongside `unclaimed`.
|
|
1360
|
+
*/
|
|
1361
|
+
claimCash(cashStr: string): Promise<ArkadeCashClaimResult>;
|
|
1362
|
+
/**
|
|
1363
|
+
* Split the VTXOs at an arkadeCash address into the ones the thin sweep can
|
|
1364
|
+
* move and the ones it can only report.
|
|
1365
|
+
*/
|
|
1366
|
+
private classifyCashVtxos;
|
|
1367
|
+
/** Read every page of an unfiltered VTXO query for the given scripts. */
|
|
1368
|
+
private fetchAllVtxos;
|
|
1369
|
+
/**
|
|
1370
|
+
* Complete any sweep a previous `claimCash` registered but never finalized.
|
|
1371
|
+
* A thin variant of {@link finalizePendingTxs}, scoped to the arkadeCash key:
|
|
1372
|
+
* the intent is signed with it, and so are the returned checkpoints.
|
|
1373
|
+
*
|
|
1374
|
+
* A drained sweep is not automatically *ours*. Whoever registered it chose
|
|
1375
|
+
* the destination, so a tx a different claimer left half-finished pays that
|
|
1376
|
+
* claimer — finalizing it is still right (the input is spent either way, and
|
|
1377
|
+
* completing it unsticks the funds), but only the value it actually pays to
|
|
1378
|
+
* `myPkScript` may be counted as claimed here.
|
|
1379
|
+
*
|
|
1380
|
+
* @param vtxos - VTXOs at the arkadeCash contract's own pkScript, spent ones
|
|
1381
|
+
* included (a registered sweep marks its input spent). Any other outpoint —
|
|
1382
|
+
* subdust above all — would make the proof invalid, since it describes every
|
|
1383
|
+
* input by that pkScript.
|
|
1384
|
+
* @returns The number of pending txs finalized, the sats among them paid to
|
|
1385
|
+
* this wallet, and the outpoints those txs consumed to pay it.
|
|
1386
|
+
*/
|
|
1387
|
+
private finalizePendingCashTxs;
|
|
1388
|
+
/** Sum the outputs of an ark tx PSBT that pay the given scriptPubKey. */
|
|
1389
|
+
private arkTxAmountPaidTo;
|
|
1267
1390
|
/**
|
|
1268
1391
|
* Send BTC and/or assets to one or more recipients.
|
|
1269
1392
|
*
|
|
@@ -1306,7 +1429,7 @@ declare class Wallet extends ReadonlyWallet implements IWallet {
|
|
|
1306
1429
|
* there is no separate change output. It records no `TxSent` history — the
|
|
1307
1430
|
* funds never leave the wallet.
|
|
1308
1431
|
*/
|
|
1309
|
-
sendSelectedVtxosToSelf(inputs: ExtendedVirtualCoin[]): Promise<string>;
|
|
1432
|
+
sendSelectedVtxosToSelf(inputs: ExtendedVirtualCoin[], now?: TimeHeight): Promise<string>;
|
|
1310
1433
|
/**
|
|
1311
1434
|
* Build an offchain transaction from the given inputs and outputs,
|
|
1312
1435
|
* sign it, submit to the Arkade provider, and finalize.
|
|
@@ -1336,4 +1459,4 @@ declare function selectVirtualCoins(coins: ExtendedVirtualCoin[], targetAmount:
|
|
|
1336
1459
|
*/
|
|
1337
1460
|
declare function waitForIncomingFunds(wallet: Wallet): Promise<IncomingFunds>;
|
|
1338
1461
|
|
|
1339
|
-
export { ArkError as A, Batch as B, type IncomingFunds as I, type ProviderConnectionState as P, ReadonlyWallet as R, type ServerInfoSource as S, Wallet as W, type ReceiveRotatorFactory as a, type ReceiveRotatorBootOpts as b, type ReceiveRotatorBoot as c, ArkErrorName as d, type
|
|
1462
|
+
export { ArkError as A, Batch as B, type IncomingFunds as I, type ProviderConnectionState as P, ReadonlyWallet as R, type ServerInfoSource as S, Wallet as W, type ReceiveRotatorFactory as a, type ReceiveRotatorBootOpts as b, type ReceiveRotatorBoot as c, ArkErrorName as d, type ArkadeCashClaimResult as e, ArkadeCashCreateError as f, type ArkadeCashUnclaimedReason as g, type ArkadeCashUnclaimedVtxo as h, type BoardingUtxoGroup as i, type ProviderKind as j, ProviderUnavailableError as k, isArkError as l, maybeArkError as m, selectVirtualCoins as s, waitForIncomingFunds as w };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
5
|
-
require('../../chunk-
|
|
6
|
-
require('../../chunk-
|
|
7
|
-
require('../../chunk-
|
|
3
|
+
var chunkSYDANBJI_cjs = require('../../chunk-SYDANBJI.cjs');
|
|
4
|
+
require('../../chunk-ENZ4YPR2.cjs');
|
|
5
|
+
require('../../chunk-EB3ALGTM.cjs');
|
|
6
|
+
require('../../chunk-5XMVTK5S.cjs');
|
|
7
|
+
require('../../chunk-7TXSPRN5.cjs');
|
|
8
8
|
require('../../chunk-5BLDMQED.cjs');
|
|
9
9
|
|
|
10
10
|
// src/worker/expo/taskQueue.ts
|
|
@@ -121,19 +121,19 @@ var AsyncStorageTaskQueue = class {
|
|
|
121
121
|
|
|
122
122
|
Object.defineProperty(exports, "CONTRACT_POLL_TASK_TYPE", {
|
|
123
123
|
enumerable: true,
|
|
124
|
-
get: function () { return
|
|
124
|
+
get: function () { return chunkSYDANBJI_cjs.CONTRACT_POLL_TASK_TYPE; }
|
|
125
125
|
});
|
|
126
126
|
Object.defineProperty(exports, "contractPollProcessor", {
|
|
127
127
|
enumerable: true,
|
|
128
|
-
get: function () { return
|
|
128
|
+
get: function () { return chunkSYDANBJI_cjs.contractPollProcessor; }
|
|
129
129
|
});
|
|
130
130
|
Object.defineProperty(exports, "createTaskDependencies", {
|
|
131
131
|
enumerable: true,
|
|
132
|
-
get: function () { return
|
|
132
|
+
get: function () { return chunkSYDANBJI_cjs.createTaskDependencies; }
|
|
133
133
|
});
|
|
134
134
|
Object.defineProperty(exports, "runTasks", {
|
|
135
135
|
enumerable: true,
|
|
136
|
-
get: function () { return
|
|
136
|
+
get: function () { return chunkSYDANBJI_cjs.runTasks; }
|
|
137
137
|
});
|
|
138
138
|
exports.AsyncStorageTaskQueue = AsyncStorageTaskQueue;
|
|
139
139
|
exports.InMemoryTaskQueue = InMemoryTaskQueue;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { T as TaskProcessor } from '../../taskRunner-
|
|
2
|
-
export { C as CreateTaskDependenciesOptions, I as InMemoryTaskQueue,
|
|
3
|
-
export {
|
|
4
|
-
import '../../ark-
|
|
1
|
+
import { T as TaskProcessor } from '../../taskRunner-Brnak0Rc.cjs';
|
|
2
|
+
export { C as CreateTaskDependenciesOptions, I as InMemoryTaskQueue, b as TaskDependencies, c as TaskItem, a as TaskQueue, d as TaskResult, e as createTaskDependencies, r as runTasks } from '../../taskRunner-Brnak0Rc.cjs';
|
|
3
|
+
export { a as AsyncStorageLike, A as AsyncStorageTaskQueue } from '../../asyncStorageTaskQueue-CeLZhZFU.cjs';
|
|
4
|
+
import '../../ark-CjE0KkGp.cjs';
|
|
5
5
|
import '@scure/btc-signer/transaction.js';
|
|
6
6
|
import '@scure/btc-signer/utils.js';
|
|
7
7
|
import '@scure/btc-signer/psbt.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { T as TaskProcessor } from '../../taskRunner-
|
|
2
|
-
export { C as CreateTaskDependenciesOptions, I as InMemoryTaskQueue,
|
|
3
|
-
export {
|
|
4
|
-
import '../../ark-
|
|
1
|
+
import { T as TaskProcessor } from '../../taskRunner-B-2MHCYG.js';
|
|
2
|
+
export { C as CreateTaskDependenciesOptions, I as InMemoryTaskQueue, b as TaskDependencies, c as TaskItem, a as TaskQueue, d as TaskResult, e as createTaskDependencies, r as runTasks } from '../../taskRunner-B-2MHCYG.js';
|
|
3
|
+
export { a as AsyncStorageLike, A as AsyncStorageTaskQueue } from '../../asyncStorageTaskQueue-D9SOPMPC.js';
|
|
4
|
+
import '../../ark-CjE0KkGp.js';
|
|
5
5
|
import '@scure/btc-signer/transaction.js';
|
|
6
6
|
import '@scure/btc-signer/utils.js';
|
|
7
7
|
import '@scure/btc-signer/psbt.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { CONTRACT_POLL_TASK_TYPE, contractPollProcessor, createTaskDependencies, runTasks } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
5
|
-
import '../../chunk-
|
|
1
|
+
export { CONTRACT_POLL_TASK_TYPE, contractPollProcessor, createTaskDependencies, runTasks } from '../../chunk-G6J6AEMH.js';
|
|
2
|
+
import '../../chunk-NYR5H6GR.js';
|
|
3
|
+
import '../../chunk-BHHLRZCS.js';
|
|
4
|
+
import '../../chunk-4VVTRPH3.js';
|
|
5
|
+
import '../../chunk-ZDDBTFVO.js';
|
|
6
6
|
import '../../chunk-NSBPE2FW.js';
|
|
7
7
|
|
|
8
8
|
// src/worker/expo/taskQueue.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkade-os/sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.48",
|
|
4
4
|
"description": "TypeScript SDK for building Bitcoin wallets using the Arkade protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -199,6 +199,7 @@
|
|
|
199
199
|
"build": "tsup",
|
|
200
200
|
"smoke:dist": "node scripts/smoke-dist.mjs",
|
|
201
201
|
"typecheck": "tsc --noEmit",
|
|
202
|
+
"check:vtxo": "node scripts/check-virtual-status.mjs && node scripts/check-provider-boundary.mjs",
|
|
202
203
|
"docs:build": "pnpm run typecheck && pnpm typedoc",
|
|
203
204
|
"docs:open": "open ../../docs/index.html",
|
|
204
205
|
"test": "vitest run",
|
|
@@ -215,7 +216,7 @@
|
|
|
215
216
|
"test:watch": "vitest",
|
|
216
217
|
"test:coverage": "vitest run --coverage",
|
|
217
218
|
"format": "prettier --write src test examples",
|
|
218
|
-
"lint": "prettier --check src test examples",
|
|
219
|
+
"lint": "prettier --check src test examples && pnpm run check:vtxo",
|
|
219
220
|
"audit": "pnpm audit"
|
|
220
221
|
}
|
|
221
222
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":[],"mappings":";;;AAkDA,eAAsB,QAAA,CAClB,KAAA,EACA,UAAA,EACA,IAAA,EACqB;AACrB,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,CAAM,QAAA,EAAS;AACnC,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,CAAE,QAAA,EAAU,CAAC,CAAC,CAAC,CAAA;AACnE,EAAA,MAAM,UAAwB,EAAC;AAE/B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACtB,IAAA,MAAM,SAAA,GAAY,YAAA,CAAa,GAAA,CAAI,IAAA,CAAK,IAAI,CAAA;AAE5C,IAAA,IAAI,OAAA;AAEJ,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,OAAA,GAAU;AAAA,QACN,YAAY,IAAA,CAAK,EAAA;AAAA,QACjB,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,MAAA,EAAQ;AAAA,OACZ;AAAA,IACJ,CAAA,MAAO;AACH,MA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AA,IAAI,UAAA,GAAa,CAAA;AAEjB,IAAA,KAAA,MAAW,YAAY,SAAA,EAAW;AAE9B,MAAA,MAAM,QAAA,GAAW,GAAA;AACjB,MAAA,IAAI,SAAA,GAAY,CAAA;AAChB,MAAA,IAAI,OAAA,GAAU,IAAA;AACd,MAAA,MAAM,WAAkC,EAAC;AAEzC,MAAA,OAAO,OAAA,EAAS;AACZ,QAAA,MAAM,EAAE,KAAA,EAAO,IAAA,EAAK,GAAI,MAAM,gBAAgB,QAAA,CAAS;AAAA,UACnD,OAAA,EAAS,CAAC,QAAA,CAAS,MAAM,CAAA;AAAA,UACzB,SAAA;AAAA,UACA;AAAA,SACH,CAAA;AAED,QAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACtB,UAAA,QAAA,CAAS,IAAA,CAAK,UAAA,CAAW,IAAA,EAAM,QAAQ,CAAC,CAAA;AAAA,QAC5C;AAEA,QAAA,OAAA,GAAU,IAAA,GAAO,KAAA,CAAM,MAAA,KAAW,QAAA,GAAW,KAAA;AAC7C,QAAA,SAAA,EAAA;AAAA,MACJ;AAKA,MAAA,MAAM,QAAA,GAAW,2BAAA;AAAA,QACb,QAAA;AAAA,QACA,QAAA,CAAS,MAAA;AAAA,QACT;AAAA,OACJ;AACA,MAAA,MAAM,oBAAA,CAAqB,gBAAA,EAAkB,QAAA,EAAU,QAAQ,CAAA;AAC/D,MAAA,UAAA,IAAc,QAAA,CAAS,MAAA;AACvB,MAAA,kBAAA,EAAA;AAAA,IACJ;AAEA,IAAA,OAAO;AAAA,MACH,YAAY,IAAA,CAAK,EAAA;AAAA,MACjB,IAAA,EAAM,uBAAA;AAAA,MACN,MAAA,EAAQ,SAAA;AAAA,MACR,IAAA,EAAM,EAAE,kBAAA,EAAoB,UAAA;AAAW,KAC3C;AAAA,EACJ;AACJ","file":"chunk-3N5I6GT6.js","sourcesContent":["import type { TaskItem, TaskResult, TaskQueue } from \"./taskQueue\";\nimport type { WalletRepository } from \"../../repositories/walletRepository\";\nimport type { ContractRepository } from \"../../repositories/contractRepository\";\nimport type { IndexerProvider } from \"../../providers/indexer\";\nimport type { ArkProvider } from \"../../providers/ark\";\nimport type { ExtendedVirtualCoin, VirtualCoin } from \"../../wallet\";\nimport type { Contract } from \"../../contracts/types\";\nimport { getRandomId, extendVirtualCoinForContract } from \"../../wallet/utils\";\n\n/**\n * Shared dependencies injected into every processor at runtime.\n *\n * `extendVtxo` requires the owning contract — processors must resolve each\n * vtxo's `script` to a known contract (via the contract repository) before\n * calling this. The strict signature prevents the footgun where a missing\n * contract silently falls back to the wallet's default tapscript.\n */\nexport interface TaskDependencies {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: ArkProvider;\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) => ExtendedVirtualCoin;\n}\n\n/**\n * A stateless unit that handles one type of task item.\n *\n * Processors must not keep in-memory state across invocations —\n * all coordination lives in the @see TaskQueue and repositories.\n *\n * The `TDeps` parameter defaults to @see TaskDependencies but\n * can be overridden for domain-specific processors (e.g. swap processing).\n */\nexport interface TaskProcessor<TDeps = TaskDependencies> {\n readonly taskType: string;\n execute(item: TaskItem, deps: TDeps): Promise<Omit<TaskResult, \"id\" | \"executedAt\">>;\n}\n\n/**\n * Run all pending tasks from the queue through matching processors.\n *\n * For each task in the inbox:\n * 1. Find the processor whose `taskType` matches `task.type`.\n * 2. Execute it, producing a @see TaskResult.\n * 3. Push the result to the outbox and remove the task from the inbox.\n *\n * Tasks with no matching processor produce a `\"noop\"` result.\n * Processor errors produce a `\"failed\"` result with the error message.\n */\nexport async function runTasks<TDeps = TaskDependencies>(\n queue: TaskQueue,\n processors: TaskProcessor<TDeps>[],\n deps: TDeps,\n): Promise<TaskResult[]> {\n const tasks = await queue.getTasks();\n const processorMap = new Map(processors.map((p) => [p.taskType, p]));\n const results: TaskResult[] = [];\n\n for (const task of tasks) {\n const processor = processorMap.get(task.type);\n\n let partial: Omit<TaskResult, \"id\" | \"executedAt\">;\n\n if (!processor) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"noop\",\n };\n } else {\n try {\n partial = await processor.execute(task, deps);\n } catch (error) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"failed\",\n data: {\n error: error instanceof Error ? error.message : String(error),\n },\n };\n }\n }\n\n const result: TaskResult = {\n ...partial,\n id: getRandomId(),\n executedAt: Date.now(),\n };\n\n await queue.pushResult(result);\n await queue.removeTask(task.id);\n results.push(result);\n }\n\n return results;\n}\n\n/**\n * Options for @see createTaskDependencies.\n */\nexport interface CreateTaskDependenciesOptions {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: ArkProvider;\n}\n\n/**\n * Build the @see TaskDependencies needed by task processors\n * (e.g. `src/worker/expo/processors/contractPollProcessor.ts`)\n *\n * This is the same construction that `defineExpoBackgroundTask` does\n * internally, extracted so that consumers with custom schedulers\n * (e.g. bare React Native with `react-native-background-fetch`)\n * can build deps without depending on Expo.\n */\nexport function createTaskDependencies(options: CreateTaskDependenciesOptions): TaskDependencies {\n return {\n ...options,\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) =>\n extendVirtualCoinForContract(vtxo, contract),\n };\n}\n","import type { TaskItem, TaskResult } from \"../taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../taskRunner\";\nimport type { ExtendedVirtualCoin } from \"../../../wallet\";\nimport {\n warnAndFilterVtxosForScript,\n saveVtxosForContract,\n} from \"../../../contracts/vtxoOwnership\";\n\nexport const CONTRACT_POLL_TASK_TYPE = \"contract-poll\";\n\n/**\n * Polls the indexer for the latest VTXO state of every contract and\n * persists the results to the wallet repository.\n *\n * Replicates the polling subset of @see ContractManager.initialize:\n * 1. Load all contracts from the contract repository.\n * 2. Paginated fetch of every VTXO (including spent) from the indexer.\n * 3. Extend each VTXO with tapscript data.\n * 4. Save to the wallet repository.\n *\n * NOTE: the indexer query deliberately omits `spendableOnly`. Every\n * repository implements `saveVtxos` as an upsert with no batch delete,\n * so filtering to spendable-only would leave VTXOs that became spent\n * between polls marked as spendable forever. Fetching the full set lets\n * the upsert overwrite stale records with their latest state.\n */\nexport const contractPollProcessor: TaskProcessor = {\n taskType: CONTRACT_POLL_TASK_TYPE,\n\n async execute(\n item: TaskItem,\n deps: TaskDependencies,\n ): Promise<Omit<TaskResult, \"id\" | \"executedAt\">> {\n const { contractRepository, walletRepository, indexerProvider, extendVtxo } = deps;\n\n const contracts = await contractRepository.getContracts();\n let contractsProcessed = 0;\n let vtxosSaved = 0;\n\n for (const contract of contracts) {\n // Paginated fetch of spendable virtual outputs\n const pageSize = 100;\n let pageIndex = 0;\n let hasMore = true;\n const allVtxos: ExtendedVirtualCoin[] = [];\n\n while (hasMore) {\n const { vtxos, page } = await indexerProvider.getVtxos({\n scripts: [contract.script],\n pageIndex,\n pageSize,\n });\n\n for (const vtxo of vtxos) {\n allVtxos.push(extendVtxo(vtxo, contract));\n }\n\n hasMore = page ? vtxos.length === pageSize : false;\n pageIndex++;\n }\n\n // Skip wrong-script rows (legacy duplicates or indexer drift)\n // before persisting; the loop must keep going for the remaining\n // contracts even when one row is rejected.\n const filtered = warnAndFilterVtxosForScript(\n allVtxos,\n contract.script,\n \"contractPollProcessor\",\n );\n await saveVtxosForContract(walletRepository, contract, filtered);\n vtxosSaved += filtered.length;\n contractsProcessed++;\n }\n\n return {\n taskItemId: item.id,\n type: CONTRACT_POLL_TASK_TYPE,\n status: \"success\",\n data: { contractsProcessed, vtxosSaved },\n };\n },\n};\n"]}
|