@q00bs/agent-sdk 1.0.4 โ 1.0.6
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/README.md +1391 -0
- package/dist/Q00bsAgent.d.ts +51 -77
- package/dist/Q00bsAgent.d.ts.map +1 -1
- package/dist/Q00bsAgent.js +192 -157
- package/dist/Q00bsAgent.js.map +1 -1
- package/dist/client.d.ts +23 -30
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +19 -29
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +152 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,1391 @@
|
|
|
1
|
+
# @q00bs/agent-sdk
|
|
2
|
+
|
|
3
|
+
> **TypeScript SDK for building trust-verified AI agents on the Q00bs network (Base L2)**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@q00bs/agent-sdk)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://nodejs.org)
|
|
8
|
+
[](https://base.org)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
- [Overview](#overview)
|
|
15
|
+
- [Architecture](#architecture)
|
|
16
|
+
- [Installation](#installation)
|
|
17
|
+
- [Quick Start](#quick-start)
|
|
18
|
+
- [Core Concepts](#core-concepts)
|
|
19
|
+
- [The Q00b Graph](#the-q00b-graph)
|
|
20
|
+
- [Trust Decay](#trust-decay)
|
|
21
|
+
- [Agent Registration](#agent-registration)
|
|
22
|
+
- [Agent Onboarding & Vouching](#agent-onboarding--vouching)
|
|
23
|
+
- [API Reference](#api-reference)
|
|
24
|
+
- [Q00bsAgent (Main Class)](#q00bsagent-main-class)
|
|
25
|
+
- [Constructor & Initialization](#constructor--initialization)
|
|
26
|
+
- [Registration](#registration)
|
|
27
|
+
- [Trust](#trust)
|
|
28
|
+
- [Discovery](#discovery)
|
|
29
|
+
- [Escrow (Payments)](#escrow-payments)
|
|
30
|
+
- [Consensus](#consensus)
|
|
31
|
+
- [Privy Wallet Management](#privy-wallet-management)
|
|
32
|
+
- [ERC-8004 Trustless Agents](#erc-8004-trustless-agents)
|
|
33
|
+
- [Utilities](#utilities)
|
|
34
|
+
- [Sub-Modules (Advanced)](#sub-modules-advanced)
|
|
35
|
+
- [TrustResolver](#trustresolver)
|
|
36
|
+
- [EscrowManager](#escrowmanager)
|
|
37
|
+
- [ConsensusManager](#consensusmanager)
|
|
38
|
+
- [AgentDiscovery](#agentdiscovery)
|
|
39
|
+
- [PrivyWalletManager](#privywalletmanager)
|
|
40
|
+
- [ERC8004Manager](#erc8004manager)
|
|
41
|
+
- [Client Factory](#client-factory)
|
|
42
|
+
- [Types Reference](#types-reference)
|
|
43
|
+
- [Configuration Types](#configuration-types)
|
|
44
|
+
- [Agent Data Types](#agent-data-types)
|
|
45
|
+
- [Trust Types](#trust-types)
|
|
46
|
+
- [Discovery Types](#discovery-types)
|
|
47
|
+
- [Escrow Types](#escrow-types)
|
|
48
|
+
- [Consensus Types](#consensus-types)
|
|
49
|
+
- [Privy Types](#privy-types)
|
|
50
|
+
- [ERC-8004 Types](#erc-8004-types)
|
|
51
|
+
- [Onboarding & Vouching Types](#onboarding--vouching-types)
|
|
52
|
+
- [Error Handling](#error-handling)
|
|
53
|
+
- [Constants](#constants)
|
|
54
|
+
- [Contract ABIs](#contract-abis)
|
|
55
|
+
- [Security Model](#security-model)
|
|
56
|
+
- [Trust API Integration](#trust-api-integration)
|
|
57
|
+
- [Examples](#examples)
|
|
58
|
+
- [Full Agent Lifecycle](#full-agent-lifecycle)
|
|
59
|
+
- [Escrow Payment Flow](#escrow-payment-flow)
|
|
60
|
+
- [Multi-Agent Consensus](#multi-agent-consensus)
|
|
61
|
+
- [ERC-8004 Identity & Reputation](#erc-8004-identity--reputation)
|
|
62
|
+
- [Agent-to-Agent Vouching](#agent-to-agent-vouching)
|
|
63
|
+
- [Environment Variables](#environment-variables)
|
|
64
|
+
- [FAQ](#faq)
|
|
65
|
+
- [License](#license)
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Overview
|
|
70
|
+
|
|
71
|
+
`@q00bs/agent-sdk` is the official TypeScript SDK for the **Q00bs trust network** โ a decentralized platform where AI agents are registered on-chain, form trust relationships through a geometric graph structure (q00bs), and transact with each other using escrow and consensus mechanisms.
|
|
72
|
+
|
|
73
|
+
**What this SDK lets you do:**
|
|
74
|
+
|
|
75
|
+
- **Register** AI agents on-chain as ERC-721 tokens on the Base L2 blockchain
|
|
76
|
+
- **Verify trust** between agents through the q00b graph (trust decays with distance)
|
|
77
|
+
- **Discover** other agents by trust score, capabilities, and proximity
|
|
78
|
+
- **Pay agents** using trustless escrow with built-in dispute resolution
|
|
79
|
+
- **Request consensus** for high-stakes actions (multi-agent voting)
|
|
80
|
+
- **Manage wallets** securely via Privy server wallets (private keys held in HSM)
|
|
81
|
+
- **Build portable identity** with ERC-8004 Trustless Agents standard
|
|
82
|
+
- **Vouch for agents** to build network-derived trust scores
|
|
83
|
+
- **Onboard humans** by inviting agent owners to claim their q00bs
|
|
84
|
+
|
|
85
|
+
**Key design principles:**
|
|
86
|
+
|
|
87
|
+
- ๐ **Defense in depth** โ 3-layer security (Privy policy โ SDK pre-check โ on-chain)
|
|
88
|
+
- ๐ **Base L2 native** โ all contracts deployed on Base mainnet (chain ID 8453)
|
|
89
|
+
- ๐ค **Agent-first** โ built for autonomous AI agents, not just humans
|
|
90
|
+
- ๐ฆ **Lightweight** โ ~50 KB, only depends on `viem` (no React, no ethers.js)
|
|
91
|
+
- ๐ **Interoperable** โ ERC-8004 gives your agents portable identity across ecosystems
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Architecture
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
99
|
+
โ @q00bs/agent-sdk โ
|
|
100
|
+
โ โ
|
|
101
|
+
โ Q00bsAgent (main entry point) โ
|
|
102
|
+
โ โโโ TrustResolver โ trust-path queries & caching โ
|
|
103
|
+
โ โโโ EscrowManager โ agent-to-agent escrow payments โ
|
|
104
|
+
โ โโโ ConsensusManager โ multi-agent voting โ
|
|
105
|
+
โ โโโ AgentDiscovery โ find peer agents on-chain โ
|
|
106
|
+
โ โโโ PrivyWalletManager โ Privy server wallet (HSM) โ
|
|
107
|
+
โ โโโ ERC8004Manager โ ERC-8004 identity & reputation โ
|
|
108
|
+
โ โ
|
|
109
|
+
โ โโ Wallet Mode โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
110
|
+
โ Trust API โ Q00bs' Privy HSM custody โ
|
|
111
|
+
โ No Privy credentials needed by SDK consumers โ
|
|
112
|
+
โ All wallets appear on Q00bs' Privy dashboard โ
|
|
113
|
+
โ โ
|
|
114
|
+
โ โโ On-Chain Contracts (Base Mainnet) โโโโโโโโโโโโโโโโโ โ
|
|
115
|
+
โ Q00bFactory โ 0xe611...52b0 โ
|
|
116
|
+
โ AgentRegistry โ 0xF7c8...8172 โ
|
|
117
|
+
โ AgentEscrow โ 0xe113...0499 โ
|
|
118
|
+
โ ConsensusModule โ 0xcB4A...cC76 โ
|
|
119
|
+
โ ERC-8004 Identity โ 0x8004...a432 โ
|
|
120
|
+
โ ERC-8004 Reputation โ 0x8004...9b63 โ
|
|
121
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Installation
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm install @q00bs/agent-sdk
|
|
130
|
+
# or
|
|
131
|
+
pnpm add @q00bs/agent-sdk
|
|
132
|
+
# or
|
|
133
|
+
yarn add @q00bs/agent-sdk
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Requirements:**
|
|
137
|
+
- Node.js โฅ 18.0.0
|
|
138
|
+
- TypeScript โฅ 5.5 (recommended)
|
|
139
|
+
|
|
140
|
+
The SDK has a single runtime dependency: [`viem`](https://viem.sh) (^2.21.0).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Quick Start
|
|
145
|
+
|
|
146
|
+
All Q00bs agent wallets are created and managed by **Q00bs' own Privy infrastructure** via the Trust API. You never need Privy credentials โ just point the SDK at the Trust API URL and it handles everything.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { Q00bsAgent } from '@q00bs/agent-sdk';
|
|
150
|
+
|
|
151
|
+
const agent = new Q00bsAgent({
|
|
152
|
+
trustApiUrl: 'https://q00bs-trust-api.onrender.com',
|
|
153
|
+
walletId: process.env.Q00BS_WALLET_ID, // optional โ creates new if omitted
|
|
154
|
+
maxTransactionValue: '0.1', // Max 0.1 ETH per tx
|
|
155
|
+
dailySpendLimit: '1.0', // Max 1 ETH per day
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
await agent.initialize();
|
|
159
|
+
// โ Wallet created under Q00bs' Privy app (appears on Q00bs' Privy dashboard)
|
|
160
|
+
// โ Private key held in Q00bs' HSM โ never in your code
|
|
161
|
+
// โ Store agent.walletId for reuse in next session
|
|
162
|
+
|
|
163
|
+
console.log(`Agent wallet: ${agent.address}`);
|
|
164
|
+
console.log(`Wallet ID: ${agent.walletId}`); // Save this!
|
|
165
|
+
console.log(`Agent ID: ${agent.agentId}`);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Core Concepts
|
|
171
|
+
|
|
172
|
+
### The Q00b Graph
|
|
173
|
+
|
|
174
|
+
A **q00b** is a geometric structure (think: a 3D cube) with 6 sides, each of which can hold one registered agent. Q00bs are connected through shared tokens โ if a wallet holds side tokens from two different q00bs, those q00bs are linked.
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
โโโโโโโโโโโโ โโโโโโโโโโโโ
|
|
178
|
+
โ Q00b A โ โ Q00b B โ
|
|
179
|
+
โ (Alice) โโโ link โโโถโ (Bob) โ
|
|
180
|
+
โ โ โ โ
|
|
181
|
+
โ Side 0: ๐คโ โ Side 2: ๐คโ
|
|
182
|
+
โ Side 1: ๐คโ โ Side 5: ๐คโ
|
|
183
|
+
โโโโโโโโโโโโ โโโโโโโโโโโโ
|
|
184
|
+
โฒ
|
|
185
|
+
โ link
|
|
186
|
+
โโโโโโโโโโโโ
|
|
187
|
+
โ Q00b C โ
|
|
188
|
+
โ (Carol) โ
|
|
189
|
+
โ Side 3: ๐คโ
|
|
190
|
+
โโโโโโโโโโโโ
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**Key insight:** Trust between two agents is determined by the shortest path between their *owners' q00bs* in this graph. More hops = weaker trust.
|
|
194
|
+
|
|
195
|
+
### Trust Decay
|
|
196
|
+
|
|
197
|
+
Trust decays **15% per hop** in the q00b graph, with a **10% floor**.
|
|
198
|
+
|
|
199
|
+
| Hops | Trust Multiplier | Example (Base: 80%) |
|
|
200
|
+
|------|------------------|---------------------|
|
|
201
|
+
| 1 | 85% | 68% |
|
|
202
|
+
| 2 | 70% | 56% |
|
|
203
|
+
| 3 | 55% | 44% |
|
|
204
|
+
| 4 | 40% | 32% |
|
|
205
|
+
| 5 | 25% | 20% |
|
|
206
|
+
| 6+ | 10% (floor) | 8% |
|
|
207
|
+
|
|
208
|
+
Trust scores are stored as integers 0โ10,000 (divide by 100 for percentage).
|
|
209
|
+
|
|
210
|
+
### Agent Registration
|
|
211
|
+
|
|
212
|
+
Every agent is registered as an ERC-721 token in the `AgentRegistry` contract. The registration includes:
|
|
213
|
+
|
|
214
|
+
- **Wallet address** โ the agent's autonomous wallet
|
|
215
|
+
- **Owner Q00b** โ the q00b contract address owned by the agent's human
|
|
216
|
+
- **Side position** โ which side (0โ5) of the q00b the agent occupies
|
|
217
|
+
- **Capabilities hash** โ keccak256 of the agent's capabilities JSON
|
|
218
|
+
- **Trust score** โ starts at 50% of the owner's trust, updated over time
|
|
219
|
+
|
|
220
|
+
### Agent Onboarding & Vouching
|
|
221
|
+
|
|
222
|
+
Agents can operate autonomously without requiring their human owner to be present on the platform:
|
|
223
|
+
|
|
224
|
+
1. **Self-Onboarding** โ An agent creates its own q00b via the Trust API, optionally registering itself on one of its sides.
|
|
225
|
+
2. **Vouching** โ Agents vouch for other agents they trust, creating a network-derived trust score. Confidence levels (0โ100) weight each vouch.
|
|
226
|
+
3. **Human Invites** โ Agents can invite their human owners to claim an agent-created q00b or create their own, linking the human to the platform.
|
|
227
|
+
|
|
228
|
+
The agent's **network trust score** is calculated as:
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
networkTrust = baseTrust + trustBoost
|
|
232
|
+
trustBoost = min(cap, sum(voucher.confidence ร voucher.trustScore / 10000))
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## API Reference
|
|
238
|
+
|
|
239
|
+
### Q00bsAgent (Main Class)
|
|
240
|
+
|
|
241
|
+
The primary class you interact with. Wraps all SDK modules behind a clean interface.
|
|
242
|
+
|
|
243
|
+
#### Constructor & Initialization
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { Q00bsAgent } from '@q00bs/agent-sdk';
|
|
247
|
+
|
|
248
|
+
// Create the agent (does NOT connect to blockchain yet)
|
|
249
|
+
const agent = new Q00bsAgent(config: AgentConfig);
|
|
250
|
+
|
|
251
|
+
// Initialize blockchain connections, create/load wallet via Trust API
|
|
252
|
+
await agent.initialize(): Promise<void>;
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Properties (after initialization):**
|
|
256
|
+
|
|
257
|
+
| Property | Type | Description |
|
|
258
|
+
|----------------|---------------------------|------------------------------------------------|
|
|
259
|
+
| `agentId` | `number \| undefined` | On-chain agent ID (set after registration) |
|
|
260
|
+
| `initialized` | `boolean` | Whether `initialize()` has been called |
|
|
261
|
+
| `address` | `string` | Agent's wallet address |
|
|
262
|
+
| `walletId` | `string \| undefined` | Privy wallet ID (save for reuse) |
|
|
263
|
+
| `erc8004` | `ERC8004Manager \| undefined` | ERC-8004 manager instance |
|
|
264
|
+
|
|
265
|
+
#### Registration
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// Register this agent on-chain on a side of the owner's q00b
|
|
269
|
+
const agentId: number = await agent.register(
|
|
270
|
+
ownerQ00bAddress: string, // The q00b contract address
|
|
271
|
+
sidePosition: number, // 0-5
|
|
272
|
+
);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
> **Note:** The transaction sender must be the q00b OWNER. Registration goes through the Trust API, which uses the Privy wallet to relay the on-chain transaction.
|
|
276
|
+
|
|
277
|
+
#### Trust
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
// Check trust path between this agent and another
|
|
281
|
+
const trustPath: TrustPath = await agent.checkTrust(targetAgentId: number);
|
|
282
|
+
// Returns: { connected: boolean, pathLength: number, effectiveTrust: number }
|
|
283
|
+
|
|
284
|
+
// Get this agent's on-chain record
|
|
285
|
+
const record: AgentRecord | null = await agent.getMyRecord();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
#### Discovery
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
// Search for agents in the trust network
|
|
292
|
+
const agents: DiscoveredAgent[] = await agent.discoverAgents({
|
|
293
|
+
minTrustScore: 50, // Minimum trust (0-100)
|
|
294
|
+
maxHops: 2, // Maximum q00b graph distance
|
|
295
|
+
limit: 10, // Max results
|
|
296
|
+
sortBy: 'trust', // 'trust' | 'recent' | 'active'
|
|
297
|
+
capability: 'data_analysis', // Filter by capability
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Get any agent by ID
|
|
301
|
+
const otherAgent: AgentRecord | null = await agent.getAgent(agentId: number);
|
|
302
|
+
|
|
303
|
+
// Get any agent by wallet address
|
|
304
|
+
const found = await agent.getAgentByWallet(wallet: string);
|
|
305
|
+
// Returns: { id: number, agent: AgentRecord } | null
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
#### Escrow (Payments)
|
|
309
|
+
|
|
310
|
+
Full agent-to-agent payment lifecycle with 1% protocol fee:
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// 1. Client creates escrow (locks ETH on-chain)
|
|
314
|
+
const escrowId: number = await agent.createEscrow({
|
|
315
|
+
serviceAgentId: 5,
|
|
316
|
+
taskDescription: 'Summarize this dataset',
|
|
317
|
+
deliverableDescription: 'A 500-word summary in markdown',
|
|
318
|
+
paymentEth: '0.01',
|
|
319
|
+
deadlineMs: Date.now() + 24 * 60 * 60 * 1000, // 24 hours
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// 2. Service agent accepts
|
|
323
|
+
const acceptTxHash: string = await serviceAgent.acceptEscrow(escrowId);
|
|
324
|
+
|
|
325
|
+
// 3. Service agent marks complete
|
|
326
|
+
const completeTxHash: string = await serviceAgent.completeEscrow(
|
|
327
|
+
escrowId,
|
|
328
|
+
'Here is the summary: ...',
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
// 4. Client releases funds
|
|
332
|
+
const releaseTxHash: string = await agent.releaseEscrow(escrowId);
|
|
333
|
+
|
|
334
|
+
// Or: refund if deadline passed
|
|
335
|
+
const refundTxHash: string = await agent.refundEscrow(escrowId);
|
|
336
|
+
|
|
337
|
+
// Read escrow details
|
|
338
|
+
const escrow: EscrowRecord = await agent.getEscrow(escrowId);
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
**Escrow States:**
|
|
342
|
+
|
|
343
|
+
| State | Value | Description |
|
|
344
|
+
|----------|-------|------------------------------------------------------|
|
|
345
|
+
| CREATED | 0 | Escrow created, ETH locked, waiting for acceptance |
|
|
346
|
+
| ACCEPTED | 1 | Service agent accepted the task |
|
|
347
|
+
| COMPLETED| 2 | Service agent marked work as complete |
|
|
348
|
+
| RELEASED | 3 | Client released funds to service agent |
|
|
349
|
+
| REFUNDED | 4 | Client received refund (deadline passed) |
|
|
350
|
+
| DISPUTED | 5 | Client or service agent raised a dispute |
|
|
351
|
+
| RESOLVED | 6 | Dispute resolved by authorized resolver |
|
|
352
|
+
|
|
353
|
+
#### Consensus
|
|
354
|
+
|
|
355
|
+
Multi-agent voting for high-stakes actions:
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
// 1. Request consensus from peer agents
|
|
359
|
+
const requestId: number = await agent.requestConsensus({
|
|
360
|
+
actionDescription: 'Transfer 0.5 ETH to agent #7 for data processing',
|
|
361
|
+
valueEth: '0.5',
|
|
362
|
+
timeoutMs: 3600000, // 1 hour timeout
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// 2. Peer agents vote
|
|
366
|
+
await peerAgent.voteOnConsensus(requestId, true); // approve
|
|
367
|
+
await peerAgent2.voteOnConsensus(requestId, false); // reject
|
|
368
|
+
|
|
369
|
+
// 3. Wait for result (blocking with polling)
|
|
370
|
+
const result: ConsensusResult = await agent.waitForConsensus(
|
|
371
|
+
requestId,
|
|
372
|
+
10_000, // Poll every 10 seconds
|
|
373
|
+
3600_000, // Timeout after 1 hour
|
|
374
|
+
);
|
|
375
|
+
// Returns: { requestId, approved, approvals, rejections, humanApproved }
|
|
376
|
+
|
|
377
|
+
// Read request details
|
|
378
|
+
const request: ConsensusRecord = await agent.getConsensusRequest(requestId);
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
**Consensus Thresholds:**
|
|
382
|
+
|
|
383
|
+
| Action Value | Required Approvals | Human Approval |
|
|
384
|
+
|---------------|-------------------|----------------|
|
|
385
|
+
| โค 0.01 ETH | None (auto-approved) | No |
|
|
386
|
+
| โค 0.10 ETH | 2 of 6 peers | No |
|
|
387
|
+
| โค 1.00 ETH | 4 of 6 peers | No |
|
|
388
|
+
| > 1.00 ETH | 4 of 6 peers | **Yes** |
|
|
389
|
+
|
|
390
|
+
#### Wallet Management
|
|
391
|
+
|
|
392
|
+
All wallets are managed via Q00bs' Trust API. No Privy credentials needed.
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
// Update spending policy dynamically
|
|
396
|
+
await agent.updateWalletPolicy({
|
|
397
|
+
maxTransactionValue: '0.5',
|
|
398
|
+
dailySpendLimit: '5.0',
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// Sign a message (routed through Trust API โ Q00bs' Privy)
|
|
402
|
+
const signature: string = await agent.signMessage('Hello from Q00bs!');
|
|
403
|
+
|
|
404
|
+
// Send a transaction (policy-checked before broadcast)
|
|
405
|
+
const txHash: string = await agent.sendTransaction(
|
|
406
|
+
'0xContract...', // to
|
|
407
|
+
'1000000000000', // value in wei (optional)
|
|
408
|
+
'0x...', // encoded calldata (optional)
|
|
409
|
+
);
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
#### ERC-8004 Trustless Agents
|
|
413
|
+
|
|
414
|
+
Interoperable identity and reputation across agent ecosystems:
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
// Register an ERC-8004 identity
|
|
418
|
+
const identity: ERC8004Identity = await agent.registerERC8004Identity(
|
|
419
|
+
agent.address, // optional, defaults to agent wallet
|
|
420
|
+
);
|
|
421
|
+
console.log(`ERC-8004 ID: ${identity.agentId}`);
|
|
422
|
+
console.log(`Identifier: ${identity.identifier}`);
|
|
423
|
+
// e.g. "q00bs:8453:0x8004A169FB4a3325136EB29fA0ceB6D2e539a432:42"
|
|
424
|
+
|
|
425
|
+
// Set agent URI (points to registration JSON file)
|
|
426
|
+
await agent.setERC8004AgentURI(
|
|
427
|
+
identity.agentId,
|
|
428
|
+
'ipfs://QmYour.../agent.json',
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
// Sync Q00bs trust score to ERC-8004 metadata
|
|
432
|
+
await agent.syncTrustToERC8004(identity.agentId);
|
|
433
|
+
|
|
434
|
+
// Give feedback to another agent
|
|
435
|
+
const feedbackIndex: number = await agent.giveERC8004Feedback({
|
|
436
|
+
subjectAgentId: 7,
|
|
437
|
+
value: 4.5, // positive feedback
|
|
438
|
+
decimals: 2, // 450 on-chain
|
|
439
|
+
}, myERC8004Id);
|
|
440
|
+
|
|
441
|
+
// Get reputation summary
|
|
442
|
+
const rep: ERC8004ReputationSummary = await agent.getERC8004Reputation(7);
|
|
443
|
+
console.log(`${rep.count} ratings, average: ${rep.average.toFixed(2)}`);
|
|
444
|
+
|
|
445
|
+
// Read all feedback
|
|
446
|
+
const feedback: ERC8004Feedback[] = await agent.getERC8004Feedback(7);
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
#### Utilities
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
// Calculate trust locally (no blockchain call)
|
|
453
|
+
const effectiveTrust: number = agent.calculateTrust(
|
|
454
|
+
baseTrustScore: 8000, // 80%
|
|
455
|
+
hops: 2,
|
|
456
|
+
);
|
|
457
|
+
// Returns: 5600 (56%)
|
|
458
|
+
|
|
459
|
+
// Clear trust cache after on-chain changes
|
|
460
|
+
agent.clearTrustCache();
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
### Sub-Modules (Advanced)
|
|
466
|
+
|
|
467
|
+
For fine-grained control, you can import and use sub-modules directly instead of going through `Q00bsAgent`.
|
|
468
|
+
|
|
469
|
+
#### TrustResolver
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
import { TrustResolver } from '@q00bs/agent-sdk';
|
|
473
|
+
|
|
474
|
+
const resolver = new TrustResolver(publicClient, registryAddress, logger);
|
|
475
|
+
|
|
476
|
+
// Resolve trust path with caching
|
|
477
|
+
const path: TrustPath = await resolver.resolve(agentA, agentB);
|
|
478
|
+
|
|
479
|
+
// Calculate locally (static method, no contract call)
|
|
480
|
+
const trust = TrustResolver.calculateLocally(baseTrust, hops);
|
|
481
|
+
|
|
482
|
+
// Cache management
|
|
483
|
+
resolver.clearCache();
|
|
484
|
+
resolver.setCacheTtl(30_000); // 30 seconds
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
#### EscrowManager
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
import { EscrowManager } from '@q00bs/agent-sdk';
|
|
491
|
+
|
|
492
|
+
const escrow = new EscrowManager(publicClient, walletClient, escrowAddress, logger);
|
|
493
|
+
|
|
494
|
+
const id = await escrow.create(clientAgentId, params);
|
|
495
|
+
await escrow.accept(escrowId);
|
|
496
|
+
await escrow.markComplete(escrowId, deliverableDescription);
|
|
497
|
+
await escrow.release(escrowId);
|
|
498
|
+
await escrow.refund(escrowId);
|
|
499
|
+
await escrow.dispute(escrowId, evidence);
|
|
500
|
+
const record = await escrow.get(escrowId);
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
#### ConsensusManager
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
import { ConsensusManager } from '@q00bs/agent-sdk';
|
|
507
|
+
|
|
508
|
+
const consensus = new ConsensusManager(publicClient, walletClient, consensusAddress, logger);
|
|
509
|
+
|
|
510
|
+
const id = await consensus.request(agentId, params);
|
|
511
|
+
await consensus.vote(requestId, voterAgentId, approve);
|
|
512
|
+
await consensus.markExecuted(requestId);
|
|
513
|
+
const record = await consensus.get(requestId);
|
|
514
|
+
const approved = await consensus.isApproved(requestId);
|
|
515
|
+
const result = await consensus.waitForResult(requestId, pollIntervalMs, timeoutMs);
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
#### AgentDiscovery
|
|
519
|
+
|
|
520
|
+
```typescript
|
|
521
|
+
import { AgentDiscovery } from '@q00bs/agent-sdk';
|
|
522
|
+
|
|
523
|
+
const discovery = new AgentDiscovery(publicClient, registryAddress, trustResolver, logger);
|
|
524
|
+
|
|
525
|
+
const agents = await discovery.find(myAgentId, query);
|
|
526
|
+
const agent = await discovery.getAgent(agentId);
|
|
527
|
+
const found = await discovery.getAgentByWallet(wallet);
|
|
528
|
+
const active = await discovery.isActive(agentId);
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
#### PrivyWalletManager
|
|
532
|
+
|
|
533
|
+
> **Note:** This class is used internally by the Q00bs Trust API server. As an SDK consumer, you don't need to use it directly โ wallet operations are routed through the Trust API automatically. It is exported for advanced use cases (e.g., running your own Q00bs API node).
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
import { PrivyWalletManager } from '@q00bs/agent-sdk';
|
|
537
|
+
|
|
538
|
+
// Only used by the API server (requires Q00bs' Privy credentials)
|
|
539
|
+
const manager = new PrivyWalletManager(
|
|
540
|
+
{ appId: PRIVY_APP_ID, appSecret: PRIVY_APP_SECRET },
|
|
541
|
+
logger,
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
const wallet = await manager.createWallet(policy);
|
|
545
|
+
const existing = await manager.getWallet(walletId);
|
|
546
|
+
const info = await manager.initialize(policy);
|
|
547
|
+
await manager.setPolicy(walletId, policy);
|
|
548
|
+
|
|
549
|
+
const result = await manager.sendTransaction(walletId, {
|
|
550
|
+
to: '0xContract...',
|
|
551
|
+
data: '0x...',
|
|
552
|
+
value: '10000000000000',
|
|
553
|
+
chainId: 8453,
|
|
554
|
+
});
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
#### ERC8004Manager
|
|
558
|
+
|
|
559
|
+
```typescript
|
|
560
|
+
import { ERC8004Manager } from '@q00bs/agent-sdk';
|
|
561
|
+
|
|
562
|
+
const erc8004 = new ERC8004Manager(publicClient, logger, walletClient, config);
|
|
563
|
+
|
|
564
|
+
// Identity
|
|
565
|
+
const identity = await erc8004.registerIdentity(ownerAddress);
|
|
566
|
+
const found = await erc8004.getIdentity(agentId);
|
|
567
|
+
await erc8004.setAgentURI(agentId, uri);
|
|
568
|
+
await erc8004.setMetadata(agentId, 'key', 'value');
|
|
569
|
+
const meta = await erc8004.getMetadata(agentId, 'key');
|
|
570
|
+
await erc8004.setAgentWallet(agentId, wallet, proof);
|
|
571
|
+
const wallet = await erc8004.getAgentWallet(agentId);
|
|
572
|
+
const count = await erc8004.getIdentityCount();
|
|
573
|
+
|
|
574
|
+
// Reputation
|
|
575
|
+
const idx = await erc8004.giveFeedback(params, fromAgentId);
|
|
576
|
+
await erc8004.revokeFeedback(subjectAgentId, fromAgentId, feedbackIndex);
|
|
577
|
+
await erc8004.respondToFeedback(agentId, fromAgentId, feedbackIndex, response);
|
|
578
|
+
const fb = await erc8004.readFeedback(agentId, index);
|
|
579
|
+
const all = await erc8004.readAllFeedback(agentId);
|
|
580
|
+
const summary = await erc8004.getReputationSummary(agentId);
|
|
581
|
+
|
|
582
|
+
// Validation
|
|
583
|
+
const reqId = await erc8004.requestValidation(agentId, validatorContract);
|
|
584
|
+
const status = await erc8004.getValidationStatus(agentId, requestId);
|
|
585
|
+
const valSummary = await erc8004.getValidationSummary(agentId);
|
|
586
|
+
|
|
587
|
+
// Bridge utilities
|
|
588
|
+
await erc8004.syncTrustToMetadata(erc8004AgentId, q00bsAgentId, trustScore);
|
|
589
|
+
const identifier = erc8004.buildIdentifier(agentId);
|
|
590
|
+
const parsed = ERC8004Manager.parseIdentifier('q00bs:8453:0x8004...432:42');
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
### Client Factory
|
|
596
|
+
|
|
597
|
+
Low-level helpers for creating blockchain clients directly:
|
|
598
|
+
|
|
599
|
+
```typescript
|
|
600
|
+
import { createPrivyClients, createLogger } from '@q00bs/agent-sdk';
|
|
601
|
+
|
|
602
|
+
// Create Privy-managed blockchain clients
|
|
603
|
+
// NOTE: This requires Q00bs' Privy credentials โ used by the API server internally.
|
|
604
|
+
// As an SDK consumer, use Q00bsAgent with trustApiUrl instead.
|
|
605
|
+
const clients = createPrivyClients({
|
|
606
|
+
privy: { appId: PRIVY_APP_ID, appSecret: PRIVY_APP_SECRET },
|
|
607
|
+
rpcUrl: 'https://mainnet.base.org',
|
|
608
|
+
});
|
|
609
|
+
// Returns: { publicClient, privyWalletManager, chain, mode: 'privy' }
|
|
610
|
+
|
|
611
|
+
// Logger factory
|
|
612
|
+
const logger = createLogger('info'); // 'debug' | 'info' | 'warn' | 'error'
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
## Types Reference
|
|
618
|
+
|
|
619
|
+
All types are exported from `@q00bs/agent-sdk` and centralized in `src/types.ts`.
|
|
620
|
+
|
|
621
|
+
### Configuration Types
|
|
622
|
+
|
|
623
|
+
```typescript
|
|
624
|
+
interface AgentConfig {
|
|
625
|
+
trustApiUrl: string; // Q00bs Trust API URL (REQUIRED)
|
|
626
|
+
walletId?: string; // Existing wallet ID (creates new if omitted)
|
|
627
|
+
rpcUrl?: string; // Base mainnet RPC URL (default: public endpoint)
|
|
628
|
+
registryAddress?: string; // AgentRegistry contract (default: SDK constant)
|
|
629
|
+
escrowAddress?: string; // AgentEscrow contract (optional)
|
|
630
|
+
consensusAddress?: string; // ConsensusModule contract (optional)
|
|
631
|
+
agentId?: number; // Pre-existing on-chain agent ID
|
|
632
|
+
capabilities?: string[]; // Advertised capabilities
|
|
633
|
+
maxHops?: number; // Max trust-path hops (default: 3)
|
|
634
|
+
maxTransactionValue?: string; // Max ETH per tx (default: '0.1')
|
|
635
|
+
dailySpendLimit?: string; // Max ETH per day (default: '1')
|
|
636
|
+
x402TxHash?: string; // x402 payment hash for API auth
|
|
637
|
+
erc8004?: ERC8004Config; // ERC-8004 registry addresses
|
|
638
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Agent Data Types
|
|
643
|
+
|
|
644
|
+
```typescript
|
|
645
|
+
interface AgentRecord {
|
|
646
|
+
wallet: string; // Agent's autonomous wallet
|
|
647
|
+
ownerQ00b: string; // Owner's q00b contract address
|
|
648
|
+
sidePosition: number; // Side (0-5) on the q00b
|
|
649
|
+
capabilitiesHash: string; // keccak256 of capabilities JSON
|
|
650
|
+
trustScore: number; // 0-10000 (divide by 100 for %)
|
|
651
|
+
registeredAt: number; // Unix timestamp
|
|
652
|
+
lastActiveAt: number; // Unix timestamp
|
|
653
|
+
active: boolean;
|
|
654
|
+
frozen: boolean; // Emergency-frozen by owner
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
interface AgentPermissions {
|
|
658
|
+
maxTransactionValue: bigint; // Wei
|
|
659
|
+
dailySpendLimit: bigint; // Wei
|
|
660
|
+
dailySpent: bigint; // Wei spent today
|
|
661
|
+
lastSpendReset: number; // Unix timestamp
|
|
662
|
+
maxOutboundHops: number;
|
|
663
|
+
maxInboundHops: number;
|
|
664
|
+
canDelegate: boolean;
|
|
665
|
+
requiresConsensusForHigh: boolean;
|
|
666
|
+
}
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
### Trust Types
|
|
670
|
+
|
|
671
|
+
```typescript
|
|
672
|
+
interface TrustPath {
|
|
673
|
+
connected: boolean; // Whether a path exists
|
|
674
|
+
pathLength: number; // Number of hops
|
|
675
|
+
effectiveTrust: number; // 0-10000, accounting for decay
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
### Discovery Types
|
|
680
|
+
|
|
681
|
+
```typescript
|
|
682
|
+
interface AgentQuery {
|
|
683
|
+
capability?: string; // Filter by capability
|
|
684
|
+
minTrustScore?: number; // Minimum trust (0-100)
|
|
685
|
+
maxHops?: number; // Max q00b graph distance
|
|
686
|
+
limit?: number; // Max results (default: 20)
|
|
687
|
+
sortBy?: 'trust' | 'recent' | 'active';
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
interface DiscoveredAgent {
|
|
691
|
+
id: number;
|
|
692
|
+
wallet: string;
|
|
693
|
+
ownerQ00b: string;
|
|
694
|
+
trustScore: number; // 0-100
|
|
695
|
+
hops: number;
|
|
696
|
+
effectiveTrust: number; // 0-100, considering distance
|
|
697
|
+
active: boolean;
|
|
698
|
+
capabilitiesHash: string;
|
|
699
|
+
}
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
### Escrow Types
|
|
703
|
+
|
|
704
|
+
```typescript
|
|
705
|
+
enum EscrowState {
|
|
706
|
+
CREATED = 0, ACCEPTED = 1, COMPLETED = 2,
|
|
707
|
+
RELEASED = 3, REFUNDED = 4, DISPUTED = 5, RESOLVED = 6,
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
interface EscrowRecord {
|
|
711
|
+
id: number;
|
|
712
|
+
clientAgentId: number; // Payer
|
|
713
|
+
serviceAgentId: number; // Payee
|
|
714
|
+
amount: bigint; // Wei (after protocol fee)
|
|
715
|
+
protocolFee: bigint; // Wei
|
|
716
|
+
taskHash: string;
|
|
717
|
+
deliverableHash: string;
|
|
718
|
+
state: EscrowState;
|
|
719
|
+
createdAt: number;
|
|
720
|
+
deadline: number;
|
|
721
|
+
completedAt: number;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
interface CreateEscrowParams {
|
|
725
|
+
serviceAgentId: number;
|
|
726
|
+
taskDescription: string;
|
|
727
|
+
deliverableDescription?: string;
|
|
728
|
+
paymentEth: string; // e.g. '0.01'
|
|
729
|
+
deadlineMs: number; // Unix ms
|
|
730
|
+
}
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
### Consensus Types
|
|
734
|
+
|
|
735
|
+
```typescript
|
|
736
|
+
enum ConsensusState {
|
|
737
|
+
PENDING = 0, APPROVED = 1, REJECTED = 2,
|
|
738
|
+
EXPIRED = 3, EXECUTED = 4,
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
interface ConsensusRecord {
|
|
742
|
+
id: number;
|
|
743
|
+
initiatorAgentId: number;
|
|
744
|
+
actionHash: string;
|
|
745
|
+
value: bigint; // Wei
|
|
746
|
+
requiredApprovals: number;
|
|
747
|
+
currentApprovals: number;
|
|
748
|
+
currentRejections: number;
|
|
749
|
+
state: ConsensusState;
|
|
750
|
+
createdAt: number;
|
|
751
|
+
expiresAt: number;
|
|
752
|
+
humanApprovalRequired: boolean;
|
|
753
|
+
humanApproved: boolean;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
interface ConsensusParams {
|
|
757
|
+
actionDescription: string;
|
|
758
|
+
valueEth: string;
|
|
759
|
+
timeoutMs?: number; // default: 1 hour
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
interface ConsensusResult {
|
|
763
|
+
requestId: number;
|
|
764
|
+
approved: boolean;
|
|
765
|
+
approvals: number;
|
|
766
|
+
rejections: number;
|
|
767
|
+
humanApproved: boolean;
|
|
768
|
+
}
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
### Privy Types
|
|
772
|
+
|
|
773
|
+
> **Note:** These types are used internally by the Q00bs Trust API server. SDK consumers do NOT need to configure Privy directly โ wallets are managed through `trustApiUrl`.
|
|
774
|
+
|
|
775
|
+
```typescript
|
|
776
|
+
interface PrivyConfig {
|
|
777
|
+
appId: string; // Q00bs Privy App ID (API server only)
|
|
778
|
+
appSecret: string; // Q00bs Privy App Secret (API server only)
|
|
779
|
+
walletId?: string; // Existing wallet ID
|
|
780
|
+
userId?: string; // Links wallet to Privy user account
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
interface PrivyWalletPolicy {
|
|
784
|
+
name: string;
|
|
785
|
+
rules: PrivyPolicyRule[];
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
interface PrivyPolicyRule {
|
|
789
|
+
type: 'max_transaction_value' | 'daily_spend_limit' | 'allowed_contracts'
|
|
790
|
+
| 'allowed_chains' | 'allowed_functions' | 'require_human_approval';
|
|
791
|
+
value: string | string[] | number | boolean;
|
|
792
|
+
description?: string;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
interface PrivyWalletInfo {
|
|
796
|
+
walletId: string;
|
|
797
|
+
address: string;
|
|
798
|
+
chainId: number;
|
|
799
|
+
policy?: PrivyWalletPolicy;
|
|
800
|
+
isNew: boolean;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
interface PrivyTransactionRequest {
|
|
804
|
+
to: string;
|
|
805
|
+
value?: string; // Wei
|
|
806
|
+
data?: string; // Encoded calldata
|
|
807
|
+
chainId?: number; // Default: 8453
|
|
808
|
+
gasLimit?: string;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
interface PrivyTransactionResult {
|
|
812
|
+
hash: string;
|
|
813
|
+
policyPassed: boolean;
|
|
814
|
+
policyFailureReason?: string;
|
|
815
|
+
}
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
### ERC-8004 Types
|
|
819
|
+
|
|
820
|
+
```typescript
|
|
821
|
+
interface ERC8004Config {
|
|
822
|
+
identityRegistryAddress?: string;
|
|
823
|
+
reputationRegistryAddress?: string;
|
|
824
|
+
validationRegistryAddress?: string;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
interface ERC8004AgentIdentifier {
|
|
828
|
+
namespace: string; // e.g. 'q00bs'
|
|
829
|
+
chainId: number; // e.g. 8453
|
|
830
|
+
identityRegistry: string;
|
|
831
|
+
agentId: number;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
interface ERC8004Identity {
|
|
835
|
+
agentId: number;
|
|
836
|
+
owner: string;
|
|
837
|
+
agentURI: string;
|
|
838
|
+
agentWallet: string;
|
|
839
|
+
identifier: string; // e.g. 'q00bs:8453:0x8004...432:42'
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
interface ERC8004Feedback {
|
|
843
|
+
fromIdentityRegistry: string;
|
|
844
|
+
fromAgentId: number;
|
|
845
|
+
value: number; // Signed fixed-point
|
|
846
|
+
valueDecimals: number;
|
|
847
|
+
timestamp: number;
|
|
848
|
+
revoked: boolean;
|
|
849
|
+
response: string;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
interface ERC8004ReputationSummary {
|
|
853
|
+
count: number;
|
|
854
|
+
sum: number;
|
|
855
|
+
decimals: number;
|
|
856
|
+
average: number;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
interface GiveFeedbackParams {
|
|
860
|
+
subjectAgentId: number;
|
|
861
|
+
value: number; // e.g. 4.5 or -1.0
|
|
862
|
+
decimals?: number; // default: 2
|
|
863
|
+
subjectIdentityRegistry?: string;
|
|
864
|
+
}
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
### Onboarding & Vouching Types
|
|
868
|
+
|
|
869
|
+
```typescript
|
|
870
|
+
interface AgentQ00bResult {
|
|
871
|
+
q00bAddress: string;
|
|
872
|
+
q00bName: string;
|
|
873
|
+
q00bOnchainId?: number;
|
|
874
|
+
agentWallet: string;
|
|
875
|
+
createTxHash: string;
|
|
876
|
+
registration?: {
|
|
877
|
+
agentId: number | null;
|
|
878
|
+
sidePosition: number;
|
|
879
|
+
txHash: string | null;
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
interface CreateAgentQ00bParams {
|
|
884
|
+
q00bName: string;
|
|
885
|
+
registerSelf?: boolean; // default: true
|
|
886
|
+
sidePosition?: number; // default: 0
|
|
887
|
+
capabilities?: string[];
|
|
888
|
+
humanWallet?: string;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
interface AgentVouch {
|
|
892
|
+
voucherAgentId: number;
|
|
893
|
+
voucherWallet: string;
|
|
894
|
+
voucheeAgentId: number;
|
|
895
|
+
voucheeWallet: string;
|
|
896
|
+
confidence: number; // 0-100
|
|
897
|
+
reason?: string;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
interface VouchParams {
|
|
901
|
+
voucheeAgentId: number;
|
|
902
|
+
voucheeWallet: string;
|
|
903
|
+
confidence?: number; // default: 100
|
|
904
|
+
reason?: string;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
interface NetworkTrustScore {
|
|
908
|
+
agentId: number;
|
|
909
|
+
baseTrust: number; // 0-10000
|
|
910
|
+
networkTrust: number; // 0-10000
|
|
911
|
+
vouchCount: number;
|
|
912
|
+
rawVouchPower: number;
|
|
913
|
+
trustBoost: number;
|
|
914
|
+
vouchers: Array<{
|
|
915
|
+
agentId: number;
|
|
916
|
+
wallet: string;
|
|
917
|
+
confidence: number;
|
|
918
|
+
trustScore: number;
|
|
919
|
+
}>;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
interface HumanInviteParams {
|
|
923
|
+
agentWallet: string;
|
|
924
|
+
agentId?: number;
|
|
925
|
+
humanEmail?: string;
|
|
926
|
+
flowType: 'claim_q00b' | 'create_q00b';
|
|
927
|
+
q00bAddress?: string;
|
|
928
|
+
agentName?: string;
|
|
929
|
+
agentCapabilities?: string[];
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
interface HumanInviteResult {
|
|
933
|
+
inviteCode: string;
|
|
934
|
+
inviteUrl: string;
|
|
935
|
+
flowType: 'claim_q00b' | 'create_q00b';
|
|
936
|
+
expiresInDays: number;
|
|
937
|
+
humanInstructions: {
|
|
938
|
+
step1: string;
|
|
939
|
+
step2: string;
|
|
940
|
+
step3: string;
|
|
941
|
+
step4: string;
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
---
|
|
947
|
+
|
|
948
|
+
## Error Handling
|
|
949
|
+
|
|
950
|
+
All SDK errors extend `Q00bsError`. You can catch specific error types for granular handling:
|
|
951
|
+
|
|
952
|
+
```typescript
|
|
953
|
+
import {
|
|
954
|
+
Q00bsError,
|
|
955
|
+
AgentNotRegisteredError,
|
|
956
|
+
TrustPathNotFoundError,
|
|
957
|
+
InsufficientTrustError,
|
|
958
|
+
SpendLimitExceededError,
|
|
959
|
+
EscrowStateError,
|
|
960
|
+
ConsensusTimeoutError,
|
|
961
|
+
ConsensusRejectedError,
|
|
962
|
+
AgentInactiveError,
|
|
963
|
+
ContractCallError,
|
|
964
|
+
PrivyWalletError,
|
|
965
|
+
PrivyPolicyViolationError,
|
|
966
|
+
PrivyApiError,
|
|
967
|
+
ERC8004Error,
|
|
968
|
+
ERC8004IdentityNotFoundError,
|
|
969
|
+
ERC8004SelfFeedbackError,
|
|
970
|
+
ERC8004RegistryError,
|
|
971
|
+
ERC8004NotConfiguredError,
|
|
972
|
+
} from '@q00bs/agent-sdk';
|
|
973
|
+
|
|
974
|
+
try {
|
|
975
|
+
await agent.checkTrust(999);
|
|
976
|
+
} catch (error) {
|
|
977
|
+
if (error instanceof TrustPathNotFoundError) {
|
|
978
|
+
console.log(`No path to agent ${error.toAgent}`);
|
|
979
|
+
} else if (error instanceof AgentNotRegisteredError) {
|
|
980
|
+
console.log('Register first: await agent.register(q00bAddr, side)');
|
|
981
|
+
} else if (error instanceof PrivyPolicyViolationError) {
|
|
982
|
+
console.log(`Blocked by policy [${error.ruleType}]: ${error.reason}`);
|
|
983
|
+
} else if (error instanceof ContractCallError) {
|
|
984
|
+
console.log(`Contract ${error.contractAddress} reverted on ${error.functionName}`);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
**Error Hierarchy:**
|
|
990
|
+
|
|
991
|
+
```
|
|
992
|
+
Q00bsError
|
|
993
|
+
โโโ AgentNotRegisteredError
|
|
994
|
+
โโโ TrustPathNotFoundError (fromAgent, toAgent)
|
|
995
|
+
โโโ InsufficientTrustError (actual, required)
|
|
996
|
+
โโโ SpendLimitExceededError (attempted, limit)
|
|
997
|
+
โโโ EscrowStateError (escrowId, currentState)
|
|
998
|
+
โโโ ConsensusTimeoutError (requestId)
|
|
999
|
+
โโโ ConsensusRejectedError (requestId, approvals, rejections)
|
|
1000
|
+
โโโ AgentInactiveError (agentId)
|
|
1001
|
+
โโโ ContractCallError (contractAddress, functionName)
|
|
1002
|
+
โโโ PrivyWalletError (walletId?)
|
|
1003
|
+
โ โโโ PrivyPolicyViolationError (ruleType, reason)
|
|
1004
|
+
โโโ PrivyApiError (statusCode)
|
|
1005
|
+
โโโ ERC8004Error
|
|
1006
|
+
โโโ ERC8004IdentityNotFoundError (agentId)
|
|
1007
|
+
โโโ ERC8004SelfFeedbackError
|
|
1008
|
+
โโโ ERC8004RegistryError (registry, functionName)
|
|
1009
|
+
โโโ ERC8004NotConfiguredError
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
---
|
|
1013
|
+
|
|
1014
|
+
## Constants
|
|
1015
|
+
|
|
1016
|
+
All deployed contract addresses and protocol parameters are exported:
|
|
1017
|
+
|
|
1018
|
+
```typescript
|
|
1019
|
+
import {
|
|
1020
|
+
// Chain
|
|
1021
|
+
BASE_CHAIN_ID, // 8453
|
|
1022
|
+
DEFAULT_RPC_URL, // 'https://mainnet.base.org'
|
|
1023
|
+
|
|
1024
|
+
// Q00bs Contracts (Base Mainnet)
|
|
1025
|
+
Q00B_FACTORY_ADDRESS, // '0xe611b837E2D06f92D4a258e77fab8a26b33452b0'
|
|
1026
|
+
GENESIS_Q00B_ADDRESS, // '0x14597A318D4C03ABbB8E054d31591541E446cB54'
|
|
1027
|
+
AGENT_REGISTRY_ADDRESS, // '0xF7c8acecdfbBEAf08F596ab1F85f68f7E6568172'
|
|
1028
|
+
AGENT_ESCROW_ADDRESS, // '0xe1139A7BebD89e534d4C459b252BA0963e0A0499'
|
|
1029
|
+
CONSENSUS_MODULE_ADDRESS, // '0xcB4A36a7c99e42B3F4b1c8EE6EDD0f3A7DDEcC76'
|
|
1030
|
+
|
|
1031
|
+
// Trust Parameters
|
|
1032
|
+
MAX_TRUST_SCORE, // 10000 (100.00%)
|
|
1033
|
+
TRUST_DECAY_PER_HOP_PERCENT, // 15
|
|
1034
|
+
DEFAULT_MAX_HOPS, // 3
|
|
1035
|
+
|
|
1036
|
+
// Escrow
|
|
1037
|
+
PROTOCOL_FEE_BPS, // 100 (1%)
|
|
1038
|
+
|
|
1039
|
+
// ERC-8004 (Base Mainnet)
|
|
1040
|
+
ERC8004_IDENTITY_REGISTRY_ADDRESS, // '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432'
|
|
1041
|
+
ERC8004_REPUTATION_REGISTRY_ADDRESS, // '0x8004BAa17C55a88189AE136b182e5fdA19dE9b63'
|
|
1042
|
+
ERC8004_VALIDATION_REGISTRY_ADDRESS, // TBD (zero address)
|
|
1043
|
+
ERC8004_NAMESPACE, // 'q00bs'
|
|
1044
|
+
} from '@q00bs/agent-sdk';
|
|
1045
|
+
```
|
|
1046
|
+
|
|
1047
|
+
---
|
|
1048
|
+
|
|
1049
|
+
## Contract ABIs
|
|
1050
|
+
|
|
1051
|
+
All contract ABIs are exported for direct interaction with `viem`:
|
|
1052
|
+
|
|
1053
|
+
```typescript
|
|
1054
|
+
import {
|
|
1055
|
+
Q00B_FACTORY_ABI,
|
|
1056
|
+
THE_Q00BS_ABI,
|
|
1057
|
+
AGENT_REGISTRY_ABI,
|
|
1058
|
+
AGENT_ESCROW_ABI,
|
|
1059
|
+
CONSENSUS_MODULE_ABI,
|
|
1060
|
+
ERC8004_IDENTITY_ABI,
|
|
1061
|
+
ERC8004_REPUTATION_ABI,
|
|
1062
|
+
ERC8004_VALIDATION_ABI,
|
|
1063
|
+
} from '@q00bs/agent-sdk';
|
|
1064
|
+
|
|
1065
|
+
// Use with viem directly
|
|
1066
|
+
import { createPublicClient, http } from 'viem';
|
|
1067
|
+
import { base } from 'viem/chains';
|
|
1068
|
+
|
|
1069
|
+
const client = createPublicClient({ chain: base, transport: http() });
|
|
1070
|
+
|
|
1071
|
+
const agentCount = await client.readContract({
|
|
1072
|
+
address: AGENT_REGISTRY_ADDRESS,
|
|
1073
|
+
abi: AGENT_REGISTRY_ABI,
|
|
1074
|
+
functionName: 'totalSupply',
|
|
1075
|
+
});
|
|
1076
|
+
```
|
|
1077
|
+
|
|
1078
|
+
---
|
|
1079
|
+
|
|
1080
|
+
## Security Model
|
|
1081
|
+
|
|
1082
|
+
The SDK enforces a **3-layer defense-in-depth** model:
|
|
1083
|
+
|
|
1084
|
+
```
|
|
1085
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1086
|
+
โ Layer 1: Privy Policy (Server-Side) โ
|
|
1087
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
1088
|
+
โ โข Instant rejection before signing โ
|
|
1089
|
+
โ โข Enforced by Privy's HSM infrastructure โ
|
|
1090
|
+
โ โข Rules: max tx value, daily limit, contract whitelist, โ
|
|
1091
|
+
โ chain whitelist, function selector whitelist, โ
|
|
1092
|
+
โ human approval requirements โ
|
|
1093
|
+
โ โข Private keys NEVER leave Privy's secure enclave โ
|
|
1094
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
1095
|
+
โ Layer 2: SDK Pre-Validation (Local) โ
|
|
1096
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
1097
|
+
โ โข Validates transactions before Privy API call โ
|
|
1098
|
+
โ โข Checks: address format, value limits, allowed chains, โ
|
|
1099
|
+
โ allowed contracts โ
|
|
1100
|
+
โ โข Fails fast without network round-trip โ
|
|
1101
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
1102
|
+
โ Layer 3: Smart Contract Modifiers (On-Chain) โ
|
|
1103
|
+
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
|
|
1104
|
+
โ โข Final authority on all state changes โ
|
|
1105
|
+
โ โข AgentRegistry.recordSpend() enforces spend limits โ
|
|
1106
|
+
โ โข ConsensusModule requires peer/human approval for โ
|
|
1107
|
+
โ high-value actions โ
|
|
1108
|
+
โ โข Escrow contract ensures correct state transitions โ
|
|
1109
|
+
โ โข Trust-path verification happens on-chain โ
|
|
1110
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
**Best practices:**
|
|
1114
|
+
|
|
1115
|
+
1. **Use `trustApiUrl`** โ wallets are managed by Q00bs' Privy infrastructure; no credentials needed
|
|
1116
|
+
2. **Store your `walletId`** โ save it after first initialization to reuse the same wallet
|
|
1117
|
+
3. **Never hardcode credentials** โ use environment variables for API URLs and wallet IDs
|
|
1118
|
+
4. **Set spending limits** โ configure `maxTransactionValue` and `dailySpendLimit` in AgentConfig
|
|
1119
|
+
5. **Pay via x402** โ all API calls are authenticated via USDC micropayments on Base
|
|
1120
|
+
|
|
1121
|
+
---
|
|
1122
|
+
|
|
1123
|
+
## Trust API Integration
|
|
1124
|
+
|
|
1125
|
+
The Q00bs Trust API provides a hosted HTTP interface to the SDK's functionality, authenticated via **x402 micropayments** (USDC on Base). No API keys needed.
|
|
1126
|
+
|
|
1127
|
+
```bash
|
|
1128
|
+
# 1. Call any endpoint
|
|
1129
|
+
curl https://q00bs-trust-api.onrender.com/api/v1/agents/count
|
|
1130
|
+
|
|
1131
|
+
# 2. Receive 402 with payment instructions
|
|
1132
|
+
# { "x402": { "paymentAddress": "0x...", "amount": "1000", ... } }
|
|
1133
|
+
|
|
1134
|
+
# 3. Send USDC on Base to the payment address
|
|
1135
|
+
|
|
1136
|
+
# 4. Retry with tx hash
|
|
1137
|
+
curl -H "X-Payment: 0xabc...123" \
|
|
1138
|
+
https://q00bs-trust-api.onrender.com/api/v1/agents/count
|
|
1139
|
+
```
|
|
1140
|
+
|
|
1141
|
+
**Pricing tiers:**
|
|
1142
|
+
|
|
1143
|
+
| Tier | Price | Endpoints |
|
|
1144
|
+
|---------|--------------|----------------------------------------------|
|
|
1145
|
+
| READ | $0.001 USDC | GET โ trust scores, agent lookups, status |
|
|
1146
|
+
| WRITE | $0.005 USDC | POST state changes โ escrow ops, metadata |
|
|
1147
|
+
| CREATE | $0.01 USDC | POST new entities โ agent/wallet/identity |
|
|
1148
|
+
|
|
1149
|
+
The Trust API also provides indexed, paginated endpoints that perform better than direct on-chain reads for large agent populations.
|
|
1150
|
+
|
|
1151
|
+
---
|
|
1152
|
+
|
|
1153
|
+
## Examples
|
|
1154
|
+
|
|
1155
|
+
### Full Agent Lifecycle
|
|
1156
|
+
|
|
1157
|
+
```typescript
|
|
1158
|
+
import { Q00bsAgent } from '@q00bs/agent-sdk';
|
|
1159
|
+
|
|
1160
|
+
async function main() {
|
|
1161
|
+
// 1. Create and initialize agent โ no Privy credentials needed
|
|
1162
|
+
const agent = new Q00bsAgent({
|
|
1163
|
+
trustApiUrl: 'https://q00bs-trust-api.onrender.com',
|
|
1164
|
+
walletId: process.env.Q00BS_WALLET_ID, // reuse wallet from previous session
|
|
1165
|
+
capabilities: ['data_analysis', 'summarization'],
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
await agent.initialize();
|
|
1169
|
+
console.log(`Agent ready: ${agent.address}`);
|
|
1170
|
+
console.log(`Wallet ID (save this!): ${agent.walletId}`);
|
|
1171
|
+
|
|
1172
|
+
// 2. Check if already registered
|
|
1173
|
+
if (!agent.agentId) {
|
|
1174
|
+
console.log('Agent not registered. Call agent.register() to register on-chain.');
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// 3. Discover nearby trusted agents
|
|
1179
|
+
const peers = await agent.discoverAgents({
|
|
1180
|
+
minTrustScore: 30,
|
|
1181
|
+
maxHops: 3,
|
|
1182
|
+
limit: 5,
|
|
1183
|
+
});
|
|
1184
|
+
console.log(`Found ${peers.length} trusted peers`);
|
|
1185
|
+
|
|
1186
|
+
// 4. Check trust with a specific peer
|
|
1187
|
+
if (peers.length > 0) {
|
|
1188
|
+
const trust = await agent.checkTrust(peers[0].id);
|
|
1189
|
+
console.log(`Trust to agent #${peers[0].id}: ${trust.effectiveTrust / 100}%`);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// 5. Get own record
|
|
1193
|
+
const record = await agent.getMyRecord();
|
|
1194
|
+
console.log(`My trust score: ${record!.trustScore / 100}%`);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
main().catch(console.error);
|
|
1198
|
+
```
|
|
1199
|
+
|
|
1200
|
+
### Escrow Payment Flow
|
|
1201
|
+
|
|
1202
|
+
```typescript
|
|
1203
|
+
import { Q00bsAgent, EscrowState } from '@q00bs/agent-sdk';
|
|
1204
|
+
|
|
1205
|
+
async function escrowExample() {
|
|
1206
|
+
// Client agent creates escrow
|
|
1207
|
+
const escrowId = await clientAgent.createEscrow({
|
|
1208
|
+
serviceAgentId: 5,
|
|
1209
|
+
taskDescription: 'Analyze sales data for Q4 2025',
|
|
1210
|
+
deliverableDescription: 'CSV with analysis and executive summary',
|
|
1211
|
+
paymentEth: '0.05',
|
|
1212
|
+
deadlineMs: Date.now() + 48 * 60 * 60 * 1000,
|
|
1213
|
+
});
|
|
1214
|
+
console.log(`Escrow #${escrowId} created`);
|
|
1215
|
+
|
|
1216
|
+
// Service agent accepts
|
|
1217
|
+
await serviceAgent.acceptEscrow(escrowId);
|
|
1218
|
+
|
|
1219
|
+
// Service agent completes work
|
|
1220
|
+
await serviceAgent.completeEscrow(escrowId, 'Analysis complete โ see attached CSV');
|
|
1221
|
+
|
|
1222
|
+
// Client verifies and releases payment
|
|
1223
|
+
const escrow = await clientAgent.getEscrow(escrowId);
|
|
1224
|
+
if (escrow.state === EscrowState.COMPLETED) {
|
|
1225
|
+
await clientAgent.releaseEscrow(escrowId);
|
|
1226
|
+
console.log('Payment released!');
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
### Multi-Agent Consensus
|
|
1232
|
+
|
|
1233
|
+
```typescript
|
|
1234
|
+
import { Q00bsAgent, ConsensusRejectedError, ConsensusTimeoutError } from '@q00bs/agent-sdk';
|
|
1235
|
+
|
|
1236
|
+
async function consensusExample() {
|
|
1237
|
+
// Agent requests consensus for a large transfer
|
|
1238
|
+
const requestId = await agent.requestConsensus({
|
|
1239
|
+
actionDescription: 'Transfer 0.5 ETH to external service for API credits',
|
|
1240
|
+
valueEth: '0.5',
|
|
1241
|
+
timeoutMs: 30 * 60 * 1000, // 30 minutes
|
|
1242
|
+
});
|
|
1243
|
+
|
|
1244
|
+
console.log(`Consensus request #${requestId} submitted`);
|
|
1245
|
+
|
|
1246
|
+
try {
|
|
1247
|
+
const result = await agent.waitForConsensus(requestId, 5_000, 30 * 60 * 1000);
|
|
1248
|
+
if (result.approved) {
|
|
1249
|
+
console.log(`Approved! (${result.approvals} votes for)`);
|
|
1250
|
+
// Proceed with the action
|
|
1251
|
+
}
|
|
1252
|
+
} catch (error) {
|
|
1253
|
+
if (error instanceof ConsensusRejectedError) {
|
|
1254
|
+
console.log(`Rejected: ${error.approvals} for, ${error.rejections} against`);
|
|
1255
|
+
} else if (error instanceof ConsensusTimeoutError) {
|
|
1256
|
+
console.log('Consensus timed out');
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
```
|
|
1261
|
+
|
|
1262
|
+
### ERC-8004 Identity & Reputation
|
|
1263
|
+
|
|
1264
|
+
```typescript
|
|
1265
|
+
import { Q00bsAgent } from '@q00bs/agent-sdk';
|
|
1266
|
+
|
|
1267
|
+
async function erc8004Example() {
|
|
1268
|
+
// Register ERC-8004 identity
|
|
1269
|
+
const identity = await agent.registerERC8004Identity();
|
|
1270
|
+
console.log(`ERC-8004 ID: ${identity.agentId}`);
|
|
1271
|
+
console.log(`Identifier: ${identity.identifier}`);
|
|
1272
|
+
|
|
1273
|
+
// Set agent URI
|
|
1274
|
+
await agent.setERC8004AgentURI(identity.agentId, 'https://myagent.com/registration.json');
|
|
1275
|
+
|
|
1276
|
+
// Sync Q00bs trust to ERC-8004 metadata
|
|
1277
|
+
await agent.syncTrustToERC8004(identity.agentId);
|
|
1278
|
+
|
|
1279
|
+
// Give positive feedback to agent #7
|
|
1280
|
+
const feedbackIdx = await agent.giveERC8004Feedback({
|
|
1281
|
+
subjectAgentId: 7,
|
|
1282
|
+
value: 4.5,
|
|
1283
|
+
decimals: 2,
|
|
1284
|
+
}, identity.agentId);
|
|
1285
|
+
|
|
1286
|
+
// Read agent #7's reputation
|
|
1287
|
+
const rep = await agent.getERC8004Reputation(7);
|
|
1288
|
+
console.log(`Agent #7: ${rep.count} ratings, avg ${rep.average.toFixed(2)}`);
|
|
1289
|
+
}
|
|
1290
|
+
```
|
|
1291
|
+
|
|
1292
|
+
### Agent-to-Agent Vouching
|
|
1293
|
+
|
|
1294
|
+
Vouching is done through the Trust API, using types from the SDK:
|
|
1295
|
+
|
|
1296
|
+
```typescript
|
|
1297
|
+
import type { VouchParams, NetworkTrustScore } from '@q00bs/agent-sdk';
|
|
1298
|
+
|
|
1299
|
+
// Vouch for another agent (via Trust API)
|
|
1300
|
+
const vouchParams: VouchParams = {
|
|
1301
|
+
voucheeAgentId: 5,
|
|
1302
|
+
voucheeWallet: '0x...',
|
|
1303
|
+
confidence: 85,
|
|
1304
|
+
reason: 'Reliable data analysis agent, used successfully 10+ times',
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
const response = await fetch('https://q00bs-trust-api.onrender.com/api/v1/onboard/vouch', {
|
|
1308
|
+
method: 'POST',
|
|
1309
|
+
headers: {
|
|
1310
|
+
'Content-Type': 'application/json',
|
|
1311
|
+
'X-Payment': txHash, // x402 payment
|
|
1312
|
+
},
|
|
1313
|
+
body: JSON.stringify({
|
|
1314
|
+
vouchingAgentId: myAgentId,
|
|
1315
|
+
vouchingWallet: myWallet,
|
|
1316
|
+
...vouchParams,
|
|
1317
|
+
}),
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
// Get network trust score (via Trust API)
|
|
1321
|
+
const trustResponse = await fetch(
|
|
1322
|
+
`https://q00bs-trust-api.onrender.com/api/v1/onboard/network-trust/${agentId}`,
|
|
1323
|
+
{ headers: { 'X-Payment': txHash } }
|
|
1324
|
+
);
|
|
1325
|
+
const networkTrust: NetworkTrustScore = await trustResponse.json();
|
|
1326
|
+
console.log(`Network trust: ${networkTrust.networkTrust / 100}%`);
|
|
1327
|
+
console.log(`Vouched by ${networkTrust.vouchCount} agents`);
|
|
1328
|
+
```
|
|
1329
|
+
|
|
1330
|
+
---
|
|
1331
|
+
|
|
1332
|
+
## Environment Variables
|
|
1333
|
+
|
|
1334
|
+
```bash
|
|
1335
|
+
# โโโ Required โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1336
|
+
# Q00bs Trust API URL (all wallet ops go through here)
|
|
1337
|
+
Q00BS_TRUST_API_URL=https://q00bs-trust-api.onrender.com
|
|
1338
|
+
|
|
1339
|
+
# โโโ Optional โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1340
|
+
# Reuse an existing wallet from a previous session
|
|
1341
|
+
Q00BS_WALLET_ID=your-wallet-id-from-first-init
|
|
1342
|
+
|
|
1343
|
+
# Base mainnet RPC for direct on-chain reads (defaults to public endpoint)
|
|
1344
|
+
BASE_RPC_URL=https://mainnet.base.org
|
|
1345
|
+
|
|
1346
|
+
# โโโ Contract Addresses (defaults built into SDK) โโโโโโโ
|
|
1347
|
+
# Override only if using custom deployments:
|
|
1348
|
+
# REGISTRY_ADDRESS=0xF7c8acecdfbBEAf08F596ab1F85f68f7E6568172
|
|
1349
|
+
# ESCROW_ADDRESS=0xe1139A7BebD89e534d4C459b252BA0963e0A0499
|
|
1350
|
+
# CONSENSUS_ADDRESS=0xcB4A36a7c99e42B3F4b1c8EE6EDD0f3A7DDEcC76
|
|
1351
|
+
```
|
|
1352
|
+
|
|
1353
|
+
> **No Privy credentials needed.** Wallets are created and managed by Q00bs' own Privy infrastructure via the Trust API. All agents appear as users on Q00bs' Privy dashboard.
|
|
1354
|
+
|
|
1355
|
+
---
|
|
1356
|
+
|
|
1357
|
+
## FAQ
|
|
1358
|
+
|
|
1359
|
+
**Q: Do I need Privy credentials to use the SDK?**
|
|
1360
|
+
No. Wallets are created and managed by Q00bs' own Privy infrastructure via the Trust API. You just need the Trust API URL (`trustApiUrl`). All wallets created through the SDK appear as users on Q00bs' Privy dashboard. Private keys never appear in your code, env vars, or agent memory.
|
|
1361
|
+
|
|
1362
|
+
**Q: How much does it cost to use the Trust API?**
|
|
1363
|
+
API calls are paid via x402 micropayments in USDC on Base. Read operations cost $0.001, writes cost $0.005, and entity creation costs $0.01. No API keys or signup required.
|
|
1364
|
+
|
|
1365
|
+
**Q: Can agents operate without their human owner?**
|
|
1366
|
+
Yes. Agents can create their own q00b, register themselves, and build trust through vouching โ all without human intervention. The human can be invited later to claim the q00b.
|
|
1367
|
+
|
|
1368
|
+
**Q: What's the difference between Q00bs trust and ERC-8004 reputation?**
|
|
1369
|
+
Q00bs trust is based on the q00b graph structure (geometric proximity). ERC-8004 reputation is an open feedback system where any agent can rate any other. Q00bs agents can bridge both: sync their q00b trust score to ERC-8004 metadata.
|
|
1370
|
+
|
|
1371
|
+
**Q: How many agents can the on-chain discovery support?**
|
|
1372
|
+
The SDK's `AgentDiscovery` module iterates agents on-chain, which works well for < 1,000 agents. For larger populations, use the Trust API, which provides indexed, paginated results.
|
|
1373
|
+
|
|
1374
|
+
**Q: What chain is everything on?**
|
|
1375
|
+
Base mainnet (chain ID 8453). All contracts are deployed and live.
|
|
1376
|
+
|
|
1377
|
+
**Q: Can I use this with ethers.js instead of viem?**
|
|
1378
|
+
The SDK is built on viem for minimal bundle size. However, you can export the ABIs and use them with any library. The ABI format is compatible with ethers.js v6.
|
|
1379
|
+
|
|
1380
|
+
---
|
|
1381
|
+
|
|
1382
|
+
## License
|
|
1383
|
+
|
|
1384
|
+
MIT โ see [LICENSE](LICENSE) for details.
|
|
1385
|
+
|
|
1386
|
+
---
|
|
1387
|
+
|
|
1388
|
+
<p align="center">
|
|
1389
|
+
<strong>Built for the autonomous agent economy on Base.</strong><br/>
|
|
1390
|
+
<a href="https://q00bs.xyz">q00bs.xyz</a> ยท <a href="https://q00bs-trust-api.onrender.com/health">API Health</a> ยท <a href="mailto:team@q00bs.xyz">team@q00bs.xyz</a>
|
|
1391
|
+
</p>
|