@arkade-os/sdk 0.5.0-rc.9 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +232 -51
  2. package/dist/adapters/expo.cjs +5 -5
  3. package/dist/adapters/expo.d.cts +5 -5
  4. package/dist/adapters/expo.d.ts +5 -5
  5. package/dist/adapters/expo.js +3 -3
  6. package/dist/{asyncStorageTaskQueue-DZYrAWN8.d.ts → asyncStorageTaskQueue-CdWheMqT.d.ts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-ChKX-D51.d.cts → asyncStorageTaskQueue-DFt5LgW5.d.cts} +1 -1
  8. package/dist/{chunk-R4KRWX7R.js → chunk-3M22PJVB.js} +427 -1078
  9. package/dist/chunk-3M22PJVB.js.map +1 -0
  10. package/dist/{chunk-J2K7WWMJ.js → chunk-6MIGYYWB.js} +112 -243
  11. package/dist/chunk-6MIGYYWB.js.map +1 -0
  12. package/dist/{chunk-FQCMEAWN.js → chunk-FXVEOEYB.js} +32 -39
  13. package/dist/chunk-FXVEOEYB.js.map +1 -0
  14. package/dist/{chunk-7OL2P5TV.cjs → chunk-GQUFPTN7.cjs} +39 -46
  15. package/dist/chunk-GQUFPTN7.cjs.map +1 -0
  16. package/dist/{chunk-VMVHRKXM.cjs → chunk-GW42FS2X.cjs} +494 -1122
  17. package/dist/chunk-GW42FS2X.cjs.map +1 -0
  18. package/dist/{chunk-V4JZOFYT.cjs → chunk-HQNQ3CLQ.cjs} +124 -254
  19. package/dist/chunk-HQNQ3CLQ.cjs.map +1 -0
  20. package/dist/{chunk-PO2ZDZZC.cjs → chunk-JJ6QKTFZ.cjs} +12 -10
  21. package/dist/chunk-JJ6QKTFZ.cjs.map +1 -0
  22. package/dist/{chunk-3TCWQPAC.js → chunk-NKKJEA3Z.js} +5842 -4284
  23. package/dist/chunk-NKKJEA3Z.js.map +1 -0
  24. package/dist/{chunk-JFZBKPSV.js → chunk-QFB55EOZ.js} +541 -400
  25. package/dist/chunk-QFB55EOZ.js.map +1 -0
  26. package/dist/{chunk-PKD5VPYX.cjs → chunk-QKNSMVBW.cjs} +6143 -4565
  27. package/dist/chunk-QKNSMVBW.cjs.map +1 -0
  28. package/dist/{chunk-VTXMC4N7.cjs → chunk-XLHUGP3G.cjs} +548 -399
  29. package/dist/chunk-XLHUGP3G.cjs.map +1 -0
  30. package/dist/{chunk-Z3QM5XFY.js → chunk-XQRIY5K5.js} +7 -5
  31. package/dist/chunk-XQRIY5K5.js.map +1 -0
  32. package/dist/contracts/handlers/index.cjs +9 -9
  33. package/dist/contracts/handlers/index.d.cts +5 -5
  34. package/dist/contracts/handlers/index.d.ts +5 -5
  35. package/dist/contracts/handlers/index.js +2 -2
  36. package/dist/{delegate-CyBnNY9v.d.ts → delegate-BSbGQabI.d.ts} +1 -1
  37. package/dist/{delegate-Cyv2suFd.d.cts → delegate-CFCfrReG.d.cts} +1 -1
  38. package/dist/{index-BIL9boGL.d.ts → index-B3fRWO5i.d.cts} +1652 -2291
  39. package/dist/{index-BIL9boGL.d.cts → index-B3fRWO5i.d.ts} +1652 -2291
  40. package/dist/index-CzUVvIxA.d.ts +645 -0
  41. package/dist/index-Fpf4mQZr.d.cts +645 -0
  42. package/dist/index.cjs +399 -311
  43. package/dist/index.d.cts +957 -1124
  44. package/dist/index.d.ts +957 -1124
  45. package/dist/index.js +4 -4
  46. package/dist/repositories/realm/index.cjs +165 -103
  47. package/dist/repositories/realm/index.cjs.map +1 -1
  48. package/dist/repositories/realm/index.d.cts +18 -14
  49. package/dist/repositories/realm/index.d.ts +18 -14
  50. package/dist/repositories/realm/index.js +153 -91
  51. package/dist/repositories/realm/index.js.map +1 -1
  52. package/dist/repositories/sqlite/index.cjs +226 -184
  53. package/dist/repositories/sqlite/index.cjs.map +1 -1
  54. package/dist/repositories/sqlite/index.d.cts +22 -21
  55. package/dist/repositories/sqlite/index.d.ts +22 -21
  56. package/dist/repositories/sqlite/index.js +218 -176
  57. package/dist/repositories/sqlite/index.js.map +1 -1
  58. package/dist/{taskRunner-Cu4uO1to.d.ts → taskRunner-CdfoCMaw.d.ts} +1 -1
  59. package/dist/{taskRunner-DxpSuKmh.d.cts → taskRunner-Dk6oDAtd.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 +10 -16
  63. package/dist/wallet/expo/background.d.ts +10 -16
  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 +19 -14
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +8 -6
  69. package/dist/wallet/expo/index.d.ts +8 -6
  70. package/dist/wallet/expo/index.js +10 -5
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/wallet-BQHNgc_v.d.ts +1874 -0
  73. package/dist/wallet-D9dvXu-K.d.cts +1874 -0
  74. package/dist/worker/expo/index.cjs +9 -9
  75. package/dist/worker/expo/index.d.cts +6 -6
  76. package/dist/worker/expo/index.d.ts +6 -6
  77. package/dist/worker/expo/index.js +5 -5
  78. package/package.json +10 -11
  79. package/dist/chunk-3TCWQPAC.js.map +0 -1
  80. package/dist/chunk-7OL2P5TV.cjs.map +0 -1
  81. package/dist/chunk-FQCMEAWN.js.map +0 -1
  82. package/dist/chunk-J2K7WWMJ.js.map +0 -1
  83. package/dist/chunk-JFZBKPSV.js.map +0 -1
  84. package/dist/chunk-PKD5VPYX.cjs.map +0 -1
  85. package/dist/chunk-PO2ZDZZC.cjs.map +0 -1
  86. package/dist/chunk-R4KRWX7R.js.map +0 -1
  87. package/dist/chunk-V4JZOFYT.cjs.map +0 -1
  88. package/dist/chunk-VMVHRKXM.cjs.map +0 -1
  89. package/dist/chunk-VTXMC4N7.cjs.map +0 -1
  90. package/dist/chunk-Z3QM5XFY.js.map +0 -1
  91. package/dist/hdWalletCapable-D1ImQqlu.d.cts +0 -2214
  92. package/dist/hdWalletCapable-DvumVrKW.d.ts +0 -2214
  93. package/dist/index-DleNQcz5.d.cts +0 -850
  94. package/dist/index-QVhQgYvU.d.ts +0 -850
@@ -0,0 +1,645 @@
1
+ import { bF as ContractHandler, x as RelativeTimelock, bR as Discoverable, V as VtxoScript, y as TapLeafScript, dI as TapscriptDeriving } from './index-B3fRWO5i.js';
2
+ import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-BSbGQabI.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 normalized SDK model: named functions, each
370
+ * 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}) — every referenced constructor
377
+ * parameter must be declared and bound,
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
+ /** Native scalar types and their compiler witness encodings. */
398
+ declare const ARKADE_TYPE_ENCODINGS: {
399
+ readonly pubkey: "raw";
400
+ readonly signature: "schnorr-64";
401
+ readonly bytes: "raw";
402
+ readonly bytes20: "raw-20";
403
+ readonly bytes32: "raw-32";
404
+ readonly asset: "raw-32";
405
+ readonly int: "scriptnum";
406
+ readonly bool: "scriptnum";
407
+ readonly AssetGroup: "scriptnum";
408
+ };
409
+ /** A native Arkade scalar type for a constructor parameter or call input. */
410
+ type ArkadeArgType = keyof typeof ARKADE_TYPE_ENCODINGS;
411
+ /**
412
+ * Maps an {@link ArkadeArgType} to its TypeScript argument type.
413
+ * @internal
414
+ */
415
+ interface ArkadeValueType {
416
+ bytes: Uint8Array;
417
+ pubkey: Uint8Array;
418
+ signature: Uint8Array;
419
+ bytes20: Uint8Array;
420
+ bytes32: Uint8Array;
421
+ asset: Uint8Array;
422
+ int: bigint | number;
423
+ bool: bigint | number;
424
+ AssetGroup: bigint | number;
425
+ }
426
+ /** A typed function input or constructor param: a name plus its {@link ArkadeArgType}. */
427
+ interface InputDef {
428
+ name: string;
429
+ type: ArkadeArgType;
430
+ }
431
+ /** A typed function input or constructor parameter. */
432
+ type InputRef = InputDef;
433
+ /** Constructor pubkey `$param` tweaked by `fn`'s covenant. */
434
+ interface TweakedSigner {
435
+ tweak: string;
436
+ fn: string;
437
+ }
438
+ /** A `"$param"` reference, literal x-only bytes, or a {@link TweakedSigner}. */
439
+ type SignerRef = string | Uint8Array | TweakedSigner;
440
+ /** A witness-stack item: a function-input name, a `"$param"`, a literal number/bigint (minimal script-num), or raw bytes. */
441
+ type WitnessRef = string | number | bigint | Uint8Array;
442
+ /** Bitcoin Script segment of a spending path — enforced on-chain. */
443
+ interface TapscriptSegment {
444
+ /**
445
+ * Required signers. A path with `arkadeScript` also inserts the emulator
446
+ * co-signer at `emulatorIndex` (last by default), unless `emulator` is `null`.
447
+ */
448
+ signers: SignerRef[];
449
+ /** Caller signature ABI; satisfied through PSBT signing, never ConditionWitness. */
450
+ signatures?: InputDef[];
451
+ /**
452
+ * Covenant named by `<EMULATOR_KEY:fn>`. `null` when this leaf belongs to a
453
+ * covenant but signs with a constructor-key tweak instead. Omitted on
454
+ * hand-written programs, which still append the co-signer.
455
+ */
456
+ emulator?: string | null;
457
+ /** Emulator's position in the full signer list; omitted to append it. */
458
+ emulatorIndex?: number;
459
+ /**
460
+ * Optional standard-opcode condition (e.g. a hashlock), encoded into a
461
+ * ConditionMultisig leaf — or ConditionCSVMultisig when combined with `csv`.
462
+ */
463
+ asm?: AsmToken[];
464
+ /**
465
+ * Relative timelock (CSV). The value is a literal or a `"$param"` reference
466
+ * resolved against the constructor args (same convention as {@link SignerRef}).
467
+ * `"blocks"` and `"seconds"` are counts; `"sequence"` is a raw BIP68
468
+ * sequence, which is what an `arkadec` CSV operand holds.
469
+ * Combinable with `asm` (condition + CSV); mutually exclusive with `cltv`.
470
+ */
471
+ csv?: {
472
+ type: "blocks" | "seconds" | "sequence";
473
+ value: bigint | string;
474
+ };
475
+ /**
476
+ * Absolute timelock (CLTV): a literal or a `"$param"` reference.
477
+ * Mutually exclusive with `csv`/`asm`.
478
+ */
479
+ cltv?: bigint | string;
480
+ /** Items satisfying the condition (e.g. an HTLC preimage); set via the ConditionWitness PSBT field. */
481
+ witness?: WitnessRef[];
482
+ }
483
+ /** Arkade Script segment of a spending path — emulated, bound via the key tweak. */
484
+ interface ArkadeSegment {
485
+ /** Raw Arkade opcodes with `$param` placeholders. */
486
+ asm: AsmToken[];
487
+ /** The arkade-script witness stack (e.g. an output index). */
488
+ witness?: WitnessRef[];
489
+ }
490
+ /** One named spending path. */
491
+ interface ArkadeFunction {
492
+ /** Compiler spend group, used to resolve named covenant commitments. */
493
+ group?: string;
494
+ /** Ordered typed call arguments; absent for nullary paths. */
495
+ inputs?: readonly InputDef[];
496
+ tapscript: TapscriptSegment;
497
+ /** Present for covenant paths; absent for pure-tapscript paths (cancel/exit). */
498
+ arkadeScript?: ArkadeSegment;
499
+ }
500
+ /** Supported normalized Program version. */
501
+ declare const SUPPORTED_PROGRAM_VERSION = 1;
502
+ /**
503
+ * A Program written for a version this SDK cannot read. Typed so a stored row in that format is
504
+ * reported as unsupported rather than broken: its script stays unknown until it is recovered with
505
+ * an SDK that reads that version, or re-created from fresh params.
506
+ */
507
+ declare class UnsupportedProgramVersionError extends Error {
508
+ readonly version: unknown;
509
+ readonly name = "UnsupportedProgramVersionError";
510
+ constructor(version: unknown, context: string);
511
+ }
512
+ /** An Arkade contract program (hand-written or compiler-emitted). */
513
+ interface Program {
514
+ version: number;
515
+ /**
516
+ * Optional program name — metadata only: round-tripped through the
517
+ * artifact JSON, never used in compilation or the taproot tree.
518
+ */
519
+ name?: string;
520
+ /** Ordered typed constructor parameters. */
521
+ params?: readonly InputDef[];
522
+ functions: Record<string, ArkadeFunction>;
523
+ }
524
+ /**
525
+ * Resolve an `asm` array to bytes: substitute `$param` placeholders from `bind`,
526
+ * pass everything else (opcode names, numbers, raw byte pushes) through to the
527
+ * Arkade script encoder. The SDK does not interpret opcodes — this is pure
528
+ * substitution + encoding. To embed a signer key (server, user, or any
529
+ * other), pass it as a `$param` in the constructor args. Compiler `<...>`
530
+ * placeholders are normalized by {@link programFromArtifact} before this step.
531
+ */
532
+ declare function resolveAsm(asm: AsmToken[], bind: Record<string, ArkadeParamValue>): Uint8Array;
533
+ /**
534
+ * Resolve one witness-stack item to bytes.
535
+ *
536
+ * - raw bytes pass through;
537
+ * - numbers/bigints encode as minimal script-nums;
538
+ * - `"$param"` strings resolve against the program's constructor args;
539
+ * - any other string is a function-input name and resolves against `callArgs`
540
+ * (throws when the input is unbound — e.g. outside a function call).
541
+ */
542
+ declare function witnessRefToBytes(ref: WitnessRef, callArgs: Record<string, ArkadeArgValue>, programArgs: Record<string, ArkadeParamValue>): Uint8Array;
543
+ /** Validate declared constructor values and reject undeclared references. */
544
+ declare function validateProgram(program: Program, args: Record<string, ArkadeParamValue>): void;
545
+ /** The signer keys a program is compiled against. */
546
+ interface ProgramKeys {
547
+ /** The Arkade Service signer key (x-only) — used for address derivation and collaborative-path detection, not for `$param` resolution. */
548
+ serverKey: Uint8Array;
549
+ /** The wallet's x-only key — identifies which inputs the wallet signs. */
550
+ userKey?: Uint8Array;
551
+ /** The co-signer (emulator) key — required only for covenant (`arkadeScript`) functions. */
552
+ emulatorKey?: Uint8Array;
553
+ }
554
+ /**
555
+ * A single spending path, fully resolved at compilation: its definition, the
556
+ * committed leaf body, the per-path arkade-script bytes (covenant paths only),
557
+ * and the {@link TapLeafScript} (control block) for spending it.
558
+ */
559
+ interface CompiledProgramFunction {
560
+ name: string;
561
+ def: ArkadeFunction;
562
+ /** The committed leaf script (body). */
563
+ leafScript: Uint8Array;
564
+ /** Resolved arkade-script bytes; undefined for pure-tapscript paths. */
565
+ arkadeScript?: Uint8Array;
566
+ /** Resolved signer keys (x-only), in the declared `signers` order. */
567
+ signerKeys: Uint8Array[];
568
+ /** Resolved once — the taproot leaf + control block for this path. */
569
+ tapLeafScript: TapLeafScript;
570
+ }
571
+ /**
572
+ * A {@link VtxoScript} compiled from an Arkade {@link Program}, its
573
+ * constructor args and the signer keys.
574
+ *
575
+ * This is the single compilation path shared by the high-level
576
+ * `ArkadeContract` client and the `"arkade"` contract handler: both produce
577
+ * byte-identical taproot trees for the same (program, args, keys), so a
578
+ * contract registered through the `src/contracts` pipeline re-derives the
579
+ * exact script it was created with.
580
+ */
581
+ declare class ArkadeProgramScript extends VtxoScript {
582
+ readonly program: Program;
583
+ readonly args: Record<string, ArkadeParamValue>;
584
+ readonly keys: ProgramKeys;
585
+ /** Spending paths in declaration order. */
586
+ readonly compiled: CompiledProgramFunction[];
587
+ constructor(program: Program, args: Record<string, ArkadeParamValue>, keys: ProgramKeys);
588
+ /** The compiled spending path with the given function name, if any. */
589
+ functionByName(name: string): CompiledProgramFunction | undefined;
590
+ }
591
+ /**
592
+ * Convert a Program JSON artifact into a {@link Program}. Byte values are
593
+ * encoded as `0x`-prefixed hex strings in `asm`/`witness`/`signers`; opcode names,
594
+ * `$param` placeholders and numbers pass through unchanged.
595
+ *
596
+ * This is *not* the JSON `arkadec` writes. That artifact lists spend groups in
597
+ * an array and uses `<param>` placeholders and raw leaf assembly; pass it to
598
+ * {@link programFromArtifact} instead.
599
+ */
600
+ declare function parseArtifact(artifact: {
601
+ version?: number;
602
+ name?: string;
603
+ params?: readonly InputDef[];
604
+ functions: unknown;
605
+ }): Program;
606
+ /**
607
+ * Serialize a {@link Program} to normalized Program JSON — the inverse of
608
+ * {@link parseArtifact}: bytes become `0x`-hex strings; bigint tokens become
609
+ * plain numbers (or, above `Number.MAX_SAFE_INTEGER`, `0x`-hex of their
610
+ * minimal script-num bytes, which the script encoder pushes identically);
611
+ * literal timelock values serialize as decimal strings while `"$param"`
612
+ * timelock references are emitted as-is.
613
+ */
614
+ declare function stringifyArtifact(program: Program): string;
615
+ /**
616
+ * Typed parameters of an `"arkade"` contract as persisted through the
617
+ * `src/contracts` pipeline. The program serializes as artifact JSON, args as
618
+ * a JSON map (`0x`-hex bytes, decimal-string bigints), keys as hex — so a
619
+ * stored contract row re-derives its script fully offline.
620
+ */
621
+ interface ArkadeContractParams {
622
+ program: Program;
623
+ args: Record<string, ArkadeParamValue>;
624
+ serverKey: Uint8Array;
625
+ userKey?: Uint8Array;
626
+ emulatorKey?: Uint8Array;
627
+ }
628
+ /** Serialize {@link ArkadeContractParams} to the string map `Contract.params` requires. */
629
+ declare function serializeArkadeContractParams(typed: ArkadeContractParams): Record<string, string>;
630
+ /** Parse the string map persisted in `Contract.params` back into typed params. */
631
+ declare function deserializeArkadeContractParams(params: Record<string, string>): ArkadeContractParams;
632
+
633
+ /**
634
+ * Generic handler for artifact/program-based Arkade contracts.
635
+ *
636
+ * Persists the full {@link ArkadeContractParams} (program artifact JSON, args,
637
+ * signer keys) as string params, so any contract created via
638
+ * `arkade.contract(program, args)` participates in the standard contract
639
+ * pipeline: ContractManager persistence and validation, watcher events,
640
+ * repository-backed balances, and offline script re-derivation. Rebuild a
641
+ * callable contract from a stored row with `ArkadeContract.fromContract`.
642
+ */
643
+ declare const ArkadeContractHandler: ContractHandler<ArkadeContractParams, ArkadeProgramScript> & TapscriptDeriving<ArkadeProgramScript>;
644
+
645
+ 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 InputDef as I, type Program as P, SUPPORTED_PROGRAM_VERSION as S, type TapscriptSegment as T, UnsupportedProgramVersionError as U, VHTLC as V, type WitnessRef as W, ArkadeProgramScript as a, type ProgramKeys as b, type ArkadeArgValue as c, type ArkadeFunction as d, type ArkadeValueType as e, type ArkadeArgType as f, type ArkadeContractParams as g, type ArkadeSegment as h, type AsmToken as i, type InputRef 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 };