-
Notifications
You must be signed in to change notification settings - Fork 0
Prepare v0.1.0 for publish #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e5c78ad
add pollingInterval and FORK_URL warning to fork setup
vraspar 236bc8d
Prepare @x402r/erc8004 v0.1.0 for publish
vraspar cadfecd
Address PR #5 review: bug fix, spec gaps, docs, alpha version
vraspar cf38ea6
Address review round 2: design fixes, bug fix, test improvements
vraspar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Changelog | ||
|
|
||
| ## 0.1.0-alpha.0 | ||
|
|
||
| Initial alpha release. | ||
|
|
||
| ### Identity | ||
|
|
||
| - `registerAgent` — register as an ERC-8004 agent (mints agent NFT) | ||
| - `parseRegisterReceipt` — extract agentId from register transaction receipt | ||
| - `isRegistered` — check if an address is a registered agent | ||
| - `verifyAgentId` — verify that an agentId belongs to a claimed address | ||
| - `resolveAgent` — resolve agent by ID (owner, wallet, URI, ownerMismatch flag) | ||
| - `getAgentWallet` / `setAgentWallet` / `unsetAgentWallet` — wallet management | ||
| - `signAgentWalletConsent` — sign EIP-712 typed data for `setAgentWallet` | ||
| - `getMetadata` / `setMetadata` — on-chain key-value metadata | ||
| - `parseMetadataSetReceipt` — extract fields from setMetadata transaction receipt | ||
| - `setAgentURI` — update agent URI | ||
| - `parseURIUpdatedReceipt` — extract fields from setAgentURI transaction receipt | ||
| - `getVersion` — read contract version string | ||
|
|
||
| ### Reputation | ||
|
|
||
| - `giveFeedback` — submit feedback for an agent | ||
| - `parseGiveFeedbackReceipt` — extract fields from giveFeedback transaction receipt | ||
| - `revokeFeedback` — revoke previously given feedback | ||
| - `parseFeedbackRevokedReceipt` — extract fields from revokeFeedback transaction receipt | ||
| - `appendResponse` — append a response to existing feedback | ||
| - `parseResponseAppendedReceipt` — extract fields from appendResponse transaction receipt | ||
| - `readFeedback` / `readAllFeedback` — read feedback entries (optional `batchSize` for large reviewer sets) | ||
| - `getSummary` — aggregated reputation summary | ||
| - `getClients` — all reviewer addresses for an agent | ||
| - `getLastIndex` — latest feedback index for an agent-client pair | ||
| - `getResponseCount` — count responses to a feedback entry | ||
| - `getIdentityRegistry` — get linked Identity Registry address | ||
| - `getVersion` — read contract version string | ||
|
|
||
| ### Infrastructure | ||
|
|
||
| - Registry addresses for 14 chains (Ethereum, Base, Polygon, Arbitrum, Optimism, Avalanche, BSC, Scroll, Linea, Mantle, Gnosis, Celo, Base Sepolia, Ethereum Sepolia) | ||
| - Auto-resolve registry address from `client.chain` | ||
| - Sub-path exports: `/identity`, `/reputation`, `/abis` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| # @x402r/erc8004 | ||
|
|
||
| TypeScript SDK for [ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) Identity and Reputation registries. Built on [viem](https://viem.sh). | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| npm install @x402r/erc8004 | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Register an agent | ||
|
|
||
| ```ts | ||
| import { registerAgent, parseRegisterReceipt } from '@x402r/erc8004/identity' | ||
|
|
||
| const hash = await registerAgent(walletClient, { | ||
| agentURI: 'https://example.com/agent.json', | ||
| }) | ||
|
|
||
| const receipt = await publicClient.waitForTransactionReceipt({ hash }) | ||
| const { agentId } = parseRegisterReceipt(receipt) | ||
| ``` | ||
|
|
||
| ### Verify identity | ||
|
|
||
| ```ts | ||
| import { verifyAgentId, resolveAgent } from '@x402r/erc8004/identity' | ||
|
|
||
| const valid = await verifyAgentId(publicClient, { | ||
| agentId: 42n, | ||
| claimedAddress: '0x...', | ||
| }) | ||
|
|
||
| const agent = await resolveAgent(publicClient, { agentId: 42n }) | ||
| // { agentId, owner, agentWallet, agentURI, ownerMismatch } | ||
| ``` | ||
|
|
||
| ### Give feedback | ||
|
|
||
| ```ts | ||
| import { giveFeedback, getSummary } from '@x402r/erc8004/reputation' | ||
|
|
||
| await giveFeedback(walletClient, { | ||
| agentId: 42n, | ||
| value: 85n, | ||
| valueDecimals: 0, | ||
| tag1: 'service', | ||
| tag2: 'quality', | ||
| }) | ||
|
|
||
| const summary = await getSummary(publicClient, { | ||
| agentId: 42n, | ||
| clientAddresses: ['0x...'], | ||
| tag1: 'service', | ||
| tag2: 'quality', | ||
| }) | ||
| ``` | ||
|
|
||
| ## API | ||
|
|
||
| ### Identity | ||
|
|
||
| | Function | Description | | ||
| |---|---| | ||
| | `registerAgent` | Register as an ERC-8004 agent (mints NFT) | | ||
| | `parseRegisterReceipt` | Extract `agentId` from register tx receipt | | ||
| | `isRegistered` | Check if an address is registered | | ||
| | `verifyAgentId` | Verify agentId belongs to a claimed address | | ||
| | `resolveAgent` | Resolve agent by ID (owner, wallet, URI) | | ||
| | `getAgentWallet` | Get wallet address for an agent | | ||
| | `setAgentWallet` | Set verified payment wallet (EIP-712 sig) | | ||
| | `signAgentWalletConsent` | Sign EIP-712 consent for `setAgentWallet` | | ||
| | `unsetAgentWallet` | Clear agent wallet | | ||
| | `getMetadata` | Read on-chain metadata by key | | ||
| | `setMetadata` | Write on-chain metadata | | ||
| | `parseMetadataSetReceipt` | Extract fields from `setMetadata` tx receipt | | ||
| | `setAgentURI` | Update agent URI | | ||
| | `parseURIUpdatedReceipt` | Extract fields from `setAgentURI` tx receipt | | ||
| | `getVersion` | Read contract version string | | ||
|
|
||
| ### Reputation | ||
|
|
||
| | Function | Description | | ||
| |---|---| | ||
| | `giveFeedback` | Submit feedback for an agent | | ||
| | `parseGiveFeedbackReceipt` | Extract fields from `giveFeedback` tx receipt | | ||
| | `revokeFeedback` | Revoke previously given feedback | | ||
| | `parseFeedbackRevokedReceipt` | Extract fields from `revokeFeedback` tx receipt | | ||
| | `appendResponse` | Append a response to feedback | | ||
| | `parseResponseAppendedReceipt` | Extract fields from `appendResponse` tx receipt | | ||
| | `readFeedback` | Read a single feedback entry | | ||
| | `readAllFeedback` | Read all feedback (filtered by reviewers and tags, optional `batchSize`) | | ||
| | `getSummary` | Aggregated reputation summary | | ||
| | `getClients` | All addresses that have given feedback | | ||
| | `getLastIndex` | Latest feedback index for an agent-client pair | | ||
| | `getResponseCount` | Count responses to a feedback entry | | ||
| | `getIdentityRegistry` | Get linked Identity Registry address | | ||
| | `getVersion` | Read contract version string | | ||
|
|
||
| ## Chains | ||
|
|
||
| | Chain | ID | | ||
| |---|---| | ||
| | Ethereum | 1 | | ||
| | Base | 8453 | | ||
| | Polygon | 137 | | ||
| | Arbitrum | 42161 | | ||
| | Optimism | 10 | | ||
| | Avalanche | 43114 | | ||
| | BSC | 56 | | ||
| | Scroll | 534352 | | ||
| | Linea | 59144 | | ||
| | Mantle | 5000 | | ||
| | Gnosis | 100 | | ||
| | Celo | 42220 | | ||
| | Base Sepolia | 84532 | | ||
| | Ethereum Sepolia | 11155111 | | ||
|
|
||
| Registry addresses auto-resolve from `client.chain`. Pass `registryAddress` to override. | ||
|
|
||
| ## Exports | ||
|
|
||
| | Path | Contents | | ||
| |---|---| | ||
| | `@x402r/erc8004` | Everything | | ||
| | `@x402r/erc8004/identity` | Identity registry functions and types | | ||
| | `@x402r/erc8004/reputation` | Reputation registry functions and types | | ||
| | `@x402r/erc8004/abis` | Raw contract ABIs | | ||
|
|
||
| ## License | ||
|
|
||
| [Apache-2.0](./LICENSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import type { PublicClient } from 'viem' | ||
| import { identityRegistryAbi } from '../abis/index.js' | ||
| import { resolveIdentityRegistry } from '../internal/resolveRegistryAddress.js' | ||
| import type { GetVersionParameters } from './types.js' | ||
|
|
||
| /** Read the contract version string from the Identity Registry. */ | ||
| export async function getVersion( | ||
| publicClient: PublicClient, | ||
| parameters: GetVersionParameters = {}, | ||
| ): Promise<string> { | ||
| const registry = resolveIdentityRegistry( | ||
| publicClient, | ||
| parameters.registryAddress, | ||
| ) | ||
|
|
||
| return publicClient.readContract({ | ||
| address: registry, | ||
| abi: identityRegistryAbi, | ||
| functionName: 'getVersion', | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,33 @@ | ||
| export { getAgentWallet } from './getAgentWallet.js' | ||
| export { getMetadata } from './getMetadata.js' | ||
| export { getVersion } from './getVersion.js' | ||
| export { isRegistered } from './isRegistered.js' | ||
| export type { MetadataSetResult } from './parseMetadataSetReceipt.js' | ||
| export { parseMetadataSetReceipt } from './parseMetadataSetReceipt.js' | ||
| export type { RegisterResult } from './parseRegisterReceipt.js' | ||
| export { parseRegisterReceipt } from './parseRegisterReceipt.js' | ||
| export type { URIUpdatedResult } from './parseURIUpdatedReceipt.js' | ||
| export { parseURIUpdatedReceipt } from './parseURIUpdatedReceipt.js' | ||
| export { registerAgent } from './register.js' | ||
| export { resolveAgent } from './resolveAgent.js' | ||
| export { setAgentURI } from './setAgentURI.js' | ||
| export { setAgentWallet } from './setAgentWallet.js' | ||
| export { setMetadata } from './setMetadata.js' | ||
| export { signAgentWalletConsent } from './signAgentWalletConsent.js' | ||
| export type { | ||
| GetAgentWalletParameters, | ||
| GetMetadataParameters, | ||
| GetVersionParameters, | ||
| IsRegisteredParameters, | ||
| RegisterAgentParameters, | ||
| ResolveAgentParameters, | ||
| ResolvedAgent, | ||
| SetAgentURIParameters, | ||
| SetAgentWalletParameters, | ||
| SetMetadataParameters, | ||
| SignAgentWalletConsentParameters, | ||
| UnsetAgentWalletParameters, | ||
| VerifyAgentIdParameters, | ||
| } from './types.js' | ||
| export { unsetAgentWallet } from './unsetAgentWallet.js' | ||
| export { verifyAgentId } from './verifyAgentId.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { type Hex, parseEventLogs, type TransactionReceipt } from 'viem' | ||
| import { identityRegistryAbi } from '../abis/index.js' | ||
|
|
||
| export interface MetadataSetResult { | ||
| agentId: bigint | ||
| metadataKey: string | ||
| metadataValue: Hex | ||
| } | ||
|
|
||
| /** Extract agentId, metadataKey, and metadataValue from a `setMetadata` transaction receipt. */ | ||
| export function parseMetadataSetReceipt( | ||
| receipt: TransactionReceipt, | ||
| ): MetadataSetResult { | ||
| const logs = parseEventLogs({ | ||
| abi: identityRegistryAbi, | ||
| logs: receipt.logs, | ||
| eventName: 'MetadataSet', | ||
| }) | ||
| if (logs.length === 0) { | ||
| throw new Error('No MetadataSet event found in receipt') | ||
| } | ||
| const { agentId, metadataKey, metadataValue } = logs[0].args | ||
| return { agentId, metadataKey, metadataValue } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { type Address, parseEventLogs, type TransactionReceipt } from 'viem' | ||
| import { identityRegistryAbi } from '../abis/index.js' | ||
|
|
||
| export interface RegisterResult { | ||
| agentId: bigint | ||
| owner: Address | ||
| agentURI: string | ||
| } | ||
|
|
||
| /** | ||
| * Extract the agentId, owner, and agentURI from a `registerAgent` transaction receipt. | ||
| * Parses the `Registered` event emitted by the Identity Registry. | ||
| */ | ||
| export function parseRegisterReceipt( | ||
| receipt: TransactionReceipt, | ||
| ): RegisterResult { | ||
| const logs = parseEventLogs({ | ||
| abi: identityRegistryAbi, | ||
| logs: receipt.logs, | ||
| eventName: 'Registered', | ||
| }) | ||
| if (logs.length === 0) { | ||
| throw new Error('No Registered event found in receipt') | ||
| } | ||
| const { agentId, owner, agentURI } = logs[0].args | ||
| return { agentId, owner, agentURI } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { type Address, parseEventLogs, type TransactionReceipt } from 'viem' | ||
| import { identityRegistryAbi } from '../abis/index.js' | ||
|
|
||
| export interface URIUpdatedResult { | ||
| agentId: bigint | ||
| newURI: string | ||
| updatedBy: Address | ||
| } | ||
|
|
||
| /** Extract agentId, newURI, and updatedBy from a `setAgentURI` transaction receipt. */ | ||
| export function parseURIUpdatedReceipt( | ||
| receipt: TransactionReceipt, | ||
| ): URIUpdatedResult { | ||
| const logs = parseEventLogs({ | ||
| abi: identityRegistryAbi, | ||
| logs: receipt.logs, | ||
| eventName: 'URIUpdated', | ||
| }) | ||
| if (logs.length === 0) { | ||
| throw new Error('No URIUpdated event found in receipt') | ||
| } | ||
| const { agentId, newURI, updatedBy } = logs[0].args | ||
| return { agentId, newURI, updatedBy } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe release alpha version first for testing with SDK, than can release actual stable one ?