@arkade-os/sdk 0.4.59 → 0.4.61

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.
Files changed (88) hide show
  1. package/README.md +34 -6
  2. package/dist/adapters/expo.cjs +5 -5
  3. package/dist/adapters/expo.d.cts +4 -4
  4. package/dist/adapters/expo.d.ts +4 -4
  5. package/dist/adapters/expo.js +3 -3
  6. package/dist/adapters/indexedDB.cjs +5 -5
  7. package/dist/adapters/indexedDB.js +4 -4
  8. package/dist/{asyncStorageTaskQueue-CYHXFfvn.d.cts → asyncStorageTaskQueue-BWDxp3Dr.d.cts} +2 -2
  9. package/dist/{asyncStorageTaskQueue-BwuWQ1Qc.d.ts → asyncStorageTaskQueue-Cq9FpKv6.d.ts} +2 -2
  10. package/dist/{chunk-V2KENVN6.cjs → chunk-2JHN5RCY.cjs} +22 -15
  11. package/dist/chunk-2JHN5RCY.cjs.map +1 -0
  12. package/dist/{chunk-DYNB6POO.cjs → chunk-3NUDA3MB.cjs} +4423 -2934
  13. package/dist/chunk-3NUDA3MB.cjs.map +1 -0
  14. package/dist/{chunk-PN5RD7ZI.js → chunk-6O5OLYTZ.js} +1685 -1138
  15. package/dist/chunk-6O5OLYTZ.js.map +1 -0
  16. package/dist/{chunk-OVSNY3HC.js → chunk-AUEXB42T.js} +3965 -2503
  17. package/dist/chunk-AUEXB42T.js.map +1 -0
  18. package/dist/{chunk-DSTYXT2D.cjs → chunk-FNCQJLR2.cjs} +44 -6
  19. package/dist/chunk-FNCQJLR2.cjs.map +1 -0
  20. package/dist/{chunk-VSHY5TBY.js → chunk-GDI2A65Z.js} +4 -4
  21. package/dist/{chunk-VSHY5TBY.js.map → chunk-GDI2A65Z.js.map} +1 -1
  22. package/dist/{chunk-FIMOVH25.js → chunk-PVY6DMN5.js} +40 -7
  23. package/dist/chunk-PVY6DMN5.js.map +1 -0
  24. package/dist/{chunk-2XO43UHI.cjs → chunk-SF5NKAUA.cjs} +1731 -1180
  25. package/dist/chunk-SF5NKAUA.cjs.map +1 -0
  26. package/dist/{chunk-7FA36NOA.cjs → chunk-XFYFREPH.cjs} +17 -17
  27. package/dist/{chunk-7FA36NOA.cjs.map → chunk-XFYFREPH.cjs.map} +1 -1
  28. package/dist/{chunk-H342JPPZ.js → chunk-XLHN5L2O.js} +5 -5
  29. package/dist/chunk-XLHN5L2O.js.map +1 -0
  30. package/dist/{chunk-IPFGYVF3.cjs → chunk-XMRB74HA.cjs} +10 -10
  31. package/dist/chunk-XMRB74HA.cjs.map +1 -0
  32. package/dist/{chunk-YEHGCHIL.js → chunk-YVQNHELA.js} +12 -5
  33. package/dist/chunk-YVQNHELA.js.map +1 -0
  34. package/dist/contracts/handlers/index.cjs +12 -8
  35. package/dist/contracts/handlers/index.d.cts +5 -5
  36. package/dist/contracts/handlers/index.d.ts +5 -5
  37. package/dist/contracts/handlers/index.js +2 -2
  38. package/dist/{delegate-D0eGaz3J.d.cts → delegate-BySzD37I.d.ts} +1 -1
  39. package/dist/{delegate-B_oKWm1k.d.ts → delegate-C4Rl6h9l.d.cts} +1 -1
  40. package/dist/{ark-C9DsPSm8.d.cts → index-BcRCHnzN.d.cts} +4887 -4331
  41. package/dist/{ark-C9DsPSm8.d.ts → index-BcRCHnzN.d.ts} +4887 -4331
  42. package/dist/{index-BmK6tEqf.d.ts → index-Butfkm-K.d.cts} +224 -68
  43. package/dist/{index-BG2AL2Ie.d.cts → index-C29VNcxC.d.ts} +224 -68
  44. package/dist/index.cjs +374 -230
  45. package/dist/index.d.cts +522 -82
  46. package/dist/index.d.ts +522 -82
  47. package/dist/index.js +4 -4
  48. package/dist/repositories/realm/index.cjs +43 -23
  49. package/dist/repositories/realm/index.cjs.map +1 -1
  50. package/dist/repositories/realm/index.d.cts +23 -11
  51. package/dist/repositories/realm/index.d.ts +23 -11
  52. package/dist/repositories/realm/index.js +29 -9
  53. package/dist/repositories/realm/index.js.map +1 -1
  54. package/dist/repositories/sqlite/index.cjs +48 -23
  55. package/dist/repositories/sqlite/index.cjs.map +1 -1
  56. package/dist/repositories/sqlite/index.d.cts +11 -5
  57. package/dist/repositories/sqlite/index.d.ts +11 -5
  58. package/dist/repositories/sqlite/index.js +35 -10
  59. package/dist/repositories/sqlite/index.js.map +1 -1
  60. package/dist/{taskRunner-Cy4Gh8n7.d.ts → taskRunner-BTq3rMpI.d.cts} +2 -2
  61. package/dist/{taskRunner-CBvKIttE.d.cts → taskRunner-DxMJYJ7Y.d.ts} +2 -2
  62. package/dist/wallet/expo/background.cjs +14 -14
  63. package/dist/wallet/expo/background.d.cts +5 -5
  64. package/dist/wallet/expo/background.d.ts +5 -5
  65. package/dist/wallet/expo/background.js +6 -6
  66. package/dist/wallet/expo/index.cjs +37 -14
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +13 -5
  69. package/dist/wallet/expo/index.d.ts +13 -5
  70. package/dist/wallet/expo/index.js +28 -5
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/{wallet-EyVDhqzP.d.ts → wallet-BVIfg2ic.d.ts} +222 -19
  73. package/dist/{wallet-DlXemAzP.d.cts → wallet-DrSsUden.d.cts} +222 -19
  74. package/dist/worker/expo/index.cjs +9 -9
  75. package/dist/worker/expo/index.d.cts +7 -7
  76. package/dist/worker/expo/index.d.ts +7 -7
  77. package/dist/worker/expo/index.js +5 -5
  78. package/package.json +4 -2
  79. package/dist/chunk-2XO43UHI.cjs.map +0 -1
  80. package/dist/chunk-DSTYXT2D.cjs.map +0 -1
  81. package/dist/chunk-DYNB6POO.cjs.map +0 -1
  82. package/dist/chunk-FIMOVH25.js.map +0 -1
  83. package/dist/chunk-H342JPPZ.js.map +0 -1
  84. package/dist/chunk-IPFGYVF3.cjs.map +0 -1
  85. package/dist/chunk-OVSNY3HC.js.map +0 -1
  86. package/dist/chunk-PN5RD7ZI.js.map +0 -1
  87. package/dist/chunk-V2KENVN6.cjs.map +0 -1
  88. package/dist/chunk-YEHGCHIL.js.map +0 -1
