@fangorn-network/sdk 2026.10.21-dev → 2026.10.23-dev
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 +21 -18
- package/lib/cli/cli.js +18 -80
- package/lib/cli/index.d.ts +2 -2
- package/lib/cli/index.js +3 -3
- package/lib/config.d.ts +420 -83
- package/lib/config.js +11 -4
- package/lib/contracts/app-registry/abi.d.ts +52 -0
- package/lib/contracts/app-registry/abi.js +56 -0
- package/lib/contracts/app-registry/index.d.ts +15 -3
- package/lib/contracts/app-registry/index.js +23 -3
- package/lib/contracts/membership-registry/index.d.ts +1 -1
- package/lib/contracts/membership-registry/index.js +1 -1
- package/lib/{cli/erc8004.d.ts → erc8004.d.ts} +5 -3
- package/lib/{cli/erc8004.js → erc8004.js} +10 -7
- package/lib/fangorn.d.ts +21 -3
- package/lib/fangorn.js +71 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/providers/storage/signed-url.d.ts +4 -4
- package/lib/providers/storage/signed-url.js +5 -4
- package/lib/test/testbed.d.ts +6088 -5710
- package/lib/test/testbed.js +5 -1
- package/package.json +3 -2
package/lib/config.js
CHANGED
|
@@ -22,7 +22,7 @@ function toAppId(nameOrId) {
|
|
|
22
22
|
if (!name) throw new Error("App name or id must not be blank.");
|
|
23
23
|
return /^0x[0-9a-fA-F]{64}$/.test(name) ? name : appId(name);
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const ArbitrumSepoliaConfig = {
|
|
26
26
|
dataRegistryContractAddress: "0x72B5f83526F3893aF9f1eE0f32A27218EA09f8aE",
|
|
27
27
|
appRegistryContractAddress: "0x55e6209ea1833ceD900989a3b3b22466934E04A5",
|
|
28
28
|
membershipRegistryContractAddress: "0xDF17030Cd65435C86eb043F31DDACa99E819E347",
|
|
@@ -42,13 +42,20 @@ const BaseSepoliaConfig = {
|
|
|
42
42
|
rpcUrl: "https://base-sepolia-rpc.publicnode.com",
|
|
43
43
|
caip2: 84532,
|
|
44
44
|
ipfsGateway: "https://ipfs.io",
|
|
45
|
-
logWindow:
|
|
45
|
+
logWindow: 1000n,
|
|
46
|
+
signedUrlWorker: "https://base-sepolia.storage-worker.fangorn.network"
|
|
46
47
|
};
|
|
47
48
|
/**
|
|
49
|
+
* The default network: what `Fangorn.create` uses without a `config`, and the CLI
|
|
50
|
+
* without `CHAIN_NAME`. Base Sepolia, which runs the contracts this SDK's ABIs are
|
|
51
|
+
* built from.
|
|
52
|
+
*/
|
|
53
|
+
const FangornConfig = BaseSepoliaConfig;
|
|
54
|
+
/**
|
|
48
55
|
* The networks supported by Fangorn, by the name `CHAIN_NAME` takes.
|
|
49
56
|
*/
|
|
50
57
|
const SupportedNetworks = {
|
|
51
|
-
arbitrumSepolia:
|
|
58
|
+
arbitrumSepolia: ArbitrumSepoliaConfig,
|
|
52
59
|
baseSepolia: BaseSepoliaConfig
|
|
53
60
|
};
|
|
54
61
|
/**
|
|
@@ -62,4 +69,4 @@ function getNetwork(name) {
|
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
//#endregion
|
|
65
|
-
export { BaseSepoliaConfig, FangornConfig, SupportedNetworks, appId, getNetwork as default, nonBlank, toAppId };
|
|
72
|
+
export { ArbitrumSepoliaConfig, BaseSepoliaConfig, FangornConfig, SupportedNetworks, appId, getNetwork as default, nonBlank, toAppId };
|
|
@@ -81,6 +81,16 @@ declare const APP_REGISTRY_ABI: readonly [{
|
|
|
81
81
|
readonly internalType: "string";
|
|
82
82
|
}];
|
|
83
83
|
readonly stateMutability: "view";
|
|
84
|
+
}, {
|
|
85
|
+
readonly type: "function";
|
|
86
|
+
readonly name: "appCount";
|
|
87
|
+
readonly inputs: readonly [];
|
|
88
|
+
readonly outputs: readonly [{
|
|
89
|
+
readonly name: "";
|
|
90
|
+
readonly type: "uint256";
|
|
91
|
+
readonly internalType: "uint256";
|
|
92
|
+
}];
|
|
93
|
+
readonly stateMutability: "view";
|
|
84
94
|
}, {
|
|
85
95
|
readonly type: "function";
|
|
86
96
|
readonly name: "approve";
|
|
@@ -95,6 +105,38 @@ declare const APP_REGISTRY_ABI: readonly [{
|
|
|
95
105
|
}];
|
|
96
106
|
readonly outputs: readonly [];
|
|
97
107
|
readonly stateMutability: "nonpayable";
|
|
108
|
+
}, {
|
|
109
|
+
readonly type: "function";
|
|
110
|
+
readonly name: "appsOf";
|
|
111
|
+
readonly inputs: readonly [{
|
|
112
|
+
readonly name: "owner";
|
|
113
|
+
readonly type: "address";
|
|
114
|
+
readonly internalType: "address";
|
|
115
|
+
}];
|
|
116
|
+
readonly outputs: readonly [{
|
|
117
|
+
readonly name: "";
|
|
118
|
+
readonly type: "bytes32[]";
|
|
119
|
+
readonly internalType: "bytes32[]";
|
|
120
|
+
}];
|
|
121
|
+
readonly stateMutability: "view";
|
|
122
|
+
}, {
|
|
123
|
+
readonly type: "function";
|
|
124
|
+
readonly name: "appsPage";
|
|
125
|
+
readonly inputs: readonly [{
|
|
126
|
+
readonly name: "offset";
|
|
127
|
+
readonly type: "uint256";
|
|
128
|
+
readonly internalType: "uint256";
|
|
129
|
+
}, {
|
|
130
|
+
readonly name: "limit";
|
|
131
|
+
readonly type: "uint256";
|
|
132
|
+
readonly internalType: "uint256";
|
|
133
|
+
}];
|
|
134
|
+
readonly outputs: readonly [{
|
|
135
|
+
readonly name: "page";
|
|
136
|
+
readonly type: "bytes32[]";
|
|
137
|
+
readonly internalType: "bytes32[]";
|
|
138
|
+
}];
|
|
139
|
+
readonly stateMutability: "view";
|
|
98
140
|
}, {
|
|
99
141
|
readonly type: "function";
|
|
100
142
|
readonly name: "balanceOf";
|
|
@@ -287,6 +329,16 @@ declare const APP_REGISTRY_ABI: readonly [{
|
|
|
287
329
|
}];
|
|
288
330
|
readonly outputs: readonly [];
|
|
289
331
|
readonly stateMutability: "nonpayable";
|
|
332
|
+
}, {
|
|
333
|
+
readonly type: "function";
|
|
334
|
+
readonly name: "initializeV2";
|
|
335
|
+
readonly inputs: readonly [{
|
|
336
|
+
readonly name: "existing";
|
|
337
|
+
readonly type: "bytes32[]";
|
|
338
|
+
readonly internalType: "bytes32[]";
|
|
339
|
+
}];
|
|
340
|
+
readonly outputs: readonly [];
|
|
341
|
+
readonly stateMutability: "nonpayable";
|
|
290
342
|
}, {
|
|
291
343
|
readonly type: "function";
|
|
292
344
|
readonly name: "isAppSuspended";
|
|
@@ -92,6 +92,17 @@ const APP_REGISTRY_ABI = [
|
|
|
92
92
|
}],
|
|
93
93
|
"stateMutability": "view"
|
|
94
94
|
},
|
|
95
|
+
{
|
|
96
|
+
"type": "function",
|
|
97
|
+
"name": "appCount",
|
|
98
|
+
"inputs": [],
|
|
99
|
+
"outputs": [{
|
|
100
|
+
"name": "",
|
|
101
|
+
"type": "uint256",
|
|
102
|
+
"internalType": "uint256"
|
|
103
|
+
}],
|
|
104
|
+
"stateMutability": "view"
|
|
105
|
+
},
|
|
95
106
|
{
|
|
96
107
|
"type": "function",
|
|
97
108
|
"name": "approve",
|
|
@@ -107,6 +118,40 @@ const APP_REGISTRY_ABI = [
|
|
|
107
118
|
"outputs": [],
|
|
108
119
|
"stateMutability": "nonpayable"
|
|
109
120
|
},
|
|
121
|
+
{
|
|
122
|
+
"type": "function",
|
|
123
|
+
"name": "appsOf",
|
|
124
|
+
"inputs": [{
|
|
125
|
+
"name": "owner",
|
|
126
|
+
"type": "address",
|
|
127
|
+
"internalType": "address"
|
|
128
|
+
}],
|
|
129
|
+
"outputs": [{
|
|
130
|
+
"name": "",
|
|
131
|
+
"type": "bytes32[]",
|
|
132
|
+
"internalType": "bytes32[]"
|
|
133
|
+
}],
|
|
134
|
+
"stateMutability": "view"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"type": "function",
|
|
138
|
+
"name": "appsPage",
|
|
139
|
+
"inputs": [{
|
|
140
|
+
"name": "offset",
|
|
141
|
+
"type": "uint256",
|
|
142
|
+
"internalType": "uint256"
|
|
143
|
+
}, {
|
|
144
|
+
"name": "limit",
|
|
145
|
+
"type": "uint256",
|
|
146
|
+
"internalType": "uint256"
|
|
147
|
+
}],
|
|
148
|
+
"outputs": [{
|
|
149
|
+
"name": "page",
|
|
150
|
+
"type": "bytes32[]",
|
|
151
|
+
"internalType": "bytes32[]"
|
|
152
|
+
}],
|
|
153
|
+
"stateMutability": "view"
|
|
154
|
+
},
|
|
110
155
|
{
|
|
111
156
|
"type": "function",
|
|
112
157
|
"name": "balanceOf",
|
|
@@ -325,6 +370,17 @@ const APP_REGISTRY_ABI = [
|
|
|
325
370
|
"outputs": [],
|
|
326
371
|
"stateMutability": "nonpayable"
|
|
327
372
|
},
|
|
373
|
+
{
|
|
374
|
+
"type": "function",
|
|
375
|
+
"name": "initializeV2",
|
|
376
|
+
"inputs": [{
|
|
377
|
+
"name": "existing",
|
|
378
|
+
"type": "bytes32[]",
|
|
379
|
+
"internalType": "bytes32[]"
|
|
380
|
+
}],
|
|
381
|
+
"outputs": [],
|
|
382
|
+
"stateMutability": "nonpayable"
|
|
383
|
+
},
|
|
328
384
|
{
|
|
329
385
|
"type": "function",
|
|
330
386
|
"name": "isAppSuspended",
|
|
@@ -78,6 +78,18 @@ declare class AppRegistryClient {
|
|
|
78
78
|
/** The ERC-20 token (USDC) every fee is paid in. */
|
|
79
79
|
usdc(): Promise<Address>;
|
|
80
80
|
getAppOwner(appId?: Hex): Promise<Address>;
|
|
81
|
+
/** How many apps have been claimed. */
|
|
82
|
+
appCount(): Promise<bigint>;
|
|
83
|
+
/** Up to `limit` app ids from position `offset`, oldest first; fewer past the end. */
|
|
84
|
+
appsPage(offset: bigint, limit: bigint): Promise<readonly Hex[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Every claimed app id, oldest first.
|
|
87
|
+
* ponytail: one eth_call for all of them; page with `appsPage` once the list
|
|
88
|
+
* outgrows the RPC's eth_call gas cap (tens of thousands of apps).
|
|
89
|
+
*/
|
|
90
|
+
allApps(): Promise<readonly Hex[]>;
|
|
91
|
+
/** The app ids `owner` claimed, oldest first. */
|
|
92
|
+
appsOf(owner: Address): Promise<readonly Hex[]>;
|
|
81
93
|
/**
|
|
82
94
|
* Point this app at its ERC-8004 agent card.
|
|
83
95
|
*
|
|
@@ -116,9 +128,9 @@ declare class AppRegistryClient {
|
|
|
116
128
|
* `AppAgentChanged` events, oldest first. The last one for an app is its
|
|
117
129
|
* current card; an empty `agentUri` means the owner unset it.
|
|
118
130
|
*
|
|
119
|
-
* Leave `appId` out to list every app that has ever set a card.
|
|
120
|
-
*
|
|
121
|
-
* `fromBlock` is required because scanning from genesis on an L2 costs
|
|
131
|
+
* Leave `appId` out to list every app that has ever set a card. To list apps,
|
|
132
|
+
* use `allApps` or `appsOf`, which are one read each; this is a windowed log
|
|
133
|
+
* scan, for a card's history. `fromBlock` is required because scanning from genesis on an L2 costs
|
|
122
134
|
* hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
|
|
123
135
|
* a block you know to be before the app's registration.
|
|
124
136
|
*/
|
|
@@ -114,6 +114,26 @@ var AppRegistryClient = class {
|
|
|
114
114
|
async getAppOwner(appId = this.app()) {
|
|
115
115
|
return this.read("getAppOwner", [appId]);
|
|
116
116
|
}
|
|
117
|
+
/** How many apps have been claimed. */
|
|
118
|
+
async appCount() {
|
|
119
|
+
return this.read("appCount", []);
|
|
120
|
+
}
|
|
121
|
+
/** Up to `limit` app ids from position `offset`, oldest first; fewer past the end. */
|
|
122
|
+
async appsPage(offset, limit) {
|
|
123
|
+
return this.read("appsPage", [offset, limit]);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Every claimed app id, oldest first.
|
|
127
|
+
* ponytail: one eth_call for all of them; page with `appsPage` once the list
|
|
128
|
+
* outgrows the RPC's eth_call gas cap (tens of thousands of apps).
|
|
129
|
+
*/
|
|
130
|
+
async allApps() {
|
|
131
|
+
return this.appsPage(0n, await this.appCount());
|
|
132
|
+
}
|
|
133
|
+
/** The app ids `owner` claimed, oldest first. */
|
|
134
|
+
async appsOf(owner) {
|
|
135
|
+
return this.read("appsOf", [owner]);
|
|
136
|
+
}
|
|
117
137
|
/**
|
|
118
138
|
* Point this app at its ERC-8004 agent card.
|
|
119
139
|
*
|
|
@@ -181,9 +201,9 @@ var AppRegistryClient = class {
|
|
|
181
201
|
* `AppAgentChanged` events, oldest first. The last one for an app is its
|
|
182
202
|
* current card; an empty `agentUri` means the owner unset it.
|
|
183
203
|
*
|
|
184
|
-
* Leave `appId` out to list every app that has ever set a card.
|
|
185
|
-
*
|
|
186
|
-
* `fromBlock` is required because scanning from genesis on an L2 costs
|
|
204
|
+
* Leave `appId` out to list every app that has ever set a card. To list apps,
|
|
205
|
+
* use `allApps` or `appsOf`, which are one read each; this is a windowed log
|
|
206
|
+
* scan, for a card's history. `fromBlock` is required because scanning from genesis on an L2 costs
|
|
187
207
|
* hundreds of thousands of RPC calls. Pass the AppRegistry's deploy block, or
|
|
188
208
|
* a block you know to be before the app's registration.
|
|
189
209
|
*/
|
|
@@ -40,7 +40,7 @@ declare const membershipTokenId: (appId: Hex, holder: Address) => bigint;
|
|
|
40
40
|
*
|
|
41
41
|
* The app owner's half is here (`setPlan`), with the reads every gate needs
|
|
42
42
|
* (`canRead`, `planOf`, `currentEpoch`) and the two relayed writes (`join`, `claim`),
|
|
43
|
-
* which take what a buyer signed and proved, so anyone may submit them
|
|
43
|
+
* which take what a buyer signed and proved, so anyone may submit them.
|
|
44
44
|
*
|
|
45
45
|
* The buyer's half (Semaphore identity, stealth holder, the payment signature, the
|
|
46
46
|
* group from `Joined` logs, the proof) lives in `@fangorn-network/fetch`: this SDK
|
|
@@ -24,7 +24,7 @@ const membershipTokenId = (appId, holder) => BigInt(keccak256(encodeAbiParameter
|
|
|
24
24
|
*
|
|
25
25
|
* The app owner's half is here (`setPlan`), with the reads every gate needs
|
|
26
26
|
* (`canRead`, `planOf`, `currentEpoch`) and the two relayed writes (`join`, `claim`),
|
|
27
|
-
* which take what a buyer signed and proved, so anyone may submit them
|
|
27
|
+
* which take what a buyer signed and proved, so anyone may submit them.
|
|
28
28
|
*
|
|
29
29
|
* The buyer's half (Semaphore identity, stealth holder, the payment signature, the
|
|
30
30
|
* group from `Joined` logs, the proof) lives in `@fangorn-network/fetch`: this SDK
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { MetadataStorage } from "./providers/storage/types.js";
|
|
1
2
|
import { Address, Chain, Hex, PublicClient, WalletClient } from "viem";
|
|
2
3
|
|
|
3
|
-
//#region src/
|
|
4
|
+
//#region src/erc8004.d.ts
|
|
4
5
|
/** The ERC-8004 identity registry by chain id */
|
|
5
6
|
declare const IDENTITY_REGISTRY: Record<number, Address>;
|
|
6
7
|
interface AgentCard {
|
|
@@ -44,11 +45,12 @@ interface Erc8004Clients {
|
|
|
44
45
|
chain: Chain;
|
|
45
46
|
publicClient: PublicClient;
|
|
46
47
|
walletClient: WalletClient;
|
|
47
|
-
|
|
48
|
+
storage: Pick<MetadataStorage, "put">;
|
|
48
49
|
}
|
|
50
|
+
declare function retryNonce<T>(f: () => Promise<T>, tries?: number): Promise<T>;
|
|
49
51
|
/** Pin `file` and point agent `agentId` at it. */
|
|
50
52
|
declare function setAgentFile(c: Erc8004Clients, agentId: bigint, file: unknown): Promise<Hex>;
|
|
51
53
|
/** Mint an agent with no URI yet, and return its id. */
|
|
52
54
|
declare function mintAgent(c: Erc8004Clients): Promise<bigint>;
|
|
53
55
|
//#endregion
|
|
54
|
-
export { AgentCard, Erc8004Clients, IDENTITY_REGISTRY, agentCardUrl, mcpTools, mintAgent, parseAgentId, registrationFile, setAgentFile };
|
|
56
|
+
export { AgentCard, Erc8004Clients, IDENTITY_REGISTRY, agentCardUrl, mcpTools, mintAgent, parseAgentId, registrationFile, retryNonce, setAgentFile };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parseAbi, parseEventLogs } from "viem";
|
|
2
|
-
import { PinataSDK } from "pinata";
|
|
3
2
|
|
|
4
|
-
//#region src/
|
|
3
|
+
//#region src/erc8004.ts
|
|
5
4
|
/** The ERC-8004 identity registry by chain id */
|
|
6
5
|
const IDENTITY_REGISTRY = {
|
|
7
6
|
84532: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
|
|
@@ -93,9 +92,13 @@ function parseAgentId(id, chainId) {
|
|
|
93
92
|
if (m[1] && Number(m[1]) !== chainId) throw new Error(`agent ${id} is on chain ${m[1]}, but the CLI is configured for ${String(chainId)}`);
|
|
94
93
|
return BigInt(m[2]);
|
|
95
94
|
}
|
|
96
|
-
async function
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
async function retryNonce(f, tries = 4) {
|
|
96
|
+
for (let i = 0;; i++) try {
|
|
97
|
+
return await f();
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (i >= tries - 1 || !/underpriced|nonce too low|nonce has already been used|already known/i.test(e.message)) throw e;
|
|
100
|
+
await new Promise((ok) => setTimeout(ok, 3e3 * (i + 1)));
|
|
101
|
+
}
|
|
99
102
|
}
|
|
100
103
|
function registry(chain) {
|
|
101
104
|
const address = IDENTITY_REGISTRY[chain.id];
|
|
@@ -104,7 +107,7 @@ function registry(chain) {
|
|
|
104
107
|
}
|
|
105
108
|
/** Pin `file` and point agent `agentId` at it. */
|
|
106
109
|
async function setAgentFile(c, agentId, file) {
|
|
107
|
-
const cid = await
|
|
110
|
+
const cid = await c.storage.put(file, { name: "agent-registration.json" });
|
|
108
111
|
const hash = await c.walletClient.writeContract({
|
|
109
112
|
address: registry(c.chain),
|
|
110
113
|
abi: ABI,
|
|
@@ -137,4 +140,4 @@ async function mintAgent(c) {
|
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
//#endregion
|
|
140
|
-
export { IDENTITY_REGISTRY, agentCardUrl, mcpTools, mintAgent, parseAgentId, registrationFile, setAgentFile };
|
|
143
|
+
export { IDENTITY_REGISTRY, agentCardUrl, mcpTools, mintAgent, parseAgentId, registrationFile, retryNonce, setAgentFile };
|
package/lib/fangorn.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ import "./contracts/index.js";
|
|
|
6
6
|
import { Registry } from "./registry.js";
|
|
7
7
|
import { MetadataStorage } from "./providers/storage/types.js";
|
|
8
8
|
import { CommitDiff, FangornEngine, RecordInput, RepoContents, RepoDiff } from "./engine/index.js";
|
|
9
|
+
import { AgentCard as AgentCard$1 } from "./erc8004.js";
|
|
9
10
|
import { FangornCreateOptions, StorageConfig } from "./types/index.js";
|
|
10
11
|
import { AppFeed } from "./feed.js";
|
|
11
|
-
import
|
|
12
|
-
import { Hex, WalletClient } from "viem";
|
|
12
|
+
import { Hash, Hex, WalletClient } from "viem";
|
|
13
13
|
import { CID } from "multiformats/cid";
|
|
14
14
|
|
|
15
15
|
//#region src/fangorn.d.ts
|
|
@@ -84,7 +84,7 @@ declare class Fangorn {
|
|
|
84
84
|
* head still names them as history.
|
|
85
85
|
*/
|
|
86
86
|
reset(repo: string): Promise<{
|
|
87
|
-
txHash:
|
|
87
|
+
txHash: Hash;
|
|
88
88
|
onChainTip: CID;
|
|
89
89
|
}>;
|
|
90
90
|
/** Stage records into one commit on top of `base`. */
|
|
@@ -317,6 +317,24 @@ declare class Fangorn {
|
|
|
317
317
|
*/
|
|
318
318
|
getAppRegistry(): AppRegistryClient;
|
|
319
319
|
getMembershipRegistry(): MembershipRegistryClient;
|
|
320
|
+
/**
|
|
321
|
+
* Register the app as an ERC-8004 agent from its card, and point the app at the card
|
|
322
|
+
* (owner only). The registration file is pinned with this client's storage, so a
|
|
323
|
+
* browser wallet on signed-URL storage needs no Pinata JWT.
|
|
324
|
+
*
|
|
325
|
+
* `update` re-files an agent already minted (its token id) from the card as it is
|
|
326
|
+
* now, minting nothing. `skipRegister` only binds the card. A binding that already
|
|
327
|
+
* points at `cardUrl` is left alone.
|
|
328
|
+
*/
|
|
329
|
+
registerAgent(cardUrl: string, opts?: {
|
|
330
|
+
mcp?: string;
|
|
331
|
+
update?: bigint;
|
|
332
|
+
skipRegister?: boolean;
|
|
333
|
+
}): Promise<{
|
|
334
|
+
card: AgentCard$1;
|
|
335
|
+
agentId?: bigint;
|
|
336
|
+
txHash?: Hash;
|
|
337
|
+
}>;
|
|
320
338
|
/** The app this client reads and publishes under, or undefined for none. */
|
|
321
339
|
getAppId(): Hex | undefined;
|
|
322
340
|
private requireApp;
|
package/lib/fangorn.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FangornConfig, nonBlank, toAppId } from "./config.js";
|
|
2
|
+
import { mcpTools, mintAgent, registrationFile, retryNonce, setAgentFile } from "./erc8004.js";
|
|
2
3
|
import { SignedUrlBackend } from "./providers/storage/signed-url.js";
|
|
3
4
|
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
4
5
|
import { AppRegistryClient } from "./contracts/app-registry/index.js";
|
|
@@ -29,7 +30,11 @@ function resolveStorage(storage, walletClient, config, getAppId) {
|
|
|
29
30
|
if (!storage) return void 0;
|
|
30
31
|
if ("backend" in storage) return storage.backend;
|
|
31
32
|
if ("pinata" in storage) return new PinataBackend(storage.pinata.jwt, storage.pinata.gateway);
|
|
32
|
-
if ("signedUrl" in storage)
|
|
33
|
+
if ("signedUrl" in storage) {
|
|
34
|
+
const workerUrl = nonBlank(storage.signedUrl.workerUrl) ?? nonBlank(config.signedUrlWorker);
|
|
35
|
+
if (!workerUrl) throw new Error(`no hosted upload worker on chain ${config.caip2.toString()}: pass storage.signedUrl.workerUrl, or bring your own storage ({ pinata } or { backend })`);
|
|
36
|
+
return new SignedUrlBackend(workerUrl, walletSigner(walletClient), storage.signedUrl.gateway ?? config.ipfsGateway, getAppId);
|
|
37
|
+
}
|
|
33
38
|
throw new Error(`Invalid storage config: must be { pinata: … }, { signedUrl: … } or { backend: … }, got ${JSON.stringify(storage)}`);
|
|
34
39
|
}
|
|
35
40
|
/** The A2A extension a Fangorn app's agent card carries: it names the app the card speaks for. */
|
|
@@ -562,6 +567,71 @@ var Fangorn = class Fangorn {
|
|
|
562
567
|
this._membership ??= new MembershipRegistryClient(this.ctx.config.membershipRegistryContractAddress, this.ctx.publicClient, this.ctx.walletClient);
|
|
563
568
|
return this._membership;
|
|
564
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Register the app as an ERC-8004 agent from its card, and point the app at the card
|
|
572
|
+
* (owner only). The registration file is pinned with this client's storage, so a
|
|
573
|
+
* browser wallet on signed-URL storage needs no Pinata JWT.
|
|
574
|
+
*
|
|
575
|
+
* `update` re-files an agent already minted (its token id) from the card as it is
|
|
576
|
+
* now, minting nothing. `skipRegister` only binds the card. A binding that already
|
|
577
|
+
* points at `cardUrl` is left alone.
|
|
578
|
+
*/
|
|
579
|
+
async registerAgent(cardUrl, opts = {}) {
|
|
580
|
+
const res = await fetch(cardUrl);
|
|
581
|
+
if (!res.ok) throw new Error(`card at ${cardUrl} returned ${String(res.status)}`);
|
|
582
|
+
const card = await res.json();
|
|
583
|
+
if (!card.name || !card.description) throw new Error("card is missing `name` or `description`");
|
|
584
|
+
const named = {
|
|
585
|
+
...card,
|
|
586
|
+
name: card.name,
|
|
587
|
+
description: card.description
|
|
588
|
+
};
|
|
589
|
+
let agentId;
|
|
590
|
+
if (!opts.skipRegister) {
|
|
591
|
+
const c = {
|
|
592
|
+
chain: this.ctx.config.chain,
|
|
593
|
+
publicClient: this.ctx.publicClient,
|
|
594
|
+
walletClient: this.ctx.walletClient,
|
|
595
|
+
storage: this.getStorage()
|
|
596
|
+
};
|
|
597
|
+
const chainId = this.ctx.config.caip2;
|
|
598
|
+
const mcp = opts.mcp ? {
|
|
599
|
+
endpoint: opts.mcp,
|
|
600
|
+
tools: await mcpTools(opts.mcp)
|
|
601
|
+
} : void 0;
|
|
602
|
+
const file = (id) => registrationFile({
|
|
603
|
+
cardUrl,
|
|
604
|
+
card: named,
|
|
605
|
+
chainId,
|
|
606
|
+
agentId: id,
|
|
607
|
+
mcp
|
|
608
|
+
});
|
|
609
|
+
const { update } = opts;
|
|
610
|
+
if (update !== void 0) {
|
|
611
|
+
agentId = update;
|
|
612
|
+
await retryNonce(() => setAgentFile(c, update, file(update)));
|
|
613
|
+
} else {
|
|
614
|
+
const id = await mintAgent(c);
|
|
615
|
+
agentId = id;
|
|
616
|
+
try {
|
|
617
|
+
await retryNonce(() => setAgentFile(c, id, file(id)));
|
|
618
|
+
} catch (e) {
|
|
619
|
+
throw Object.assign(/* @__PURE__ */ new Error(`agent ${String(chainId)}:${String(agentId)} was minted but its registration file was not set (${e.message}); finish it with registerAgent(cardUrl, { update: ${String(agentId)}n })`), { agentId });
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
const apps = this.getAppRegistry();
|
|
624
|
+
if (await apps.appAgentUri().catch(() => "") === cardUrl) return {
|
|
625
|
+
card: named,
|
|
626
|
+
agentId
|
|
627
|
+
};
|
|
628
|
+
const txHash = await retryNonce(() => apps.setAppAgentUri(cardUrl));
|
|
629
|
+
return {
|
|
630
|
+
card: named,
|
|
631
|
+
agentId,
|
|
632
|
+
txHash
|
|
633
|
+
};
|
|
634
|
+
}
|
|
565
635
|
/** The app this client reads and publishes under, or undefined for none. */
|
|
566
636
|
getAppId() {
|
|
567
637
|
return this.ctx.appId;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppConfig, BaseSepoliaConfig, FangornConfig, SupportedNetworks, appId, nonBlank, toAppId } from "./config.js";
|
|
1
|
+
import { AppConfig, ArbitrumSepoliaConfig, BaseSepoliaConfig, FangornConfig, SupportedNetworks, appId, nonBlank, toAppId } from "./config.js";
|
|
2
2
|
import { APP_REGISTRY_ABI } from "./contracts/app-registry/abi.js";
|
|
3
3
|
import { PublisherStatus } from "./contracts/types.js";
|
|
4
4
|
import { PreparedTx } from "./contracts/write.js";
|
|
@@ -17,4 +17,4 @@ import { AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, Edge, FileFaca
|
|
|
17
17
|
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
18
18
|
import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend, SignedUrlSigner } from "./providers/storage/signed-url.js";
|
|
19
19
|
import { MAX_UPLOAD_ATTEMPTS, deserialize, fetchRawByCid, isTransientUpload, retrieveByCid, serialize, withUploadRetry } from "./providers/storage/utils.js";
|
|
20
|
-
export { APP_REGISTRY_ABI, AccessRequest, AccessSigner, AgentCard, AppAccess, AppAgentLog, AppConfig, AppFeed, AppRegistryClient, AssetProcessor, BaseSepoliaConfig, BuildAssetGraphOptions, ChainRegistry, ChainRegistryConfig, ClaimArgs, CommitFileGraph, DATA_REGISTRY_ABI, DEFAULT_SIGNED_URL_WORKER, DecryptHandleParams, EPOCH_SECONDS, Edge, EncryptAndUploadParams, Exclusion, FANGORN_APP_EXTENSION, Fangorn, FangornConfig, FangornContext, FangornCreateOptions, FileFacade, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, JoinArgs, LogFilter, MAX_UPLOAD_ATTEMPTS, MEMBERSHIP_REGISTRY_ABI, MembershipPayment, MembershipRegistryClient, PinataBackend, PreparedTx, ProcessorResult, PublisherStatus, Registry, RepoChange, RepoRef, SignedUrlBackend, SignedUrlSigner, StorageConfig, SubscribeOptions, SupportedNetworks, UpdateEntry, Vertex, X25519_PUBKEY_LENGTH, ZERO_HEAD, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, covers, decryptHandle, deserialize, encryptAndUpload, epochOf, exclusionId, extractMarkdownLinks, fetchRawByCid, isTransientUpload, joinNonce, membershipScope, membershipTokenId, nonBlank, repoExcluded, repoId, retrieveByCid, seal, sealSelf, serialize, sha256Hex, toAppId, unseal, unsealSelf, withUploadRetry };
|
|
20
|
+
export { APP_REGISTRY_ABI, AccessRequest, AccessSigner, AgentCard, AppAccess, AppAgentLog, AppConfig, AppFeed, AppRegistryClient, ArbitrumSepoliaConfig, AssetProcessor, BaseSepoliaConfig, BuildAssetGraphOptions, ChainRegistry, ChainRegistryConfig, ClaimArgs, CommitFileGraph, DATA_REGISTRY_ABI, DEFAULT_SIGNED_URL_WORKER, DecryptHandleParams, EPOCH_SECONDS, Edge, EncryptAndUploadParams, Exclusion, FANGORN_APP_EXTENSION, Fangorn, FangornConfig, FangornContext, FangornCreateOptions, FileFacade, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, JoinArgs, LogFilter, MAX_UPLOAD_ATTEMPTS, MEMBERSHIP_REGISTRY_ABI, MembershipPayment, MembershipRegistryClient, PinataBackend, PreparedTx, ProcessorResult, PublisherStatus, Registry, RepoChange, RepoRef, SignedUrlBackend, SignedUrlSigner, StorageConfig, SubscribeOptions, SupportedNetworks, UpdateEntry, Vertex, X25519_PUBKEY_LENGTH, ZERO_HEAD, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, covers, decryptHandle, deserialize, encryptAndUpload, epochOf, exclusionId, extractMarkdownLinks, fetchRawByCid, isTransientUpload, joinNonce, membershipScope, membershipTokenId, nonBlank, repoExcluded, repoId, retrieveByCid, seal, sealSelf, serialize, sha256Hex, toAppId, unseal, unsealSelf, withUploadRetry };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseSepoliaConfig, FangornConfig, SupportedNetworks, appId, nonBlank, toAppId } from "./config.js";
|
|
1
|
+
import { ArbitrumSepoliaConfig, BaseSepoliaConfig, FangornConfig, SupportedNetworks, appId, nonBlank, toAppId } from "./config.js";
|
|
2
2
|
import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend } from "./providers/storage/signed-url.js";
|
|
3
3
|
import { MAX_UPLOAD_ATTEMPTS, deserialize, fetchRawByCid, isTransientUpload, retrieveByCid, serialize, withUploadRetry } from "./providers/storage/utils.js";
|
|
4
4
|
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
@@ -16,4 +16,4 @@ import { FANGORN_APP_EXTENSION, Fangorn } from "./fangorn.js";
|
|
|
16
16
|
import { buildAssetGraph, buildMarkdownGraph, extractMarkdownLinks } from "./harness/index.js";
|
|
17
17
|
import { GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, X25519_PUBKEY_LENGTH, accessMessageHash, buildAccessRequest, decryptHandle, encryptAndUpload, seal, sealSelf, sha256Hex, unseal, unsealSelf } from "./crypto/encryption.js";
|
|
18
18
|
|
|
19
|
-
export { APP_REGISTRY_ABI, AppFeed, AppRegistryClient, BaseSepoliaConfig, ChainRegistry, DATA_REGISTRY_ABI, DEFAULT_SIGNED_URL_WORKER, EPOCH_SECONDS, FANGORN_APP_EXTENSION, Fangorn, FangornConfig, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, MAX_UPLOAD_ATTEMPTS, MEMBERSHIP_REGISTRY_ABI, MembershipRegistryClient, PinataBackend, PublisherStatus, SignedUrlBackend, SupportedNetworks, X25519_PUBKEY_LENGTH, ZERO_HEAD, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, covers, decryptHandle, deserialize, encryptAndUpload, epochOf, exclusionId, extractMarkdownLinks, fetchRawByCid, isTransientUpload, joinNonce, membershipScope, membershipTokenId, nonBlank, repoExcluded, repoId, retrieveByCid, seal, sealSelf, serialize, sha256Hex, toAppId, unseal, unsealSelf, withUploadRetry };
|
|
19
|
+
export { APP_REGISTRY_ABI, AppFeed, AppRegistryClient, ArbitrumSepoliaConfig, BaseSepoliaConfig, ChainRegistry, DATA_REGISTRY_ABI, DEFAULT_SIGNED_URL_WORKER, EPOCH_SECONDS, FANGORN_APP_EXTENSION, Fangorn, FangornConfig, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, MAX_UPLOAD_ATTEMPTS, MEMBERSHIP_REGISTRY_ABI, MembershipRegistryClient, PinataBackend, PublisherStatus, SignedUrlBackend, SupportedNetworks, X25519_PUBKEY_LENGTH, ZERO_HEAD, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, covers, decryptHandle, deserialize, encryptAndUpload, epochOf, exclusionId, extractMarkdownLinks, fetchRawByCid, isTransientUpload, joinNonce, membershipScope, membershipTokenId, nonBlank, repoExcluded, repoId, retrieveByCid, seal, sealSelf, serialize, sha256Hex, toAppId, unseal, unsealSelf, withUploadRetry };
|
|
@@ -4,11 +4,11 @@ import { Hex } from "viem";
|
|
|
4
4
|
//#region src/providers/storage/signed-url.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* The hosted
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* The hosted worker for the default network (Base Sepolia). Used when neither
|
|
8
|
+
* a worker URL nor the network's config names one. `Fangorn.create` passes the
|
|
9
|
+
* config's `signedUrlWorker`, so a Base client reaches Base's worker.
|
|
10
10
|
*/
|
|
11
|
-
declare const DEFAULT_SIGNED_URL_WORKER
|
|
11
|
+
declare const DEFAULT_SIGNED_URL_WORKER: string;
|
|
12
12
|
/** Just enough of a wallet to run the worker's ownership handshake. */
|
|
13
13
|
interface SignedUrlSigner {
|
|
14
14
|
address: Hex;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { FangornConfig } from "../../config.js";
|
|
1
2
|
import { fetchRawByCid, serialize, withUploadRetry } from "./utils.js";
|
|
2
3
|
|
|
3
4
|
//#region src/providers/storage/signed-url.ts
|
|
4
5
|
/**
|
|
5
|
-
* The hosted
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* The hosted worker for the default network (Base Sepolia). Used when neither
|
|
7
|
+
* a worker URL nor the network's config names one. `Fangorn.create` passes the
|
|
8
|
+
* config's `signedUrlWorker`, so a Base client reaches Base's worker.
|
|
8
9
|
*/
|
|
9
|
-
const DEFAULT_SIGNED_URL_WORKER =
|
|
10
|
+
const DEFAULT_SIGNED_URL_WORKER = FangornConfig.signedUrlWorker;
|
|
10
11
|
/** A human-readable reason from a worker error response, detail included. */
|
|
11
12
|
function workerError(r) {
|
|
12
13
|
const base = r.error ?? "unknown error";
|