-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.js
More file actions
1249 lines (1161 loc) · 46.5 KB
/
cli.js
File metadata and controls
1249 lines (1161 loc) · 46.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/**
* @veritasacta/verify — unified verifier CLI (v0.5.4)
*
* Verifies Ed25519 signed receipts, VOPRF anonymous-credential tokens,
* Knowledge Unit bundles, and selective-disclosure receipts — all offline,
* all under one binary with one Sigil commitment.
*
* Architecture is modular: this file is the entry point + dispatcher.
* Cryptographic verification lives in src/engines/*.js. Output formatting
* lives in src/output/*.js.
*
* Usage:
* npx @veritasacta/verify receipt.json
* npx @veritasacta/verify receipt.json --key <hex>
* npx @veritasacta/verify receipt.json --jwks <url>
* npx @veritasacta/verify bundle.json --bundle
* npx @veritasacta/verify ku.json --mode ku
* npx @veritasacta/verify receipt.json --disclose field1,field2:salt:value
* npx @veritasacta/verify receipt.json --require-context sensor:temp<18
* npx @veritasacta/verify --self-check
* npx @veritasacta/verify --self-test
* npx @veritasacta/verify --capabilities
*
* Exit codes:
* 0 = signature valid (proven authentic)
* 1 = signature invalid (proven tampered)
* 2 = verifier error (malformed input, missing key, unsupported algorithm)
*
* References:
* - draft-farley-acta-signed-receipts-03
* - draft-farley-acta-knowledge-units-00
* - AIP-0001, AIP-0002, AIP-0003
* - Provisional patents #1-5
*
* @license Apache-2.0
*/
import { readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { detectFormat } from './src/detect.js';
import { verifyReceipt, verifyBundle } from './src/engines/ed25519-receipt.js';
import { verifyVoprfToken } from './src/engines/voprf-token.js';
import { verifyKnowledgeUnit } from './src/engines/knowledge-unit.js';
import {
verifySelectiveDisclosure,
listRedactedFields,
} from './src/engines/selective-disclosure.js';
import {
verifyCommittedReceipt,
loadDisclosuresFromText,
} from './src/engines/commitment-mode.js';
import { selfCheck, evaluateLiveContext } from './src/engines/sigil.js';
import {
buildCanonicalAttestation,
buildVerificationReceipt,
} from './src/engines/attestation.js';
import { replayChain } from './src/engines/bulk.js';
import { diffReceipts } from './src/engines/diff.js';
import { runInit, buildNextSteps } from './src/engines/init.js';
import { runProxy } from './src/engines/proxy.js';
import { runDaemon } from './src/engines/daemon.js';
import { verifyPrompt } from './src/engines/prompt.js';
import { exploreChain, renderChainTree } from './src/engines/chain-explore.js';
import { exportCompliance, renderComplianceHTML } from './src/engines/compliance-export.js';
import { startDashboard } from './src/engines/dashboard.js';
import { verifyDelegationChain } from './src/engines/delegation.js';
import { verifyCosignatures } from './src/engines/cosign.js';
import { parseContextArgs } from './src/context/live-context.js';
import { detectTier } from './src/conformance.js';
import { resolveFromJwks } from './src/util/jwks.js';
import { appendAuditEntry } from './src/util/audit-log.js';
import { fipsStatus } from './src/util/fips.js';
import { renderHtmlReport } from './src/output/html-report.js';
import { getError, exitCodeFor } from './src/errors.js';
import {
formatReceiptResult,
formatBundleResult,
formatKuResult,
formatSelfCheckResult,
green,
red,
yellow,
dim,
bold,
teal,
renderTerminalSigil,
} from './src/output/terminal.js';
import { formatAsJson } from './src/output/json.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PKG = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf-8'));
const MODE_LABELS = {
'ed25519-receipt-v1': 'Ed25519 receipt v1 (RFC 8032)',
'ed25519-receipt-v2': 'Ed25519 receipt v2 (RFC 8032 + draft-farley-acta-signed-receipts)',
'ed25519-passport': 'Ed25519 Passport envelope (RFC 8032)',
'ed25519-bundle': 'Ed25519 audit bundle',
'voprf-token': 'VOPRF token (RFC 9497)',
'knowledge-unit': 'Knowledge Unit bundle (draft-farley-acta-knowledge-units)',
};
// ──────────────────────────────────────────────────────────────────
// CLI argument parsing
// ──────────────────────────────────────────────────────────────────
function parseArgs() {
const args = process.argv.slice(2);
const opts = {
file: null,
publicKey: null,
jwksUrl: null,
trustAnchor: null,
stdin: false,
mode: 'auto',
bundle: false,
json: false,
help: false,
version: false,
verbose: false,
selfTest: false,
selfCheck: false,
capabilities: false,
allowEmbeddedKey: false,
requireContext: [],
disclose: [],
disclosureFile: null,
tier: null,
strict: false,
noSigil: false,
attest: false,
attestOrg: null,
attestKey: null,
pinSigil: null,
auditLog: null,
replayChain: null,
diff: null,
auditReport: false,
output: null,
emitVerificationReceipt: false,
fips: false,
subcommand: null,
force: false,
proxyTarget: null,
proxyReceiptsDir: null,
daemonSocket: null,
frameworkOverride: null,
};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
const next = () => args[++i];
switch (arg) {
case '--help':
case '-h': opts.help = true; break;
case '--version':
case '-V': opts.version = true; break;
case '--key':
case '-k': opts.publicKey = next(); break;
case '--jwks': opts.jwksUrl = next(); break;
case '--trust-anchor': opts.trustAnchor = next(); break;
case '--stdin': opts.stdin = true; break;
case '--mode': opts.mode = next(); break;
case '--bundle': opts.bundle = true; break;
case '--json': opts.json = true; break;
case '--verbose':
case '-v': opts.verbose = true; break;
case '--self-test': opts.selfTest = true; break;
case '--self-check': opts.selfCheck = true; break;
case '--capabilities': opts.capabilities = true; break;
case '--allow-embedded-key': opts.allowEmbeddedKey = true; break;
case '--require-context': opts.requireContext.push(next()); break;
case '--disclose': opts.disclose.push(next()); break;
case '--disclosure-file': opts.disclosureFile = next(); break;
case '--tier': opts.tier = Number(next()); break;
case '--strict': opts.strict = true; break;
case '--no-sigil': opts.noSigil = true; break;
case '--attest': opts.attest = true; break;
case '--attest-org': opts.attestOrg = next(); break;
case '--attest-key': opts.attestKey = next(); break;
case '--pin-sigil': opts.pinSigil = next(); break;
case '--audit-log': opts.auditLog = next(); break;
case '--replay-chain': opts.replayChain = next(); break;
case '--diff': opts.diff = next(); break;
case '--audit-report': opts.auditReport = true; break;
case '--output': opts.output = next(); break;
case '--emit-verification-receipt': opts.emitVerificationReceipt = true; break;
case '--fips': opts.fips = true; break;
case '--allow-partial-voprf': opts.allowPartialVoprf = true; break;
case '--force': opts.force = true; break;
case '--target': opts.proxyTarget = next(); break;
case '--framework': opts.frameworkOverride = next(); break;
case '--receipts-dir': opts.proxyReceiptsDir = next(); break;
case '--socket': opts.daemonSocket = next(); break;
case '--prompt-receipt': opts.promptReceipt = next(); break;
case '--sigstore-bundle': opts.sigstoreBundle = next(); break;
case '--expected-hash': opts.expectedHash = next(); break;
case '--search-dir': opts.chainSearchDir = next(); break;
case '--max-depth': opts.chainMaxDepth = Number(next()); break;
case '--profile': opts.profile = next(); break;
case '--start-date': opts.startDate = next(); break;
case '--end-date': opts.endDate = next(); break;
case '--org': opts.organization = next(); break;
case '--port': opts.dashboardPort = Number(next()); break;
case '--bind': opts.dashboardBind = next(); break;
case '--bilateral': opts.proxyBilateral = true; break;
case '--server-key': opts.serverKey = next(); break;
case '--scrub-secrets': opts.scrubSecrets = true; break;
case '--trace-id': opts.traceId = next(); break;
case '--group-by-trace': opts.groupByTrace = true; break;
case 'init':
case 'proxy':
case 'daemon':
case 'prompt':
case 'chain':
case 'compliance':
case 'dashboard':
if (!opts.subcommand) opts.subcommand = arg;
else if (!arg.startsWith('-')) opts.file = arg;
break;
case 'explore':
// `verify chain explore <file>` → subcommand stays "chain",
// sub-subcommand captured below
if (opts.subcommand === 'chain') opts.chainVerb = arg;
else if (!arg.startsWith('-')) opts.file = arg;
break;
default:
if (!arg.startsWith('-')) opts.file = arg;
// unknown flags silently ignored (forward-compat)
}
}
return opts;
}
function printHelp() {
console.log(`
${bold('@veritasacta/verify')} ${PKG.version} — unified verifier for signed receipts, VOPRF tokens, and Knowledge Units
${bold('Usage:')}
npx @veritasacta/verify <file.json> Auto-detect format, verify
npx @veritasacta/verify <file.json> --key <hex> Provide verification key
npx @veritasacta/verify <file.json> --jwks <url> Fetch key from JWKS
npx @veritasacta/verify <file.json> --mode receipt|voprf|ku
npx @veritasacta/verify <bundle.json> --bundle Verify audit bundle
cat receipt.json | npx @veritasacta/verify --stdin Read from stdin
npx @veritasacta/verify <file.json> --json Machine-readable output
${bold('Selective disclosure (AIP-0002 legacy):')}
--disclose field:salt:value Reveal a field and verify its commitment
${bold('Commitment-mode disclosure (draft-farley-acta-signed-receipts-01):')}
--disclosure-file <path.json> Verify Merkle inclusion proofs against committed_fields_root
${bold('Live-context verification (Sigil claim 2):')}
--require-context clock:±5s
--require-context geofence:inside:<polygon>
--require-context sensor:temp<18
${bold('Subcommands:')}
init Zero-config onboarding wizard (detects framework, generates keys)
proxy --target "<cmd>" Wrap an MCP server; sign every tools/call transparently
daemon Sidecar daemon: sign receipts over a unix socket (any language)
prompt <path> Verify a prompt/skill/system-instruction file's provenance
[--prompt-receipt <r.json> | --sigstore-bundle <b.json> | --expected-hash <hex>]
chain explore <r.json> Walk a receipt chain to its root; verify every hash link
[--search-dir <dir>] [--max-depth N] [--json]
compliance SOC 2 / ISO 42001 / EU AI Act evidence bundle from a receipt directory
--receipts-dir <dir> [--framework soc2|iso42001|eu-ai-act|all]
[--start-date ISO] [--end-date ISO] [--org "<name>"] [--output audit.html|bundle.json]
dashboard Start local audit dashboard server (loopback only, no telemetry)
[--port 3847] [--bind 127.0.0.1] [--receipts-dir <dir>]
proxy --target "<cmd>" Already-present wrap-and-sign proxy. New flags:
[--bilateral --server-key <file>] Cosign every receipt with a second key
[--scrub-secrets] Redact api_key/token/etc in outgoing args and flag on receipt
[--trace-id <id>] Stamp a workflow trace_id on every receipt
${bold('Options:')}
--key, -k <hex> Ed25519 public key (64 hex chars)
--jwks <url> JWKS endpoint to fetch signing key
--trust-anchor <file> Local trust-anchor JSON with public keys
--mode <m> Force mode: receipt|voprf|ku|auto (default: auto)
--bundle Verify as audit bundle
--stdin Read input from stdin
--json Output JSON
--verbose, -v Detailed verification info
--tier N Require minimum conformance tier (1-5)
--pin-sigil <hex> Require installed Sigil fingerprint to match
--strict Disable all deprecated fallbacks
--fips Enforce FIPS-approved algorithms only
--audit-log <file> Append verification event to a local JSONL audit log
--self-test Verify bundled sample artifacts
--self-check Prove this verifier is the canonical release
--capabilities List supported modes/algorithms/tiers
--allow-embedded-key DEPRECATED. Accept keys embedded in payloads.
Removed in v0.6.0.
--allow-partial-voprf Treat a partial (structural-only) VOPRF result
as valid. Default fails closed (exit 2).
Full DLEQ verification lands in v0.6.0.
--no-sigil Suppress Sigil art in terminal output
--help, -h
--version, -V
${bold('Bulk / replay / diff:')}
--replay-chain <file> Verify every receipt in a JSONL chain file
--diff <other-file> Show structural diff between two receipts
${bold('Attestation and audit:')}
--attest Emit a canonical verifier attestation (signed)
--attest-org <name> Include this org name in the attestation
--attest-key <file> Override attester key location
(default: ~/.veritasacta-verify/attester.json)
--emit-verification-receipt
Emit a signed verification receipt for the subject
--audit-report Render an HTML audit report
--output <file> Write output to a file (HTML reports, attestations)
${bold('Supported formats:')}
v1 artifacts, v2 artifacts, Passport envelopes, audit bundles,
VOPRF tokens, Knowledge Unit bundles, selective-disclosure receipts.
${bold('Exit codes:')}
0 Valid — proven authentic
1 Invalid — proven tampered
2 Undecidable — malformed input, missing key, unsupported algorithm,
or --tier requirement not achieved
${bold('Standards:')}
RFC 8032 (Ed25519), RFC 8785 (JCS), RFC 9497 (VOPRF),
RFC 7517/7638 (JWK / thumbprint),
draft-farley-acta-signed-receipts-03,
draft-farley-acta-knowledge-units-00,
AIP-0001, AIP-0002, AIP-0003.
${bold('Protocol:')} https://veritasacta.com (open, Apache-2.0)
${bold('Managed:')} https://scopeblind.com (optional, commercial)
`);
}
function printCapabilities() {
console.log(JSON.stringify({
package: PKG.name,
version: PKG.version,
modes: Object.keys(MODE_LABELS),
algorithms: ['ed25519', 'EdDSA', 'voprf-p256-sha256'],
unsupported_but_recognized: ['ed25519+ml-dsa-65', 'ed25519+dilithium3'],
tiers: [1, 2, 3, 4],
max_tier_v0_5_0: 4,
features: [
'ed25519-receipt-verification',
'voprf-token-structural-verification',
'knowledge-unit-bundle-verification',
'selective-disclosure-aip-0002',
'sigil-self-check-claim-1',
'sigil-live-context-claim-2',
'conformance-tier-detection',
'embedded-key-rejection',
],
specs: [
'RFC 8032', 'RFC 8785', 'RFC 9497', 'RFC 7517', 'RFC 7638',
'draft-farley-acta-signed-receipts-03',
'draft-farley-acta-knowledge-units-00',
'AIP-0001', 'AIP-0002', 'AIP-0003',
],
wayfinding: {
protocol: 'https://veritasacta.com',
managed: 'https://scopeblind.com',
},
}, null, 2));
}
// ──────────────────────────────────────────────────────────────────
// Self-check: prove this binary is the canonical unmodified release
// ──────────────────────────────────────────────────────────────────
async function runSelfCheck() {
const sigilPath = join(__dirname, 'sigil.json');
let sigil;
try {
sigil = JSON.parse(readFileSync(sigilPath, 'utf-8'));
} catch {
console.log(`\n ${red('✗')} No sigil.json found — this verifier has no Sigil commitment.`);
console.log(` This may be a development build or a fork.\n`);
process.exit(2);
}
// Use the shared monitored file list (keeps runSelfCheck and
// selfCheckResult in sync).
const bufs = [];
for (const f of MONITORED_FILES_FOR_SIGIL) {
try { bufs.push(readFileSync(join(__dirname, f))); } catch { /* missing */ }
}
const installedSourceBytes = Buffer.concat(bufs);
const r = selfCheck({ sigil, installedSourceBytes });
r.projectPublicKey = sigil.project_public_key;
console.log(bold('@veritasacta/verify — self-check'));
console.log(formatSelfCheckResult(r));
process.exit(r.canonical ? 0 : 1);
}
// ──────────────────────────────────────────────────────────────────
// Self-test: verify bundled samples
// ──────────────────────────────────────────────────────────────────
async function runSelfTest(opts) {
const samplesDir = join(__dirname, 'samples');
const testKey = 'd75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a';
let allPassed = true;
console.log(`\n${bold('@veritasacta/verify — self-test')}\n`);
if (!process.env.CI && !process.env.NO_COLOR) {
console.log(renderTerminalSigil(testKey));
console.log('');
}
try {
const receipt = JSON.parse(readFileSync(join(samplesDir, 'sample-receipt.json'), 'utf-8'));
const detected = detectFormat(receipt);
const r = await verifyReceipt(receipt, detected.mode, { publicKey: testKey });
if (r.valid) {
console.log(` ${green('✓')} Sample receipt: ${green('VALID')} (${r.type}, kid: ${r.kid || 'n/a'})`);
} else {
console.log(` ${red('✗')} Sample receipt: ${red('INVALID')} (${r.error})`);
allPassed = false;
}
} catch (e) {
console.log(` ${red('✗')} Sample receipt: ${red(e.message)}`);
allPassed = false;
}
try {
const bundle = JSON.parse(readFileSync(join(samplesDir, 'sample-bundle.json'), 'utf-8'));
const r = await verifyBundle(bundle, { publicKey: testKey });
if (r.valid) {
console.log(` ${green('✓')} Sample bundle: ${green('VALID')} (${r.passed}/${r.total} receipts)`);
} else {
console.log(` ${red('✗')} Sample bundle: ${red('INVALID')} (${r.failed} failed)`);
allPassed = false;
}
} catch (e) {
console.log(` ${red('✗')} Sample bundle: ${red(e.message)}`);
allPassed = false;
}
console.log('');
if (allPassed) {
console.log(` ${green('All self-tests passed.')} The verifier is working correctly.`);
console.log(` ${dim('No ScopeBlind servers were contacted. No accounts required.')}`);
} else {
console.log(` ${red('Some self-tests failed.')} Check the output above.`);
}
console.log('');
process.exit(allPassed ? 0 : 1);
}
// ──────────────────────────────────────────────────────────────────
// Dispatch
// ──────────────────────────────────────────────────────────────────
async function readInput(opts) {
if (opts.stdin) {
const chunks = [];
for await (const chunk of process.stdin) chunks.push(chunk);
return Buffer.concat(chunks).toString('utf-8');
}
if (opts.file) return readFileSync(opts.file, 'utf-8');
return null;
}
async function dispatch(input, opts) {
// Forced-mode overrides
let detected = detectFormat(input);
if (opts.mode && opts.mode !== 'auto') {
const forced = opts.mode.toLowerCase();
if (forced === 'receipt') detected.mode = 'ed25519-passport';
else if (forced === 'voprf') detected.mode = 'voprf-token';
else if (forced === 'ku') detected.mode = 'knowledge-unit';
else if (forced === 'bundle') detected.mode = 'ed25519-bundle';
}
if (opts.bundle) detected.mode = 'ed25519-bundle';
// Resolve JWKS if needed
let publicKey = opts.publicKey;
let keySource = publicKey ? 'provided' : null;
if (!publicKey && opts.jwksUrl) {
const kid = input.kid || input.signature?.kid;
const resolved = await resolveFromJwks(opts.jwksUrl, kid);
if (resolved.key) {
publicKey = resolved.key;
keySource = resolved.source?.resolved ? `jwks:${resolved.source.resolved}` : 'jwks';
} else {
const result = {
valid: false,
error: 'jwks_fetch_failed',
format: detected.mode,
detail: resolved.error,
};
return result;
}
}
const subOpts = { ...opts, publicKey };
// Route to engine
switch (detected.mode) {
case 'ed25519-bundle': {
return await verifyBundle(input, subOpts);
}
case 'knowledge-unit': {
const r = await verifyKnowledgeUnit(input, subOpts);
const tier = detectTier({ mode: 'knowledge-unit', payloadFields: {} });
return { ...r, tier };
}
case 'voprf-token': {
const r = await verifyVoprfToken(input, subOpts);
const tier = detectTier({
mode: 'voprf-token',
payloadFields: {
transport_hint: r.transport_hint,
},
voprfVerified: r.valid,
});
return { ...r, tier, modeLabel: MODE_LABELS['voprf-token'] };
}
case 'ed25519-receipt-v1':
case 'ed25519-receipt-v2':
case 'ed25519-passport': {
const r = await verifyReceipt(input, detected.mode, subOpts);
// Selective disclosure: attach if commitments present.
// Two formats supported:
// - Legacy AIP-0002 (_commitments map + --disclose field:salt:value)
// - draft-farley-acta-signed-receipts-01 commitment-mode
// (committed_fields_root + --disclosure-file path)
let disclosureResult = null;
const hasCommittedFieldsRoot = detected.signals?.includes('committed_fields_root');
const hasLegacyCommitments = detected.signals?.includes('_commitments');
if (hasCommittedFieldsRoot) {
// draft-01 commitment-mode path
let disclosures = [];
if (opts.disclosureFile) {
try {
const fs = await import('node:fs');
const text = fs.readFileSync(opts.disclosureFile, 'utf8');
disclosures = loadDisclosuresFromText(text);
} catch (err) {
r.valid = false;
r.error = `disclosure_file_load_failed: ${err?.message ?? 'unknown'}`;
}
}
if (r.valid !== false) {
disclosureResult = verifyCommittedReceipt(input, disclosures);
r.committedFieldsRoot = input.committed_fields_root;
r.committedFieldNames = input.committed_field_names;
r.disclosedFields = disclosures.map((d) => d.name);
if (!disclosureResult.valid) {
r.valid = false;
r.error = disclosureResult.error || 'commitment_mismatch';
}
}
} else if (hasLegacyCommitments) {
// Legacy AIP-0002 path
const disclosures = parseDisclosures(opts.disclose);
disclosureResult = verifySelectiveDisclosure(input, disclosures);
r.redactedFields = listRedactedFields(input);
r.disclosedFields = disclosures.map((d) => d.field);
if (!disclosureResult.valid) {
r.valid = false;
r.error = 'commitment_mismatch';
}
}
// Live-context predicates
if (opts.requireContext.length > 0) {
const preds = parseContextArgs(opts.requireContext);
const ctx = await evaluateLiveContext(preds);
r.contextChecks = ctx.checks;
if (!ctx.allSatisfied) {
r.valid = false;
r.error = r.error || 'context_requirement_unmet';
}
}
// Surface attestation_mode as dedicated output field
if (r.payloadFields?.attestation_mode) {
r.attestationMode = r.payloadFields.attestation_mode;
}
if (r.payloadFields?.scope) r.scope = r.payloadFields.scope;
if (r.payloadFields?.nullifier) r.nullifier = r.payloadFields.nullifier;
if (r.payloadFields?.transport_hint) r.transport_hint = r.payloadFields.transport_hint;
const tier = detectTier({
mode: detected.mode,
payloadFields: r.payloadFields,
disclosuresVerified: disclosureResult?.disclosuresVerified || 0,
});
r.tier = tier;
r.modeLabel = MODE_LABELS[detected.mode];
r.specVersion = 'draft-farley-acta-signed-receipts-03';
return r;
}
default:
return {
valid: false,
error: 'unknown_format',
format: 'unknown',
detail: `Could not detect format. Signals: ${detected.signals.join(', ') || 'none'}`,
};
}
}
/**
* Parse --disclose arguments into disclosure packages.
* Format: "field.path:salt_hex:json_value" (value is JSON-parsed)
*/
function parseDisclosures(args) {
const packages = [];
for (const a of args) {
const firstColon = a.indexOf(':');
const secondColon = a.indexOf(':', firstColon + 1);
if (firstColon < 0 || secondColon < 0) continue;
const field = a.slice(0, firstColon);
const salt = a.slice(firstColon + 1, secondColon);
const raw = a.slice(secondColon + 1);
let value;
try { value = JSON.parse(raw); } catch { value = raw; }
packages.push({ field, salt, value });
}
return packages;
}
// ──────────────────────────────────────────────────────────────────
// Main
// ──────────────────────────────────────────────────────────────────
function applyTierGate(result, minTier) {
if (!minTier) return result;
const achieved = result.tier?.tier || 1;
if (achieved < minTier) {
return {
...result,
valid: false,
error: 'tier_not_achieved',
detail: `Required tier T${minTier}, achieved T${achieved}`,
};
}
return result;
}
/**
* Load and parse the Sigil commitment from disk.
* Used by attestation and report generators.
*/
function loadSigil() {
try {
return JSON.parse(readFileSync(join(__dirname, 'sigil.json'), 'utf-8'));
} catch {
return null;
}
}
/**
* --pin-sigil: require the installed Sigil fingerprint to match a
* specified value. Fails early if mismatch.
*/
function enforcePinSigil(expected) {
const sigil = loadSigil();
if (!sigil) {
console.error(red('--pin-sigil requires a sigil.json; none found.'));
process.exit(2);
}
if (sigil.fingerprint !== expected) {
console.error(red(`--pin-sigil: mismatch (expected ${expected}, got ${sigil.fingerprint})`));
console.error(yellow(`Installed verifier is "${sigil.name}" (${sigil.fingerprint}); expected fingerprint ${expected}.`));
console.error(dim(`Ensure you have installed the expected release: npm install @veritasacta/verify@<version>`));
process.exit(2);
}
}
/**
* --replay-chain FILE: verify an entire JSONL chain.
*/
async function runReplayChain(opts) {
const sigil = loadSigil();
const result = await replayChain(opts.replayChain, opts);
if (opts.auditReport) {
let attestation = null;
if (opts.attest) {
const r = selfCheckResult(sigil);
attestation = buildCanonicalAttestation({
sigil, canonical: r.canonical, org: opts.attestOrg, keyPath: opts.attestKey,
});
}
const html = renderHtmlReport({ result, sigil, attestation, title: 'Veritas Acta chain-replay audit report' });
if (opts.output) {
writeFileSync(opts.output, html);
console.log(dim(`wrote ${opts.output}`));
} else {
console.log(html);
}
process.exit(result.valid ? 0 : 1);
}
if (opts.json) {
console.log(JSON.stringify(result, null, 2));
} else {
console.log(`\n${bold('Chain replay result')}`);
console.log(` Total: ${result.total}`);
console.log(` Verified: ${green(String(result.verified))}`);
console.log(` Failed: ${result.failed > 0 ? red(String(result.failed)) : '0'}`);
console.log(` Chain breaks: ${result.chainBreaks > 0 ? red(String(result.chainBreaks)) : '0'}`);
if (result.errors.length > 0) {
console.log(`\n ${red('Errors:')}`);
for (const e of result.errors.slice(0, 20)) console.log(` ${red('•')} ${e}`);
if (result.errors.length > 20) console.log(` ${dim(`... ${result.errors.length - 20} more`)}`);
}
console.log('');
}
process.exit(result.valid ? 0 : 1);
}
/**
* --diff A B: show structural differences between two receipts.
*/
async function runDiff(opts) {
const a = JSON.parse(await readInput(opts) || '{}');
const b = JSON.parse(readFileSync(opts.diff, 'utf-8'));
const d = diffReceipts(a, b);
if (opts.json) {
console.log(JSON.stringify(d, null, 2));
} else {
console.log(`\n${bold('Receipt diff')}`);
console.log(` Canonical hash A: ${dim(d.canonical_hash_a)}`);
console.log(` Canonical hash B: ${dim(d.canonical_hash_b)}`);
console.log(` Payload identical: ${d.hash_equal ? green('yes') : red('no')}`);
console.log(` Signature identical: ${d.signature_equal ? green('yes') : red('no')}`);
if (d.added.length > 0) console.log(`\n ${green('Added:')} ${d.added.join(', ')}`);
if (d.removed.length > 0) console.log(` ${red('Removed:')} ${d.removed.join(', ')}`);
if (d.changed.length > 0) {
console.log(` ${yellow('Changed:')}`);
for (const c of d.changed) {
console.log(` ${c.field}: ${dim(JSON.stringify(c.before))} -> ${dim(JSON.stringify(c.after))}`);
}
}
console.log('');
}
process.exit(d.hash_equal && d.signature_equal ? 0 : 1);
}
/**
* verify prompt <file> [--prompt-receipt <r> | --sigstore-bundle <b> | --expected-hash <h>]
*
* Verify the provenance of a prompt / instruction file against one of
* three sources. Closes the CLAUDE.md / SKILLS.md supply-chain gap.
*/
async function runPromptVerify(opts) {
if (!opts.file) {
console.error(red(' verify prompt requires a file path to the prompt'));
console.error(dim(' usage: verify prompt <path> [--prompt-receipt <receipt.json> | --sigstore-bundle <bundle.json> | --expected-hash <hex>]'));
process.exit(2);
}
const result = await verifyPrompt({
promptPath: opts.file,
receiptPath: opts.promptReceipt,
sigstoreBundle: opts.sigstoreBundle,
expectedHash: opts.expectedHash,
});
if (opts.json) {
console.log(JSON.stringify(result, null, 2));
} else {
console.log('');
console.log(`${bold('Prompt verification')}`);
console.log(` File: ${result.prompt_path}`);
console.log(` Hash: ${dim(result.prompt_hash)}`);
if (result.source) console.log(` Source: ${result.source}`);
if (result.expected_hash) {
const eq = result.expected_hash === result.prompt_hash;
console.log(` Expected: ${dim(result.expected_hash)} ${eq ? green('match') : red('MISMATCH')}`);
}
if (result.receipt_summary) {
console.log(` Receipt: ${dim(JSON.stringify(result.receipt_summary))}`);
}
if (result.bundle_summary) {
console.log(` Bundle: ${dim(JSON.stringify(result.bundle_summary))}`);
}
if (result.valid) {
console.log(` ${green('\u2713')} prompt matches the asserted provenance`);
} else {
console.log(` ${red('\u2717')} ${result.error || 'verification failed'}`);
}
console.log('');
}
process.exit(result.valid ? 0 : 1);
}
/**
* verify chain explore <file> [--search-dir <dir>] [--max-depth N]
*
* Walk the causal ancestry of a receipt via previousReceiptHash and
* validate every hash link along the way. Surfaces cryptographic
* causal integrity as a concrete operation.
*/
async function runChainExplore(opts) {
if (opts.chainVerb !== 'explore') {
console.error(red(` unknown chain subcommand: ${opts.chainVerb || '(none)'}`));
console.error(dim(' usage: verify chain explore <receipt.json> [--search-dir <dir>] [--max-depth N]'));
process.exit(2);
}
if (!opts.file) {
console.error(red(' verify chain explore requires a receipt file path'));
process.exit(2);
}
const result = await exploreChain({
receiptPath: opts.file,
searchDir: opts.chainSearchDir,
maxDepth: opts.chainMaxDepth,
});
if (opts.json) {
console.log(JSON.stringify(result, null, 2));
} else {
console.log(renderChainTree(result));
}
process.exit(result.valid ? 0 : 1);
}
/**
* verify compliance [--framework soc2|iso42001|eu-ai-act|all]
* --receipts-dir <dir> [--start-date ISO] [--end-date ISO]
* [--org "<name>"] [--output <file>] [--json]
*
* Produce a compliance evidence bundle: control-mapped receipt
* summaries, HTML audit report suitable for auditors.
*/
async function runCompliance(opts) {
const dir = opts.proxyReceiptsDir || opts.receiptsDir || opts.file;
if (!dir) {
console.error(red(' verify compliance requires --receipts-dir <dir>'));
console.error(dim(' usage: verify compliance --receipts-dir <dir> [--framework soc2|iso42001|eu-ai-act|all]'));
console.error(dim(' [--start-date ISO] [--end-date ISO] [--org "<name>"] [--output <file>] [--json]'));
process.exit(2);
}
let result;
try {
result = exportCompliance({
receiptsDir: dir,
framework: opts.frameworkOverride || 'all',
startDate: opts.startDate,
endDate: opts.endDate,
organizationName: opts.organization,
});
} catch (err) {
console.error(red(` compliance export failed: ${err.message}`));
process.exit(2);
}
if (opts.output) {
const isHtml = opts.output.endsWith('.html');
const body = isHtml
? renderComplianceHTML(result)
: JSON.stringify(result, null, 2);
writeFileSync(opts.output, body);
console.log(green(` ✓ Compliance bundle written to ${opts.output}`));
console.log(dim(` Receipts scanned: ${result.manifest.receipts_scanned} / in window: ${result.manifest.receipts_in_window}`));
for (const [fwId, fw] of Object.entries(result.manifest.frameworks)) {
const evidenced = Object.values(fw.controls).filter((c) => c.evidence_count > 0).length;
const total = Object.keys(fw.controls).length;
console.log(dim(` ${fw.framework}: ${evidenced}/${total} controls evidenced`));
}
return;
}
if (opts.json) {
console.log(JSON.stringify(result, null, 2));
return;
}
// Terminal rendering
console.log('');
console.log(bold('Compliance evidence bundle'));
console.log(` Organization: ${result.manifest.organization}`);
console.log(` Receipts: ${result.manifest.receipts_scanned} scanned, ${result.manifest.receipts_in_window} in window`);
if (result.manifest.window.start || result.manifest.window.end) {
console.log(` Window: ${result.manifest.window.start || '(begin)'} → ${result.manifest.window.end || '(end)'}`);
}
for (const [, fw] of Object.entries(result.manifest.frameworks)) {
console.log('');
console.log(bold(` ${fw.framework}`));
for (const [ctrlId, ctrl] of Object.entries(fw.controls)) {
const mark = ctrl.evidence_count > 0 ? green('●') : dim('○');
console.log(` ${mark} ${ctrlId} ${ctrl.name} ${dim(`(${ctrl.evidence_count})`)}`);
}
}
if (result.warnings.length) {
console.log('');
console.log(yellow(' Warnings:'));
for (const w of result.warnings) console.log(` • ${w}`);
}
console.log('');
}
/**
* verify dashboard [--port 3847] [--bind 127.0.0.1] [--receipts-dir <dir>]
*
* Spin up the local dashboard server. Opens a browser tab to it.
* Binds loopback only.
*/
async function runDashboard(opts) {
const receiptsDir = opts.proxyReceiptsDir || opts.receiptsDir;
let dash;
try {
dash = await startDashboard({
port: opts.dashboardPort || 3847,
bind: opts.dashboardBind || '127.0.0.1',
receiptsDir,
});
} catch (err) {
console.error(red(` dashboard failed to start: ${err.message}`));
process.exit(2);
}
console.log('');
console.log(bold(' Veritas Acta dashboard'));
console.log(` Serving at: ${dash.url}`);
if (receiptsDir) {
console.log(` Receipts: ${receiptsDir}`);
} else {
console.log(dim(` Receipts: (none — paste JSON or drop files in the UI)`));
}
console.log(dim(' Loopback-only. No TLS, no auth, no telemetry.'));
console.log(dim(' Press Ctrl+C to stop.'));
console.log('');
// Stay alive until interrupted.
await new Promise(() => {});
}
/**
* Canonical list of files committed by the Sigil.
* MUST match generate-sigil.mjs's MONITORED_FILES exactly.
*/
const MONITORED_FILES_FOR_SIGIL = [
'cli.js',
'src/detect.js',
'src/conformance.js',
'src/errors.js',
'src/engines/ed25519-receipt.js',
'src/engines/voprf-token.js',
'src/engines/knowledge-unit.js',
'src/engines/selective-disclosure.js',
'src/engines/sigil.js',
'src/engines/attestation.js',
'src/engines/bulk.js',
'src/engines/diff.js',
'src/engines/init.js',
'src/engines/proxy.js',
'src/engines/daemon.js',
'src/engines/prompt.js',
'src/engines/chain-explore.js',
'src/engines/compliance-export.js',
'src/engines/dsse.js',
'src/engines/delegation.js',
'src/engines/cosign.js',
'src/engines/dashboard.js',
'src/engines/rekor.js',
'src/engines/attestation-quote.js',
'src/engines/watch.js',
'src/engines/sbom.js',
'src/engines/transparency.js',
'src/context/live-context.js',
'src/output/terminal.js',
'src/output/json.js',
'src/output/html-report.js',
'src/util/canonical.js',
'src/util/hex.js',
'src/util/jwks.js',
'src/util/audit-log.js',
'src/util/fips.js',
'src/util/voprf-crypto.js',
'src/util/voprf-crypto-v2.js',
];
function selfCheckResult(sigil) {
if (!sigil) return { canonical: false };
const bufs = [];
for (const f of MONITORED_FILES_FOR_SIGIL) {
try { bufs.push(readFileSync(join(__dirname, f))); } catch { /* missing => modified */ }
}
const installedSourceBytes = Buffer.concat(bufs);
return selfCheck({ sigil, installedSourceBytes });
}
async function main() {
const opts = parseArgs();