@t402/erc8004 2.7.0 → 2.7.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/README.md +208 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# @t402/erc8004
|
|
2
|
+
|
|
3
|
+
ERC-8004 Trustless Agents integration for the t402 payment protocol.
|
|
4
|
+
|
|
5
|
+
Enables AI agent identity resolution, reputation scoring, and validation registry integration for T402 payments.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @t402/erc8004 @t402/core
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @t402/erc8004 @t402/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Optional peer dependency for on-chain interactions:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install viem
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
[ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) defines a standard for trustless AI agent identity on Ethereum. This package integrates ERC-8004 with the T402 payment protocol, enabling:
|
|
24
|
+
|
|
25
|
+
- **Identity Resolution** — resolve agent addresses to on-chain identities via the Identity Registry
|
|
26
|
+
- **Reputation Scoring** — query and submit feedback for agents via the Reputation Registry
|
|
27
|
+
- **Validation Registry** — submit and check validation requests for agent transactions
|
|
28
|
+
- **Payment Extensions** — declare and verify ERC-8004 identity in T402 payment flows
|
|
29
|
+
- **Server/Client Hooks** — pre-built hooks for identity checks, reputation gating, and feedback submission
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { resolveAgent, getReputationSummary } from '@t402/erc8004'
|
|
35
|
+
|
|
36
|
+
// Resolve an agent's on-chain identity
|
|
37
|
+
const agent = await resolveAgent(client, '0x1234...abcd')
|
|
38
|
+
console.log(agent.identity.name, agent.reputation.score)
|
|
39
|
+
|
|
40
|
+
// Check reputation before accepting payment
|
|
41
|
+
const reputation = await getReputationSummary(client, '0x1234...abcd')
|
|
42
|
+
if (reputation.score < 50) {
|
|
43
|
+
throw new Error('Agent reputation too low')
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Identity Resolution
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import {
|
|
51
|
+
getAgentIdentity,
|
|
52
|
+
fetchRegistrationFile,
|
|
53
|
+
resolveAgent,
|
|
54
|
+
verifyPayToMatchesAgent,
|
|
55
|
+
parseAgentRegistry,
|
|
56
|
+
} from '@t402/erc8004'
|
|
57
|
+
|
|
58
|
+
// Get on-chain identity from the Identity Registry
|
|
59
|
+
const identity = await getAgentIdentity(client, agentAddress)
|
|
60
|
+
|
|
61
|
+
// Fetch off-chain registration file (linked from on-chain record)
|
|
62
|
+
const registration = await fetchRegistrationFile(identity.registrationUrl)
|
|
63
|
+
|
|
64
|
+
// Full resolution: identity + registration + reputation
|
|
65
|
+
const resolved = await resolveAgent(client, agentAddress)
|
|
66
|
+
|
|
67
|
+
// Verify that a payTo address belongs to a registered agent
|
|
68
|
+
const isValid = await verifyPayToMatchesAgent(client, payToAddress, agentAddress)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Reputation
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import {
|
|
75
|
+
getReputationSummary,
|
|
76
|
+
buildFeedbackFile,
|
|
77
|
+
submitFeedback,
|
|
78
|
+
} from '@t402/erc8004'
|
|
79
|
+
|
|
80
|
+
// Query agent reputation
|
|
81
|
+
const summary = await getReputationSummary(client, agentAddress)
|
|
82
|
+
// summary.score, summary.totalFeedback, summary.positiveRatio
|
|
83
|
+
|
|
84
|
+
// Submit feedback after a payment
|
|
85
|
+
const feedbackFile = buildFeedbackFile({
|
|
86
|
+
agent: agentAddress,
|
|
87
|
+
tag: 'positive',
|
|
88
|
+
comment: 'Fast and reliable service',
|
|
89
|
+
proofOfPayment: { txHash, network, amount },
|
|
90
|
+
})
|
|
91
|
+
await submitFeedback(client, feedbackFile)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Validation
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import {
|
|
98
|
+
submitValidationRequest,
|
|
99
|
+
getValidationStatus,
|
|
100
|
+
getValidationSummary,
|
|
101
|
+
} from '@t402/erc8004'
|
|
102
|
+
|
|
103
|
+
// Submit a validation request for an agent transaction
|
|
104
|
+
await submitValidationRequest(client, {
|
|
105
|
+
agent: agentAddress,
|
|
106
|
+
txHash: '0xabc...',
|
|
107
|
+
network: 'eip155:8453',
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
// Check validation status
|
|
111
|
+
const status = await getValidationStatus(client, requestId)
|
|
112
|
+
|
|
113
|
+
// Get full validation summary for an agent
|
|
114
|
+
const summary = await getValidationSummary(client, agentAddress)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Extension Integration
|
|
118
|
+
|
|
119
|
+
Use ERC-8004 as a T402 payment extension to declare and verify agent identity in payment flows:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import {
|
|
123
|
+
declareERC8004Extension,
|
|
124
|
+
getERC8004Extension,
|
|
125
|
+
createERC8004PayloadExtension,
|
|
126
|
+
verifyAgentIdentity,
|
|
127
|
+
erc8004ResourceServerExtension,
|
|
128
|
+
} from '@t402/erc8004'
|
|
129
|
+
|
|
130
|
+
// Server: declare ERC-8004 support in PaymentRequirements
|
|
131
|
+
const requirements = declareERC8004Extension(baseRequirements, {
|
|
132
|
+
identityRegistry: '0x...',
|
|
133
|
+
reputationRegistry: '0x...',
|
|
134
|
+
requiredScore: 50,
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
// Client: extract extension from requirements
|
|
138
|
+
const ext = getERC8004Extension(requirements)
|
|
139
|
+
|
|
140
|
+
// Client: create payload extension with identity proof
|
|
141
|
+
const payloadExt = await createERC8004PayloadExtension(client, agentAddress)
|
|
142
|
+
|
|
143
|
+
// Server: verify agent identity from payment payload
|
|
144
|
+
const verified = await verifyAgentIdentity(client, payload)
|
|
145
|
+
|
|
146
|
+
// Express/Hono: resource server extension (auto-verify on each request)
|
|
147
|
+
app.use(erc8004ResourceServerExtension(client, { requiredScore: 50 }))
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Hooks
|
|
151
|
+
|
|
152
|
+
Pre-built hooks for common patterns:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import {
|
|
156
|
+
erc8004IdentityCheck,
|
|
157
|
+
erc8004ReputationCheck,
|
|
158
|
+
erc8004ServerIdentityCheck,
|
|
159
|
+
erc8004SubmitFeedback,
|
|
160
|
+
verifyAgentIdentityFromTask,
|
|
161
|
+
} from '@t402/erc8004'
|
|
162
|
+
|
|
163
|
+
// Client hook: verify server identity before paying
|
|
164
|
+
const identityCheck = erc8004IdentityCheck(client, {
|
|
165
|
+
minScore: 50,
|
|
166
|
+
allowUnregistered: false,
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
// Server hook: verify client agent identity on each payment
|
|
170
|
+
const serverCheck = erc8004ServerIdentityCheck(client)
|
|
171
|
+
|
|
172
|
+
// Server hook: check reputation before accepting payment
|
|
173
|
+
const reputationCheck = erc8004ReputationCheck(client, { minScore: 50 })
|
|
174
|
+
|
|
175
|
+
// Server hook: submit feedback after successful payment
|
|
176
|
+
const feedback = erc8004SubmitFeedback(client, { autoPositive: true })
|
|
177
|
+
|
|
178
|
+
// MCP/A2A: verify agent from task context
|
|
179
|
+
const verified = await verifyAgentIdentityFromTask(client, taskContext)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Constants
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import {
|
|
186
|
+
ERC8004_EXTENSION_KEY, // 'erc8004' — extension key in PaymentRequirements
|
|
187
|
+
IDENTITY_REGISTRIES, // Default identity registry addresses per network
|
|
188
|
+
REPUTATION_REGISTRIES, // Default reputation registry addresses per network
|
|
189
|
+
VALIDATION_REGISTRIES, // Default validation registry addresses per network
|
|
190
|
+
FEEDBACK_TAGS, // Standard feedback tags: 'positive', 'negative', 'neutral'
|
|
191
|
+
IDENTITY_REGISTRY_DOMAIN, // EIP-712 domain for identity registry
|
|
192
|
+
SET_AGENT_WALLET_TYPES, // EIP-712 types for setAgentWallet
|
|
193
|
+
} from '@t402/erc8004'
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## ABIs
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import {
|
|
200
|
+
identityRegistryAbi, // Identity Registry contract ABI
|
|
201
|
+
reputationRegistryAbi, // Reputation Registry contract ABI
|
|
202
|
+
validationRegistryAbi, // Validation Registry contract ABI
|
|
203
|
+
} from '@t402/erc8004'
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t402/erc8004",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "ERC-8004 Trustless Agents integration for t402 payment protocol",
|
|
5
5
|
"main": "./dist/cjs/index.cjs",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@t402/core": "2.7.
|
|
25
|
+
"@t402/core": "2.7.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"viem": "^2.0.0"
|