@secondlayer/subgraphs 7.0.2 → 7.0.4
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/dist/index.d.ts +19 -4
- package/dist/index.js +5 -5
- package/dist/index.js.map +12 -12
- package/dist/runtime/replay.d.ts +3 -0
- package/dist/runtime/replay.js +5 -5
- package/dist/runtime/replay.js.map +5 -5
- package/dist/schema/index.d.ts +6 -2
- package/dist/schema/index.js +5 -5
- package/dist/schema/index.js.map +5 -5
- package/dist/testing/index.d.ts +9 -2
- package/dist/testing/index.js +5 -5
- package/dist/testing/index.js.map +8 -8
- package/dist/types.d.ts +3 -2
- package/dist/validate.d.ts +3 -2
- package/dist/verification.d.ts +4 -2
- package/dist/verification.js +5 -5
- package/dist/verification.js.map +3 -3
- package/dist/verify/index.d.ts +8 -2
- package/dist/verify/index.js +5 -5
- package/dist/verify/index.js.map +9 -9
- package/package.json +4 -4
package/dist/types.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { AssetIdentifier } from "@secondlayer/stacks/filters";
|
|
|
15
15
|
* first answer forever, so it is opt-in and never inferred.
|
|
16
16
|
*/
|
|
17
17
|
type ChainReadCacheMode = "per-block" | "contract-constant";
|
|
18
|
+
/** Options for a contract read, such as cache mode. */
|
|
18
19
|
type ChainReadOptions = {
|
|
19
20
|
cache?: ChainReadCacheMode;
|
|
20
21
|
};
|
|
@@ -61,7 +62,7 @@ interface SubgraphTable {
|
|
|
61
62
|
/** Unique key constraints (each entry is an array of column names). Required for upsert. */
|
|
62
63
|
uniqueKeys?: readonly (readonly string[])[];
|
|
63
64
|
}
|
|
64
|
-
/**
|
|
65
|
+
/** Maps table names to table definitions. */
|
|
65
66
|
type SubgraphSchema = Record<string, SubgraphTable>;
|
|
66
67
|
/** STX event filters */
|
|
67
68
|
interface StxTransferFilter {
|
|
@@ -333,7 +334,7 @@ type UnpinnedPrintEventFilter = PrintEventFields & {
|
|
|
333
334
|
* `prints`; trait and unpinned sources may omit it.
|
|
334
335
|
*/
|
|
335
336
|
type PrintEventFilter = PinnedPrintEventFilter | TraitPrintEventFilter | UnpinnedPrintEventFilter;
|
|
336
|
-
/**
|
|
337
|
+
/** A subgraph filter, discriminated on `type`. */
|
|
337
338
|
type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter | NestedContractCallFilter | VarSetFilter | MapWriteFilter;
|
|
338
339
|
/** Transaction metadata available in handlers */
|
|
339
340
|
interface TxMeta {
|
package/dist/validate.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { AssetIdentifier } from "@secondlayer/stacks/filters";
|
|
|
16
16
|
* first answer forever, so it is opt-in and never inferred.
|
|
17
17
|
*/
|
|
18
18
|
type ChainReadCacheMode = "per-block" | "contract-constant";
|
|
19
|
+
/** Options for a contract read, such as cache mode. */
|
|
19
20
|
type ChainReadOptions = {
|
|
20
21
|
cache?: ChainReadCacheMode;
|
|
21
22
|
};
|
|
@@ -62,7 +63,7 @@ interface SubgraphTable {
|
|
|
62
63
|
/** Unique key constraints (each entry is an array of column names). Required for upsert. */
|
|
63
64
|
uniqueKeys?: readonly (readonly string[])[];
|
|
64
65
|
}
|
|
65
|
-
/**
|
|
66
|
+
/** Maps table names to table definitions. */
|
|
66
67
|
type SubgraphSchema = Record<string, SubgraphTable>;
|
|
67
68
|
/** STX event filters */
|
|
68
69
|
interface StxTransferFilter {
|
|
@@ -293,7 +294,7 @@ type UnpinnedPrintEventFilter = PrintEventFields & {
|
|
|
293
294
|
* `prints`; trait and unpinned sources may omit it.
|
|
294
295
|
*/
|
|
295
296
|
type PrintEventFilter = PinnedPrintEventFilter | TraitPrintEventFilter | UnpinnedPrintEventFilter;
|
|
296
|
-
/**
|
|
297
|
+
/** A subgraph filter, discriminated on `type`. */
|
|
297
298
|
type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter | NestedContractCallFilter | VarSetFilter | MapWriteFilter;
|
|
298
299
|
/** Transaction metadata available in handlers */
|
|
299
300
|
interface TxMeta {
|
package/dist/verification.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { AssetIdentifier } from "@secondlayer/stacks/filters";
|
|
|
16
16
|
* first answer forever, so it is opt-in and never inferred.
|
|
17
17
|
*/
|
|
18
18
|
type ChainReadCacheMode = "per-block" | "contract-constant";
|
|
19
|
+
/** Options for a contract read, such as cache mode. */
|
|
19
20
|
type ChainReadOptions = {
|
|
20
21
|
cache?: ChainReadCacheMode;
|
|
21
22
|
};
|
|
@@ -62,7 +63,7 @@ interface SubgraphTable {
|
|
|
62
63
|
/** Unique key constraints (each entry is an array of column names). Required for upsert. */
|
|
63
64
|
uniqueKeys?: readonly (readonly string[])[];
|
|
64
65
|
}
|
|
65
|
-
/**
|
|
66
|
+
/** Maps table names to table definitions. */
|
|
66
67
|
type SubgraphSchema = Record<string, SubgraphTable>;
|
|
67
68
|
/** STX event filters */
|
|
68
69
|
interface StxTransferFilter {
|
|
@@ -293,7 +294,7 @@ type UnpinnedPrintEventFilter = PrintEventFields & {
|
|
|
293
294
|
* `prints`; trait and unpinned sources may omit it.
|
|
294
295
|
*/
|
|
295
296
|
type PrintEventFilter = PinnedPrintEventFilter | TraitPrintEventFilter | UnpinnedPrintEventFilter;
|
|
296
|
-
/**
|
|
297
|
+
/** A subgraph filter, discriminated on `type`. */
|
|
297
298
|
type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter | NestedContractCallFilter | VarSetFilter | MapWriteFilter;
|
|
298
299
|
/** Transaction metadata available in handlers */
|
|
299
300
|
interface TxMeta {
|
|
@@ -416,6 +417,7 @@ declare function deriveVerification(def: Pick<SubgraphDefinition, "sources" | "b
|
|
|
416
417
|
* contract is enforced, and the scan broke it.
|
|
417
418
|
*/
|
|
418
419
|
declare function isDeterminismViolation(v: SubgraphVerification): boolean;
|
|
420
|
+
/** What a pin is computed from: schema hash, handler code, network. */
|
|
419
421
|
interface PinInput {
|
|
420
422
|
/** Existing `schema_hash` (name + schema + sources). */
|
|
421
423
|
schemaHash: string;
|
package/dist/verification.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
// package.json
|
|
4
4
|
var package_default = {
|
|
5
5
|
name: "@secondlayer/subgraphs",
|
|
6
|
-
version: "7.0.
|
|
6
|
+
version: "7.0.4",
|
|
7
7
|
description: "Describe the Stacks data you want as one TypeScript file; it fills itself and survives reorgs.",
|
|
8
8
|
license: "MIT",
|
|
9
9
|
repository: {
|
|
@@ -63,9 +63,9 @@ var package_default = {
|
|
|
63
63
|
prepublishOnly: "bun run build"
|
|
64
64
|
},
|
|
65
65
|
dependencies: {
|
|
66
|
-
"@secondlayer/shared": "^
|
|
67
|
-
"@secondlayer/stacks": "^6.2.
|
|
68
|
-
"@secondlayer/verify": "^0.5.
|
|
66
|
+
"@secondlayer/shared": "^13.0.0",
|
|
67
|
+
"@secondlayer/stacks": "^6.2.2",
|
|
68
|
+
"@secondlayer/verify": "^0.5.4",
|
|
69
69
|
esbuild: "^0.28.2",
|
|
70
70
|
kysely: "0.28.17",
|
|
71
71
|
zod: "^4.3.6"
|
|
@@ -279,5 +279,5 @@ export {
|
|
|
279
279
|
pinPreimage
|
|
280
280
|
};
|
|
281
281
|
|
|
282
|
-
//# debugId=
|
|
282
|
+
//# debugId=5508A61962BAC6F264756E2164756E21
|
|
283
283
|
//# sourceMappingURL=verification.js.map
|
package/dist/verification.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/verification.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Verifiable subgraphs: the determinism contract, the derived level and the\n * pin. Pure (node:crypto only) so the bundler's deploy scan, the API and the\n * runtime realm all read the same rules.\n *\n * A subgraph is never configured as verifiable. Its level is derived from\n * its sources plus a scan of the bundled handler, and only a subgraph whose\n * every input is provable today (`state`: named state writes) has the contract\n * enforced. Everything else gets the same findings as advice.\n */\nimport { createHash } from \"node:crypto\";\nimport type { SubgraphVerification } from \"@secondlayer/shared/schemas/subgraphs\";\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport type { SubgraphDefinition, SubgraphFilter } from \"./types.ts\";\n\nexport type { SubgraphVerification };\n\n/** Runtime identity baked into every pin: matcher, decode and flush semantics. */\nexport const SUBGRAPHS_RUNTIME: string = `@secondlayer/subgraphs@${pkg.version}`;\n\n// ── Determinism contract ────────────────────────────────────────────────\n\n/**\n * Globals a handler may not touch, with the reason shown to the developer.\n * The deploy scan reports them; the realm replaces each with a getter that\n * throws `NondeterminismError`.\n */\nexport const FORBIDDEN_GLOBALS: Readonly<Record<string, string>> = {\n\tDate: \"wall-clock time differs per run\",\n\tperformance: \"timers differ per run\",\n\tprocess: \"host environment differs per run\",\n\tfetch: \"network reads are not chain inputs\",\n\tcrypto: \"randomness differs per run\",\n\tsetTimeout: \"scheduling order differs per run\",\n\tsetInterval: \"scheduling order differs per run\",\n\tsetImmediate: \"scheduling order differs per run\",\n\tclearTimeout: \"scheduling order differs per run\",\n\tclearInterval: \"scheduling order differs per run\",\n\tqueueMicrotask: \"scheduling order differs per run\",\n\tWeakRef: \"garbage collection timing differs per run\",\n\tFinalizationRegistry: \"garbage collection timing differs per run\",\n\tAtomics: \"shared memory is not single-threaded\",\n\tSharedArrayBuffer: \"shared memory is not single-threaded\",\n\tIntl: \"locale and time zone data differ per host\",\n\tTemporal: \"locale and time zone data differ per host\",\n\teval: \"generated code hides inputs from the scan\",\n\tWebAssembly: \"compiled code hides inputs from the scan\",\n\tShadowRealm: \"a nested realm escapes the allow-list\",\n\trequire: \"imports must be bundled into the handler\",\n};\n\n/**\n * Globals a handler may use: ECMAScript built-ins whose results are fully\n * specified, plus deterministic host encoders. `Math` is narrowed separately\n * ({@link ALLOWED_MATH}).\n */\nexport const ALLOWED_GLOBALS: readonly string[] = [\n\t\"undefined\",\n\t\"NaN\",\n\t\"Infinity\",\n\t\"globalThis\",\n\t\"isNaN\",\n\t\"isFinite\",\n\t\"parseInt\",\n\t\"parseFloat\",\n\t\"decodeURI\",\n\t\"decodeURIComponent\",\n\t\"encodeURI\",\n\t\"encodeURIComponent\",\n\t\"escape\",\n\t\"unescape\",\n\t\"Object\",\n\t\"Function\",\n\t\"Array\",\n\t\"Number\",\n\t\"Boolean\",\n\t\"String\",\n\t\"Symbol\",\n\t\"BigInt\",\n\t\"Math\",\n\t\"JSON\",\n\t\"Reflect\",\n\t\"Proxy\",\n\t\"Promise\",\n\t\"Map\",\n\t\"Set\",\n\t\"WeakMap\",\n\t\"WeakSet\",\n\t\"RegExp\",\n\t\"Iterator\",\n\t\"DisposableStack\",\n\t\"AsyncDisposableStack\",\n\t\"Error\",\n\t\"AggregateError\",\n\t\"SuppressedError\",\n\t\"EvalError\",\n\t\"RangeError\",\n\t\"ReferenceError\",\n\t\"SyntaxError\",\n\t\"TypeError\",\n\t\"URIError\",\n\t\"ArrayBuffer\",\n\t\"DataView\",\n\t\"Int8Array\",\n\t\"Uint8Array\",\n\t\"Uint8ClampedArray\",\n\t\"Int16Array\",\n\t\"Uint16Array\",\n\t\"Int32Array\",\n\t\"Uint32Array\",\n\t\"Float16Array\",\n\t\"Float32Array\",\n\t\"Float64Array\",\n\t\"BigInt64Array\",\n\t\"BigUint64Array\",\n\t\"TextEncoder\",\n\t\"TextDecoder\",\n\t\"atob\",\n\t\"btoa\",\n\t\"console\",\n];\n\n/** `Math` members whose results are exact on every engine. The rest\n * (`sin`, `pow`, `log`, …) are implementation-approximated. */\nexport const ALLOWED_MATH: readonly string[] = [\n\t\"abs\",\n\t\"min\",\n\t\"max\",\n\t\"floor\",\n\t\"ceil\",\n\t\"trunc\",\n\t\"sign\",\n\t\"round\",\n\t\"E\",\n\t\"LN10\",\n\t\"LN2\",\n\t\"LOG10E\",\n\t\"LOG2E\",\n\t\"PI\",\n\t\"SQRT1_2\",\n\t\"SQRT2\",\n];\n\n/** Methods whose output depends on the host's locale data. */\nexport const LOCALE_METHODS: readonly string[] = [\n\t\"toLocaleString\",\n\t\"toLocaleDateString\",\n\t\"toLocaleTimeString\",\n\t\"toLocaleUpperCase\",\n\t\"toLocaleLowerCase\",\n\t\"localeCompare\",\n];\n\n/**\n * One thing the deploy scan found in a bundled handler.\n *\n * - `nondeterministic`: breaks the determinism contract. Fails the deploy of\n * a state subgraph; advice for everything else.\n * - `needs-events`: deterministic, but reads something only re-execution proofs cover\n * (`ctx.client`). Raises the level instead of failing.\n */\nexport interface HandlerFinding {\n\tkind: \"nondeterministic\" | \"needs-events\";\n\t/** What was used, e.g. `Date`, `Math.random`, `import()`, `ctx.client`. */\n\tname: string;\n\treason: string;\n\t/** Original source file when a sourcemap was available, else the bundle. */\n\tfile: string;\n\t/** 1-based. */\n\tline: number;\n\t/** 1-based. */\n\tcolumn: number;\n}\n\n/** Formats a handler finding as `file:line:column name: reason`. */\nexport function formatFinding(f: HandlerFinding): string {\n\treturn `${f.file}:${f.line}:${f.column} ${f.name}: ${f.reason}`;\n}\n\n// ── Derived level ───────────────────────────────────────────────────────\n\n/**\n * Sources whose every field is a named state write: provable per block from\n * the header-backed witness plus `state_writes`. Not `map_insert`: storage\n * holds `(some v)` for an insert and a set alike, so telling them apart takes\n * re-execution (event proofs).\n */\nconst STATE_SOURCE_TYPES: ReadonlySet<string> = new Set([\n\t\"var_set\",\n\t\"map_set\",\n\t\"map_delete\",\n]);\n\nconst LEVEL_RANK = { state: 0, events: 1, none: 2 } as const;\n\n/** Handler findings listed in `reasons`; the rest are counted. */\nconst MAX_LISTED_FINDINGS = 10;\n\n/**\n * Derive how far a subgraph's rows can be checked. Level = the highest any\n * source or handler read needs. `reasons` lists everything standing between\n * the subgraph and checkable rows; a `state` subgraph with any reason is\n * refused at deploy, so every stored `state` row has none. Never configured,\n * never a flag.\n */\nexport function deriveVerification(\n\tdef: Pick<SubgraphDefinition, \"sources\" | \"backfillMode\">,\n\tfindings: readonly HandlerFinding[] = [],\n): SubgraphVerification {\n\tlet level: keyof typeof LEVEL_RANK = \"state\";\n\tconst raise = (to: keyof typeof LEVEL_RANK) => {\n\t\tif (LEVEL_RANK[to] > LEVEL_RANK[level]) level = to;\n\t};\n\tconst reasons: string[] = [];\n\n\tfor (const [name, source] of Object.entries(def.sources ?? {})) {\n\t\tconst filter = source as SubgraphFilter & { trait?: string };\n\t\tif (filter.trait) {\n\t\t\traise(\"none\");\n\t\t\treasons.push(\n\t\t\t\t`source \"${name}\": trait scope needs a proven contract registry`,\n\t\t\t);\n\t\t} else if (filter.type === \"map_insert\") {\n\t\t\traise(\"events\");\n\t\t\treasons.push(\n\t\t\t\t`map_insert source \"${name}\": map_insert vs map_set needs event proofs`,\n\t\t\t);\n\t\t} else if (!STATE_SOURCE_TYPES.has(filter.type)) {\n\t\t\traise(\"events\");\n\t\t\treasons.push(`${filter.type} source \"${name}\" needs event proofs`);\n\t\t}\n\t}\n\tif (def.backfillMode === \"concurrent\") {\n\t\traise(\"none\");\n\t\treasons.push(\"backfillMode concurrent: tip-first order is not chain order\");\n\t}\n\tif (findings.some((f) => f.kind === \"needs-events\")) raise(\"events\");\n\t// A large bundled library can trip dozens of findings; list a few.\n\tfor (const f of findings.slice(0, MAX_LISTED_FINDINGS)) {\n\t\treasons.push(\n\t\t\tf.kind === \"needs-events\"\n\t\t\t\t? `${formatFinding(f)} (needs event proofs)`\n\t\t\t\t: formatFinding(f),\n\t\t);\n\t}\n\tif (findings.length > MAX_LISTED_FINDINGS) {\n\t\treasons.push(\n\t\t\t`…and ${findings.length - MAX_LISTED_FINDINGS} more handler findings`,\n\t\t);\n\t}\n\n\treturn {\n\t\tlevel,\n\t\treasons,\n\t\tunproven:\n\t\t\treasons.length === 0\n\t\t\t\t? [\n\t\t\t\t\t\t\"tx attribution of writes: event.tx, _tx_id (needs event proofs)\",\n\t\t\t\t\t\t\"intermediate writes within a block (needs event proofs)\",\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t};\n}\n\n/**\n * Tells whether a deploy must be refused for breaking determinism.\n *\n * It is refused when the sources are provable (`state`), so the determinism\n * contract is enforced, and the scan broke it.\n */\nexport function isDeterminismViolation(v: SubgraphVerification): boolean {\n\treturn v.level === \"state\" && v.reasons.length > 0;\n}\n\n// ── Pin ─────────────────────────────────────────────────────────────────\n\nexport interface PinInput {\n\t/** Existing `schema_hash` (name + schema + sources). */\n\tschemaHash: string;\n\t/** Bundled ESM exactly as stored in `subgraphs.handler_code`. */\n\thandlerCode: string;\n\tstartBlock?: number | null;\n\tnetwork: string;\n\t/** Defaults to {@link SUBGRAPHS_RUNTIME}. */\n\truntime?: string;\n}\n\nfunction sha256(input: string): string {\n\treturn createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\n/** What a pin commits to, as stored in `pin_preimage`. */\nexport interface PinFields {\n\t/** sha256 of the bundled handler, hex. */\n\thandlerHash: string;\n\tnetwork: string;\n\truntime: string;\n\tschemaHash: string;\n\tstartBlock: number | null;\n}\n\n/**\n * The canonical JSON a pin is the sha256 of: fixed key order, primitives\n * only. Stored beside the pin so anyone can recompute it from the served\n * handler code.\n */\nexport function pinPreimage(input: PinInput): string {\n\tconst fields: PinFields = {\n\t\thandlerHash: sha256(input.handlerCode),\n\t\tnetwork: input.network,\n\t\truntime: input.runtime ?? SUBGRAPHS_RUNTIME,\n\t\tschemaHash: input.schemaHash,\n\t\tstartBlock: input.startBlock ?? null,\n\t};\n\treturn JSON.stringify(fields);\n}\n\n/**\n * Content hash over everything that shapes a subgraph's rows. Unlike\n * `schema_hash`, it changes with the handler, `startBlock` and runtime, so\n * two deploys with the same pin produce the same rows from the same chain.\n */\nexport function computePin(input: PinInput): string {\n\treturn sha256(pinPreimage(input));\n}\n"
|
|
5
|
+
"/**\n * Verifiable subgraphs: the determinism contract, the derived level and the\n * pin. Pure (node:crypto only) so the bundler's deploy scan, the API and the\n * runtime realm all read the same rules.\n *\n * A subgraph is never configured as verifiable. Its level is derived from\n * its sources plus a scan of the bundled handler, and only a subgraph whose\n * every input is provable today (`state`: named state writes) has the contract\n * enforced. Everything else gets the same findings as advice.\n */\nimport { createHash } from \"node:crypto\";\nimport type { SubgraphVerification } from \"@secondlayer/shared/schemas/subgraphs\";\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport type { SubgraphDefinition, SubgraphFilter } from \"./types.ts\";\n\nexport type { SubgraphVerification };\n\n/** Runtime identity baked into every pin: matcher, decode and flush semantics. */\nexport const SUBGRAPHS_RUNTIME: string = `@secondlayer/subgraphs@${pkg.version}`;\n\n// ── Determinism contract ────────────────────────────────────────────────\n\n/**\n * Globals a handler may not touch, with the reason shown to the developer.\n * The deploy scan reports them; the realm replaces each with a getter that\n * throws `NondeterminismError`.\n */\nexport const FORBIDDEN_GLOBALS: Readonly<Record<string, string>> = {\n\tDate: \"wall-clock time differs per run\",\n\tperformance: \"timers differ per run\",\n\tprocess: \"host environment differs per run\",\n\tfetch: \"network reads are not chain inputs\",\n\tcrypto: \"randomness differs per run\",\n\tsetTimeout: \"scheduling order differs per run\",\n\tsetInterval: \"scheduling order differs per run\",\n\tsetImmediate: \"scheduling order differs per run\",\n\tclearTimeout: \"scheduling order differs per run\",\n\tclearInterval: \"scheduling order differs per run\",\n\tqueueMicrotask: \"scheduling order differs per run\",\n\tWeakRef: \"garbage collection timing differs per run\",\n\tFinalizationRegistry: \"garbage collection timing differs per run\",\n\tAtomics: \"shared memory is not single-threaded\",\n\tSharedArrayBuffer: \"shared memory is not single-threaded\",\n\tIntl: \"locale and time zone data differ per host\",\n\tTemporal: \"locale and time zone data differ per host\",\n\teval: \"generated code hides inputs from the scan\",\n\tWebAssembly: \"compiled code hides inputs from the scan\",\n\tShadowRealm: \"a nested realm escapes the allow-list\",\n\trequire: \"imports must be bundled into the handler\",\n};\n\n/**\n * Globals a handler may use: ECMAScript built-ins whose results are fully\n * specified, plus deterministic host encoders. `Math` is narrowed separately\n * ({@link ALLOWED_MATH}).\n */\nexport const ALLOWED_GLOBALS: readonly string[] = [\n\t\"undefined\",\n\t\"NaN\",\n\t\"Infinity\",\n\t\"globalThis\",\n\t\"isNaN\",\n\t\"isFinite\",\n\t\"parseInt\",\n\t\"parseFloat\",\n\t\"decodeURI\",\n\t\"decodeURIComponent\",\n\t\"encodeURI\",\n\t\"encodeURIComponent\",\n\t\"escape\",\n\t\"unescape\",\n\t\"Object\",\n\t\"Function\",\n\t\"Array\",\n\t\"Number\",\n\t\"Boolean\",\n\t\"String\",\n\t\"Symbol\",\n\t\"BigInt\",\n\t\"Math\",\n\t\"JSON\",\n\t\"Reflect\",\n\t\"Proxy\",\n\t\"Promise\",\n\t\"Map\",\n\t\"Set\",\n\t\"WeakMap\",\n\t\"WeakSet\",\n\t\"RegExp\",\n\t\"Iterator\",\n\t\"DisposableStack\",\n\t\"AsyncDisposableStack\",\n\t\"Error\",\n\t\"AggregateError\",\n\t\"SuppressedError\",\n\t\"EvalError\",\n\t\"RangeError\",\n\t\"ReferenceError\",\n\t\"SyntaxError\",\n\t\"TypeError\",\n\t\"URIError\",\n\t\"ArrayBuffer\",\n\t\"DataView\",\n\t\"Int8Array\",\n\t\"Uint8Array\",\n\t\"Uint8ClampedArray\",\n\t\"Int16Array\",\n\t\"Uint16Array\",\n\t\"Int32Array\",\n\t\"Uint32Array\",\n\t\"Float16Array\",\n\t\"Float32Array\",\n\t\"Float64Array\",\n\t\"BigInt64Array\",\n\t\"BigUint64Array\",\n\t\"TextEncoder\",\n\t\"TextDecoder\",\n\t\"atob\",\n\t\"btoa\",\n\t\"console\",\n];\n\n/** `Math` members whose results are exact on every engine. The rest\n * (`sin`, `pow`, `log`, …) are implementation-approximated. */\nexport const ALLOWED_MATH: readonly string[] = [\n\t\"abs\",\n\t\"min\",\n\t\"max\",\n\t\"floor\",\n\t\"ceil\",\n\t\"trunc\",\n\t\"sign\",\n\t\"round\",\n\t\"E\",\n\t\"LN10\",\n\t\"LN2\",\n\t\"LOG10E\",\n\t\"LOG2E\",\n\t\"PI\",\n\t\"SQRT1_2\",\n\t\"SQRT2\",\n];\n\n/** Methods whose output depends on the host's locale data. */\nexport const LOCALE_METHODS: readonly string[] = [\n\t\"toLocaleString\",\n\t\"toLocaleDateString\",\n\t\"toLocaleTimeString\",\n\t\"toLocaleUpperCase\",\n\t\"toLocaleLowerCase\",\n\t\"localeCompare\",\n];\n\n/**\n * One thing the deploy scan found in a bundled handler.\n *\n * - `nondeterministic`: breaks the determinism contract. Fails the deploy of\n * a state subgraph; advice for everything else.\n * - `needs-events`: deterministic, but reads something only re-execution proofs cover\n * (`ctx.client`). Raises the level instead of failing.\n */\nexport interface HandlerFinding {\n\tkind: \"nondeterministic\" | \"needs-events\";\n\t/** What was used, e.g. `Date`, `Math.random`, `import()`, `ctx.client`. */\n\tname: string;\n\treason: string;\n\t/** Original source file when a sourcemap was available, else the bundle. */\n\tfile: string;\n\t/** 1-based. */\n\tline: number;\n\t/** 1-based. */\n\tcolumn: number;\n}\n\n/** Formats a handler finding as `file:line:column name: reason`. */\nexport function formatFinding(f: HandlerFinding): string {\n\treturn `${f.file}:${f.line}:${f.column} ${f.name}: ${f.reason}`;\n}\n\n// ── Derived level ───────────────────────────────────────────────────────\n\n/**\n * Sources whose every field is a named state write: provable per block from\n * the header-backed witness plus `state_writes`. Not `map_insert`: storage\n * holds `(some v)` for an insert and a set alike, so telling them apart takes\n * re-execution (event proofs).\n */\nconst STATE_SOURCE_TYPES: ReadonlySet<string> = new Set([\n\t\"var_set\",\n\t\"map_set\",\n\t\"map_delete\",\n]);\n\nconst LEVEL_RANK = { state: 0, events: 1, none: 2 } as const;\n\n/** Handler findings listed in `reasons`; the rest are counted. */\nconst MAX_LISTED_FINDINGS = 10;\n\n/**\n * Derive how far a subgraph's rows can be checked. Level = the highest any\n * source or handler read needs. `reasons` lists everything standing between\n * the subgraph and checkable rows; a `state` subgraph with any reason is\n * refused at deploy, so every stored `state` row has none. Never configured,\n * never a flag.\n */\nexport function deriveVerification(\n\tdef: Pick<SubgraphDefinition, \"sources\" | \"backfillMode\">,\n\tfindings: readonly HandlerFinding[] = [],\n): SubgraphVerification {\n\tlet level: keyof typeof LEVEL_RANK = \"state\";\n\tconst raise = (to: keyof typeof LEVEL_RANK) => {\n\t\tif (LEVEL_RANK[to] > LEVEL_RANK[level]) level = to;\n\t};\n\tconst reasons: string[] = [];\n\n\tfor (const [name, source] of Object.entries(def.sources ?? {})) {\n\t\tconst filter = source as SubgraphFilter & { trait?: string };\n\t\tif (filter.trait) {\n\t\t\traise(\"none\");\n\t\t\treasons.push(\n\t\t\t\t`source \"${name}\": trait scope needs a proven contract registry`,\n\t\t\t);\n\t\t} else if (filter.type === \"map_insert\") {\n\t\t\traise(\"events\");\n\t\t\treasons.push(\n\t\t\t\t`map_insert source \"${name}\": map_insert vs map_set needs event proofs`,\n\t\t\t);\n\t\t} else if (!STATE_SOURCE_TYPES.has(filter.type)) {\n\t\t\traise(\"events\");\n\t\t\treasons.push(`${filter.type} source \"${name}\" needs event proofs`);\n\t\t}\n\t}\n\tif (def.backfillMode === \"concurrent\") {\n\t\traise(\"none\");\n\t\treasons.push(\"backfillMode concurrent: tip-first order is not chain order\");\n\t}\n\tif (findings.some((f) => f.kind === \"needs-events\")) raise(\"events\");\n\t// A large bundled library can trip dozens of findings; list a few.\n\tfor (const f of findings.slice(0, MAX_LISTED_FINDINGS)) {\n\t\treasons.push(\n\t\t\tf.kind === \"needs-events\"\n\t\t\t\t? `${formatFinding(f)} (needs event proofs)`\n\t\t\t\t: formatFinding(f),\n\t\t);\n\t}\n\tif (findings.length > MAX_LISTED_FINDINGS) {\n\t\treasons.push(\n\t\t\t`…and ${findings.length - MAX_LISTED_FINDINGS} more handler findings`,\n\t\t);\n\t}\n\n\treturn {\n\t\tlevel,\n\t\treasons,\n\t\tunproven:\n\t\t\treasons.length === 0\n\t\t\t\t? [\n\t\t\t\t\t\t\"tx attribution of writes: event.tx, _tx_id (needs event proofs)\",\n\t\t\t\t\t\t\"intermediate writes within a block (needs event proofs)\",\n\t\t\t\t\t]\n\t\t\t\t: [],\n\t};\n}\n\n/**\n * Tells whether a deploy must be refused for breaking determinism.\n *\n * It is refused when the sources are provable (`state`), so the determinism\n * contract is enforced, and the scan broke it.\n */\nexport function isDeterminismViolation(v: SubgraphVerification): boolean {\n\treturn v.level === \"state\" && v.reasons.length > 0;\n}\n\n// ── Pin ─────────────────────────────────────────────────────────────────\n\n/** What a pin is computed from: schema hash, handler code, network. */\nexport interface PinInput {\n\t/** Existing `schema_hash` (name + schema + sources). */\n\tschemaHash: string;\n\t/** Bundled ESM exactly as stored in `subgraphs.handler_code`. */\n\thandlerCode: string;\n\tstartBlock?: number | null;\n\tnetwork: string;\n\t/** Defaults to {@link SUBGRAPHS_RUNTIME}. */\n\truntime?: string;\n}\n\nfunction sha256(input: string): string {\n\treturn createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\n/** What a pin commits to, as stored in `pin_preimage`. */\nexport interface PinFields {\n\t/** sha256 of the bundled handler, hex. */\n\thandlerHash: string;\n\tnetwork: string;\n\truntime: string;\n\tschemaHash: string;\n\tstartBlock: number | null;\n}\n\n/**\n * The canonical JSON a pin is the sha256 of: fixed key order, primitives\n * only. Stored beside the pin so anyone can recompute it from the served\n * handler code.\n */\nexport function pinPreimage(input: PinInput): string {\n\tconst fields: PinFields = {\n\t\thandlerHash: sha256(input.handlerCode),\n\t\tnetwork: input.network,\n\t\truntime: input.runtime ?? SUBGRAPHS_RUNTIME,\n\t\tschemaHash: input.schemaHash,\n\t\tstartBlock: input.startBlock ?? null,\n\t};\n\treturn JSON.stringify(fields);\n}\n\n/**\n * Content hash over everything that shapes a subgraph's rows. Unlike\n * `schema_hash`, it changes with the handler, `startBlock` and runtime, so\n * two deploys with the same pin produce the same rows from the same chain.\n */\nexport function computePin(input: PinInput): string {\n\treturn sha256(pinPreimage(input));\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQO,IAAM,oBAA4B,0BAA0B,gBAAI;AAShE,IAAM,oBAAsD;AAAA,EAClE,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,cAAc;AAAA,EACd,cAAc;AAAA,EACd,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,SAAS;AAAA,EACT,sBAAsB;AAAA,EACtB,SAAS;AAAA,EACT,mBAAmB;AAAA,EACnB,MAAM;AAAA,EACN,UAAU;AAAA,EACV,MAAM;AAAA,EACN,aAAa;AAAA,EACb,aAAa;AAAA,EACb,SAAS;AACV;AAOO,IAAM,kBAAqC;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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AAc,CAAC,CACnB;AAAA,EACD;AAAA,EACA,IAAI,SAAS,SAAS,qBAAqB;AAAA,IAC1C,QAAQ,KACP,QAAQ,SAAS,SAAS,2CAC3B;AAAA,EACD;AAAA,EAEA,OAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,UACC,QAAQ,WAAW,IAChB;AAAA,MACA;AAAA,MACA;AAAA,IACD,IACC,CAAC;AAAA,EACN;AAAA;AASM,SAAS,sBAAsB,CAAC,GAAkC;AAAA,EACxE,OAAO,EAAE,UAAU,WAAW,EAAE,QAAQ,SAAS;AAAA;AAiBlD,SAAS,MAAM,CAAC,OAAuB;AAAA,EACtC,OAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA;AAkBhD,SAAS,WAAW,CAAC,OAAyB;AAAA,EACpD,MAAM,SAAoB;AAAA,IACzB,aAAa,OAAO,MAAM,WAAW;AAAA,IACrC,SAAS,MAAM;AAAA,IACf,SAAS,MAAM,WAAW;AAAA,IAC1B,YAAY,MAAM;AAAA,IAClB,YAAY,MAAM,cAAc;AAAA,EACjC;AAAA,EACA,OAAO,KAAK,UAAU,MAAM;AAAA;AAQtB,SAAS,UAAU,CAAC,OAAyB;AAAA,EACnD,OAAO,OAAO,YAAY,KAAK,CAAC;AAAA;",
|
|
8
|
+
"debugId": "5508A61962BAC6F264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/verify/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { AssetIdentifier } from "@secondlayer/stacks/filters";
|
|
|
16
16
|
* first answer forever, so it is opt-in and never inferred.
|
|
17
17
|
*/
|
|
18
18
|
type ChainReadCacheMode = "per-block" | "contract-constant";
|
|
19
|
+
/** Options for a contract read, such as cache mode. */
|
|
19
20
|
type ChainReadOptions = {
|
|
20
21
|
cache?: ChainReadCacheMode;
|
|
21
22
|
};
|
|
@@ -62,7 +63,7 @@ interface SubgraphTable {
|
|
|
62
63
|
/** Unique key constraints (each entry is an array of column names). Required for upsert. */
|
|
63
64
|
uniqueKeys?: readonly (readonly string[])[];
|
|
64
65
|
}
|
|
65
|
-
/**
|
|
66
|
+
/** Maps table names to table definitions. */
|
|
66
67
|
type SubgraphSchema = Record<string, SubgraphTable>;
|
|
67
68
|
/** STX event filters */
|
|
68
69
|
interface StxTransferFilter {
|
|
@@ -293,7 +294,7 @@ type UnpinnedPrintEventFilter = PrintEventFields & {
|
|
|
293
294
|
* `prints`; trait and unpinned sources may omit it.
|
|
294
295
|
*/
|
|
295
296
|
type PrintEventFilter = PinnedPrintEventFilter | TraitPrintEventFilter | UnpinnedPrintEventFilter;
|
|
296
|
-
/**
|
|
297
|
+
/** A subgraph filter, discriminated on `type`. */
|
|
297
298
|
type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter | NestedContractCallFilter | VarSetFilter | MapWriteFilter;
|
|
298
299
|
/** Transaction metadata available in handlers */
|
|
299
300
|
interface TxMeta {
|
|
@@ -370,6 +371,7 @@ interface ReplayFailure {
|
|
|
370
371
|
/** The source could not serve the input: unchecked, not disproven. */
|
|
371
372
|
unavailable?: boolean;
|
|
372
373
|
}
|
|
374
|
+
/** The outcome of a replay: pass or fail, blocks covered, failures. */
|
|
373
375
|
interface ReplayResult {
|
|
374
376
|
ok: boolean;
|
|
375
377
|
/** Set when the range starts after startBlock and a handler read or merged earlier rows. */
|
|
@@ -391,6 +393,7 @@ interface ReplayResult {
|
|
|
391
393
|
/** The first entry is the first broken link. */
|
|
392
394
|
failures: ReplayFailure[];
|
|
393
395
|
}
|
|
396
|
+
/** What to replay: proof source, handler bundle, and block range. */
|
|
394
397
|
interface ReplayOptions {
|
|
395
398
|
/** Needs `getStateWrites`: the names are what feed the handlers. */
|
|
396
399
|
source: ProofSource;
|
|
@@ -415,6 +418,7 @@ declare const REPLAY_WINDOW = 512;
|
|
|
415
418
|
declare function replayContracts(def: Pick<SubgraphDefinition, "sources">): string[] | {
|
|
416
419
|
error: string;
|
|
417
420
|
};
|
|
421
|
+
/** Whether a served pin matches the served bundle. */
|
|
418
422
|
type PinCheck = {
|
|
419
423
|
status: "ok";
|
|
420
424
|
notes: string[];
|
|
@@ -461,6 +465,7 @@ declare function replaySubgraph(opts: ReplayOptions): Promise<ReplayResult>;
|
|
|
461
465
|
* every handler wrapped to receive the {@link deterministicContext} facade.
|
|
462
466
|
*/
|
|
463
467
|
declare function loadDeterministicDefinition(handlerCode: string): Promise<SubgraphDefinition>;
|
|
468
|
+
/** A table row as a plain column-to-value record. */
|
|
464
469
|
type Row = Record<string, unknown>;
|
|
465
470
|
interface TableComparison {
|
|
466
471
|
table: string;
|
|
@@ -473,6 +478,7 @@ interface TableComparison {
|
|
|
473
478
|
/** The same digest over the served rows in the window. */
|
|
474
479
|
servedDigest: string;
|
|
475
480
|
}
|
|
481
|
+
/** Replayed tables compared with served tables, and any mismatches. */
|
|
476
482
|
interface RowComparison {
|
|
477
483
|
failures: ReplayFailure[];
|
|
478
484
|
tables: TableComparison[];
|
package/dist/verify/index.js
CHANGED
|
@@ -475,7 +475,7 @@ import { createHash } from "node:crypto";
|
|
|
475
475
|
// package.json
|
|
476
476
|
var package_default = {
|
|
477
477
|
name: "@secondlayer/subgraphs",
|
|
478
|
-
version: "7.0.
|
|
478
|
+
version: "7.0.4",
|
|
479
479
|
description: "Describe the Stacks data you want as one TypeScript file; it fills itself and survives reorgs.",
|
|
480
480
|
license: "MIT",
|
|
481
481
|
repository: {
|
|
@@ -535,9 +535,9 @@ var package_default = {
|
|
|
535
535
|
prepublishOnly: "bun run build"
|
|
536
536
|
},
|
|
537
537
|
dependencies: {
|
|
538
|
-
"@secondlayer/shared": "^
|
|
539
|
-
"@secondlayer/stacks": "^6.2.
|
|
540
|
-
"@secondlayer/verify": "^0.5.
|
|
538
|
+
"@secondlayer/shared": "^13.0.0",
|
|
539
|
+
"@secondlayer/stacks": "^6.2.2",
|
|
540
|
+
"@secondlayer/verify": "^0.5.4",
|
|
541
541
|
esbuild: "^0.28.2",
|
|
542
542
|
kysely: "0.28.17",
|
|
543
543
|
zod: "^4.3.6"
|
|
@@ -3346,5 +3346,5 @@ export {
|
|
|
3346
3346
|
replaySubgraph
|
|
3347
3347
|
};
|
|
3348
3348
|
|
|
3349
|
-
//# debugId=
|
|
3349
|
+
//# debugId=64B0D4D40A5E161564756E2164756E21
|
|
3350
3350
|
//# sourceMappingURL=index.js.map
|