@peac/schema 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/carrier.d.ts +93 -0
- package/dist/carrier.d.ts.map +1 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +98 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
/** Schema for PeacEvidenceCarrier */
|
|
37
|
+
export declare const PeacEvidenceCarrierSchema: z.ZodObject<{
|
|
38
|
+
receipt_ref: z.ZodString;
|
|
39
|
+
receipt_jws: z.ZodOptional<z.ZodString>;
|
|
40
|
+
policy_binding: z.ZodOptional<z.ZodString>;
|
|
41
|
+
actor_binding: z.ZodOptional<z.ZodString>;
|
|
42
|
+
request_nonce: z.ZodOptional<z.ZodString>;
|
|
43
|
+
verification_report_ref: z.ZodOptional<z.ZodString>;
|
|
44
|
+
use_policy_ref: z.ZodOptional<z.ZodString>;
|
|
45
|
+
representation_ref: z.ZodOptional<z.ZodString>;
|
|
46
|
+
attestation_ref: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
/** Schema for CarrierMeta */
|
|
49
|
+
export declare const CarrierMetaSchema: z.ZodObject<{
|
|
50
|
+
transport: z.ZodString;
|
|
51
|
+
format: z.ZodEnum<{
|
|
52
|
+
embed: "embed";
|
|
53
|
+
reference: "reference";
|
|
54
|
+
}>;
|
|
55
|
+
max_size: z.ZodNumber;
|
|
56
|
+
redaction: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
/**
|
|
59
|
+
* Canonical receipt_ref computation (single source of truth).
|
|
60
|
+
*
|
|
61
|
+
* Computes SHA-256 of the UTF-8 bytes of the compact JWS string as emitted.
|
|
62
|
+
* All carrier adapters MUST use this function rather than computing SHA-256
|
|
63
|
+
* locally, to ensure consistency across protocols (correction item 4).
|
|
64
|
+
*/
|
|
65
|
+
export declare function computeReceiptRef(jws: string): Promise<ReceiptRef>;
|
|
66
|
+
/**
|
|
67
|
+
* Canonical carrier constraint validator (DD-127, DD-129, DD-131).
|
|
68
|
+
*
|
|
69
|
+
* Validates a carrier against transport-specific constraints using
|
|
70
|
+
* the provided CarrierMeta. This is the single validation function
|
|
71
|
+
* that all CarrierAdapter.validateConstraints() implementations delegate to.
|
|
72
|
+
*
|
|
73
|
+
* Checks performed:
|
|
74
|
+
* 1. receipt_ref format (sha256:<hex64>)
|
|
75
|
+
* 2. receipt_jws format (if present): valid compact JWS
|
|
76
|
+
* 3. Total serialized size within meta.max_size
|
|
77
|
+
* 4. If receipt_jws present: receipt_ref consistency (DD-129)
|
|
78
|
+
* 5. All string fields within MAX_STRING_LENGTH
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateCarrierConstraints(carrier: PeacEvidenceCarrier, meta: CarrierMeta): CarrierValidationResult;
|
|
81
|
+
/**
|
|
82
|
+
* Verify receipt_ref consistency with receipt_jws (DD-129).
|
|
83
|
+
*
|
|
84
|
+
* If both receipt_ref and receipt_jws are present, verifies that
|
|
85
|
+
* sha256(receipt_jws) equals receipt_ref. This prevents carrier
|
|
86
|
+
* tampering after attachment.
|
|
87
|
+
*
|
|
88
|
+
* Returns null if consistent or receipt_jws is absent;
|
|
89
|
+
* returns an error string if inconsistent.
|
|
90
|
+
*/
|
|
91
|
+
export declare function verifyReceiptRefConsistency(carrier: PeacEvidenceCarrier): Promise<string | null>;
|
|
92
|
+
export type { CarrierFormat, CarrierMeta, CarrierValidationResult, PeacEvidenceCarrier, ReceiptRef, CarrierAdapter, } from '@peac/kernel';
|
|
93
|
+
//# 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,qCAAqC;AACrC,eAAO,MAAM,yBAAyB;;;;;;;;;;iBAUpC,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,CA8CzB;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
|
@@ -2650,6 +2650,103 @@ function isAttestationOnly(claims) {
|
|
|
2650
2650
|
function isPaymentReceipt(claims) {
|
|
2651
2651
|
return "amt" in claims && "cur" in claims && "payment" in claims;
|
|
2652
2652
|
}
|
|
2653
|
+
var CARRIER_TRANSPORT_LIMITS = {
|
|
2654
|
+
/** MCP _meta: 64 KB */
|
|
2655
|
+
mcp: 65536,
|
|
2656
|
+
/** A2A metadata: 64 KB */
|
|
2657
|
+
a2a: 65536,
|
|
2658
|
+
/** ACP embed in body: 64 KB; headers only: 8 KB */
|
|
2659
|
+
acp_embed: 65536,
|
|
2660
|
+
acp_headers: 8192,
|
|
2661
|
+
/** UCP webhook body: 64 KB */
|
|
2662
|
+
ucp: 65536,
|
|
2663
|
+
/** x402 embed in body: 64 KB; headers only: 8 KB */
|
|
2664
|
+
x402_embed: 65536,
|
|
2665
|
+
x402_headers: 8192,
|
|
2666
|
+
/** HTTP headers only: 8 KB */
|
|
2667
|
+
http: 8192
|
|
2668
|
+
};
|
|
2669
|
+
var ReceiptRefSchema2 = zod.z.string().regex(/^sha256:[a-f0-9]{64}$/, "receipt_ref must be sha256:<64 hex chars>");
|
|
2670
|
+
var CompactJwsSchema = zod.z.string().regex(
|
|
2671
|
+
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
|
|
2672
|
+
"receipt_jws must be a valid compact JWS (header.payload.signature)"
|
|
2673
|
+
);
|
|
2674
|
+
var CarrierFormatSchema = zod.z.enum(["embed", "reference"]);
|
|
2675
|
+
var PeacEvidenceCarrierSchema = zod.z.object({
|
|
2676
|
+
receipt_ref: ReceiptRefSchema2,
|
|
2677
|
+
receipt_jws: CompactJwsSchema.optional(),
|
|
2678
|
+
policy_binding: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
|
|
2679
|
+
actor_binding: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
|
|
2680
|
+
request_nonce: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
|
|
2681
|
+
verification_report_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
|
|
2682
|
+
use_policy_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
|
|
2683
|
+
representation_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional(),
|
|
2684
|
+
attestation_ref: zod.z.string().max(KERNEL_CONSTRAINTS.MAX_STRING_LENGTH).optional()
|
|
2685
|
+
});
|
|
2686
|
+
var CarrierMetaSchema = zod.z.object({
|
|
2687
|
+
transport: zod.z.string().min(1),
|
|
2688
|
+
format: CarrierFormatSchema,
|
|
2689
|
+
max_size: zod.z.number().int().positive(),
|
|
2690
|
+
redaction: zod.z.array(zod.z.string()).optional()
|
|
2691
|
+
});
|
|
2692
|
+
async function computeReceiptRef(jws) {
|
|
2693
|
+
if (!globalThis.crypto?.subtle) {
|
|
2694
|
+
throw new Error(
|
|
2695
|
+
"computeReceiptRef requires WebCrypto (crypto.subtle). Supported runtimes: Node >= 20, Cloudflare Workers, Deno, Bun."
|
|
2696
|
+
);
|
|
2697
|
+
}
|
|
2698
|
+
const data = new TextEncoder().encode(jws);
|
|
2699
|
+
const hash = await globalThis.crypto.subtle.digest("SHA-256", data);
|
|
2700
|
+
const hex = Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2701
|
+
return `sha256:${hex}`;
|
|
2702
|
+
}
|
|
2703
|
+
function validateCarrierConstraints(carrier, meta) {
|
|
2704
|
+
const violations = [];
|
|
2705
|
+
const refResult = ReceiptRefSchema2.safeParse(carrier.receipt_ref);
|
|
2706
|
+
if (!refResult.success) {
|
|
2707
|
+
violations.push(`invalid receipt_ref format: ${carrier.receipt_ref}`);
|
|
2708
|
+
}
|
|
2709
|
+
if (carrier.receipt_jws !== void 0) {
|
|
2710
|
+
const jwsResult = CompactJwsSchema.safeParse(carrier.receipt_jws);
|
|
2711
|
+
if (!jwsResult.success) {
|
|
2712
|
+
violations.push("invalid receipt_jws format: not a valid compact JWS");
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
const serialized = JSON.stringify(carrier);
|
|
2716
|
+
const sizeBytes = new TextEncoder().encode(serialized).byteLength;
|
|
2717
|
+
if (sizeBytes > meta.max_size) {
|
|
2718
|
+
violations.push(
|
|
2719
|
+
`carrier size ${sizeBytes} bytes exceeds transport limit ${meta.max_size} bytes for ${meta.transport}`
|
|
2720
|
+
);
|
|
2721
|
+
}
|
|
2722
|
+
const stringFields = [
|
|
2723
|
+
["policy_binding", carrier.policy_binding],
|
|
2724
|
+
["actor_binding", carrier.actor_binding],
|
|
2725
|
+
["request_nonce", carrier.request_nonce],
|
|
2726
|
+
["verification_report_ref", carrier.verification_report_ref],
|
|
2727
|
+
["use_policy_ref", carrier.use_policy_ref],
|
|
2728
|
+
["representation_ref", carrier.representation_ref],
|
|
2729
|
+
["attestation_ref", carrier.attestation_ref]
|
|
2730
|
+
];
|
|
2731
|
+
for (const [name, value] of stringFields) {
|
|
2732
|
+
if (value !== void 0 && value.length > KERNEL_CONSTRAINTS.MAX_STRING_LENGTH) {
|
|
2733
|
+
violations.push(
|
|
2734
|
+
`${name} length ${value.length} exceeds MAX_STRING_LENGTH ${KERNEL_CONSTRAINTS.MAX_STRING_LENGTH}`
|
|
2735
|
+
);
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
return { valid: violations.length === 0, violations };
|
|
2739
|
+
}
|
|
2740
|
+
async function verifyReceiptRefConsistency(carrier) {
|
|
2741
|
+
if (carrier.receipt_jws === void 0) {
|
|
2742
|
+
return null;
|
|
2743
|
+
}
|
|
2744
|
+
const computed = await computeReceiptRef(carrier.receipt_jws);
|
|
2745
|
+
if (computed !== carrier.receipt_ref) {
|
|
2746
|
+
return `receipt_ref mismatch: expected ${computed}, got ${carrier.receipt_ref}`;
|
|
2747
|
+
}
|
|
2748
|
+
return null;
|
|
2749
|
+
}
|
|
2653
2750
|
|
|
2654
2751
|
// src/receipt-parser.ts
|
|
2655
2752
|
function classifyReceipt(obj) {
|
|
@@ -2727,10 +2824,14 @@ exports.AttributionUsageSchema = AttributionUsageSchema;
|
|
|
2727
2824
|
exports.BindingDetailsSchema = BindingDetailsSchema;
|
|
2728
2825
|
exports.CANONICAL_DIGEST_ALGS = CANONICAL_DIGEST_ALGS;
|
|
2729
2826
|
exports.CANONICAL_PURPOSES = CANONICAL_PURPOSES;
|
|
2827
|
+
exports.CARRIER_TRANSPORT_LIMITS = CARRIER_TRANSPORT_LIMITS;
|
|
2730
2828
|
exports.CONTRIBUTION_TYPES = CONTRIBUTION_TYPES;
|
|
2731
2829
|
exports.CONTROL_TYPES = CONTROL_TYPES;
|
|
2732
2830
|
exports.CREDIT_METHODS = CREDIT_METHODS;
|
|
2733
2831
|
exports.CanonicalPurposeSchema = CanonicalPurposeSchema;
|
|
2832
|
+
exports.CarrierFormatSchema = CarrierFormatSchema;
|
|
2833
|
+
exports.CarrierMetaSchema = CarrierMetaSchema;
|
|
2834
|
+
exports.CompactJwsSchema = CompactJwsSchema;
|
|
2734
2835
|
exports.ContactMethodSchema = ContactMethodSchema;
|
|
2735
2836
|
exports.ContentHashSchema = ContentHashSchema;
|
|
2736
2837
|
exports.ContributionObligationSchema = ContributionObligationSchema;
|
|
@@ -2823,6 +2924,7 @@ exports.PayloadRefSchema = PayloadRefSchema;
|
|
|
2823
2924
|
exports.PaymentEvidenceSchema = PaymentEvidenceSchema;
|
|
2824
2925
|
exports.PaymentRoutingSchema = PaymentRoutingSchema;
|
|
2825
2926
|
exports.PaymentSplitSchema = PaymentSplitSchema;
|
|
2927
|
+
exports.PeacEvidenceCarrierSchema = PeacEvidenceCarrierSchema;
|
|
2826
2928
|
exports.PolicyContextSchema = PolicyContextSchema;
|
|
2827
2929
|
exports.ProofMethodSchema = ProofMethodSchema;
|
|
2828
2930
|
exports.PurposeReasonSchema = PurposeReasonSchema;
|
|
@@ -2833,6 +2935,7 @@ exports.RESERVED_KIND_PREFIXES = RESERVED_KIND_PREFIXES;
|
|
|
2833
2935
|
exports.RESULT_STATUSES = RESULT_STATUSES;
|
|
2834
2936
|
exports.ReceiptClaims = ReceiptClaims;
|
|
2835
2937
|
exports.ReceiptClaimsSchema = ReceiptClaimsSchema;
|
|
2938
|
+
exports.ReceiptRefSchema = ReceiptRefSchema2;
|
|
2836
2939
|
exports.RefsSchema = RefsSchema;
|
|
2837
2940
|
exports.RemediationSchema = RemediationSchema;
|
|
2838
2941
|
exports.RemediationTypeSchema = RemediationTypeSchema;
|
|
@@ -2861,6 +2964,7 @@ exports.WorkflowSummaryAttestationSchema = WorkflowSummaryAttestationSchema;
|
|
|
2861
2964
|
exports.WorkflowSummaryEvidenceSchema = WorkflowSummaryEvidenceSchema;
|
|
2862
2965
|
exports.assertJsonSafeIterative = assertJsonSafeIterative;
|
|
2863
2966
|
exports.canTransitionTo = canTransitionTo;
|
|
2967
|
+
exports.computeReceiptRef = computeReceiptRef;
|
|
2864
2968
|
exports.computeTotalWeight = computeTotalWeight;
|
|
2865
2969
|
exports.createAgentIdentityAttestation = createAgentIdentityAttestation;
|
|
2866
2970
|
exports.createAttestationReceiptClaims = createAttestationReceiptClaims;
|
|
@@ -2930,6 +3034,7 @@ exports.validateAgentIdentityAttestation = validateAgentIdentityAttestation;
|
|
|
2930
3034
|
exports.validateAttestationReceiptClaims = validateAttestationReceiptClaims;
|
|
2931
3035
|
exports.validateAttributionAttestation = validateAttributionAttestation;
|
|
2932
3036
|
exports.validateAttributionSource = validateAttributionSource;
|
|
3037
|
+
exports.validateCarrierConstraints = validateCarrierConstraints;
|
|
2933
3038
|
exports.validateContentHash = validateContentHash;
|
|
2934
3039
|
exports.validateContributionObligation = validateContributionObligation;
|
|
2935
3040
|
exports.validateCreditObligation = validateCreditObligation;
|
|
@@ -2949,5 +3054,6 @@ exports.validateSubjectSnapshot = validateSubjectSnapshot;
|
|
|
2949
3054
|
exports.validateWorkflowContext = validateWorkflowContext;
|
|
2950
3055
|
exports.validateWorkflowContextOrdered = validateWorkflowContextOrdered;
|
|
2951
3056
|
exports.validateWorkflowSummaryAttestation = validateWorkflowSummaryAttestation;
|
|
3057
|
+
exports.verifyReceiptRefConsistency = verifyReceiptRefConsistency;
|
|
2952
3058
|
//# sourceMappingURL=index.cjs.map
|
|
2953
3059
|
//# sourceMappingURL=index.cjs.map
|