@agent-blueprint-protocol/verifier 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +891 -0
  2. package/LICENSE +190 -0
  3. package/NOTICE +4 -0
  4. package/README.md +199 -0
  5. package/dist/corpus/cases/base64url-decode.json +1 -0
  6. package/dist/corpus/cases/blueprint-decode.json +1 -0
  7. package/dist/corpus/cases/bounds-new.json +1 -0
  8. package/dist/corpus/cases/bounds_algebra-intersect.json +1 -0
  9. package/dist/corpus/cases/canonicalization-encode.json +1 -0
  10. package/dist/corpus/cases/compatibility-verify.json +1 -0
  11. package/dist/corpus/cases/deployment-decode.json +1 -0
  12. package/dist/corpus/cases/digest-tagged.json +1 -0
  13. package/dist/corpus/cases/extension-resolve.json +1 -0
  14. package/dist/corpus/cases/federation-decode.json +1 -0
  15. package/dist/corpus/cases/federation-verify_commitment.json +1 -0
  16. package/dist/corpus/cases/json-decode.json +1 -0
  17. package/dist/corpus/cases/negotiation-negotiate.json +1 -0
  18. package/dist/corpus/cases/portability-scan.json +1 -0
  19. package/dist/corpus/cases/schema-validate_instance.json +1 -0
  20. package/dist/corpus/cases/signature-verify.json +1 -0
  21. package/dist/corpus/index.json +1 -0
  22. package/dist/corpus/schemas/estate-contract.schema.json +1 -0
  23. package/dist/corpus/schemas/object.schema.json +1 -0
  24. package/dist/corpus/vectors/blueprint-golden.json +1 -0
  25. package/dist/corpus/vectors/deployment-golden.json +1 -0
  26. package/dist/corpus/vectors/rfc8785-numbers.json +1 -0
  27. package/dist/kit/cli.mjs +24 -0
  28. package/dist/verifier/b64url.d.ts +16 -0
  29. package/dist/verifier/b64url.js +36 -0
  30. package/dist/verifier/blueprint.d.ts +56 -0
  31. package/dist/verifier/blueprint.js +795 -0
  32. package/dist/verifier/bounds.d.ts +19 -0
  33. package/dist/verifier/bounds.js +45 -0
  34. package/dist/verifier/bounds_algebra.d.ts +27 -0
  35. package/dist/verifier/bounds_algebra.js +282 -0
  36. package/dist/verifier/canonical.d.ts +17 -0
  37. package/dist/verifier/canonical.js +160 -0
  38. package/dist/verifier/cli.d.ts +1 -0
  39. package/dist/verifier/cli.js +149 -0
  40. package/dist/verifier/compatibility.d.ts +22 -0
  41. package/dist/verifier/compatibility.js +112 -0
  42. package/dist/verifier/corpus.d.ts +42 -0
  43. package/dist/verifier/corpus.js +672 -0
  44. package/dist/verifier/decode.d.ts +16 -0
  45. package/dist/verifier/decode.js +457 -0
  46. package/dist/verifier/deployment.d.ts +49 -0
  47. package/dist/verifier/deployment.js +830 -0
  48. package/dist/verifier/digest.d.ts +23 -0
  49. package/dist/verifier/digest.js +58 -0
  50. package/dist/verifier/extension.d.ts +11 -0
  51. package/dist/verifier/extension.js +75 -0
  52. package/dist/verifier/federation.d.ts +76 -0
  53. package/dist/verifier/federation.js +817 -0
  54. package/dist/verifier/negotiation.d.ts +29 -0
  55. package/dist/verifier/negotiation.js +324 -0
  56. package/dist/verifier/portability.d.ts +12 -0
  57. package/dist/verifier/portability.js +184 -0
  58. package/dist/verifier/predicate.d.ts +10 -0
  59. package/dist/verifier/predicate.js +172 -0
  60. package/dist/verifier/registry.d.ts +16 -0
  61. package/dist/verifier/registry.js +120 -0
  62. package/dist/verifier/registry_engine.d.ts +42 -0
  63. package/dist/verifier/registry_engine.js +220 -0
  64. package/dist/verifier/report.d.ts +13 -0
  65. package/dist/verifier/report.js +29 -0
  66. package/dist/verifier/run_corpus.d.ts +1 -0
  67. package/dist/verifier/run_corpus.js +81 -0
  68. package/dist/verifier/runner.d.ts +20 -0
  69. package/dist/verifier/runner.js +778 -0
  70. package/dist/verifier/schema.d.ts +20 -0
  71. package/dist/verifier/schema.js +623 -0
  72. package/dist/verifier/self_checks.d.ts +1 -0
  73. package/dist/verifier/self_checks.js +316 -0
  74. package/dist/verifier/signature.d.ts +23 -0
  75. package/dist/verifier/signature.js +226 -0
  76. package/dist/verifier/value.d.ts +44 -0
  77. package/dist/verifier/value.js +77 -0
  78. package/package.json +42 -0
