@openserv-labs/client 2.0.2 → 2.1.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 +142 -2
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +4 -0
- package/dist/erc8004-abi.d.ts +113 -0
- package/dist/erc8004-abi.d.ts.map +1 -0
- package/dist/erc8004-abi.js +123 -0
- package/dist/erc8004-api.d.ts +318 -0
- package/dist/erc8004-api.d.ts.map +1 -0
- package/dist/erc8004-api.js +558 -0
- package/dist/erc8004-contracts.d.ts +92 -0
- package/dist/erc8004-contracts.d.ts.map +1 -0
- package/dist/erc8004-contracts.js +250 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/triggers-api.d.ts +4 -4
- package/dist/triggers-api.js +4 -4
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { PlatformClient } from "./client";
|
|
2
|
+
import type { Erc8004DeployRequest, Web3Wallet, ImportWeb3WalletRequest, CallableTrigger, PresignIpfsUrlResponse, SignFeedbackAuthResponse, WorkflowData } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* API for ERC-8004 agent identity operations on the OpenServ platform.
|
|
5
|
+
*
|
|
6
|
+
* ERC-8004 is an on-chain agent identity standard. This API enables:
|
|
7
|
+
* - Deploying workspace agents to the blockchain as ERC-8004 tokens
|
|
8
|
+
* - Managing web3 wallets associated with workspaces
|
|
9
|
+
* - Presigning IPFS URLs for uploading agent registration files
|
|
10
|
+
* - Querying callable triggers for on-chain service registration
|
|
11
|
+
* - Signing feedback auth for reputation interactions
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const client = new PlatformClient({ apiKey: 'your-key' });
|
|
16
|
+
*
|
|
17
|
+
* // Generate a web3 wallet for the workspace
|
|
18
|
+
* const wallet = await client.erc8004.generateWallet({ workflowId: 123 });
|
|
19
|
+
*
|
|
20
|
+
* // Get a presigned IPFS URL for uploading the agent card
|
|
21
|
+
* const { url } = await client.erc8004.presignIpfsUrl({ workflowId: 123 });
|
|
22
|
+
*
|
|
23
|
+
* // Deploy to ERC-8004
|
|
24
|
+
* await client.erc8004.deploy({
|
|
25
|
+
* workflowId: 123,
|
|
26
|
+
* erc8004AgentId: '8453:42',
|
|
27
|
+
* stringifiedAgentCard: JSON.stringify(registrationFile),
|
|
28
|
+
* walletAddress: '0x...',
|
|
29
|
+
* network: 'base',
|
|
30
|
+
* chainId: 8453,
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class Erc8004API {
|
|
35
|
+
private client;
|
|
36
|
+
constructor(client: PlatformClient);
|
|
37
|
+
/**
|
|
38
|
+
* Deploy a workspace agent to the ERC-8004 identity registry.
|
|
39
|
+
*
|
|
40
|
+
* This records the deployment details in the platform database. The actual
|
|
41
|
+
* on-chain registration should be performed separately using the agent0 SDK.
|
|
42
|
+
* Call this method both before and after blockchain registration to keep
|
|
43
|
+
* the platform in sync.
|
|
44
|
+
*
|
|
45
|
+
* If the deploy fails (e.g. insufficient ETH for gas), the error is
|
|
46
|
+
* enriched with the workspace wallet address and instructions for funding
|
|
47
|
+
* it so you can retry.
|
|
48
|
+
*
|
|
49
|
+
* @param params - Deployment parameters
|
|
50
|
+
* @param params.workflowId - The workflow (workspace) ID to deploy
|
|
51
|
+
* @param params.erc8004AgentId - Agent ID in format "chainId:tokenId"
|
|
52
|
+
* @param params.stringifiedAgentCard - JSON-stringified registration file
|
|
53
|
+
* @param params.latestDeploymentTransactionHash - Transaction hash from on-chain registration
|
|
54
|
+
* @param params.latestDeploymentTimestamp - Timestamp of the deployment
|
|
55
|
+
* @param params.walletAddress - Wallet address that performed the deployment
|
|
56
|
+
* @param params.network - Network name (e.g., "base")
|
|
57
|
+
* @param params.chainId - Chain ID (e.g., 8453 for Base mainnet)
|
|
58
|
+
* @param params.rpcUrl - RPC URL for the chain
|
|
59
|
+
* @param params.swap - If true, swap USDC in the wallet to ETH for gas before deploying (not yet implemented)
|
|
60
|
+
* @returns The updated workflow data
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // Before blockchain registration (save initial state)
|
|
65
|
+
* await client.erc8004.deploy({
|
|
66
|
+
* workflowId: 123,
|
|
67
|
+
* erc8004AgentId: '',
|
|
68
|
+
* stringifiedAgentCard: JSON.stringify(registrationFile),
|
|
69
|
+
* walletAddress: '0x...',
|
|
70
|
+
* network: 'base',
|
|
71
|
+
* chainId: 8453,
|
|
72
|
+
* rpcUrl: 'https://mainnet.base.org',
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // ... perform on-chain registration ...
|
|
76
|
+
*
|
|
77
|
+
* // After blockchain registration (save final state with tx hash)
|
|
78
|
+
* await client.erc8004.deploy({
|
|
79
|
+
* workflowId: 123,
|
|
80
|
+
* erc8004AgentId: '8453:42',
|
|
81
|
+
* stringifiedAgentCard: JSON.stringify(updatedRegistrationFile),
|
|
82
|
+
* latestDeploymentTransactionHash: '0xabc...',
|
|
83
|
+
* latestDeploymentTimestamp: new Date(),
|
|
84
|
+
* walletAddress: '0x...',
|
|
85
|
+
* network: 'base',
|
|
86
|
+
* chainId: 8453,
|
|
87
|
+
* rpcUrl: 'https://mainnet.base.org',
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
deploy(params: Erc8004DeployRequest & {
|
|
92
|
+
workflowId: number;
|
|
93
|
+
}): Promise<WorkflowData>;
|
|
94
|
+
/**
|
|
95
|
+
* Enrich a deploy error with the workspace wallet address and funding
|
|
96
|
+
* instructions. Called automatically when deploy() fails.
|
|
97
|
+
*/
|
|
98
|
+
private enrichDeployError;
|
|
99
|
+
/**
|
|
100
|
+
* Register (or re-deploy) a workspace agent on-chain as an ERC-8004 identity.
|
|
101
|
+
*
|
|
102
|
+
* This is a high-level method that orchestrates the entire deployment:
|
|
103
|
+
* 1. Reads workspace wallet and callable triggers
|
|
104
|
+
* 2. Builds the ERC-8004 agent card JSON
|
|
105
|
+
* 3. Uploads the agent card to IPFS via a presigned Pinata URL
|
|
106
|
+
* 4. Registers on-chain (first deploy) or updates the URI (re-deploy)
|
|
107
|
+
* 5. Saves the deployment state to the platform
|
|
108
|
+
*
|
|
109
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
110
|
+
* @param params.privateKey - Funded private key for on-chain transactions (must have ETH for gas)
|
|
111
|
+
* @param params.chainId - Chain ID (default: 8453 for Base mainnet)
|
|
112
|
+
* @param params.rpcUrl - RPC URL (default: "https://mainnet.base.org")
|
|
113
|
+
* @param params.name - Agent name override (falls back to "ERC-8004 Agent")
|
|
114
|
+
* @param params.description - Agent description override
|
|
115
|
+
* @returns Deployment result with agentId, IPFS CID, transaction hash, and URLs
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const result = await client.erc8004.registerOnChain({
|
|
120
|
+
* workflowId: 123,
|
|
121
|
+
* privateKey: '0x...',
|
|
122
|
+
* name: 'My AI Agent',
|
|
123
|
+
* description: 'An agent that does amazing things',
|
|
124
|
+
* });
|
|
125
|
+
* console.log(result.agentId); // "8453:42"
|
|
126
|
+
* console.log(result.txHash); // "0xabc..."
|
|
127
|
+
* console.log(result.ipfsCid); // "bafkrei..."
|
|
128
|
+
* console.log(result.blockExplorerUrl); // "https://basescan.org/tx/0xabc..."
|
|
129
|
+
* console.log(result.scanUrl); // "https://www.8004scan.io/agents/base/42"
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
registerOnChain(params: {
|
|
133
|
+
workflowId: number;
|
|
134
|
+
privateKey: string;
|
|
135
|
+
chainId?: number;
|
|
136
|
+
rpcUrl?: string;
|
|
137
|
+
name?: string;
|
|
138
|
+
description?: string;
|
|
139
|
+
}): Promise<RegisterOnChainResult>;
|
|
140
|
+
/**
|
|
141
|
+
* Upload a JSON string to IPFS using a presigned Pinata URL.
|
|
142
|
+
*/
|
|
143
|
+
private uploadToIpfs;
|
|
144
|
+
/**
|
|
145
|
+
* Extract the agent token ID from a registration transaction receipt.
|
|
146
|
+
* Looks for the Registered event first, then falls back to Transfer event.
|
|
147
|
+
*/
|
|
148
|
+
private extractAgentIdFromReceipt;
|
|
149
|
+
/**
|
|
150
|
+
* Get a presigned IPFS URL for uploading an agent registration file.
|
|
151
|
+
*
|
|
152
|
+
* The returned URL is a signed Pinata upload URL that expires in 60 seconds.
|
|
153
|
+
* Use it to upload the agent's registration file (agent card) to IPFS before
|
|
154
|
+
* on-chain registration.
|
|
155
|
+
*
|
|
156
|
+
* @param params - Parameters
|
|
157
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
158
|
+
* @returns Object containing the presigned IPFS upload URL
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const { url } = await client.erc8004.presignIpfsUrl({ workflowId: 123 });
|
|
163
|
+
* // Use the URL to upload agent card to IPFS within 60 seconds
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
presignIpfsUrl(params: {
|
|
167
|
+
workflowId: number;
|
|
168
|
+
}): Promise<PresignIpfsUrlResponse>;
|
|
169
|
+
/**
|
|
170
|
+
* Get the web3 wallet associated with a workspace.
|
|
171
|
+
*
|
|
172
|
+
* @param params - Parameters
|
|
173
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
174
|
+
* @returns The web3 wallet details
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const wallet = await client.erc8004.getWallet({ workflowId: 123 });
|
|
179
|
+
* console.log(wallet.address, wallet.deployed, wallet.erc8004AgentId);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
getWallet(params: {
|
|
183
|
+
workflowId: number;
|
|
184
|
+
}): Promise<Web3Wallet>;
|
|
185
|
+
/**
|
|
186
|
+
* Generate a new web3 wallet for a workspace.
|
|
187
|
+
*
|
|
188
|
+
* Creates a fresh wallet with a server-generated private key. The wallet
|
|
189
|
+
* is stored securely on the platform and used for ERC-8004 operations.
|
|
190
|
+
* A workspace can only have one web3 wallet.
|
|
191
|
+
*
|
|
192
|
+
* @param params - Parameters
|
|
193
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
194
|
+
* @returns The generated web3 wallet
|
|
195
|
+
* @throws Error if the workspace already has a web3 wallet
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const wallet = await client.erc8004.generateWallet({ workflowId: 123 });
|
|
200
|
+
* console.log('Wallet address:', wallet.address);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
generateWallet(params: {
|
|
204
|
+
workflowId: number;
|
|
205
|
+
}): Promise<Web3Wallet>;
|
|
206
|
+
/**
|
|
207
|
+
* Import an existing web3 wallet into a workspace.
|
|
208
|
+
*
|
|
209
|
+
* Use this to associate a pre-existing wallet (e.g., one that already has
|
|
210
|
+
* an ERC-8004 registration) with a workspace.
|
|
211
|
+
* A workspace can only have one web3 wallet.
|
|
212
|
+
*
|
|
213
|
+
* @param params - Import parameters
|
|
214
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
215
|
+
* @param params.address - Wallet address
|
|
216
|
+
* @param params.network - Network name (e.g., "base")
|
|
217
|
+
* @param params.chainId - Chain ID (e.g., 8453)
|
|
218
|
+
* @param params.privateKey - Wallet private key
|
|
219
|
+
* @returns The imported web3 wallet
|
|
220
|
+
* @throws Error if the workspace already has a web3 wallet
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* const wallet = await client.erc8004.importWallet({
|
|
225
|
+
* workflowId: 123,
|
|
226
|
+
* address: '0x...',
|
|
227
|
+
* network: 'base',
|
|
228
|
+
* chainId: 8453,
|
|
229
|
+
* privateKey: '0x...',
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
importWallet(params: ImportWeb3WalletRequest & {
|
|
234
|
+
workflowId: number;
|
|
235
|
+
}): Promise<Web3Wallet>;
|
|
236
|
+
/**
|
|
237
|
+
* Delete the web3 wallet associated with a workspace.
|
|
238
|
+
*
|
|
239
|
+
* This removes the wallet record from the platform. Note that the on-chain
|
|
240
|
+
* ERC-8004 registration is not affected -- this only removes the platform's
|
|
241
|
+
* association.
|
|
242
|
+
*
|
|
243
|
+
* @param params - Parameters
|
|
244
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* await client.erc8004.deleteWallet({ workflowId: 123 });
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
deleteWallet(params: {
|
|
252
|
+
workflowId: number;
|
|
253
|
+
}): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Sign a feedback auth message for a buyer address.
|
|
256
|
+
*
|
|
257
|
+
* This is used for the ERC-8004 reputation system. The workspace's web3 wallet
|
|
258
|
+
* signs an auth message that allows a buyer to submit feedback/reputation
|
|
259
|
+
* for the agent on-chain.
|
|
260
|
+
*
|
|
261
|
+
* @param params - Parameters
|
|
262
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
263
|
+
* @param params.buyerAddress - The buyer's wallet address to authorize
|
|
264
|
+
* @returns Object containing the signed feedback auth
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const { signature } = await client.erc8004.signFeedbackAuth({
|
|
269
|
+
* workflowId: 123,
|
|
270
|
+
* buyerAddress: '0xBuyer...',
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
signFeedbackAuth(params: {
|
|
275
|
+
workflowId: number;
|
|
276
|
+
buyerAddress: string;
|
|
277
|
+
}): Promise<SignFeedbackAuthResponse>;
|
|
278
|
+
/**
|
|
279
|
+
* Get callable triggers for a workspace.
|
|
280
|
+
*
|
|
281
|
+
* Returns the list of triggers that can be called externally, along with
|
|
282
|
+
* their input schemas and endpoint URLs. This is used during ERC-8004
|
|
283
|
+
* deployment to register the agent's available services on-chain.
|
|
284
|
+
*
|
|
285
|
+
* @param params - Parameters
|
|
286
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
287
|
+
* @returns Array of callable triggers with their schemas and endpoints
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const triggers = await client.erc8004.getCallableTriggers({ workflowId: 123 });
|
|
292
|
+
* for (const trigger of triggers) {
|
|
293
|
+
* console.log(trigger.name, trigger.webEndpoint);
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
getCallableTriggers(params: {
|
|
298
|
+
workflowId: number;
|
|
299
|
+
}): Promise<CallableTrigger[]>;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Result of a successful on-chain ERC-8004 registration.
|
|
303
|
+
*/
|
|
304
|
+
export interface RegisterOnChainResult {
|
|
305
|
+
/** ERC-8004 agent ID in format "chainId:tokenId" (e.g., "8453:42") */
|
|
306
|
+
agentId: string;
|
|
307
|
+
/** IPFS CID of the uploaded agent card */
|
|
308
|
+
ipfsCid: string;
|
|
309
|
+
/** Transaction hash of the final on-chain transaction */
|
|
310
|
+
txHash: string;
|
|
311
|
+
/** URL to view the agent card on IPFS */
|
|
312
|
+
agentCardUrl: string;
|
|
313
|
+
/** URL to view the transaction on the block explorer */
|
|
314
|
+
blockExplorerUrl: string;
|
|
315
|
+
/** URL to view the agent on 8004scan.io (e.g., "https://www.8004scan.io/agents/base/42") */
|
|
316
|
+
scanUrl: string;
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=erc8004-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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