@agent-blueprint-protocol/verifier 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +6 -6
  3. package/dist/corpus/cases/blueprint-decode.json +1 -1
  4. package/dist/corpus/cases/bounds-new.json +1 -1
  5. package/dist/corpus/cases/bounds_algebra-intersect.json +1 -1
  6. package/dist/corpus/cases/canonicalization-encode.json +1 -1
  7. package/dist/corpus/cases/deployment-decode.json +1 -1
  8. package/dist/corpus/cases/federation-decode.json +1 -1
  9. package/dist/corpus/cases/json-decode.json +1 -1
  10. package/dist/corpus/cases/portability-scan.json +1 -1
  11. package/dist/corpus/cases/schema-validate_instance.json +1 -1
  12. package/dist/corpus/index.json +1 -1
  13. package/dist/kit/cli.mjs +1 -4
  14. package/dist/release-metadata.json +1 -1
  15. package/dist/verifier/b64url.d.ts +6 -2
  16. package/dist/verifier/b64url.js +6 -0
  17. package/dist/verifier/blueprint.d.ts +12 -3
  18. package/dist/verifier/blueprint.js +21 -7
  19. package/dist/verifier/bounds.d.ts +1 -1
  20. package/dist/verifier/bounds.js +3 -3
  21. package/dist/verifier/bounds_algebra.js +7 -4
  22. package/dist/verifier/canonical.d.ts +1 -1
  23. package/dist/verifier/canonical.js +41 -8
  24. package/dist/verifier/cli.js +111 -42
  25. package/dist/verifier/compatibility.js +6 -8
  26. package/dist/verifier/corpus.js +5 -1
  27. package/dist/verifier/decode.js +9 -3
  28. package/dist/verifier/deployment.d.ts +12 -3
  29. package/dist/verifier/deployment.js +33 -10
  30. package/dist/verifier/digest.d.ts +12 -0
  31. package/dist/verifier/digest.js +16 -2
  32. package/dist/verifier/extension.js +4 -4
  33. package/dist/verifier/federation.js +18 -74
  34. package/dist/verifier/negotiation.js +8 -2
  35. package/dist/verifier/portability.d.ts +1 -1
  36. package/dist/verifier/portability.js +45 -8
  37. package/dist/verifier/predicate.js +4 -7
  38. package/dist/verifier/registry_engine.js +29 -12
  39. package/dist/verifier/report.d.ts +8 -0
  40. package/dist/verifier/report.js +9 -2
  41. package/dist/verifier/run_corpus.js +4 -80
  42. package/dist/verifier/runner.d.ts +4 -0
  43. package/dist/verifier/runner.js +13 -15
  44. package/dist/verifier/schema.js +14 -55
  45. package/dist/verifier/signature.d.ts +2 -2
  46. package/dist/verifier/signature.js +10 -4
  47. package/dist/verifier/value.d.ts +9 -2
  48. package/dist/verifier/value.js +81 -11
  49. package/package.json +1 -1
