@sanning/proof 0.12.0 → 0.14.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.
Files changed (59) hide show
  1. package/README.md +25 -12
  2. package/dist/agent-proof.d.ts +2 -2
  3. package/dist/agent-proof.js +4 -4
  4. package/dist/case-file.d.ts +126 -0
  5. package/dist/case-file.js +353 -0
  6. package/dist/case.d.ts +217 -26
  7. package/dist/case.js +535 -124
  8. package/dist/cli.d.ts +64 -8
  9. package/dist/cli.js +799 -219
  10. package/dist/compose.js +6 -1
  11. package/dist/crypto.d.ts +1 -1
  12. package/dist/crypto.js +5 -1
  13. package/dist/declaration.d.ts +58 -52
  14. package/dist/declaration.js +256 -33
  15. package/dist/evidence.d.ts +38 -0
  16. package/dist/evidence.js +238 -22
  17. package/dist/exit-codes.d.ts +17 -0
  18. package/dist/exit-codes.js +50 -0
  19. package/dist/file-match.d.ts +105 -0
  20. package/dist/file-match.js +374 -0
  21. package/dist/grading.d.ts +28 -13
  22. package/dist/grading.js +90 -31
  23. package/dist/index.d.ts +14 -7
  24. package/dist/index.js +20 -6
  25. package/dist/message-parts.d.ts +18 -10
  26. package/dist/message-parts.js +25 -15
  27. package/dist/types.d.ts +1 -0
  28. package/dist/verifier.d.ts +63 -4
  29. package/dist/verifier.js +223 -15
  30. package/dist/witness-cache.d.ts +85 -0
  31. package/dist/witness-cache.js +264 -0
  32. package/dist/zip-reader.d.ts +50 -0
  33. package/dist/zip-reader.js +220 -0
  34. package/package.json +2 -2
  35. package/src/agent-proof.ts +4 -4
  36. package/src/case-file.ts +422 -0
  37. package/src/case.ts +671 -131
  38. package/src/cli.ts +932 -217
  39. package/src/compose.ts +8 -1
  40. package/src/crypto.ts +5 -1
  41. package/src/declaration.ts +248 -52
  42. package/src/evidence.ts +257 -23
  43. package/src/exit-codes.ts +54 -0
  44. package/src/file-match.ts +461 -0
  45. package/src/grading.ts +109 -52
  46. package/src/index.ts +101 -2
  47. package/src/message-parts.ts +25 -15
  48. package/src/types.ts +5 -0
  49. package/src/verifier.ts +225 -16
  50. package/src/witness-cache.ts +306 -0
  51. package/src/zip-reader.ts +229 -0
  52. package/vectors/README.md +66 -8
  53. package/vectors/case-file-index.json +668 -0
  54. package/vectors/case-split.json +218 -9
  55. package/vectors/file-match.json +1808 -0
  56. package/vectors/jcs-reader.json +82 -3
  57. package/vectors/pack-grading.json +68 -4
  58. package/vectors/stamp-on-chain.json +20 -5
  59. package/vectors/witness-cache.json +1304 -0
package/dist/grading.js CHANGED
@@ -41,13 +41,13 @@
41
41
  // presents a different number of records than a checkpoint
42
42
  // signed for — UNKNOWN
43
43
  //
44
- // `incomplete` is the surface's word for undetermined, and it is deliberately
45
- // NOT `verdict.status` from `evidence-bundle.md` §3. That enum grades a signed
46
- // bundle; this one grades a PACK — a strictly larger object, the bundle plus
47
- // whatever bytes travelled beside it. A pack can be incomplete while the bundle
48
- // it carries is impeccable, which is exactly the case that used to render green
49
- // over zero hashed bytes. Widening §3 to carry `incomplete` would be a spec
50
- // change; keeping the two enums distinct is not.
44
+ // `incomplete` is one of the eight words of `evidence-bundle.md` §3 (v1.17,
45
+ // A18), and it is a PACK verdict, never a bundle status. The bundle status
46
+ // grades a signed bundle; this grades a PACK — a strictly larger object, the
47
+ // bundle plus whatever bytes travelled beside it. A pack can be incomplete
48
+ // while the bundle it carries is impeccable, which is exactly the case that
49
+ // used to render green over zero hashed bytes. One vocabulary, two layers,
50
+ // each issuing the subset it can reach.
51
51
  //
52
52
  // `recordsVerified` counts CONTENT-BOUND records only. The kernel's own
53
53
  // `event.ok` tolerates undisclosed content by design — a bundle may legitimately
@@ -73,6 +73,37 @@ import { hasSideContent, sideContentKeys } from "./side-content.js";
73
73
  // byte-order mark, no non-finite literal. `jcs_loads` in
74
74
  // `src/sanning_proof/canonicalize.py` is the twin (proof#140 gate 5).
75
75
  import { jcsParse } from "./verifier.js";
76
+ // ---- The verdict a surface may print ----------------------------------------
77
+ // A superset of `EvidenceStatus`: the four the kernel can return, plus the
78
+ // pack-level `incomplete`, plus `pending` from the shared §3 vocabulary so a
79
+ // kernel headline this module does not downgrade can pass through unchanged.
80
+ export const PACK_VERDICTS = [
81
+ "verified",
82
+ "partial",
83
+ "pending",
84
+ "not_found",
85
+ "mixed",
86
+ "failed",
87
+ "malformed",
88
+ "incomplete",
89
+ ];
90
+ // ---- Output ------------------------------------------------------------------
91
+ export const PACK_GRADE_CAUSE_KINDS = [
92
+ "records_omitted",
93
+ "records_surplus",
94
+ "leaf_count_unreadable",
95
+ "no_disclosure",
96
+ "missing_disclosure",
97
+ "unreadable_disclosure",
98
+ "unaccounted_disclosure",
99
+ "declaration_deviation",
100
+ /**
101
+ * The pack and the UNSIGNED content handed in beside it do not line up
102
+ * (proof#147). A cause, so the pack cannot read clean over it and a reader
103
+ * is told which record; NOT a deviation, so it never reaches `failed`.
104
+ */
105
+ "declaration_content_dependent",
106
+ ];
76
107
  /**
77
108
  * The checkpoint's join key, in whichever vocabulary the bundle speaks.
78
109
  *
@@ -358,7 +389,19 @@ export function completenessNotes(bundle) {
358
389
  * Every reason this pack is not `verified`, in the order a reader should hear
359
390
  * them: what is missing from the whole, then what is missing from the parts.
360
391
  */
