@arkade-os/sdk 0.5.0-rc.2 → 0.5.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -83
- package/dist/adapters/expo.cjs +5 -6
- package/dist/adapters/expo.d.cts +4 -4
- package/dist/adapters/expo.d.ts +4 -4
- package/dist/adapters/expo.js +3 -4
- package/dist/{asyncStorageTaskQueue-C5rBYlru.d.ts → asyncStorageTaskQueue-aL7K14e4.d.ts} +2 -2
- package/dist/{asyncStorageTaskQueue-BuDvgWh6.d.cts → asyncStorageTaskQueue-x8ok3tJy.d.cts} +2 -2
- package/dist/{chunk-ISO4TI5J.js → chunk-4FDNOLBO.js} +566 -459
- package/dist/chunk-4FDNOLBO.js.map +1 -0
- package/dist/{chunk-JZWLXNHV.cjs → chunk-5XBH5SAL.cjs} +574 -464
- package/dist/chunk-5XBH5SAL.cjs.map +1 -0
- package/dist/{chunk-3R476TDV.js → chunk-CXHJGED6.js} +293 -1071
- package/dist/chunk-CXHJGED6.js.map +1 -0
- package/dist/{chunk-ZRNQV6HV.js → chunk-EXFU6MTA.js} +4578 -4396
- package/dist/chunk-EXFU6MTA.js.map +1 -0
- package/dist/{chunk-43FKNLX4.cjs → chunk-GVF4OCTL.cjs} +357 -1114
- package/dist/chunk-GVF4OCTL.cjs.map +1 -0
- package/dist/{chunk-HLCGYOIH.cjs → chunk-HIZNPHB2.cjs} +37 -36
- package/dist/chunk-HIZNPHB2.cjs.map +1 -0
- package/dist/{chunk-4PKLULWT.js → chunk-JZAEFOE4.js} +109 -246
- package/dist/chunk-JZAEFOE4.js.map +1 -0
- package/dist/{chunk-ZOTXDOS5.js → chunk-LNJPVLIC.js} +30 -29
- package/dist/chunk-LNJPVLIC.js.map +1 -0
- package/dist/{chunk-NVZJSKZS.cjs → chunk-Q7PC3NHX.cjs} +121 -257
- package/dist/chunk-Q7PC3NHX.cjs.map +1 -0
- package/dist/{chunk-GMZZQXV5.cjs → chunk-R5OFJ23O.cjs} +4961 -4767
- package/dist/chunk-R5OFJ23O.cjs.map +1 -0
- package/dist/{chunk-6DNR46C7.js → chunk-S2WWOVFC.js} +7 -5
- package/dist/chunk-S2WWOVFC.js.map +1 -0
- package/dist/{chunk-D25O4EGY.cjs → chunk-VZMLADXQ.cjs} +12 -10
- package/dist/chunk-VZMLADXQ.cjs.map +1 -0
- package/dist/contracts/handlers/index.cjs +9 -10
- package/dist/contracts/handlers/index.d.cts +5 -5
- package/dist/contracts/handlers/index.d.ts +5 -5
- package/dist/contracts/handlers/index.js +2 -3
- package/dist/{delegate-BAX5QftB.d.ts → delegate-BT5iON1T.d.ts} +1 -1
- package/dist/{delegate-1yp1HyP7.d.cts → delegate-u6kXTtWY.d.cts} +1 -1
- package/dist/index-BCnhItOQ.d.cts +639 -0
- package/dist/{index-DUxufw76.d.cts → index-CK5QbTmZ.d.cts} +1387 -2404
- package/dist/{index-DUxufw76.d.ts → index-CK5QbTmZ.d.ts} +1387 -2404
- package/dist/index-D1D4cR-G.d.ts +639 -0
- package/dist/index.cjs +375 -340
- package/dist/index.d.cts +784 -1197
- package/dist/index.d.ts +784 -1197
- package/dist/index.js +4 -5
- package/dist/repositories/realm/index.cjs +201 -106
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +28 -16
- package/dist/repositories/realm/index.d.ts +28 -16
- package/dist/repositories/realm/index.js +190 -95
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +301 -189
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +32 -21
- package/dist/repositories/sqlite/index.d.ts +32 -21
- package/dist/repositories/sqlite/index.js +294 -182
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-D_iPiZIi.d.ts → taskRunner-BeYR6NpQ.d.ts} +2 -2
- package/dist/{taskRunner-Dr3NStc0.d.cts → taskRunner-Csey3EYJ.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -15
- package/dist/wallet/expo/background.cjs.map +1 -1
- package/dist/wallet/expo/background.d.cts +10 -16
- package/dist/wallet/expo/background.d.ts +10 -16
- package/dist/wallet/expo/background.js +6 -7
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +16 -23
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +6 -9
- package/dist/wallet/expo/index.d.ts +6 -9
- package/dist/wallet/expo/index.js +8 -15
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/wallet-DG3Qmbmt.d.cts +1848 -0
- package/dist/wallet-DzSLMxBZ.d.ts +1848 -0
- package/dist/worker/expo/index.cjs +9 -10
- package/dist/worker/expo/index.cjs.map +1 -1
- package/dist/worker/expo/index.d.cts +6 -6
- package/dist/worker/expo/index.d.ts +6 -6
- package/dist/worker/expo/index.js +5 -6
- package/dist/worker/expo/index.js.map +1 -1
- package/package.json +12 -51
- package/dist/adapters/asyncStorage.cjs +0 -48
- package/dist/adapters/asyncStorage.cjs.map +0 -1
- package/dist/adapters/asyncStorage.d.cts +0 -16
- package/dist/adapters/asyncStorage.d.ts +0 -16
- package/dist/adapters/asyncStorage.js +0 -46
- package/dist/adapters/asyncStorage.js.map +0 -1
- package/dist/adapters/fileSystem.cjs +0 -116
- package/dist/adapters/fileSystem.cjs.map +0 -1
- package/dist/adapters/fileSystem.d.cts +0 -17
- package/dist/adapters/fileSystem.d.ts +0 -17
- package/dist/adapters/fileSystem.js +0 -93
- package/dist/adapters/fileSystem.js.map +0 -1
- package/dist/adapters/indexedDB.cjs +0 -103
- package/dist/adapters/indexedDB.cjs.map +0 -1
- package/dist/adapters/indexedDB.d.cts +0 -18
- package/dist/adapters/indexedDB.d.ts +0 -18
- package/dist/adapters/indexedDB.js +0 -101
- package/dist/adapters/indexedDB.js.map +0 -1
- package/dist/adapters/localStorage.cjs +0 -50
- package/dist/adapters/localStorage.cjs.map +0 -1
- package/dist/adapters/localStorage.d.cts +0 -14
- package/dist/adapters/localStorage.d.ts +0 -14
- package/dist/adapters/localStorage.js +0 -48
- package/dist/adapters/localStorage.js.map +0 -1
- package/dist/chunk-3R476TDV.js.map +0 -1
- package/dist/chunk-43FKNLX4.cjs.map +0 -1
- package/dist/chunk-4PKLULWT.js.map +0 -1
- package/dist/chunk-5BLDMQED.cjs +0 -18
- package/dist/chunk-5BLDMQED.cjs.map +0 -1
- package/dist/chunk-6DNR46C7.js.map +0 -1
- package/dist/chunk-D25O4EGY.cjs.map +0 -1
- package/dist/chunk-GMZZQXV5.cjs.map +0 -1
- package/dist/chunk-HLCGYOIH.cjs.map +0 -1
- package/dist/chunk-ISO4TI5J.js.map +0 -1
- package/dist/chunk-JZWLXNHV.cjs.map +0 -1
- package/dist/chunk-NSBPE2FW.js +0 -15
- package/dist/chunk-NSBPE2FW.js.map +0 -1
- package/dist/chunk-NVZJSKZS.cjs.map +0 -1
- package/dist/chunk-ZOTXDOS5.js.map +0 -1
- package/dist/chunk-ZRNQV6HV.js.map +0 -1
- package/dist/hdWalletCapable-CmEU0NP1.d.ts +0 -2232
- package/dist/hdWalletCapable-eJgaT-ec.d.cts +0 -2232
- package/dist/index-Bem5vKzX.d.ts +0 -850
- package/dist/index-C0IanN1m.d.cts +0 -11
- package/dist/index-C0IanN1m.d.ts +0 -11
- package/dist/index-W_oMcOmG.d.cts +0 -850
package/dist/index-Bem5vKzX.d.ts
DELETED
|
@@ -1,850 +0,0 @@
|
|
|
1
|
-
import { bn as ContractHandler, w as RelativeTimelock, bz as Discoverable, V as VtxoScript, x as TapLeafScript, df as TapscriptDeriving } from './index-DUxufw76.js';
|
|
2
|
-
import { D as DefaultVtxo, a as DelegateVtxo } from './delegate-BAX5QftB.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
|
-
/**
|
|
24
|
-
* Register a contract handler.
|
|
25
|
-
*
|
|
26
|
-
* @param handler - The handler to register
|
|
27
|
-
* @throws If a handler for this type is already registered
|
|
28
|
-
*/
|
|
29
|
-
register(handler: ContractHandler<unknown>): void;
|
|
30
|
-
/**
|
|
31
|
-
* Get a handler by type.
|
|
32
|
-
*
|
|
33
|
-
* @param type - The contract type
|
|
34
|
-
* @returns The handler, or undefined if not found
|
|
35
|
-
*/
|
|
36
|
-
get(type: string): ContractHandler<unknown> | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Get a handler by type, throwing if not found.
|
|
39
|
-
*
|
|
40
|
-
* @param type - The contract type
|
|
41
|
-
* @returns The handler
|
|
42
|
-
* @throws If no handler is registered for this type
|
|
43
|
-
*/
|
|
44
|
-
getOrThrow(type: string): ContractHandler<unknown>;
|
|
45
|
-
/**
|
|
46
|
-
* Check if a handler is registered.
|
|
47
|
-
*
|
|
48
|
-
* @param type - The contract type
|
|
49
|
-
*/
|
|
50
|
-
has(type: string): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Get all registered types.
|
|
53
|
-
*/
|
|
54
|
-
getRegisteredTypes(): string[];
|
|
55
|
-
/**
|
|
56
|
-
* Unregister a handler (mainly for testing).
|
|
57
|
-
*/
|
|
58
|
-
unregister(type: string): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Clear all handlers (mainly for testing).
|
|
61
|
-
*/
|
|
62
|
-
clear(): void;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Global registry of contract handlers.
|
|
66
|
-
*/
|
|
67
|
-
declare const contractHandlers: ContractHandlerRegistry;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Typed parameters for DefaultVtxo contracts.
|
|
71
|
-
*/
|
|
72
|
-
interface DefaultContractParams {
|
|
73
|
-
pubKey: Uint8Array;
|
|
74
|
-
serverPubKey: Uint8Array;
|
|
75
|
-
csvTimelock: RelativeTimelock;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Handler for default wallet VTXOs.
|
|
79
|
-
*
|
|
80
|
-
* Default contracts use the standard forfeit + exit tapscript:
|
|
81
|
-
* - forfeit: (Alice + Server) multisig for collaborative spending
|
|
82
|
-
* - exit: (Alice) + CSV timelock for unilateral exit
|
|
83
|
-
*/
|
|
84
|
-
declare const DefaultContractHandler: ContractHandler<DefaultContractParams, DefaultVtxo.Script> & Discoverable;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Typed parameters for DelegateVtxo contracts.
|
|
88
|
-
*/
|
|
89
|
-
interface DelegateContractParams {
|
|
90
|
-
pubKey: Uint8Array;
|
|
91
|
-
serverPubKey: Uint8Array;
|
|
92
|
-
delegatePubKey: Uint8Array;
|
|
93
|
-
csvTimelock: RelativeTimelock;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Handler for delegate wallet virtual outputs.
|
|
97
|
-
*
|
|
98
|
-
* Delegate contracts extend the default tapscript with an additional delegate path:
|
|
99
|
-
* - forfeit: (Alice + Server) multisig for collaborative spending
|
|
100
|
-
* - exit: (Alice) + CSV timelock for unilateral exit
|
|
101
|
-
* - delegate: (Alice + Delegate + Server) multisig for delegated renewal
|
|
102
|
-
*/
|
|
103
|
-
declare const DelegateContractHandler: ContractHandler<DelegateContractParams, DelegateVtxo.Script> & Discoverable;
|
|
104
|
-
|
|
105
|
-
/** Virtual Hash Time Lock Contract (VHTLC) namespace. */
|
|
106
|
-
declare namespace VHTLC {
|
|
107
|
-
export interface Options {
|
|
108
|
-
sender: Bytes;
|
|
109
|
-
receiver: Bytes;
|
|
110
|
-
server: Bytes;
|
|
111
|
-
preimageHash: Bytes;
|
|
112
|
-
refundLocktime: bigint;
|
|
113
|
-
unilateralClaimDelay: RelativeTimelock;
|
|
114
|
-
unilateralRefundDelay: RelativeTimelock;
|
|
115
|
-
unilateralRefundWithoutReceiverDelay: RelativeTimelock;
|
|
116
|
-
/**
|
|
117
|
-
* The emulator covenant leaves, ALL OR NOTHING. Present, this adds the
|
|
118
|
-
* three non-interactive leaves the emulator co-signs under a covenant
|
|
119
|
-
* pinning the payout to a pre-committed destination:
|
|
120
|
-
*
|
|
121
|
-
* - `nonInteractiveClaim`: `server` + a covenant-tweaked emulator
|
|
122
|
-
* co-signer, paying `receiverPkScript` — the receiver's claim can
|
|
123
|
-
* be pushed without the receiver being online.
|
|
124
|
-
* - `nonInteractiveRefund`: `server` + `receiver` + a covenant-tweaked
|
|
125
|
-
* emulator co-signer, paying `senderPkScript`, no timelock — lets
|
|
126
|
-
* server and receiver release the refund the moment they agree the
|
|
127
|
-
* swap has failed, and recoverable even if the sender's own key is
|
|
128
|
-
* lost, since no OTHER refund-side leaf survives that.
|
|
129
|
-
* - `nonInteractiveRefundWithoutReceiver`: `server` + the SAME
|
|
130
|
-
* covenant-tweaked co-signer as `nonInteractiveRefund`, paying
|
|
131
|
-
* `senderPkScript` after `refundLocktime` — the only refund tier
|
|
132
|
-
* needing no participant signature at all, so a sender who funded
|
|
133
|
-
* a lockup and vanished is refundable through it alone.
|
|
134
|
-
*
|
|
135
|
-
* WHY ONE FLAG AND NOT A SWITCH PER LEAF. The three are one mechanism
|
|
136
|
-
* — the same emulator key, the same `enforcePayTo` covenant pointed
|
|
137
|
-
* at a per-role destination — and they protect opposite directions of
|
|
138
|
-
* the same swap, so no real configuration wants a subset. A subset
|
|
139
|
-
* would cost, not buy: every optional leaf multiplies the tree shapes
|
|
140
|
-
* a counterparty must derive to verify an address (nothing on the
|
|
141
|
-
* wire says which leaves a quote carries), so per-leaf toggling turns
|
|
142
|
-
* one address comparison into a combinatorial guess. All-or-nothing
|
|
143
|
-
* keeps the shape count at two: suite, or no suite.
|
|
144
|
-
*
|
|
145
|
-
* Leaf order fixes the taproot merkle root, so the suite is appended
|
|
146
|
-
* after the six signature leaves in a fixed order (claim, refund,
|
|
147
|
-
* timelocked refund) and a script built with this option NEVER
|
|
148
|
-
* collides with one built without it — which is what makes "did this
|
|
149
|
-
* quote opt in" a question an address comparison answers.
|
|
150
|
-
*
|
|
151
|
-
* STABLE PER RELEASE: what this option builds does not change within
|
|
152
|
-
* a published SDK version. A future covenant leaf joins the suite
|
|
153
|
-
* only behind a NEW option, so re-deriving a lockup with the SDK
|
|
154
|
-
* that quoted it reproduces its address byte-for-byte.
|
|
155
|
-
*/
|
|
156
|
-
nonInteractiveParameters?: {
|
|
157
|
-
/**
|
|
158
|
-
* The emulator service's public key, 32-byte x-only or 33-byte
|
|
159
|
-
* compressed. ONE key, tweaked per covenant destination, becomes
|
|
160
|
-
* the co-signer of every leaf in the suite — the leaves share it
|
|
161
|
-
* structurally, and BIP-341 tapscript sighashes committing to the
|
|
162
|
-
* tapleaf hash are what keep a signature for one leaf from
|
|
163
|
-
* replaying against another.
|
|
164
|
-
*/
|
|
165
|
-
emulatorPubkey: Bytes;
|
|
166
|
-
/**
|
|
167
|
-
* Where the claim covenant pays: the receiver's own P2TR
|
|
168
|
-
* pkScript, 34 bytes.
|
|
169
|
-
*/
|
|
170
|
-
receiverPkScript: Bytes;
|
|
171
|
-
/**
|
|
172
|
-
* Where BOTH refund covenants pay: the sender's own P2TR
|
|
173
|
-
* pkScript, 34 bytes. One destination shared by both refund
|
|
174
|
-
* leaves, so they cannot diverge on where a refund goes.
|
|
175
|
-
*/
|
|
176
|
-
senderPkScript: Bytes;
|
|
177
|
-
/**
|
|
178
|
-
* LEGACY REBUILD ONLY — never for a new lockup.
|
|
179
|
-
*
|
|
180
|
-
* `"preTimelockedRefund"` builds the suite WITHOUT its timelocked
|
|
181
|
-
* refund leaf: the shape every emulator-covenant lockup funded
|
|
182
|
-
* before that leaf shipped carries. Lockups already funded in that
|
|
183
|
-
* shape keep it permanently — a leaf cannot be retrofitted onto an
|
|
184
|
-
* address already committed — so re-deriving such a lockup (to
|
|
185
|
-
* spend it, or to verify an old quote's address) needs this. A new
|
|
186
|
-
* lockup that omits the leaf gives up the one refund tier needing
|
|
187
|
-
* nobody, for nothing.
|
|
188
|
-
*/
|
|
189
|
-
legacy?: "preTimelockedRefund";
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Optional: denominate this contract in an Arkade ASSET rather than in
|
|
193
|
-
* sats alone.
|
|
194
|
-
*
|
|
195
|
-
* Only the two NON-INTERACTIVE leaves change. Every other leaf is a
|
|
196
|
-
* signature path that asserts nothing about value, so an asset makes no
|
|
197
|
-
* difference to them — which is why this option reaches exactly the
|
|
198
|
-
* leaves whose covenant the emulator enforces.
|
|
199
|
-
*
|
|
200
|
-
* When set, those covenants additionally require the output to carry at
|
|
201
|
-
* least the input's amount of THIS asset, and to carry exactly one
|
|
202
|
-
* asset. The sat clause is RETAINED, not replaced: an asset-carrying
|
|
203
|
-
* VTXO carries sats too, so dropping it would let a spend satisfy the
|
|
204
|
-
* asset covenant while stripping the sats — exactly as the sat-only
|
|
205
|
-
* covenant lets a spend strip the asset.
|
|
206
|
-
*
|
|
207
|
-
* ONE ASSET IS BOUND, AND ONLY THAT ONE IS PROTECTED. If a VTXO funded to
|
|
208
|
-
* this contract carries ADDITIONAL assets alongside the bound one, those
|
|
209
|
-
* are not covered: whoever assembles a covenant spend chooses where they
|
|
210
|
-
* go, and can send them anywhere.
|
|
211
|
-
*
|
|
212
|
-
* `INSPECTOUTASSETCOUNT == 1` does not close that. It constrains the
|
|
213
|
-
* covenant's OUTPUT to exactly one asset — so the extras cannot ride
|
|
214
|
-
* along with the bound asset — but arkd's conservation rule is satisfied
|
|
215
|
-
* by routing them to a different output, which the covenant says nothing
|
|
216
|
-
* about. The bound asset arrives; the rest is the spender's to direct.
|
|
217
|
-
*
|
|
218
|
-
* So fund an asset contract with the asset it names and nothing else. A
|
|
219
|
-
* multi-asset VTXO behind this covenant is a loss waiting for whoever
|
|
220
|
-
* pushes the spend.
|
|
221
|
-
*
|
|
222
|
-
* The id is the pair the introspection opcodes take. A canonical Asset
|
|
223
|
-
* ID is `(genesis txid, group index)`, never a single blob.
|
|
224
|
-
*/
|
|
225
|
-
asset?: {
|
|
226
|
-
/**
|
|
227
|
-
* The asset's genesis transaction id, 32 bytes, in CANONICAL order
|
|
228
|
-
* — exactly the leading 32 bytes of a serialized Asset ID, no flip.
|
|
229
|
-
*
|
|
230
|
-
* The covenant reverses it internally because the introspection
|
|
231
|
-
* opcodes match wire order; callers never do that themselves, and a
|
|
232
|
-
* caller who pre-reverses gets a contract that is unspendable on its
|
|
233
|
-
* covenant leaves with nothing in the error naming why.
|
|
234
|
-
*/
|
|
235
|
-
txid: Bytes;
|
|
236
|
-
/** The asset group index within that genesis transaction. */
|
|
237
|
-
groupIndex: number;
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Shared construction and accessors for every VHTLC script version. The
|
|
242
|
-
* only thing that varies between versions is which preimage-condition
|
|
243
|
-
* fragment `claim`/`unilateralClaim`/`nonInteractiveClaim` are built
|
|
244
|
-
* from — everything else (the multisig/timelock leaves, the
|
|
245
|
-
* non-interactive covenant leaves, the accessor methods) is identical,
|
|
246
|
-
* so versions are expressed as thin subclasses over one builder rather
|
|
247
|
-
* than as separate, independently-maintained copies of this class.
|
|
248
|
-
*/
|
|
249
|
-
abstract class BaseScript extends VtxoScript {
|
|
250
|
-
readonly options: Options;
|
|
251
|
-
readonly claimScript: string;
|
|
252
|
-
readonly refundScript: string;
|
|
253
|
-
readonly refundWithoutReceiverScript: string;
|
|
254
|
-
readonly unilateralClaimScript: string;
|
|
255
|
-
readonly unilateralRefundScript: string;
|
|
256
|
-
readonly unilateralRefundWithoutReceiverScript: string;
|
|
257
|
-
readonly nonInteractiveClaimScript?: string;
|
|
258
|
-
readonly nonInteractiveClaimArkadeScript?: Bytes;
|
|
259
|
-
readonly nonInteractiveRefundScript?: string;
|
|
260
|
-
readonly nonInteractiveRefundArkadeScript?: Bytes;
|
|
261
|
-
readonly nonInteractiveRefundWithoutReceiverScript?: string;
|
|
262
|
-
readonly nonInteractiveRefundWithoutReceiverArkadeScript?: Bytes;
|
|
263
|
-
protected constructor(options: Options, preimageCondition: (hash: Bytes) => Bytes);
|
|
264
|
-
/** Return the collaborative claim tapleaf script. */
|
|
265
|
-
claim(): TapLeafScript;
|
|
266
|
-
/** Return the collaborative refund tapleaf script. */
|
|
267
|
-
refund(): TapLeafScript;
|
|
268
|
-
/** Return the refund-without-receiver tapleaf script. */
|
|
269
|
-
refundWithoutReceiver(): TapLeafScript;
|
|
270
|
-
/** Return the unilateral claim tapleaf script. */
|
|
271
|
-
unilateralClaim(): TapLeafScript;
|
|
272
|
-
/** Return the unilateral refund tapleaf script. */
|
|
273
|
-
unilateralRefund(): TapLeafScript;
|
|
274
|
-
/** Return the unilateral refund-without-receiver tapleaf script. */
|
|
275
|
-
unilateralRefundWithoutReceiver(): TapLeafScript;
|
|
276
|
-
/** Return the non-interactive claim tapleaf script as well as the ArkadeScript. */
|
|
277
|
-
nonInteractiveClaim(): [TapLeafScript, Bytes];
|
|
278
|
-
/** Return the non-interactive refund tapleaf script as well as the ArkadeScript. */
|
|
279
|
-
nonInteractiveRefund(): [TapLeafScript, Bytes];
|
|
280
|
-
/**
|
|
281
|
-
* Return the timelocked non-interactive refund tapleaf and its ArkadeScript.
|
|
282
|
-
*
|
|
283
|
-
* SPENDING THIS LEAF, CONCRETELY — confirmed from this SDK's own
|
|
284
|
-
* emulator client and covenant-spend builder ({@link
|
|
285
|
-
* EmulatorProvider} in `src/providers/emulator.ts`, and {@link
|
|
286
|
-
* ArkadeTransactionBuilder} in `src/arkade/contract.ts`), which is
|
|
287
|
-
* the general machinery every covenant leaf in this file goes
|
|
288
|
-
* through:
|
|
289
|
-
*
|
|
290
|
-
* 1. Build the ark tx spending this leaf (this method's {@link
|
|
291
|
-
* TapLeafScript} as `tapLeafScript`, this script's {@link
|
|
292
|
-
* VtxoScript.encode} as `tapTree`), plus its checkpoint tx.
|
|
293
|
-
* 2. Attach the ArkadeScript this method returns to the spent
|
|
294
|
-
* input via an `EmulatorPacket` (type 1) — `{ vin, script:
|
|
295
|
-
* <this ArkadeScript>, witness: <empty> }`, empty because the
|
|
296
|
-
* script pushes its own input/output index with
|
|
297
|
-
* `PUSHCURRENTINPUTINDEX` rather than reading one from the
|
|
298
|
-
* witness — wrapped in an `Extension` OP_RETURN output on the
|
|
299
|
-
* ark tx.
|
|
300
|
-
* 3. Attach the spent input's OWN creating ark tx as `PrevArkTx` on
|
|
301
|
-
* input 0 — required so the emulator can resolve that input's
|
|
302
|
-
* prevout pkScript/value; it does not otherwise have them.
|
|
303
|
-
* 4. POST the (base64-PSBT) ark tx and checkpoint(s) as `{ arkTx,
|
|
304
|
-
* checkpointTxs }` to the emulator's `POST /v1/tx`.
|
|
305
|
-
*
|
|
306
|
-
* THE COVENANT CHECK the emulator runs against that ArkadeScript —
|
|
307
|
-
* `enforcePayTo(senderPkScript)`, see that function above — is: the
|
|
308
|
-
* output at this SAME input's index is a v1 P2TR output paying
|
|
309
|
-
* `senderPkScript`, with a value at least the input's. Only on that
|
|
310
|
-
* check passing does the emulator sign for `nirCosigner` (the
|
|
311
|
-
* `emulatorPubkey` tweaked by this ArkadeScript's hash); the
|
|
312
|
-
* response carries the fully co-signed `signedArkTx` and
|
|
313
|
-
* `signedCheckpointTxs` — `ArkadeTransactionBuilder.send()`'s own
|
|
314
|
-
* comment on this path: "the emulator executes the arkade script
|
|
315
|
-
* and finalizes with arkd" — no separate call to arkd is made by
|
|
316
|
-
* this SDK for a covenant spend.
|
|
317
|
-
* Neither `server` nor `receiver` play any part in that check: this
|
|
318
|
-
* leaf's tapscript still requires `server`'s own signature
|
|
319
|
-
* alongside `nirCosigner`'s (see the class doc above), but that is
|
|
320
|
-
* consensus-level multisig, not something the covenant enforces.
|
|
321
|
-
*
|
|
322
|
-
* NOT SPENDABLE UNTIL `refundLocktime` MATURES — the tapscript's
|
|
323
|
-
* `OP_CHECKLOCKTIMEVERIFY` is arkd's concern, not the emulator's;
|
|
324
|
-
* the emulator will happily co-sign an immature spend and arkd will
|
|
325
|
-
* then refuse it. A block-height-typed `refundLocktime` (below the
|
|
326
|
-
* standard height/timestamp boundary this SDK names
|
|
327
|
-
* `CLTV_HEIGHT_THRESHOLD`, 500,000,000, in
|
|
328
|
-
* `src/contracts/handlers/helpers.ts`) is refused by arkd for a
|
|
329
|
-
* forfeit-eligible leaf independent of maturity — use a
|
|
330
|
-
* seconds-typed (absolute Unix timestamp) value.
|
|
331
|
-
*/
|
|
332
|
-
nonInteractiveRefundWithoutReceiver(): [TapLeafScript, Bytes];
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Virtual Hash Time Lock Contract (VHTLC) script implementation.
|
|
336
|
-
*
|
|
337
|
-
* VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
|
|
338
|
-
* It provides multiple spending paths:
|
|
339
|
-
*
|
|
340
|
-
* - **claim**: Receiver can claim funds by revealing the preimage
|
|
341
|
-
* - **refund**: Sender and receiver can collaboratively refund
|
|
342
|
-
* - **refundWithoutReceiver**: Sender can refund after locktime expires
|
|
343
|
-
* - **unilateralClaim**: Receiver can claim unilaterally after delay
|
|
344
|
-
* - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
|
|
345
|
-
* - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
|
|
346
|
-
* - **nonInteractiveClaim** (with `nonInteractiveParameters`): server + emulator
|
|
347
|
-
* can push the receiver's claim, pinned to a pre-committed destination
|
|
348
|
-
* - **nonInteractiveRefund** (with `nonInteractiveParameters`): server + receiver
|
|
349
|
-
* + emulator can push the sender's refund immediately, no timelock,
|
|
350
|
-
* pinned to a pre-committed destination — recoverable even if the
|
|
351
|
-
* sender's own key is lost
|
|
352
|
-
* - **nonInteractiveRefundWithoutReceiver** (with `nonInteractiveParameters`):
|
|
353
|
-
* server + emulator can push the sender's refund after `refundLocktime`,
|
|
354
|
-
* pinned to a pre-committed destination — the only refund tier needing
|
|
355
|
-
* no participant signature at all
|
|
356
|
-
*
|
|
357
|
-
* See {@link ScriptV2} for the current recommended construction — same
|
|
358
|
-
* leaf ladder, same options shape, an added length check on the claim
|
|
359
|
-
* preimage. This class is unchanged and stays available as-is.
|
|
360
|
-
*
|
|
361
|
-
* **Pre-existing limitation: the `vhtlc` contract handler registers none
|
|
362
|
-
* of the covenant leaves.** `nonInteractiveParameters` builds on this class
|
|
363
|
-
* exactly as it does on {@link ScriptV2} — both extend the same
|
|
364
|
-
* `BaseScript` where those leaves are constructed. But the `vhtlc`
|
|
365
|
-
* contract handler (`src/contracts/handlers/vhtlc.ts`) round-trips none
|
|
366
|
-
* of them: its params type carries no covenant fields, and
|
|
367
|
-
* `createScript` only ever builds the six signature-only leaves. A V1
|
|
368
|
-
* script built with the covenant suite therefore compiles and can
|
|
369
|
-
* be funded, but cannot be registered as a `vhtlc` contract — the
|
|
370
|
-
* handler would derive a different (six-leaf) script for the same
|
|
371
|
-
* params and `ContractManager` refuses the mismatch. Register through
|
|
372
|
-
* the `vhtlc-v2` handler instead, which round-trips the suite.
|
|
373
|
-
*
|
|
374
|
-
* @example
|
|
375
|
-
* ```typescript
|
|
376
|
-
* const vhtlc = new VHTLC.Script({
|
|
377
|
-
* sender: alicePubKey,
|
|
378
|
-
* receiver: bobPubKey,
|
|
379
|
-
* server: serverPubKey,
|
|
380
|
-
* preimageHash: hash160(secret),
|
|
381
|
-
* refundLocktime: BigInt(chainTip + 10),
|
|
382
|
-
* unilateralClaimDelay: { type: 'blocks', value: 100n },
|
|
383
|
-
* unilateralRefundDelay: { type: 'blocks', value: 102n },
|
|
384
|
-
* unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
|
|
385
|
-
* });
|
|
386
|
-
* ```
|
|
387
|
-
*/
|
|
388
|
-
export class Script extends BaseScript {
|
|
389
|
-
constructor(options: Options);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Same leaf ladder as {@link Script}, built with {@link
|
|
393
|
-
* preimageConditionScriptV2} instead of {@link preimageConditionScript}
|
|
394
|
-
* for every leaf that gates on the preimage (`claim`, `unilateralClaim`,
|
|
395
|
-
* and, when present, `nonInteractiveClaim`) — see that function's doc
|
|
396
|
-
* comment for what differs and why. A distinct class rather than a flag
|
|
397
|
-
* on {@link Script}: the two produce different script bytes (and so
|
|
398
|
-
* different addresses) for the same participant keys, and keeping them
|
|
399
|
-
* as separate types makes that a compile-time-visible choice at every
|
|
400
|
-
* call site instead of a runtime option that's easy to get wrong.
|
|
401
|
-
*/
|
|
402
|
-
export class ScriptV2 extends BaseScript {
|
|
403
|
-
constructor(options: Options);
|
|
404
|
-
}
|
|
405
|
-
export { };
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Typed parameters for VHTLC contracts.
|
|
410
|
-
*/
|
|
411
|
-
interface VHTLCContractParams {
|
|
412
|
-
sender: Uint8Array;
|
|
413
|
-
receiver: Uint8Array;
|
|
414
|
-
server: Uint8Array;
|
|
415
|
-
preimageHash: Uint8Array;
|
|
416
|
-
refundLocktime: bigint;
|
|
417
|
-
unilateralClaimDelay: RelativeTimelock;
|
|
418
|
-
unilateralRefundDelay: RelativeTimelock;
|
|
419
|
-
unilateralRefundWithoutReceiverDelay: RelativeTimelock;
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Handler for Virtual Hash Time Lock Contract (VHTLC).
|
|
423
|
-
*
|
|
424
|
-
* VHTLC supports multiple spending paths:
|
|
425
|
-
*
|
|
426
|
-
* Collaborative paths (with server):
|
|
427
|
-
* - claim: Receiver + Server with preimage
|
|
428
|
-
* - refund: Sender + Receiver + Server
|
|
429
|
-
* - refundWithoutReceiver: Sender + Server after CLTV locktime
|
|
430
|
-
*
|
|
431
|
-
* Unilateral paths (without server):
|
|
432
|
-
* - unilateralClaim: Receiver with preimage after CSV delay
|
|
433
|
-
* - unilateralRefund: Sender + Receiver after CSV delay
|
|
434
|
-
* - unilateralRefundWithoutReceiver: Sender after CSV delay
|
|
435
|
-
*/
|
|
436
|
-
declare const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script> & TapscriptDeriving<VHTLC.Script>;
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Typed parameters for {@link VHTLC.ScriptV2} contracts.
|
|
440
|
-
*
|
|
441
|
-
* The eight mandatory fields are `VHTLCContractParams` verbatim — the two
|
|
442
|
-
* script versions take the same {@link VHTLC.Options}, so a divergent shape
|
|
443
|
-
* here would be a difference with no cause. What V1's handler has no field for
|
|
444
|
-
* is the emulator covenant suite, and that is exactly what the swap corridor's
|
|
445
|
-
* lockup carries, so leaving it out would make this handler unable to
|
|
446
|
-
* round-trip the contract it exists to serve.
|
|
447
|
-
*/
|
|
448
|
-
interface VHTLCV2ContractParams {
|
|
449
|
-
sender: Uint8Array;
|
|
450
|
-
receiver: Uint8Array;
|
|
451
|
-
server: Uint8Array;
|
|
452
|
-
preimageHash: Uint8Array;
|
|
453
|
-
refundLocktime: bigint;
|
|
454
|
-
unilateralClaimDelay: RelativeTimelock;
|
|
455
|
-
unilateralRefundDelay: RelativeTimelock;
|
|
456
|
-
unilateralRefundWithoutReceiverDelay: RelativeTimelock;
|
|
457
|
-
/**
|
|
458
|
-
* The Arkade asset the covenant leaves bind, if any.
|
|
459
|
-
*
|
|
460
|
-
* @see VHTLC.Options.asset
|
|
461
|
-
*/
|
|
462
|
-
asset?: {
|
|
463
|
-
/** The asset's genesis txid, 32 bytes, canonical order — as the serialized Asset ID carries it. */
|
|
464
|
-
txid: Uint8Array;
|
|
465
|
-
/** The asset group index within that genesis transaction. */
|
|
466
|
-
groupIndex: number;
|
|
467
|
-
};
|
|
468
|
-
/**
|
|
469
|
-
* The emulator covenant suite, all or nothing — mirrors {@link
|
|
470
|
-
* VHTLC.Options.nonInteractiveParameters} exactly, including the legacy selector:
|
|
471
|
-
* a row funded before the timelocked refund leaf shipped round-trips with
|
|
472
|
-
* `legacy: "preTimelockedRefund"` and re-derives its eight-leaf shape.
|
|
473
|
-
*/
|
|
474
|
-
nonInteractiveParameters?: {
|
|
475
|
-
receiverPkScript: Uint8Array;
|
|
476
|
-
emulatorPubkey: Uint8Array;
|
|
477
|
-
senderPkScript: Uint8Array;
|
|
478
|
-
/** @see VHTLC.Options.nonInteractiveParameters.legacy */
|
|
479
|
-
legacy?: "preTimelockedRefund";
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Handler for {@link VHTLC.ScriptV2} — the VHTLC whose preimage leaves carry an
|
|
484
|
-
* explicit `OP_SIZE 32 OP_EQUALVERIFY` before the hash check, and which the RFQ
|
|
485
|
-
* swap corridor builds (`@arkade-os/swap`'s `lightningSendContract`).
|
|
486
|
-
*
|
|
487
|
-
* **Why a separate type string rather than a flag on `vhtlc`.** A handler's
|
|
488
|
-
* `type` names the script class it derives, the way every other registered type
|
|
489
|
-
* does (`default` → `DefaultVtxo.Script`, `vhtlc` → `VHTLC.Script`, `boarding`,
|
|
490
|
-
* `arkade`). V1 and V2 produce different script bytes — and so different
|
|
491
|
-
* pkScripts — for identical participant keys, and `upsertContractRow` derives
|
|
492
|
-
* the script from `params` and refuses any row whose supplied `script` does not
|
|
493
|
-
* match. One type cannot serve both. `vhtlc-v2` also cannot COLLIDE with
|
|
494
|
-
* `vhtlc`: a colliding row needs one pkScript claimed by two types, and the two
|
|
495
|
-
* versions' preimage conditions differ in every tree, so no parameters make
|
|
496
|
-
* them equal. A use-named type (`swap-lockup`) was the alternative and is
|
|
497
|
-
* worse: contracts are keyed by script, so the moment a second use registered
|
|
498
|
-
* the same ScriptV2 the two uses would fight over one row.
|
|
499
|
-
*
|
|
500
|
-
* **Which leaves this offers, and why the set is smaller than the ladder.**
|
|
501
|
-
* ScriptV2 has nine leaves; a wallet holding ONE of the two participant keys
|
|
502
|
-
* can satisfy four of them, and offering a leaf whose signature the caller
|
|
503
|
-
* cannot produce is worse than offering fewer — it turns a refusal into a
|
|
504
|
-
* transaction that gets built and then rejected.
|
|
505
|
-
*
|
|
506
|
-
* | leaf | needs | offered |
|
|
507
|
-
* |---------------------------------------|--------------------------------|---------|
|
|
508
|
-
* | `claim` | receiver + server, preimage | yes, to the receiver |
|
|
509
|
-
* | `refund` | sender + receiver + server | no — needs the counterparty live |
|
|
510
|
-
* | `refundWithoutReceiver` | sender + server, CLTV | yes, to the sender |
|
|
511
|
-
* | `unilateralClaim` | receiver, CSV | yes, to the receiver |
|
|
512
|
-
* | `unilateralRefund` | sender + receiver, CSV | no — needs the counterparty live |
|
|
513
|
-
* | `unilateralRefundWithoutReceiver` | sender, CSV | yes, to the sender |
|
|
514
|
-
* | `nonInteractiveClaim` | server + emulator | no — the wallet holds neither key |
|
|
515
|
-
* | `nonInteractiveRefund` | server + receiver + emulator | no — the wallet holds neither key |
|
|
516
|
-
* | `nonInteractiveRefundWithoutReceiver` | server + emulator, CLTV | no — the wallet holds neither key |
|
|
517
|
-
*
|
|
518
|
-
* The two omitted interactive leaves are the same two the `vhtlc` handler
|
|
519
|
-
* omits, for the same reason: `refund` and `unilateralRefund` both need the
|
|
520
|
-
* OTHER party's signature, and this protocol has no message that asks for one
|
|
521
|
-
* (see `@arkade-os/swap`'s `refund.ts` module doc). The two covenant leaves are
|
|
522
|
-
* pushed by the emulator on the counterparty's behalf and are not this wallet's
|
|
523
|
-
* to build at all.
|
|
524
|
-
*
|
|
525
|
-
* So `refundWithoutReceiver` is the sender's only collaborative way out, gated
|
|
526
|
-
* on the CLTV the quote committed to — which is exactly the leaf
|
|
527
|
-
* `pushRefundWithoutReceiver` builds. The CSV leaves are offered only in the
|
|
528
|
-
* non-collaborative context, where the caller has already accepted that
|
|
529
|
-
* spending them means a real unilateral exit first.
|
|
530
|
-
*
|
|
531
|
-
* The selection discipline is deliberately identical to the `vhtlc` handler's,
|
|
532
|
-
* and `test/contracts/vhtlcV2-handler.test.ts` pins the two against each other
|
|
533
|
-
* rung-for-rung across every role and timelock context so they cannot drift.
|
|
534
|
-
*/
|
|
535
|
-
declare const VHTLCV2ContractHandler: ContractHandler<VHTLCV2ContractParams, VHTLC.ScriptV2> & TapscriptDeriving<VHTLC.ScriptV2>;
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* Typed parameters for boarding contracts.
|
|
539
|
-
*
|
|
540
|
-
* Boarding reuses the exact `default` contract parameter shape
|
|
541
|
-
* (`pubKey` / `serverPubKey` / `csvTimelock`) rather than inventing
|
|
542
|
-
* boarding-specific names — the boarding semantics come from the
|
|
543
|
-
* contract type and from populating `csvTimelock` with the server's
|
|
544
|
-
* boarding-exit delay (`ArkadeInfo.boardingExitDelay`) instead of the
|
|
545
|
-
* offchain unilateral-exit delay.
|
|
546
|
-
*/
|
|
547
|
-
type BoardingContractParams = DefaultContractParams;
|
|
548
|
-
/**
|
|
549
|
-
* Handler for the boarding contract (registered type `boarding`).
|
|
550
|
-
*
|
|
551
|
-
* The boarding contract derives the on-chain Bitcoin address used to
|
|
552
|
-
* board funds onto Arkade. It shares the exact `DefaultVtxo.Script`
|
|
553
|
-
* shape with the `default` contract — a Taproot output co-owned by the
|
|
554
|
-
* wallet and the Ark server, with a CSV exit path back to the wallet —
|
|
555
|
-
* and therefore reuses the `default` handler's path logic (forfeit via
|
|
556
|
-
* server cooperation, exit after the boarding CSV).
|
|
557
|
-
*
|
|
558
|
-
* Boarding semantics come entirely from the contract type and from
|
|
559
|
-
* sourcing the CSV timelock from the server's boarding-exit delay
|
|
560
|
-
* (`ArkadeInfo.boardingExitDelay`), not from renamed parameters. The
|
|
561
|
-
* offchain `default` contract is built from `ArkadeInfo.unilateralExitDelay`
|
|
562
|
-
* instead, so the two share a script shape but differ in their CSV
|
|
563
|
-
* timelock value. Parameters round-trip through the same
|
|
564
|
-
* `timelockToSequence` / `sequenceToTimelock` helpers and BIP68 sequence
|
|
565
|
-
* encoding as `default` / `delegate`.
|
|
566
|
-
*
|
|
567
|
-
* Like `default` / `delegate`, the boarding handler implements
|
|
568
|
-
* {@link Discoverable.discoverAt} so `wallet.restore()` can rediscover
|
|
569
|
-
* used boarding indices from authoritative on-chain data. It differs from
|
|
570
|
-
* the L2 handlers in its source of truth: boarding probes the **on-chain**
|
|
571
|
-
* UTXO set at its P2TR address (`OnchainProvider.getCoins`) rather than the
|
|
572
|
-
* Ark indexer, and builds its candidate from the boarding-exit CSV
|
|
573
|
-
* (`deps.boardingTimelock`). When boarding discovery is not plumbed (no
|
|
574
|
-
* `deps.boardingTimelock` / `deps.onchainNetwork`) `discoverAt` no-ops.
|
|
575
|
-
*
|
|
576
|
-
* Identity & the default/boarding collision: a contract's `script` (pkScript)
|
|
577
|
-
* is its unique identity — a script owns exactly one repository row. `boarding`
|
|
578
|
-
* is a first-class type with its own row **when its script is distinct** from
|
|
579
|
-
* the wallet's `default` baseline — the real-world case, since a sound Ark
|
|
580
|
-
* server keeps boardingExitDelay strictly longer than unilateralExitDelay (equal
|
|
581
|
-
* delays would expose the provider to a double-spend). Should those delays ever
|
|
582
|
-
* coincide (a misconfigured/malicious server), the boarding script is
|
|
583
|
-
* byte-identical to the default script. `discoverAt` does NOT pre-coalesce that
|
|
584
|
-
* collision: it always emits `type: "boarding"`, and the single shared row is
|
|
585
|
-
* resolved FIRST-WINS at the persistence layer
|
|
586
|
-
* ({@link ContractManager.upsertContract}) — whichever purpose is persisted
|
|
587
|
-
* first keeps the row, and the scan deliberately probes boarding first
|
|
588
|
-
* (see docs/hd-wallets_onchain_rotation_collision_fix.md §5.1–5.2). Either way
|
|
589
|
-
* the funds are equally spendable through the shared `DefaultVtxo.Script` paths.
|
|
590
|
-
* Consumers must NOT rely on `contract.type === "boarding"` to identify the
|
|
591
|
-
* boarding purpose — resolve the boarding script via
|
|
592
|
-
* `wallet.getBoardingAddress()` / `wallet.boardingTapscript` (which never depend
|
|
593
|
-
* on the persisted contract's type) and match by script when needed.
|
|
594
|
-
*/
|
|
595
|
-
declare const BoardingContractHandler: ContractHandler<BoardingContractParams, DefaultVtxo.Script> & Discoverable;
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* Arkade Program model & compiler.
|
|
599
|
-
*
|
|
600
|
-
* A {@link Program} is the artifact shape shared with the ArkadeScript
|
|
601
|
-
* compiler: named functions, each split into a `tapscript` segment enforced
|
|
602
|
-
* on-chain and an optional `arkadeScript` segment emulated by the co-signing
|
|
603
|
-
* service. This module owns everything that is *pure data → script*:
|
|
604
|
-
*
|
|
605
|
-
* - the Program/segment/token types,
|
|
606
|
-
* - `$param` resolution ({@link resolveAsm}), witness and timelock resolution,
|
|
607
|
-
* - program validation ({@link validateProgram}) — typed constructor params
|
|
608
|
-
* are authoritative when present,
|
|
609
|
-
* - {@link ArkadeProgramScript} — a {@link VtxoScript} compiled from a
|
|
610
|
-
* program, its constructor args and the signer keys,
|
|
611
|
-
* - artifact JSON (de)serialization ({@link parseArtifact} /
|
|
612
|
-
* {@link stringifyArtifact}) and the string-keyed contract params used to
|
|
613
|
-
* persist a program contract through the `src/contracts` pipeline.
|
|
614
|
-
*
|
|
615
|
-
* Keeping this free of provider/transaction imports lets the generic
|
|
616
|
-
* `arkade` contract handler (src/contracts/handlers/arkade.ts) and the
|
|
617
|
-
* high-level `ArkadeContract` client share one compilation path.
|
|
618
|
-
*
|
|
619
|
-
* @module arkade/program
|
|
620
|
-
*/
|
|
621
|
-
|
|
622
|
-
/** A token in an `asm` array: an opcode name, a number/bigint push, raw bytes, or a `$param` placeholder. */
|
|
623
|
-
type AsmToken = string | number | bigint | Uint8Array;
|
|
624
|
-
/** A constructor argument or resolved value. */
|
|
625
|
-
type ArkadeParamValue = Uint8Array | bigint | number;
|
|
626
|
-
/** A function call argument (function input). */
|
|
627
|
-
type ArkadeArgValue = Uint8Array | bigint | number;
|
|
628
|
-
/**
|
|
629
|
-
* The declared type of a function input, used to derive the static TS type of
|
|
630
|
-
* the corresponding `functions.<name>(...)` argument. Byte-like types map to
|
|
631
|
-
* `Uint8Array`; `int` maps to `bigint | number`.
|
|
632
|
-
*/
|
|
633
|
-
type ArkadeArgType = "bytes" | "pubkey" | "sig" | "hash" | "int";
|
|
634
|
-
/**
|
|
635
|
-
* Maps an {@link ArkadeArgType} to its TypeScript argument type.
|
|
636
|
-
* @internal
|
|
637
|
-
*/
|
|
638
|
-
interface ArkadeValueType {
|
|
639
|
-
bytes: Uint8Array;
|
|
640
|
-
pubkey: Uint8Array;
|
|
641
|
-
sig: Uint8Array;
|
|
642
|
-
hash: Uint8Array;
|
|
643
|
-
int: bigint | number;
|
|
644
|
-
}
|
|
645
|
-
/** A typed function input or constructor param: a name plus its {@link ArkadeArgType}. */
|
|
646
|
-
interface InputDef {
|
|
647
|
-
name: string;
|
|
648
|
-
type: ArkadeArgType;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* A function input or constructor param declaration: either a typed descriptor
|
|
652
|
-
* `{ name, type }` (the argument is statically typed and its bound value is
|
|
653
|
-
* validated) or a bare name string (the argument falls back to the loose
|
|
654
|
-
* {@link ArkadeArgValue}).
|
|
655
|
-
*/
|
|
656
|
-
type InputRef = string | InputDef;
|
|
657
|
-
/** Reference to a signer key: a `"$param"` reference or literal x-only bytes. */
|
|
658
|
-
type SignerRef = string | Uint8Array;
|
|
659
|
-
/** A witness-stack item: a function-input name, a `"$param"`, a literal number/bigint (minimal script-num), or raw bytes. */
|
|
660
|
-
type WitnessRef = string | number | bigint | Uint8Array;
|
|
661
|
-
/** Bitcoin Script segment of a spending path — enforced on-chain. */
|
|
662
|
-
interface TapscriptSegment {
|
|
663
|
-
/** Required signers. The tweaked co-signer is appended automatically when the path has an `arkadeScript`. */
|
|
664
|
-
signers: SignerRef[];
|
|
665
|
-
/**
|
|
666
|
-
* Optional standard-opcode condition (e.g. a hashlock), encoded into a
|
|
667
|
-
* ConditionMultisig leaf — or ConditionCSVMultisig when combined with `csv`.
|
|
668
|
-
*/
|
|
669
|
-
asm?: AsmToken[];
|
|
670
|
-
/**
|
|
671
|
-
* Relative timelock (CSV). The value is a literal or a `"$param"` reference
|
|
672
|
-
* resolved against the constructor args (same convention as {@link SignerRef}).
|
|
673
|
-
* Combinable with `asm` (condition + CSV); mutually exclusive with `cltv`.
|
|
674
|
-
*/
|
|
675
|
-
csv?: {
|
|
676
|
-
type: "blocks" | "seconds";
|
|
677
|
-
value: bigint | string;
|
|
678
|
-
};
|
|
679
|
-
/**
|
|
680
|
-
* Absolute timelock (CLTV): a literal or a `"$param"` reference.
|
|
681
|
-
* Mutually exclusive with `csv`/`asm`.
|
|
682
|
-
*/
|
|
683
|
-
cltv?: bigint | string;
|
|
684
|
-
/** Items satisfying the condition (e.g. an HTLC preimage); set via the ConditionWitness PSBT field. */
|
|
685
|
-
witness?: WitnessRef[];
|
|
686
|
-
}
|
|
687
|
-
/** Arkade Script segment of a spending path — emulated, bound via the key tweak. */
|
|
688
|
-
interface ArkadeSegment {
|
|
689
|
-
/** Raw Arkade opcodes with `$param` placeholders. */
|
|
690
|
-
asm: AsmToken[];
|
|
691
|
-
/** The arkade-script witness stack (e.g. an output index). */
|
|
692
|
-
witness?: WitnessRef[];
|
|
693
|
-
}
|
|
694
|
-
/** One named spending path. */
|
|
695
|
-
interface ArkadeFunction {
|
|
696
|
-
/**
|
|
697
|
-
* The function ABI: an ordered list of call arguments. Each entry is a typed
|
|
698
|
-
* descriptor `{ name, type }` (which gives the matching `functions.<name>`
|
|
699
|
-
* argument a precise static type) or a bare name string (loose
|
|
700
|
-
* {@link ArkadeArgValue}). Absent for nullary paths (e.g. exit/cancel).
|
|
701
|
-
*/
|
|
702
|
-
inputs?: readonly InputRef[];
|
|
703
|
-
tapscript: TapscriptSegment;
|
|
704
|
-
/** Present for covenant paths; absent for pure-tapscript paths (cancel/exit). */
|
|
705
|
-
arkadeScript?: ArkadeSegment;
|
|
706
|
-
}
|
|
707
|
-
declare const SUPPORTED_PROGRAM_VERSION = 0;
|
|
708
|
-
/** An Arkade contract program (hand-written or compiler-emitted). */
|
|
709
|
-
interface Program {
|
|
710
|
-
version: number;
|
|
711
|
-
/**
|
|
712
|
-
* Optional program name — metadata only: round-tripped through the
|
|
713
|
-
* artifact JSON, never used in compilation or the taproot tree.
|
|
714
|
-
*/
|
|
715
|
-
name?: string;
|
|
716
|
-
/**
|
|
717
|
-
* Ordered constructor parameters. Bare name strings are documentation only
|
|
718
|
-
* (the legacy hand-written form); typed descriptors `{ name, type }` make
|
|
719
|
-
* the list authoritative — see {@link validateProgram}.
|
|
720
|
-
*/
|
|
721
|
-
params?: readonly InputRef[];
|
|
722
|
-
functions: Record<string, ArkadeFunction>;
|
|
723
|
-
}
|
|
724
|
-
/**
|
|
725
|
-
* Resolve an `asm` array to bytes: substitute `$param` placeholders from `bind`,
|
|
726
|
-
* pass everything else (opcode names, numbers, raw byte pushes) through to the
|
|
727
|
-
* Arkade script encoder. The SDK does not interpret opcodes — this is pure
|
|
728
|
-
* substitution + encoding. To embed a signer key (server, user, or any
|
|
729
|
-
* other), pass it as a `$param` in the constructor args; there is no
|
|
730
|
-
* `<SERVER_KEY>`/`<COSIGNER_KEY>` token.
|
|
731
|
-
*/
|
|
732
|
-
declare function resolveAsm(asm: AsmToken[], bind: Record<string, ArkadeParamValue>): Uint8Array;
|
|
733
|
-
/**
|
|
734
|
-
* Resolve one witness-stack item to bytes.
|
|
735
|
-
*
|
|
736
|
-
* - raw bytes pass through;
|
|
737
|
-
* - numbers/bigints encode as minimal script-nums;
|
|
738
|
-
* - `"$param"` strings resolve against the program's constructor args;
|
|
739
|
-
* - any other string is a function-input name and resolves against `callArgs`
|
|
740
|
-
* (throws when the input is unbound — e.g. outside a function call).
|
|
741
|
-
*/
|
|
742
|
-
declare function witnessRefToBytes(ref: WitnessRef, callArgs: Record<string, ArkadeArgValue>, programArgs: Record<string, ArkadeParamValue>): Uint8Array;
|
|
743
|
-
/**
|
|
744
|
-
* Validate a program's constructor-parameter declarations against the bound
|
|
745
|
-
* args. A `params` list of bare name strings is documentation only (the
|
|
746
|
-
* legacy hand-written form — no checks). When at least one entry is a typed
|
|
747
|
-
* descriptor (the compiler-emitted form), the list is authoritative: every
|
|
748
|
-
* declared param must be bound in `args`, every `"$name"` reference in the
|
|
749
|
-
* program must be declared, and typed entries validate their bound value
|
|
750
|
-
* (bytes-like types require a Uint8Array — 32 bytes for `pubkey`, 64 for
|
|
751
|
-
* `sig`; `int` requires a bigint/number).
|
|
752
|
-
*/
|
|
753
|
-
declare function validateProgram(program: Program, args: Record<string, ArkadeParamValue>): void;
|
|
754
|
-
/** The signer keys a program is compiled against. */
|
|
755
|
-
interface ProgramKeys {
|
|
756
|
-
/** The Arkade Service signer key (x-only) — used for address derivation and collaborative-path detection, not for `$param` resolution. */
|
|
757
|
-
serverKey: Uint8Array;
|
|
758
|
-
/** The wallet's x-only key — identifies which inputs the wallet signs. */
|
|
759
|
-
userKey?: Uint8Array;
|
|
760
|
-
/** The co-signer (emulator) key — required only for covenant (`arkadeScript`) functions. */
|
|
761
|
-
emulatorKey?: Uint8Array;
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* A single spending path, fully resolved at compilation: its definition, the
|
|
765
|
-
* committed leaf body, the per-path arkade-script bytes (covenant paths only),
|
|
766
|
-
* and the {@link TapLeafScript} (control block) for spending it.
|
|
767
|
-
*/
|
|
768
|
-
interface CompiledProgramFunction {
|
|
769
|
-
name: string;
|
|
770
|
-
def: ArkadeFunction;
|
|
771
|
-
/** The committed leaf script (body). */
|
|
772
|
-
leafScript: Uint8Array;
|
|
773
|
-
/** Resolved arkade-script bytes; undefined for pure-tapscript paths. */
|
|
774
|
-
arkadeScript?: Uint8Array;
|
|
775
|
-
/** Resolved signer keys (x-only), in the declared `signers` order. */
|
|
776
|
-
signerKeys: Uint8Array[];
|
|
777
|
-
/** Resolved once — the taproot leaf + control block for this path. */
|
|
778
|
-
tapLeafScript: TapLeafScript;
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* A {@link VtxoScript} compiled from an Arkade {@link Program}, its
|
|
782
|
-
* constructor args and the signer keys.
|
|
783
|
-
*
|
|
784
|
-
* This is the single compilation path shared by the high-level
|
|
785
|
-
* `ArkadeContract` client and the `"arkade"` contract handler: both produce
|
|
786
|
-
* byte-identical taproot trees for the same (program, args, keys), so a
|
|
787
|
-
* contract registered through the `src/contracts` pipeline re-derives the
|
|
788
|
-
* exact script it was created with.
|
|
789
|
-
*/
|
|
790
|
-
declare class ArkadeProgramScript extends VtxoScript {
|
|
791
|
-
readonly program: Program;
|
|
792
|
-
readonly args: Record<string, ArkadeParamValue>;
|
|
793
|
-
readonly keys: ProgramKeys;
|
|
794
|
-
/** Spending paths in declaration order. */
|
|
795
|
-
readonly compiled: CompiledProgramFunction[];
|
|
796
|
-
constructor(program: Program, args: Record<string, ArkadeParamValue>, keys: ProgramKeys);
|
|
797
|
-
/** The compiled spending path with the given function name, if any. */
|
|
798
|
-
functionByName(name: string): CompiledProgramFunction | undefined;
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Convert a compiler-style JSON artifact into a {@link Program}. Byte values are
|
|
802
|
-
* encoded as `0x`-prefixed hex strings in `asm`/`witness`/`signers`; opcode names,
|
|
803
|
-
* `$param` placeholders and numbers pass through unchanged.
|
|
804
|
-
*/
|
|
805
|
-
declare function parseArtifact(artifact: {
|
|
806
|
-
version?: number;
|
|
807
|
-
name?: string;
|
|
808
|
-
params?: readonly InputRef[];
|
|
809
|
-
functions: Record<string, any>;
|
|
810
|
-
}): Program;
|
|
811
|
-
/**
|
|
812
|
-
* Serialize a {@link Program} to compiler-artifact JSON — the inverse of
|
|
813
|
-
* {@link parseArtifact}: bytes become `0x`-hex strings; bigint tokens become
|
|
814
|
-
* plain numbers (or, above `Number.MAX_SAFE_INTEGER`, `0x`-hex of their
|
|
815
|
-
* minimal script-num bytes, which the script encoder pushes identically);
|
|
816
|
-
* literal timelock values serialize as decimal strings while `"$param"`
|
|
817
|
-
* timelock references are emitted as-is.
|
|
818
|
-
*/
|
|
819
|
-
declare function stringifyArtifact(program: Program): string;
|
|
820
|
-
/**
|
|
821
|
-
* Typed parameters of an `"arkade"` contract as persisted through the
|
|
822
|
-
* `src/contracts` pipeline. The program serializes as artifact JSON, args as
|
|
823
|
-
* a JSON map (`0x`-hex bytes, decimal-string bigints), keys as hex — so a
|
|
824
|
-
* stored contract row re-derives its script fully offline.
|
|
825
|
-
*/
|
|
826
|
-
interface ArkadeContractParams {
|
|
827
|
-
program: Program;
|
|
828
|
-
args: Record<string, ArkadeParamValue>;
|
|
829
|
-
serverKey: Uint8Array;
|
|
830
|
-
userKey?: Uint8Array;
|
|
831
|
-
emulatorKey?: Uint8Array;
|
|
832
|
-
}
|
|
833
|
-
/** Serialize {@link ArkadeContractParams} to the string map `Contract.params` requires. */
|
|
834
|
-
declare function serializeArkadeContractParams(typed: ArkadeContractParams): Record<string, string>;
|
|
835
|
-
/** Parse the string map persisted in `Contract.params` back into typed params. */
|
|
836
|
-
declare function deserializeArkadeContractParams(params: Record<string, string>): ArkadeContractParams;
|
|
837
|
-
|
|
838
|
-
/**
|
|
839
|
-
* Generic handler for artifact/program-based Arkade contracts.
|
|
840
|
-
*
|
|
841
|
-
* Persists the full {@link ArkadeContractParams} (program artifact JSON, args,
|
|
842
|
-
* signer keys) as string params, so any contract created via
|
|
843
|
-
* `arkade.contract(program, args)` participates in the standard contract
|
|
844
|
-
* pipeline: ContractManager persistence and validation, watcher events,
|
|
845
|
-
* repository-backed balances, and offline script re-derivation. Rebuild a
|
|
846
|
-
* callable contract from a stored row with `ArkadeContract.fromContract`.
|
|
847
|
-
*/
|
|
848
|
-
declare const ArkadeContractHandler: ContractHandler<ArkadeContractParams, ArkadeProgramScript> & TapscriptDeriving<ArkadeProgramScript>;
|
|
849
|
-
|
|
850
|
-
export { type ArkadeParamValue as A, BoardingContractHandler as B, type CompiledProgramFunction as C, DefaultContractHandler as D, type VHTLCV2ContractParams as E, contractHandlers as F, type InputRef as I, type Program as P, SUPPORTED_PROGRAM_VERSION as S, type TapscriptSegment as T, VHTLC as V, type WitnessRef as W, ArkadeProgramScript as a, type ProgramKeys as b, type ArkadeArgValue as c, type ArkadeFunction as d, type InputDef as e, type ArkadeValueType as f, type ArkadeArgType as g, type ArkadeContractParams as h, type ArkadeSegment as i, type AsmToken as j, type SignerRef as k, deserializeArkadeContractParams as l, stringifyArtifact as m, ArkadeContractHandler as n, type BoardingContractParams as o, parseArtifact as p, type DefaultContractParams as q, resolveAsm as r, serializeArkadeContractParams as s, DelegateContractHandler as t, type DelegateContractParams as u, validateProgram as v, witnessRefToBytes as w, VHTLCContractHandler as x, type VHTLCContractParams as y, VHTLCV2ContractHandler as z };
|