@t402/erc8004 2.7.0

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,704 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ERC8004_EXTENSION_KEY: () => ERC8004_EXTENSION_KEY,
24
+ FEEDBACK_TAGS: () => FEEDBACK_TAGS,
25
+ IDENTITY_REGISTRIES: () => IDENTITY_REGISTRIES,
26
+ IDENTITY_REGISTRY_DOMAIN: () => IDENTITY_REGISTRY_DOMAIN,
27
+ REPUTATION_REGISTRIES: () => REPUTATION_REGISTRIES,
28
+ SET_AGENT_WALLET_TYPES: () => SET_AGENT_WALLET_TYPES,
29
+ VALIDATION_REGISTRIES: () => VALIDATION_REGISTRIES,
30
+ buildFeedbackFile: () => buildFeedbackFile,
31
+ createERC8004PayloadExtension: () => createERC8004PayloadExtension,
32
+ declareERC8004Extension: () => declareERC8004Extension,
33
+ erc8004IdentityCheck: () => erc8004IdentityCheck,
34
+ erc8004ReputationCheck: () => erc8004ReputationCheck,
35
+ erc8004ResourceServerExtension: () => erc8004ResourceServerExtension,
36
+ erc8004ServerIdentityCheck: () => erc8004ServerIdentityCheck,
37
+ erc8004SubmitFeedback: () => erc8004SubmitFeedback,
38
+ fetchRegistrationFile: () => fetchRegistrationFile,
39
+ getAgentIdentity: () => getAgentIdentity,
40
+ getERC8004Extension: () => getERC8004Extension,
41
+ getReputationSummary: () => getReputationSummary,
42
+ getValidationStatus: () => getValidationStatus,
43
+ getValidationSummary: () => getValidationSummary,
44
+ identityRegistryAbi: () => identityRegistryAbi,
45
+ parseAgentRegistry: () => parseAgentRegistry,
46
+ reputationRegistryAbi: () => reputationRegistryAbi,
47
+ resolveAgent: () => resolveAgent,
48
+ submitFeedback: () => submitFeedback,
49
+ submitValidationRequest: () => submitValidationRequest,
50
+ validationRegistryAbi: () => validationRegistryAbi,
51
+ verifyAgentIdentity: () => verifyAgentIdentity,
52
+ verifyAgentIdentityFromTask: () => verifyAgentIdentityFromTask,
53
+ verifyPayToMatchesAgent: () => verifyPayToMatchesAgent
54
+ });
55
+ module.exports = __toCommonJS(index_exports);
56
+
57
+ // src/constants.ts
58
+ var IDENTITY_REGISTRIES = {};
59
+ var REPUTATION_REGISTRIES = {};
60
+ var VALIDATION_REGISTRIES = {};
61
+ var ERC8004_EXTENSION_KEY = "erc8004";
62
+ var FEEDBACK_TAGS = {
63
+ /** tag1: Payment completed successfully */
64
+ PAYMENT_SUCCESS: "paymentSuccess",
65
+ /** tag1: Payment verification failed */
66
+ PAYMENT_FAILED: "paymentFailed",
67
+ /** tag1: Service quality rating */
68
+ SERVICE_QUALITY: "starred",
69
+ /** tag2: Response time measurement */
70
+ RESPONSE_TIME: "responseTime",
71
+ /** tag2: Uptime measurement */
72
+ UPTIME: "uptime"
73
+ };
74
+ var IDENTITY_REGISTRY_DOMAIN = {
75
+ name: "IdentityRegistry",
76
+ version: "1"
77
+ };
78
+ var SET_AGENT_WALLET_TYPES = {
79
+ SetAgentWallet: [
80
+ { name: "agentId", type: "uint256" },
81
+ { name: "newWallet", type: "address" },
82
+ { name: "deadline", type: "uint256" },
83
+ { name: "nonce", type: "uint256" }
84
+ ]
85
+ };
86
+
87
+ // src/abis.ts
88
+ var identityRegistryAbi = [
89
+ {
90
+ type: "function",
91
+ name: "register",
92
+ inputs: [
93
+ { name: "agentURI", type: "string" },
94
+ {
95
+ name: "metadata",
96
+ type: "tuple[]",
97
+ components: [
98
+ { name: "metadataKey", type: "string" },
99
+ { name: "metadataValue", type: "bytes" }
100
+ ]
101
+ }
102
+ ],
103
+ outputs: [{ type: "uint256" }],
104
+ stateMutability: "nonpayable"
105
+ },
106
+ {
107
+ type: "function",
108
+ name: "getAgentWallet",
109
+ inputs: [{ name: "agentId", type: "uint256" }],
110
+ outputs: [{ type: "address" }],
111
+ stateMutability: "view"
112
+ },
113
+ {
114
+ type: "function",
115
+ name: "tokenURI",
116
+ inputs: [{ name: "tokenId", type: "uint256" }],
117
+ outputs: [{ type: "string" }],
118
+ stateMutability: "view"
119
+ },
120
+ {
121
+ type: "function",
122
+ name: "ownerOf",
123
+ inputs: [{ name: "tokenId", type: "uint256" }],
124
+ outputs: [{ type: "address" }],
125
+ stateMutability: "view"
126
+ },
127
+ {
128
+ type: "function",
129
+ name: "getMetadata",
130
+ inputs: [
131
+ { name: "agentId", type: "uint256" },
132
+ { name: "metadataKey", type: "string" }
133
+ ],
134
+ outputs: [{ type: "bytes" }],
135
+ stateMutability: "view"
136
+ },
137
+ {
138
+ type: "function",
139
+ name: "setAgentWallet",
140
+ inputs: [
141
+ { name: "agentId", type: "uint256" },
142
+ { name: "newWallet", type: "address" },
143
+ { name: "deadline", type: "uint256" },
144
+ { name: "signature", type: "bytes" }
145
+ ],
146
+ outputs: [],
147
+ stateMutability: "nonpayable"
148
+ },
149
+ {
150
+ type: "event",
151
+ name: "Registered",
152
+ inputs: [
153
+ { name: "agentId", type: "uint256", indexed: true },
154
+ { name: "agentURI", type: "string", indexed: false },
155
+ { name: "owner", type: "address", indexed: true }
156
+ ]
157
+ }
158
+ ];
159
+ var reputationRegistryAbi = [
160
+ {
161
+ type: "function",
162
+ name: "giveFeedback",
163
+ inputs: [
164
+ { name: "agentId", type: "uint256" },
165
+ { name: "value", type: "int128" },
166
+ { name: "valueDecimals", type: "uint8" },
167
+ { name: "tag1", type: "string" },
168
+ { name: "tag2", type: "string" },
169
+ { name: "endpoint", type: "string" },
170
+ { name: "feedbackURI", type: "string" },
171
+ { name: "feedbackHash", type: "bytes32" }
172
+ ],
173
+ outputs: [],
174
+ stateMutability: "nonpayable"
175
+ },
176
+ {
177
+ type: "function",
178
+ name: "getSummary",
179
+ inputs: [
180
+ { name: "agentId", type: "uint256" },
181
+ { name: "clientAddresses", type: "address[]" },
182
+ { name: "tag1", type: "string" },
183
+ { name: "tag2", type: "string" }
184
+ ],
185
+ outputs: [
186
+ { name: "count", type: "uint64" },
187
+ { name: "summaryValue", type: "int128" },
188
+ { name: "summaryValueDecimals", type: "uint8" }
189
+ ],
190
+ stateMutability: "view"
191
+ },
192
+ {
193
+ type: "function",
194
+ name: "revokeFeedback",
195
+ inputs: [
196
+ { name: "agentId", type: "uint256" },
197
+ { name: "feedbackIndex", type: "uint64" }
198
+ ],
199
+ outputs: [],
200
+ stateMutability: "nonpayable"
201
+ },
202
+ {
203
+ type: "function",
204
+ name: "getClients",
205
+ inputs: [{ name: "agentId", type: "uint256" }],
206
+ outputs: [{ type: "address[]" }],
207
+ stateMutability: "view"
208
+ },
209
+ {
210
+ type: "event",
211
+ name: "NewFeedback",
212
+ inputs: [
213
+ { name: "agentId", type: "uint256", indexed: true },
214
+ { name: "clientAddress", type: "address", indexed: true },
215
+ { name: "feedbackIndex", type: "uint64", indexed: false },
216
+ { name: "value", type: "int128", indexed: false },
217
+ { name: "valueDecimals", type: "uint8", indexed: false },
218
+ { name: "indexedTag1", type: "string", indexed: true },
219
+ { name: "tag1", type: "string", indexed: false },
220
+ { name: "tag2", type: "string", indexed: false },
221
+ { name: "endpoint", type: "string", indexed: false },
222
+ { name: "feedbackURI", type: "string", indexed: false },
223
+ { name: "feedbackHash", type: "bytes32", indexed: false }
224
+ ]
225
+ }
226
+ ];
227
+ var validationRegistryAbi = [
228
+ {
229
+ type: "function",
230
+ name: "validationRequest",
231
+ inputs: [
232
+ { name: "validatorAddress", type: "address" },
233
+ { name: "agentId", type: "uint256" },
234
+ { name: "requestURI", type: "string" },
235
+ { name: "requestHash", type: "bytes32" }
236
+ ],
237
+ outputs: [],
238
+ stateMutability: "nonpayable"
239
+ },
240
+ {
241
+ type: "function",
242
+ name: "validationResponse",
243
+ inputs: [
244
+ { name: "requestHash", type: "bytes32" },
245
+ { name: "response", type: "uint8" },
246
+ { name: "responseURI", type: "string" },
247
+ { name: "responseHash", type: "bytes32" },
248
+ { name: "tag", type: "string" }
249
+ ],
250
+ outputs: [],
251
+ stateMutability: "nonpayable"
252
+ },
253
+ {
254
+ type: "function",
255
+ name: "getValidationStatus",
256
+ inputs: [{ name: "requestHash", type: "bytes32" }],
257
+ outputs: [
258
+ { name: "validatorAddress", type: "address" },
259
+ { name: "agentId", type: "uint256" },
260
+ { name: "response", type: "uint8" },
261
+ { name: "responseHash", type: "bytes32" },
262
+ { name: "tag", type: "string" },
263
+ { name: "lastUpdate", type: "uint256" }
264
+ ],
265
+ stateMutability: "view"
266
+ },
267
+ {
268
+ type: "function",
269
+ name: "getSummary",
270
+ inputs: [
271
+ { name: "agentId", type: "uint256" },
272
+ { name: "validatorAddresses", type: "address[]" },
273
+ { name: "tag", type: "string" }
274
+ ],
275
+ outputs: [
276
+ { name: "count", type: "uint64" },
277
+ { name: "averageResponse", type: "uint8" }
278
+ ],
279
+ stateMutability: "view"
280
+ },
281
+ {
282
+ type: "event",
283
+ name: "ValidationRequest",
284
+ inputs: [
285
+ { name: "validatorAddress", type: "address", indexed: true },
286
+ { name: "agentId", type: "uint256", indexed: true },
287
+ { name: "requestURI", type: "string", indexed: false },
288
+ { name: "requestHash", type: "bytes32", indexed: true }
289
+ ]
290
+ },
291
+ {
292
+ type: "event",
293
+ name: "ValidationResponse",
294
+ inputs: [
295
+ { name: "validatorAddress", type: "address", indexed: true },
296
+ { name: "agentId", type: "uint256", indexed: true },
297
+ { name: "requestHash", type: "bytes32", indexed: true },
298
+ { name: "response", type: "uint8", indexed: false },
299
+ { name: "responseURI", type: "string", indexed: false },
300
+ { name: "responseHash", type: "bytes32", indexed: false },
301
+ { name: "tag", type: "string", indexed: false }
302
+ ]
303
+ }
304
+ ];
305
+
306
+ // src/identity.ts
307
+ function parseAgentRegistry(registryId) {
308
+ const parts = registryId.split(":");
309
+ if (parts.length < 3) {
310
+ throw new Error(
311
+ `Invalid agent registry ID: ${registryId}. Expected format: namespace:chainId:address`
312
+ );
313
+ }
314
+ const namespace = parts[0];
315
+ const chainId = parts[1];
316
+ const address = parts.slice(2).join(":");
317
+ if (!namespace || !chainId || !address) {
318
+ throw new Error(
319
+ `Invalid agent registry ID: ${registryId}. All parts must be non-empty`
320
+ );
321
+ }
322
+ return { namespace, chainId, address, id: registryId };
323
+ }
324
+ async function getAgentIdentity(client, identityRegistry, agentId, registryId) {
325
+ const [agentWallet, owner, agentURI] = await Promise.all([
326
+ client.readContract({
327
+ address: identityRegistry,
328
+ abi: identityRegistryAbi,
329
+ functionName: "getAgentWallet",
330
+ args: [agentId]
331
+ }),
332
+ client.readContract({
333
+ address: identityRegistry,
334
+ abi: identityRegistryAbi,
335
+ functionName: "ownerOf",
336
+ args: [agentId]
337
+ }),
338
+ client.readContract({
339
+ address: identityRegistry,
340
+ abi: identityRegistryAbi,
341
+ functionName: "tokenURI",
342
+ args: [agentId]
343
+ })
344
+ ]);
345
+ return {
346
+ agentId,
347
+ owner,
348
+ agentURI,
349
+ agentWallet,
350
+ registry: parseAgentRegistry(registryId)
351
+ };
352
+ }
353
+ async function fetchRegistrationFile(agentURI) {
354
+ const response = await fetch(agentURI);
355
+ if (!response.ok) {
356
+ throw new Error(
357
+ `Failed to fetch registration file from ${agentURI}: ${response.status}`
358
+ );
359
+ }
360
+ return response.json();
361
+ }
362
+ async function resolveAgent(client, identityRegistry, agentId, registryId) {
363
+ const identity = await getAgentIdentity(
364
+ client,
365
+ identityRegistry,
366
+ agentId,
367
+ registryId
368
+ );
369
+ const registration = await fetchRegistrationFile(identity.agentURI);
370
+ return { ...identity, registration };
371
+ }
372
+ async function verifyPayToMatchesAgent(client, identityRegistry, agentId, payTo) {
373
+ const agentWallet = await client.readContract({
374
+ address: identityRegistry,
375
+ abi: identityRegistryAbi,
376
+ functionName: "getAgentWallet",
377
+ args: [agentId]
378
+ });
379
+ return agentWallet.toLowerCase() === payTo.toLowerCase();
380
+ }
381
+
382
+ // src/reputation.ts
383
+ async function getReputationSummary(client, reputationRegistry, agentId, trustedReviewers, tag1 = "", tag2 = "") {
384
+ const result = await client.readContract({
385
+ address: reputationRegistry,
386
+ abi: reputationRegistryAbi,
387
+ functionName: "getSummary",
388
+ args: [agentId, trustedReviewers, tag1, tag2]
389
+ });
390
+ const [count, summaryValue, summaryValueDecimals] = result;
391
+ const divisor = 10 ** summaryValueDecimals;
392
+ const normalizedScore = count > 0n ? Math.min(100, Math.max(0, Number(summaryValue) / divisor)) : 0;
393
+ return {
394
+ agentId,
395
+ count,
396
+ summaryValue,
397
+ summaryValueDecimals,
398
+ normalizedScore
399
+ };
400
+ }
401
+ function buildFeedbackFile(agentId, agentRegistry, clientAddress, value, valueDecimals, tag1, tag2, proofOfPayment) {
402
+ return {
403
+ agentRegistry,
404
+ agentId,
405
+ clientAddress,
406
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
407
+ value,
408
+ valueDecimals,
409
+ tag1,
410
+ tag2,
411
+ ...proofOfPayment && { proofOfPayment }
412
+ };
413
+ }
414
+ async function submitFeedback(client, reputationRegistry, params) {
415
+ return client.writeContract({
416
+ address: reputationRegistry,
417
+ abi: reputationRegistryAbi,
418
+ functionName: "giveFeedback",
419
+ args: [
420
+ params.agentId,
421
+ params.value,
422
+ params.valueDecimals,
423
+ params.tag1,
424
+ params.tag2,
425
+ params.endpoint ?? "",
426
+ params.feedbackURI ?? "",
427
+ params.feedbackHash ?? "0x" + "0".repeat(64)
428
+ ]
429
+ });
430
+ }
431
+
432
+ // src/validation.ts
433
+ async function submitValidationRequest(client, validationRegistry, params) {
434
+ return client.writeContract({
435
+ address: validationRegistry,
436
+ abi: validationRegistryAbi,
437
+ functionName: "validationRequest",
438
+ args: [
439
+ params.validatorAddress,
440
+ params.agentId,
441
+ params.requestURI,
442
+ params.requestHash
443
+ ]
444
+ });
445
+ }
446
+ async function getValidationStatus(client, validationRegistry, requestHash) {
447
+ const result = await client.readContract({
448
+ address: validationRegistry,
449
+ abi: validationRegistryAbi,
450
+ functionName: "getValidationStatus",
451
+ args: [requestHash]
452
+ });
453
+ return {
454
+ validatorAddress: result[0],
455
+ agentId: result[1],
456
+ response: result[2],
457
+ responseHash: result[3],
458
+ tag: result[4],
459
+ lastUpdate: result[5]
460
+ };
461
+ }
462
+ async function getValidationSummary(client, validationRegistry, agentId, validatorAddresses, tag = "") {
463
+ const result = await client.readContract({
464
+ address: validationRegistry,
465
+ abi: validationRegistryAbi,
466
+ functionName: "getSummary",
467
+ args: [agentId, validatorAddresses, tag]
468
+ });
469
+ return {
470
+ count: result[0],
471
+ averageResponse: result[1]
472
+ };
473
+ }
474
+
475
+ // src/extension.ts
476
+ function declareERC8004Extension(agentId, agentRegistry, agentWallet) {
477
+ return {
478
+ agentId,
479
+ agentRegistry,
480
+ ...agentWallet && { agentWallet }
481
+ };
482
+ }
483
+ function getERC8004Extension(paymentRequired) {
484
+ return paymentRequired.extensions?.[ERC8004_EXTENSION_KEY];
485
+ }
486
+ function createERC8004PayloadExtension(agentId, agentRegistry, verified) {
487
+ return {
488
+ identityVerified: verified,
489
+ agentId,
490
+ agentRegistry
491
+ };
492
+ }
493
+ async function verifyAgentIdentity(client, paymentRequired) {
494
+ const ext = getERC8004Extension(paymentRequired);
495
+ if (!ext) return false;
496
+ const registry = ext.agentRegistry.split(":");
497
+ const registryAddress = registry.slice(2).join(":");
498
+ for (const accept of paymentRequired.accepts) {
499
+ const matches = await verifyPayToMatchesAgent(
500
+ client,
501
+ registryAddress,
502
+ BigInt(ext.agentId),
503
+ accept.payTo
504
+ );
505
+ if (!matches) return false;
506
+ }
507
+ return true;
508
+ }
509
+ function erc8004ResourceServerExtension(config) {
510
+ return {
511
+ key: ERC8004_EXTENSION_KEY,
512
+ enrichDeclaration: async (declaration) => {
513
+ let enriched = declaration;
514
+ if (config.reputationRegistry && config.trustedReviewers?.length) {
515
+ const summary = await getReputationSummary(
516
+ config.client,
517
+ config.reputationRegistry,
518
+ BigInt(enriched.agentId),
519
+ config.trustedReviewers
520
+ );
521
+ enriched = {
522
+ ...enriched,
523
+ reputationScore: summary.normalizedScore,
524
+ feedbackCount: Number(summary.count)
525
+ };
526
+ }
527
+ if (config.validationRegistry && config.trustedValidators?.length) {
528
+ const summary = await getValidationSummary(
529
+ config.client,
530
+ config.validationRegistry,
531
+ BigInt(enriched.agentId),
532
+ config.trustedValidators
533
+ );
534
+ enriched = {
535
+ ...enriched,
536
+ validationScore: summary.averageResponse
537
+ };
538
+ }
539
+ return enriched;
540
+ }
541
+ };
542
+ }
543
+
544
+ // src/hooks.ts
545
+ var import_types = require("@t402/core/types");
546
+ function erc8004IdentityCheck(client, options = {}) {
547
+ const { abortOnFailure = true, abortOnMissing = false } = options;
548
+ return async (context) => {
549
+ const ext = getERC8004Extension(context.paymentRequired);
550
+ if (!ext) {
551
+ if (abortOnMissing) {
552
+ return {
553
+ abort: true,
554
+ reason: "ERC-8004 extension not present in payment requirements"
555
+ };
556
+ }
557
+ return;
558
+ }
559
+ const verified = await verifyAgentIdentity(
560
+ client,
561
+ context.paymentRequired
562
+ );
563
+ if (!verified && abortOnFailure) {
564
+ return {
565
+ abort: true,
566
+ reason: `ERC-8004 identity verification failed for agent ${ext.agentId} on registry ${ext.agentRegistry}`
567
+ };
568
+ }
569
+ };
570
+ }
571
+ async function verifyAgentIdentityFromTask(client, task) {
572
+ const paymentRequired = (0, import_types.getPaymentRequired)(task);
573
+ if (!paymentRequired) return false;
574
+ return verifyAgentIdentity(client, paymentRequired);
575
+ }
576
+ function getPayloadExtension(context) {
577
+ return context.paymentPayload.extensions?.[ERC8004_EXTENSION_KEY];
578
+ }
579
+ function erc8004ReputationCheck(client, reputationRegistry, config) {
580
+ return async (context) => {
581
+ const ext = getPayloadExtension(context);
582
+ if (!ext) return;
583
+ const summary = await getReputationSummary(
584
+ client,
585
+ reputationRegistry,
586
+ BigInt(ext.agentId),
587
+ config.trustedReviewers,
588
+ config.tag1 ?? "",
589
+ config.tag2 ?? ""
590
+ );
591
+ if (summary.normalizedScore < config.minScore) {
592
+ const action = config.onBelowThreshold ?? "reject";
593
+ if (action === "reject") {
594
+ return {
595
+ abort: true,
596
+ reason: `Agent ${ext.agentId} reputation score ${summary.normalizedScore} is below minimum ${config.minScore}`
597
+ };
598
+ }
599
+ console.warn(
600
+ `[erc8004] Agent ${ext.agentId} reputation score ${summary.normalizedScore} is below minimum ${config.minScore}`
601
+ );
602
+ }
603
+ };
604
+ }
605
+ function erc8004ServerIdentityCheck(client) {
606
+ return async (context) => {
607
+ const ext = getPayloadExtension(context);
608
+ if (!ext) return;
609
+ const registry = ext.agentRegistry.split(":");
610
+ const registryAddress = registry.slice(2).join(":");
611
+ const matches = await verifyPayToMatchesAgent(
612
+ client,
613
+ registryAddress,
614
+ BigInt(ext.agentId),
615
+ context.requirements.payTo
616
+ );
617
+ if (!matches) {
618
+ return {
619
+ abort: true,
620
+ reason: `payTo address ${context.requirements.payTo} does not match on-chain agentWallet for agent ${ext.agentId}`
621
+ };
622
+ }
623
+ };
624
+ }
625
+ function erc8004SubmitFeedback(writeClient, reputationRegistry, config = {}) {
626
+ return async (context) => {
627
+ const ext = getPayloadExtension(context);
628
+ if (!ext) return;
629
+ if (!context.result.success) return;
630
+ const tag1 = config.tag1 ?? FEEDBACK_TAGS.PAYMENT_SUCCESS;
631
+ const tag2 = config.tag2 ?? "";
632
+ let feedbackURI = "";
633
+ const feedbackHash = "0x" + "0".repeat(64);
634
+ if (config.includeProofOfPayment && context.result.transaction) {
635
+ buildFeedbackFile(
636
+ ext.agentId,
637
+ ext.agentRegistry,
638
+ context.result.payer ?? "",
639
+ 100,
640
+ 0,
641
+ tag1,
642
+ tag2,
643
+ {
644
+ fromAddress: context.result.payer ?? "",
645
+ toAddress: context.requirements.payTo,
646
+ chainId: context.requirements.network,
647
+ txHash: context.result.transaction
648
+ }
649
+ );
650
+ if (config.feedbackBaseURI) {
651
+ feedbackURI = `${config.feedbackBaseURI}/${context.result.transaction}.json`;
652
+ }
653
+ }
654
+ submitFeedback(writeClient, reputationRegistry, {
655
+ agentId: BigInt(ext.agentId),
656
+ value: 100n,
657
+ valueDecimals: 0,
658
+ tag1,
659
+ tag2,
660
+ endpoint: context.paymentPayload.resource?.url,
661
+ feedbackURI,
662
+ feedbackHash
663
+ }).catch((err) => {
664
+ console.warn(
665
+ `[erc8004] Failed to submit feedback for agent ${ext.agentId}:`,
666
+ err
667
+ );
668
+ });
669
+ };
670
+ }
671
+ // Annotate the CommonJS export names for ESM import in node:
672
+ 0 && (module.exports = {
673
+ ERC8004_EXTENSION_KEY,
674
+ FEEDBACK_TAGS,
675
+ IDENTITY_REGISTRIES,
676
+ IDENTITY_REGISTRY_DOMAIN,
677
+ REPUTATION_REGISTRIES,
678
+ SET_AGENT_WALLET_TYPES,
679
+ VALIDATION_REGISTRIES,
680
+ buildFeedbackFile,
681
+ createERC8004PayloadExtension,
682
+ declareERC8004Extension,
683
+ erc8004IdentityCheck,
684
+ erc8004ReputationCheck,
685
+ erc8004ResourceServerExtension,
686
+ erc8004ServerIdentityCheck,
687
+ erc8004SubmitFeedback,
688
+ fetchRegistrationFile,
689
+ getAgentIdentity,
690
+ getERC8004Extension,
691
+ getReputationSummary,
692
+ getValidationStatus,
693
+ getValidationSummary,
694
+ identityRegistryAbi,
695
+ parseAgentRegistry,
696
+ reputationRegistryAbi,
697
+ resolveAgent,
698
+ submitFeedback,
699
+ submitValidationRequest,
700
+ validationRegistryAbi,
701
+ verifyAgentIdentity,
702
+ verifyAgentIdentityFromTask,
703
+ verifyPayToMatchesAgent
704
+ });