@aixyz/erc-8004 0.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.
@@ -0,0 +1,219 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * ERC-8004 Raw Agent Registration File Schema
4
+ * For parsing raw registration files fetched from IPFS/URIs
5
+ *
6
+ * Based on: https://github.com/erc-8004/erc-8004-contracts/blob/093d7b91eb9c22048d411896ed397d695742a5f8/ERC8004SPEC.md#agent-uri-and-agent-registration-file
7
+ */
8
+ export declare const ERC8004_REGISTRATION_TYPE = "https://eips.ethereum.org/EIPS/eip-8004#registration-v1";
9
+ /**
10
+ * Supported trust mechanisms for agent validation
11
+ */
12
+ export declare const TrustMechanismSchema: z.ZodEnum<{
13
+ reputation: "reputation";
14
+ "crypto-economic": "crypto-economic";
15
+ "tee-attestation": "tee-attestation";
16
+ social: "social";
17
+ governance: "governance";
18
+ }>;
19
+ /**
20
+ * Service/Endpoint - represents a single service endpoint
21
+ * Examples: MCP server, A2A endpoint, web interface, OASF spec
22
+ */
23
+ export declare const ServiceSchema: z.ZodObject<{
24
+ name: z.ZodString;
25
+ endpoint: z.ZodURL;
26
+ version: z.ZodOptional<z.ZodString>;
27
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
28
+ domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
30
+ prompts: z.ZodOptional<z.ZodArray<z.ZodString>>;
31
+ resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
32
+ }, z.core.$strip>;
33
+ /**
34
+ * Registration entry - links to agent registrations on other chains
35
+ * Format: { agentId: "123", agentRegistry: "eip155:1:0x..." }
36
+ */
37
+ export declare const RegistrationEntrySchema: z.ZodObject<{
38
+ agentId: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<number, string | number>>, z.ZodNumber>;
39
+ agentRegistry: z.ZodString;
40
+ }, z.core.$strip>;
41
+ /**
42
+ * Raw Agent Registration File Schema
43
+ * For parsing registration files fetched from IPFS/URIs
44
+ */
45
+ export declare const RawAgentRegistrationFileSchema: z.ZodObject<{
46
+ type: z.ZodOptional<z.ZodString>;
47
+ $schema: z.ZodOptional<z.ZodString>;
48
+ name: z.ZodString;
49
+ description: z.ZodString;
50
+ image: z.ZodString;
51
+ services: z.ZodOptional<z.ZodArray<z.ZodObject<{
52
+ name: z.ZodString;
53
+ endpoint: z.ZodURL;
54
+ version: z.ZodOptional<z.ZodString>;
55
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
56
+ domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
57
+ tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
58
+ prompts: z.ZodOptional<z.ZodArray<z.ZodString>>;
59
+ resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
60
+ }, z.core.$strip>>>;
61
+ endpoints: z.ZodOptional<z.ZodArray<z.ZodObject<{
62
+ name: z.ZodString;
63
+ endpoint: z.ZodURL;
64
+ version: z.ZodOptional<z.ZodString>;
65
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
66
+ domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
67
+ tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
68
+ prompts: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
+ resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
70
+ }, z.core.$strip>>>;
71
+ active: z.ZodOptional<z.ZodBoolean>;
72
+ x402support: z.ZodOptional<z.ZodBoolean>;
73
+ x402Support: z.ZodOptional<z.ZodBoolean>;
74
+ registrations: z.ZodOptional<z.ZodArray<z.ZodObject<{
75
+ agentId: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<number, string | number>>, z.ZodNumber>;
76
+ agentRegistry: z.ZodString;
77
+ }, z.core.$strip>>>;
78
+ supportedTrust: z.ZodOptional<z.ZodArray<z.ZodString>>;
79
+ ens: z.ZodOptional<z.ZodString>;
80
+ did: z.ZodOptional<z.ZodString>;
81
+ }, z.core.$strip>;
82
+ /**
83
+ * Strict Schema - for creating new registration files
84
+ * Requires correct type literal and at least one service
85
+ */
86
+ export declare const StrictAgentRegistrationFileSchema: z.ZodObject<{
87
+ $schema: z.ZodOptional<z.ZodString>;
88
+ name: z.ZodString;
89
+ description: z.ZodString;
90
+ image: z.ZodString;
91
+ endpoints: z.ZodOptional<z.ZodArray<z.ZodObject<{
92
+ name: z.ZodString;
93
+ endpoint: z.ZodURL;
94
+ version: z.ZodOptional<z.ZodString>;
95
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
96
+ domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
97
+ tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
98
+ prompts: z.ZodOptional<z.ZodArray<z.ZodString>>;
99
+ resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
100
+ }, z.core.$strip>>>;
101
+ active: z.ZodOptional<z.ZodBoolean>;
102
+ x402support: z.ZodOptional<z.ZodBoolean>;
103
+ x402Support: z.ZodOptional<z.ZodBoolean>;
104
+ registrations: z.ZodOptional<z.ZodArray<z.ZodObject<{
105
+ agentId: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<number, string | number>>, z.ZodNumber>;
106
+ agentRegistry: z.ZodString;
107
+ }, z.core.$strip>>>;
108
+ supportedTrust: z.ZodOptional<z.ZodArray<z.ZodString>>;
109
+ ens: z.ZodOptional<z.ZodString>;
110
+ did: z.ZodOptional<z.ZodString>;
111
+ type: z.ZodLiteral<"https://eips.ethereum.org/EIPS/eip-8004#registration-v1">;
112
+ services: z.ZodArray<z.ZodObject<{
113
+ name: z.ZodString;
114
+ endpoint: z.ZodURL;
115
+ version: z.ZodOptional<z.ZodString>;
116
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
117
+ domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
118
+ tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
119
+ prompts: z.ZodOptional<z.ZodArray<z.ZodString>>;
120
+ resources: z.ZodOptional<z.ZodArray<z.ZodString>>;
121
+ }, z.core.$strip>>;
122
+ }, z.core.$strip>;
123
+ export type TrustMechanism = z.infer<typeof TrustMechanismSchema>;
124
+ export type Service = z.infer<typeof ServiceSchema>;
125
+ export type RegistrationEntry = z.infer<typeof RegistrationEntrySchema>;
126
+ export type RawAgentRegistrationFile = z.infer<typeof RawAgentRegistrationFileSchema>;
127
+ export type StrictAgentRegistrationFile = z.infer<typeof StrictAgentRegistrationFileSchema>;
128
+ /**
129
+ * Parse a raw registration file
130
+ * Use for existing/untrusted data fetched from IPFS/URIs - won't throw on malformed input
131
+ */
132
+ export declare function parseRawRegistrationFile(data: unknown): z.ZodSafeParseResult<{
133
+ name: string;
134
+ description: string;
135
+ image: string;
136
+ type?: string | undefined;
137
+ $schema?: string | undefined;
138
+ services?: {
139
+ name: string;
140
+ endpoint: string;
141
+ version?: string | undefined;
142
+ skills?: string[] | undefined;
143
+ domains?: string[] | undefined;
144
+ tools?: string[] | undefined;
145
+ prompts?: string[] | undefined;
146
+ resources?: string[] | undefined;
147
+ }[] | undefined;
148
+ endpoints?: {
149
+ name: string;
150
+ endpoint: string;
151
+ version?: string | undefined;
152
+ skills?: string[] | undefined;
153
+ domains?: string[] | undefined;
154
+ tools?: string[] | undefined;
155
+ prompts?: string[] | undefined;
156
+ resources?: string[] | undefined;
157
+ }[] | undefined;
158
+ active?: boolean | undefined;
159
+ x402support?: boolean | undefined;
160
+ x402Support?: boolean | undefined;
161
+ registrations?: {
162
+ agentId: number;
163
+ agentRegistry: string;
164
+ }[] | undefined;
165
+ supportedTrust?: string[] | undefined;
166
+ ens?: string | undefined;
167
+ did?: string | undefined;
168
+ }>;
169
+ /**
170
+ * Validate a registration file with strict validation
171
+ * Use when creating or submitting new registration files
172
+ */
173
+ export declare function validateRegistrationFile(data: unknown): z.ZodSafeParseResult<{
174
+ name: string;
175
+ description: string;
176
+ image: string;
177
+ type: "https://eips.ethereum.org/EIPS/eip-8004#registration-v1";
178
+ services: {
179
+ name: string;
180
+ endpoint: string;
181
+ version?: string | undefined;
182
+ skills?: string[] | undefined;
183
+ domains?: string[] | undefined;
184
+ tools?: string[] | undefined;
185
+ prompts?: string[] | undefined;
186
+ resources?: string[] | undefined;
187
+ }[];
188
+ $schema?: string | undefined;
189
+ endpoints?: {
190
+ name: string;
191
+ endpoint: string;
192
+ version?: string | undefined;
193
+ skills?: string[] | undefined;
194
+ domains?: string[] | undefined;
195
+ tools?: string[] | undefined;
196
+ prompts?: string[] | undefined;
197
+ resources?: string[] | undefined;
198
+ }[] | undefined;
199
+ active?: boolean | undefined;
200
+ x402support?: boolean | undefined;
201
+ x402Support?: boolean | undefined;
202
+ registrations?: {
203
+ agentId: number;
204
+ agentRegistry: string;
205
+ }[] | undefined;
206
+ supportedTrust?: string[] | undefined;
207
+ ens?: string | undefined;
208
+ did?: string | undefined;
209
+ }>;
210
+ /**
211
+ * Get services from a registration file
212
+ * Handles both `services` (new) and `endpoints` (legacy) field names
213
+ */
214
+ export declare function getServices(file: RawAgentRegistrationFile | StrictAgentRegistrationFile): Service[];
215
+ /**
216
+ * Check if agent supports x402 payment protocol
217
+ * Handles both `x402support` and `x402Support` casing variants
218
+ */
219
+ export declare function hasX402Support(file: RawAgentRegistrationFile | StrictAgentRegistrationFile): boolean;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StrictAgentRegistrationFileSchema = exports.RawAgentRegistrationFileSchema = exports.RegistrationEntrySchema = exports.ServiceSchema = exports.TrustMechanismSchema = exports.ERC8004_REGISTRATION_TYPE = void 0;
4
+ exports.parseRawRegistrationFile = parseRawRegistrationFile;
5
+ exports.validateRegistrationFile = validateRegistrationFile;
6
+ exports.getServices = getServices;
7
+ exports.hasX402Support = hasX402Support;
8
+ const zod_1 = require("zod");
9
+ /**
10
+ * ERC-8004 Raw Agent Registration File Schema
11
+ * For parsing raw registration files fetched from IPFS/URIs
12
+ *
13
+ * Based on: https://github.com/erc-8004/erc-8004-contracts/blob/093d7b91eb9c22048d411896ed397d695742a5f8/ERC8004SPEC.md#agent-uri-and-agent-registration-file
14
+ */
15
+ // =============================================================================
16
+ // Constants
17
+ // =============================================================================
18
+ exports.ERC8004_REGISTRATION_TYPE = "https://eips.ethereum.org/EIPS/eip-8004#registration-v1";
19
+ // =============================================================================
20
+ // Building Block Schemas
21
+ // =============================================================================
22
+ /**
23
+ * Supported trust mechanisms for agent validation
24
+ */
25
+ exports.TrustMechanismSchema = zod_1.z.enum([
26
+ "reputation",
27
+ "crypto-economic",
28
+ "tee-attestation",
29
+ "social",
30
+ "governance",
31
+ ]);
32
+ /**
33
+ * Service/Endpoint - represents a single service endpoint
34
+ * Examples: MCP server, A2A endpoint, web interface, OASF spec
35
+ */
36
+ exports.ServiceSchema = zod_1.z.object({
37
+ name: zod_1.z.string(),
38
+ endpoint: zod_1.z.url(),
39
+ version: zod_1.z.string().optional(),
40
+ // OASF-specific fields
41
+ skills: zod_1.z.array(zod_1.z.string()).optional(),
42
+ domains: zod_1.z.array(zod_1.z.string()).optional(),
43
+ // MCP-specific fields
44
+ tools: zod_1.z.array(zod_1.z.string()).optional(),
45
+ prompts: zod_1.z.array(zod_1.z.string()).optional(),
46
+ resources: zod_1.z.array(zod_1.z.string()).optional(),
47
+ });
48
+ /**
49
+ * Registration entry - links to agent registrations on other chains
50
+ * Format: { agentId: "123", agentRegistry: "eip155:1:0x..." }
51
+ */
52
+ exports.RegistrationEntrySchema = zod_1.z.object({
53
+ agentId: zod_1.z
54
+ .union([zod_1.z.string().trim().regex(/^\d+$/), zod_1.z.number()])
55
+ .transform((val) => Number(val))
56
+ .pipe(zod_1.z.number().int().nonnegative()),
57
+ agentRegistry: zod_1.z.string(),
58
+ });
59
+ // =============================================================================
60
+ // Main Schemas
61
+ // =============================================================================
62
+ /**
63
+ * Raw Agent Registration File Schema
64
+ * For parsing registration files fetched from IPFS/URIs
65
+ */
66
+ exports.RawAgentRegistrationFileSchema = zod_1.z.object({
67
+ // Schema identifiers
68
+ type: zod_1.z.string().optional(),
69
+ $schema: zod_1.z.string().optional(),
70
+ // ERC-721 metadata compatibility (required)
71
+ name: zod_1.z.string(),
72
+ description: zod_1.z.string(),
73
+ image: zod_1.z.string(),
74
+ // Service endpoints
75
+ services: zod_1.z.array(exports.ServiceSchema).optional(),
76
+ endpoints: zod_1.z.array(exports.ServiceSchema).optional(), // Legacy field name
77
+ // Agent configuration
78
+ active: zod_1.z.boolean().optional(),
79
+ x402support: zod_1.z.boolean().optional(),
80
+ x402Support: zod_1.z.boolean().optional(), // Alternative casing
81
+ // Cross-chain & identity
82
+ registrations: zod_1.z.array(exports.RegistrationEntrySchema).optional(),
83
+ supportedTrust: zod_1.z.array(zod_1.z.string()).optional(),
84
+ ens: zod_1.z.string().optional(),
85
+ did: zod_1.z.string().optional(),
86
+ });
87
+ /**
88
+ * Strict Schema - for creating new registration files
89
+ * Requires correct type literal and at least one service
90
+ */
91
+ exports.StrictAgentRegistrationFileSchema = exports.RawAgentRegistrationFileSchema.extend({
92
+ type: zod_1.z.literal(exports.ERC8004_REGISTRATION_TYPE),
93
+ services: zod_1.z.array(exports.ServiceSchema).min(1, "At least one service endpoint is required"),
94
+ });
95
+ // =============================================================================
96
+ // Helper Functions
97
+ // =============================================================================
98
+ /**
99
+ * Parse a raw registration file
100
+ * Use for existing/untrusted data fetched from IPFS/URIs - won't throw on malformed input
101
+ */
102
+ function parseRawRegistrationFile(data) {
103
+ return exports.RawAgentRegistrationFileSchema.safeParse(data);
104
+ }
105
+ /**
106
+ * Validate a registration file with strict validation
107
+ * Use when creating or submitting new registration files
108
+ */
109
+ function validateRegistrationFile(data) {
110
+ return exports.StrictAgentRegistrationFileSchema.safeParse(data);
111
+ }
112
+ /**
113
+ * Get services from a registration file
114
+ * Handles both `services` (new) and `endpoints` (legacy) field names
115
+ */
116
+ function getServices(file) {
117
+ return file.services ?? file.endpoints ?? [];
118
+ }
119
+ /**
120
+ * Check if agent supports x402 payment protocol
121
+ * Handles both `x402support` and `x402Support` casing variants
122
+ */
123
+ function hasX402Support(file) {
124
+ return file.x402support === true || file.x402Support === true;
125
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@aixyz/erc-8004",
3
+ "version": "0.0.6",
4
+ "description": "Shared ERC-8004 contract ABIs, addresses, and Solidity sources for the aixyz ecosystem.",
5
+ "homepage": "https://github.com/AgentlyHQ/aixyz#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/AgentlyHQ/aixyz/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/AgentlyHQ/aixyz.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": {
15
+ "name": "kevzzsk"
16
+ },
17
+ "type": "commonjs",
18
+ "exports": {
19
+ ".": {
20
+ "require": "./dist/src/index.js",
21
+ "default": "./dist/src/index.js"
22
+ },
23
+ "./*": {
24
+ "require": "./dist/src/*.js",
25
+ "default": "./dist/src/*.js"
26
+ }
27
+ },
28
+ "main": "dist/src/index.js",
29
+ "types": "dist/src/index.d.ts",
30
+ "files": [
31
+ "dist",
32
+ "contracts"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "test": "bun test"
37
+ },
38
+ "dependencies": {
39
+ "zod": "^4.3.6"
40
+ }
41
+ }