@catp-protocol/cli 0.2.1 → 0.2.2
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/dist/adapters/claude-code.d.ts +3 -0
- package/dist/adapters/claude-code.d.ts.map +1 -0
- package/dist/adapters/claude-code.js +36 -0
- package/dist/adapters/claude-code.js.map +1 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +15 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/registry.d.ts +5 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +18 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/audit/logger.d.ts +5 -4
- package/dist/audit/logger.d.ts.map +1 -1
- package/dist/audit/logger.js +6 -6
- package/dist/audit/logger.js.map +1 -1
- package/dist/cli.js +24 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/anchor.js +8 -8
- package/dist/commands/authorization.d.ts +5 -0
- package/dist/commands/authorization.d.ts.map +1 -1
- package/dist/commands/authorization.js +167 -10
- package/dist/commands/authorization.js.map +1 -1
- package/dist/commands/event.d.ts +18 -0
- package/dist/commands/event.d.ts.map +1 -0
- package/dist/commands/event.js +78 -0
- package/dist/commands/event.js.map +1 -0
- package/dist/commands/init.d.ts +6 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +20 -3
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/validate.d.ts +2 -0
- package/dist/commands/validate.d.ts.map +1 -1
- package/dist/commands/validate.js +12 -1
- package/dist/commands/validate.js.map +1 -1
- package/dist/commands/witness.d.ts +8 -0
- package/dist/commands/witness.d.ts.map +1 -1
- package/dist/commands/witness.js +49 -0
- package/dist/commands/witness.js.map +1 -1
- package/dist/enforcement/core.d.ts +11 -0
- package/dist/enforcement/core.d.ts.map +1 -0
- package/dist/enforcement/core.js +21 -0
- package/dist/enforcement/core.js.map +1 -0
- package/dist/hook/post.d.ts +5 -1
- package/dist/hook/post.d.ts.map +1 -1
- package/dist/hook/post.js +10 -18
- package/dist/hook/post.js.map +1 -1
- package/dist/hook/pre.d.ts +5 -1
- package/dist/hook/pre.d.ts.map +1 -1
- package/dist/hook/pre.js +12 -25
- package/dist/hook/pre.js.map +1 -1
- package/dist/hook/runtime.d.ts +4 -0
- package/dist/hook/runtime.d.ts.map +1 -0
- package/dist/hook/runtime.js +22 -0
- package/dist/hook/runtime.js.map +1 -0
- package/dist/policy/engine.d.ts +3 -2
- package/dist/policy/engine.d.ts.map +1 -1
- package/dist/policy/engine.js +3 -3
- package/dist/policy/engine.js.map +1 -1
- package/dist/policy/types.d.ts +0 -5
- package/dist/policy/types.d.ts.map +1 -1
- package/dist/runtime/types.d.ts +35 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +2 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/validate.d.ts +8 -0
- package/dist/runtime/validate.d.ts.map +1 -0
- package/dist/runtime/validate.js +43 -0
- package/dist/runtime/validate.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code.d.ts","sourceRoot":"","sources":["../../src/adapters/claude-code.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAQpF,eAAO,MAAM,iBAAiB,EAAE,cAQ/B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const claudeCodeAdapter = {
|
|
2
|
+
runtime: "claude-code",
|
|
3
|
+
fromPreToolUse(input) {
|
|
4
|
+
return toToolAction(input, "pre");
|
|
5
|
+
},
|
|
6
|
+
fromPostToolUse(input) {
|
|
7
|
+
return toToolAction(input, "post");
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
function toToolAction(input, phase) {
|
|
11
|
+
if (!isClaudeCodeHookInput(input)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
runtime: claudeCodeAdapter.runtime,
|
|
16
|
+
phase,
|
|
17
|
+
sessionId: input.session_id,
|
|
18
|
+
toolName: input.tool_name,
|
|
19
|
+
toolInput: input.tool_input,
|
|
20
|
+
raw: input,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function isClaudeCodeHookInput(input) {
|
|
24
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const value = input;
|
|
28
|
+
return (typeof value.tool_name === "string" &&
|
|
29
|
+
!!value.tool_name &&
|
|
30
|
+
isRecord(value.tool_input) &&
|
|
31
|
+
(value.session_id === undefined || typeof value.session_id === "string"));
|
|
32
|
+
}
|
|
33
|
+
function isRecord(value) {
|
|
34
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=claude-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../src/adapters/claude-code.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,iBAAiB,GAAmB;IAC/C,OAAO,EAAE,aAAa;IACtB,cAAc,CAAC,KAAc;QAC3B,OAAO,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,eAAe,CAAC,KAAc;QAC5B,OAAO,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;CACF,CAAC;AAEF,SAAS,YAAY,CAAC,KAAc,EAAE,KAAmB;IACvD,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO,EAAE,iBAAiB,CAAC,OAAO;QAClC,KAAK;QACL,SAAS,EAAE,KAAK,CAAC,UAAU;QAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS;QACzB,SAAS,EAAE,KAAK,CAAC,UAAU;QAC3B,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,KAAK,GAAG,KAAgC,CAAC;IAC/C,OAAO,CACL,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QACnC,CAAC,CAAC,KAAK,CAAC,SAAS;QACjB,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;QAC1B,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,CAAC,CACzE,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RuntimeAdapter } from "../runtime/types.js";
|
|
2
|
+
export declare function getRuntimeAdapter(runtime: string): RuntimeAdapter | null;
|
|
3
|
+
export declare function supportedRuntimeAdapters(): string[];
|
|
4
|
+
export declare function formatSupportedRuntimeAdapters(): string;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAExE;AAED,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,CAEnD;AAED,wBAAgB,8BAA8B,IAAI,MAAM,CAKvD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { claudeCodeAdapter } from "./claude-code.js";
|
|
2
|
+
const ADAPTERS = [claudeCodeAdapter];
|
|
3
|
+
export function getRuntimeAdapter(runtime) {
|
|
4
|
+
return ADAPTERS.find((adapter) => adapter.runtime === runtime) ?? null;
|
|
5
|
+
}
|
|
6
|
+
export function supportedRuntimeAdapters() {
|
|
7
|
+
return ADAPTERS.map((adapter) => adapter.runtime);
|
|
8
|
+
}
|
|
9
|
+
export function formatSupportedRuntimeAdapters() {
|
|
10
|
+
return [
|
|
11
|
+
"Supported runtime adapters:",
|
|
12
|
+
...supportedRuntimeAdapters().map((runtime) => `- ${runtime}`),
|
|
13
|
+
].join("\n") + "\n";
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,QAAQ,GAAG,CAAC,iBAAiB,CAAU,CAAC;AAE9C,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,IAAI,IAAI,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,OAAO;QACL,6BAA6B;QAC7B,GAAG,wBAAwB,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC;KAC/D,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RuntimeAdapter, RuntimePhase, ToolAction } from "../runtime/types.js";
|
|
2
|
+
export declare function listRuntimeAdapters(): string[];
|
|
3
|
+
export declare function getRuntimeAdapter(name: string): RuntimeAdapter | null;
|
|
4
|
+
export declare function adaptRuntimePayload(adapterName: string, phase: RuntimePhase, payload: unknown): ToolAction | null;
|
|
5
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/adapters/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAIpF,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAE9C;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAErE;AAED,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,OAAO,GACf,UAAU,GAAG,IAAI,CAQnB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { claudeCodeAdapter } from "./claude-code.js";
|
|
2
|
+
const adapters = [claudeCodeAdapter];
|
|
3
|
+
export function listRuntimeAdapters() {
|
|
4
|
+
return adapters.map((adapter) => adapter.runtime);
|
|
5
|
+
}
|
|
6
|
+
export function getRuntimeAdapter(name) {
|
|
7
|
+
return adapters.find((adapter) => adapter.runtime === name) ?? null;
|
|
8
|
+
}
|
|
9
|
+
export function adaptRuntimePayload(adapterName, phase, payload) {
|
|
10
|
+
const adapter = getRuntimeAdapter(adapterName);
|
|
11
|
+
if (!adapter) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return phase === "post"
|
|
15
|
+
? adapter.fromPostToolUse(payload)
|
|
16
|
+
: adapter.fromPreToolUse(payload);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/adapters/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,QAAQ,GAAqB,CAAC,iBAAiB,CAAC,CAAC;AAEvD,MAAM,UAAU,mBAAmB;IACjC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,WAAmB,EACnB,KAAmB,EACnB,OAAgB;IAEhB,MAAM,OAAO,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,KAAK,MAAM;QACrB,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC;QAClC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/audit/logger.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { AuditEntry, AuthorizationAction
|
|
1
|
+
import type { AuditEntry, AuthorizationAction } from "../policy/types.js";
|
|
2
|
+
import type { ToolAction } from "../runtime/types.js";
|
|
2
3
|
export declare function computeCommitment(tool: string, decision: "allow" | "deny", ts: string, prev?: string, ruleMatched?: string | null, inputSummary?: string): string;
|
|
3
|
-
export declare function summarizeInput(input:
|
|
4
|
+
export declare function summarizeInput(input: ToolAction): string;
|
|
4
5
|
export declare function auditDir(agentId: string): string;
|
|
5
6
|
export declare function getLastCommitment(agentId: string): string;
|
|
6
7
|
export declare function appendAuditEntry(agentId: string, entry: AuditEntry): void;
|
|
7
|
-
export declare function buildEntry(input:
|
|
8
|
-
export declare function extractAuthorizationAction(input:
|
|
8
|
+
export declare function buildEntry(input: ToolAction, decision: "allow" | "deny", ruleMatched: string | null, prevCommitment?: string): AuditEntry;
|
|
9
|
+
export declare function extractAuthorizationAction(input: ToolAction): AuthorizationAction | undefined;
|
|
9
10
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/audit/logger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/audit/logger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMtD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,MAAY,EAClB,WAAW,GAAE,MAAM,GAAG,IAAW,EACjC,YAAY,GAAE,MAAW,GACxB,MAAM,CAIR;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAGxD;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAYzD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAIzE;AAED,wBAAgB,UAAU,CACxB,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,cAAc,GAAE,MAAY,GAC3B,UAAU,CAgBZ;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,GAAG,mBAAmB,GAAG,SAAS,CAsB7F"}
|
package/dist/audit/logger.js
CHANGED
|
@@ -2,17 +2,17 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { auditDirForDate } from "./paths.js";
|
|
5
|
-
// Phase 0: SHA-256 commitment
|
|
5
|
+
// Phase 0: SHA-256 audit commitment.
|
|
6
6
|
// Chains on fields stored in the log (tool, decision, ts, prev) so the chain
|
|
7
7
|
// is verifiable from the JSONL file alone without replaying tool_input.
|
|
8
|
-
//
|
|
8
|
+
// A future proof bridge can add Poseidon commitments over the full action witness.
|
|
9
9
|
export function computeCommitment(tool, decision, ts, prev = "0", ruleMatched = null, inputSummary = "") {
|
|
10
10
|
return createHash("sha256")
|
|
11
11
|
.update(JSON.stringify({ tool, decision, ts, ruleMatched, inputSummary, prev }))
|
|
12
12
|
.digest("hex");
|
|
13
13
|
}
|
|
14
14
|
export function summarizeInput(input) {
|
|
15
|
-
const raw = JSON.stringify(input.
|
|
15
|
+
const raw = JSON.stringify(input.toolInput);
|
|
16
16
|
return raw.length > 200 ? raw.slice(0, 200) + "…" : raw;
|
|
17
17
|
}
|
|
18
18
|
export function auditDir(agentId) {
|
|
@@ -44,10 +44,10 @@ export function buildEntry(input, decision, ruleMatched, prevCommitment = "0") {
|
|
|
44
44
|
const inputSummary = summarizeInput(input);
|
|
45
45
|
const entry = {
|
|
46
46
|
ts,
|
|
47
|
-
tool: input.
|
|
47
|
+
tool: input.toolName,
|
|
48
48
|
decision,
|
|
49
49
|
rule_matched: ruleMatched,
|
|
50
|
-
commitment: computeCommitment(input.
|
|
50
|
+
commitment: computeCommitment(input.toolName, decision, ts, prevCommitment, ruleMatched, inputSummary),
|
|
51
51
|
input_summary: inputSummary,
|
|
52
52
|
};
|
|
53
53
|
const authorization = extractAuthorizationAction(input);
|
|
@@ -57,7 +57,7 @@ export function buildEntry(input, decision, ruleMatched, prevCommitment = "0") {
|
|
|
57
57
|
return entry;
|
|
58
58
|
}
|
|
59
59
|
export function extractAuthorizationAction(input) {
|
|
60
|
-
const candidate = input.
|
|
60
|
+
const candidate = input.toolInput.catp_authorization ?? input.toolInput.authorization;
|
|
61
61
|
if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
62
62
|
return undefined;
|
|
63
63
|
}
|
package/dist/audit/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/audit/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/audit/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7C,qCAAqC;AACrC,6EAA6E;AAC7E,wEAAwE;AACxE,mFAAmF;AACnF,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,QAA0B,EAC1B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CAAC;IACtF,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5E,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,SAAoC,CAAC;IACnD,IACE,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC;QACnC,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ;QAClC,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC/B,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,EAC9B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjG,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/F,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAChE,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { runPreHook } from "./hook/pre.js";
|
|
5
5
|
import { runPostHook } from "./hook/post.js";
|
|
6
|
+
import { formatSupportedRuntimeAdapters, getRuntimeAdapter, supportedRuntimeAdapters } from "./adapters/index.js";
|
|
6
7
|
import { cmdInit } from "./commands/init.js";
|
|
7
8
|
import { cmdValidate } from "./commands/validate.js";
|
|
8
9
|
import { cmdLogShow, cmdLogVerify } from "./commands/log.js";
|
|
@@ -19,6 +20,7 @@ program
|
|
|
19
20
|
program
|
|
20
21
|
.command("init")
|
|
21
22
|
.description("Scaffold a catp-policy.toml in the current directory")
|
|
23
|
+
.option("--authorization", "include example authorization_groth16_v1 policy fields")
|
|
22
24
|
.action(cmdInit);
|
|
23
25
|
program
|
|
24
26
|
.command("validate")
|
|
@@ -26,14 +28,34 @@ program
|
|
|
26
28
|
.option("-f, --file <path>", "path to policy file (default: auto-discover)")
|
|
27
29
|
.action(cmdValidate);
|
|
28
30
|
const hook = program.command("hook").description("Hook handlers called by agent frameworks");
|
|
31
|
+
function resolveHookAdapter(runtime) {
|
|
32
|
+
const adapter = getRuntimeAdapter(runtime);
|
|
33
|
+
if (!adapter) {
|
|
34
|
+
process.stderr.write(`catp: unsupported runtime adapter "${runtime}". Supported: ${supportedRuntimeAdapters().join(", ")}\n`);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
return adapter;
|
|
38
|
+
}
|
|
39
|
+
hook
|
|
40
|
+
.command("runtimes")
|
|
41
|
+
.description("List supported runtime adapter ids")
|
|
42
|
+
.action(() => {
|
|
43
|
+
process.stdout.write(formatSupportedRuntimeAdapters());
|
|
44
|
+
});
|
|
29
45
|
hook
|
|
30
46
|
.command("pre")
|
|
31
47
|
.description("PreToolUse handler — reads stdin JSON, allows or blocks")
|
|
32
|
-
.
|
|
48
|
+
.option("--runtime <id>", "runtime adapter id", "claude-code")
|
|
49
|
+
.action((opts) => {
|
|
50
|
+
runPreHook({ adapter: resolveHookAdapter(opts.runtime) }).catch(() => process.exit(0));
|
|
51
|
+
});
|
|
33
52
|
hook
|
|
34
53
|
.command("post")
|
|
35
54
|
.description("PostToolUse handler — reads stdin JSON, records to audit log")
|
|
36
|
-
.
|
|
55
|
+
.option("--runtime <id>", "runtime adapter id", "claude-code")
|
|
56
|
+
.action((opts) => {
|
|
57
|
+
runPostHook({ adapter: resolveHookAdapter(opts.runtime) }).catch(() => process.exit(0));
|
|
58
|
+
});
|
|
37
59
|
const log = program.command("log").description("Audit log commands");
|
|
38
60
|
log
|
|
39
61
|
.command("show")
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE5F,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAEtE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,MAAM,CAAC;KACZ,WAAW,CAAC,sEAAsE,CAAC;KACnF,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KAC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ChG,MAAM,CAAC,sBAAsB,EAAE,gDAAgD,CAAC;KAChF,MAAM,CAAC,8BAA8B,EAAE,yBAAyB,CAAC;KACjE,MAAM,CAAC,iBAAiB,EAAE,sCAAsC,CAAC;KACjE,MAAM,CAAC,mBAAmB,EAAE,uDAAuD,CAAC;KACpF,MAAM,CAAC,cAAc,EAAE,qDAAqD,CAAC;KAC7E,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEjC,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,6BAA6B,CAAC,CAAC;AAEpF,MAAM;KACH,OAAO,CAAC,eAAe,CAAC;KACxB,WAAW,CAAC,0CAA0C,CAAC;KACvD,cAAc,CAAC,mBAAmB,EAAE,mCAAmC,CAAC;KACxE,MAAM,CAAC,eAAe,EAAE,0DAA0D,CAAC;KACnF,MAAM,CAAC,oBAAoB,EAAE,mCAAmC,CAAC;KACjE,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAElC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IAC7C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAU,GAAa,CAAC,OAAO,IAAI,CAAC,CAAC;IAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/commands/anchor.js
CHANGED
|
@@ -54,21 +54,21 @@ export function merkleRoot(commitments) {
|
|
|
54
54
|
if (commitments.length === 0) {
|
|
55
55
|
return `0x${"00".repeat(32)}`;
|
|
56
56
|
}
|
|
57
|
-
let
|
|
57
|
+
let level = commitments.map((c) => {
|
|
58
58
|
const b = Buffer.from(c, "hex");
|
|
59
59
|
return b.length === 32 ? b : createHash("sha256").update(c).digest();
|
|
60
60
|
});
|
|
61
|
-
while (
|
|
62
|
-
if (
|
|
63
|
-
|
|
61
|
+
while (level.length > 1) {
|
|
62
|
+
if (level.length % 2 !== 0) {
|
|
63
|
+
level.push(level[level.length - 1]);
|
|
64
64
|
}
|
|
65
65
|
const next = [];
|
|
66
|
-
for (let i = 0; i <
|
|
67
|
-
next.push(createHash("sha256").update(
|
|
66
|
+
for (let i = 0; i < level.length; i += 2) {
|
|
67
|
+
next.push(createHash("sha256").update(level[i]).update(level[i + 1]).digest());
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
level = next;
|
|
70
70
|
}
|
|
71
|
-
return `0x${
|
|
71
|
+
return `0x${level[0].toString("hex")}`;
|
|
72
72
|
}
|
|
73
73
|
async function submitOnChain(root, rpcUrl, privateKey, contractAddress) {
|
|
74
74
|
const { createPublicClient, createWalletClient, http, defineChain } = await import("viem");
|
|
@@ -65,4 +65,9 @@ export declare function cmdVerifyAuthorization(opts: {
|
|
|
65
65
|
checkAudit?: boolean;
|
|
66
66
|
auditAgent?: string;
|
|
67
67
|
}): void;
|
|
68
|
+
export declare function formatAuthorizationManifestSummary(manifest: AuthorizationProofManifest, opts?: {
|
|
69
|
+
extraLines?: string[];
|
|
70
|
+
includeStatus?: boolean;
|
|
71
|
+
manifestPath?: string;
|
|
72
|
+
}): string;
|
|
68
73
|
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src/commands/authorization.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src/commands/authorization.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,KAAK,EAAE,MAAM,GA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M,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GAAG,IAAI,CA4CP;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAeA;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA+BnH;AAED,wBAAgB,kCAAkC,CAChD,QAAQ,EAAE,0BAA0B,EACpC,IAAI,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GACnF,MAAM,CA2BR"}
|
|
@@ -6,6 +6,12 @@ import { buildGroth16WitnessFromSources } from "./witness.js";
|
|
|
6
6
|
import { auditRoot } from "../audit/paths.js";
|
|
7
7
|
import { findPolicyFile, loadPolicy } from "../policy/loader.js";
|
|
8
8
|
const PROOF_VERSION = "authorization_groth16_v1";
|
|
9
|
+
const ACTION_TYPE = {
|
|
10
|
+
swap: "0",
|
|
11
|
+
transfer: "1",
|
|
12
|
+
deposit: "2",
|
|
13
|
+
withdraw: "3",
|
|
14
|
+
};
|
|
9
15
|
export function buildAuthorizationProofManifest(artifact, opts = {}) {
|
|
10
16
|
validateGroth16Artifact(artifact);
|
|
11
17
|
if (opts.auditCommitment !== undefined) {
|
|
@@ -23,6 +29,9 @@ export function buildAuthorizationProofManifest(artifact, opts = {}) {
|
|
|
23
29
|
if (opts.chainId !== undefined && !/^[0-9]+$/.test(opts.chainId)) {
|
|
24
30
|
throw new Error("chainId must be a decimal integer string");
|
|
25
31
|
}
|
|
32
|
+
if (opts.proofUrl !== undefined) {
|
|
33
|
+
assertProofUrl(opts.proofUrl, "proofUrl");
|
|
34
|
+
}
|
|
26
35
|
return {
|
|
27
36
|
manifestVersion: "catp_authorization_proof_manifest_v1",
|
|
28
37
|
proofVersion: PROOF_VERSION,
|
|
@@ -71,6 +80,9 @@ export function validateAuthorizationProofManifest(manifest) {
|
|
|
71
80
|
if (manifest.chainId !== null && !/^[0-9]+$/.test(manifest.chainId)) {
|
|
72
81
|
throw new Error("chainId must be a decimal integer string");
|
|
73
82
|
}
|
|
83
|
+
if (manifest.proofUrl !== null) {
|
|
84
|
+
assertProofUrl(manifest.proofUrl, "proofUrl");
|
|
85
|
+
}
|
|
74
86
|
}
|
|
75
87
|
export function cmdProveAuthorization(opts) {
|
|
76
88
|
if (opts.artifact && opts.action) {
|
|
@@ -104,6 +116,7 @@ export function cmdProveAuthorization(opts) {
|
|
|
104
116
|
if (opts.out) {
|
|
105
117
|
writeFileSync(opts.out, encoded, "utf8");
|
|
106
118
|
process.stdout.write(`Wrote authorization proof manifest to ${opts.out}\n`);
|
|
119
|
+
process.stdout.write(formatAuthorizationManifestSummary(manifest, { includeStatus: false, manifestPath: opts.out }));
|
|
107
120
|
}
|
|
108
121
|
else {
|
|
109
122
|
process.stdout.write(encoded);
|
|
@@ -123,10 +136,14 @@ export function readDeploymentMetadata(path) {
|
|
|
123
136
|
const verifier = optionalString(parsed.groth16AuthorizationVerifier, "deployment.groth16AuthorizationVerifier");
|
|
124
137
|
const agentAuthorizer = optionalString(parsed.agentAuthorizer, "deployment.agentAuthorizer");
|
|
125
138
|
const chainId = optionalIntegerString(parsed.chainId, "deployment.chainId");
|
|
139
|
+
const proofVersion = optionalString(parsed.authorizationProofVersion, "deployment.authorizationProofVersion");
|
|
126
140
|
if (verifier !== undefined)
|
|
127
141
|
assertAddress(verifier, "deployment.groth16AuthorizationVerifier");
|
|
128
142
|
if (agentAuthorizer !== undefined)
|
|
129
143
|
assertAddress(agentAuthorizer, "deployment.agentAuthorizer");
|
|
144
|
+
if (proofVersion !== undefined && proofVersion !== PROOF_VERSION) {
|
|
145
|
+
throw new Error(`deployment.authorizationProofVersion must be ${PROOF_VERSION}`);
|
|
146
|
+
}
|
|
130
147
|
return { verifier, agentAuthorizer, chainId };
|
|
131
148
|
}
|
|
132
149
|
export function cmdVerifyAuthorization(opts) {
|
|
@@ -138,12 +155,7 @@ export function cmdVerifyAuthorization(opts) {
|
|
|
138
155
|
}
|
|
139
156
|
const manifest = JSON.parse(readFileSync(opts.manifest, "utf8"));
|
|
140
157
|
validateAuthorizationProofManifest(manifest);
|
|
141
|
-
const
|
|
142
|
-
"Authorization proof manifest is structurally valid.",
|
|
143
|
-
`proofVersion=${manifest.proofVersion}`,
|
|
144
|
-
`policyCommitment=${manifest.policyCommitment}`,
|
|
145
|
-
`auditCommitment=${manifest.auditCommitment ?? "none"}`,
|
|
146
|
-
];
|
|
158
|
+
const extraLines = [];
|
|
147
159
|
if (opts.checkAudit) {
|
|
148
160
|
const auditAgent = opts.auditAgent ?? manifest.auditAgent;
|
|
149
161
|
if (!manifest.auditCommitment) {
|
|
@@ -152,12 +164,47 @@ export function cmdVerifyAuthorization(opts) {
|
|
|
152
164
|
if (!auditAgent) {
|
|
153
165
|
throw new Error("missing --audit-agent <id>; manifest does not include auditAgent");
|
|
154
166
|
}
|
|
155
|
-
|
|
167
|
+
const entry = findAuditEntry(auditAgent, manifest.auditCommitment);
|
|
168
|
+
if (!entry) {
|
|
156
169
|
throw new Error(`No audit entry found for commitment ${manifest.auditCommitment}`);
|
|
157
170
|
}
|
|
158
|
-
|
|
171
|
+
validateAuditEntryMatchesManifest(entry, manifest);
|
|
172
|
+
extraLines.push(`auditEntry=found:${auditAgent}`);
|
|
173
|
+
extraLines.push("auditAction=matched");
|
|
174
|
+
}
|
|
175
|
+
process.stdout.write(formatAuthorizationManifestSummary(manifest, {
|
|
176
|
+
extraLines,
|
|
177
|
+
includeStatus: true,
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
export function formatAuthorizationManifestSummary(manifest, opts = {}) {
|
|
181
|
+
const lines = [
|
|
182
|
+
...(opts.includeStatus === false ? [] : ["Authorization proof manifest is structurally valid."]),
|
|
183
|
+
`proofVersion=${manifest.proofVersion}`,
|
|
184
|
+
`policyCommitment=${manifest.policyCommitment}`,
|
|
185
|
+
`value=${manifest.value}`,
|
|
186
|
+
`currentTimestamp=${manifest.currentTimestamp}`,
|
|
187
|
+
`cumulativeSpend=${manifest.cumulativeSpend}`,
|
|
188
|
+
`chainId=${manifest.chainId ?? "none"}`,
|
|
189
|
+
`verifier=${manifest.verifier ?? "none"}`,
|
|
190
|
+
`agentAuthorizer=${manifest.agentAuthorizer ?? "none"}`,
|
|
191
|
+
`auditCommitment=${manifest.auditCommitment ?? "none"}`,
|
|
192
|
+
`auditAgent=${manifest.auditAgent ?? "none"}`,
|
|
193
|
+
`sourceArtifact=${manifest.sourceArtifact ?? "none"}`,
|
|
194
|
+
`proofUrl=${manifest.proofUrl ?? "none"}`,
|
|
195
|
+
...(opts.extraLines ?? []),
|
|
196
|
+
"cryptographicVerification=external:EVM-or-offchain-verifier",
|
|
197
|
+
];
|
|
198
|
+
if (manifest.agentAuthorizer) {
|
|
199
|
+
lines.push("next=Use the proof artifact with AgentAuthorizer.executeAuthorized or npm run groth16:execute.");
|
|
159
200
|
}
|
|
160
|
-
|
|
201
|
+
else {
|
|
202
|
+
lines.push("next=Attach deployment metadata to execute this proof on-chain.");
|
|
203
|
+
}
|
|
204
|
+
if (opts.manifestPath) {
|
|
205
|
+
lines.push(`verifyCommand=catp verify authorization --manifest ${opts.manifestPath}${manifest.auditCommitment ? " --check-audit" : ""}`);
|
|
206
|
+
}
|
|
207
|
+
return `${lines.join("\n")}\n`;
|
|
161
208
|
}
|
|
162
209
|
function validateGroth16Artifact(artifact) {
|
|
163
210
|
if (artifact.proofVersion !== PROOF_VERSION) {
|
|
@@ -165,6 +212,9 @@ function validateGroth16Artifact(artifact) {
|
|
|
165
212
|
}
|
|
166
213
|
assertBytes32(artifact.policyCommitment, "policyCommitment");
|
|
167
214
|
assertHex(artifact.actionData, "actionData");
|
|
215
|
+
if (hexByteLength(artifact.actionData) !== 128) {
|
|
216
|
+
throw new Error("actionData must be 128 bytes");
|
|
217
|
+
}
|
|
168
218
|
assertHex(artifact.proof, "proof");
|
|
169
219
|
if (hexByteLength(artifact.proof) !== 256) {
|
|
170
220
|
throw new Error("proof must be 256 bytes");
|
|
@@ -190,6 +240,7 @@ function validateGroth16Artifact(artifact) {
|
|
|
190
240
|
if (normalizeU64(artifact.publicInputs[12], "publicInputs[12]") !== cumulativeSpend) {
|
|
191
241
|
throw new Error("publicInputs[12] must equal cumulativeSpend");
|
|
192
242
|
}
|
|
243
|
+
validateActionDataMatchesPublicInputs(artifact.actionData, artifact.publicInputs);
|
|
193
244
|
}
|
|
194
245
|
function generateGroth16Artifact(opts) {
|
|
195
246
|
if (!opts.action && !opts.auditCommitment) {
|
|
@@ -205,7 +256,10 @@ function generateGroth16Artifact(opts) {
|
|
|
205
256
|
if (!existsSync(proverScript)) {
|
|
206
257
|
if (cleanupDir)
|
|
207
258
|
rmSync(cleanupDir, { recursive: true, force: true });
|
|
208
|
-
throw new Error(`prover script not found: ${proverScript}`
|
|
259
|
+
throw new Error(`prover script not found: ${proverScript}. ` +
|
|
260
|
+
"Full Groth16 proof generation requires a CATP repository checkout; " +
|
|
261
|
+
"the npm CLI package only includes local enforcement, audit logs, witness generation, and manifest tooling. " +
|
|
262
|
+
"Run this command from the repository root or pass --prover-script <path>.");
|
|
209
263
|
}
|
|
210
264
|
const witness = buildGroth16WitnessFromSources({
|
|
211
265
|
action: opts.action,
|
|
@@ -222,6 +276,7 @@ function generateGroth16Artifact(opts) {
|
|
|
222
276
|
witnessPath,
|
|
223
277
|
"--out",
|
|
224
278
|
artifactPath,
|
|
279
|
+
"--proof-only",
|
|
225
280
|
], { stdio: "inherit" });
|
|
226
281
|
return { artifactPath, cleanupDir };
|
|
227
282
|
}
|
|
@@ -258,6 +313,91 @@ function findAuditEntry(agentId, commitment) {
|
|
|
258
313
|
}
|
|
259
314
|
return null;
|
|
260
315
|
}
|
|
316
|
+
function validateAuditEntryMatchesManifest(entry, manifest) {
|
|
317
|
+
if (!entry.authorization) {
|
|
318
|
+
throw new Error(`Audit entry ${entry.commitment} does not contain authorization action data`);
|
|
319
|
+
}
|
|
320
|
+
const expectedActionData = encodeAuthorizationAction(entry.authorization);
|
|
321
|
+
if (expectedActionData.toLowerCase() !== manifest.actionData.toLowerCase()) {
|
|
322
|
+
throw new Error("manifest actionData does not match audit authorization action");
|
|
323
|
+
}
|
|
324
|
+
const auditValue = normalizeU64(entry.authorization.value, "audit.authorization.value");
|
|
325
|
+
if (auditValue !== manifest.value) {
|
|
326
|
+
throw new Error("manifest value does not match audit authorization action");
|
|
327
|
+
}
|
|
328
|
+
if (entry.authorization.currentTimestamp !== undefined) {
|
|
329
|
+
const auditTimestamp = normalizeU64(entry.authorization.currentTimestamp, "audit.authorization.currentTimestamp");
|
|
330
|
+
if (auditTimestamp !== manifest.currentTimestamp) {
|
|
331
|
+
throw new Error("manifest currentTimestamp does not match audit authorization action");
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (entry.authorization.cumulativeSpend !== undefined) {
|
|
335
|
+
const auditSpend = normalizeU64(entry.authorization.cumulativeSpend, "audit.authorization.cumulativeSpend");
|
|
336
|
+
if (auditSpend !== manifest.cumulativeSpend) {
|
|
337
|
+
throw new Error("manifest cumulativeSpend does not match audit authorization action");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function validateActionDataMatchesPublicInputs(actionData, publicInputs) {
|
|
342
|
+
const decoded = decodeActionData(actionData);
|
|
343
|
+
if (decoded.actionType !== normalizeU64(publicInputs[1], "publicInputs[1]")) {
|
|
344
|
+
throw new Error("actionData actionType must equal publicInputs[1]");
|
|
345
|
+
}
|
|
346
|
+
for (const [index, limb] of decoded.protocol.entries()) {
|
|
347
|
+
if (limb !== normalizeU64(publicInputs[2 + index], `publicInputs[${2 + index}]`)) {
|
|
348
|
+
throw new Error(`actionData protocol limb ${index} must equal publicInputs[${2 + index}]`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
for (const [index, limb] of decoded.token.entries()) {
|
|
352
|
+
if (limb !== normalizeU64(publicInputs[6 + index], `publicInputs[${6 + index}]`)) {
|
|
353
|
+
throw new Error(`actionData token limb ${index} must equal publicInputs[${6 + index}]`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (decoded.value !== normalizeU64(publicInputs[10], "publicInputs[10]")) {
|
|
357
|
+
throw new Error("actionData value must equal publicInputs[10]");
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function decodeActionData(actionData) {
|
|
361
|
+
const clean = actionData.slice(2);
|
|
362
|
+
const actionType = BigInt(`0x${clean.slice(0, 64)}`).toString();
|
|
363
|
+
const protocol = decodeLeU64Limbs(clean.slice(64, 128));
|
|
364
|
+
const token = decodeLeU64Limbs(clean.slice(128, 192));
|
|
365
|
+
const value = BigInt(`0x${clean.slice(192, 256)}`).toString();
|
|
366
|
+
return { actionType, protocol, token, value };
|
|
367
|
+
}
|
|
368
|
+
function decodeLeU64Limbs(wordHex) {
|
|
369
|
+
const limbs = [];
|
|
370
|
+
for (let limbIndex = 0; limbIndex < 4; limbIndex += 1) {
|
|
371
|
+
const offset = limbIndex * 16;
|
|
372
|
+
let value = 0n;
|
|
373
|
+
for (let byteIndex = 0; byteIndex < 8; byteIndex += 1) {
|
|
374
|
+
const byteHex = wordHex.slice(offset + byteIndex * 2, offset + byteIndex * 2 + 2);
|
|
375
|
+
value |= BigInt(`0x${byteHex}`) << BigInt(8 * byteIndex);
|
|
376
|
+
}
|
|
377
|
+
limbs.push(value.toString());
|
|
378
|
+
}
|
|
379
|
+
return limbs;
|
|
380
|
+
}
|
|
381
|
+
function encodeAuthorizationAction(action) {
|
|
382
|
+
const actionType = normalizeAuthorizationActionType(action.actionType, "audit.authorization.actionType");
|
|
383
|
+
const value = normalizeU64(action.value, "audit.authorization.value");
|
|
384
|
+
assertBytes32(action.protocol, "audit.authorization.protocol");
|
|
385
|
+
assertBytes32(action.token, "audit.authorization.token");
|
|
386
|
+
return `0x${u256Hex(actionType)}${action.protocol.slice(2)}${action.token.slice(2)}${u256Hex(value)}`;
|
|
387
|
+
}
|
|
388
|
+
function normalizeAuthorizationActionType(value, field) {
|
|
389
|
+
if (typeof value === "string" && ACTION_TYPE[value.toLowerCase()] !== undefined) {
|
|
390
|
+
return ACTION_TYPE[value.toLowerCase()];
|
|
391
|
+
}
|
|
392
|
+
const parsed = normalizeU64(value, field);
|
|
393
|
+
if (!["0", "1", "2", "3"].includes(parsed)) {
|
|
394
|
+
throw new Error(`${field} must be Swap, Transfer, Deposit, Withdraw, or 0..3`);
|
|
395
|
+
}
|
|
396
|
+
return parsed;
|
|
397
|
+
}
|
|
398
|
+
function u256Hex(value) {
|
|
399
|
+
return BigInt(value).toString(16).padStart(64, "0");
|
|
400
|
+
}
|
|
261
401
|
function normalizeIntegerString(value, field) {
|
|
262
402
|
return normalizeU64(value, field);
|
|
263
403
|
}
|
|
@@ -336,6 +476,23 @@ function assertAddress(value, field) {
|
|
|
336
476
|
throw new Error(`${field} must be an EVM address`);
|
|
337
477
|
}
|
|
338
478
|
}
|
|
479
|
+
function assertProofUrl(value, field) {
|
|
480
|
+
let parsed;
|
|
481
|
+
try {
|
|
482
|
+
parsed = new URL(value);
|
|
483
|
+
}
|
|
484
|
+
catch {
|
|
485
|
+
throw new Error(`${field} must be a valid URL`);
|
|
486
|
+
}
|
|
487
|
+
if (parsed.protocol === "https:" || parsed.protocol === "ipfs:" || parsed.protocol === "ar:") {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (parsed.protocol === "http:" &&
|
|
491
|
+
(parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "::1" || parsed.hostname === "[::1]")) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
throw new Error(`${field} must use https, ipfs, ar, or localhost http`);
|
|
495
|
+
}
|
|
339
496
|
function hexByteLength(value) {
|
|
340
497
|
return (value.length - 2) / 2;
|
|
341
498
|
}
|