@agnt-id/agent0 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ import type { Agent0RegistrationFile, AgntIdentityLink, AgntNameLike, AgntRecordLike, ToRegistrationFileOptions } from "./types.js";
2
+ /**
3
+ * Parse an .agnt identity string into its components.
4
+ *
5
+ * The identity field is a CAIP-10-like string with an appended agent ID:
6
+ * "eip155:1:0xRegistryAddress:42"
7
+ *
8
+ * @returns Parsed identity link, or null if the format is invalid
9
+ */
10
+ export declare function parseIdentityLink(identity: string): AgntIdentityLink | null;
11
+ /**
12
+ * Format an identity link back to the CAIP-style string.
13
+ */
14
+ export declare function formatIdentityLink(link: AgntIdentityLink): string;
15
+ /**
16
+ * Convert a resolved .agnt name to an ERC-8004 Agent Registration File.
17
+ *
18
+ * This produces the JSON structure that would be hosted at an agentURI
19
+ * for on-chain agent discovery via the ERC-8004 standard.
20
+ */
21
+ export declare function toRegistrationFile(agnt: AgntNameLike, options?: ToRegistrationFileOptions): Agent0RegistrationFile;
22
+ /**
23
+ * Convert an ERC-8004 registration file back to .agnt record fields.
24
+ * Useful for importing Agent0 agents into the .agnt naming system.
25
+ */
26
+ export declare function fromRegistrationFile(file: Agent0RegistrationFile): AgntRecordLike;
27
+ /**
28
+ * Resolve a .agnt name and return its ERC-8004 registration file.
29
+ * Requires @agnt-id/resolve to be installed.
30
+ */
31
+ export declare function fromAgnt(name: string, options?: ToRegistrationFileOptions & {
32
+ gateway?: string;
33
+ chainId?: string;
34
+ }): Promise<Agent0RegistrationFile | null>;
package/dist/bridge.js ADDED
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Parse an .agnt identity string into its components.
3
+ *
4
+ * The identity field is a CAIP-10-like string with an appended agent ID:
5
+ * "eip155:1:0xRegistryAddress:42"
6
+ *
7
+ * @returns Parsed identity link, or null if the format is invalid
8
+ */
9
+ export function parseIdentityLink(identity) {
10
+ // Expected format: namespace:chainRef:registryAddress:agentId
11
+ const parts = identity.split(":");
12
+ if (parts.length < 4)
13
+ return null;
14
+ const namespace = parts[0];
15
+ const chainRef = parts[1];
16
+ const registry = parts[2];
17
+ const agentIdStr = parts[3];
18
+ const agentId = Number(agentIdStr);
19
+ if (!Number.isFinite(agentId) || agentId < 0)
20
+ return null;
21
+ return {
22
+ chainId: `${namespace}:${chainRef}`,
23
+ registry,
24
+ agentId,
25
+ };
26
+ }
27
+ /**
28
+ * Format an identity link back to the CAIP-style string.
29
+ */
30
+ export function formatIdentityLink(link) {
31
+ return `${link.chainId}:${link.registry}:${link.agentId}`;
32
+ }
33
+ /**
34
+ * Convert a resolved .agnt name to an ERC-8004 Agent Registration File.
35
+ *
36
+ * This produces the JSON structure that would be hosted at an agentURI
37
+ * for on-chain agent discovery via the ERC-8004 standard.
38
+ */
39
+ export function toRegistrationFile(agnt, options = {}) {
40
+ const rec = agnt.records;
41
+ const description = rec.texts?.description ?? `AI agent registered as ${agnt.name}`;
42
+ const image = options.image ?? rec.texts?.avatar;
43
+ // Build services from .agnt record endpoints
44
+ const services = [];
45
+ if (rec.a2a) {
46
+ services.push({
47
+ name: "a2a",
48
+ endpoint: rec.a2a,
49
+ version: rec.a2aVersion,
50
+ skills: rec.skills,
51
+ domains: rec.domains,
52
+ });
53
+ }
54
+ if (rec.mcp) {
55
+ services.push({
56
+ name: "mcp",
57
+ endpoint: rec.mcp,
58
+ version: rec.mcpVersion,
59
+ skills: rec.skills,
60
+ domains: rec.domains,
61
+ });
62
+ }
63
+ if (options.extraServices) {
64
+ services.push(...options.extraServices);
65
+ }
66
+ // Build registrations from identity link
67
+ const registrations = [];
68
+ if (rec.identity) {
69
+ const link = parseIdentityLink(rec.identity);
70
+ if (link) {
71
+ registrations.push({
72
+ agentId: link.agentId,
73
+ agentRegistry: `${link.chainId}:${link.registry}`,
74
+ });
75
+ }
76
+ }
77
+ if (options.extraRegistrations) {
78
+ registrations.push(...options.extraRegistrations);
79
+ }
80
+ // Map .agnt trustModels to ERC-8004 supportedTrust
81
+ const supportedTrust = (rec.trustModels ?? []).filter((t) => [
82
+ "reputation",
83
+ "crypto-economic",
84
+ "tee-attestation",
85
+ "social-graph",
86
+ ].includes(t));
87
+ const file = {
88
+ type: "https://eips.ethereum.org/EIPS/eip-8004#registration-v1",
89
+ name: agnt.name,
90
+ description,
91
+ services,
92
+ registrations,
93
+ active: options.active ?? true,
94
+ x402Support: rec.x402Support,
95
+ };
96
+ if (image)
97
+ file.image = image;
98
+ if (supportedTrust.length > 0) {
99
+ file.supportedTrust =
100
+ supportedTrust;
101
+ }
102
+ return file;
103
+ }
104
+ /**
105
+ * Convert an ERC-8004 registration file back to .agnt record fields.
106
+ * Useful for importing Agent0 agents into the .agnt naming system.
107
+ */
108
+ export function fromRegistrationFile(file) {
109
+ const rec = {};
110
+ // Extract A2A and MCP services
111
+ for (const svc of file.services) {
112
+ if (svc.name === "a2a") {
113
+ rec.a2a = svc.endpoint;
114
+ if (svc.version)
115
+ rec.a2aVersion = svc.version;
116
+ if (svc.skills?.length)
117
+ rec.skills = svc.skills;
118
+ if (svc.domains?.length)
119
+ rec.domains = svc.domains;
120
+ }
121
+ else if (svc.name === "mcp") {
122
+ rec.mcp = svc.endpoint;
123
+ if (svc.version)
124
+ rec.mcpVersion = svc.version;
125
+ if (!rec.skills && svc.skills?.length)
126
+ rec.skills = svc.skills;
127
+ if (!rec.domains && svc.domains?.length)
128
+ rec.domains = svc.domains;
129
+ }
130
+ }
131
+ // Map first registration to identity link
132
+ if (file.registrations.length > 0) {
133
+ const reg = file.registrations[0];
134
+ rec.identity = `${reg.agentRegistry}:${reg.agentId}`;
135
+ }
136
+ // Map trust models
137
+ if (file.supportedTrust?.length) {
138
+ rec.trustModels = [...file.supportedTrust];
139
+ }
140
+ if (file.x402Support != null)
141
+ rec.x402Support = file.x402Support;
142
+ if (file.image)
143
+ rec.texts = { avatar: file.image };
144
+ if (file.description) {
145
+ rec.texts = { ...rec.texts, description: file.description };
146
+ }
147
+ return rec;
148
+ }
149
+ /**
150
+ * Resolve a .agnt name and return its ERC-8004 registration file.
151
+ * Requires @agnt-id/resolve to be installed.
152
+ */
153
+ export async function fromAgnt(name, options = {}) {
154
+ const { AgntClient } = await import("@agnt-id/resolve");
155
+ const client = new AgntClient({
156
+ gateway: options.gateway,
157
+ chainId: options.chainId,
158
+ });
159
+ const result = await client.resolve(name);
160
+ if (!result)
161
+ return null;
162
+ return toRegistrationFile(result, options);
163
+ }
@@ -0,0 +1,2 @@
1
+ export { formatIdentityLink, fromAgnt, fromRegistrationFile, parseIdentityLink, toRegistrationFile, } from "./bridge.js";
2
+ export type { Agent0FeedbackFile, Agent0Registration, Agent0RegistrationFile, Agent0Service, AgntIdentityLink, AgntNameLike, AgntRecordLike, ToRegistrationFileOptions, } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { formatIdentityLink, fromAgnt, fromRegistrationFile, parseIdentityLink, toRegistrationFile, } from "./bridge.js";
@@ -0,0 +1,112 @@
1
+ /**
2
+ * ERC-8004 types and .agnt bridge structures.
3
+ * @see https://eips.ethereum.org/EIPS/eip-8004
4
+ * @see https://www.8004.org/build
5
+ */
6
+ /** A service entry in the ERC-8004 registration file. */
7
+ export type Agent0Service = {
8
+ name: string;
9
+ endpoint: string;
10
+ version?: string;
11
+ skills?: string[];
12
+ domains?: string[];
13
+ };
14
+ /** An agent's registration entry across chains. */
15
+ export type Agent0Registration = {
16
+ agentId: number;
17
+ agentRegistry: string;
18
+ };
19
+ /**
20
+ * ERC-8004 Agent Registration File — the JSON at an agentURI.
21
+ * @see https://eips.ethereum.org/EIPS/eip-8004#registration-v1
22
+ */
23
+ export type Agent0RegistrationFile = {
24
+ type: "https://eips.ethereum.org/EIPS/eip-8004#registration-v1";
25
+ name: string;
26
+ description: string;
27
+ image?: string;
28
+ services: Agent0Service[];
29
+ x402Support?: boolean;
30
+ active?: boolean;
31
+ registrations: Agent0Registration[];
32
+ supportedTrust?: ("reputation" | "crypto-economic" | "tee-attestation" | "social-graph")[];
33
+ };
34
+ /** Feedback file for the ERC-8004 reputation registry. */
35
+ export type Agent0FeedbackFile = {
36
+ agentRegistry: string;
37
+ agentId: number;
38
+ clientAddress: string;
39
+ createdAt: string;
40
+ value: number;
41
+ valueDecimals: number;
42
+ tag1: string;
43
+ tag2: string;
44
+ endpoint: string;
45
+ mcp?: {
46
+ tool?: string;
47
+ prompt?: string;
48
+ resource?: string;
49
+ };
50
+ a2a?: {
51
+ skills?: string[];
52
+ contextId?: string;
53
+ taskId?: string;
54
+ };
55
+ oasf?: {
56
+ skills?: string[];
57
+ domains?: string[];
58
+ };
59
+ proofOfPayment?: {
60
+ fromAddress: string;
61
+ toAddress: string;
62
+ chainId: number;
63
+ txHash: string;
64
+ };
65
+ };
66
+ /**
67
+ * Minimal shape of an .agnt record for bridge operations.
68
+ * Matches @agnt-id/resolve AgntRecord without requiring the dependency.
69
+ */
70
+ export type AgntRecordLike = {
71
+ wallets?: Record<string, string>;
72
+ agentId?: string;
73
+ a2a?: string;
74
+ mcp?: string;
75
+ texts?: Record<string, string>;
76
+ identity?: string;
77
+ wallet?: string;
78
+ did?: string;
79
+ skills?: string[];
80
+ domains?: string[];
81
+ a2aVersion?: string;
82
+ mcpVersion?: string;
83
+ profileURI?: string;
84
+ x402Support?: boolean;
85
+ trustModels?: string[];
86
+ };
87
+ /** Minimal resolved .agnt name. */
88
+ export type AgntNameLike = {
89
+ name: string;
90
+ owner: string;
91
+ records: AgntRecordLike;
92
+ };
93
+ /** The parsed identity link stored on the .agnt resolver. */
94
+ export type AgntIdentityLink = {
95
+ /** CAIP-2 chain ID (e.g. "eip155:1"). */
96
+ chainId: string;
97
+ /** ERC-8004 registry contract address. */
98
+ registry: string;
99
+ /** ERC-8004 agent token ID. */
100
+ agentId: number;
101
+ };
102
+ /** Options for bridge conversion. */
103
+ export type ToRegistrationFileOptions = {
104
+ /** Override active flag (default: true). */
105
+ active?: boolean;
106
+ /** Override image URL. */
107
+ image?: string;
108
+ /** Additional registrations to include. */
109
+ extraRegistrations?: Agent0Registration[];
110
+ /** Additional services to include. */
111
+ extraServices?: Agent0Service[];
112
+ };
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * ERC-8004 types and .agnt bridge structures.
3
+ * @see https://eips.ethereum.org/EIPS/eip-8004
4
+ * @see https://www.8004.org/build
5
+ */
6
+ export {};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@agnt-id/agent0",
3
+ "version": "0.1.0",
4
+ "description": "Bridge between .agnt names and ERC-8004 agent identities",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "prepublishOnly": "tsc"
21
+ },
22
+ "keywords": [
23
+ "agnt",
24
+ "agent0",
25
+ "erc-8004",
26
+ "agent-identity",
27
+ "naming",
28
+ "bridge",
29
+ "ethereum",
30
+ "web3"
31
+ ],
32
+ "license": "MIT",
33
+ "peerDependencies": {
34
+ "@agnt-id/resolve": ">=0.1.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@agnt-id/resolve": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^5.9.3"
43
+ }
44
+ }