@agent-blueprint-protocol/verifier 0.8.4 → 1.0.0-rc.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 +139 -0
- package/LICENSE +1 -1
- package/NOTICE +2 -2
- package/README.md +143 -255
- package/dist/corpus/cases/blueprint-decode.json +1 -1
- package/dist/corpus/cases/bounds-new.json +1 -1
- package/dist/corpus/cases/bounds_algebra-intersect.json +1 -1
- package/dist/corpus/cases/canonicalization-encode.json +1 -1
- package/dist/corpus/cases/deployment-decode.json +1 -1
- package/dist/corpus/cases/extension-resolve.json +1 -1
- package/dist/corpus/cases/federation-decode.json +1 -1
- package/dist/corpus/cases/federation-verify_commitment.json +1 -1
- package/dist/corpus/cases/json-decode.json +1 -1
- package/dist/corpus/cases/negotiation-negotiate.json +1 -1
- package/dist/corpus/cases/predicate.json +1 -0
- package/dist/corpus/cases/reconcile.json +1 -0
- package/dist/corpus/cases/schema-validate_instance.json +1 -1
- package/dist/corpus/cases/signature-verify.json +1 -1
- package/dist/corpus/index.json +1 -1
- package/dist/release-history.json +1 -0
- package/dist/release-metadata.json +1 -1
- package/dist/spec/FOUNDATION-TRANSITION.md +67 -0
- package/dist/spec/IPR.md +27 -0
- package/dist/spec/LICENSE +190 -0
- package/dist/spec/NOTICE +4 -0
- package/dist/spec/README.md +47 -0
- package/dist/spec/conformance/base64url-decode.schema.json +176 -0
- package/dist/spec/conformance/blueprint-decode.schema.json +280 -0
- package/dist/spec/conformance/bounds-new.schema.json +302 -0
- package/dist/spec/conformance/bounds_algebra-intersect.schema.json +457 -0
- package/dist/spec/conformance/canonicalization-encode.schema.json +280 -0
- package/dist/spec/conformance/case-file.schema.json +122 -0
- package/dist/spec/conformance/certified-results.json +1 -0
- package/dist/spec/conformance/claim.schema.json +52 -0
- package/dist/spec/conformance/compatibility-verify.schema.json +262 -0
- package/dist/spec/conformance/deployment-decode.schema.json +322 -0
- package/dist/spec/conformance/digest-tagged.schema.json +200 -0
- package/dist/spec/conformance/evidence.schema.json +249 -0
- package/dist/spec/conformance/execution.md +80 -0
- package/dist/spec/conformance/extension-resolve.schema.json +264 -0
- package/dist/spec/conformance/federation-decode.schema.json +318 -0
- package/dist/spec/conformance/federation-verify_commitment.schema.json +342 -0
- package/dist/spec/conformance/index.schema.json +102 -0
- package/dist/spec/conformance/json-decode.schema.json +287 -0
- package/dist/spec/conformance/negotiation-negotiate.schema.json +264 -0
- package/dist/spec/conformance/portability-scan.schema.json +188 -0
- package/dist/spec/conformance/predicate.schema.json +201 -0
- package/dist/spec/conformance/reconcile.schema.json +287 -0
- package/dist/spec/conformance/runner.md +185 -0
- package/dist/spec/conformance/schema-validate_instance.schema.json +206 -0
- package/dist/spec/conformance/signature-verify.schema.json +224 -0
- package/dist/spec/conformance/support.schema.json +72 -0
- package/dist/spec/errata.md +13 -0
- package/dist/spec/grammar/blueprint.cddl +92 -0
- package/dist/spec/grammar/deployment.cddl +125 -0
- package/dist/spec/grammar/derived/blueprint.schema.json +340 -0
- package/dist/spec/grammar/derived/deployment.schema.json +496 -0
- package/dist/spec/grammar/derived/taskenvelope.schema.json +244 -0
- package/dist/spec/grammar/taskenvelope.cddl +77 -0
- package/dist/spec/protocol.md +1237 -0
- package/dist/spec/registry/OPERATIONS.md +78 -0
- package/dist/spec/registry/registry.json +23 -0
- package/dist/verifier/b64url.js +1 -1
- package/dist/verifier/blueprint.d.ts +2 -15
- package/dist/verifier/blueprint.js +21 -107
- package/dist/verifier/bounds_algebra.d.ts +9 -0
- package/dist/verifier/bounds_algebra.js +6 -6
- package/dist/verifier/cli.js +14 -31
- package/dist/verifier/corpus.d.ts +1 -1
- package/dist/verifier/corpus.js +5 -1
- package/dist/verifier/decode.js +15 -3
- package/dist/verifier/deployment.d.ts +8 -0
- package/dist/verifier/deployment.js +17 -2
- package/dist/verifier/digest.js +1 -1
- package/dist/verifier/errors.d.ts +2 -0
- package/dist/verifier/errors.js +1 -0
- package/dist/verifier/execution.d.ts +13 -0
- package/dist/verifier/execution.js +82 -0
- package/dist/verifier/facade.d.ts +311 -0
- package/dist/verifier/facade.js +78 -0
- package/dist/verifier/federation.d.ts +2 -2
- package/dist/verifier/federation.js +10 -7
- package/dist/verifier/harness.d.ts +16 -0
- package/dist/verifier/harness.js +201 -0
- package/dist/verifier/index.d.ts +3 -0
- package/dist/verifier/index.js +2 -0
- package/dist/verifier/mapping.d.ts +139 -0
- package/dist/verifier/mapping.js +1 -0
- package/dist/verifier/negotiation.d.ts +2 -1
- package/dist/verifier/negotiation.js +6 -3
- package/dist/verifier/plain.d.ts +4 -0
- package/dist/verifier/plain.js +38 -0
- package/dist/verifier/predicate.d.ts +7 -0
- package/dist/verifier/predicate.js +60 -1
- package/dist/verifier/reconcile.d.ts +37 -0
- package/dist/verifier/reconcile.js +115 -0
- package/dist/verifier/registry.js +9 -51
- package/dist/verifier/registry_engine.d.ts +3 -0
- package/dist/verifier/registry_engine.js +8 -8
- package/dist/verifier/results.d.ts +3 -0
- package/dist/verifier/results.js +13 -0
- package/dist/verifier/runner.d.ts +2 -0
- package/dist/verifier/runner.js +115 -16
- package/dist/verifier/signature.d.ts +17 -6
- package/dist/verifier/signature.js +41 -25
- package/package.json +17 -12
- package/dist/corpus/schemas/estate-contract.schema.json +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as blueprint from './blueprint.js';
|
|
2
|
+
import * as deployment from './deployment.js';
|
|
3
|
+
import * as negotiation from './negotiation.js';
|
|
4
|
+
import * as algebra from './bounds_algebra.js';
|
|
5
|
+
import * as signature from './signature.js';
|
|
6
|
+
import * as digest from './digest.js';
|
|
7
|
+
import { validate } from './registry_engine.js';
|
|
8
|
+
import { member, memberString } from './corpus.js';
|
|
9
|
+
import { plain, jsonValue } from './plain.js';
|
|
10
|
+
import { isValue } from './value.js';
|
|
11
|
+
const HOST_OWNED = ['tenancy', 'live_policy', 'authority', 'effect_ownership', 'execution', 'billing', 'evaluation_truth'];
|
|
12
|
+
const CLASSIFICATION = ['public', 'internal', 'confidential', 'restricted'];
|
|
13
|
+
function failure(e, subject = []) { return { ok: false, e, subject }; }
|
|
14
|
+
function lift(bp) {
|
|
15
|
+
const b = plain(bp.value);
|
|
16
|
+
const sites = [b.classification_ceiling, b.output_contract.classification_ceiling, ...b.input_ports.map((p) => p.classification_ceiling), ...b.output_ports.map((p) => p.classification_ceiling), ...b.capability_requirements.map((p) => p.classification_ceiling)];
|
|
17
|
+
const strongest = (values, order) => order[Math.max(0, ...values.map(x => order.indexOf(x)))];
|
|
18
|
+
return { ...b.ceilings, classification_ceiling: { ordinal: strongest(sites, CLASSIFICATION), markers: [] }, disclosure_ceiling: 'full', approval_trait: strongest(b.capability_requirements.map((x) => x.approval_trait), ['none', 'human_required', 'separated_human_required']), authority_trait: strongest(b.capability_requirements.map((x) => x.authority_trait), ['none', 'local_policy', 'external_authority_required']), effect_impact_ceiling: strongest([...b.capability_requirements, ...b.effect_intents].map((x) => x.impact_class), ['ordinary', 'money', 'authority', 'secret']) };
|
|
19
|
+
}
|
|
20
|
+
export function reconcile(bp, dep, inputs) {
|
|
21
|
+
if (!bp || !isValue(bp.value))
|
|
22
|
+
return failure('invalid_type', ['blueprint']);
|
|
23
|
+
if (!dep || !isValue(dep.value))
|
|
24
|
+
return failure('invalid_type', ['deployment']);
|
|
25
|
+
if (!inputs || typeof inputs !== 'object')
|
|
26
|
+
return failure('invalid_type', ['inputs']);
|
|
27
|
+
for (const key of ['support', 'observations', 'hostBounds'])
|
|
28
|
+
if (!inputs[key] || typeof inputs[key] !== 'object')
|
|
29
|
+
return failure('invalid_type', ['inputs', key === 'hostBounds' ? 'host_bounds' : key]);
|
|
30
|
+
if (!Array.isArray(inputs.keys))
|
|
31
|
+
return failure('invalid_type', ['inputs', 'keys']);
|
|
32
|
+
for (let i = 0; i < inputs.keys.length; i++)
|
|
33
|
+
if (!inputs.keys[i] || typeof inputs.keys[i] !== 'object')
|
|
34
|
+
return failure('invalid_type', ['inputs', 'keys', i]);
|
|
35
|
+
if (!['deny', 'acknowledge'].includes(inputs.protectedClamp))
|
|
36
|
+
return failure('invalid_type', ['inputs', 'protected_clamp']);
|
|
37
|
+
const checks = [];
|
|
38
|
+
const checked = (surface, subject, verified = true, detail = null) => checks.push({ surface, subject: [subject], verified, detail });
|
|
39
|
+
const artifacts = [['blueprint', bp, blueprint], ['deployment', dep, deployment]];
|
|
40
|
+
// Stage order is part of the verification contract.
|
|
41
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
42
|
+
if (artifact.value.t !== 'obj')
|
|
43
|
+
return failure('invalid_type', [name]);
|
|
44
|
+
const result = mod.canonicalBytes(artifact); // stage: canonical
|
|
45
|
+
if (!result.ok)
|
|
46
|
+
return failure(result.e, [name]);
|
|
47
|
+
checked('canonical', name);
|
|
48
|
+
}
|
|
49
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
50
|
+
const result = mod.verifyContentDigest(artifact); // stage: digest
|
|
51
|
+
if (!result.ok)
|
|
52
|
+
return failure(result.e, [name]);
|
|
53
|
+
checked('digest', name, true, mod.contentDigest(artifact));
|
|
54
|
+
}
|
|
55
|
+
const outcomes = [];
|
|
56
|
+
for (const [name, artifact] of artifacts) {
|
|
57
|
+
const result = negotiation.negotiate(artifact.value, inputs.support); // stage: negotiation
|
|
58
|
+
if (!result.ok)
|
|
59
|
+
return failure(result.e, [name, ...(result.e === 'protocol_revision_unsupported' ? ['protocol_revision'] : result.e === 'required_core_field_unsupported' || result.e === 'required_core_field_not_digest_covered' ? ['required_core_fields'] : [])]);
|
|
60
|
+
outcomes.push(result.v);
|
|
61
|
+
checked('negotiation', name);
|
|
62
|
+
}
|
|
63
|
+
for (const outcome of outcomes) {
|
|
64
|
+
for (const ns of outcome.quarantinedExtensions)
|
|
65
|
+
checked('extensions', ns, false, 'quarantined');
|
|
66
|
+
for (const ns of outcome.optionalRetained)
|
|
67
|
+
checked('extensions', ns, false, 'retained');
|
|
68
|
+
}
|
|
69
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
70
|
+
const result = validate(mod.table(), artifact.value); // stage: structure
|
|
71
|
+
if (!result.ok)
|
|
72
|
+
return failure(result.e, [name, ...(result.subject ?? [])]);
|
|
73
|
+
checked('structure', name);
|
|
74
|
+
}
|
|
75
|
+
for (let i = 0; i < artifacts.length; i++) {
|
|
76
|
+
const [name, artifact, mod] = artifacts[i];
|
|
77
|
+
const result = mod.scan(artifact.value, new Set(outcomes[i].criticalExtensions)); // stage: portability
|
|
78
|
+
if (!result.ok)
|
|
79
|
+
return failure(result.e, [name]);
|
|
80
|
+
checked('portability', name);
|
|
81
|
+
}
|
|
82
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
83
|
+
const entries = member(artifact.value, 'signatures');
|
|
84
|
+
const signatures = entries?.t === 'arr' ? entries.v : [];
|
|
85
|
+
for (let i = 0; i < signatures.length; i++) {
|
|
86
|
+
const result = signature.verify(signatures[i], inputs.keys); // stage: signatures
|
|
87
|
+
if (!result.ok)
|
|
88
|
+
return failure(result.e, [name, 'signatures', i, ...(result.subject ?? [])]);
|
|
89
|
+
if (digest.toTagged(result.v.contentDigest) !== mod.contentDigest(artifact))
|
|
90
|
+
return failure('digest_mismatch', [name, 'signatures', i]);
|
|
91
|
+
}
|
|
92
|
+
checked('signatures', name, signatures.length > 0, signatures.length ? { key_ids: [...new Set(signatures.map(x => { const a = signature.attributes(x); if (!a.ok)
|
|
93
|
+
throw Error('signature invariant'); return a.v.keyId; }))] } : 'no_signatures_present');
|
|
94
|
+
}
|
|
95
|
+
const binding = deployment.verifyBinding(dep, bp, inputs.observations); // stage: bind
|
|
96
|
+
if (!binding.ok)
|
|
97
|
+
return failure(binding.e, ['deployment', ...(binding.subject ?? [])]);
|
|
98
|
+
const bindings = member(dep.value, 'tool_bindings');
|
|
99
|
+
const names = bindings.v.map(x => memberString(x, 'logical_operation'));
|
|
100
|
+
const staleness = names.length > 0 && inputs.observations.now !== null && inputs.observations.maxAttestationAgeMs !== null;
|
|
101
|
+
const descriptors = names.length > 0 && names.every(x => Object.hasOwn(inputs.observations.observed, x));
|
|
102
|
+
const extra = [['binding_staleness', staleness], ['binding_descriptors', descriptors]];
|
|
103
|
+
const skipped = extra.filter(x => !x[1]).map(x => x[0]);
|
|
104
|
+
checked('bind', 'deployment', skipped.length === 0, { checked: ['release_binding', 'binding_completeness', 'effect_recovery', ...extra.filter(x => x[1]).map(x => x[0])], not_verified: skipped });
|
|
105
|
+
const depBounds = plain(member(dep.value, 'host_bounds'));
|
|
106
|
+
depBounds.classification_ceiling = { ordinal: depBounds.classification_ceiling, markers: [] };
|
|
107
|
+
const bounds = algebra.intersect(lift(bp), depBounds, inputs.hostBounds, inputs.protectedClamp); // stage: bounds
|
|
108
|
+
if (!bounds.ok)
|
|
109
|
+
return failure(bounds.e, bounds.subject ?? []);
|
|
110
|
+
checked('bounds', 'bounds');
|
|
111
|
+
const clamps = jsonValue(bounds.v.clamps.map(c => ({ field: c.field, class: c.cls, unit: c.cls === 'protected' ? 'ordinal' : c.field === 'max_cost' ? 'money' : c.field === 'max_elapsed_ms' ? 'millisecond' : c.field === 'max_tokens' ? 'token' : 'count', requested: c.requested, effective: c.effective, source: c.source, acknowledged: c.acknowledged }))).map((c) => { delete c.cls; return c; });
|
|
112
|
+
for (const clamp of clamps)
|
|
113
|
+
checked('bounds', clamp.field, true, clamp);
|
|
114
|
+
return { ok: true, v: { protocol_revision: plain(member(bp.value, 'protocol_revision')), blueprint_digest: blueprint.contentDigest(bp), deployment_digest: deployment.contentDigest(dep), checks, effective_bounds: bounds.v.effective, clamps, optional_extensions_retained: [...new Set(outcomes.flatMap(o => o.optionalRetained))], not_verified: [...new Set([...HOST_OWNED, 'signature_created_at', 'lifecycle_state', ...checks.flatMap(c => c.verified ? [] : [c.surface]), ...skipped])] } };
|
|
115
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
// The
|
|
2
|
-
//
|
|
3
|
-
// the
|
|
4
|
-
// to. Agreement with the Elixir twin is proven by the corpus's own
|
|
5
|
-
// registry_digest check at load — neither side reads the other's source.
|
|
1
|
+
// The protocol-owned federation registry and schema. Hosts supply other
|
|
2
|
+
// registrations through negotiation support. The corpus binds both runtimes
|
|
3
|
+
// to the same registry content digest.
|
|
6
4
|
import * as digest from "./digest.js";
|
|
7
5
|
import { encode } from "./canonical.js";
|
|
8
6
|
import { bool, int, nil, obj, str } from "./value.js";
|
|
@@ -31,61 +29,21 @@ function taggedFederationDigest() {
|
|
|
31
29
|
function entries() {
|
|
32
30
|
return [
|
|
33
31
|
{
|
|
34
|
-
namespace: "com.example
|
|
35
|
-
owner: "
|
|
32
|
+
namespace: "com.example/federation",
|
|
33
|
+
owner: "Agent Blueprint Protocol",
|
|
36
34
|
criticality: "critical",
|
|
37
|
-
state: "active",
|
|
38
|
-
schema_digest: null,
|
|
39
|
-
a2a_uri: "https://example.com/extensions/commerce-graph",
|
|
40
|
-
promoted_at_revision: null,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
namespace: "com.example.commerce/classification-labels",
|
|
44
|
-
owner: "ExampleCommerce",
|
|
45
|
-
criticality: "optional",
|
|
46
|
-
state: "active",
|
|
47
|
-
schema_digest: null,
|
|
48
|
-
a2a_uri: "https://example.com/extensions/commerce-classification-labels",
|
|
49
|
-
promoted_at_revision: null,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
namespace: "com.example.commerce/rubric-assertion",
|
|
53
|
-
owner: "ExampleCommerce",
|
|
54
|
-
criticality: "optional",
|
|
55
|
-
state: "active",
|
|
56
|
-
schema_digest: null,
|
|
57
|
-
a2a_uri: "https://example.com/extensions/commerce-rubric-assertion",
|
|
58
|
-
promoted_at_revision: null,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
namespace: "com.example.platform/estate",
|
|
62
|
-
owner: "ExamplePlatform",
|
|
63
|
-
criticality: "optional",
|
|
64
35
|
state: "deprecated",
|
|
65
|
-
schema_digest:
|
|
66
|
-
a2a_uri: "https://example.com/extensions/
|
|
67
|
-
promoted_at_revision: null,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
// The product-extension registration: the first product-owned critical
|
|
71
|
-
// pin. The document is corpus data (schemas/estate-contract.schema.json);
|
|
72
|
-
// this digest is JCS-of-parsed-document under the extension-schema
|
|
73
|
-
// domain, bound to the shipped file by the Elixir pin test.
|
|
74
|
-
namespace: "com.example.platform/estate-contract",
|
|
75
|
-
owner: "ExamplePlatform",
|
|
76
|
-
criticality: "critical",
|
|
77
|
-
state: "active",
|
|
78
|
-
schema_digest: "sha-256:s_ToZWwxrhhd4vVxAyUh2Q6Gddston4tBSLHTLvCQAw",
|
|
79
|
-
a2a_uri: "https://example.com/extensions/platform-estate-contract",
|
|
36
|
+
schema_digest: taggedFederationDigest(),
|
|
37
|
+
a2a_uri: "https://example.com/extensions/federation",
|
|
80
38
|
promoted_at_revision: null,
|
|
81
39
|
},
|
|
82
40
|
{
|
|
83
|
-
namespace: "
|
|
41
|
+
namespace: "io.github.baselabs/federation",
|
|
84
42
|
owner: "Agent Blueprint Protocol",
|
|
85
43
|
criticality: "critical",
|
|
86
44
|
state: "active",
|
|
87
45
|
schema_digest: taggedFederationDigest(),
|
|
88
|
-
a2a_uri: "https://
|
|
46
|
+
a2a_uri: "https://baselabs.github.io/agent_blueprint_protocol/extensions/federation",
|
|
89
47
|
promoted_at_revision: null,
|
|
90
48
|
},
|
|
91
49
|
];
|
|
@@ -13,12 +13,14 @@ export type Check = (value: Value) => {
|
|
|
13
13
|
} | {
|
|
14
14
|
ok: false;
|
|
15
15
|
e: string;
|
|
16
|
+
subject?: (string | number)[];
|
|
16
17
|
};
|
|
17
18
|
export type RootHook = (members: Map<string, Value>) => {
|
|
18
19
|
ok: true;
|
|
19
20
|
} | {
|
|
20
21
|
ok: false;
|
|
21
22
|
e: string;
|
|
23
|
+
subject?: (string | number)[];
|
|
22
24
|
};
|
|
23
25
|
export interface Spec {
|
|
24
26
|
name?: string;
|
|
@@ -35,6 +37,7 @@ export type VResult = {
|
|
|
35
37
|
} | {
|
|
36
38
|
ok: false;
|
|
37
39
|
e: string;
|
|
40
|
+
subject?: (string | number)[];
|
|
38
41
|
};
|
|
39
42
|
export declare function field(name: string, kind: Kind, opts?: Partial<Spec>): Spec;
|
|
40
43
|
export declare function validate(table: Spec[], value: Value): VResult;
|
|
@@ -21,13 +21,13 @@ export function validate(table, value) {
|
|
|
21
21
|
const tableNames = new Set(table.map((spec) => spec.name));
|
|
22
22
|
for (const [name] of members) {
|
|
23
23
|
if (!tableNames.has(name))
|
|
24
|
-
return { ok: false, e: "unknown_member" };
|
|
24
|
+
return { ok: false, e: "unknown_member", subject: [] };
|
|
25
25
|
}
|
|
26
26
|
const present = new Set(members.map(([name]) => name));
|
|
27
27
|
for (const spec of table) {
|
|
28
28
|
// Table specs always come from field() (named); the ! mirrors that invariant.
|
|
29
29
|
if (spec.required && !present.has(spec.name))
|
|
30
|
-
return { ok: false, e: "missing_required_field" };
|
|
30
|
+
return { ok: false, e: "missing_required_field", subject: [spec.name] };
|
|
31
31
|
}
|
|
32
32
|
// Every table stage shares one walk: find the first spec (in table order)
|
|
33
33
|
// whose present value fails.
|
|
@@ -38,7 +38,7 @@ export function validate(table, value) {
|
|
|
38
38
|
continue;
|
|
39
39
|
const failure = judge(spec, found);
|
|
40
40
|
if (failure !== null)
|
|
41
|
-
return { ok: false, e: failure.e };
|
|
41
|
+
return { ok: false, e: failure.e, subject: [spec.name, ...(failure.subject ?? [])] };
|
|
42
42
|
}
|
|
43
43
|
return { ok: true };
|
|
44
44
|
};
|
|
@@ -62,7 +62,7 @@ export function validate(table, value) {
|
|
|
62
62
|
continue;
|
|
63
63
|
const result = spec.rootHook(memberMap);
|
|
64
64
|
if (!result.ok)
|
|
65
|
-
return result;
|
|
65
|
+
return { ...result, subject: [spec.name, ...(result.subject ?? [])] };
|
|
66
66
|
}
|
|
67
67
|
return { ok: true };
|
|
68
68
|
}
|
|
@@ -94,7 +94,7 @@ function specConstraint(spec, value) {
|
|
|
94
94
|
}
|
|
95
95
|
if (spec.check !== undefined) {
|
|
96
96
|
const result = spec.check(value);
|
|
97
|
-
return result.ok ? null :
|
|
97
|
+
return result.ok ? null : result;
|
|
98
98
|
}
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
@@ -137,10 +137,10 @@ function recurse(kind, value) {
|
|
|
137
137
|
if (typeof kind === "object" && "array" in kind) {
|
|
138
138
|
if (value.t !== "arr")
|
|
139
139
|
return { ok: true };
|
|
140
|
-
for (const item of value.v) {
|
|
140
|
+
for (const [index, item] of value.v.entries()) {
|
|
141
141
|
const result = elementOk(kind.array, item);
|
|
142
142
|
if (!result.ok)
|
|
143
|
-
return result;
|
|
143
|
+
return { ...result, subject: [index, ...(result.subject ?? [])] };
|
|
144
144
|
}
|
|
145
145
|
return { ok: true };
|
|
146
146
|
}
|
|
@@ -156,7 +156,7 @@ function elementOk(spec, value) {
|
|
|
156
156
|
return { ok: false, e: "invalid_type" };
|
|
157
157
|
const constraint = specConstraint(spec, value);
|
|
158
158
|
if (constraint !== null)
|
|
159
|
-
return
|
|
159
|
+
return constraint;
|
|
160
160
|
return recurse(spec.kind, value);
|
|
161
161
|
}
|
|
162
162
|
// ---- kinds --------------------------------------------------------------------------
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { encode } from './canonical.js';
|
|
2
|
+
import { tagged } from './plain.js';
|
|
3
|
+
import { project } from './runner.js';
|
|
4
|
+
import { memberString } from './corpus.js';
|
|
5
|
+
export function canonical(value) {
|
|
6
|
+
const result = encode(tagged(value));
|
|
7
|
+
if (!result.ok)
|
|
8
|
+
throw new TypeError(result.e);
|
|
9
|
+
return result.v;
|
|
10
|
+
}
|
|
11
|
+
export function resultsDocument(corpus) {
|
|
12
|
+
return { format: 'agent-blueprint-protocol-conformance-results', corpus_digest: corpus.identity, registry_digest: memberString(corpus.index, 'registry_digest'), results: corpus.cases.flatMap(f => f.cases).sort((a, b) => Buffer.compare(Buffer.from(a.id), Buffer.from(b.id))).map(c => ({ id: c.id, surface: c.surface, result: project(c, corpus.data, corpus.raws) })) };
|
|
13
|
+
}
|
|
@@ -20,5 +20,7 @@ export type SurfaceResult = {
|
|
|
20
20
|
} | {
|
|
21
21
|
ok: false;
|
|
22
22
|
e: string;
|
|
23
|
+
subject?: (string | number)[];
|
|
23
24
|
};
|
|
24
25
|
export { str, int, float, nil };
|
|
26
|
+
export declare function project(caseObj: CaseObj, data: Map<string, Value>, raws: Map<string, Buffer>): Record<string, unknown>;
|
package/dist/verifier/runner.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import * as reconcile from "./reconcile.js";
|
|
2
|
+
import * as predicate from "./predicate.js";
|
|
3
|
+
import { plain, jsonValue } from "./plain.js";
|
|
4
|
+
import * as canonical from "./canonical.js";
|
|
1
5
|
import { isValue } from "./value.js";
|
|
2
6
|
// The case executor — the mirror of AgentBlueprintProtocol.Conformance.Runner:
|
|
3
7
|
// dispatches each corpus case against the verifier's own surface twins and
|
|
@@ -70,6 +74,9 @@ function agrees(expected, actual) {
|
|
|
70
74
|
return false;
|
|
71
75
|
const verdict = memberString(expected, "verdict");
|
|
72
76
|
if (verdict === "invalid") {
|
|
77
|
+
const subject = member(expected, "subject");
|
|
78
|
+
if (!actual.ok && subject !== null && !deepEqual(subject, actual.subject ?? []))
|
|
79
|
+
return false;
|
|
73
80
|
if (!actual.ok)
|
|
74
81
|
return actual.e === memberString(expected, "code");
|
|
75
82
|
return false;
|
|
@@ -211,6 +218,52 @@ function dispatch(surface, input, data, raws) {
|
|
|
211
218
|
return encoded;
|
|
212
219
|
return { ok: true, v: { encoded: encoded.v } };
|
|
213
220
|
}
|
|
221
|
+
case "reconcile": {
|
|
222
|
+
const b = memberString(input, "blueprint"), d = memberString(input, "deployment");
|
|
223
|
+
if (b === null || d === null)
|
|
224
|
+
return { ok: false, e: "invalid_type" };
|
|
225
|
+
const bp = canonical.verify(b), dep = canonical.verify(d);
|
|
226
|
+
if (!bp.ok)
|
|
227
|
+
return bp;
|
|
228
|
+
if (!dep.ok)
|
|
229
|
+
return dep;
|
|
230
|
+
const host = member(input, "inputs");
|
|
231
|
+
if (host?.t !== "obj")
|
|
232
|
+
return { ok: false, e: "invalid_type" };
|
|
233
|
+
const support = buildSupport(host);
|
|
234
|
+
if (!support.ok)
|
|
235
|
+
return support;
|
|
236
|
+
const raw = plain(host);
|
|
237
|
+
const observations = member(host, "observations");
|
|
238
|
+
if (observations !== null && observations.t !== "obj")
|
|
239
|
+
return { ok: false, e: "invalid_type" };
|
|
240
|
+
const hostBounds = boundSet(host, "host_bounds");
|
|
241
|
+
if (!hostBounds.ok)
|
|
242
|
+
return hostBounds;
|
|
243
|
+
const keys = buildKeys({ t: "obj", v: [["keys", member(host, "keys") ?? { t: "arr", v: [] }]] });
|
|
244
|
+
if (!keys.ok)
|
|
245
|
+
return keys;
|
|
246
|
+
const now = raw.observations?.now ?? null;
|
|
247
|
+
if (now !== null && (typeof now !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.test(now) || deployment.parseTimestamp(now) === null))
|
|
248
|
+
return { ok: false, e: "invalid_type", subject: ["now"] };
|
|
249
|
+
const result = reconcile.reconcile({ value: bp.v }, { value: dep.v }, { hostBounds: hostBounds.v, support: support.v, keys: keys.v, protectedClamp: raw.protected_clamp === "acknowledge" ? "acknowledge" : "deny", observations: { now, maxAttestationAgeMs: raw.observations?.max_attestation_age_ms ?? null, observed: raw.observations && Object.hasOwn(raw.observations, "observed") ? raw.observations.observed : {} } });
|
|
250
|
+
return result.ok ? { ok: true, v: { evidence: result.v } } : result;
|
|
251
|
+
}
|
|
252
|
+
case "predicate": {
|
|
253
|
+
const p = member(input, "predicate"), names = member(input, "port_names");
|
|
254
|
+
if (!p || names?.t !== "arr")
|
|
255
|
+
return { ok: false, e: "invalid_type" };
|
|
256
|
+
const validated = predicate.validate(p, plain(names));
|
|
257
|
+
if (!validated.ok)
|
|
258
|
+
return validated;
|
|
259
|
+
if (memberString(input, "mode") === "validate")
|
|
260
|
+
return { ok: true, v: { valid: true } };
|
|
261
|
+
const ports = member(input, "ports");
|
|
262
|
+
if (memberString(input, "mode") !== "evaluate" || ports?.t !== "obj")
|
|
263
|
+
return { ok: false, e: "invalid_type" };
|
|
264
|
+
const result = predicate.evaluate(p, new Map(ports.v), plain(names));
|
|
265
|
+
return result.ok ? { ok: true, v: { value: result.v } } : result;
|
|
266
|
+
}
|
|
214
267
|
case "base64url.decode": {
|
|
215
268
|
const segment = memberString(input, "base64url");
|
|
216
269
|
if (segment === null)
|
|
@@ -295,6 +348,9 @@ function dispatch(surface, input, data, raws) {
|
|
|
295
348
|
const instance = taggedField(input, "instance");
|
|
296
349
|
if (!instance.ok)
|
|
297
350
|
return instance;
|
|
351
|
+
const dialectRaw = member(input, "dialect");
|
|
352
|
+
if (dialectRaw !== null && dialectRaw.t !== "null" && dialectRaw.t !== "str")
|
|
353
|
+
return { ok: false, e: "invalid_type" };
|
|
298
354
|
const dialect = memberString(input, "dialect") ?? schema.dialect();
|
|
299
355
|
const validated = schema.validateInstance(schemaInput.v, instance.v, dialect);
|
|
300
356
|
if ("ok" in validated && !validated.ok)
|
|
@@ -447,7 +503,7 @@ function inputBytes(input, raws) {
|
|
|
447
503
|
}
|
|
448
504
|
function boundsOverrides(input) {
|
|
449
505
|
const overrides = member(input, "bounds");
|
|
450
|
-
if (overrides === null)
|
|
506
|
+
if (overrides === null || overrides.t === "null")
|
|
451
507
|
return { ok: true, v: {} };
|
|
452
508
|
if (overrides.t !== "obj")
|
|
453
509
|
return { ok: false, e: "invalid_type" };
|
|
@@ -518,25 +574,32 @@ function buildKeys(input) {
|
|
|
518
574
|
return { ok: true, v: out };
|
|
519
575
|
}
|
|
520
576
|
function buildSupport(input) {
|
|
521
|
-
const
|
|
577
|
+
const supportRaw = member(input, "support");
|
|
578
|
+
const support = supportRaw?.t === "null" ? null : supportRaw;
|
|
522
579
|
const supportInput = support === null ? null : support.t === "obj" ? support : null;
|
|
523
580
|
if (support !== null && support.t !== "obj")
|
|
524
581
|
return { ok: false, e: "invalid_type" };
|
|
525
582
|
const source = supportInput ?? { t: "obj", v: [] };
|
|
526
583
|
const revisionsRaw = member(source, "revisions");
|
|
584
|
+
if (revisionsRaw !== null && revisionsRaw.t !== "arr")
|
|
585
|
+
return { ok: false, e: "invalid_type" };
|
|
527
586
|
const revisions = revisionsRaw !== null && revisionsRaw.t === "arr"
|
|
528
587
|
? revisionsRaw.v.map((r) => (r.t === "int" ? r.v : plainOf(r)))
|
|
529
588
|
: [1];
|
|
530
589
|
const coreFieldsRaw = member(source, "core_fields");
|
|
590
|
+
if (coreFieldsRaw !== null && coreFieldsRaw.t !== "arr")
|
|
591
|
+
return { ok: false, e: "invalid_type" };
|
|
531
592
|
const coreFields = coreFieldsRaw !== null && coreFieldsRaw.t === "arr"
|
|
532
|
-
? coreFieldsRaw.v.map((r) => (r.t === "str" ? r.v :
|
|
593
|
+
? coreFieldsRaw.v.map((r) => (r.t === "str" ? r.v : plainOf(r)))
|
|
533
594
|
: [];
|
|
534
595
|
const registryRaw = member(source, "registry");
|
|
596
|
+
if (registryRaw !== null && registryRaw.t !== "obj")
|
|
597
|
+
return { ok: false, e: "invalid_type" };
|
|
535
598
|
const registry = Object.create(null);
|
|
536
599
|
if (registryRaw !== null && registryRaw.t === "obj") {
|
|
537
600
|
for (const [ns, entryValue] of registryRaw.v) {
|
|
538
601
|
if (entryValue.t !== "obj")
|
|
539
|
-
|
|
602
|
+
return { ok: false, e: "invalid_type" };
|
|
540
603
|
const criticality = memberString(entryValue, "criticality") ?? "optional";
|
|
541
604
|
const state = memberString(entryValue, "state") ?? "active";
|
|
542
605
|
registry[ns] = {
|
|
@@ -550,6 +613,8 @@ function buildSupport(input) {
|
|
|
550
613
|
}
|
|
551
614
|
}
|
|
552
615
|
const schemasRaw = member(source, "schemas");
|
|
616
|
+
if (schemasRaw !== null && schemasRaw.t !== "obj")
|
|
617
|
+
return { ok: false, e: "invalid_type" };
|
|
553
618
|
const schemas = Object.create(null);
|
|
554
619
|
if (schemasRaw !== null && schemasRaw.t === "obj") {
|
|
555
620
|
for (const [ns, schemaValue] of schemasRaw.v)
|
|
@@ -578,7 +643,8 @@ function boundSet(input, key) {
|
|
|
578
643
|
}
|
|
579
644
|
out[name] = descopeValue(value);
|
|
580
645
|
}
|
|
581
|
-
|
|
646
|
+
const validated = boundsAlgebra.buildSet(out);
|
|
647
|
+
return validated.ok ? { ok: true, v: out } : validated;
|
|
582
648
|
}
|
|
583
649
|
// The 13-bound vocabulary (BoundsAlgebra.names()): every protected bound
|
|
584
650
|
// routes through descopeValue exactly as the twin's add_bound_entry does.
|
|
@@ -610,8 +676,8 @@ function descopeValue(value) {
|
|
|
610
676
|
return {
|
|
611
677
|
ordinal,
|
|
612
678
|
markers: markersRaw !== null && markersRaw.t === "arr"
|
|
613
|
-
? markersRaw.v.map(
|
|
614
|
-
: [],
|
|
679
|
+
? markersRaw.v.map(plainOf)
|
|
680
|
+
: markersRaw === null ? [] : plainOf(markersRaw),
|
|
615
681
|
};
|
|
616
682
|
}
|
|
617
683
|
const amount = memberNumber(value, "amount");
|
|
@@ -655,7 +721,7 @@ function buildObserved(input) {
|
|
|
655
721
|
}
|
|
656
722
|
function buildContext(input) {
|
|
657
723
|
const ctxValue = member(input, "context");
|
|
658
|
-
if (ctxValue === null) {
|
|
724
|
+
if (ctxValue === null || ctxValue.t === "null") {
|
|
659
725
|
return { ok: true, v: { keys: [], issuerKeySets: null, priorReceipts: [] } };
|
|
660
726
|
}
|
|
661
727
|
if (ctxValue.t !== "obj")
|
|
@@ -666,6 +732,8 @@ function buildContext(input) {
|
|
|
666
732
|
if (!keys.ok)
|
|
667
733
|
return keys;
|
|
668
734
|
const issuerKeySetsRaw = member(ctx, "issuer_key_sets");
|
|
735
|
+
if (issuerKeySetsRaw !== null && issuerKeySetsRaw.t !== "null" && issuerKeySetsRaw.t !== "obj")
|
|
736
|
+
return { ok: false, e: "invalid_type" };
|
|
669
737
|
let issuerKeySets = null;
|
|
670
738
|
if (issuerKeySetsRaw !== null && issuerKeySetsRaw.t === "obj") {
|
|
671
739
|
issuerKeySets = Object.create(null);
|
|
@@ -705,18 +773,28 @@ function buildContext(input) {
|
|
|
705
773
|
// Pins ride as RAW tagged values: the twin compares members[m] against
|
|
706
774
|
// {:string, pin} exactly, so a present non-string pin DENIES (the
|
|
707
775
|
// audience constraint is enforced, never silently dropped).
|
|
708
|
-
issuer:
|
|
709
|
-
subject:
|
|
710
|
-
audience:
|
|
776
|
+
issuer: nullableMember(ctx, "issuer"),
|
|
777
|
+
subject: nullableMember(ctx, "subject"),
|
|
778
|
+
audience: nullableMember(ctx, "audience"),
|
|
711
779
|
issuerKeySets,
|
|
712
|
-
createdAfter:
|
|
713
|
-
createdBefore:
|
|
780
|
+
createdAfter: plainOptional(ctx, "created_after"),
|
|
781
|
+
createdBefore: plainOptional(ctx, "created_before"),
|
|
714
782
|
priorReceipts,
|
|
715
783
|
},
|
|
716
784
|
};
|
|
717
785
|
}
|
|
786
|
+
function plainOptional(input, name) {
|
|
787
|
+
const value = nullableMember(input, name);
|
|
788
|
+
return value === null ? null : plainOf(value);
|
|
789
|
+
}
|
|
790
|
+
function nullableMember(input, name) {
|
|
791
|
+
const value = member(input, name);
|
|
792
|
+
return value?.t === "null" ? null : value;
|
|
793
|
+
}
|
|
718
794
|
function projectDeployment(deploymentValue, input) {
|
|
719
795
|
const binding = member(input, "binding");
|
|
796
|
+
if (binding !== null && binding.t !== "obj")
|
|
797
|
+
return { ok: false, e: "invalid_type" };
|
|
720
798
|
if (binding !== null && binding.t === "obj") {
|
|
721
799
|
const blueprintBytes = memberString(binding, "blueprint");
|
|
722
800
|
if (blueprintBytes === null)
|
|
@@ -724,10 +802,10 @@ function projectDeployment(deploymentValue, input) {
|
|
|
724
802
|
const decoded = blueprint.decode(Buffer.from(blueprintBytes, "utf8"));
|
|
725
803
|
if (!decoded.ok)
|
|
726
804
|
return decoded;
|
|
727
|
-
const now =
|
|
805
|
+
const now = plainOptional(binding, "now");
|
|
728
806
|
const observations = {
|
|
729
|
-
now: now
|
|
730
|
-
maxAttestationAgeMs:
|
|
807
|
+
now: typeof now === "string" || now === false ? now : null,
|
|
808
|
+
maxAttestationAgeMs: plainOptional(binding, "max_attestation_age_ms"),
|
|
731
809
|
observed: {},
|
|
732
810
|
};
|
|
733
811
|
const verified = deployment.verifyBinding(deploymentValue, decoded.v, observations);
|
|
@@ -801,3 +879,24 @@ function toPlainValue(value) {
|
|
|
801
879
|
}
|
|
802
880
|
}
|
|
803
881
|
export { str, int, float, nil };
|
|
882
|
+
export function project(caseObj, data, raws) {
|
|
883
|
+
if (!caseObj || typeof caseObj.surface !== "string" || !isValue(caseObj.input) || !isValue(caseObj.expected) || !(data instanceof Map) || !(raws instanceof Map))
|
|
884
|
+
return { verdict: "invalid", code: "invalid_type" };
|
|
885
|
+
const result = execute(caseObj, data, raws).actual;
|
|
886
|
+
const output = result.ok ? { verdict: 'valid', ...jsonValue(result.v) } : { verdict: 'invalid', code: result.e, ...(caseObj.surface === 'reconcile' ? { subject: result.subject ?? [] } : {}) };
|
|
887
|
+
if (result.ok && caseObj.surface === 'federation.decode' && typeof result.v.canonical === 'string')
|
|
888
|
+
output.canonical = Buffer.from(result.v.canonical).toString('base64url');
|
|
889
|
+
if (result.ok && caseObj.surface === 'canonicalization.encode')
|
|
890
|
+
output.encoded = Buffer.from(result.v.encoded).toString('base64url');
|
|
891
|
+
if (caseObj.surface === 'signature.verify') {
|
|
892
|
+
const text = memberString(caseObj.input, 'entry');
|
|
893
|
+
const entry = text === null ? null : decode(text);
|
|
894
|
+
if (entry?.ok) {
|
|
895
|
+
const body = memberString(entry.v, 'signature');
|
|
896
|
+
const bytes = body === null ? null : b64.decodeStrict(body);
|
|
897
|
+
if (bytes?.ok && bytes.v.length === 64)
|
|
898
|
+
output.strict_signature = signature.strictSignature(bytes.v);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
return output;
|
|
902
|
+
}
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
+
import * as digest from "./digest.ts";
|
|
1
2
|
import type { Value } from "./value.ts";
|
|
2
3
|
export interface PublicKey {
|
|
3
4
|
keyId: string;
|
|
4
5
|
key: Uint8Array;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export interface Attributes {
|
|
8
|
+
algorithm: "Ed25519";
|
|
9
|
+
contentDigest: digest.Digest;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
keyId: string;
|
|
12
|
+
purpose: "blueprint" | "deployment" | "federation-envelope";
|
|
13
|
+
}
|
|
14
|
+
type Failure = {
|
|
10
15
|
ok: false;
|
|
11
16
|
e: string;
|
|
17
|
+
subject?: (string | number)[];
|
|
12
18
|
};
|
|
19
|
+
type VerifyResult = {
|
|
20
|
+
ok: true;
|
|
21
|
+
v: Attributes;
|
|
22
|
+
} | Failure;
|
|
13
23
|
export declare function verify(entry: Value, keys: PublicKey[]): VerifyResult;
|
|
24
|
+
export declare function attributes(entry: Value): VerifyResult;
|
|
14
25
|
export declare function signingInput(entry: Value): {
|
|
15
26
|
ok: true;
|
|
16
27
|
v: string;
|
|
17
|
-
} |
|
|
28
|
+
} | Failure;
|
|
18
29
|
export declare function toCompact(entry: Value): {
|
|
19
30
|
ok: true;
|
|
20
31
|
v: string;
|
|
21
|
-
} |
|
|
32
|
+
} | Failure;
|
|
22
33
|
export declare const KEY_OBJECT_CACHE_LIMIT = 256;
|
|
23
34
|
export declare function keyObjectCacheSize(): number;
|
|
24
35
|
export declare function strictSignature(signature: Buffer): boolean;
|