@originaryx/agent-auditor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/dist/index.js +447 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Originary
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
6
|
+
import { resolve as resolve2 } from "path";
|
|
7
|
+
|
|
8
|
+
// src/commands/inspect.ts
|
|
9
|
+
import {
|
|
10
|
+
detectArtifactKind,
|
|
11
|
+
parseReceipt,
|
|
12
|
+
normalizeBundle,
|
|
13
|
+
buildInspectReceiptOutput,
|
|
14
|
+
buildInspectBundleOutput
|
|
15
|
+
} from "@originaryx/agent-auditor-core";
|
|
16
|
+
|
|
17
|
+
// src/read-bundle.ts
|
|
18
|
+
import { readDisputeBundle } from "@peac/audit";
|
|
19
|
+
async function readBundle(data) {
|
|
20
|
+
const result = await readDisputeBundle(data);
|
|
21
|
+
if (!result.ok) {
|
|
22
|
+
return {
|
|
23
|
+
ok: false,
|
|
24
|
+
code: result.error.code,
|
|
25
|
+
message: result.error.message
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const bundle = result.value;
|
|
29
|
+
const receipts = [];
|
|
30
|
+
if (bundle.receipts instanceof Map) {
|
|
31
|
+
for (const jws of bundle.receipts.values()) {
|
|
32
|
+
receipts.push(jws);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const keys = bundle.keys ?? { keys: [] };
|
|
36
|
+
return {
|
|
37
|
+
ok: true,
|
|
38
|
+
manifest: bundle.manifest,
|
|
39
|
+
receipts,
|
|
40
|
+
keys,
|
|
41
|
+
files: ["manifest.json", "receipts.ndjson", "keys/keys.json"]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/format.ts
|
|
46
|
+
import { EXTENSION_DISPLAY_NAMES } from "@originaryx/agent-auditor-core";
|
|
47
|
+
var DIM = "\x1B[2m";
|
|
48
|
+
var RESET = "\x1B[0m";
|
|
49
|
+
var BOLD = "\x1B[1m";
|
|
50
|
+
var GREEN = "\x1B[32m";
|
|
51
|
+
var RED = "\x1B[31m";
|
|
52
|
+
var YELLOW = "\x1B[33m";
|
|
53
|
+
var CYAN = "\x1B[36m";
|
|
54
|
+
function field(label, value, mono = false) {
|
|
55
|
+
if (value === void 0) return "";
|
|
56
|
+
const formatted = mono ? `${DIM}${value}${RESET}` : value;
|
|
57
|
+
return ` ${DIM}${label.padEnd(16)}${RESET}${formatted}`;
|
|
58
|
+
}
|
|
59
|
+
function formatReceiptSummary(receipt) {
|
|
60
|
+
const s = receipt.claimsSummary;
|
|
61
|
+
const lines = [];
|
|
62
|
+
lines.push(`${BOLD}Receipt Summary${RESET}`);
|
|
63
|
+
lines.push("");
|
|
64
|
+
lines.push(field("Issuer", s.iss));
|
|
65
|
+
lines.push(field("Kind", s.kind));
|
|
66
|
+
lines.push(field("Type", s.type));
|
|
67
|
+
lines.push(field("Receipt ID", s.jti, true));
|
|
68
|
+
if (s.sub) lines.push(field("Subject", s.sub));
|
|
69
|
+
lines.push(field("Wire Version", s.wire_version));
|
|
70
|
+
if (s.issued_at) lines.push(field("Issued At", s.issued_at));
|
|
71
|
+
if (s.occurred_at) lines.push(field("Occurred At", s.occurred_at));
|
|
72
|
+
if (s.pillars && s.pillars.length > 0) {
|
|
73
|
+
lines.push(field("Pillars", s.pillars.join(", ")));
|
|
74
|
+
}
|
|
75
|
+
const extKeys = Object.keys(receipt.extensions);
|
|
76
|
+
if (extKeys.length > 0) {
|
|
77
|
+
lines.push("");
|
|
78
|
+
lines.push(`${BOLD}Extensions${RESET}`);
|
|
79
|
+
for (const key of extKeys) {
|
|
80
|
+
const displayName = EXTENSION_DISPLAY_NAMES[key] ?? `Custom: ${key}`;
|
|
81
|
+
lines.push(` ${CYAN}${displayName}${RESET}`);
|
|
82
|
+
const val = receipt.extensions[key];
|
|
83
|
+
const jsonStr = JSON.stringify(val, null, 2);
|
|
84
|
+
for (const line of jsonStr.split("\n")) {
|
|
85
|
+
lines.push(` ${DIM}${line}${RESET}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (receipt.unknownFields.length > 0) {
|
|
90
|
+
lines.push("");
|
|
91
|
+
lines.push(`${YELLOW}Unknown fields: ${receipt.unknownFields.join(", ")}${RESET}`);
|
|
92
|
+
}
|
|
93
|
+
return lines.filter(Boolean).join("\n");
|
|
94
|
+
}
|
|
95
|
+
function formatBundleSummary(bundle) {
|
|
96
|
+
const s = bundle.bundleSummary;
|
|
97
|
+
const lines = [];
|
|
98
|
+
lines.push(`${BOLD}Bundle Summary${RESET}`);
|
|
99
|
+
lines.push("");
|
|
100
|
+
lines.push(field("Bundle ID", s.bundle_id, true));
|
|
101
|
+
lines.push(field("Kind", s.kind));
|
|
102
|
+
lines.push(field("Created By", s.created_by));
|
|
103
|
+
lines.push(field("Created At", s.created_at));
|
|
104
|
+
lines.push(field("Total Receipts", String(s.total_receipts)));
|
|
105
|
+
lines.push(field("Keys Included", String(s.keys_included)));
|
|
106
|
+
lines.push(field("Policy Included", s.policy_included ? "Yes" : "No"));
|
|
107
|
+
return lines.filter(Boolean).join("\n");
|
|
108
|
+
}
|
|
109
|
+
function formatTimeline(events) {
|
|
110
|
+
if (events.length === 0) return ` ${DIM}No timeline events.${RESET}`;
|
|
111
|
+
const lines = [];
|
|
112
|
+
lines.push(`${BOLD}Timeline${RESET}`);
|
|
113
|
+
lines.push("");
|
|
114
|
+
for (const e of events) {
|
|
115
|
+
const ts = `${DIM}${e.timestamp}${RESET}`;
|
|
116
|
+
lines.push(` ${ts} ${e.label}`);
|
|
117
|
+
if (e.detail) lines.push(` ${"".padEnd(24)}${DIM}${e.detail}${RESET}`);
|
|
118
|
+
}
|
|
119
|
+
return lines.join("\n");
|
|
120
|
+
}
|
|
121
|
+
function formatVerifyResult(result) {
|
|
122
|
+
const lines = [];
|
|
123
|
+
const statusIcon = result.ok ? `${GREEN}VALID${RESET}` : `${RED}INVALID${RESET}`;
|
|
124
|
+
lines.push(`${BOLD}Verification: ${statusIcon}`);
|
|
125
|
+
lines.push("");
|
|
126
|
+
for (const check of result.checks) {
|
|
127
|
+
const icon = check.passed ? `${GREEN}PASS${RESET}` : `${RED}FAIL${RESET}`;
|
|
128
|
+
const msg = check.message ? ` ${DIM}(${check.message})${RESET}` : "";
|
|
129
|
+
lines.push(` ${icon} ${check.name}${msg}`);
|
|
130
|
+
}
|
|
131
|
+
if (result.policyBinding) {
|
|
132
|
+
const pbColor = result.policyBinding === "verified" ? GREEN : result.policyBinding === "failed" ? RED : YELLOW;
|
|
133
|
+
lines.push("");
|
|
134
|
+
lines.push(` ${DIM}Policy binding:${RESET} ${pbColor}${result.policyBinding}${RESET}`);
|
|
135
|
+
}
|
|
136
|
+
if (result.errors.length > 0) {
|
|
137
|
+
lines.push("");
|
|
138
|
+
for (const e of result.errors) {
|
|
139
|
+
lines.push(` ${RED}${e.code}: ${e.message}${RESET}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (result.warnings.length > 0) {
|
|
143
|
+
lines.push("");
|
|
144
|
+
for (const w of result.warnings) {
|
|
145
|
+
const pointer = w.pointer ? ` at ${w.pointer}` : "";
|
|
146
|
+
lines.push(` ${YELLOW}${w.code}: ${w.message}${pointer}${RESET}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return lines.join("\n");
|
|
150
|
+
}
|
|
151
|
+
function formatBundleVerifyResults(results) {
|
|
152
|
+
const lines = [];
|
|
153
|
+
const validCount = results.filter((r) => r.result.ok).length;
|
|
154
|
+
const invalidCount = results.filter((r) => !r.result.ok).length;
|
|
155
|
+
lines.push(`${BOLD}Receipt Signature Verification${RESET}`);
|
|
156
|
+
lines.push(`${DIM} Ed25519 signatures verified against included keys${RESET}`);
|
|
157
|
+
lines.push("");
|
|
158
|
+
lines.push(` ${GREEN}${validCount} signature${validCount !== 1 ? "s" : ""} valid${RESET}${invalidCount > 0 ? ` ${RED}${invalidCount} invalid${RESET}` : ""}`);
|
|
159
|
+
lines.push("");
|
|
160
|
+
for (const r of results) {
|
|
161
|
+
const icon = r.result.ok ? `${GREEN}VALID${RESET}` : `${RED}INVALID${RESET}`;
|
|
162
|
+
lines.push(` ${icon} ${DIM}${r.receiptId}${RESET}`);
|
|
163
|
+
if (!r.result.ok && r.result.errors.length > 0) {
|
|
164
|
+
lines.push(` ${RED}${r.result.errors[0].code}: ${r.result.errors[0].message}${RESET}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return lines.join("\n");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/commands/inspect.ts
|
|
171
|
+
async function inspect(data, filePath, json) {
|
|
172
|
+
const kind = detectArtifactKind(new Uint8Array(data));
|
|
173
|
+
if (kind === "receipt-jws") {
|
|
174
|
+
const jws = data.toString("utf-8").trim();
|
|
175
|
+
const receipt = parseReceipt(jws);
|
|
176
|
+
const output = buildInspectReceiptOutput(receipt);
|
|
177
|
+
if (json) {
|
|
178
|
+
console.log(JSON.stringify(output, null, 2));
|
|
179
|
+
process.exit(0);
|
|
180
|
+
}
|
|
181
|
+
console.log(formatReceiptSummary(receipt));
|
|
182
|
+
console.log("");
|
|
183
|
+
console.log(formatTimeline(receipt.timeline));
|
|
184
|
+
process.exit(0);
|
|
185
|
+
}
|
|
186
|
+
if (kind === "bundle-zip") {
|
|
187
|
+
const readResult = await readBundle(data);
|
|
188
|
+
if (!readResult.ok) {
|
|
189
|
+
console.error(`Error reading bundle: ${readResult.code}: ${readResult.message}`);
|
|
190
|
+
process.exit(2);
|
|
191
|
+
}
|
|
192
|
+
const bundle = normalizeBundle(readResult);
|
|
193
|
+
const output = buildInspectBundleOutput(bundle);
|
|
194
|
+
if (json) {
|
|
195
|
+
console.log(JSON.stringify(output, null, 2));
|
|
196
|
+
process.exit(0);
|
|
197
|
+
}
|
|
198
|
+
console.log(formatBundleSummary(bundle));
|
|
199
|
+
console.log("");
|
|
200
|
+
console.log(formatTimeline(bundle.timeline));
|
|
201
|
+
if (bundle.receipts.length > 0) {
|
|
202
|
+
console.log("");
|
|
203
|
+
console.log("\x1B[1mReceipts\x1B[0m");
|
|
204
|
+
for (const receipt of bundle.receipts) {
|
|
205
|
+
const s = receipt.claimsSummary;
|
|
206
|
+
console.log(` \x1B[2m${s.jti}\x1B[0m ${s.kind}/${s.type} from ${s.iss}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
process.exit(0);
|
|
210
|
+
}
|
|
211
|
+
if (kind === "receipt-json") {
|
|
212
|
+
try {
|
|
213
|
+
const parsed = JSON.parse(data.toString("utf-8"));
|
|
214
|
+
const { parseReceiptJson } = await import("@originaryx/agent-auditor-core");
|
|
215
|
+
const receipt = parseReceiptJson(parsed);
|
|
216
|
+
const output = buildInspectReceiptOutput(receipt);
|
|
217
|
+
if (json) {
|
|
218
|
+
console.log(JSON.stringify(output, null, 2));
|
|
219
|
+
process.exit(0);
|
|
220
|
+
}
|
|
221
|
+
console.log(formatReceiptSummary(receipt));
|
|
222
|
+
console.log("");
|
|
223
|
+
console.log(formatTimeline(receipt.timeline));
|
|
224
|
+
process.exit(0);
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
console.error(`Error: could not detect artifact type for "${filePath}"`);
|
|
229
|
+
console.error("Supported formats: .jws (compact JWS), .json (receipt claims), .zip (dispute bundle)");
|
|
230
|
+
process.exit(2);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/commands/verify.ts
|
|
234
|
+
import { readFileSync } from "fs";
|
|
235
|
+
import { resolve } from "path";
|
|
236
|
+
import {
|
|
237
|
+
detectArtifactKind as detectArtifactKind2,
|
|
238
|
+
parseReceipt as parseReceipt2,
|
|
239
|
+
verifyReceipt,
|
|
240
|
+
verifyBundleReceipts,
|
|
241
|
+
normalizeBundle as normalizeBundle2
|
|
242
|
+
} from "@originaryx/agent-auditor-core";
|
|
243
|
+
async function verify(data, filePath, opts) {
|
|
244
|
+
const kind = detectArtifactKind2(new Uint8Array(data));
|
|
245
|
+
if (kind === "receipt-jws") {
|
|
246
|
+
await verifyReceiptFile(data, opts);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (kind === "bundle-zip") {
|
|
250
|
+
await verifyBundleFile(data, opts);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
console.error(`Error: could not detect artifact type for "${filePath}"`);
|
|
254
|
+
console.error("verify supports .jws (receipt) and .zip (bundle) files");
|
|
255
|
+
process.exit(2);
|
|
256
|
+
}
|
|
257
|
+
async function verifyReceiptFile(data, opts) {
|
|
258
|
+
const jws = data.toString("utf-8").trim();
|
|
259
|
+
const publicKey = resolvePublicKey(opts);
|
|
260
|
+
if (!publicKey) {
|
|
261
|
+
console.error("Error: receipt verification requires a public key");
|
|
262
|
+
console.error(" --key <path> Raw Ed25519 public key file (32 bytes)");
|
|
263
|
+
console.error(" --jwks <path> JWKS file (use --kid to select key)");
|
|
264
|
+
process.exit(2);
|
|
265
|
+
}
|
|
266
|
+
const receipt = parseReceipt2(jws);
|
|
267
|
+
const result = await verifyReceipt(jws, publicKey);
|
|
268
|
+
if (opts.json) {
|
|
269
|
+
const output = {
|
|
270
|
+
ok: result.ok,
|
|
271
|
+
artifact_kind: "receipt-jws",
|
|
272
|
+
status: result.status,
|
|
273
|
+
checks: result.checks,
|
|
274
|
+
claims_summary: result.claimsSummary,
|
|
275
|
+
policy_binding: result.policyBinding,
|
|
276
|
+
warnings: result.warnings,
|
|
277
|
+
errors: result.errors,
|
|
278
|
+
timeline: result.timeline
|
|
279
|
+
};
|
|
280
|
+
console.log(JSON.stringify(output, null, 2));
|
|
281
|
+
process.exit(result.ok ? 0 : 1);
|
|
282
|
+
}
|
|
283
|
+
console.log(formatReceiptSummary(receipt));
|
|
284
|
+
console.log("");
|
|
285
|
+
console.log(formatVerifyResult(result));
|
|
286
|
+
process.exit(result.ok ? 0 : 1);
|
|
287
|
+
}
|
|
288
|
+
async function verifyBundleFile(data, opts) {
|
|
289
|
+
const readResult = await readBundle(data);
|
|
290
|
+
if (!readResult.ok) {
|
|
291
|
+
if (opts.json) {
|
|
292
|
+
const output = {
|
|
293
|
+
ok: false,
|
|
294
|
+
artifact_kind: "bundle-zip",
|
|
295
|
+
status: "error",
|
|
296
|
+
warnings: [],
|
|
297
|
+
errors: [{ code: readResult.code, message: readResult.message }],
|
|
298
|
+
timeline: []
|
|
299
|
+
};
|
|
300
|
+
console.log(JSON.stringify(output, null, 2));
|
|
301
|
+
} else {
|
|
302
|
+
console.error(`Error reading bundle: ${readResult.code}: ${readResult.message}`);
|
|
303
|
+
}
|
|
304
|
+
process.exit(2);
|
|
305
|
+
}
|
|
306
|
+
const bundle = normalizeBundle2(readResult);
|
|
307
|
+
const results = await verifyBundleReceipts(readResult.receipts, readResult.keys);
|
|
308
|
+
const validCount = results.filter((r) => r.result.ok).length;
|
|
309
|
+
const invalidCount = results.filter((r) => !r.result.ok).length;
|
|
310
|
+
if (opts.json) {
|
|
311
|
+
const output = {
|
|
312
|
+
ok: invalidCount === 0,
|
|
313
|
+
artifact_kind: "bundle-zip",
|
|
314
|
+
status: invalidCount === 0 ? "valid" : "invalid",
|
|
315
|
+
bundle_summary: {
|
|
316
|
+
bundle_id: bundle.bundleSummary.bundle_id,
|
|
317
|
+
kind: bundle.bundleSummary.kind,
|
|
318
|
+
content_hash_valid: true,
|
|
319
|
+
total_receipts: results.length,
|
|
320
|
+
valid_receipts: validCount,
|
|
321
|
+
invalid_receipts: invalidCount
|
|
322
|
+
},
|
|
323
|
+
receipts: results.map((r) => ({
|
|
324
|
+
receipt_id: r.receiptId,
|
|
325
|
+
status: r.result.ok ? "valid" : "invalid",
|
|
326
|
+
claims_summary: r.result.claimsSummary ? {
|
|
327
|
+
iss: r.result.claimsSummary.iss,
|
|
328
|
+
kind: r.result.claimsSummary.kind,
|
|
329
|
+
type: r.result.claimsSummary.type,
|
|
330
|
+
jti: r.result.claimsSummary.jti,
|
|
331
|
+
wire_version: r.result.claimsSummary.wire_version
|
|
332
|
+
} : void 0,
|
|
333
|
+
error: !r.result.ok && r.result.errors.length > 0 ? { code: r.result.errors[0].code, message: r.result.errors[0].message } : void 0
|
|
334
|
+
})),
|
|
335
|
+
warnings: results.flatMap((r) => r.result.warnings),
|
|
336
|
+
errors: results.flatMap((r) => r.result.errors),
|
|
337
|
+
timeline: bundle.timeline
|
|
338
|
+
};
|
|
339
|
+
console.log(JSON.stringify(output, null, 2));
|
|
340
|
+
process.exit(invalidCount === 0 ? 0 : 1);
|
|
341
|
+
}
|
|
342
|
+
console.log(formatBundleSummary(bundle));
|
|
343
|
+
console.log("");
|
|
344
|
+
console.log(formatBundleVerifyResults(results));
|
|
345
|
+
process.exit(invalidCount === 0 ? 0 : 1);
|
|
346
|
+
}
|
|
347
|
+
function resolvePublicKey(opts) {
|
|
348
|
+
if (opts.key) {
|
|
349
|
+
const keyPath = resolve(opts.key);
|
|
350
|
+
const keyData = readFileSync(keyPath);
|
|
351
|
+
if (keyData.length === 32) {
|
|
352
|
+
return new Uint8Array(keyData);
|
|
353
|
+
}
|
|
354
|
+
const keyStr = keyData.toString("utf-8").trim();
|
|
355
|
+
if (keyStr.length > 0) {
|
|
356
|
+
return keyStr;
|
|
357
|
+
}
|
|
358
|
+
console.error(`Error: key file must be 32-byte raw Ed25519 or base64url-encoded`);
|
|
359
|
+
process.exit(2);
|
|
360
|
+
}
|
|
361
|
+
if (opts.jwks) {
|
|
362
|
+
const jwksPath = resolve(opts.jwks);
|
|
363
|
+
const jwksData = JSON.parse(readFileSync(jwksPath, "utf-8"));
|
|
364
|
+
const keys = jwksData.keys;
|
|
365
|
+
if (!keys || keys.length === 0) {
|
|
366
|
+
console.error("Error: JWKS file contains no keys");
|
|
367
|
+
process.exit(2);
|
|
368
|
+
}
|
|
369
|
+
let key;
|
|
370
|
+
if (opts.kid) {
|
|
371
|
+
key = keys.find((k) => k.kid === opts.kid);
|
|
372
|
+
if (!key) {
|
|
373
|
+
console.error(`Error: no key found with kid "${opts.kid}" in JWKS`);
|
|
374
|
+
console.error(`Available kids: ${keys.map((k) => k.kid).join(", ")}`);
|
|
375
|
+
process.exit(2);
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
key = keys.find((k) => k.kty === "OKP") ?? keys[0];
|
|
379
|
+
}
|
|
380
|
+
if (!key?.x) {
|
|
381
|
+
console.error('Error: selected key has no "x" (public key) field');
|
|
382
|
+
process.exit(2);
|
|
383
|
+
}
|
|
384
|
+
return key.x;
|
|
385
|
+
}
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/commands/demo.ts
|
|
390
|
+
import { parseReceipt as parseReceipt3, buildInspectReceiptOutput as buildInspectReceiptOutput2 } from "@originaryx/agent-auditor-core";
|
|
391
|
+
var SAMPLE_JWS = "eyJ0eXAiOiJpbnRlcmFjdGlvbi1yZWNvcmQrand0IiwiYWxnIjoiRWREU0EiLCJraWQiOiJzcGlrZS1rZXktMDAxIn0.eyJwZWFjX3ZlcnNpb24iOiIwLjIiLCJraW5kIjoiZXZpZGVuY2UiLCJ0eXBlIjoib3JnLnBlYWNwcm90b2NvbC9jb21tZXJjZSIsImlzcyI6Imh0dHBzOi8vZGVtby5wZWFjcHJvdG9jb2wub3JnIiwiaWF0IjoxNzczMTAyMzM1LCJqdGkiOiIwMTljZDUyMi04NGNlLTdhMzctOGNjOC01NDAyODcxYTZkNWQiLCJzdWIiOiJodHRwczovL2FwcC5leGFtcGxlLmNvbS91c2VyLzQyIiwicGlsbGFycyI6WyJjb21tZXJjZSJdLCJvY2N1cnJlZF9hdCI6IjIwMjYtMDMtMTBUMDA6MjU6MzUuMTgxWiIsImV4dGVuc2lvbnMiOnsib3JnLnBlYWNwcm90b2NvbC9jb21tZXJjZSI6eyJwYXltZW50X3JhaWwiOiJzdHJpcGUiLCJhbW91bnRfbWlub3IiOiIxNTAwIiwiY3VycmVuY3kiOiJVU0QifX19.CMJeGuqGSbvwpc6lv4fvDAxxqDMeQYgzF6DQWDrZYhgTLvWHPgqNmxidZ6Iz6trnMe5oOgptrNnLOtgauzkbAw";
|
|
392
|
+
async function demo(json) {
|
|
393
|
+
const receipt = parseReceipt3(SAMPLE_JWS);
|
|
394
|
+
const output = buildInspectReceiptOutput2(receipt);
|
|
395
|
+
if (json) {
|
|
396
|
+
console.log(JSON.stringify(output, null, 2));
|
|
397
|
+
process.exit(0);
|
|
398
|
+
}
|
|
399
|
+
console.log("");
|
|
400
|
+
console.log("\x1B[1mAgent Auditor Demo\x1B[0m");
|
|
401
|
+
console.log("\x1B[2mShowing a sample Wire 0.2 evidence receipt\x1B[0m");
|
|
402
|
+
console.log("");
|
|
403
|
+
console.log(formatReceiptSummary(receipt));
|
|
404
|
+
console.log("");
|
|
405
|
+
console.log(formatTimeline(receipt.timeline));
|
|
406
|
+
console.log("");
|
|
407
|
+
console.log("\x1B[2mTo inspect your own receipts:\x1B[0m");
|
|
408
|
+
console.log(" agent-auditor inspect ./receipt.jws");
|
|
409
|
+
console.log(" agent-auditor verify ./receipt.jws --key ./public-key.bin");
|
|
410
|
+
console.log(" agent-auditor verify ./bundle.zip");
|
|
411
|
+
console.log("");
|
|
412
|
+
process.exit(0);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// src/index.ts
|
|
416
|
+
var program = new Command();
|
|
417
|
+
program.name("agent-auditor").description("Inspect and verify signed agent receipts and evidence bundles").version("0.1.0");
|
|
418
|
+
program.command("inspect").description("Decode and display receipt or bundle details").argument("<file>", "Receipt (.jws, .json) or bundle (.zip) file").option("--json", "Output as machine-readable JSON (frozen contract)").action(async (file, opts) => {
|
|
419
|
+
try {
|
|
420
|
+
const filePath = resolve2(file);
|
|
421
|
+
const data = readFileSync2(filePath);
|
|
422
|
+
await inspect(data, filePath, opts.json ?? false);
|
|
423
|
+
} catch (err) {
|
|
424
|
+
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
425
|
+
console.error(`Error: file not found: ${file}`);
|
|
426
|
+
process.exit(2);
|
|
427
|
+
}
|
|
428
|
+
throw err;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
program.command("verify").description("Verify receipt with key, or bundle with included keys").argument("<file>", "Receipt (.jws, .json) or bundle (.zip) file").option("--key <path>", "Public key file (raw Ed25519, 32 bytes)").option("--jwks <path>", "JWKS file containing public keys").option("--kid <kid>", "Key ID to select from JWKS (used with --jwks)").option("--json", "Output as machine-readable JSON (frozen contract)").action(async (file, opts) => {
|
|
432
|
+
try {
|
|
433
|
+
const filePath = resolve2(file);
|
|
434
|
+
const data = readFileSync2(filePath);
|
|
435
|
+
await verify(data, filePath, opts);
|
|
436
|
+
} catch (err) {
|
|
437
|
+
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
438
|
+
console.error(`Error: file not found: ${file}`);
|
|
439
|
+
process.exit(2);
|
|
440
|
+
}
|
|
441
|
+
throw err;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
program.command("demo").description("Run inspect on an embedded sample receipt (instant first-use)").option("--json", "Output as machine-readable JSON").action(async (opts) => {
|
|
445
|
+
await demo(opts.json ?? false);
|
|
446
|
+
});
|
|
447
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@originaryx/agent-auditor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Inspect and verify signed agent receipts and evidence bundles",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"bin": {
|
|
10
|
+
"agent-auditor": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@peac/audit": "^0.12.0",
|
|
14
|
+
"commander": "^13.0.0",
|
|
15
|
+
"@originaryx/agent-auditor-core": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^22.0.0",
|
|
19
|
+
"tsup": "^8.0.0",
|
|
20
|
+
"typescript": "^5.7.0",
|
|
21
|
+
"vitest": "^3.0.0"
|
|
22
|
+
},
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/originaryx/agent-auditor.git",
|
|
27
|
+
"directory": "packages/cli"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/originaryx/agent-auditor#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/originaryx/agent-auditor/issues"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"agent",
|
|
35
|
+
"auditor",
|
|
36
|
+
"receipt",
|
|
37
|
+
"verify",
|
|
38
|
+
"inspect",
|
|
39
|
+
"cryptography",
|
|
40
|
+
"ed25519",
|
|
41
|
+
"peac"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest"
|
|
51
|
+
}
|
|
52
|
+
}
|