@openagentmarket/nodejs 1.0.0 → 1.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.
package/dist/index.d.ts CHANGED
@@ -2,9 +2,11 @@ import { type AgentMiddleware } from '@xmtp/agent-sdk';
2
2
  import { type Signer } from 'ethers';
3
3
  import { type PaymentConfig } from './skills/payment.js';
4
4
  import { type AgentCard } from './skills/discovery.js';
5
+ import { type AgentConfig as RegistryAgentConfig, type RegisterResult } from './registry.js';
5
6
  export * from './skills/payment.js';
6
7
  export * from './skills/discovery.js';
7
8
  export * from './skills/job.js';
9
+ export * from './registry.js';
8
10
  export interface OpenAgentConfig {
9
11
  signer?: Signer;
10
12
  mnemonic?: string;
@@ -32,5 +34,15 @@ export declare class OpenAgent {
32
34
  * Start listening to the network.
33
35
  */
34
36
  start(): Promise<void>;
37
+ /**
38
+ * Register this agent on the ERC-8004 Registry (Base).
39
+ * @param info Configuration for registration (name, image, endpoints)
40
+ * @param secrets Secrets for registration (privateKey, pinataJwt)
41
+ */
42
+ register(info: RegistryAgentConfig, secrets: {
43
+ privateKey: string;
44
+ pinataJwt: string;
45
+ rpcUrl?: string;
46
+ }): Promise<RegisterResult>;
35
47
  }
36
48
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,KAAK,MAAM,EAAoB,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGvE,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAEhC,MAAM,WAAW,eAAe;IAC5B,MAAM,CA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AC,EAAE,aAAa,CAAC;IACxB,GAAG,CAAC,EAAE,YAAY,GAAG,KAAK,GAAG,OAAO,CAAC;CACxC;AAED,qBAAa,SAAS;IAClB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,MAAM,CAAkB;IAEhC,OAAO;WAMa,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IAoCvE,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACI,GAAG,CAAC,UAAU,EAAE,eAAe;IAItC;;;;OAIG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC;IAIrE;;OAEG;IACU,KAAK;IAKlB;;;;OAIG;IACU,QAAQ,CACjB,IAAI,EAAE,mBAAmB,EACzB,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GACpE,OAAO,CAAC,cAAc,CAAC;CAS7B"}
package/dist/index.js CHANGED
@@ -3,9 +3,11 @@ import { Wallet, getBytes } from 'ethers';
3
3
  import { paymentSkill } from './skills/payment.js';
4
4
  import { discoverySkill } from './skills/discovery.js';
5
5
  import { jobSkill } from './skills/job.js';
6
+ import { Registry } from './registry.js';
6
7
  export * from './skills/payment.js';
7
8
  export * from './skills/discovery.js';
8
9
  export * from './skills/job.js';
10
+ export * from './registry.js';
9
11
  export class OpenAgent {
10
12
  agent;
11
13
  config;
@@ -30,7 +32,16 @@ export class OpenAgent {
30
32
  };
31
33
  }
32
34
  else if (config.signer) {
33
- signer = config.signer;
35
+ const s = config.signer;
36
+ signer = {
37
+ getAddress: async () => s.getAddress(),
38
+ getIdentifier: async () => ({ identifier: await s.getAddress(), identifierKind: 0 }),
39
+ signMessage: async (message) => {
40
+ const sig = await s.signMessage(message);
41
+ return getBytes(sig);
42
+ },
43
+ type: "EOA"
44
+ };
34
45
  }
35
46
  else {
36
47
  throw new Error("OpenAgent requires either 'mnemonic' or 'signer' in config.");
@@ -71,4 +82,17 @@ export class OpenAgent {
71
82
  console.log(`OpenAgent starting... Address: ${this.agent.address}`);
72
83
  await this.agent.start();
73
84
  }
85
+ /**
86
+ * Register this agent on the ERC-8004 Registry (Base).
87
+ * @param info Configuration for registration (name, image, endpoints)
88
+ * @param secrets Secrets for registration (privateKey, pinataJwt)
89
+ */
90
+ async register(info, secrets) {
91
+ const registry = new Registry({
92
+ signer: secrets.privateKey,
93
+ pinataJwt: secrets.pinataJwt,
94
+ rpcUrl: secrets.rpcUrl
95
+ });
96
+ return await registry.register(info);
97
+ }
74
98
  }
@@ -0,0 +1,27 @@
1
+ export interface AgentConfig {
2
+ name: string;
3
+ description: string;
4
+ image: string;
5
+ a2aEndpoint: string;
6
+ signer?: string;
7
+ pinataJwt?: string;
8
+ rpcUrl?: string;
9
+ metadata?: Record<string, any>;
10
+ }
11
+ export interface RegisterResult {
12
+ agentId: string;
13
+ agentURI: string;
14
+ txHash: string;
15
+ explorerUrl: string;
16
+ }
17
+ export declare class Registry {
18
+ private config;
19
+ private sdk;
20
+ constructor(config: {
21
+ signer: string;
22
+ pinataJwt: string;
23
+ rpcUrl?: string;
24
+ });
25
+ register(agentInfo: AgentConfig): Promise<RegisterResult>;
26
+ }
27
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IAEpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,QAAQ;IAGL,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,GAAG,CAAM;gBAEG,MAAM,EAAE;QACxB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB;IAUY,QAAQ,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;CA6CzE"}
@@ -0,0 +1,47 @@
1
+ import { SDK } from 'agent0-sdk';
2
+ export class Registry {
3
+ config;
4
+ sdk;
5
+ constructor(config) {
6
+ this.config = config;
7
+ this.sdk = new SDK({
8
+ chainId: 8453, // Base
9
+ rpcUrl: config.rpcUrl || 'https://mainnet.base.org',
10
+ signer: config.signer,
11
+ ipfs: 'pinata',
12
+ pinataJwt: config.pinataJwt,
13
+ });
14
+ }
15
+ async register(agentInfo) {
16
+ console.log(`[OpenAgent] 📝 Creating agent: ${agentInfo.name}...`);
17
+ const agent = this.sdk.createAgent(agentInfo.name, agentInfo.description, agentInfo.image);
18
+ console.log(`[OpenAgent] 🔗 Setting A2A endpoint: ${agentInfo.a2aEndpoint}`);
19
+ await agent.setA2A(agentInfo.a2aEndpoint);
20
+ agent.setTrust(true, false, false);
21
+ agent.setActive(true);
22
+ agent.setX402Support(true);
23
+ // Add protocol metadata + user custom metadata
24
+ const finalMetadata = {
25
+ ...agentInfo.metadata,
26
+ protocol: "openagentmarket"
27
+ };
28
+ if (typeof agent.setMetadata === 'function') {
29
+ agent.setMetadata(finalMetadata);
30
+ }
31
+ console.log('[OpenAgent] ⛓️ Registering on Base...');
32
+ const txHandle = await agent.registerIPFS();
33
+ const { result } = await txHandle.waitMined();
34
+ // txHandle usually contains the hash if it's a ContractTransactionResponse
35
+ const txHash = txHandle.hash || "unknown";
36
+ const agentId = result.agentId;
37
+ if (!agentId)
38
+ throw new Error("Registration failed: No Agent ID returned");
39
+ const agentIdNum = agentId.split(':')[1] || agentId;
40
+ return {
41
+ agentId: agentId,
42
+ agentURI: result.agentURI || "",
43
+ txHash: txHash,
44
+ explorerUrl: `https://www.8004scan.io/agents/base/${agentIdNum}`
45
+ };
46
+ }
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openagentmarket/nodejs",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "OpenAgent Market Node.js SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,6 +24,7 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@xmtp/agent-sdk": "^1.0.0",
27
+ "agent0-sdk": "^1.5.3",
27
28
  "dotenv": "^16.4.0",
28
29
  "ethers": "^6.10.0"
29
30
  },
package/src/index.ts CHANGED
@@ -3,10 +3,12 @@ import { type Signer, Wallet, getBytes } from 'ethers';
3
3
  import { paymentSkill, type PaymentConfig } from './skills/payment.js';
4
4
  import { discoverySkill, type AgentCard } from './skills/discovery.js';
5
5
  import { jobSkill } from './skills/job.js';
6
+ import { Registry, type AgentConfig as RegistryAgentConfig, type RegisterResult } from './registry.js';
6
7
 
7
8
  export * from './skills/payment.js';
8
9
  export * from './skills/discovery.js';
9
10
  export * from './skills/job.js';
11
+ export * from './registry.js';
10
12
 
11
13
  export interface OpenAgentConfig {
12
14
  signer?: Signer;
@@ -42,7 +44,16 @@ export class OpenAgent {
42
44
  type: "EOA"
43
45
  };
44
46
  } else if (config.signer) {
45
- signer = config.signer;
47
+ const s = config.signer;
48
+ signer = {
49
+ getAddress: async () => s.getAddress(),
50
+ getIdentifier: async () => ({ identifier: await s.getAddress(), identifierKind: 0 }),
51
+ signMessage: async (message: string | Uint8Array) => {
52
+ const sig = await s.signMessage(message);
53
+ return getBytes(sig);
54
+ },
55
+ type: "EOA"
56
+ };
46
57
  } else {
47
58
  throw new Error("OpenAgent requires either 'mnemonic' or 'signer' in config.");
48
59
  }
@@ -88,4 +99,22 @@ export class OpenAgent {
88
99
  console.log(`OpenAgent starting... Address: ${this.agent.address}`);
89
100
  await this.agent.start();
90
101
  }
102
+
103
+ /**
104
+ * Register this agent on the ERC-8004 Registry (Base).
105
+ * @param info Configuration for registration (name, image, endpoints)
106
+ * @param secrets Secrets for registration (privateKey, pinataJwt)
107
+ */
108
+ public async register(
109
+ info: RegistryAgentConfig,
110
+ secrets: { privateKey: string; pinataJwt: string; rpcUrl?: string }
111
+ ): Promise<RegisterResult> {
112
+ const registry = new Registry({
113
+ signer: secrets.privateKey,
114
+ pinataJwt: secrets.pinataJwt,
115
+ rpcUrl: secrets.rpcUrl
116
+ });
117
+
118
+ return await registry.register(info);
119
+ }
91
120
  }
