@peac/schema 0.10.9 → 0.10.10
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/LICENSE +1 -1
- package/dist/attestation-receipt.cjs +127 -0
- package/dist/attestation-receipt.cjs.map +1 -0
- package/dist/attestation-receipt.mjs +113 -0
- package/dist/attestation-receipt.mjs.map +1 -0
- package/dist/attribution.cjs +249 -0
- package/dist/attribution.cjs.map +1 -0
- package/dist/attribution.mjs +227 -0
- package/dist/attribution.mjs.map +1 -0
- package/dist/dispute.d.ts.map +1 -1
- package/dist/index.cjs +2818 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +2577 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interaction.cjs +619 -0
- package/dist/interaction.cjs.map +1 -0
- package/dist/interaction.mjs +583 -0
- package/dist/interaction.mjs.map +1 -0
- package/dist/normalize.cjs +84 -0
- package/dist/normalize.cjs.map +1 -0
- package/dist/normalize.d.ts +15 -9
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.mjs +82 -0
- package/dist/normalize.mjs.map +1 -0
- package/dist/receipt-parser.cjs +333 -0
- package/dist/receipt-parser.cjs.map +1 -0
- package/dist/receipt-parser.mjs +331 -0
- package/dist/receipt-parser.mjs.map +1 -0
- package/dist/workflow.cjs +321 -0
- package/dist/workflow.cjs.map +1 -0
- package/dist/workflow.mjs +292 -0
- package/dist/workflow.mjs.map +1 -0
- package/package.json +50 -6
- package/dist/agent-identity.js +0 -357
- package/dist/agent-identity.js.map +0 -1
- package/dist/attestation-receipt.js +0 -249
- package/dist/attestation-receipt.js.map +0 -1
- package/dist/attribution.js +0 -444
- package/dist/attribution.js.map +0 -1
- package/dist/constants.js +0 -73
- package/dist/constants.js.map +0 -1
- package/dist/control.js +0 -9
- package/dist/control.js.map +0 -1
- package/dist/dispute.js +0 -832
- package/dist/dispute.js.map +0 -1
- package/dist/envelope.js +0 -9
- package/dist/envelope.js.map +0 -1
- package/dist/errors.js +0 -116
- package/dist/errors.js.map +0 -1
- package/dist/evidence.js +0 -8
- package/dist/evidence.js.map +0 -1
- package/dist/index.js +0 -283
- package/dist/index.js.map +0 -1
- package/dist/interaction.js +0 -918
- package/dist/interaction.js.map +0 -1
- package/dist/json.js +0 -267
- package/dist/json.js.map +0 -1
- package/dist/normalize.js +0 -103
- package/dist/normalize.js.map +0 -1
- package/dist/obligations.js +0 -337
- package/dist/obligations.js.map +0 -1
- package/dist/purpose.js +0 -296
- package/dist/purpose.js.map +0 -1
- package/dist/receipt-parser.js +0 -89
- package/dist/receipt-parser.js.map +0 -1
- package/dist/schemas.js +0 -7
- package/dist/schemas.js.map +0 -1
- package/dist/subject.js +0 -9
- package/dist/subject.js.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/validators.js +0 -421
- package/dist/validators.js.map +0 -1
- package/dist/version.js +0 -7
- package/dist/version.js.map +0 -1
- package/dist/workflow.js +0 -523
- package/dist/workflow.js.map +0 -1
package/dist/agent-identity.js
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentIdentityVerifiedSchema = exports.IdentityBindingSchema = exports.AgentIdentityAttestationSchema = exports.AGENT_IDENTITY_TYPE = exports.AgentIdentityEvidenceSchema = exports.AgentProofSchema = exports.BindingDetailsSchema = exports.PROOF_METHODS = exports.ProofMethodSchema = exports.CONTROL_TYPES = exports.ControlTypeSchema = void 0;
|
|
4
|
-
exports.validateAgentIdentityAttestation = validateAgentIdentityAttestation;
|
|
5
|
-
exports.isAgentIdentityAttestation = isAgentIdentityAttestation;
|
|
6
|
-
exports.createAgentIdentityAttestation = createAgentIdentityAttestation;
|
|
7
|
-
exports.validateIdentityBinding = validateIdentityBinding;
|
|
8
|
-
exports.isAttestationExpired = isAttestationExpired;
|
|
9
|
-
exports.isAttestationNotYetValid = isAttestationNotYetValid;
|
|
10
|
-
/**
|
|
11
|
-
* Agent Identity Attestation Types and Validators (v0.9.25+)
|
|
12
|
-
*
|
|
13
|
-
* Provides cryptographic proof-of-control binding for agents,
|
|
14
|
-
* distinguishing operator-verified bots from user-delegated agents.
|
|
15
|
-
*
|
|
16
|
-
* @see docs/specs/AGENT-IDENTITY.md for normative specification
|
|
17
|
-
*/
|
|
18
|
-
const zod_1 = require("zod");
|
|
19
|
-
const json_1 = require("./json");
|
|
20
|
-
// =============================================================================
|
|
21
|
-
// CONTROL TYPE (v0.9.25+)
|
|
22
|
-
// =============================================================================
|
|
23
|
-
/**
|
|
24
|
-
* Control type distinguishes operator-verified bots from user-delegated agents.
|
|
25
|
-
*
|
|
26
|
-
* - 'operator': Bot/crawler operated by a known organization (e.g., Googlebot, GPTBot)
|
|
27
|
-
* - 'user-delegated': Agent acting on behalf of a human user (e.g., browser extension, AI assistant)
|
|
28
|
-
*/
|
|
29
|
-
exports.ControlTypeSchema = zod_1.z.enum(['operator', 'user-delegated']);
|
|
30
|
-
/**
|
|
31
|
-
* Array of valid control types for runtime checks
|
|
32
|
-
*/
|
|
33
|
-
exports.CONTROL_TYPES = ['operator', 'user-delegated'];
|
|
34
|
-
// =============================================================================
|
|
35
|
-
// PROOF METHOD (v0.9.25+)
|
|
36
|
-
// =============================================================================
|
|
37
|
-
/**
|
|
38
|
-
* Proof method used to establish agent identity.
|
|
39
|
-
*
|
|
40
|
-
* - 'http-message-signature': RFC 9421 HTTP Message Signatures
|
|
41
|
-
* - 'dpop': RFC 9449 DPoP token binding
|
|
42
|
-
* - 'mtls': Mutual TLS client certificate
|
|
43
|
-
* - 'jwk-thumbprint': JWK Thumbprint confirmation (RFC 7638)
|
|
44
|
-
*/
|
|
45
|
-
exports.ProofMethodSchema = zod_1.z.enum([
|
|
46
|
-
'http-message-signature',
|
|
47
|
-
'dpop',
|
|
48
|
-
'mtls',
|
|
49
|
-
'jwk-thumbprint',
|
|
50
|
-
]);
|
|
51
|
-
/**
|
|
52
|
-
* Array of valid proof methods for runtime checks
|
|
53
|
-
*/
|
|
54
|
-
exports.PROOF_METHODS = ['http-message-signature', 'dpop', 'mtls', 'jwk-thumbprint'];
|
|
55
|
-
// =============================================================================
|
|
56
|
-
// BINDING DETAILS (v0.9.25+)
|
|
57
|
-
// =============================================================================
|
|
58
|
-
/**
|
|
59
|
-
* Details of what was included in the binding message for http-message-signature.
|
|
60
|
-
*
|
|
61
|
-
* This allows verifiers to reconstruct the binding message for verification.
|
|
62
|
-
*/
|
|
63
|
-
exports.BindingDetailsSchema = zod_1.z
|
|
64
|
-
.object({
|
|
65
|
-
/** HTTP method (uppercase: GET, POST, etc.) */
|
|
66
|
-
method: zod_1.z.string().min(1).max(16),
|
|
67
|
-
/** Target URI of the request */
|
|
68
|
-
target: zod_1.z.string().min(1).max(2048),
|
|
69
|
-
/** Headers included in the signature (lowercase) */
|
|
70
|
-
headers_included: zod_1.z.array(zod_1.z.string().max(64)).max(32),
|
|
71
|
-
/** SHA-256 hash of request body (base64url), empty string if no body */
|
|
72
|
-
body_hash: zod_1.z.string().max(64).optional(),
|
|
73
|
-
/** When the binding was signed (RFC 3339) */
|
|
74
|
-
signed_at: zod_1.z.string().datetime(),
|
|
75
|
-
})
|
|
76
|
-
.strict();
|
|
77
|
-
// =============================================================================
|
|
78
|
-
// AGENT PROOF (v0.9.25+)
|
|
79
|
-
// =============================================================================
|
|
80
|
-
/**
|
|
81
|
-
* Proof of control binding - cryptographic evidence that the agent controls the key.
|
|
82
|
-
*/
|
|
83
|
-
exports.AgentProofSchema = zod_1.z
|
|
84
|
-
.object({
|
|
85
|
-
/** Proof method used */
|
|
86
|
-
method: exports.ProofMethodSchema,
|
|
87
|
-
/** Key ID (matches kid in JWS header or JWKS) */
|
|
88
|
-
key_id: zod_1.z.string().min(1).max(256),
|
|
89
|
-
/** Algorithm used (default: EdDSA for Ed25519) */
|
|
90
|
-
alg: zod_1.z.string().max(32).default('EdDSA'),
|
|
91
|
-
/** Signature over binding message (base64url, for http-message-signature) */
|
|
92
|
-
signature: zod_1.z.string().max(512).optional(),
|
|
93
|
-
/** DPoP proof JWT (for dpop method) */
|
|
94
|
-
dpop_proof: zod_1.z.string().max(4096).optional(),
|
|
95
|
-
/** Certificate fingerprint (for mtls method, SHA-256 base64url) */
|
|
96
|
-
cert_thumbprint: zod_1.z.string().max(64).optional(),
|
|
97
|
-
/** Binding details for http-message-signature */
|
|
98
|
-
binding: exports.BindingDetailsSchema.optional(),
|
|
99
|
-
})
|
|
100
|
-
.strict();
|
|
101
|
-
// =============================================================================
|
|
102
|
-
// AGENT IDENTITY EVIDENCE (v0.9.25+)
|
|
103
|
-
// =============================================================================
|
|
104
|
-
/**
|
|
105
|
-
* Agent identity evidence - the payload of an AgentIdentityAttestation.
|
|
106
|
-
*
|
|
107
|
-
* Contains the agent identifier, control type, capabilities, and optional
|
|
108
|
-
* cryptographic proof of key control.
|
|
109
|
-
*/
|
|
110
|
-
exports.AgentIdentityEvidenceSchema = zod_1.z
|
|
111
|
-
.object({
|
|
112
|
-
/** Stable agent identifier (opaque string, REQUIRED) */
|
|
113
|
-
agent_id: zod_1.z.string().min(1).max(256),
|
|
114
|
-
/** Control type: operator-verified or user-delegated (REQUIRED) */
|
|
115
|
-
control_type: exports.ControlTypeSchema,
|
|
116
|
-
/** Agent capabilities/scopes (optional, for fine-grained access) */
|
|
117
|
-
capabilities: zod_1.z.array(zod_1.z.string().max(64)).max(32).optional(),
|
|
118
|
-
/** Delegation chain for user-delegated agents (optional) */
|
|
119
|
-
delegation_chain: zod_1.z.array(zod_1.z.string().max(256)).max(8).optional(),
|
|
120
|
-
/** Cryptographic proof of key control (optional) */
|
|
121
|
-
proof: exports.AgentProofSchema.optional(),
|
|
122
|
-
/** Key directory URL for public key discovery (optional) */
|
|
123
|
-
key_directory_url: zod_1.z.string().url().max(2048).optional(),
|
|
124
|
-
/** Agent operator/organization (optional, for operator type) */
|
|
125
|
-
operator: zod_1.z.string().max(256).optional(),
|
|
126
|
-
/** User identifier (optional, for user-delegated type, should be opaque) */
|
|
127
|
-
user_id: zod_1.z.string().max(256).optional(),
|
|
128
|
-
/** Additional type-specific metadata (optional) */
|
|
129
|
-
metadata: zod_1.z.record(zod_1.z.string(), json_1.JsonValueSchema).optional(),
|
|
130
|
-
})
|
|
131
|
-
.strict();
|
|
132
|
-
// =============================================================================
|
|
133
|
-
// AGENT IDENTITY ATTESTATION (v0.9.25+)
|
|
134
|
-
// =============================================================================
|
|
135
|
-
/**
|
|
136
|
-
* Attestation type literal for agent identity
|
|
137
|
-
*/
|
|
138
|
-
exports.AGENT_IDENTITY_TYPE = 'peac/agent-identity';
|
|
139
|
-
/**
|
|
140
|
-
* AgentIdentityAttestation - extends generic Attestation with agent-specific evidence.
|
|
141
|
-
*
|
|
142
|
-
* This attestation proves cryptographic control over an agent identity,
|
|
143
|
-
* distinguishing operator-verified bots from user-delegated agents.
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* ```typescript
|
|
147
|
-
* const attestation: AgentIdentityAttestation = {
|
|
148
|
-
* type: 'peac/agent-identity',
|
|
149
|
-
* issuer: 'https://crawler.example.com',
|
|
150
|
-
* issued_at: '2026-01-03T12:00:00Z',
|
|
151
|
-
* evidence: {
|
|
152
|
-
* agent_id: 'bot:crawler-prod-001',
|
|
153
|
-
* control_type: 'operator',
|
|
154
|
-
* operator: 'Example Crawler Inc.',
|
|
155
|
-
* capabilities: ['crawl', 'index'],
|
|
156
|
-
* proof: {
|
|
157
|
-
* method: 'http-message-signature',
|
|
158
|
-
* key_id: 'key-2026-01',
|
|
159
|
-
* alg: 'EdDSA',
|
|
160
|
-
* },
|
|
161
|
-
* },
|
|
162
|
-
* };
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
exports.AgentIdentityAttestationSchema = zod_1.z
|
|
166
|
-
.object({
|
|
167
|
-
/** Attestation type (MUST be 'peac/agent-identity') */
|
|
168
|
-
type: zod_1.z.literal(exports.AGENT_IDENTITY_TYPE),
|
|
169
|
-
/** Issuer of the attestation (agent operator, IdP, or platform) */
|
|
170
|
-
issuer: zod_1.z.string().min(1).max(2048),
|
|
171
|
-
/** When the attestation was issued (RFC 3339) */
|
|
172
|
-
issued_at: zod_1.z.string().datetime(),
|
|
173
|
-
/** When the attestation expires (RFC 3339, optional) */
|
|
174
|
-
expires_at: zod_1.z.string().datetime().optional(),
|
|
175
|
-
/** Reference to external verification endpoint (optional) */
|
|
176
|
-
ref: zod_1.z.string().url().max(2048).optional(),
|
|
177
|
-
/** Agent identity evidence */
|
|
178
|
-
evidence: exports.AgentIdentityEvidenceSchema,
|
|
179
|
-
})
|
|
180
|
-
.strict();
|
|
181
|
-
// =============================================================================
|
|
182
|
-
// IDENTITY BINDING (v0.9.25+)
|
|
183
|
-
// =============================================================================
|
|
184
|
-
/**
|
|
185
|
-
* Identity binding result from constructBindingMessage().
|
|
186
|
-
*
|
|
187
|
-
* Used to tie an agent identity attestation to a specific HTTP request.
|
|
188
|
-
*/
|
|
189
|
-
exports.IdentityBindingSchema = zod_1.z
|
|
190
|
-
.object({
|
|
191
|
-
/** SHA-256 hash of the canonical binding message (base64url) */
|
|
192
|
-
binding_message_hash: zod_1.z.string().min(1).max(64),
|
|
193
|
-
/** Ed25519 signature over binding message (base64url) */
|
|
194
|
-
signature: zod_1.z.string().min(1).max(512),
|
|
195
|
-
/** Key ID used for signing */
|
|
196
|
-
key_id: zod_1.z.string().min(1).max(256),
|
|
197
|
-
/** When the binding was created (RFC 3339) */
|
|
198
|
-
signed_at: zod_1.z.string().datetime(),
|
|
199
|
-
})
|
|
200
|
-
.strict();
|
|
201
|
-
// =============================================================================
|
|
202
|
-
// AGENT IDENTITY VERIFIED BLOCK (v0.9.25+)
|
|
203
|
-
// =============================================================================
|
|
204
|
-
/**
|
|
205
|
-
* Agent identity verification result to include in receipt evidence.
|
|
206
|
-
*
|
|
207
|
-
* This block is added by the publisher after verifying an agent identity
|
|
208
|
-
* attestation, binding the verified identity to the issued receipt.
|
|
209
|
-
*/
|
|
210
|
-
exports.AgentIdentityVerifiedSchema = zod_1.z
|
|
211
|
-
.object({
|
|
212
|
-
/** Agent ID from the verified attestation */
|
|
213
|
-
agent_id: zod_1.z.string().min(1).max(256),
|
|
214
|
-
/** Control type from the verified attestation */
|
|
215
|
-
control_type: exports.ControlTypeSchema,
|
|
216
|
-
/** When the publisher verified the identity (RFC 3339) */
|
|
217
|
-
verified_at: zod_1.z.string().datetime(),
|
|
218
|
-
/** Key ID that was used for verification */
|
|
219
|
-
key_id: zod_1.z.string().min(1).max(256),
|
|
220
|
-
/** SHA-256 hash of the binding message (base64url) */
|
|
221
|
-
binding_hash: zod_1.z.string().min(1).max(64),
|
|
222
|
-
})
|
|
223
|
-
.strict();
|
|
224
|
-
// =============================================================================
|
|
225
|
-
// VALIDATION HELPERS (v0.9.25+)
|
|
226
|
-
// =============================================================================
|
|
227
|
-
/**
|
|
228
|
-
* Validate an AgentIdentityAttestation.
|
|
229
|
-
*
|
|
230
|
-
* @param data - Unknown data to validate
|
|
231
|
-
* @returns Result with validated attestation or error message
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```typescript
|
|
235
|
-
* const result = validateAgentIdentityAttestation(data);
|
|
236
|
-
* if (result.ok) {
|
|
237
|
-
* console.log('Agent ID:', result.value.evidence.agent_id);
|
|
238
|
-
* } else {
|
|
239
|
-
* console.error('Validation error:', result.error);
|
|
240
|
-
* }
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
function validateAgentIdentityAttestation(data) {
|
|
244
|
-
const result = exports.AgentIdentityAttestationSchema.safeParse(data);
|
|
245
|
-
if (result.success) {
|
|
246
|
-
return { ok: true, value: result.data };
|
|
247
|
-
}
|
|
248
|
-
return { ok: false, error: result.error.message };
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Check if an object is an AgentIdentityAttestation.
|
|
252
|
-
*
|
|
253
|
-
* @param attestation - Object with a type field
|
|
254
|
-
* @returns True if the type is 'peac/agent-identity'
|
|
255
|
-
*/
|
|
256
|
-
function isAgentIdentityAttestation(attestation) {
|
|
257
|
-
return attestation.type === exports.AGENT_IDENTITY_TYPE;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Create an AgentIdentityAttestation with current timestamp.
|
|
261
|
-
*
|
|
262
|
-
* @param params - Attestation parameters
|
|
263
|
-
* @returns A valid AgentIdentityAttestation
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* ```typescript
|
|
267
|
-
* const attestation = createAgentIdentityAttestation({
|
|
268
|
-
* issuer: 'https://crawler.example.com',
|
|
269
|
-
* agent_id: 'bot:crawler-prod-001',
|
|
270
|
-
* control_type: 'operator',
|
|
271
|
-
* operator: 'Example Crawler Inc.',
|
|
272
|
-
* capabilities: ['crawl', 'index'],
|
|
273
|
-
* });
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
function createAgentIdentityAttestation(params) {
|
|
277
|
-
const evidence = {
|
|
278
|
-
agent_id: params.agent_id,
|
|
279
|
-
control_type: params.control_type,
|
|
280
|
-
};
|
|
281
|
-
if (params.capabilities) {
|
|
282
|
-
evidence.capabilities = params.capabilities;
|
|
283
|
-
}
|
|
284
|
-
if (params.delegation_chain) {
|
|
285
|
-
evidence.delegation_chain = params.delegation_chain;
|
|
286
|
-
}
|
|
287
|
-
if (params.proof) {
|
|
288
|
-
evidence.proof = params.proof;
|
|
289
|
-
}
|
|
290
|
-
if (params.key_directory_url) {
|
|
291
|
-
evidence.key_directory_url = params.key_directory_url;
|
|
292
|
-
}
|
|
293
|
-
if (params.operator) {
|
|
294
|
-
evidence.operator = params.operator;
|
|
295
|
-
}
|
|
296
|
-
if (params.user_id) {
|
|
297
|
-
evidence.user_id = params.user_id;
|
|
298
|
-
}
|
|
299
|
-
if (params.metadata) {
|
|
300
|
-
// Validate metadata is JSON-safe at runtime
|
|
301
|
-
evidence.metadata = params.metadata;
|
|
302
|
-
}
|
|
303
|
-
const attestation = {
|
|
304
|
-
type: exports.AGENT_IDENTITY_TYPE,
|
|
305
|
-
issuer: params.issuer,
|
|
306
|
-
issued_at: new Date().toISOString(),
|
|
307
|
-
evidence,
|
|
308
|
-
};
|
|
309
|
-
if (params.expires_at) {
|
|
310
|
-
attestation.expires_at = params.expires_at;
|
|
311
|
-
}
|
|
312
|
-
if (params.ref) {
|
|
313
|
-
attestation.ref = params.ref;
|
|
314
|
-
}
|
|
315
|
-
return attestation;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Validate an IdentityBinding.
|
|
319
|
-
*
|
|
320
|
-
* @param data - Unknown data to validate
|
|
321
|
-
* @returns Result with validated binding or error message
|
|
322
|
-
*/
|
|
323
|
-
function validateIdentityBinding(data) {
|
|
324
|
-
const result = exports.IdentityBindingSchema.safeParse(data);
|
|
325
|
-
if (result.success) {
|
|
326
|
-
return { ok: true, value: result.data };
|
|
327
|
-
}
|
|
328
|
-
return { ok: false, error: result.error.message };
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Check if an agent identity attestation is expired.
|
|
332
|
-
*
|
|
333
|
-
* @param attestation - The attestation to check
|
|
334
|
-
* @param clockSkew - Optional clock skew tolerance in milliseconds (default: 30000)
|
|
335
|
-
* @returns True if the attestation has expired
|
|
336
|
-
*/
|
|
337
|
-
function isAttestationExpired(attestation, clockSkew = 30000) {
|
|
338
|
-
if (!attestation.expires_at) {
|
|
339
|
-
return false; // No expiry = never expires
|
|
340
|
-
}
|
|
341
|
-
const expiresAt = new Date(attestation.expires_at).getTime();
|
|
342
|
-
const now = Date.now();
|
|
343
|
-
return expiresAt < now - clockSkew;
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Check if an agent identity attestation is not yet valid.
|
|
347
|
-
*
|
|
348
|
-
* @param attestation - The attestation to check
|
|
349
|
-
* @param clockSkew - Optional clock skew tolerance in milliseconds (default: 30000)
|
|
350
|
-
* @returns True if the attestation is not yet valid (issued_at in the future)
|
|
351
|
-
*/
|
|
352
|
-
function isAttestationNotYetValid(attestation, clockSkew = 30000) {
|
|
353
|
-
const issuedAt = new Date(attestation.issued_at).getTime();
|
|
354
|
-
const now = Date.now();
|
|
355
|
-
return issuedAt > now + clockSkew;
|
|
356
|
-
}
|
|
357
|
-
//# sourceMappingURL=agent-identity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-identity.js","sourceRoot":"","sources":["../src/agent-identity.ts"],"names":[],"mappings":";;;AAqSA,4EAQC;AAQD,gEAIC;AAiDD,wEA8CC;AAQD,0DAQC;AASD,oDAUC;AASD,4DAOC;AA3cD;;;;;;;GAOG;AACH,6BAAwB;AAExB,iCAAyC;AAEzC,gFAAgF;AAChF,0BAA0B;AAC1B,gFAAgF;AAEhF;;;;;GAKG;AACU,QAAA,iBAAiB,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAGxE;;GAEG;AACU,QAAA,aAAa,GAAG,CAAC,UAAU,EAAE,gBAAgB,CAAU,CAAC;AAErE,gFAAgF;AAChF,0BAA0B;AAC1B,gFAAgF;AAEhF;;;;;;;GAOG;AACU,QAAA,iBAAiB,GAAG,OAAC,CAAC,IAAI,CAAC;IACtC,wBAAwB;IACxB,MAAM;IACN,MAAM;IACN,gBAAgB;CACjB,CAAC,CAAC;AAGH;;GAEG;AACU,QAAA,aAAa,GAAG,CAAC,wBAAwB,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAU,CAAC;AAEnG,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,OAAC;KAClC,MAAM,CAAC;IACN,+CAA+C;IAC/C,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IAEjC,gCAAgC;IAChC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CA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ation Receipt Types (v0.10.8+)
|
|
4
|
-
*
|
|
5
|
-
* Attestation receipts are lightweight signed tokens that attest to API
|
|
6
|
-
* interactions WITHOUT payment fields. This is a distinct profile from
|
|
7
|
-
* full payment receipts (PEACReceiptClaims).
|
|
8
|
-
*
|
|
9
|
-
* Use cases:
|
|
10
|
-
* - API interaction logging with evidentiary value
|
|
11
|
-
* - Middleware-issued receipts for non-payment flows
|
|
12
|
-
* - Audit trails for agent/tool interactions
|
|
13
|
-
*
|
|
14
|
-
* Claims structure:
|
|
15
|
-
* - Core JWT claims: iss, aud, iat, exp
|
|
16
|
-
* - PEAC claims: rid (UUIDv7 receipt ID)
|
|
17
|
-
* - Optional: sub, ext (extensions including interaction binding)
|
|
18
|
-
*
|
|
19
|
-
* @see docs/specs/ATTESTATION-RECEIPTS.md
|
|
20
|
-
*/
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.AttestationReceiptClaimsSchema = exports.AttestationExtensionsSchema = exports.MinimalInteractionBindingSchema = exports.ATTESTATION_LIMITS = exports.MIDDLEWARE_INTERACTION_KEY = exports.ATTESTATION_RECEIPT_TYPE = void 0;
|
|
23
|
-
exports.validateAttestationReceiptClaims = validateAttestationReceiptClaims;
|
|
24
|
-
exports.isAttestationReceiptClaims = isAttestationReceiptClaims;
|
|
25
|
-
exports.validateMinimalInteractionBinding = validateMinimalInteractionBinding;
|
|
26
|
-
exports.isMinimalInteractionBinding = isMinimalInteractionBinding;
|
|
27
|
-
exports.createAttestationReceiptClaims = createAttestationReceiptClaims;
|
|
28
|
-
exports.isAttestationOnly = isAttestationOnly;
|
|
29
|
-
exports.isPaymentReceipt = isPaymentReceipt;
|
|
30
|
-
const zod_1 = require("zod");
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// Constants
|
|
33
|
-
// ============================================================================
|
|
34
|
-
/**
|
|
35
|
-
* Attestation receipt type constant
|
|
36
|
-
*/
|
|
37
|
-
exports.ATTESTATION_RECEIPT_TYPE = 'peac/attestation-receipt';
|
|
38
|
-
/**
|
|
39
|
-
* Extension key for minimal interaction binding (middleware profile)
|
|
40
|
-
*
|
|
41
|
-
* This is a simplified binding used by middleware packages. For full
|
|
42
|
-
* interaction evidence, use INTERACTION_EXTENSION_KEY from ./interaction.ts
|
|
43
|
-
*/
|
|
44
|
-
exports.MIDDLEWARE_INTERACTION_KEY = 'org.peacprotocol/middleware-interaction@0.1';
|
|
45
|
-
/**
|
|
46
|
-
* Limits for attestation receipt fields (DoS protection)
|
|
47
|
-
*/
|
|
48
|
-
exports.ATTESTATION_LIMITS = {
|
|
49
|
-
/** Maximum issuer URL length */
|
|
50
|
-
maxIssuerLength: 2048,
|
|
51
|
-
/** Maximum audience URL length */
|
|
52
|
-
maxAudienceLength: 2048,
|
|
53
|
-
/** Maximum subject length */
|
|
54
|
-
maxSubjectLength: 256,
|
|
55
|
-
/** Maximum path length in interaction binding */
|
|
56
|
-
maxPathLength: 2048,
|
|
57
|
-
/** Maximum method length */
|
|
58
|
-
maxMethodLength: 16,
|
|
59
|
-
/** Maximum HTTP status code */
|
|
60
|
-
maxStatusCode: 599,
|
|
61
|
-
/** Minimum HTTP status code */
|
|
62
|
-
minStatusCode: 100,
|
|
63
|
-
};
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// Zod Schemas
|
|
66
|
-
// ============================================================================
|
|
67
|
-
/**
|
|
68
|
-
* HTTPS URL validation (reused from validators.ts pattern)
|
|
69
|
-
*/
|
|
70
|
-
const httpsUrl = zod_1.z
|
|
71
|
-
.string()
|
|
72
|
-
.url()
|
|
73
|
-
.max(exports.ATTESTATION_LIMITS.maxIssuerLength)
|
|
74
|
-
.refine((url) => url.startsWith('https://'), 'Must be HTTPS URL');
|
|
75
|
-
/**
|
|
76
|
-
* UUIDv7 format validation
|
|
77
|
-
*/
|
|
78
|
-
const uuidv7 = zod_1.z
|
|
79
|
-
.string()
|
|
80
|
-
.regex(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, 'Must be UUIDv7 format');
|
|
81
|
-
/**
|
|
82
|
-
* Minimal interaction binding schema (for middleware use)
|
|
83
|
-
*
|
|
84
|
-
* This is a simplified version of full interaction evidence.
|
|
85
|
-
* Contains only: method, path, status.
|
|
86
|
-
*
|
|
87
|
-
* Privacy note: Query strings are excluded by default to avoid
|
|
88
|
-
* leaking sensitive data (API keys, tokens, PII in parameters).
|
|
89
|
-
*/
|
|
90
|
-
exports.MinimalInteractionBindingSchema = zod_1.z
|
|
91
|
-
.object({
|
|
92
|
-
/** HTTP method (uppercase, e.g., GET, POST) */
|
|
93
|
-
method: zod_1.z
|
|
94
|
-
.string()
|
|
95
|
-
.min(1)
|
|
96
|
-
.max(exports.ATTESTATION_LIMITS.maxMethodLength)
|
|
97
|
-
.transform((m) => m.toUpperCase()),
|
|
98
|
-
/** Request path (no query string by default) */
|
|
99
|
-
path: zod_1.z.string().min(1).max(exports.ATTESTATION_LIMITS.maxPathLength),
|
|
100
|
-
/** HTTP response status code */
|
|
101
|
-
status: zod_1.z
|
|
102
|
-
.number()
|
|
103
|
-
.int()
|
|
104
|
-
.min(exports.ATTESTATION_LIMITS.minStatusCode)
|
|
105
|
-
.max(exports.ATTESTATION_LIMITS.maxStatusCode),
|
|
106
|
-
})
|
|
107
|
-
.strict();
|
|
108
|
-
/**
|
|
109
|
-
* Attestation receipt extensions schema
|
|
110
|
-
*
|
|
111
|
-
* Allows interaction binding and other namespaced extensions.
|
|
112
|
-
*/
|
|
113
|
-
exports.AttestationExtensionsSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
114
|
-
/**
|
|
115
|
-
* PEAC Attestation Receipt Claims schema
|
|
116
|
-
*
|
|
117
|
-
* This is the claims structure for attestation receipts - lightweight
|
|
118
|
-
* receipts without payment fields. For full payment receipts, use
|
|
119
|
-
* ReceiptClaimsSchema from ./validators.ts
|
|
120
|
-
*/
|
|
121
|
-
exports.AttestationReceiptClaimsSchema = zod_1.z
|
|
122
|
-
.object({
|
|
123
|
-
/** Issuer URL (normalized, no trailing slash) */
|
|
124
|
-
iss: httpsUrl,
|
|
125
|
-
/** Audience URL */
|
|
126
|
-
aud: httpsUrl,
|
|
127
|
-
/** Issued at (Unix seconds) */
|
|
128
|
-
iat: zod_1.z.number().int().nonnegative(),
|
|
129
|
-
/** Expiration (Unix seconds) */
|
|
130
|
-
exp: zod_1.z.number().int().nonnegative(),
|
|
131
|
-
/** Receipt ID (UUIDv7) */
|
|
132
|
-
rid: uuidv7,
|
|
133
|
-
/** Subject identifier (optional) */
|
|
134
|
-
sub: zod_1.z.string().max(exports.ATTESTATION_LIMITS.maxSubjectLength).optional(),
|
|
135
|
-
/** Extensions (optional) */
|
|
136
|
-
ext: exports.AttestationExtensionsSchema.optional(),
|
|
137
|
-
})
|
|
138
|
-
.strict();
|
|
139
|
-
/**
|
|
140
|
-
* Validate attestation receipt claims
|
|
141
|
-
*
|
|
142
|
-
* @param input - Raw input to validate
|
|
143
|
-
* @returns Validation result
|
|
144
|
-
*/
|
|
145
|
-
function validateAttestationReceiptClaims(input) {
|
|
146
|
-
const result = exports.AttestationReceiptClaimsSchema.safeParse(input);
|
|
147
|
-
if (result.success) {
|
|
148
|
-
return { valid: true };
|
|
149
|
-
}
|
|
150
|
-
const firstIssue = result.error.issues[0];
|
|
151
|
-
return {
|
|
152
|
-
valid: false,
|
|
153
|
-
error_code: 'E_ATTESTATION_INVALID_CLAIMS',
|
|
154
|
-
error_message: firstIssue?.message || 'Invalid attestation receipt claims',
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Check if an object is valid attestation receipt claims (non-throwing)
|
|
159
|
-
*
|
|
160
|
-
* @param claims - Object to check
|
|
161
|
-
* @returns True if valid AttestationReceiptClaims
|
|
162
|
-
*/
|
|
163
|
-
function isAttestationReceiptClaims(claims) {
|
|
164
|
-
return exports.AttestationReceiptClaimsSchema.safeParse(claims).success;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Validate minimal interaction binding
|
|
168
|
-
*
|
|
169
|
-
* @param input - Raw input to validate
|
|
170
|
-
* @returns Validation result
|
|
171
|
-
*/
|
|
172
|
-
function validateMinimalInteractionBinding(input) {
|
|
173
|
-
const result = exports.MinimalInteractionBindingSchema.safeParse(input);
|
|
174
|
-
if (result.success) {
|
|
175
|
-
return { valid: true };
|
|
176
|
-
}
|
|
177
|
-
const firstIssue = result.error.issues[0];
|
|
178
|
-
return {
|
|
179
|
-
valid: false,
|
|
180
|
-
error_code: 'E_ATTESTATION_INVALID_INTERACTION',
|
|
181
|
-
error_message: firstIssue?.message || 'Invalid interaction binding',
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Check if an object is valid minimal interaction binding (non-throwing)
|
|
186
|
-
*
|
|
187
|
-
* @param binding - Object to check
|
|
188
|
-
* @returns True if valid MinimalInteractionBinding
|
|
189
|
-
*/
|
|
190
|
-
function isMinimalInteractionBinding(binding) {
|
|
191
|
-
return exports.MinimalInteractionBindingSchema.safeParse(binding).success;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Create validated attestation receipt claims
|
|
195
|
-
*
|
|
196
|
-
* @param params - Attestation receipt parameters
|
|
197
|
-
* @returns Validated AttestationReceiptClaims
|
|
198
|
-
* @throws ZodError if validation fails
|
|
199
|
-
*/
|
|
200
|
-
function createAttestationReceiptClaims(params) {
|
|
201
|
-
const now = Math.floor(Date.now() / 1000);
|
|
202
|
-
const expiresIn = params.expiresIn ?? 300;
|
|
203
|
-
// Normalize issuer (remove trailing slashes)
|
|
204
|
-
// Using explicit loop instead of regex to avoid ReDoS with quantifiers
|
|
205
|
-
let normalizedIssuer = params.issuer;
|
|
206
|
-
while (normalizedIssuer.endsWith('/')) {
|
|
207
|
-
normalizedIssuer = normalizedIssuer.slice(0, -1);
|
|
208
|
-
}
|
|
209
|
-
// Build extensions
|
|
210
|
-
const ext = { ...params.extensions };
|
|
211
|
-
if (params.interaction) {
|
|
212
|
-
ext[exports.MIDDLEWARE_INTERACTION_KEY] = params.interaction;
|
|
213
|
-
}
|
|
214
|
-
const claims = {
|
|
215
|
-
iss: normalizedIssuer,
|
|
216
|
-
aud: params.audience,
|
|
217
|
-
iat: now,
|
|
218
|
-
exp: now + expiresIn,
|
|
219
|
-
rid: params.rid,
|
|
220
|
-
...(params.sub && { sub: params.sub }),
|
|
221
|
-
...(Object.keys(ext).length > 0 && { ext }),
|
|
222
|
-
};
|
|
223
|
-
return exports.AttestationReceiptClaimsSchema.parse(claims);
|
|
224
|
-
}
|
|
225
|
-
// ============================================================================
|
|
226
|
-
// Type Guard for Receipt Profile Discrimination
|
|
227
|
-
// ============================================================================
|
|
228
|
-
/**
|
|
229
|
-
* Check if claims are attestation-only (no payment fields)
|
|
230
|
-
*
|
|
231
|
-
* This helps discriminate between attestation receipts and
|
|
232
|
-
* full payment receipts at runtime.
|
|
233
|
-
*
|
|
234
|
-
* @param claims - Receipt claims to check
|
|
235
|
-
* @returns True if claims lack payment fields (amt, cur, payment)
|
|
236
|
-
*/
|
|
237
|
-
function isAttestationOnly(claims) {
|
|
238
|
-
return !('amt' in claims) && !('cur' in claims) && !('payment' in claims);
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Check if claims are payment receipt (has payment fields)
|
|
242
|
-
*
|
|
243
|
-
* @param claims - Receipt claims to check
|
|
244
|
-
* @returns True if claims have payment fields
|
|
245
|
-
*/
|
|
246
|
-
function isPaymentReceipt(claims) {
|
|
247
|
-
return 'amt' in claims && 'cur' in claims && 'payment' in claims;
|
|
248
|
-
}
|
|
249
|
-
//# sourceMappingURL=attestation-receipt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attestation-receipt.js","sourceRoot":"","sources":["../src/attestation-receipt.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAwJH,4EAWC;AAQD,gEA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