@arkade-os/sdk 0.4.63 → 0.4.65
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.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{asyncStorageTaskQueue-CIUEhv2t.d.cts → asyncStorageTaskQueue-Chwe60Ce.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-LT-xvvDN.d.ts → asyncStorageTaskQueue-Dq_UcvDx.d.ts} +2 -2
- package/dist/{chunk-CZFAMS57.js → chunk-3G5V564P.js} +141 -3
- package/dist/chunk-3G5V564P.js.map +1 -0
- package/dist/{chunk-X7MMBB7S.js → chunk-5YTSQSLE.js} +226 -353
- package/dist/chunk-5YTSQSLE.js.map +1 -0
- package/dist/{chunk-K56BNZV3.cjs → chunk-7X744EFF.cjs} +10 -10
- package/dist/{chunk-K56BNZV3.cjs.map → chunk-7X744EFF.cjs.map} +1 -1
- package/dist/{chunk-OL7V43WS.cjs → chunk-BABJ77NG.cjs} +196 -57
- package/dist/chunk-BABJ77NG.cjs.map +1 -0
- package/dist/{chunk-AB67CMHS.cjs → chunk-G552MISJ.cjs} +3 -3
- package/dist/{chunk-AB67CMHS.cjs.map → chunk-G552MISJ.cjs.map} +1 -1
- package/dist/{chunk-COOBS7ET.cjs → chunk-GFZNEMGL.cjs} +629 -748
- package/dist/chunk-GFZNEMGL.cjs.map +1 -0
- package/dist/{chunk-KWW74O2F.js → chunk-RESN6QHP.js} +4 -4
- package/dist/{chunk-KWW74O2F.js.map → chunk-RESN6QHP.js.map} +1 -1
- package/dist/{chunk-P6XYE27K.cjs → chunk-SJQM5AVB.cjs} +17 -17
- package/dist/{chunk-P6XYE27K.cjs.map → chunk-SJQM5AVB.cjs.map} +1 -1
- package/dist/{chunk-MA32NXUV.js → chunk-TFSVXMTM.js} +3 -3
- package/dist/{chunk-MA32NXUV.js.map → chunk-TFSVXMTM.js.map} +1 -1
- package/dist/{chunk-FKKERGKA.js → chunk-TYTPVPKD.js} +4 -4
- package/dist/{chunk-FKKERGKA.js.map → chunk-TYTPVPKD.js.map} +1 -1
- package/dist/{chunk-OAESYVZQ.js → chunk-XMOIRDLF.js} +151 -12
- package/dist/chunk-XMOIRDLF.js.map +1 -0
- package/dist/{chunk-LG5GY73A.cjs → chunk-XN55B6EP.cjs} +155 -17
- package/dist/chunk-XN55B6EP.cjs.map +1 -0
- package/dist/contracts/handlers/index.cjs +9 -9
- package/dist/contracts/handlers/index.d.cts +1 -1
- package/dist/contracts/handlers/index.d.ts +1 -1
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{index-aZycGEsQ.d.cts → index-BtTtQFUX.d.cts} +109 -0
- package/dist/{index-Bxe9kBFs.d.ts → index-fDDiA1-L.d.ts} +109 -0
- package/dist/index.cjs +300 -268
- package/dist/index.d.cts +187 -13
- package/dist/index.d.ts +187 -13
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +19 -19
- package/dist/repositories/realm/index.js +5 -5
- package/dist/repositories/sqlite/index.cjs +18 -18
- package/dist/repositories/sqlite/index.js +5 -5
- package/dist/{taskRunner-BQb0W1XG.d.ts → taskRunner-BDzWbpct.d.ts} +1 -1
- package/dist/{taskRunner-BJ6_AnLq.d.cts → taskRunner-CIKOS2OO.d.cts} +1 -1
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +2 -2
- package/dist/wallet/expo/background.d.ts +2 -2
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +14 -14
- package/dist/wallet/expo/index.d.cts +1 -1
- package/dist/wallet/expo/index.d.ts +1 -1
- package/dist/wallet/expo/index.js +5 -5
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +3 -3
- package/dist/worker/expo/index.d.ts +3 -3
- package/dist/worker/expo/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-COOBS7ET.cjs.map +0 -1
- package/dist/chunk-CZFAMS57.js.map +0 -1
- package/dist/chunk-LG5GY73A.cjs.map +0 -1
- package/dist/chunk-OAESYVZQ.js.map +0 -1
- package/dist/chunk-OL7V43WS.cjs.map +0 -1
- package/dist/chunk-X7MMBB7S.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkGFZNEMGL_cjs = require('./chunk-GFZNEMGL.cjs');
|
|
4
|
+
var chunkG552MISJ_cjs = require('./chunk-G552MISJ.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: chunkGFZNEMGL_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) => chunkGFZNEMGL_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 contractRepository.getContracts()).filter(
|
|
58
|
+
const contracts = (await contractRepository.getContracts()).filter(chunkGFZNEMGL_cjs.isWatchedContract);
|
|
59
59
|
let contractsProcessed = 0;
|
|
60
60
|
let vtxosSaved = 0;
|
|
61
61
|
for (const contract of contracts) {
|
|
@@ -64,7 +64,7 @@ var contractPollProcessor = {
|
|
|
64
64
|
let hasMore = true;
|
|
65
65
|
const allVtxos = [];
|
|
66
66
|
while (hasMore) {
|
|
67
|
-
const { vtxos, page } = await
|
|
67
|
+
const { vtxos, page } = await chunkG552MISJ_cjs.getNormalizedVtxos(indexerProvider, {
|
|
68
68
|
scripts: [contract.script],
|
|
69
69
|
pageIndex,
|
|
70
70
|
pageSize
|
|
@@ -75,12 +75,12 @@ var contractPollProcessor = {
|
|
|
75
75
|
hasMore = page ? vtxos.length === pageSize : false;
|
|
76
76
|
pageIndex++;
|
|
77
77
|
}
|
|
78
|
-
const filtered =
|
|
78
|
+
const filtered = chunkGFZNEMGL_cjs.warnAndFilterVtxosForScript(
|
|
79
79
|
allVtxos,
|
|
80
80
|
contract.script,
|
|
81
81
|
"contractPollProcessor"
|
|
82
82
|
);
|
|
83
|
-
await
|
|
83
|
+
await chunkGFZNEMGL_cjs.saveVtxosForContract(walletRepository, contract, filtered);
|
|
84
84
|
vtxosSaved += filtered.length;
|
|
85
85
|
contractsProcessed++;
|
|
86
86
|
}
|
|
@@ -97,5 +97,5 @@ exports.CONTRACT_POLL_TASK_TYPE = CONTRACT_POLL_TASK_TYPE;
|
|
|
97
97
|
exports.contractPollProcessor = contractPollProcessor;
|
|
98
98
|
exports.createTaskDependencies = createTaskDependencies;
|
|
99
99
|
exports.runTasks = runTasks;
|
|
100
|
-
//# sourceMappingURL=chunk-
|
|
101
|
-
//# sourceMappingURL=chunk-
|
|
100
|
+
//# sourceMappingURL=chunk-7X744EFF.cjs.map
|
|
101
|
+
//# sourceMappingURL=chunk-7X744EFF.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":["getRandomId","extendVirtualCoinFor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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-K56BNZV3.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 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\";\nimport { isWatchedContract } from \"../../../contracts/types\";\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 contractRepository.getContracts()).filter(isWatchedContract);\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":["getRandomId","extendVirtualCoinForContract","isWatchedContract","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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IAAA,EAAM,uBAAA;AAAA,MACN,MAAA,EAAQ,SAAA;AAAA,MACR,IAAA,EAAM,EAAE,kBAAA,EAAoB,UAAA;AAAW,KAC3C;AAAA,EACJ;AACJ","file":"chunk-7X744EFF.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 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\";\nimport { isWatchedContract } from \"../../../contracts/types\";\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 contractRepository.getContracts()).filter(isWatchedContract);\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
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkG552MISJ_cjs = require('./chunk-G552MISJ.cjs');
|
|
4
4
|
var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
|
|
5
5
|
var base = require('@scure/base');
|
|
6
6
|
var descriptorsScure = require('@bitcoinerlab/descriptors-scure');
|
|
@@ -76,14 +76,14 @@ var ContractHandlerRegistry = class {
|
|
|
76
76
|
var contractHandlers = new ContractHandlerRegistry();
|
|
77
77
|
exports.DefaultVtxo = void 0;
|
|
78
78
|
((DefaultVtxo2) => {
|
|
79
|
-
class Script3 extends
|
|
79
|
+
class Script3 extends chunkG552MISJ_cjs.VtxoScript {
|
|
80
80
|
/** Create the default virtual output script with one forfeit path and one exit path. */
|
|
81
81
|
constructor(options) {
|
|
82
82
|
const { pubKey, serverPubKey, csvTimelock } = options;
|
|
83
|
-
const forfeitScript =
|
|
83
|
+
const forfeitScript = chunkG552MISJ_cjs.MultisigTapscript.encode({
|
|
84
84
|
pubkeys: [pubKey, serverPubKey]
|
|
85
85
|
}).script;
|
|
86
|
-
const exitScript =
|
|
86
|
+
const exitScript = chunkG552MISJ_cjs.CSVMultisigTapscript.encode({
|
|
87
87
|
timelock: csvTimelock,
|
|
88
88
|
pubkeys: [pubKey]
|
|
89
89
|
}).script;
|
|
@@ -288,7 +288,7 @@ function extractPubKeyBytes(value) {
|
|
|
288
288
|
return base.hex.decode(extractPubKey(normalizeToDescriptor(value)));
|
|
289
289
|
}
|
|
290
290
|
function deserializeCsvTimelock(value) {
|
|
291
|
-
return value !== void 0 && value !== "" ?
|
|
291
|
+
return value !== void 0 && value !== "" ? chunkG552MISJ_cjs.sequenceToTimelock(Number(value)) : exports.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
292
292
|
}
|
|
293
293
|
var CLTV_HEIGHT_THRESHOLD = 500000000n;
|
|
294
294
|
function isCltvSatisfied(context, locktime) {
|
|
@@ -330,7 +330,7 @@ function assertVhtlcSpendableNow(contract, context) {
|
|
|
330
330
|
function isCsvSpendable(context, sequence) {
|
|
331
331
|
if (sequence === void 0) return true;
|
|
332
332
|
if (!context.vtxo) return false;
|
|
333
|
-
const timelock =
|
|
333
|
+
const timelock = chunkG552MISJ_cjs.sequenceToTimelock(sequence);
|
|
334
334
|
if (timelock.type === "blocks") {
|
|
335
335
|
if (context.blockHeight === void 0 || context.vtxo.status.block_height === void 0) {
|
|
336
336
|
return false;
|
|
@@ -388,21 +388,21 @@ function forfeitExitSpendablePaths(script, contract, context) {
|
|
|
388
388
|
async function detectUsedScripts(indexerProvider, scriptHexes) {
|
|
389
389
|
const used = /* @__PURE__ */ new Set();
|
|
390
390
|
const unique = [...new Set(scriptHexes)];
|
|
391
|
-
for (let offset = 0; offset < unique.length; offset +=
|
|
392
|
-
const scripts = unique.slice(offset, offset +
|
|
391
|
+
for (let offset = 0; offset < unique.length; offset += chunkG552MISJ_cjs.SCRIPT_QUERY_CHUNK_SIZE) {
|
|
392
|
+
const scripts = unique.slice(offset, offset + chunkG552MISJ_cjs.SCRIPT_QUERY_CHUNK_SIZE);
|
|
393
393
|
const remaining = new Set(scripts);
|
|
394
394
|
let pageIndex = 0;
|
|
395
395
|
let hasMore = true;
|
|
396
396
|
while (hasMore && remaining.size > 0) {
|
|
397
|
-
const { vtxos, page } = await
|
|
397
|
+
const { vtxos, page } = await chunkG552MISJ_cjs.getNormalizedVtxos(indexerProvider, {
|
|
398
398
|
scripts,
|
|
399
399
|
pageIndex,
|
|
400
|
-
pageSize:
|
|
400
|
+
pageSize: chunkG552MISJ_cjs.DEFAULT_PAGE_SIZE
|
|
401
401
|
});
|
|
402
402
|
for (const vtxo of vtxos) {
|
|
403
403
|
if (remaining.delete(vtxo.script)) used.add(vtxo.script);
|
|
404
404
|
}
|
|
405
|
-
hasMore = page ? vtxos.length ===
|
|
405
|
+
hasMore = page ? vtxos.length === chunkG552MISJ_cjs.DEFAULT_PAGE_SIZE : false;
|
|
406
406
|
pageIndex++;
|
|
407
407
|
}
|
|
408
408
|
}
|
|
@@ -463,7 +463,7 @@ var DefaultContractHandler = {
|
|
|
463
463
|
return {
|
|
464
464
|
pubKey: base.hex.encode(params.pubKey),
|
|
465
465
|
serverPubKey: base.hex.encode(params.serverPubKey),
|
|
466
|
-
csvTimelock:
|
|
466
|
+
csvTimelock: chunkG552MISJ_cjs.timelockToSequence(params.csvTimelock).toString()
|
|
467
467
|
};
|
|
468
468
|
},
|
|
469
469
|
deserializeParams(params) {
|
|
@@ -498,7 +498,7 @@ function defaultCandidatesAt(_index, descriptor, deps) {
|
|
|
498
498
|
params: {
|
|
499
499
|
pubKey: base.hex.encode(c.pubKey),
|
|
500
500
|
serverPubKey: base.hex.encode(c.serverPubKey),
|
|
501
|
-
csvTimelock:
|
|
501
|
+
csvTimelock: chunkG552MISJ_cjs.timelockToSequence(c.csvTimelock).toString()
|
|
502
502
|
},
|
|
503
503
|
script: c.scriptHex,
|
|
504
504
|
address: c.script.address(deps.network.hrp, c.serverPubKey).encode()
|
|
@@ -514,12 +514,12 @@ function discoverDefaultRange(entries, deps) {
|
|
|
514
514
|
}
|
|
515
515
|
exports.DelegateVtxo = void 0;
|
|
516
516
|
((DelegateVtxo2) => {
|
|
517
|
-
class Script3 extends
|
|
517
|
+
class Script3 extends chunkG552MISJ_cjs.VtxoScript {
|
|
518
518
|
/** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
|
|
519
519
|
constructor(options) {
|
|
520
520
|
const defaultVtxo = new exports.DefaultVtxo.Script(options);
|
|
521
521
|
const { delegatePubKey, pubKey, serverPubKey } = options;
|
|
522
|
-
const delegateScript =
|
|
522
|
+
const delegateScript = chunkG552MISJ_cjs.MultisigTapscript.encode({
|
|
523
523
|
pubkeys: [pubKey, delegatePubKey, serverPubKey]
|
|
524
524
|
}).script;
|
|
525
525
|
super([...defaultVtxo.scripts, delegateScript]);
|
|
@@ -558,7 +558,7 @@ var DelegateContractHandler = {
|
|
|
558
558
|
pubKey: base.hex.encode(params.pubKey),
|
|
559
559
|
serverPubKey: base.hex.encode(params.serverPubKey),
|
|
560
560
|
delegatePubKey: base.hex.encode(params.delegatePubKey),
|
|
561
|
-
csvTimelock:
|
|
561
|
+
csvTimelock: chunkG552MISJ_cjs.timelockToSequence(params.csvTimelock).toString()
|
|
562
562
|
};
|
|
563
563
|
},
|
|
564
564
|
deserializeParams(params) {
|
|
@@ -602,7 +602,7 @@ function delegateCandidatesAt(_index, descriptor, deps) {
|
|
|
602
602
|
pubKey: base.hex.encode(c.pubKey),
|
|
603
603
|
serverPubKey: base.hex.encode(c.serverPubKey),
|
|
604
604
|
delegatePubKey: base.hex.encode(delegatePubKey),
|
|
605
|
-
csvTimelock:
|
|
605
|
+
csvTimelock: chunkG552MISJ_cjs.timelockToSequence(c.csvTimelock).toString()
|
|
606
606
|
},
|
|
607
607
|
script: c.scriptHex,
|
|
608
608
|
address: c.script.address(deps.network.hrp, c.serverPubKey).encode()
|
|
@@ -1437,7 +1437,7 @@ function computeArkadeScriptPublicKey(pubKey, script) {
|
|
|
1437
1437
|
// src/script/vhtlc.ts
|
|
1438
1438
|
exports.VHTLC = void 0;
|
|
1439
1439
|
((VHTLC2) => {
|
|
1440
|
-
class BaseScript extends
|
|
1440
|
+
class BaseScript extends chunkG552MISJ_cjs.VtxoScript {
|
|
1441
1441
|
options;
|
|
1442
1442
|
claimScript;
|
|
1443
1443
|
refundScript;
|
|
@@ -1462,27 +1462,27 @@ exports.VHTLC = void 0;
|
|
|
1462
1462
|
unilateralRefundWithoutReceiverDelay
|
|
1463
1463
|
} = options;
|
|
1464
1464
|
const conditionScript = preimageCondition(preimageHash);
|
|
1465
|
-
const claimScript =
|
|
1465
|
+
const claimScript = chunkG552MISJ_cjs.ConditionMultisigTapscript.encode({
|
|
1466
1466
|
conditionScript,
|
|
1467
1467
|
pubkeys: [receiver, server]
|
|
1468
1468
|
}).script;
|
|
1469
|
-
const refundScript =
|
|
1469
|
+
const refundScript = chunkG552MISJ_cjs.MultisigTapscript.encode({
|
|
1470
1470
|
pubkeys: [sender, receiver, server]
|
|
1471
1471
|
}).script;
|
|
1472
|
-
const refundWithoutReceiverScript =
|
|
1472
|
+
const refundWithoutReceiverScript = chunkG552MISJ_cjs.CLTVMultisigTapscript.encode({
|
|
1473
1473
|
absoluteTimelock: refundLocktime,
|
|
1474
1474
|
pubkeys: [sender, server]
|
|
1475
1475
|
}).script;
|
|
1476
|
-
const unilateralClaimScript =
|
|
1476
|
+
const unilateralClaimScript = chunkG552MISJ_cjs.ConditionCSVMultisigTapscript.encode({
|
|
1477
1477
|
conditionScript,
|
|
1478
1478
|
timelock: unilateralClaimDelay,
|
|
1479
1479
|
pubkeys: [receiver]
|
|
1480
1480
|
}).script;
|
|
1481
|
-
const unilateralRefundScript =
|
|
1481
|
+
const unilateralRefundScript = chunkG552MISJ_cjs.CSVMultisigTapscript.encode({
|
|
1482
1482
|
timelock: unilateralRefundDelay,
|
|
1483
1483
|
pubkeys: [sender, receiver]
|
|
1484
1484
|
}).script;
|
|
1485
|
-
const unilateralRefundWithoutReceiverScript =
|
|
1485
|
+
const unilateralRefundWithoutReceiverScript = chunkG552MISJ_cjs.CSVMultisigTapscript.encode({
|
|
1486
1486
|
timelock: unilateralRefundWithoutReceiverDelay,
|
|
1487
1487
|
pubkeys: [sender]
|
|
1488
1488
|
}).script;
|
|
@@ -1497,8 +1497,12 @@ exports.VHTLC = void 0;
|
|
|
1497
1497
|
let arkadeScriptNic;
|
|
1498
1498
|
let nonInteractiveClaimScript;
|
|
1499
1499
|
if (options.nonInteractiveClaim) {
|
|
1500
|
-
arkadeScriptNic =
|
|
1501
|
-
|
|
1500
|
+
arkadeScriptNic = enforcePayToMaybeAsset(
|
|
1501
|
+
options.nonInteractiveClaim.receiverPkScript,
|
|
1502
|
+
options.asset,
|
|
1503
|
+
options.nonInteractiveClaim.strict
|
|
1504
|
+
);
|
|
1505
|
+
nonInteractiveClaimScript = chunkG552MISJ_cjs.ConditionMultisigTapscript.encode({
|
|
1502
1506
|
conditionScript,
|
|
1503
1507
|
pubkeys: [
|
|
1504
1508
|
server,
|
|
@@ -1513,8 +1517,11 @@ exports.VHTLC = void 0;
|
|
|
1513
1517
|
let arkadeScriptNir;
|
|
1514
1518
|
let nonInteractiveRefundScript;
|
|
1515
1519
|
if (options.nonInteractiveRefund) {
|
|
1516
|
-
arkadeScriptNir =
|
|
1517
|
-
|
|
1520
|
+
arkadeScriptNir = enforcePayToMaybeAsset(
|
|
1521
|
+
options.nonInteractiveRefund.senderPkScript,
|
|
1522
|
+
options.asset
|
|
1523
|
+
);
|
|
1524
|
+
nonInteractiveRefundScript = chunkG552MISJ_cjs.MultisigTapscript.encode({
|
|
1518
1525
|
pubkeys: [
|
|
1519
1526
|
server,
|
|
1520
1527
|
receiver,
|
|
@@ -1616,6 +1623,30 @@ exports.VHTLC = void 0;
|
|
|
1616
1623
|
if (!preimageHash || preimageHash.length !== 20) {
|
|
1617
1624
|
throw new Error("preimage hash must be 20 bytes");
|
|
1618
1625
|
}
|
|
1626
|
+
if (options.asset !== void 0 && !options.nonInteractiveClaim && !options.nonInteractiveRefund) {
|
|
1627
|
+
throw new Error(
|
|
1628
|
+
"asset has no effect without nonInteractiveClaim or nonInteractiveRefund"
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1631
|
+
const strict = options.nonInteractiveClaim?.strict;
|
|
1632
|
+
if (strict !== void 0) {
|
|
1633
|
+
if (strict.amount <= 0n) {
|
|
1634
|
+
throw new Error(`strict claim amount must be positive, got ${strict.amount}`);
|
|
1635
|
+
}
|
|
1636
|
+
if (options.asset !== void 0 && strict.assetAmount === void 0) {
|
|
1637
|
+
throw new Error(
|
|
1638
|
+
"strict claim needs assetAmount when the contract is denominated in an asset: bounding only the sats would leave the asset amount unenforced"
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1641
|
+
if (options.asset === void 0 && strict.assetAmount !== void 0) {
|
|
1642
|
+
throw new Error("strict claim assetAmount has no effect without asset");
|
|
1643
|
+
}
|
|
1644
|
+
if (strict.assetAmount !== void 0 && strict.assetAmount <= 0n) {
|
|
1645
|
+
throw new Error(
|
|
1646
|
+
`strict claim assetAmount must be positive, got ${strict.assetAmount}`
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1619
1650
|
if (options.nonInteractiveClaim) {
|
|
1620
1651
|
const { emulatorPubkey, receiverPkScript } = options.nonInteractiveClaim;
|
|
1621
1652
|
if (!emulatorPubkey || emulatorPubkey.length !== 32 && emulatorPubkey.length !== 33) {
|
|
@@ -1684,11 +1715,8 @@ function preimageConditionScriptV2(preimageHash) {
|
|
|
1684
1715
|
function isP2trPkScript(pkScript) {
|
|
1685
1716
|
return pkScript.length === 34 && pkScript[0] === 81 && pkScript[1] === 32;
|
|
1686
1717
|
}
|
|
1687
|
-
function
|
|
1688
|
-
|
|
1689
|
-
throw new Error("invalid P2TR script");
|
|
1690
|
-
}
|
|
1691
|
-
return ArkadeScript.encode([
|
|
1718
|
+
function satClause(destinationPkScript, quotedSats) {
|
|
1719
|
+
return [
|
|
1692
1720
|
"PUSHCURRENTINPUTINDEX",
|
|
1693
1721
|
"DUP",
|
|
1694
1722
|
"INSPECTOUTPUTSCRIPTPUBKEY",
|
|
@@ -1697,11 +1725,68 @@ function enforcePayTo(destinationPkScript) {
|
|
|
1697
1725
|
destinationPkScript.subarray(2),
|
|
1698
1726
|
"EQUALVERIFY",
|
|
1699
1727
|
"INSPECTOUTPUTVALUE",
|
|
1728
|
+
// `DUP` because the output value is needed twice: once against the
|
|
1729
|
+
// quote, once against the input.
|
|
1730
|
+
...quotedSats === void 0 ? [] : ["DUP", quotedSats, "GREATERTHANOREQUAL", "VERIFY"],
|
|
1700
1731
|
"PUSHCURRENTINPUTINDEX",
|
|
1701
1732
|
"INSPECTINPUTVALUE",
|
|
1702
1733
|
"GREATERTHANOREQUAL"
|
|
1734
|
+
];
|
|
1735
|
+
}
|
|
1736
|
+
function enforcePayTo(destinationPkScript, quotedSats) {
|
|
1737
|
+
if (!isP2trPkScript(destinationPkScript)) {
|
|
1738
|
+
throw new Error("invalid P2TR script");
|
|
1739
|
+
}
|
|
1740
|
+
return ArkadeScript.encode(satClause(destinationPkScript, quotedSats));
|
|
1741
|
+
}
|
|
1742
|
+
function enforcePayToAsset(destinationPkScript, asset, strict) {
|
|
1743
|
+
if (!isP2trPkScript(destinationPkScript)) {
|
|
1744
|
+
throw new Error("invalid P2TR script");
|
|
1745
|
+
}
|
|
1746
|
+
if (asset.txid.length !== 32) {
|
|
1747
|
+
throw new Error(`asset txid must be 32 bytes, got ${asset.txid.length}`);
|
|
1748
|
+
}
|
|
1749
|
+
if (!Number.isInteger(asset.groupIndex) || asset.groupIndex < 0 || asset.groupIndex > 65535) {
|
|
1750
|
+
throw new Error(
|
|
1751
|
+
`asset group index must be an integer in [0, 65535], got ${asset.groupIndex}`
|
|
1752
|
+
);
|
|
1753
|
+
}
|
|
1754
|
+
const inspectionTxid = Uint8Array.from(asset.txid).reverse();
|
|
1755
|
+
return ArkadeScript.encode([
|
|
1756
|
+
// The output carries at least as much of the asset as the input did.
|
|
1757
|
+
// Output index is the input's -- the same index alignment the sat
|
|
1758
|
+
// covenant relies on, and the same liveness obligation on whoever
|
|
1759
|
+
// assembles the spend.
|
|
1760
|
+
"PUSHCURRENTINPUTINDEX",
|
|
1761
|
+
inspectionTxid,
|
|
1762
|
+
asset.groupIndex,
|
|
1763
|
+
"INSPECTOUTASSETLOOKUP",
|
|
1764
|
+
"VERIFY",
|
|
1765
|
+
// PRESENT on the output, not merely "zero of it"
|
|
1766
|
+
// The quoted bound, when the caller opted in — added to the input
|
|
1767
|
+
// comparison below, not substituted for it. `DUP` because the output's
|
|
1768
|
+
// asset amount is needed twice.
|
|
1769
|
+
...strict?.assetAmount === void 0 ? [] : ["DUP", strict.assetAmount, "GREATERTHANOREQUAL", "VERIFY"],
|
|
1770
|
+
"PUSHCURRENTINPUTINDEX",
|
|
1771
|
+
inspectionTxid,
|
|
1772
|
+
asset.groupIndex,
|
|
1773
|
+
"INSPECTINASSETLOOKUP",
|
|
1774
|
+
"VERIFY",
|
|
1775
|
+
// ...and on the input, so the comparison means something
|
|
1776
|
+
"GREATERTHANOREQUAL",
|
|
1777
|
+
"VERIFY",
|
|
1778
|
+
// Exactly one asset out: nothing injected alongside the one bound.
|
|
1779
|
+
"PUSHCURRENTINPUTINDEX",
|
|
1780
|
+
"INSPECTOUTASSETCOUNT",
|
|
1781
|
+
1,
|
|
1782
|
+
"EQUALVERIFY",
|
|
1783
|
+
// ...then the sat covenant, the same tokens `enforcePayTo` emits.
|
|
1784
|
+
...satClause(destinationPkScript, strict?.amount)
|
|
1703
1785
|
]);
|
|
1704
1786
|
}
|
|
1787
|
+
function enforcePayToMaybeAsset(destinationPkScript, asset, strict) {
|
|
1788
|
+
return asset === void 0 ? enforcePayTo(destinationPkScript, strict?.amount) : enforcePayToAsset(destinationPkScript, asset, strict);
|
|
1789
|
+
}
|
|
1705
1790
|
|
|
1706
1791
|
// src/contracts/handlers/vhtlc.ts
|
|
1707
1792
|
var VHTLCContractHandler = {
|
|
@@ -1717,9 +1802,9 @@ var VHTLCContractHandler = {
|
|
|
1717
1802
|
server: base.hex.encode(params.server),
|
|
1718
1803
|
hash: base.hex.encode(params.preimageHash),
|
|
1719
1804
|
refundLocktime: params.refundLocktime.toString(),
|
|
1720
|
-
claimDelay:
|
|
1721
|
-
refundDelay:
|
|
1722
|
-
refundNoReceiverDelay:
|
|
1805
|
+
claimDelay: chunkG552MISJ_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
|
|
1806
|
+
refundDelay: chunkG552MISJ_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
|
|
1807
|
+
refundNoReceiverDelay: chunkG552MISJ_cjs.timelockToSequence(
|
|
1723
1808
|
params.unilateralRefundWithoutReceiverDelay
|
|
1724
1809
|
).toString()
|
|
1725
1810
|
};
|
|
@@ -1731,9 +1816,9 @@ var VHTLCContractHandler = {
|
|
|
1731
1816
|
server: base.hex.decode(params.server),
|
|
1732
1817
|
preimageHash: base.hex.decode(params.hash),
|
|
1733
1818
|
refundLocktime: BigInt(params.refundLocktime),
|
|
1734
|
-
unilateralClaimDelay:
|
|
1735
|
-
unilateralRefundDelay:
|
|
1736
|
-
unilateralRefundWithoutReceiverDelay:
|
|
1819
|
+
unilateralClaimDelay: chunkG552MISJ_cjs.sequenceToTimelock(Number(params.claimDelay)),
|
|
1820
|
+
unilateralRefundDelay: chunkG552MISJ_cjs.sequenceToTimelock(Number(params.refundDelay)),
|
|
1821
|
+
unilateralRefundWithoutReceiverDelay: chunkG552MISJ_cjs.sequenceToTimelock(
|
|
1737
1822
|
Number(params.refundNoReceiverDelay)
|
|
1738
1823
|
)
|
|
1739
1824
|
};
|
|
@@ -1948,6 +2033,14 @@ var VHTLCContractHandler = {
|
|
|
1948
2033
|
};
|
|
1949
2034
|
}
|
|
1950
2035
|
};
|
|
2036
|
+
var parseGroupIndex = (raw) => {
|
|
2037
|
+
if (!/^(0|[1-9][0-9]*)$/.test(raw)) {
|
|
2038
|
+
throw new Error(
|
|
2039
|
+
`assetGroupIndex must be a canonical decimal integer, got ${JSON.stringify(raw)}`
|
|
2040
|
+
);
|
|
2041
|
+
}
|
|
2042
|
+
return Number(raw);
|
|
2043
|
+
};
|
|
1951
2044
|
function decodeCovenantLeaf(params, destinationKey, emulatorKey, label) {
|
|
1952
2045
|
const destination = params[destinationKey];
|
|
1953
2046
|
const emulator = params[emulatorKey];
|
|
@@ -1970,9 +2063,9 @@ var VHTLCV2ContractHandler = {
|
|
|
1970
2063
|
server: base.hex.encode(params.server),
|
|
1971
2064
|
hash: base.hex.encode(params.preimageHash),
|
|
1972
2065
|
refundLocktime: params.refundLocktime.toString(),
|
|
1973
|
-
claimDelay:
|
|
1974
|
-
refundDelay:
|
|
1975
|
-
refundNoReceiverDelay:
|
|
2066
|
+
claimDelay: chunkG552MISJ_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
|
|
2067
|
+
refundDelay: chunkG552MISJ_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
|
|
2068
|
+
refundNoReceiverDelay: chunkG552MISJ_cjs.timelockToSequence(
|
|
1976
2069
|
params.unilateralRefundWithoutReceiverDelay
|
|
1977
2070
|
).toString(),
|
|
1978
2071
|
// Spread rather than written as `undefined`: a `Record<string,
|
|
@@ -1984,7 +2077,17 @@ var VHTLCV2ContractHandler = {
|
|
|
1984
2077
|
),
|
|
1985
2078
|
nonInteractiveClaimEmulatorPubkey: base.hex.encode(
|
|
1986
2079
|
params.nonInteractiveClaim.emulatorPubkey
|
|
1987
|
-
)
|
|
2080
|
+
),
|
|
2081
|
+
// The opt-in quoted bound. Dropping it re-derives the DEFAULT
|
|
2082
|
+
// claim covenant — a strictly weaker one — and registration dies
|
|
2083
|
+
// at `upsertContractRow` with an opaque `Script mismatch`. Same
|
|
2084
|
+
// silent-drop class as the asset keys above.
|
|
2085
|
+
...params.nonInteractiveClaim.strict && {
|
|
2086
|
+
strictClaimAmount: params.nonInteractiveClaim.strict.amount.toString(),
|
|
2087
|
+
...params.nonInteractiveClaim.strict.assetAmount !== void 0 && {
|
|
2088
|
+
strictClaimAssetAmount: params.nonInteractiveClaim.strict.assetAmount.toString()
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
1988
2091
|
},
|
|
1989
2092
|
...params.nonInteractiveRefund && {
|
|
1990
2093
|
nonInteractiveRefundSenderPkScript: base.hex.encode(
|
|
@@ -1993,6 +2096,19 @@ var VHTLCV2ContractHandler = {
|
|
|
1993
2096
|
nonInteractiveRefundEmulatorPubkey: base.hex.encode(
|
|
1994
2097
|
params.nonInteractiveRefund.emulatorPubkey
|
|
1995
2098
|
)
|
|
2099
|
+
},
|
|
2100
|
+
// The asset must round-trip, and its absence here used to be silent
|
|
2101
|
+
// in the worst way. `ContractManager` re-derives a contract from
|
|
2102
|
+
// these params; dropping the asset derives the SAT-ONLY script, so
|
|
2103
|
+
// registration died at `upsertContractRow` with a `Script mismatch`
|
|
2104
|
+
// naming two hex strings and no cause. Same silent-drop class
|
|
2105
|
+
// `validateOptions` refuses one layer up.
|
|
2106
|
+
//
|
|
2107
|
+
// Two keys rather than one blob, mirroring the script's own view of
|
|
2108
|
+
// an Asset ID as a (txid, groupIndex) pair.
|
|
2109
|
+
...params.asset && {
|
|
2110
|
+
assetTxid: base.hex.encode(params.asset.txid),
|
|
2111
|
+
assetGroupIndex: params.asset.groupIndex.toString()
|
|
1996
2112
|
}
|
|
1997
2113
|
};
|
|
1998
2114
|
},
|
|
@@ -2009,21 +2125,44 @@ var VHTLCV2ContractHandler = {
|
|
|
2009
2125
|
"nonInteractiveRefundEmulatorPubkey",
|
|
2010
2126
|
"nonInteractiveRefund"
|
|
2011
2127
|
);
|
|
2128
|
+
if (params.assetTxid === void 0 !== (params.assetGroupIndex === void 0)) {
|
|
2129
|
+
throw new Error(
|
|
2130
|
+
"asset params are incomplete: assetTxid and assetGroupIndex must both be present or both absent"
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
if (params.strictClaimAssetAmount !== void 0 && params.strictClaimAmount === void 0) {
|
|
2134
|
+
throw new Error(
|
|
2135
|
+
"strictClaimAssetAmount without strictClaimAmount: reading this as 'not strict' would re-derive the default claim covenant, which is weaker than the row asked for"
|
|
2136
|
+
);
|
|
2137
|
+
}
|
|
2138
|
+
const asset = params.assetTxid !== void 0 && params.assetGroupIndex !== void 0 ? {
|
|
2139
|
+
txid: base.hex.decode(params.assetTxid),
|
|
2140
|
+
groupIndex: parseGroupIndex(params.assetGroupIndex)
|
|
2141
|
+
} : void 0;
|
|
2012
2142
|
return {
|
|
2013
2143
|
sender: base.hex.decode(params.sender),
|
|
2014
2144
|
receiver: base.hex.decode(params.receiver),
|
|
2015
2145
|
server: base.hex.decode(params.server),
|
|
2016
2146
|
preimageHash: base.hex.decode(params.hash),
|
|
2017
2147
|
refundLocktime: BigInt(params.refundLocktime),
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2148
|
+
...asset && { asset },
|
|
2149
|
+
unilateralClaimDelay: chunkG552MISJ_cjs.sequenceToTimelock(Number(params.claimDelay)),
|
|
2150
|
+
unilateralRefundDelay: chunkG552MISJ_cjs.sequenceToTimelock(Number(params.refundDelay)),
|
|
2151
|
+
unilateralRefundWithoutReceiverDelay: chunkG552MISJ_cjs.sequenceToTimelock(
|
|
2021
2152
|
Number(params.refundNoReceiverDelay)
|
|
2022
2153
|
),
|
|
2023
2154
|
...claim && {
|
|
2024
2155
|
nonInteractiveClaim: {
|
|
2025
2156
|
receiverPkScript: claim.destination,
|
|
2026
|
-
emulatorPubkey: claim.emulatorPubkey
|
|
2157
|
+
emulatorPubkey: claim.emulatorPubkey,
|
|
2158
|
+
...params.strictClaimAmount !== void 0 && {
|
|
2159
|
+
strict: {
|
|
2160
|
+
amount: BigInt(params.strictClaimAmount),
|
|
2161
|
+
...params.strictClaimAssetAmount !== void 0 && {
|
|
2162
|
+
assetAmount: BigInt(params.strictClaimAssetAmount)
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2027
2166
|
}
|
|
2028
2167
|
},
|
|
2029
2168
|
...refund && {
|
|
@@ -2290,7 +2429,7 @@ var BoardingContractHandler = {
|
|
|
2290
2429
|
const coins = await deps.onchainProvider.getCoins(onchainAddress);
|
|
2291
2430
|
if (coins.length === 0) return [];
|
|
2292
2431
|
const scriptHex = base.hex.encode(script.pkScript);
|
|
2293
|
-
const boardingSeq =
|
|
2432
|
+
const boardingSeq = chunkG552MISJ_cjs.timelockToSequence(deps.boardingTimelock);
|
|
2294
2433
|
return [
|
|
2295
2434
|
{
|
|
2296
2435
|
type: "boarding",
|
|
@@ -2451,27 +2590,27 @@ function encodeTapscriptSegment(seg, pubkeys, args) {
|
|
|
2451
2590
|
if (seg.csv) {
|
|
2452
2591
|
const timelock = { type: seg.csv.type, value: resolveTimelockValue(seg.csv.value, args) };
|
|
2453
2592
|
if (seg.asm) {
|
|
2454
|
-
return
|
|
2593
|
+
return chunkG552MISJ_cjs.ConditionCSVMultisigTapscript.encode({
|
|
2455
2594
|
conditionScript: resolveAsm(seg.asm, args),
|
|
2456
2595
|
timelock,
|
|
2457
2596
|
pubkeys
|
|
2458
2597
|
});
|
|
2459
2598
|
}
|
|
2460
|
-
return
|
|
2599
|
+
return chunkG552MISJ_cjs.CSVMultisigTapscript.encode({ timelock, pubkeys });
|
|
2461
2600
|
}
|
|
2462
2601
|
if (seg.cltv !== void 0) {
|
|
2463
|
-
return
|
|
2602
|
+
return chunkG552MISJ_cjs.CLTVMultisigTapscript.encode({
|
|
2464
2603
|
absoluteTimelock: resolveTimelockValue(seg.cltv, args),
|
|
2465
2604
|
pubkeys
|
|
2466
2605
|
});
|
|
2467
2606
|
}
|
|
2468
2607
|
if (seg.asm) {
|
|
2469
|
-
return
|
|
2608
|
+
return chunkG552MISJ_cjs.ConditionMultisigTapscript.encode({
|
|
2470
2609
|
conditionScript: resolveAsm(seg.asm, args),
|
|
2471
2610
|
pubkeys
|
|
2472
2611
|
});
|
|
2473
2612
|
}
|
|
2474
|
-
return
|
|
2613
|
+
return chunkG552MISJ_cjs.MultisigTapscript.encode({ pubkeys });
|
|
2475
2614
|
}
|
|
2476
2615
|
function compileFunctions(program, args, keys) {
|
|
2477
2616
|
if (program.version !== SUPPORTED_PROGRAM_VERSION) {
|
|
@@ -2501,7 +2640,7 @@ function compileFunctions(program, args, keys) {
|
|
|
2501
2640
|
return { name: names[i], def, leafScript, arkadeScript, signerKeys: pubkeys };
|
|
2502
2641
|
});
|
|
2503
2642
|
}
|
|
2504
|
-
var ArkadeProgramScript = class extends
|
|
2643
|
+
var ArkadeProgramScript = class extends chunkG552MISJ_cjs.VtxoScript {
|
|
2505
2644
|
constructor(program, args, keys) {
|
|
2506
2645
|
const partial = compileFunctions(program, args, keys);
|
|
2507
2646
|
super(partial.map((p) => p.leafScript));
|
|
@@ -2714,7 +2853,7 @@ function pathsFor(script, context, opts) {
|
|
|
2714
2853
|
continue;
|
|
2715
2854
|
}
|
|
2716
2855
|
if (requiresServer) continue;
|
|
2717
|
-
const sequence = csv ? Number(
|
|
2856
|
+
const sequence = csv ? Number(chunkG552MISJ_cjs.timelockToSequence(csv)) : void 0;
|
|
2718
2857
|
if (opts.checkTimelocks && csv && !isCsvSpendable(context, sequence)) continue;
|
|
2719
2858
|
if (opts.checkTimelocks && cltv !== void 0 && !isCltvSatisfied(context, cltv)) {
|
|
2720
2859
|
continue;
|
|
@@ -2842,5 +2981,5 @@ exports.stringifyArtifact = stringifyArtifact;
|
|
|
2842
2981
|
exports.toASM = toASM;
|
|
2843
2982
|
exports.validateProgram = validateProgram;
|
|
2844
2983
|
exports.witnessRefToBytes = witnessRefToBytes;
|
|
2845
|
-
//# sourceMappingURL=chunk-
|
|
2846
|
-
//# sourceMappingURL=chunk-
|
|
2984
|
+
//# sourceMappingURL=chunk-BABJ77NG.cjs.map
|
|
2985
|
+
//# sourceMappingURL=chunk-BABJ77NG.cjs.map
|