@peac/schema 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Evidence Carrier Contract schemas and helpers (DD-124)
3
+ *
4
+ * Zod validation schemas for PeacEvidenceCarrier and CarrierMeta,
5
+ * plus the canonical computeReceiptRef() and validateCarrierConstraints()
6
+ * functions used by all carrier adapters.
7
+ */
8
+ import { z } from 'zod';
9
+ import type { CarrierMeta, CarrierValidationResult, PeacEvidenceCarrier, ReceiptRef } from '@peac/kernel';
10
+ /** Maximum carrier size per transport (DD-127) */
11
+ export declare const CARRIER_TRANSPORT_LIMITS: {
12
+ /** MCP _meta: 64 KB */
13
+ readonly mcp: 65536;
14
+ /** A2A metadata: 64 KB */
15
+ readonly a2a: 65536;
16
+ /** ACP embed in body: 64 KB; headers only: 8 KB */
17
+ readonly acp_embed: 65536;
18
+ readonly acp_headers: 8192;
19
+ /** UCP webhook body: 64 KB */
20
+ readonly ucp: 65536;
21
+ /** x402 embed in body: 64 KB; headers only: 8 KB */
22
+ readonly x402_embed: 65536;
23
+ readonly x402_headers: 8192;
24
+ /** HTTP headers only: 8 KB */
25
+ readonly http: 8192;
26
+ };
27
+ /** Validates a content-addressed receipt reference: sha256:<64 hex chars> */
28
+ export declare const ReceiptRefSchema: z.ZodString;
29
+ /** Validates a compact JWS: header.payload.signature (base64url parts) */
30
+ export declare const CompactJwsSchema: z.ZodString;
31
+ /** Carrier format schema */
32
+ export declare const CarrierFormatSchema: z.ZodEnum<{
33
+ embed: "embed";
34
+ reference: "reference";
35
+ }>;
36
+ /**
37
+ * Validates receipt_url: HTTPS-only, max 2048 chars, no credentials (DD-135).
38
+ * Validation only (DD-141): no I/O, no fetch. Resolution lives in Layer 4.
39
+ */
40
+ export declare const ReceiptUrlSchema: z.ZodString;
41
+ /** Schema for PeacEvidenceCarrier */
42
+ export declare const PeacEvidenceCarrierSchema: z.ZodObject<{
43
+ receipt_ref: z.ZodString;
44
+ receipt_jws: z.ZodOptional<z.ZodString>;
45
+ receipt_url: z.ZodOptional<z.ZodString>;
46
+ policy_binding: z.ZodOptional<z.ZodString>;
47
+ actor_binding: z.ZodOptional<z.ZodString>;
48
+ request_nonce: z.ZodOptional<z.ZodString>;
49
+ verification_report_ref: z.ZodOptional<z.ZodString>;
50
+ use_policy_ref: z.ZodOptional<z.ZodString>;
51
+ representation_ref: z.ZodOptional<z.ZodString>;
52
+ attestation_ref: z.ZodOptional<z.ZodString>;
53
+ }, z.core.$strip>;
54
+ /** Schema for CarrierMeta */
55
+ export declare const CarrierMetaSchema: z.ZodObject<{
56
+ transport: z.ZodString;
57
+ format: z.ZodEnum<{
58
+ embed: "embed";
59
+ reference: "reference";
60
+ }>;
61
+ max_size: z.ZodNumber;
62
+ redaction: z.ZodOptional<z.ZodArray<z.ZodString>>;
63
+ }, z.core.$strip>;
64
+ /**
65
+ * Canonical receipt_ref computation (single source of truth).
66
+ *
67
+ * Computes SHA-256 of the UTF-8 bytes of the compact JWS string as emitted.
68
+ * All carrier adapters MUST use this function rather than computing SHA-256
69
+ * locally, to ensure consistency across protocols (correction item 4).
70
+ */
71
+ export declare function computeReceiptRef(jws: string): Promise<ReceiptRef>;
72
+ /**
73
+ * Canonical carrier constraint validator (DD-127, DD-129, DD-131).
74
+ *
75
+ * Validates a carrier against transport-specific constraints using
76
+ * the provided CarrierMeta. This is the single validation function
77
+ * that all CarrierAdapter.validateConstraints() implementations delegate to.
78
+ *
79
+ * Checks performed:
80
+ * 1. receipt_ref format (sha256:<hex64>)
81
+ * 2. receipt_jws format (if present): valid compact JWS
82
+ * 3. Total serialized size within meta.max_size
83
+ * 4. If receipt_jws present: receipt_ref consistency (DD-129)
84
+ * 5. All string fields within MAX_STRING_LENGTH
85
+ */
86
+ export declare function validateCarrierConstraints(carrier: PeacEvidenceCarrier, meta: CarrierMeta): CarrierValidationResult;
87
+ /**
88
+ * Verify receipt_ref consistency with receipt_jws (DD-129).
89
+ *
90
+ * If both receipt_ref and receipt_jws are present, verifies that
91
+ * sha256(receipt_jws) equals receipt_ref. This prevents carrier
92
+ * tampering after attachment.
93
+ *
94
+ * Returns null if consistent or receipt_jws is absent;
95
+ * returns an error string if inconsistent.
96
+ */
97
+ export declare function verifyReceiptRefConsistency(carrier: PeacEvidenceCarrier): Promise<string | null>;
98
+ export type { CarrierFormat, CarrierMeta, CarrierValidationResult, PeacEvidenceCarrier, ReceiptRef, CarrierAdapter, } from '@peac/kernel';
99
+ //# sourceMappingURL=carrier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carrier.d.ts","sourceRoot":"","sources":["../src/carrier.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAEV,WAAW,EACX,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,EACX,MAAM,cAAc,CAAC;AAQtB,kDAAkD;AAClD,eAAO,MAAM,wBAAwB;IACnC,uBAAuB;;IAEvB,0BAA0B;;IAE1B,mDAAmD;;;IAGnD,8BAA8B;;IAE9B,oDAAoD;;;IAGpD,8BAA8B;;CAEtB,CAAC;AAMX,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB,aAEiD,CAAC;AAE/E,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,aAK1B,CAAC;AAEJ,4BAA4B;AAC5B,eAAO,MAAM,mBAAmB;;;EAAiC,CAAC;AAElE;;;GAGG;AACH,eAAO,MAAM,gBAAgB,aAmB1B,CAAC;AAEJ,qCAAqC;AACrC,eAAO,MAAM,yBAAyB;;;;;;;;;;;iBAWpC,CAAC;AAEH,6BAA6B;AAC7B,eAAO,MAAM,iBAAiB;;;;;;;;iBAK5B,CAAC;AAMH;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAaxE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,WAAW,GAChB,uBAAuB,CAwDzB;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASxB;AAMD,YAAY,EACV,aAAa,EACb,WAAW,EACX,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,EACV,cAAc,GACf,MAAM,cAAc,CAAC"}
package/dist/index.cjs CHANGED
@@ -1872,7 +1872,8 @@ var WELL_KNOWN_KINDS = [
1872
1872
  "http.request",
1873
1873
  "fs.read",
1874
1874
  "fs.write",
1875
- "message"
1875
+ "message",
1876
+ "inference.chat_completion"
1876
1877
  ];