@@ -1,71 +1,7 @@
1
- import { p as RelativeTimelock, V as VtxoScript, q as TapLeafScript, b9 as ContractHandler, bk as Discoverable, cC as TapscriptDeriving } from './ark-C9DsPSm8.js';
2
- import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-B_oKWm1k.js';
1
+ import { ba as ContractHandler, p as RelativeTimelock, bl as Discoverable, V as VtxoScript, q as TapLeafScript, cO as TapscriptDeriving } from './index-BcRCHnzN.cjs';
2
+ import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-C4Rl6h9l.cjs';
3
3
  import { Bytes } from '@scure/btc-signer/utils.js';
4
4
 
5
- /** Virtual Hash Time Lock Contract (VHTLC) namespace. */
6
- declare namespace VHTLC {
7
- interface Options {
8
- sender: Bytes;
9
- receiver: Bytes;
10
- server: Bytes;
11
- preimageHash: Bytes;
12
- refundLocktime: bigint;
13
- unilateralClaimDelay: RelativeTimelock;
14
- unilateralRefundDelay: RelativeTimelock;
15
- unilateralRefundWithoutReceiverDelay: RelativeTimelock;
16
- }
17
- /**
18
- * Virtual Hash Time Lock Contract (VHTLC) script implementation.
19
- *
20
- * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
21
- * It provides multiple spending paths:
22
- *
23
- * - **claim**: Receiver can claim funds by revealing the preimage
24
- * - **refund**: Sender and receiver can collaboratively refund
25
- * - **refundWithoutReceiver**: Sender can refund after locktime expires
26
- * - **unilateralClaim**: Receiver can claim unilaterally after delay
27
- * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
28
- * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
29
- *
30
- * @example
31
- * ```typescript
32
- * const vhtlc = new VHTLC.Script({
33
- * sender: alicePubKey,
34
- * receiver: bobPubKey,
35
- * server: serverPubKey,
36
- * preimageHash: hash160(secret),
37
- * refundLocktime: BigInt(chainTip + 10),
38
- * unilateralClaimDelay: { type: 'blocks', value: 100n },
39
- * unilateralRefundDelay: { type: 'blocks', value: 102n },
40
- * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
41
- * });
42
- * ```
43
- */
44
- class Script extends VtxoScript {
45
- readonly options: Options;
46
- readonly claimScript: string;
47
- readonly refundScript: string;
48
- readonly refundWithoutReceiverScript: string;
49
- readonly unilateralClaimScript: string;
50
- readonly unilateralRefundScript: string;
51
- readonly unilateralRefundWithoutReceiverScript: string;
52
- /** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */
53
- constructor(options: Options);
54
- /** Return the collaborative claim tapleaf script. */
55
- claim(): TapLeafScript;
56
- /** Return the collaborative refund tapleaf script. */
57
- refund(): TapLeafScript;
58
- /** Return the refund-without-receiver tapleaf script. */
59
- refundWithoutReceiver(): TapLeafScript;
60
- /** Return the unilateral claim tapleaf script. */
61
- unilateralClaim(): TapLeafScript;
62
- /** Return the unilateral refund tapleaf script. */
63
- unilateralRefund(): TapLeafScript;
64
- /** Return the unilateral refund-without-receiver tapleaf script. */
65
- unilateralRefundWithoutReceiver(): TapLeafScript;
66
- }
67
- }
68
-
69
5
  /**
70
6
  * Registry for contract handlers.
71
7
  *
@@ -166,6 +102,142 @@ interface DelegateContractParams {
166
102
  */
167
103
  declare const DelegateContractHandler: ContractHandler<DelegateContractParams, DelegateVtxo.Script> & Discoverable;
168
104
 
