@arkade-os/sdk 0.4.45 → 0.4.47

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 (91) hide show
  1. package/dist/adapters/expo.cjs +5 -5
  2. package/dist/adapters/expo.d.cts +2 -2
  3. package/dist/adapters/expo.d.ts +2 -2
  4. package/dist/adapters/expo.js +3 -3
  5. package/dist/adapters/indexedDB.cjs +5 -5
  6. package/dist/adapters/indexedDB.js +4 -4
  7. package/dist/{ark-C-PjOngm.d.cts → ark-CoJgwTi_.d.cts} +31 -3
  8. package/dist/{ark-C-PjOngm.d.ts → ark-CoJgwTi_.d.ts} +31 -3
  9. package/dist/{asyncStorageTaskQueue-BmBPvTyh.d.cts → asyncStorageTaskQueue-Dowyo59a.d.cts} +2 -2
  10. package/dist/{asyncStorageTaskQueue-CHpI3moJ.d.ts → asyncStorageTaskQueue-Z3aFoXCl.d.ts} +2 -2
  11. package/dist/{chunk-QZ6HZZZK.js → chunk-3N5I6GT6.js} +3 -3
  12. package/dist/{chunk-QZ6HZZZK.js.map → chunk-3N5I6GT6.js.map} +1 -1
  13. package/dist/{chunk-BOA4SHCD.js → chunk-AJQ4AOT3.js} +4 -4
  14. package/dist/{chunk-BOA4SHCD.js.map → chunk-AJQ4AOT3.js.map} +1 -1
  15. package/dist/{chunk-BE5MUB7T.js → chunk-C7TXXTMS.js} +9 -5
  16. package/dist/chunk-C7TXXTMS.js.map +1 -0
  17. package/dist/{chunk-YBQV7XBC.js → chunk-CDDWXBEM.js} +139 -21
  18. package/dist/chunk-CDDWXBEM.js.map +1 -0
  19. package/dist/{chunk-UHOHLN3C.cjs → chunk-HHV5FPC6.cjs} +148 -25
  20. package/dist/chunk-HHV5FPC6.cjs.map +1 -0
  21. package/dist/{chunk-HZ7VIN7P.cjs → chunk-JAYOXOLT.cjs} +14 -14
  22. package/dist/{chunk-HZ7VIN7P.cjs.map → chunk-JAYOXOLT.cjs.map} +1 -1
  23. package/dist/{chunk-HXDZ2QTW.cjs → chunk-L5ND2FJJ.cjs} +9 -5
  24. package/dist/chunk-L5ND2FJJ.cjs.map +1 -0
  25. package/dist/{chunk-TGRJ5WAX.js → chunk-OCS5S3L3.js} +1085 -103
  26. package/dist/chunk-OCS5S3L3.js.map +1 -0
  27. package/dist/chunk-RQSA7ADZ.cjs +2286 -0
  28. package/dist/chunk-RQSA7ADZ.cjs.map +1 -0
  29. package/dist/{chunk-OFQGANH2.cjs → chunk-VE67GMGM.cjs} +7 -7
  30. package/dist/{chunk-OFQGANH2.cjs.map → chunk-VE67GMGM.cjs.map} +1 -1
  31. package/dist/{chunk-SRCWBFSZ.cjs → chunk-WTTLIFS7.cjs} +1281 -289
  32. package/dist/chunk-WTTLIFS7.cjs.map +1 -0
  33. package/dist/chunk-XN3554FT.js +2244 -0
  34. package/dist/chunk-XN3554FT.js.map +1 -0
  35. package/dist/contracts/handlers/index.cjs +11 -7
  36. package/dist/contracts/handlers/index.d.cts +3 -3
  37. package/dist/contracts/handlers/index.d.ts +3 -3
  38. package/dist/contracts/handlers/index.js +2 -2
  39. package/dist/{delegate-BKNqva1j.d.ts → delegate-CuaDqqQi.d.ts} +1 -1
  40. package/dist/{delegate-DOEobYwH.d.cts → delegate-Dl87_zMA.d.cts} +1 -1
  41. package/dist/index-BC_G0VTh.d.cts +512 -0
  42. package/dist/index-CKwpZEpw.d.ts +512 -0
  43. package/dist/index.cjs +219 -159
  44. package/dist/index.d.cts +3097 -2090
  45. package/dist/index.d.ts +3097 -2090
  46. package/dist/index.js +4 -4
  47. package/dist/repositories/realm/index.cjs +23 -19
  48. package/dist/repositories/realm/index.cjs.map +1 -1
  49. package/dist/repositories/realm/index.d.cts +2 -2
  50. package/dist/repositories/realm/index.d.ts +2 -2
  51. package/dist/repositories/realm/index.js +9 -5
  52. package/dist/repositories/realm/index.js.map +1 -1
  53. package/dist/repositories/sqlite/index.cjs +22 -18
  54. package/dist/repositories/sqlite/index.cjs.map +1 -1
  55. package/dist/repositories/sqlite/index.d.cts +2 -2
  56. package/dist/repositories/sqlite/index.d.ts +2 -2
  57. package/dist/repositories/sqlite/index.js +9 -5
  58. package/dist/repositories/sqlite/index.js.map +1 -1
  59. package/dist/{taskRunner-BngWSFMi.d.ts → taskRunner-Dz-TI4Rb.d.ts} +2 -2
  60. package/dist/{taskRunner-DOiyRuJa.d.cts → taskRunner-Dz47k0lp.d.cts} +2 -2
  61. package/dist/wallet/expo/background.cjs +14 -14
  62. package/dist/wallet/expo/background.d.cts +3 -3
  63. package/dist/wallet/expo/background.d.ts +3 -3
  64. package/dist/wallet/expo/background.js +6 -6
  65. package/dist/wallet/expo/index.cjs +18 -14
  66. package/dist/wallet/expo/index.cjs.map +1 -1
  67. package/dist/wallet/expo/index.d.cts +4 -4
  68. package/dist/wallet/expo/index.d.ts +4 -4
  69. package/dist/wallet/expo/index.js +9 -5
  70. package/dist/wallet/expo/index.js.map +1 -1
  71. package/dist/{wallet-DBjumS42.d.cts → wallet-Oxz_wLxo.d.cts} +47 -3
  72. package/dist/{wallet-B3awP1Nj.d.ts → wallet-x7egmXq6.d.ts} +47 -3
  73. package/dist/worker/expo/index.cjs +10 -9
  74. package/dist/worker/expo/index.cjs.map +1 -1
  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 +6 -5
  78. package/dist/worker/expo/index.js.map +1 -1
  79. package/package.json +2 -2
  80. package/dist/chunk-32YKLQPS.cjs +0 -970
  81. package/dist/chunk-32YKLQPS.cjs.map +0 -1
  82. package/dist/chunk-BE5MUB7T.js.map +0 -1
  83. package/dist/chunk-HXDZ2QTW.cjs.map +0 -1
  84. package/dist/chunk-SRCWBFSZ.cjs.map +0 -1
  85. package/dist/chunk-TGRJ5WAX.js.map +0 -1
  86. package/dist/chunk-UHOHLN3C.cjs.map +0 -1
  87. package/dist/chunk-YBQV7XBC.js.map +0 -1
  88. package/dist/chunk-YNEDJTX2.js +0 -957
  89. package/dist/chunk-YNEDJTX2.js.map +0 -1
  90. package/dist/index-BlW4I30l.d.cts +0 -259
  91. package/dist/index-Cm2fGeox.d.ts +0 -259
