@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.
- package/README.md +107 -2
- package/dist/client.d.ts +534 -0
- package/dist/client.js +1319 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.js +75 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +53 -0
- package/dist/lib/config.d.ts +42 -0
- package/dist/lib/config.js +64 -0
- package/dist/lib/keys.d.ts +42 -0
- package/dist/lib/keys.js +48 -0
- package/dist/lib/overlay.d.ts +190 -0
- package/dist/lib/overlay.js +302 -0
- package/dist/lib/skein.d.ts +82 -0
- package/dist/lib/skein.js +142 -0
- package/dist/lib/tokenId.d.ts +72 -0
- package/dist/lib/tokenId.js +121 -0
- package/dist/lp/amounts.d.ts +12 -0
- package/dist/lp/amounts.js +38 -0
- package/dist/lp/close.d.ts +90 -0
- package/dist/lp/close.js +140 -0
- package/dist/lp/images.d.ts +11 -0
- package/dist/lp/images.js +45 -0
- package/dist/lp/inventory.d.ts +68 -0
- package/dist/lp/inventory.js +84 -0
- package/dist/lp/poolDeploy.d.ts +220 -0
- package/dist/lp/poolDeploy.js +291 -0
- package/dist/lp/poolRows.d.ts +13 -0
- package/dist/lp/poolRows.js +19 -0
- package/dist/lp/positions.d.ts +81 -0
- package/dist/lp/positions.js +144 -0
- package/dist/lp/rebalance.d.ts +101 -0
- package/dist/lp/rebalance.js +168 -0
- package/dist/lp/wallet.d.ts +12 -0
- package/dist/lp/wallet.js +19 -0
- package/dist/market/activeSwap.d.ts +158 -0
- package/dist/market/activeSwap.js +320 -0
- package/dist/market/plan.d.ts +85 -0
- package/dist/market/plan.js +149 -0
- package/dist/market/prices.d.ts +13 -0
- package/dist/market/prices.js +14 -0
- package/dist/market/relay.d.ts +84 -0
- package/dist/market/relay.js +201 -0
- package/dist/market/swapAction.d.ts +306 -0
- package/dist/market/swapAction.js +508 -0
- package/dist/market/swapFlow.d.ts +58 -0
- package/dist/market/swapFlow.js +86 -0
- package/dist/market/view.d.ts +58 -0
- package/dist/market/view.js +63 -0
- package/dist/pool/artifact.d.ts +23 -0
- package/dist/pool/artifact.js +38 -0
- package/dist/pool/index.d.ts +8 -0
- package/dist/pool/index.js +8 -0
- package/dist/pool/oneColor.d.ts +19 -0
- package/dist/pool/oneColor.js +39 -0
- package/dist/pool/pool.artifact.json +5069 -0
- package/dist/pool/runar-ir-schema.d.ts +21 -0
- package/dist/pool/runar-ir-schema.js +18 -0
- package/dist/pool/template.d.ts +295 -0
- package/dist/pool/template.js +715 -0
- package/dist/vendor/runar/LICENSE +21 -0
- package/dist/vendor/runar/NOTICE +15 -0
- package/dist/vendor/runar/runar-ir-schema/src/abi-type-encoding.d.ts +42 -0
- package/dist/vendor/runar/runar-ir-schema/src/abi-type-encoding.js +53 -0
- package/dist/vendor/runar/runar-ir-schema/src/anf-ir.d.ts +221 -0
- package/dist/vendor/runar/runar-ir-schema/src/anf-ir.js +33 -0
- package/dist/vendor/runar/runar-ir-schema/src/artifact.d.ts +288 -0
- package/dist/vendor/runar/runar-ir-schema/src/artifact.js +8 -0
- package/dist/vendor/runar/runar-ir-schema/src/canonical-json.d.ts +43 -0
- package/dist/vendor/runar/runar-ir-schema/src/canonical-json.js +204 -0
- package/dist/vendor/runar/runar-ir-schema/src/input-limits.d.ts +89 -0
- package/dist/vendor/runar/runar-ir-schema/src/input-limits.js +100 -0
- package/dist/vendor/runar/runar-ir-schema/src/stack-ir.d.ts +118 -0
- package/dist/vendor/runar/runar-ir-schema/src/stack-ir.js +8 -0
- package/dist/vendor/runar/runar-ir-schema/src/state-layout.d.ts +56 -0
- package/dist/vendor/runar/runar-ir-schema/src/state-layout.js +145 -0
- package/dist/vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.d.ts +18 -0
- package/dist/vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.js +25 -0
- package/dist/vendor/runar/runar-sdk/src/anf-interpreter.d.ts +160 -0
- package/dist/vendor/runar/runar-sdk/src/anf-interpreter.js +1149 -0
- package/dist/vendor/runar/runar-sdk/src/calling.d.ts +98 -0
- package/dist/vendor/runar/runar-sdk/src/calling.js +209 -0
- package/dist/vendor/runar/runar-sdk/src/contract.d.ts +443 -0
- package/dist/vendor/runar/runar-sdk/src/contract.js +2516 -0
- package/dist/vendor/runar/runar-sdk/src/deployment.d.ts +36 -0
- package/dist/vendor/runar/runar-sdk/src/deployment.js +119 -0
- package/dist/vendor/runar/runar-sdk/src/errors.d.ts +46 -0
- package/dist/vendor/runar/runar-sdk/src/errors.js +59 -0
- package/dist/vendor/runar/runar-sdk/src/oppushtx.d.ts +23 -0
- package/dist/vendor/runar/runar-sdk/src/oppushtx.js +95 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/envelope.d.ts +31 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/envelope.js +272 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/types.d.ts +21 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/types.js +4 -0
- package/dist/vendor/runar/runar-sdk/src/providers/provider.d.ts +65 -0
- package/dist/vendor/runar/runar-sdk/src/providers/provider.js +59 -0
- package/dist/vendor/runar/runar-sdk/src/providers/wallet-provider.d.ts +94 -0
- package/dist/vendor/runar/runar-sdk/src/providers/wallet-provider.js +297 -0
- package/dist/vendor/runar/runar-sdk/src/script-utils.d.ts +54 -0
- package/dist/vendor/runar/runar-sdk/src/script-utils.js +252 -0
- package/dist/vendor/runar/runar-sdk/src/signers/signer.d.ts +17 -0
- package/dist/vendor/runar/runar-sdk/src/signers/signer.js +4 -0
- package/dist/vendor/runar/runar-sdk/src/spend-safety.d.ts +31 -0
- package/dist/vendor/runar/runar-sdk/src/spend-safety.js +35 -0
- package/dist/vendor/runar/runar-sdk/src/state.d.ts +54 -0
- package/dist/vendor/runar/runar-sdk/src/state.js +584 -0
- package/dist/vendor/runar/runar-sdk/src/types.d.ts +227 -0
- package/dist/vendor/runar/runar-sdk/src/types.js +4 -0
- package/dist/vendor/runar/runar-sdk/src/unsound-primitives.d.ts +30 -0
- package/dist/vendor/runar/runar-sdk/src/unsound-primitives.js +42 -0
- package/dist/vendor/runar/runar-sdk.d.ts +9 -0
- package/dist/vendor/runar/runar-sdk.js +8 -0
- package/dist/wallet/action.d.ts +28 -0
- package/dist/wallet/action.js +42 -0
- package/dist/wallet/brc29.d.ts +83 -0
- package/dist/wallet/brc29.js +80 -0
- package/dist/wallet/color.d.ts +110 -0
- package/dist/wallet/color.js +134 -0
- package/dist/wallet/swapPayouts.d.ts +35 -0
- package/dist/wallet/swapPayouts.js +146 -0
- package/package.json +39 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State-tail byte layout — the single source of truth for WHERE each
|
|
3
|
+
* serialized state field lives in a stateful contract's locking script.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the SDK's `serializeState` wire format exactly:
|
|
6
|
+
*
|
|
7
|
+
* <code part> OP_RETURN <field0> <field1> ... <fieldN>
|
|
8
|
+
*
|
|
9
|
+
* - bigint / int : 8 raw bytes, little-endian sign-magnitude (OP_NUM2BIN 8)
|
|
10
|
+
* - bool : 1 raw byte (0x00 / 0x01)
|
|
11
|
+
* - PubKey : 33 raw bytes - Addr / Ripemd160 : 20 raw bytes
|
|
12
|
+
* - Sha256 : 32 raw bytes - Point : 64 raw bytes
|
|
13
|
+
* - P256Point : 64 raw bytes - P384Point : 96 raw bytes
|
|
14
|
+
* - anything else: push-data framed (variable length)
|
|
15
|
+
*
|
|
16
|
+
* The curve-point types are raw and fixed-width because `runar-lang`'s
|
|
17
|
+
* `P256Point` / `P384Point` cast constructors hard-assert 64 / 96 bytes, and
|
|
18
|
+
* all seven COMPILERS emit them as fixed raw slices in the state tail. An SDK
|
|
19
|
+
* that push-data frames them instead deploys a state section one (64 -> 0x40)
|
|
20
|
+
* or two (96 -> OP_PUSHDATA1) bytes longer than the script's own reader
|
|
21
|
+
* expects, and the first spend fails with the funds locked.
|
|
22
|
+
*
|
|
23
|
+
* Fields are concatenated in `StateField.index` order. FixedArray fields
|
|
24
|
+
* serialize as their flattened leaves back-to-back.
|
|
25
|
+
*
|
|
26
|
+
* Lives in runar-ir-schema so the compiler (which annotates `stateFields`
|
|
27
|
+
* in the artifact), the SDK's state codec, and any verifier tooling share
|
|
28
|
+
* ONE width table instead of re-deriving it.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Fixed serialized widths (bytes) for scalar state-field types.
|
|
32
|
+
* Types absent from this table serialize as push-data framed variable-length
|
|
33
|
+
* values ('pushdata').
|
|
34
|
+
*/
|
|
35
|
+
export const STATE_FIELD_WIDTHS = {
|
|
36
|
+
int: { size: 8, encoding: 'num2bin-le8' },
|
|
37
|
+
bigint: { size: 8, encoding: 'num2bin-le8' },
|
|
38
|
+
bool: { size: 1, encoding: 'bool1' },
|
|
39
|
+
boolean: { size: 1, encoding: 'bool1' },
|
|
40
|
+
PubKey: { size: 33, encoding: 'raw' },
|
|
41
|
+
Addr: { size: 20, encoding: 'raw' },
|
|
42
|
+
Ripemd160: { size: 20, encoding: 'raw' },
|
|
43
|
+
Sha256: { size: 32, encoding: 'raw' },
|
|
44
|
+
Point: { size: 64, encoding: 'raw' },
|
|
45
|
+
P256Point: { size: 64, encoding: 'raw' },
|
|
46
|
+
P384Point: { size: 96, encoding: 'raw' },
|
|
47
|
+
};
|
|
48
|
+
/** Return the innermost scalar type of a (possibly nested) FixedArray string. */
|
|
49
|
+
function unwrapFixedArrayLeaf(type) {
|
|
50
|
+
let current = type.trim();
|
|
51
|
+
while (current.startsWith('FixedArray<')) {
|
|
52
|
+
const inner = current.slice('FixedArray<'.length, -1);
|
|
53
|
+
let depth = 0;
|
|
54
|
+
let splitAt = -1;
|
|
55
|
+
for (let i = inner.length - 1; i >= 0; i--) {
|
|
56
|
+
const ch = inner[i];
|
|
57
|
+
if (ch === '>')
|
|
58
|
+
depth++;
|
|
59
|
+
else if (ch === '<')
|
|
60
|
+
depth--;
|
|
61
|
+
else if (ch === ',' && depth === 0) {
|
|
62
|
+
splitAt = i;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (splitAt < 0)
|
|
67
|
+
return current;
|
|
68
|
+
current = inner.slice(0, splitAt).trim();
|
|
69
|
+
}
|
|
70
|
+
return current;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Annotate state fields with their byte layout (`encoding`, `byteOffset`,
|
|
74
|
+
* `byteLength`, `tailOffset`). Returns NEW field objects (inputs are not
|
|
75
|
+
* mutated), sorted by `index` — the serialization order.
|
|
76
|
+
*
|
|
77
|
+
* `byteOffset` counts from the byte AFTER the OP_RETURN separator and is
|
|
78
|
+
* present only while every preceding field is fixed-length. `tailOffset` is
|
|
79
|
+
* a NEGATIVE offset from the END of the locking script and is present only
|
|
80
|
+
* when the field itself and every following field is fixed-length.
|
|
81
|
+
*/
|
|
82
|
+
export function annotateStateFieldLayout(fields) {
|
|
83
|
+
const sorted = [...fields].sort((a, b) => a.index - b.index);
|
|
84
|
+
const out = sorted.map(field => {
|
|
85
|
+
const annotated = { ...field };
|
|
86
|
+
if (field.fixedArray) {
|
|
87
|
+
// Flattened leaves serialize back-to-back; fixed only if the leaf is.
|
|
88
|
+
const leaf = STATE_FIELD_WIDTHS[unwrapFixedArrayLeaf(field.type)];
|
|
89
|
+
const count = field.fixedArray.syntheticNames.length;
|
|
90
|
+
if (leaf) {
|
|
91
|
+
annotated.encoding = leaf.encoding;
|
|
92
|
+
annotated.byteLength = leaf.size * count;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
annotated.encoding = 'pushdata';
|
|
96
|
+
}
|
|
97
|
+
return annotated;
|
|
98
|
+
}
|
|
99
|
+
const fixed = STATE_FIELD_WIDTHS[field.type];
|
|
100
|
+
if (fixed) {
|
|
101
|
+
annotated.encoding = fixed.encoding;
|
|
102
|
+
annotated.byteLength = fixed.size;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
annotated.encoding = 'pushdata';
|
|
106
|
+
}
|
|
107
|
+
return annotated;
|
|
108
|
+
});
|
|
109
|
+
// Forward pass: byteOffset while all preceding fields are fixed-length.
|
|
110
|
+
let offset = 0;
|
|
111
|
+
let frontFixed = true;
|
|
112
|
+
for (const f of out) {
|
|
113
|
+
if (frontFixed)
|
|
114
|
+
f.byteOffset = offset;
|
|
115
|
+
if (f.byteLength === undefined) {
|
|
116
|
+
frontFixed = false;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
offset += f.byteLength;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Backward pass: tailOffset while the field and all following are fixed.
|
|
123
|
+
let fromEnd = 0;
|
|
124
|
+
for (let i = out.length - 1; i >= 0; i--) {
|
|
125
|
+
const f = out[i];
|
|
126
|
+
if (f.byteLength === undefined)
|
|
127
|
+
break;
|
|
128
|
+
fromEnd += f.byteLength;
|
|
129
|
+
f.tailOffset = -fromEnd;
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Total serialized state length in bytes (after the OP_RETURN byte), or
|
|
135
|
+
* undefined when any field is variable-length.
|
|
136
|
+
*/
|
|
137
|
+
export function totalStateByteLength(fields) {
|
|
138
|
+
let total = 0;
|
|
139
|
+
for (const f of annotateStateFieldLayout(fields)) {
|
|
140
|
+
if (f.byteLength === undefined)
|
|
141
|
+
return undefined;
|
|
142
|
+
total += f.byteLength;
|
|
143
|
+
}
|
|
144
|
+
return total;
|
|
145
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error thrown by ANF / Stack-IR / constant-fold dispatch sites when
|
|
3
|
+
* they encounter an ANFValue kind they don't recognize.
|
|
4
|
+
*
|
|
5
|
+
* Historically these dispatchers used silent `default:` fall-throughs that
|
|
6
|
+
* returned a no-op value (empty refs list, unchanged ANFValue, `false` for
|
|
7
|
+
* side-effect checks). Adding a new ANFValue variant and forgetting to wire
|
|
8
|
+
* it into all 14 dispatch sites (see CLAUDE.md § Adding a New ANF Value Kind)
|
|
9
|
+
* would then silently corrupt output instead of failing loudly.
|
|
10
|
+
*
|
|
11
|
+
* Every former silent default now throws this error so the regression is
|
|
12
|
+
* caught at the first dispatch site instead of leaking into Stack IR / hex.
|
|
13
|
+
*/
|
|
14
|
+
export declare class UnknownANFKindError extends Error {
|
|
15
|
+
readonly kind: string;
|
|
16
|
+
readonly location: string;
|
|
17
|
+
constructor(kind: string, location: string);
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error thrown by ANF / Stack-IR / constant-fold dispatch sites when
|
|
3
|
+
* they encounter an ANFValue kind they don't recognize.
|
|
4
|
+
*
|
|
5
|
+
* Historically these dispatchers used silent `default:` fall-throughs that
|
|
6
|
+
* returned a no-op value (empty refs list, unchanged ANFValue, `false` for
|
|
7
|
+
* side-effect checks). Adding a new ANFValue variant and forgetting to wire
|
|
8
|
+
* it into all 14 dispatch sites (see CLAUDE.md § Adding a New ANF Value Kind)
|
|
9
|
+
* would then silently corrupt output instead of failing loudly.
|
|
10
|
+
*
|
|
11
|
+
* Every former silent default now throws this error so the regression is
|
|
12
|
+
* caught at the first dispatch site instead of leaking into Stack IR / hex.
|
|
13
|
+
*/
|
|
14
|
+
export class UnknownANFKindError extends Error {
|
|
15
|
+
kind;
|
|
16
|
+
location;
|
|
17
|
+
constructor(kind, location) {
|
|
18
|
+
super(`Unknown ANF kind '${kind}' encountered in ${location} — ` +
|
|
19
|
+
`if you added a new ANFValue variant, update all dispatch sites ` +
|
|
20
|
+
`(see CLAUDE.md § Adding a New ANF Value Kind for the 14-step recipe).`);
|
|
21
|
+
this.name = 'UnknownANFKindError';
|
|
22
|
+
this.kind = kind;
|
|
23
|
+
this.location = location;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight ANF interpreter for auto-computing state transitions.
|
|
3
|
+
*
|
|
4
|
+
* Given a compiled artifact's ANF IR, the current contract state, and
|
|
5
|
+
* method arguments, this interpreter walks the ANF bindings and computes
|
|
6
|
+
* the new state. It handles `update_prop` nodes to track state mutations,
|
|
7
|
+
* while skipping on-chain-only operations like `check_preimage`,
|
|
8
|
+
* `deserialize_state`, `get_state_script`, `add_output`, and `add_raw_output`.
|
|
9
|
+
*
|
|
10
|
+
* Three execution modes:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Lenient** (`computeNewState`, `computeNewStateAndDataOutputs`) —
|
|
13
|
+
* skips `assert` predicates so the SDK can pre-compute the post-state
|
|
14
|
+
* even when arguments wouldn't actually pass the on-chain script. This
|
|
15
|
+
* is the canonical use: auto-deriving `newState` for the next call.
|
|
16
|
+
* 2. **Strict** (`executeStrict`) — evaluates every `assert` predicate and
|
|
17
|
+
* throws `AssertionFailureError` (carrying the contract method + ANF
|
|
18
|
+
* binding name of the failing predicate) on the first false assert. Use
|
|
19
|
+
* for "will this call go through?" / "would the asserts hold" smoke
|
|
20
|
+
* tests off-chain before paying broadcast fees. Crypto built-ins
|
|
21
|
+
* (`checkSig`, `checkMultiSig`, `checkPreimage`) still mock-return
|
|
22
|
+
* `true` — only explicit `assert(...)` predicates are enforced.
|
|
23
|
+
* 3. **On-chain authoritative** (`executeOnChainAuthoritative`) — strict
|
|
24
|
+
* assert enforcement PLUS real ECDSA / SHA-256 preimage verification
|
|
25
|
+
* against a caller-supplied `sighash`. The signature shape requires the
|
|
26
|
+
* caller to provide the sighash up front, so it is impossible to invoke
|
|
27
|
+
* this mode accidentally without the cryptographic inputs. Use this to
|
|
28
|
+
* validate the exact transaction the caller intends to broadcast: a
|
|
29
|
+
* `checkSig(sig, pk)` only passes if the supplied DER signature
|
|
30
|
+
* verifies against the supplied compressed public key over the
|
|
31
|
+
* supplied sighash, and `checkPreimage(preimage)` only passes if
|
|
32
|
+
* `SHA256(SHA256(preimage)) === sighash` (the canonical BIP-143
|
|
33
|
+
* `OP_PUSH_TX` semantic).
|
|
34
|
+
*/
|
|
35
|
+
import type { ANFProgram } from '../../../../pool/runar-ir-schema.js';
|
|
36
|
+
/**
|
|
37
|
+
* Compute the new state after executing a contract method.
|
|
38
|
+
*
|
|
39
|
+
* @param anf The ANF IR from the compiled artifact.
|
|
40
|
+
* @param methodName The method to execute (must be a public method).
|
|
41
|
+
* @param currentState Current contract state (property name → value).
|
|
42
|
+
* @param args Method arguments (param name → value).
|
|
43
|
+
* @param constructorArgs Constructor arg values (declaration order) for readonly fields.
|
|
44
|
+
* @returns The updated state (merged with currentState).
|
|
45
|
+
*/
|
|
46
|
+
export interface DataOutputEntry {
|
|
47
|
+
satoshis: bigint | number;
|
|
48
|
+
script: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Raw outputs produced by `this.addRawOutput(satoshis, scriptBytes)` in the
|
|
52
|
+
* method body. `script` is the **caller-supplied** locking-script bytes
|
|
53
|
+
* (hex-encoded), in contrast to `DataOutputEntry.script`, which is the hex
|
|
54
|
+
* payload that becomes part of an `OP_RETURN` data output. The simulator
|
|
55
|
+
* cannot introspect these bytes — it surfaces them so a caller building
|
|
56
|
+
* the broadcast transaction off-chain can splice them in at the correct
|
|
57
|
+
* position. Entries appear in declaration order, after the state output
|
|
58
|
+
* and after `dataOutputs`.
|
|
59
|
+
*/
|
|
60
|
+
export interface RawOutputEntry {
|
|
61
|
+
satoshis: bigint | number;
|
|
62
|
+
script: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A single state-class output in the exact SOURCE order the method body emits
|
|
66
|
+
* it, capturing the interleaving of `this.addOutput(...)` (state continuation)
|
|
67
|
+
* and `this.addRawOutput(...)` (caller-supplied script). The compiler folds
|
|
68
|
+
* these into the continuation `hashOutputs` in this same order (see
|
|
69
|
+
* `packages/runar-compiler/src/passes/04-anf-lower.ts` — `add_output` and
|
|
70
|
+
* `add_raw_output` share one `addOutputRefs` list), so a transaction builder
|
|
71
|
+
* MUST emit them in this order or the on-chain state-check OP_VERIFY rejects
|
|
72
|
+
* (finding G1). `script` is populated for `raw` entries only; `state` entries
|
|
73
|
+
* take the freshly computed continuation locking script from the caller.
|
|
74
|
+
* Data outputs (`add_data_output`) are NOT included here — they are always
|
|
75
|
+
* emitted after every state-class output, in their own `dataOutputs` list.
|
|
76
|
+
*/
|
|
77
|
+
export interface OrderedOutputEntry {
|
|
78
|
+
kind: 'state' | 'raw';
|
|
79
|
+
satoshis: bigint;
|
|
80
|
+
script?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The full result envelope produced by
|
|
84
|
+
* {@link computeNewStateAndDataOutputs}, {@link executeStrict}, and
|
|
85
|
+
* {@link executeOnChainAuthoritative}. All three modes return the same
|
|
86
|
+
* shape; mode-specific behaviour only changes whether asserts and crypto
|
|
87
|
+
* primitives are enforced or mocked, not what fields are populated.
|
|
88
|
+
*/
|
|
89
|
+
export interface ExecutionResult {
|
|
90
|
+
state: Record<string, unknown>;
|
|
91
|
+
dataOutputs: DataOutputEntry[];
|
|
92
|
+
rawOutputs: RawOutputEntry[];
|
|
93
|
+
/** State-class outputs (state continuation + raw) in source order. */
|
|
94
|
+
outputs: OrderedOutputEntry[];
|
|
95
|
+
}
|
|
96
|
+
export declare function computeNewState(anf: ANFProgram, methodName: string, currentState: Record<string, unknown>, args: Record<string, unknown>, constructorArgs?: unknown[]): Record<string, unknown>;
|
|
97
|
+
/**
|
|
98
|
+
* Like {@link computeNewState} but also returns data outputs resolved
|
|
99
|
+
* from `this.addDataOutput(...)` and raw outputs resolved from
|
|
100
|
+
* `this.addRawOutput(...)` in the method body. Entries appear in
|
|
101
|
+
* declaration order and are what `buildCallTransaction` should emit
|
|
102
|
+
* between state outputs and the change output so the on-chain
|
|
103
|
+
* continuation-hash check passes.
|
|
104
|
+
*/
|
|
105
|
+
export declare function computeNewStateAndDataOutputs(anf: ANFProgram, methodName: string, currentState: Record<string, unknown>, args: Record<string, unknown>, constructorArgs?: unknown[]): ExecutionResult;
|
|
106
|
+
/**
|
|
107
|
+
* Thrown by {@link executeStrict} on the first failing `assert` predicate.
|
|
108
|
+
* Carries enough context to point a developer at the exact ANF binding
|
|
109
|
+
* that aborted: the method being executed and the binding name (e.g.
|
|
110
|
+
* `assertPositive` from the source `assert(amount > 0)`).
|
|
111
|
+
*/
|
|
112
|
+
export declare class AssertionFailureError extends Error {
|
|
113
|
+
readonly methodName: string;
|
|
114
|
+
readonly bindingName: string;
|
|
115
|
+
constructor(methodName: string, bindingName: string);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Strict-mode counterpart to {@link computeNewStateAndDataOutputs}: walks
|
|
119
|
+
* the same ANF body but throws {@link AssertionFailureError} on the first
|
|
120
|
+
* `assert(predicate)` whose predicate evaluates to a falsy value. Use this
|
|
121
|
+
* before broadcasting a transaction to surface guard failures off-chain
|
|
122
|
+
* instead of relying on a node rejection. Crypto built-ins (`checkSig`,
|
|
123
|
+
* `checkMultiSig`, `checkPreimage`) still mock-return `true` — strict mode
|
|
124
|
+
* only enforces explicit `assert(...)` predicates.
|
|
125
|
+
*/
|
|
126
|
+
export declare function executeStrict(anf: ANFProgram, methodName: string, currentState: Record<string, unknown>, args: Record<string, unknown>, constructorArgs?: unknown[]): ExecutionResult;
|
|
127
|
+
/**
|
|
128
|
+
* Required cryptographic context for {@link executeOnChainAuthoritative}.
|
|
129
|
+
*
|
|
130
|
+
* `sighash` is the 32-byte BIP-143 sighash digest the on-chain VM would
|
|
131
|
+
* verify signatures against (and that the caller would have signed with
|
|
132
|
+
* `LocalSigner.sign(...)` before broadcasting). The interpreter:
|
|
133
|
+
*
|
|
134
|
+
* - verifies `checkSig(sig, pk)` by parsing `pk` as a compressed/uncompressed
|
|
135
|
+
* secp256k1 point, parsing `sig` as DER (with optional trailing sighash byte
|
|
136
|
+
* stripped), and calling `pubKey.verify(sighash, signature)` — a real
|
|
137
|
+
* ECDSA verification. Any mismatch returns `false`, which then trips the
|
|
138
|
+
* enclosing `assert(...)` and throws.
|
|
139
|
+
* - verifies `checkMultiSig(sigs, pks)` by iterating signatures left-to-right
|
|
140
|
+
* and consuming pubkeys greedily, mirroring Bitcoin's `OP_CHECKMULTISIG`.
|
|
141
|
+
* - verifies `checkPreimage(preimage)` by computing `hash256(preimage)`
|
|
142
|
+
* (i.e. `SHA256(SHA256(preimage))`) and comparing it to `sighash`
|
|
143
|
+
* byte-for-byte — the on-chain `OP_PUSH_TX` semantic.
|
|
144
|
+
*/
|
|
145
|
+
export interface OnChainCryptoContext {
|
|
146
|
+
/** 32-byte BIP-143 sighash, as a hex string or `Uint8Array`. */
|
|
147
|
+
sighash: string | Uint8Array;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Like {@link executeStrict} but also performs real cryptographic
|
|
151
|
+
* verification of `checkSig`, `checkMultiSig`, and `checkPreimage` against
|
|
152
|
+
* the supplied `sighash`. Throws {@link AssertionFailureError} when any
|
|
153
|
+
* `assert(...)` (including the implicit one wrapping a failed crypto
|
|
154
|
+
* built-in) fires.
|
|
155
|
+
*
|
|
156
|
+
* The `ctx` parameter is mandatory and carries the sighash, so it is
|
|
157
|
+
* impossible to call this entry point accidentally without supplying the
|
|
158
|
+
* cryptographic inputs the verification needs.
|
|
159
|
+
*/
|
|
160
|
+
export declare function executeOnChainAuthoritative(anf: ANFProgram, methodName: string, currentState: Record<string, unknown>, args: Record<string, unknown>, constructorArgs: unknown[], ctx: OnChainCryptoContext): ExecutionResult;
|