@peac/schema 0.12.1 → 0.12.3

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 (76) hide show
  1. package/dist/actor-binding.d.ts +10 -10
  2. package/dist/agent-identity.d.ts +8 -6
  3. package/dist/agent-identity.d.ts.map +1 -1
  4. package/dist/carrier.d.ts +7 -7
  5. package/dist/carrier.d.ts.map +1 -1
  6. package/dist/constraints.d.ts +4 -4
  7. package/dist/constraints.d.ts.map +1 -1
  8. package/dist/extensions/control-action.d.ts +1 -1
  9. package/dist/extensions/credential-event.d.ts +4 -4
  10. package/dist/extensions/fingerprint-ref.d.ts +1 -1
  11. package/dist/extensions/index.d.ts +1 -1
  12. package/dist/extensions/tool-registry.d.ts +1 -1
  13. package/dist/extensions/treaty.d.ts +2 -2
  14. package/dist/index.cjs +733 -44
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.mjs +684 -46
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/issuer-config.d.ts +1 -1
  21. package/dist/policy-binding.d.ts +2 -2
  22. package/dist/receipt-parser.cjs +626 -14
  23. package/dist/receipt-parser.cjs.map +1 -1
  24. package/dist/receipt-parser.mjs +627 -15
  25. package/dist/receipt-parser.mjs.map +1 -1
  26. package/dist/subject.d.ts +33 -12
  27. package/dist/subject.d.ts.map +1 -1
  28. package/dist/types.d.ts +1 -1
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/wire-02-envelope.d.ts +2 -2
  31. package/dist/wire-02-extensions/access.d.ts +19 -0
  32. package/dist/wire-02-extensions/access.d.ts.map +1 -0
  33. package/dist/wire-02-extensions/accessors.d.ts +44 -0
  34. package/dist/wire-02-extensions/accessors.d.ts.map +1 -0
  35. package/dist/wire-02-extensions/attribution.d.ts +44 -0
  36. package/dist/wire-02-extensions/attribution.d.ts.map +1 -0
  37. package/dist/wire-02-extensions/challenge.d.ts +60 -0
  38. package/dist/wire-02-extensions/challenge.d.ts.map +1 -0
  39. package/dist/wire-02-extensions/commerce.d.ts +29 -0
  40. package/dist/wire-02-extensions/commerce.d.ts.map +1 -0
  41. package/dist/wire-02-extensions/compliance.d.ts +49 -0
  42. package/dist/wire-02-extensions/compliance.d.ts.map +1 -0
  43. package/dist/wire-02-extensions/consent.d.ts +48 -0
  44. package/dist/wire-02-extensions/consent.d.ts.map +1 -0
  45. package/dist/wire-02-extensions/correlation.d.ts +18 -0
  46. package/dist/wire-02-extensions/correlation.d.ts.map +1 -0
  47. package/dist/wire-02-extensions/grammar.d.ts +40 -0
  48. package/dist/wire-02-extensions/grammar.d.ts.map +1 -0
  49. package/dist/wire-02-extensions/identity.d.ts +13 -0
  50. package/dist/wire-02-extensions/identity.d.ts.map +1 -0
  51. package/dist/wire-02-extensions/index.d.ts +40 -0
  52. package/dist/wire-02-extensions/index.d.ts.map +1 -0
  53. package/dist/wire-02-extensions/limits.d.ts +80 -0
  54. package/dist/wire-02-extensions/limits.d.ts.map +1 -0
  55. package/dist/wire-02-extensions/privacy.d.ts +64 -0
  56. package/dist/wire-02-extensions/privacy.d.ts.map +1 -0
  57. package/dist/wire-02-extensions/provenance.d.ts +58 -0
  58. package/dist/wire-02-extensions/provenance.d.ts.map +1 -0
  59. package/dist/wire-02-extensions/purpose-extension.d.ts +26 -0
  60. package/dist/wire-02-extensions/purpose-extension.d.ts.map +1 -0
  61. package/dist/wire-02-extensions/safety.d.ts +65 -0
  62. package/dist/wire-02-extensions/safety.d.ts.map +1 -0
  63. package/dist/wire-02-extensions/schema-map.d.ts +13 -0
  64. package/dist/wire-02-extensions/schema-map.d.ts.map +1 -0
  65. package/dist/wire-02-extensions/shared-validators.d.ts +192 -0
  66. package/dist/wire-02-extensions/shared-validators.d.ts.map +1 -0
  67. package/dist/wire-02-extensions/validation.d.ts +57 -0
  68. package/dist/wire-02-extensions/validation.d.ts.map +1 -0
  69. package/dist/wire-02-extensions.d.ts +7 -211
  70. package/dist/wire-02-extensions.d.ts.map +1 -1
  71. package/dist/wire-02-registries.d.ts +5 -2
  72. package/dist/wire-02-registries.d.ts.map +1 -1
  73. package/dist/wire-02-representation.d.ts +3 -3
  74. package/dist/wire-02-warnings.d.ts +5 -1
  75. package/dist/wire-02-warnings.d.ts.map +1 -1
  76. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ALGORITHMS, HEADERS, POLICY, ISSUER_CONFIG, DISCOVERY, WIRE_TYPE, TYPE_GRAMMAR, ISS_CANONICAL, POLICY_BLOCK, HASH } from '@peac/kernel';
2
+ import { ALGORITHMS, HEADERS, POLICY, ISSUER_CONFIG, DISCOVERY, WIRE_TYPE, HASH, TYPE_GRAMMAR, ISS_CANONICAL, POLICY_BLOCK, ERROR_CODES as ERROR_CODES$1, EXTENSION_BUDGET } from '@peac/kernel';
3
3
 
4
4
  // src/validators.ts
5
5
  var PEAC_WIRE_TYP = WIRE_TYPE;
