@perkos/contracts-erc8004 1.0.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.
package/dist/index.mjs ADDED
@@ -0,0 +1,670 @@
1
+ // src/index.ts
2
+ var IDENTITY_REGISTRY_ABI = [
3
+ // Read functions
4
+ {
5
+ inputs: [{ name: "agentId", type: "uint256" }],
6
+ name: "tokenURI",
7
+ outputs: [{ name: "", type: "string" }],
8
+ stateMutability: "view",
9
+ type: "function"
10
+ },
11
+ {
12
+ inputs: [{ name: "agentId", type: "uint256" }],
13
+ name: "ownerOf",
14
+ outputs: [{ name: "", type: "address" }],
15
+ stateMutability: "view",
16
+ type: "function"
17
+ },
18
+ {
19
+ inputs: [{ name: "owner", type: "address" }],
20
+ name: "getAgentsByOwner",
21
+ outputs: [{ name: "", type: "uint256[]" }],
22
+ stateMutability: "view",
23
+ type: "function"
24
+ },
25
+ {
26
+ inputs: [],
27
+ name: "totalAgents",
28
+ outputs: [{ name: "", type: "uint256" }],
29
+ stateMutability: "view",
30
+ type: "function"
31
+ },
32
+ {
33
+ inputs: [],
34
+ name: "nextAgentId",
35
+ outputs: [{ name: "", type: "uint256" }],
36
+ stateMutability: "view",
37
+ type: "function"
38
+ },
39
+ {
40
+ inputs: [
41
+ { name: "agentId", type: "uint256" },
42
+ { name: "key", type: "string" }
43
+ ],
44
+ name: "getMetadata",
45
+ outputs: [{ name: "value", type: "bytes" }],
46
+ stateMutability: "view",
47
+ type: "function"
48
+ },
49
+ {
50
+ inputs: [],
51
+ name: "version",
52
+ outputs: [{ name: "", type: "string" }],
53
+ stateMutability: "pure",
54
+ type: "function"
55
+ },
56
+ // Write functions
57
+ {
58
+ inputs: [
59
+ { name: "tokenURI_", type: "string" },
60
+ {
61
+ name: "metadata",
62
+ type: "tuple[]",
63
+ components: [
64
+ { name: "key", type: "string" },
65
+ { name: "value", type: "bytes" }
66
+ ]
67
+ }
68
+ ],
69
+ name: "register",
70
+ outputs: [{ name: "agentId", type: "uint256" }],
71
+ stateMutability: "nonpayable",
72
+ type: "function"
73
+ },
74
+ {
75
+ inputs: [{ name: "tokenURI_", type: "string" }],
76
+ name: "register",
77
+ outputs: [{ name: "agentId", type: "uint256" }],
78
+ stateMutability: "nonpayable",
79
+ type: "function"
80
+ },
81
+ {
82
+ inputs: [],
83
+ name: "register",
84
+ outputs: [{ name: "agentId", type: "uint256" }],
85
+ stateMutability: "nonpayable",
86
+ type: "function"
87
+ },
88
+ {
89
+ inputs: [
90
+ { name: "agentId", type: "uint256" },
91
+ { name: "key", type: "string" },
92
+ { name: "value", type: "bytes" }
93
+ ],
94
+ name: "setMetadata",
95
+ outputs: [],
96
+ stateMutability: "nonpayable",
97
+ type: "function"
98
+ },
99
+ {
100
+ inputs: [
101
+ { name: "agentId", type: "uint256" },
102
+ { name: "tokenURI_", type: "string" }
103
+ ],
104
+ name: "setTokenURI",
105
+ outputs: [],
106
+ stateMutability: "nonpayable",
107
+ type: "function"
108
+ },
109
+ // Events
110
+ {
111
+ anonymous: false,
112
+ inputs: [
113
+ { indexed: true, name: "agentId", type: "uint256" },
114
+ { indexed: false, name: "tokenURI", type: "string" },
115
+ { indexed: true, name: "owner", type: "address" }
116
+ ],
117
+ name: "Registered",
118
+ type: "event"
119
+ },
120
+ {
121
+ anonymous: false,
122
+ inputs: [
123
+ { indexed: true, name: "agentId", type: "uint256" },
124
+ { indexed: true, name: "indexedKey", type: "string" },
125
+ { indexed: false, name: "key", type: "string" },
126
+ { indexed: false, name: "value", type: "bytes" }
127
+ ],
128
+ name: "MetadataSet",
129
+ type: "event"
130
+ }
131
+ ];
132
+ var REPUTATION_REGISTRY_ABI = [
133
+ // Read functions
134
+ {
135
+ inputs: [{ name: "agentId", type: "uint256" }],
136
+ name: "getSummary",
137
+ outputs: [
138
+ {
139
+ name: "summary",
140
+ type: "tuple",
141
+ components: [
142
+ { name: "totalFeedback", type: "uint256" },
143
+ { name: "activeFeedback", type: "uint256" },
144
+ { name: "averageRating", type: "int256" },
145
+ { name: "positiveCount", type: "uint256" },
146
+ { name: "negativeCount", type: "uint256" },
147
+ { name: "neutralCount", type: "uint256" },
148
+ { name: "lastUpdated", type: "uint256" }
149
+ ]
150
+ }
151
+ ],
152
+ stateMutability: "view",
153
+ type: "function"
154
+ },
155
+ {
156
+ inputs: [
157
+ { name: "agentId", type: "uint256" },
158
+ { name: "index", type: "uint256" }
159
+ ],
160
+ name: "readFeedback",
161
+ outputs: [
162
+ {
163
+ name: "feedback",
164
+ type: "tuple",
165
+ components: [
166
+ { name: "client", type: "address" },
167
+ { name: "rating", type: "int8" },
168
+ { name: "comment", type: "string" },
169
+ { name: "timestamp", type: "uint256" },
170
+ { name: "revoked", type: "bool" },
171
+ { name: "response", type: "string" }
172
+ ]
173
+ }
174
+ ],
175
+ stateMutability: "view",
176
+ type: "function"
177
+ },
178
+ {
179
+ inputs: [{ name: "agentId", type: "uint256" }],
180
+ name: "readAllFeedback",
181
+ outputs: [
182
+ {
183
+ name: "",
184
+ type: "tuple[]",
185
+ components: [
186
+ { name: "client", type: "address" },
187
+ { name: "rating", type: "int8" },
188
+ { name: "comment", type: "string" },
189
+ { name: "timestamp", type: "uint256" },
190
+ { name: "revoked", type: "bool" },
191
+ { name: "response", type: "string" }
192
+ ]
193
+ }
194
+ ],
195
+ stateMutability: "view",
196
+ type: "function"
197
+ },
198
+ {
199
+ inputs: [{ name: "agentId", type: "uint256" }],
200
+ name: "getLastIndex",
201
+ outputs: [{ name: "lastIndex", type: "uint256" }],
202
+ stateMutability: "view",
203
+ type: "function"
204
+ },
205
+ {
206
+ inputs: [{ name: "agentId", type: "uint256" }],
207
+ name: "getClients",
208
+ outputs: [{ name: "", type: "address[]" }],
209
+ stateMutability: "view",
210
+ type: "function"
211
+ },
212
+ {
213
+ inputs: [
214
+ { name: "agentId", type: "uint256" },
215
+ { name: "client", type: "address" }
216
+ ],
217
+ name: "hasClientFeedback",
218
+ outputs: [{ name: "hasFeedback", type: "bool" }],
219
+ stateMutability: "view",
220
+ type: "function"
221
+ },
222
+ {
223
+ inputs: [],
224
+ name: "identityRegistry",
225
+ outputs: [{ name: "registry", type: "address" }],
226
+ stateMutability: "view",
227
+ type: "function"
228
+ },
229
+ {
230
+ inputs: [],
231
+ name: "version",
232
+ outputs: [{ name: "", type: "string" }],
233
+ stateMutability: "pure",
234
+ type: "function"
235
+ },
236
+ // Write functions
237
+ {
238
+ inputs: [
239
+ { name: "agentId", type: "uint256" },
240
+ { name: "rating", type: "int8" },
241
+ { name: "comment", type: "string" },
242
+ {
243
+ name: "auth",
244
+ type: "tuple",
245
+ components: [
246
+ { name: "agentId", type: "uint256" },
247
+ { name: "client", type: "address" },
248
+ { name: "nonce", type: "uint256" },
249
+ { name: "deadline", type: "uint256" }
250
+ ]
251
+ },
252
+ { name: "signature", type: "bytes" }
253
+ ],
254
+ name: "giveFeedback",
255
+ outputs: [{ name: "index", type: "uint256" }],
256
+ stateMutability: "nonpayable",
257
+ type: "function"
258
+ },
259
+ {
260
+ inputs: [
261
+ { name: "agentId", type: "uint256" },
262
+ { name: "rating", type: "int8" },
263
+ { name: "comment", type: "string" }
264
+ ],
265
+ name: "giveFeedback",
266
+ outputs: [{ name: "index", type: "uint256" }],
267
+ stateMutability: "nonpayable",
268
+ type: "function"
269
+ },
270
+ {
271
+ inputs: [
272
+ { name: "agentId", type: "uint256" },
273
+ { name: "index", type: "uint256" }
274
+ ],
275
+ name: "revokeFeedback",
276
+ outputs: [],
277
+ stateMutability: "nonpayable",
278
+ type: "function"
279
+ },
280
+ {
281
+ inputs: [
282
+ { name: "agentId", type: "uint256" },
283
+ { name: "index", type: "uint256" },
284
+ { name: "response", type: "string" }
285
+ ],
286
+ name: "appendResponse",
287
+ outputs: [],
288
+ stateMutability: "nonpayable",
289
+ type: "function"
290
+ },
291
+ // Events
292
+ {
293
+ anonymous: false,
294
+ inputs: [
295
+ { indexed: true, name: "agentId", type: "uint256" },
296
+ { indexed: true, name: "client", type: "address" },
297
+ { indexed: true, name: "index", type: "uint256" },
298
+ { indexed: false, name: "rating", type: "int8" },
299
+ { indexed: false, name: "comment", type: "string" }
300
+ ],
301
+ name: "FeedbackGiven",
302
+ type: "event"
303
+ },
304
+ {
305
+ anonymous: false,
306
+ inputs: [
307
+ { indexed: true, name: "agentId", type: "uint256" },
308
+ { indexed: true, name: "client", type: "address" },
309
+ { indexed: true, name: "index", type: "uint256" }
310
+ ],
311
+ name: "FeedbackRevoked",
312
+ type: "event"
313
+ },
314
+ {
315
+ anonymous: false,
316
+ inputs: [
317
+ { indexed: true, name: "agentId", type: "uint256" },
318
+ { indexed: true, name: "feedbackIndex", type: "uint256" },
319
+ { indexed: false, name: "response", type: "string" }
320
+ ],
321
+ name: "ResponseAppended",
322
+ type: "event"
323
+ }
324
+ ];
325
+ var VALIDATION_REGISTRY_ABI = [
326
+ // Read functions
327
+ {
328
+ inputs: [{ name: "validator", type: "address" }],
329
+ name: "getValidator",
330
+ outputs: [
331
+ {
332
+ name: "info",
333
+ type: "tuple",
334
+ components: [
335
+ { name: "name", type: "string" },
336
+ { name: "metadataURI", type: "string" },
337
+ { name: "stake", type: "uint256" },
338
+ { name: "registeredAt", type: "uint256" },
339
+ { name: "active", type: "bool" },
340
+ { name: "attestationCount", type: "uint256" }
341
+ ]
342
+ }
343
+ ],
344
+ stateMutability: "view",
345
+ type: "function"
346
+ },
347
+ {
348
+ inputs: [{ name: "validator", type: "address" }],
349
+ name: "isActiveValidator",
350
+ outputs: [{ name: "isActive", type: "bool" }],
351
+ stateMutability: "view",
352
+ type: "function"
353
+ },
354
+ {
355
+ inputs: [
356
+ { name: "agentId", type: "uint256" },
357
+ { name: "attestationId", type: "uint256" }
358
+ ],
359
+ name: "getAttestation",
360
+ outputs: [
361
+ {
362
+ name: "attestation",
363
+ type: "tuple",
364
+ components: [
365
+ { name: "validator", type: "address" },
366
+ { name: "attestationType", type: "string" },
367
+ { name: "dataHash", type: "bytes32" },
368
+ { name: "dataURI", type: "string" },
369
+ { name: "createdAt", type: "uint256" },
370
+ { name: "expiresAt", type: "uint256" },
371
+ { name: "revoked", type: "bool" },
372
+ { name: "confidenceScore", type: "uint8" }
373
+ ]
374
+ }
375
+ ],
376
+ stateMutability: "view",
377
+ type: "function"
378
+ },
379
+ {
380
+ inputs: [{ name: "agentId", type: "uint256" }],
381
+ name: "getAllAttestations",
382
+ outputs: [
383
+ {
384
+ name: "",
385
+ type: "tuple[]",
386
+ components: [
387
+ { name: "validator", type: "address" },
388
+ { name: "attestationType", type: "string" },
389
+ { name: "dataHash", type: "bytes32" },
390
+ { name: "dataURI", type: "string" },
391
+ { name: "createdAt", type: "uint256" },
392
+ { name: "expiresAt", type: "uint256" },
393
+ { name: "revoked", type: "bool" },
394
+ { name: "confidenceScore", type: "uint8" }
395
+ ]
396
+ }
397
+ ],
398
+ stateMutability: "view",
399
+ type: "function"
400
+ },
401
+ {
402
+ inputs: [{ name: "agentId", type: "uint256" }],
403
+ name: "getActiveAttestations",
404
+ outputs: [
405
+ {
406
+ name: "",
407
+ type: "tuple[]",
408
+ components: [
409
+ { name: "validator", type: "address" },
410
+ { name: "attestationType", type: "string" },
411
+ { name: "dataHash", type: "bytes32" },
412
+ { name: "dataURI", type: "string" },
413
+ { name: "createdAt", type: "uint256" },
414
+ { name: "expiresAt", type: "uint256" },
415
+ { name: "revoked", type: "bool" },
416
+ { name: "confidenceScore", type: "uint8" }
417
+ ]
418
+ }
419
+ ],
420
+ stateMutability: "view",
421
+ type: "function"
422
+ },
423
+ {
424
+ inputs: [
425
+ { name: "agentId", type: "uint256" },
426
+ { name: "attestationType", type: "string" }
427
+ ],
428
+ name: "getAttestationsByType",
429
+ outputs: [
430
+ {
431
+ name: "",
432
+ type: "tuple[]",
433
+ components: [
434
+ { name: "validator", type: "address" },
435
+ { name: "attestationType", type: "string" },
436
+ { name: "dataHash", type: "bytes32" },
437
+ { name: "dataURI", type: "string" },
438
+ { name: "createdAt", type: "uint256" },
439
+ { name: "expiresAt", type: "uint256" },
440
+ { name: "revoked", type: "bool" },
441
+ { name: "confidenceScore", type: "uint8" }
442
+ ]
443
+ }
444
+ ],
445
+ stateMutability: "view",
446
+ type: "function"
447
+ },
448
+ {
449
+ inputs: [{ name: "agentId", type: "uint256" }],
450
+ name: "getValidationSummary",
451
+ outputs: [
452
+ {
453
+ name: "summary",
454
+ type: "tuple",
455
+ components: [
456
+ { name: "totalAttestations", type: "uint256" },
457
+ { name: "activeAttestations", type: "uint256" },
458
+ { name: "expiredAttestations", type: "uint256" },
459
+ { name: "revokedAttestations", type: "uint256" },
460
+ { name: "validatorCount", type: "uint256" },
461
+ { name: "averageConfidence", type: "uint8" },
462
+ { name: "lastUpdated", type: "uint256" }
463
+ ]
464
+ }
465
+ ],
466
+ stateMutability: "view",
467
+ type: "function"
468
+ },
469
+ {
470
+ inputs: [
471
+ { name: "agentId", type: "uint256" },
472
+ { name: "attestationType", type: "string" }
473
+ ],
474
+ name: "hasValidAttestation",
475
+ outputs: [{ name: "hasValid", type: "bool" }],
476
+ stateMutability: "view",
477
+ type: "function"
478
+ },
479
+ {
480
+ inputs: [],
481
+ name: "identityRegistry",
482
+ outputs: [{ name: "registry", type: "address" }],
483
+ stateMutability: "view",
484
+ type: "function"
485
+ },
486
+ {
487
+ inputs: [],
488
+ name: "minimumStake",
489
+ outputs: [{ name: "minStake", type: "uint256" }],
490
+ stateMutability: "view",
491
+ type: "function"
492
+ },
493
+ {
494
+ inputs: [],
495
+ name: "version",
496
+ outputs: [{ name: "", type: "string" }],
497
+ stateMutability: "pure",
498
+ type: "function"
499
+ },
500
+ // Write functions
501
+ {
502
+ inputs: [
503
+ { name: "name", type: "string" },
504
+ { name: "metadataURI", type: "string" }
505
+ ],
506
+ name: "registerValidator",
507
+ outputs: [],
508
+ stateMutability: "payable",
509
+ type: "function"
510
+ },
511
+ {
512
+ inputs: [],
513
+ name: "updateStake",
514
+ outputs: [],
515
+ stateMutability: "payable",
516
+ type: "function"
517
+ },
518
+ {
519
+ inputs: [{ name: "amount", type: "uint256" }],
520
+ name: "withdrawStake",
521
+ outputs: [],
522
+ stateMutability: "nonpayable",
523
+ type: "function"
524
+ },
525
+ {
526
+ inputs: [],
527
+ name: "deactivateValidator",
528
+ outputs: [],
529
+ stateMutability: "nonpayable",
530
+ type: "function"
531
+ },
532
+ {
533
+ inputs: [
534
+ { name: "agentId", type: "uint256" },
535
+ { name: "attestationType", type: "string" },
536
+ { name: "dataHash", type: "bytes32" },
537
+ { name: "dataURI", type: "string" },
538
+ { name: "validityPeriod", type: "uint256" },
539
+ { name: "confidenceScore", type: "uint8" }
540
+ ],
541
+ name: "attest",
542
+ outputs: [{ name: "attestationId", type: "uint256" }],
543
+ stateMutability: "nonpayable",
544
+ type: "function"
545
+ },
546
+ {
547
+ inputs: [
548
+ { name: "agentId", type: "uint256" },
549
+ { name: "attestationId", type: "uint256" }
550
+ ],
551
+ name: "revokeAttestation",
552
+ outputs: [],
553
+ stateMutability: "nonpayable",
554
+ type: "function"
555
+ },
556
+ // Events
557
+ {
558
+ anonymous: false,
559
+ inputs: [
560
+ { indexed: true, name: "validator", type: "address" },
561
+ { indexed: false, name: "name", type: "string" },
562
+ { indexed: false, name: "stake", type: "uint256" }
563
+ ],
564
+ name: "ValidatorRegistered",
565
+ type: "event"
566
+ },
567
+ {
568
+ anonymous: false,
569
+ inputs: [
570
+ { indexed: true, name: "validator", type: "address" },
571
+ { indexed: false, name: "oldStake", type: "uint256" },
572
+ { indexed: false, name: "newStake", type: "uint256" }
573
+ ],
574
+ name: "StakeUpdated",
575
+ type: "event"
576
+ },
577
+ {
578
+ anonymous: false,
579
+ inputs: [{ indexed: true, name: "validator", type: "address" }],
580
+ name: "ValidatorRemoved",
581
+ type: "event"
582
+ },
583
+ {
584
+ anonymous: false,
585
+ inputs: [
586
+ { indexed: true, name: "agentId", type: "uint256" },
587
+ { indexed: true, name: "validator", type: "address" },
588
+ { indexed: true, name: "attestationId", type: "uint256" },
589
+ { indexed: false, name: "attestationType", type: "string" }
590
+ ],
591
+ name: "AttestationCreated",
592
+ type: "event"
593
+ },
594
+ {
595
+ anonymous: false,
596
+ inputs: [
597
+ { indexed: true, name: "agentId", type: "uint256" },
598
+ { indexed: true, name: "validator", type: "address" },
599
+ { indexed: true, name: "attestationId", type: "uint256" }
600
+ ],
601
+ name: "AttestationRevoked",
602
+ type: "event"
603
+ },
604
+ {
605
+ anonymous: false,
606
+ inputs: [
607
+ { indexed: true, name: "agentId", type: "uint256" },
608
+ { indexed: true, name: "attestationId", type: "uint256" }
609
+ ],
610
+ name: "AttestationExpired",
611
+ type: "event"
612
+ }
613
+ ];
614
+ var ERC8004_ABIS = {
615
+ IdentityRegistry: IDENTITY_REGISTRY_ABI,
616
+ ReputationRegistry: REPUTATION_REGISTRY_ABI,
617
+ ValidationRegistry: VALIDATION_REGISTRY_ABI
618
+ };
619
+ var RATING = {
620
+ NEGATIVE: -1,
621
+ NEUTRAL: 0,
622
+ POSITIVE: 1
623
+ };
624
+ var ATTESTATION_TYPES = {
625
+ KYC: "kyc",
626
+ AML: "aml",
627
+ IDENTITY: "identity",
628
+ CAPABILITY: "capability",
629
+ PERFORMANCE: "performance",
630
+ SECURITY: "security",
631
+ COMPLIANCE: "compliance"
632
+ };
633
+ function encodeMetadataValue(value) {
634
+ const encoder = new TextEncoder();
635
+ const bytes = encoder.encode(value);
636
+ return `0x${Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
637
+ }
638
+ function decodeMetadataValue(hex) {
639
+ const bytes = hex.slice(2).match(/.{2}/g);
640
+ if (!bytes) return "";
641
+ const decoder = new TextDecoder();
642
+ return decoder.decode(new Uint8Array(bytes.map((b) => parseInt(b, 16))));
643
+ }
644
+ function calculateAverageRating(summary) {
645
+ if (summary.activeFeedback === 0n) return 0;
646
+ return Number(summary.averageRating) / Number(summary.activeFeedback);
647
+ }
648
+ function isAttestationValid(attestation) {
649
+ const now = BigInt(Math.floor(Date.now() / 1e3));
650
+ return !attestation.revoked && attestation.expiresAt > now;
651
+ }
652
+ function getAttestationStatus(attestation) {
653
+ if (attestation.revoked) return "revoked";
654
+ const now = BigInt(Math.floor(Date.now() / 1e3));
655
+ if (attestation.expiresAt <= now) return "expired";
656
+ return "active";
657
+ }
658
+ export {
659
+ ATTESTATION_TYPES,
660
+ ERC8004_ABIS,
661
+ IDENTITY_REGISTRY_ABI,
662
+ RATING,
663
+ REPUTATION_REGISTRY_ABI,
664
+ VALIDATION_REGISTRY_ABI,
665
+ calculateAverageRating,
666
+ decodeMetadataValue,
667
+ encodeMetadataValue,
668
+ getAttestationStatus,
669
+ isAttestationValid
670
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@perkos/contracts-erc8004",
3
+ "version": "1.0.0",
4
+ "description": "ERC-8004 Decentralized AI Agent Registry contract ABIs and utilities",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup src/index.ts --format cjs,esm --dts",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "keywords": [
23
+ "ERC-8004",
24
+ "AI",
25
+ "agent",
26
+ "registry",
27
+ "identity",
28
+ "reputation",
29
+ "validation",
30
+ "ethereum",
31
+ "smart-contracts"
32
+ ],
33
+ "author": "PerkOS",
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/PerkOS-xyz/pkg-contracts-erc8004"
38
+ },
39
+ "dependencies": {
40
+ "viem": "^2.28.2"
41
+ },
42
+ "devDependencies": {
43
+ "tsup": "^8.5.0",
44
+ "typescript": "^5.8.3"
45
+ }
46
+ }