@@ -0,0 +1,512 @@
1
+ import { q as RelativeTimelock, V as VtxoScript, r as TapLeafScript, b3 as ContractHandler, bf as Discoverable, ck as TapscriptDeriving } from './ark-CoJgwTi_.js';
2
+ import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-CuaDqqQi.js';
3
+ import { Bytes } from '@scure/btc-signer/utils.js';
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
+ /**
70
+ * Registry for contract handlers.
71
+ *
72
+ * Each contract type ("default", "vhtlc", etc.) has a handler that knows
73
+ * how to create VtxoScripts, serialize params, and select spending paths.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Register a custom handler
78
+ * contractHandlers.register(myCustomHandler);
79
+ *
80
+ * // Get handler for a type
81
+ * const handler = contractHandlers.get("vhtlc");
82
+ * const script = handler.createScript(contract.params);
83
+ * ```
84
+ */
85
+ declare class ContractHandlerRegistry {
86
+ private handlers;
87
+ /**
88
+ * Register a contract handler.
89
+ *
90
+ * @param handler - The handler to register
91
+ * @throws If a handler for this type is already registered
92
+ */
93
+ register(handler: ContractHandler<unknown>): void;
94
+ /**
95
+ * Get a handler by type.
96
+ *
97
+ * @param type - The contract type
98
+ * @returns The handler, or undefined if not found
99
+ */
100
+ get(type: string): ContractHandler<unknown> | undefined;
101
+ /**
102
+ * Get a handler by type, throwing if not found.
103
+ *
104
+ * @param type - The contract type
105
+ * @returns The handler
106
+ * @throws If no handler is registered for this type
107
+ */
108
+ getOrThrow(type: string): ContractHandler<unknown>;
109
+ /**
110
+ * Check if a handler is registered.
111
+ *
112
+ * @param type - The contract type
113
+ */
114
+ has(type: string): boolean;
115
+ /**
116
+ * Get all registered types.
117
+ */
118
+ getRegisteredTypes(): string[];
119
+ /**
120
+ * Unregister a handler (mainly for testing).
121
+ */
122
+ unregister(type: string): boolean;
123
+ /**
124
+ * Clear all handlers (mainly for testing).
125
+ */
126
+ clear(): void;
127
+ }
128
+ /**
129
+ * Global registry of contract handlers.
130
+ */
131
+ declare const contractHandlers: ContractHandlerRegistry;
132
+
133
+ /**
134
+ * Typed parameters for DefaultVtxo contracts.
135
+ */
136
+ interface DefaultContractParams {
137
+ pubKey: Uint8Array;
138
+ serverPubKey: Uint8Array;
139
+ csvTimelock: RelativeTimelock;
140
+ }
141
+ /**
142
+ * Handler for default wallet VTXOs.
143
+ *
144
+ * Default contracts use the standard forfeit + exit tapscript:
145
+ * - forfeit: (Alice + Server) multisig for collaborative spending
146
+ * - exit: (Alice) + CSV timelock for unilateral exit
147
+ */
148
+ declare const DefaultContractHandler: ContractHandler<DefaultContractParams, DefaultVtxo.Script> & Discoverable;
149
+
150
+ /**
151
+ * Typed parameters for DelegateVtxo contracts.
152
+ */
153
+ interface DelegateContractParams {
154
+ pubKey: Uint8Array;
155
+ serverPubKey: Uint8Array;
156
+ delegatePubKey: Uint8Array;
157
+ csvTimelock: RelativeTimelock;
158
+ }
159
+ /**
160
+ * Handler for delegate wallet virtual outputs.
161
+ *
162
+ * Delegate contracts extend the default tapscript with an additional delegate path:
163
+ * - forfeit: (Alice + Server) multisig for collaborative spending
164
+ * - exit: (Alice) + CSV timelock for unilateral exit
165
+ * - delegate: (Alice + Delegate + Server) multisig for delegated renewal
166
+ */
167
+ declare const DelegateContractHandler: ContractHandler<DelegateContractParams, DelegateVtxo.Script> & Discoverable;
168
+
169
+ /**
170
+ * Typed parameters for VHTLC contracts.
171
+ */
172
+ interface VHTLCContractParams {
173
+ sender: Uint8Array;
174
+ receiver: Uint8Array;
175
+ server: Uint8Array;
176
+ preimageHash: Uint8Array;
177
+ refundLocktime: bigint;
178
+ unilateralClaimDelay: RelativeTimelock;
179
+ unilateralRefundDelay: RelativeTimelock;
180
+ unilateralRefundWithoutReceiverDelay: RelativeTimelock;
181
+ }
182
+ /**
183
+ * Handler for Virtual Hash Time Lock Contract (VHTLC).
184
+ *
185
+ * VHTLC supports multiple spending paths:
186
+ *
187
+ * Collaborative paths (with server):
188
+ * - claim: Receiver + Server with preimage
189
+ * - refund: Sender + Receiver + Server
190
+ * - refundWithoutReceiver: Sender + Server after CLTV locktime
191
+ *
192
+ * Unilateral paths (without server):
193
+ * - unilateralClaim: Receiver with preimage after CSV delay
194
+ * - unilateralRefund: Sender + Receiver after CSV delay
195
+ * - unilateralRefundWithoutReceiver: Sender after CSV delay
196
+ */
197
+ declare const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script>;
198
+
199
+ /**
200
+ * Typed parameters for boarding contracts.
201
+ *
202
+ * Boarding reuses the exact `default` contract parameter shape
203
+ * (`pubKey` / `serverPubKey` / `csvTimelock`) rather than inventing
204
+ * boarding-specific names — the boarding semantics come from the
205
+ * contract type and from populating `csvTimelock` with the server's
206
+ * boarding-exit delay (`ArkInfo.boardingExitDelay`) instead of the
207
+ * offchain unilateral-exit delay.
208
+ */
209
+ type BoardingContractParams = DefaultContractParams;
210
+ /**
211
+ * Handler for the boarding contract (registered type `boarding`).
212
+ *
213
+ * The boarding contract derives the on-chain Bitcoin address used to
214
+ * board funds onto Arkade. It shares the exact `DefaultVtxo.Script`
215
+ * shape with the `default` contract — a Taproot output co-owned by the
216
+ * wallet and the Ark server, with a CSV exit path back to the wallet —
217
+ * and therefore reuses the `default` handler's path logic (forfeit via
218
+ * server cooperation, exit after the boarding CSV).
219
+ *
220
+ * Boarding semantics come entirely from the contract type and from
221
+ * sourcing the CSV timelock from the server's boarding-exit delay
222
+ * (`ArkInfo.boardingExitDelay`), not from renamed parameters. The
223
+ * offchain `default` contract is built from `ArkInfo.unilateralExitDelay`
224
+ * instead, so the two share a script shape but differ in their CSV
225
+ * timelock value. Parameters round-trip through the same
226
+ * `timelockToSequence` / `sequenceToTimelock` helpers and BIP68 sequence
227
+ * encoding as `default` / `delegate`.
228
+ *
229
+ * Like `default` / `delegate`, the boarding handler implements
230
+ * {@link Discoverable.discoverAt} so `wallet.restore()` can rediscover
231
+ * used boarding indices from authoritative on-chain data. It differs from
232
+ * the L2 handlers in its source of truth: boarding probes the **on-chain**
233
+ * UTXO set at its P2TR address (`OnchainProvider.getCoins`) rather than the
234
+ * Ark indexer, and builds its candidate from the boarding-exit CSV
235
+ * (`deps.boardingTimelock`). When boarding discovery is not plumbed (no
236
+ * `deps.boardingTimelock` / `deps.onchainNetwork`) `discoverAt` no-ops.
237
+ *
238
+ * Identity & the default/boarding collision: a contract's `script` (pkScript)
239
+ * is its unique identity — a script owns exactly one repository row. `boarding`
240
+ * is a first-class type with its own row **when its script is distinct** from
241
+ * the wallet's `default` baseline — the real-world case, since a sound Ark
242
+ * server keeps boardingExitDelay strictly longer than unilateralExitDelay (equal
243
+ * delays would expose the provider to a double-spend). Should those delays ever
244
+ * coincide (a misconfigured/malicious server), the boarding script is
245
+ * byte-identical to the default script. `discoverAt` does NOT pre-coalesce that
246
+ * collision: it always emits `type: "boarding"`, and the single shared row is
247
+ * resolved FIRST-WINS at the persistence layer
248
+ * ({@link ContractManager.upsertContract}) — whichever purpose is persisted
249
+ * first keeps the row, and the scan deliberately probes boarding first
250
+ * (see docs/hd-wallets_onchain_rotation_collision_fix.md §5.1–5.2). Either way
251
+ * the funds are equally spendable through the shared `DefaultVtxo.Script` paths.
252
+ * Consumers must NOT rely on `contract.type === "boarding"` to identify the
253
+ * boarding purpose — resolve the boarding script via
254
+ * `wallet.getBoardingAddress()` / `wallet.boardingTapscript` (which never depend
255
+ * on the persisted contract's type) and match by script when needed.
256
+ */
257
+ declare const BoardingContractHandler: ContractHandler<BoardingContractParams, DefaultVtxo.Script> & Discoverable;
258
+
259
+ /**
260
+ * Arkade Program model & compiler.
261
+ *
262
+ * A {@link Program} is the artifact shape shared with the ArkadeScript
263
+ * compiler: named functions, each split into a `tapscript` segment enforced
264
+ * on-chain and an optional `arkadeScript` segment emulated by the co-signing
265
+ * service. This module owns everything that is *pure data → script*:
266
+ *
267
+ * - the Program/segment/token types,
268
+ * - `$param` resolution ({@link resolveAsm}), witness and timelock resolution,
269
+ * - program validation ({@link validateProgram}) — typed constructor params
270
+ * are authoritative when present,
271
+ * - {@link ArkadeProgramScript} — a {@link VtxoScript} compiled from a
272
+ * program, its constructor args and the signer keys,
273
+ * - artifact JSON (de)serialization ({@link parseArtifact} /
274
+ * {@link stringifyArtifact}) and the string-keyed contract params used to
275
+ * persist a program contract through the `src/contracts` pipeline.
276
+ *
277
+ * Keeping this free of provider/transaction imports lets the generic
278
+ * `arkade` contract handler (src/contracts/handlers/arkade.ts) and the
279
+ * high-level `ArkadeContract` client share one compilation path.
280
+ *
281
+ * @module arkade/program
282
+ */
283
+
284
+ /** A token in an `asm` array: an opcode name, a number/bigint push, raw bytes, or a `$param` placeholder. */
285
+ type AsmToken = string | number | bigint | Uint8Array;
286
+ /** A constructor argument or resolved value. */
287
+ type ArkadeParamValue = Uint8Array | bigint | number;
288
+ /** A function call argument (function input). */
289
+ type ArkadeArgValue = Uint8Array | bigint | number;
290
+ /**
291
+ * The declared type of a function input, used to derive the static TS type of
292
+ * the corresponding `functions.<name>(...)` argument. Byte-like types map to
293
+ * `Uint8Array`; `int` maps to `bigint | number`.
294
+ */
295
+ type ArkadeArgType = "bytes" | "pubkey" | "sig" | "hash" | "int";
296
+ /**
297
+ * Maps an {@link ArkadeArgType} to its TypeScript argument type.
298
+ * @internal
299
+ */
300
+ interface ArkadeValueType {
301
+ bytes: Uint8Array;
302
+ pubkey: Uint8Array;
303
+ sig: Uint8Array;
304
+ hash: Uint8Array;
305
+ int: bigint | number;
306
+ }
307
+ /** A typed function input or constructor param: a name plus its {@link ArkadeArgType}. */
308
+ interface InputDef {
309
+ name: string;
310
+ type: ArkadeArgType;
311
+ }
312
+ /**
313
+ * A function input or constructor param declaration: either a typed descriptor
314
+ * `{ name, type }` (the argument is statically typed and its bound value is
315
+ * validated) or a bare name string (the argument falls back to the loose
316
+ * {@link ArkadeArgValue}).
317
+ */
318
+ type InputRef = string | InputDef;
319
+ /** Reference to a signer key: a `"$param"` reference or literal x-only bytes. */
320
+ type SignerRef = string | Uint8Array;
321
+ /** A witness-stack item: a function-input name, a `"$param"`, a literal number/bigint (minimal script-num), or raw bytes. */
322
+ type WitnessRef = string | number | bigint | Uint8Array;
323
+ /** Bitcoin Script segment of a spending path — enforced on-chain. */
324
+ interface TapscriptSegment {
325
+ /** Required signers. The tweaked co-signer is appended automatically when the path has an `arkadeScript`. */
326
+ signers: SignerRef[];
327
+ /**
328
+ * Optional standard-opcode condition (e.g. a hashlock), encoded into a
329
+ * ConditionMultisig leaf — or ConditionCSVMultisig when combined with `csv`.
330
+ */
331
+ asm?: AsmToken[];
332
+ /**
333
+ * Relative timelock (CSV). The value is a literal or a `"$param"` reference
334
+ * resolved against the constructor args (same convention as {@link SignerRef}).
335
+ * Combinable with `asm` (condition + CSV); mutually exclusive with `cltv`.
336
+ */
337
+ csv?: {
338
+ type: "blocks" | "seconds";
339
+ value: bigint | string;
340
+ };
341
+ /**
342
+ * Absolute timelock (CLTV): a literal or a `"$param"` reference.
343
+ * Mutually exclusive with `csv`/`asm`.
344
+ */
345
+ cltv?: bigint | string;
346
+ /** Items satisfying the condition (e.g. an HTLC preimage); set via the ConditionWitness PSBT field. */
347
+ witness?: WitnessRef[];
348
+ }
349
+ /** Arkade Script segment of a spending path — emulated, bound via the key tweak. */
350
+ interface ArkadeSegment {
351
+ /** Raw Arkade opcodes with `$param` placeholders. */
352
+ asm: AsmToken[];
353
+ /** The arkade-script witness stack (e.g. an output index). */
354
+ witness?: WitnessRef[];
355
+ }
356
+ /** One named spending path. */
357
+ interface ArkadeFunction {
358
+ /**
359
+ * The function ABI: an ordered list of call arguments. Each entry is a typed
360
+ * descriptor `{ name, type }` (which gives the matching `functions.<name>`
361
+ * argument a precise static type) or a bare name string (loose
362
+ * {@link ArkadeArgValue}). Absent for nullary paths (e.g. exit/cancel).
363
+ */
364
+ inputs?: readonly InputRef[];
365
+ tapscript: TapscriptSegment;
366
+ /** Present for covenant paths; absent for pure-tapscript paths (cancel/exit). */
367
+ arkadeScript?: ArkadeSegment;
368
+ }
369
+ declare const SUPPORTED_PROGRAM_VERSION = 0;
370
+ /** An Arkade contract program (hand-written or compiler-emitted). */
371
+ interface Program {
372
+ version: number;
373
+ /**
374
+ * Optional program name — metadata only: round-tripped through the
375
+ * artifact JSON, never used in compilation or the taproot tree.
376
+ */
377
+ name?: string;
378
+ /**
379
+ * Ordered constructor parameters. Bare name strings are documentation only
380
+ * (the legacy hand-written form); typed descriptors `{ name, type }` make
381
+ * the list authoritative — see {@link validateProgram}.
382
+ */
383
+ params?: readonly InputRef[];
384
+ functions: Record<string, ArkadeFunction>;
385
+ }
386
+ /**
387
+ * Resolve an `asm` array to bytes: substitute `$param` placeholders from `bind`,
388
+ * pass everything else (opcode names, numbers, raw byte pushes) through to the
389
+ * Arkade script encoder. The SDK does not interpret opcodes — this is pure
390
+ * substitution + encoding. To embed a signer key (server, user, or any
391
+ * other), pass it as a `$param` in the constructor args; there is no
392
+ * `<SERVER_KEY>`/`<COSIGNER_KEY>` token.
393
+ */
394
+ declare function resolveAsm(asm: AsmToken[], bind: Record<string, ArkadeParamValue>): Uint8Array;
395
+ /**
396
+ * Resolve one witness-stack item to bytes.
397
+ *
398
+ * - raw bytes pass through;
399
+ * - numbers/bigints encode as minimal script-nums;
400
+ * - `"$param"` strings resolve against the program's constructor args;
401
+ * - any other string is a function-input name and resolves against `callArgs`
402
+ * (throws when the input is unbound — e.g. outside a function call).
403
+ */
404
+ declare function witnessRefToBytes(ref: WitnessRef, callArgs: Record<string, ArkadeArgValue>, programArgs: Record<string, ArkadeParamValue>): Uint8Array;
405
+ /**
406
+ * Validate a program's constructor-parameter declarations against the bound
407
+ * args. A `params` list of bare name strings is documentation only (the
408
+ * legacy hand-written form — no checks). When at least one entry is a typed
409
+ * descriptor (the compiler-emitted form), the list is authoritative: every
410
+ * declared param must be bound in `args`, every `"$name"` reference in the
411
+ * program must be declared, and typed entries validate their bound value
412
+ * (bytes-like types require a Uint8Array — 32 bytes for `pubkey`, 64 for
413
+ * `sig`; `int` requires a bigint/number).
414
+ */
415
+ declare function validateProgram(program: Program, args: Record<string, ArkadeParamValue>): void;
416
+ /** The signer keys a program is compiled against. */
417
+ interface ProgramKeys {
418
+ /** The Arkade Service signer key (x-only) — used for address derivation and collaborative-path detection, not for `$param` resolution. */
419
+ serverKey: Uint8Array;
420
+ /** The wallet's x-only key — identifies which inputs the wallet signs. */
421
+ userKey?: Uint8Array;
422
+ /** The co-signer (emulator) key — required only for covenant (`arkadeScript`) functions. */
423
+ emulatorKey?: Uint8Array;
424
+ }
425
+ /**
426
+ * A single spending path, fully resolved at compilation: its definition, the
427
+ * committed leaf body, the per-path arkade-script bytes (covenant paths only),
428
+ * and the {@link TapLeafScript} (control block) for spending it.
429
+ */
430
+ interface CompiledProgramFunction {
431
+ name: string;
432
+ def: ArkadeFunction;
433
+ /** The committed leaf script (body). */
434
+ leafScript: Uint8Array;
435
+ /** Resolved arkade-script bytes; undefined for pure-tapscript paths. */
436
+ arkadeScript?: Uint8Array;
437
+ /** Resolved signer keys (x-only), in the declared `signers` order. */
438
+ signerKeys: Uint8Array[];
439
+ /** Resolved once — the taproot leaf + control block for this path. */
440
+ tapLeafScript: TapLeafScript;
441
+ }
442
+ /**
443
+ * A {@link VtxoScript} compiled from an Arkade {@link Program}, its
444
+ * constructor args and the signer keys.
445
+ *
446
+ * This is the single compilation path shared by the high-level
447
+ * `ArkadeContract` client and the `"arkade"` contract handler: both produce
448
+ * byte-identical taproot trees for the same (program, args, keys), so a
449
+ * contract registered through the `src/contracts` pipeline re-derives the
450
+ * exact script it was created with.
451
+ */
452
+ declare class ArkadeProgramScript extends VtxoScript {
453
+ readonly program: Program;
454
+ readonly args: Record<string, ArkadeParamValue>;
455
+ readonly keys: ProgramKeys;
456
+ /** Spending paths in declaration order. */
457
+ readonly compiled: CompiledProgramFunction[];
458
+ constructor(program: Program, args: Record<string, ArkadeParamValue>, keys: ProgramKeys);
459
+ /** The compiled spending path with the given function name, if any. */
460
+ functionByName(name: string): CompiledProgramFunction | undefined;
461
+ }
462
+ /**
463
+ * Convert a compiler-style JSON artifact into a {@link Program}. Byte values are
464
+ * encoded as `0x`-prefixed hex strings in `asm`/`witness`/`signers`; opcode names,
465
+ * `$param` placeholders and numbers pass through unchanged.
466
+ */
467
+ declare function parseArtifact(artifact: {
468
+ version?: number;
469
+ name?: string;
470
+ params?: readonly InputRef[];
471
+ functions: Record<string, any>;
472
+ }): Program;
473
+ /**
474
+ * Serialize a {@link Program} to compiler-artifact JSON — the inverse of
475
+ * {@link parseArtifact}: bytes become `0x`-hex strings; bigint tokens become
476
+ * plain numbers (or, above `Number.MAX_SAFE_INTEGER`, `0x`-hex of their
477
+ * minimal script-num bytes, which the script encoder pushes identically);
478
+ * literal timelock values serialize as decimal strings while `"$param"`
479
+ * timelock references are emitted as-is.
480
+ */
481
+ declare function stringifyArtifact(program: Program): string;
482
+ /**
483
+ * Typed parameters of an `"arkade"` contract as persisted through the
484
+ * `src/contracts` pipeline. The program serializes as artifact JSON, args as
485
+ * a JSON map (`0x`-hex bytes, decimal-string bigints), keys as hex — so a
486
+ * stored contract row re-derives its script fully offline.
487
+ */
488
+ interface ArkadeContractParams {
489
+ program: Program;
490
+ args: Record<string, ArkadeParamValue>;
491
+ serverKey: Uint8Array;
492
+ userKey?: Uint8Array;
493
+ emulatorKey?: Uint8Array;
494
+ }
495
+ /** Serialize {@link ArkadeContractParams} to the string map `Contract.params` requires. */
496
+ declare function serializeArkadeContractParams(typed: ArkadeContractParams): Record<string, string>;
497
+ /** Parse the string map persisted in `Contract.params` back into typed params. */
498
+ declare function deserializeArkadeContractParams(params: Record<string, string>): ArkadeContractParams;
499
+
500
+ /**
501
+ * Generic handler for artifact/program-based Arkade contracts.
502
+ *
503
+ * Persists the full {@link ArkadeContractParams} (program artifact JSON, args,
504
+ * signer keys) as string params, so any contract created via
505
+ * `arkade.contract(program, args)` participates in the standard contract
506
+ * pipeline: ContractManager persistence and validation, watcher events,
507
+ * repository-backed balances, and offline script re-derivation. Rebuild a
508
+ * callable contract from a stored row with `ArkadeContract.fromContract`.
509
+ */
510
+ declare const ArkadeContractHandler: ContractHandler<ArkadeContractParams, ArkadeProgramScript> & TapscriptDeriving<ArkadeProgramScript>;
511
+
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 };