@ch4r10teer41/clawpass 1.0.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/index.mjs ADDED
@@ -0,0 +1,1115 @@
1
+ // src/clients/IdentityRegistryClient.ts
2
+ import { Contract } from "ethers";
3
+
4
+ // src/abis/IdentityRegistry.json
5
+ var IdentityRegistry_default = [
6
+ {
7
+ type: "function",
8
+ name: "register",
9
+ inputs: [
10
+ { name: "agentURI", type: "string" },
11
+ {
12
+ name: "metadata",
13
+ type: "tuple[]",
14
+ components: [
15
+ { name: "metadataKey", type: "string" },
16
+ { name: "metadataValue", type: "bytes" }
17
+ ]
18
+ }
19
+ ],
20
+ outputs: [{ name: "agentId", type: "uint256" }],
21
+ stateMutability: "nonpayable"
22
+ },
23
+ {
24
+ type: "function",
25
+ name: "register",
26
+ inputs: [{ name: "agentURI", type: "string" }],
27
+ outputs: [{ name: "agentId", type: "uint256" }],
28
+ stateMutability: "nonpayable"
29
+ },
30
+ {
31
+ type: "function",
32
+ name: "register",
33
+ inputs: [],
34
+ outputs: [{ name: "agentId", type: "uint256" }],
35
+ stateMutability: "nonpayable"
36
+ },
37
+ {
38
+ type: "function",
39
+ name: "setAgentURI",
40
+ inputs: [
41
+ { name: "agentId", type: "uint256" },
42
+ { name: "newURI", type: "string" }
43
+ ],
44
+ outputs: [],
45
+ stateMutability: "nonpayable"
46
+ },
47
+ {
48
+ type: "function",
49
+ name: "tokenURI",
50
+ inputs: [{ name: "tokenId", type: "uint256" }],
51
+ outputs: [{ name: "", type: "string" }],
52
+ stateMutability: "view"
53
+ },
54
+ {
55
+ type: "function",
56
+ name: "getMetadata",
57
+ inputs: [
58
+ { name: "agentId", type: "uint256" },
59
+ { name: "metadataKey", type: "string" }
60
+ ],
61
+ outputs: [{ name: "", type: "bytes" }],
62
+ stateMutability: "view"
63
+ },
64
+ {
65
+ type: "function",
66
+ name: "setMetadata",
67
+ inputs: [
68
+ { name: "agentId", type: "uint256" },
69
+ { name: "metadataKey", type: "string" },
70
+ { name: "metadataValue", type: "bytes" }
71
+ ],
72
+ outputs: [],
73
+ stateMutability: "nonpayable"
74
+ },
75
+ {
76
+ type: "function",
77
+ name: "getAgentWallet",
78
+ inputs: [{ name: "agentId", type: "uint256" }],
79
+ outputs: [{ name: "", type: "address" }],
80
+ stateMutability: "view"
81
+ },
82
+ {
83
+ type: "function",
84
+ name: "setAgentWallet",
85
+ inputs: [
86
+ { name: "agentId", type: "uint256" },
87
+ { name: "newWallet", type: "address" },
88
+ { name: "deadline", type: "uint256" },
89
+ { name: "signature", type: "bytes" }
90
+ ],
91
+ outputs: [],
92
+ stateMutability: "nonpayable"
93
+ },
94
+ {
95
+ type: "function",
96
+ name: "unsetAgentWallet",
97
+ inputs: [{ name: "agentId", type: "uint256" }],
98
+ outputs: [],
99
+ stateMutability: "nonpayable"
100
+ },
101
+ {
102
+ type: "function",
103
+ name: "ownerOf",
104
+ inputs: [{ name: "tokenId", type: "uint256" }],
105
+ outputs: [{ name: "", type: "address" }],
106
+ stateMutability: "view"
107
+ },
108
+ {
109
+ type: "event",
110
+ name: "Registered",
111
+ inputs: [
112
+ { name: "agentId", type: "uint256", indexed: true },
113
+ { name: "agentURI", type: "string", indexed: false },
114
+ { name: "owner", type: "address", indexed: true }
115
+ ]
116
+ },
117
+ {
118
+ type: "event",
119
+ name: "URIUpdated",
120
+ inputs: [
121
+ { name: "agentId", type: "uint256", indexed: true },
122
+ { name: "newURI", type: "string", indexed: false },
123
+ { name: "updatedBy", type: "address", indexed: true }
124
+ ]
125
+ },
126
+ {
127
+ type: "event",
128
+ name: "MetadataSet",
129
+ inputs: [
130
+ { name: "agentId", type: "uint256", indexed: true },
131
+ { name: "indexedMetadataKey", type: "string", indexed: true },
132
+ { name: "metadataKey", type: "string", indexed: false },
133
+ { name: "metadataValue", type: "bytes", indexed: false }
134
+ ]
135
+ }
136
+ ];
137
+
138
+ // src/schemas/index.ts
139
+ import { z } from "zod";
140
+ var AgentServiceSchema = z.object({
141
+ name: z.string(),
142
+ endpoint: z.string(),
143
+ version: z.string().optional(),
144
+ skills: z.array(z.string()).optional(),
145
+ domains: z.array(z.string()).optional()
146
+ });
147
+ var AgentRegistrationSchema = z.object({
148
+ agentId: z.number(),
149
+ agentRegistry: z.string().regex(/^[^:]+:[^:]+:0x[a-fA-F0-9]{40}$/)
150
+ });
151
+ var AgentRegistrationFileSchema = z.object({
152
+ type: z.literal("https://eips.ethereum.org/EIPS/eip-8004#registration-v1"),
153
+ name: z.string(),
154
+ description: z.string(),
155
+ image: z.string().optional(),
156
+ services: z.array(AgentServiceSchema),
157
+ x402Support: z.boolean(),
158
+ active: z.boolean(),
159
+ registrations: z.array(AgentRegistrationSchema),
160
+ supportedTrust: z.array(z.enum(["reputation", "crypto-economic", "tee-attestation"])).optional()
161
+ });
162
+ var FeedbackFileSchema = z.object({
163
+ agentRegistry: z.string(),
164
+ agentId: z.number(),
165
+ clientAddress: z.string(),
166
+ createdAt: z.string(),
167
+ value: z.number(),
168
+ valueDecimals: z.number().min(0).max(18),
169
+ tag1: z.string().optional(),
170
+ tag2: z.string().optional(),
171
+ endpoint: z.string().optional(),
172
+ mcp: z.object({
173
+ tool: z.string().optional(),
174
+ prompt: z.string().optional(),
175
+ resource: z.string().optional()
176
+ }).optional(),
177
+ a2a: z.object({
178
+ skills: z.array(z.string()).optional(),
179
+ contextId: z.string().optional(),
180
+ taskId: z.string().optional()
181
+ }).optional(),
182
+ oasf: z.object({
183
+ skills: z.array(z.string()).optional(),
184
+ domains: z.array(z.string()).optional()
185
+ }).optional(),
186
+ proofOfPayment: z.object({
187
+ fromAddress: z.string(),
188
+ toAddress: z.string(),
189
+ chainId: z.string(),
190
+ txHash: z.string()
191
+ }).optional()
192
+ });
193
+
194
+ // src/clients/IdentityRegistryClient.ts
195
+ var IdentityRegistryClient = class {
196
+ constructor(contractAddress, providerOrSigner) {
197
+ if ("provider" in providerOrSigner && providerOrSigner.provider) {
198
+ this.signer = providerOrSigner;
199
+ this.contract = new Contract(contractAddress, IdentityRegistry_default, this.signer);
200
+ } else {
201
+ this.contract = new Contract(contractAddress, IdentityRegistry_default, providerOrSigner);
202
+ }
203
+ }
204
+ /**
205
+ * Register a new agent with URI and optional metadata
206
+ */
207
+ async register(agentURI, metadata) {
208
+ if (!this.signer) {
209
+ throw new Error("Signer required for registration");
210
+ }
211
+ let tx;
212
+ if (agentURI && metadata && metadata.length > 0) {
213
+ const formattedMetadata = metadata.map((m) => ({
214
+ metadataKey: m.metadataKey,
215
+ metadataValue: m.metadataValue
216
+ }));
217
+ tx = await this.contract["register(string,(string,bytes)[])"](agentURI, formattedMetadata);
218
+ } else if (agentURI) {
219
+ tx = await this.contract["register(string)"](agentURI);
220
+ } else {
221
+ tx = await this.contract["register()"]();
222
+ }
223
+ const receipt = await tx.wait();
224
+ const event = receipt.logs.find(
225
+ (log) => log.fragment && log.fragment.name === "Registered"
226
+ );
227
+ if (!event) {
228
+ throw new Error("Registration event not found");
229
+ }
230
+ return event.args.agentId;
231
+ }
232
+ /**
233
+ * Update the agent URI
234
+ */
235
+ async setAgentURI(agentId, newURI) {
236
+ if (!this.signer) {
237
+ throw new Error("Signer required for updating URI");
238
+ }
239
+ const tx = await this.contract.setAgentURI(agentId, newURI);
240
+ await tx.wait();
241
+ }
242
+ /**
243
+ * Get the agent URI (tokenURI)
244
+ */
245
+ async getAgentURI(agentId) {
246
+ return await this.contract.tokenURI(agentId);
247
+ }
248
+ /**
249
+ * Fetch and parse the agent registration file from URI
250
+ */
251
+ async getAgentRegistrationFile(agentId) {
252
+ const uri = await this.getAgentURI(agentId);
253
+ let content;
254
+ if (uri.startsWith("data:")) {
255
+ const base64Data = uri.split(",")[1];
256
+ content = Buffer.from(base64Data, "base64").toString("utf-8");
257
+ } else if (uri.startsWith("ipfs://")) {
258
+ const cid = uri.replace("ipfs://", "");
259
+ const response = await fetch(`https://ipfs.io/ipfs/${cid}`);
260
+ content = await response.text();
261
+ } else if (uri.startsWith("http://") || uri.startsWith("https://")) {
262
+ const response = await fetch(uri);
263
+ content = await response.text();
264
+ } else {
265
+ throw new Error(`Unsupported URI scheme: ${uri}`);
266
+ }
267
+ const data = JSON.parse(content);
268
+ return AgentRegistrationFileSchema.parse(data);
269
+ }
270
+ /**
271
+ * Set metadata for an agent
272
+ */
273
+ async setMetadata(agentId, metadataKey, metadataValue) {
274
+ if (!this.signer) {
275
+ throw new Error("Signer required for setting metadata");
276
+ }
277
+ const tx = await this.contract.setMetadata(agentId, metadataKey, metadataValue);
278
+ await tx.wait();
279
+ }
280
+ /**
281
+ * Get metadata for an agent
282
+ */
283
+ async getMetadata(agentId, metadataKey) {
284
+ return await this.contract.getMetadata(agentId, metadataKey);
285
+ }
286
+ /**
287
+ * Get the agent wallet address
288
+ */
289
+ async getAgentWallet(agentId) {
290
+ return await this.contract.getAgentWallet(agentId);
291
+ }
292
+ /**
293
+ * Set the agent wallet with signature
294
+ */
295
+ async setAgentWallet(agentId, newWallet, deadline, signature) {
296
+ if (!this.signer) {
297
+ throw new Error("Signer required for setting agent wallet");
298
+ }
299
+ const tx = await this.contract.setAgentWallet(agentId, newWallet, deadline, signature);
300
+ await tx.wait();
301
+ }
302
+ /**
303
+ * Unset the agent wallet
304
+ */
305
+ async unsetAgentWallet(agentId) {
306
+ if (!this.signer) {
307
+ throw new Error("Signer required for unsetting agent wallet");
308
+ }
309
+ const tx = await this.contract.unsetAgentWallet(agentId);
310
+ await tx.wait();
311
+ }
312
+ /**
313
+ * Get the owner of an agent
314
+ */
315
+ async getOwner(agentId) {
316
+ return await this.contract.ownerOf(agentId);
317
+ }
318
+ /**
319
+ * Create a signature for setting agent wallet (EIP-712)
320
+ */
321
+ async createAgentWalletSignature(agentId, newWallet, deadline, chainId) {
322
+ if (!this.signer) {
323
+ throw new Error("Signer required for creating signature");
324
+ }
325
+ const domain = {
326
+ name: "IdentityRegistry",
327
+ version: "1",
328
+ chainId,
329
+ verifyingContract: await this.contract.getAddress()
330
+ };
331
+ const types = {
332
+ SetAgentWallet: [
333
+ { name: "agentId", type: "uint256" },
334
+ { name: "newWallet", type: "address" },
335
+ { name: "deadline", type: "uint256" }
336
+ ]
337
+ };
338
+ const value = {
339
+ agentId,
340
+ newWallet,
341
+ deadline
342
+ };
343
+ return await this.signer.signTypedData(domain, types, value);
344
+ }
345
+ };
346
+
347
+ // src/clients/ReputationRegistryClient.ts
348
+ import { Contract as Contract2, ethers as ethers2 } from "ethers";
349
+
350
+ // src/abis/ReputationRegistry.json
351
+ var ReputationRegistry_default = [
352
+ {
353
+ type: "function",
354
+ name: "initialize",
355
+ inputs: [{ name: "identityRegistry_", type: "address" }],
356
+ outputs: [],
357
+ stateMutability: "nonpayable"
358
+ },
359
+ {
360
+ type: "function",
361
+ name: "getIdentityRegistry",
362
+ inputs: [],
363
+ outputs: [{ name: "", type: "address" }],
364
+ stateMutability: "view"
365
+ },
366
+ {
367
+ type: "function",
368
+ name: "giveFeedback",
369
+ inputs: [
370
+ { name: "agentId", type: "uint256" },
371
+ { name: "value", type: "int128" },
372
+ { name: "valueDecimals", type: "uint8" },
373
+ { name: "tag1", type: "string" },
374
+ { name: "tag2", type: "string" },
375
+ { name: "endpoint", type: "string" },
376
+ { name: "feedbackURI", type: "string" },
377
+ { name: "feedbackHash", type: "bytes32" }
378
+ ],
379
+ outputs: [],
380
+ stateMutability: "nonpayable"
381
+ },
382
+ {
383
+ type: "function",
384
+ name: "revokeFeedback",
385
+ inputs: [
386
+ { name: "agentId", type: "uint256" },
387
+ { name: "feedbackIndex", type: "uint64" }
388
+ ],
389
+ outputs: [],
390
+ stateMutability: "nonpayable"
391
+ },
392
+ {
393
+ type: "function",
394
+ name: "appendResponse",
395
+ inputs: [
396
+ { name: "agentId", type: "uint256" },
397
+ { name: "clientAddress", type: "address" },
398
+ { name: "feedbackIndex", type: "uint64" },
399
+ { name: "responseURI", type: "string" },
400
+ { name: "responseHash", type: "bytes32" }
401
+ ],
402
+ outputs: [],
403
+ stateMutability: "nonpayable"
404
+ },
405
+ {
406
+ type: "function",
407
+ name: "getSummary",
408
+ inputs: [
409
+ { name: "agentId", type: "uint256" },
410
+ { name: "clientAddresses", type: "address[]" },
411
+ { name: "tag1", type: "string" },
412
+ { name: "tag2", type: "string" }
413
+ ],
414
+ outputs: [
415
+ { name: "count", type: "uint64" },
416
+ { name: "summaryValue", type: "int128" },
417
+ { name: "summaryValueDecimals", type: "uint8" }
418
+ ],
419
+ stateMutability: "view"
420
+ },
421
+ {
422
+ type: "function",
423
+ name: "readFeedback",
424
+ inputs: [
425
+ { name: "agentId", type: "uint256" },
426
+ { name: "clientAddress", type: "address" },
427
+ { name: "feedbackIndex", type: "uint64" }
428
+ ],
429
+ outputs: [
430
+ { name: "value", type: "int128" },
431
+ { name: "valueDecimals", type: "uint8" },
432
+ { name: "tag1", type: "string" },
433
+ { name: "tag2", type: "string" },
434
+ { name: "isRevoked", type: "bool" }
435
+ ],
436
+ stateMutability: "view"
437
+ },
438
+ {
439
+ type: "function",
440
+ name: "readAllFeedback",
441
+ inputs: [
442
+ { name: "agentId", type: "uint256" },
443
+ { name: "clientAddresses", type: "address[]" },
444
+ { name: "tag1", type: "string" },
445
+ { name: "tag2", type: "string" },
446
+ { name: "includeRevoked", type: "bool" }
447
+ ],
448
+ outputs: [
449
+ { name: "clients", type: "address[]" },
450
+ { name: "feedbackIndexes", type: "uint64[]" },
451
+ { name: "values", type: "int128[]" },
452
+ { name: "valueDecimals", type: "uint8[]" },
453
+ { name: "tag1s", type: "string[]" },
454
+ { name: "tag2s", type: "string[]" },
455
+ { name: "revokedStatuses", type: "bool[]" }
456
+ ],
457
+ stateMutability: "view"
458
+ },
459
+ {
460
+ type: "function",
461
+ name: "getResponseCount",
462
+ inputs: [
463
+ { name: "agentId", type: "uint256" },
464
+ { name: "clientAddress", type: "address" },
465
+ { name: "feedbackIndex", type: "uint64" },
466
+ { name: "responders", type: "address[]" }
467
+ ],
468
+ outputs: [{ name: "count", type: "uint64" }],
469
+ stateMutability: "view"
470
+ },
471
+ {
472
+ type: "function",
473
+ name: "getClients",
474
+ inputs: [{ name: "agentId", type: "uint256" }],
475
+ outputs: [{ name: "", type: "address[]" }],
476
+ stateMutability: "view"
477
+ },
478
+ {
479
+ type: "function",
480
+ name: "getLastIndex",
481
+ inputs: [
482
+ { name: "agentId", type: "uint256" },
483
+ { name: "clientAddress", type: "address" }
484
+ ],
485
+ outputs: [{ name: "", type: "uint64" }],
486
+ stateMutability: "view"
487
+ },
488
+ {
489
+ type: "event",
490
+ name: "NewFeedback",
491
+ inputs: [
492
+ { name: "agentId", type: "uint256", indexed: true },
493
+ { name: "clientAddress", type: "address", indexed: true },
494
+ { name: "feedbackIndex", type: "uint64", indexed: false },
495
+ { name: "value", type: "int128", indexed: false },
496
+ { name: "valueDecimals", type: "uint8", indexed: false },
497
+ { name: "indexedTag1", type: "string", indexed: true },
498
+ { name: "tag1", type: "string", indexed: false },
499
+ { name: "tag2", type: "string", indexed: false },
500
+ { name: "endpoint", type: "string", indexed: false },
501
+ { name: "feedbackURI", type: "string", indexed: false },
502
+ { name: "feedbackHash", type: "bytes32", indexed: false }
503
+ ]
504
+ },
505
+ {
506
+ type: "event",
507
+ name: "FeedbackRevoked",
508
+ inputs: [
509
+ { name: "agentId", type: "uint256", indexed: true },
510
+ { name: "clientAddress", type: "address", indexed: true },
511
+ { name: "feedbackIndex", type: "uint64", indexed: true }
512
+ ]
513
+ },
514
+ {
515
+ type: "event",
516
+ name: "ResponseAppended",
517
+ inputs: [
518
+ { name: "agentId", type: "uint256", indexed: true },
519
+ { name: "clientAddress", type: "address", indexed: true },
520
+ { name: "feedbackIndex", type: "uint64", indexed: false },
521
+ { name: "responder", type: "address", indexed: true },
522
+ { name: "responseURI", type: "string", indexed: false },
523
+ { name: "responseHash", type: "bytes32", indexed: false }
524
+ ]
525
+ }
526
+ ];
527
+
528
+ // src/clients/ReputationRegistryClient.ts
529
+ var ReputationRegistryClient = class {
530
+ constructor(contractAddress, providerOrSigner) {
531
+ if ("provider" in providerOrSigner && providerOrSigner.provider) {
532
+ this.signer = providerOrSigner;
533
+ this.contract = new Contract2(contractAddress, ReputationRegistry_default, this.signer);
534
+ } else {
535
+ this.contract = new Contract2(contractAddress, ReputationRegistry_default, providerOrSigner);
536
+ }
537
+ }
538
+ /**
539
+ * Get the identity registry address
540
+ */
541
+ async getIdentityRegistry() {
542
+ return await this.contract.getIdentityRegistry();
543
+ }
544
+ /**
545
+ * Give feedback to an agent
546
+ */
547
+ async giveFeedback(feedback) {
548
+ if (!this.signer) {
549
+ throw new Error("Signer required for giving feedback");
550
+ }
551
+ if (feedback.valueDecimals < 0 || feedback.valueDecimals > 18) {
552
+ throw new Error("valueDecimals must be between 0 and 18");
553
+ }
554
+ const tx = await this.contract.giveFeedback(
555
+ feedback.agentId,
556
+ feedback.value,
557
+ feedback.valueDecimals,
558
+ feedback.tag1 || "",
559
+ feedback.tag2 || "",
560
+ feedback.endpoint || "",
561
+ feedback.feedbackURI || "",
562
+ feedback.feedbackHash || ethers2.ZeroHash
563
+ );
564
+ await tx.wait();
565
+ }
566
+ /**
567
+ * Revoke feedback
568
+ */
569
+ async revokeFeedback(agentId, feedbackIndex) {
570
+ if (!this.signer) {
571
+ throw new Error("Signer required for revoking feedback");
572
+ }
573
+ const tx = await this.contract.revokeFeedback(agentId, feedbackIndex);
574
+ await tx.wait();
575
+ }
576
+ /**
577
+ * Append a response to feedback
578
+ */
579
+ async appendResponse(agentId, clientAddress, feedbackIndex, responseURI, responseHash) {
580
+ if (!this.signer) {
581
+ throw new Error("Signer required for appending response");
582
+ }
583
+ const tx = await this.contract.appendResponse(
584
+ agentId,
585
+ clientAddress,
586
+ feedbackIndex,
587
+ responseURI,
588
+ responseHash || ethers2.ZeroHash
589
+ );
590
+ await tx.wait();
591
+ }
592
+ /**
593
+ * Get feedback summary for an agent
594
+ */
595
+ async getSummary(agentId, clientAddresses, tag1, tag2) {
596
+ if (clientAddresses.length === 0) {
597
+ throw new Error("clientAddresses must not be empty (Sybil attack prevention)");
598
+ }
599
+ const result = await this.contract.getSummary(
600
+ agentId,
601
+ clientAddresses,
602
+ tag1 || "",
603
+ tag2 || ""
604
+ );
605
+ return {
606
+ count: result.count,
607
+ summaryValue: result.summaryValue,
608
+ summaryValueDecimals: result.summaryValueDecimals
609
+ };
610
+ }
611
+ /**
612
+ * Read a specific feedback
613
+ */
614
+ async readFeedback(agentId, clientAddress, feedbackIndex) {
615
+ const result = await this.contract.readFeedback(agentId, clientAddress, feedbackIndex);
616
+ return {
617
+ agentId,
618
+ clientAddress,
619
+ feedbackIndex,
620
+ value: result.value,
621
+ valueDecimals: Number(result.valueDecimals),
622
+ tag1: result.tag1,
623
+ tag2: result.tag2,
624
+ isRevoked: result.isRevoked
625
+ };
626
+ }
627
+ /**
628
+ * Read all feedback for an agent with optional filters
629
+ */
630
+ async readAllFeedback(agentId, clientAddresses, tag1, tag2, includeRevoked = false) {
631
+ const result = await this.contract.readAllFeedback(
632
+ agentId,
633
+ clientAddresses || [],
634
+ tag1 || "",
635
+ tag2 || "",
636
+ includeRevoked
637
+ );
638
+ const feedback = [];
639
+ for (let i = 0; i < result.clients.length; i++) {
640
+ feedback.push({
641
+ agentId,
642
+ clientAddress: result.clients[i],
643
+ feedbackIndex: result.feedbackIndexes[i],
644
+ value: result.values[i],
645
+ valueDecimals: Number(result.valueDecimals[i]),
646
+ tag1: result.tag1s[i],
647
+ tag2: result.tag2s[i],
648
+ isRevoked: result.revokedStatuses[i]
649
+ });
650
+ }
651
+ return feedback;
652
+ }
653
+ /**
654
+ * Get response count for feedback
655
+ */
656
+ async getResponseCount(agentId, clientAddress, feedbackIndex, responders) {
657
+ return await this.contract.getResponseCount(
658
+ agentId,
659
+ clientAddress || ethers2.ZeroAddress,
660
+ feedbackIndex || 0n,
661
+ responders || []
662
+ );
663
+ }
664
+ /**
665
+ * Get all clients who gave feedback to an agent
666
+ */
667
+ async getClients(agentId) {
668
+ return await this.contract.getClients(agentId);
669
+ }
670
+ /**
671
+ * Get the last feedback index for a client-agent pair
672
+ */
673
+ async getLastIndex(agentId, clientAddress) {
674
+ return await this.contract.getLastIndex(agentId, clientAddress);
675
+ }
676
+ /**
677
+ * Fetch and parse feedback file from URI
678
+ */
679
+ async getFeedbackFile(feedbackURI) {
680
+ let content;
681
+ if (feedbackURI.startsWith("ipfs://")) {
682
+ const cid = feedbackURI.replace("ipfs://", "");
683
+ const response = await fetch(`https://ipfs.io/ipfs/${cid}`);
684
+ content = await response.text();
685
+ } else if (feedbackURI.startsWith("http://") || feedbackURI.startsWith("https://")) {
686
+ const response = await fetch(feedbackURI);
687
+ content = await response.text();
688
+ } else {
689
+ throw new Error(`Unsupported URI scheme: ${feedbackURI}`);
690
+ }
691
+ const data = JSON.parse(content);
692
+ return FeedbackFileSchema.parse(data);
693
+ }
694
+ /**
695
+ * Calculate hash for feedback file content
696
+ */
697
+ static calculateFeedbackHash(content) {
698
+ return ethers2.keccak256(ethers2.toUtf8Bytes(content));
699
+ }
700
+ };
701
+
702
+ // src/clients/ValidationRegistryClient.ts
703
+ import { Contract as Contract3, ethers as ethers3 } from "ethers";
704
+
705
+ // src/abis/ValidationRegistry.json
706
+ var ValidationRegistry_default = [
707
+ {
708
+ type: "function",
709
+ name: "initialize",
710
+ inputs: [{ name: "identityRegistry_", type: "address" }],
711
+ outputs: [],
712
+ stateMutability: "nonpayable"
713
+ },
714
+ {
715
+ type: "function",
716
+ name: "getIdentityRegistry",
717
+ inputs: [],
718
+ outputs: [{ name: "", type: "address" }],
719
+ stateMutability: "view"
720
+ },
721
+ {
722
+ type: "function",
723
+ name: "validationRequest",
724
+ inputs: [
725
+ { name: "validatorAddress", type: "address" },
726
+ { name: "agentId", type: "uint256" },
727
+ { name: "requestURI", type: "string" },
728
+ { name: "requestHash", type: "bytes32" }
729
+ ],
730
+ outputs: [],
731
+ stateMutability: "nonpayable"
732
+ },
733
+ {
734
+ type: "function",
735
+ name: "validationResponse",
736
+ inputs: [
737
+ { name: "requestHash", type: "bytes32" },
738
+ { name: "response", type: "uint8" },
739
+ { name: "responseURI", type: "string" },
740
+ { name: "responseHash", type: "bytes32" },
741
+ { name: "tag", type: "string" }
742
+ ],
743
+ outputs: [],
744
+ stateMutability: "nonpayable"
745
+ },
746
+ {
747
+ type: "function",
748
+ name: "getValidationStatus",
749
+ inputs: [{ name: "requestHash", type: "bytes32" }],
750
+ outputs: [
751
+ { name: "validatorAddress", type: "address" },
752
+ { name: "agentId", type: "uint256" },
753
+ { name: "response", type: "uint8" },
754
+ { name: "responseHash", type: "bytes32" },
755
+ { name: "tag", type: "string" },
756
+ { name: "lastUpdate", type: "uint256" }
757
+ ],
758
+ stateMutability: "view"
759
+ },
760
+ {
761
+ type: "function",
762
+ name: "getSummary",
763
+ inputs: [
764
+ { name: "agentId", type: "uint256" },
765
+ { name: "validatorAddresses", type: "address[]" },
766
+ { name: "tag", type: "string" }
767
+ ],
768
+ outputs: [
769
+ { name: "count", type: "uint64" },
770
+ { name: "averageResponse", type: "uint8" }
771
+ ],
772
+ stateMutability: "view"
773
+ },
774
+ {
775
+ type: "function",
776
+ name: "getAgentValidations",
777
+ inputs: [{ name: "agentId", type: "uint256" }],
778
+ outputs: [{ name: "", type: "bytes32[]" }],
779
+ stateMutability: "view"
780
+ },
781
+ {
782
+ type: "function",
783
+ name: "getValidatorRequests",
784
+ inputs: [{ name: "validatorAddress", type: "address" }],
785
+ outputs: [{ name: "", type: "bytes32[]" }],
786
+ stateMutability: "view"
787
+ },
788
+ {
789
+ type: "event",
790
+ name: "ValidationRequest",
791
+ inputs: [
792
+ { name: "validatorAddress", type: "address", indexed: true },
793
+ { name: "agentId", type: "uint256", indexed: true },
794
+ { name: "requestURI", type: "string", indexed: false },
795
+ { name: "requestHash", type: "bytes32", indexed: true }
796
+ ]
797
+ },
798
+ {
799
+ type: "event",
800
+ name: "ValidationResponse",
801
+ inputs: [
802
+ { name: "validatorAddress", type: "address", indexed: true },
803
+ { name: "agentId", type: "uint256", indexed: true },
804
+ { name: "requestHash", type: "bytes32", indexed: true },
805
+ { name: "response", type: "uint8", indexed: false },
806
+ { name: "responseURI", type: "string", indexed: false },
807
+ { name: "responseHash", type: "bytes32", indexed: false },
808
+ { name: "tag", type: "string", indexed: false }
809
+ ]
810
+ }
811
+ ];
812
+
813
+ // src/clients/ValidationRegistryClient.ts
814
+ var ValidationRegistryClient = class {
815
+ constructor(contractAddress, providerOrSigner) {
816
+ if ("provider" in providerOrSigner && providerOrSigner.provider) {
817
+ this.signer = providerOrSigner;
818
+ this.contract = new Contract3(contractAddress, ValidationRegistry_default, this.signer);
819
+ } else {
820
+ this.contract = new Contract3(contractAddress, ValidationRegistry_default, providerOrSigner);
821
+ }
822
+ }
823
+ /**
824
+ * Get the identity registry address
825
+ */
826
+ async getIdentityRegistry() {
827
+ return await this.contract.getIdentityRegistry();
828
+ }
829
+ /**
830
+ * Submit a validation request
831
+ */
832
+ async validationRequest(request) {
833
+ if (!this.signer) {
834
+ throw new Error("Signer required for validation request");
835
+ }
836
+ const tx = await this.contract.validationRequest(
837
+ request.validatorAddress,
838
+ request.agentId,
839
+ request.requestURI,
840
+ request.requestHash
841
+ );
842
+ await tx.wait();
843
+ }
844
+ /**
845
+ * Submit a validation response (called by validator)
846
+ */
847
+ async validationResponse(response) {
848
+ if (!this.signer) {
849
+ throw new Error("Signer required for validation response");
850
+ }
851
+ if (response.response < 0 || response.response > 100) {
852
+ throw new Error("response must be between 0 and 100");
853
+ }
854
+ const tx = await this.contract.validationResponse(
855
+ response.requestHash,
856
+ response.response,
857
+ response.responseURI || "",
858
+ response.responseHash || ethers3.ZeroHash,
859
+ response.tag || ""
860
+ );
861
+ await tx.wait();
862
+ }
863
+ /**
864
+ * Get validation status for a request
865
+ */
866
+ async getValidationStatus(requestHash) {
867
+ const result = await this.contract.getValidationStatus(requestHash);
868
+ return {
869
+ validatorAddress: result.validatorAddress,
870
+ agentId: result.agentId,
871
+ response: result.response,
872
+ responseHash: result.responseHash,
873
+ tag: result.tag,
874
+ lastUpdate: result.lastUpdate
875
+ };
876
+ }
877
+ /**
878
+ * Get validation summary for an agent
879
+ */
880
+ async getSummary(agentId, validatorAddresses, tag) {
881
+ const result = await this.contract.getSummary(
882
+ agentId,
883
+ validatorAddresses || [],
884
+ tag || ""
885
+ );
886
+ return {
887
+ count: result.count,
888
+ averageResponse: result.averageResponse
889
+ };
890
+ }
891
+ /**
892
+ * Get all validation request hashes for an agent
893
+ */
894
+ async getAgentValidations(agentId) {
895
+ return await this.contract.getAgentValidations(agentId);
896
+ }
897
+ /**
898
+ * Get all validation request hashes for a validator
899
+ */
900
+ async getValidatorRequests(validatorAddress) {
901
+ return await this.contract.getValidatorRequests(validatorAddress);
902
+ }
903
+ /**
904
+ * Calculate request hash from request data
905
+ */
906
+ static calculateRequestHash(requestData) {
907
+ return ethers3.keccak256(ethers3.toUtf8Bytes(requestData));
908
+ }
909
+ /**
910
+ * Calculate response hash from response data
911
+ */
912
+ static calculateResponseHash(responseData) {
913
+ return ethers3.keccak256(ethers3.toUtf8Bytes(responseData));
914
+ }
915
+ };
916
+
917
+ // src/ClawpassClient.ts
918
+ var ClawpassClient = class {
919
+ constructor(config) {
920
+ this.identity = new IdentityRegistryClient(
921
+ config.identityRegistryAddress,
922
+ config.providerOrSigner
923
+ );
924
+ this.reputation = new ReputationRegistryClient(
925
+ config.reputationRegistryAddress,
926
+ config.providerOrSigner
927
+ );
928
+ this.validation = new ValidationRegistryClient(
929
+ config.validationRegistryAddress,
930
+ config.providerOrSigner
931
+ );
932
+ }
933
+ /**
934
+ * Verify that reputation and validation registries are linked to the identity registry
935
+ */
936
+ async verifyRegistryLinks() {
937
+ const raw = this.identity["contract"].target;
938
+ const identityAddress = typeof raw === "string" ? raw : raw.address;
939
+ const reputationIdentity = await this.reputation.getIdentityRegistry();
940
+ const validationIdentity = await this.validation.getIdentityRegistry();
941
+ return reputationIdentity.toLowerCase() === identityAddress.toLowerCase() && validationIdentity.toLowerCase() === identityAddress.toLowerCase();
942
+ }
943
+ /**
944
+ * Get comprehensive agent information
945
+ */
946
+ async getAgentInfo(agentId) {
947
+ const [registrationFile, owner, wallet] = await Promise.all([
948
+ this.identity.getAgentRegistrationFile(agentId),
949
+ this.identity.getOwner(agentId),
950
+ this.identity.getAgentWallet(agentId)
951
+ ]);
952
+ return {
953
+ agentId,
954
+ owner,
955
+ wallet,
956
+ registration: registrationFile
957
+ };
958
+ }
959
+ /**
960
+ * Get agent reputation summary from trusted clients
961
+ */
962
+ async getAgentReputation(agentId, trustedClients, tag1, tag2) {
963
+ const summary = await this.reputation.getSummary(agentId, trustedClients, tag1, tag2);
964
+ const allFeedback = await this.reputation.readAllFeedback(agentId, trustedClients, tag1, tag2);
965
+ return {
966
+ summary,
967
+ feedback: allFeedback
968
+ };
969
+ }
970
+ /**
971
+ * Get agent validation summary
972
+ */
973
+ async getAgentValidationSummary(agentId, validatorAddresses, tag) {
974
+ const summary = await this.validation.getSummary(agentId, validatorAddresses, tag);
975
+ const validationHashes = await this.validation.getAgentValidations(agentId);
976
+ return {
977
+ summary,
978
+ validationCount: validationHashes.length,
979
+ validationHashes
980
+ };
981
+ }
982
+ };
983
+
984
+ // src/types/index.ts
985
+ function formatAgentRegistry(registry) {
986
+ return `${registry.namespace}:${registry.chainId}:${registry.identityRegistry}`;
987
+ }
988
+ function parseAgentRegistry(registryString) {
989
+ const parts = registryString.split(":");
990
+ if (parts.length !== 3) {
991
+ throw new Error("Invalid agent registry format. Expected: namespace:chainId:identityRegistry");
992
+ }
993
+ return {
994
+ namespace: parts[0],
995
+ chainId: parts[1],
996
+ identityRegistry: parts[2]
997
+ };
998
+ }
999
+
1000
+ // src/utils/index.ts
1001
+ import { ethers as ethers4 } from "ethers";
1002
+ function createDataURI(registrationFile) {
1003
+ const json = JSON.stringify(registrationFile);
1004
+ const base64 = Buffer.from(json).toString("base64");
1005
+ return `data:application/json;base64,${base64}`;
1006
+ }
1007
+ function parseDataURI(dataURI) {
1008
+ if (!dataURI.startsWith("data:application/json;base64,")) {
1009
+ throw new Error("Invalid data URI format");
1010
+ }
1011
+ const base64Data = dataURI.split(",")[1];
1012
+ const json = Buffer.from(base64Data, "base64").toString("utf-8");
1013
+ return JSON.parse(json);
1014
+ }
1015
+ function toFixedPoint(value, decimals) {
1016
+ if (decimals < 0 || decimals > 18) {
1017
+ throw new Error("Decimals must be between 0 and 18");
1018
+ }
1019
+ const multiplier = 10 ** decimals;
1020
+ return BigInt(Math.round(value * multiplier));
1021
+ }
1022
+ function fromFixedPoint(value, decimals) {
1023
+ if (decimals < 0 || decimals > 18) {
1024
+ throw new Error("Decimals must be between 0 and 18");
1025
+ }
1026
+ const divisor = 10 ** decimals;
1027
+ return Number(value) / divisor;
1028
+ }
1029
+ function createFeedbackFile(agentRegistry, agentId, clientAddress, value, valueDecimals, options) {
1030
+ return {
1031
+ agentRegistry,
1032
+ agentId,
1033
+ clientAddress,
1034
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1035
+ value,
1036
+ valueDecimals,
1037
+ ...options
1038
+ };
1039
+ }
1040
+ function calculateHash(content) {
1041
+ return ethers4.keccak256(ethers4.toUtf8Bytes(content));
1042
+ }
1043
+ function verifyHash(content, hash) {
1044
+ return calculateHash(content) === hash;
1045
+ }
1046
+ function formatAgentRegistryString(namespace, chainId, identityRegistry) {
1047
+ return `${namespace}:${chainId}:${identityRegistry}`;
1048
+ }
1049
+ function parseAgentRegistryString(registryString) {
1050
+ const parts = registryString.split(":");
1051
+ if (parts.length !== 3) {
1052
+ throw new Error("Invalid agent registry format");
1053
+ }
1054
+ return {
1055
+ namespace: parts[0],
1056
+ chainId: parts[1],
1057
+ identityRegistry: parts[2]
1058
+ };
1059
+ }
1060
+ function createIPFSUri(cid) {
1061
+ return `ipfs://${cid}`;
1062
+ }
1063
+ function extractCIDFromIPFS(ipfsUri) {
1064
+ if (!ipfsUri.startsWith("ipfs://")) {
1065
+ throw new Error("Invalid IPFS URI");
1066
+ }
1067
+ return ipfsUri.replace("ipfs://", "");
1068
+ }
1069
+ function ipfsToHTTP(ipfsUri, gateway = "https://ipfs.io") {
1070
+ const cid = extractCIDFromIPFS(ipfsUri);
1071
+ return `${gateway}/ipfs/${cid}`;
1072
+ }
1073
+ function calculateAverageFeedback(feedbackValues) {
1074
+ if (feedbackValues.length === 0) return 0;
1075
+ const total = feedbackValues.reduce((sum, fb) => {
1076
+ return sum + fromFixedPoint(fb.value, fb.decimals);
1077
+ }, 0);
1078
+ return total / feedbackValues.length;
1079
+ }
1080
+ function encodeMetadata(value) {
1081
+ return ethers4.hexlify(ethers4.toUtf8Bytes(value));
1082
+ }
1083
+ function decodeMetadata(hexValue) {
1084
+ return ethers4.toUtf8String(hexValue);
1085
+ }
1086
+ export {
1087
+ AgentRegistrationFileSchema,
1088
+ AgentRegistrationSchema,
1089
+ AgentServiceSchema,
1090
+ ClawpassClient,
1091
+ FeedbackFileSchema,
1092
+ IdentityRegistry_default as IdentityRegistryABI,
1093
+ IdentityRegistryClient,
1094
+ ReputationRegistry_default as ReputationRegistryABI,
1095
+ ReputationRegistryClient,
1096
+ ValidationRegistry_default as ValidationRegistryABI,
1097
+ ValidationRegistryClient,
1098
+ calculateAverageFeedback,
1099
+ calculateHash,
1100
+ createDataURI,
1101
+ createFeedbackFile,
1102
+ createIPFSUri,
1103
+ decodeMetadata,
1104
+ encodeMetadata,
1105
+ extractCIDFromIPFS,
1106
+ formatAgentRegistry,
1107
+ formatAgentRegistryString,
1108
+ fromFixedPoint,
1109
+ ipfsToHTTP,
1110
+ parseAgentRegistry,
1111
+ parseAgentRegistryString,
1112
+ parseDataURI,
1113
+ toFixedPoint,
1114
+ verifyHash
1115
+ };