@perpbrain/sdk 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ import { type LinkSelector } from "./fillLink.ts";
2
+ export declare const HOLDING_KIND = "perpbrain.holding-receipt";
3
+ export declare const HOLDING_VERSION = 3;
4
+ export declare const HOLDING_STATEMENT = "reproducible from the supplied inputs; not authenticated to the venue or account";
5
+ export declare const VERIFY_SCOPE = "ARITHMETIC_AND_HASHES_REPRODUCED_FROM_SUPPLIED_INPUTS; authenticity of fills and funding rows is not established";
6
+ export declare const FUNDING_SCOPE = "ACCOUNT_COIN_SUM_NOT_POSITION_ATTRIBUTED";
7
+ export declare const FUNDING_COVERAGE = "UNKNOWN";
8
+ type Row = Record<string, unknown>;
9
+ export interface HoldingLeg {
10
+ by: LinkSelector;
11
+ value: string;
12
+ trade_index: number;
13
+ }
14
+ export interface HoldingInputs {
15
+ account: string;
16
+ network: string;
17
+ coin: string;
18
+ start_ms: number;
19
+ end_ms: number;
20
+ entry: HoldingLeg;
21
+ exit: HoldingLeg | null;
22
+ funding_rows: Row[];
23
+ }
24
+ export interface BuiltHolding {
25
+ record: Record<string, unknown>;
26
+ recordBytes: Buffer;
27
+ inputsBytes: Buffer;
28
+ }
29
+ export interface HoldingVerify {
30
+ status: "VERIFIED" | "MISMATCH" | "UNCHECKED_PARTIAL";
31
+ mismatches: string[];
32
+ unchecked?: string[];
33
+ scope?: string;
34
+ upstream_receipt_verification?: string;
35
+ }
36
+ export declare function computeHolding(inputs: HoldingInputs, receipt: Row, allFills: Row[], receiptVerified?: boolean): Row;
37
+ /** receiptVerified is true only when the caller ran the upstream receipt verifier. The default
38
+ * is false: the record is capped at PROVISIONAL with reason RECEIPT_NOT_VERIFIED. */
39
+ export declare function buildHolding(inputs: HoldingInputs, receipt: Row, allFills: Row[], receiptVerified?: boolean): BuiltHolding;
40
+ /** VERIFIED only when the receipt is supplied and every hash and the result reproduce.
41
+ * receiptVerified is the caller's assertion that it ran an upstream receipt verifier; this
42
+ * function cannot check it, and the TS side has no CLI path that sets it (default false).
43
+ * VERIFIED does not mean the receipt is authentic. The record field is outside
44
+ * result_sha256, but the hashed result carries RECEIPT_NOT_VERIFIED when it is not set.
45
+ * Without a receipt only kind, version and the inputs hash can be checked: the answer is
46
+ * UNCHECKED_PARTIAL, never VERIFIED. */
47
+ export declare function verifyHolding(record: unknown, inputsBytes: Buffer, allFills: Row[], receipt?: Row, receiptVerified?: boolean): HoldingVerify;
48
+ export {};
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FUNDING_COVERAGE = exports.FUNDING_SCOPE = exports.VERIFY_SCOPE = exports.HOLDING_STATEMENT = exports.HOLDING_VERSION = exports.HOLDING_KIND = void 0;
4
+ exports.computeHolding = computeHolding;
5
+ exports.buildHolding = buildHolding;
6
+ exports.verifyHolding = verifyHolding;
7
+ /**
8
+ * Holding-period receipts (issue 96): entry and exit fill linkage plus a funding sum.
9
+ *
10
+ * TypeScript port of `perpbrain_read.sim.holding` (record version 2). Same record, same
11
+ * canonical JSON, so a record built by either SDK verifies in the other.
12
+ *
13
+ * What the record proves: the result reproduces from the stored inputs. Tamper-evidence only.
14
+ * Fills and funding rows are caller-supplied and not authenticated to the venue or account.
15
+ * `funding_usdc` is the account-level sum of the supplied rows for one coin in the window, NOT
16
+ * attributed to this position. Funding coverage is unknown. Fee tokens other than USDC are
17
+ * flagged, never valued as zero.
18
+ *
19
+ * Pinned definitions: funding window `start_ms < time <= end_ms`; each leg's first and last
20
+ * fill time in `[start_ms, end_ms]`. COMPLETE needs both legs LINKED with fill_ratio 1, equal
21
+ * size, same coin as the funding coin, opposite sides, distinct fills, exit after entry, fills
22
+ * in window and USDC fees only. Otherwise INCOMPLETE with reasons. An open position with no
23
+ * reasons is PROVISIONAL.
24
+ *
25
+ * Read-only: no keys, no order path, no network.
26
+ */
27
+ const node_crypto_1 = require("node:crypto");
28
+ const receipt_ts_1 = require("./receipt.js");
29
+ const fillLink_ts_1 = require("./fillLink.js");
30
+ const fixedDecimal_ts_1 = require("./fixedDecimal.js");
31
+ exports.HOLDING_KIND = "perpbrain.holding-receipt";
32
+ exports.HOLDING_VERSION = 3;
33
+ exports.HOLDING_STATEMENT = "reproducible from the supplied inputs; not authenticated to the venue or account";
34
+ exports.VERIFY_SCOPE = "ARITHMETIC_AND_HASHES_REPRODUCED_FROM_SUPPLIED_INPUTS; authenticity of fills and funding rows is not established";
35
+ exports.FUNDING_SCOPE = "ACCOUNT_COIN_SUM_NOT_POSITION_ATTRIBUTED";
36
+ exports.FUNDING_COVERAGE = "UNKNOWN";
37
+ function sha256Hex(raw) {
38
+ return (0, node_crypto_1.createHash)("sha256").update(raw).digest("hex");
39
+ }
40
+ function isInt(value) {
41
+ return typeof value === "number" && Number.isInteger(value);
42
+ }
43
+ function validate(inputs) {
44
+ if (inputs.network !== "mainnet" && inputs.network !== "testnet") {
45
+ throw new Error("network must be mainnet or testnet");
46
+ }
47
+ if (!isInt(inputs.start_ms) || !isInt(inputs.end_ms)) {
48
+ throw new Error("start_ms and end_ms must be integers");
49
+ }
50
+ if (inputs.end_ms <= inputs.start_ms)
51
+ throw new Error("end_ms must be after start_ms");
52
+ }
53
+ function fundingRows(inputs) {
54
+ const rows = inputs.funding_rows;
55
+ if (!Array.isArray(rows))
56
+ throw new Error("funding_rows must be a list");
57
+ for (const row of rows) {
58
+ if (row === null || typeof row !== "object" || Array.isArray(row)) {
59
+ throw new Error("funding row must be an object");
60
+ }
61
+ if (typeof row.coin !== "string" || !isInt(row.time)) {
62
+ throw new Error("funding row needs a string coin and an integer time");
63
+ }
64
+ if (!(0, fixedDecimal_ts_1.isStrictDecimal)(row.usdc))
65
+ throw new Error("funding row usdc must be a plain decimal string");
66
+ }
67
+ return rows;
68
+ }
69
+ function leg(inputs, spec, receipt, allFills) {
70
+ const sim = (0, fillLink_ts_1.simFromReceipt)(receipt, spec.trade_index);
71
+ const built = (0, fillLink_ts_1.linkInputs)(receipt, allFills, {
72
+ network: inputs.network,
73
+ user: inputs.account,
74
+ by: spec.by,
75
+ value: spec.value,
76
+ tradeIndex: spec.trade_index,
77
+ });
78
+ const result = (0, fillLink_ts_1.computeLink)(built);
79
+ return {
80
+ block: {
81
+ selector: { by: spec.by, value: (0, fillLink_ts_1.normaliseSelector)(spec.by, spec.value) },
82
+ market: sim.market,
83
+ side: sim.side,
84
+ status: result.status,
85
+ size: result.size,
86
+ avg_px: result.avg_px,
87
+ fees_usdc: result.fees_usdc,
88
+ fill_ratio: result.fill_ratio,
89
+ slippage_vs_sim_bps: result.slippage_vs_sim_bps,
90
+ fee_drag_usd: result.fee_drag_usd,
91
+ time_to_first_fill_ms: result.time_to_first_fill_ms,
92
+ first_time_ms: result.first_time_ms,
93
+ last_time_ms: result.last_time_ms,
94
+ oids: result.oids,
95
+ hashes: result.hashes,
96
+ },
97
+ fills: built.fills,
98
+ };
99
+ }
100
+ function legReasons(name, block, fills) {
101
+ const reasons = [];
102
+ if (block.status !== "LINKED")
103
+ reasons.push(`${name}_NOT_LINKED`);
104
+ if (block.fill_ratio !== "1")
105
+ reasons.push(`${name}_NOT_FULL_FILL`);
106
+ if (fills.some((f) => f.feeToken !== undefined && f.feeToken !== null && f.feeToken !== "USDC")) {
107
+ reasons.push(`${name}_UNSUPPORTED_FEE_TOKEN`);
108
+ }
109
+ return reasons;
110
+ }
111
+ function outside(block, startMs, endMs) {
112
+ const first = block.first_time_ms;
113
+ const last = block.last_time_ms;
114
+ return first === null || last === null || first < startMs || last > endMs;
115
+ }
116
+ function intersects(a, b) {
117
+ const right = new Set(b);
118
+ return a.some((x) => right.has(x));
119
+ }
120
+ function computeHolding(inputs, receipt, allFills, receiptVerified = false) {
121
+ validate(inputs);
122
+ const rows = fundingRows(inputs);
123
+ const { start_ms: startMs, end_ms: endMs } = inputs;
124
+ const entryOut = leg(inputs, inputs.entry, receipt, allFills);
125
+ const entry = entryOut.block;
126
+ let reasons = legReasons("ENTRY", entry, entryOut.fills);
127
+ if (outside(entry, startMs, endMs))
128
+ reasons.push("ENTRY_OUTSIDE_WINDOW");
129
+ if (entry.market !== inputs.coin)
130
+ reasons.push("COIN_MISMATCH");
131
+ let exitBlock = null;
132
+ const isOpen = inputs.exit === null;
133
+ if (inputs.exit !== null) {
134
+ const exitOut = leg(inputs, inputs.exit, receipt, allFills);
135
+ exitBlock = exitOut.block;
136
+ reasons = reasons.concat(legReasons("EXIT", exitBlock, exitOut.fills));
137
+ if (outside(exitBlock, startMs, endMs))
138
+ reasons.push("EXIT_OUTSIDE_WINDOW");
139
+ if (exitBlock.market !== inputs.coin)
140
+ reasons.push("COIN_MISMATCH");
141
+ if (exitBlock.side === entry.side)
142
+ reasons.push("SIDE_NOT_OPPOSITE");
143
+ if (exitBlock.size !== entry.size)
144
+ reasons.push("SIZE_MISMATCH");
145
+ if (intersects(exitBlock.oids, entry.oids) || intersects(exitBlock.hashes, entry.hashes)) {
146
+ reasons.push("LEGS_SHARE_FILLS");
147
+ }
148
+ if (entry.last_time_ms !== null &&
149
+ exitBlock.first_time_ms !== null &&
150
+ exitBlock.first_time_ms <= entry.last_time_ms) {
151
+ reasons.push("EXIT_NOT_AFTER_ENTRY");
152
+ }
153
+ }
154
+ const inWindow = rows.filter((r) => r.coin === inputs.coin && startMs < r.time && r.time <= endMs);
155
+ let funding = 0n;
156
+ for (const r of inWindow)
157
+ funding += (0, fixedDecimal_ts_1.parseStrictFixed)(r.usdc, "funding row usdc");
158
+ reasons = [...new Set(reasons)].sort();
159
+ const status = reasons.length
160
+ ? "INCOMPLETE"
161
+ : isOpen || !receiptVerified
162
+ ? "PROVISIONAL"
163
+ : "COMPLETE";
164
+ if (!receiptVerified)
165
+ reasons = [...new Set([...reasons, "RECEIPT_NOT_VERIFIED"])].sort();
166
+ return {
167
+ status,
168
+ reasons,
169
+ entry,
170
+ exit: exitBlock,
171
+ funding_usdc: (0, fixedDecimal_ts_1.formatFixed)(funding),
172
+ funding_rows_count: inWindow.length,
173
+ funding_scope: exports.FUNDING_SCOPE,
174
+ funding_coverage: exports.FUNDING_COVERAGE,
175
+ hold_ms: endMs - startMs,
176
+ open: isOpen,
177
+ };
178
+ }
179
+ /** receiptVerified is true only when the caller ran the upstream receipt verifier. The default
180
+ * is false: the record is capped at PROVISIONAL with reason RECEIPT_NOT_VERIFIED. */
181
+ function buildHolding(inputs, receipt, allFills, receiptVerified = false) {
182
+ const raw = (0, receipt_ts_1.canonical)(inputs);
183
+ const result = computeHolding(inputs, receipt, allFills, receiptVerified);
184
+ const record = {
185
+ kind: exports.HOLDING_KIND,
186
+ version: exports.HOLDING_VERSION,
187
+ label: (inputs.network === "mainnet" ? "MAINNET" : "TESTNET") +
188
+ (result.open ? " OPEN" : ""),
189
+ statement: exports.HOLDING_STATEMENT,
190
+ receipt_sha256: (0, receipt_ts_1.sha256Json)(receipt),
191
+ upstream_receipt_verification: receiptVerified ? "VERIFIED" : "NOT_VERIFIED",
192
+ inputs_sha256: sha256Hex(raw),
193
+ result,
194
+ result_sha256: (0, receipt_ts_1.sha256Json)(result),
195
+ };
196
+ return {
197
+ record,
198
+ recordBytes: Buffer.from((0, receipt_ts_1.canonical)(record) + "\n", "utf8"),
199
+ inputsBytes: Buffer.from(raw + "\n", "utf8"),
200
+ };
201
+ }
202
+ /** VERIFIED only when the receipt is supplied and every hash and the result reproduce.
203
+ * receiptVerified is the caller's assertion that it ran an upstream receipt verifier; this
204
+ * function cannot check it, and the TS side has no CLI path that sets it (default false).
205
+ * VERIFIED does not mean the receipt is authentic. The record field is outside
206
+ * result_sha256, but the hashed result carries RECEIPT_NOT_VERIFIED when it is not set.
207
+ * Without a receipt only kind, version and the inputs hash can be checked: the answer is
208
+ * UNCHECKED_PARTIAL, never VERIFIED. */
209
+ function verifyHolding(record, inputsBytes, allFills, receipt, receiptVerified = false) {
210
+ const problems = [];
211
+ const body = (record ?? null);
212
+ if (body === null || typeof body !== "object") {
213
+ return { status: "MISMATCH", mismatches: ["record must be an object"] };
214
+ }
215
+ if (body.kind !== exports.HOLDING_KIND)
216
+ problems.push("kind");
217
+ if (body.version !== exports.HOLDING_VERSION)
218
+ problems.push("version");
219
+ let result;
220
+ try {
221
+ const inputs = JSON.parse(inputsBytes.toString("utf8"));
222
+ if (sha256Hex((0, receipt_ts_1.canonical)(inputs)) !== body.inputs_sha256)
223
+ problems.push("inputs_sha256");
224
+ if (receipt === undefined) {
225
+ if (problems.length)
226
+ return { status: "MISMATCH", mismatches: problems };
227
+ return {
228
+ status: "UNCHECKED_PARTIAL",
229
+ mismatches: [],
230
+ unchecked: ["result", "result_sha256", "receipt_sha256"],
231
+ };
232
+ }
233
+ result = computeHolding(inputs, receipt, allFills, receiptVerified);
234
+ }
235
+ catch (exc) {
236
+ problems.push(`inputs: ${exc instanceof Error ? exc.message : String(exc)}`);
237
+ return { status: "MISMATCH", mismatches: problems };
238
+ }
239
+ const network = JSON.parse(inputsBytes.toString("utf8")).network;
240
+ const expectedLabel = (network === "mainnet" ? "MAINNET" : "TESTNET") + (result.open ? " OPEN" : "");
241
+ if (body.label !== expectedLabel)
242
+ problems.push("label");
243
+ if (body.statement !== exports.HOLDING_STATEMENT)
244
+ problems.push("statement");
245
+ if ((0, receipt_ts_1.canonical)(body.result) !== (0, receipt_ts_1.canonical)(result))
246
+ problems.push("result");
247
+ if (body.result_sha256 !== (0, receipt_ts_1.sha256Json)(result))
248
+ problems.push("result_sha256");
249
+ if (body.receipt_sha256 !== (0, receipt_ts_1.sha256Json)(receipt))
250
+ problems.push("receipt_sha256");
251
+ const expectedFlag = receiptVerified ? "VERIFIED" : "NOT_VERIFIED";
252
+ if (body.upstream_receipt_verification !== expectedFlag) {
253
+ problems.push("upstream_receipt_verification");
254
+ }
255
+ if (problems.length)
256
+ return { status: "MISMATCH", mismatches: problems };
257
+ return {
258
+ status: "VERIFIED",
259
+ mismatches: [],
260
+ scope: exports.VERIFY_SCOPE,
261
+ upstream_receipt_verification: expectedFlag,
262
+ };
263
+ }
@@ -4,7 +4,17 @@ export type { GuardCode, GuardLimits, GuardOverrides, GuardResult, Guards, Marke
4
4
  export { guardedSimulate } from "./guarded.ts";
5
5
  export type { GuardedSimulateResult } from "./guarded.ts";
6
6
  export { renderReceiptCard } from "./card.ts";
7
- export { RECEIPT_KIND, RECEIPT_STATEMENT, RECEIPT_VERSION, buildGuardedReceipt, buildReceiptDir, buildReceiptFiles, canonical, costBreakdownFromReceipt, exampleInputs, limitsPayload, sha256Json, simulateInputs, snapshotRows, verifyReceipt, verifyReceiptAt, writeReceiptDir, } from "./receipt.ts";
7
+ export { CALIBRATION_KIND, CALIBRATION_VERSION, CALIBRATION_STATEMENT, MIN_SAMPLE, buildReport, computeReport, verifyReport, } from "./calibration.ts";
8
+ export type { BuiltReport, CalibrationCandidate, CalibrationInputs, ReportVerify, } from "./calibration.ts";
9
+ export { CLIENT_META_ALLOWED_KEYS, CLIENT_META_MAX_CANONICAL_BYTES, attachClientMeta, makeEntry, validateClientMeta, } from "./clientMeta.ts";
10
+ export type { ClientMetaEntry } from "./clientMeta.ts";
11
+ export { FUNDING_COVERAGE, FUNDING_SCOPE, HOLDING_KIND, HOLDING_STATEMENT, HOLDING_VERSION, VERIFY_SCOPE, buildHolding, computeHolding, verifyHolding, } from "./holding.ts";
12
+ export type { BuiltHolding, HoldingInputs, HoldingLeg, HoldingVerify } from "./holding.ts";
13
+ export { RECON_KIND, RECON_VERSION, reconcile, verifyReconReceipt } from "./fundingRecon.ts";
14
+ export type { ReconVerify } from "./fundingRecon.ts";
15
+ export { LINK_KIND, LINK_VERSION, buildLink, computeLink, linkInputs, normaliseSelector, selectFills, simFromReceipt, verifyLink, } from "./fillLink.ts";
16
+ export type { BuiltLink, LinkInputs, LinkNetwork, LinkResult, LinkSelector, LinkVerify, SimTrade, } from "./fillLink.ts";
17
+ export { RECEIPT_KIND, RECEIPT_STATEMENT, RECEIPT_VERSION, buildGuardedReceipt, buildReceiptDir, buildReceiptFiles, canonical, costBreakdownFromReceipt, exampleInputs, limitsPayload, sha256Json, simulateInputs, snapshotRows, verifyReceipt, verifyReceiptAt, ResourceLimitError, UnsupportedVerificationError, MissingInputsError, InvalidLimitError, NoVerdictError, writeReceiptDir, } from "./receipt.ts";
8
18
  export type { BuiltReceipt } from "./receipt.ts";
9
19
  export { executionCost } from "./vendor/costs.ts";
10
20
  export type { CostBreakdown } from "./vendor/costs.ts";
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  /** Read-only and simulation-only SDK surface. */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.READ_AND_SIM_TOOLS = exports.simulate = exports.positions = exports.orderBook = exports.markets = exports.funding = exports.fees = exports.InfoClient = exports.executionCost = exports.writeReceiptDir = exports.verifyReceiptAt = exports.verifyReceipt = exports.snapshotRows = exports.simulateInputs = exports.sha256Json = exports.limitsPayload = exports.exampleInputs = exports.costBreakdownFromReceipt = exports.canonical = exports.buildReceiptFiles = exports.buildReceiptDir = exports.buildGuardedReceipt = exports.RECEIPT_VERSION = exports.RECEIPT_STATEMENT = exports.RECEIPT_KIND = exports.renderReceiptCard = exports.guardedSimulate = exports.wireCode = exports.survivalReport = exports.fromConfig = exports.defaultSnapshot = exports.defaultGuards = exports.GuardSession = exports.GuardLoosenError = exports.GuardConfigError = exports.GuardBlocked = exports.STALE_HALT_MS = exports.STALE_BLOCK_MS = exports.PRESETS = exports.HARD_MAX_SLIPPAGE_BPS = exports.HARD_MAX_ORDER_RATE = exports.HARD_MAX_OPEN_POSITIONS = exports.HARD_MAX_DAILY_LOSS_PCT = exports.CODES = void 0;
4
+ exports.normaliseSelector = exports.linkInputs = exports.computeLink = exports.buildLink = exports.LINK_VERSION = exports.LINK_KIND = exports.verifyReconReceipt = exports.reconcile = exports.RECON_VERSION = exports.RECON_KIND = exports.verifyHolding = exports.computeHolding = exports.buildHolding = exports.VERIFY_SCOPE = exports.HOLDING_VERSION = exports.HOLDING_STATEMENT = exports.HOLDING_KIND = exports.FUNDING_SCOPE = exports.FUNDING_COVERAGE = exports.validateClientMeta = exports.makeEntry = exports.attachClientMeta = exports.CLIENT_META_MAX_CANONICAL_BYTES = exports.CLIENT_META_ALLOWED_KEYS = exports.verifyReport = exports.computeReport = exports.buildReport = exports.MIN_SAMPLE = exports.CALIBRATION_STATEMENT = exports.CALIBRATION_VERSION = exports.CALIBRATION_KIND = exports.renderReceiptCard = exports.guardedSimulate = exports.wireCode = exports.survivalReport = exports.fromConfig = exports.defaultSnapshot = exports.defaultGuards = exports.GuardSession = exports.GuardLoosenError = exports.GuardConfigError = exports.GuardBlocked = exports.STALE_HALT_MS = exports.STALE_BLOCK_MS = exports.PRESETS = exports.HARD_MAX_SLIPPAGE_BPS = exports.HARD_MAX_ORDER_RATE = exports.HARD_MAX_OPEN_POSITIONS = exports.HARD_MAX_DAILY_LOSS_PCT = exports.CODES = void 0;
5
+ exports.READ_AND_SIM_TOOLS = exports.simulate = exports.positions = exports.orderBook = exports.markets = exports.funding = exports.fees = exports.InfoClient = exports.executionCost = exports.writeReceiptDir = exports.NoVerdictError = exports.InvalidLimitError = exports.MissingInputsError = exports.UnsupportedVerificationError = exports.ResourceLimitError = exports.verifyReceiptAt = exports.verifyReceipt = exports.snapshotRows = exports.simulateInputs = exports.sha256Json = exports.limitsPayload = exports.exampleInputs = exports.costBreakdownFromReceipt = exports.canonical = exports.buildReceiptFiles = exports.buildReceiptDir = exports.buildGuardedReceipt = exports.RECEIPT_VERSION = exports.RECEIPT_STATEMENT = exports.RECEIPT_KIND = exports.verifyLink = exports.simFromReceipt = exports.selectFills = void 0;
5
6
  var guards_ts_1 = require("./guards.js");
6
7
  Object.defineProperty(exports, "CODES", { enumerable: true, get: function () { return guards_ts_1.CODES; } });
7
8
  Object.defineProperty(exports, "HARD_MAX_DAILY_LOSS_PCT", { enumerable: true, get: function () { return guards_ts_1.HARD_MAX_DAILY_LOSS_PCT; } });
@@ -24,6 +25,45 @@ var guarded_ts_1 = require("./guarded.js");
24
25
  Object.defineProperty(exports, "guardedSimulate", { enumerable: true, get: function () { return guarded_ts_1.guardedSimulate; } });
25
26
  var card_ts_1 = require("./card.js");
26
27
  Object.defineProperty(exports, "renderReceiptCard", { enumerable: true, get: function () { return card_ts_1.renderReceiptCard; } });
28
+ var calibration_ts_1 = require("./calibration.js");
29
+ Object.defineProperty(exports, "CALIBRATION_KIND", { enumerable: true, get: function () { return calibration_ts_1.CALIBRATION_KIND; } });
30
+ Object.defineProperty(exports, "CALIBRATION_VERSION", { enumerable: true, get: function () { return calibration_ts_1.CALIBRATION_VERSION; } });
31
+ Object.defineProperty(exports, "CALIBRATION_STATEMENT", { enumerable: true, get: function () { return calibration_ts_1.CALIBRATION_STATEMENT; } });
32
+ Object.defineProperty(exports, "MIN_SAMPLE", { enumerable: true, get: function () { return calibration_ts_1.MIN_SAMPLE; } });
33
+ Object.defineProperty(exports, "buildReport", { enumerable: true, get: function () { return calibration_ts_1.buildReport; } });
34
+ Object.defineProperty(exports, "computeReport", { enumerable: true, get: function () { return calibration_ts_1.computeReport; } });
35
+ Object.defineProperty(exports, "verifyReport", { enumerable: true, get: function () { return calibration_ts_1.verifyReport; } });
36
+ var clientMeta_ts_1 = require("./clientMeta.js");
37
+ Object.defineProperty(exports, "CLIENT_META_ALLOWED_KEYS", { enumerable: true, get: function () { return clientMeta_ts_1.CLIENT_META_ALLOWED_KEYS; } });
38
+ Object.defineProperty(exports, "CLIENT_META_MAX_CANONICAL_BYTES", { enumerable: true, get: function () { return clientMeta_ts_1.CLIENT_META_MAX_CANONICAL_BYTES; } });
39
+ Object.defineProperty(exports, "attachClientMeta", { enumerable: true, get: function () { return clientMeta_ts_1.attachClientMeta; } });
40
+ Object.defineProperty(exports, "makeEntry", { enumerable: true, get: function () { return clientMeta_ts_1.makeEntry; } });
41
+ Object.defineProperty(exports, "validateClientMeta", { enumerable: true, get: function () { return clientMeta_ts_1.validateClientMeta; } });
42
+ var holding_ts_1 = require("./holding.js");
43
+ Object.defineProperty(exports, "FUNDING_COVERAGE", { enumerable: true, get: function () { return holding_ts_1.FUNDING_COVERAGE; } });
44
+ Object.defineProperty(exports, "FUNDING_SCOPE", { enumerable: true, get: function () { return holding_ts_1.FUNDING_SCOPE; } });
45
+ Object.defineProperty(exports, "HOLDING_KIND", { enumerable: true, get: function () { return holding_ts_1.HOLDING_KIND; } });
46
+ Object.defineProperty(exports, "HOLDING_STATEMENT", { enumerable: true, get: function () { return holding_ts_1.HOLDING_STATEMENT; } });
47
+ Object.defineProperty(exports, "HOLDING_VERSION", { enumerable: true, get: function () { return holding_ts_1.HOLDING_VERSION; } });
48
+ Object.defineProperty(exports, "VERIFY_SCOPE", { enumerable: true, get: function () { return holding_ts_1.VERIFY_SCOPE; } });
49
+ Object.defineProperty(exports, "buildHolding", { enumerable: true, get: function () { return holding_ts_1.buildHolding; } });
50
+ Object.defineProperty(exports, "computeHolding", { enumerable: true, get: function () { return holding_ts_1.computeHolding; } });
51
+ Object.defineProperty(exports, "verifyHolding", { enumerable: true, get: function () { return holding_ts_1.verifyHolding; } });
52
+ var fundingRecon_ts_1 = require("./fundingRecon.js");
53
+ Object.defineProperty(exports, "RECON_KIND", { enumerable: true, get: function () { return fundingRecon_ts_1.RECON_KIND; } });
54
+ Object.defineProperty(exports, "RECON_VERSION", { enumerable: true, get: function () { return fundingRecon_ts_1.RECON_VERSION; } });
55
+ Object.defineProperty(exports, "reconcile", { enumerable: true, get: function () { return fundingRecon_ts_1.reconcile; } });
56
+ Object.defineProperty(exports, "verifyReconReceipt", { enumerable: true, get: function () { return fundingRecon_ts_1.verifyReconReceipt; } });
57
+ var fillLink_ts_1 = require("./fillLink.js");
58
+ Object.defineProperty(exports, "LINK_KIND", { enumerable: true, get: function () { return fillLink_ts_1.LINK_KIND; } });
59
+ Object.defineProperty(exports, "LINK_VERSION", { enumerable: true, get: function () { return fillLink_ts_1.LINK_VERSION; } });
60
+ Object.defineProperty(exports, "buildLink", { enumerable: true, get: function () { return fillLink_ts_1.buildLink; } });
61
+ Object.defineProperty(exports, "computeLink", { enumerable: true, get: function () { return fillLink_ts_1.computeLink; } });
62
+ Object.defineProperty(exports, "linkInputs", { enumerable: true, get: function () { return fillLink_ts_1.linkInputs; } });
63
+ Object.defineProperty(exports, "normaliseSelector", { enumerable: true, get: function () { return fillLink_ts_1.normaliseSelector; } });
64
+ Object.defineProperty(exports, "selectFills", { enumerable: true, get: function () { return fillLink_ts_1.selectFills; } });
65
+ Object.defineProperty(exports, "simFromReceipt", { enumerable: true, get: function () { return fillLink_ts_1.simFromReceipt; } });
66
+ Object.defineProperty(exports, "verifyLink", { enumerable: true, get: function () { return fillLink_ts_1.verifyLink; } });
27
67
  var receipt_ts_1 = require("./receipt.js");
28
68
  Object.defineProperty(exports, "RECEIPT_KIND", { enumerable: true, get: function () { return receipt_ts_1.RECEIPT_KIND; } });
29
69
  Object.defineProperty(exports, "RECEIPT_STATEMENT", { enumerable: true, get: function () { return receipt_ts_1.RECEIPT_STATEMENT; } });
@@ -40,6 +80,11 @@ Object.defineProperty(exports, "simulateInputs", { enumerable: true, get: functi
40
80
  Object.defineProperty(exports, "snapshotRows", { enumerable: true, get: function () { return receipt_ts_1.snapshotRows; } });
41
81
  Object.defineProperty(exports, "verifyReceipt", { enumerable: true, get: function () { return receipt_ts_1.verifyReceipt; } });
42
82
  Object.defineProperty(exports, "verifyReceiptAt", { enumerable: true, get: function () { return receipt_ts_1.verifyReceiptAt; } });
83
+ Object.defineProperty(exports, "ResourceLimitError", { enumerable: true, get: function () { return receipt_ts_1.ResourceLimitError; } });
84
+ Object.defineProperty(exports, "UnsupportedVerificationError", { enumerable: true, get: function () { return receipt_ts_1.UnsupportedVerificationError; } });
85
+ Object.defineProperty(exports, "MissingInputsError", { enumerable: true, get: function () { return receipt_ts_1.MissingInputsError; } });
86
+ Object.defineProperty(exports, "InvalidLimitError", { enumerable: true, get: function () { return receipt_ts_1.InvalidLimitError; } });
87
+ Object.defineProperty(exports, "NoVerdictError", { enumerable: true, get: function () { return receipt_ts_1.NoVerdictError; } });
43
88
  Object.defineProperty(exports, "writeReceiptDir", { enumerable: true, get: function () { return receipt_ts_1.writeReceiptDir; } });
44
89
  var costs_ts_1 = require("./vendor/costs.js");
45
90
  Object.defineProperty(exports, "executionCost", { enumerable: true, get: function () { return costs_ts_1.executionCost; } });
@@ -1,4 +1,5 @@
1
1
  /** Re-derive a simulation receipt. The check is verified and reproducible. */
2
+ import type { ClientMetaEntry } from "./clientMeta.ts";
2
3
  import { GuardSession, type Guards, type MarketSnapshot } from "./guards.ts";
3
4
  import { type GuardedSimulateResult } from "./guarded.ts";
4
5
  import { type CostBreakdown } from "./vendor/costs.ts";
@@ -8,6 +9,11 @@ export declare const RECEIPT_VERSION = 5;
8
9
  export interface VerifyReport {
9
10
  status: "VERIFIED" | "MISMATCH";
10
11
  mismatches: string[];
12
+ /** Set on kinds whose VERIFIED covers less than a full re-run. A calibration report sets
13
+ * "self-consistency-only" with venue_authenticated false: arithmetic and hashes reproduce from
14
+ * the supplied inputs, and nothing is matched to a venue. Absent on other kinds. */
15
+ scope?: "self-consistency-only";
16
+ venue_authenticated?: false;
11
17
  }
12
18
  export declare function verifyReceipt(receipt: unknown, manifest: Uint8Array, inputs: Uint8Array): VerifyReport;
13
19
  export declare function canonical(value: unknown): string;
@@ -24,7 +30,7 @@ export declare function exampleInputs(): Record<string, unknown>;
24
30
  export declare function limitsPayload(limits: Guards): Record<string, unknown>;
25
31
  export declare function snapshotRows(snapshot: MarketSnapshot): Record<string, unknown>[];
26
32
  export declare function simulateInputs(inputs: Record<string, unknown>): Record<string, unknown>;
27
- export declare function buildReceiptFiles(inputs: Record<string, unknown>, result: Record<string, unknown>, limits: Record<string, unknown>, marketSnapshot: Record<string, unknown>[]): BuiltReceipt;
33
+ export declare function buildReceiptFiles(inputs: Record<string, unknown>, result: Record<string, unknown>, limits: Record<string, unknown>, marketSnapshot: Record<string, unknown>[], clientMetadata?: ClientMetaEntry[]): BuiltReceipt;
28
34
  export declare function writeReceiptDir(directory: string, built: BuiltReceipt): string;
29
35
  export declare function buildReceiptDir(directory: string, inputs?: Record<string, unknown>, limits?: Guards | null, snapshot?: MarketSnapshot | null): string;
30
36
  /**
@@ -42,4 +48,45 @@ export declare function buildReceiptDir(directory: string, inputs?: Record<strin
42
48
  */
43
49
  export declare function buildGuardedReceipt(directory: string, inputs: Record<string, unknown>, result: GuardedSimulateResult | Record<string, unknown>, session: GuardSession, snapshot?: MarketSnapshot | null): string;
44
50
  /** Read a receipt.json file, or a directory that contains one, and check it. */
45
- export declare function verifyReceiptAt(path: string): VerifyReport;
51
+ /**
52
+ * Base for "no verdict reached": the check did not run to VERIFIED or MISMATCH. Thrown, never
53
+ * folded into a report, and says nothing about whether the record is valid.
54
+ */
55
+ export declare class NoVerdictError extends Error {
56
+ constructor(message: string);
57
+ }
58
+ /**
59
+ * A file is larger than the caller's explicit read limit. Thrown, never folded into a
60
+ * MISMATCH or VERIFIED report: "too big to check" is a resource failure, not a verdict.
61
+ */
62
+ export declare class ResourceLimitError extends NoVerdictError {
63
+ constructor(message: string);
64
+ }
65
+ /** The record is of a kind this function does not check. No verdict was reached: this is neither
66
+ * VERIFIED nor MISMATCH, and says nothing about whether the record is valid. */
67
+ export declare class UnsupportedVerificationError extends NoVerdictError {
68
+ constructor(message: string);
69
+ }
70
+ /** The inputs a record is checked against were not supplied (not found beside it). No verdict:
71
+ * a missing file is not evidence that the record is invalid. */
72
+ export declare class MissingInputsError extends NoVerdictError {
73
+ constructor(message: string);
74
+ }
75
+ /** The caller's `maxBytes` is not a positive safe integer. A caller error, thrown before any file
76
+ * is read: it is neither a verdict nor a resource failure. */
77
+ export declare class InvalidLimitError extends RangeError {
78
+ constructor(message: string);
79
+ }
80
+ export interface VerifyAtOptions {
81
+ /** Opt-in per-file read limit for receipt.json, manifest.json and inputs.json. Default: none. */
82
+ maxBytes?: number;
83
+ }
84
+ /** Reads with a shared descriptor reader; exported only so a test can inject a growing file. */
85
+ export type ChunkReader = (buffer: Buffer, length: number) => number;
86
+ /**
87
+ * Read chunks until end of file or one byte past ``maxBytes``. The size comes from the bytes
88
+ * actually read, never from a stat, so a file that grows or is replaced after any size check is
89
+ * still bounded, and a large limit never allocates for the limit.
90
+ */
91
+ export declare function readChunksCapped(read: ChunkReader, maxBytes: number, name: string): Buffer;
92
+ export declare function verifyReceiptAt(path: string, options?: VerifyAtOptions): VerifyReport;