@@ -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) => equal(x, b.v[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 && equal(value, other[1]);
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
- if (index >= items.length)
563
- return ok(undefined);
564
- // Schema first, instance second — the historical swap here evaluated each
565
- // item AS the schema (object-shaped items passed vacuously, scalar items
566
- // crashed); the tier schemas are the first corpus-bearing items user.
567
- const result = evaluate(sub, items[index], [String(index), ...loc], memo, pointers);
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,7 +1,7 @@
1
1
  import type { Value } from "./value.ts";
2
2
  export interface PublicKey {
3
3
  keyId: string;
4
- key: Buffer;
4
+ key: Uint8Array;
5
5
  }
6
6
  type VerifyResult = {
7
7
  ok: true;
@@ -28,5 +28,5 @@ export declare const ED25519_CONSTANTS: {
28
28
  readonly sqrtM1: 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
29
29
  readonly l: bigint;
30
30
  };
31
- export declare function usableEd25519Key(encoding: Buffer): boolean;
31
+ export declare function usableEd25519Key(input: Uint8Array): boolean;
32
32
  export {};
@@ -24,6 +24,8 @@ function malformed() {
24
24
  return { ok: false, e: "signature_malformed" };
25
25
  }
26
26
  export function verify(entry, keys) {
27
+ if (!Array.isArray(keys) || keys.some((key) => key === null || typeof key !== "object"))
28
+ return { ok: false, e: "invalid_type" };
27
29
  const parts = parseParts(entry);
28
30
  if (!parts.ok)
29
31
  return parts;
@@ -45,6 +47,9 @@ export function toCompact(entry) {
45
47
  return { ok: true, v: parts.v.headerB64 + "." + "." + b64.encode(parts.v.signature) };
46
48
  }
47
49
  function parseParts(entry) {
50
+ const shaped = encode(entry);
51
+ if (!shaped.ok)
52
+ return shaped.e === "invalid_type" ? shaped : malformed();
48
53
  if (entry.t !== "obj")
49
54
  return malformed();
50
55
  const names = entry.v.map(([k]) => k).sort();
@@ -179,7 +184,7 @@ export function keyObjectCacheSize() {
179
184
  return keyObjectCache.size;
180
185
  }
181
186
  function keyObject(raw) {
182
- const x = raw.toString("base64url");
187
+ const x = Buffer.from(raw).toString("base64url");
183
188
  const cached = keyObjectCache.get(x);
184
189
  if (cached !== undefined)
185
190
  return cached;
@@ -200,7 +205,7 @@ function keyObject(raw) {
200
205
  // honest key; node 24.19.0 rejects it) — mirrors the Elixir twin.
201
206
  const ED_L = 2n ** 252n + 27742317777372353535851937790883648493n;
202
207
  export function strictSignature(signature) {
203
- if (signature.length !== 64)
208
+ if (!Buffer.isBuffer(signature) || signature.length !== 64)
204
209
  return false;
205
210
  return leInt(signature.subarray(32)) < ED_L && usableEd25519Key(signature.subarray(0, 32));
206
211
  }
@@ -229,9 +234,10 @@ function modPow(base, exponent) {
229
234
  }
230
235
  return result;
231
236
  }
232
- export function usableEd25519Key(encoding) {
233
- if (encoding.length !== 32)
237
+ export function usableEd25519Key(input) {
238
+ if (!(input instanceof Uint8Array) || input.length !== 32)
234
239
  return false;
240
+ const encoding = Buffer.from(input);
235
241
  const yRaw = encoding.readBigUInt64LE(0) | (encoding.readBigUInt64LE(8) << 64n) |
236
242
  (encoding.readBigUInt64LE(16) << 128n) | (encoding.readBigUInt64LE(24) << 192n);
237
243
  // RFC 8032 5.1.2: bit 255 carries the sign of x; the low 255 bits are y.
@@ -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
- export declare function fromPlain(p: Plain): Value;
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
+ };
@@ -18,7 +18,48 @@ export const IJSON_MAX = 9_007_199_254_740_991;
18
18
  // Deep equality over the tagged algebra. Numbers compare numerically
19
19
  // (int 2 equals float 2.0 — Elixir's `==` semantics, which the runner's
20
20
  // expectation comparison relies on); ±0 are equal.
21
+ // Host-built tagged values are bounded before recursive projections or comparisons.
22
+ export function isValue(value) {
23
+ return isValueAt(value, 0);
24
+ }
25
+ function isValueAt(value, depth) {
26
+ if (value === null || typeof value !== "object" || depth > 64)
27
+ return false;
28
+ const v = value;
29
+ switch (v.t) {
30
+ case "null": return true;
31
+ case "bool": return typeof v.v === "boolean";
32
+ case "int": return Number.isSafeInteger(v.v);
33
+ case "float": return typeof v.v === "number" && Number.isFinite(v.v);
34
+ case "str": return typeof v.v === "string" && Buffer.from(v.v).toString("utf8") === v.v;
35
+ case "arr":
36
+ if (!Array.isArray(v.v))
37
+ return false;
38
+ for (const item of v.v)
39
+ if (!isValueAt(item, depth + 1))
40
+ return false;
41
+ return true;
42
+ case "obj": {
43
+ if (!Array.isArray(v.v))
44
+ return false;
45
+ const seen = new Set();
46
+ for (const pair of v.v) {
47
+ if (!Array.isArray(pair) || pair.length !== 2 || typeof pair[0] !== "string" ||
48
+ Buffer.from(pair[0]).toString("utf8") !== pair[0] || seen.has(pair[0]))
49
+ return false;
50
+ seen.add(pair[0]);
51
+ if (!isValueAt(pair[1], depth + 1))
52
+ return false;
53
+ }
54
+ return true;
55
+ }
56
+ default: return false;
57
+ }
58
+ }
21
59
  export function sameValue(a, b) {
60
+ return isValue(a) && isValue(b) && sameValueAt(a, b);
61
+ }
62
+ function sameValueAt(a, b) {
22
63
  if (a.t !== b.t) {
23
64
  if ((a.t === "int" || a.t === "float") && (b.t === "int" || b.t === "float")) {
24
65
  return a.v === b.v;
@@ -34,16 +75,19 @@ export function sameValue(a, b) {
34
75
  case "str":
35
76
  return a.v === b.v;
36
77
  case "arr":
37
- return (a.v.length === b.v.length && a.v.every((x, i) => sameValue(x, b.v[i])));
78
+ return (a.v.length === b.v.length && a.v.every((x, i) => sameValueAt(x, b.v[i])));
38
79
  case "obj":
39
80
  return (a.v.length === b.v.length &&
40
81
  a.v.every((pair, i) => {
41
82
  const other = b.v[i];
42
- return pair[0] === other[0] && sameValue(pair[1], other[1]);
83
+ return pair[0] === other[0] && sameValueAt(pair[1], other[1]);
43
84
  }));
44
85
  }
45
86
  }
46
87
  export function toPlain(v) {
88
+ return isValue(v) ? toPlainAt(v) : { ok: false, e: "invalid_type" };
89
+ }
90
+ function toPlainAt(v) {
47
91
  switch (v.t) {
48
92
  case "null":
49
93
  return null;
@@ -53,25 +97,51 @@ export function toPlain(v) {
53
97
  case "str":
54
98
  return v.v;
55
99
  case "arr":
56
- return v.v.map(toPlain);
100
+ return v.v.map(toPlainAt);
57
101
  case "obj":
58
102
  // Null prototype: "__proto__" and friends stay plain members.
59
103
  const out = Object.create(null);
60
104
  for (const [k, member] of v.v)
61
- out[k] = toPlain(member);
105
+ out[k] = toPlainAt(member);
62
106
  return out;
63
107
  }
64
108
  }
65
109
  export function fromPlain(p) {
110
+ const result = fromPlainAt(p, 0);
111
+ return result.ok ? result.v : result;
112
+ }
113
+ function fromPlainAt(p, depth) {
114
+ if (depth > 64)
115
+ return err("invalid_type");
66
116
  if (p === null)
67
- return nil;
117
+ return ok(nil);
68
118
  if (typeof p === "boolean")
69
- return bool(p);
119
+ return ok(bool(p));
70
120
  if (typeof p === "number")
71
- return Number.isInteger(p) ? int(p) : float(p);
121
+ return Number.isFinite(p) && (!Number.isInteger(p) || Number.isSafeInteger(p))
122
+ ? ok(Number.isInteger(p) ? int(p) : float(p)) : err("invalid_type");
72
123
  if (typeof p === "string")
73
- return str(p);
74
- if (Array.isArray(p))
75
- return arr(p.map(fromPlain));
76
- return obj(Object.entries(p).map(([k, member]) => [k, fromPlain(member)]));
124
+ return Buffer.from(p).toString("utf8") === p ? ok(str(p)) : err("invalid_type");
125
+ if (Array.isArray(p)) {
126
+ const items = [];
127
+ for (const item of p) {
128
+ const result = fromPlainAt(item, depth + 1);
129
+ if (!result.ok)
130
+ return result;
131
+ items.push(result.v);
132
+ }
133
+ return ok(arr(items));
134
+ }
135
+ if (typeof p !== "object" || (Object.getPrototypeOf(p) !== null && Object.getPrototypeOf(p) !== Object.prototype))
136
+ return err("invalid_type");
137
+ const members = [];
138
+ for (const [key, member] of Object.entries(p)) {
139
+ if (Buffer.from(key).toString("utf8") !== key)
140
+ return err("invalid_type");
141
+ const result = fromPlainAt(member, depth + 1);
142
+ if (!result.ok)
143
+ return result;
144
+ members.push([key, result.v]);
145
+ }
146
+ return ok(obj(members));
77
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-blueprint-protocol/verifier",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "Installable verifier for the Agent Blueprint Protocol: canonical-bytes, digest, signature, bounds, and conformance-corpus verification. Non-authorizing \u2014 evidence, never a decision.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {