@arkade-os/sdk 0.5.0 → 0.5.1
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/README.md +1 -1
- 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/{asyncStorageTaskQueue-BFv2O1y1.d.ts → asyncStorageTaskQueue-CdWheMqT.d.ts} +2 -2
- package/dist/{asyncStorageTaskQueue-qRRQUOE8.d.cts → asyncStorageTaskQueue-DFt5LgW5.d.cts} +2 -2
- package/dist/{chunk-K352GMVL.js → chunk-3M22PJVB.js} +3 -3
- package/dist/{chunk-K352GMVL.js.map → chunk-3M22PJVB.js.map} +1 -1
- package/dist/{chunk-HABGVRLF.js → chunk-6MIGYYWB.js} +3 -3
- package/dist/{chunk-HABGVRLF.js.map → chunk-6MIGYYWB.js.map} +1 -1
- package/dist/{chunk-K2E6X6JT.js → chunk-FXVEOEYB.js} +4 -4
- package/dist/{chunk-K2E6X6JT.js.map → chunk-FXVEOEYB.js.map} +1 -1
- package/dist/{chunk-JT5YVMCJ.cjs → chunk-GQUFPTN7.cjs} +16 -16
- package/dist/{chunk-JT5YVMCJ.cjs.map → chunk-GQUFPTN7.cjs.map} +1 -1
- package/dist/{chunk-GN2K4WBP.cjs → chunk-GW42FS2X.cjs} +48 -48
- package/dist/{chunk-GN2K4WBP.cjs.map → chunk-GW42FS2X.cjs.map} +1 -1
- package/dist/{chunk-IQWLFYT2.cjs → chunk-HQNQ3CLQ.cjs} +18 -18
- package/dist/{chunk-IQWLFYT2.cjs.map → chunk-HQNQ3CLQ.cjs.map} +1 -1
- package/dist/{chunk-GOM26K6H.cjs → chunk-JJ6QKTFZ.cjs} +10 -10
- package/dist/{chunk-GOM26K6H.cjs.map → chunk-JJ6QKTFZ.cjs.map} +1 -1
- package/dist/{chunk-GWJWXVUB.js → chunk-NKKJEA3Z.js} +51 -37
- package/dist/chunk-NKKJEA3Z.js.map +1 -0
- package/dist/{chunk-ZOEB53NQ.js → chunk-QFB55EOZ.js} +3 -3
- package/dist/{chunk-ZOEB53NQ.js.map → chunk-QFB55EOZ.js.map} +1 -1
- package/dist/{chunk-AU77RYOC.cjs → chunk-QKNSMVBW.cjs} +546 -532
- package/dist/chunk-QKNSMVBW.cjs.map +1 -0
- package/dist/{chunk-UUSKJOSX.cjs → chunk-XLHUGP3G.cjs} +3 -3
- package/dist/{chunk-UUSKJOSX.cjs.map → chunk-XLHUGP3G.cjs.map} +1 -1
- package/dist/{chunk-TZSKLERU.js → chunk-XQRIY5K5.js} +4 -4
- package/dist/{chunk-TZSKLERU.js.map → chunk-XQRIY5K5.js.map} +1 -1
- package/dist/contracts/handlers/index.cjs +9 -9
- 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-DNbiUgy8.d.ts → delegate-BSbGQabI.d.ts} +1 -1
- package/dist/{delegate-B5BmYkEY.d.cts → delegate-CFCfrReG.d.cts} +1 -1
- package/dist/{index-CZw-MMfY.d.cts → index-B3fRWO5i.d.cts} +9 -1
- package/dist/{index-CZw-MMfY.d.ts → index-B3fRWO5i.d.ts} +9 -1
- package/dist/{index-CYeyT3kn.d.ts → index-CzUVvIxA.d.ts} +2 -2
- package/dist/{index-B4QuO9sH.d.cts → index-Fpf4mQZr.d.cts} +2 -2
- package/dist/index.cjs +313 -313
- package/dist/index.d.cts +15 -8
- package/dist/index.d.ts +15 -8
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +35 -35
- 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 +33 -33
- 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-wm1bhmtP.d.ts → taskRunner-CdfoCMaw.d.ts} +2 -2
- package/dist/{taskRunner-B3SLvUfL.d.cts → taskRunner-Dk6oDAtd.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 +15 -15
- package/dist/wallet/expo/index.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +5 -5
- package/dist/{wallet-DCZ2-Bea.d.cts → wallet-BQHNgc_v.d.ts} +3 -3
- package/dist/{wallet-DGLXuwXT.d.ts → wallet-D9dvXu-K.d.cts} +3 -3
- 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 +1 -1
- package/dist/chunk-AU77RYOC.cjs.map +0 -1
- package/dist/chunk-GWJWXVUB.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkQKNSMVBW_cjs = require('./chunk-QKNSMVBW.cjs');
|
|
4
|
+
var chunkXLHUGP3G_cjs = require('./chunk-XLHUGP3G.cjs');
|
|
5
5
|
|
|
6
6
|
// src/worker/expo/taskRunner.ts
|
|
7
7
|
async function runTasks(queue, processors, deps) {
|
|
@@ -33,7 +33,7 @@ async function runTasks(queue, processors, deps) {
|
|
|
33
33
|
}
|
|
34
34
|
const result = {
|
|
35
35
|
...partial,
|
|
36
|
-
id:
|
|
36
|
+
id: chunkQKNSMVBW_cjs.getRandomId(),
|
|
37
37
|
executedAt: Date.now()
|
|
38
38
|
};
|
|
39
39
|
await queue.pushResult(result);
|
|
@@ -45,7 +45,7 @@ async function runTasks(queue, processors, deps) {
|
|
|
45
45
|
function createTaskDependencies(options) {
|
|
46
46
|
return {
|
|
47
47
|
...options,
|
|
48
|
-
extendVtxo: (vtxo, contract) =>
|
|
48
|
+
extendVtxo: (vtxo, contract) => chunkQKNSMVBW_cjs.extendVirtualCoinForContract(vtxo, contract)
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -55,7 +55,7 @@ var contractPollProcessor = {
|
|
|
55
55
|
taskType: CONTRACT_POLL_TASK_TYPE,
|
|
56
56
|
async execute(item, deps) {
|
|
57
57
|
const { contractRepository, walletRepository, indexerProvider, extendVtxo } = deps;
|
|
58
|
-
const contracts = await
|
|
58
|
+
const contracts = await chunkQKNSMVBW_cjs.collectContracts(contractRepository, {
|
|
59
59
|
watch: ["watched", "awaiting-funds"]
|
|
60
60
|
});
|
|
61
61
|
let contractsProcessed = 0;
|
|
@@ -66,7 +66,7 @@ var contractPollProcessor = {
|
|
|
66
66
|
let hasMore = true;
|
|
67
67
|
const allVtxos = [];
|
|
68
68
|
while (hasMore) {
|
|
69
|
-
const { vtxos, page } = await
|
|
69
|
+
const { vtxos, page } = await chunkXLHUGP3G_cjs.getNormalizedVtxos(indexerProvider, {
|
|
70
70
|
scripts: [contract.script],
|
|
71
71
|
pageIndex,
|
|
72
72
|
pageSize
|
|
@@ -77,12 +77,12 @@ var contractPollProcessor = {
|
|
|
77
77
|
hasMore = page ? vtxos.length === pageSize : false;
|
|
78
78
|
pageIndex++;
|
|
79
79
|
}
|
|
80
|
-
const filtered =
|
|
80
|
+
const filtered = chunkQKNSMVBW_cjs.warnAndFilterVtxosForScript(
|
|
81
81
|
allVtxos,
|
|
82
82
|
contract.script,
|
|
83
83
|
"contractPollProcessor"
|
|
84
84
|
);
|
|
85
|
-
await
|
|
85
|
+
await chunkQKNSMVBW_cjs.saveVtxosForContract(walletRepository, contract, filtered);
|
|
86
86
|
vtxosSaved += filtered.length;
|
|
87
87
|
contractsProcessed++;
|
|
88
88
|
}
|
|
@@ -99,5 +99,5 @@ exports.CONTRACT_POLL_TASK_TYPE = CONTRACT_POLL_TASK_TYPE;
|
|
|
99
99
|
exports.contractPollProcessor = contractPollProcessor;
|
|
100
100
|
exports.createTaskDependencies = createTaskDependencies;
|
|
101
101
|
exports.runTasks = runTasks;
|
|
102
|
-
//# sourceMappingURL=chunk-
|
|
103
|
-
//# sourceMappingURL=chunk-
|
|
102
|
+
//# sourceMappingURL=chunk-JJ6QKTFZ.cjs.map
|
|
103
|
+
//# sourceMappingURL=chunk-JJ6QKTFZ.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":["getRandomId","extendVirtualCoinForContract","collectContracts","getNormalizedVtxos","warnAndFilterVtxosForScript","saveVtxosForContract"],"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,MAAA,IAAI;AACA,QAAA,OAAA,GAAU,MAAM,SAAA,CAAU,OAAA,CAA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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 { collectContracts } from \"../../../repositories/contractRepository\";\nimport type { TaskItem, TaskResult } from \"../taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../taskRunner\";\nimport type { ExtendedVirtualCoin } from \"../../../wallet\";\nimport { getNormalizedVtxos } from \"../../../wallet/vtxo\";\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 every watched contract 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 // Background channel, so it covers exactly what the watcher's\n // subscription covers: `retained` rows are kept for reads only.\n const contracts = await collectContracts(contractRepository, {\n watch: [\"watched\", \"awaiting-funds\"],\n });\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 getNormalizedVtxos(indexerProvider, {\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":["get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AED,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,GAAWC,6CAAA;AAAA,QACb,QAAA;AAAA,QACA,QAAA,CAAS,MAAA;AAAA,QACT;AAAA,OACJ;AACA,MAAA,MAAMC,sCAAA,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-JJ6QKTFZ.cjs","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 { collectContracts } from \"../../../repositories/contractRepository\";\nimport type { TaskItem, TaskResult } from \"../taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../taskRunner\";\nimport type { ExtendedVirtualCoin } from \"../../../wallet\";\nimport { getNormalizedVtxos } from \"../../../wallet/vtxo\";\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 every watched contract 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 // Background channel, so it covers exactly what the watcher's\n // subscription covers: `retained` rows are kept for reads only.\n const contracts = await collectContracts(contractRepository, {\n watch: [\"watched\", \"awaiting-funds\"],\n });\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 getNormalizedVtxos(indexerProvider, {\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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AssetId, AssetGroup, AssetInput, AssetOutput, Metadata, Packet, RestIndexerProvider, BufferReader, BufferWriter, AssetRef } from './chunk-
|
|
2
|
-
import { witnessRefToBytes, validateProgram, toASM, stringifyArtifact, serializeArkadeContractParams, resolveAsm, parseArtifact, getOpcodeValue, getOpcodeName, fromASM, deserializeArkadeContractParams, computeArkadeScriptPublicKey, bytesToASM, asmToBytes, arkadeWitnessHash, arkadeScriptHash, UnsupportedProgramVersionError, SUPPORTED_PROGRAM_VERSION, OPCODE_VALUES, OPCODE_NAMES, bignum_exports, ArkadeScript, ArkadeProgramScript, ARKADE_OPS, ARKADE_OPCODE_VALUES, ARKADE_OPCODE_NAMES, ARKADE_OPCODES, ARKADE_OP, toXOnly, ARKADE_TYPE_ENCODINGS, validateParamValue, contractHandlers, speculativeReceiveMetadata, isMainnetDescriptor, descriptorIsOurs, deriveDescriptorLeafPubKey, deriveDescriptorLeafCompressedPubKey, normalizeToDescriptor, extractPubKey, parseHDDescriptor, identityDescriptor, DefaultVtxo, DelegateVtxo, WALLET_RECEIVE_SOURCE, BoardingContractHandler } from './chunk-
|
|
3
|
-
import { VtxoScript, __export, Transaction, requiresForfeit, CSVMultisigTapscript, networks, getNetwork, DEFAULT_NETWORK, resolveEmulatorPubkey, timelockToSequence, isVtxoSpent, getNormalizedVtxos, setArkPsbtField, PrevArkTxField, ConditionWitness, craftToSpendTx, RestArkProvider, ArkAddress, isVirtualCoin, getArkPsbtFields, CosignerPublicKey, ServerResponseMismatchError, assertNonNegativeMs, isRetryableProviderError, getAllNormalizedVtxos, DEFAULT_PAGE_SIZE, OP_RETURN_EMPTY_PKSCRIPT, canSweepOnchain, sequenceToTimelock, DEFAULT_ARKADE_SERVER_URL, baseFetch, DEFAULT_NETWORK_NAME, sequenceToCanonicalTimelock, assertTimerMs, isEventSourceError, isEventSourceUnavailableError, normalizeVtxo, isPastExpiry, decodeTapscript, scriptFromTapLeafScript, CLTVMultisigTapscript, VtxoTaprootTree, isArkError, ArkErrorName, assertAllowedSighashTypes, Intent, rateGate, formatSighash, getSequence, maybeArkError, toOffchainInputFeeParams, canRecoverOnchain, MultisigTapscript, DEFAULT_ARKADE_EMULATOR_URL, networkFromArkadeInfo, ArkError, toBIP371TapTree, resolveTimeHeight, canSpendOffchain, INFO_FETCH_TIMEOUT_MS, PrevoutTxField, fetchVtxoCreatedAtByTxid, EXPIRY_MIN_PLAUSIBLE_MS, ProviderUnavailableError } from './chunk-
|
|
1
|
+
import { AssetId, AssetGroup, AssetInput, AssetOutput, Metadata, Packet, RestIndexerProvider, BufferReader, BufferWriter, AssetRef } from './chunk-6MIGYYWB.js';
|
|
2
|
+
import { witnessRefToBytes, validateProgram, toASM, stringifyArtifact, serializeArkadeContractParams, resolveAsm, parseArtifact, getOpcodeValue, getOpcodeName, fromASM, deserializeArkadeContractParams, computeArkadeScriptPublicKey, bytesToASM, asmToBytes, arkadeWitnessHash, arkadeScriptHash, UnsupportedProgramVersionError, SUPPORTED_PROGRAM_VERSION, OPCODE_VALUES, OPCODE_NAMES, bignum_exports, ArkadeScript, ArkadeProgramScript, ARKADE_OPS, ARKADE_OPCODE_VALUES, ARKADE_OPCODE_NAMES, ARKADE_OPCODES, ARKADE_OP, toXOnly, ARKADE_TYPE_ENCODINGS, validateParamValue, contractHandlers, speculativeReceiveMetadata, isMainnetDescriptor, descriptorIsOurs, deriveDescriptorLeafPubKey, deriveDescriptorLeafCompressedPubKey, normalizeToDescriptor, extractPubKey, parseHDDescriptor, identityDescriptor, DefaultVtxo, DelegateVtxo, WALLET_RECEIVE_SOURCE, BoardingContractHandler } from './chunk-3M22PJVB.js';
|
|
3
|
+
import { VtxoScript, __export, Transaction, requiresForfeit, CSVMultisigTapscript, networks, getNetwork, DEFAULT_NETWORK, resolveEmulatorPubkey, timelockToSequence, isVtxoSpent, getNormalizedVtxos, setArkPsbtField, PrevArkTxField, ConditionWitness, craftToSpendTx, RestArkProvider, ArkAddress, isVirtualCoin, getArkPsbtFields, CosignerPublicKey, ServerResponseMismatchError, assertNonNegativeMs, isRetryableProviderError, getAllNormalizedVtxos, DEFAULT_PAGE_SIZE, OP_RETURN_EMPTY_PKSCRIPT, canSweepOnchain, sequenceToTimelock, DEFAULT_ARKADE_SERVER_URL, baseFetch, DEFAULT_NETWORK_NAME, sequenceToCanonicalTimelock, assertTimerMs, isEventSourceError, isEventSourceUnavailableError, normalizeVtxo, isPastExpiry, decodeTapscript, scriptFromTapLeafScript, CLTVMultisigTapscript, VtxoTaprootTree, isArkError, ArkErrorName, assertAllowedSighashTypes, Intent, rateGate, formatSighash, getSequence, maybeArkError, toOffchainInputFeeParams, canRecoverOnchain, MultisigTapscript, DEFAULT_ARKADE_EMULATOR_URL, networkFromArkadeInfo, ArkError, toBIP371TapTree, resolveTimeHeight, canSpendOffchain, INFO_FETCH_TIMEOUT_MS, PrevoutTxField, fetchVtxoCreatedAtByTxid, EXPIRY_MIN_PLAUSIBLE_MS, ProviderUnavailableError } from './chunk-QFB55EOZ.js';
|
|
4
4
|
import { sha256, equalBytes, hash160, sha256x2, concatBytes, randomPrivateKeyBytes, pubECDSA, pubSchnorr } from '@scure/btc-signer/utils.js';
|
|
5
5
|
import { SigHash, Script, OP, OutScript, Address, RawWitness, p2tr, p2wpkh, TaprootControlBlock, DEFAULT_SEQUENCE, Transaction as Transaction$1 } from '@scure/btc-signer';
|
|
6
6
|
import { hex, base58, base64, bech32m } from '@scure/base';
|
|
@@ -7947,23 +7947,16 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7947
7947
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
7948
7948
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
7949
7949
|
} else {
|
|
7950
|
-
|
|
7950
|
+
const nowMs = now.timestamp.getTime();
|
|
7951
|
+
const target = expiryTimestamp - Number(arkInfo.sessionDuration * 3000n);
|
|
7952
|
+
delegateAt = new Date(
|
|
7953
|
+
target > nowMs ? target : expiryTimestamp > nowMs ? nowMs + 2e3 : nowMs + 6e4
|
|
7954
|
+
);
|
|
7951
7955
|
}
|
|
7952
7956
|
}
|
|
7953
7957
|
const { fees, dust, forfeitAddress, network } = arkInfo;
|
|
7954
7958
|
const delegateAtSeconds = delegateAt.getTime() / 1e3;
|
|
7955
|
-
const estimator =
|
|
7956
|
-
...fees.intentFee,
|
|
7957
|
-
// replace now() function with the delegateAt timestamp
|
|
7958
|
-
offchainInput: fees.intentFee.offchainInput?.replace(
|
|
7959
|
-
"now()",
|
|
7960
|
-
`double(${delegateAtSeconds})`
|
|
7961
|
-
),
|
|
7962
|
-
offchainOutput: fees.intentFee.offchainOutput?.replace(
|
|
7963
|
-
"now()",
|
|
7964
|
-
`double(${delegateAtSeconds})`
|
|
7965
|
-
)
|
|
7966
|
-
});
|
|
7959
|
+
const estimator = estimatorAt(fees.intentFee, delegateAt);
|
|
7967
7960
|
let amount = 0n;
|
|
7968
7961
|
for (const coin of vtxos) {
|
|
7969
7962
|
const inputFee = estimator.evalOffchainInput({
|
|
@@ -8107,14 +8100,6 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
8107
8100
|
message
|
|
8108
8101
|
};
|
|
8109
8102
|
}
|
|
8110
|
-
function defaultDelegateAt(expiryTimestamp, sessionDurationSeconds, now = Date.now()) {
|
|
8111
|
-
const remainingTimeMs = expiryTimestamp - now;
|
|
8112
|
-
if (remainingTimeMs <= 0) return new Date(now + 6e4);
|
|
8113
|
-
const sessionLeadMs = Number(sessionDurationSeconds * 1000n);
|
|
8114
|
-
const leadTimeMs = Math.max(remainingTimeMs * 0.1, sessionLeadMs);
|
|
8115
|
-
const delegateAt = expiryTimestamp - leadTimeMs;
|
|
8116
|
-
return new Date(delegateAt > now ? delegateAt : now + 2e3);
|
|
8117
|
-
}
|
|
8118
8103
|
function findDestinationOutputIndex(outputs, destinationScript) {
|
|
8119
8104
|
return outputs.findIndex((o) => o.script && equalBytes(o.script, destinationScript));
|
|
8120
8105
|
}
|
|
@@ -8136,6 +8121,14 @@ function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
|
8136
8121
|
function isAnnotated(v) {
|
|
8137
8122
|
return v.tapTree !== void 0 && v.forfeitTapLeafScript !== void 0 && v.intentTapLeafScript !== void 0;
|
|
8138
8123
|
}
|
|
8124
|
+
function estimatorAt(intentFee, at) {
|
|
8125
|
+
const now = `double(${at.getTime() / 1e3})`;
|
|
8126
|
+
return new Estimator({
|
|
8127
|
+
...intentFee,
|
|
8128
|
+
offchainInput: intentFee.offchainInput?.replace("now()", now),
|
|
8129
|
+
offchainOutput: intentFee.offchainOutput?.replace("now()", now)
|
|
8130
|
+
});
|
|
8131
|
+
}
|
|
8139
8132
|
|
|
8140
8133
|
// src/repositories/inMemory/intentRepository.ts
|
|
8141
8134
|
var InMemoryIntentRepository = class {
|
|
@@ -11527,7 +11520,9 @@ async function setupServiceWorker(pathOrOptions) {
|
|
|
11527
11520
|
}
|
|
11528
11521
|
const { path, activationTimeoutMs } = normalizeOptions2(pathOrOptions);
|
|
11529
11522
|
const registration = await navigator.serviceWorker.register(path);
|
|
11530
|
-
|
|
11523
|
+
registration.update().catch(
|
|
11524
|
+
(error) => console.warn("Service worker update failed; continuing with the active worker", error)
|
|
11525
|
+
);
|
|
11531
11526
|
const serviceWorker = registration.active || registration.waiting || registration.installing;
|
|
11532
11527
|
if (!serviceWorker) {
|
|
11533
11528
|
throw new Error("Failed to get service worker instance");
|
|
@@ -13812,6 +13807,17 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13812
13807
|
const commitmentsToIgnore = /* @__PURE__ */ new Set();
|
|
13813
13808
|
const tapscripts = await this.getBoardingTapscripts(this.watchedBoardingSigners());
|
|
13814
13809
|
const outspendCache = /* @__PURE__ */ new Map();
|
|
13810
|
+
const outspendOf = async (txid, index) => {
|
|
13811
|
+
if (this.onchainProvider.getTxOutspend) {
|
|
13812
|
+
return this.onchainProvider.getTxOutspend(txid, index);
|
|
13813
|
+
}
|
|
13814
|
+
let statuses = outspendCache.get(txid);
|
|
13815
|
+
if (!statuses) {
|
|
13816
|
+
statuses = await this.onchainProvider.getTxOutspends(txid);
|
|
13817
|
+
outspendCache.set(txid, statuses);
|
|
13818
|
+
}
|
|
13819
|
+
return statuses[index];
|
|
13820
|
+
};
|
|
13815
13821
|
for (const tapscript of tapscripts) {
|
|
13816
13822
|
const boardingAddress = tapscript.onchainAddress(this.network);
|
|
13817
13823
|
const scriptHex = hex.encode(tapscript.pkScript);
|
|
@@ -13826,12 +13832,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13826
13832
|
for (let i = 0; i < tx.vout.length; i++) {
|
|
13827
13833
|
const vout = tx.vout[i];
|
|
13828
13834
|
if (vout.scriptpubkey_address === boardingAddress) {
|
|
13829
|
-
|
|
13830
|
-
if (!spentStatuses) {
|
|
13831
|
-
spentStatuses = await this.onchainProvider.getTxOutspends(tx.txid);
|
|
13832
|
-
outspendCache.set(tx.txid, spentStatuses);
|
|
13833
|
-
}
|
|
13834
|
-
const spentStatus = spentStatuses[i];
|
|
13835
|
+
const spentStatus = await outspendOf(tx.txid, i);
|
|
13835
13836
|
const commitmentTxid = spentStatus?.txid || commitmentByOutpoint.get(`${tx.txid}:${i}`);
|
|
13836
13837
|
const spent = Boolean(spentStatus?.spent) || commitmentTxid !== void 0;
|
|
13837
13838
|
if (spent && commitmentTxid) {
|
|
@@ -14249,6 +14250,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14249
14250
|
...[...this._deprecatedSigners.keys()].map((h) => hex.decode(h))
|
|
14250
14251
|
];
|
|
14251
14252
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
14253
|
+
const baseline = [];
|
|
14252
14254
|
for (const serverPubKey of baselineSigners) {
|
|
14253
14255
|
for (const csvTimelock2 of this.walletContractTimelocks) {
|
|
14254
14256
|
const csvTimelockStr = timelockToSequence(csvTimelock2).toString();
|
|
@@ -14260,7 +14262,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14260
14262
|
const defaultScriptHex = hex.encode(defaultScript.pkScript);
|
|
14261
14263
|
if (!seenBaselineScripts.has(defaultScriptHex)) {
|
|
14262
14264
|
seenBaselineScripts.add(defaultScriptHex);
|
|
14263
|
-
|
|
14265
|
+
baseline.push({
|
|
14264
14266
|
type: "default",
|
|
14265
14267
|
params: {
|
|
14266
14268
|
pubKey: hex.encode(defaultScript.options.pubKey),
|
|
@@ -14282,7 +14284,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14282
14284
|
const delegateScriptHex = hex.encode(delegateScript.pkScript);
|
|
14283
14285
|
if (seenBaselineScripts.has(delegateScriptHex)) continue;
|
|
14284
14286
|
seenBaselineScripts.add(delegateScriptHex);
|
|
14285
|
-
|
|
14287
|
+
baseline.push({
|
|
14286
14288
|
type: "delegate",
|
|
14287
14289
|
params: {
|
|
14288
14290
|
pubKey: hex.encode(delegateScript.options.pubKey),
|
|
@@ -14307,7 +14309,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14307
14309
|
const boardingScriptHex = hex.encode(baselineBoarding.pkScript);
|
|
14308
14310
|
if (seenBaselineScripts.has(boardingScriptHex)) continue;
|
|
14309
14311
|
seenBaselineScripts.add(boardingScriptHex);
|
|
14310
|
-
|
|
14312
|
+
baseline.push({
|
|
14311
14313
|
type: "boarding",
|
|
14312
14314
|
params: {
|
|
14313
14315
|
pubKey: hex.encode(baselineBoarding.options.pubKey),
|
|
@@ -14319,6 +14321,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14319
14321
|
state: "active"
|
|
14320
14322
|
});
|
|
14321
14323
|
}
|
|
14324
|
+
await manager.createContracts(baseline);
|
|
14322
14325
|
return manager;
|
|
14323
14326
|
}
|
|
14324
14327
|
/** Dispose wallet-owned managers and release background resources. */
|
|
@@ -22106,6 +22109,14 @@ var ElectrumOnchainProvider = class {
|
|
|
22106
22109
|
return hex.decode(tx.hex);
|
|
22107
22110
|
}
|
|
22108
22111
|
async getTxOutspends(txid) {
|
|
22112
|
+
return this.resolveOutspends(txid);
|
|
22113
|
+
}
|
|
22114
|
+
/** Reads `vout`'s script alone: another output of a tx someone else built (their change, a
|
|
22115
|
+
* service's fee address) can have a history Fulcrum answers empty and electrs refuses. */
|
|
22116
|
+
async getTxOutspend(txid, vout) {
|
|
22117
|
+
return (await this.resolveOutspends(txid, vout))[vout] ?? { spent: false, txid: "" };
|
|
22118
|
+
}
|
|
22119
|
+
async resolveOutspends(txid, only) {
|
|
22109
22120
|
const [txResult] = await this.chain.fetchTransactions([txid]);
|
|
22110
22121
|
const tx = Transaction$1.fromRaw(hex.decode(txResult.hex), {
|
|
22111
22122
|
allowUnknownOutputs: true
|
|
@@ -22114,7 +22125,10 @@ var ElectrumOnchainProvider = class {
|
|
|
22114
22125
|
const outputScriptHashes = [];
|
|
22115
22126
|
for (let i = 0; i < outputCount; i++) {
|
|
22116
22127
|
const output = tx.getOutput(i);
|
|
22117
|
-
|
|
22128
|
+
const wanted = only === void 0 || i === only;
|
|
22129
|
+
outputScriptHashes.push(
|
|
22130
|
+
wanted && output.script ? toScriptHash(output.script) : void 0
|
|
22131
|
+
);
|
|
22118
22132
|
}
|
|
22119
22133
|
const validScriptHashes = outputScriptHashes.filter((h) => h !== void 0);
|
|
22120
22134
|
const results = Array.from(
|
|
@@ -25674,5 +25688,5 @@ function createDefaultPaymentRouter(wallet) {
|
|
|
25674
25688
|
}
|
|
25675
25689
|
|
|
25676
25690
|
export { ARKADE_MAGIC, ARKADE_SALTED_PREIMAGE_TAG, ARKADE_SWAP_PREIMAGE_TAG, ASSET_CARRIER_SATS, AbortError, ActivityRegistry, AmbiguousRouteError, ArkNote, Arkade, ArkadeCash, ArkadeCashCreateError, ArkadeCashOperatorMismatchError, AssetManager, BIP21, BIP21Error, BIP322, BLOCKED_UPGRADE_TIMEOUT_MS, Batch, CachingArkProvider, ChainedTxType, ConnectionDisposedError, ContractManager, ContractWatcher, DEFAULT_MESSAGE_TIMEOUTS, DEFAULT_MIN_BATCH_EXPIRY_SECONDS, DatabaseUpgradeBlockedError, DelegateManagerImpl, DelegateNotConfiguredError, DescriptorIdentity, DescriptorSigningProviderMissingError, DustChangeError, ELECTRUM_TCP_HOST, ELECTRUM_WS_URL, ESPLORA_URL, ElectrumOnchainProvider, EmulatorPacket, EsploraProvider, Estimator, Extension, ExtensionNotFoundError, ForeignDescriptorError, HDDescriptorProvider, INTENT_TERMINAL_STATES, InMemoryContractRepository, InMemoryIntentRepository, InMemoryVirtualTxRepository, InMemoryWalletRepository, IndexedDBContractRepository, IndexedDBIntentRepository, IndexedDBVirtualTxRepository, IndexedDBWalletRepository, KeyringDescriptorProvider, MAX_PAGE_SIZE, MAX_USED_SIGNING_DESCRIPTORS_LOOK_AHEAD, MESSAGE_BUS_INITIALIZING, MESSAGE_BUS_NOT_INITIALIZED, MessageBus, MessageBusInitializingError, MessageBusNotInitializedError, MissingSigningDescriptorError, MnemonicIdentity, OnchainWallet, OversizedChangeError, P2A, PaymentRouter, PrevTxUnavailableError, REGTEST_MIN_BATCH_EXPIRY_SECONDS, Ramps, ReadonlyAssetManager, ReadonlyDescriptorIdentity, ReadonlySingleKey, ReadonlyWallet, ReadonlyWalletError, RestDelegateProvider, RestEmulatorProvider, SeedIdentity, SendDeadlineExceededError, ServiceWorkerReadonlyWallet, ServiceWorkerTimeoutError, ServiceWorkerWallet, SingleKey, StaticDescriptorProvider, TxTree, TxType, TxWeightEstimator, UnannotatableInputError, UnilateralExit, UnknownPacket, Unroll, VtxoManager, VtxoReservedError, Wallet2 as Wallet, WalletCannotAllocateAddressError, WalletCannotSignError, WalletMessageHandler, WalletNotInitializedError, WsElectrumChainSource, adoptContractDescriptor, arkAssetRail, arkRail, arkTarget, arkade_exports, assertFinalCommitmentMatchesValidated, assertHistoryPageFilter, assertIntentIdUnique, assertNoAssets, assertNoSelection, assertPageRequest, assertRecipientArkadeAddress, assertSendDeadline, assertSendableAmount, assertSubmittedArkTxid, assertValidBatchExpiry, assertValidServerUnrollScript, assetMintResolver, assetsOf, attachPrevArkTxs, attachPrevoutTxs, awaitTransaction, boardingResolver, btcTarget, buildForfeitTx, buildOffchainTx, buildPreimageMessage, buildSaltedPreimageMessage, captureSendDeadline, checkSaveVtxosForScript, claimWithPreimageIdentity, classifyAgainstSignerSet, classifyContractSigner, closeDatabase, collabExitResolver, collectContracts, collectIntents, collectPages, collectScriptVtxos, collectTransactionHistory, collectUtxos, collectVtxos, combineTapscriptSigs, compareHistoryCursors, contractFilterMatchesNothing, contractFromArkContract, contractFromArkContractWithAddress, contractPreimage, contractSigner, createAssetPacket, createDefaultActivityRegistry, createDefaultPaymentRouter, createExitChainResolver, createManagedConnection, createdAtToIso, decodeArkContract, defaultBatchExpiryPolicy, deleteByIndex, deserializeAssets, deserializeExitPackage, deserializeUtxo, deserializeVtxo, encodeArkContract, exitObserverFor, extendVirtualCoinForContract, extractArkProviderUrl, gateExclusion, gatedContracts, getAllByIndexValues, getRandomId, hasBoardingTxExpired, hasCandidates, intentMatchesFilter, invoiceTarget, isAddressAllocationCapable, isArkContract, isBatchSignable, isBtcAddress, isContractGenericallySpendable, isContractVtxoEvent, isCooperativelyMigratable, isDeterministicSigner, isDiscoverable, isHDAllocationCapable, isHDDeterministicSignCapable, isHDWalletCapable, isLightningInvoice, isLnurl, isMessageBusInitializingError, isMessageBusNotInitializedError, isPerArtifactDescriptor, isSigningIdentity, isSubdust, isTerminalIntentState, isValidArkAddress, isVtxoExpiringSoon, iteratePages, legacyVtxoFacts, logExcludedVtxos, makeHandle, matchServerCheckpoints, mergeChainedTxType, notifyExitObserved, onchainRail, openDatabase, outpointExclusion, outpointReasons, pageResult, promisifyRequest, provisionClaimSecret, provisionRefundKey, registerWalletRestoreHook, resolveAssetAmount, resolveBatchExpiryPolicy, resolveDescriptorSigner, resolvePrevTxs, resolveSendAmount, saveVtxosForContract, scriptFromArkAddress, selectCoinsWithAsset, selectVirtualCoins, selectionOf, serializeAssets, serializeExitPackage, serializeUtxo, serializeVtxo, setupServiceWorker, signAndSubmitOffchainTx, signerSetFromInfo, signingDescriptorIndex, strictSigningDescriptorIndex, submitViaEmulator, toXOnlySignerHex, tryResolveSendAmount, utxoEntries, validateBatchRecipients, validateConnectorsTxGraph, validateVtxoTxGraph, verifyTapscriptSignatures, waitForIncomingFunds, walletFeeSource, warnAndFilterVtxosForScript, withPrevTxs };
|
|
25677
|
-
//# sourceMappingURL=chunk-
|
|
25678
|
-
//# sourceMappingURL=chunk-
|
|
25691
|
+
//# sourceMappingURL=chunk-NKKJEA3Z.js.map
|
|
25692
|
+
//# sourceMappingURL=chunk-NKKJEA3Z.js.map
|