@arkade-os/sdk 0.5.0-rc.11 → 0.5.0-rc.13

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 (94) hide show
  1. package/README.md +43 -12
  2. package/dist/adapters/expo.cjs +5 -5
  3. package/dist/adapters/expo.d.cts +2 -2
  4. package/dist/adapters/expo.d.ts +2 -2
  5. package/dist/adapters/expo.js +3 -3
  6. package/dist/{asyncStorageTaskQueue-DBaZsltv.d.cts → asyncStorageTaskQueue-0EeSeCAt.d.cts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-uAG3XLyg.d.ts → asyncStorageTaskQueue-DV94jhwq.d.ts} +1 -1
  8. package/dist/{chunk-WSQAWSEH.js → chunk-3JLYJ5KZ.js} +75 -237
  9. package/dist/chunk-3JLYJ5KZ.js.map +1 -0
  10. package/dist/{chunk-VMLLYEYM.js → chunk-4EU2Q6YT.js} +12 -14
  11. package/dist/chunk-4EU2Q6YT.js.map +1 -0
  12. package/dist/{chunk-IA32YGLH.cjs → chunk-7BACS4XK.cjs} +10 -10
  13. package/dist/chunk-7BACS4XK.cjs.map +1 -0
  14. package/dist/{chunk-5OBGYL6U.cjs → chunk-7NK6XFC3.cjs} +120 -194
  15. package/dist/chunk-7NK6XFC3.cjs.map +1 -0
  16. package/dist/{chunk-CQPQ7D4U.cjs → chunk-BFQX2KS3.cjs} +87 -248
  17. package/dist/chunk-BFQX2KS3.cjs.map +1 -0
  18. package/dist/{chunk-DD6MTNAS.js → chunk-D7JLTHSZ.js} +5 -5
  19. package/dist/chunk-D7JLTHSZ.js.map +1 -0
  20. package/dist/{chunk-CMLSTGOC.js → chunk-EJYWGTZ7.js} +119 -194
  21. package/dist/chunk-EJYWGTZ7.js.map +1 -0
  22. package/dist/{chunk-T2ILYGWE.cjs → chunk-FDQQOF3F.cjs} +327 -1080
  23. package/dist/chunk-FDQQOF3F.cjs.map +1 -0
  24. package/dist/{chunk-MGDXN74N.cjs → chunk-I4YBVHAK.cjs} +2357 -3374
  25. package/dist/chunk-I4YBVHAK.cjs.map +1 -0
  26. package/dist/{chunk-M2ZUPLKQ.js → chunk-IV2252XM.js} +1946 -2977
  27. package/dist/chunk-IV2252XM.js.map +1 -0
  28. package/dist/{chunk-OMJRW2D5.js → chunk-JOUPIZ32.js} +263 -1036
  29. package/dist/chunk-JOUPIZ32.js.map +1 -0
  30. package/dist/{chunk-PWEBQNIE.cjs → chunk-RDQSVIXD.cjs} +22 -24
  31. package/dist/chunk-RDQSVIXD.cjs.map +1 -0
  32. package/dist/contracts/handlers/index.cjs +9 -9
  33. package/dist/contracts/handlers/index.d.cts +3 -3
  34. package/dist/contracts/handlers/index.d.ts +3 -3
  35. package/dist/contracts/handlers/index.js +2 -2
  36. package/dist/{delegate-DFwlkVYR.d.cts → delegate-BgpUJW5B.d.cts} +1 -1
  37. package/dist/{delegate-D3YHDERL.d.ts → delegate-BuagcGnG.d.ts} +1 -1
  38. package/dist/{index-DTvUv5lD.d.cts → index-CKmB14Yu.d.cts} +1145 -2263
  39. package/dist/{index-DTvUv5lD.d.ts → index-CKmB14Yu.d.ts} +1145 -2263
  40. package/dist/index-D0BuYwhF.d.cts +637 -0
  41. package/dist/index-DbzyrqK7.d.ts +637 -0
  42. package/dist/index.cjs +341 -297
  43. package/dist/index.d.cts +379 -788
  44. package/dist/index.d.ts +379 -788
  45. package/dist/index.js +4 -4
  46. package/dist/repositories/realm/index.cjs +142 -101
  47. package/dist/repositories/realm/index.cjs.map +1 -1
  48. package/dist/repositories/realm/index.d.cts +13 -11
  49. package/dist/repositories/realm/index.d.ts +13 -11
  50. package/dist/repositories/realm/index.js +130 -89
  51. package/dist/repositories/realm/index.js.map +1 -1
  52. package/dist/repositories/sqlite/index.cjs +158 -118
  53. package/dist/repositories/sqlite/index.cjs.map +1 -1
  54. package/dist/repositories/sqlite/index.d.cts +14 -13
  55. package/dist/repositories/sqlite/index.d.ts +14 -13
  56. package/dist/repositories/sqlite/index.js +147 -107
  57. package/dist/repositories/sqlite/index.js.map +1 -1
  58. package/dist/{taskRunner-B5bl0YRt.d.ts → taskRunner-BX-pB0sv.d.ts} +1 -1
  59. package/dist/{taskRunner--sKy9Inv.d.cts → taskRunner-DJrFFyus.d.cts} +1 -1
  60. package/dist/wallet/expo/background.cjs +14 -14
  61. package/dist/wallet/expo/background.cjs.map +1 -1
  62. package/dist/wallet/expo/background.d.cts +8 -14
  63. package/dist/wallet/expo/background.d.ts +8 -14
  64. package/dist/wallet/expo/background.js +6 -6
  65. package/dist/wallet/expo/background.js.map +1 -1
  66. package/dist/wallet/expo/index.cjs +14 -14
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +5 -5
  69. package/dist/wallet/expo/index.d.ts +5 -5
  70. package/dist/wallet/expo/index.js +5 -5
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/wallet-BsL2G3Qb.d.cts +1542 -0
  73. package/dist/wallet-DXNiCmq8.d.ts +1542 -0
  74. package/dist/worker/expo/index.cjs +9 -9
  75. package/dist/worker/expo/index.d.cts +4 -4
  76. package/dist/worker/expo/index.d.ts +4 -4
  77. package/dist/worker/expo/index.js +5 -5
  78. package/package.json +3 -2
  79. package/dist/chunk-5OBGYL6U.cjs.map +0 -1
  80. package/dist/chunk-CMLSTGOC.js.map +0 -1
  81. package/dist/chunk-CQPQ7D4U.cjs.map +0 -1
  82. package/dist/chunk-DD6MTNAS.js.map +0 -1
  83. package/dist/chunk-IA32YGLH.cjs.map +0 -1
  84. package/dist/chunk-M2ZUPLKQ.js.map +0 -1
  85. package/dist/chunk-MGDXN74N.cjs.map +0 -1
  86. package/dist/chunk-OMJRW2D5.js.map +0 -1
  87. package/dist/chunk-PWEBQNIE.cjs.map +0 -1
  88. package/dist/chunk-T2ILYGWE.cjs.map +0 -1
  89. package/dist/chunk-VMLLYEYM.js.map +0 -1
  90. package/dist/chunk-WSQAWSEH.js.map +0 -1
  91. package/dist/hdWalletCapable-C350s3bP.d.ts +0 -2206
  92. package/dist/hdWalletCapable-rrOmXcbT.d.cts +0 -2206
  93. package/dist/index-C0ZyGoyP.d.cts +0 -850
  94. package/dist/index-DASN1cVk.d.ts +0 -850
