@agent-blueprint-protocol/verifier 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +891 -0
- package/LICENSE +190 -0
- package/NOTICE +4 -0
- package/README.md +199 -0
- package/dist/corpus/cases/base64url-decode.json +1 -0
- package/dist/corpus/cases/blueprint-decode.json +1 -0
- package/dist/corpus/cases/bounds-new.json +1 -0
- package/dist/corpus/cases/bounds_algebra-intersect.json +1 -0
- package/dist/corpus/cases/canonicalization-encode.json +1 -0
- package/dist/corpus/cases/compatibility-verify.json +1 -0
- package/dist/corpus/cases/deployment-decode.json +1 -0
- package/dist/corpus/cases/digest-tagged.json +1 -0
- package/dist/corpus/cases/extension-resolve.json +1 -0
- package/dist/corpus/cases/federation-decode.json +1 -0
- package/dist/corpus/cases/federation-verify_commitment.json +1 -0
- package/dist/corpus/cases/json-decode.json +1 -0
- package/dist/corpus/cases/negotiation-negotiate.json +1 -0
- package/dist/corpus/cases/portability-scan.json +1 -0
- package/dist/corpus/cases/schema-validate_instance.json +1 -0
- package/dist/corpus/cases/signature-verify.json +1 -0
- package/dist/corpus/index.json +1 -0
- package/dist/corpus/schemas/estate-contract.schema.json +1 -0
- package/dist/corpus/schemas/object.schema.json +1 -0
- package/dist/corpus/vectors/blueprint-golden.json +1 -0
- package/dist/corpus/vectors/deployment-golden.json +1 -0
- package/dist/corpus/vectors/rfc8785-numbers.json +1 -0
- package/dist/kit/cli.mjs +24 -0
- package/dist/verifier/b64url.d.ts +16 -0
- package/dist/verifier/b64url.js +36 -0
- package/dist/verifier/blueprint.d.ts +56 -0
- package/dist/verifier/blueprint.js +795 -0
- package/dist/verifier/bounds.d.ts +19 -0
- package/dist/verifier/bounds.js +45 -0
- package/dist/verifier/bounds_algebra.d.ts +27 -0
- package/dist/verifier/bounds_algebra.js +282 -0
- package/dist/verifier/canonical.d.ts +17 -0
- package/dist/verifier/canonical.js +160 -0
- package/dist/verifier/cli.d.ts +1 -0
- package/dist/verifier/cli.js +149 -0
- package/dist/verifier/compatibility.d.ts +22 -0
- package/dist/verifier/compatibility.js +112 -0
- package/dist/verifier/corpus.d.ts +42 -0
- package/dist/verifier/corpus.js +672 -0
- package/dist/verifier/decode.d.ts +16 -0
- package/dist/verifier/decode.js +457 -0
- package/dist/verifier/deployment.d.ts +49 -0
- package/dist/verifier/deployment.js +830 -0
- package/dist/verifier/digest.d.ts +23 -0
- package/dist/verifier/digest.js +58 -0
- package/dist/verifier/extension.d.ts +11 -0
- package/dist/verifier/extension.js +75 -0
- package/dist/verifier/federation.d.ts +76 -0
- package/dist/verifier/federation.js +817 -0
- package/dist/verifier/negotiation.d.ts +29 -0
- package/dist/verifier/negotiation.js +324 -0
- package/dist/verifier/portability.d.ts +12 -0
- package/dist/verifier/portability.js +184 -0
- package/dist/verifier/predicate.d.ts +10 -0
- package/dist/verifier/predicate.js +172 -0
- package/dist/verifier/registry.d.ts +16 -0
- package/dist/verifier/registry.js +120 -0
- package/dist/verifier/registry_engine.d.ts +42 -0
- package/dist/verifier/registry_engine.js +220 -0
- package/dist/verifier/report.d.ts +13 -0
- package/dist/verifier/report.js +29 -0
- package/dist/verifier/run_corpus.d.ts +1 -0
- package/dist/verifier/run_corpus.js +81 -0
- package/dist/verifier/runner.d.ts +20 -0
- package/dist/verifier/runner.js +778 -0
- package/dist/verifier/schema.d.ts +20 -0
- package/dist/verifier/schema.js +623 -0
- package/dist/verifier/self_checks.d.ts +1 -0
- package/dist/verifier/self_checks.js +316 -0
- package/dist/verifier/signature.d.ts +23 -0
- package/dist/verifier/signature.js +226 -0
- package/dist/verifier/value.d.ts +44 -0
- package/dist/verifier/value.js +77 -0
- package/package.json +42 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
// Bounded JSON scanner — the mirror of AgentBlueprintProtocol.Json over
|
|
2
|
+
// Erlang's :json decoder. Own scanner (JSON.parse keeps LAST duplicate, the
|
|
3
|
+
// proven divergence the design names), every ceiling enforced, duplicate members
|
|
4
|
+
// rejected, the integer window admitted through the one ES6 oracle.
|
|
5
|
+
//
|
|
6
|
+
// Check ORDER mirrors the twin exactly (corpus expectations pin precedence):
|
|
7
|
+
// bytes ceiling → parse (structure) → per-member/element guards
|
|
8
|
+
// (members/key/items/nodes) → sink (number resolution then string size) →
|
|
9
|
+
// duplicate rejection at container close → trailing bytes at root.
|
|
10
|
+
// A STRUCTURAL parse failure classifies by whole-input UTF-8 validity (the
|
|
11
|
+
// twin's classify_parse_error): invalid_encoding when any byte is bad, else
|
|
12
|
+
// invalid_syntax. Ceiling/code failures carry their own reason verbatim —
|
|
13
|
+
// the twin throws those from inside :json's hooks with the reason attached.
|
|
14
|
+
import { maximum } from "./bounds.js";
|
|
15
|
+
import { number } from "./canonical.js";
|
|
16
|
+
import { err, ok } from "./value.js";
|
|
17
|
+
// Thrown for ceiling/code denials — reason rides the exception.
|
|
18
|
+
export class CodeFail extends Error {
|
|
19
|
+
code;
|
|
20
|
+
constructor(code) {
|
|
21
|
+
super(code);
|
|
22
|
+
this.code = code;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Thrown for structural parse failures — classified by input validity.
|
|
26
|
+
export class SyntaxFail extends Error {
|
|
27
|
+
}
|
|
28
|
+
export function decode(input, bounds) {
|
|
29
|
+
if (typeof input !== "string" && !Buffer.isBuffer(input))
|
|
30
|
+
return err("invalid_type");
|
|
31
|
+
const bytes = typeof input === "string" ? Buffer.from(input, "utf8") : input;
|
|
32
|
+
// The profile is read field-wise (bytes/items/…) whatever the caller passed.
|
|
33
|
+
const profile = (bounds ?? maximum());
|
|
34
|
+
if (bytes.length > profile.bytes)
|
|
35
|
+
return err("ceiling:bytes");
|
|
36
|
+
const validUtf8 = isUtf8(bytes);
|
|
37
|
+
const s = new Scanner(bytes, profile);
|
|
38
|
+
try {
|
|
39
|
+
const value = s.parseRoot();
|
|
40
|
+
return ok(value);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e instanceof CodeFail)
|
|
44
|
+
return err(e.code);
|
|
45
|
+
if (e instanceof SyntaxFail)
|
|
46
|
+
return err(validUtf8 ? "invalid_syntax" : "invalid_encoding");
|
|
47
|
+
throw e;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const WS = new Set([0x20, 0x09, 0x0a, 0x0d]);
|
|
51
|
+
class Scanner {
|
|
52
|
+
pos = 0;
|
|
53
|
+
nodes = 0;
|
|
54
|
+
depth = 0;
|
|
55
|
+
b;
|
|
56
|
+
bounds;
|
|
57
|
+
constructor(b, bounds) {
|
|
58
|
+
this.b = b;
|
|
59
|
+
this.bounds = bounds;
|
|
60
|
+
}
|
|
61
|
+
eof() {
|
|
62
|
+
return this.pos >= this.b.length;
|
|
63
|
+
}
|
|
64
|
+
peek() {
|
|
65
|
+
return this.b[this.pos];
|
|
66
|
+
}
|
|
67
|
+
skipWs() {
|
|
68
|
+
while (!this.eof() && WS.has(this.peek()))
|
|
69
|
+
this.pos++;
|
|
70
|
+
}
|
|
71
|
+
parseRoot() {
|
|
72
|
+
this.skipWs();
|
|
73
|
+
if (this.eof())
|
|
74
|
+
throw new SyntaxFail();
|
|
75
|
+
const value = this.parseValue();
|
|
76
|
+
this.skipWs();
|
|
77
|
+
if (!this.eof())
|
|
78
|
+
throw new SyntaxFail(); // trailing bytes
|
|
79
|
+
this.bumpNodes();
|
|
80
|
+
return this.sink(value);
|
|
81
|
+
}
|
|
82
|
+
parseValue() {
|
|
83
|
+
if (this.eof())
|
|
84
|
+
throw new SyntaxFail();
|
|
85
|
+
const c = this.peek();
|
|
86
|
+
if (c === 0x7b)
|
|
87
|
+
return this.parseObject();
|
|
88
|
+
if (c === 0x5b)
|
|
89
|
+
return this.parseArray();
|
|
90
|
+
if (c === 0x22)
|
|
91
|
+
return { t: "str", v: this.parseString() };
|
|
92
|
+
if (c === 0x74)
|
|
93
|
+
return this.parseLiteral("true", { t: "bool", v: true });
|
|
94
|
+
if (c === 0x66)
|
|
95
|
+
return this.parseLiteral("false", { t: "bool", v: false });
|
|
96
|
+
if (c === 0x6e)
|
|
97
|
+
return this.parseLiteral("null", { t: "null" });
|
|
98
|
+
if (c === 0x2d || (c >= 0x30 && c <= 0x39))
|
|
99
|
+
return this.parseNumber();
|
|
100
|
+
throw new SyntaxFail();
|
|
101
|
+
}
|
|
102
|
+
parseLiteral(word, value) {
|
|
103
|
+
for (let i = 0; i < word.length; i++) {
|
|
104
|
+
if (this.eof() || this.peek() !== word.charCodeAt(i))
|
|
105
|
+
throw new SyntaxFail();
|
|
106
|
+
this.pos++;
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
// Containers guard depth at ENTRY (live depth, root container = 1).
|
|
111
|
+
parseArray() {
|
|
112
|
+
this.enter();
|
|
113
|
+
this.pos++; // '['
|
|
114
|
+
const items = [];
|
|
115
|
+
this.skipWs();
|
|
116
|
+
if (!this.eof() && this.peek() === 0x5d) {
|
|
117
|
+
this.pos++;
|
|
118
|
+
this.leave();
|
|
119
|
+
return { t: "arr", v: items };
|
|
120
|
+
}
|
|
121
|
+
for (;;) {
|
|
122
|
+
this.skipWs();
|
|
123
|
+
const element = this.parseValue();
|
|
124
|
+
this.guard(items.length + 1, this.bounds.items, "items");
|
|
125
|
+
this.bumpNodes();
|
|
126
|
+
items.push(this.sink(element));
|
|
127
|
+
this.skipWs();
|
|
128
|
+
if (this.eof())
|
|
129
|
+
throw new SyntaxFail();
|
|
130
|
+
if (this.peek() === 0x2c) {
|
|
131
|
+
this.pos++;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (this.peek() === 0x5d) {
|
|
135
|
+
this.pos++;
|
|
136
|
+
this.leave();
|
|
137
|
+
return { t: "arr", v: items };
|
|
138
|
+
}
|
|
139
|
+
throw new SyntaxFail();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
parseObject() {
|
|
143
|
+
this.enter();
|
|
144
|
+
this.pos++; // '{'
|
|
145
|
+
const members = [];
|
|
146
|
+
this.skipWs();
|
|
147
|
+
if (!this.eof() && this.peek() === 0x7d) {
|
|
148
|
+
this.pos++;
|
|
149
|
+
this.leave();
|
|
150
|
+
return { t: "obj", v: members };
|
|
151
|
+
}
|
|
152
|
+
for (;;) {
|
|
153
|
+
this.skipWs();
|
|
154
|
+
if (this.eof() || this.peek() !== 0x22)
|
|
155
|
+
throw new SyntaxFail();
|
|
156
|
+
const key = this.parseString();
|
|
157
|
+
this.skipWs();
|
|
158
|
+
if (this.eof() || this.peek() !== 0x3a)
|
|
159
|
+
throw new SyntaxFail();
|
|
160
|
+
this.pos++;
|
|
161
|
+
this.skipWs();
|
|
162
|
+
const value = this.parseValue();
|
|
163
|
+
this.guard(members.length + 1, this.bounds.members, "members");
|
|
164
|
+
if (Buffer.byteLength(key, "utf8") > this.bounds.key) {
|
|
165
|
+
throw new CodeFail("ceiling:key");
|
|
166
|
+
}
|
|
167
|
+
this.bumpNodes();
|
|
168
|
+
members.push([key, this.sink(value)]);
|
|
169
|
+
this.skipWs();
|
|
170
|
+
if (this.eof())
|
|
171
|
+
throw new SyntaxFail();
|
|
172
|
+
if (this.peek() === 0x2c) {
|
|
173
|
+
this.pos++;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (this.peek() === 0x7d) {
|
|
177
|
+
this.pos++;
|
|
178
|
+
this.leave();
|
|
179
|
+
this.rejectDuplicates(members);
|
|
180
|
+
return { t: "obj", v: members };
|
|
181
|
+
}
|
|
182
|
+
throw new SyntaxFail();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Strings: escapes per RFC 8259; raw control bytes and unpaired surrogate
|
|
186
|
+
// escapes are parse failures; UTF-8 validity is enforced per byte sequence
|
|
187
|
+
// (the whole-input flag only classifies, as the twin does).
|
|
188
|
+
parseString() {
|
|
189
|
+
this.pos++; // '"'
|
|
190
|
+
let out = "";
|
|
191
|
+
let chunkStart = this.pos;
|
|
192
|
+
const flush = () => {
|
|
193
|
+
if (this.pos > chunkStart) {
|
|
194
|
+
const slice = this.b.subarray(chunkStart, this.pos);
|
|
195
|
+
if (!isUtf8(slice))
|
|
196
|
+
throw new SyntaxFail();
|
|
197
|
+
out += slice.toString("utf8");
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
for (;;) {
|
|
201
|
+
if (this.eof())
|
|
202
|
+
throw new SyntaxFail();
|
|
203
|
+
const c = this.peek();
|
|
204
|
+
if (c === 0x22) {
|
|
205
|
+
flush();
|
|
206
|
+
this.pos++;
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
if (c === 0x5c) {
|
|
210
|
+
flush();
|
|
211
|
+
this.pos++;
|
|
212
|
+
if (this.eof())
|
|
213
|
+
throw new SyntaxFail();
|
|
214
|
+
const e = this.peek();
|
|
215
|
+
this.pos++;
|
|
216
|
+
switch (e) {
|
|
217
|
+
case 0x22:
|
|
218
|
+
out += '"';
|
|
219
|
+
break;
|
|
220
|
+
case 0x5c:
|
|
221
|
+
out += "\\";
|
|
222
|
+
break;
|
|
223
|
+
case 0x2f:
|
|
224
|
+
out += "/";
|
|
225
|
+
break;
|
|
226
|
+
case 0x62:
|
|
227
|
+
out += "\b";
|
|
228
|
+
break;
|
|
229
|
+
case 0x66:
|
|
230
|
+
out += "\f";
|
|
231
|
+
break;
|
|
232
|
+
case 0x6e:
|
|
233
|
+
out += "\n";
|
|
234
|
+
break;
|
|
235
|
+
case 0x72:
|
|
236
|
+
out += "\r";
|
|
237
|
+
break;
|
|
238
|
+
case 0x74:
|
|
239
|
+
out += "\t";
|
|
240
|
+
break;
|
|
241
|
+
case 0x75: {
|
|
242
|
+
const unit = this.hex4();
|
|
243
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
244
|
+
if (this.b[this.pos] !== 0x5c || this.b[this.pos + 1] !== 0x75) {
|
|
245
|
+
throw new SyntaxFail();
|
|
246
|
+
}
|
|
247
|
+
this.pos += 2;
|
|
248
|
+
const low = this.hex4();
|
|
249
|
+
if (!(low >= 0xdc00 && low <= 0xdfff))
|
|
250
|
+
throw new SyntaxFail();
|
|
251
|
+
out += String.fromCharCode(unit, low);
|
|
252
|
+
}
|
|
253
|
+
else if (unit >= 0xdc00 && unit <= 0xdfff) {
|
|
254
|
+
throw new SyntaxFail();
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
out += String.fromCharCode(unit);
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
default:
|
|
262
|
+
throw new SyntaxFail();
|
|
263
|
+
}
|
|
264
|
+
chunkStart = this.pos;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (c < 0x20)
|
|
268
|
+
throw new SyntaxFail();
|
|
269
|
+
if (c < 0x80) {
|
|
270
|
+
this.pos++;
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const len = utf8Len(c);
|
|
274
|
+
if (len === 0 || this.pos + len > this.b.length)
|
|
275
|
+
throw new SyntaxFail();
|
|
276
|
+
for (let i = 1; i < len; i++) {
|
|
277
|
+
if ((this.b[this.pos + i] & 0xc0) !== 0x80)
|
|
278
|
+
throw new SyntaxFail();
|
|
279
|
+
}
|
|
280
|
+
this.pos += len;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
hex4() {
|
|
284
|
+
let value = 0;
|
|
285
|
+
for (let i = 0; i < 4; i++) {
|
|
286
|
+
if (this.eof())
|
|
287
|
+
throw new SyntaxFail();
|
|
288
|
+
const c = this.peek();
|
|
289
|
+
this.pos++;
|
|
290
|
+
const digit = hexValue(c);
|
|
291
|
+
if (digit < 0)
|
|
292
|
+
throw new SyntaxFail();
|
|
293
|
+
value = value * 16 + digit;
|
|
294
|
+
}
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
// Numbers: RFC 8259 grammar; the lexeme is carried raw for the sink.
|
|
298
|
+
parseNumber() {
|
|
299
|
+
const start = this.pos;
|
|
300
|
+
if (this.peek() === 0x2d)
|
|
301
|
+
this.pos++;
|
|
302
|
+
if (this.eof())
|
|
303
|
+
throw new SyntaxFail();
|
|
304
|
+
if (this.peek() === 0x30) {
|
|
305
|
+
this.pos++;
|
|
306
|
+
if (!this.eof() && this.peek() >= 0x30 && this.peek() <= 0x39)
|
|
307
|
+
throw new SyntaxFail();
|
|
308
|
+
}
|
|
309
|
+
else if (this.peek() >= 0x31 && this.peek() <= 0x39) {
|
|
310
|
+
while (!this.eof() && this.peek() >= 0x30 && this.peek() <= 0x39)
|
|
311
|
+
this.pos++;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
throw new SyntaxFail();
|
|
315
|
+
}
|
|
316
|
+
let isFloat = false;
|
|
317
|
+
if (!this.eof() && this.peek() === 0x2e) {
|
|
318
|
+
isFloat = true;
|
|
319
|
+
this.pos++;
|
|
320
|
+
if (this.eof() || this.peek() < 0x30 || this.peek() > 0x39)
|
|
321
|
+
throw new SyntaxFail();
|
|
322
|
+
while (!this.eof() && this.peek() >= 0x30 && this.peek() <= 0x39)
|
|
323
|
+
this.pos++;
|
|
324
|
+
}
|
|
325
|
+
if (!this.eof() && (this.peek() === 0x65 || this.peek() === 0x45)) {
|
|
326
|
+
isFloat = true;
|
|
327
|
+
this.pos++;
|
|
328
|
+
if (!this.eof() && (this.peek() === 0x2b || this.peek() === 0x2d))
|
|
329
|
+
this.pos++;
|
|
330
|
+
if (this.eof() || this.peek() < 0x30 || this.peek() > 0x39)
|
|
331
|
+
throw new SyntaxFail();
|
|
332
|
+
while (!this.eof() && this.peek() >= 0x30 && this.peek() <= 0x39)
|
|
333
|
+
this.pos++;
|
|
334
|
+
}
|
|
335
|
+
return { raw: "number", lexeme: this.b.toString("utf8", start, this.pos), isFloat };
|
|
336
|
+
}
|
|
337
|
+
// The sink: number resolution then string-size bounding, exactly at the
|
|
338
|
+
// point a value settles into its container (or the root).
|
|
339
|
+
sink(value) {
|
|
340
|
+
if (isRawNumber(value)) {
|
|
341
|
+
const lexeme = value.lexeme;
|
|
342
|
+
if (Buffer.byteLength(lexeme, "utf8") > this.bounds.number_lexeme) {
|
|
343
|
+
throw new CodeFail("ceiling:number_lexeme");
|
|
344
|
+
}
|
|
345
|
+
if (value.isFloat) {
|
|
346
|
+
const parsed = Number(lexeme);
|
|
347
|
+
if (!Number.isFinite(parsed))
|
|
348
|
+
throw new CodeFail("invalid_number");
|
|
349
|
+
return { t: "float", v: parsed };
|
|
350
|
+
}
|
|
351
|
+
if (beyondIjsonMax(lexeme)) {
|
|
352
|
+
// Integer window: admit iff the correctly-rounded double's own
|
|
353
|
+
// canonical ES6 form IS the lexeme (mis-round reference:
|
|
354
|
+
// 73639773945516200000 = bits 440FEFA841F21479; Number(lexeme) is
|
|
355
|
+
// the correctly-rounded parse, Float.parse's equivalent).
|
|
356
|
+
const parsed = Number(lexeme);
|
|
357
|
+
if (number(parsed) !== lexeme) {
|
|
358
|
+
throw new CodeFail("number_not_double_expressible");
|
|
359
|
+
}
|
|
360
|
+
return { t: "float", v: parsed };
|
|
361
|
+
}
|
|
362
|
+
return { t: "int", v: normalizeZero(Number(lexeme)) };
|
|
363
|
+
}
|
|
364
|
+
if (value.t === "str" && Buffer.byteLength(value.v, "utf8") > this.bounds.string) {
|
|
365
|
+
throw new CodeFail("ceiling:string");
|
|
366
|
+
}
|
|
367
|
+
return value;
|
|
368
|
+
}
|
|
369
|
+
rejectDuplicates(members) {
|
|
370
|
+
const seen = new Set();
|
|
371
|
+
for (const [key] of members) {
|
|
372
|
+
if (seen.has(key))
|
|
373
|
+
throw new CodeFail("duplicate_member");
|
|
374
|
+
seen.add(key);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
enter() {
|
|
378
|
+
this.depth++;
|
|
379
|
+
if (this.depth > this.bounds.depth)
|
|
380
|
+
throw new CodeFail("ceiling:depth");
|
|
381
|
+
}
|
|
382
|
+
leave() {
|
|
383
|
+
this.depth--;
|
|
384
|
+
}
|
|
385
|
+
guard(observed, ceiling, name) {
|
|
386
|
+
if (observed > ceiling)
|
|
387
|
+
throw new CodeFail("ceiling:" + name);
|
|
388
|
+
}
|
|
389
|
+
bumpNodes() {
|
|
390
|
+
this.nodes++;
|
|
391
|
+
if (this.nodes > this.bounds.nodes)
|
|
392
|
+
throw new CodeFail("ceiling:nodes");
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function isRawNumber(v) {
|
|
396
|
+
return v.raw === "number";
|
|
397
|
+
}
|
|
398
|
+
// ---- helpers ---------------------------------------------------------------------
|
|
399
|
+
function normalizeZero(v) {
|
|
400
|
+
return v === 0 ? 0 : v;
|
|
401
|
+
}
|
|
402
|
+
function beyondIjsonMax(lexeme) {
|
|
403
|
+
const abs = lexeme.startsWith("-") ? lexeme.slice(1) : lexeme;
|
|
404
|
+
if (abs.length !== 16)
|
|
405
|
+
return abs.length > 16;
|
|
406
|
+
return abs > "9007199254740991";
|
|
407
|
+
}
|
|
408
|
+
function hexValue(c) {
|
|
409
|
+
if (c >= 0x30 && c <= 0x39)
|
|
410
|
+
return c - 0x30;
|
|
411
|
+
if (c >= 0x61 && c <= 0x66)
|
|
412
|
+
return c - 0x61 + 10;
|
|
413
|
+
if (c >= 0x41 && c <= 0x46)
|
|
414
|
+
return c - 0x41 + 10;
|
|
415
|
+
return -1;
|
|
416
|
+
}
|
|
417
|
+
function utf8Len(firstByte) {
|
|
418
|
+
if ((firstByte & 0xe0) === 0xc0)
|
|
419
|
+
return 2;
|
|
420
|
+
if ((firstByte & 0xf0) === 0xe0)
|
|
421
|
+
return 3;
|
|
422
|
+
if ((firstByte & 0xf8) === 0xf0)
|
|
423
|
+
return 4;
|
|
424
|
+
return 0;
|
|
425
|
+
}
|
|
426
|
+
// Strict UTF-8 validation: rejects overlong forms, surrogates, > U+10FFFF.
|
|
427
|
+
export function isUtf8(bytes) {
|
|
428
|
+
let i = 0;
|
|
429
|
+
while (i < bytes.length) {
|
|
430
|
+
const c = bytes[i];
|
|
431
|
+
if (c < 0x80) {
|
|
432
|
+
i++;
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
const len = utf8Len(c);
|
|
436
|
+
if (len === 0 || i + len > bytes.length)
|
|
437
|
+
return false;
|
|
438
|
+
for (let j = 1; j < len; j++) {
|
|
439
|
+
if ((bytes[i + j] & 0xc0) !== 0x80)
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
if (len === 2 && c < 0xc2)
|
|
443
|
+
return false;
|
|
444
|
+
if (len === 3 && c === 0xe0 && bytes[i + 1] < 0xa0)
|
|
445
|
+
return false;
|
|
446
|
+
if (len === 3 && c === 0xed && bytes[i + 1] >= 0xa0)
|
|
447
|
+
return false;
|
|
448
|
+
if (len === 4 && c === 0xf0 && bytes[i + 1] < 0x90)
|
|
449
|
+
return false;
|
|
450
|
+
if (len === 4 && c === 0xf4 && bytes[i + 1] >= 0x90)
|
|
451
|
+
return false;
|
|
452
|
+
if (len === 4 && c > 0xf4)
|
|
453
|
+
return false;
|
|
454
|
+
i += len;
|
|
455
|
+
}
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Bounds } from "./bounds.ts";
|
|
2
|
+
import * as blueprint from "./blueprint.ts";
|
|
3
|
+
import { type Spec } from "./registry_engine.ts";
|
|
4
|
+
import type { Value } from "./value.ts";
|
|
5
|
+
export interface Deployment {
|
|
6
|
+
value: Value;
|
|
7
|
+
}
|
|
8
|
+
export interface Observations {
|
|
9
|
+
now: string | null;
|
|
10
|
+
maxAttestationAgeMs: number | null;
|
|
11
|
+
observed: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
type VResult = {
|
|
14
|
+
ok: true;
|
|
15
|
+
} | {
|
|
16
|
+
ok: false;
|
|
17
|
+
e: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function table(): Spec[];
|
|
20
|
+
export declare function decode(bytes: Buffer | string | symbol, bounds?: Bounds | Record<string, unknown>): {
|
|
21
|
+
ok: true;
|
|
22
|
+
v: Deployment;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
e: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function fromValue(value: Value, opts?: {
|
|
28
|
+
authoredExtensions?: string[];
|
|
29
|
+
}): {
|
|
30
|
+
ok: true;
|
|
31
|
+
v: Deployment;
|
|
32
|
+
} | {
|
|
33
|
+
ok: false;
|
|
34
|
+
e: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function toValue(deployment: Deployment): Value;
|
|
37
|
+
export declare function digestInput(deployment: Deployment): Value;
|
|
38
|
+
export declare function canonicalBytes(deployment: Deployment): {
|
|
39
|
+
ok: true;
|
|
40
|
+
v: string;
|
|
41
|
+
} | {
|
|
42
|
+
ok: false;
|
|
43
|
+
e: string;
|
|
44
|
+
};
|
|
45
|
+
export declare function contentDigest(deployment: Deployment): string;
|
|
46
|
+
export declare function verifyContentDigest(deployment: Deployment): VResult;
|
|
47
|
+
export declare function verifyBinding(deployment: Deployment, bound: blueprint.Blueprint, obs: Observations): VResult;
|
|
48
|
+
export declare function parseTimestamp(stamped: string): number | null;
|
|
49
|
+
export {};
|