105
+ /** Virtual Hash Time Lock Contract (VHTLC) namespace. */
106
+ declare namespace VHTLC {
107
+ export interface Options {
108
+ sender: Bytes;
109
+ receiver: Bytes;
110
+ server: Bytes;
111
+ preimageHash: Bytes;
112
+ refundLocktime: bigint;
113
+ unilateralClaimDelay: RelativeTimelock;
114
+ unilateralRefundDelay: RelativeTimelock;
115
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
116
+ /**
117
+ * Optional non-interactive claim leaf: `server` plus a covenant-tweaked
118
+ * emulator co-signer, pinned to `receiverPkScript`. Lets the receiver's
119
+ * claim be pushed by the emulator without the receiver being online.
120
+ */
121
+ nonInteractiveClaim?: {
122
+ receiverPkScript: Bytes;
123
+ emulatorPubkey: Bytes;
124
+ };
125
+ /**
126
+ * Optional non-interactive refund leaf: `server` + `receiver` + a
127
+ * covenant-tweaked emulator co-signer, pinned to `senderPkScript`, no
128
+ * timelock. Every OTHER refund-side leaf in this contract requires
129
+ * the sender's own signature — if the sender permanently loses that
130
+ * key, none of them are reachable. This leaf is the one exception:
131
+ * it needs neither the sender's presence nor their key, so funds
132
+ * remain recoverable to the sender's pre-committed address even
133
+ * then. It still needs the receiver (unlike `nonInteractiveClaim`,
134
+ * which needs only server + emulator) — deliberately: this is what
135
+ * lets server + receiver release the refund immediately, the moment
136
+ * they agree the swap has failed, rather than making the sender wait
137
+ * out `refundLocktime` the way {@link Script.refundWithoutReceiver}
138
+ * does.
139
+ */
140
+ nonInteractiveRefund?: {
141
+ senderPkScript: Bytes;
142
+ emulatorPubkey: Bytes;
143
+ };
144
+ }
145
+ /**
146
+ * Shared construction and accessors for every VHTLC script version. The
147
+ * only thing that varies between versions is which preimage-condition
148
+ * fragment `claim`/`unilateralClaim`/`nonInteractiveClaim` are built
149
+ * from — everything else (the multisig/timelock leaves, the
150
+ * non-interactive covenant leaves, the accessor methods) is identical,
151
+ * so versions are expressed as thin subclasses over one builder rather
152
+ * than as separate, independently-maintained copies of this class.
153
+ */
154
+ abstract class BaseScript extends VtxoScript {
155
+ readonly options: Options;
156
+ readonly claimScript: string;
157
+ readonly refundScript: string;
158
+ readonly refundWithoutReceiverScript: string;
159
+ readonly unilateralClaimScript: string;
160
+ readonly unilateralRefundScript: string;
161
+ readonly unilateralRefundWithoutReceiverScript: string;
162
+ readonly nonInteractiveClaimScript?: string;
163
+ readonly nonInteractiveClaimArkadeScript?: Bytes;
164
+ readonly nonInteractiveRefundScript?: string;
165
+ readonly nonInteractiveRefundArkadeScript?: Bytes;
166
+ protected constructor(options: Options, preimageCondition: (hash: Bytes) => Bytes);
167
+ /** Return the collaborative claim tapleaf script. */
168
+ claim(): TapLeafScript;
169
+ /** Return the collaborative refund tapleaf script. */
170
+ refund(): TapLeafScript;
171
+ /** Return the refund-without-receiver tapleaf script. */
172
+ refundWithoutReceiver(): TapLeafScript;
173
+ /** Return the unilateral claim tapleaf script. */
174
+ unilateralClaim(): TapLeafScript;
175
+ /** Return the unilateral refund tapleaf script. */
176
+ unilateralRefund(): TapLeafScript;
177
+ /** Return the unilateral refund-without-receiver tapleaf script. */
178
+ unilateralRefundWithoutReceiver(): TapLeafScript;
179
+ /** Return the non-interactive claim tapleaf script as well as the ArkadeScript. */
180
+ nonInteractiveClaim(): [TapLeafScript, Bytes];
181
+ /** Return the non-interactive refund tapleaf script as well as the ArkadeScript. */
182
+ nonInteractiveRefund(): [TapLeafScript, Bytes];
183
+ }
184
+ /**
185
+ * Virtual Hash Time Lock Contract (VHTLC) script implementation.
186
+ *
187
+ * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
188
+ * It provides multiple spending paths:
189
+ *
190
+ * - **claim**: Receiver can claim funds by revealing the preimage
191
+ * - **refund**: Sender and receiver can collaboratively refund
192
+ * - **refundWithoutReceiver**: Sender can refund after locktime expires
193
+ * - **unilateralClaim**: Receiver can claim unilaterally after delay
194
+ * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
195
+ * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
196
+ * - **nonInteractiveClaim** (optional): server + emulator can push the
197
+ * receiver's claim, pinned to a pre-committed destination
198
+ * - **nonInteractiveRefund** (optional): server + receiver + emulator
199
+ * can push the sender's refund immediately, no timelock, pinned to a
200
+ * pre-committed destination — recoverable even if the sender's own key
201
+ * is lost
202
+ *
203
+ * See {@link ScriptV2} for the current recommended construction — same
204
+ * leaf ladder, same options shape, an added length check on the claim
205
+ * preimage. This class is unchanged and stays available as-is.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const vhtlc = new VHTLC.Script({
210
+ * sender: alicePubKey,
211
+ * receiver: bobPubKey,
212
+ * server: serverPubKey,
213
+ * preimageHash: hash160(secret),
214
+ * refundLocktime: BigInt(chainTip + 10),
215
+ * unilateralClaimDelay: { type: 'blocks', value: 100n },
216
+ * unilateralRefundDelay: { type: 'blocks', value: 102n },
217
+ * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
218
+ * });
219
+ * ```
220
+ */
221
+ export class Script extends BaseScript {
222
+ constructor(options: Options);
223
+ }
224
+ /**
225
+ * Same leaf ladder as {@link Script}, built with {@link
226
+ * preimageConditionScriptV2} instead of {@link preimageConditionScript}
227
+ * for every leaf that gates on the preimage (`claim`, `unilateralClaim`,
228
+ * and, when present, `nonInteractiveClaim`) — see that function's doc
229
+ * comment for what differs and why. A distinct class rather than a flag
230
+ * on {@link Script}: the two produce different script bytes (and so
231
+ * different addresses) for the same participant keys, and keeping them
232
+ * as separate types makes that a compile-time-visible choice at every
233
+ * call site instead of a runtime option that's easy to get wrong.
234
+ */
235
+ export class ScriptV2 extends BaseScript {
236
+ constructor(options: Options);
237
+ }
238
+ export { };
239
+ }
240
+
169
241
  /**
170
242
  * Typed parameters for VHTLC contracts.
171
243
  */