@@ -0,0 +1,637 @@
1
+ import { bv as ContractHandler, w as RelativeTimelock, bG as Discoverable, V as VtxoScript, x as TapLeafScript, du as TapscriptDeriving } from './index-CKmB14Yu.js';
2
+ import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-BuagcGnG.js';
3
+ import { Bytes } from '@scure/btc-signer/utils.js';
4
+
5
+ /**
6
+ * Registry for contract handlers.
7
+ *
8
+ * Each contract type ("default", "vhtlc", etc.) has a handler that knows
9
+ * how to create VtxoScripts, serialize params, and select spending paths.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Register a custom handler
14
+ * contractHandlers.register(myCustomHandler);
15
+ *
16
+ * // Get handler for a type
17
+ * const handler = contractHandlers.get("vhtlc");
18
+ * const script = handler.createScript(contract.params);
19
+ * ```
20
+ */
21
+ declare class ContractHandlerRegistry {
22
+ private handlers;
23
+ /** @throws If a handler for this type is already registered */
24
+ register(handler: ContractHandler<unknown>): void;
25
+ get(type: string): ContractHandler<unknown> | undefined;
26
+ /** @throws If no handler is registered for this type */
27
+ getOrThrow(type: string): ContractHandler<unknown>;
28
+ has(type: string): boolean;
29
+ getRegisteredTypes(): string[];
30
+ /** Unregister a handler (mainly for testing). */
31
+ unregister(type: string): boolean;
32
+ /** Clear all handlers (mainly for testing). */
33
+ clear(): void;
34
+ }
35
+ /** Global registry of contract handlers. */
36
+ declare const contractHandlers: ContractHandlerRegistry;
37
+
38
+ /**
39
+ * Typed parameters for DefaultVtxo contracts.
40
+ */
41
+ interface DefaultContractParams {
42
+ pubKey: Uint8Array;
43
+ serverPubKey: Uint8Array;
44
+ csvTimelock: RelativeTimelock;
45
+ }
46
+ /**
47
+ * Handler for default wallet VTXOs.
48
+ *
49
+ * Default contracts use the standard forfeit + exit tapscript:
50
+ * - forfeit: (Alice + Server) multisig for collaborative spending
51
+ * - exit: (Alice) + CSV timelock for unilateral exit
52
+ */
53
+ declare const DefaultContractHandler: ContractHandler<DefaultContractParams, DefaultVtxo.Script> & Discoverable;
54
+
55
+ /**
56
+ * Typed parameters for DelegateVtxo contracts.
57
+ */
58
+ interface DelegateContractParams {
59
+ pubKey: Uint8Array;
60
+ serverPubKey: Uint8Array;
61
+ delegatePubKey: Uint8Array;
62
+ csvTimelock: RelativeTimelock;
63
+ }
64
+ /**
65
+ * Handler for delegate wallet virtual outputs.
66
+ *
67
+ * Delegate contracts extend the default tapscript with an additional delegate path:
68
+ * - forfeit: (Alice + Server) multisig for collaborative spending
69
+ * - exit: (Alice) + CSV timelock for unilateral exit
70
+ * - delegate: (Alice + Delegate + Server) multisig for delegated renewal
71
+ */
72
+ declare const DelegateContractHandler: ContractHandler<DelegateContractParams, DelegateVtxo.Script> & Discoverable;
73
+
74
+ /** Virtual Hash Time Lock Contract (VHTLC) namespace. */
75
+ declare namespace VHTLC {
76
+ export interface Options {
77
+ sender: Bytes;
78
+ receiver: Bytes;
79
+ server: Bytes;
80
+ preimageHash: Bytes;
81
+ refundLocktime: bigint;
82
+ unilateralClaimDelay: RelativeTimelock;
83
+ unilateralRefundDelay: RelativeTimelock;
84
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
85
+ /**
86
+ * The emulator covenant leaves, ALL OR NOTHING. Adds three leaves the emulator co-signs
87
+ * under a covenant pinning the payout to a pre-committed destination:
88
+ *
89
+ * - `nonInteractiveClaim`: `server` + covenant-tweaked emulator, paying
90
+ * `receiverPkScript`; the claim can be pushed without the receiver online.
91
+ * - `nonInteractiveRefund`: `server` + `receiver` + covenant-tweaked emulator, paying
92
+ * `senderPkScript`, no timelock; recoverable even if the sender's key is lost.
93
+ * - `nonInteractiveRefundWithoutReceiver`: `server` + the SAME co-signer as
94
+ * `nonInteractiveRefund`, paying `senderPkScript` after `refundLocktime`; the only
95
+ * refund tier needing no participant signature.
96
+ *
97
+ * One flag, not one per leaf: nothing on the wire says which leaves a quote carries, so
98
+ * each optional leaf multiplies the tree shapes a counterparty must derive to verify an
99
+ * address. All-or-nothing keeps it at two.
100
+ *
101
+ * Leaf order fixes the merkle root: the suite is appended after the six signature leaves
102
+ * (claim, refund, timelocked refund), so a script with it NEVER collides with one without.
103
+ *
104
+ * STABLE PER RELEASE: a future covenant leaf joins only behind a NEW option, so
105
+ * re-deriving a lockup with the SDK that quoted it reproduces its address byte-for-byte.
106
+ */
107
+ nonInteractiveParameters?: {
108
+ /**
109
+ * Emulator public key, 32-byte x-only or 33-byte compressed. ONE key, tweaked per
110
+ * covenant destination, co-signs every suite leaf; BIP-341 sighashes committing to
111
+ * the tapleaf hash keep a signature for one leaf from replaying against another.
112
+ */
113
+ emulatorPubkey: Bytes;
114
+ /** Where the claim covenant pays: the receiver's P2TR pkScript, 34 bytes. */
115
+ receiverPkScript: Bytes;
116
+ /**
117
+ * Where BOTH refund covenants pay: the sender's P2TR pkScript, 34 bytes. Shared, so
118
+ * the two refund leaves cannot diverge.
119
+ */
120
+ senderPkScript: Bytes;
121
+ /**
122
+ * LEGACY REBUILD ONLY, never for a new lockup. Builds the suite WITHOUT the
123
+ * timelocked refund leaf, the shape of lockups funded before it shipped; a leaf can't
124
+ * be retrofitted onto a committed address, so re-deriving those needs this.
125
+ */
126
+ legacy?: "preTimelockedRefund";
127
+ };
128
+ /**
129
+ * Denominate this contract in an Arkade ASSET. Only the covenant (non-interactive)
130
+ * leaves change; the signature leaves assert nothing about value.
131
+ *
132
+ * The covenants then also require the output to carry at least the input's amount of
133
+ * THIS asset and exactly one asset. The sat clause is RETAINED: dropping it would let a
134
+ * spend strip the sats, as the sat-only covenant lets a spend strip the asset.
135
+ *
136
+ * ONLY THE BOUND ASSET IS PROTECTED. `INSPECTOUTASSETCOUNT == 1` constrains only the
137
+ * covenant's output; arkd's conservation rule lets extra assets on the funding VTXO be
138
+ * routed to another output the spender chooses. Fund it with the named asset only.
139
+ *
140
+ * A canonical Asset ID is the pair `(genesis txid, group index)`, never a single blob.
141
+ */
142
+ asset?: {
143
+ /**
144
+ * Genesis txid, 32 bytes, in CANONICAL order (the leading 32 bytes of a serialized
145
+ * Asset ID). Do not pre-reverse: the covenant reverses internally for the wire-order
146
+ * opcodes, and a pre-reversed id silently makes the covenant leaves unspendable.
147
+ */
148
+ txid: Bytes;
149
+ /** The asset group index within that genesis transaction. */
150
+ groupIndex: number;
151
+ };
152
+ }
153
+ /**
154
+ * Shared construction for every VHTLC script version; versions differ only in the
155
+ * preimage-condition fragment `claim`/`unilateralClaim`/`nonInteractiveClaim` are built from.
156
+ */
157
+ abstract class BaseScript extends VtxoScript {
158
+ readonly options: Options;
159
+ readonly claimScript: string;
160
+ readonly refundScript: string;
161
+ readonly refundWithoutReceiverScript: string;
162
+ readonly unilateralClaimScript: string;
163
+ readonly unilateralRefundScript: string;
164
+ readonly unilateralRefundWithoutReceiverScript: string;
165
+ readonly nonInteractiveClaimScript?: string;
166
+ readonly nonInteractiveClaimArkadeScript?: Bytes;
167
+ readonly nonInteractiveRefundScript?: string;
168
+ readonly nonInteractiveRefundArkadeScript?: Bytes;
169
+ readonly nonInteractiveRefundWithoutReceiverScript?: string;
170
+ readonly nonInteractiveRefundWithoutReceiverArkadeScript?: Bytes;
171
+ protected constructor(options: Options, preimageCondition: (hash: Bytes) => Bytes);
172
+ /** Return the collaborative claim tapleaf script. */
173
+ claim(): TapLeafScript;
174
+ /** Return the collaborative refund tapleaf script. */
175
+ refund(): TapLeafScript;
176
+ /** Return the refund-without-receiver tapleaf script. */
177
+ refundWithoutReceiver(): TapLeafScript;
178
+ /** Return the unilateral claim tapleaf script. */
179
+ unilateralClaim(): TapLeafScript;
180
+ /** Return the unilateral refund tapleaf script. */
181
+ unilateralRefund(): TapLeafScript;
182
+ /** Return the unilateral refund-without-receiver tapleaf script. */
183
+ unilateralRefundWithoutReceiver(): TapLeafScript;
184
+ /** Return the non-interactive claim tapleaf script as well as the ArkadeScript. */
185
+ nonInteractiveClaim(): [TapLeafScript, Bytes];
186
+ /** Return the non-interactive refund tapleaf script as well as the ArkadeScript. */
187
+ nonInteractiveRefund(): [TapLeafScript, Bytes];
188
+ /**
189
+ * Return the timelocked non-interactive refund tapleaf and its ArkadeScript.
190
+ *
191
+ * Spent through the generic covenant path ({@link EmulatorProvider},
192
+ * {@link ArkadeTransactionBuilder}): build the ark tx on this leaf plus its checkpoint;
193
+ * attach this ArkadeScript to the input in an `EmulatorPacket` (type 1, empty witness:
194
+ * the script pushes its own index with `PUSHCURRENTINPUTINDEX`) inside an `Extension`
195
+ * OP_RETURN; attach the input's creating ark tx as `PrevArkTx` (the emulator can't
196
+ * otherwise resolve its prevout); POST to the emulator's `/v1/tx`. The emulator co-signs
197
+ * for `nirCosigner` only if `enforcePayTo(senderPkScript)` holds, and finalizes with arkd.
198
+ * `server`'s signature is still required at consensus level, outside the covenant.
199
+ *
200
+ * The emulator does not check `refundLocktime`: it co-signs an immature spend and arkd's
201
+ * CLTV refuses it. arkd also refuses a block-height `refundLocktime`
202
+ * (< `CLTV_HEIGHT_THRESHOLD`, 500,000,000) on a forfeit-eligible leaf regardless of
203
+ * maturity: use a seconds-typed (Unix timestamp) value.
204
+ */
205
+ nonInteractiveRefundWithoutReceiver(): [TapLeafScript, Bytes];
206
+ }
207
+ /**
208
+ * Virtual Hash Time Lock Contract (VHTLC) script implementation.
209
+ *
210
+ * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
211
+ * It provides multiple spending paths:
212
+ *
213
+ * - **claim**: Receiver can claim funds by revealing the preimage
214
+ * - **refund**: Sender and receiver can collaboratively refund
215
+ * - **refundWithoutReceiver**: Sender can refund after locktime expires
216
+ * - **unilateralClaim**: Receiver can claim unilaterally after delay
217
+ * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
218
+ * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
219
+ * - **nonInteractive\*** (with `nonInteractiveParameters`): emulator covenant leaves; see
220
+ * {@link VHTLC.Options.nonInteractiveParameters}
221
+ *
222
+ * Prefer {@link ScriptV2} (same leaves and options, plus a claim-preimage length check).
223
+ *
224
+ * **The `vhtlc` contract handler registers none of the covenant leaves**: its params carry
225
+ * no covenant fields, so a V1 script built with `nonInteractiveParameters` can be funded but
226
+ * not registered (`ContractManager` refuses the six-leaf script mismatch). Use the
227
+ * `vhtlc-v2` handler, which round-trips the suite.
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const vhtlc = new VHTLC.Script({
232
+ * sender: alicePubKey,
233
+ * receiver: bobPubKey,
234
+ * server: serverPubKey,
235
+ * preimageHash: hash160(secret),
236
+ * refundLocktime: BigInt(chainTip + 10),
237
+ * unilateralClaimDelay: { type: 'blocks', value: 100n },
238
+ * unilateralRefundDelay: { type: 'blocks', value: 102n },
239
+ * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
240
+ * });
241
+ * ```
242
+ */
243
+ export class Script extends BaseScript {
244
+ constructor(options: Options);
245
+ }
246
+ /**
247
+ * {@link Script} built with {@link preimageConditionScriptV2} for every preimage-gated leaf.
248
+ * A separate class rather than a flag: the two give different script bytes (so addresses)
249
+ * for the same keys, which should be a compile-time-visible choice.
250
+ */
251
+ export class ScriptV2 extends BaseScript {
252
+ constructor(options: Options);
253
+ }
254
+ export { };
255
+ }
256
+
257
+ /** Typed parameters for VHTLC contracts. */
258
+ interface VHTLCContractParams {
259
+ sender: Uint8Array;
260
+ receiver: Uint8Array;
261
+ server: Uint8Array;
262
+ preimageHash: Uint8Array;
263
+ refundLocktime: bigint;
264
+ unilateralClaimDelay: RelativeTimelock;
265
+ unilateralRefundDelay: RelativeTimelock;
266
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
267
+ }
268
+ /**
269
+ * Handler for Virtual Hash Time Lock Contract (VHTLC).
270
+ *
271
+ * VHTLC supports multiple spending paths:
272
+ *
273
+ * Collaborative paths (with server):
274
+ * - claim: Receiver + Server with preimage
275
+ * - refund: Sender + Receiver + Server
276
+ * - refundWithoutReceiver: Sender + Server after CLTV locktime
277
+ *
278
+ * Unilateral paths (without server):
279
+ * - unilateralClaim: Receiver with preimage after CSV delay
280
+ * - unilateralRefund: Sender + Receiver after CSV delay
281
+ * - unilateralRefundWithoutReceiver: Sender after CSV delay
282
+ */
283
+ declare const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script> & TapscriptDeriving<VHTLC.Script>;
284
+
285
+ /**
286
+ * Typed parameters for {@link VHTLC.ScriptV2} contracts: `VHTLCContractParams` verbatim (both
287
+ * versions take the same {@link VHTLC.Options}), plus the asset and emulator covenant suite the
288
+ * swap corridor's lockup carries.
289
+ */
290
+ interface VHTLCV2ContractParams {
291
+ sender: Uint8Array;
292
+ receiver: Uint8Array;
293
+ server: Uint8Array;
294
+ preimageHash: Uint8Array;
295
+ refundLocktime: bigint;
296
+ unilateralClaimDelay: RelativeTimelock;
297
+ unilateralRefundDelay: RelativeTimelock;
298
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
299
+ /**
300
+ * The Arkade asset the covenant leaves bind, if any.
301
+ *
302
+ * @see VHTLC.Options.asset
303
+ */
304
+ asset?: {
305
+ /** The asset's genesis txid, 32 bytes, canonical order — as the serialized Asset ID carries it. */
306
+ txid: Uint8Array;
307
+ /** The asset group index within that genesis transaction. */
308
+ groupIndex: number;
309
+ };
310
+ /**
311
+ * The emulator covenant suite, all or nothing — mirrors {@link
312
+ * VHTLC.Options.nonInteractiveParameters}, including `legacy: "preTimelockedRefund"` for
313
+ * eight-leaf rows funded before the timelocked refund leaf shipped.
314
+ */
315
+ nonInteractiveParameters?: {
316
+ receiverPkScript: Uint8Array;
317
+ emulatorPubkey: Uint8Array;
318
+ senderPkScript: Uint8Array;
319
+ /** @see VHTLC.Options.nonInteractiveParameters.legacy */
320
+ legacy?: "preTimelockedRefund";
321
+ };
322
+ }
323
+ /**
324
+ * Handler for {@link VHTLC.ScriptV2} — the VHTLC whose preimage leaves add `OP_SIZE 32
325
+ * OP_EQUALVERIFY`, built by the RFQ swap corridor (`@arkade-os/swap`'s `lightningSendContract`).
326
+ *
327
+ * A separate type rather than a flag on `vhtlc`: V1 and V2 derive different pkScripts for the same
328
+ * keys and `upsertContractRow` rejects a row whose script doesn't match its params, so one type
329
+ * can't serve both (and they can never collide). A use-named type (`swap-lockup`) loses because
330
+ * contracts are keyed by script: a second use of the same ScriptV2 would fight over one row.
331
+ *
332
+ * Only the four leaves a single-key wallet can sign are offered: `claim`/`unilateralClaim` to the
333
+ * receiver, `refundWithoutReceiver` (CLTV)/`unilateralRefundWithoutReceiver` to the sender.
334
+ * `refund`/`unilateralRefund` need the counterparty's signature and no protocol message asks for
335
+ * one; the three `nonInteractive*` leaves are the emulator's. CSV leaves are offered only in the
336
+ * non-collaborative context. Selection matches the `vhtlc` handler rung-for-rung, pinned by
337
+ * `test/contracts/vhtlcV2-handler.test.ts`.
338
+ */
339
+ declare const VHTLCV2ContractHandler: ContractHandler<VHTLCV2ContractParams, VHTLC.ScriptV2> & TapscriptDeriving<VHTLC.ScriptV2>;
340
+
341
+ /**
342
+ * Typed parameters for boarding contracts: the `default` shape, with `csvTimelock` carrying the
343
+ * server's boarding-exit delay (`ArkadeInfo.boardingExitDelay`) instead of the unilateral-exit
344
+ * delay.
345
+ */
346
+ type BoardingContractParams = DefaultContractParams;
347
+ /**
348
+ * Handler for the boarding contract (registered type `boarding`), which derives the on-chain
349
+ * address used to board funds. Same `DefaultVtxo.Script` shape and path logic as `default`; only
350
+ * the CSV differs (`boardingExitDelay` vs `unilateralExitDelay`).
351
+ *
352
+ * {@link Discoverable.discoverAt} probes the **on-chain** UTXO set at the P2TR address, not the
353
+ * Ark indexer, and no-ops when `deps.boardingTimelock` / `deps.onchainNetwork` are absent.
354
+ *
355
+ * Default/boarding collision: a script owns exactly one repository row. A sound server keeps
356
+ * boardingExitDelay > unilateralExitDelay (equal delays expose it to a double-spend); if they
357
+ * coincide the two scripts are byte-identical. Discovery still emits `type: "boarding"` and the
358
+ * row is resolved first-wins in {@link ContractManager.upsertContract}; the scan probes boarding
359
+ * first so a both-purpose rotated index keeps its on-chain UTXO and any L2 VTXO recoverable.
360
+ * Funds are spendable either way, but consumers must NOT identify boarding by
361
+ * `contract.type === "boarding"` — match by script via `wallet.getBoardingAddress()` /
362
+ * `wallet.boardingTapscript`.
363
+ */
364
+ declare const BoardingContractHandler: ContractHandler<BoardingContractParams, DefaultVtxo.Script> & Discoverable;
365
+
366
+ /**
367
+ * Arkade Program model & compiler.
368
+ *
369
+ * A {@link Program} is the artifact shape shared with the ArkadeScript
370
+ * compiler: named functions, each split into a `tapscript` segment enforced
371
+ * on-chain and an optional `arkadeScript` segment emulated by the co-signing
372
+ * service. This module owns everything that is *pure data → script*:
373
+ *
374
+ * - the Program/segment/token types,
375
+ * - `$param` resolution ({@link resolveAsm}), witness and timelock resolution,
376
+ * - program validation ({@link validateProgram}) — typed constructor params
377
+ * are authoritative when present,
378
+ * - {@link ArkadeProgramScript} — a {@link VtxoScript} compiled from a
379
+ * program, its constructor args and the signer keys,
380
+ * - artifact JSON (de)serialization ({@link parseArtifact} /
381
+ * {@link stringifyArtifact}) and the string-keyed contract params used to
382
+ * persist a program contract through the `src/contracts` pipeline.
383
+ *
384
+ * Keeping this free of provider/transaction imports lets the generic
385
+ * `arkade` contract handler (src/contracts/handlers/arkade.ts) and the
386
+ * high-level `ArkadeContract` client share one compilation path.
387
+ *
388
+ * @module arkade/program
389
+ */
390
+
391
+ /** A token in an `asm` array: an opcode name, a number/bigint push, raw bytes, or a `$param` placeholder. */
392
+ type AsmToken = string | number | bigint | Uint8Array;
393
+ /** A constructor argument or resolved value. */
394
+ type ArkadeParamValue = Uint8Array | bigint | number;
395
+ /** A function call argument (function input). */
396
+ type ArkadeArgValue = Uint8Array | bigint | number;
397
+ /**
398
+ * The declared type of a function input, used to derive the static TS type of
399
+ * the corresponding `functions.<name>(...)` argument. Byte-like types map to
400
+ * `Uint8Array`; `int` maps to `bigint | number`.
401
+ */
402
+ type ArkadeArgType = "bytes" | "pubkey" | "sig" | "hash" | "int";
403
+ /**
404
+ * Maps an {@link ArkadeArgType} to its TypeScript argument type.
405
+ * @internal
406
+ */
407
+ interface ArkadeValueType {
408
+ bytes: Uint8Array;
409
+ pubkey: Uint8Array;
410
+ sig: Uint8Array;
411
+ hash: Uint8Array;
412
+ int: bigint | number;
413
+ }
414
+ /** A typed function input or constructor param: a name plus its {@link ArkadeArgType}. */
415
+ interface InputDef {
416
+ name: string;
417
+ type: ArkadeArgType;
418
+ }
419
+ /**
420
+ * A function input or constructor param declaration: either a typed descriptor
421
+ * `{ name, type }` (the argument is statically typed and its bound value is
422
+ * validated) or a bare name string (the argument falls back to the loose
423
+ * {@link ArkadeArgValue}).
424
+ */
425
+ type InputRef = string | InputDef;
426
+ /** Constructor pubkey `$param` tweaked by `fn`'s covenant. */
427
+ interface TweakedSigner {
428
+ tweak: string;
429
+ fn: string;
430
+ }
431
+ /** A `"$param"` reference, literal x-only bytes, or a {@link TweakedSigner}. */
432
+ type SignerRef = string | Uint8Array | TweakedSigner;
433
+ /** A witness-stack item: a function-input name, a `"$param"`, a literal number/bigint (minimal script-num), or raw bytes. */
434
+ type WitnessRef = string | number | bigint | Uint8Array;
435
+ /** Bitcoin Script segment of a spending path — enforced on-chain. */
436
+ interface TapscriptSegment {
437
+ /**
438
+ * Required signers. A path with `arkadeScript` also appends the emulator
439
+ * co-signer, unless `emulator` is `null`.
440
+ */
441
+ signers: SignerRef[];
442
+ /**
443
+ * Covenant named by `<EMULATOR_KEY:fn>`. `null` when this leaf belongs to a
444
+ * covenant but signs with a constructor-key tweak instead. Omitted on
445
+ * hand-written programs, which still append the co-signer.
446
+ */
447
+ emulator?: string | null;
448
+ /**
449
+ * Optional standard-opcode condition (e.g. a hashlock), encoded into a
450
+ * ConditionMultisig leaf — or ConditionCSVMultisig when combined with `csv`.
451
+ */
452
+ asm?: AsmToken[];
453
+ /**
454
+ * Relative timelock (CSV). The value is a literal or a `"$param"` reference
455
+ * resolved against the constructor args (same convention as {@link SignerRef}).
456
+ * Combinable with `asm` (condition + CSV); mutually exclusive with `cltv`.
457
+ */
458
+ csv?: {
459
+ type: "blocks" | "seconds";
460
+ value: bigint | string;
461
+ };
462
+ /**
463
+ * Absolute timelock (CLTV): a literal or a `"$param"` reference.
464
+ * Mutually exclusive with `csv`/`asm`.
465
+ */
466
+ cltv?: bigint | string;
467
+ /** Items satisfying the condition (e.g. an HTLC preimage); set via the ConditionWitness PSBT field. */
468
+ witness?: WitnessRef[];
469
+ }
470
+ /** Arkade Script segment of a spending path — emulated, bound via the key tweak. */
471
+ interface ArkadeSegment {
472
+ /** Raw Arkade opcodes with `$param` placeholders. */
473
+ asm: AsmToken[];
474
+ /** The arkade-script witness stack (e.g. an output index). */
475
+ witness?: WitnessRef[];
476
+ }
477
+ /** One named spending path. */
478
+ interface ArkadeFunction {
479
+ /**
480
+ * The function ABI: an ordered list of call arguments. Each entry is a typed
481
+ * descriptor `{ name, type }` (which gives the matching `functions.<name>`
482
+ * argument a precise static type) or a bare name string (loose
483
+ * {@link ArkadeArgValue}). Absent for nullary paths (e.g. exit/cancel).
484
+ */
485
+ inputs?: readonly InputRef[];
486
+ tapscript: TapscriptSegment;
487
+ /** Present for covenant paths; absent for pure-tapscript paths (cancel/exit). */
488
+ arkadeScript?: ArkadeSegment;
489
+ }
490
+ declare const SUPPORTED_PROGRAM_VERSION = 0;
491
+ /** An Arkade contract program (hand-written or compiler-emitted). */
492
+ interface Program {
493
+ version: number;
494
+ /**
495
+ * Optional program name — metadata only: round-tripped through the
496
+ * artifact JSON, never used in compilation or the taproot tree.
497
+ */
498
+ name?: string;
499
+ /**
500
+ * Ordered constructor parameters. Bare name strings are documentation only
501
+ * (the legacy hand-written form); typed descriptors `{ name, type }` make
502
+ * the list authoritative — see {@link validateProgram}.
503
+ */
504
+ params?: readonly InputRef[];
505
+ functions: Record<string, ArkadeFunction>;
506
+ }
507
+ /**
508
+ * Resolve an `asm` array to bytes: substitute `$param` placeholders from `bind`,
509
+ * pass everything else (opcode names, numbers, raw byte pushes) through to the
510
+ * Arkade script encoder. The SDK does not interpret opcodes — this is pure
511
+ * substitution + encoding. To embed a signer key (server, user, or any
512
+ * other), pass it as a `$param` in the constructor args; there is no
513
+ * `<SERVER_KEY>`/`<COSIGNER_KEY>` token.
514
+ */
515
+ declare function resolveAsm(asm: AsmToken[], bind: Record<string, ArkadeParamValue>): Uint8Array;
516
+ /**
517
+ * Resolve one witness-stack item to bytes.
518
+ *
519
+ * - raw bytes pass through;
520
+ * - numbers/bigints encode as minimal script-nums;
521
+ * - `"$param"` strings resolve against the program's constructor args;
522
+ * - any other string is a function-input name and resolves against `callArgs`
523
+ * (throws when the input is unbound — e.g. outside a function call).
524
+ */
525
+ declare function witnessRefToBytes(ref: WitnessRef, callArgs: Record<string, ArkadeArgValue>, programArgs: Record<string, ArkadeParamValue>): Uint8Array;
526
+ /**
527
+ * Validate a program's constructor-parameter declarations against the bound
528
+ * args. A `params` list of bare name strings is documentation only (the
529
+ * legacy hand-written form — no checks). When at least one entry is a typed
530
+ * descriptor (the compiler-emitted form), the list is authoritative: every
531
+ * declared param must be bound in `args`, every `"$name"` reference in the
532
+ * program must be declared, and typed entries validate their bound value
533
+ * (bytes-like types require a Uint8Array — 32 bytes for `pubkey`, 64 for
534
+ * `sig`; `int` requires a bigint/number).
535
+ */
536
+ declare function validateProgram(program: Program, args: Record<string, ArkadeParamValue>): void;
537
+ /** The signer keys a program is compiled against. */
538
+ interface ProgramKeys {
539
+ /** The Arkade Service signer key (x-only) — used for address derivation and collaborative-path detection, not for `$param` resolution. */
540
+ serverKey: Uint8Array;
541
+ /** The wallet's x-only key — identifies which inputs the wallet signs. */
542
+ userKey?: Uint8Array;
543
+ /** The co-signer (emulator) key — required only for covenant (`arkadeScript`) functions. */
544
+ emulatorKey?: Uint8Array;
545
+ }
546
+ /**
547
+ * A single spending path, fully resolved at compilation: its definition, the
548
+ * committed leaf body, the per-path arkade-script bytes (covenant paths only),
549
+ * and the {@link TapLeafScript} (control block) for spending it.
550
+ */
551
+ interface CompiledProgramFunction {
552
+ name: string;
553
+ def: ArkadeFunction;
554
+ /** The committed leaf script (body). */
555
+ leafScript: Uint8Array;
556
+ /** Resolved arkade-script bytes; undefined for pure-tapscript paths. */
557
+ arkadeScript?: Uint8Array;
558
+ /** Resolved signer keys (x-only), in the declared `signers` order. */
559
+ signerKeys: Uint8Array[];
560
+ /** Resolved once — the taproot leaf + control block for this path. */
561
+ tapLeafScript: TapLeafScript;
562
+ }
563
+ /**
564
+ * A {@link VtxoScript} compiled from an Arkade {@link Program}, its
565
+ * constructor args and the signer keys.
566
+ *
567
+ * This is the single compilation path shared by the high-level
568
+ * `ArkadeContract` client and the `"arkade"` contract handler: both produce
569
+ * byte-identical taproot trees for the same (program, args, keys), so a
570
+ * contract registered through the `src/contracts` pipeline re-derives the
571
+ * exact script it was created with.
572
+ */
573
+ declare class ArkadeProgramScript extends VtxoScript {
574
+ readonly program: Program;
575
+ readonly args: Record<string, ArkadeParamValue>;
576
+ readonly keys: ProgramKeys;
577
+ /** Spending paths in declaration order. */
578
+ readonly compiled: CompiledProgramFunction[];
579
+ constructor(program: Program, args: Record<string, ArkadeParamValue>, keys: ProgramKeys);
580
+ /** The compiled spending path with the given function name, if any. */
581
+ functionByName(name: string): CompiledProgramFunction | undefined;
582
+ }
583
+ /**
584
+ * Convert a Program JSON artifact into a {@link Program}. Byte values are
585
+ * encoded as `0x`-prefixed hex strings in `asm`/`witness`/`signers`; opcode names,
586
+ * `$param` placeholders and numbers pass through unchanged.
587
+ *
588
+ * This is *not* the JSON `arkadec` writes. That artifact lists spend groups in
589
+ * an array and uses `<param>` placeholders and raw leaf assembly; pass it to
590
+ * {@link programFromArtifact} instead.
591
+ */
592
+ declare function parseArtifact(artifact: {
593
+ version?: number;
594
+ name?: string;
595
+ params?: readonly InputRef[];
596
+ functions: unknown;
597
+ }): Program;
598
+ /**
599
+ * Serialize a {@link Program} to compiler-artifact JSON — the inverse of
600
+ * {@link parseArtifact}: bytes become `0x`-hex strings; bigint tokens become
601
+ * plain numbers (or, above `Number.MAX_SAFE_INTEGER`, `0x`-hex of their
602
+ * minimal script-num bytes, which the script encoder pushes identically);
603
+ * literal timelock values serialize as decimal strings while `"$param"`
604
+ * timelock references are emitted as-is.
605
+ */
606
+ declare function stringifyArtifact(program: Program): string;
607
+ /**
608
+ * Typed parameters of an `"arkade"` contract as persisted through the
609
+ * `src/contracts` pipeline. The program serializes as artifact JSON, args as
610
+ * a JSON map (`0x`-hex bytes, decimal-string bigints), keys as hex — so a
611
+ * stored contract row re-derives its script fully offline.
612
+ */
613
+ interface ArkadeContractParams {
614
+ program: Program;
615
+ args: Record<string, ArkadeParamValue>;
616
+ serverKey: Uint8Array;
617
+ userKey?: Uint8Array;
618
+ emulatorKey?: Uint8Array;
619
+ }
620
+ /** Serialize {@link ArkadeContractParams} to the string map `Contract.params` requires. */
621
+ declare function serializeArkadeContractParams(typed: ArkadeContractParams): Record<string, string>;
622
+ /** Parse the string map persisted in `Contract.params` back into typed params. */
623
+ declare function deserializeArkadeContractParams(params: Record<string, string>): ArkadeContractParams;
624
+
625
+ /**
626
+ * Generic handler for artifact/program-based Arkade contracts.
627
+ *
628
+ * Persists the full {@link ArkadeContractParams} (program artifact JSON, args,
629
+ * signer keys) as string params, so any contract created via
630
+ * `arkade.contract(program, args)` participates in the standard contract
631
+ * pipeline: ContractManager persistence and validation, watcher events,
632
+ * repository-backed balances, and offline script re-derivation. Rebuild a
633
+ * callable contract from a stored row with `ArkadeContract.fromContract`.
634
+ */
635
+ declare const ArkadeContractHandler: ContractHandler<ArkadeContractParams, ArkadeProgramScript> & TapscriptDeriving<ArkadeProgramScript>;
636
+
637
+ export { type ArkadeParamValue as A, BoardingContractHandler as B, type CompiledProgramFunction as C, DefaultContractHandler as D, VHTLCV2ContractHandler as E, type VHTLCV2ContractParams as F, contractHandlers as G, 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, type TweakedSigner as l, deserializeArkadeContractParams as m, stringifyArtifact as n, ArkadeContractHandler as o, parseArtifact as p, type BoardingContractParams as q, resolveAsm as r, serializeArkadeContractParams as s, type DefaultContractParams as t, DelegateContractHandler as u, validateProgram as v, witnessRefToBytes as w, type DelegateContractParams as x, VHTLCContractHandler as y, type VHTLCContractParams as z };