@dcasegr/amm-client 0.0.0-stage → 0.38.2

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 (121) hide show
  1. package/README.md +107 -2
  2. package/dist/client.d.ts +534 -0
  3. package/dist/client.js +1319 -0
  4. package/dist/errors.d.ts +17 -0
  5. package/dist/errors.js +75 -0
  6. package/dist/index.d.ts +51 -0
  7. package/dist/index.js +53 -0
  8. package/dist/lib/config.d.ts +42 -0
  9. package/dist/lib/config.js +64 -0
  10. package/dist/lib/keys.d.ts +42 -0
  11. package/dist/lib/keys.js +48 -0
  12. package/dist/lib/overlay.d.ts +190 -0
  13. package/dist/lib/overlay.js +302 -0
  14. package/dist/lib/skein.d.ts +82 -0
  15. package/dist/lib/skein.js +142 -0
  16. package/dist/lib/tokenId.d.ts +72 -0
  17. package/dist/lib/tokenId.js +121 -0
  18. package/dist/lp/amounts.d.ts +12 -0
  19. package/dist/lp/amounts.js +38 -0
  20. package/dist/lp/close.d.ts +90 -0
  21. package/dist/lp/close.js +140 -0
  22. package/dist/lp/images.d.ts +11 -0
  23. package/dist/lp/images.js +45 -0
  24. package/dist/lp/inventory.d.ts +68 -0
  25. package/dist/lp/inventory.js +84 -0
  26. package/dist/lp/poolDeploy.d.ts +220 -0
  27. package/dist/lp/poolDeploy.js +291 -0
  28. package/dist/lp/poolRows.d.ts +13 -0
  29. package/dist/lp/poolRows.js +19 -0
  30. package/dist/lp/positions.d.ts +81 -0
  31. package/dist/lp/positions.js +144 -0
  32. package/dist/lp/rebalance.d.ts +101 -0
  33. package/dist/lp/rebalance.js +168 -0
  34. package/dist/lp/wallet.d.ts +12 -0
  35. package/dist/lp/wallet.js +19 -0
  36. package/dist/market/activeSwap.d.ts +158 -0
  37. package/dist/market/activeSwap.js +320 -0
  38. package/dist/market/plan.d.ts +85 -0
  39. package/dist/market/plan.js +149 -0
  40. package/dist/market/prices.d.ts +13 -0
  41. package/dist/market/prices.js +14 -0
  42. package/dist/market/relay.d.ts +84 -0
  43. package/dist/market/relay.js +201 -0
  44. package/dist/market/swapAction.d.ts +306 -0
  45. package/dist/market/swapAction.js +508 -0
  46. package/dist/market/swapFlow.d.ts +58 -0
  47. package/dist/market/swapFlow.js +86 -0
  48. package/dist/market/view.d.ts +58 -0
  49. package/dist/market/view.js +63 -0
  50. package/dist/pool/artifact.d.ts +23 -0
  51. package/dist/pool/artifact.js +38 -0
  52. package/dist/pool/index.d.ts +8 -0
  53. package/dist/pool/index.js +8 -0
  54. package/dist/pool/oneColor.d.ts +19 -0
  55. package/dist/pool/oneColor.js +39 -0
  56. package/dist/pool/pool.artifact.json +5069 -0
  57. package/dist/pool/runar-ir-schema.d.ts +21 -0
  58. package/dist/pool/runar-ir-schema.js +18 -0
  59. package/dist/pool/template.d.ts +295 -0
  60. package/dist/pool/template.js +715 -0
  61. package/dist/vendor/runar/LICENSE +21 -0
  62. package/dist/vendor/runar/NOTICE +15 -0
  63. package/dist/vendor/runar/runar-ir-schema/src/abi-type-encoding.d.ts +42 -0
  64. package/dist/vendor/runar/runar-ir-schema/src/abi-type-encoding.js +53 -0
  65. package/dist/vendor/runar/runar-ir-schema/src/anf-ir.d.ts +221 -0
  66. package/dist/vendor/runar/runar-ir-schema/src/anf-ir.js +33 -0
  67. package/dist/vendor/runar/runar-ir-schema/src/artifact.d.ts +288 -0
  68. package/dist/vendor/runar/runar-ir-schema/src/artifact.js +8 -0
  69. package/dist/vendor/runar/runar-ir-schema/src/canonical-json.d.ts +43 -0
  70. package/dist/vendor/runar/runar-ir-schema/src/canonical-json.js +204 -0
  71. package/dist/vendor/runar/runar-ir-schema/src/input-limits.d.ts +89 -0
  72. package/dist/vendor/runar/runar-ir-schema/src/input-limits.js +100 -0
  73. package/dist/vendor/runar/runar-ir-schema/src/stack-ir.d.ts +118 -0
  74. package/dist/vendor/runar/runar-ir-schema/src/stack-ir.js +8 -0
  75. package/dist/vendor/runar/runar-ir-schema/src/state-layout.d.ts +56 -0
  76. package/dist/vendor/runar/runar-ir-schema/src/state-layout.js +145 -0
  77. package/dist/vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.d.ts +18 -0
  78. package/dist/vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.js +25 -0
  79. package/dist/vendor/runar/runar-sdk/src/anf-interpreter.d.ts +160 -0
  80. package/dist/vendor/runar/runar-sdk/src/anf-interpreter.js +1149 -0
  81. package/dist/vendor/runar/runar-sdk/src/calling.d.ts +98 -0
  82. package/dist/vendor/runar/runar-sdk/src/calling.js +209 -0
  83. package/dist/vendor/runar/runar-sdk/src/contract.d.ts +443 -0
  84. package/dist/vendor/runar/runar-sdk/src/contract.js +2516 -0
  85. package/dist/vendor/runar/runar-sdk/src/deployment.d.ts +36 -0
  86. package/dist/vendor/runar/runar-sdk/src/deployment.js +119 -0
  87. package/dist/vendor/runar/runar-sdk/src/errors.d.ts +46 -0
  88. package/dist/vendor/runar/runar-sdk/src/errors.js +59 -0
  89. package/dist/vendor/runar/runar-sdk/src/oppushtx.d.ts +23 -0
  90. package/dist/vendor/runar/runar-sdk/src/oppushtx.js +95 -0
  91. package/dist/vendor/runar/runar-sdk/src/ordinals/envelope.d.ts +31 -0
  92. package/dist/vendor/runar/runar-sdk/src/ordinals/envelope.js +272 -0
  93. package/dist/vendor/runar/runar-sdk/src/ordinals/types.d.ts +21 -0
  94. package/dist/vendor/runar/runar-sdk/src/ordinals/types.js +4 -0
  95. package/dist/vendor/runar/runar-sdk/src/providers/provider.d.ts +65 -0
  96. package/dist/vendor/runar/runar-sdk/src/providers/provider.js +59 -0
  97. package/dist/vendor/runar/runar-sdk/src/providers/wallet-provider.d.ts +94 -0
  98. package/dist/vendor/runar/runar-sdk/src/providers/wallet-provider.js +297 -0
  99. package/dist/vendor/runar/runar-sdk/src/script-utils.d.ts +54 -0
  100. package/dist/vendor/runar/runar-sdk/src/script-utils.js +252 -0
  101. package/dist/vendor/runar/runar-sdk/src/signers/signer.d.ts +17 -0
  102. package/dist/vendor/runar/runar-sdk/src/signers/signer.js +4 -0
  103. package/dist/vendor/runar/runar-sdk/src/spend-safety.d.ts +31 -0
  104. package/dist/vendor/runar/runar-sdk/src/spend-safety.js +35 -0
  105. package/dist/vendor/runar/runar-sdk/src/state.d.ts +54 -0
  106. package/dist/vendor/runar/runar-sdk/src/state.js +584 -0
  107. package/dist/vendor/runar/runar-sdk/src/types.d.ts +227 -0
  108. package/dist/vendor/runar/runar-sdk/src/types.js +4 -0
  109. package/dist/vendor/runar/runar-sdk/src/unsound-primitives.d.ts +30 -0
  110. package/dist/vendor/runar/runar-sdk/src/unsound-primitives.js +42 -0
  111. package/dist/vendor/runar/runar-sdk.d.ts +9 -0
  112. package/dist/vendor/runar/runar-sdk.js +8 -0
  113. package/dist/wallet/action.d.ts +28 -0
  114. package/dist/wallet/action.js +42 -0
  115. package/dist/wallet/brc29.d.ts +83 -0
  116. package/dist/wallet/brc29.js +80 -0
  117. package/dist/wallet/color.d.ts +110 -0
  118. package/dist/wallet/color.js +134 -0
  119. package/dist/wallet/swapPayouts.d.ts +35 -0
  120. package/dist/wallet/swapPayouts.js +146 -0
  121. package/package.json +39 -4