361
- export function gradeCauses(account, notes, declaration) {
392
+ export function gradeCauses(account, notes, declaration, withheld = []) {
393
+ // The `event_id`s WITHHELD BY THEIR DECLARATION (rule version 6) are taken
394
+ // out of `expected` and `missing` before the disclosure causes are computed,
395
+ // so a pack whose every record its declaration withholds earns neither
396
+ // `no_disclosure` nor `missing_disclosure`.
397
+ if (withheld.length > 0) {
398
+ const gone = new Set(withheld);
399
+ account = {
400
+ ...account,
401
+ expected: account.expected.filter((e) => !gone.has(e)),
402
+ missing: account.missing.filter((e) => !gone.has(e)),
403
+ };
404
+ }
362
405
  const causes = [];
363
406
  // What the pack CLAIMED to hold comes first, because it frames everything
364
407
  // below it: a reader told "four records are missing from what this pack says
@@ -367,7 +410,7 @@ export function gradeCauses(account, notes, declaration) {
367
410
  // four ways can never be reported as one vague shortfall.
368
411
  for (const deviation of declaration?.deviations ?? []) {
369
412
  causes.push({
370
- kind: "declaration-deviation",
413
+ kind: "declaration_deviation",
371
414
  deviation: deviation.kind,
372
415
  ...(deviation.eventId === undefined ? {} : { firstEventId: deviation.eventId }),
373
416
  reason: renderDeviation(deviation),
@@ -378,7 +421,7 @@ export function gradeCauses(account, notes, declaration) {
378
421
  // deviation, so it never reaches `failed`.
379
422
  for (const finding of declaration?.contentFindings ?? []) {
380
423
  causes.push({
381
- kind: "declaration-content-dependent",
424
+ kind: "declaration_content_dependent",
382
425
  deviation: finding.kind,
383
426
  ...(finding.eventId === undefined ? {} : { firstEventId: finding.eventId }),
384
427
  reason: renderContentFinding(finding),
@@ -387,7 +430,7 @@ export function gradeCauses(account, notes, declaration) {
387
430
  for (const note of notes) {
388
431
  if (note.kind === "omitted") {
389
432
  causes.push({
390
- kind: "records-omitted",
433
+ kind: "records_omitted",
391
434
  checkpointRef: note.checkpointRef,
392
435
  signed: note.signed,
393
436
  presented: note.presented,
@@ -396,7 +439,7 @@ export function gradeCauses(account, notes, declaration) {
396
439
  }
397
440
  else if (note.kind === "surplus") {
398
441
  causes.push({
399
- kind: "records-surplus",
442
+ kind: "records_surplus",
400
443
  checkpointRef: note.checkpointRef,
401
444
  signed: note.signed,
402
445
  presented: note.presented,
@@ -404,7 +447,7 @@ export function gradeCauses(account, notes, declaration) {
404
447
  });
405
448
  }
406
449
  else {
407
- causes.push({ kind: "leaf-count-unreadable", checkpointRef: note.checkpointRef });
450
+ causes.push({ kind: "leaf_count_unreadable", checkpointRef: note.checkpointRef });
408
451
  }
409
452
  }
410
453
  // "Nothing at all was disclosed" is reported once, as itself. It is the
@@ -412,22 +455,22 @@ export function gradeCauses(account, notes, declaration) {
412
455
  // reader deserves to be told the pack disclosed nothing rather than counting
413
456
  // N absences.
414
457
  if (account.expected.length > 0 && account.present.length === 0 && account.unreadable.length === 0) {
415
- causes.push({ kind: "no-disclosure", count: account.expected.length, of: account.expected.length });
458
+ causes.push({ kind: "no_disclosure", count: account.expected.length, of: account.expected.length });
416
459
  }
417
460
  else if (account.missing.length > 0) {
418
461
  causes.push({
419
- kind: "missing-disclosure",
462
+ kind: "missing_disclosure",
420
463
  count: account.missing.length,
421
464
  of: account.expected.length,
422
465
  ...(account.missing[0] === undefined ? {} : { firstEventId: account.missing[0] }),
423
466
  });
424
467
  }
425
468
  for (const u of account.unreadable) {
426
- causes.push({ kind: "unreadable-disclosure", firstEventId: u.eventId, reason: u.reason });
469
+ causes.push({ kind: "unreadable_disclosure", firstEventId: u.eventId, reason: u.reason });
427
470
  }
428
471
  if (account.extra.length > 0) {
429
472
  causes.push({
430
- kind: "unaccounted-disclosure",
473
+ kind: "unaccounted_disclosure",
431
474
  count: account.extra.length,
432
475
  ...(account.extra[0] === undefined ? {} : { firstEventId: account.extra[0] }),
433
476
  });
@@ -445,7 +488,8 @@ export function gradeCauses(account, notes, declaration) {
445
488
  * the type and renders the verdict verbatim would then print the one word
446
489
  * `evidence-bundle.md` §6 forbids, over a pack this rule never graded.
447
490
  *
448
- * So: the six states of the §3 vocabulary pass through, and ANYTHING ELSE is
491
+ * So: the five words of the §3 vocabulary that a bundle status can pass up to
492
+ * a pack pass through, and ANYTHING ELSE is
449
493
  * `incomplete`. A verdict we cannot interpret is a check we could not run, and
450
494
  * the answer to that is UNKNOWN — never a pass, and never an accusation.
451
495
  * (`failed` and `malformed` are handled before this is reached.)
@@ -466,8 +510,9 @@ function passThrough(status) {
466
510
  * The verdict a surface may print, and the counts it may print beside it.
467
511
  *
468
512
  * The invariant, stated so a mutation test can kill it: `verified` is reachable
469
- * ONLY when every record's supplied bytes bound to its own commitment and
470
- * nothing is missing, unreadable, surplus or omitted.
513
+ * ONLY when every record's supplied bytes bound to its own commitment, or
514
+ * (rule version 6) the record is withheld by its declaration, and nothing is
515
+ * missing, unreadable, surplus or omitted.
471
516
  *
472
517
  * Precedence: malformed > failed > incomplete > the kernel's own headline.
473
518
  * A hard verdict wins — "the bytes are absent" is never reported as failure
@@ -520,8 +565,20 @@ export function gradePack(result, account, notes, declaration) {
520
565
  const events = Array.isArray(result?.events) ? result.events : [];
521
566
  const recordsVerified = events.filter((e) => e.ok && e.contentOk === true).length;
522
567
  const recordsFailed = events.filter((e) => e.ok === false || e.contentOk === false).length;
523
- const recordsUndetermined = events.length - recordsVerified - recordsFailed;
524
- const causes = gradeCauses(account, notes, declaration);
568
+ // WITHHELD BY ITS DECLARATION (rule version 6, 5.4.5 v1.20, A22, D5). All
569
+ // four conditions, each on its own. `declaredWithheld` is empty for an
570
+ // absent, unreadable or malformed declaration.
571
+ const declaredWithheld = new Set(declaration?.declaredWithheld ?? []);
572
+ const withheldEventIds = events
573
+ .filter((e) => typeof e.eventId === "string" &&
574
+ declaredWithheld.has(e.eventId) &&
575
+ e.ok === true &&
576
+ e.contentOk === null &&
577
+ e.payloadBindingOk === true)
578
+ .map((e) => e.eventId);
579
+ const recordsWithheld = withheldEventIds.length;
580
+ const recordsUndetermined = events.length - recordsVerified - recordsFailed - recordsWithheld;
581
+ const causes = gradeCauses(account, notes, declaration, withheldEventIds);
525
582
  let verdict;
526
583
  if (result?.status === "malformed")
527
584
  verdict = "malformed";
@@ -541,6 +598,8 @@ export function gradePack(result, account, notes, declaration) {
541
598
  recordsFailed,
542
599
  recordsUndetermined,
543
600
  causes,
601
+ recordsWithheld,
602
+ withheldEventIds,
544
603
  };
545
604
  if (declaration != null)
546
605
  grade.declaration = declaration.verdict;
@@ -559,32 +618,32 @@ export function gradePack(result, account, notes, declaration) {
559
618
  */
560
619
  export function renderCause(cause, subject = "this pack") {
561
620
  switch (cause.kind) {
562
- case "records-omitted":
621
+ case "records_omitted":
563
622
  return (`checkpoint ${cause.checkpointRef} commits to ${cause.signed} record(s); ${subject} presents ` +
564
623
  `${cause.presented} — ${cause.count} record(s) OMITTED`);
565
- case "records-surplus":
624
+ case "records_surplus":
566
625
  return (`checkpoint ${cause.checkpointRef} commits to ${cause.signed} record(s); ${subject} presents ` +
567
626
  `${cause.presented} — more records than the signed tree accounts for`);
568
- case "leaf-count-unreadable":
627
+ case "leaf_count_unreadable":
569
628
  return `checkpoint ${cause.checkpointRef} has no readable signed leaf_count — completeness is UNKNOWN`;
570
- case "no-disclosure":
629
+ case "no_disclosure":
571
630
  return (`no event bytes were disclosed — content binding is UNKNOWN for all ${cause.count} ` +
572
631
  `record(s), not verified`);
573
- case "missing-disclosure":
632
+ case "missing_disclosure":
574
633
  return (`${cause.count} of ${cause.of} record(s) disclose no bytes (first: ${cause.firstEventId}) — ` +
575
634
  `content binding is UNKNOWN, not verified`);
576
- case "unreadable-disclosure":
635
+ case "unreadable_disclosure":
577
636
  return `the disclosure for ${cause.firstEventId} is unreadable: ${cause.reason}`;
578
- case "unaccounted-disclosure":
637
+ case "unaccounted_disclosure":
579
638
  return (`${cause.count} disclosed file(s) are not accounted for by any record in this bundle ` +
580
639
  `(first: ${cause.firstEventId})`);
581
640
  // Rendered once, by `renderDeviation` in `./declaration.ts`, and carried
582
641
  // here on `reason`. Re-deriving the sentence from the cause fields would
583
642
  // put the declaration's wording in two places, and one of the two would be
584
643
  // edited alone.
585
- case "declaration-deviation":
644
+ case "declaration_deviation":
586
645
  return `this pack deviates from its own declaration: ${cause.reason}`;
587
- case "declaration-content-dependent":
646
+ case "declaration_content_dependent":
588
647
  // Named as what the reader could not establish, never as what the
589
648
  // holder did: the bytes it turns on are unsigned and whoever assembled
590
649
  // the case chose them (proof#147).
package/dist/index.d.ts CHANGED
@@ -2,19 +2,26 @@ export { ACCEPTED_SPEC_MAJORS, contentHashes, jcs, specVersionSupported, verifyE
2
2
  export { bytesToHex, deriveOperatorAddress, ed25519Verify, hexToBytes, sha256Bytes, sha256Hex, utf8, verifyRsaPssSha256, } from "./crypto.js";
3
3
  export { EMPTY_TREE_ROOT_HEX, auditPath, leafHash, merkleRoot, nodeHash, verifyInclusion, } from "./merkle.js";
4
4
  export type { ContentRole, Envelope, Subject, VerificationResult, VerifyOptions } from "./types.js";
5
- export { ANCHOR_TRACE_BODY_TYPE, EXPORT_BODY_TYPE, STAMP_BODY_VERSION, STAMP_TRACE_BODY_TYPE, STAMP_EVIDENCE_BODY_TYPE, disclosedContent, recomputeExportVerdict, verifyEvidenceBundle, } from "./evidence.js";
5
+ export { ACCEPTED_EVIDENCE_MAJORS, ANCHOR_TRACE_BODY_TYPE, CO_SIGNATURES_NOTE, EXPORT_BODY_TYPE, STAMP_BODY_VERSION, STAMP_TRACE_BODY_TYPE, STAMP_EVIDENCE_BODY_TYPE, coSignaturesPresent, disclosedContent, recomputeExportVerdict, verifyEvidenceBundle, } from "./evidence.js";
6
6
  export type { AnchorTraceBody, AttestationPayload, AttestationRecord, AttestationResult, CheckpointResult, ComposeVerdictResult, DisclosedContentResult, DisclosedEventContent, DisclosureStatus, EvidenceBundle, EvidenceBundleResult, EvidenceIssuer, EvidenceStatus, EvidenceVerdict, EventResult, ExportBody, ExportResult, OnChainOutcome, OnChainResult, PerGatewayOutcome, AnchorRef, StampBody, StampEntry, StampResult, StampSubtree, StampSubtreeResult, StampTraceBody, StampEvidenceBody, StampEvidenceEvent, StampEvidenceInclusion, TraceCheckpoint, TraceEvent, TraceInclusion, VerdictAttestation, VerdictCheckpoint, VerdictEvent, VerdictObject, VerdictOnChain, VerdictOnChainGateway, VerifyEvidenceOptions, } from "./evidence.js";
7
- export { accountDisclosure, completenessNotes, gradeCauses, gradePack, renderCause, signedLeafCount, } from "./grading.js";
7
+ export { PACK_GRADE_CAUSE_KINDS, PACK_VERDICTS, accountDisclosure, completenessNotes, gradeCauses, gradePack, renderCause, signedLeafCount, } from "./grading.js";
8
8
  export type { CompletenessNote, DisclosureAccount, GradeInput, PackGrade, PackGradeCause, PackGradeCauseKind, PackVerdict, } from "./grading.js";
9
- export { DECLARATION_VERSION, checkDeclaration, declarationClaims, packRecords, renderContentFinding, renderDeclarationSummary, renderDeviation, renderNote, } from "./declaration.js";
10
- export type { DeclarationCheck, DeclarationClaims, DeclarationContentFinding, DeclarationContentKind, DeclarationDeviation, DeclarationDeviationKind, DeclarationNote, DeclarationNoteKind, DeclarationVerdict, PackRecord, } from "./declaration.js";
11
- export { CASE_BODY_TYPES, CASE_EXCEPTION_KINDS, CASE_QUARANTINED_PROFILES, CASE_RECORD_PROFILES, CASE_VERDICTS, readCase, renderCaseSummary, renderException, } from "./case.js";
12
- export type { CaseException, CaseExceptionKind, CasePack, CaseReading, CaseRecordReading, CaseVerdict, } from "./case.js";
9
+ export { DECLARATION_CONTENT_KINDS, DECLARATION_DEVIATION_KINDS, DECLARATION_NOTE_KINDS, DECLARATION_ROLES, DECLARATION_VERDICTS, DECLARATION_VERSION, DECLARATION_VERSION_V2, DECLARATION_VERSIONS, checkDeclaration, declarationClaims, packRecords, renderContentFinding, renderDeclarationSummary, renderDeviation, renderNote, } from "./declaration.js";
10
+ export type { DeclarationCheck, DeclarationClaims, DeclarationContentFinding, DeclarationContentKind, DeclarationDeviation, DeclarationDeviationKind, DeclarationNote, DeclarationNoteKind, DeclarationRole, DeclarationVerdict, PackRecord, } from "./declaration.js";
11
+ export { CASE_BODY_TYPES, CASE_EXCEPTION_KINDS, CASE_QUARANTINED_PROFILES, CASE_RECORD_PROFILES, CASE_NOTE_KINDS, CASE_RELIANCE, CASE_RELIANCE_HANDOFF_CLAUSE, CASE_VERDICTS, CONTENT_WITHHELD_BY_DECLARATION, CO_SIGNATURES_PRESENT, VERDICT_DISPLAY_TITLES, WITNESS_NOT_LOOKED_UP, WITNESS_STATES, WITNESS_TIME_CACHED, WITNESS_TIME_RECORDED, caseReliance, readCase, renderCaseNote, renderCaseSummary, renderException, renderWitnessLine, } from "./case.js";
12
+ export { MAX_BLOCK_TIME, MAX_WITNESS_CACHE_DEPTH, WITNESS_CACHE_NAME, WITNESS_CACHE_VERSION, checkWitnessCache, formatBlockTime, readWitnessCache, renderWitnessTime, witnessTimeQuery, } from "./witness-cache.js";
13
+ export type { CachedWitnessTime, WitnessTimeAnswer, WitnessTimeCheck } from "./witness-cache.js";
14
+ export type { CaseException, CaseExceptionKind, CaseNote, CaseNoteKind, CasePack, CasePackReading, CaseReading, CaseRecordReading, CaseVerdict, WitnessLine, WitnessState, } from "./case.js";
15
+ export { CASE_FILE_FINDING_KINDS, CASE_FILE_INDEX_NAME, CASE_FILE_VERSION, HOW_TO_VERIFY_NAME, REPORT_README_FIRST_LINE, howToVerifyText, isPackRef, readCaseFileIndex, renderCaseFileFinding, } from "./case-file.js";
16
+ export type { CaseFileFinding, CaseFileFindingKind, CaseFileIndexReading, } from "./case-file.js";
17
+ export { FILE_MATCH_SCOPE, NOT_READ_REASONS, fileMatchToJson, matchCaseFiles, matchFiles, renderFileMatch, } from "./file-match.js";
18
+ export type { FileCommitment, FileMatchPack, FileMatchReading, MatchedFile, NotRead, NotReadReason, OfferedFile, UnmatchedFile, } from "./file-match.js";
13
19
  export { ADAPTER_CHAIN_NAMESPACES, CHAIN_READING_SCOPE, readChains, renderChainFinding, } from "./chain.js";
14
20
  export type { ChainFinding, ChainFindingKind, ChainReading, ChainSource, ChainSummary, } from "./chain.js";
21
+ export { EXIT_CODES, EXIT_CODES_HELP, EXIT_FAILED, EXIT_MALFORMED, EXIT_MIXED, EXIT_UNDETERMINED, EXIT_VERIFIED, exitCodeFor, } from "./exit-codes.js";
15
22
  export { attestationSignatureToHex, composeExport } from "./compose.js";
16
23
  export type { ComposeExportOptions, ComposeExportResult, ExporterKey } from "./compose.js";
17
- export { AGENT_PROOF_SPEC_PREFIX, isAgentProofSpec, verifyAgentProofBundle } from "./agent-proof.js";
24
+ export { AGENT_PROOF_SPEC_VERSION, isAgentProofSpec, verifyAgentProof } from "./agent-proof.js";
18
25
  export type { AgentProofBundle, AgentProofResult, VerifyAgentProofOptions, } from "./agent-proof.js";
19
26
  export { CANDIDATE_NAMESPACE, DEFINED_EVENT_TYPES, NOT_A_HANDOFF_FINDING, isConformantHandoffRecord, readHandoff, readHandoffs, recordIsMalformed, } from "./handoff.js";
20
27
  export type { CandidateReading, HandoffReading, HandoffRecord, HandoffVerdict, HeldRecord, } from "./handoff.js";
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@
11
11
  // envelope. Chain walking (previous_hash), checkpoint reconciliation, and
12
12
  // gateway/transport concerns are consumer-layer logic composed above it.
13
13
  // ACCEPTED_SPEC_MAJORS is exported for parity with the sibling kernels'
14
- // registries (Python ACCEPTED_SPEC_VERSIONS, Go SupportedSpecMajor): a consumer
14
+ // registries (Python ACCEPTED_SPEC_MAJORS, Go SupportedSpecMajor): a consumer
15
15
  // can see which profiles this build admits without inferring it from probe
16
16
  // calls. It is frozen at its definition (`Object.freeze`, typed
17
17
  // `readonly string[]`) because the verifier reads that same array — an exported
@@ -34,7 +34,7 @@ export { EMPTY_TREE_ROOT_HEX, auditPath, leafHash, merkleRoot, nodeHash, verifyI
34
34
  // files that failed verification on genuine evidence. This hands back DECODED
35
35
  // bytes, and only for events whose verification bound them to the committed
36
36
  // content_hash. Additive; verifyEvidenceBundle's behavior is unchanged.
37
- export { ANCHOR_TRACE_BODY_TYPE, EXPORT_BODY_TYPE, STAMP_BODY_VERSION, STAMP_TRACE_BODY_TYPE, STAMP_EVIDENCE_BODY_TYPE, disclosedContent, recomputeExportVerdict, verifyEvidenceBundle, } from "./evidence.js";
37
+ export { ACCEPTED_EVIDENCE_MAJORS, ANCHOR_TRACE_BODY_TYPE, CO_SIGNATURES_NOTE, EXPORT_BODY_TYPE, STAMP_BODY_VERSION, STAMP_TRACE_BODY_TYPE, STAMP_EVIDENCE_BODY_TYPE, coSignaturesPresent, disclosedContent, recomputeExportVerdict, verifyEvidenceBundle, } from "./evidence.js";
38
38
  // Pack grading (src/grading.ts): what a verification SURFACE may claim about a
39
39
  // pack — the signed bundle PLUS whatever disclosed bytes travelled beside it.
40
40
  //
@@ -50,7 +50,7 @@ export { ANCHOR_TRACE_BODY_TYPE, EXPORT_BODY_TYPE, STAMP_BODY_VERSION, STAMP_TRA
50
50
  // consumer that cannot yet import `gradePack` can vendor the table, hold its own
51
51
  // derivation to it, and diff its copy against ours. Additive — no existing
52
52
  // export changes.
53
- export { accountDisclosure, completenessNotes, gradeCauses, gradePack, renderCause, signedLeafCount, } from "./grading.js";
53
+ export { PACK_GRADE_CAUSE_KINDS, PACK_VERDICTS, accountDisclosure, completenessNotes, gradeCauses, gradePack, renderCause, signedLeafCount, } from "./grading.js";
54
54
  // The declaration (src/declaration.ts): what a pack SAYS it holds, checked
55
55
  // against what it does (evidence-bundle.md §5.4).
56
56
  //
@@ -67,7 +67,7 @@ export { accountDisclosure, completenessNotes, gradeCauses, gradePack, renderCau
67
67
  // Pure: data in, data out, no I/O. `gradePack` takes the result as an
68
68
  // optional fourth argument, so a surface gets one verdict; omitting it is the
69
69
  // pre-§5.4 behavior, unchanged. Additive: no existing export changes.
70
- export { DECLARATION_VERSION, checkDeclaration, declarationClaims, packRecords, renderContentFinding, renderDeclarationSummary, renderDeviation, renderNote, } from "./declaration.js";
70
+ export { DECLARATION_CONTENT_KINDS, DECLARATION_DEVIATION_KINDS, DECLARATION_NOTE_KINDS, DECLARATION_ROLES, DECLARATION_VERDICTS, DECLARATION_VERSION, DECLARATION_VERSION_V2, DECLARATION_VERSIONS, checkDeclaration, declarationClaims, packRecords, renderContentFinding, renderDeclarationSummary, renderDeviation, renderNote, } from "./declaration.js";
71
71
  // The case (src/case.ts): one verdict over SEVERAL packs, across organizations
72
72
  // (anchor#198). The layer above the declaration, and the closure for what a
73
73
  // declaration cannot reach.
@@ -85,7 +85,18 @@ export { DECLARATION_VERSION, checkDeclaration, declarationClaims, packRecords,
85
85
  //
86
86
  // Pure: data in, data out, no I/O. Additive: a new module, no existing export
87
87
  // changes, and no new verdict word anywhere.
88
- export { CASE_BODY_TYPES, CASE_EXCEPTION_KINDS, CASE_QUARANTINED_PROFILES, CASE_RECORD_PROFILES, CASE_VERDICTS, readCase, renderCaseSummary, renderException, } from "./case.js";
88
+ export { CASE_BODY_TYPES, CASE_EXCEPTION_KINDS, CASE_QUARANTINED_PROFILES, CASE_RECORD_PROFILES, CASE_NOTE_KINDS, CASE_RELIANCE, CASE_RELIANCE_HANDOFF_CLAUSE, CASE_VERDICTS, CONTENT_WITHHELD_BY_DECLARATION, CO_SIGNATURES_PRESENT, VERDICT_DISPLAY_TITLES, WITNESS_NOT_LOOKED_UP, WITNESS_STATES, WITNESS_TIME_CACHED, WITNESS_TIME_RECORDED, caseReliance, readCase, renderCaseNote, renderCaseSummary, renderException, renderWitnessLine, } from "./case.js";
89
+ // The witnessed-time cache (evidence-bundle 5.6.6, v1.25, A30): read it, look it
90
+ // up, print it. Never an input to a verdict.
91
+ export { MAX_BLOCK_TIME, MAX_WITNESS_CACHE_DEPTH, WITNESS_CACHE_NAME, WITNESS_CACHE_VERSION, checkWitnessCache, formatBlockTime, readWitnessCache, renderWitnessTime, witnessTimeQuery, } from "./witness-cache.js";
92
+ // The case file's index (src/case-file.ts, evidence-bundle.md §5.6, A25):
93
+ // compared with the drop it describes, with NO verdict contribution. The index
94
+ // is never an input to `readCase`. Pure: bytes and a file list in.
95
+ export { CASE_FILE_FINDING_KINDS, CASE_FILE_INDEX_NAME, CASE_FILE_VERSION, HOW_TO_VERIFY_NAME, REPORT_README_FIRST_LINE, howToVerifyText, isPackRef, readCaseFileIndex, renderCaseFileFinding, } from "./case-file.js";
96
+ // Files handed in beside a pack (src/file-match.ts, evidence-bundle.md §5.7,
97
+ // A29, proof#92): each file's SHA-256 matched against the commitments the
98
+ // pack's SIGNED records make, by hash alone. Never moves a verdict.
99
+ export { FILE_MATCH_SCOPE, NOT_READ_REASONS, fileMatchToJson, matchCaseFiles, matchFiles, renderFileMatch, } from "./file-match.js";
89
100
  // Chain reading (src/chain.ts): following the pointer every sanning.events/v2
90
101
  // record carries to the record before it, over the records ONE bundle presents.
91
102
  //
@@ -111,11 +122,14 @@ export { ADAPTER_CHAIN_NAMESPACES, CHAIN_READING_SCOPE, readChains, renderChainF
111
122
  // signed, offline-verifiable sanning.evidence.export/v2 artifact from a source
112
123
  // anchor-trace bundle + operator attestations + an exporter Ed25519 key. The
113
124
  // inverse of verifyEvidenceBundle's verifyExportBody dispatch.
125
+ // One exit-code table for every verb (0.13.0): the verdict word to the exit
126
+ // code, and the help text every verb prints. Additive.
127
+ export { EXIT_CODES, EXIT_CODES_HELP, EXIT_FAILED, EXIT_MALFORMED, EXIT_MIXED, EXIT_UNDETERMINED, EXIT_VERIFIED, exitCodeFor, } from "./exit-codes.js";
114
128
  export { attestationSignatureToHex, composeExport } from "./compose.js";
115
129
  // Agent inclusion-proof bundle verification: the
116
130
  // sanning.agent.proof/v1 bundle. The CLI sniffs spec_version and routes here so
117
131
  // one verifier covers both agent and anchor bundles.
118
- export { AGENT_PROOF_SPEC_PREFIX, isAgentProofSpec, verifyAgentProofBundle } from "./agent-proof.js";
132
+ export { AGENT_PROOF_SPEC_VERSION, isAgentProofSpec, verifyAgentProof } from "./agent-proof.js";
119
133
  // The hand-off pairing rule (src/handoff.ts): which records are candidates to
120
134
  // be the counterpart of a hand-off record, how a candidate set of more than one
121
135
  // is ordered, and what a formed pair grades to (specs/envelope-spec.md §4.1
@@ -118,19 +118,27 @@ export declare const REFUSAL_ORDER: readonly ["bytes_for_unknown_part", "conflic
118
118
  export declare const MESSAGE_RESULT_ORDER: readonly ["parts_not_an_array"];
119
119
  /**
120
120
  * The keys that make a part carry its content INLINE, in the order they are
121
- * read. Named rather than inferred: `bytes` is A2A's spelling of an inline file
122
- * part, and `data` and `content` are the two other spellings in the wild. The
123
- * FIRST of them present with a value that is not `null` is the inline content,
124
- * so a part spelling it twice reads one way in both kernels.
121
+ * read. Settled at `bytes` alone (envelope-spec §4.1, A31, proof#163): that
122
+ * is A2A's spelling, the one the wedge actually emits, and it is the only
123
+ * inline spelling either reference kernel has read from a real producer.
124
+ * `content` and `data` were added on inference rather than on an observed
125
+ * wire shape, and sanning-io/anchor's `filePart()` and `file_part()` SDK
126
+ * helpers, the only producer this plane ships, confirm the inference was
127
+ * wrong: both emit a descriptor part, `kind: "file"` plus `content_hash` and
128
+ * `content_length`, and neither ever writes a `content` or `data` wire key
129
+ * for inline bytes. None is A2A 1.0.0's either: its `Part` has no `kind` and
130
+ * carries a file as `raw` or `url`, so a literal A2A part reads
131
+ * `part_not_a_file` (envelope-spec §4.1, A19). The one key present with a
132
+ * value that is not `null` is the inline content.
125
133
  *
126
134
  * A key present with `null` is an ABSENT inline value, on A14's ruling that an
127
- * absent value and one written as `null` name one thing. That matters: an A2A
128
- * `FilePart` with `uri` set carries `"bytes": null`, and so does proto3 JSON,
129
- * and reading those as inline made a conformant DESCRIPTOR part uncheckable
130
- * (proof#156 gate). They fall through to the descriptor rule, which is what
131
- * they are.
135
+ * absent value and one written as `null` name one thing. That matters: a
136
+ * proto3 JSON encoder can write an unset field as `"bytes": null`, and reading
137
+ * that as inline made a conformant DESCRIPTOR part uncheckable
138
+ * (proof#156 gate). Such a part falls through to the descriptor rule, which is
139
+ * what it is.
132
140
  */
133
- export declare const INLINE_BYTES_KEYS: readonly ["bytes", "content", "data"];
141
+ export declare const INLINE_BYTES_KEYS: readonly ["bytes"];
134
142
  /**
135
143
  * The largest integer a double carries exactly, the same bound section 4.1 puts
136
144
  * on `event.sequence`: a `content_length` outside it is a value the two kernels
@@ -262,23 +262,33 @@ const HELD_UNCHECKED_RESULTS = [
262
262
  ];
263
263
  /**
264
264
  * The keys that make a part carry its content INLINE, in the order they are
265
- * read. Named rather than inferred: `bytes` is A2A's spelling of an inline file
266
- * part, and `data` and `content` are the two other spellings in the wild. The
267
- * FIRST of them present with a value that is not `null` is the inline content,
268
- * so a part spelling it twice reads one way in both kernels.
265
+ * read. Settled at `bytes` alone (envelope-spec §4.1, A31, proof#163): that
266
+ * is A2A's spelling, the one the wedge actually emits, and it is the only
267
+ * inline spelling either reference kernel has read from a real producer.
268
+ * `content` and `data` were added on inference rather than on an observed
269
+ * wire shape, and sanning-io/anchor's `filePart()` and `file_part()` SDK
270
+ * helpers, the only producer this plane ships, confirm the inference was
271
+ * wrong: both emit a descriptor part, `kind: "file"` plus `content_hash` and
272
+ * `content_length`, and neither ever writes a `content` or `data` wire key
273
+ * for inline bytes. None is A2A 1.0.0's either: its `Part` has no `kind` and
274
+ * carries a file as `raw` or `url`, so a literal A2A part reads
275
+ * `part_not_a_file` (envelope-spec §4.1, A19). The one key present with a
276
+ * value that is not `null` is the inline content.
269
277
  *
270
278
  * A key present with `null` is an ABSENT inline value, on A14's ruling that an
271
- * absent value and one written as `null` name one thing. That matters: an A2A
272
- * `FilePart` with `uri` set carries `"bytes": null`, and so does proto3 JSON,
273
- * and reading those as inline made a conformant DESCRIPTOR part uncheckable
274
- * (proof#156 gate). They fall through to the descriptor rule, which is what
275
- * they are.
276
- */
277
- // A conformant DESCRIPTOR part that also carries a `content` or `data` key
278
- // meaning something else (a filename, a metadata blob) is reclassified by this
279
- // list and never checked against supplied bytes. That is inside section 4.1's
280
- // stated rule, and whether these parts ought to fall into it is proof#163.
281
- export const INLINE_BYTES_KEYS = ["bytes", "content", "data"];
279
+ * absent value and one written as `null` name one thing. That matters: a
280
+ * proto3 JSON encoder can write an unset field as `"bytes": null`, and reading
281
+ * that as inline made a conformant DESCRIPTOR part uncheckable
282
+ * (proof#156 gate). Such a part falls through to the descriptor rule, which is
283
+ * what it is.
284
+ */
285
+ // Before A31 this list also carried `content` and `data`, and a conformant
286
+ // DESCRIPTOR part that happened to carry either key meaning something else (a
287
+ // filename, a caption) was silently reclassified as inline and never checked
288
+ // against supplied bytes: the swapped-bytes check A18 exists to run
289
+ // (proof#145) never ran on it. proof#163 is resolved by narrowing to `bytes`
290
+ // alone, closing that gap.
291
+ export const INLINE_BYTES_KEYS = ["bytes"];
282
292
  const HEX64 = /^[0-9a-fA-F]{64}$/;
283
293
  const HEX_CHARSET = /^[0-9a-fA-F]+$/;
284
294
  const LOWER_HEX = "0123456789abcdef";
package/dist/types.d.ts CHANGED
@@ -22,6 +22,7 @@ export type ContentRole = "asset" | "baseline" | "observed";
22
22
  export interface VerifyOptions {
23
23
  payloadBytes?: Uint8Array;
24
24
  expectedContentHash?: string;
25
+ acceptedSpecMajors?: readonly string[];
25
26
  }
26
27
  export interface VerificationResult {
27
28
  ok: boolean;
@@ -8,11 +8,13 @@ export declare function jcs(value: unknown): string;
8
8
  * twin is `jcs_loads` in `src/sanning_proof/canonicalize.py`, and every site in
9
9
  * either kernel that reads bytes a producer signed goes through one of the two.
10
10
  *
11
- * ONE RULE, SPELLED OUT, BECAUSE TWO BUILT-INS ARE NOT ONE RULE. Four checks
11
+ * ONE RULE, SPELLED OUT, BECAUSE TWO BUILT-INS ARE NOT ONE RULE. Five checks
12
12
  * carry it, none of them left to a decoder's defaults: strict UTF-8, no leading
13
13
  * byte-order mark, no non-finite literal (this kernel's `JSON.parse` rejects
14
14
  * `NaN`, `Infinity` and `-Infinity` natively, and Python names them in a
15
- * `parse_constant` hook), and no unpaired surrogate in the parsed value.
15
+ * `parse_constant` hook), no object that repeats a member name
16
+ * (`DuplicateKeyError`, proof#144), and no unpaired surrogate in the parsed
17
+ * value.
16
18
  *
17
19
  * THE FOURTH CHECK IS NOT THE FIRST ONE TWICE. The strict decode refuses a
18
20
  * surrogate written as raw bytes; it cannot see one written as the ASCII
@@ -38,11 +40,68 @@ export declare function jcs(value: unknown): string;
38
40
  * Throws for anything that is not conformant; every call site treats a throw as
39
41
  * "this reader cannot read these bytes" and names the check that failed.
40
42
  */
43
+ /**
44
+ * Bytes as strict UTF-8, a leading byte-order mark KEPT as a character.
45
+ * `utf8_strict` in the Python twin's `canonicalize.py` is the same rule, and
46
+ * `jcsParse` below performs the identical decode. Throws on bytes that are not
47
+ * UTF-8.
48
+ */
49
+ export declare function utf8Strict(bytes: Uint8Array): string;
41
50
  export declare function jcsParse(bytes: Uint8Array): unknown;
42
- export declare function specVersionSupported(specVersion: string): boolean;
51
+ /**
52
+ * A JSON object that names one member twice (I-JSON, RFC 7493 section 2.3).
53
+ * The Python twin is `DuplicateKey` in `canonicalize.py`, and the message is
54
+ * the same kernel wording in both: `duplicate key ` and the name as
55
+ * `renderKey` spells it.
56
+ *
57
+ * JCS (RFC 8785) is defined over I-JSON, and I-JSON forbids duplicate member
58
+ * names, so bytes that repeat a name are MALFORMED rather than another spelling
59
+ * of the last value. `JSON.parse` and Python's `json.loads` both keep the last
60
+ * value and say nothing, which let a bundle carrying `"spec_version":"junk"`
61
+ * before its real `spec_version` read `verified` in both kernels (proof#144).
62
+ */
63
+ export declare class DuplicateKeyError extends Error {
64
+ readonly key: string;
65
+ constructor(key: string);
66
+ }
67
+ /**
68
+ * A member name as a quoted, pure-ASCII string, identically in both kernels
69
+ * (`render_key` in the Python twin). Printable ASCII other than `"` and `\` is
70
+ * kept; `"` and `\` are backslash-escaped; every other UTF-16 code unit is
71
+ * `\uXXXX` in lower-case hex. A rendering longer than 64 characters is cut
72
+ * there and `...` follows the closing quote.
73
+ */
74
+ export declare function renderKey(key: string): string;
75
+ /**
76
+ * `JSON.parse(text)`, refusing an object that repeats a member name. The Python
77
+ * twin is `loads_refusing_duplicates` in `canonicalize.py`.
78
+ *
79
+ * `JSON.parse` cannot see a repeat, because it keeps the last value, so the
80
+ * text is scanned once more AFTER it parsed. The parse runs first, so text
81
+ * that is not JSON at all fails as JSON and never as a duplicate, as it does in
82
+ * the Python twin. Throws `DuplicateKeyError`.
83
+ */
84
+ export declare function parseRefusingDuplicates(text: string): unknown;
85
+ /**
86
+ * The repeated member name to report for text `JSON.parse` has already
87
+ * accepted, or `undefined` when no object repeats one.
88
+ *
89
+ * WHICH ONE, because both kernels must name the same one. Objects are checked
90
+ * as they CLOSE, innermost first, which is the order Python's
91
+ * `object_pairs_hook` sees them in; inside one object the name reported is the
92
+ * first whose repeat comes earliest. Names compare after unescaping, so `"a"`
93
+ * and `"\u0061"` are one name, as they are to both parsers.
94
+ *
95
+ * ITERATIVE, with an explicit stack, for the reason `rejectUnpairedSurrogates`
96
+ * is: this walks bytes a producer wrote. It relies on the text being valid
97
+ * JSON, which is why it runs only after `JSON.parse` succeeded: outside a
98
+ * string, only `{`, `[`, `}`, `]`, `,` and `"` change what comes next.
99
+ */
100
+ export declare function firstDuplicateKey(text: string): string | undefined;
101
+ export declare function specVersionSupported(specVersion: string, accepted?: readonly string[]): boolean;
43
102
  export declare function isRfc3339UtcInstant(value: unknown): boolean;
44
103
  export declare function contentHashes(env: Envelope): {
45
104
  role: ContentRole;
46
105
  hash: string;
47
106
  }[];
48
- export declare function verifyEnvelope(env: Envelope, optionsOrContentHash?: string | VerifyOptions): Promise<VerificationResult>;
107
+ export declare function verifyEnvelope(env: Envelope, options?: VerifyOptions): Promise<VerificationResult>;