@openserv-labs/client 2.0.2 → 2.1.2
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 +189 -0
- package/dist/erc8004-api.d.ts.map +1 -0
- package/dist/erc8004-api.js +491 -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 +27 -5
- package/dist/triggers-api.d.ts.map +1 -1
- package/dist/triggers-api.js +26 -4
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/workflows-api.d.ts +110 -1
- package/dist/workflows-api.d.ts.map +1 -1
- package/dist/workflows-api.js +112 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -307,6 +307,137 @@ console.log(`Pay to: ${preflight.x402WalletAddress}`)
|
|
|
307
307
|
console.log(`Input schema: ${JSON.stringify(preflight.jsonSchema)}`)
|
|
308
308
|
```
|
|
309
309
|
|
|
310
|
+
### ERC-8004 (Agent Identity)
|
|
311
|
+
|
|
312
|
+
ERC-8004 is an on-chain agent identity standard. The `registerOnChain` method handles the entire flow in a single call -- building the agent card, uploading to IPFS, and registering on-chain.
|
|
313
|
+
|
|
314
|
+
> **Note**: The wallet used for `registerOnChain` must have ETH for gas on the target chain (Base mainnet by default).
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
// Register an agent on-chain in one call
|
|
318
|
+
const result = await client.erc8004.registerOnChain({
|
|
319
|
+
workflowId: 123,
|
|
320
|
+
privateKey: process.env.WALLET_PRIVATE_KEY!,
|
|
321
|
+
name: 'My AI Agent',
|
|
322
|
+
description: 'An agent that does amazing things',
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
console.log(result.agentId) // "8453:42"
|
|
326
|
+
console.log(result.txHash) // "0xabc..."
|
|
327
|
+
console.log(result.ipfsCid) // "bafkrei..."
|
|
328
|
+
console.log(result.agentCardUrl) // "https://gateway.pinata.cloud/ipfs/bafkrei..."
|
|
329
|
+
console.log(result.blockExplorerUrl) // "https://basescan.org/tx/0xabc..."
|
|
330
|
+
console.log(result.scanUrl) // "https://www.8004scan.io/agents/base/42"
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Under the hood, `registerOnChain` does the following:
|
|
334
|
+
|
|
335
|
+
1. Reads the workspace wallet and callable triggers
|
|
336
|
+
2. Builds the ERC-8004 agent card JSON (with services and wallet info)
|
|
337
|
+
3. Uploads the agent card to IPFS via a presigned Pinata URL
|
|
338
|
+
4. Registers on-chain (first deploy) or updates the URI (re-deploy)
|
|
339
|
+
5. Saves the deployment state back to the platform
|
|
340
|
+
|
|
341
|
+
Re-deploying (updating an existing registration) uses the same call -- it automatically detects whether the workspace already has an `erc8004AgentId` and uploads a fresh agent card with the latest name, description, services, and wallet info, then updates the on-chain URI to point to it. No new token is minted; only the metadata changes.
|
|
342
|
+
|
|
343
|
+
#### Supported Chains
|
|
344
|
+
|
|
345
|
+
`registerOnChain` defaults to Base mainnet (`chainId: 8453`). You can target any supported chain:
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
// Deploy on a different chain
|
|
349
|
+
const result = await client.erc8004.registerOnChain({
|
|
350
|
+
workflowId: 123,
|
|
351
|
+
privateKey: process.env.WALLET_PRIVATE_KEY!,
|
|
352
|
+
chainId: 42161, // Arbitrum One
|
|
353
|
+
rpcUrl: 'https://arb1.arbitrum.io/rpc',
|
|
354
|
+
name: 'My Agent',
|
|
355
|
+
})
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
**Mainnets:** Ethereum (1), Base (8453), Polygon (137), Arbitrum One (42161), Celo (42220), Gnosis (100), Scroll (534352), Taiko (167000), BNB Smart Chain (56)
|
|
359
|
+
|
|
360
|
+
**Testnets:** Ethereum Sepolia (11155111), Base Sepolia (84532), Polygon Amoy (80002), Arbitrum Sepolia (421614), Celo Alfajores (44787), Scroll Sepolia (534351), BNB Testnet (97)
|
|
361
|
+
|
|
362
|
+
You can also query supported chains programmatically:
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
import { listErc8004ChainIds, getErc8004Chain } from '@openserv-labs/client'
|
|
366
|
+
|
|
367
|
+
const mainnets = listErc8004ChainIds('mainnet') // [1, 8453, 137, ...]
|
|
368
|
+
const testnets = listErc8004ChainIds('testnet') // [11155111, 84532, ...]
|
|
369
|
+
|
|
370
|
+
const baseConfig = getErc8004Chain(8453)
|
|
371
|
+
console.log(baseConfig?.contracts.IDENTITY_REGISTRY)
|
|
372
|
+
// "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432"
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
#### Low-level ERC-8004 Operations
|
|
376
|
+
|
|
377
|
+
For more control over individual steps, use the lower-level methods directly:
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
// Generate a web3 wallet for the workspace
|
|
381
|
+
const wallet = await client.workflows.generateWallet({ id: 123 })
|
|
382
|
+
console.log('Wallet address:', wallet.address)
|
|
383
|
+
|
|
384
|
+
// Import an existing wallet
|
|
385
|
+
const imported = await client.workflows.importWallet({
|
|
386
|
+
id: 123,
|
|
387
|
+
address: '0x...',
|
|
388
|
+
network: 'base',
|
|
389
|
+
chainId: 8453,
|
|
390
|
+
privateKey: '0x...'
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
// Get the workspace wallet
|
|
394
|
+
const existing = await client.workflows.getWallet({ id: 123 })
|
|
395
|
+
console.log(existing.deployed, existing.erc8004AgentId)
|
|
396
|
+
|
|
397
|
+
// Delete the workspace wallet
|
|
398
|
+
await client.workflows.deleteWallet({ id: 123 })
|
|
399
|
+
|
|
400
|
+
// Get a presigned IPFS URL for uploading the agent card
|
|
401
|
+
const { url } = await client.erc8004.presignIpfsUrl({ workflowId: 123 })
|
|
402
|
+
// Upload agent card to IPFS within 60 seconds using the signed URL
|
|
403
|
+
|
|
404
|
+
// Deploy to ERC-8004 (before on-chain registration)
|
|
405
|
+
await client.erc8004.deploy({
|
|
406
|
+
workflowId: 123,
|
|
407
|
+
erc8004AgentId: '',
|
|
408
|
+
stringifiedAgentCard: JSON.stringify(registrationFile),
|
|
409
|
+
walletAddress: '0x...',
|
|
410
|
+
network: 'base',
|
|
411
|
+
chainId: 8453,
|
|
412
|
+
rpcUrl: 'https://mainnet.base.org'
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
// Deploy to ERC-8004 (after on-chain registration, with tx hash)
|
|
416
|
+
await client.erc8004.deploy({
|
|
417
|
+
workflowId: 123,
|
|
418
|
+
erc8004AgentId: '8453:42',
|
|
419
|
+
stringifiedAgentCard: JSON.stringify(updatedRegistrationFile),
|
|
420
|
+
latestDeploymentTransactionHash: '0xabc...',
|
|
421
|
+
latestDeploymentTimestamp: new Date(),
|
|
422
|
+
walletAddress: '0x...',
|
|
423
|
+
network: 'base',
|
|
424
|
+
chainId: 8453,
|
|
425
|
+
rpcUrl: 'https://mainnet.base.org'
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
// Get callable triggers for on-chain service registration
|
|
429
|
+
const callableTriggers = await client.erc8004.getCallableTriggers({ workflowId: 123 })
|
|
430
|
+
for (const trigger of callableTriggers) {
|
|
431
|
+
console.log(trigger.name, trigger.webEndpoint)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Sign feedback auth for the reputation system
|
|
435
|
+
const { signature } = await client.workflows.signFeedbackAuth({
|
|
436
|
+
id: 123,
|
|
437
|
+
buyerAddress: '0xBuyer...'
|
|
438
|
+
})
|
|
439
|
+
```
|
|
440
|
+
|
|
310
441
|
### Integrations
|
|
311
442
|
|
|
312
443
|
Manage integration connections for triggers and external services.
|
|
@@ -556,9 +687,9 @@ triggers.webhook({
|
|
|
556
687
|
description: 'Receives data from external systems for processing',
|
|
557
688
|
input: { message: { type: 'string' } },
|
|
558
689
|
waitForCompletion: true,
|
|
559
|
-
timeout:
|
|
690
|
+
timeout: 600
|
|
560
691
|
})
|
|
561
|
-
// { type: 'webhook', name: '...', waitForCompletion: true, timeout:
|
|
692
|
+
// { type: 'webhook', name: '...', waitForCompletion: true, timeout: 600, inputSchema: {...} }
|
|
562
693
|
|
|
563
694
|
// Cron trigger
|
|
564
695
|
triggers.cron({
|
|
@@ -647,6 +778,15 @@ import type {
|
|
|
647
778
|
// x402 Payment types
|
|
648
779
|
X402PaymentRequest,
|
|
649
780
|
X402PaymentResult,
|
|
781
|
+
// ERC-8004 types
|
|
782
|
+
Erc8004DeployRequest,
|
|
783
|
+
RegisterOnChainResult,
|
|
784
|
+
Erc8004ChainConfig,
|
|
785
|
+
Web3Wallet,
|
|
786
|
+
ImportWeb3WalletRequest,
|
|
787
|
+
CallableTrigger,
|
|
788
|
+
PresignIpfsUrlResponse,
|
|
789
|
+
SignFeedbackAuthResponse,
|
|
650
790
|
// Provision types
|
|
651
791
|
ProvisionConfig,
|
|
652
792
|
ProvisionResult,
|
package/dist/client.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { TasksAPI } from "./tasks-api";
|
|
|
6
6
|
import { WorkflowsAPI } from "./workflows-api";
|
|
7
7
|
import { Web3API } from "./web3-api";
|
|
8
8
|
import { PaymentsAPI } from "./payments-api";
|
|
9
|
+
import { Erc8004API } from "./erc8004-api";
|
|
9
10
|
/**
|
|
10
11
|
* Client for interacting with the OpenServ Platform API.
|
|
11
12
|
*
|
|
@@ -40,6 +41,8 @@ export declare class PlatformClient {
|
|
|
40
41
|
readonly web3: Web3API;
|
|
41
42
|
/** API for x402 payments to access paid workflows */
|
|
42
43
|
readonly payments: PaymentsAPI;
|
|
44
|
+
/** API for ERC-8004 agent identity (deployment, wallets, IPFS, reputation) */
|
|
45
|
+
readonly erc8004: Erc8004API;
|
|
43
46
|
/**
|
|
44
47
|
* Get the raw axios client for advanced use cases.
|
|
45
48
|
* @returns The underlying axios instance
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAgB;IAElC,gHAAgH;IAChH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IACvC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,iCAAiC;IACjC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAE7B;;;OAGG;IACH,IAAI,SAAS,IAAI,aAAa,CAE7B;IAED;;;;;OAKG;IACG,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKnE;;;;;;OAMG;IACG,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,CAAC,CAAC;IAKb;;;;;;OAMG;IACG,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,CAAC,CAAC;IAKb;;;;;OAKG;IACG,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAKtE;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAsB3D;;;;;;;;;;;;;;;;;OAiBG;IACG,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmExD;;;;;;;;OAQG;IACH,oBAAoB,IAAI,MAAM,GAAG,SAAS;CAO3C"}
|
package/dist/client.js
CHANGED
|
@@ -13,6 +13,7 @@ const tasks_api_1 = require("./tasks-api");
|
|
|
13
13
|
const workflows_api_1 = require("./workflows-api");
|
|
14
14
|
const web3_api_1 = require("./web3-api");
|
|
15
15
|
const payments_api_1 = require("./payments-api");
|
|
16
|
+
const erc8004_api_1 = require("./erc8004-api");
|
|
16
17
|
const PLATFORM_URL = process.env.OPENSERV_API_URL || "https://api.openserv.ai";
|
|
17
18
|
/**
|
|
18
19
|
* Client for interacting with the OpenServ Platform API.
|
|
@@ -48,6 +49,8 @@ class PlatformClient {
|
|
|
48
49
|
web3;
|
|
49
50
|
/** API for x402 payments to access paid workflows */
|
|
50
51
|
payments;
|
|
52
|
+
/** API for ERC-8004 agent identity (deployment, wallets, IPFS, reputation) */
|
|
53
|
+
erc8004;
|
|
51
54
|
/**
|
|
52
55
|
* Get the raw axios client for advanced use cases.
|
|
53
56
|
* @returns The underlying axios instance
|
|
@@ -121,6 +124,7 @@ class PlatformClient {
|
|
|
121
124
|
this.workflows = new workflows_api_1.WorkflowsAPI(this);
|
|
122
125
|
this.web3 = new web3_api_1.Web3API(this);
|
|
123
126
|
this.payments = new payments_api_1.PaymentsAPI(this);
|
|
127
|
+
this.erc8004 = new erc8004_api_1.Erc8004API(this);
|
|
124
128
|
}
|
|
125
129
|
/**
|
|
126
130
|
* Authenticate using an Ethereum wallet (SIWE - EIP-4361).
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal IdentityRegistry ABI for ERC-8004 on-chain operations.
|
|
3
|
+
*
|
|
4
|
+
* Contains only the functions needed for agent registration:
|
|
5
|
+
* - register() — mint a new agent NFT
|
|
6
|
+
* - setAgentURI() — set/update the IPFS URI for an agent
|
|
7
|
+
* - tokenURI() — read the current URI (for verification)
|
|
8
|
+
* - Registered event — extract agentId from registration receipt
|
|
9
|
+
* - Transfer event — fallback for extracting agentId
|
|
10
|
+
*
|
|
11
|
+
* Sourced from the full ABI in the OpenServ monorepo:
|
|
12
|
+
* packages/ai/agent0/core/contracts.ts
|
|
13
|
+
*/
|
|
14
|
+
export declare const IDENTITY_REGISTRY_ABI: readonly [{
|
|
15
|
+
readonly inputs: readonly [];
|
|
16
|
+
readonly name: "register";
|
|
17
|
+
readonly outputs: readonly [{
|
|
18
|
+
readonly internalType: "uint256";
|
|
19
|
+
readonly name: "agentId";
|
|
20
|
+
readonly type: "uint256";
|
|
21
|
+
}];
|
|
22
|
+
readonly stateMutability: "nonpayable";
|
|
23
|
+
readonly type: "function";
|
|
24
|
+
}, {
|
|
25
|
+
readonly inputs: readonly [{
|
|
26
|
+
readonly internalType: "uint256";
|
|
27
|
+
readonly name: "agentId";
|
|
28
|
+
readonly type: "uint256";
|
|
29
|
+
}, {
|
|
30
|
+
readonly internalType: "string";
|
|
31
|
+
readonly name: "newURI";
|
|
32
|
+
readonly type: "string";
|
|
33
|
+
}];
|
|
34
|
+
readonly name: "setAgentURI";
|
|
35
|
+
readonly outputs: readonly [];
|
|
36
|
+
readonly stateMutability: "nonpayable";
|
|
37
|
+
readonly type: "function";
|
|
38
|
+
}, {
|
|
39
|
+
readonly inputs: readonly [{
|
|
40
|
+
readonly internalType: "uint256";
|
|
41
|
+
readonly name: "tokenId";
|
|
42
|
+
readonly type: "uint256";
|
|
43
|
+
}];
|
|
44
|
+
readonly name: "tokenURI";
|
|
45
|
+
readonly outputs: readonly [{
|
|
46
|
+
readonly internalType: "string";
|
|
47
|
+
readonly name: "";
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
}];
|
|
50
|
+
readonly stateMutability: "view";
|
|
51
|
+
readonly type: "function";
|
|
52
|
+
}, {
|
|
53
|
+
readonly anonymous: false;
|
|
54
|
+
readonly inputs: readonly [{
|
|
55
|
+
readonly indexed: true;
|
|
56
|
+
readonly internalType: "uint256";
|
|
57
|
+
readonly name: "agentId";
|
|
58
|
+
readonly type: "uint256";
|
|
59
|
+
}, {
|
|
60
|
+
readonly indexed: false;
|
|
61
|
+
readonly internalType: "string";
|
|
62
|
+
readonly name: "agentURI";
|
|
63
|
+
readonly type: "string";
|
|
64
|
+
}, {
|
|
65
|
+
readonly indexed: true;
|
|
66
|
+
readonly internalType: "address";
|
|
67
|
+
readonly name: "owner";
|
|
68
|
+
readonly type: "address";
|
|
69
|
+
}];
|
|
70
|
+
readonly name: "Registered";
|
|
71
|
+
readonly type: "event";
|
|
72
|
+
}, {
|
|
73
|
+
readonly anonymous: false;
|
|
74
|
+
readonly inputs: readonly [{
|
|
75
|
+
readonly indexed: true;
|
|
76
|
+
readonly internalType: "uint256";
|
|
77
|
+
readonly name: "agentId";
|
|
78
|
+
readonly type: "uint256";
|
|
79
|
+
}, {
|
|
80
|
+
readonly indexed: false;
|
|
81
|
+
readonly internalType: "string";
|
|
82
|
+
readonly name: "newURI";
|
|
83
|
+
readonly type: "string";
|
|
84
|
+
}, {
|
|
85
|
+
readonly indexed: true;
|
|
86
|
+
readonly internalType: "address";
|
|
87
|
+
readonly name: "updatedBy";
|
|
88
|
+
readonly type: "address";
|
|
89
|
+
}];
|
|
90
|
+
readonly name: "URIUpdated";
|
|
91
|
+
readonly type: "event";
|
|
92
|
+
}, {
|
|
93
|
+
readonly anonymous: false;
|
|
94
|
+
readonly inputs: readonly [{
|
|
95
|
+
readonly indexed: true;
|
|
96
|
+
readonly internalType: "address";
|
|
97
|
+
readonly name: "from";
|
|
98
|
+
readonly type: "address";
|
|
99
|
+
}, {
|
|
100
|
+
readonly indexed: true;
|
|
101
|
+
readonly internalType: "address";
|
|
102
|
+
readonly name: "to";
|
|
103
|
+
readonly type: "address";
|
|
104
|
+
}, {
|
|
105
|
+
readonly indexed: true;
|
|
106
|
+
readonly internalType: "uint256";
|
|
107
|
+
readonly name: "tokenId";
|
|
108
|
+
readonly type: "uint256";
|
|
109
|
+
}];
|
|
110
|
+
readonly name: "Transfer";
|
|
111
|
+
readonly type: "event";
|
|
112
|
+
}];
|
|
113
|
+
//# sourceMappingURL=erc8004-abi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc8004-abi.d.ts","sourceRoot":"","sources":["../src/erc8004-abi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0GxB,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IDENTITY_REGISTRY_ABI = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Minimal IdentityRegistry ABI for ERC-8004 on-chain operations.
|
|
6
|
+
*
|
|
7
|
+
* Contains only the functions needed for agent registration:
|
|
8
|
+
* - register() — mint a new agent NFT
|
|
9
|
+
* - setAgentURI() — set/update the IPFS URI for an agent
|
|
10
|
+
* - tokenURI() — read the current URI (for verification)
|
|
11
|
+
* - Registered event — extract agentId from registration receipt
|
|
12
|
+
* - Transfer event — fallback for extracting agentId
|
|
13
|
+
*
|
|
14
|
+
* Sourced from the full ABI in the OpenServ monorepo:
|
|
15
|
+
* packages/ai/agent0/core/contracts.ts
|
|
16
|
+
*/
|
|
17
|
+
exports.IDENTITY_REGISTRY_ABI = [
|
|
18
|
+
// register() — no-args overload, mints a new agent ID
|
|
19
|
+
{
|
|
20
|
+
inputs: [],
|
|
21
|
+
name: "register",
|
|
22
|
+
outputs: [{ internalType: "uint256", name: "agentId", type: "uint256" }],
|
|
23
|
+
stateMutability: "nonpayable",
|
|
24
|
+
type: "function",
|
|
25
|
+
},
|
|
26
|
+
// setAgentURI(uint256 agentId, string newURI)
|
|
27
|
+
{
|
|
28
|
+
inputs: [
|
|
29
|
+
{ internalType: "uint256", name: "agentId", type: "uint256" },
|
|
30
|
+
{ internalType: "string", name: "newURI", type: "string" },
|
|
31
|
+
],
|
|
32
|
+
name: "setAgentURI",
|
|
33
|
+
outputs: [],
|
|
34
|
+
stateMutability: "nonpayable",
|
|
35
|
+
type: "function",
|
|
36
|
+
},
|
|
37
|
+
// tokenURI(uint256 tokenId) — read the IPFS URI for verification
|
|
38
|
+
{
|
|
39
|
+
inputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }],
|
|
40
|
+
name: "tokenURI",
|
|
41
|
+
outputs: [{ internalType: "string", name: "", type: "string" }],
|
|
42
|
+
stateMutability: "view",
|
|
43
|
+
type: "function",
|
|
44
|
+
},
|
|
45
|
+
// Registered event — emitted on register()
|
|
46
|
+
{
|
|
47
|
+
anonymous: false,
|
|
48
|
+
inputs: [
|
|
49
|
+
{
|
|
50
|
+
indexed: true,
|
|
51
|
+
internalType: "uint256",
|
|
52
|
+
name: "agentId",
|
|
53
|
+
type: "uint256",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
indexed: false,
|
|
57
|
+
internalType: "string",
|
|
58
|
+
name: "agentURI",
|
|
59
|
+
type: "string",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
indexed: true,
|
|
63
|
+
internalType: "address",
|
|
64
|
+
name: "owner",
|
|
65
|
+
type: "address",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
name: "Registered",
|
|
69
|
+
type: "event",
|
|
70
|
+
},
|
|
71
|
+
// URIUpdated event — emitted on setAgentURI()
|
|
72
|
+
{
|
|
73
|
+
anonymous: false,
|
|
74
|
+
inputs: [
|
|
75
|
+
{
|
|
76
|
+
indexed: true,
|
|
77
|
+
internalType: "uint256",
|
|
78
|
+
name: "agentId",
|
|
79
|
+
type: "uint256",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
indexed: false,
|
|
83
|
+
internalType: "string",
|
|
84
|
+
name: "newURI",
|
|
85
|
+
type: "string",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
indexed: true,
|
|
89
|
+
internalType: "address",
|
|
90
|
+
name: "updatedBy",
|
|
91
|
+
type: "address",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
name: "URIUpdated",
|
|
95
|
+
type: "event",
|
|
96
|
+
},
|
|
97
|
+
// Transfer event (ERC-721) — fallback for extracting agentId
|
|
98
|
+
{
|
|
99
|
+
anonymous: false,
|
|
100
|
+
inputs: [
|
|
101
|
+
{
|
|
102
|
+
indexed: true,
|
|
103
|
+
internalType: "address",
|
|
104
|
+
name: "from",
|
|
105
|
+
type: "address",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
indexed: true,
|
|
109
|
+
internalType: "address",
|
|
110
|
+
name: "to",
|
|
111
|
+
type: "address",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
indexed: true,
|
|
115
|
+
internalType: "uint256",
|
|
116
|
+
name: "tokenId",
|
|
117
|
+
type: "uint256",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
name: "Transfer",
|
|
121
|
+
type: "event",
|
|
122
|
+
},
|
|
123
|
+
];
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { PlatformClient } from "./client";
|
|
2
|
+
import type { Erc8004DeployRequest, PresignIpfsUrlResponse, 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.workflows.generateWallet({ id: 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 (defaults: single trigger → trigger name, else workspace name)
|
|
114
|
+
* @param params.description - Agent description override (defaults: single trigger → trigger description, else workspace goal + service list)
|
|
115
|
+
* @param params.image - Agent image URL (optional)
|
|
116
|
+
* @returns Deployment result with agentId, IPFS CID, transaction hash, and URLs
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const result = await client.erc8004.registerOnChain({
|
|
121
|
+
* workflowId: 123,
|
|
122
|
+
* privateKey: '0x...',
|
|
123
|
+
* name: 'My AI Agent',
|
|
124
|
+
* description: 'An agent that does amazing things',
|
|
125
|
+
* });
|
|
126
|
+
* console.log(result.agentId); // "8453:42"
|
|
127
|
+
* console.log(result.txHash); // "0xabc..."
|
|
128
|
+
* console.log(result.ipfsCid); // "bafkrei..."
|
|
129
|
+
* console.log(result.blockExplorerUrl); // "https://basescan.org/tx/0xabc..."
|
|
130
|
+
* console.log(result.scanUrl); // "https://www.8004scan.io/agents/base/42"
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
registerOnChain(params: {
|
|
134
|
+
workflowId: number;
|
|
135
|
+
privateKey: string;
|
|
136
|
+
chainId?: number;
|
|
137
|
+
rpcUrl?: string;
|
|
138
|
+
name?: string;
|
|
139
|
+
description?: string;
|
|
140
|
+
image?: string;
|
|
141
|
+
}): Promise<RegisterOnChainResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Upload a JSON string to IPFS using a presigned Pinata URL.
|
|
144
|
+
*/
|
|
145
|
+
private uploadToIpfs;
|
|
146
|
+
/**
|
|
147
|
+
* Extract the agent token ID from a registration transaction receipt.
|
|
148
|
+
* Looks for the Registered event first, then falls back to Transfer event.
|
|
149
|
+
*/
|
|
150
|
+
private extractAgentIdFromReceipt;
|
|
151
|
+
/**
|
|
152
|
+
* Get a presigned IPFS URL for uploading an agent registration file.
|
|
153
|
+
*
|
|
154
|
+
* The returned URL is a signed Pinata upload URL that expires in 60 seconds.
|
|
155
|
+
* Use it to upload the agent's registration file (agent card) to IPFS before
|
|
156
|
+
* on-chain registration.
|
|
157
|
+
*
|
|
158
|
+
* @param params - Parameters
|
|
159
|
+
* @param params.workflowId - The workflow (workspace) ID
|
|
160
|
+
* @returns Object containing the presigned IPFS upload URL
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const { url } = await client.erc8004.presignIpfsUrl({ workflowId: 123 });
|
|
165
|
+
* // Use the URL to upload agent card to IPFS within 60 seconds
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
presignIpfsUrl(params: {
|
|
169
|
+
workflowId: number;
|
|
170
|
+
}): Promise<PresignIpfsUrlResponse>;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Result of a successful on-chain ERC-8004 registration.
|
|
174
|
+
*/
|
|
175
|
+
export interface RegisterOnChainResult {
|
|
176
|
+
/** ERC-8004 agent ID in format "chainId:tokenId" (e.g., "8453:42") */
|
|
177
|
+
agentId: string;
|
|
178
|
+
/** IPFS CID of the uploaded agent card */
|
|
179
|
+
ipfsCid: string;
|
|
180
|
+
/** Transaction hash of the final on-chain transaction */
|
|
181
|
+
txHash: string;
|
|
182
|
+
/** URL to view the agent card on IPFS */
|
|
183
|
+
agentCardUrl: string;
|
|
184
|
+
/** URL to view the transaction on the block explorer */
|
|
185
|
+
blockExplorerUrl: string;
|
|
186
|
+
/** URL to view the agent on 8004scan.io (e.g., "https://www.8004scan.io/agents/base/42") */
|
|
187
|
+
scanUrl: string;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=erc8004-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc8004-api.d.ts","sourceRoot":"","sources":["../src/erc8004-api.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,EACb,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,UAAU;IACT,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAM1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IACG,MAAM,CACV,MAAM,EAAE,oBAAoB,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GACpD,OAAO,CAAC,YAAY,CAAC;IAsBxB;;;OAGG;YACW,iBAAiB;IAiC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,eAAe,CAAC,MAAM,EAAE;QAC5B,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAsQlC;;OAEG;YACW,YAAY;IAyB1B;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IA8CjC;;;;;;;;;;;;;;;;OAgBG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAKpC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,gBAAgB,EAAE,MAAM,CAAC;IACzB,4FAA4F;IAC5F,OAAO,EAAE,MAAM,CAAC;CACjB"}
|