@@ -0,0 +1,443 @@
1
+ import type { RunarArtifact } from '../../../../pool/runar-ir-schema.js';
2
+ import type { Provider } from './providers/provider.js';
3
+ import type { Signer } from './signers/signer.js';
4
+ import type { TransactionData, UTXO, DeployOptions, CallOptions, PreparedCall } from './types.js';
5
+ import type { Inscription } from './ordinals/types.js';
6
+ import { Transaction as BsvTransaction } from '@bsv/sdk';
7
+ /**
8
+ * Deep-review finding C8: opt-out for `finalizeCall`'s pre-broadcast local
9
+ * dry-run, plus the internal field that carries it from `prepareCall` to
10
+ * `finalizeCall`.
11
+ *
12
+ * This augments (does not redeclare) `CallOptions`/`PreparedCall` from
13
+ * `./types.js` — kept here rather than in types.ts so this change stays
14
+ * scoped to contract.ts, its only reader/writer, while that file is being
15
+ * edited concurrently by other work in this tree.
16
+ */
17
+ declare module './types.js' {
18
+ interface CallOptions {
19
+ /**
20
+ * Run a local pre-broadcast Spend dry-run of the primary contract input
21
+ * before `finalizeCall` broadcasts (deep-review C8). The dry-run replays
22
+ * the fully-signed input through @bsv/sdk's production `Spend`
23
+ * interpreter (real BIP-143, real OP_CHECKSIG) and throws instead of
24
+ * broadcasting when the input would be rejected on-chain.
25
+ *
26
+ * **Default: OFF (opt-in).** C8 asked for this to default ON, and that is
27
+ * still the goal — but it is not yet safe to. The local harness currently
28
+ * produces at least one FALSE REJECTION: it rejects `Auction.bid()`
29
+ * (`codeseparator-signing.test.ts`, a real contract signed by a real
30
+ * `LocalSigner`) with "OP_CHECKSIGVERIFY requires that a valid signature
31
+ * is provided", while the independent real-crypto oracle
32
+ * (`conformance/witnesses/real-crypto/auction.json`, which drives the same
33
+ * method deploy->call->Spend through `runStatefulSpend`) ACCEPTS it — so
34
+ * the transaction is valid and the dry-run's tx modelling is wrong, not
35
+ * the signature. Nine other pre-existing tests fail the same way on
36
+ * synthetic stub artifacts whose scripts do not consume their pushed args
37
+ * (clean-stack violations).
38
+ *
39
+ * For a FAIL-CLOSED pre-broadcast gate a false rejection is worse than the
40
+ * hole it closes: it would block legitimate calls and strand funds. So the
41
+ * capability ships opt-in until its fidelity is proven against the
42
+ * real-crypto oracle across the fixture corpus. Flip the default to ON
43
+ * once `dryRunContractInput` agrees with `runStatefulSpend` on every
44
+ * `witnesses/real-crypto/*.json` accept case.
45
+ *
46
+ * Set `true` to opt in. Do not enable it for setups the local harness
47
+ * cannot model — e.g. a covenant whose correctness depends on OTHER
48
+ * inputs' final scripts that aren't known yet at `finalizeCall` time
49
+ * (multi-party assembly finished by a later step), or a
50
+ * deliberately-invalid tx built for negative testing.
51
+ */
52
+ dryRun?: boolean;
53
+ }
54
+ interface PreparedCall {
55
+ /** @internal C8 — carries CallOptions.dryRun into finalizeCall. */
56
+ _dryRun: boolean;
57
+ }
58
+ }
59
+ /**
60
+ * Producer-side marker (issue #106) for the deliberately-empty branch of an
61
+ * OR-CHECKSIG method — `checkSig(sigA, pkA) || checkSig(sigB, pkB)`, where
62
+ * `||` short-circuits (NEW-014), so the second `OP_CHECKSIG` runs only when the
63
+ * first branch FAILS — and when it does, the first ran with a non-empty
64
+ * signature. Only the
65
+ * matching branch supplies a real signature; the failing branch MUST push an
66
+ * empty signature (OP_0) or BIP146 NULLFAIL rejects the whole spend.
67
+ *
68
+ * Pass `EMPTY_SIG` as the call arg for the non-matching `Sig` slot: the SDK
69
+ * pushes OP_0 for it and never signs it, distinct from `null` (auto-sign) and
70
+ * an explicit hex-bytes value. Coexists with `null` at the same call —
71
+ * `call('execute', [null, EMPTY_SIG])` signs only slot 0.
72
+ *
73
+ * Uses the global symbol registry so identity holds across duplicate module
74
+ * instances (bundlers).
75
+ */
76
+ export declare const EMPTY_SIG: unique symbol;
77
+ /** Type guard: is this call arg the {@link EMPTY_SIG} marker (issue #106)? */
78
+ export declare function isEmptySig(value: unknown): value is typeof EMPTY_SIG;
79
+ /**
80
+ * True when the locking script looks like OR-CHECKSIG (OP_BOOLOR + OP_CHECKSIG)
81
+ * rather than multi-sig (OP_CHECKMULTISIG). Used to scope the multi-null-Sig
82
+ * soft warning so genuine checkMultiSig unlocks are not spammed.
83
+ *
84
+ * Exported for unit tests.
85
+ */
86
+ export declare function isLikelyOrCheckSigMethod(artifact: {
87
+ asm?: string;
88
+ script?: string;
89
+ scriptHex?: string;
90
+ }): boolean;
91
+ /**
92
+ * Walk a hex-encoded script and return the byte offsets of every
93
+ * OP_CODESEPARATOR (0xab) that sits at a real opcode boundary (i.e. not inside
94
+ * push-data). Correctly skips all BSV push opcodes (0x01..0x4b,
95
+ * OP_PUSHDATA1/2/4).
96
+ *
97
+ * Used by getSubscriptForSigning to recover the true on-chain byte offsets when
98
+ * the in-memory constructor args don't reflect what was actually baked into the
99
+ * locking script (e.g. after fromTxid populates dummy placeholders).
100
+ */
101
+ export declare function findCodesepOffsets(scriptHex: string): number[];
102
+ /**
103
+ * Runtime wrapper for a compiled Runar contract.
104
+ *
105
+ * Handles deployment, method invocation, state tracking, and script
106
+ * construction. Works with any Provider and Signer implementation.
107
+ *
108
+ * ```ts
109
+ * const artifact = JSON.parse(fs.readFileSync('./artifacts/Counter.json', 'utf8'));
110
+ * const contract = new RunarContract(artifact, [0n]); // constructor args
111
+ * const { txid } = await contract.deploy(provider, signer, { satoshis: 10000 });
112
+ * ```
113
+ */
114
+ export declare class RunarContract {
115
+ readonly artifact: RunarArtifact;
116
+ /**
117
+ * Constructor arguments for the contract, typed as `unknown[]` because
118
+ * they can be any of the Runar primitive types: `bigint`, `boolean`,
119
+ * `ByteString` (hex string), `PubKey` (hex string), etc. TypeScript
120
+ * generics are not practical here since the types depend on the specific
121
+ * contract being used and are only known at runtime from the ABI.
122
+ */
123
+ private readonly constructorArgs;
124
+ private _state;
125
+ private _codeScript;
126
+ private _inscription;
127
+ private currentUtxo;
128
+ /** Returns the current UTXO tracked by this contract, if any. */
129
+ getUtxo(): UTXO | null;
130
+ private _provider;
131
+ private _signer;
132
+ /**
133
+ * Witness values for intent-covenant intrinsic auto-injected params.
134
+ * `_prevOutScript_<i>` values are stored per-input-index in `_prevOutScripts`;
135
+ * `_serialisedOutputs` is stored in `_serialisedOutputs`. Both are hex strings
136
+ * (normalized in the setters). Read by the call-builder when assembling the
137
+ * unlocking script for methods that use `extractPrevOutputScript` /
138
+ * `requireOutputP2PKH`.
139
+ */
140
+ private _prevOutScripts;
141
+ private _serialisedOutputs;
142
+ constructor(artifact: RunarArtifact, constructorArgs: unknown[]);
143
+ /**
144
+ * Store a provider and signer on this contract so they don't need to be
145
+ * passed to every `deploy()` and `call()` invocation.
146
+ */
147
+ connect(provider: Provider, signer: Signer): void;
148
+ /**
149
+ * Attach a 1sat ordinals inscription to this contract. The inscription
150
+ * envelope is injected into the locking script between the compiled code
151
+ * and the state section (if any). Once deployed, the inscription is
152
+ * immutable — it persists identically across all state transitions.
153
+ *
154
+ * ```ts
155
+ * contract.withInscription({ contentType: 'image/png', data: pngHex });
156
+ * ```
157
+ *
158
+ * N-043 — THROWS when the envelope would break the contract's own
159
+ * `SIZE(_codePart)` pin. A stateful contract with a variable-length state
160
+ * section carries an equality pin on the deployed code-part length, and the
161
+ * envelope lands INSIDE the code part (see `getCodePartHex`). The compiler
162
+ * bakes that number before any inscription exists, so the pinned length and
163
+ * the real one differ by the envelope's size and every honest spend aborts
164
+ * at OP_VERIFY — with the funds already committed. Refusing here turns a
165
+ * permanent, silent lock into a loud error before a single satoshi moves.
166
+ */
167
+ withInscription(inscription: Inscription): this;
168
+ /**
169
+ * Verify that every equality `verify_code_part_len` pin the compiler baked
170
+ * into this artifact still describes the code part this contract produces.
171
+ *
172
+ * The check is the invariant itself, not a restatement of the compiler's
173
+ * derivation: it decodes the pinned number straight out of the emitted
174
+ * template and compares it to `getCodePartHex()`. So it permits every
175
+ * combination that actually works — a stateless contract or a fixed-size
176
+ * state layout carries no pin at all, and a lower-bound pin is satisfied by
177
+ * a longer code part — and rejects only the shape that would lock funds.
178
+ */
179
+ private assertCodePartLengthPinHonoured;
180
+ /** Returns the current inscription, if any. */
181
+ get inscription(): Inscription | null;
182
+ /**
183
+ * Resolve provider/signer: explicit args win, then connected, then error.
184
+ */
185
+ private resolveProviderSigner;
186
+ /**
187
+ * Deploy the contract by creating a UTXO with the locking script.
188
+ *
189
+ * Provider and signer can be passed explicitly or omitted to use
190
+ * the ones stored via `connect()`.
191
+ */
192
+ deploy(options: DeployOptions): Promise<{
193
+ txid: string;
194
+ tx: TransactionData;
195
+ }>;
196
+ deploy(provider: Provider, signer: Signer, options: DeployOptions): Promise<{
197
+ txid: string;
198
+ tx: TransactionData;
199
+ }>;
200
+ /**
201
+ * Deploy the contract using a BRC-100 wallet. The wallet owns the coins
202
+ * and creates the transaction itself via `createAction()`.
203
+ *
204
+ * Requires the contract to be connected to a `WalletProvider` (via `connect()`).
205
+ *
206
+ * @param options.satoshis - Satoshis to lock in the contract output (default: 1).
207
+ * @param options.description - Description for the wallet action.
208
+ */
209
+ deployWithWallet(options?: {
210
+ satoshis?: number;
211
+ description?: string;
212
+ /**
213
+ * R-062: builtins the caller accepts despite the compiler not claiming
214
+ * they are sound. Required — naming each one — when the artifact declares
215
+ * `unsoundPrimitives`; ignored otherwise. Same mechanism and same error as
216
+ * `DeployOptions.acknowledgeUnsound` on the ordinary `deploy()` path.
217
+ */
218
+ acknowledgeUnsound?: readonly string[];
219
+ }): Promise<{
220
+ txid: string;
221
+ outputIndex: number;
222
+ }>;
223
+ /**
224
+ * Call a public method on the contract (spend the UTXO).
225
+ *
226
+ * For stateful contracts, a new UTXO is created with the updated state.
227
+ * Provider and signer can be passed explicitly or omitted to use
228
+ * the ones stored via `connect()`.
229
+ */
230
+ call(methodName: string, args: unknown[], options?: CallOptions): Promise<{
231
+ txid: string;
232
+ tx: TransactionData;
233
+ }>;
234
+ call(methodName: string, args: unknown[], provider: Provider, signer: Signer, options?: CallOptions): Promise<{
235
+ txid: string;
236
+ tx: TransactionData;
237
+ }>;
238
+ /**
239
+ * Build the transaction for a method call without signing the primary
240
+ * contract input's Sig params. Returns a `PreparedCall` containing the
241
+ * BIP-143 sighash that external signers need, plus opaque internals for
242
+ * `finalizeCall()`.
243
+ *
244
+ * P2PKH funding inputs and additional contract inputs ARE signed with the
245
+ * connected signer. Only the primary contract input's Sig params are left
246
+ * as 72-byte placeholders.
247
+ */
248
+ prepareCall(methodName: string, args: unknown[], options?: CallOptions): Promise<PreparedCall>;
249
+ /**
250
+ * Complete a prepared call by injecting external signatures and broadcasting.
251
+ *
252
+ * @param prepared — The `PreparedCall` returned by `prepareCall()`.
253
+ * @param signatures — Map from arg index to DER signature hex (with sighash byte).
254
+ * Each key must be one of `prepared.sigIndices`.
255
+ */
256
+ finalizeCall(prepared: PreparedCall, signatures: Record<number, string>): Promise<{
257
+ txid: string;
258
+ tx: TransactionData;
259
+ }>;
260
+ /** Get the current contract state (for stateful contracts). */
261
+ get state(): Record<string, unknown>;
262
+ /** Update state values directly (for stateful contracts). */
263
+ setState(newState: Record<string, unknown>): void;
264
+ /**
265
+ * Supply the prev-output locking-script witness for input `inputIndex`.
266
+ * Required for methods that call `extractPrevOutputScript(inputIndex)`,
267
+ * which the compiler lowers into an auto-injected
268
+ * `_prevOutScript_<inputIndex>` ABI param.
269
+ *
270
+ * @param inputIndex the literal input index passed to extractPrevOutputScript
271
+ * @param bytes hex string (with or without 0x prefix) or raw bytes
272
+ */
273
+ setPrevOutScript(inputIndex: number, bytes: string | Uint8Array): void;
274
+ /**
275
+ * Supply the serialised-outputs witness for the current call.
276
+ * Required for methods that call `requireOutputP2PKH(...)`, which the
277
+ * compiler lowers into an auto-injected `_serialisedOutputs` ABI param.
278
+ *
279
+ * @param bytes hex string (with or without 0x prefix) or raw bytes
280
+ */
281
+ setSerialisedOutputs(bytes: string | Uint8Array): void;
282
+ /**
283
+ * Build the trailing witness-hex for the auto-injected intent-intrinsic
284
+ * params of a method, in ABI order (`_prevOutScript_*` first, then
285
+ * `_serialisedOutputs`). Each value is pushed via PUSHDATA so that the
286
+ * on-chain method body's `load_param` lifts the exact bytes the caller set.
287
+ *
288
+ * Throws {@link WitnessValueMissingError} for any auto-injected param the
289
+ * caller hasn't supplied via setPrevOutScript / setSerialisedOutputs.
290
+ */
291
+ private buildIntentWitnessHex;
292
+ /**
293
+ * Get the full locking script hex for the contract.
294
+ *
295
+ * For stateful contracts this includes the code followed by OP_RETURN and
296
+ * the serialized state fields.
297
+ */
298
+ getLockingScript(): string;
299
+ /**
300
+ * Build the code portion of the locking script from the artifact and
301
+ * constructor args. This is the script without any state suffix.
302
+ */
303
+ private buildCodeScript;
304
+ /**
305
+ * Build the unlocking script for a method call.
306
+ *
307
+ * The unlocking script pushes the method arguments onto the stack in
308
+ * order, followed by a method selector (the method index as a Script
309
+ * number) if the contract has multiple public methods.
310
+ */
311
+ buildUnlockingScript(methodName: string, args: unknown[]): string;
312
+ /**
313
+ * Get the code script hex (locking script without state) for use as _codePart.
314
+ * Returns the code portion that the on-chain contract uses for output reconstruction.
315
+ * Includes the inscription envelope if one is attached — this is required for
316
+ * stateful contracts where the on-chain hashOutputs verification includes
317
+ * the envelope as part of the codePart.
318
+ *
319
+ * Public low-level assembly surface: needed for cross-artifact transaction
320
+ * assembly (see `assembleMultiContractCall`), where a spending tx mixes
321
+ * covenant inputs from DIFFERENT artifacts and each input's `_codePart` /
322
+ * continuation script must be built outside `call()`.
323
+ */
324
+ getCodePartHex(): string;
325
+ /**
326
+ * Adjust a code separator byte offset from the base (template) script to
327
+ * the fully-substituted script. Both constructor arg slots and codeSepIndex
328
+ * slots replace OP_0 (1 byte) with encoded push data, shifting subsequent
329
+ * byte offsets.
330
+ */
331
+ private adjustCodeSepOffset;
332
+ /**
333
+ * Resolve the adjusted codeSep index values for all codeSepIndex slots,
334
+ * processing them in ascending template byte-offset order so that each
335
+ * slot's value correctly accounts for earlier slots' expansions.
336
+ */
337
+ private _resolvedCodeSepSlotValues;
338
+ /**
339
+ * Get the subscript trimmed at the OP_CODESEPARATOR for a given method.
340
+ * Used for BIP-143 sighash computation for the user CHECKSIG whenever the
341
+ * script contains an OP_CODESEPARATOR before it (per BIP-143 / BSV consensus,
342
+ * for stateful AND terminal methods alike). Returns the full script unchanged
343
+ * when no OP_CODESEPARATOR is present.
344
+ *
345
+ * When `_codeScript` is set (the contract is loaded from chain, or the deploy
346
+ * script has already been built from real constructor args), walk the actual
347
+ * script and trim at the true on-chain byte position. This is required
348
+ * because `fromTxid` populates constructorArgs with dummy placeholders — the
349
+ * real arg bytes are already baked into the on-chain locking script — so
350
+ * `adjustCodeSepOffset` computes a shift of zero and returns the wrong offset
351
+ * whenever the OP_CODESEPARATOR sits after constructor slots that expand at
352
+ * deploy time. The symptom of using the wrong offset is NULLFAIL at
353
+ * OP_CHECKSIG for terminal methods.
354
+ *
355
+ * Public low-level assembly surface: multi-contract tx assembly must sign
356
+ * each covenant input's user `Sig` over ITS artifact's codesep-trimmed
357
+ * subscript, which `call()` only does for its own single primary input.
358
+ */
359
+ getSubscriptForSigning(fullScript: string, methodIndex?: number): string;
360
+ /**
361
+ * Wrap computeOpPushTx to automatically pass the correct codeSeparatorIndex.
362
+ * For multi-method contracts, each method has its own separator at a different
363
+ * byte offset. Uses codeSeparatorIndices[methodIndex] if available, otherwise
364
+ * falls back to the single codeSeparatorIndex.
365
+ *
366
+ * When `_codeScript` is set (chain-loaded, or a deploy script already built
367
+ * from real constructor args), byte-walk the actual script for the true
368
+ * on-chain OP_CODESEPARATOR offset — mirroring `getSubscriptForSigning`.
369
+ * `adjustCodeSepOffset` derives the shift from the in-memory
370
+ * `constructorArgs`, which are placeholders on the restore path (issue #132);
371
+ * the byte-walk is independent of those args. The template `adjustCodeSepOffset`
372
+ * path remains only for template-built (deploy-time) contracts.
373
+ *
374
+ * Public low-level assembly surface: each covenant input of a
375
+ * multi-contract tx needs its own OP_PUSH_TX signature + BIP-143 preimage
376
+ * computed against ITS artifact's code separator layout.
377
+ */
378
+ computeOpPushTxWithCodeSep(tx: BsvTransaction, inputIndex: number, subscript: string, satoshis: number, methodIndex?: number): {
379
+ sigHex: string;
380
+ preimageHex: string;
381
+ };
382
+ /**
383
+ * Build the prefix for an unlocking script: optionally _codePart.
384
+ * needsCodePart should be true only when the method constructs continuation outputs
385
+ * (non-terminal stateful calls). Terminal and stateless methods don't use _codePart.
386
+ *
387
+ * Public low-level assembly surface. BUG-100: the OP_PUSH_TX signature is
388
+ * derived on-chain from the preimage (see codegen emitCheckPreimageBinding),
389
+ * so NO signature is pushed here — the stateful unlock layout is
390
+ * `[_codePart?] args... [_changePKH _changeAmount] [_newAmount] txPreimage
391
+ * [selector]` (multi-contract assembly rebuilds it per input). `opSig` is
392
+ * accepted for call-site compatibility but ignored.
393
+ */
394
+ buildStatefulPrefix(_opSig: string, needsCodePart?: boolean): string;
395
+ /**
396
+ * Reconnect to an existing deployed contract from a known UTXO.
397
+ *
398
+ * This is the synchronous equivalent of `fromTxId()` — use it when the
399
+ * UTXO data is already available (e.g. from an overlay service or cache)
400
+ * without needing a Provider to fetch the transaction.
401
+ *
402
+ * @param artifact - The compiled artifact describing the contract.
403
+ * @param utxo - The UTXO containing the contract output.
404
+ * @returns A RunarContract instance connected to the existing UTXO.
405
+ */
406
+ static fromUtxo(artifact: RunarArtifact, utxo: {
407
+ txid: string;
408
+ outputIndex: number;
409
+ satoshis: number;
410
+ script: string;
411
+ }): RunarContract;
412
+ /**
413
+ * Reconnect to an existing deployed contract from its deployment transaction.
414
+ *
415
+ * @param artifact - The compiled artifact describing the contract.
416
+ * @param txid - The transaction ID containing the contract UTXO.
417
+ * @param outputIndex - The output index of the contract UTXO.
418
+ * @param provider - Blockchain provider.
419
+ * @returns A RunarContract instance connected to the existing UTXO.
420
+ */
421
+ static fromTxId(artifact: RunarArtifact, txid: string, outputIndex: number, provider: Provider): Promise<RunarContract>;
422
+ private findMethod;
423
+ }
424
+ /**
425
+ * Encode an argument value as a Bitcoin Script push data element.
426
+ *
427
+ * Exported as part of the low-level assembly surface: downstream tooling
428
+ * (runar-testing's mock-preimage builders) and multi-contract tx assembly (and
429
+ * any external unlocking-script construction) must encode arguments
430
+ * byte-identically to `buildUnlockingScript` — share this, don't copy it.
431
+ */
432
+ export declare function encodeArg(value: unknown): string;
433
+ /**
434
+ * Encode a bigint as a minimally-encoded Bitcoin Script number push
435
+ * (OP_0 / OP_1..OP_16 / OP_1NEGATE / sign-magnitude LE push data).
436
+ * Exported as part of the low-level assembly surface.
437
+ */
438
+ export declare function encodeScriptNumber(n: bigint): string;
439
+ /**
440
+ * Encode raw hex bytes as a Bitcoin Script push (direct push / PUSHDATA1/2/4).
441
+ * Exported as part of the low-level assembly surface.
442
+ */
443
+ export declare function encodePushData(dataHex: string): string;