@humain/humain-code-contracts 0.3.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/CHANGELOG.md +51 -0
- package/README.md +92 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestration.d.ts +327 -0
- package/dist/orchestration.d.ts.map +1 -0
- package/dist/orchestration.js +307 -0
- package/dist/orchestration.js.map +1 -0
- package/dist/rpc.d.ts +63 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +147 -0
- package/dist/rpc.js.map +1 -0
- package/dist/subagent-progress.d.ts +106 -0
- package/dist/subagent-progress.d.ts.map +1 -0
- package/dist/subagent-progress.js +440 -0
- package/dist/subagent-progress.js.map +1 -0
- package/dist/testing.d.ts +390 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +431 -0
- package/dist/testing.js.map +1 -0
- package/dist/trace-api.d.ts +293 -0
- package/dist/trace-api.d.ts.map +1 -0
- package/dist/trace-api.js +202 -0
- package/dist/trace-api.js.map +1 -0
- package/dist/trace-artifact.d.ts +94 -0
- package/dist/trace-artifact.d.ts.map +1 -0
- package/dist/trace-artifact.js +168 -0
- package/dist/trace-artifact.js.map +1 -0
- package/dist/trace-canonical.d.ts +23 -0
- package/dist/trace-canonical.d.ts.map +1 -0
- package/dist/trace-canonical.js +240 -0
- package/dist/trace-canonical.js.map +1 -0
- package/dist/trace-export.d.ts +94 -0
- package/dist/trace-export.d.ts.map +1 -0
- package/dist/trace-export.js +374 -0
- package/dist/trace-export.js.map +1 -0
- package/dist/trace-http.d.ts +1294 -0
- package/dist/trace-http.d.ts.map +1 -0
- package/dist/trace-http.js +1481 -0
- package/dist/trace-http.js.map +1 -0
- package/dist/trace-payload.d.ts +425 -0
- package/dist/trace-payload.d.ts.map +1 -0
- package/dist/trace-payload.js +1519 -0
- package/dist/trace-payload.js.map +1 -0
- package/dist/trace.d.ts +257 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +1014 -0
- package/dist/trace.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { assertDhPlainData, DhContractError, dhCanonicalText } from "./trace-canonical.js";
|
|
3
|
+
import { DH_HTTP_SCHEMA_IDS, dhStrictDtoParser } from "./trace-http.js";
|
|
4
|
+
import { DH_PAYLOAD_SCHEMA_IDS } from "./trace-payload.js";
|
|
5
|
+
export const DH_ARTIFACT_SCHEMA_IDS = Object.freeze({
|
|
6
|
+
capabilityManifest: "dh.capability-manifest/1",
|
|
7
|
+
contractArtifact: "dh.contract-artifact/1",
|
|
8
|
+
});
|
|
9
|
+
/** Literal implemented IDs only; lazy to preserve /trace entry-order neutrality. */
|
|
10
|
+
export function getDhImplementedSchemaIds() {
|
|
11
|
+
return Object.freeze([
|
|
12
|
+
"dh.event/1",
|
|
13
|
+
"dh.artifact/1",
|
|
14
|
+
"dh.ack/1",
|
|
15
|
+
"dh.batch/1-proposal",
|
|
16
|
+
"dh.canonical-jcs/1",
|
|
17
|
+
"dh.export-download/2",
|
|
18
|
+
"dh.bundle-frame/1",
|
|
19
|
+
"dh.bundle-seal/1",
|
|
20
|
+
...Object.values(DH_HTTP_SCHEMA_IDS),
|
|
21
|
+
...Object.values(DH_PAYLOAD_SCHEMA_IDS),
|
|
22
|
+
...Object.values(DH_ARTIFACT_SCHEMA_IDS),
|
|
23
|
+
].sort());
|
|
24
|
+
}
|
|
25
|
+
const strict = (properties) => Type.Object(properties, { additionalProperties: false });
|
|
26
|
+
const digest = Type.String({ pattern: "^[a-f0-9]{64}$" });
|
|
27
|
+
const ref = Type.String({ minLength: 1, maxLength: 128, pattern: "^[A-Za-z0-9_.-]+$" });
|
|
28
|
+
const schemaIds = Type.Array(Type.String({ minLength: 1, maxLength: 128 }), {
|
|
29
|
+
minItems: 1,
|
|
30
|
+
maxItems: 128,
|
|
31
|
+
uniqueItems: true,
|
|
32
|
+
});
|
|
33
|
+
export const DH_CAPABILITY_ACTIONS = [
|
|
34
|
+
"backgroundStatus",
|
|
35
|
+
"cancelSelected",
|
|
36
|
+
"cancelWholeRun",
|
|
37
|
+
"continueLive",
|
|
38
|
+
"retryFresh",
|
|
39
|
+
];
|
|
40
|
+
function actionSupportSchema() {
|
|
41
|
+
return strict({
|
|
42
|
+
status: Type.Enum(["supported", "unsupported", "unknown"]),
|
|
43
|
+
channel: Type.Enum(["unix-socket", "inherited-fd3", "in-process", "native-executor", "none"]),
|
|
44
|
+
qualificationSha256: Type.Optional(digest),
|
|
45
|
+
reasonCode: Type.Optional(ref),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function capabilitySchema() {
|
|
49
|
+
return strict({
|
|
50
|
+
schema: Type.Literal(DH_ARTIFACT_SCHEMA_IDS.capabilityManifest),
|
|
51
|
+
packageName: Type.Literal("@humain/humain-code-contracts"),
|
|
52
|
+
packageVersion: Type.String({ minLength: 1, maxLength: 64 }),
|
|
53
|
+
contractVersion: Type.Literal(1),
|
|
54
|
+
artifactSha256: digest,
|
|
55
|
+
canonicalProfile: Type.Literal("dh.canonical-jcs/1"),
|
|
56
|
+
schemaIds,
|
|
57
|
+
conformanceVectorSha256: digest,
|
|
58
|
+
runtimes: Type.Array(strict({
|
|
59
|
+
runtime: Type.Enum(["cli-node", "cli-bun", "flow", "forge-native"]),
|
|
60
|
+
buildSha256: digest,
|
|
61
|
+
mode: ref,
|
|
62
|
+
platform: Type.Enum(["darwin", "linux", "win32"]),
|
|
63
|
+
actions: strict({
|
|
64
|
+
backgroundStatus: actionSupportSchema(),
|
|
65
|
+
cancelSelected: actionSupportSchema(),
|
|
66
|
+
cancelWholeRun: actionSupportSchema(),
|
|
67
|
+
continueLive: actionSupportSchema(),
|
|
68
|
+
retryFresh: actionSupportSchema(),
|
|
69
|
+
}),
|
|
70
|
+
}), { maxItems: 128 }),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function assertRegistry(ids) {
|
|
74
|
+
if (dhCanonicalText([...ids].sort()) !== dhCanonicalText(getDhImplementedSchemaIds()))
|
|
75
|
+
throw new DhContractError("contract_incompatible");
|
|
76
|
+
}
|
|
77
|
+
export const parseDhCapabilityManifest = dhStrictDtoParser("capability manifest", capabilitySchema, (manifest) => {
|
|
78
|
+
assertRegistry(manifest.schemaIds);
|
|
79
|
+
const targets = new Set();
|
|
80
|
+
for (const runtime of manifest.runtimes) {
|
|
81
|
+
const key = dhCanonicalText([runtime.runtime, runtime.buildSha256, runtime.mode, runtime.platform]);
|
|
82
|
+
if (targets.has(key))
|
|
83
|
+
throw new DhContractError("schema_invalid");
|
|
84
|
+
targets.add(key);
|
|
85
|
+
for (const support of Object.values(runtime.actions)) {
|
|
86
|
+
if (support.status === "supported") {
|
|
87
|
+
if (support.channel === "none" || support.qualificationSha256 === undefined)
|
|
88
|
+
throw new DhContractError("schema_invalid");
|
|
89
|
+
}
|
|
90
|
+
else if (support.reasonCode === undefined || support.qualificationSha256 !== undefined)
|
|
91
|
+
throw new DhContractError("schema_invalid");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
export function assertDhCapabilityAction(input, target, action) {
|
|
96
|
+
const manifest = parseDhCapabilityManifest(input);
|
|
97
|
+
assertDhPlainData(target);
|
|
98
|
+
if (!DH_CAPABILITY_ACTIONS.includes(action))
|
|
99
|
+
throw new DhContractError("capability_unknown");
|
|
100
|
+
const runtime = manifest.runtimes.find((value) => value.runtime === target.runtime &&
|
|
101
|
+
value.buildSha256 === target.buildSha256 &&
|
|
102
|
+
value.mode === target.mode &&
|
|
103
|
+
value.platform === target.platform);
|
|
104
|
+
if (!runtime)
|
|
105
|
+
throw new DhContractError("capability_unknown");
|
|
106
|
+
const support = runtime.actions[action];
|
|
107
|
+
if (support.status === "unsupported" ||
|
|
108
|
+
target.platform === "win32" ||
|
|
109
|
+
["agent-exec-workflow", "experimental-transport"].includes(target.mode))
|
|
110
|
+
throw new DhContractError("capability_unsupported");
|
|
111
|
+
if (support.status !== "supported")
|
|
112
|
+
throw new DhContractError("capability_unknown");
|
|
113
|
+
return support;
|
|
114
|
+
}
|
|
115
|
+
const relativeFile = Type.String({
|
|
116
|
+
minLength: 1,
|
|
117
|
+
maxLength: 512,
|
|
118
|
+
pattern: "^(?!/)(?!.*(?:^|/)\\.\\.?(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$",
|
|
119
|
+
});
|
|
120
|
+
export const parseDhContractArtifact = dhStrictDtoParser("contract artifact", () => strict({
|
|
121
|
+
schema: Type.Literal(DH_ARTIFACT_SCHEMA_IDS.contractArtifact),
|
|
122
|
+
packageName: Type.Literal("@humain/humain-code-contracts"),
|
|
123
|
+
packageVersion: Type.Literal("0.3.2"),
|
|
124
|
+
contractVersion: Type.Literal(1),
|
|
125
|
+
tarballFile: relativeFile,
|
|
126
|
+
sha256: digest,
|
|
127
|
+
npmIntegrity: Type.String({ minLength: 1, maxLength: 128, pattern: "^sha512-[A-Za-z0-9+/]{85}[AQgw]==$" }),
|
|
128
|
+
capabilityManifestFile: relativeFile,
|
|
129
|
+
capabilityManifestSha256: digest,
|
|
130
|
+
conformanceVectorSha256: digest,
|
|
131
|
+
schemaIds,
|
|
132
|
+
}), (artifact) => {
|
|
133
|
+
assertRegistry(artifact.schemaIds);
|
|
134
|
+
if (artifact.tarballFile.split("/").at(-1) !== `humain-code-contracts-${artifact.sha256}.tgz` ||
|
|
135
|
+
artifact.capabilityManifestFile.split("/").at(-1) !==
|
|
136
|
+
`humain-code-contracts-${artifact.sha256}.capabilities.json`)
|
|
137
|
+
throw new DhContractError("schema_invalid");
|
|
138
|
+
});
|
|
139
|
+
export function assertDhContractArtifact(input, inspection) {
|
|
140
|
+
const artifact = parseDhContractArtifact(input);
|
|
141
|
+
assertDhPlainData(inspection);
|
|
142
|
+
if (inspection.distPresent !== true)
|
|
143
|
+
throw new DhContractError("artifact_unbuilt");
|
|
144
|
+
if (inspection.tarballSymlink !== false ||
|
|
145
|
+
inspection.capabilityManifestSymlink !== false ||
|
|
146
|
+
inspection.sha256 !== artifact.sha256 ||
|
|
147
|
+
inspection.npmIntegrity !== artifact.npmIntegrity ||
|
|
148
|
+
inspection.capabilityManifestSha256 !== artifact.capabilityManifestSha256)
|
|
149
|
+
throw new DhContractError("artifact_integrity");
|
|
150
|
+
const exports = Object.fromEntries(["index", "orchestration", "rpc", "trace", "testing"].map((name) => [
|
|
151
|
+
name === "index" ? "." : `./${name}`,
|
|
152
|
+
{ types: `./dist/${name}.d.ts`, import: `./dist/${name}.js` },
|
|
153
|
+
]));
|
|
154
|
+
if (inspection.packageName !== artifact.packageName ||
|
|
155
|
+
inspection.packageVersion !== artifact.packageVersion ||
|
|
156
|
+
inspection.contractVersion !== 1 ||
|
|
157
|
+
inspection.conformanceVectorSha256 !== artifact.conformanceVectorSha256 ||
|
|
158
|
+
dhCanonicalText(inspection.exports) !== dhCanonicalText(exports))
|
|
159
|
+
throw new DhContractError("contract_incompatible");
|
|
160
|
+
assertRegistry(inspection.schemaIds);
|
|
161
|
+
const manifest = parseDhCapabilityManifest(inspection.capabilityManifest);
|
|
162
|
+
if (manifest.artifactSha256 !== artifact.sha256 ||
|
|
163
|
+
manifest.packageVersion !== artifact.packageVersion ||
|
|
164
|
+
manifest.conformanceVectorSha256 !== artifact.conformanceVectorSha256 ||
|
|
165
|
+
dhCanonicalText([...manifest.schemaIds].sort()) !== dhCanonicalText([...artifact.schemaIds].sort()))
|
|
166
|
+
throw new DhContractError("contract_incompatible");
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=trace-artifact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-artifact.js","sourceRoot":"","sources":["../src/trace-artifact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,iBAAiB,E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;QACvE,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,eAAe,CAAC,OAAO,CAAC;QAEhE,MAAM,IAAI,eAAe,CAAC,uBAAuB,CAAC,CAAC;IACpD,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,yBAAyB,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC1E,IACC,QAAQ,CAAC,cAAc,KAAK,QAAQ,CAAC,MAAM;QAC3C,QAAQ,CAAC,cAAc,KAAK,QAAQ,CAAC,cAAc;QACnD,QAAQ,CAAC,uBAAuB,KAAK,QAAQ,CAAC,uBAAuB;QACrE,eAAe,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,eAAe,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;QAEnG,MAAM,IAAI,eAAe,CAAC,uBAAuB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport { assertDhPlainData, DhContractError, dhCanonicalText } from \"./trace-canonical.ts\";\nimport { DH_HTTP_SCHEMA_IDS, dhStrictDtoParser } from \"./trace-http.ts\";\nimport { DH_PAYLOAD_SCHEMA_IDS } from \"./trace-payload.ts\";\n\nexport const DH_ARTIFACT_SCHEMA_IDS = Object.freeze({\n\tcapabilityManifest: \"dh.capability-manifest/1\",\n\tcontractArtifact: \"dh.contract-artifact/1\",\n} as const);\n/** Literal implemented IDs only; lazy to preserve /trace entry-order neutrality. */\nexport function getDhImplementedSchemaIds(): readonly string[] {\n\treturn Object.freeze(\n\t\t[\n\t\t\t\"dh.event/1\",\n\t\t\t\"dh.artifact/1\",\n\t\t\t\"dh.ack/1\",\n\t\t\t\"dh.batch/1-proposal\",\n\t\t\t\"dh.canonical-jcs/1\",\n\t\t\t\"dh.export-download/2\",\n\t\t\t\"dh.bundle-frame/1\",\n\t\t\t\"dh.bundle-seal/1\",\n\t\t\t...Object.values(DH_HTTP_SCHEMA_IDS),\n\t\t\t...Object.values(DH_PAYLOAD_SCHEMA_IDS),\n\t\t\t...Object.values(DH_ARTIFACT_SCHEMA_IDS),\n\t\t].sort(),\n\t);\n}\nconst strict = <const T extends Parameters<typeof Type.Object>[0]>(properties: T) =>\n\tType.Object(properties, { additionalProperties: false });\nconst digest = Type.String({ pattern: \"^[a-f0-9]{64}$\" });\nconst ref = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z0-9_.-]+$\" });\nconst schemaIds = Type.Array(Type.String({ minLength: 1, maxLength: 128 }), {\n\tminItems: 1,\n\tmaxItems: 128,\n\tuniqueItems: true,\n});\nexport const DH_CAPABILITY_ACTIONS = [\n\t\"backgroundStatus\",\n\t\"cancelSelected\",\n\t\"cancelWholeRun\",\n\t\"continueLive\",\n\t\"retryFresh\",\n] as const;\nexport type DhCapabilityAction = (typeof DH_CAPABILITY_ACTIONS)[number];\nfunction actionSupportSchema() {\n\treturn strict({\n\t\tstatus: Type.Enum([\"supported\", \"unsupported\", \"unknown\"] as const),\n\t\tchannel: Type.Enum([\"unix-socket\", \"inherited-fd3\", \"in-process\", \"native-executor\", \"none\"] as const),\n\t\tqualificationSha256: Type.Optional(digest),\n\t\treasonCode: Type.Optional(ref),\n\t});\n}\nfunction capabilitySchema() {\n\treturn strict({\n\t\tschema: Type.Literal(DH_ARTIFACT_SCHEMA_IDS.capabilityManifest),\n\t\tpackageName: Type.Literal(\"@humain/humain-code-contracts\"),\n\t\tpackageVersion: Type.String({ minLength: 1, maxLength: 64 }),\n\t\tcontractVersion: Type.Literal(1),\n\t\tartifactSha256: digest,\n\t\tcanonicalProfile: Type.Literal(\"dh.canonical-jcs/1\"),\n\t\tschemaIds,\n\t\tconformanceVectorSha256: digest,\n\t\truntimes: Type.Array(\n\t\t\tstrict({\n\t\t\t\truntime: Type.Enum([\"cli-node\", \"cli-bun\", \"flow\", \"forge-native\"] as const),\n\t\t\t\tbuildSha256: digest,\n\t\t\t\tmode: ref,\n\t\t\t\tplatform: Type.Enum([\"darwin\", \"linux\", \"win32\"] as const),\n\t\t\t\tactions: strict({\n\t\t\t\t\tbackgroundStatus: actionSupportSchema(),\n\t\t\t\t\tcancelSelected: actionSupportSchema(),\n\t\t\t\t\tcancelWholeRun: actionSupportSchema(),\n\t\t\t\t\tcontinueLive: actionSupportSchema(),\n\t\t\t\t\tretryFresh: actionSupportSchema(),\n\t\t\t\t}),\n\t\t\t}),\n\t\t\t{ maxItems: 128 },\n\t\t),\n\t});\n}\nfunction assertRegistry(ids: readonly string[]): void {\n\tif (dhCanonicalText([...ids].sort()) !== dhCanonicalText(getDhImplementedSchemaIds()))\n\t\tthrow new DhContractError(\"contract_incompatible\");\n}\nexport const parseDhCapabilityManifest = dhStrictDtoParser(\"capability manifest\", capabilitySchema, (manifest) => {\n\tassertRegistry(manifest.schemaIds);\n\tconst targets = new Set<string>();\n\tfor (const runtime of manifest.runtimes) {\n\t\tconst key = dhCanonicalText([runtime.runtime, runtime.buildSha256, runtime.mode, runtime.platform]);\n\t\tif (targets.has(key)) throw new DhContractError(\"schema_invalid\");\n\t\ttargets.add(key);\n\t\tfor (const support of Object.values(runtime.actions)) {\n\t\t\tif (support.status === \"supported\") {\n\t\t\t\tif (support.channel === \"none\" || support.qualificationSha256 === undefined)\n\t\t\t\t\tthrow new DhContractError(\"schema_invalid\");\n\t\t\t} else if (support.reasonCode === undefined || support.qualificationSha256 !== undefined)\n\t\t\t\tthrow new DhContractError(\"schema_invalid\");\n\t\t}\n\t}\n});\nexport type DhCapabilityManifest = ReturnType<typeof parseDhCapabilityManifest>;\nexport type DhCapabilityTarget = Pick<\n\tDhCapabilityManifest[\"runtimes\"][number],\n\t\"runtime\" | \"buildSha256\" | \"mode\" | \"platform\"\n>;\nexport function assertDhCapabilityAction(\n\tinput: unknown,\n\ttarget: DhCapabilityTarget,\n\taction: DhCapabilityAction,\n): DhCapabilityManifest[\"runtimes\"][number][\"actions\"][DhCapabilityAction] {\n\tconst manifest = parseDhCapabilityManifest(input);\n\tassertDhPlainData(target);\n\tif (!(DH_CAPABILITY_ACTIONS as readonly string[]).includes(action)) throw new DhContractError(\"capability_unknown\");\n\tconst runtime = manifest.runtimes.find(\n\t\t(value) =>\n\t\t\tvalue.runtime === target.runtime &&\n\t\t\tvalue.buildSha256 === target.buildSha256 &&\n\t\t\tvalue.mode === target.mode &&\n\t\t\tvalue.platform === target.platform,\n\t);\n\tif (!runtime) throw new DhContractError(\"capability_unknown\");\n\tconst support = runtime.actions[action];\n\tif (\n\t\tsupport.status === \"unsupported\" ||\n\t\ttarget.platform === \"win32\" ||\n\t\t[\"agent-exec-workflow\", \"experimental-transport\"].includes(target.mode)\n\t)\n\t\tthrow new DhContractError(\"capability_unsupported\");\n\tif (support.status !== \"supported\") throw new DhContractError(\"capability_unknown\");\n\treturn support;\n}\nconst relativeFile = Type.String({\n\tminLength: 1,\n\tmaxLength: 512,\n\tpattern: \"^(?!/)(?!.*(?:^|/)\\\\.\\\\.?(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$\",\n});\nexport const parseDhContractArtifact = dhStrictDtoParser(\n\t\"contract artifact\",\n\t() =>\n\t\tstrict({\n\t\t\tschema: Type.Literal(DH_ARTIFACT_SCHEMA_IDS.contractArtifact),\n\t\t\tpackageName: Type.Literal(\"@humain/humain-code-contracts\"),\n\t\t\tpackageVersion: Type.Literal(\"0.3.2\"),\n\t\t\tcontractVersion: Type.Literal(1),\n\t\t\ttarballFile: relativeFile,\n\t\t\tsha256: digest,\n\t\t\tnpmIntegrity: Type.String({ minLength: 1, maxLength: 128, pattern: \"^sha512-[A-Za-z0-9+/]{85}[AQgw]==$\" }),\n\t\t\tcapabilityManifestFile: relativeFile,\n\t\t\tcapabilityManifestSha256: digest,\n\t\t\tconformanceVectorSha256: digest,\n\t\t\tschemaIds,\n\t\t}),\n\t(artifact) => {\n\t\tassertRegistry(artifact.schemaIds);\n\t\tif (\n\t\t\tartifact.tarballFile.split(\"/\").at(-1) !== `humain-code-contracts-${artifact.sha256}.tgz` ||\n\t\t\tartifact.capabilityManifestFile.split(\"/\").at(-1) !==\n\t\t\t\t`humain-code-contracts-${artifact.sha256}.capabilities.json`\n\t\t)\n\t\t\tthrow new DhContractError(\"schema_invalid\");\n\t},\n);\nexport type DhContractArtifact = ReturnType<typeof parseDhContractArtifact>;\n/** Actual file/digest/export inspection is owned by the installer, not inferred from a descriptor. */\nexport interface DhContractArtifactInspection {\n\treadonly packageName: string;\n\treadonly packageVersion: string;\n\treadonly contractVersion: number;\n\treadonly exports: Readonly<Record<string, { readonly types: string; readonly import: string }>>;\n\treadonly distPresent: boolean;\n\treadonly sha256: string;\n\treadonly npmIntegrity: string;\n\treadonly capabilityManifest: unknown;\n\treadonly capabilityManifestSha256: string;\n\treadonly conformanceVectorSha256: string;\n\treadonly schemaIds: readonly string[];\n\treadonly tarballSymlink: boolean;\n\treadonly capabilityManifestSymlink: boolean;\n}\nexport function assertDhContractArtifact(input: unknown, inspection: DhContractArtifactInspection): void {\n\tconst artifact = parseDhContractArtifact(input);\n\tassertDhPlainData(inspection);\n\tif (inspection.distPresent !== true) throw new DhContractError(\"artifact_unbuilt\");\n\tif (\n\t\tinspection.tarballSymlink !== false ||\n\t\tinspection.capabilityManifestSymlink !== false ||\n\t\tinspection.sha256 !== artifact.sha256 ||\n\t\tinspection.npmIntegrity !== artifact.npmIntegrity ||\n\t\tinspection.capabilityManifestSha256 !== artifact.capabilityManifestSha256\n\t)\n\t\tthrow new DhContractError(\"artifact_integrity\");\n\tconst exports = Object.fromEntries(\n\t\t[\"index\", \"orchestration\", \"rpc\", \"trace\", \"testing\"].map((name) => [\n\t\t\tname === \"index\" ? \".\" : `./${name}`,\n\t\t\t{ types: `./dist/${name}.d.ts`, import: `./dist/${name}.js` },\n\t\t]),\n\t);\n\tif (\n\t\tinspection.packageName !== artifact.packageName ||\n\t\tinspection.packageVersion !== artifact.packageVersion ||\n\t\tinspection.contractVersion !== 1 ||\n\t\tinspection.conformanceVectorSha256 !== artifact.conformanceVectorSha256 ||\n\t\tdhCanonicalText(inspection.exports) !== dhCanonicalText(exports)\n\t)\n\t\tthrow new DhContractError(\"contract_incompatible\");\n\tassertRegistry(inspection.schemaIds);\n\tconst manifest = parseDhCapabilityManifest(inspection.capabilityManifest);\n\tif (\n\t\tmanifest.artifactSha256 !== artifact.sha256 ||\n\t\tmanifest.packageVersion !== artifact.packageVersion ||\n\t\tmanifest.conformanceVectorSha256 !== artifact.conformanceVectorSha256 ||\n\t\tdhCanonicalText([...manifest.schemaIds].sort()) !== dhCanonicalText([...artifact.schemaIds].sort())\n\t)\n\t\tthrow new DhContractError(\"contract_incompatible\");\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DhJsonValue } from "./trace.ts";
|
|
2
|
+
export declare const DH_CANONICAL_PROFILE: "dh.canonical-jcs/1";
|
|
3
|
+
export declare const DH_WIRE_MAX_DEPTH = 24;
|
|
4
|
+
export declare const DH_WIRE_MAX_NODES = 500000;
|
|
5
|
+
export declare const DH_DIGEST_DOMAINS: readonly ["dh.event/1", "dh.artifact/1", "dh.control-request/2", "dh.cursor-binding/2", "dh.cursor-filter/1", "dh.tenant-mapping/1", "dh.export-record/1", "dh.export-shard/2", "dh.export-header/2", "dh.contract-vectors/1", "dh.capability-manifest/1"];
|
|
6
|
+
export type DhDigestDomain = (typeof DH_DIGEST_DOMAINS)[number];
|
|
7
|
+
/** Messages are constants selected by contract code, never rejected content. */
|
|
8
|
+
export declare class DhContractError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
constructor(code: string, message?: string);
|
|
11
|
+
}
|
|
12
|
+
/** Descriptor gate shared by all wire parsers. Proxies are not wire authorities. */
|
|
13
|
+
export declare function assertDhPlainData(root: unknown): asserts root is DhJsonValue;
|
|
14
|
+
/** Raw parsing retains the key and integer-token information JSON.parse discards. */
|
|
15
|
+
export declare function parseDhRawJson(bytes: Uint8Array, options: {
|
|
16
|
+
maxBytes: number;
|
|
17
|
+
rootArrayItemMaxBytes?: Readonly<Record<string, number>>;
|
|
18
|
+
}): DhJsonValue;
|
|
19
|
+
/** RFC 8785: ECMAScript primitive rendering, UTF-16 key order, no Unicode normalization. */
|
|
20
|
+
export declare function dhCanonicalText(value: unknown): string;
|
|
21
|
+
/** Caller hashes these exact bytes using native SHA-256; artifact content hashes remain raw-byte hashes. */
|
|
22
|
+
export declare function dhDigestInput(domain: DhDigestDomain, value: unknown): Uint8Array;
|
|
23
|
+
//# sourceMappingURL=trace-canonical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-canonical.d.ts","sourceRoot":"","sources":["../src/trace-canonical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,oBAAoB,EAAG,oBAA6B,CAAC;AAClE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,SAAU,CAAC;AACzC,eAAO,MAAM,iBAAiB,YAC7B,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,CACjB,CAAC;AACX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,gFAAgF;AAChF,qBAAa,eAAgB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,SAA6B,EAI7D;CACD;AAOD,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,WAAW,CAqD5E;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAC7B,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,qBAAqB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,GACrF,WAAW,CAwGb;AAED,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAYtD;AAED,4GAA4G;AAC5G,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,GAAG,UAAU,CAGhF"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
export const DH_CANONICAL_PROFILE = "dh.canonical-jcs/1";
|
|
2
|
+
export const DH_WIRE_MAX_DEPTH = 24;
|
|
3
|
+
export const DH_WIRE_MAX_NODES = 500_000;
|
|
4
|
+
export const DH_DIGEST_DOMAINS = [
|
|
5
|
+
"dh.event/1",
|
|
6
|
+
"dh.artifact/1",
|
|
7
|
+
"dh.control-request/2",
|
|
8
|
+
"dh.cursor-binding/2",
|
|
9
|
+
"dh.cursor-filter/1",
|
|
10
|
+
"dh.tenant-mapping/1",
|
|
11
|
+
"dh.export-record/1",
|
|
12
|
+
"dh.export-shard/2",
|
|
13
|
+
"dh.export-header/2",
|
|
14
|
+
"dh.contract-vectors/1",
|
|
15
|
+
"dh.capability-manifest/1",
|
|
16
|
+
];
|
|
17
|
+
/** Messages are constants selected by contract code, never rejected content. */
|
|
18
|
+
export class DhContractError extends Error {
|
|
19
|
+
code;
|
|
20
|
+
constructor(code, message = "Invalid DH contract data") {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "DhContractError";
|
|
23
|
+
this.code = code;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const forbidden = new Set(["__proto__", "constructor", "prototype"]);
|
|
27
|
+
function assertUnicode(value) {
|
|
28
|
+
if (!value.isWellFormed())
|
|
29
|
+
throw new DhContractError("invalid_unicode", "Invalid Unicode");
|
|
30
|
+
}
|
|
31
|
+
/** Descriptor gate shared by all wire parsers. Proxies are not wire authorities. */
|
|
32
|
+
export function assertDhPlainData(root) {
|
|
33
|
+
const stack = [{ value: root, depth: 0 }];
|
|
34
|
+
let nodes = 1;
|
|
35
|
+
while (stack.length > 0) {
|
|
36
|
+
const item = stack.pop();
|
|
37
|
+
if (item === undefined)
|
|
38
|
+
break;
|
|
39
|
+
const { value, depth } = item;
|
|
40
|
+
if (depth > DH_WIRE_MAX_DEPTH)
|
|
41
|
+
throw new DhContractError("too_large", "Invalid nesting depth");
|
|
42
|
+
if (value === null || typeof value === "boolean")
|
|
43
|
+
continue;
|
|
44
|
+
if (typeof value === "string") {
|
|
45
|
+
assertUnicode(value);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === "number") {
|
|
49
|
+
if (!Number.isFinite(value))
|
|
50
|
+
throw new DhContractError("nonfinite_number", "Invalid non-finite number");
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (typeof value !== "object")
|
|
54
|
+
throw new DhContractError("schema_invalid", "Invalid non-JSON type");
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
if (Object.getPrototypeOf(value) !== Array.prototype)
|
|
57
|
+
throw new DhContractError("schema_invalid", "Invalid not a plain array");
|
|
58
|
+
if (value.length > DH_WIRE_MAX_NODES - nodes)
|
|
59
|
+
throw new DhContractError("too_large", "Invalid too many values");
|
|
60
|
+
nodes += value.length;
|
|
61
|
+
if (Reflect.ownKeys(value).length !== value.length + 1)
|
|
62
|
+
throw new DhContractError("schema_invalid", "Invalid sparse or extended array");
|
|
63
|
+
for (let index = 0; index < value.length; index++) {
|
|
64
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
65
|
+
if (descriptor === undefined || !("value" in descriptor))
|
|
66
|
+
throw new DhContractError("schema_invalid", "Invalid sparse array or accessor property");
|
|
67
|
+
if (!descriptor.enumerable)
|
|
68
|
+
throw new DhContractError("schema_invalid", "Invalid non-enumerable array index");
|
|
69
|
+
stack.push({ value: descriptor.value, depth: depth + 1 });
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const proto = Object.getPrototypeOf(value);
|
|
74
|
+
if (proto !== Object.prototype && proto !== null)
|
|
75
|
+
throw new DhContractError("schema_invalid", "Invalid not a plain object");
|
|
76
|
+
const keys = Reflect.ownKeys(value);
|
|
77
|
+
if (keys.length > DH_WIRE_MAX_NODES - nodes)
|
|
78
|
+
throw new DhContractError("too_large", "Invalid too many values");
|
|
79
|
+
nodes += keys.length;
|
|
80
|
+
for (const key of keys) {
|
|
81
|
+
if (typeof key !== "string")
|
|
82
|
+
throw new DhContractError("schema_invalid", "Invalid symbol key");
|
|
83
|
+
assertUnicode(key);
|
|
84
|
+
if (forbidden.has(key))
|
|
85
|
+
throw new DhContractError("schema_invalid", "Invalid forbidden key");
|
|
86
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
87
|
+
if (descriptor === undefined || !("value" in descriptor))
|
|
88
|
+
throw new DhContractError("schema_invalid", "Invalid accessor property");
|
|
89
|
+
if (!descriptor.enumerable)
|
|
90
|
+
throw new DhContractError("schema_invalid", "Invalid non-enumerable property");
|
|
91
|
+
stack.push({ value: descriptor.value, depth: depth + 1 });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Raw parsing retains the key and integer-token information JSON.parse discards. */
|
|
96
|
+
export function parseDhRawJson(bytes, options) {
|
|
97
|
+
if (!(bytes instanceof Uint8Array) || !Number.isSafeInteger(options?.maxBytes) || options.maxBytes < 0)
|
|
98
|
+
throw new DhContractError("schema_invalid");
|
|
99
|
+
if (Object.values(options.rootArrayItemMaxBytes ?? {}).some((limit) => !Number.isSafeInteger(limit) || limit < 0))
|
|
100
|
+
throw new DhContractError("schema_invalid");
|
|
101
|
+
if (bytes.byteLength > options.maxBytes)
|
|
102
|
+
throw new DhContractError("too_large", "Invalid UTF-8 bytes limit");
|
|
103
|
+
let text;
|
|
104
|
+
try {
|
|
105
|
+
text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new DhContractError("invalid_unicode", "Invalid UTF-8");
|
|
109
|
+
}
|
|
110
|
+
let position = 0;
|
|
111
|
+
let nodes = 0;
|
|
112
|
+
const invalid = () => {
|
|
113
|
+
throw new DhContractError("raw_json_invalid", "Invalid raw JSON");
|
|
114
|
+
};
|
|
115
|
+
const whitespace = () => {
|
|
116
|
+
while (/[\x20\x09\x0a\x0d]/.test(text[position] ?? ""))
|
|
117
|
+
position++;
|
|
118
|
+
};
|
|
119
|
+
const string = () => {
|
|
120
|
+
const start = position++;
|
|
121
|
+
while (position < text.length) {
|
|
122
|
+
const char = text[position++];
|
|
123
|
+
if (char === '"') {
|
|
124
|
+
let value;
|
|
125
|
+
try {
|
|
126
|
+
value = JSON.parse(text.slice(start, position));
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return invalid();
|
|
130
|
+
}
|
|
131
|
+
assertUnicode(value);
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
if (char === "\\")
|
|
135
|
+
position++;
|
|
136
|
+
}
|
|
137
|
+
return invalid();
|
|
138
|
+
};
|
|
139
|
+
const value = (depth, itemMaxBytes) => {
|
|
140
|
+
whitespace();
|
|
141
|
+
if (++nodes > DH_WIRE_MAX_NODES)
|
|
142
|
+
throw new DhContractError("too_large", "Invalid too many values");
|
|
143
|
+
if (depth > DH_WIRE_MAX_DEPTH)
|
|
144
|
+
throw new DhContractError("too_large", "Invalid nesting depth");
|
|
145
|
+
const char = text[position];
|
|
146
|
+
if (char === '"')
|
|
147
|
+
return string();
|
|
148
|
+
if (char === "{" || char === "[") {
|
|
149
|
+
position++;
|
|
150
|
+
let itemStart = position;
|
|
151
|
+
whitespace();
|
|
152
|
+
const close = char === "{" ? "}" : "]";
|
|
153
|
+
const object = Object.create(null);
|
|
154
|
+
const array = [];
|
|
155
|
+
const keys = new Set();
|
|
156
|
+
if (text[position] !== close)
|
|
157
|
+
while (true) {
|
|
158
|
+
whitespace();
|
|
159
|
+
if (char === "{") {
|
|
160
|
+
if (text[position] !== '"')
|
|
161
|
+
return invalid();
|
|
162
|
+
const key = string();
|
|
163
|
+
if (keys.has(key))
|
|
164
|
+
throw new DhContractError("duplicate_json_key", "Invalid duplicate JSON key");
|
|
165
|
+
if (forbidden.has(key))
|
|
166
|
+
throw new DhContractError("schema_invalid", "Invalid forbidden key");
|
|
167
|
+
keys.add(key);
|
|
168
|
+
whitespace();
|
|
169
|
+
if (text[position++] !== ":")
|
|
170
|
+
return invalid();
|
|
171
|
+
object[key] = value(depth + 1, depth === 0 ? options.rootArrayItemMaxBytes?.[key] : undefined);
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
array.push(value(depth + 1));
|
|
175
|
+
whitespace();
|
|
176
|
+
if (char === "[" &&
|
|
177
|
+
itemMaxBytes !== undefined &&
|
|
178
|
+
new TextEncoder().encode(text.slice(itemStart, position)).byteLength > itemMaxBytes)
|
|
179
|
+
throw new DhContractError("too_large", "Invalid raw array item UTF-8 bytes limit");
|
|
180
|
+
if (text[position] !== ",")
|
|
181
|
+
break;
|
|
182
|
+
position++;
|
|
183
|
+
itemStart = position;
|
|
184
|
+
}
|
|
185
|
+
if (text[position++] !== close)
|
|
186
|
+
return invalid();
|
|
187
|
+
return char === "{" ? object : array;
|
|
188
|
+
}
|
|
189
|
+
for (const [token, result] of [
|
|
190
|
+
["null", null],
|
|
191
|
+
["true", true],
|
|
192
|
+
["false", false],
|
|
193
|
+
]) {
|
|
194
|
+
if (text.startsWith(token, position)) {
|
|
195
|
+
position += token.length;
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const match = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(text.slice(position));
|
|
200
|
+
if (match === null)
|
|
201
|
+
return invalid();
|
|
202
|
+
const token = match[0];
|
|
203
|
+
position += token.length;
|
|
204
|
+
const number = Number(token);
|
|
205
|
+
if (!Number.isFinite(number))
|
|
206
|
+
throw new DhContractError("nonfinite_number", "Invalid non-finite number");
|
|
207
|
+
// Integer-form tokens must survive binary64 exactly. Decimal/exponent tokens use JCS binary64 semantics.
|
|
208
|
+
if (!/[.eE]/.test(token) && BigInt(token) !== BigInt(number))
|
|
209
|
+
throw new DhContractError("integer_precision_loss", "Invalid integer precision loss");
|
|
210
|
+
return number;
|
|
211
|
+
};
|
|
212
|
+
const parsed = value(0);
|
|
213
|
+
whitespace();
|
|
214
|
+
if (position !== text.length)
|
|
215
|
+
return invalid();
|
|
216
|
+
return parsed;
|
|
217
|
+
}
|
|
218
|
+
/** RFC 8785: ECMAScript primitive rendering, UTF-16 key order, no Unicode normalization. */
|
|
219
|
+
export function dhCanonicalText(value) {
|
|
220
|
+
assertDhPlainData(value);
|
|
221
|
+
const render = (item) => {
|
|
222
|
+
if (item === null || typeof item !== "object")
|
|
223
|
+
return JSON.stringify(item);
|
|
224
|
+
if (Array.isArray(item))
|
|
225
|
+
return `[${item.map(render).join(",")}]`;
|
|
226
|
+
const object = item;
|
|
227
|
+
return `{${Object.keys(object)
|
|
228
|
+
.sort()
|
|
229
|
+
.map((key) => `${JSON.stringify(key)}:${render(object[key])}`)
|
|
230
|
+
.join(",")}}`;
|
|
231
|
+
};
|
|
232
|
+
return render(value);
|
|
233
|
+
}
|
|
234
|
+
/** Caller hashes these exact bytes using native SHA-256; artifact content hashes remain raw-byte hashes. */
|
|
235
|
+
export function dhDigestInput(domain, value) {
|
|
236
|
+
if (!DH_DIGEST_DOMAINS.includes(domain))
|
|
237
|
+
throw new DhContractError("schema_invalid");
|
|
238
|
+
return new TextEncoder().encode(`${domain}\0${dhCanonicalText(value)}`);
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=trace-canonical.js.map
|
|
@@ -0,0 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AAE;QAC5C,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC3E,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAClE,MAAM,MAAM,GAAG,IAA+C,CAAC;QAC/D,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aAC5B,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAE,CAAC,EAAE,CAAC;aAC9D,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAChB,CAAC,CAAC;IACF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,aAAa,CAAC,MAAsB,EAAE,KAAc;IACnE,IAAI,CAAE,iBAAuC,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAC5G,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,MAAM,KAAK,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import type { DhJsonValue } from \"./trace.ts\";\n\nexport const DH_CANONICAL_PROFILE = \"dh.canonical-jcs/1\" as const;\nexport const DH_WIRE_MAX_DEPTH = 24;\nexport const DH_WIRE_MAX_NODES = 500_000;\nexport const DH_DIGEST_DOMAINS = [\n\t\"dh.event/1\",\n\t\"dh.artifact/1\",\n\t\"dh.control-request/2\",\n\t\"dh.cursor-binding/2\",\n\t\"dh.cursor-filter/1\",\n\t\"dh.tenant-mapping/1\",\n\t\"dh.export-record/1\",\n\t\"dh.export-shard/2\",\n\t\"dh.export-header/2\",\n\t\"dh.contract-vectors/1\",\n\t\"dh.capability-manifest/1\",\n] as const;\nexport type DhDigestDomain = (typeof DH_DIGEST_DOMAINS)[number];\n\n/** Messages are constants selected by contract code, never rejected content. */\nexport class DhContractError extends Error {\n\treadonly code: string;\n\tconstructor(code: string, message = \"Invalid DH contract data\") {\n\t\tsuper(message);\n\t\tthis.name = \"DhContractError\";\n\t\tthis.code = code;\n\t}\n}\n\nconst forbidden = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\nfunction assertUnicode(value: string): void {\n\tif (!value.isWellFormed()) throw new DhContractError(\"invalid_unicode\", \"Invalid Unicode\");\n}\n\n/** Descriptor gate shared by all wire parsers. Proxies are not wire authorities. */\nexport function assertDhPlainData(root: unknown): asserts root is DhJsonValue {\n\tconst stack: { value: unknown; depth: number }[] = [{ value: root, depth: 0 }];\n\tlet nodes = 1;\n\twhile (stack.length > 0) {\n\t\tconst item = stack.pop();\n\t\tif (item === undefined) break;\n\t\tconst { value, depth } = item;\n\t\tif (depth > DH_WIRE_MAX_DEPTH) throw new DhContractError(\"too_large\", \"Invalid nesting depth\");\n\t\tif (value === null || typeof value === \"boolean\") continue;\n\t\tif (typeof value === \"string\") {\n\t\t\tassertUnicode(value);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"number\") {\n\t\t\tif (!Number.isFinite(value)) throw new DhContractError(\"nonfinite_number\", \"Invalid non-finite number\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value !== \"object\") throw new DhContractError(\"schema_invalid\", \"Invalid non-JSON type\");\n\t\tif (Array.isArray(value)) {\n\t\t\tif (Object.getPrototypeOf(value) !== Array.prototype)\n\t\t\t\tthrow new DhContractError(\"schema_invalid\", \"Invalid not a plain array\");\n\t\t\tif (value.length > DH_WIRE_MAX_NODES - nodes)\n\t\t\t\tthrow new DhContractError(\"too_large\", \"Invalid too many values\");\n\t\t\tnodes += value.length;\n\t\t\tif (Reflect.ownKeys(value).length !== value.length + 1)\n\t\t\t\tthrow new DhContractError(\"schema_invalid\", \"Invalid sparse or extended array\");\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\t\t\tif (descriptor === undefined || !(\"value\" in descriptor))\n\t\t\t\t\tthrow new DhContractError(\"schema_invalid\", \"Invalid sparse array or accessor property\");\n\t\t\t\tif (!descriptor.enumerable)\n\t\t\t\t\tthrow new DhContractError(\"schema_invalid\", \"Invalid non-enumerable array index\");\n\t\t\t\tstack.push({ value: descriptor.value, depth: depth + 1 });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst proto = Object.getPrototypeOf(value);\n\t\tif (proto !== Object.prototype && proto !== null)\n\t\t\tthrow new DhContractError(\"schema_invalid\", \"Invalid not a plain object\");\n\t\tconst keys = Reflect.ownKeys(value);\n\t\tif (keys.length > DH_WIRE_MAX_NODES - nodes) throw new DhContractError(\"too_large\", \"Invalid too many values\");\n\t\tnodes += keys.length;\n\t\tfor (const key of keys) {\n\t\t\tif (typeof key !== \"string\") throw new DhContractError(\"schema_invalid\", \"Invalid symbol key\");\n\t\t\tassertUnicode(key);\n\t\t\tif (forbidden.has(key)) throw new DhContractError(\"schema_invalid\", \"Invalid forbidden key\");\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\tif (descriptor === undefined || !(\"value\" in descriptor))\n\t\t\t\tthrow new DhContractError(\"schema_invalid\", \"Invalid accessor property\");\n\t\t\tif (!descriptor.enumerable) throw new DhContractError(\"schema_invalid\", \"Invalid non-enumerable property\");\n\t\t\tstack.push({ value: descriptor.value, depth: depth + 1 });\n\t\t}\n\t}\n}\n\n/** Raw parsing retains the key and integer-token information JSON.parse discards. */\nexport function parseDhRawJson(\n\tbytes: Uint8Array,\n\toptions: { maxBytes: number; rootArrayItemMaxBytes?: Readonly<Record<string, number>> },\n): DhJsonValue {\n\tif (!(bytes instanceof Uint8Array) || !Number.isSafeInteger(options?.maxBytes) || options.maxBytes < 0)\n\t\tthrow new DhContractError(\"schema_invalid\");\n\tif (Object.values(options.rootArrayItemMaxBytes ?? {}).some((limit) => !Number.isSafeInteger(limit) || limit < 0))\n\t\tthrow new DhContractError(\"schema_invalid\");\n\tif (bytes.byteLength > options.maxBytes) throw new DhContractError(\"too_large\", \"Invalid UTF-8 bytes limit\");\n\tlet text: string;\n\ttry {\n\t\ttext = new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: true }).decode(bytes);\n\t} catch {\n\t\tthrow new DhContractError(\"invalid_unicode\", \"Invalid UTF-8\");\n\t}\n\tlet position = 0;\n\tlet nodes = 0;\n\tconst invalid = (): never => {\n\t\tthrow new DhContractError(\"raw_json_invalid\", \"Invalid raw JSON\");\n\t};\n\tconst whitespace = () => {\n\t\twhile (/[\\x20\\x09\\x0a\\x0d]/.test(text[position] ?? \"\")) position++;\n\t};\n\tconst string = (): string => {\n\t\tconst start = position++;\n\t\twhile (position < text.length) {\n\t\t\tconst char = text[position++];\n\t\t\tif (char === '\"') {\n\t\t\t\tlet value: string;\n\t\t\t\ttry {\n\t\t\t\t\tvalue = JSON.parse(text.slice(start, position)) as string;\n\t\t\t\t} catch {\n\t\t\t\t\treturn invalid();\n\t\t\t\t}\n\t\t\t\tassertUnicode(value);\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tif (char === \"\\\\\") position++;\n\t\t}\n\t\treturn invalid();\n\t};\n\tconst value = (depth: number, itemMaxBytes?: number): DhJsonValue => {\n\t\twhitespace();\n\t\tif (++nodes > DH_WIRE_MAX_NODES) throw new DhContractError(\"too_large\", \"Invalid too many values\");\n\t\tif (depth > DH_WIRE_MAX_DEPTH) throw new DhContractError(\"too_large\", \"Invalid nesting depth\");\n\t\tconst char = text[position];\n\t\tif (char === '\"') return string();\n\t\tif (char === \"{\" || char === \"[\") {\n\t\t\tposition++;\n\t\t\tlet itemStart = position;\n\t\t\twhitespace();\n\t\t\tconst close = char === \"{\" ? \"}\" : \"]\";\n\t\t\tconst object: Record<string, DhJsonValue> = Object.create(null);\n\t\t\tconst array: DhJsonValue[] = [];\n\t\t\tconst keys = new Set<string>();\n\t\t\tif (text[position] !== close)\n\t\t\t\twhile (true) {\n\t\t\t\t\twhitespace();\n\t\t\t\t\tif (char === \"{\") {\n\t\t\t\t\t\tif (text[position] !== '\"') return invalid();\n\t\t\t\t\t\tconst key = string();\n\t\t\t\t\t\tif (keys.has(key)) throw new DhContractError(\"duplicate_json_key\", \"Invalid duplicate JSON key\");\n\t\t\t\t\t\tif (forbidden.has(key)) throw new DhContractError(\"schema_invalid\", \"Invalid forbidden key\");\n\t\t\t\t\t\tkeys.add(key);\n\t\t\t\t\t\twhitespace();\n\t\t\t\t\t\tif (text[position++] !== \":\") return invalid();\n\t\t\t\t\t\tobject[key] = value(depth + 1, depth === 0 ? options.rootArrayItemMaxBytes?.[key] : undefined);\n\t\t\t\t\t} else array.push(value(depth + 1));\n\t\t\t\t\twhitespace();\n\t\t\t\t\tif (\n\t\t\t\t\t\tchar === \"[\" &&\n\t\t\t\t\t\titemMaxBytes !== undefined &&\n\t\t\t\t\t\tnew TextEncoder().encode(text.slice(itemStart, position)).byteLength > itemMaxBytes\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new DhContractError(\"too_large\", \"Invalid raw array item UTF-8 bytes limit\");\n\t\t\t\t\tif (text[position] !== \",\") break;\n\t\t\t\t\tposition++;\n\t\t\t\t\titemStart = position;\n\t\t\t\t}\n\t\t\tif (text[position++] !== close) return invalid();\n\t\t\treturn char === \"{\" ? object : array;\n\t\t}\n\t\tfor (const [token, result] of [\n\t\t\t[\"null\", null],\n\t\t\t[\"true\", true],\n\t\t\t[\"false\", false],\n\t\t] as const) {\n\t\t\tif (text.startsWith(token, position)) {\n\t\t\t\tposition += token.length;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t\tconst match = /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(text.slice(position));\n\t\tif (match === null) return invalid();\n\t\tconst token = match[0];\n\t\tposition += token.length;\n\t\tconst number = Number(token);\n\t\tif (!Number.isFinite(number)) throw new DhContractError(\"nonfinite_number\", \"Invalid non-finite number\");\n\t\t// Integer-form tokens must survive binary64 exactly. Decimal/exponent tokens use JCS binary64 semantics.\n\t\tif (!/[.eE]/.test(token) && BigInt(token) !== BigInt(number))\n\t\t\tthrow new DhContractError(\"integer_precision_loss\", \"Invalid integer precision loss\");\n\t\treturn number;\n\t};\n\tconst parsed = value(0);\n\twhitespace();\n\tif (position !== text.length) return invalid();\n\treturn parsed;\n}\n\n/** RFC 8785: ECMAScript primitive rendering, UTF-16 key order, no Unicode normalization. */\nexport function dhCanonicalText(value: unknown): string {\n\tassertDhPlainData(value);\n\tconst render = (item: DhJsonValue): string => {\n\t\tif (item === null || typeof item !== \"object\") return JSON.stringify(item);\n\t\tif (Array.isArray(item)) return `[${item.map(render).join(\",\")}]`;\n\t\tconst object = item as { readonly [key: string]: DhJsonValue };\n\t\treturn `{${Object.keys(object)\n\t\t\t.sort()\n\t\t\t.map((key) => `${JSON.stringify(key)}:${render(object[key]!)}`)\n\t\t\t.join(\",\")}}`;\n\t};\n\treturn render(value);\n}\n\n/** Caller hashes these exact bytes using native SHA-256; artifact content hashes remain raw-byte hashes. */\nexport function dhDigestInput(domain: DhDigestDomain, value: unknown): Uint8Array {\n\tif (!(DH_DIGEST_DOMAINS as readonly string[]).includes(domain)) throw new DhContractError(\"schema_invalid\");\n\treturn new TextEncoder().encode(`${domain}\\0${dhCanonicalText(value)}`);\n}\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
import { type DhExportDownload } from "./trace-api.ts";
|
|
3
|
+
import { type DhExportManifestHeader, type DhExportManifestPage, type DhManifestEntry } from "./trace-http.ts";
|
|
4
|
+
export interface DhExportHashOptions {
|
|
5
|
+
readonly sha256Hex: (bytes: Uint8Array) => string;
|
|
6
|
+
}
|
|
7
|
+
export interface DhExportManifestValidation {
|
|
8
|
+
readonly header: DhExportManifestHeader;
|
|
9
|
+
readonly sha256Hex: (bytes: Uint8Array) => string;
|
|
10
|
+
nextShard: number;
|
|
11
|
+
eventCount: number;
|
|
12
|
+
artifactCount: number;
|
|
13
|
+
streamCount: number;
|
|
14
|
+
omittedArtifactCount: number;
|
|
15
|
+
lastKey: string;
|
|
16
|
+
root: string;
|
|
17
|
+
readonly cursors: Set<string>;
|
|
18
|
+
}
|
|
19
|
+
export declare function beginDhExportManifest(headerInput: unknown, options: DhExportHashOptions): DhExportManifestValidation;
|
|
20
|
+
/** Retains one last identity and at most 1,024 navigation cursors, never all record IDs. */
|
|
21
|
+
export declare function acceptDhExportManifestPage(state: DhExportManifestValidation, input: unknown): DhExportManifestPage;
|
|
22
|
+
export declare function finishDhExportManifest(state: DhExportManifestValidation): DhExportManifestHeader;
|
|
23
|
+
export declare const DH_BUNDLE_MAGIC: "DH-BUNDLE/1\n";
|
|
24
|
+
declare function bundleFrameSchema(): Type.TObject<{
|
|
25
|
+
readonly schema: Type.TLiteral<"dh.bundle-frame/1">;
|
|
26
|
+
readonly kind: Type.TEnum<["manifest-header", "manifest-page", "event", "artifact-metadata", "artifact-bytes", "end"]>;
|
|
27
|
+
readonly id: Type.TString;
|
|
28
|
+
readonly sizeBytes: Type.TInteger;
|
|
29
|
+
readonly sha256: Type.TString;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const parseDhBundleFrameHeader: (value: unknown) => {
|
|
32
|
+
readonly schema: "dh.bundle-frame/1";
|
|
33
|
+
readonly kind: "artifact-bytes" | "artifact-metadata" | "end" | "event" | "manifest-header" | "manifest-page";
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly sizeBytes: number;
|
|
36
|
+
readonly sha256: string;
|
|
37
|
+
};
|
|
38
|
+
export type DhBundleFrameHeader = Static<ReturnType<typeof bundleFrameSchema>>;
|
|
39
|
+
export declare const parseDhBundleSeal: (value: unknown) => {
|
|
40
|
+
readonly schema: "dh.bundle-seal/1";
|
|
41
|
+
readonly jobId: string;
|
|
42
|
+
readonly generationId: string;
|
|
43
|
+
readonly manifestSha256: string;
|
|
44
|
+
readonly headerSha256: string;
|
|
45
|
+
readonly eventCount: number;
|
|
46
|
+
readonly artifactCount: number;
|
|
47
|
+
readonly streamCount: number;
|
|
48
|
+
};
|
|
49
|
+
export type DhBundleSeal = ReturnType<typeof parseDhBundleSeal>;
|
|
50
|
+
export declare function parseDhBundleHeaderLength(bytes: Uint8Array): number;
|
|
51
|
+
export declare function assertDhExportDownloadBinding(descriptorInput: unknown, headerInput: unknown, options: DhExportHashOptions): Extract<DhExportDownload, {
|
|
52
|
+
state: "ready";
|
|
53
|
+
}>;
|
|
54
|
+
export interface DhBundleHasher {
|
|
55
|
+
update(bytes: Uint8Array): unknown;
|
|
56
|
+
digest(encoding: "hex"): string;
|
|
57
|
+
}
|
|
58
|
+
export interface DhBundleHashOptions extends DhExportHashOptions {
|
|
59
|
+
readonly createHasher: () => DhBundleHasher;
|
|
60
|
+
}
|
|
61
|
+
export interface DhBundleVerification {
|
|
62
|
+
readonly header: DhExportManifestHeader;
|
|
63
|
+
readonly descriptor: Extract<DhExportDownload, {
|
|
64
|
+
state: "ready";
|
|
65
|
+
}>;
|
|
66
|
+
readonly options: DhBundleHashOptions;
|
|
67
|
+
readonly hasher: DhBundleHasher;
|
|
68
|
+
readonly manifest: DhExportManifestValidation;
|
|
69
|
+
readonly members: Iterator<DhManifestEntry>;
|
|
70
|
+
bytes: number;
|
|
71
|
+
headerRead: boolean;
|
|
72
|
+
sealed: boolean;
|
|
73
|
+
failed: boolean;
|
|
74
|
+
member: DhManifestEntry | undefined;
|
|
75
|
+
pendingBytes: Extract<DhManifestEntry, {
|
|
76
|
+
kind: "artifact";
|
|
77
|
+
}> | undefined;
|
|
78
|
+
frame: {
|
|
79
|
+
header: DhBundleFrameHeader;
|
|
80
|
+
hasher: DhBundleHasher;
|
|
81
|
+
bytes: number;
|
|
82
|
+
} | undefined;
|
|
83
|
+
}
|
|
84
|
+
/** The second page scan is validated against the same sealed root before yielding members. */
|
|
85
|
+
export declare function beginDhBundleVerification(magic: Uint8Array, headerInput: unknown, descriptorInput: unknown, pages: Iterable<unknown>, options: DhBundleHashOptions): DhBundleVerification;
|
|
86
|
+
export declare function beginDhBundleFrame(state: DhBundleVerification, bytes: Uint8Array): DhBundleFrameHeader;
|
|
87
|
+
/** No chunk is retained; artifact bytes can be streamed at any caller-selected chunk size. */
|
|
88
|
+
export declare function acceptDhBundlePayloadChunk(state: DhBundleVerification, bytes: Uint8Array): void;
|
|
89
|
+
/** Non-byte frames require the caller's bounded raw parse; its canonical raw hash must agree with streamed bytes. */
|
|
90
|
+
export declare function finishDhBundleFrame(state: DhBundleVerification, recordInput?: unknown): void;
|
|
91
|
+
/** Publication is permitted only after this succeeds; the library performs no filesystem I/O. */
|
|
92
|
+
export declare function finishDhBundleVerification(state: DhBundleVerification): void;
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=trace-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-export.d.ts","sourceRoot":"","sources":["../src/trace-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,KAAK,gBAAgB,EAAyB,MAAM,gBAAgB,CAAC;AAE9E,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAMpB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,CAAC;CAClD;AACD,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;IACxC,QAAQ,CAA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