@@ -44,7 +44,7 @@ var JsonObjectSchema = PlainObjectSchema.transform(
44
44
  ).pipe(z.record(z.string(), JsonValueSchema));
45
45
  z.array(JsonValueSchema);
46
46
  var ERROR_CODES = {
47
- // Wire 0.2 extension errors (400, DD-153/DD-156)
47
+ // Wire 0.2 extension errors (400/)
48
48
  E_INVALID_EXTENSION_KEY: "E_INVALID_EXTENSION_KEY"
49
49
  };
50
50
 
@@ -323,7 +323,7 @@ function isOriginOnly(value) {
323
323
  var ActorBindingSchema = z.object({
324
324
  /** Stable actor identifier (opaque, no PII) */
325
325
  id: z.string().min(1).max(256),
326
- /** Proof type from DD-143 multi-root vocabulary */
326
+ /** Proof type from multi-root vocabulary */
327
327
  proof_type: ProofTypeSchema,
328
328
  /** URI or hash of external proof artifact */
329
329
  proof_ref: z.string().max(2048).optional(),
@@ -331,7 +331,7 @@ var ActorBindingSchema = z.object({
331
331
  origin: z.string().max(2048).refine(isOriginOnly, {
332
332
  message: "origin must be an origin-only URL (scheme + host + optional port; no path, query, or fragment)"
333
333
  }),
334
- /** SHA-256 hash of the intent (hash-first per DD-138) */
334
+ /** SHA-256 hash of the intent (hash-first per ) */
335
335
  intent_hash: z.string().regex(/^sha256:[a-f0-9]{64}$/, {
336
336
  message: "intent_hash must match sha256:<64 hex chars>"
337
337
  }).optional()
@@ -457,8 +457,52 @@ var EXTENSION_LIMITS = {
457
457
  maxSpanIdLength: 16,
458
458
  maxWorkflowIdLength: 256,
459
459
  maxParentJtiLength: 256,
460
- maxDependsOnLength: 64
461
- };
460
+ maxDependsOnLength: 64,
461
+ // Consent
462
+ maxConsentBasisLength: 128,
463
+ maxConsentMethodLength: 128,
464
+ maxDataCategoriesCount: 64,
465
+ maxDataCategoryLength: 128,
466
+ maxConsentScopeLength: 256,
467
+ maxJurisdictionLength: 16,
468
+ // Compliance
469
+ maxFrameworkLength: 256,
470
+ maxAuditRefLength: 256,
471
+ maxAuditorLength: 256,
472
+ maxComplianceScopeLength: 512,
473
+ // Privacy
474
+ maxDataClassificationLength: 128,
475
+ maxProcessingBasisLength: 128,
476
+ maxAnonymizationMethodLength: 128,
477
+ maxDataSubjectCategoryLength: 128,
478
+ maxTransferMechanismLength: 128,
479
+ // Safety
480
+ maxAssessmentMethodLength: 256,
481
+ maxSafetyMeasuresCount: 32,
482
+ maxSafetyMeasureLength: 256,
483
+ maxIncidentRefLength: 256,
484
+ maxModelRefLength: 256,
485
+ maxSafetyCategoryLength: 128,
486
+ // Provenance
487
+ maxSourceTypeLength: 128,
488
+ maxSourceRefLength: 256,
489
+ maxVerificationMethodLength: 128,
490
+ maxCustodyChainCount: 16,
491
+ maxCustodianLength: 256,
492
+ maxCustodyActionLength: 128,
493
+ maxSlsaTrackLength: 64,
494
+ maxSlsaVersionLength: 16,
495
+ // Attribution
496
+ maxCreatorRefLength: 256,
497
+ maxObligationTypeLength: 128,
498
+ maxAttributionTextLength: 1024,
499
+ // Purpose
500
+ maxExternalPurposesCount: 32,
501
+ maxExternalPurposeLength: 128,
502
+ maxPurposeBasisLength: 128,
503
+ maxCompatiblePurposesCount: 32};
504
+
505
+ // src/wire-02-extensions/grammar.ts
462
506
  var DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
463
507
  var SEGMENT_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
464
508
  function isValidExtensionKey(key) {
@@ -479,10 +523,6 @@ function isValidExtensionKey(key) {
479
523
  return true;
480
524
  }
481
525
  var COMMERCE_EXTENSION_KEY = "org.peacprotocol/commerce";
482
- var ACCESS_EXTENSION_KEY = "org.peacprotocol/access";
483
- var CHALLENGE_EXTENSION_KEY = "org.peacprotocol/challenge";
484
- var IDENTITY_EXTENSION_KEY = "org.peacprotocol/identity";
485
- var CORRELATION_EXTENSION_KEY = "org.peacprotocol/correlation";
486
526
  var AMOUNT_MINOR_PATTERN = /^-?[0-9]+$/;
487
527
  var CommerceExtensionSchema = z.object({
488
528
  /** Payment rail identifier (e.g., 'stripe', 'x402', 'lightning') */
@@ -503,8 +543,11 @@ var CommerceExtensionSchema = z.object({
503
543
  /** Asset identifier for non-fiat (e.g., token address) */
504
544
  asset: z.string().max(EXTENSION_LIMITS.maxAssetLength).optional(),
505
545
  /** Environment discriminant */
506
- env: z.enum(["live", "test"]).optional()
546
+ env: z.enum(["live", "test"]).optional(),
547
+ /** Commerce lifecycle phase. Observational metadata only: does not encode settlement finality or protocol state transitions */
548
+ event: z.enum(["authorization", "capture", "settlement", "refund", "void", "chargeback"]).optional()
507
549
  }).strict();
550
+ var ACCESS_EXTENSION_KEY = "org.peacprotocol/access";
508
551
  var AccessExtensionSchema = z.object({
509
552
  /** Resource being accessed (URI or identifier) */
510
553
  resource: z.string().min(1).max(EXTENSION_LIMITS.maxResourceLength),
@@ -513,6 +556,7 @@ var AccessExtensionSchema = z.object({
513
556
  /** Access decision */
514
557
  decision: z.enum(["allow", "deny", "review"])
515
558
  }).strict();
559
+ var CHALLENGE_EXTENSION_KEY = "org.peacprotocol/challenge";
516
560
  var CHALLENGE_TYPES = [
517
561
  "payment_required",
518
562
  "identity_required",
@@ -547,10 +591,12 @@ var ChallengeExtensionSchema = z.object({
547
591
  /** Caller-defined requirements for resolving the challenge */
548
592
  requirements: z.record(z.string(), z.unknown()).optional()
549
593
  }).strict();
594
+ var IDENTITY_EXTENSION_KEY = "org.peacprotocol/identity";
550
595
  var IdentityExtensionSchema = z.object({
551
596
  /** Proof reference (opaque string; no actor_binding: top-level actor is sole location) */
552
597
  proof_ref: z.string().max(EXTENSION_LIMITS.maxProofRefLength).optional()
553
598
  }).strict();
599
+ var CORRELATION_EXTENSION_KEY = "org.peacprotocol/correlation";
554
600
  var TRACE_ID_PATTERN = /^[0-9a-f]{32}$/;
555
601
  var SPAN_ID_PATTERN = /^[0-9a-f]{16}$/;
556
602
  var CorrelationExtensionSchema = z.object({
@@ -565,15 +611,554 @@ var CorrelationExtensionSchema = z.object({
565
611
  /** JTIs this receipt depends on */
566
612
  depends_on: z.array(z.string().min(1).max(EXTENSION_LIMITS.maxParentJtiLength)).max(EXTENSION_LIMITS.maxDependsOnLength).optional()
567
613
  }).strict();
614
+ var Sha256DigestSchema = z.string().max(71).regex(HASH.pattern, "must be a valid SHA-256 digest (sha256:<64 lowercase hex>)");
615
+ var CONTROL_CHAR_PATTERN = /[\x00-\x1f\x7f]/;
616
+ var HttpsUriHintSchema = z.string().min(1).max(2048).refine(
617
+ (value) => {
618
+ if (CONTROL_CHAR_PATTERN.test(value)) return false;
619
+ if (value.includes("#")) return false;
620
+ try {
621
+ const url = new URL(value);
622
+ if (url.protocol !== "https:") return false;
623
+ if (url.username !== "" || url.password !== "") return false;
624
+ if (!url.hostname) return false;
625
+ return true;
626
+ } catch {
627
+ return false;
628
+ }
629
+ },
630
+ {
631
+ message: "must be a valid HTTPS URI (no credentials, no fragments, no control characters)"
632
+ }
633
+ );
634
+ var DATE_DESIGNATOR_ORDER = ["Y", "M", "W", "D"];
635
+ var TIME_DESIGNATOR_ORDER = ["H", "M", "S"];
636
+ function parseIso8601Duration(value) {
637
+ if (typeof value !== "string" || value.length === 0 || value.length > 64) {
638
+ return null;
639
+ }
640
+ if (value.charAt(0) !== "P") return null;
641
+ let pos = 1;
642
+ const len = value.length;
643
+ if (pos >= len) return null;
644
+ const result = {
645
+ years: 0,
646
+ months: 0,
647
+ weeks: 0,
648
+ days: 0,
649
+ hours: 0,
650
+ minutes: 0,
651
+ seconds: 0
652
+ };
653
+ let inTimePart = false;
654
+ let hasAnyComponent = false;
655
+ const seenDesignators = /* @__PURE__ */ new Set();
656
+ let dateOrderIdx = 0;
657
+ let timeOrderIdx = 0;
658
+ while (pos < len) {
659
+ if (value.charAt(pos) === "T") {
660
+ if (inTimePart) return null;
661
+ inTimePart = true;
662
+ pos++;
663
+ if (pos >= len) return null;
664
+ continue;
665
+ }
666
+ const numStart = pos;
667
+ while (pos < len && value.charAt(pos) >= "0" && value.charAt(pos) <= "9") {
668
+ pos++;
669
+ }
670
+ if (pos === numStart) return null;
671
+ const digits = value.slice(numStart, pos);
672
+ if (digits.length > 15) return null;
673
+ const num = parseInt(digits, 10);
674
+ if (!Number.isFinite(num) || num < 0) return null;
675
+ if (pos >= len) return null;
676
+ const designator = value.charAt(pos);
677
+ pos++;
678
+ const designatorKey = (inTimePart ? "T" : "") + designator;
679
+ if (seenDesignators.has(designatorKey)) return null;
680
+ seenDesignators.add(designatorKey);
681
+ if (inTimePart) {
682
+ const timeIdx = TIME_DESIGNATOR_ORDER.indexOf(designator);
683
+ if (timeIdx === -1) return null;
684
+ if (timeIdx < timeOrderIdx) return null;
685
+ timeOrderIdx = timeIdx + 1;
686
+ switch (designator) {
687
+ case "H":
688
+ result.hours = num;
689
+ break;
690
+ case "M":
691
+ result.minutes = num;
692
+ break;
693
+ case "S":
694
+ result.seconds = num;
695
+ break;
696
+ }
697
+ } else {
698
+ const dateIdx = DATE_DESIGNATOR_ORDER.indexOf(designator);
699
+ if (dateIdx === -1) return null;
700
+ if (dateIdx < dateOrderIdx) return null;
701
+ dateOrderIdx = dateIdx + 1;
702
+ switch (designator) {
703
+ case "Y":
704
+ result.years = num;
705
+ break;
706
+ case "M":
707
+ result.months = num;
708
+ break;
709
+ case "W":
710
+ result.weeks = num;
711
+ break;
712
+ case "D":
713
+ result.days = num;
714
+ break;
715
+ }
716
+ }
717
+ hasAnyComponent = true;
718
+ }
719
+ if (!hasAnyComponent) return null;
720
+ if (result.weeks > 0 && (result.years > 0 || result.months > 0 || result.days > 0)) {
721
+ return null;
722
+ }
723
+ return result;
724
+ }
725
+ var Iso8601DurationSchema = z.string().min(2).max(64).refine((value) => parseIso8601Duration(value) !== null, {
726
+ message: "must be a valid ISO 8601 duration (e.g., P30D, P1Y6M, PT1H30M)"
727
+ });
728
+ var Iso8601DateStringSchema = z.string().length(10).regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/, {
729
+ message: "must be a structurally valid date string (YYYY-MM-DD)"
730
+ });
731
+ z.iso.datetime({ offset: true });
732
+ var RFC3339_SECONDS_PATTERN = /T\d{2}:\d{2}:\d{2}/;
733
+ var Rfc3339DateTimeSchema = z.iso.datetime({ offset: true }).refine((value) => RFC3339_SECONDS_PATTERN.test(value), {
734
+ message: "RFC 3339 requires seconds precision (e.g., 2026-03-14T12:00:00Z)"
735
+ });
736
+ function isValidSpdxSubsetExpression(expr) {
737
+ if (typeof expr !== "string" || expr.length === 0 || expr.length > 128) {
738
+ return false;
739
+ }
740
+ const tokens = [];
741
+ let current = "";
742
+ for (let i = 0; i < expr.length; i++) {
743
+ const ch = expr.charAt(i);
744
+ if (ch === "(" || ch === ")") {
745
+ if (current.length > 0) {
746
+ tokens.push(current);
747
+ current = "";
748
+ }
749
+ tokens.push(ch);
750
+ } else if (ch === " " || ch === " ") {
751
+ if (current.length > 0) {
752
+ tokens.push(current);
753
+ current = "";
754
+ }
755
+ } else {
756
+ current += ch;
757
+ }
758
+ }
759
+ if (current.length > 0) {
760
+ tokens.push(current);
761
+ }
762
+ if (tokens.length === 0) return false;
763
+ let pos = 0;
764
+ function peek() {
765
+ return tokens[pos];
766
+ }
767
+ function advance() {
768
+ return tokens[pos++];
769
+ }
770
+ function isLicenseId(token) {
771
+ const base = token.endsWith("+") ? token.slice(0, -1) : token;
772
+ if (base.length === 0) return false;
773
+ if (base.startsWith("LicenseRef-")) {
774
+ const ref = base.slice(11);
775
+ return ref.length > 0 && /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(ref);
776
+ }
777
+ return /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(base);
778
+ }
779
+ function isExceptionId(token) {
780
+ return /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(token);
781
+ }
782
+ function parseExpr() {
783
+ if (!parseTerm()) return false;
784
+ while (pos < tokens.length) {
785
+ const op = peek();
786
+ if (op === "AND" || op === "OR") {
787
+ advance();
788
+ if (!parseTerm()) return false;
789
+ } else {
790
+ break;
791
+ }
792
+ }
793
+ return true;
794
+ }
795
+ function parseTerm() {
796
+ if (!parseAtom()) return false;
797
+ if (peek() === "WITH") {
798
+ advance();
799
+ const exception = peek();
800
+ if (exception === void 0 || !isExceptionId(exception)) return false;
801
+ advance();
802
+ }
803
+ return true;
804
+ }
805
+ function parseAtom() {
806
+ const token = peek();
807
+ if (token === void 0) return false;
808
+ if (token === "(") {
809
+ advance();
810
+ if (!parseExpr()) return false;
811
+ if (peek() !== ")") return false;
812
+ advance();
813
+ return true;
814
+ }
815
+ if (token === ")" || token === "AND" || token === "OR" || token === "WITH") {
816
+ return false;
817
+ }
818
+ if (!isLicenseId(token)) return false;
819
+ advance();
820
+ return true;
821
+ }
822
+ const result = parseExpr();
823
+ return result && pos === tokens.length;
824
+ }
825
+ var SpdxExpressionSchema = z.string().min(1).max(128).refine(isValidSpdxSubsetExpression, {
826
+ message: "must be a valid SPDX license expression (e.g., MIT, Apache-2.0, MIT AND Apache-2.0). DocumentRef-* not yet supported."
827
+ });
828
+
829
+ // src/wire-02-extensions/consent.ts
830
+ var CONSENT_EXTENSION_KEY = "org.peacprotocol/consent";
831
+ var CONSENT_STATUSES = ["granted", "withdrawn", "denied", "expired"];
832
+ var ConsentStatusSchema = z.enum(CONSENT_STATUSES);
833
+ var ConsentExtensionSchema = z.object({
834
+ /**
835
+ * Legal basis identifier for consent.
836
+ * Open string: jurisdictions define different bases
837
+ * (e.g., explicit, implied, opt_out, legitimate_interest, contractual, legal_obligation).
838
+ */
839
+ consent_basis: z.string().min(1).max(EXTENSION_LIMITS.maxConsentBasisLength),
840
+ /** Consent lifecycle state (closed vocabulary) */
841
+ consent_status: ConsentStatusSchema,
842
+ /**
843
+ * Data categories covered by this consent.
844
+ * Open vocabulary (e.g., personal, sensitive, biometric).
845
+ */
846
+ data_categories: z.array(z.string().min(1).max(EXTENSION_LIMITS.maxDataCategoryLength)).max(EXTENSION_LIMITS.maxDataCategoriesCount).optional(),
847
+ /** Data retention period as ISO 8601 duration. */
848
+ retention_period: Iso8601DurationSchema.optional(),
849
+ /**
850
+ * How consent was collected.
851
+ * Open vocabulary (e.g., click_through, double_opt_in, verbal, written).
852
+ */
853
+ consent_method: z.string().min(1).max(EXTENSION_LIMITS.maxConsentMethodLength).optional(),
854
+ /**
855
+ * HTTPS URI hint for consent withdrawal.
856
+ * Locator hint only: callers MUST NOT auto-fetch.
857
+ * Rejects non-HTTPS, embedded credentials, fragments, control chars.
858
+ */
859
+ withdrawal_uri: HttpsUriHintSchema.optional(),
860
+ /** Free-text scope description */
861
+ scope: z.string().min(1).max(EXTENSION_LIMITS.maxConsentScopeLength).optional(),
862
+ /**
863
+ * Jurisdiction code: ISO 3166-1 alpha-2 or composite.
864
+ * Examples: EU, US-CA, BR, GB, DE, JP, IN.
865
+ */
866
+ jurisdiction: z.string().min(1).max(EXTENSION_LIMITS.maxJurisdictionLength).optional()
867
+ }).strict();
868
+ var PRIVACY_EXTENSION_KEY = "org.peacprotocol/privacy";
869
+ var RETENTION_MODES = ["time_bound", "indefinite", "session_only"];
870
+ var RetentionModeSchema = z.enum(RETENTION_MODES);
871
+ var RECIPIENT_SCOPES = ["internal", "processor", "third_party", "public"];
872
+ var RecipientScopeSchema = z.enum(RECIPIENT_SCOPES);
873
+ var PrivacyExtensionSchema = z.object({
874
+ /**
875
+ * Data classification level.
876
+ * Open taxonomy (e.g., public, internal, confidential, restricted, pii, sensitive_pii).
877
+ */
878
+ data_classification: z.string().min(1).max(EXTENSION_LIMITS.maxDataClassificationLength),
879
+ /**
880
+ * Legal basis for data processing.
881
+ * Open vocabulary (e.g., consent, legitimate_interest, contract, legal_obligation).
882
+ */
883
+ processing_basis: z.string().min(1).max(EXTENSION_LIMITS.maxProcessingBasisLength).optional(),
884
+ /**
885
+ * Data retention period as ISO 8601 duration.
886
+ * For non-duration retention semantics, use retention_mode instead.
887
+ */
888
+ retention_period: Iso8601DurationSchema.optional(),
889
+ /**
890
+ * Retention mode for non-duration semantics.
891
+ * Closed enum: time_bound, indefinite, session_only.
892
+ * When time_bound, retention_period SHOULD also be present.
893
+ */
894
+ retention_mode: RetentionModeSchema.optional(),
895
+ /**
896
+ * Data recipient classification.
897
+ * Closed enum aligned with GDPR Art 13-14 disclosure categories.
898
+ */
899
+ recipient_scope: RecipientScopeSchema.optional(),
900
+ /**
901
+ * Anonymization or pseudonymization method applied.
902
+ * Open vocabulary (e.g., k_anonymity, differential_privacy, pseudonymization,
903
+ * tokenization, aggregation).
904
+ */
905
+ anonymization_method: z.string().min(1).max(EXTENSION_LIMITS.maxAnonymizationMethodLength).optional(),
906
+ /**
907
+ * Data subject category.
908
+ * Open vocabulary (e.g., customer, employee, minor, patient, student).
909
+ */
910
+ data_subject_category: z.string().min(1).max(EXTENSION_LIMITS.maxDataSubjectCategoryLength).optional(),
911
+ /**
912
+ * Cross-border data transfer mechanism.
913
+ * Open vocabulary (e.g., adequacy_decision, scc, bcr, derogation, consent).
914
+ */
915
+ transfer_mechanism: z.string().min(1).max(EXTENSION_LIMITS.maxTransferMechanismLength).optional()
916
+ }).strict();
917
+ var SAFETY_EXTENSION_KEY = "org.peacprotocol/safety";
918
+ var REVIEW_STATUSES = ["reviewed", "pending", "flagged", "not_applicable"];
919
+ var ReviewStatusSchema = z.enum(REVIEW_STATUSES);
920
+ var RISK_LEVELS = ["unacceptable", "high", "limited", "minimal"];
921
+ var RiskLevelSchema = z.enum(RISK_LEVELS);
922
+ var SafetyExtensionSchema = z.object({
923
+ /** Safety review status (closed vocabulary, universal lifecycle) */
924
+ review_status: ReviewStatusSchema,
925
+ /**
926
+ * Risk classification level.
927
+ * Optional at schema level; usage profiles may require it.
928
+ * Converges across EU AI Act Art 6, NIST AI RMF, ISO 23894.
929
+ */
930
+ risk_level: RiskLevelSchema.optional(),
931
+ /**
932
+ * Assessment method used.
933
+ * Open vocabulary (e.g., automated_scan, human_review, red_team,
934
+ * penetration_test, static_analysis, model_evaluation).
935
+ */
936
+ assessment_method: z.string().min(1).max(EXTENSION_LIMITS.maxAssessmentMethodLength).optional(),
937
+ /**
938
+ * Safety measures applied.
939
+ * Open vocabulary. Array bounded by maxSafetyMeasuresCount.
940
+ */
941
+ safety_measures: z.array(z.string().min(1).max(EXTENSION_LIMITS.maxSafetyMeasureLength)).max(EXTENSION_LIMITS.maxSafetyMeasuresCount).optional(),
942
+ /** Incident report reference. Opaque identifier (e.g., ticket ID or digest). */
943
+ incident_ref: z.string().min(1).max(EXTENSION_LIMITS.maxIncidentRefLength).optional(),
944
+ /** AI model reference. Opaque identifier (e.g., model version string). */
945
+ model_ref: z.string().min(1).max(EXTENSION_LIMITS.maxModelRefLength).optional(),
946
+ /**
947
+ * Safety category.
948
+ * Open vocabulary (e.g., content_safety, bias, hallucination,
949
+ * toxicity, fairness, robustness, privacy_risk).
950
+ */
951
+ category: z.string().min(1).max(EXTENSION_LIMITS.maxSafetyCategoryLength).optional()
952
+ }).strict();
953
+ var COMPLIANCE_EXTENSION_KEY = "org.peacprotocol/compliance";
954
+ var COMPLIANCE_STATUSES = [
955
+ "compliant",
956
+ "non_compliant",
957
+ "partial",
958
+ "under_review",
959
+ "exempt"
960
+ ];
961
+ var ComplianceStatusSchema = z.enum(COMPLIANCE_STATUSES);
962
+ var ComplianceExtensionSchema = z.object({
963
+ /**
964
+ * Framework identifier evaluated.
965
+ * Open string: preferred grammar is lowercase slugs with hyphens
966
+ * (e.g., eu-ai-act, soc2-type2, iso-27001, nist-ai-rmf, gdpr, hipaa).
967
+ */
968
+ framework: z.string().min(1).max(EXTENSION_LIMITS.maxFrameworkLength),
969
+ /** Observed compliance status (closed vocabulary) */
970
+ compliance_status: ComplianceStatusSchema,
971
+ /** Opaque reference to audit report or evidence (e.g., report ID, ticket number). */
972
+ audit_ref: z.string().min(1).max(EXTENSION_LIMITS.maxAuditRefLength).optional(),
973
+ /** Auditor identifier (organization name or DID). */
974
+ auditor: z.string().min(1).max(EXTENSION_LIMITS.maxAuditorLength).optional(),
975
+ /** Date the compliance check was performed (YYYY-MM-DD). */
976
+ audit_date: Iso8601DateStringSchema.optional(),
977
+ /** Scope of the compliance check. */
978
+ scope: z.string().min(1).max(EXTENSION_LIMITS.maxComplianceScopeLength).optional(),
979
+ /** How long this finding remains valid as an ISO 8601 duration. */
980
+ validity_period: Iso8601DurationSchema.optional(),
981
+ /** SHA-256 digest of supporting evidence document. */
982
+ evidence_ref: Sha256DigestSchema.optional()
983
+ }).strict();
984
+ var PROVENANCE_EXTENSION_KEY = "org.peacprotocol/provenance";
985
+ var CustodyEntrySchema = z.object({
986
+ /** Custodian identifier (organization name, DID, or opaque ID). */
987
+ custodian: z.string().min(1).max(EXTENSION_LIMITS.maxCustodianLength),
988
+ /** Action performed (e.g., received, transformed, verified, released). */
989
+ action: z.string().min(1).max(EXTENSION_LIMITS.maxCustodyActionLength),
990
+ /** When the custody event occurred (RFC 3339 with seconds). */
991
+ timestamp: Rfc3339DateTimeSchema
992
+ }).strict();
993
+ var SlsaLevelSchema = z.object({
994
+ /** SLSA track identifier (e.g., build, source). */
995
+ track: z.string().min(1).max(EXTENSION_LIMITS.maxSlsaTrackLength),
996
+ /** SLSA level within the track (0-4). */
997
+ level: z.number().int().min(0).max(4),
998
+ /** SLSA spec version this metadata references (e.g., 1.0, 1.2). */
999
+ version: z.string().min(1).max(EXTENSION_LIMITS.maxSlsaVersionLength)
1000
+ }).strict();
1001
+ var ProvenanceExtensionSchema = z.object({
1002
+ /**
1003
+ * Type of source or derivation.
1004
+ * Open vocabulary (e.g., original, derived, curated, synthetic, aggregated, transformed).
1005
+ */
1006
+ source_type: z.string().min(1).max(EXTENSION_LIMITS.maxSourceTypeLength),
1007
+ /** Opaque source reference identifier (e.g., commit hash, artifact ID). */
1008
+ source_ref: z.string().min(1).max(EXTENSION_LIMITS.maxSourceRefLength).optional(),
1009
+ /**
1010
+ * HTTPS URI hint for the source artifact.
1011
+ * Locator hint only: callers MUST NOT auto-fetch.
1012
+ */
1013
+ source_uri: HttpsUriHintSchema.optional(),
1014
+ /**
1015
+ * HTTPS URI hint for build provenance metadata.
1016
+ * Locator hint only: callers MUST NOT auto-fetch.
1017
+ */
1018
+ build_provenance_uri: HttpsUriHintSchema.optional(),
1019
+ /**
1020
+ * How provenance was verified.
1021
+ * Open vocabulary (e.g., signature_check, hash_chain,
1022
+ * manual_attestation, transparency_log).
1023
+ */
1024
+ verification_method: z.string().min(1).max(EXTENSION_LIMITS.maxVerificationMethodLength).optional(),
1025
+ /**
1026
+ * Ordered custody chain entries.
1027
+ * Each entry records a custodian, action, and timestamp.
1028
+ */
1029
+ custody_chain: z.array(CustodyEntrySchema).max(EXTENSION_LIMITS.maxCustodyChainCount).optional(),
1030
+ /**
1031
+ * Structured SLSA-aligned provenance metadata.
1032
+ * Records track, level, and spec version.
1033
+ */
1034
+ slsa: SlsaLevelSchema.optional()
1035
+ }).strict();
1036
+ var ATTRIBUTION_EXTENSION_KEY = "org.peacprotocol/attribution";
1037
+ var CONTENT_SIGNAL_SOURCES = [
1038
+ "tdmrep_json",
1039
+ "content_signal_header",
1040
+ "content_usage_header",
1041
+ "robots_txt",
1042
+ "custom"
1043
+ ];
1044
+ var ContentSignalSourceSchema = z.enum(CONTENT_SIGNAL_SOURCES);
1045
+ var AttributionExtensionSchema = z.object({
1046
+ /**
1047
+ * Creator identifier (DID, URI, or opaque ID).
1048
+ * Not an identity attestation; records observed attribution metadata.
1049
+ */
1050
+ creator_ref: z.string().min(1).max(EXTENSION_LIMITS.maxCreatorRefLength),
1051
+ /** SPDX license expression (parser-grade structural subset validator). */
1052
+ license_spdx: SpdxExpressionSchema.optional(),
1053
+ /**
1054
+ * Obligation type.
1055
+ * Open vocabulary (e.g., attribution_required, share_alike, non_commercial).
1056
+ */
1057
+ obligation_type: z.string().min(1).max(EXTENSION_LIMITS.maxObligationTypeLength).optional(),
1058
+ /** Required attribution text. */
1059
+ attribution_text: z.string().min(1).max(EXTENSION_LIMITS.maxAttributionTextLength).optional(),
1060
+ /** Content signal observation source (closed vocabulary). */
1061
+ content_signal_source: ContentSignalSourceSchema.optional(),
1062
+ /** SHA-256 digest of the attributed content. */
1063
+ content_digest: Sha256DigestSchema.optional()
1064
+ }).strict();
1065
+ var PURPOSE_EXTENSION_KEY = "org.peacprotocol/purpose";
1066
+ var MachineSafePurposeTokenSchema = z.string().min(1).max(EXTENSION_LIMITS.maxExternalPurposeLength).regex(PURPOSE_TOKEN_REGEX, "must be a machine-safe lowercase token");
1067
+ function hasUniqueItems(items) {
1068
+ return new Set(items).size === items.length;
1069
+ }
1070
+ var PurposeExtensionSchema = z.object({
1071
+ /**
1072
+ * External/legal/business purpose labels.
1073
+ * Machine-safe tokens: lowercase alphanumeric with underscores, hyphens,
1074
+ * and optional vendor prefix (e.g., ai_training, analytics, marketing).
1075
+ * Not PEAC operational tokens; use peac_purpose_mapping for bridging.
1076
+ * Items must be unique.
1077
+ */
1078
+ external_purposes: z.array(MachineSafePurposeTokenSchema).min(1).max(EXTENSION_LIMITS.maxExternalPurposesCount).refine(hasUniqueItems, { message: "external_purposes must contain unique items" }),
1079
+ /**
1080
+ * Legal or policy basis for the declared purposes.
1081
+ * Open vocabulary (e.g., consent, legitimate_interest, contract).
1082
+ */
1083
+ purpose_basis: z.string().min(1).max(EXTENSION_LIMITS.maxPurposeBasisLength).optional(),
1084
+ /** Whether purpose limitation applies. */
1085
+ purpose_limitation: z.boolean().optional(),
1086
+ /** Whether data minimization was applied. */
1087
+ data_minimization: z.boolean().optional(),
1088
+ /**
1089
+ * Compatible purposes for secondary use.
1090
+ * Same machine-safe token grammar as external_purposes.
1091
+ * Items must be unique.
1092
+ */
1093
+ compatible_purposes: z.array(MachineSafePurposeTokenSchema).max(EXTENSION_LIMITS.maxCompatiblePurposesCount).refine(hasUniqueItems, { message: "compatible_purposes must contain unique items" }).optional(),
1094
+ /**
1095
+ * Explicit mapping to a PEAC operational CanonicalPurpose token.
1096
+ * Validated against PURPOSE_TOKEN_REGEX from purpose.ts.
1097
+ * Bridges external purpose vocabulary to operational tokens.
1098
+ */
1099
+ peac_purpose_mapping: z.string().min(1).max(MAX_PURPOSE_TOKEN_LENGTH).regex(PURPOSE_TOKEN_REGEX, "must be a valid PEAC purpose token").optional()
1100
+ }).strict();
1101
+
1102
+ // src/wire-02-extensions/schema-map.ts
568
1103
  var EXTENSION_SCHEMA_MAP = /* @__PURE__ */ new Map();
569
1104
  EXTENSION_SCHEMA_MAP.set(COMMERCE_EXTENSION_KEY, CommerceExtensionSchema);
570
1105
  EXTENSION_SCHEMA_MAP.set(ACCESS_EXTENSION_KEY, AccessExtensionSchema);
571
1106
  EXTENSION_SCHEMA_MAP.set(CHALLENGE_EXTENSION_KEY, ChallengeExtensionSchema);
572
1107
  EXTENSION_SCHEMA_MAP.set(IDENTITY_EXTENSION_KEY, IdentityExtensionSchema);
573
1108
  EXTENSION_SCHEMA_MAP.set(CORRELATION_EXTENSION_KEY, CorrelationExtensionSchema);
1109
+ EXTENSION_SCHEMA_MAP.set(CONSENT_EXTENSION_KEY, ConsentExtensionSchema);
1110
+ EXTENSION_SCHEMA_MAP.set(PRIVACY_EXTENSION_KEY, PrivacyExtensionSchema);
1111
+ EXTENSION_SCHEMA_MAP.set(SAFETY_EXTENSION_KEY, SafetyExtensionSchema);
1112
+ EXTENSION_SCHEMA_MAP.set(COMPLIANCE_EXTENSION_KEY, ComplianceExtensionSchema);
1113
+ EXTENSION_SCHEMA_MAP.set(PROVENANCE_EXTENSION_KEY, ProvenanceExtensionSchema);
1114
+ EXTENSION_SCHEMA_MAP.set(ATTRIBUTION_EXTENSION_KEY, AttributionExtensionSchema);
1115
+ EXTENSION_SCHEMA_MAP.set(PURPOSE_EXTENSION_KEY, PurposeExtensionSchema);
1116
+
1117
+ // src/wire-02-extensions/validation.ts
1118
+ var textEncoder = new TextEncoder();
1119
+ function jsonUtf8ByteLength(value) {
1120
+ try {
1121
+ return textEncoder.encode(JSON.stringify(value)).byteLength;
1122
+ } catch {
1123
+ return Infinity;
1124
+ }
1125
+ }
1126
+ var MAX_JSON_GUARD_DEPTH = 64;
1127
+ function isPlainJsonValueRecursive(value, depth, seen) {
1128
+ if (depth > MAX_JSON_GUARD_DEPTH) return false;
1129
+ if (value === null) return true;
1130
+ const t = typeof value;
1131
+ if (t === "string" || t === "boolean") return true;
1132
+ if (t === "number") return Number.isFinite(value);
1133
+ if (t === "function" || t === "symbol" || t === "bigint" || t === "undefined") return false;
1134
+ if (t !== "object") return false;
1135
+ const obj = value;
1136
+ if (seen.has(obj)) return false;
1137
+ seen.add(obj);
1138
+ if (Array.isArray(obj)) {
1139
+ for (let i = 0; i < obj.length; i++) {
1140
+ if (!isPlainJsonValueRecursive(obj[i], depth + 1, seen)) return false;
1141
+ }
1142
+ return true;
1143
+ }
1144
+ const proto = Object.getPrototypeOf(obj);
1145
+ if (proto !== Object.prototype && proto !== null) return false;
1146
+ if (typeof obj.toJSON === "function") return false;
1147
+ const keys = Object.keys(obj);
1148
+ for (const key of keys) {
1149
+ if (!isPlainJsonValueRecursive(obj[key], depth + 1, seen)) {
1150
+ return false;
1151
+ }
1152
+ }
1153
+ return true;
1154
+ }
1155
+ function isPlainJsonValue(value) {
1156
+ return isPlainJsonValueRecursive(value, 0, /* @__PURE__ */ new WeakSet());
1157
+ }
574
1158
  function validateKnownExtensions(extensions, ctx) {
575
1159
  if (extensions === void 0) return;
576
- for (const key of Object.keys(extensions)) {
1160
+ const keys = Object.keys(extensions);
1161
+ for (const key of keys) {
577
1162
  if (!isValidExtensionKey(key)) {
578
1163
  ctx.addIssue({
579
1164
  code: "custom",
@@ -582,6 +1167,14 @@ function validateKnownExtensions(extensions, ctx) {
582
1167
  });
583
1168
  continue;
584
1169
  }
1170
+ if (!isPlainJsonValue(extensions[key])) {
1171
+ ctx.addIssue({
1172
+ code: "custom",
1173
+ message: ERROR_CODES$1.E_EXTENSION_NON_JSON_VALUE,
1174
+ path: ["extensions", key]
1175
+ });
1176
+ continue;
1177
+ }
585
1178
  const schema = EXTENSION_SCHEMA_MAP.get(key);
586
1179
  if (schema !== void 0) {
587
1180
  const result = schema.safeParse(extensions[key]);
@@ -596,6 +1189,25 @@ function validateKnownExtensions(extensions, ctx) {
596
1189
  }
597
1190
  }
598
1191
  }
1192
+ const totalBytes = jsonUtf8ByteLength(extensions);
1193
+ if (totalBytes > EXTENSION_BUDGET.maxTotalBytes) {
1194
+ ctx.addIssue({
1195
+ code: "custom",
1196
+ message: ERROR_CODES$1.E_EXTENSION_SIZE_EXCEEDED,
1197
+ path: ["extensions"]
1198
+ });
1199
+ return;
1200
+ }
1201
+ for (const key of keys) {
1202
+ const groupBytes = jsonUtf8ByteLength(extensions[key]);
1203
+ if (groupBytes > EXTENSION_BUDGET.maxGroupBytes) {
1204
+ ctx.addIssue({
1205
+ code: "custom",
1206
+ message: ERROR_CODES$1.E_EXTENSION_SIZE_EXCEEDED,
1207
+ path: ["extensions", key]
1208
+ });
1209
+ }
1210
+ }
599
1211
  }
600
1212
 
601
1213
  // src/wire-02-envelope.ts
@@ -673,7 +1285,7 @@ var PolicyBlockSchema = z.object({
673
1285
  /**
674
1286
  * HTTPS locator hint for the policy document.
675
1287
  * MUST be an https:// URL (max 2048 chars).
676
- * MUST NOT trigger auto-fetch; callers use this as a hint only (DD-55).
1288
+ * MUST NOT trigger auto-fetch; callers use this as a hint only.
677
1289
  */
678
1290
  uri: z.string().max(POLICY_BLOCK.uriMaxLength).url().refine((u) => u.startsWith("https://"), "policy.uri must be an https:// URL").optional(),
679
1291
  /** Caller-assigned version label (max 256 chars) */
@@ -698,9 +1310,9 @@ var Wire02ClaimsSchema = z.object({
698
1310
  pillars: PillarsSchema.optional(),
699
1311
  /** Top-level actor binding (sole location for ActorBinding in Wire 0.2) */
700
1312
  actor: ActorBindingSchema.optional(),
701
- /** Policy binding block (DD-151) */
1313
+ /** Policy binding block */
702
1314
  policy: PolicyBlockSchema.optional(),
703
- /** Representation fields (DD-152): FingerprintRef validation, sha256-only, strict */
1315
+ /** Representation fields: FingerprintRef validation, sha256-only, strict */
704
1316
  representation: Wire02RepresentationFieldsSchema.optional(),
705
1317
  /** ISO 8601 / RFC 3339 timestamp when the interaction occurred; evidence kind only */
706
1318
  occurred_at: z.string().datetime({ offset: true }).optional(),