@bolyra/receipts 0.11.1 → 0.12.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/LICENSE +201 -0
- package/NOTICE +121 -0
- package/README.md +115 -0
- package/dist/approval.d.ts +251 -0
- package/dist/approval.js +1173 -0
- package/dist/chain.d.ts +3 -0
- package/dist/chain.js +0 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -1
- package/dist/sign.d.ts +7 -0
- package/dist/sign.js +3 -0
- package/dist/types.d.ts +7 -2
- package/package.json +3 -4
- package/src/approval.ts +1410 -0
- package/src/chain.ts +10 -1
- package/src/index.ts +39 -0
- package/src/sign.ts +41 -2
- package/src/types.ts +7 -2
package/dist/approval.js
ADDED
|
@@ -0,0 +1,1173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Approval-to-execution binding primitive
|
|
4
|
+
* (docs/superpowers/specs/2026-10-25-approval-binding-design.md).
|
|
5
|
+
*
|
|
6
|
+
* Three pieces, all inside the signed payloads:
|
|
7
|
+
*
|
|
8
|
+
* 1. An approval receipt (`bolyra.approval`, scheme `bab1`) binds the reviewed
|
|
9
|
+
* action — requester, audience, tool, operation id — and a digest of the
|
|
10
|
+
* exact reviewed arguments, together with who approved it and when.
|
|
11
|
+
* 2. `executeApproved` verifies that receipt immediately before dispatch and
|
|
12
|
+
* dispatches only the immutable argument snapshot it checked. It is the
|
|
13
|
+
* only path that dispatches; there is no standalone guard to misuse.
|
|
14
|
+
* 3. An execution observation (`bolyra.execution`, scheme `beo1`) links to the
|
|
15
|
+
* approval receipt hash, the operation and attempt ids and the digest of the
|
|
16
|
+
* dispatched snapshot, and verifies offline with
|
|
17
|
+
* `verifyApprovalExecutionLink`.
|
|
18
|
+
*
|
|
19
|
+
* What this does NOT establish (the README repeats the list): verified human
|
|
20
|
+
* identity because a name was signed; authorization correctness; downstream
|
|
21
|
+
* commitment from dispatch; exactly-once execution; protection against
|
|
22
|
+
* bypassing the hook; log completeness; live vendor integration. The receipt
|
|
23
|
+
* records what the operator asserted was reviewed; it carries the argument
|
|
24
|
+
* digest only, never the arguments.
|
|
25
|
+
*
|
|
26
|
+
* No function here logs, writes files or makes network calls.
|
|
27
|
+
*/
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
45
|
+
var ownKeys = function(o) {
|
|
46
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
49
|
+
return ar;
|
|
50
|
+
};
|
|
51
|
+
return ownKeys(o);
|
|
52
|
+
};
|
|
53
|
+
return function (mod) {
|
|
54
|
+
if (mod && mod.__esModule) return mod;
|
|
55
|
+
var result = {};
|
|
56
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
57
|
+
__setModuleDefault(result, mod);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
})();
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.ApprovedExecutionError = exports.LINK_VERIFICATION_STATEMENT = exports.ARGUMENTS_MAX_BYTES = exports.ARGUMENTS_MAX_DEPTH = exports.ARGUMENTS_DIGEST_DST = void 0;
|
|
63
|
+
exports.validateArgumentsJson = validateArgumentsJson;
|
|
64
|
+
exports.computeArgumentsDigest = computeArgumentsDigest;
|
|
65
|
+
exports.createApprovalReceipt = createApprovalReceipt;
|
|
66
|
+
exports.executeApproved = executeApproved;
|
|
67
|
+
exports.verifyApprovalExecutionLink = verifyApprovalExecutionLink;
|
|
68
|
+
const secp256k1 = __importStar(require("@noble/secp256k1"));
|
|
69
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
70
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
71
|
+
const canonical_1 = require("./canonical");
|
|
72
|
+
const chain_1 = require("./chain");
|
|
73
|
+
const sign_1 = require("./sign");
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Constants
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
/** Domain-separation tag for the arguments digest, terminated by an explicit 0x00. */
|
|
78
|
+
exports.ARGUMENTS_DIGEST_DST = 'bolyra.approval.arguments/1';
|
|
79
|
+
/** Maximum container nesting depth of the argument object (the root object is depth 1). */
|
|
80
|
+
exports.ARGUMENTS_MAX_DEPTH = 64;
|
|
81
|
+
/** Maximum serialized size (UTF-8 bytes) of the argument text and of its canonical form. */
|
|
82
|
+
exports.ARGUMENTS_MAX_BYTES = 1024 * 1024;
|
|
83
|
+
/** Fixed text returned with every link verification result. */
|
|
84
|
+
exports.LINK_VERIFICATION_STATEMENT = 'A PASS establishes only that the approval receipt and the execution observation are validly signed ' +
|
|
85
|
+
'by the expected signers and that the observation links to that approval receipt, operation, context ' +
|
|
86
|
+
'and argument digest. It does not establish human review, actual dispatch, consumption, response ' +
|
|
87
|
+
'success, business-state freshness or committed effect.';
|
|
88
|
+
const ID_PATTERN = /^[\x21-\x7e]{1,256}$/;
|
|
89
|
+
const APPROVER_PATTERN = /^[\x20-\x7e]{1,256}$/;
|
|
90
|
+
const RFC3339_MS_Z = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
91
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
92
|
+
const HEX_0X64 = /^0x[0-9a-f]{64}$/;
|
|
93
|
+
const HEX_0X16 = /^0x[0-9a-f]{16}$/;
|
|
94
|
+
const ADDRESS_PATTERN = /^0x[0-9a-fA-F]{40}$/;
|
|
95
|
+
const SIGNATURE_VALUE_PATTERN = /^0x[0-9a-f]{130}$/;
|
|
96
|
+
const PRIVATE_KEY_PATTERN = /^(0x)?[0-9a-fA-F]{64}$/;
|
|
97
|
+
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
98
|
+
/** Exclusive upper bound for clock samples: Date.prototype.toISOString must yield a 4-digit year. */
|
|
99
|
+
const MAX_TIMESTAMP_MS = Date.UTC(10000, 0, 1);
|
|
100
|
+
/** Upper bound for any untrusted value echoed into a diagnostic detail. */
|
|
101
|
+
const MAX_DETAIL_CHARS = 120;
|
|
102
|
+
/** The dispatch promise rejected (or dispatch threw). Carries the observation when one was signed. */
|
|
103
|
+
class ApprovedExecutionError extends Error {
|
|
104
|
+
constructor(cause, observation, observationError) {
|
|
105
|
+
super('approved dispatch threw');
|
|
106
|
+
this.name = 'ApprovedExecutionError';
|
|
107
|
+
this.cause = cause;
|
|
108
|
+
if (observation !== undefined)
|
|
109
|
+
this.observation = observation;
|
|
110
|
+
if (observationError !== undefined)
|
|
111
|
+
this.observationError = observationError;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ApprovedExecutionError = ApprovedExecutionError;
|
|
115
|
+
const OK = { ok: true };
|
|
116
|
+
function fail(detail) {
|
|
117
|
+
return { ok: false, detail };
|
|
118
|
+
}
|
|
119
|
+
function utf8(str) {
|
|
120
|
+
return new TextEncoder().encode(str);
|
|
121
|
+
}
|
|
122
|
+
function joinPath(path, member) {
|
|
123
|
+
return path === '' ? member : `${path}.${member}`;
|
|
124
|
+
}
|
|
125
|
+
function isObjectLike(v) {
|
|
126
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
127
|
+
}
|
|
128
|
+
function truncate(text) {
|
|
129
|
+
return text.length > MAX_DETAIL_CHARS ? text.slice(0, MAX_DETAIL_CHARS - 1) + '…' : text;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Bounded, non-throwing rendering of an untrusted value for diagnostics. Never
|
|
133
|
+
* invokes user code: no toString/valueOf/toJSON, no template interpolation of
|
|
134
|
+
* symbols or null-prototype objects, no JSON.stringify of bigint or cycles.
|
|
135
|
+
*/
|
|
136
|
+
function formatUnknown(v) {
|
|
137
|
+
try {
|
|
138
|
+
switch (typeof v) {
|
|
139
|
+
case 'string':
|
|
140
|
+
return truncate(JSON.stringify(v));
|
|
141
|
+
case 'number':
|
|
142
|
+
case 'boolean':
|
|
143
|
+
return String(v);
|
|
144
|
+
case 'undefined':
|
|
145
|
+
return 'undefined';
|
|
146
|
+
case 'bigint':
|
|
147
|
+
return `${truncate(v.toString())}n (bigint)`;
|
|
148
|
+
case 'symbol':
|
|
149
|
+
return 'symbol';
|
|
150
|
+
case 'function':
|
|
151
|
+
return 'function';
|
|
152
|
+
default:
|
|
153
|
+
if (v === null)
|
|
154
|
+
return 'null';
|
|
155
|
+
return Array.isArray(v) ? 'array' : 'object';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return 'unprintable';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Bounded, non-throwing message for a caught value (Error-like or anything else). */
|
|
163
|
+
/** Property read that never throws (revoked or trapping Proxies, throwing getters). */
|
|
164
|
+
function safeRead(target, key) {
|
|
165
|
+
try {
|
|
166
|
+
return target[key];
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function errorMessage(e) {
|
|
173
|
+
try {
|
|
174
|
+
if (typeof e === 'object' && e !== null) {
|
|
175
|
+
const message = safeRead(e, 'message');
|
|
176
|
+
if (typeof message === 'string') {
|
|
177
|
+
const name = safeRead(e, 'name');
|
|
178
|
+
return truncate(typeof name === 'string' && name.length > 0 ? `${name}: ${message}` : message);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return `non-Error value thrown: ${formatUnknown(e)}`;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return 'unprintable error';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** Wraps a caught value into an Error without ever invoking its own conversion methods. */
|
|
188
|
+
function toError(e) {
|
|
189
|
+
// `instanceof` runs prototype machinery: a revoked Proxy or a throwing
|
|
190
|
+
// getPrototypeOf trap would throw here and break the settlement contract.
|
|
191
|
+
try {
|
|
192
|
+
if (e instanceof Error)
|
|
193
|
+
return e;
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// fall through
|
|
197
|
+
}
|
|
198
|
+
return new Error(errorMessage(e));
|
|
199
|
+
}
|
|
200
|
+
function describe(v) {
|
|
201
|
+
return formatUnknown(v);
|
|
202
|
+
}
|
|
203
|
+
/** Strict RFC 3339 UTC-ms-Z: pattern plus an exact round-trip through Date. */
|
|
204
|
+
function parseRfc3339MsZ(value) {
|
|
205
|
+
if (typeof value !== 'string' || !RFC3339_MS_Z.test(value))
|
|
206
|
+
return undefined;
|
|
207
|
+
const ms = Date.parse(value);
|
|
208
|
+
if (!Number.isFinite(ms))
|
|
209
|
+
return undefined;
|
|
210
|
+
if (new Date(ms).toISOString() !== value)
|
|
211
|
+
return undefined;
|
|
212
|
+
return ms;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Closed-schema member check: unknown members are rejected first, then every
|
|
216
|
+
* required member must be present. Presence is `in`, so a member explicitly
|
|
217
|
+
* set to `undefined` is present and is rejected by its type check instead of
|
|
218
|
+
* being silently dropped by JSON serialization.
|
|
219
|
+
*/
|
|
220
|
+
function checkMembers(obj, path, required, optional = []) {
|
|
221
|
+
for (const key of Object.keys(obj)) {
|
|
222
|
+
if (!required.includes(key) && !optional.includes(key)) {
|
|
223
|
+
return fail(`unknown member "${joinPath(path, truncate(key))}" (closed schema)`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const key of required) {
|
|
227
|
+
if (!(key in obj)) {
|
|
228
|
+
return fail(`missing required member "${joinPath(path, key)}"`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return OK;
|
|
232
|
+
}
|
|
233
|
+
function checkId(obj, path, member) {
|
|
234
|
+
const v = obj[member];
|
|
235
|
+
if (typeof v !== 'string' || !ID_PATTERN.test(v)) {
|
|
236
|
+
return fail(`member "${joinPath(path, member)}" must be an id: printable ASCII excluding space (0x21..0x7E), 1..256 characters`);
|
|
237
|
+
}
|
|
238
|
+
return OK;
|
|
239
|
+
}
|
|
240
|
+
function checkNonEmptyString(obj, path, member) {
|
|
241
|
+
const v = obj[member];
|
|
242
|
+
if (typeof v !== 'string' || v.length === 0) {
|
|
243
|
+
return fail(`member "${joinPath(path, member)}" must be a non-empty string`);
|
|
244
|
+
}
|
|
245
|
+
return OK;
|
|
246
|
+
}
|
|
247
|
+
function deepFreeze(value) {
|
|
248
|
+
if (typeof value === 'object' && value !== null && !Object.isFrozen(value)) {
|
|
249
|
+
Object.freeze(value);
|
|
250
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
251
|
+
deepFreeze(value[key]);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
}
|
|
256
|
+
const SIZE_CAP_DETAIL = 'serialized size exceeds the 1 MiB cap';
|
|
257
|
+
function renderPath(stack) {
|
|
258
|
+
let out = '$';
|
|
259
|
+
for (const part of stack)
|
|
260
|
+
out += typeof part === 'number' ? `[${part}]` : `.${truncate(part)}`;
|
|
261
|
+
return out;
|
|
262
|
+
}
|
|
263
|
+
function charge(count, bytes, stack) {
|
|
264
|
+
count.bytes += bytes;
|
|
265
|
+
return count.bytes > exports.ARGUMENTS_MAX_BYTES ? `${SIZE_CAP_DETAIL} at ${renderPath(stack)}` : undefined;
|
|
266
|
+
}
|
|
267
|
+
function validateJsonNode(node, stack, depth, count) {
|
|
268
|
+
switch (typeof node) {
|
|
269
|
+
case 'string':
|
|
270
|
+
return charge(count, node.length + 2, stack);
|
|
271
|
+
case 'boolean':
|
|
272
|
+
return charge(count, node ? 4 : 5, stack);
|
|
273
|
+
case 'number':
|
|
274
|
+
if (!Number.isFinite(node))
|
|
275
|
+
return `non-finite number at ${renderPath(stack)}`;
|
|
276
|
+
if (Object.is(node, -0))
|
|
277
|
+
return `negative zero at ${renderPath(stack)}`;
|
|
278
|
+
return charge(count, String(node).length, stack);
|
|
279
|
+
case 'object':
|
|
280
|
+
break;
|
|
281
|
+
default:
|
|
282
|
+
// undefined, function, symbol, bigint: unreachable from JSON.parse
|
|
283
|
+
return `unsupported ${typeof node} at ${renderPath(stack)}`;
|
|
284
|
+
}
|
|
285
|
+
if (node === null)
|
|
286
|
+
return charge(count, 4, stack);
|
|
287
|
+
if (depth > exports.ARGUMENTS_MAX_DEPTH)
|
|
288
|
+
return `nesting depth exceeds ${exports.ARGUMENTS_MAX_DEPTH} at ${renderPath(stack)}`;
|
|
289
|
+
if (Array.isArray(node)) {
|
|
290
|
+
let problem = charge(count, 2 + Math.max(0, node.length - 1), stack);
|
|
291
|
+
if (problem)
|
|
292
|
+
return problem;
|
|
293
|
+
for (let i = 0; i < node.length; i++) {
|
|
294
|
+
stack.push(i);
|
|
295
|
+
problem = validateJsonNode(node[i], stack, depth + 1, count);
|
|
296
|
+
stack.pop();
|
|
297
|
+
if (problem)
|
|
298
|
+
return problem;
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
// Object.keys lists the own "__proto__" property JSON.parse creates.
|
|
303
|
+
const keys = Object.keys(node);
|
|
304
|
+
let problem = charge(count, 2 + Math.max(0, keys.length - 1), stack);
|
|
305
|
+
if (problem)
|
|
306
|
+
return problem;
|
|
307
|
+
for (const key of keys) {
|
|
308
|
+
if (FORBIDDEN_KEYS.has(key))
|
|
309
|
+
return `forbidden key "${key}" at ${renderPath(stack)}`;
|
|
310
|
+
problem = charge(count, key.length + 3, stack);
|
|
311
|
+
if (problem)
|
|
312
|
+
return problem;
|
|
313
|
+
stack.push(key);
|
|
314
|
+
problem = validateJsonNode(node[key], stack, depth + 1, count);
|
|
315
|
+
stack.pop();
|
|
316
|
+
if (problem)
|
|
317
|
+
return problem;
|
|
318
|
+
}
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
/** Parse once (try/catch), validate the parsed tree, canonicalize, apply both size caps. */
|
|
322
|
+
function analyzeArgumentsJson(argumentsJson) {
|
|
323
|
+
if (typeof argumentsJson !== 'string') {
|
|
324
|
+
return fail(`argumentsJson must be a string, got ${describe(argumentsJson)}`);
|
|
325
|
+
}
|
|
326
|
+
if (utf8(argumentsJson).length > exports.ARGUMENTS_MAX_BYTES) {
|
|
327
|
+
return fail('argument text exceeds the 1 MiB size cap');
|
|
328
|
+
}
|
|
329
|
+
let parsed;
|
|
330
|
+
try {
|
|
331
|
+
parsed = JSON.parse(argumentsJson);
|
|
332
|
+
}
|
|
333
|
+
catch (e) {
|
|
334
|
+
return fail(`invalid JSON: ${errorMessage(e)}`);
|
|
335
|
+
}
|
|
336
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
337
|
+
return fail(`arguments must be a JSON object, got ${describe(parsed)}`);
|
|
338
|
+
}
|
|
339
|
+
const problem = validateJsonNode(parsed, [], 1, { bytes: 0 });
|
|
340
|
+
if (problem)
|
|
341
|
+
return fail(problem);
|
|
342
|
+
const canonical = (0, canonical_1.canonicalize)(parsed);
|
|
343
|
+
if (utf8(canonical).length > exports.ARGUMENTS_MAX_BYTES) {
|
|
344
|
+
return fail(`canonical ${SIZE_CAP_DETAIL}`);
|
|
345
|
+
}
|
|
346
|
+
return { ok: true, value: parsed, canonical };
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* bab1 domain check for argument JSON text: invalid JSON → ok:false with an
|
|
350
|
+
* "invalid JSON" detail; otherwise the parsed tree must be a non-array object
|
|
351
|
+
* whose values are objects, arrays, strings, finite numbers, booleans or null,
|
|
352
|
+
* with no -0, no `__proto__`/`constructor`/`prototype` key at any depth,
|
|
353
|
+
* nesting depth ≤ 64, text and canonical form ≤ 1 MiB.
|
|
354
|
+
*/
|
|
355
|
+
function validateArgumentsJson(argumentsJson) {
|
|
356
|
+
const analyzed = analyzeArgumentsJson(argumentsJson);
|
|
357
|
+
return analyzed.ok ? OK : fail(analyzed.detail);
|
|
358
|
+
}
|
|
359
|
+
function digestCanonical(canonical) {
|
|
360
|
+
const dst = utf8(exports.ARGUMENTS_DIGEST_DST);
|
|
361
|
+
const body = utf8(canonical);
|
|
362
|
+
const input = new Uint8Array(dst.length + 1 + body.length);
|
|
363
|
+
input.set(dst, 0);
|
|
364
|
+
input[dst.length] = 0x00;
|
|
365
|
+
input.set(body, dst.length + 1);
|
|
366
|
+
return (0, utils_1.bytesToHex)((0, sha256_1.sha256)(input));
|
|
367
|
+
}
|
|
368
|
+
/** The deep-frozen parsed tree is the snapshot used for both the digest and dispatch. */
|
|
369
|
+
function parseArguments(argumentsJson) {
|
|
370
|
+
const analyzed = analyzeArgumentsJson(argumentsJson);
|
|
371
|
+
if (!analyzed.ok)
|
|
372
|
+
return analyzed;
|
|
373
|
+
return { ok: true, value: deepFreeze(analyzed.value), digest: digestCanonical(analyzed.canonical) };
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* argumentsDigest = sha256hex( utf8("bolyra.approval.arguments/1") || 0x00 || utf8(canonicalize(value)) )
|
|
377
|
+
* where `value` is the parsed, bab1-validated argument object. Throws on
|
|
378
|
+
* invalid JSON or out-of-domain values.
|
|
379
|
+
*/
|
|
380
|
+
function computeArgumentsDigest(argumentsJson) {
|
|
381
|
+
if (typeof argumentsJson !== 'string') {
|
|
382
|
+
throw new TypeError('computeArgumentsDigest: argumentsJson must be a string');
|
|
383
|
+
}
|
|
384
|
+
const parsed = parseArguments(argumentsJson);
|
|
385
|
+
if (!parsed.ok) {
|
|
386
|
+
throw new Error(`computeArgumentsDigest: ${parsed.detail}`);
|
|
387
|
+
}
|
|
388
|
+
return parsed.digest;
|
|
389
|
+
}
|
|
390
|
+
function validateApprovalPayloadMembers(payload, path) {
|
|
391
|
+
let r = checkMembers(payload, path, ['v', 'kind', 'issuedAt', 'issuer', 'keyId', 'binding', 'approval']);
|
|
392
|
+
if (!r.ok)
|
|
393
|
+
return r;
|
|
394
|
+
if (payload.v !== 1)
|
|
395
|
+
return fail(`member "${joinPath(path, 'v')}" must be 1`);
|
|
396
|
+
if (payload.kind !== 'bolyra.approval')
|
|
397
|
+
return fail(`member "${joinPath(path, 'kind')}" must be "bolyra.approval"`);
|
|
398
|
+
if (!Number.isSafeInteger(payload.issuedAt) || payload.issuedAt < 0) {
|
|
399
|
+
return fail(`member "${joinPath(path, 'issuedAt')}" must be a non-negative integer (unix seconds)`);
|
|
400
|
+
}
|
|
401
|
+
r = checkNonEmptyString(payload, path, 'issuer');
|
|
402
|
+
if (!r.ok)
|
|
403
|
+
return r;
|
|
404
|
+
r = checkNonEmptyString(payload, path, 'keyId');
|
|
405
|
+
if (!r.ok)
|
|
406
|
+
return r;
|
|
407
|
+
const bindingPath = joinPath(path, 'binding');
|
|
408
|
+
const binding = payload.binding;
|
|
409
|
+
if (!isObjectLike(binding))
|
|
410
|
+
return fail(`member "${bindingPath}" must be an object`);
|
|
411
|
+
r = checkMembers(binding, bindingPath, ['scheme', 'requester', 'audience', 'tool', 'operationId', 'argumentsDigest']);
|
|
412
|
+
if (!r.ok)
|
|
413
|
+
return r;
|
|
414
|
+
if (binding.scheme !== 'bab1')
|
|
415
|
+
return fail(`member "${joinPath(bindingPath, 'scheme')}" must be "bab1"`);
|
|
416
|
+
for (const member of ['requester', 'audience', 'tool', 'operationId']) {
|
|
417
|
+
r = checkId(binding, bindingPath, member);
|
|
418
|
+
if (!r.ok)
|
|
419
|
+
return r;
|
|
420
|
+
}
|
|
421
|
+
if (typeof binding.argumentsDigest !== 'string' || !HEX64.test(binding.argumentsDigest)) {
|
|
422
|
+
return fail(`member "${joinPath(bindingPath, 'argumentsDigest')}" must be 64 lowercase hex characters`);
|
|
423
|
+
}
|
|
424
|
+
return validateApprovalAssertion(payload.approval, joinPath(path, 'approval'));
|
|
425
|
+
}
|
|
426
|
+
function validateApprovalAssertion(approval, path) {
|
|
427
|
+
if (!isObjectLike(approval))
|
|
428
|
+
return fail(`member "${path}" must be an object`);
|
|
429
|
+
let r = checkMembers(approval, path, ['approver', 'source', 'decision', 'decidedAt', 'validity'], ['requestId']);
|
|
430
|
+
if (!r.ok)
|
|
431
|
+
return r;
|
|
432
|
+
if (typeof approval.approver !== 'string' || !APPROVER_PATTERN.test(approval.approver)) {
|
|
433
|
+
return fail(`member "${joinPath(path, 'approver')}" must be printable ASCII (0x20..0x7E), 1..256 characters`);
|
|
434
|
+
}
|
|
435
|
+
r = checkId(approval, path, 'source');
|
|
436
|
+
if (!r.ok)
|
|
437
|
+
return r;
|
|
438
|
+
if (approval.decision !== 'approved' && approval.decision !== 'denied') {
|
|
439
|
+
return fail(`member "${joinPath(path, 'decision')}" must be "approved" or "denied"`);
|
|
440
|
+
}
|
|
441
|
+
if (parseRfc3339MsZ(approval.decidedAt) === undefined) {
|
|
442
|
+
return fail(`member "${joinPath(path, 'decidedAt')}" must match YYYY-MM-DDTHH:MM:SS.mmmZ exactly (3-digit ms, UTC Z)`);
|
|
443
|
+
}
|
|
444
|
+
const validityPath = joinPath(path, 'validity');
|
|
445
|
+
const validity = approval.validity;
|
|
446
|
+
if (!isObjectLike(validity))
|
|
447
|
+
return fail(`member "${validityPath}" must be an object`);
|
|
448
|
+
if (validity.kind === 'once') {
|
|
449
|
+
r = checkMembers(validity, validityPath, ['kind']);
|
|
450
|
+
if (!r.ok)
|
|
451
|
+
return r;
|
|
452
|
+
}
|
|
453
|
+
else if (validity.kind === 'until') {
|
|
454
|
+
r = checkMembers(validity, validityPath, ['kind', 'notAfter']);
|
|
455
|
+
if (!r.ok)
|
|
456
|
+
return r;
|
|
457
|
+
if (parseRfc3339MsZ(validity.notAfter) === undefined) {
|
|
458
|
+
return fail(`member "${joinPath(validityPath, 'notAfter')}" must match YYYY-MM-DDTHH:MM:SS.mmmZ exactly (3-digit ms, UTC Z)`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
return fail(`member "${joinPath(validityPath, 'kind')}" must be "once" or "until"`);
|
|
463
|
+
}
|
|
464
|
+
if ('requestId' in approval) {
|
|
465
|
+
r = checkId(approval, path, 'requestId');
|
|
466
|
+
if (!r.ok)
|
|
467
|
+
return r;
|
|
468
|
+
}
|
|
469
|
+
return OK;
|
|
470
|
+
}
|
|
471
|
+
function approvalTimes(payload) {
|
|
472
|
+
const decidedAtMs = parseRfc3339MsZ(payload.approval.decidedAt);
|
|
473
|
+
const validity = payload.approval.validity;
|
|
474
|
+
return validity.kind === 'until'
|
|
475
|
+
? { decidedAtMs, notAfterMs: parseRfc3339MsZ(validity.notAfter) }
|
|
476
|
+
: { decidedAtMs };
|
|
477
|
+
}
|
|
478
|
+
function validateExecutionPayloadMembers(payload, path) {
|
|
479
|
+
let r = checkMembers(payload, path, ['v', 'kind', 'issuedAt', 'issuer', 'keyId', 'execution']);
|
|
480
|
+
if (!r.ok)
|
|
481
|
+
return r;
|
|
482
|
+
if (payload.v !== 1)
|
|
483
|
+
return fail(`member "${joinPath(path, 'v')}" must be 1`);
|
|
484
|
+
if (payload.kind !== 'bolyra.execution')
|
|
485
|
+
return fail(`member "${joinPath(path, 'kind')}" must be "bolyra.execution"`);
|
|
486
|
+
if (!Number.isSafeInteger(payload.issuedAt) || payload.issuedAt < 0) {
|
|
487
|
+
return fail(`member "${joinPath(path, 'issuedAt')}" must be a non-negative integer (unix seconds)`);
|
|
488
|
+
}
|
|
489
|
+
r = checkNonEmptyString(payload, path, 'issuer');
|
|
490
|
+
if (!r.ok)
|
|
491
|
+
return r;
|
|
492
|
+
r = checkNonEmptyString(payload, path, 'keyId');
|
|
493
|
+
if (!r.ok)
|
|
494
|
+
return r;
|
|
495
|
+
const execPath = joinPath(path, 'execution');
|
|
496
|
+
const exec = payload.execution;
|
|
497
|
+
if (!isObjectLike(exec))
|
|
498
|
+
return fail(`member "${execPath}" must be an object`);
|
|
499
|
+
r = checkMembers(exec, execPath, [
|
|
500
|
+
'scheme',
|
|
501
|
+
'approvalReceiptHash',
|
|
502
|
+
'approvalReceiptId',
|
|
503
|
+
'operationId',
|
|
504
|
+
'attemptId',
|
|
505
|
+
'requester',
|
|
506
|
+
'audience',
|
|
507
|
+
'tool',
|
|
508
|
+
'actionDigest',
|
|
509
|
+
'dispatchedAt',
|
|
510
|
+
'outcome',
|
|
511
|
+
]);
|
|
512
|
+
if (!r.ok)
|
|
513
|
+
return r;
|
|
514
|
+
if (exec.scheme !== 'beo1')
|
|
515
|
+
return fail(`member "${joinPath(execPath, 'scheme')}" must be "beo1"`);
|
|
516
|
+
if (typeof exec.approvalReceiptHash !== 'string' || !HEX_0X64.test(exec.approvalReceiptHash)) {
|
|
517
|
+
return fail(`member "${joinPath(execPath, 'approvalReceiptHash')}" must be 0x + 64 lowercase hex characters`);
|
|
518
|
+
}
|
|
519
|
+
if (typeof exec.approvalReceiptId !== 'string' || !HEX_0X16.test(exec.approvalReceiptId)) {
|
|
520
|
+
return fail(`member "${joinPath(execPath, 'approvalReceiptId')}" must be 0x + 16 lowercase hex characters`);
|
|
521
|
+
}
|
|
522
|
+
for (const member of ['operationId', 'attemptId', 'requester', 'audience', 'tool']) {
|
|
523
|
+
r = checkId(exec, execPath, member);
|
|
524
|
+
if (!r.ok)
|
|
525
|
+
return r;
|
|
526
|
+
}
|
|
527
|
+
if (typeof exec.actionDigest !== 'string' || !HEX64.test(exec.actionDigest)) {
|
|
528
|
+
return fail(`member "${joinPath(execPath, 'actionDigest')}" must be 64 lowercase hex characters`);
|
|
529
|
+
}
|
|
530
|
+
if (parseRfc3339MsZ(exec.dispatchedAt) === undefined) {
|
|
531
|
+
return fail(`member "${joinPath(execPath, 'dispatchedAt')}" must match YYYY-MM-DDTHH:MM:SS.mmmZ exactly (3-digit ms, UTC Z)`);
|
|
532
|
+
}
|
|
533
|
+
if (exec.outcome !== 'returned' && exec.outcome !== 'threw') {
|
|
534
|
+
return fail(`member "${joinPath(execPath, 'outcome')}" must be "returned" or "threw"`);
|
|
535
|
+
}
|
|
536
|
+
return OK;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Structural validation of a signed envelope of one of the new kinds: closed
|
|
540
|
+
* schema at every level, kind, v, scheme, envelope/payload keyId agreement,
|
|
541
|
+
* signature alg and byte lengths, derived id. Signature VALIDITY is a
|
|
542
|
+
* separate step (verifyReceipt).
|
|
543
|
+
*/
|
|
544
|
+
function validateEnvelope(value, kind, validatePayload) {
|
|
545
|
+
const bad = (detail) => ({ ok: false, code: 'malformed_receipt', detail });
|
|
546
|
+
if (!isObjectLike(value))
|
|
547
|
+
return bad(`receipt must be an object, got ${describe(value)}`);
|
|
548
|
+
let r = checkMembers(value, '', ['id', 'payload', 'signature']);
|
|
549
|
+
if (!r.ok)
|
|
550
|
+
return bad(r.detail);
|
|
551
|
+
const payload = value.payload;
|
|
552
|
+
if (!isObjectLike(payload))
|
|
553
|
+
return bad('member "payload" must be an object');
|
|
554
|
+
if (payload.kind !== kind) {
|
|
555
|
+
return { ok: false, code: 'wrong_kind', detail: `expected payload.kind "${kind}", got ${formatUnknown(payload.kind)}` };
|
|
556
|
+
}
|
|
557
|
+
r = validatePayload(payload, 'payload');
|
|
558
|
+
if (!r.ok)
|
|
559
|
+
return bad(r.detail);
|
|
560
|
+
const signature = value.signature;
|
|
561
|
+
if (!isObjectLike(signature))
|
|
562
|
+
return bad('member "signature" must be an object');
|
|
563
|
+
r = checkMembers(signature, 'signature', ['alg', 'keyId', 'signer', 'payloadHash', 'value']);
|
|
564
|
+
if (!r.ok)
|
|
565
|
+
return bad(r.detail);
|
|
566
|
+
if (typeof signature.keyId !== 'string')
|
|
567
|
+
return bad('member "signature.keyId" must be a string');
|
|
568
|
+
if (signature.keyId !== payload.keyId) {
|
|
569
|
+
return {
|
|
570
|
+
ok: false,
|
|
571
|
+
code: 'keyid_mismatch',
|
|
572
|
+
detail: `envelope signature.keyId ${formatUnknown(signature.keyId)} differs from payload.keyId ${formatUnknown(payload.keyId)}`,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
if (signature.alg !== 'ES256K')
|
|
576
|
+
return bad('member "signature.alg" must be "ES256K"');
|
|
577
|
+
if (typeof signature.signer !== 'string' || !ADDRESS_PATTERN.test(signature.signer)) {
|
|
578
|
+
return bad('member "signature.signer" must be a 20-byte 0x-prefixed hex address');
|
|
579
|
+
}
|
|
580
|
+
if (typeof signature.payloadHash !== 'string' || !HEX_0X64.test(signature.payloadHash)) {
|
|
581
|
+
return bad('member "signature.payloadHash" must be 0x + 64 lowercase hex characters (32 bytes)');
|
|
582
|
+
}
|
|
583
|
+
if (typeof signature.value !== 'string' || !SIGNATURE_VALUE_PATTERN.test(signature.value)) {
|
|
584
|
+
return bad('member "signature.value" must be 0x + 130 lowercase hex characters (65 bytes r||s||v)');
|
|
585
|
+
}
|
|
586
|
+
if (typeof value.id !== 'string' || value.id !== '0x' + signature.payloadHash.slice(2, 18)) {
|
|
587
|
+
return bad('envelope id does not equal the id derived from signature.payloadHash');
|
|
588
|
+
}
|
|
589
|
+
return { ok: true, receipt: value };
|
|
590
|
+
}
|
|
591
|
+
function validateApprovalEnvelope(value) {
|
|
592
|
+
return validateEnvelope(value, 'bolyra.approval', validateApprovalPayloadMembers);
|
|
593
|
+
}
|
|
594
|
+
function validateExecutionEnvelope(value) {
|
|
595
|
+
return validateEnvelope(value, 'bolyra.execution', validateExecutionPayloadMembers);
|
|
596
|
+
}
|
|
597
|
+
function validateSignerConfig(value, path) {
|
|
598
|
+
if (!isObjectLike(value))
|
|
599
|
+
return fail(`${path} must be an object with issuer, keyId and privateKey`);
|
|
600
|
+
let r = checkNonEmptyString(value, path, 'issuer');
|
|
601
|
+
if (!r.ok)
|
|
602
|
+
return r;
|
|
603
|
+
r = checkNonEmptyString(value, path, 'keyId');
|
|
604
|
+
if (!r.ok)
|
|
605
|
+
return r;
|
|
606
|
+
const key = value.privateKey;
|
|
607
|
+
if (typeof key !== 'string' || !PRIVATE_KEY_PATTERN.test(key)) {
|
|
608
|
+
return fail(`member "${joinPath(path, 'privateKey')}" must be a 32-byte hex-encoded secp256k1 private key`);
|
|
609
|
+
}
|
|
610
|
+
const clean = key.startsWith('0x') ? key.slice(2) : key;
|
|
611
|
+
if (!secp256k1.utils.isValidPrivateKey(clean)) {
|
|
612
|
+
return fail(`member "${joinPath(path, 'privateKey')}" is not a valid secp256k1 private key`);
|
|
613
|
+
}
|
|
614
|
+
return OK;
|
|
615
|
+
}
|
|
616
|
+
// ---------------------------------------------------------------------------
|
|
617
|
+
// §5.2 — createApprovalReceipt
|
|
618
|
+
// ---------------------------------------------------------------------------
|
|
619
|
+
/**
|
|
620
|
+
* Validates every member of `input` and the bab1 domain of `argumentsJson`,
|
|
621
|
+
* computes the digest, builds the §4.1 payload and signs it. Throws on any
|
|
622
|
+
* invalid input, naming the first offending member. Provenance (`approver`,
|
|
623
|
+
* `source`, `decidedAt`, `decision`, `validity`) is never defaulted; only the
|
|
624
|
+
* fixed discriminators (`v`, `kind`, `scheme`) and `issuedAt` have defaults.
|
|
625
|
+
*/
|
|
626
|
+
function createApprovalReceipt(input, signerConfig) {
|
|
627
|
+
const throwOn = (r) => {
|
|
628
|
+
if (!r.ok)
|
|
629
|
+
throw new Error(`createApprovalReceipt: ${r.detail}`);
|
|
630
|
+
};
|
|
631
|
+
throwOn(validateSignerConfig(signerConfig, 'signerConfig'));
|
|
632
|
+
if (!isObjectLike(input))
|
|
633
|
+
throw new Error(`createApprovalReceipt: input must be an object, got ${describe(input)}`);
|
|
634
|
+
throwOn(checkMembers(input, '', ['binding', 'approval', 'argumentsJson'], ['v', 'kind', 'issuedAt']));
|
|
635
|
+
if ('v' in input && input.v !== 1)
|
|
636
|
+
throwOn(fail('member "v" must be 1'));
|
|
637
|
+
if ('kind' in input && input.kind !== 'bolyra.approval')
|
|
638
|
+
throwOn(fail('member "kind" must be "bolyra.approval"'));
|
|
639
|
+
let issuedAt;
|
|
640
|
+
if ('issuedAt' in input) {
|
|
641
|
+
if (!Number.isSafeInteger(input.issuedAt) || input.issuedAt < 0) {
|
|
642
|
+
throwOn(fail('member "issuedAt" must be a non-negative integer (unix seconds)'));
|
|
643
|
+
}
|
|
644
|
+
issuedAt = input.issuedAt;
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
issuedAt = Math.floor(Date.now() / 1000);
|
|
648
|
+
}
|
|
649
|
+
const binding = input.binding;
|
|
650
|
+
if (!isObjectLike(binding))
|
|
651
|
+
throwOn(fail('member "binding" must be an object'));
|
|
652
|
+
throwOn(checkMembers(binding, 'binding', ['requester', 'audience', 'tool', 'operationId'], ['scheme']));
|
|
653
|
+
const b = binding;
|
|
654
|
+
if ('scheme' in b && b.scheme !== 'bab1')
|
|
655
|
+
throwOn(fail('member "binding.scheme" must be "bab1"'));
|
|
656
|
+
if (typeof input.argumentsJson !== 'string')
|
|
657
|
+
throwOn(fail('member "argumentsJson" must be a string'));
|
|
658
|
+
const parsed = parseArguments(input.argumentsJson);
|
|
659
|
+
if (!parsed.ok)
|
|
660
|
+
throwOn(fail(`member "argumentsJson": ${parsed.detail}`));
|
|
661
|
+
const digest = parsed.digest;
|
|
662
|
+
for (const member of ['requester', 'audience', 'tool', 'operationId']) {
|
|
663
|
+
throwOn(checkId(b, 'binding', member));
|
|
664
|
+
}
|
|
665
|
+
// The approval block is the same closed schema inside the payload; validate
|
|
666
|
+
// the caller's object before copying it member by member.
|
|
667
|
+
throwOn(validateApprovalAssertion(input.approval, 'approval'));
|
|
668
|
+
const a = input.approval;
|
|
669
|
+
const validity = a.validity.kind === 'until' ? { kind: 'until', notAfter: a.validity.notAfter } : { kind: 'once' };
|
|
670
|
+
const payload = {
|
|
671
|
+
v: 1,
|
|
672
|
+
kind: 'bolyra.approval',
|
|
673
|
+
issuedAt,
|
|
674
|
+
issuer: signerConfig.issuer,
|
|
675
|
+
keyId: signerConfig.keyId,
|
|
676
|
+
binding: {
|
|
677
|
+
scheme: 'bab1',
|
|
678
|
+
requester: b.requester,
|
|
679
|
+
audience: b.audience,
|
|
680
|
+
tool: b.tool,
|
|
681
|
+
operationId: b.operationId,
|
|
682
|
+
argumentsDigest: digest,
|
|
683
|
+
},
|
|
684
|
+
approval: {
|
|
685
|
+
approver: a.approver,
|
|
686
|
+
source: a.source,
|
|
687
|
+
decision: a.decision,
|
|
688
|
+
decidedAt: a.decidedAt,
|
|
689
|
+
validity,
|
|
690
|
+
...(a.requestId !== undefined ? { requestId: a.requestId } : {}),
|
|
691
|
+
},
|
|
692
|
+
};
|
|
693
|
+
// The emitter never produces what the verifier would reject.
|
|
694
|
+
throwOn(validateApprovalPayloadMembers(payload, ''));
|
|
695
|
+
const signed = (0, sign_1.signReceipt)(payload, signerConfig);
|
|
696
|
+
const envelope = validateApprovalEnvelope(signed);
|
|
697
|
+
if (!envelope.ok)
|
|
698
|
+
throw new Error(`createApprovalReceipt: produced an invalid envelope: ${envelope.detail}`);
|
|
699
|
+
return signed;
|
|
700
|
+
}
|
|
701
|
+
// ---------------------------------------------------------------------------
|
|
702
|
+
// §5.3 — executeApproved
|
|
703
|
+
// ---------------------------------------------------------------------------
|
|
704
|
+
function blocked(code, detail) {
|
|
705
|
+
return { outcome: 'blocked', code, detail };
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Sample the captured clock: epoch ms via Date.prototype.getTime.call, or
|
|
709
|
+
* undefined when the clock throws, returns a non-Date, an invalid Date, or a
|
|
710
|
+
* time outside the observation timestamp domain (0 <= ms < year 10000, so
|
|
711
|
+
* toISOString yields a 4-digit year and issuedAt is a non-negative integer).
|
|
712
|
+
*/
|
|
713
|
+
function sampleClock(clock) {
|
|
714
|
+
try {
|
|
715
|
+
const t = Date.prototype.getTime.call(clock());
|
|
716
|
+
if (typeof t !== 'number' || !Number.isFinite(t))
|
|
717
|
+
return undefined;
|
|
718
|
+
if (t < 0 || t >= MAX_TIMESTAMP_MS)
|
|
719
|
+
return undefined;
|
|
720
|
+
return t;
|
|
721
|
+
}
|
|
722
|
+
catch {
|
|
723
|
+
return undefined;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const INVALID_CLOCK_DETAIL = 'clock threw, did not return a valid Date, or returned a time outside 1970-01-01T00:00:00.000Z..9999-12-31T23:59:59.999Z';
|
|
727
|
+
/** Attach a no-op sink to a thenable so a rejected consume result never surfaces as an unhandled rejection. Never awaits. */
|
|
728
|
+
function sinkThenable(v) {
|
|
729
|
+
try {
|
|
730
|
+
if ((typeof v === 'object' && v !== null) || typeof v === 'function') {
|
|
731
|
+
const then = v.then;
|
|
732
|
+
if (typeof then === 'function') {
|
|
733
|
+
const noop = () => undefined;
|
|
734
|
+
then.call(v, noop, noop);
|
|
735
|
+
return true;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
catch {
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
function temporalCheck(nowMs, times, label) {
|
|
745
|
+
if (times.decidedAtMs > nowMs) {
|
|
746
|
+
return blocked('future_decision', `decidedAt is after the ${label} clock sample`);
|
|
747
|
+
}
|
|
748
|
+
if (times.notAfterMs !== undefined && nowMs >= times.notAfterMs) {
|
|
749
|
+
return blocked('expired', `${label} clock sample is at or after validity.notAfter`);
|
|
750
|
+
}
|
|
751
|
+
return undefined;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Steps 1–6a of §5.3, fully synchronous: everything that must happen before
|
|
755
|
+
* dispatch, with every caller-controlled read guarded. Any failure here is a
|
|
756
|
+
* typed blocked result; nothing in here may dispatch.
|
|
757
|
+
*/
|
|
758
|
+
function prepareDispatch(params, dispatch) {
|
|
759
|
+
// ----- Step 1: capture and snapshot once, before any other read ---------
|
|
760
|
+
if (!isObjectLike(params)) {
|
|
761
|
+
return blocked('malformed_input', `params must be an object, got ${describe(params)}`);
|
|
762
|
+
}
|
|
763
|
+
let rawReceipt;
|
|
764
|
+
let rawExpectedSigner;
|
|
765
|
+
let rawContext;
|
|
766
|
+
let argumentsJson;
|
|
767
|
+
let attemptId;
|
|
768
|
+
let consume;
|
|
769
|
+
let rawObserver;
|
|
770
|
+
let rawClock;
|
|
771
|
+
try {
|
|
772
|
+
rawReceipt = params.receipt;
|
|
773
|
+
rawExpectedSigner = params.expectedSigner;
|
|
774
|
+
rawContext = params.context;
|
|
775
|
+
argumentsJson = params.argumentsJson;
|
|
776
|
+
attemptId = params.attemptId;
|
|
777
|
+
consume = params.consume;
|
|
778
|
+
rawObserver = params.observer;
|
|
779
|
+
rawClock = params.clock;
|
|
780
|
+
}
|
|
781
|
+
catch (e) {
|
|
782
|
+
return blocked('malformed_input', `reading params threw: ${errorMessage(e)}`);
|
|
783
|
+
}
|
|
784
|
+
if (typeof dispatch !== 'function')
|
|
785
|
+
return blocked('malformed_input', 'dispatch must be a function');
|
|
786
|
+
if (typeof argumentsJson !== 'string')
|
|
787
|
+
return blocked('malformed_input', 'argumentsJson must be a string');
|
|
788
|
+
if (typeof attemptId !== 'string' || !ID_PATTERN.test(attemptId)) {
|
|
789
|
+
return blocked('malformed_input', 'attemptId must be an id: printable ASCII excluding space (0x21..0x7E), 1..256 characters');
|
|
790
|
+
}
|
|
791
|
+
if (consume !== undefined && typeof consume !== 'function') {
|
|
792
|
+
return blocked('malformed_input', 'consume must be a function when provided');
|
|
793
|
+
}
|
|
794
|
+
if (rawClock !== undefined && typeof rawClock !== 'function') {
|
|
795
|
+
return blocked('malformed_input', 'clock must be a function when provided');
|
|
796
|
+
}
|
|
797
|
+
if (typeof rawExpectedSigner !== 'string' || rawExpectedSigner.length === 0) {
|
|
798
|
+
return blocked('malformed_input', 'expectedSigner must be a non-empty string');
|
|
799
|
+
}
|
|
800
|
+
const clock = rawClock === undefined ? () => new Date() : rawClock;
|
|
801
|
+
const consumeFn = consume;
|
|
802
|
+
let receiptSnapshot;
|
|
803
|
+
let contextSnapshot;
|
|
804
|
+
let observerSnapshot;
|
|
805
|
+
let expectedSigner;
|
|
806
|
+
try {
|
|
807
|
+
receiptSnapshot = structuredClone(rawReceipt);
|
|
808
|
+
contextSnapshot = structuredClone(rawContext);
|
|
809
|
+
observerSnapshot = rawObserver === undefined ? undefined : structuredClone(rawObserver);
|
|
810
|
+
expectedSigner = structuredClone(rawExpectedSigner);
|
|
811
|
+
}
|
|
812
|
+
catch (e) {
|
|
813
|
+
return blocked('malformed_input', `params are not structured-cloneable: ${errorMessage(e)}`);
|
|
814
|
+
}
|
|
815
|
+
if (!isObjectLike(contextSnapshot)) {
|
|
816
|
+
return blocked('malformed_input', `context must be an object, got ${describe(contextSnapshot)}`);
|
|
817
|
+
}
|
|
818
|
+
{
|
|
819
|
+
let r = checkMembers(contextSnapshot, 'context', ['requester', 'audience', 'tool', 'operationId']);
|
|
820
|
+
if (!r.ok)
|
|
821
|
+
return blocked('malformed_input', r.detail);
|
|
822
|
+
for (const member of ['requester', 'audience', 'tool', 'operationId']) {
|
|
823
|
+
r = checkId(contextSnapshot, 'context', member);
|
|
824
|
+
if (!r.ok)
|
|
825
|
+
return blocked('malformed_input', r.detail);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const checkedContext = deepFreeze(contextSnapshot);
|
|
829
|
+
const parsed = parseArguments(argumentsJson);
|
|
830
|
+
if (!parsed.ok)
|
|
831
|
+
return blocked('arguments_out_of_domain', parsed.detail);
|
|
832
|
+
const snapshot = parsed.value;
|
|
833
|
+
const snapshotDigest = parsed.digest;
|
|
834
|
+
// ----- Step 2: observer preflight, before anything is consumed ----------
|
|
835
|
+
if (observerSnapshot !== undefined) {
|
|
836
|
+
const r = validateSignerConfig(observerSnapshot, 'observer');
|
|
837
|
+
if (!r.ok)
|
|
838
|
+
return blocked('observer_invalid', r.detail);
|
|
839
|
+
}
|
|
840
|
+
const observer = observerSnapshot;
|
|
841
|
+
// ----- Step 3: validate the receipt against the snapshots ---------------
|
|
842
|
+
const envelope = validateApprovalEnvelope(receiptSnapshot);
|
|
843
|
+
if (!envelope.ok)
|
|
844
|
+
return blocked(envelope.code, envelope.detail);
|
|
845
|
+
const receipt = deepFreeze(envelope.receipt);
|
|
846
|
+
if (!(0, sign_1.verifyReceipt)(receipt)) {
|
|
847
|
+
return blocked('signature_invalid', 'ES256K signature does not verify against the payload and claimed signer');
|
|
848
|
+
}
|
|
849
|
+
if (!(0, sign_1.verifyReceipt)(receipt, expectedSigner)) {
|
|
850
|
+
return blocked('untrusted_signer', `receipt signer ${receipt.signature.signer} is not the expected signer`);
|
|
851
|
+
}
|
|
852
|
+
if (receipt.payload.approval.decision !== 'approved') {
|
|
853
|
+
return blocked('decision_not_approved', `approval decision is "${receipt.payload.approval.decision}"`);
|
|
854
|
+
}
|
|
855
|
+
for (const member of ['requester', 'audience', 'tool', 'operationId']) {
|
|
856
|
+
if (receipt.payload.binding[member] !== checkedContext[member]) {
|
|
857
|
+
return blocked('context_mismatch', `binding.${member} does not equal context.${member}`);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (receipt.payload.binding.argumentsDigest !== snapshotDigest) {
|
|
861
|
+
return blocked('arguments_mismatch', 'argumentsDigest does not equal the digest of the supplied arguments');
|
|
862
|
+
}
|
|
863
|
+
const times = approvalTimes(receipt.payload);
|
|
864
|
+
// ----- Step 4: first clock sample -----------------------------------------
|
|
865
|
+
const t0 = sampleClock(clock);
|
|
866
|
+
if (t0 === undefined)
|
|
867
|
+
return blocked('invalid_clock', `${INVALID_CLOCK_DETAIL} (t0)`);
|
|
868
|
+
const t0Problem = temporalCheck(t0, times, 'first');
|
|
869
|
+
if (t0Problem)
|
|
870
|
+
return t0Problem;
|
|
871
|
+
// ----- Step 5: consumption (once receipts only) ---------------------------
|
|
872
|
+
if (receipt.payload.approval.validity.kind === 'once') {
|
|
873
|
+
if (consumeFn === undefined) {
|
|
874
|
+
return blocked('consume_required', 'a once receipt requires a consume callback');
|
|
875
|
+
}
|
|
876
|
+
const claim = Object.freeze({
|
|
877
|
+
signer: receipt.signature.signer.toLowerCase(),
|
|
878
|
+
payloadHash: receipt.signature.payloadHash,
|
|
879
|
+
operationId: receipt.payload.binding.operationId,
|
|
880
|
+
});
|
|
881
|
+
let decision;
|
|
882
|
+
try {
|
|
883
|
+
decision = consumeFn(claim);
|
|
884
|
+
}
|
|
885
|
+
catch (e) {
|
|
886
|
+
return blocked('consume_rejected', `consume threw: ${errorMessage(e)}`);
|
|
887
|
+
}
|
|
888
|
+
if (decision !== true) {
|
|
889
|
+
// A thenable (Promise or foreign) is never awaited and never authorizes;
|
|
890
|
+
// sink its eventual rejection so blocking does not leak an unhandled one.
|
|
891
|
+
const thenable = sinkThenable(decision);
|
|
892
|
+
return blocked('consume_rejected', `consume did not return the literal true (got ${thenable ? 'a thenable' : describe(decision)})`);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
// ----- Step 6a: second clock sample -----------------------------------------
|
|
896
|
+
const td = sampleClock(clock);
|
|
897
|
+
if (td === undefined)
|
|
898
|
+
return blocked('invalid_clock', `${INVALID_CLOCK_DETAIL} (td)`);
|
|
899
|
+
const tdProblem = temporalCheck(td, times, 'second');
|
|
900
|
+
if (tdProblem)
|
|
901
|
+
return tdProblem;
|
|
902
|
+
const dispatchedAt = new Date(td).toISOString();
|
|
903
|
+
return Object.freeze({
|
|
904
|
+
outcome: 'prepared',
|
|
905
|
+
snapshot,
|
|
906
|
+
checkedContext,
|
|
907
|
+
receipt,
|
|
908
|
+
observer,
|
|
909
|
+
attemptId,
|
|
910
|
+
td,
|
|
911
|
+
dispatchedAt,
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* The only path that dispatches. Follows spec §5.3 steps 1–7 in order:
|
|
916
|
+
* snapshot once, preflight the observer, validate the receipt against the
|
|
917
|
+
* snapshots, sample the clock, consume (once receipts), re-check the clock and
|
|
918
|
+
* dispatch the frozen snapshot, then sign the observation.
|
|
919
|
+
*
|
|
920
|
+
* Result contract: any failure before dispatch — including an unexpected
|
|
921
|
+
* exception — resolves to a typed blocked result and dispatch is never called.
|
|
922
|
+
* After dispatch the result is always `returned` or an ApprovedExecutionError
|
|
923
|
+
* rejection carrying the original cause; an observation failure of any kind
|
|
924
|
+
* is reported as `observationError` and never changes the settlement.
|
|
925
|
+
*/
|
|
926
|
+
async function executeApproved(params, dispatch) {
|
|
927
|
+
// Captured once, as a local: invoked below as a bare function (`this` is
|
|
928
|
+
// undefined), never as a method of any internal object.
|
|
929
|
+
const dispatchFn = dispatch;
|
|
930
|
+
let prepared;
|
|
931
|
+
try {
|
|
932
|
+
const outcome = prepareDispatch(params, dispatchFn);
|
|
933
|
+
if (outcome.outcome === 'blocked')
|
|
934
|
+
return outcome;
|
|
935
|
+
prepared = outcome;
|
|
936
|
+
}
|
|
937
|
+
catch (e) {
|
|
938
|
+
// Fail closed: nothing has been dispatched, so a typed block is always correct.
|
|
939
|
+
return blocked('malformed_input', `unexpected failure before dispatch: ${errorMessage(e)}`);
|
|
940
|
+
}
|
|
941
|
+
// ----- Step 6b: dispatch immediately, no await between validation and call --
|
|
942
|
+
let settlement;
|
|
943
|
+
try {
|
|
944
|
+
const value = await dispatchFn(prepared.snapshot, prepared.checkedContext);
|
|
945
|
+
settlement = { outcome: 'returned', value };
|
|
946
|
+
}
|
|
947
|
+
catch (cause) {
|
|
948
|
+
settlement = { outcome: 'threw', cause };
|
|
949
|
+
}
|
|
950
|
+
// ----- Step 7: observation (never alters the settlement) --------------------
|
|
951
|
+
let observation;
|
|
952
|
+
let observationError;
|
|
953
|
+
if (prepared.observer !== undefined) {
|
|
954
|
+
try {
|
|
955
|
+
const { receipt, checkedContext, observer } = prepared;
|
|
956
|
+
const payload = {
|
|
957
|
+
v: 1,
|
|
958
|
+
kind: 'bolyra.execution',
|
|
959
|
+
issuedAt: Math.floor(prepared.td / 1000),
|
|
960
|
+
issuer: observer.issuer,
|
|
961
|
+
keyId: observer.keyId,
|
|
962
|
+
execution: {
|
|
963
|
+
scheme: 'beo1',
|
|
964
|
+
approvalReceiptHash: (0, chain_1.computeReceiptHash)(receipt),
|
|
965
|
+
approvalReceiptId: receipt.id,
|
|
966
|
+
operationId: checkedContext.operationId,
|
|
967
|
+
attemptId: prepared.attemptId,
|
|
968
|
+
requester: checkedContext.requester,
|
|
969
|
+
audience: checkedContext.audience,
|
|
970
|
+
tool: checkedContext.tool,
|
|
971
|
+
actionDigest: digestCanonical((0, canonical_1.canonicalize)(prepared.snapshot)),
|
|
972
|
+
dispatchedAt: prepared.dispatchedAt,
|
|
973
|
+
outcome: settlement.outcome,
|
|
974
|
+
},
|
|
975
|
+
};
|
|
976
|
+
observation = (0, sign_1.signReceipt)(payload, observer);
|
|
977
|
+
}
|
|
978
|
+
catch (e) {
|
|
979
|
+
observationError = toError(e);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (settlement.outcome === 'returned') {
|
|
983
|
+
const result = { outcome: 'returned', value: settlement.value };
|
|
984
|
+
if (observation !== undefined)
|
|
985
|
+
result.observation = observation;
|
|
986
|
+
if (observationError !== undefined)
|
|
987
|
+
result.observationError = observationError;
|
|
988
|
+
return result;
|
|
989
|
+
}
|
|
990
|
+
throw new ApprovedExecutionError(settlement.cause, observation, observationError);
|
|
991
|
+
}
|
|
992
|
+
// ---------------------------------------------------------------------------
|
|
993
|
+
// §5.5 — verifyApprovalExecutionLink
|
|
994
|
+
// ---------------------------------------------------------------------------
|
|
995
|
+
const LINK_CHECK_IDS = ['A1', 'A2', 'A3', 'E1', 'E2', 'L1', 'L2', 'L3', 'L4'];
|
|
996
|
+
/**
|
|
997
|
+
* Offline, pure link verification. Always reports all nine checks; a check
|
|
998
|
+
* whose prerequisite failed is reported FAIL as "not evaluated". Never throws:
|
|
999
|
+
* hostile inputs (cycles, bigint, throwing getters) yield FAIL checks.
|
|
1000
|
+
*/
|
|
1001
|
+
function verifyApprovalExecutionLink(params) {
|
|
1002
|
+
try {
|
|
1003
|
+
return verifyLinkChecked(params);
|
|
1004
|
+
}
|
|
1005
|
+
catch (e) {
|
|
1006
|
+
const detail = `verification aborted: ${errorMessage(e)}`;
|
|
1007
|
+
return {
|
|
1008
|
+
ok: false,
|
|
1009
|
+
checks: LINK_CHECK_IDS.map((id) => ({ id, status: 'FAIL', detail })),
|
|
1010
|
+
statement: exports.LINK_VERIFICATION_STATEMENT,
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
function verifyLinkChecked(params) {
|
|
1015
|
+
const checks = [];
|
|
1016
|
+
const pass = (id, detail) => {
|
|
1017
|
+
checks.push({ id, status: 'PASS', detail });
|
|
1018
|
+
};
|
|
1019
|
+
const failCheck = (id, detail) => {
|
|
1020
|
+
checks.push({ id, status: 'FAIL', detail });
|
|
1021
|
+
};
|
|
1022
|
+
const notEvaluated = (id, dependsOn) => {
|
|
1023
|
+
failCheck(id, `not evaluated: ${dependsOn} failed`);
|
|
1024
|
+
};
|
|
1025
|
+
let expectedApprovalSigner;
|
|
1026
|
+
let expectedExecutionSigner;
|
|
1027
|
+
let approvalClone;
|
|
1028
|
+
let observationClone;
|
|
1029
|
+
let approvalCloneError;
|
|
1030
|
+
let observationCloneError;
|
|
1031
|
+
if (!isObjectLike(params)) {
|
|
1032
|
+
approvalCloneError = observationCloneError = `params must be an object, got ${describe(params)}`;
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
try {
|
|
1036
|
+
expectedApprovalSigner = params.expectedApprovalSigner;
|
|
1037
|
+
expectedExecutionSigner = params.expectedExecutionSigner;
|
|
1038
|
+
approvalClone = structuredClone(params.approval);
|
|
1039
|
+
}
|
|
1040
|
+
catch (e) {
|
|
1041
|
+
approvalCloneError = `approval could not be read or cloned: ${errorMessage(e)}`;
|
|
1042
|
+
}
|
|
1043
|
+
try {
|
|
1044
|
+
observationClone = structuredClone(params.observation);
|
|
1045
|
+
}
|
|
1046
|
+
catch (e) {
|
|
1047
|
+
observationCloneError = `observation could not be read or cloned: ${errorMessage(e)}`;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
// A1
|
|
1051
|
+
let approval;
|
|
1052
|
+
if (approvalCloneError !== undefined) {
|
|
1053
|
+
failCheck('A1', approvalCloneError);
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
const a = validateApprovalEnvelope(approvalClone);
|
|
1057
|
+
if (a.ok) {
|
|
1058
|
+
approval = a.receipt;
|
|
1059
|
+
pass('A1', 'approval receipt: closed schema, kind, scheme, keyId agreement and derived id hold');
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
failCheck('A1', `approval receipt ${a.code}: ${a.detail}`);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
// A2
|
|
1066
|
+
if (!approval) {
|
|
1067
|
+
notEvaluated('A2', 'A1');
|
|
1068
|
+
}
|
|
1069
|
+
else if (typeof expectedApprovalSigner !== 'string' || expectedApprovalSigner.length === 0) {
|
|
1070
|
+
failCheck('A2', 'expectedApprovalSigner must be a non-empty string');
|
|
1071
|
+
}
|
|
1072
|
+
else if (!(0, sign_1.verifyReceipt)(approval)) {
|
|
1073
|
+
failCheck('A2', 'approval signature does not verify');
|
|
1074
|
+
}
|
|
1075
|
+
else if (!(0, sign_1.verifyReceipt)(approval, expectedApprovalSigner)) {
|
|
1076
|
+
failCheck('A2', `approval signer ${approval.signature.signer} is not the expected approval signer`);
|
|
1077
|
+
}
|
|
1078
|
+
else {
|
|
1079
|
+
pass('A2', `approval signature valid; signer ${approval.signature.signer} is the expected approval signer`);
|
|
1080
|
+
}
|
|
1081
|
+
// A3
|
|
1082
|
+
if (!approval) {
|
|
1083
|
+
notEvaluated('A3', 'A1');
|
|
1084
|
+
}
|
|
1085
|
+
else if (approval.payload.approval.decision !== 'approved') {
|
|
1086
|
+
failCheck('A3', `approval decision is "${approval.payload.approval.decision}"`);
|
|
1087
|
+
}
|
|
1088
|
+
else {
|
|
1089
|
+
pass('A3', 'approval decision is "approved"');
|
|
1090
|
+
}
|
|
1091
|
+
// E1
|
|
1092
|
+
let observation;
|
|
1093
|
+
if (observationCloneError !== undefined) {
|
|
1094
|
+
failCheck('E1', observationCloneError);
|
|
1095
|
+
}
|
|
1096
|
+
else {
|
|
1097
|
+
const o = validateExecutionEnvelope(observationClone);
|
|
1098
|
+
if (o.ok) {
|
|
1099
|
+
observation = o.receipt;
|
|
1100
|
+
pass('E1', 'execution observation: closed schema, kind, scheme, keyId agreement and derived id hold');
|
|
1101
|
+
}
|
|
1102
|
+
else {
|
|
1103
|
+
failCheck('E1', `execution observation ${o.code}: ${o.detail}`);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
// E2
|
|
1107
|
+
if (!observation) {
|
|
1108
|
+
notEvaluated('E2', 'E1');
|
|
1109
|
+
}
|
|
1110
|
+
else if (typeof expectedExecutionSigner !== 'string' || expectedExecutionSigner.length === 0) {
|
|
1111
|
+
failCheck('E2', 'expectedExecutionSigner must be a non-empty string');
|
|
1112
|
+
}
|
|
1113
|
+
else if (!(0, sign_1.verifyReceipt)(observation)) {
|
|
1114
|
+
failCheck('E2', 'observation signature does not verify');
|
|
1115
|
+
}
|
|
1116
|
+
else if (!(0, sign_1.verifyReceipt)(observation, expectedExecutionSigner)) {
|
|
1117
|
+
failCheck('E2', `observation signer ${observation.signature.signer} is not the expected execution signer`);
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
pass('E2', `observation signature valid; signer ${observation.signature.signer} is the expected execution signer`);
|
|
1121
|
+
}
|
|
1122
|
+
// L1–L4
|
|
1123
|
+
if (!approval || !observation) {
|
|
1124
|
+
const dep = !approval ? 'A1' : 'E1';
|
|
1125
|
+
notEvaluated('L1', dep);
|
|
1126
|
+
notEvaluated('L2', dep);
|
|
1127
|
+
notEvaluated('L3', dep);
|
|
1128
|
+
notEvaluated('L4', dep);
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
const exec = observation.payload.execution;
|
|
1132
|
+
const binding = approval.payload.binding;
|
|
1133
|
+
const recomputedHash = (0, chain_1.computeReceiptHash)(approval);
|
|
1134
|
+
if (exec.approvalReceiptHash !== recomputedHash) {
|
|
1135
|
+
failCheck('L1', 'approvalReceiptHash does not equal the recomputed computeReceiptHash(approval)');
|
|
1136
|
+
}
|
|
1137
|
+
else if (exec.approvalReceiptId !== approval.id) {
|
|
1138
|
+
failCheck('L1', 'approvalReceiptId does not equal the approval receipt id');
|
|
1139
|
+
}
|
|
1140
|
+
else {
|
|
1141
|
+
pass('L1', 'observation references the approval receipt hash and id');
|
|
1142
|
+
}
|
|
1143
|
+
const mismatched = ['operationId', 'requester', 'audience', 'tool'].filter((m) => exec[m] !== binding[m]);
|
|
1144
|
+
if (mismatched.length > 0) {
|
|
1145
|
+
failCheck('L2', `context differs between approval and observation: ${mismatched.join(', ')}`);
|
|
1146
|
+
}
|
|
1147
|
+
else {
|
|
1148
|
+
pass('L2', 'operationId, requester, audience and tool are equal');
|
|
1149
|
+
}
|
|
1150
|
+
if (exec.actionDigest !== binding.argumentsDigest) {
|
|
1151
|
+
failCheck('L3', 'actionDigest does not equal the approved argumentsDigest');
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
pass('L3', 'actionDigest equals the approved argumentsDigest');
|
|
1155
|
+
}
|
|
1156
|
+
const times = approvalTimes(approval.payload);
|
|
1157
|
+
const dispatchedAtMs = parseRfc3339MsZ(exec.dispatchedAt);
|
|
1158
|
+
if (times.decidedAtMs > dispatchedAtMs) {
|
|
1159
|
+
failCheck('L4', 'dispatchedAt precedes decidedAt');
|
|
1160
|
+
}
|
|
1161
|
+
else if (times.notAfterMs !== undefined && dispatchedAtMs >= times.notAfterMs) {
|
|
1162
|
+
failCheck('L4', 'dispatchedAt is at or after validity.notAfter');
|
|
1163
|
+
}
|
|
1164
|
+
else {
|
|
1165
|
+
pass('L4', 'dispatchedAt is within the approval validity window');
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
return {
|
|
1169
|
+
ok: checks.every((c) => c.status === 'PASS'),
|
|
1170
|
+
checks,
|
|
1171
|
+
statement: exports.LINK_VERIFICATION_STATEMENT,
|
|
1172
|
+
};
|
|
1173
|
+
}
|