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