@oxdeai/conformance 1.0.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/README.md +54 -0
- package/dist/extract-vectors.js +416 -0
- package/dist/scripts/extract-vectors.d.ts +6 -0
- package/dist/scripts/extract-vectors.js +417 -0
- package/dist/scripts/extract-vectors.js.map +1 -0
- package/dist/src/validate.d.ts +1 -0
- package/dist/src/validate.js +394 -0
- package/dist/src/validate.js.map +1 -0
- package/package.json +20 -0
- package/scripts/extract-vectors.ts +460 -0
- package/src/validate.ts +467 -0
- package/tsconfig.json +14 -0
- package/vectors/audit-chain.json +94 -0
- package/vectors/authorization-payload.json +58 -0
- package/vectors/envelope-verification.json +78 -0
- package/vectors/intent-hash.json +87 -0
- package/vectors/snapshot-hash.json +130 -0
package/src/validate.ts
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import {
|
|
5
|
+
encodeCanonicalState,
|
|
6
|
+
encodeEnvelope,
|
|
7
|
+
PolicyEngine,
|
|
8
|
+
sha256HexFromJson,
|
|
9
|
+
verifyEnvelope,
|
|
10
|
+
verifySnapshot
|
|
11
|
+
} from "@oxdeai/core";
|
|
12
|
+
import type { Intent, State, VerificationResult } from "@oxdeai/core";
|
|
13
|
+
|
|
14
|
+
type JsonRecord = Record<string, unknown>;
|
|
15
|
+
|
|
16
|
+
type AuthorizationLike = {
|
|
17
|
+
intent_hash: string;
|
|
18
|
+
state_snapshot_hash: string;
|
|
19
|
+
expires_at: number;
|
|
20
|
+
engine_signature: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type ConformanceAdapter = {
|
|
24
|
+
name: string;
|
|
25
|
+
canonicalJson(value: unknown): string;
|
|
26
|
+
intentHash(intent: Intent): string;
|
|
27
|
+
evaluateAuthorization(intent: Intent): { authorization: AuthorizationLike; policyId: string };
|
|
28
|
+
encodeSnapshot(state: State): { bytes: Uint8Array; policyId: string };
|
|
29
|
+
verifySnapshot(bytes: Uint8Array, expectedPolicyId?: string): VerificationResult;
|
|
30
|
+
verifyEnvelope(bytes: Uint8Array, opts?: { expectedPolicyId?: string; mode?: "strict" | "best-effort" }): VerificationResult;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const CORE_ENGINE_SECRET = "test-secret";
|
|
34
|
+
const CORE_POLICY_ID = "a".repeat(64);
|
|
35
|
+
const INTENT_BINDING_FIELDS = [
|
|
36
|
+
"intent_id",
|
|
37
|
+
"agent_id",
|
|
38
|
+
"action_type",
|
|
39
|
+
"depth",
|
|
40
|
+
"amount",
|
|
41
|
+
"asset",
|
|
42
|
+
"target",
|
|
43
|
+
"timestamp",
|
|
44
|
+
"metadata_hash",
|
|
45
|
+
"nonce",
|
|
46
|
+
"type",
|
|
47
|
+
"authorization_id",
|
|
48
|
+
"tool",
|
|
49
|
+
"tool_call"
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
function makeEngine(): PolicyEngine {
|
|
53
|
+
return new PolicyEngine({
|
|
54
|
+
policy_version: "v1.0.0",
|
|
55
|
+
engine_secret: CORE_ENGINE_SECRET,
|
|
56
|
+
authorization_ttl_seconds: 60,
|
|
57
|
+
policyId: CORE_POLICY_ID
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function makeBaseState(): State {
|
|
62
|
+
return {
|
|
63
|
+
policy_version: "v1.0.0",
|
|
64
|
+
period_id: "period-1",
|
|
65
|
+
kill_switch: { global: false, agents: {} },
|
|
66
|
+
allowlists: {},
|
|
67
|
+
budget: {
|
|
68
|
+
budget_limit: { "agent-1": 5_000_000n },
|
|
69
|
+
spent_in_period: { "agent-1": 0n }
|
|
70
|
+
},
|
|
71
|
+
max_amount_per_action: { "agent-1": 2_000_000n },
|
|
72
|
+
velocity: {
|
|
73
|
+
config: { window_seconds: 60, max_actions: 10 },
|
|
74
|
+
counters: {}
|
|
75
|
+
},
|
|
76
|
+
replay: {
|
|
77
|
+
window_seconds: 300,
|
|
78
|
+
max_nonces_per_agent: 256,
|
|
79
|
+
nonces: {}
|
|
80
|
+
},
|
|
81
|
+
concurrency: {
|
|
82
|
+
max_concurrent: { "agent-1": 3 },
|
|
83
|
+
active: {},
|
|
84
|
+
active_auths: {}
|
|
85
|
+
},
|
|
86
|
+
recursion: {
|
|
87
|
+
max_depth: { "agent-1": 5 }
|
|
88
|
+
},
|
|
89
|
+
tool_limits: {
|
|
90
|
+
window_seconds: 60,
|
|
91
|
+
max_calls: { "agent-1": 50 },
|
|
92
|
+
calls: {}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function asRecord(value: unknown): JsonRecord {
|
|
98
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
99
|
+
throw new Error("expected object");
|
|
100
|
+
}
|
|
101
|
+
return value as JsonRecord;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseIntent(input: unknown): Intent {
|
|
105
|
+
const r = asRecord(input);
|
|
106
|
+
const maybeType = r.type;
|
|
107
|
+
const type = maybeType === "RELEASE" ? "RELEASE" : "EXECUTE";
|
|
108
|
+
|
|
109
|
+
const base = {
|
|
110
|
+
intent_id: String(r.intent_id),
|
|
111
|
+
agent_id: String(r.agent_id),
|
|
112
|
+
action_type: String(r.action_type) as Intent["action_type"],
|
|
113
|
+
amount: BigInt(String(r.amount)),
|
|
114
|
+
asset: r.asset === undefined ? undefined : String(r.asset),
|
|
115
|
+
target: String(r.target),
|
|
116
|
+
timestamp: Number(r.timestamp),
|
|
117
|
+
metadata_hash: String(r.metadata_hash),
|
|
118
|
+
nonce: BigInt(String(r.nonce)),
|
|
119
|
+
signature: String(r.signature),
|
|
120
|
+
depth: r.depth === undefined ? undefined : Number(r.depth),
|
|
121
|
+
tool: r.tool === undefined ? undefined : String(r.tool),
|
|
122
|
+
tool_call: r.tool_call === undefined ? undefined : Boolean(r.tool_call)
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
if (type === "RELEASE") {
|
|
126
|
+
return {
|
|
127
|
+
...base,
|
|
128
|
+
type: "RELEASE",
|
|
129
|
+
authorization_id: String(r.authorization_id)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
...base,
|
|
135
|
+
type: "EXECUTE",
|
|
136
|
+
authorization_id: r.authorization_id === undefined ? undefined : String(r.authorization_id)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function parseState(input: unknown): State {
|
|
141
|
+
const r = asRecord(input);
|
|
142
|
+
const budget = asRecord(r.budget);
|
|
143
|
+
const budget_limit = asRecord(budget.budget_limit);
|
|
144
|
+
const spent_in_period = asRecord(budget.spent_in_period);
|
|
145
|
+
|
|
146
|
+
const max_amount_per_action = asRecord(r.max_amount_per_action);
|
|
147
|
+
|
|
148
|
+
const toBigintRecord = (rec: JsonRecord): Record<string, bigint> => {
|
|
149
|
+
const out: Record<string, bigint> = {};
|
|
150
|
+
for (const [k, v] of Object.entries(rec)) out[k] = BigInt(String(v));
|
|
151
|
+
return out;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const state = makeBaseState();
|
|
155
|
+
state.policy_version = String(r.policy_version);
|
|
156
|
+
state.period_id = String(r.period_id);
|
|
157
|
+
|
|
158
|
+
state.kill_switch = {
|
|
159
|
+
global: Boolean(asRecord(r.kill_switch).global),
|
|
160
|
+
agents: asRecord(asRecord(r.kill_switch).agents) as Record<string, boolean>
|
|
161
|
+
};
|
|
162
|
+
state.allowlists = asRecord(r.allowlists) as State["allowlists"];
|
|
163
|
+
state.budget = {
|
|
164
|
+
budget_limit: toBigintRecord(budget_limit),
|
|
165
|
+
spent_in_period: toBigintRecord(spent_in_period)
|
|
166
|
+
};
|
|
167
|
+
state.max_amount_per_action = toBigintRecord(max_amount_per_action);
|
|
168
|
+
state.velocity = asRecord(r.velocity) as State["velocity"];
|
|
169
|
+
state.replay = asRecord(r.replay) as State["replay"];
|
|
170
|
+
state.concurrency = asRecord(r.concurrency) as State["concurrency"];
|
|
171
|
+
state.recursion = asRecord(r.recursion) as State["recursion"];
|
|
172
|
+
state.tool_limits = asRecord(r.tool_limits) as State["tool_limits"];
|
|
173
|
+
|
|
174
|
+
return state;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function b64ToBytes(value: string): Uint8Array {
|
|
178
|
+
return Uint8Array.from(Buffer.from(value, "base64"));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function hexSha256Utf8(value: string): string {
|
|
182
|
+
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function isPlainObject(v: unknown): v is Record<string, unknown> {
|
|
186
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function canonicalize(value: unknown): unknown {
|
|
190
|
+
if (value === undefined) return null;
|
|
191
|
+
if (typeof value === "bigint") return value.toString();
|
|
192
|
+
if (Array.isArray(value)) return value.map(canonicalize);
|
|
193
|
+
if (isPlainObject(value)) {
|
|
194
|
+
const out: Record<string, unknown> = {};
|
|
195
|
+
for (const k of Object.keys(value).sort()) out[k] = canonicalize(value[k]);
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function canonicalJson(value: unknown): string {
|
|
202
|
+
return JSON.stringify(canonicalize(value));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const coreAdapter: ConformanceAdapter = {
|
|
206
|
+
name: "@oxdeai/core",
|
|
207
|
+
canonicalJson,
|
|
208
|
+
intentHash(intent: Intent): string {
|
|
209
|
+
const src = intent as unknown as Record<string, unknown>;
|
|
210
|
+
const binding: Record<string, unknown> = {};
|
|
211
|
+
for (const key of INTENT_BINDING_FIELDS) {
|
|
212
|
+
const value = src[key];
|
|
213
|
+
if (value !== undefined) binding[key] = value;
|
|
214
|
+
}
|
|
215
|
+
return sha256HexFromJson(binding);
|
|
216
|
+
},
|
|
217
|
+
evaluateAuthorization(intent: Intent) {
|
|
218
|
+
const engine = makeEngine();
|
|
219
|
+
const out = engine.evaluatePure(intent, makeBaseState());
|
|
220
|
+
if (out.decision !== "ALLOW") {
|
|
221
|
+
throw new Error(`expected ALLOW, got DENY: ${out.reasons.join(",")}`);
|
|
222
|
+
}
|
|
223
|
+
return { authorization: out.authorization, policyId: engine.computePolicyId() };
|
|
224
|
+
},
|
|
225
|
+
encodeSnapshot(state: State) {
|
|
226
|
+
const engine = makeEngine();
|
|
227
|
+
const snapshot = engine.exportState(state);
|
|
228
|
+
return { bytes: encodeCanonicalState(snapshot), policyId: engine.computePolicyId() };
|
|
229
|
+
},
|
|
230
|
+
verifySnapshot(bytes: Uint8Array, expectedPolicyId?: string): VerificationResult {
|
|
231
|
+
return verifySnapshot(bytes, expectedPolicyId ? { expectedPolicyId } : undefined);
|
|
232
|
+
},
|
|
233
|
+
verifyEnvelope
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
function loadJson<T>(name: string): T {
|
|
237
|
+
const p = resolve(process.cwd(), "vectors", name);
|
|
238
|
+
return JSON.parse(readFileSync(p, "utf8")) as T;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
type VectorFile = { version: string; vectors: Array<JsonRecord> };
|
|
242
|
+
|
|
243
|
+
type CheckCtx = {
|
|
244
|
+
failures: string[];
|
|
245
|
+
passed: number;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
function pass(ctx: CheckCtx, msg: string): void {
|
|
249
|
+
ctx.passed += 1;
|
|
250
|
+
console.log(`PASS ${msg}`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function fail(ctx: CheckCtx, msg: string): void {
|
|
254
|
+
ctx.failures.push(msg);
|
|
255
|
+
console.error(`FAIL ${msg}`);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function eq(ctx: CheckCtx, label: string, actual: unknown, expected: unknown): void {
|
|
259
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
260
|
+
fail(ctx, `${label}: expected=${JSON.stringify(expected)} actual=${JSON.stringify(actual)}`);
|
|
261
|
+
} else {
|
|
262
|
+
pass(ctx, label);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function validateIntentHashVectors(ctx: CheckCtx, adapter: ConformanceAdapter): void {
|
|
267
|
+
const file = loadJson<VectorFile>("intent-hash.json");
|
|
268
|
+
const vectors = file.vectors;
|
|
269
|
+
const hashes: Record<string, string> = {};
|
|
270
|
+
|
|
271
|
+
for (const v of vectors) {
|
|
272
|
+
const id = String(v.id);
|
|
273
|
+
const intent = parseIntent(v.input);
|
|
274
|
+
const got = adapter.intentHash(intent);
|
|
275
|
+
const want = String(asRecord(v.expected).hash);
|
|
276
|
+
hashes[id] = got;
|
|
277
|
+
eq(ctx, `${id} hash`, got, want);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
eq(ctx, "intent-hash-002 invariant", hashes["intent-hash-002"], hashes["intent-hash-001"]);
|
|
281
|
+
eq(ctx, "intent-hash-003 invariant", hashes["intent-hash-003"], hashes["intent-hash-001"]);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function validateAuthorizationVectors(ctx: CheckCtx, adapter: ConformanceAdapter): void {
|
|
285
|
+
const file = loadJson<VectorFile>("authorization-payload.json");
|
|
286
|
+
|
|
287
|
+
for (const v of file.vectors) {
|
|
288
|
+
const id = String(v.id);
|
|
289
|
+
const intent = parseIntent(v.input);
|
|
290
|
+
const { authorization, policyId } = adapter.evaluateAuthorization(intent);
|
|
291
|
+
const expected = asRecord(v.expected);
|
|
292
|
+
|
|
293
|
+
eq(ctx, `${id} intent_hash`, authorization.intent_hash, String(expected.intent_hash));
|
|
294
|
+
if (expected.state_hash !== undefined) {
|
|
295
|
+
eq(ctx, `${id} state_hash`, authorization.state_snapshot_hash, String(expected.state_hash));
|
|
296
|
+
}
|
|
297
|
+
eq(ctx, `${id} expires_at`, authorization.expires_at, Number(expected.expires_at));
|
|
298
|
+
|
|
299
|
+
const payload = adapter.canonicalJson({
|
|
300
|
+
expires_at: authorization.expires_at,
|
|
301
|
+
intent_hash: authorization.intent_hash,
|
|
302
|
+
policy_id: policyId,
|
|
303
|
+
state_hash: authorization.state_snapshot_hash
|
|
304
|
+
});
|
|
305
|
+
eq(ctx, `${id} canonical_signing_payload`, payload, String(expected.canonical_signing_payload));
|
|
306
|
+
eq(ctx, `${id} signature`, authorization.engine_signature, String(expected.signature));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function validateSnapshotVectors(ctx: CheckCtx, adapter: ConformanceAdapter): void {
|
|
311
|
+
const file = loadJson<VectorFile>("snapshot-hash.json");
|
|
312
|
+
|
|
313
|
+
for (const v of file.vectors) {
|
|
314
|
+
const id = String(v.id);
|
|
315
|
+
const expected = asRecord(v.expected);
|
|
316
|
+
|
|
317
|
+
if (v.input_state !== undefined) {
|
|
318
|
+
const state = parseState(v.input_state);
|
|
319
|
+
const { bytes, policyId } = adapter.encodeSnapshot(state);
|
|
320
|
+
const out = adapter.verifySnapshot(bytes, policyId);
|
|
321
|
+
if (out.status !== "ok" || !out.stateHash) {
|
|
322
|
+
fail(ctx, `${id} verifySnapshot expected ok`);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
eq(ctx, `${id} snapshot_base64`, Buffer.from(bytes).toString("base64"), String(expected.snapshot_base64));
|
|
326
|
+
eq(ctx, `${id} state_hash`, out.stateHash, String(expected.state_hash));
|
|
327
|
+
} else {
|
|
328
|
+
const bytes = b64ToBytes(String(v.input_snapshot_base64));
|
|
329
|
+
const out = adapter.verifySnapshot(bytes, CORE_POLICY_ID);
|
|
330
|
+
if (out.status !== "ok" || !out.stateHash) {
|
|
331
|
+
fail(ctx, `${id} verifySnapshot expected ok`);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
eq(ctx, `${id} state_hash`, out.stateHash, String(expected.state_hash));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function validateAuditChainVectors(ctx: CheckCtx, adapter: ConformanceAdapter): void {
|
|
340
|
+
const file = loadJson<VectorFile>("audit-chain.json");
|
|
341
|
+
const [v1, v2, v3, v4] = file.vectors;
|
|
342
|
+
|
|
343
|
+
const genesis = hexSha256Utf8(String(v1.input));
|
|
344
|
+
eq(ctx, "audit-chain-001 genesis", genesis, String(asRecord(v1.expected).genesis_hex));
|
|
345
|
+
|
|
346
|
+
const i2 = asRecord(v2.input);
|
|
347
|
+
const e0 = i2.event_0;
|
|
348
|
+
const head1 = hexSha256Utf8(`${String(i2.head_0)}\n${adapter.canonicalJson(e0)}`);
|
|
349
|
+
eq(ctx, "audit-chain-002 head_1", head1, String(asRecord(v2.expected).head_1));
|
|
350
|
+
|
|
351
|
+
const i3 = asRecord(v3.input);
|
|
352
|
+
const events = (i3.events as unknown[]) ?? [];
|
|
353
|
+
let head = String(i3.genesis);
|
|
354
|
+
const heads: string[] = [];
|
|
355
|
+
for (const ev of events) {
|
|
356
|
+
head = hexSha256Utf8(`${head}\n${adapter.canonicalJson(ev)}`);
|
|
357
|
+
heads.push(head);
|
|
358
|
+
}
|
|
359
|
+
const e3 = asRecord(v3.expected);
|
|
360
|
+
eq(ctx, "audit-chain-003 head_1", heads[0], String(e3.head_1));
|
|
361
|
+
eq(ctx, "audit-chain-003 head_2", heads[1], String(e3.head_2));
|
|
362
|
+
eq(ctx, "audit-chain-003 head_3", heads[2], String(e3.head_3));
|
|
363
|
+
|
|
364
|
+
const i4 = asRecord(v4.input);
|
|
365
|
+
const mut = i4.mutated_event_0;
|
|
366
|
+
const mutHead1 = hexSha256Utf8(`${String(i4.head_0)}\n${adapter.canonicalJson(mut)}`);
|
|
367
|
+
const e4 = asRecord(v4.expected);
|
|
368
|
+
eq(ctx, "audit-chain-004 original_head_1", String(e4.original_head_1), String(e4.original_head_1));
|
|
369
|
+
eq(ctx, "audit-chain-004 mutated_head_1", mutHead1, String(e4.mutated_head_1));
|
|
370
|
+
eq(ctx, "audit-chain-004 must differ", mutHead1 !== String(e4.original_head_1), true);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function buildEnvelopeCases(adapter: ConformanceAdapter): Array<{ status: string; violations: unknown[]; policyId?: string; stateHash?: string; auditHeadHash?: string }> {
|
|
374
|
+
const engine = makeEngine();
|
|
375
|
+
const state = makeBaseState();
|
|
376
|
+
const intent = parseIntent({
|
|
377
|
+
intent_id: "intent-300",
|
|
378
|
+
agent_id: "agent-1",
|
|
379
|
+
action_type: "PAYMENT",
|
|
380
|
+
amount: "1000000",
|
|
381
|
+
target: "merchant-1",
|
|
382
|
+
timestamp: 1730000000,
|
|
383
|
+
metadata_hash: "0".repeat(64),
|
|
384
|
+
nonce: "300",
|
|
385
|
+
signature: "sig-placeholder",
|
|
386
|
+
depth: 0,
|
|
387
|
+
tool: "openai.responses",
|
|
388
|
+
tool_call: true,
|
|
389
|
+
type: "EXECUTE"
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const out = engine.evaluatePure(intent, state);
|
|
393
|
+
if (out.decision !== "ALLOW") throw new Error("expected ALLOW for envelope cases");
|
|
394
|
+
|
|
395
|
+
const events = engine.audit.snapshot();
|
|
396
|
+
const snapshotBytes = encodeCanonicalState(engine.exportState(state));
|
|
397
|
+
const snap = adapter.verifySnapshot(snapshotBytes, engine.computePolicyId());
|
|
398
|
+
if (snap.status !== "ok" || !snap.stateHash) throw new Error("failed to build envelope cases");
|
|
399
|
+
|
|
400
|
+
const valid = encodeEnvelope({ formatVersion: 1, snapshot: snapshotBytes, events });
|
|
401
|
+
const withCheckpoint = encodeEnvelope({
|
|
402
|
+
formatVersion: 1,
|
|
403
|
+
snapshot: snapshotBytes,
|
|
404
|
+
events: [
|
|
405
|
+
...events,
|
|
406
|
+
{
|
|
407
|
+
type: "STATE_CHECKPOINT",
|
|
408
|
+
stateHash: snap.stateHash,
|
|
409
|
+
timestamp: intent.timestamp,
|
|
410
|
+
policyId: engine.computePolicyId()
|
|
411
|
+
}
|
|
412
|
+
]
|
|
413
|
+
});
|
|
414
|
+
const mismatched = encodeEnvelope({
|
|
415
|
+
formatVersion: 1,
|
|
416
|
+
snapshot: snapshotBytes,
|
|
417
|
+
events: events.map((e) => ({ ...e, policyId: "c".repeat(64) }))
|
|
418
|
+
});
|
|
419
|
+
const corrupt = new Uint8Array([1, 2, 3, 4, 5]);
|
|
420
|
+
|
|
421
|
+
return [
|
|
422
|
+
adapter.verifyEnvelope(withCheckpoint, { expectedPolicyId: engine.computePolicyId(), mode: "strict" }),
|
|
423
|
+
adapter.verifyEnvelope(valid, { expectedPolicyId: engine.computePolicyId(), mode: "best-effort" }),
|
|
424
|
+
adapter.verifyEnvelope(mismatched, { expectedPolicyId: engine.computePolicyId(), mode: "best-effort" }),
|
|
425
|
+
adapter.verifyEnvelope(corrupt, { expectedPolicyId: engine.computePolicyId(), mode: "best-effort" }),
|
|
426
|
+
adapter.verifyEnvelope(valid, { expectedPolicyId: engine.computePolicyId(), mode: "strict" })
|
|
427
|
+
];
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function validateEnvelopeVectors(ctx: CheckCtx, adapter: ConformanceAdapter): void {
|
|
431
|
+
const file = loadJson<VectorFile>("envelope-verification.json");
|
|
432
|
+
const actual = buildEnvelopeCases(adapter);
|
|
433
|
+
|
|
434
|
+
for (let i = 0; i < file.vectors.length; i++) {
|
|
435
|
+
const id = String(file.vectors[i].id);
|
|
436
|
+
const expected = asRecord(file.vectors[i].expected);
|
|
437
|
+
const got = actual[i];
|
|
438
|
+
|
|
439
|
+
eq(ctx, `${id} status`, got.status, String(expected.status));
|
|
440
|
+
if (expected.policyId !== undefined) eq(ctx, `${id} policyId`, got.policyId, String(expected.policyId));
|
|
441
|
+
if (expected.stateHash !== undefined) eq(ctx, `${id} stateHash`, got.stateHash, String(expected.stateHash));
|
|
442
|
+
if (expected.auditHeadHash !== undefined) eq(ctx, `${id} auditHeadHash`, got.auditHeadHash, String(expected.auditHeadHash));
|
|
443
|
+
eq(ctx, `${id} violations`, got.violations, expected.violations ?? []);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function main(): void {
|
|
448
|
+
const ctx: CheckCtx = { failures: [], passed: 0 };
|
|
449
|
+
const adapter = coreAdapter;
|
|
450
|
+
|
|
451
|
+
console.log(`Running conformance validation with ${adapter.name}`);
|
|
452
|
+
|
|
453
|
+
validateIntentHashVectors(ctx, adapter);
|
|
454
|
+
validateAuthorizationVectors(ctx, adapter);
|
|
455
|
+
validateSnapshotVectors(ctx, adapter);
|
|
456
|
+
validateAuditChainVectors(ctx, adapter);
|
|
457
|
+
validateEnvelopeVectors(ctx, adapter);
|
|
458
|
+
|
|
459
|
+
if (ctx.failures.length > 0) {
|
|
460
|
+
console.error(`\nConformance failed: ${ctx.failures.length} assertion(s)`);
|
|
461
|
+
process.exit(1);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
console.log(`\nConformance passed: ${ctx.passed} assertions`);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
main();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src", "scripts"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"hash_algorithm": "SHA256",
|
|
4
|
+
"separator": "0x0A",
|
|
5
|
+
"chain_rule": "head_(k+1) = SHA256(head_k || 0x0A || canonical(event_k))",
|
|
6
|
+
"vectors": [
|
|
7
|
+
{
|
|
8
|
+
"id": "audit-chain-001",
|
|
9
|
+
"input": "OxDeAI::GENESIS::v1",
|
|
10
|
+
"expected": {
|
|
11
|
+
"genesis_hex": "db393af6a9cf189c2b250a0a7dea0c776a3d446c9f51999426f933c53416238b"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "audit-chain-002",
|
|
16
|
+
"input": {
|
|
17
|
+
"head_0": "db393af6a9cf189c2b250a0a7dea0c776a3d446c9f51999426f933c53416238b",
|
|
18
|
+
"event_0": {
|
|
19
|
+
"type": "INTENT_RECEIVED",
|
|
20
|
+
"intent_hash": "d17664c344609e5bd498107bcf12d31bfa289afaa3516b34d96f1d6785a8e0b9",
|
|
21
|
+
"agent_id": "agent-1",
|
|
22
|
+
"timestamp": 1730000000,
|
|
23
|
+
"policyId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
24
|
+
},
|
|
25
|
+
"canonical_event_0": "{\"agent_id\":\"agent-1\",\"intent_hash\":\"d17664c344609e5bd498107bcf12d31bfa289afaa3516b34d96f1d6785a8e0b9\",\"policyId\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"timestamp\":1730000000,\"type\":\"INTENT_RECEIVED\"}"
|
|
26
|
+
},
|
|
27
|
+
"expected": {
|
|
28
|
+
"head_1": "c673c25dd89343acc3475712bdf30e41f1ef0e3a41f7bc8454885646e720ab08"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "audit-chain-003",
|
|
33
|
+
"input": {
|
|
34
|
+
"genesis": "db393af6a9cf189c2b250a0a7dea0c776a3d446c9f51999426f933c53416238b",
|
|
35
|
+
"events": [
|
|
36
|
+
{
|
|
37
|
+
"type": "INTENT_RECEIVED",
|
|
38
|
+
"intent_hash": "d17664c344609e5bd498107bcf12d31bfa289afaa3516b34d96f1d6785a8e0b9",
|
|
39
|
+
"agent_id": "agent-1",
|
|
40
|
+
"timestamp": 1730000000,
|
|
41
|
+
"policyId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"type": "DECISION",
|
|
45
|
+
"intent_hash": "d17664c344609e5bd498107bcf12d31bfa289afaa3516b34d96f1d6785a8e0b9",
|
|
46
|
+
"decision": "ALLOW",
|
|
47
|
+
"reasons": [],
|
|
48
|
+
"policy_version": "v1.0.0",
|
|
49
|
+
"timestamp": 1730000000,
|
|
50
|
+
"policyId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"type": "AUTH_EMITTED",
|
|
54
|
+
"authorization_id": "4f7d785c1bda92e97284cac53d01793135d29bb9af5b20c0bfedebed31efc9f8",
|
|
55
|
+
"intent_hash": "d17664c344609e5bd498107bcf12d31bfa289afaa3516b34d96f1d6785a8e0b9",
|
|
56
|
+
"expires_at": 1730000060,
|
|
57
|
+
"timestamp": 1730000000,
|
|
58
|
+
"policyId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"expected": {
|
|
63
|
+
"head_1": "c673c25dd89343acc3475712bdf30e41f1ef0e3a41f7bc8454885646e720ab08",
|
|
64
|
+
"head_2": "470e52c94946ed14693a379b95d56b477ade9413c53539d48cea4e9b2daaa186",
|
|
65
|
+
"head_3": "b08c083788ecf399e491767c8037f34220cd6db86e47f4de900a21a65f1712c9"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"id": "audit-chain-004",
|
|
70
|
+
"input": {
|
|
71
|
+
"original_event_0": {
|
|
72
|
+
"type": "INTENT_RECEIVED",
|
|
73
|
+
"intent_hash": "d17664c344609e5bd498107bcf12d31bfa289afaa3516b34d96f1d6785a8e0b9",
|
|
74
|
+
"agent_id": "agent-1",
|
|
75
|
+
"timestamp": 1730000000,
|
|
76
|
+
"policyId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
77
|
+
},
|
|
78
|
+
"mutated_event_0": {
|
|
79
|
+
"type": "TAMPERED",
|
|
80
|
+
"intent_hash": "d17664c344609e5bd498107bcf12d31bfa289afaa3516b34d96f1d6785a8e0b9",
|
|
81
|
+
"agent_id": "agent-1",
|
|
82
|
+
"timestamp": 1730000000,
|
|
83
|
+
"policyId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
84
|
+
},
|
|
85
|
+
"head_0": "db393af6a9cf189c2b250a0a7dea0c776a3d446c9f51999426f933c53416238b"
|
|
86
|
+
},
|
|
87
|
+
"expected": {
|
|
88
|
+
"original_head_1": "c673c25dd89343acc3475712bdf30e41f1ef0e3a41f7bc8454885646e720ab08",
|
|
89
|
+
"mutated_head_1": "73f0ee8e9fd465b67096611386b745640cd9e7a89ad2b288bc4a7cc08a70cbaa",
|
|
90
|
+
"must_not_equal_original_head_1": true
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"ttl_seconds": 60,
|
|
4
|
+
"signing_algorithm": "HMAC-SHA256",
|
|
5
|
+
"vectors": [
|
|
6
|
+
{
|
|
7
|
+
"id": "auth-payload-001",
|
|
8
|
+
"input": {
|
|
9
|
+
"intent_id": "intent-100",
|
|
10
|
+
"agent_id": "agent-1",
|
|
11
|
+
"action_type": "PAYMENT",
|
|
12
|
+
"amount": "1000000",
|
|
13
|
+
"target": "merchant-1",
|
|
14
|
+
"timestamp": 1730000000,
|
|
15
|
+
"metadata_hash": "0000000000000000000000000000000000000000000000000000000000000000",
|
|
16
|
+
"nonce": "100",
|
|
17
|
+
"signature": "sig-placeholder",
|
|
18
|
+
"depth": 0,
|
|
19
|
+
"tool": "openai.responses",
|
|
20
|
+
"tool_call": true,
|
|
21
|
+
"type": "EXECUTE"
|
|
22
|
+
},
|
|
23
|
+
"expected": {
|
|
24
|
+
"intent_hash": "c272c586c9c9bd258cc1e794322401f3de021882f255ba16ff921255776066a5",
|
|
25
|
+
"policy_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
26
|
+
"state_hash": "2c8281e90260dae7f4f7bb9906e3049a1d57d141d2c4980b89be1e0c1fbba96f",
|
|
27
|
+
"expires_at": 1730000060,
|
|
28
|
+
"canonical_signing_payload": "{\"expires_at\":1730000060,\"intent_hash\":\"c272c586c9c9bd258cc1e794322401f3de021882f255ba16ff921255776066a5\",\"policy_id\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"state_hash\":\"2c8281e90260dae7f4f7bb9906e3049a1d57d141d2c4980b89be1e0c1fbba96f\"}",
|
|
29
|
+
"signature": "855c55e58a5920dc173dfb9cff4a8254fba4ee65c9fa7d55323535ca386a07e1"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "auth-payload-002",
|
|
34
|
+
"input": {
|
|
35
|
+
"intent_id": "intent-101",
|
|
36
|
+
"agent_id": "agent-1",
|
|
37
|
+
"action_type": "PAYMENT",
|
|
38
|
+
"amount": "1000000",
|
|
39
|
+
"target": "merchant-1",
|
|
40
|
+
"timestamp": 0,
|
|
41
|
+
"metadata_hash": "0000000000000000000000000000000000000000000000000000000000000000",
|
|
42
|
+
"nonce": "101",
|
|
43
|
+
"signature": "sig-placeholder",
|
|
44
|
+
"depth": 0,
|
|
45
|
+
"tool": "openai.responses",
|
|
46
|
+
"tool_call": true,
|
|
47
|
+
"type": "EXECUTE"
|
|
48
|
+
},
|
|
49
|
+
"expected": {
|
|
50
|
+
"intent_hash": "cbe2f7253a1696395cb8353e6995038aa664ac56ac6d1d0e84927b3f5e22ca6e",
|
|
51
|
+
"expires_at": 60,
|
|
52
|
+
"expires_at_derivation": "intent.timestamp(0) + ttl_seconds(60) = 60",
|
|
53
|
+
"canonical_signing_payload": "{\"expires_at\":60,\"intent_hash\":\"cbe2f7253a1696395cb8353e6995038aa664ac56ac6d1d0e84927b3f5e22ca6e\",\"policy_id\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"state_hash\":\"ed859c6eed3ab68576e6a71b087c86cecda8263271ddee98d3684c44f285a6b6\"}",
|
|
54
|
+
"signature": "d27d65e4b24fb276ca03468642700c511f2f9e0f66920c0aa0b6a50feb4c34bb"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|