@@ -0,0 +1,85 @@
1
+ import { SDK } from 'agent0-sdk';
2
+ import { Wallet } from 'ethers';
3
+
4
+ export interface AgentConfig {
5
+ name: string;
6
+ description: string;
7
+ image: string;
8
+ a2aEndpoint: string;
9
+ // Optional: if not provided, will look for env vars or throw
10
+ signer?: string; // Private key
11
+ pinataJwt?: string;
12
+ rpcUrl?: string;
13
+ metadata?: Record<string, any>; // Custom metadata
14
+ }
15
+
16
+ export interface RegisterResult {
17
+ agentId: string;
18
+ agentURI: string;
19
+ txHash: string;
20
+ explorerUrl: string;
21
+ }
22
+
23
+ export class Registry {
24
+ private sdk: SDK;
25
+
26
+ constructor(private config: {
27
+ signer: string;
28
+ pinataJwt: string;
29
+ rpcUrl?: string;
30
+ }) {
31
+ this.sdk = new SDK({
32
+ chainId: 8453, // Base
33
+ rpcUrl: config.rpcUrl || 'https://mainnet.base.org',
34
+ signer: config.signer,
35
+ ipfs: 'pinata',
36
+ pinataJwt: config.pinataJwt,
37
+ });
38
+ }
39
+
40
+ public async register(agentInfo: AgentConfig): Promise<RegisterResult> {
41
+ console.log(`[OpenAgent] 📝 Creating agent: ${agentInfo.name}...`);
42
+
43
+ const agent = this.sdk.createAgent(
44
+ agentInfo.name,
45
+ agentInfo.description,
46
+ agentInfo.image
47
+ );
48
+
49
+ console.log(`[OpenAgent] 🔗 Setting A2A endpoint: ${agentInfo.a2aEndpoint}`);
50
+ await agent.setA2A(agentInfo.a2aEndpoint);
51
+
52
+ agent.setTrust(true, false, false);
53
+ agent.setActive(true);
54
+ agent.setX402Support(true);
55
+
56
+ // Add protocol metadata + user custom metadata
57
+ const finalMetadata = {
58
+ ...agentInfo.metadata,
59
+ protocol: "openagentmarket"
60
+ };
61
+
62
+ if (typeof (agent as any).setMetadata === 'function') {
63
+ (agent as any).setMetadata(finalMetadata);
64
+ }
65
+
66
+ console.log('[OpenAgent] ⛓️ Registering on Base...');
67
+ const txHandle = await agent.registerIPFS();
68
+ const { result } = await txHandle.waitMined();
69
+
70
+ // txHandle usually contains the hash if it's a ContractTransactionResponse
71
+ const txHash = (txHandle as any).hash || "unknown";
72
+
73
+ const agentId = result.agentId;
74
+ if (!agentId) throw new Error("Registration failed: No Agent ID returned");
75
+
76
+ const agentIdNum = agentId.split(':')[1] || agentId;
77
+
78
+ return {
79
+ agentId: agentId,
80
+ agentURI: result.agentURI || "",
81
+ txHash: txHash,
82
+ explorerUrl: `https://www.8004scan.io/agents/base/${agentIdNum}`
83
+ };
84
+ }
85
+ }