@agent-blueprint-protocol/verifier 0.8.3 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -0
- package/LICENSE +1 -1
- package/NOTICE +2 -2
- package/README.md +164 -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/kit/cli.mjs +1 -4
- 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 +182 -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 +1238 -0
- package/dist/spec/registry/OPERATIONS.md +69 -0
- package/dist/spec/registry/registry.json +68 -0
- package/dist/verifier/b64url.d.ts +6 -2
- package/dist/verifier/b64url.js +7 -1
- package/dist/verifier/blueprint.d.ts +12 -16
- package/dist/verifier/blueprint.js +40 -112
- package/dist/verifier/bounds.d.ts +1 -1
- package/dist/verifier/bounds.js +2 -2
- package/dist/verifier/bounds_algebra.d.ts +9 -0
- package/dist/verifier/bounds_algebra.js +10 -7
- package/dist/verifier/canonical.d.ts +1 -1
- package/dist/verifier/canonical.js +41 -8
- package/dist/verifier/cli.js +97 -45
- package/dist/verifier/compatibility.js +5 -7
- package/dist/verifier/corpus.d.ts +1 -1
- package/dist/verifier/corpus.js +10 -2
- package/dist/verifier/decode.js +24 -6
- package/dist/verifier/deployment.d.ts +20 -3
- package/dist/verifier/deployment.js +48 -10
- package/dist/verifier/digest.d.ts +12 -0
- package/dist/verifier/digest.js +17 -3
- 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/extension.js +4 -4
- package/dist/verifier/facade.d.ts +325 -0
- package/dist/verifier/facade.js +78 -0
- package/dist/verifier/federation.d.ts +2 -2
- package/dist/verifier/federation.js +26 -79
- 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 +12 -3
- package/dist/verifier/plain.d.ts +4 -0
- package/dist/verifier/plain.js +38 -0
- package/dist/verifier/portability.d.ts +1 -1
- package/dist/verifier/portability.js +19 -6
- package/dist/verifier/predicate.d.ts +7 -0
- package/dist/verifier/predicate.js +63 -7
- package/dist/verifier/reconcile.d.ts +37 -0
- package/dist/verifier/reconcile.js +115 -0
- package/dist/verifier/registry.js +10 -1
- package/dist/verifier/registry_engine.d.ts +3 -0
- package/dist/verifier/registry_engine.js +37 -20
- package/dist/verifier/report.d.ts +8 -0
- package/dist/verifier/report.js +9 -2
- package/dist/verifier/results.d.ts +3 -0
- package/dist/verifier/results.js +13 -0
- package/dist/verifier/run_corpus.js +4 -80
- package/dist/verifier/runner.d.ts +6 -0
- package/dist/verifier/runner.js +123 -17
- package/dist/verifier/schema.js +14 -55
- package/dist/verifier/signature.d.ts +19 -8
- package/dist/verifier/signature.js +51 -29
- package/dist/verifier/value.d.ts +9 -2
- package/dist/verifier/value.js +81 -11
- package/package.json +17 -12
package/dist/verifier/runner.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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";
|
|
5
|
+
import { isValue } from "./value.js";
|
|
1
6
|
// The case executor — the mirror of AgentBlueprintProtocol.Conformance.Runner:
|
|
2
7
|
// dispatches each corpus case against the verifier's own surface twins and
|
|
3
8
|
// compares to the case's code-level, shape-agnostic expectation (invalid →
|
|
@@ -18,13 +23,19 @@ import * as federation from "./federation.js";
|
|
|
18
23
|
import * as portability from "./portability.js";
|
|
19
24
|
import * as schema from "./schema.js";
|
|
20
25
|
import * as signature from "./signature.js";
|
|
21
|
-
export function run(
|
|
26
|
+
export function run(input) {
|
|
27
|
+
const corpus = input;
|
|
28
|
+
if (!corpus || !Array.isArray(corpus.cases) || !(corpus.data instanceof Map) || !(corpus.raws instanceof Map) ||
|
|
29
|
+
corpus.cases.some((file) => !file || !Array.isArray(file.cases) || file.cases.some((row) => !row || typeof row.id !== "string" || !isValue(row.input) || !isValue(row.expected))))
|
|
30
|
+
return { ok: false, e: "invalid_type" };
|
|
22
31
|
return corpus.cases.map((file) => file.cases.map((caseObj) => ({
|
|
23
32
|
caseId: caseObj.id,
|
|
24
33
|
agree: execute(caseObj, corpus.data, corpus.raws).agree,
|
|
25
34
|
})));
|
|
26
35
|
}
|
|
27
36
|
export function execute(caseObj, data, raws) {
|
|
37
|
+
if (!caseObj || typeof caseObj !== "object" || !isValue(caseObj.input) || !isValue(caseObj.expected) || !(data instanceof Map) || !(raws instanceof Map))
|
|
38
|
+
return { actual: { ok: false, e: "invalid_type" }, agree: false };
|
|
28
39
|
const input = caseObj.input;
|
|
29
40
|
const strict = caseObj.expected.t === "obj" ? member(caseObj.expected, "strict_signature") : null;
|
|
30
41
|
const expected = caseObj.expected.t === "obj"
|
|
@@ -63,6 +74,9 @@ function agrees(expected, actual) {
|
|
|
63
74
|
return false;
|
|
64
75
|
const verdict = memberString(expected, "verdict");
|
|
65
76
|
if (verdict === "invalid") {
|
|
77
|
+
const subject = member(expected, "subject");
|
|
78
|
+
if (!actual.ok && subject !== null && !deepEqual(subject, actual.subject ?? []))
|
|
79
|
+
return false;
|
|
66
80
|
if (!actual.ok)
|
|
67
81
|
return actual.e === memberString(expected, "code");
|
|
68
82
|
return false;
|
|
@@ -204,6 +218,52 @@ function dispatch(surface, input, data, raws) {
|
|
|
204
218
|
return encoded;
|
|
205
219
|
return { ok: true, v: { encoded: encoded.v } };
|
|
206
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
|
+
}
|
|
207
267
|
case "base64url.decode": {
|
|
208
268
|
const segment = memberString(input, "base64url");
|
|
209
269
|
if (segment === null)
|
|
@@ -288,6 +348,9 @@ function dispatch(surface, input, data, raws) {
|
|
|
288
348
|
const instance = taggedField(input, "instance");
|
|
289
349
|
if (!instance.ok)
|
|
290
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" };
|
|
291
354
|
const dialect = memberString(input, "dialect") ?? schema.dialect();
|
|
292
355
|
const validated = schema.validateInstance(schemaInput.v, instance.v, dialect);
|
|
293
356
|
if ("ok" in validated && !validated.ok)
|
|
@@ -440,7 +503,7 @@ function inputBytes(input, raws) {
|
|
|
440
503
|
}
|
|
441
504
|
function boundsOverrides(input) {
|
|
442
505
|
const overrides = member(input, "bounds");
|
|
443
|
-
if (overrides === null)
|
|
506
|
+
if (overrides === null || overrides.t === "null")
|
|
444
507
|
return { ok: true, v: {} };
|
|
445
508
|
if (overrides.t !== "obj")
|
|
446
509
|
return { ok: false, e: "invalid_type" };
|
|
@@ -511,25 +574,32 @@ function buildKeys(input) {
|
|
|
511
574
|
return { ok: true, v: out };
|
|
512
575
|
}
|
|
513
576
|
function buildSupport(input) {
|
|
514
|
-
const
|
|
577
|
+
const supportRaw = member(input, "support");
|
|
578
|
+
const support = supportRaw?.t === "null" ? null : supportRaw;
|
|
515
579
|
const supportInput = support === null ? null : support.t === "obj" ? support : null;
|
|
516
580
|
if (support !== null && support.t !== "obj")
|
|
517
581
|
return { ok: false, e: "invalid_type" };
|
|
518
582
|
const source = supportInput ?? { t: "obj", v: [] };
|
|
519
583
|
const revisionsRaw = member(source, "revisions");
|
|
584
|
+
if (revisionsRaw !== null && revisionsRaw.t !== "arr")
|
|
585
|
+
return { ok: false, e: "invalid_type" };
|
|
520
586
|
const revisions = revisionsRaw !== null && revisionsRaw.t === "arr"
|
|
521
587
|
? revisionsRaw.v.map((r) => (r.t === "int" ? r.v : plainOf(r)))
|
|
522
588
|
: [1];
|
|
523
589
|
const coreFieldsRaw = member(source, "core_fields");
|
|
590
|
+
if (coreFieldsRaw !== null && coreFieldsRaw.t !== "arr")
|
|
591
|
+
return { ok: false, e: "invalid_type" };
|
|
524
592
|
const coreFields = coreFieldsRaw !== null && coreFieldsRaw.t === "arr"
|
|
525
|
-
? coreFieldsRaw.v.map((r) => (r.t === "str" ? r.v :
|
|
593
|
+
? coreFieldsRaw.v.map((r) => (r.t === "str" ? r.v : plainOf(r)))
|
|
526
594
|
: [];
|
|
527
595
|
const registryRaw = member(source, "registry");
|
|
596
|
+
if (registryRaw !== null && registryRaw.t !== "obj")
|
|
597
|
+
return { ok: false, e: "invalid_type" };
|
|
528
598
|
const registry = Object.create(null);
|
|
529
599
|
if (registryRaw !== null && registryRaw.t === "obj") {
|
|
530
600
|
for (const [ns, entryValue] of registryRaw.v) {
|
|
531
601
|
if (entryValue.t !== "obj")
|
|
532
|
-
|
|
602
|
+
return { ok: false, e: "invalid_type" };
|
|
533
603
|
const criticality = memberString(entryValue, "criticality") ?? "optional";
|
|
534
604
|
const state = memberString(entryValue, "state") ?? "active";
|
|
535
605
|
registry[ns] = {
|
|
@@ -543,6 +613,8 @@ function buildSupport(input) {
|
|
|
543
613
|
}
|
|
544
614
|
}
|
|
545
615
|
const schemasRaw = member(source, "schemas");
|
|
616
|
+
if (schemasRaw !== null && schemasRaw.t !== "obj")
|
|
617
|
+
return { ok: false, e: "invalid_type" };
|
|
546
618
|
const schemas = Object.create(null);
|
|
547
619
|
if (schemasRaw !== null && schemasRaw.t === "obj") {
|
|
548
620
|
for (const [ns, schemaValue] of schemasRaw.v)
|
|
@@ -571,7 +643,8 @@ function boundSet(input, key) {
|
|
|
571
643
|
}
|
|
572
644
|
out[name] = descopeValue(value);
|
|
573
645
|
}
|
|
574
|
-
|
|
646
|
+
const validated = boundsAlgebra.buildSet(out);
|
|
647
|
+
return validated.ok ? { ok: true, v: out } : validated;
|
|
575
648
|
}
|
|
576
649
|
// The 13-bound vocabulary (BoundsAlgebra.names()): every protected bound
|
|
577
650
|
// routes through descopeValue exactly as the twin's add_bound_entry does.
|
|
@@ -603,8 +676,8 @@ function descopeValue(value) {
|
|
|
603
676
|
return {
|
|
604
677
|
ordinal,
|
|
605
678
|
markers: markersRaw !== null && markersRaw.t === "arr"
|
|
606
|
-
? markersRaw.v.map(
|
|
607
|
-
: [],
|
|
679
|
+
? markersRaw.v.map(plainOf)
|
|
680
|
+
: markersRaw === null ? [] : plainOf(markersRaw),
|
|
608
681
|
};
|
|
609
682
|
}
|
|
610
683
|
const amount = memberNumber(value, "amount");
|
|
@@ -648,7 +721,7 @@ function buildObserved(input) {
|
|
|
648
721
|
}
|
|
649
722
|
function buildContext(input) {
|
|
650
723
|
const ctxValue = member(input, "context");
|
|
651
|
-
if (ctxValue === null) {
|
|
724
|
+
if (ctxValue === null || ctxValue.t === "null") {
|
|
652
725
|
return { ok: true, v: { keys: [], issuerKeySets: null, priorReceipts: [] } };
|
|
653
726
|
}
|
|
654
727
|
if (ctxValue.t !== "obj")
|
|
@@ -659,6 +732,8 @@ function buildContext(input) {
|
|
|
659
732
|
if (!keys.ok)
|
|
660
733
|
return keys;
|
|
661
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" };
|
|
662
737
|
let issuerKeySets = null;
|
|
663
738
|
if (issuerKeySetsRaw !== null && issuerKeySetsRaw.t === "obj") {
|
|
664
739
|
issuerKeySets = Object.create(null);
|
|
@@ -698,18 +773,28 @@ function buildContext(input) {
|
|
|
698
773
|
// Pins ride as RAW tagged values: the twin compares members[m] against
|
|
699
774
|
// {:string, pin} exactly, so a present non-string pin DENIES (the
|
|
700
775
|
// audience constraint is enforced, never silently dropped).
|
|
701
|
-
issuer:
|
|
702
|
-
subject:
|
|
703
|
-
audience:
|
|
776
|
+
issuer: nullableMember(ctx, "issuer"),
|
|
777
|
+
subject: nullableMember(ctx, "subject"),
|
|
778
|
+
audience: nullableMember(ctx, "audience"),
|
|
704
779
|
issuerKeySets,
|
|
705
|
-
createdAfter:
|
|
706
|
-
createdBefore:
|
|
780
|
+
createdAfter: plainOptional(ctx, "created_after"),
|
|
781
|
+
createdBefore: plainOptional(ctx, "created_before"),
|
|
707
782
|
priorReceipts,
|
|
708
783
|
},
|
|
709
784
|
};
|
|
710
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
|
+
}
|
|
711
794
|
function projectDeployment(deploymentValue, input) {
|
|
712
795
|
const binding = member(input, "binding");
|
|
796
|
+
if (binding !== null && binding.t !== "obj")
|
|
797
|
+
return { ok: false, e: "invalid_type" };
|
|
713
798
|
if (binding !== null && binding.t === "obj") {
|
|
714
799
|
const blueprintBytes = memberString(binding, "blueprint");
|
|
715
800
|
if (blueprintBytes === null)
|
|
@@ -717,10 +802,10 @@ function projectDeployment(deploymentValue, input) {
|
|
|
717
802
|
const decoded = blueprint.decode(Buffer.from(blueprintBytes, "utf8"));
|
|
718
803
|
if (!decoded.ok)
|
|
719
804
|
return decoded;
|
|
720
|
-
const now =
|
|
805
|
+
const now = plainOptional(binding, "now");
|
|
721
806
|
const observations = {
|
|
722
|
-
now: now
|
|
723
|
-
maxAttestationAgeMs:
|
|
807
|
+
now: typeof now === "string" || now === false ? now : null,
|
|
808
|
+
maxAttestationAgeMs: plainOptional(binding, "max_attestation_age_ms"),
|
|
724
809
|
observed: {},
|
|
725
810
|
};
|
|
726
811
|
const verified = deployment.verifyBinding(deploymentValue, decoded.v, observations);
|
|
@@ -794,3 +879,24 @@ function toPlainValue(value) {
|
|
|
794
879
|
}
|
|
795
880
|
}
|
|
796
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
|
+
}
|
package/dist/verifier/schema.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// pinned canonical keyword order with (schema-node, instance-location)
|
|
6
6
|
// memoization. Numbers compare by mathematical value across the int/float
|
|
7
7
|
// tags; string lengths count codepoints.
|
|
8
|
-
import { err, ok } from "./value.js";
|
|
8
|
+
import { err, ok, isValue as wellFormed } from "./value.js";
|
|
9
9
|
const DIALECT = "https://json-schema.org/draft/2020-12/schema";
|
|
10
10
|
const CEILING = 512;
|
|
11
11
|
const TYPE_NAMES = new Set(["null", "boolean", "object", "array", "number", "string", "integer"]);
|
|
@@ -70,6 +70,9 @@ export function validateInstance(schema, instance, dialectId) {
|
|
|
70
70
|
// codepoint-for-codepoint, arrays order-sensitive, objects order-blind with
|
|
71
71
|
// equal member counts.
|
|
72
72
|
export function equal(a, b) {
|
|
73
|
+
return wellFormed(a) && wellFormed(b) && equalAt(a, b);
|
|
74
|
+
}
|
|
75
|
+
function equalAt(a, b) {
|
|
73
76
|
if ((a.t === "int" || a.t === "float") &&
|
|
74
77
|
(b.t === "int" || b.t === "float")) {
|
|
75
78
|
return a.v === b.v;
|
|
@@ -85,7 +88,7 @@ export function equal(a, b) {
|
|
|
85
88
|
case "arr":
|
|
86
89
|
return (b.t === "arr" &&
|
|
87
90
|
a.v.length === b.v.length &&
|
|
88
|
-
a.v.every((x, i) =>
|
|
91
|
+
a.v.every((x, i) => equalAt(x, b.v[i])));
|
|
89
92
|
case "obj":
|
|
90
93
|
if (b.t !== "obj")
|
|
91
94
|
return false;
|
|
@@ -93,7 +96,7 @@ export function equal(a, b) {
|
|
|
93
96
|
return false;
|
|
94
97
|
return a.v.every(([name, value]) => {
|
|
95
98
|
const other = b.v.find(([n]) => n === name);
|
|
96
|
-
return other !== undefined &&
|
|
99
|
+
return other !== undefined && equalAt(value, other[1]);
|
|
97
100
|
});
|
|
98
101
|
// int/float cannot reach the switch (the numeric cross-compare above
|
|
99
102
|
// already returned); the default only completes the switch for the compiler.
|
|
@@ -103,48 +106,7 @@ export function equal(a, b) {
|
|
|
103
106
|
}
|
|
104
107
|
// ---- gates ----------------------------------------------------------------------
|
|
105
108
|
function rootShape(value) {
|
|
106
|
-
return value.t === "obj" || value.t === "bool";
|
|
107
|
-
}
|
|
108
|
-
// The tagged-value well-formedness gate (decoder output always passes; this
|
|
109
|
-
// is the fail-closed guard for hand-built terms).
|
|
110
|
-
function wellFormed(value) {
|
|
111
|
-
switch (value.t) {
|
|
112
|
-
case "null":
|
|
113
|
-
case "bool":
|
|
114
|
-
case "int":
|
|
115
|
-
case "float":
|
|
116
|
-
return true;
|
|
117
|
-
case "str":
|
|
118
|
-
return validString(value.v);
|
|
119
|
-
case "arr":
|
|
120
|
-
return value.v.every(wellFormed);
|
|
121
|
-
case "obj": {
|
|
122
|
-
const seen = new Set();
|
|
123
|
-
for (const [name, member] of value.v) {
|
|
124
|
-
if (typeof name !== "string" || !validString(name) || seen.has(name))
|
|
125
|
-
return false;
|
|
126
|
-
if (!wellFormed(member))
|
|
127
|
-
return false;
|
|
128
|
-
seen.add(name);
|
|
129
|
-
}
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function validString(s) {
|
|
135
|
-
for (let i = 0; i < s.length; i++) {
|
|
136
|
-
const c = s.charCodeAt(i);
|
|
137
|
-
if (c >= 0xd800 && c <= 0xdbff) {
|
|
138
|
-
const next = s.charCodeAt(i + 1);
|
|
139
|
-
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
140
|
-
return false;
|
|
141
|
-
i++;
|
|
142
|
-
}
|
|
143
|
-
else if (c >= 0xdc00 && c <= 0xdfff) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
109
|
+
return value !== null && typeof value === "object" && (value.t === "obj" || value.t === "bool");
|
|
148
110
|
}
|
|
149
111
|
function meter0() {
|
|
150
112
|
return { nodes: 0, keywords: 0, branches: 0, depth: 0 };
|
|
@@ -198,7 +160,7 @@ function allowedKey(key) {
|
|
|
198
160
|
return KEYWORD_ORDER.includes(key) || key === "$defs";
|
|
199
161
|
}
|
|
200
162
|
function schemaShape(value) {
|
|
201
|
-
return value.t === "obj" || value.t === "bool";
|
|
163
|
+
return value !== null && typeof value === "object" && (value.t === "obj" || value.t === "bool");
|
|
202
164
|
}
|
|
203
165
|
function validateValue(key, value) {
|
|
204
166
|
const invalid = err("schema_keyword_value_invalid");
|
|
@@ -559,15 +521,12 @@ function evalPresentProperties(subs, members, loc, memo, pointers) {
|
|
|
559
521
|
return ok(undefined);
|
|
560
522
|
}
|
|
561
523
|
function evalItems(items, index, sub, loc, memo, pointers) {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (!result.ok)
|
|
569
|
-
return result;
|
|
570
|
-
return evalItems(items, index + 1, sub, loc, memo, pointers);
|
|
524
|
+
for (let i = index; i < items.length; i++) {
|
|
525
|
+
const result = evaluate(sub, items[i], [String(i), ...loc], memo, pointers);
|
|
526
|
+
if (!result.ok)
|
|
527
|
+
return result;
|
|
528
|
+
}
|
|
529
|
+
return ok(undefined);
|
|
571
530
|
}
|
|
572
531
|
function evalAdditional(additional, sub, loc, memo, pointers) {
|
|
573
532
|
for (const [name, value] of additional) {
|
|
@@ -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
|
-
key:
|
|
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;
|
|
@@ -28,5 +39,5 @@ export declare const ED25519_CONSTANTS: {
|
|
|
28
39
|
readonly sqrtM1: 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
29
40
|
readonly l: bigint;
|
|
30
41
|
};
|
|
31
|
-
export declare function usableEd25519Key(
|
|
42
|
+
export declare function usableEd25519Key(input: Uint8Array): boolean;
|
|
32
43
|
export {};
|
|
@@ -18,17 +18,25 @@ import * as b64 from "./b64url.js";
|
|
|
18
18
|
import { encode } from "./canonical.js";
|
|
19
19
|
import * as digest from "./digest.js";
|
|
20
20
|
import { member, memberString } from "./corpus.js";
|
|
21
|
+
const HEADER_ALGORITHMS = new Set(["EdDSA", "Ed25519"]);
|
|
21
22
|
const PURPOSES = new Set(["blueprint", "deployment", "federation-envelope"]);
|
|
22
23
|
const CREATED_AT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
|
|
23
|
-
function malformed() {
|
|
24
|
-
return { ok: false, e: "signature_malformed" };
|
|
24
|
+
function malformed(subject = []) {
|
|
25
|
+
return { ok: false, e: "signature_malformed", subject };
|
|
25
26
|
}
|
|
26
27
|
export function verify(entry, keys) {
|
|
28
|
+
if (!Array.isArray(keys) || keys.some((key) => key === null || typeof key !== "object"))
|
|
29
|
+
return { ok: false, e: "invalid_type" };
|
|
27
30
|
const parts = parseParts(entry);
|
|
28
31
|
if (!parts.ok)
|
|
29
32
|
return parts;
|
|
30
33
|
const input = parts.v.headerB64 + "." + parts.v.payload;
|
|
31
|
-
|
|
34
|
+
const result = check(input, parts.v.signature, parts.v.keyId, keys);
|
|
35
|
+
return result.ok ? { ok: true, v: parts.v.attributes } : result;
|
|
36
|
+
}
|
|
37
|
+
export function attributes(entry) {
|
|
38
|
+
const parts = parseParts(entry);
|
|
39
|
+
return parts.ok ? { ok: true, v: parts.v.attributes } : parts;
|
|
32
40
|
}
|
|
33
41
|
export function signingInput(entry) {
|
|
34
42
|
const parts = parseParts(entry);
|
|
@@ -45,6 +53,9 @@ export function toCompact(entry) {
|
|
|
45
53
|
return { ok: true, v: parts.v.headerB64 + "." + "." + b64.encode(parts.v.signature) };
|
|
46
54
|
}
|
|
47
55
|
function parseParts(entry) {
|
|
56
|
+
const shaped = encode(entry);
|
|
57
|
+
if (!shaped.ok)
|
|
58
|
+
return shaped.e === "invalid_type" ? shaped : malformed();
|
|
48
59
|
if (entry.t !== "obj")
|
|
49
60
|
return malformed();
|
|
50
61
|
const names = entry.v.map(([k]) => k).sort();
|
|
@@ -56,70 +67,73 @@ function parseParts(entry) {
|
|
|
56
67
|
}
|
|
57
68
|
const header = member(entry, "protected");
|
|
58
69
|
const attrs = member(entry, "signed_attributes");
|
|
59
|
-
// Header: exactly {alg, b64, crit, kid}; alg
|
|
70
|
+
// Header: exactly {alg, b64, crit, kid}; alg is EdDSA or Ed25519 (the twin's
|
|
60
71
|
// algorithm-unsupported denial in the header), b64 exactly false, crit
|
|
61
72
|
// exactly ["b64"], kid a non-empty string.
|
|
62
73
|
if (header.t !== "obj")
|
|
63
|
-
return malformed();
|
|
74
|
+
return malformed(["protected"]);
|
|
64
75
|
const headerNames = header.v.map(([k]) => k).sort();
|
|
65
76
|
if (headerNames.length !== 4 || headerNames.join() !== "alg,b64,crit,kid") {
|
|
66
|
-
return malformed();
|
|
77
|
+
return malformed(["protected"]);
|
|
67
78
|
}
|
|
68
79
|
const alg = member(header, "alg");
|
|
69
|
-
if (alg !== null && alg.t === "str" && alg.v
|
|
70
|
-
return { ok: false, e: "signature_algorithm_unsupported" };
|
|
80
|
+
if (alg !== null && alg.t === "str" && !HEADER_ALGORITHMS.has(alg.v)) {
|
|
81
|
+
return { ok: false, e: "signature_algorithm_unsupported", subject: ["protected"] };
|
|
71
82
|
}
|
|
72
83
|
if (alg === null || alg.t !== "str")
|
|
73
|
-
return malformed();
|
|
84
|
+
return malformed(["protected"]);
|
|
74
85
|
const b64Flag = member(header, "b64");
|
|
75
86
|
if (b64Flag === null || b64Flag.t !== "bool" || b64Flag.v !== false)
|
|
76
|
-
return malformed();
|
|
87
|
+
return malformed(["protected"]);
|
|
77
88
|
const crit = member(header, "crit");
|
|
78
89
|
if (crit === null ||
|
|
79
90
|
crit.t !== "arr" ||
|
|
80
91
|
crit.v.length !== 1 ||
|
|
81
92
|
crit.v[0].t !== "str" ||
|
|
82
93
|
crit.v[0].v !== "b64") {
|
|
83
|
-
return malformed();
|
|
94
|
+
return malformed(["protected"]);
|
|
84
95
|
}
|
|
85
96
|
const kid = member(header, "kid");
|
|
86
97
|
if (kid === null || kid.t !== "str" || kid.v === "")
|
|
87
|
-
return malformed();
|
|
98
|
+
return malformed(["protected"]);
|
|
88
99
|
// Attributes: exactly the five closed members.
|
|
89
100
|
if (attrs.t !== "obj")
|
|
90
|
-
return malformed();
|
|
101
|
+
return malformed(["signed_attributes"]);
|
|
91
102
|
const attrNames = attrs.v.map(([k]) => k).sort();
|
|
92
103
|
if (attrNames.length !== 5 ||
|
|
93
104
|
attrNames.join() !== "algorithm,content_digest,created_at,key_id,purpose") {
|
|
94
|
-
return malformed();
|
|
105
|
+
return malformed(["signed_attributes"]);
|
|
95
106
|
}
|
|
96
107
|
const algorithm = member(attrs, "algorithm");
|
|
97
108
|
if (algorithm !== null && algorithm.t === "str" && algorithm.v !== "Ed25519") {
|
|
98
|
-
return { ok: false, e: "signature_algorithm_unsupported" };
|
|
109
|
+
return { ok: false, e: "signature_algorithm_unsupported", subject: ["signed_attributes"] };
|
|
99
110
|
}
|
|
100
111
|
if (algorithm === null || algorithm.t !== "str")
|
|
101
|
-
return malformed();
|
|
112
|
+
return malformed(["signed_attributes"]);
|
|
102
113
|
const contentDigest = memberString(attrs, "content_digest");
|
|
103
|
-
if (contentDigest === null
|
|
104
|
-
return malformed();
|
|
114
|
+
if (contentDigest === null)
|
|
115
|
+
return malformed(["signed_attributes"]);
|
|
116
|
+
const parsedDigest = digest.fromTagged(contentDigest);
|
|
117
|
+
if (!parsedDigest.ok)
|
|
118
|
+
return malformed(["signed_attributes"]);
|
|
105
119
|
const createdAt = memberString(attrs, "created_at");
|
|
106
120
|
if (createdAt === null || !CREATED_AT.test(createdAt) || !validZFormDate(createdAt)) {
|
|
107
|
-
return malformed();
|
|
121
|
+
return malformed(["signed_attributes"]);
|
|
108
122
|
}
|
|
109
123
|
const keyId = memberString(attrs, "key_id");
|
|
110
|
-
if (keyId === null || keyId === ""
|
|
111
|
-
return malformed();
|
|
124
|
+
if (keyId === null || keyId === "")
|
|
125
|
+
return malformed(["signed_attributes"]);
|
|
112
126
|
const purpose = memberString(attrs, "purpose");
|
|
113
127
|
if (purpose === null || !PURPOSES.has(purpose))
|
|
114
|
-
return malformed();
|
|
128
|
+
return malformed(["signed_attributes"]);
|
|
115
129
|
if (kid.v !== keyId)
|
|
116
130
|
return malformed();
|
|
117
131
|
const signatureBody = member(entry, "signature");
|
|
118
132
|
if (signatureBody === null || signatureBody.t !== "str")
|
|
119
|
-
return malformed();
|
|
133
|
+
return malformed(["signature"]);
|
|
120
134
|
const decodedSignature = b64.decodeStrict(signatureBody.v);
|
|
121
135
|
if (!decodedSignature.ok || decodedSignature.v.length !== 64)
|
|
122
|
-
return malformed();
|
|
136
|
+
return malformed(["signature"]);
|
|
123
137
|
const headerJson = encode(header);
|
|
124
138
|
const attrsJson = encode(attrs);
|
|
125
139
|
if (!headerJson.ok || !attrsJson.ok)
|
|
@@ -131,6 +145,13 @@ function parseParts(entry) {
|
|
|
131
145
|
payload: attrsJson.v,
|
|
132
146
|
signature: decodedSignature.v,
|
|
133
147
|
keyId,
|
|
148
|
+
attributes: {
|
|
149
|
+
algorithm: "Ed25519",
|
|
150
|
+
contentDigest: parsedDigest.v,
|
|
151
|
+
createdAt,
|
|
152
|
+
keyId,
|
|
153
|
+
purpose: purpose,
|
|
154
|
+
},
|
|
134
155
|
},
|
|
135
156
|
};
|
|
136
157
|
}
|
|
@@ -164,7 +185,7 @@ function check(input, signature, keyId, keys) {
|
|
|
164
185
|
const inputBytes = Buffer.from(input, "utf8");
|
|
165
186
|
for (const key of usable) {
|
|
166
187
|
if (cryptoVerify(null, inputBytes, keyObject(key.key), signature)) {
|
|
167
|
-
return { ok: true
|
|
188
|
+
return { ok: true };
|
|
168
189
|
}
|
|
169
190
|
}
|
|
170
191
|
return { ok: false, e: "signature_not_verified" };
|
|
@@ -179,7 +200,7 @@ export function keyObjectCacheSize() {
|
|
|
179
200
|
return keyObjectCache.size;
|
|
180
201
|
}
|
|
181
202
|
function keyObject(raw) {
|
|
182
|
-
const x = raw.toString("base64url");
|
|
203
|
+
const x = Buffer.from(raw).toString("base64url");
|
|
183
204
|
const cached = keyObjectCache.get(x);
|
|
184
205
|
if (cached !== undefined)
|
|
185
206
|
return cached;
|
|
@@ -200,7 +221,7 @@ function keyObject(raw) {
|
|
|
200
221
|
// honest key; node 24.19.0 rejects it) — mirrors the Elixir twin.
|
|
201
222
|
const ED_L = 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
202
223
|
export function strictSignature(signature) {
|
|
203
|
-
if (signature.length !== 64)
|
|
224
|
+
if (!Buffer.isBuffer(signature) || signature.length !== 64)
|
|
204
225
|
return false;
|
|
205
226
|
return leInt(signature.subarray(32)) < ED_L && usableEd25519Key(signature.subarray(0, 32));
|
|
206
227
|
}
|
|
@@ -229,9 +250,10 @@ function modPow(base, exponent) {
|
|
|
229
250
|
}
|
|
230
251
|
return result;
|
|
231
252
|
}
|
|
232
|
-
export function usableEd25519Key(
|
|
233
|
-
if (
|
|
253
|
+
export function usableEd25519Key(input) {
|
|
254
|
+
if (!(input instanceof Uint8Array) || input.length !== 32)
|
|
234
255
|
return false;
|
|
256
|
+
const encoding = Buffer.from(input);
|
|
235
257
|
const yRaw = encoding.readBigUInt64LE(0) | (encoding.readBigUInt64LE(8) << 64n) |
|
|
236
258
|
(encoding.readBigUInt64LE(16) << 128n) | (encoding.readBigUInt64LE(24) << 192n);
|
|
237
259
|
// RFC 8032 5.1.2: bit 255 carries the sign of x; the low 255 bits are y.
|
package/dist/verifier/value.d.ts
CHANGED
|
@@ -36,9 +36,16 @@ export declare const str: (v: string) => Value;
|
|
|
36
36
|
export declare const arr: (v: Value[]) => Value;
|
|
37
37
|
export declare const obj: (v: [string, Value][]) => Value;
|
|
38
38
|
export declare const IJSON_MAX = 9007199254740991;
|
|
39
|
+
export declare function isValue(value: unknown): value is Value;
|
|
39
40
|
export declare function sameValue(a: Value, b: Value): boolean;
|
|
40
41
|
export type Plain = null | boolean | number | string | Plain[] | {
|
|
41
42
|
[k: string]: Plain;
|
|
42
43
|
};
|
|
43
|
-
export declare function toPlain(v: Value): Plain
|
|
44
|
-
|
|
44
|
+
export declare function toPlain(v: Value): Plain | {
|
|
45
|
+
ok: false;
|
|
46
|
+
e: string;
|
|
47
|
+
};
|
|
48
|
+
export declare function fromPlain(p: Plain): Value | {
|
|
49
|
+
ok: false;
|
|
50
|
+
e: string;
|
|
51
|
+
};
|