1877
1878
  var RESERVED_KIND_PREFIXES = ["peac.", "org.peacprotocol."];
1878
1879
  var INTERACTION_LIMITS = {
@@ -2650,6 +2651,127 @@ function isAttestationOnly(claims) {
2650
2651
  function isPaymentReceipt(claims) {
2651
2652
  return "amt" in claims && "cur" in claims && "payment" in claims;
2652
2653
  }
2654
+ var CARRIER_TRANSPORT_LIMITS = {
2655
+ /** MCP _meta: 64 KB */
2656
+ mcp: 65536,
2657
+ /** A2A metadata: 64 KB */
2658
+ a2a: 65536,
2659
+ /** ACP embed in body: 64 KB; headers only: 8 KB */
2660
+ acp_embed: 65536,
2661
+ acp_headers: 8192,
2662
+ /** UCP webhook body: 64 KB */
2663
+ ucp: 65536,
2664
+ /** x402 embed in body: 64 KB; headers only: 8 KB */
2665
+ x402_embed: 65536,
2666
+ x402_headers: 8192,
2667
+ /** HTTP headers only: 8 KB */
2668
+ http: 8192
2669
+ };
2670
+ var ReceiptRefSchema2 = zod.z.string().regex(/^sha256:[a-f0-9]{64}$/, "receipt_ref must be sha256:<64 hex chars>");
2671
+ var CompactJwsSchema = zod.z.string().regex(
2672
+ /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
2673
+ "receipt_jws must be a valid compact JWS (header.payload.signature)"
2674
+ );
2675
+ var CarrierFormatSchema = zod.z.enum(["embed", "reference"]);
2676
+ var ReceiptUrlSchema = zod.z.string().url().max(2048).refine((url) => url.startsWith("https://"), {
2677
+ message: "receipt_url must use HTTPS scheme"
2678
+ }).refine(
2679
+ (url) => {
2680
+ try {
2681
+ const parsed = new URL(url);
2682
+ return !parsed.username && !parsed.password;
2683
+ } catch {
2684
+ return false;
2685
+ }
2686
+ },
2687
+ {
2688
+ message: "receipt_url must not contain credentials"
2689
+ }
2690
+ );
2691
+ var PeacEvidenceCarrierSchema = zod.z.object({
2692
+ receipt_ref: ReceiptRefSchema2,
2693
+ receipt_jws: CompactJwsSchema.optional(),
2694
+ receipt_url: ReceiptUrlSchema.optional(),
2695
+ policy_binding: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
2696
+ actor_binding: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
2697
+ request_nonce: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
2698
+ verification_report_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
2699
+ use_policy_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
2700
+ representation_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
2701
+ attestation_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional()
2702
+ });
2703
+ var CarrierMetaSchema = zod.z.object({
2704
+ transport: zod.z.string().min(1),
2705
+ format: CarrierFormatSchema,
2706
+ max_size: zod.z.number().int().positive(),
2707
+ redaction: zod.z.array(zod.z.string()).optional()
2708
+ });
2709
+ async function computeReceiptRef(jws) {
2710
+ if (!globalThis.crypto?.subtle) {
2711
+ throw new Error(
2712
+ "computeReceiptRef requires WebCrypto (crypto.subtle). Supported runtimes: Node >= 20, Cloudflare Workers, Deno, Bun."
2713
+ );
2714
+ }
2715
+ const data = new TextEncoder().encode(jws);
2716
+ const hash = await globalThis.crypto.subtle.digest("SHA-256", data);
2717
+ const hex = Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
2718
+ return `sha256:${hex}`;
2719
+ }
2720
+ function validateCarrierConstraints(carrier, meta) {
2721
+ const violations = [];
2722
+ const refResult = ReceiptRefSchema2.safeParse(carrier.receipt_ref);
2723
+ if (!refResult.success) {
2724
+ violations.push(`invalid receipt_ref format: ${carrier.receipt_ref}`);
2725
+ }
2726
+ if (carrier.receipt_jws !== void 0) {
2727
+ const jwsResult = CompactJwsSchema.safeParse(carrier.receipt_jws);
2728
+ if (!jwsResult.success) {
2729
+ violations.push("invalid receipt_jws format: not a valid compact JWS");
2730
+ }
2731
+ }
2732
+ const serialized = JSON.stringify(carrier);
2733
+ const sizeBytes = new TextEncoder().encode(serialized).byteLength;
2734
+ if (sizeBytes > meta.max_size) {
2735
+ violations.push(
2736
+ `carrier size ${sizeBytes} bytes exceeds transport limit ${meta.max_size} bytes for ${meta.transport}`
2737
+ );
2738
+ }
2739
+ if (carrier.receipt_url !== void 0) {
2740
+ const urlResult = ReceiptUrlSchema.safeParse(carrier.receipt_url);
2741
+ if (!urlResult.success) {
2742
+ for (const issue of urlResult.error.issues) {
2743
+ violations.push(`invalid receipt_url: ${issue.message}`);
2744
+ }
2745
+ }
2746
+ }
2747
+ const stringFields = [
2748
+ ["policy_binding", carrier.policy_binding],
2749
+ ["actor_binding", carrier.actor_binding],
2750
+ ["request_nonce", carrier.request_nonce],
2751
+ ["verification_report_ref", carrier.verification_report_ref],
2752
+ ["use_policy_ref", carrier.use_policy_ref],
2753
+ ["representation_ref", carrier.representation_ref],
2754
+ ["attestation_ref", carrier.attestation_ref]
2755
+ ];
2756
+ for (const [name, value] of stringFields) {
2757
+ if (value !== void 0 && value.length > KERNEL_CONSTRAINTS.MAX_STRING_LENGTH) {
2758
+ violations.push(
2759
+ `${name} length ${value.length} exceeds MAX_STRING_LENGTH ${KERNEL_CONSTRAINTS.MAX_STRING_LENGTH}`
2760
+ );
2761
+ }
2762
+ }
2763
+ return { valid: violations.length === 0, violations };
2764
+ }
2765
+ async function verifyReceiptRefConsistency(carrier) {
2766
+ if (carrier.receipt_jws === void 0) {
2767
+ return null;
2768
+ }
2769
+ const computed = await computeReceiptRef(carrier.receipt_jws);
2770
+ if (computed !== carrier.receipt_ref) {
2771
+ return `receipt_ref mismatch: expected ${computed}, got ${carrier.receipt_ref}`;
2772
+ }
2773
+ return null;
2774
+ }
2653
2775
 
2654
2776
  // src/receipt-parser.ts
2655
2777
  function classifyReceipt(obj) {
@@ -2727,10 +2849,14 @@ exports.AttributionUsageSchema = AttributionUsageSchema;
2727
2849
  exports.BindingDetailsSchema = BindingDetailsSchema;
2728
2850
  exports.CANONICAL_DIGEST_ALGS = CANONICAL_DIGEST_ALGS;
2729
2851
  exports.CANONICAL_PURPOSES = CANONICAL_PURPOSES;
2852
+ exports.CARRIER_TRANSPORT_LIMITS = CARRIER_TRANSPORT_LIMITS;
2730
2853
  exports.CONTRIBUTION_TYPES = CONTRIBUTION_TYPES;
2731
2854
  exports.CONTROL_TYPES = CONTROL_TYPES;
2732
2855
  exports.CREDIT_METHODS = CREDIT_METHODS;
2733
2856
  exports.CanonicalPurposeSchema = CanonicalPurposeSchema;
2857
+ exports.CarrierFormatSchema = CarrierFormatSchema;
2858
+ exports.CarrierMetaSchema = CarrierMetaSchema;
2859
+ exports.CompactJwsSchema = CompactJwsSchema;
2734
2860
  exports.ContactMethodSchema = ContactMethodSchema;
2735
2861
  exports.ContentHashSchema = ContentHashSchema;
2736
2862
  exports.ContributionObligationSchema = ContributionObligationSchema;
@@ -2823,6 +2949,7 @@ exports.PayloadRefSchema = PayloadRefSchema;
2823
2949
  exports.PaymentEvidenceSchema = PaymentEvidenceSchema;
2824
2950
  exports.PaymentRoutingSchema = PaymentRoutingSchema;
2825
2951
  exports.PaymentSplitSchema = PaymentSplitSchema;
2952
+ exports.PeacEvidenceCarrierSchema = PeacEvidenceCarrierSchema;
2826
2953
  exports.PolicyContextSchema = PolicyContextSchema;
2827
2954
  exports.ProofMethodSchema = ProofMethodSchema;
2828
2955
  exports.PurposeReasonSchema = PurposeReasonSchema;
@@ -2833,6 +2960,8 @@ exports.RESERVED_KIND_PREFIXES = RESERVED_KIND_PREFIXES;
2833
2960
  exports.RESULT_STATUSES = RESULT_STATUSES;
2834
2961
  exports.ReceiptClaims = ReceiptClaims;
2835
2962
  exports.ReceiptClaimsSchema = ReceiptClaimsSchema;
2963
+ exports.ReceiptRefSchema = ReceiptRefSchema2;
2964
+ exports.ReceiptUrlSchema = ReceiptUrlSchema;
2836
2965
  exports.RefsSchema = RefsSchema;
2837
2966
  exports.RemediationSchema = RemediationSchema;
2838
2967
  exports.RemediationTypeSchema = RemediationTypeSchema;
@@ -2861,6 +2990,7 @@ exports.WorkflowSummaryAttestationSchema = WorkflowSummaryAttestationSchema;
2861
2990
  exports.WorkflowSummaryEvidenceSchema = WorkflowSummaryEvidenceSchema;
2862
2991
  exports.assertJsonSafeIterative = assertJsonSafeIterative;
2863
2992
  exports.canTransitionTo = canTransitionTo;
2993
+ exports.computeReceiptRef = computeReceiptRef;
2864
2994
  exports.computeTotalWeight = computeTotalWeight;
2865
2995
  exports.createAgentIdentityAttestation = createAgentIdentityAttestation;
2866
2996
  exports.createAttestationReceiptClaims = createAttestationReceiptClaims;
@@ -2930,6 +3060,7 @@ exports.validateAgentIdentityAttestation = validateAgentIdentityAttestation;
2930
3060
  exports.validateAttestationReceiptClaims = validateAttestationReceiptClaims;
2931
3061
  exports.validateAttributionAttestation = validateAttributionAttestation;
2932
3062
  exports.validateAttributionSource = validateAttributionSource;
3063
+ exports.validateCarrierConstraints = validateCarrierConstraints;
2933
3064
  exports.validateContentHash = validateContentHash;
2934
3065
  exports.validateContributionObligation = validateContributionObligation;
2935
3066
  exports.validateCreditObligation = validateCreditObligation;
@@ -2949,5 +3080,6 @@ exports.validateSubjectSnapshot = validateSubjectSnapshot;
2949
3080
  exports.validateWorkflowContext = validateWorkflowContext;
2950
3081
  exports.validateWorkflowContextOrdered = validateWorkflowContextOrdered;
2951
3082
  exports.validateWorkflowSummaryAttestation = validateWorkflowSummaryAttestation;
3083
+ exports.verifyReceiptRefConsistency = verifyReceiptRefConsistency;
2952
3084
  //# sourceMappingURL=index.cjs.map
2953
3085
  //# sourceMappingURL=index.cjs.map