@q00bs/agent-sdk 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.
Files changed (85) hide show
  1. package/dist/Q00bsAgent.d.ts +331 -0
  2. package/dist/Q00bsAgent.d.ts.map +1 -0
  3. package/dist/Q00bsAgent.js +695 -0
  4. package/dist/Q00bsAgent.js.map +1 -0
  5. package/dist/abis/AgentEscrow.d.ts +336 -0
  6. package/dist/abis/AgentEscrow.d.ts.map +1 -0
  7. package/dist/abis/AgentEscrow.js +206 -0
  8. package/dist/abis/AgentEscrow.js.map +1 -0
  9. package/dist/abis/AgentRegistry.d.ts +496 -0
  10. package/dist/abis/AgentRegistry.d.ts.map +1 -0
  11. package/dist/abis/AgentRegistry.js +280 -0
  12. package/dist/abis/AgentRegistry.js.map +1 -0
  13. package/dist/abis/ConsensusModule.d.ts +270 -0
  14. package/dist/abis/ConsensusModule.d.ts.map +1 -0
  15. package/dist/abis/ConsensusModule.js +157 -0
  16. package/dist/abis/ConsensusModule.js.map +1 -0
  17. package/dist/abis/ERC8004Identity.d.ts +293 -0
  18. package/dist/abis/ERC8004Identity.d.ts.map +1 -0
  19. package/dist/abis/ERC8004Identity.js +223 -0
  20. package/dist/abis/ERC8004Identity.js.map +1 -0
  21. package/dist/abis/ERC8004Reputation.d.ts +362 -0
  22. package/dist/abis/ERC8004Reputation.d.ts.map +1 -0
  23. package/dist/abis/ERC8004Reputation.js +229 -0
  24. package/dist/abis/ERC8004Reputation.js.map +1 -0
  25. package/dist/abis/ERC8004Validation.d.ts +234 -0
  26. package/dist/abis/ERC8004Validation.d.ts.map +1 -0
  27. package/dist/abis/ERC8004Validation.js +162 -0
  28. package/dist/abis/ERC8004Validation.js.map +1 -0
  29. package/dist/abis/Q00bFactory.d.ts +123 -0
  30. package/dist/abis/Q00bFactory.d.ts.map +1 -0
  31. package/dist/abis/Q00bFactory.js +65 -0
  32. package/dist/abis/Q00bFactory.js.map +1 -0
  33. package/dist/abis/TheQ00bs.d.ts +119 -0
  34. package/dist/abis/TheQ00bs.d.ts.map +1 -0
  35. package/dist/abis/TheQ00bs.js +73 -0
  36. package/dist/abis/TheQ00bs.js.map +1 -0
  37. package/dist/abis/index.d.ts +9 -0
  38. package/dist/abis/index.d.ts.map +1 -0
  39. package/dist/abis/index.js +17 -0
  40. package/dist/abis/index.js.map +1 -0
  41. package/dist/client.d.ts +111 -0
  42. package/dist/client.d.ts.map +1 -0
  43. package/dist/client.js +134 -0
  44. package/dist/client.js.map +1 -0
  45. package/dist/consensus.d.ts +85 -0
  46. package/dist/consensus.d.ts.map +1 -0
  47. package/dist/consensus.js +227 -0
  48. package/dist/consensus.js.map +1 -0
  49. package/dist/constants.d.ts +85 -0
  50. package/dist/constants.d.ts.map +1 -0
  51. package/dist/constants.js +113 -0
  52. package/dist/constants.js.map +1 -0
  53. package/dist/discovery.d.ts +70 -0
  54. package/dist/discovery.d.ts.map +1 -0
  55. package/dist/discovery.js +214 -0
  56. package/dist/discovery.js.map +1 -0
  57. package/dist/erc8004.d.ts +311 -0
  58. package/dist/erc8004.d.ts.map +1 -0
  59. package/dist/erc8004.js +824 -0
  60. package/dist/erc8004.js.map +1 -0
  61. package/dist/errors.d.ts +107 -0
  62. package/dist/errors.d.ts.map +1 -0
  63. package/dist/errors.js +210 -0
  64. package/dist/errors.js.map +1 -0
  65. package/dist/escrow.d.ts +86 -0
  66. package/dist/escrow.d.ts.map +1 -0
  67. package/dist/escrow.js +267 -0
  68. package/dist/escrow.js.map +1 -0
  69. package/dist/index.d.ts +51 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +118 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/privy.d.ts +197 -0
  74. package/dist/privy.d.ts.map +1 -0
  75. package/dist/privy.js +524 -0
  76. package/dist/privy.js.map +1 -0
  77. package/dist/trust.d.ts +49 -0
  78. package/dist/trust.d.ts.map +1 -0
  79. package/dist/trust.js +117 -0
  80. package/dist/trust.js.map +1 -0
  81. package/dist/types.d.ts +472 -0
  82. package/dist/types.d.ts.map +1 -0
  83. package/dist/types.js +36 -0
  84. package/dist/types.js.map +1 -0
  85. package/package.json +30 -0
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ /**
3
+ * @q00bs/agent-sdk — Discovery Module
4
+ *
5
+ * Finds other registered agents on-chain based on trust proximity,
6
+ * activity status, and capabilities.
7
+ *
8
+ * HOW DISCOVERY WORKS:
9
+ * 1. Read totalSupply() from AgentRegistry to know how many agents exist.
10
+ * 2. Iterate through agents, filtering by:
11
+ * - Active + not frozen
12
+ * - Connected to the querying agent (trust path exists)
13
+ * - Minimum trust score
14
+ * - Max hops
15
+ * 3. Sort results by trust score (default) or recency.
16
+ *
17
+ * NOTE: For large agent populations, this on-chain iteration won't scale.
18
+ * The Trust API server (api/) provides an indexed, paginated version.
19
+ * This SDK module works well for <1000 agents.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.AgentDiscovery = void 0;
23
+ const AgentRegistry_1 = require("./abis/AgentRegistry");
24
+ const constants_1 = require("./constants");
25
+ // ─────────────────────────────────────────────────────────────
26
+ // AGENT DISCOVERY
27
+ // ─────────────────────────────────────────────────────────────
28
+ class AgentDiscovery {
29
+ client;
30
+ registryAddress;
31
+ trustResolver;
32
+ logger;
33
+ constructor(client, registryAddress, trustResolver, logger) {
34
+ this.client = client;
35
+ this.registryAddress = registryAddress;
36
+ this.trustResolver = trustResolver;
37
+ this.logger = logger;
38
+ }
39
+ /**
40
+ * Search for agents that match given criteria.
41
+ *
42
+ * @param myAgentId - Your agent's on-chain ID (used for trust-path filtering).
43
+ * @param query - Filters: minimum trust, max hops, limit, sort order.
44
+ * @returns Array of discovered agents, sorted by effective trust (descending).
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const agents = await discovery.find(1, {
49
+ * minTrustScore: 50,
50
+ * maxHops: 2,
51
+ * limit: 10,
52
+ * });
53
+ * ```
54
+ */
55
+ async find(myAgentId, query = {}) {
56
+ const { minTrustScore = 0, maxHops = constants_1.DEFAULT_MAX_HOPS, limit = 20, sortBy = 'trust', } = query;
57
+ this.logger.info(`Discovering agents: minTrust=${minTrustScore}, maxHops=${maxHops}, limit=${limit}`);
58
+ // Get total agent count
59
+ const totalSupply = await this.client.readContract({
60
+ address: this.registryAddress,
61
+ abi: AgentRegistry_1.AGENT_REGISTRY_ABI,
62
+ functionName: 'totalSupply',
63
+ });
64
+ const total = Number(totalSupply);
65
+ this.logger.debug(`Total registered agents: ${total}`);
66
+ const results = [];
67
+ // Iterate through all agents (IDs start at 1)
68
+ for (let id = 1; id <= total && results.length < limit * 2; id++) {
69
+ if (id === myAgentId)
70
+ continue; // Skip self
71
+ try {
72
+ // Read agent record
73
+ const agentData = await this.client.readContract({
74
+ address: this.registryAddress,
75
+ abi: AgentRegistry_1.AGENT_REGISTRY_ABI,
76
+ functionName: 'getAgent',
77
+ args: [BigInt(id)],
78
+ });
79
+ // Skip inactive/frozen
80
+ if (!agentData.active || agentData.frozen)
81
+ continue;
82
+ // Check raw trust score threshold
83
+ const rawTrust = Number(agentData.trustScore);
84
+ if (rawTrust / 100 < minTrustScore)
85
+ continue;
86
+ // Check trust path
87
+ try {
88
+ const trustPath = await this.trustResolver.resolve(myAgentId, id);
89
+ if (!trustPath.connected || trustPath.pathLength > maxHops)
90
+ continue;
91
+ results.push({
92
+ id,
93
+ wallet: agentData.wallet,
94
+ ownerQ00b: agentData.ownerQ00b,
95
+ trustScore: rawTrust / 100,
96
+ hops: trustPath.pathLength,
97
+ effectiveTrust: trustPath.effectiveTrust / 100,
98
+ active: true,
99
+ capabilitiesHash: agentData.capabilitiesHash,
100
+ });
101
+ }
102
+ catch {
103
+ // No trust path → skip
104
+ continue;
105
+ }
106
+ }
107
+ catch (error) {
108
+ this.logger.debug(`Skipping agent ${id}: ${error}`);
109
+ continue;
110
+ }
111
+ }
112
+ // Sort results
113
+ if (sortBy === 'trust') {
114
+ results.sort((a, b) => b.effectiveTrust - a.effectiveTrust);
115
+ }
116
+ else if (sortBy === 'recent') {
117
+ // Would need lastActiveAt — for now sort by ID desc (higher ID = more recent)
118
+ results.sort((a, b) => b.id - a.id);
119
+ }
120
+ // Apply limit
121
+ const limited = results.slice(0, limit);
122
+ this.logger.info(`Found ${limited.length} agents matching criteria`);
123
+ return limited;
124
+ }
125
+ /**
126
+ * Get a single agent by its on-chain ID.
127
+ *
128
+ * @param agentId - The agent's on-chain ID.
129
+ * @returns The agent record, or null if not found.
130
+ */
131
+ async getAgent(agentId) {
132
+ try {
133
+ const data = await this.client.readContract({
134
+ address: this.registryAddress,
135
+ abi: AgentRegistry_1.AGENT_REGISTRY_ABI,
136
+ functionName: 'getAgent',
137
+ args: [BigInt(agentId)],
138
+ });
139
+ // Check if agent exists (wallet will be zero address if not)
140
+ if (data.wallet === '0x0000000000000000000000000000000000000000') {
141
+ return null;
142
+ }
143
+ return {
144
+ wallet: data.wallet,
145
+ ownerQ00b: data.ownerQ00b,
146
+ sidePosition: Number(data.sidePosition),
147
+ capabilitiesHash: data.capabilitiesHash,
148
+ trustScore: Number(data.trustScore),
149
+ registeredAt: Number(data.registeredAt),
150
+ lastActiveAt: Number(data.lastActiveAt),
151
+ active: data.active,
152
+ frozen: data.frozen,
153
+ };
154
+ }
155
+ catch {
156
+ return null;
157
+ }
158
+ }
159
+ /**
160
+ * Get an agent by its wallet address.
161
+ *
162
+ * @param wallet - The agent's wallet address.
163
+ * @returns Object with { id, agent } or null if not found.
164
+ */
165
+ async getAgentByWallet(wallet) {
166
+ try {
167
+ const [id, data] = await this.client.readContract({
168
+ address: this.registryAddress,
169
+ abi: AgentRegistry_1.AGENT_REGISTRY_ABI,
170
+ functionName: 'getAgentByWallet',
171
+ args: [wallet],
172
+ });
173
+ if (Number(id) === 0)
174
+ return null;
175
+ return {
176
+ id: Number(id),
177
+ agent: {
178
+ wallet: data.wallet,
179
+ ownerQ00b: data.ownerQ00b,
180
+ sidePosition: Number(data.sidePosition),
181
+ capabilitiesHash: data.capabilitiesHash,
182
+ trustScore: Number(data.trustScore),
183
+ registeredAt: Number(data.registeredAt),
184
+ lastActiveAt: Number(data.lastActiveAt),
185
+ active: data.active,
186
+ frozen: data.frozen,
187
+ },
188
+ };
189
+ }
190
+ catch {
191
+ return null;
192
+ }
193
+ }
194
+ /**
195
+ * Check if a specific agent is active and not frozen.
196
+ *
197
+ * @param agentId - The agent's on-chain ID.
198
+ */
199
+ async isActive(agentId) {
200
+ try {
201
+ return await this.client.readContract({
202
+ address: this.registryAddress,
203
+ abi: AgentRegistry_1.AGENT_REGISTRY_ABI,
204
+ functionName: 'isAgentActive',
205
+ args: [BigInt(agentId)],
206
+ });
207
+ }
208
+ catch {
209
+ return false;
210
+ }
211
+ }
212
+ }
213
+ exports.AgentDiscovery = AgentDiscovery;
214
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAGH,wDAA0D;AAG1D,2CAAgE;AAEhE,gEAAgE;AAChE,kBAAkB;AAClB,gEAAgE;AAEhE,MAAa,cAAc;IACjB,MAAM,CAAiC;IACvC,eAAe,CAAgB;IAC/B,aAAa,CAAgB;IAC7B,MAAM,CAAS;IAEvB,YACE,MAAsC,EACtC,eAAuB,EACvB,aAA4B,EAC5B,MAAc;QAEd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,eAAgC,CAAC;QACxD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,QAAoB,EAAE;QAClD,MAAM,EACJ,aAAa,GAAG,CAAC,EACjB,OAAO,GAAG,4BAAgB,EAC1B,KAAK,GAAG,EAAE,EACV,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agents Manager
3
+ *
4
+ * This module integrates the ERC-8004 standard (Trustless Agents) into the
5
+ * Q00bs agent platform. ERC-8004 defines three on-chain registries that give
6
+ * agents interoperable identity, reputation, and validation across the
7
+ * broader ecosystem — not just within Q00bs.
8
+ *
9
+ * WHY ERC-8004?
10
+ * Q00bs agents already have identity via AgentRegistry (ERC-721) and trust
11
+ * via the q00b graph. ERC-8004 adds a PORTABLE layer:
12
+ * - Identity that other agent platforms can read and verify
13
+ * - Reputation that follows an agent across ecosystems
14
+ * - Validation from third-party auditors (compliance, capabilities)
15
+ *
16
+ * Base is already implementing ERC-8004, making it the canonical standard
17
+ * for agent identity on L2. Integrating now gives Q00bs agents first-mover
18
+ * advantage in the interoperable agent economy.
19
+ *
20
+ * ARCHITECTURE:
21
+ * ┌──────────────────┐ ┌────────────────────────────────────┐
22
+ * │ Q00bs │ │ ERC-8004 Registries (Base) │
23
+ * │ AgentRegistry │────▶│ IdentityRegistry (0x8004...432) │
24
+ * │ (your agents) │ │ ReputationRegistry (0x8004...b63) │
25
+ * │ │ │ ValidationRegistry (TBD) │
26
+ * └──────────────────┘ └────────────────────────────────────┘
27
+ *
28
+ * Q00bs agents register in BOTH registries:
29
+ * 1. AgentRegistry (Q00bs-specific: trust scores, q00b graph, escrow)
30
+ * 2. ERC-8004 IdentityRegistry (ecosystem-wide: portable identity)
31
+ *
32
+ * The ERC-8004 identity links back to the Q00bs agent via:
33
+ * - agentWallet (same wallet address)
34
+ * - agentURI (points to registration file with Q00bs metadata)
35
+ * - Metadata keys (e.g. "q00bs_agent_id", "q00bs_trust_score")
36
+ *
37
+ * THREE REGISTRIES:
38
+ *
39
+ * 1. IDENTITY REGISTRY (ERC-721)
40
+ * - Mint agent identity NFTs
41
+ * - Set agentURI (registration file)
42
+ * - Bind agent wallet with EIP-712/ERC-1271 proof
43
+ * - Store extensible key-value metadata
44
+ *
45
+ * 2. REPUTATION REGISTRY
46
+ * - Give signed fixed-point feedback to other agents
47
+ * - Read aggregate reputation summaries
48
+ * - Respond to feedback received
49
+ * - Self-feedback is prevented on-chain
50
+ *
51
+ * 3. VALIDATION REGISTRY (evolving)
52
+ * - Request validation from third-party validators
53
+ * - Read validation results and summaries
54
+ *
55
+ * REFERENCE: https://www.8004.org/build
56
+ *
57
+ * USAGE:
58
+ * ```ts
59
+ * const manager = new ERC8004Manager(publicClient, walletClient, logger);
60
+ *
61
+ * // Register an ERC-8004 identity
62
+ * const identity = await manager.registerIdentity('0xOwnerAddress');
63
+ *
64
+ * // Set the agent URI
65
+ * await manager.setAgentURI(identity.agentId, 'https://q00bs.com/agents/42.json');
66
+ *
67
+ * // Give feedback to another agent
68
+ * await manager.giveFeedback({
69
+ * subjectAgentId: 7,
70
+ * value: 4.5,
71
+ * decimals: 2,
72
+ * }, myAgentId);
73
+ *
74
+ * // Read reputation
75
+ * const summary = await manager.getReputationSummary(7);
76
+ * console.log(`Average: ${summary.average}`);
77
+ * ```
78
+ */
79
+ import type { PublicClient, WalletClient, Chain, Transport, Account } from 'viem';
80
+ import type { ERC8004Config, ERC8004Identity, ERC8004AgentIdentifier, ERC8004Feedback, ERC8004ReputationSummary, ERC8004ValidationResult, ERC8004ValidationSummary, GiveFeedbackParams, Logger } from './types';
81
+ export declare class ERC8004Manager {
82
+ private publicClient;
83
+ private walletClient?;
84
+ private logger;
85
+ private identityRegistry;
86
+ private reputationRegistry;
87
+ private validationRegistry;
88
+ private _erc8004AgentId?;
89
+ /** The agent's ERC-8004 agentId (if registered). */
90
+ get erc8004AgentId(): number | undefined;
91
+ /** The IdentityRegistry address being used. */
92
+ get identityRegistryAddress(): string;
93
+ /** The ReputationRegistry address being used. */
94
+ get reputationRegistryAddress(): string;
95
+ constructor(publicClient: PublicClient<Transport, Chain>, logger: Logger, walletClient?: WalletClient<Transport, Chain, Account>, config?: ERC8004Config);
96
+ /**
97
+ * Register a new ERC-8004 agent identity.
98
+ *
99
+ * Mints an ERC-721 token in the IdentityRegistry. The tokenId becomes
100
+ * the agent's ERC-8004 agentId.
101
+ *
102
+ * @param ownerAddress - Address to mint the identity NFT to.
103
+ * @returns The new ERC-8004 identity.
104
+ * @throws ERC8004RegistryError if the transaction fails.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const identity = await erc8004.registerIdentity('0xYourAddress');
109
+ * console.log(`ERC-8004 ID: ${identity.agentId}`);
110
+ * console.log(`Identifier: ${identity.identifier}`);
111
+ * ```
112
+ */
113
+ registerIdentity(ownerAddress: string): Promise<ERC8004Identity>;
114
+ /**
115
+ * Get an ERC-8004 identity by agentId.
116
+ *
117
+ * @param agentId - The ERC-8004 agentId (tokenId).
118
+ * @returns The identity, or null if not found.
119
+ */
120
+ getIdentity(agentId: number): Promise<ERC8004Identity | null>;
121
+ /**
122
+ * Set the agentURI (tokenURI) for an ERC-8004 identity.
123
+ *
124
+ * The agentURI should point to a JSON file describing the agent
125
+ * (name, capabilities, endpoints, etc.).
126
+ *
127
+ * @param agentId - The ERC-8004 agentId.
128
+ * @param uri - The URI to set (IPFS, HTTPS, etc.).
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * await erc8004.setAgentURI(42, 'ipfs://Qm.../agent.json');
133
+ * ```
134
+ */
135
+ setAgentURI(agentId: number, uri: string): Promise<void>;
136
+ /**
137
+ * Get metadata for an ERC-8004 identity.
138
+ *
139
+ * @param agentId - The ERC-8004 agentId.
140
+ * @param key - The metadata key to read.
141
+ * @returns The metadata value (empty string if not set).
142
+ */
143
+ getMetadata(agentId: number, key: string): Promise<string>;
144
+ /**
145
+ * Set metadata on an ERC-8004 identity.
146
+ *
147
+ * Use this to store Q00bs-specific data on the ERC-8004 identity,
148
+ * making it discoverable by other platforms.
149
+ *
150
+ * @param agentId - The ERC-8004 agentId.
151
+ * @param key - The metadata key (cannot be "agentWallet" — use setAgentWallet).
152
+ * @param value - The metadata value.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * await erc8004.setMetadata(42, 'q00bs_agent_id', '7');
157
+ * await erc8004.setMetadata(42, 'q00bs_trust_score', '8500');
158
+ * await erc8004.setMetadata(42, 'capabilities', 'data_analysis,web_scraping');
159
+ * ```
160
+ */
161
+ setMetadata(agentId: number, key: string, value: string): Promise<void>;
162
+ /**
163
+ * Get the agent wallet address for an ERC-8004 identity.
164
+ *
165
+ * @param agentId - The ERC-8004 agentId.
166
+ * @returns The wallet address, or null if not set.
167
+ */
168
+ getAgentWallet(agentId: number): Promise<string | null>;
169
+ /**
170
+ * Set the agent wallet for an ERC-8004 identity with EIP-712/ERC-1271 proof.
171
+ *
172
+ * The proof ensures the wallet owner has consented to being linked
173
+ * to this identity. In practice, this means the agent wallet signs
174
+ * a typed-data message proving ownership.
175
+ *
176
+ * @param agentId - The ERC-8004 agentId.
177
+ * @param wallet - The wallet address to bind.
178
+ * @param proof - The EIP-712 or ERC-1271 proof bytes.
179
+ */
180
+ setAgentWallet(agentId: number, wallet: string, proof: `0x${string}`): Promise<void>;
181
+ /**
182
+ * Get the total number of ERC-8004 identities registered.
183
+ */
184
+ getIdentityCount(): Promise<number>;
185
+ /**
186
+ * Give feedback to another agent via the ERC-8004 ReputationRegistry.
187
+ *
188
+ * Feedback is a signed fixed-point number (e.g. 4.5 → value=450, decimals=2).
189
+ * Self-feedback is prevented at the contract level.
190
+ *
191
+ * @param params - Feedback parameters (subject, value, decimals).
192
+ * @param fromAgentId - The ERC-8004 agentId of the feedback giver (your agent).
193
+ * @param fromIdentityRegistry - Override sender's identity registry (default: this one).
194
+ * @returns The feedback index.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * const index = await erc8004.giveFeedback({
199
+ * subjectAgentId: 7,
200
+ * value: 4.5,
201
+ * decimals: 2,
202
+ * }, myERC8004AgentId);
203
+ * ```
204
+ */
205
+ giveFeedback(params: GiveFeedbackParams, fromAgentId: number, fromIdentityRegistry?: string): Promise<number>;
206
+ /**
207
+ * Revoke previously given feedback.
208
+ *
209
+ * @param subjectAgentId - The agent that received the feedback.
210
+ * @param fromAgentId - Your agent's ERC-8004 ID.
211
+ * @param feedbackIndex - The index of the feedback to revoke.
212
+ * @param subjectIdentityRegistry - Override subject's registry.
213
+ * @param fromIdentityRegistry - Override sender's registry.
214
+ */
215
+ revokeFeedback(subjectAgentId: number, fromAgentId: number, feedbackIndex: number, subjectIdentityRegistry?: string, fromIdentityRegistry?: string): Promise<void>;
216
+ /**
217
+ * Append a response to feedback your agent received.
218
+ *
219
+ * @param agentId - Your agent's ERC-8004 ID.
220
+ * @param fromAgentId - The feedback giver's ERC-8004 ID.
221
+ * @param feedbackIndex - The index of the feedback to respond to.
222
+ * @param response - The response text.
223
+ * @param fromIdentityRegistry - Override feedback giver's registry.
224
+ */
225
+ respondToFeedback(agentId: number, fromAgentId: number, feedbackIndex: number, response: string, fromIdentityRegistry?: string): Promise<void>;
226
+ /**
227
+ * Read a specific feedback entry.
228
+ *
229
+ * @param agentId - The agent's ERC-8004 ID.
230
+ * @param index - The feedback index.
231
+ * @param identityRegistry - Override identity registry.
232
+ * @returns The feedback entry.
233
+ */
234
+ readFeedback(agentId: number, index: number, identityRegistry?: string): Promise<ERC8004Feedback>;
235
+ /**
236
+ * Read all feedback entries for an agent.
237
+ *
238
+ * @param agentId - The agent's ERC-8004 ID.
239
+ * @param identityRegistry - Override identity registry.
240
+ * @returns Array of all feedback entries.
241
+ */
242
+ readAllFeedback(agentId: number, identityRegistry?: string): Promise<ERC8004Feedback[]>;
243
+ /**
244
+ * Get the reputation summary for an agent.
245
+ *
246
+ * @param agentId - The agent's ERC-8004 ID.
247
+ * @param identityRegistry - Override identity registry.
248
+ * @returns Aggregate reputation summary.
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * const rep = await erc8004.getReputationSummary(42);
253
+ * console.log(`${rep.count} ratings, average: ${rep.average.toFixed(2)}`);
254
+ * ```
255
+ */
256
+ getReputationSummary(agentId: number, identityRegistry?: string): Promise<ERC8004ReputationSummary>;
257
+ /**
258
+ * Get the last feedback index for an agent.
259
+ */
260
+ getLastFeedbackIndex(agentId: number, identityRegistry?: string): Promise<number>;
261
+ /**
262
+ * Request validation from a validator contract.
263
+ *
264
+ * @param agentId - The agent's ERC-8004 ID.
265
+ * @param validatorContract - The validator contract address.
266
+ * @returns The validation request ID.
267
+ */
268
+ requestValidation(agentId: number, validatorContract: string): Promise<number>;
269
+ /**
270
+ * Get the status of a validation request.
271
+ *
272
+ * @param agentId - The agent's ERC-8004 ID.
273
+ * @param requestId - The validation request ID.
274
+ * @returns The validation result.
275
+ */
276
+ getValidationStatus(agentId: number, requestId: number): Promise<ERC8004ValidationResult>;
277
+ /**
278
+ * Get the validation summary for an agent.
279
+ *
280
+ * @param agentId - The agent's ERC-8004 ID.
281
+ * @returns Validation summary with counts.
282
+ */
283
+ getValidationSummary(agentId: number): Promise<ERC8004ValidationSummary>;
284
+ /**
285
+ * Sync a Q00bs agent's trust score to ERC-8004 metadata.
286
+ *
287
+ * This writes the Q00bs trust score as metadata on the ERC-8004 identity,
288
+ * making it visible to other agent platforms that read ERC-8004.
289
+ *
290
+ * @param erc8004AgentId - The agent's ERC-8004 ID.
291
+ * @param q00bsAgentId - The agent's Q00bs AgentRegistry ID.
292
+ * @param trustScore - The Q00bs trust score (0-10000).
293
+ */
294
+ syncTrustToMetadata(erc8004AgentId: number, q00bsAgentId: number, trustScore: number): Promise<void>;
295
+ /**
296
+ * Build the full ERC-8004 agent identifier string.
297
+ *
298
+ * Format: {namespace}:{chainId}:{identityRegistry}:{agentId}
299
+ */
300
+ buildIdentifier(agentId: number): string;
301
+ /**
302
+ * Parse an ERC-8004 agent identifier string.
303
+ *
304
+ * @param identifier - The identifier string.
305
+ * @returns Parsed components.
306
+ */
307
+ static parseIdentifier(identifier: string): ERC8004AgentIdentifier;
308
+ private ensureWalletClient;
309
+ private ensureValidationRegistry;
310
+ }
311
+ //# sourceMappingURL=erc8004.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erc8004.d.ts","sourceRoot":"","sources":["../src/erc8004.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;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