@@ -0,0 +1,29 @@
1
+ import { type RegState } from "./registry.ts";
2
+ import type { Value } from "./value.ts";
3
+ export interface RegistryEntryInput {
4
+ owner: string;
5
+ criticality: "critical" | "optional";
6
+ state: RegState;
7
+ schemaDigest: string | null;
8
+ a2aUri: string;
9
+ promotedAtRevision: number | null;
10
+ }
11
+ export interface Support {
12
+ revisions: Set<number>;
13
+ coreFields: Set<string>;
14
+ registry: Record<string, RegistryEntryInput>;
15
+ schemas: Record<string, Value>;
16
+ }
17
+ export interface Outcome {
18
+ protocolRevision: number;
19
+ criticalExtensions: string[];
20
+ quarantinedExtensions: string[];
21
+ notices: string[];
22
+ }
23
+ export declare function negotiate(artifact: Value, support: Support): {
24
+ ok: true;
25
+ v: Outcome;
26
+ } | {
27
+ ok: false;
28
+ e: string;
29
+ };
@@ -0,0 +1,324 @@
1
+ // Negotiation — the mirror of AgentBlueprintProtocol.Negotiation: the
2
+ // evolution gate over protocol machinery only (protocol_revision →
3
+ // required_core_fields → extensions, precedence pinned), the host-pinned
4
+ // lifecycle-only registry view layered over the compiled registry, the
5
+ // extension region state machine (criticality before state for LIVE states),
6
+ // digest-pinned schema validation of critical bodies, and the
7
+ // reserved-semantics denylist over all extension bodies.
8
+ import * as canonical from "./canonical.js";
9
+ import * as digest from "./digest.js";
10
+ import { keyfind } from "./registry_engine.js";
11
+ import { entry as compiledEntry } from "./registry.js";
12
+ import * as schema from "./schema.js";
13
+ const BLUEPRINT_CORE_MEMBERS = [
14
+ "blueprint_id",
15
+ "capability_requirements",
16
+ "ceilings",
17
+ "classification_ceiling",
18
+ "content_digest",
19
+ "effect_intents",
20
+ "evaluation_assertions",
21
+ "extensions",
22
+ "input_ports",
23
+ "output_contract",
24
+ "output_ports",
25
+ "producer",
26
+ "protocol_revision",
27
+ "release_number",
28
+ "required_core_fields",
29
+ "signatures",
30
+ "attestations",
31
+ "triggers",
32
+ ];
33
+ const DEPLOYMENT_CORE_MEMBERS = [
34
+ "authority_requirement",
35
+ "blueprint_release",
36
+ "build_identities",
37
+ "data_bindings",
38
+ "deployment_digest",
39
+ "effect_owner",
40
+ "eligibility",
41
+ "evaluation_binding",
42
+ "extensions",
43
+ "host_bounds",
44
+ "lifecycle",
45
+ "model_policy",
46
+ "protocol_revision",
47
+ "required_core_fields",
48
+ "scope_projection",
49
+ "signer_custody",
50
+ "signatures",
51
+ "attestations",
52
+ "tool_bindings",
53
+ ];
54
+ const BLUEPRINT_EVIDENCE_MEMBERS = ["content_digest", "signatures", "attestations"];
55
+ const DEPLOYMENT_EVIDENCE_MEMBERS = ["deployment_digest", "signatures", "attestations"];
56
+ // The protected families + the eight ceilings, snake and camel — stored
57
+ // NORMALIZED; kebab/upper/case-collapsed spellings converge at compare time.
58
+ const RESERVED_NAMES = new Set([
59
+ "approval_trait",
60
+ "approvaltrait",
61
+ "authority_trait",
62
+ "authoritytrait",
63
+ "classification_ceiling",
64
+ "classificationceiling",
65
+ "disclosure_ceiling",
66
+ "disclosureceiling",
67
+ "effect_impact_ceiling",
68
+ "effectimpactceiling",
69
+ "max_attempts",
70
+ "max_concurrency",
71
+ "max_cost",
72
+ "max_depth",
73
+ "max_descendants",
74
+ "max_elapsed_ms",
75
+ "max_fan_out",
76
+ "max_tokens",
77
+ "maxattempts",
78
+ "maxconcurrency",
79
+ "maxcost",
80
+ "maxdepth",
81
+ "maxdescendants",
82
+ "maxelapsedms",
83
+ "maxfanout",
84
+ "maxtokens",
85
+ ]);
86
+ export function negotiate(artifact, support) {
87
+ // Revision stays FIRST — a max+1 artifact reports its revision reason
88
+ // before any other defect.
89
+ const revision = revisionCheck(artifact, support);
90
+ if (!revision.ok)
91
+ return revision;
92
+ const vocabulary = vocabularyOf(artifact);
93
+ if (!vocabulary.ok)
94
+ return vocabulary;
95
+ const fields = requiredFieldsCheck(artifact, support, vocabulary.v);
96
+ if (!fields.ok)
97
+ return fields;
98
+ const extensions = extensionsCheck(artifact, support);
99
+ if (!extensions.ok)
100
+ return extensions;
101
+ return {
102
+ ok: true,
103
+ v: {
104
+ protocolRevision: revision.v,
105
+ criticalExtensions: extensions.v.critical,
106
+ quarantinedExtensions: extensions.v.quarantined,
107
+ notices: extensions.v.notices,
108
+ },
109
+ };
110
+ }
111
+ // The artifact kind resolves through MACHINERY only: which digest member the
112
+ // value carries selects the vocabulary. Neither member is an absent-machinery
113
+ // deny; both is an undecidable kind.
114
+ function vocabularyOf(value) {
115
+ const deployment = memberOf(value, "deployment_digest");
116
+ const blueprint = memberOf(value, "content_digest");
117
+ const deploymentString = deployment !== null && deployment.t === "str";
118
+ const blueprintString = blueprint !== null && blueprint.t === "str";
119
+ if (deploymentString && blueprintString)
120
+ return { ok: false, e: "invalid_type" };
121
+ if (deploymentString)
122
+ return { ok: true, v: { core: DEPLOYMENT_CORE_MEMBERS, evidence: DEPLOYMENT_EVIDENCE_MEMBERS } };
123
+ if (blueprintString)
124
+ return { ok: true, v: { core: BLUEPRINT_CORE_MEMBERS, evidence: BLUEPRINT_EVIDENCE_MEMBERS } };
125
+ if (deployment !== null || blueprint !== null)
126
+ return { ok: false, e: "invalid_type" };
127
+ return { ok: false, e: "missing_required_field" };
128
+ }
129
+ // ---- revision (first in the pinned order) -------------------------------------------
130
+ function revisionCheck(value, support) {
131
+ const found = memberOf(value, "protocol_revision");
132
+ if (found === null)
133
+ return { ok: false, e: "missing_required_field" };
134
+ if (found.t !== "int")
135
+ return { ok: false, e: "invalid_type" };
136
+ if (found.v < 1)
137
+ return { ok: false, e: "invalid_constraint" };
138
+ if (!support.revisions.has(found.v))
139
+ return { ok: false, e: "protocol_revision_unsupported" };
140
+ return { ok: true, v: found.v };
141
+ }
142
+ // ---- required_core_fields (second) -----------------------------------------------------
143
+ function requiredFieldsCheck(value, support, vocabulary) {
144
+ const found = memberOf(value, "required_core_fields");
145
+ if (found === null)
146
+ return { ok: false, e: "missing_required_field" };
147
+ if (found.t !== "arr")
148
+ return { ok: false, e: "invalid_type" };
149
+ for (const item of found.v) {
150
+ if (item.t !== "str")
151
+ return { ok: false, e: "invalid_type" };
152
+ const name = item.v;
153
+ if (!vocabulary.core.includes(name))
154
+ return { ok: false, e: "required_core_field_unsupported" };
155
+ if (vocabulary.evidence.includes(name))
156
+ return { ok: false, e: "required_core_field_not_digest_covered" };
157
+ if (!support.coreFields.has(name))
158
+ return { ok: false, e: "required_core_field_unsupported" };
159
+ }
160
+ return { ok: true };
161
+ }
162
+ function extensionsCheck(value, support) {
163
+ const found = memberOf(value, "extensions");
164
+ if (found === null)
165
+ return { ok: false, e: "missing_required_field" };
166
+ if (found.t !== "obj")
167
+ return { ok: false, e: "invalid_type" };
168
+ const regions = found.v;
169
+ // Both regions present, both objects — anything else is malformed machinery.
170
+ const names = regions.map(([name]) => name).sort();
171
+ const allObjects = regions.every(([, region]) => region.t === "obj");
172
+ if (names.length !== 2 || names[0] !== "critical" || names[1] !== "optional" || !allObjects) {
173
+ return { ok: false, e: "invalid_type" };
174
+ }
175
+ const reserved = reservedSemanticsCheck(regions);
176
+ if (!reserved.ok)
177
+ return reserved;
178
+ const critical = regionNamespaces(regions, "critical");
179
+ const optional = regionNamespaces(regions, "optional");
180
+ const flow = { critical: [], quarantined: [], notices: [] };
181
+ for (const ns of critical) {
182
+ const judgment = criticalJudgment(ns, regions, support);
183
+ if (!judgment.ok)
184
+ return judgment;
185
+ flow.critical.push(ns);
186
+ if (judgment.deprecated)
187
+ flow.notices.push("extension_deprecated");
188
+ }
189
+ for (const ns of optional) {
190
+ const judgment = optionalJudgment(ns, support);
191
+ if (typeof judgment === "object" && "error" in judgment)
192
+ return { ok: false, e: judgment.error };
193
+ if (judgment === "quarantine") {
194
+ flow.quarantined.push(ns);
195
+ flow.notices.push("extension_unknown_optional_retained");
196
+ }
197
+ else if (judgment.notice !== null) {
198
+ flow.notices.push(judgment.notice);
199
+ }
200
+ }
201
+ return { ok: true, v: flow };
202
+ }
203
+ // The host-pinned view is LIFECYCLE-ONLY over compiled entries: state may be
204
+ // supplied, but criticality and the schema digest pin are the registry's
205
+ // alone. Entries for namespaces the registry does not carry pass through as
206
+ // given (the host-supplied registration surface).
207
+ function resolveEntry(namespace, support) {
208
+ const override = support.registry[namespace];
209
+ if (override !== undefined) {
210
+ const valid = (override.criticality === "critical" || override.criticality === "optional") &&
211
+ ["reserved", "active", "deprecated", "retired"].includes(override.state);
212
+ if (valid) {
213
+ const compiled = compiledEntry(namespace);
214
+ if (compiled !== null) {
215
+ return { criticality: compiled.criticality, state: override.state, schemaDigest: compiled.schema_digest };
216
+ }
217
+ return {
218
+ criticality: override.criticality,
219
+ state: override.state,
220
+ schemaDigest: override.schemaDigest,
221
+ };
222
+ }
223
+ }
224
+ const compiled = compiledEntry(namespace);
225
+ if (compiled === null)
226
+ return null;
227
+ return { criticality: compiled.criticality, state: compiled.state, schemaDigest: compiled.schema_digest };
228
+ }
229
+ function regionNamespaces(regions, name) {
230
+ const found = regions.find(([key]) => key === name);
231
+ if (found === undefined || found[1].t !== "obj")
232
+ return [];
233
+ return found[1].v.map(([ns]) => ns);
234
+ }
235
+ function regionBody(regions, name, namespace) {
236
+ const found = regions.find(([key]) => key === name);
237
+ if (found === undefined || found[1].t !== "obj")
238
+ return null;
239
+ const body = found[1].v.find(([ns]) => ns === namespace);
240
+ return body ? body[1] : null;
241
+ }
242
+ function criticalJudgment(ns, regions, support) {
243
+ const entry = resolveEntry(ns, support);
244
+ if (entry === null)
245
+ return { ok: false, e: "extension_unknown_critical" };
246
+ if (entry.state === "retired")
247
+ return { ok: false, e: "extension_retired" };
248
+ if (entry.state === "reserved")
249
+ return { ok: false, e: "extension_unknown_critical" };
250
+ if (entry.criticality !== "critical")
251
+ return { ok: false, e: "extension_criticality_conflict" };
252
+ const body = regionBody(regions, "critical", ns);
253
+ const checked = criticalBodyCheck(entry, body, support, ns);
254
+ if (!checked.ok)
255
+ return checked;
256
+ return { ok: true, deprecated: entry.state === "deprecated" };
257
+ }
258
+ function criticalBodyCheck(entry, body, support, namespace) {
259
+ if (entry.schemaDigest === null)
260
+ return { ok: false, e: "extension_schema_unavailable" };
261
+ const schemaDocument = support.schemas[namespace];
262
+ if (schemaDocument === undefined)
263
+ return { ok: false, e: "extension_schema_unavailable" };
264
+ // The pin: JCS of the parsed document under the extension-schema domain.
265
+ const parsed = schema.parse(schemaDocument, schema.dialect());
266
+ if (!parsed.ok)
267
+ return parsed;
268
+ const jcs = canonical.encode(parsed.v.root);
269
+ if (!jcs.ok)
270
+ return jcs;
271
+ const tagged = digest.toTagged(digest.hash("extension_schema", Buffer.from(jcs.v, "utf8")));
272
+ if (tagged !== entry.schemaDigest)
273
+ return { ok: false, e: "extension_schema_digest_mismatch" };
274
+ return schema.validateInstance(schemaDocument, body, schema.dialect());
275
+ }
276
+ function optionalJudgment(ns, support) {
277
+ const entry = resolveEntry(ns, support);
278
+ if (entry === null)
279
+ return "quarantine";
280
+ switch (entry.state) {
281
+ case "retired":
282
+ return { notice: "extension_retired" };
283
+ case "reserved":
284
+ return { notice: "extension_unknown_optional_retained" };
285
+ case "deprecated":
286
+ if (entry.criticality === "optional")
287
+ return { notice: "extension_deprecated" };
288
+ return { error: "extension_criticality_conflict" };
289
+ case "active":
290
+ if (entry.criticality === "optional")
291
+ return { notice: null };
292
+ return { error: "extension_criticality_conflict" };
293
+ }
294
+ }
295
+ // ---- reserved-semantics denylist --------------------------------------------------------
296
+ function reservedSemanticsCheck(regions) {
297
+ for (const [, region] of regions) {
298
+ if (region.t !== "obj")
299
+ continue;
300
+ for (const [, body] of region.v) {
301
+ if (boundShapedWalk(body))
302
+ return { ok: false, e: "extension_payload_forbidden" };
303
+ }
304
+ }
305
+ return { ok: true };
306
+ }
307
+ function reservedShape(name) {
308
+ return name.toLowerCase().replaceAll("-", "_");
309
+ }
310
+ function boundShapedWalk(value) {
311
+ switch (value.t) {
312
+ case "obj":
313
+ return value.v.some(([name, member]) => RESERVED_NAMES.has(reservedShape(name)) || boundShapedWalk(member));
314
+ case "arr":
315
+ return value.v.some(boundShapedWalk);
316
+ default:
317
+ return false;
318
+ }
319
+ }
320
+ function memberOf(value, name) {
321
+ if (value.t !== "obj")
322
+ return null;
323
+ return keyfind(value.v, name);
324
+ }
@@ -0,0 +1,12 @@
1
+ import type { Value } from "./value.ts";
2
+ type ScanResult = {
3
+ ok: true;
4
+ } | {
5
+ ok: false;
6
+ e: "forbidden_portable_value";
7
+ };
8
+ export declare function scan(value: Value): ScanResult;
9
+ export declare function scanAuthored(value: Value): ScanResult;
10
+ export declare function scanIdentifier(value: Value): ScanResult;
11
+ export declare function scanValue(value: Value): ScanResult;
12
+ export {};
@@ -0,0 +1,184 @@
1
+ // The never-portable structural guard — the mirror of AgentBlueprintProtocol.Portability:
2
+ // member-name and value-shape denylists over tagged values, four walks
3
+ // (scan / scanAuthored / scanIdentifier / scanValue) with the position-scoped
4
+ // identifier exemption. Deny reason everywhere: forbidden_portable_value.
5
+ // The 34-name member denylist, verbatim, stored NORMALIZED (snake +
6
+ // case-folded, kebab folded in at compare time) so camel, kebab, and
7
+ // SCREAMING forms of one denied name converge.
8
+ const DENIED_NAMES_SOURCE = [
9
+ "secret",
10
+ "secrets",
11
+ "private_key",
12
+ "privateKey",
13
+ "api_key",
14
+ "apiKey",
15
+ "token",
16
+ "password",
17
+ "passphrase",
18
+ "credential",
19
+ "credentials",
20
+ "tenant_id",
21
+ "tenantId",
22
+ "org_id",
23
+ "orgId",
24
+ "user_id",
25
+ "userId",
26
+ "account_id",
27
+ "accountId",
28
+ "grantId",
29
+ "primaryKey",
30
+ "databaseUrl",
31
+ "connectionString",
32
+ "engineId",
33
+ "billingAccount",
34
+ "grant",
35
+ "grant_id",
36
+ "decision",
37
+ "endpoint",
38
+ "url",
39
+ "uri",
40
+ "href",
41
+ "dsn",
42
+ "connection_string",
43
+ "database_url",
44
+ "primary_key",
45
+ "row_id",
46
+ "billing_account",
47
+ "engine",
48
+ "engine_id",
49
+ "provider_key",
50
+ ];
51
+ const DENIED_NAMES = new Set(DENIED_NAMES_SOURCE.flatMap((name) => {
52
+ const normalized = name.toLowerCase().replaceAll("-", "_");
53
+ const folded = normalized.replaceAll("_", "");
54
+ return folded === normalized ? [normalized] : [normalized, folded];
55
+ }));
56
+ const PEM_MARKER = "-----BEGIN";
57
+ const MIN_SIGNATURE_CHARS = 43;
58
+ const SECRET_ENTROPY_BYTES = 24; // separator-free floor (the AES-128 hex class)
59
+ const SEPARATOR_BEARING_ENTROPY_BYTES = 32; // the base64url calibration
60
+ const HEX_CHUNK = /^[0-9a-fA-F]{1,2}$/;
61
+ const UUID_SHAPE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
62
+ const B64URL = /^[A-Za-z0-9_-]+$/;
63
+ // RFC 3986 scheme + "://" + non-empty authority, or the scheme-less
64
+ // network-path reference anchored at string start.
65
+ const NETWORK_URI = /[A-Za-z][A-Za-z0-9+.-]*:\/\/[^/\s#?]+|^\/\/[^/\s#?]+/;
66
+ const LOWER_IDENTIFIER = /^[a-z0-9_-]+$/;
67
+ const UPPER_IDENTIFIER = /^[A-Z0-9_-]+$/;
68
+ const forbidden = () => ({ ok: false, e: "forbidden_portable_value" });
69
+ // Names + values, identifier exemption OFF (extension bodies).
70
+ export function scan(value) {
71
+ return walk(value, true, false);
72
+ }
73
+ // Names + values, identifier exemption ON (authored JSON: schemas, predicate operands).
74
+ export function scanAuthored(value) {
75
+ return walk(value, true, true);
76
+ }
77
+ // Values only, identifier exemption ON (the protocol's identifier positions).
78
+ export function scanIdentifier(value) {
79
+ return walk(value, false, true);
80
+ }
81
+ // Values only, exemption OFF (every other string position).
82
+ export function scanValue(value) {
83
+ return walk(value, false, false);
84
+ }
85
+ function deniedName(name) {
86
+ const normalized = name.toLowerCase().replaceAll("-", "_");
87
+ return DENIED_NAMES.has(normalized);
88
+ }
89
+ function walk(value, names, exempt) {
90
+ switch (value.t) {
91
+ case "obj": {
92
+ if (names && value.v.some(([name]) => deniedName(name)))
93
+ return forbidden();
94
+ for (const [, member] of value.v) {
95
+ if (!walk(member, names, exempt).ok)
96
+ return forbidden();
97
+ }
98
+ return { ok: true };
99
+ }
100
+ case "arr": {
101
+ for (const item of value.v) {
102
+ if (!walk(item, names, exempt).ok)
103
+ return forbidden();
104
+ }
105
+ return { ok: true };
106
+ }
107
+ case "str":
108
+ if (exempt && identifierStyle(value.v))
109
+ return { ok: true };
110
+ return forbiddenValue(value.v) ? forbidden() : { ok: true };
111
+ default:
112
+ return { ok: true };
113
+ }
114
+ }
115
+ // ---- value shapes -------------------------------------------------------------------
116
+ function forbiddenValue(s) {
117
+ return !uuidShaped(s) && structuralSecret(s);
118
+ }
119
+ function uuidShaped(s) {
120
+ return UUID_SHAPE.test(s);
121
+ }
122
+ function structuralSecret(s) {
123
+ return (s.includes(PEM_MARKER) ||
124
+ compactJws(s) ||
125
+ NETWORK_URI.test(s) ||
126
+ rawKeyMaterial(s) ||
127
+ paddedStandardB64(s) ||
128
+ colonHexFingerprint(s));
129
+ }
130
+ // Pad-identified standard base64 (1-6 "=" at 32+ chars), or unpadded
131
+ // standard-alphabet runs at the 43-char calibration.
132
+ function paddedStandardB64(s) {
133
+ return /^[A-Za-z0-9+/]{32,}={1,6}$/.test(s) || /^[A-Za-z0-9+/]{43,}$/.test(s);
134
+ }
135
+ // 1-2 hex digits per ":" chunk, 24+ CHUNKS — each chunk is one byte in the
136
+ // SSH-fingerprint / EUI form, so zero-stripped one-digit chunks count fully.
137
+ function colonHexFingerprint(s) {
138
+ const chunks = s.split(":");
139
+ return chunks.length >= 24 && chunks.every((chunk) => HEX_CHUNK.test(chunk));
140
+ }
141
+ // RFC 7797 detached form carries an EMPTY payload segment; the header is
142
+ // never empty, the signature carries the ≥32-byte weight.
143
+ function compactJws(s) {
144
+ const parts = s.split(".");
145
+ if (parts.length !== 3)
146
+ return false;
147
+ const [header, payload, signature] = parts;
148
+ return (b64url(header) &&
149
+ header.length > 0 &&
150
+ (payload === "" || b64url(payload)) &&
151
+ b64url(signature) &&
152
+ Buffer.byteLength(signature, "utf8") >= MIN_SIGNATURE_CHARS);
153
+ }
154
+ function rawKeyMaterial(s) {
155
+ return b64url(s) && decodedBytes(s) >= entropyFloor(s);
156
+ }
157
+ function entropyFloor(s) {
158
+ return s.includes("-") || s.includes("_")
159
+ ? SEPARATOR_BEARING_ENTROPY_BYTES
160
+ : SECRET_ENTROPY_BYTES;
161
+ }
162
+ function b64url(s) {
163
+ return B64URL.test(s);
164
+ }
165
+ // One case, digits, and at least one `_` or `-` separator. POSITION-SCOPED:
166
+ // the artifact layer's call for positions whose convention it owns.
167
+ function identifierStyle(s) {
168
+ return ((s.includes("_") || s.includes("-")) &&
169
+ (LOWER_IDENTIFIER.test(s) || UPPER_IDENTIFIER.test(s)));
170
+ }
171
+ // Unpadded base64url length: 4k → 3k bytes, 4k+2 → 3k+1, 4k+3 → 3k+2.
172
+ function decodedBytes(s) {
173
+ const size = Buffer.byteLength(s, "utf8");
174
+ switch (size % 4) {
175
+ case 0:
176
+ return Math.floor((size * 3) / 4);
177
+ case 2:
178
+ return Math.floor(((size - 2) * 3) / 4) + 1;
179
+ case 3:
180
+ return Math.floor(((size - 3) * 3) / 4) + 2;
181
+ default:
182
+ return 0;
183
+ }
184
+ }
@@ -0,0 +1,10 @@
1
+ import type { Value } from "./value.ts";
2
+ type Reason = "predicate_op_unknown" | "predicate_path_unresolved" | "predicate_nodes_exceeded" | "unknown_member" | "missing_required_field" | "invalid_type" | "invalid_cardinality";
3
+ type VResult = {
4
+ ok: true;
5
+ } | {
6
+ ok: false;
7
+ e: Reason;
8
+ };
9
+ export declare function validate(predicate: Value, portNames: string[]): VResult;
10
+ export {};