@@ -194,7 +266,91 @@ interface VHTLCContractParams {
194
266
  * - unilateralRefund: Sender + Receiver after CSV delay
195
267
  * - unilateralRefundWithoutReceiver: Sender after CSV delay
196
268
  */
197
- declare const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script>;
269
+ declare const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script> & TapscriptDeriving<VHTLC.Script>;
270
+
271
+ /**
272
+ * Typed parameters for {@link VHTLC.ScriptV2} contracts.
273
+ *
274
+ * The eight mandatory fields are `VHTLCContractParams` verbatim — the two
275
+ * script versions take the same {@link VHTLC.Options}, so a divergent shape
276
+ * here would be a difference with no cause. What V1's handler has no field for
277
+ * is the two optional covenant leaves, and those are exactly what the swap
278
+ * corridor's lockup carries, so leaving them out would make this handler unable
279
+ * to round-trip the contract it exists to serve.
280
+ */
281
+ interface VHTLCV2ContractParams {
282
+ sender: Uint8Array;
283
+ receiver: Uint8Array;
284
+ server: Uint8Array;
285
+ preimageHash: Uint8Array;
286
+ refundLocktime: bigint;
287
+ unilateralClaimDelay: RelativeTimelock;
288
+ unilateralRefundDelay: RelativeTimelock;
289
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
290
+ /** @see VHTLC.Options.nonInteractiveClaim */
291
+ nonInteractiveClaim?: {
292
+ receiverPkScript: Uint8Array;
293
+ emulatorPubkey: Uint8Array;
294
+ };
295
+ /** @see VHTLC.Options.nonInteractiveRefund */
296
+ nonInteractiveRefund?: {
297
+ senderPkScript: Uint8Array;
298
+ emulatorPubkey: Uint8Array;
299
+ };
300
+ }
301
+ /**
302
+ * Handler for {@link VHTLC.ScriptV2} — the VHTLC whose preimage leaves carry an
303
+ * explicit `OP_SIZE 32 OP_EQUALVERIFY` before the hash check, and which the RFQ
304
+ * swap corridor builds (`@arkade-os/swap`'s `lightningSendVtxoScript`).
305
+ *
306
+ * **Why a separate type string rather than a flag on `vhtlc`.** A handler's
307
+ * `type` names the script class it derives, the way every other registered type
308
+ * does (`default` → `DefaultVtxo.Script`, `vhtlc` → `VHTLC.Script`, `boarding`,
309
+ * `arkade`). V1 and V2 produce different script bytes — and so different
310
+ * pkScripts — for identical participant keys, and `upsertContractRow` derives
311
+ * the script from `params` and refuses any row whose supplied `script` does not
312
+ * match. One type cannot serve both. `vhtlc-v2` also cannot COLLIDE with
313
+ * `vhtlc`: a colliding row needs one pkScript claimed by two types, and the two
314
+ * versions' preimage conditions differ in every tree, so no parameters make
315
+ * them equal. A use-named type (`swap-lockup`) was the alternative and is
316
+ * worse: contracts are keyed by script, so the moment a second use registered
317
+ * the same ScriptV2 the two uses would fight over one row.
318
+ *
319
+ * **Which leaves this offers, and why the set is smaller than the ladder.**
320
+ * ScriptV2 has eight leaves; a wallet holding ONE of the two participant keys
321
+ * can satisfy four of them, and offering a leaf whose signature the caller
322
+ * cannot produce is worse than offering fewer — it turns a refusal into a
323
+ * transaction that gets built and then rejected.
324
+ *
325
+ * | leaf | needs | offered |
326
+ * |-----------------------------------|--------------------------------|---------|
327
+ * | `claim` | receiver + server, preimage | yes, to the receiver |
328
+ * | `refund` | sender + receiver + server | no — needs the counterparty live |
329
+ * | `refundWithoutReceiver` | sender + server, CLTV | yes, to the sender |
330
+ * | `unilateralClaim` | receiver, CSV | yes, to the receiver |
331
+ * | `unilateralRefund` | sender + receiver, CSV | no — needs the counterparty live |
332
+ * | `unilateralRefundWithoutReceiver` | sender, CSV | yes, to the sender |
333
+ * | `nonInteractiveClaim` | server + emulator | no — the wallet holds neither key |
334
+ * | `nonInteractiveRefund` | server + receiver + emulator | no — the wallet holds neither key |
335
+ *
336
+ * The two omitted interactive leaves are the same two the `vhtlc` handler
337
+ * omits, for the same reason: `refund` and `unilateralRefund` both need the
338
+ * OTHER party's signature, and this protocol has no message that asks for one
339
+ * (see `@arkade-os/swap`'s `refund.ts` module doc). The two covenant leaves are
340
+ * pushed by the emulator on the counterparty's behalf and are not this wallet's
341
+ * to build at all.
342
+ *
343
+ * So `refundWithoutReceiver` is the sender's only collaborative way out, gated
344
+ * on the CLTV the quote committed to — which is exactly the leaf
345
+ * `pushRefundWithoutReceiver` builds. The CSV leaves are offered only in the
346
+ * non-collaborative context, where the caller has already accepted that
347
+ * spending them means a real unilateral exit first.
348
+ *
349
+ * The selection discipline is deliberately identical to the `vhtlc` handler's,
350
+ * and `test/contracts/vhtlcV2-handler.test.ts` pins the two against each other
351
+ * rung-for-rung across every role and timelock context so they cannot drift.
352
+ */
353
+ declare const VHTLCV2ContractHandler: ContractHandler<VHTLCV2ContractParams, VHTLC.ScriptV2> & TapscriptDeriving<VHTLC.ScriptV2>;
198
354
 
199
355
  /**
200
356
  * Typed parameters for boarding contracts.
@@ -509,4 +665,4 @@ declare function deserializeArkadeContractParams(params: Record<string, string>)
509
665
  */
510
666
  declare const ArkadeContractHandler: ContractHandler<ArkadeContractParams, ArkadeProgramScript> & TapscriptDeriving<ArkadeProgramScript>;
511
667
 
512
- export { type ArkadeParamValue as A, BoardingContractHandler as B, type CompiledProgramFunction as C, DefaultContractHandler as D, type InputRef as I, type Program as P, SUPPORTED_PROGRAM_VERSION as S, type TapscriptSegment as T, VHTLC as V, type WitnessRef as W, ArkadeProgramScript as a, type ProgramKeys as b, type ArkadeArgValue as c, type ArkadeFunction as d, type InputDef as e, type ArkadeValueType as f, type ArkadeArgType as g, type ArkadeContractParams as h, type ArkadeSegment as i, type AsmToken as j, type SignerRef as k, deserializeArkadeContractParams as l, stringifyArtifact as m, ArkadeContractHandler as n, type BoardingContractParams as o, parseArtifact as p, type DefaultContractParams as q, resolveAsm as r, serializeArkadeContractParams as s, DelegateContractHandler as t, type DelegateContractParams as u, validateProgram as v, witnessRefToBytes as w, VHTLCContractHandler as x, type VHTLCContractParams as y, contractHandlers as z };
668
+ export { type ArkadeParamValue as A, BoardingContractHandler as B, type CompiledProgramFunction as C, DefaultContractHandler as D, type VHTLCV2ContractParams as E, contractHandlers as F, type InputRef as I, type Program as P, SUPPORTED_PROGRAM_VERSION as S, type TapscriptSegment as T, VHTLC as V, type WitnessRef as W, ArkadeProgramScript as a, type ProgramKeys as b, type ArkadeArgValue as c, type ArkadeFunction as d, type InputDef as e, type ArkadeValueType as f, type ArkadeArgType as g, type ArkadeContractParams as h, type ArkadeSegment as i, type AsmToken as j, type SignerRef as k, deserializeArkadeContractParams as l, stringifyArtifact as m, ArkadeContractHandler as n, type BoardingContractParams as o, parseArtifact as p, type DefaultContractParams as q, resolveAsm as r, serializeArkadeContractParams as s, DelegateContractHandler as t, type DelegateContractParams as u, validateProgram as v, witnessRefToBytes as w, VHTLCContractHandler as x, type VHTLCContractParams as y, VHTLCV2ContractHandler as z };
@@ -1,71 +1,7 @@
1
- import { p as RelativeTimelock, V as VtxoScript, q as TapLeafScript, b9 as ContractHandler, bk as Discoverable, cC as TapscriptDeriving } from './ark-C9DsPSm8.cjs';
2
- import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-D0eGaz3J.cjs';
1
+ import { ba as ContractHandler, p as RelativeTimelock, bl as Discoverable, V as VtxoScript, q as TapLeafScript, cO as TapscriptDeriving } from './index-BcRCHnzN.js';
2
+ import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-BySzD37I.js';
3
3
  import { Bytes } from '@scure/btc-signer/utils.js';
4
4
 
5
- /** Virtual Hash Time Lock Contract (VHTLC) namespace. */
6
- declare namespace VHTLC {
7
- interface Options {
8
- sender: Bytes;
9
- receiver: Bytes;
10
- server: Bytes;
11
- preimageHash: Bytes;
12
- refundLocktime: bigint;
13
- unilateralClaimDelay: RelativeTimelock;
14
- unilateralRefundDelay: RelativeTimelock;
15
- unilateralRefundWithoutReceiverDelay: RelativeTimelock;
16
- }
17
- /**
18
- * Virtual Hash Time Lock Contract (VHTLC) script implementation.
19
- *
20
- * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
21
- * It provides multiple spending paths:
22
- *
23
- * - **claim**: Receiver can claim funds by revealing the preimage
24
- * - **refund**: Sender and receiver can collaboratively refund
25
- * - **refundWithoutReceiver**: Sender can refund after locktime expires
26
- * - **unilateralClaim**: Receiver can claim unilaterally after delay
27
- * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
28
- * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
29
- *
30
- * @example
31
- * ```typescript
32
- * const vhtlc = new VHTLC.Script({
33
- * sender: alicePubKey,
34
- * receiver: bobPubKey,
35
- * server: serverPubKey,
36
- * preimageHash: hash160(secret),
37
- * refundLocktime: BigInt(chainTip + 10),
38
- * unilateralClaimDelay: { type: 'blocks', value: 100n },
39
- * unilateralRefundDelay: { type: 'blocks', value: 102n },
40
- * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
41
- * });
42
- * ```
43
- */
44
- class Script extends VtxoScript {
45
- readonly options: Options;
46
- readonly claimScript: string;
47
- readonly refundScript: string;
48
- readonly refundWithoutReceiverScript: string;
49
- readonly unilateralClaimScript: string;
50
- readonly unilateralRefundScript: string;
51
- readonly unilateralRefundWithoutReceiverScript: string;
52
- /** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */
53
- constructor(options: Options);
54
- /** Return the collaborative claim tapleaf script. */
55
- claim(): TapLeafScript;
56
- /** Return the collaborative refund tapleaf script. */
57
- refund(): TapLeafScript;
58
- /** Return the refund-without-receiver tapleaf script. */
59
- refundWithoutReceiver(): TapLeafScript;
60
- /** Return the unilateral claim tapleaf script. */
61
- unilateralClaim(): TapLeafScript;
62
- /** Return the unilateral refund tapleaf script. */
63
- unilateralRefund(): TapLeafScript;
64
- /** Return the unilateral refund-without-receiver tapleaf script. */
65
- unilateralRefundWithoutReceiver(): TapLeafScript;
66
- }
67
- }
68
-
69
5
  /**
70
6
  * Registry for contract handlers.
71
7
  *
@@ -166,6 +102,142 @@ interface DelegateContractParams {
166
102
  */
167
103
  declare const DelegateContractHandler: ContractHandler<DelegateContractParams, DelegateVtxo.Script> & Discoverable;
168
104
 
105
+ /** Virtual Hash Time Lock Contract (VHTLC) namespace. */
106
+ declare namespace VHTLC {
107
+ export interface Options {
108
+ sender: Bytes;
109
+ receiver: Bytes;
110
+ server: Bytes;
111
+ preimageHash: Bytes;
112
+ refundLocktime: bigint;
113
+ unilateralClaimDelay: RelativeTimelock;
114
+ unilateralRefundDelay: RelativeTimelock;
115
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
116
+ /**
117
+ * Optional non-interactive claim leaf: `server` plus a covenant-tweaked
118
+ * emulator co-signer, pinned to `receiverPkScript`. Lets the receiver's
119
+ * claim be pushed by the emulator without the receiver being online.
120
+ */
121
+ nonInteractiveClaim?: {
122
+ receiverPkScript: Bytes;
123
+ emulatorPubkey: Bytes;
124
+ };
125
+ /**
126
+ * Optional non-interactive refund leaf: `server` + `receiver` + a
127
+ * covenant-tweaked emulator co-signer, pinned to `senderPkScript`, no
128
+ * timelock. Every OTHER refund-side leaf in this contract requires
129
+ * the sender's own signature — if the sender permanently loses that
130
+ * key, none of them are reachable. This leaf is the one exception:
131
+ * it needs neither the sender's presence nor their key, so funds
132
+ * remain recoverable to the sender's pre-committed address even
133
+ * then. It still needs the receiver (unlike `nonInteractiveClaim`,
134
+ * which needs only server + emulator) — deliberately: this is what
135
+ * lets server + receiver release the refund immediately, the moment
136
+ * they agree the swap has failed, rather than making the sender wait
137
+ * out `refundLocktime` the way {@link Script.refundWithoutReceiver}
138
+ * does.
139
+ */
140
+ nonInteractiveRefund?: {
141
+ senderPkScript: Bytes;
142
+ emulatorPubkey: Bytes;
143
+ };
144
+ }
145
+ /**
146
+ * Shared construction and accessors for every VHTLC script version. The
147
+ * only thing that varies between versions is which preimage-condition
148
+ * fragment `claim`/`unilateralClaim`/`nonInteractiveClaim` are built
149
+ * from — everything else (the multisig/timelock leaves, the
150
+ * non-interactive covenant leaves, the accessor methods) is identical,
151
+ * so versions are expressed as thin subclasses over one builder rather
152
+ * than as separate, independently-maintained copies of this class.
153
+ */
154
+ abstract class BaseScript extends VtxoScript {
155
+ readonly options: Options;
156
+ readonly claimScript: string;
157
+ readonly refundScript: string;
158
+ readonly refundWithoutReceiverScript: string;
159
+ readonly unilateralClaimScript: string;
160
+ readonly unilateralRefundScript: string;
161
+ readonly unilateralRefundWithoutReceiverScript: string;
162
+ readonly nonInteractiveClaimScript?: string;
163
+ readonly nonInteractiveClaimArkadeScript?: Bytes;
164
+ readonly nonInteractiveRefundScript?: string;
165
+ readonly nonInteractiveRefundArkadeScript?: Bytes;
166
+ protected constructor(options: Options, preimageCondition: (hash: Bytes) => Bytes);
167
+ /** Return the collaborative claim tapleaf script. */
168
+ claim(): TapLeafScript;
169
+ /** Return the collaborative refund tapleaf script. */
170
+ refund(): TapLeafScript;
171
+ /** Return the refund-without-receiver tapleaf script. */
172
+ refundWithoutReceiver(): TapLeafScript;
173
+ /** Return the unilateral claim tapleaf script. */
174
+ unilateralClaim(): TapLeafScript;
175
+ /** Return the unilateral refund tapleaf script. */
176
+ unilateralRefund(): TapLeafScript;
177
+ /** Return the unilateral refund-without-receiver tapleaf script. */
178
+ unilateralRefundWithoutReceiver(): TapLeafScript;
179
+ /** Return the non-interactive claim tapleaf script as well as the ArkadeScript. */
180
+ nonInteractiveClaim(): [TapLeafScript, Bytes];
181
+ /** Return the non-interactive refund tapleaf script as well as the ArkadeScript. */
182
+ nonInteractiveRefund(): [TapLeafScript, Bytes];
183
+ }
184
+ /**
185
+ * Virtual Hash Time Lock Contract (VHTLC) script implementation.
186
+ *
187
+ * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
188
+ * It provides multiple spending paths:
189
+ *
190
+ * - **claim**: Receiver can claim funds by revealing the preimage
191
+ * - **refund**: Sender and receiver can collaboratively refund
192
+ * - **refundWithoutReceiver**: Sender can refund after locktime expires
193
+ * - **unilateralClaim**: Receiver can claim unilaterally after delay
194
+ * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
195
+ * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
196
+ * - **nonInteractiveClaim** (optional): server + emulator can push the
197
+ * receiver's claim, pinned to a pre-committed destination
198
+ * - **nonInteractiveRefund** (optional): server + receiver + emulator
199
+ * can push the sender's refund immediately, no timelock, pinned to a
200
+ * pre-committed destination — recoverable even if the sender's own key
201
+ * is lost
202
+ *
203
+ * See {@link ScriptV2} for the current recommended construction — same
204
+ * leaf ladder, same options shape, an added length check on the claim
205
+ * preimage. This class is unchanged and stays available as-is.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const vhtlc = new VHTLC.Script({
210
+ * sender: alicePubKey,
211
+ * receiver: bobPubKey,
212
+ * server: serverPubKey,
213
+ * preimageHash: hash160(secret),
214
+ * refundLocktime: BigInt(chainTip + 10),
215
+ * unilateralClaimDelay: { type: 'blocks', value: 100n },
216
+ * unilateralRefundDelay: { type: 'blocks', value: 102n },
217
+ * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
218
+ * });
219
+ * ```
220
+ */
221
+ export class Script extends BaseScript {
222
+ constructor(options: Options);
223
+ }
224
+ /**
225
+ * Same leaf ladder as {@link Script}, built with {@link
226
+ * preimageConditionScriptV2} instead of {@link preimageConditionScript}
227
+ * for every leaf that gates on the preimage (`claim`, `unilateralClaim`,
228
+ * and, when present, `nonInteractiveClaim`) — see that function's doc
229
+ * comment for what differs and why. A distinct class rather than a flag
230
+ * on {@link Script}: the two produce different script bytes (and so
231
+ * different addresses) for the same participant keys, and keeping them
232
+ * as separate types makes that a compile-time-visible choice at every
233
+ * call site instead of a runtime option that's easy to get wrong.
234
+ */
235
+ export class ScriptV2 extends BaseScript {
236
+ constructor(options: Options);
237
+ }
238
+ export { };
239
+ }
240
+
169
241
  /**
170
242
  * Typed parameters for VHTLC contracts.
171
243
  */
@@ -194,7 +266,91 @@ interface VHTLCContractParams {
194
266
  * - unilateralRefund: Sender + Receiver after CSV delay
195
267
  * - unilateralRefundWithoutReceiver: Sender after CSV delay
196
268
  */
197
- declare const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script>;
269
+ declare const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script> & TapscriptDeriving<VHTLC.Script>;
270
+
271
+ /**
272
+ * Typed parameters for {@link VHTLC.ScriptV2} contracts.
273
+ *
274
+ * The eight mandatory fields are `VHTLCContractParams` verbatim — the two
275
+ * script versions take the same {@link VHTLC.Options}, so a divergent shape
276
+ * here would be a difference with no cause. What V1's handler has no field for
277
+ * is the two optional covenant leaves, and those are exactly what the swap
278
+ * corridor's lockup carries, so leaving them out would make this handler unable
279
+ * to round-trip the contract it exists to serve.
280
+ */
281
+ interface VHTLCV2ContractParams {
282
+ sender: Uint8Array;
283
+ receiver: Uint8Array;
284
+ server: Uint8Array;
285
+ preimageHash: Uint8Array;
286
+ refundLocktime: bigint;
287
+ unilateralClaimDelay: RelativeTimelock;
288
+ unilateralRefundDelay: RelativeTimelock;
289
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
290
+ /** @see VHTLC.Options.nonInteractiveClaim */
291
+ nonInteractiveClaim?: {
292
+ receiverPkScript: Uint8Array;
293
+ emulatorPubkey: Uint8Array;
294
+ };
295
+ /** @see VHTLC.Options.nonInteractiveRefund */
296
+ nonInteractiveRefund?: {
297
+ senderPkScript: Uint8Array;
298
+ emulatorPubkey: Uint8Array;
299
+ };
300
+ }
301
+ /**
302
+ * Handler for {@link VHTLC.ScriptV2} — the VHTLC whose preimage leaves carry an
303
+ * explicit `OP_SIZE 32 OP_EQUALVERIFY` before the hash check, and which the RFQ
304
+ * swap corridor builds (`@arkade-os/swap`'s `lightningSendVtxoScript`).
305
+ *
306
+ * **Why a separate type string rather than a flag on `vhtlc`.** A handler's
307
+ * `type` names the script class it derives, the way every other registered type
308
+ * does (`default` → `DefaultVtxo.Script`, `vhtlc` → `VHTLC.Script`, `boarding`,
309
+ * `arkade`). V1 and V2 produce different script bytes — and so different
310
+ * pkScripts — for identical participant keys, and `upsertContractRow` derives
311
+ * the script from `params` and refuses any row whose supplied `script` does not
312
+ * match. One type cannot serve both. `vhtlc-v2` also cannot COLLIDE with
313
+ * `vhtlc`: a colliding row needs one pkScript claimed by two types, and the two
314
+ * versions' preimage conditions differ in every tree, so no parameters make
315
+ * them equal. A use-named type (`swap-lockup`) was the alternative and is
316
+ * worse: contracts are keyed by script, so the moment a second use registered
317
+ * the same ScriptV2 the two uses would fight over one row.
318
+ *
319
+ * **Which leaves this offers, and why the set is smaller than the ladder.**
320
+ * ScriptV2 has eight leaves; a wallet holding ONE of the two participant keys
321
+ * can satisfy four of them, and offering a leaf whose signature the caller
322
+ * cannot produce is worse than offering fewer — it turns a refusal into a
323
+ * transaction that gets built and then rejected.
324
+ *
325
+ * | leaf | needs | offered |
326
+ * |-----------------------------------|--------------------------------|---------|
327
+ * | `claim` | receiver + server, preimage | yes, to the receiver |
328
+ * | `refund` | sender + receiver + server | no — needs the counterparty live |
329
+ * | `refundWithoutReceiver` | sender + server, CLTV | yes, to the sender |
330
+ * | `unilateralClaim` | receiver, CSV | yes, to the receiver |
331
+ * | `unilateralRefund` | sender + receiver, CSV | no — needs the counterparty live |
332
+ * | `unilateralRefundWithoutReceiver` | sender, CSV | yes, to the sender |
333
+ * | `nonInteractiveClaim` | server + emulator | no — the wallet holds neither key |
334
+ * | `nonInteractiveRefund` | server + receiver + emulator | no — the wallet holds neither key |
335
+ *
336
+ * The two omitted interactive leaves are the same two the `vhtlc` handler
337
+ * omits, for the same reason: `refund` and `unilateralRefund` both need the
338
+ * OTHER party's signature, and this protocol has no message that asks for one
339
+ * (see `@arkade-os/swap`'s `refund.ts` module doc). The two covenant leaves are
340
+ * pushed by the emulator on the counterparty's behalf and are not this wallet's
341
+ * to build at all.
342
+ *
343
+ * So `refundWithoutReceiver` is the sender's only collaborative way out, gated
344
+ * on the CLTV the quote committed to — which is exactly the leaf
345
+ * `pushRefundWithoutReceiver` builds. The CSV leaves are offered only in the
346
+ * non-collaborative context, where the caller has already accepted that
347
+ * spending them means a real unilateral exit first.
348
+ *
349
+ * The selection discipline is deliberately identical to the `vhtlc` handler's,
350
+ * and `test/contracts/vhtlcV2-handler.test.ts` pins the two against each other
351
+ * rung-for-rung across every role and timelock context so they cannot drift.
352
+ */
353
+ declare const VHTLCV2ContractHandler: ContractHandler<VHTLCV2ContractParams, VHTLC.ScriptV2> & TapscriptDeriving<VHTLC.ScriptV2>;
198
354
 
199
355
  /**
200
356
  * Typed parameters for boarding contracts.
@@ -509,4 +665,4 @@ declare function deserializeArkadeContractParams(params: Record<string, string>)
509
665
  */
510
666
  declare const ArkadeContractHandler: ContractHandler<ArkadeContractParams, ArkadeProgramScript> & TapscriptDeriving<ArkadeProgramScript>;
511
667
 
512
- export { type ArkadeParamValue as A, BoardingContractHandler as B, type CompiledProgramFunction as C, DefaultContractHandler as D, type InputRef as I, type Program as P, SUPPORTED_PROGRAM_VERSION as S, type TapscriptSegment as T, VHTLC as V, type WitnessRef as W, ArkadeProgramScript as a, type ProgramKeys as b, type ArkadeArgValue as c, type ArkadeFunction as d, type InputDef as e, type ArkadeValueType as f, type ArkadeArgType as g, type ArkadeContractParams as h, type ArkadeSegment as i, type AsmToken as j, type SignerRef as k, deserializeArkadeContractParams as l, stringifyArtifact as m, ArkadeContractHandler as n, type BoardingContractParams as o, parseArtifact as p, type DefaultContractParams as q, resolveAsm as r, serializeArkadeContractParams as s, DelegateContractHandler as t, type DelegateContractParams as u, validateProgram as v, witnessRefToBytes as w, VHTLCContractHandler as x, type VHTLCContractParams as y, contractHandlers as z };
668
+ export { type ArkadeParamValue as A, BoardingContractHandler as B, type CompiledProgramFunction as C, DefaultContractHandler as D, type VHTLCV2ContractParams as E, contractHandlers as F, type InputRef as I, type Program as P, SUPPORTED_PROGRAM_VERSION as S, type TapscriptSegment as T, VHTLC as V, type WitnessRef as W, ArkadeProgramScript as a, type ProgramKeys as b, type ArkadeArgValue as c, type ArkadeFunction as d, type InputDef as e, type ArkadeValueType as f, type ArkadeArgType as g, type ArkadeContractParams as h, type ArkadeSegment as i, type AsmToken as j, type SignerRef as k, deserializeArkadeContractParams as l, stringifyArtifact as m, ArkadeContractHandler as n, type BoardingContractParams as o, parseArtifact as p, type DefaultContractParams as q, resolveAsm as r, serializeArkadeContractParams as s, DelegateContractHandler as t, type DelegateContractParams as u, validateProgram as v, witnessRefToBytes as w, VHTLCContractHandler as x, type VHTLCContractParams as y, VHTLCV2ContractHandler as z };