@peac/mappings-ucp 0.9.31

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 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;CAkCb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAErE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CA4BrD,CAAC;AAEF;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAE/B,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQ/E,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAQlC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,QAAQ,CAEV"}
package/dist/errors.js ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @peac/mappings-ucp - Error codes
3
+ *
4
+ * UCP webhook verification and mapping error codes.
5
+ * Follows E_UCP_* naming convention.
6
+ */
7
+ /**
8
+ * UCP error codes.
9
+ */
10
+ export const ErrorCodes = {
11
+ // Signature verification errors (400 - malformed)
12
+ SIGNATURE_MISSING: 'E_UCP_SIGNATURE_MISSING',
13
+ SIGNATURE_MALFORMED: 'E_UCP_SIGNATURE_MALFORMED',
14
+ SIGNATURE_ALGORITHM_UNSUPPORTED: 'E_UCP_SIGNATURE_ALGORITHM_UNSUPPORTED',
15
+ SIGNATURE_B64_INVALID: 'E_UCP_SIGNATURE_B64_INVALID',
16
+ // Key errors (401 - auth failure)
17
+ KEY_NOT_FOUND: 'E_UCP_KEY_NOT_FOUND',
18
+ KEY_ALGORITHM_MISMATCH: 'E_UCP_KEY_ALGORITHM_MISMATCH',
19
+ KEY_CURVE_MISMATCH: 'E_UCP_KEY_CURVE_MISMATCH',
20
+ // Verification errors (401 - auth failure)
21
+ SIGNATURE_INVALID: 'E_UCP_SIGNATURE_INVALID',
22
+ VERIFICATION_FAILED: 'E_UCP_VERIFICATION_FAILED',
23
+ // Profile errors (502 - upstream failure)
24
+ PROFILE_FETCH_FAILED: 'E_UCP_PROFILE_FETCH_FAILED',
25
+ PROFILE_INVALID: 'E_UCP_PROFILE_INVALID',
26
+ PROFILE_NO_SIGNING_KEYS: 'E_UCP_PROFILE_NO_SIGNING_KEYS',
27
+ // Payload errors (400 - malformed)
28
+ PAYLOAD_EMPTY: 'E_UCP_PAYLOAD_EMPTY',
29
+ PAYLOAD_NOT_JSON: 'E_UCP_PAYLOAD_NOT_JSON',
30
+ PAYLOAD_TOO_LARGE: 'E_UCP_PAYLOAD_TOO_LARGE',
31
+ // Mapping errors (400 - malformed)
32
+ ORDER_INVALID: 'E_UCP_ORDER_INVALID',
33
+ ORDER_MISSING_ID: 'E_UCP_ORDER_MISSING_ID',
34
+ ORDER_MISSING_LINE_ITEMS: 'E_UCP_ORDER_MISSING_LINE_ITEMS',
35
+ ORDER_MISSING_TOTALS: 'E_UCP_ORDER_MISSING_TOTALS',
36
+ // Evidence errors (500 - internal)
37
+ EVIDENCE_SERIALIZATION_FAILED: 'E_UCP_EVIDENCE_SERIALIZATION_FAILED',
38
+ };
39
+ /**
40
+ * HTTP status codes for each error.
41
+ */
42
+ export const ErrorHttpStatus = {
43
+ // 400 - Bad Request (malformed)
44
+ [ErrorCodes.SIGNATURE_MISSING]: 400,
45
+ [ErrorCodes.SIGNATURE_MALFORMED]: 400,
46
+ [ErrorCodes.SIGNATURE_ALGORITHM_UNSUPPORTED]: 400,
47
+ [ErrorCodes.SIGNATURE_B64_INVALID]: 400,
48
+ [ErrorCodes.PAYLOAD_EMPTY]: 400,
49
+ [ErrorCodes.PAYLOAD_NOT_JSON]: 400,
50
+ [ErrorCodes.PAYLOAD_TOO_LARGE]: 400,
51
+ [ErrorCodes.ORDER_INVALID]: 400,
52
+ [ErrorCodes.ORDER_MISSING_ID]: 400,
53
+ [ErrorCodes.ORDER_MISSING_LINE_ITEMS]: 400,
54
+ [ErrorCodes.ORDER_MISSING_TOTALS]: 400,
55
+ // 401 - Unauthorized (auth failure)
56
+ [ErrorCodes.KEY_NOT_FOUND]: 401,
57
+ [ErrorCodes.KEY_ALGORITHM_MISMATCH]: 401,
58
+ [ErrorCodes.KEY_CURVE_MISMATCH]: 401,
59
+ [ErrorCodes.SIGNATURE_INVALID]: 401,
60
+ [ErrorCodes.VERIFICATION_FAILED]: 401,
61
+ // 500 - Internal Server Error
62
+ [ErrorCodes.EVIDENCE_SERIALIZATION_FAILED]: 500,
63
+ // 502 - Bad Gateway (upstream failure)
64
+ [ErrorCodes.PROFILE_FETCH_FAILED]: 502,
65
+ [ErrorCodes.PROFILE_INVALID]: 502,
66
+ [ErrorCodes.PROFILE_NO_SIGNING_KEYS]: 502,
67
+ };
68
+ /**
69
+ * UCP-specific error class.
70
+ */
71
+ export class UcpError extends Error {
72
+ code;
73
+ httpStatus;
74
+ details;
75
+ constructor(code, message, details) {
76
+ super(message);
77
+ this.name = 'UcpError';
78
+ this.code = code;
79
+ this.httpStatus = ErrorHttpStatus[code];
80
+ this.details = details;
81
+ }
82
+ toJSON() {
83
+ return {
84
+ code: this.code,
85
+ message: this.message,
86
+ httpStatus: this.httpStatus,
87
+ ...(this.details && { details: this.details }),
88
+ };
89
+ }
90
+ }
91
+ /**
92
+ * Create a UCP error with standard format.
93
+ */
94
+ export function ucpError(code, message, details) {
95
+ return new UcpError(code, message, details);
96
+ }
97
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,kDAAkD;IAClD,iBAAiB,EAAE,yBAAyB;IAC5C,mBAAmB,EAAE,2BAA2B;IAChD,+BAA+B,EAAE,uCAAuC;IACxE,qBAAqB,EAAE,6BAA6B;IAEpD,kCAAkC;IAClC,aAAa,EAAE,qBAAqB;IACpC,sBAAsB,EAAE,8BAA8B;IACtD,kBAAkB,EAAE,0BAA0B;IAE9C,2CAA2C;IAC3C,iBAAiB,EAAE,yBAAyB;IAC5C,mBAAmB,EAAE,2BAA2B;IAEhD,0CAA0C;IAC1C,oBAAoB,EAAE,4BAA4B;IAClD,eAAe,EAAE,uBAAuB;IACxC,uBAAuB,EAAE,+BAA+B;IAExD,mCAAmC;IACnC,aAAa,EAAE,qBAAqB;IACpC,gBAAgB,EAAE,wBAAwB;IAC1C,iBAAiB,EAAE,yBAAyB;IAE5C,mCAAmC;IACnC,aAAa,EAAE,qBAAqB;IACpC,gBAAgB,EAAE,wBAAwB;IAC1C,wBAAwB,EAAE,gCAAgC;IAC1D,oBAAoB,EAAE,4BAA4B;IAElD,mCAAmC;IACnC,6BAA6B,EAAE,qCAAqC;CAC5D,CAAC;AAIX;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA8B;IACxD,gCAAgC;IAChC,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,GAAG;IACnC,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,GAAG;IACrC,CAAC,UAAU,CAAC,+BAA+B,CAAC,EAAE,GAAG;IACjD,CAAC,UA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xC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;SAC/C,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAe,EACf,OAAe,EACf,OAAiC;IAEjC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @peac/mappings-ucp - Evidence YAML generation
3
+ *
4
+ * Generates deterministic YAML for UCP webhook evidence.
5
+ * Uses fixed key ordering (manual string building) for byte-stable output.
6
+ *
7
+ * Key design principles:
8
+ * 1. Cannot be misinterpreted as executable policy (peac_bundle_metadata_version first)
9
+ * 2. Stores both raw and JCS payload representations for reproducible verification
10
+ * 3. Includes full signature header value for offline replay
11
+ * 4. Records all verification attempts for debugging
12
+ * 5. Timestamps are injected, not generated, for deterministic fixtures
13
+ */
14
+ import type { UcpWebhookEvidence, PayloadEvidence, SignatureEvidence, ProfileSnapshot, WebhookEventMeta, LinkedReceipt, VerificationAttempt, UcpSigningKey } from './types.js';
15
+ /**
16
+ * Options for creating UCP webhook evidence.
17
+ */
18
+ export interface CreateEvidenceOptions {
19
+ /** HTTP method */
20
+ method: string;
21
+ /** Request path */
22
+ path: string;
23
+ /** When request was received (ISO 8601) - REQUIRED for determinism */
24
+ received_at: string;
25
+ /** Payload evidence */
26
+ payload: PayloadEvidence;
27
+ /** Signature evidence */
28
+ signature: SignatureEvidence;
29
+ /** Profile snapshot */
30
+ profile: ProfileSnapshot;
31
+ /** Event metadata (optional) */
32
+ event?: WebhookEventMeta;
33
+ /** Linked receipts (optional) */
34
+ linked_receipts?: LinkedReceipt[];
35
+ }
36
+ /**
37
+ * Create UCP webhook evidence object.
38
+ * Use serializeEvidenceYaml() to convert to deterministic YAML string.
39
+ */
40
+ export declare function createUcpWebhookEvidence(options: CreateEvidenceOptions): UcpWebhookEvidence;
41
+ /**
42
+ * Serialize evidence to deterministic YAML string.
43
+ * Uses fixed key ordering for byte-stable output.
44
+ *
45
+ * IMPORTANT: Do NOT use a YAML serializer library as they may reorder keys.
46
+ */
47
+ export declare function serializeEvidenceYaml(evidence: UcpWebhookEvidence): string;
48
+ /**
49
+ * Create payload evidence from raw request body.
50
+ */
51
+ export declare function createPayloadEvidence(bodyBytes: Uint8Array, options?: {
52
+ maxBodyEvidenceBytes?: number;
53
+ includeJcsText?: boolean;
54
+ }): PayloadEvidence;
55
+ /**
56
+ * Create signature evidence from verification result.
57
+ */
58
+ export declare function createSignatureEvidence(headerValue: string, header: {
59
+ kid: string;
60
+ alg: string;
61
+ b64?: boolean;
62
+ crit?: string[];
63
+ }, verified: boolean, attempts: VerificationAttempt[], modeUsed?: 'raw' | 'jcs'): SignatureEvidence;
64
+ /**
65
+ * Create profile snapshot from fetched profile.
66
+ */
67
+ export declare function createProfileSnapshot(url: string, profile: Record<string, unknown>, keyUsed: UcpSigningKey, fetchedAt: string): ProfileSnapshot;
68
+ export { sha256Hex, sha256Bytes, base64urlEncode, jcsCanonicalizeSync } from './util.js';
69
+ //# sourceMappingURL=evidence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence.d.ts","sourceRoot":"","sources":["../src/evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACd,MAAM,YAAY,CAAC;AASpB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,kBAAkB;I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eAAe,CAuBjB;AAGD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,249 @@
1
+ /**
2
+ * @peac/mappings-ucp - Evidence YAML generation
3
+ *
4
+ * Generates deterministic YAML for UCP webhook evidence.
5
+ * Uses fixed key ordering (manual string building) for byte-stable output.
6
+ *
7
+ * Key design principles:
8
+ * 1. Cannot be misinterpreted as executable policy (peac_bundle_metadata_version first)
9
+ * 2. Stores both raw and JCS payload representations for reproducible verification
10
+ * 3. Includes full signature header value for offline replay
11
+ * 4. Records all verification attempts for debugging
12
+ * 5. Timestamps are injected, not generated, for deterministic fixtures
13
+ */
14
+ import { UCP_EVIDENCE_VERSION } from './types.js';
15
+ import { sha256Hex, sha256Bytes, base64urlEncode, jcsCanonicalizeSync } from './util.js';
16
+ /**
17
+ * Maximum body size to include as base64url in evidence (256KB).
18
+ */
19
+ const DEFAULT_MAX_BODY_EVIDENCE_BYTES = 256 * 1024;
20
+ /**
21
+ * Create UCP webhook evidence object.
22
+ * Use serializeEvidenceYaml() to convert to deterministic YAML string.
23
+ */
24
+ export function createUcpWebhookEvidence(options) {
25
+ const { method, path, received_at, payload, signature, profile, event, linked_receipts } = options;
26
+ return {
27
+ peac_bundle_metadata_version: UCP_EVIDENCE_VERSION,
28
+ kind: 'evidence_attachment',
29
+ scope: 'ucp_webhook',
30
+ request: {
31
+ method,
32
+ path,
33
+ received_at,
34
+ },
35
+ payload,
36
+ signature,
37
+ ...(event && { event }),
38
+ profile,
39
+ ...(linked_receipts && linked_receipts.length > 0 && { linked_receipts }),
40
+ };
41
+ }
42
+ /**
43
+ * Serialize evidence to deterministic YAML string.
44
+ * Uses fixed key ordering for byte-stable output.
45
+ *
46
+ * IMPORTANT: Do NOT use a YAML serializer library as they may reorder keys.
47
+ */
48
+ export function serializeEvidenceYaml(evidence) {
49
+ const lines = [];
50
+ // Header comment
51
+ lines.push('# PEAC UCP Webhook Evidence');
52
+ lines.push('# This file is evidence data, NOT executable policy');
53
+ lines.push('');
54
+ // Top-level metadata (prevents misinterpretation as policy)
55
+ lines.push(`peac_bundle_metadata_version: "${evidence.peac_bundle_metadata_version}"`);
56
+ lines.push(`kind: "${evidence.kind}"`);
57
+ lines.push(`scope: "${evidence.scope}"`);
58
+ lines.push('');
59
+ // Request section
60
+ lines.push('request:');
61
+ lines.push(` method: "${evidence.request.method}"`);
62
+ lines.push(` path: "${escapeYamlString(evidence.request.path)}"`);
63
+ lines.push(` received_at: "${evidence.request.received_at}"`);
64
+ lines.push('');
65
+ // Payload section
66
+ lines.push('payload:');
67
+ lines.push(` raw_sha256_hex: "${evidence.payload.raw_sha256_hex}"`);
68
+ if (evidence.payload.raw_bytes_b64url) {
69
+ lines.push(` raw_bytes_b64url: "${evidence.payload.raw_bytes_b64url}"`);
70
+ }
71
+ if (evidence.payload.jcs_sha256_hex) {
72
+ lines.push(` jcs_sha256_hex: "${evidence.payload.jcs_sha256_hex}"`);
73
+ }
74
+ if (evidence.payload.jcs_text) {
75
+ lines.push(' jcs_text: |');
76
+ const jcsLines = evidence.payload.jcs_text.split('\n');
77
+ for (const line of jcsLines) {
78
+ lines.push(` ${line}`);
79
+ }
80
+ }
81
+ lines.push(` json_parseable: ${evidence.payload.json_parseable}`);
82
+ lines.push('');
83
+ // Signature section
84
+ lines.push('signature:');
85
+ lines.push(` header_value: "${escapeYamlString(evidence.signature.header_value)}"`);
86
+ lines.push(` kid: "${evidence.signature.kid}"`);
87
+ lines.push(` alg: "${evidence.signature.alg}"`);
88
+ lines.push(` b64: ${evidence.signature.b64 === null ? 'null' : evidence.signature.b64}`);
89
+ if (evidence.signature.crit && evidence.signature.crit.length > 0) {
90
+ lines.push(' crit:');
91
+ for (const c of evidence.signature.crit) {
92
+ lines.push(` - "${c}"`);
93
+ }
94
+ }
95
+ lines.push(` verified: ${evidence.signature.verified}`);
96
+ if (evidence.signature.verification_mode_used) {
97
+ lines.push(` verification_mode_used: "${evidence.signature.verification_mode_used}"`);
98
+ }
99
+ lines.push(' verification_attempts:');
100
+ for (const attempt of evidence.signature.verification_attempts) {
101
+ lines.push(` - mode: "${attempt.mode}"`);
102
+ lines.push(` success: ${attempt.success}`);
103
+ if (attempt.error_code) {
104
+ lines.push(` error_code: "${attempt.error_code}"`);
105
+ }
106
+ if (attempt.error_message) {
107
+ lines.push(` error_message: "${escapeYamlString(attempt.error_message)}"`);
108
+ }
109
+ }
110
+ lines.push('');
111
+ // Event section (optional)
112
+ if (evidence.event) {
113
+ lines.push('event:');
114
+ lines.push(` type: "${evidence.event.type}"`);
115
+ if (evidence.event.resource_id) {
116
+ lines.push(` resource_id: "${evidence.event.resource_id}"`);
117
+ }
118
+ if (evidence.event.timestamp) {
119
+ lines.push(` timestamp: "${evidence.event.timestamp}"`);
120
+ }
121
+ lines.push('');
122
+ }
123
+ // Profile section
124
+ lines.push('profile:');
125
+ lines.push(` url: "${evidence.profile.url}"`);
126
+ lines.push(` fetched_at: "${evidence.profile.fetched_at}"`);
127
+ lines.push(` profile_jcs_sha256_hex: "${evidence.profile.profile_jcs_sha256_hex}"`);
128
+ if (evidence.profile.key_thumbprint) {
129
+ lines.push(` key_thumbprint: "${evidence.profile.key_thumbprint}"`);
130
+ }
131
+ if (evidence.profile.key_jwk) {
132
+ lines.push(' key_jwk:');
133
+ lines.push(` kty: "${evidence.profile.key_jwk.kty}"`);
134
+ lines.push(` crv: "${evidence.profile.key_jwk.crv}"`);
135
+ lines.push(` kid: "${evidence.profile.key_jwk.kid}"`);
136
+ lines.push(` x: "${evidence.profile.key_jwk.x}"`);
137
+ lines.push(` y: "${evidence.profile.key_jwk.y}"`);
138
+ if (evidence.profile.key_jwk.alg) {
139
+ lines.push(` alg: "${evidence.profile.key_jwk.alg}"`);
140
+ }
141
+ if (evidence.profile.key_jwk.use) {
142
+ lines.push(` use: "${evidence.profile.key_jwk.use}"`);
143
+ }
144
+ }
145
+ lines.push('');
146
+ // Linked receipts (optional)
147
+ if (evidence.linked_receipts && evidence.linked_receipts.length > 0) {
148
+ lines.push('linked_receipts:');
149
+ for (const lr of evidence.linked_receipts) {
150
+ lines.push(` - receipt_id: "${lr.receipt_id}"`);
151
+ lines.push(` relationship: "${lr.relationship}"`);
152
+ }
153
+ }
154
+ // Remove trailing empty lines and ensure exactly one trailing newline (LF)
155
+ while (lines.length > 0 && lines[lines.length - 1] === '') {
156
+ lines.pop();
157
+ }
158
+ return lines.join('\n') + '\n';
159
+ }
160
+ /**
161
+ * Escape special characters in YAML string values.
162
+ */
163
+ function escapeYamlString(s) {
164
+ return s
165
+ .replace(/\\/g, '\\\\')
166
+ .replace(/"/g, '\\"')
167
+ .replace(/\n/g, '\\n')
168
+ .replace(/\r/g, '\\r')
169
+ .replace(/\t/g, '\\t');
170
+ }
171
+ /**
172
+ * Create payload evidence from raw request body.
173
+ */
174
+ export function createPayloadEvidence(bodyBytes, options = {}) {
175
+ const { maxBodyEvidenceBytes = DEFAULT_MAX_BODY_EVIDENCE_BYTES, includeJcsText = false } = options;
176
+ // Compute raw hash
177
+ const rawSha256Hex = sha256Hex(bodyBytes);
178
+ // Include raw bytes if under size limit
179
+ let rawBytesB64url;
180
+ if (bodyBytes.length <= maxBodyEvidenceBytes) {
181
+ rawBytesB64url = base64urlEncode(bodyBytes);
182
+ }
183
+ // Try to parse as JSON and compute JCS hash
184
+ let jcsSha256Hex;
185
+ let jcsText;
186
+ let jsonParseable = false;
187
+ try {
188
+ const bodyText = new TextDecoder().decode(bodyBytes);
189
+ const parsed = JSON.parse(bodyText);
190
+ jsonParseable = true;
191
+ // JCS canonicalize
192
+ const canonicalized = jcsCanonicalizeSync(parsed);
193
+ jcsSha256Hex = sha256Hex(new TextEncoder().encode(canonicalized));
194
+ if (includeJcsText) {
195
+ jcsText = canonicalized;
196
+ }
197
+ }
198
+ catch {
199
+ // Not valid JSON, that's fine
200
+ }
201
+ return {
202
+ raw_sha256_hex: rawSha256Hex,
203
+ ...(rawBytesB64url && { raw_bytes_b64url: rawBytesB64url }),
204
+ ...(jcsSha256Hex && { jcs_sha256_hex: jcsSha256Hex }),
205
+ ...(jcsText && { jcs_text: jcsText }),
206
+ json_parseable: jsonParseable,
207
+ };
208
+ }
209
+ /**
210
+ * Create signature evidence from verification result.
211
+ */
212
+ export function createSignatureEvidence(headerValue, header, verified, attempts, modeUsed) {
213
+ return {
214
+ header_value: headerValue,
215
+ kid: header.kid,
216
+ alg: header.alg,
217
+ b64: header.b64 === undefined ? null : header.b64,
218
+ ...(header.crit && header.crit.length > 0 && { crit: header.crit }),
219
+ verified,
220
+ ...(modeUsed && { verification_mode_used: modeUsed }),
221
+ verification_attempts: attempts,
222
+ };
223
+ }
224
+ /**
225
+ * Create profile snapshot from fetched profile.
226
+ */
227
+ export function createProfileSnapshot(url, profile, keyUsed, fetchedAt) {
228
+ // JCS canonicalize the profile
229
+ const canonicalized = jcsCanonicalizeSync(profile);
230
+ const profileJcsSha256Hex = sha256Hex(new TextEncoder().encode(canonicalized));
231
+ // Compute JWK thumbprint (SHA-256 of JCS-canonicalized required members)
232
+ const thumbprintInput = {
233
+ crv: keyUsed.crv,
234
+ kty: keyUsed.kty,
235
+ x: keyUsed.x,
236
+ y: keyUsed.y,
237
+ };
238
+ const thumbprint = base64urlEncode(sha256Bytes(new TextEncoder().encode(jcsCanonicalizeSync(thumbprintInput))));
239
+ return {
240
+ url,
241
+ fetched_at: fetchedAt,
242
+ profile_jcs_sha256_hex: profileJcsSha256Hex,
243
+ key_thumbprint: thumbprint,
244
+ key_jwk: keyUsed,
245
+ };
246
+ }
247
+ // Re-export utilities for backwards compatibility
248
+ export { sha256Hex, sha256Bytes, base64urlEncode, jcsCanonicalizeSync } from './util.js';
249
+ //# sourceMappingURL=evidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence.js","sourceRoot":"","sources":["../src/evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAA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ED,kDAAkD;AAClD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @peac/mappings-ucp
3
+ *
4
+ * Google Universal Commerce Protocol (UCP) mapping to PEAC receipts
5
+ * and dispute evidence.
6
+ *
7
+ * Features:
8
+ * - Webhook signature verification (raw-first, JCS fallback)
9
+ * - UCP order to PEAC receipt mapping
10
+ * - Dispute evidence generation for @peac/audit bundles
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import {
15
+ * verifyUcpWebhookSignature,
16
+ * mapUcpOrderToReceipt,
17
+ * createUcpDisputeEvidence,
18
+ * } from '@peac/mappings-ucp';
19
+ *
20
+ * // Verify webhook signature
21
+ * const result = await verifyUcpWebhookSignature({
22
+ * signature_header: req.headers['request-signature'],
23
+ * body_bytes: rawBody,
24
+ * profile_url: 'https://business.example.com/.well-known/ucp',
25
+ * });
26
+ *
27
+ * if (result.valid) {
28
+ * // Map order to PEAC receipt
29
+ * const claims = mapUcpOrderToReceipt({
30
+ * order: body.order,
31
+ * issuer: 'https://platform.example.com',
32
+ * subject: 'buyer:123',
33
+ * currency: 'USD',
34
+ * });
35
+ *
36
+ * // Sign with @peac/protocol
37
+ * const receipt = await issue(claims, privateKey, kid);
38
+ * }
39
+ * ```
40
+ */
41
+ export type { UcpSignatureAlgorithm, MinorUnits, VerificationMode, B64Mode, UcpJwsHeader, ParsedDetachedJws, UcpSigningKey, UcpProfile, UcpCapability, VerificationAttempt, PayloadEvidence, SignatureEvidence, ProfileSnapshot, WebhookEventMeta, UcpWebhookEvidence, LinkedReceipt, VerifyUcpWebhookOptions, VerifyUcpWebhookResult, UcpLineItem, UcpOrder, MapUcpOrderOptions, MappedReceiptClaims, } from './types.js';
42
+ export { UCP_EVIDENCE_VERSION } from './types.js';
43
+ export { ErrorCodes, ErrorHttpStatus, UcpError, ucpError } from './errors.js';
44
+ export type { ErrorCode } from './errors.js';
45
+ export { verifyUcpWebhookSignature, parseDetachedJws, findSigningKey } from './verify.js';
46
+ export { mapUcpOrderToReceipt, extractLineItemSummary, calculateOrderStats } from './mapper.js';
47
+ export { createUcpWebhookEvidence, serializeEvidenceYaml, createPayloadEvidence, createSignatureEvidence, createProfileSnapshot, } from './evidence.js';
48
+ export type { CreateEvidenceOptions } from './evidence.js';
49
+ export { createUcpDisputeEvidence, parseWebhookEvent, determineReceiptRelationship, } from './bundle.js';
50
+ export type { CreateUcpDisputeEvidenceOptions, CreateUcpDisputeEvidenceResult } from './bundle.js';
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,YAAY,EAEV,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,OAAO,EAEP,YAAY,EACZ,iBAAiB,EAEjB,aAAa,EACb,UAAU,EACV,aAAa,EAEb,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EAEb,uBAAuB,EACvB,sBAAsB,EAEtB,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG1F,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGhG,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,+BAA+B,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @peac/mappings-ucp
3
+ *
4
+ * Google Universal Commerce Protocol (UCP) mapping to PEAC receipts
5
+ * and dispute evidence.
6
+ *
7
+ * Features:
8
+ * - Webhook signature verification (raw-first, JCS fallback)
9
+ * - UCP order to PEAC receipt mapping
10
+ * - Dispute evidence generation for @peac/audit bundles
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import {
15
+ * verifyUcpWebhookSignature,
16
+ * mapUcpOrderToReceipt,
17
+ * createUcpDisputeEvidence,
18
+ * } from '@peac/mappings-ucp';
19
+ *
20
+ * // Verify webhook signature
21
+ * const result = await verifyUcpWebhookSignature({
22
+ * signature_header: req.headers['request-signature'],
23
+ * body_bytes: rawBody,
24
+ * profile_url: 'https://business.example.com/.well-known/ucp',
25
+ * });
26
+ *
27
+ * if (result.valid) {
28
+ * // Map order to PEAC receipt
29
+ * const claims = mapUcpOrderToReceipt({
30
+ * order: body.order,
31
+ * issuer: 'https://platform.example.com',
32
+ * subject: 'buyer:123',
33
+ * currency: 'USD',
34
+ * });
35
+ *
36
+ * // Sign with @peac/protocol
37
+ * const receipt = await issue(claims, privateKey, kid);
38
+ * }
39
+ * ```
40
+ */
41
+ export { UCP_EVIDENCE_VERSION } from './types.js';
42
+ // Errors
43
+ export { ErrorCodes, ErrorHttpStatus, UcpError, ucpError } from './errors.js';
44
+ // Verification
45
+ export { verifyUcpWebhookSignature, parseDetachedJws, findSigningKey } from './verify.js';
46
+ // Mapping
47
+ export { mapUcpOrderToReceipt, extractLineItemSummary, calculateOrderStats } from './mapper.js';
48
+ // Evidence
49
+ export { createUcpWebhookEvidence, serializeEvidenceYaml, createPayloadEvidence, createSignatureEvidence, createProfileSnapshot, } from './evidence.js';
50
+ // Bundle helpers
51
+ export { createUcpDisputeEvidence, parseWebhookEvent, determineReceiptRelationship, } from './bundle.js';
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAkCH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG9E,eAAe;AACf,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1F,UAAU;AACV,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEhG,WAAW;AACX,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAIvB,iBAAiB;AACjB,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,aAAa,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @peac/mappings-ucp - UCP to PEAC receipt mapping
3
+ *
4
+ * Maps UCP order data to PEAC receipt claims.
5
+ * Amounts are in minor units (cents), NOT micros.
6
+ */
7
+ import type { UcpOrder, MapUcpOrderOptions, MappedReceiptClaims, MinorUnits } from './types.js';
8
+ /**
9
+ * Map a UCP order to PEAC receipt claims.
10
+ *
11
+ * @param options - Mapping options
12
+ * @returns PEAC receipt claims (ready for signing)
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const claims = mapUcpOrderToReceipt({
17
+ * order: ucpOrder,
18
+ * issuer: 'https://merchant.example.com',
19
+ * subject: 'agent:shopper-bot-123',
20
+ * currency: 'USD',
21
+ * });
22
+ *
23
+ * // Sign with @peac/protocol
24
+ * const receipt = await issue(claims, privateKey, kid);
25
+ * ```
26
+ */
27
+ export declare function mapUcpOrderToReceipt(options: MapUcpOrderOptions): MappedReceiptClaims;
28
+ /**
29
+ * Extract line item summary for evidence.
30
+ */
31
+ export declare function extractLineItemSummary(order: UcpOrder): Array<{
32
+ id: string;
33
+ title: string;
34
+ quantity: number;
35
+ price: MinorUnits;
36
+ status: string;
37
+ }>;
38
+ /**
39
+ * Calculate order summary statistics.
40
+ */
41
+ export declare function calculateOrderStats(order: UcpOrder): {
42
+ total_items: number;
43
+ fulfilled_items: number;
44
+ pending_items: number;
45
+ total_quantity: number;
46
+ fulfilled_quantity: number;
47
+ };
48
+ //# sourceMappingURL=mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../src/mapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAyEhG;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,mBAAmB,CAgDrF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAQD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,GAAG;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CA0BA"}