@fangorn-network/sdk 2026.3.11
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/LICENSE.md +20 -0
- package/README.md +276 -0
- package/lib/builders/a2aCardBuilder.d.ts +28 -0
- package/lib/builders/a2aCardBuilder.js +104 -0
- package/lib/cli/cli.d.ts +2 -0
- package/lib/cli/cli.js +500 -0
- package/lib/cli/index.d.ts +738 -0
- package/lib/cli/index.js +36 -0
- package/lib/cli/registry.d.ts +29 -0
- package/lib/cli/registry.js +53 -0
- package/lib/config.d.ts +761 -0
- package/lib/config.js +46 -0
- package/lib/deployContract.d.ts +23 -0
- package/lib/deployContract.js +78 -0
- package/lib/fangorn.d.ts +59 -0
- package/lib/fangorn.js +145 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +11 -0
- package/lib/interface/datasource-registry/abi.d.ts +97 -0
- package/lib/interface/datasource-registry/abi.js +110 -0
- package/lib/interface/datasource-registry/dataSourceRegistry.d.ts +24 -0
- package/lib/interface/datasource-registry/dataSourceRegistry.js +81 -0
- package/lib/interface/index.d.ts +3 -0
- package/lib/interface/index.js +4 -0
- package/lib/interface/manifest.d.ts +7 -0
- package/lib/interface/manifest.js +10 -0
- package/lib/interface/settlement-tracker/abi.d.ts +26 -0
- package/lib/interface/settlement-tracker/abi.js +88 -0
- package/lib/interface/settlement-tracker/settlementTracker.d.ts +32 -0
- package/lib/interface/settlement-tracker/settlementTracker.js +64 -0
- package/lib/modules/encryption/actions.d.ts +4 -0
- package/lib/modules/encryption/actions.js +18 -0
- package/lib/modules/encryption/aes.d.ts +10 -0
- package/lib/modules/encryption/aes.js +51 -0
- package/lib/modules/encryption/index.d.ts +27 -0
- package/lib/modules/encryption/index.js +3 -0
- package/lib/modules/encryption/lit.d.ts +36 -0
- package/lib/modules/encryption/lit.js +156 -0
- package/lib/modules/encryption/rand.d.ts +5 -0
- package/lib/modules/encryption/rand.js +16 -0
- package/lib/modules/encryption/types.d.ts +55 -0
- package/lib/modules/encryption/types.js +1 -0
- package/lib/modules/gadgets/acc/gadgets.d.ts +7 -0
- package/lib/modules/gadgets/acc/gadgets.js +10 -0
- package/lib/modules/gadgets/acc.d.ts +15 -0
- package/lib/modules/gadgets/acc.js +24 -0
- package/lib/modules/gadgets/builder.d.ts +1 -0
- package/lib/modules/gadgets/builder.js +1 -0
- package/lib/modules/gadgets/index.d.ts +2 -0
- package/lib/modules/gadgets/index.js +1 -0
- package/lib/modules/gadgets/payment.d.ts +23 -0
- package/lib/modules/gadgets/payment.js +88 -0
- package/lib/modules/gadgets/types.d.ts +15 -0
- package/lib/modules/gadgets/types.js +1 -0
- package/lib/providers/storage/index.d.ts +10 -0
- package/lib/providers/storage/index.js +3 -0
- package/lib/providers/storage/pinata/index.d.ts +12 -0
- package/lib/providers/storage/pinata/index.js +26 -0
- package/lib/providers/storage/s3/index.d.ts +1 -0
- package/lib/providers/storage/s3/index.js +1 -0
- package/lib/test/index.d.ts +7 -0
- package/lib/test/index.js +25 -0
- package/lib/test/test-gadget.d.ts +7 -0
- package/lib/test/test-gadget.js +10 -0
- package/lib/test/testbed.d.ts +43 -0
- package/lib/test/testbed.js +174 -0
- package/lib/types/index.d.ts +43 -0
- package/lib/types/index.js +12 -0
- package/lib/utils/index.d.ts +12 -0
- package/lib/utils/index.js +43 -0
- package/package.json +83 -0
package/lib/cli/cli.js
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { FangornConfig, SupportedNetworks } from "../config.js";
|
|
3
|
+
import { Fangorn } from "../fangorn.js";
|
|
4
|
+
import { PinataStorage } from "../providers/storage/pinata/index.js";
|
|
5
|
+
import "../providers/storage/index.js";
|
|
6
|
+
import { computeTagCommitment, fieldToHex } from "../utils/index.js";
|
|
7
|
+
import { LitEncryptionService } from "../modules/encryption/lit.js";
|
|
8
|
+
import { agentCardBuilder } from "../builders/a2aCardBuilder.js";
|
|
9
|
+
import { getChain, handleCancel, parseGadgetArg, selectChain } from "./index.js";
|
|
10
|
+
import { GADGET_REGISTRY, selectGadget } from "./registry.js";
|
|
11
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
12
|
+
import { basename, extname, join } from "path";
|
|
13
|
+
import { createWalletClient, http } from "viem";
|
|
14
|
+
import { PinataSDK } from "pinata";
|
|
15
|
+
import { Command } from "commander";
|
|
16
|
+
import { confirm, intro, multiselect, note, outro, select, spinner, text } from "@clack/prompts";
|
|
17
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
18
|
+
import "dotenv/config";
|
|
19
|
+
import { SDK } from "agent0-sdk";
|
|
20
|
+
import { homedir } from "os";
|
|
21
|
+
|
|
22
|
+
//#region src/cli/cli.ts
|
|
23
|
+
const CONFIG_DIR = join(homedir(), ".fangorn");
|
|
24
|
+
const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
25
|
+
let _config = null;
|
|
26
|
+
let _account = null;
|
|
27
|
+
let _fangorn = null;
|
|
28
|
+
function loadConfig() {
|
|
29
|
+
if (_config) return _config;
|
|
30
|
+
const privateKey = process.env.DELEGATOR_ETH_PRIVATE_KEY;
|
|
31
|
+
const jwt = process.env.PINATA_JWT;
|
|
32
|
+
const gateway = process.env.PINATA_GATEWAY;
|
|
33
|
+
const chainName = process.env.CHAIN_NAME;
|
|
34
|
+
if (privateKey && jwt && gateway && chainName) {
|
|
35
|
+
_config = buildConfig({
|
|
36
|
+
privateKey,
|
|
37
|
+
jwt,
|
|
38
|
+
gateway,
|
|
39
|
+
chainName
|
|
40
|
+
});
|
|
41
|
+
return _config;
|
|
42
|
+
}
|
|
43
|
+
if (existsSync(CONFIG_PATH)) {
|
|
44
|
+
_config = buildConfig(JSON.parse(readFileSync(CONFIG_PATH, "utf-8")));
|
|
45
|
+
return _config;
|
|
46
|
+
}
|
|
47
|
+
throw new Error("No configuration found. Run `fangorn init` to set up your credentials, or set DELEGATOR_ETH_PRIVATE_KEY, PINATA_JWT, PINATA_GATEWAY, and CHAIN_NAME env vars.");
|
|
48
|
+
}
|
|
49
|
+
function buildConfig({ privateKey, jwt, gateway, chainName }) {
|
|
50
|
+
let cfg = FangornConfig.BaseSepolia;
|
|
51
|
+
if (chainName === SupportedNetworks.ArbitrumSepolia.name) cfg = FangornConfig.ArbitrumSepolia;
|
|
52
|
+
return {
|
|
53
|
+
privateKey,
|
|
54
|
+
jwt,
|
|
55
|
+
gateway,
|
|
56
|
+
cfg
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getAccount() {
|
|
60
|
+
if (_account) return _account;
|
|
61
|
+
_account = privateKeyToAccount(loadConfig().privateKey);
|
|
62
|
+
return _account;
|
|
63
|
+
}
|
|
64
|
+
async function getFangorn(chain) {
|
|
65
|
+
if (_fangorn) return _fangorn;
|
|
66
|
+
const cfg = loadConfig();
|
|
67
|
+
const walletClient = createWalletClient({
|
|
68
|
+
account: getAccount(),
|
|
69
|
+
transport: http(cfg.cfg.rpcUrl),
|
|
70
|
+
chain
|
|
71
|
+
});
|
|
72
|
+
const appConfig = cfg.cfg;
|
|
73
|
+
const domain = process.env.DOMAIN || "localhost:3000";
|
|
74
|
+
const storage = new PinataStorage(new PinataSDK({
|
|
75
|
+
pinataJwt: cfg.jwt,
|
|
76
|
+
pinataGateway: cfg.gateway
|
|
77
|
+
}));
|
|
78
|
+
const chainName = process.env.CHAIN_NAME;
|
|
79
|
+
const encryptionService = await LitEncryptionService.init(chainName);
|
|
80
|
+
_fangorn = await Fangorn.init(walletClient, storage, encryptionService, domain, appConfig);
|
|
81
|
+
return _fangorn;
|
|
82
|
+
}
|
|
83
|
+
const program = new Command();
|
|
84
|
+
program.name("Fangorn").description("CLI for Fangorn").version("0.0.1");
|
|
85
|
+
program.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
86
|
+
intro("Fangorn Setup");
|
|
87
|
+
const privateKey = await text({
|
|
88
|
+
message: "Your wallet private key (stored locally, never transmitted):",
|
|
89
|
+
placeholder: "0x...",
|
|
90
|
+
validate: (v) => {
|
|
91
|
+
if (!v.startsWith("0x") || v.length !== 66) return "Must be a valid 0x-prefixed 32-byte hex key";
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
handleCancel(privateKey);
|
|
95
|
+
const jwt = await text({
|
|
96
|
+
message: "Pinata JWT:",
|
|
97
|
+
validate: (v) => {
|
|
98
|
+
if (!v) return "Required";
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
handleCancel(jwt);
|
|
102
|
+
const gateway = await text({
|
|
103
|
+
message: "Pinata Gateway URL:",
|
|
104
|
+
placeholder: "https://your-gateway.mypinata.cloud",
|
|
105
|
+
validate: (v) => {
|
|
106
|
+
if (!v) return "Required";
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
handleCancel(gateway);
|
|
110
|
+
const chainName = await select({
|
|
111
|
+
message: "Default chain:",
|
|
112
|
+
options: [{
|
|
113
|
+
value: SupportedNetworks.ArbitrumSepolia.name,
|
|
114
|
+
label: "Arbitrum Sepolia"
|
|
115
|
+
}, {
|
|
116
|
+
value: SupportedNetworks.BaseSepolia.name,
|
|
117
|
+
label: "Base Sepolia"
|
|
118
|
+
}]
|
|
119
|
+
});
|
|
120
|
+
handleCancel(chainName);
|
|
121
|
+
const stored = {
|
|
122
|
+
privateKey,
|
|
123
|
+
jwt,
|
|
124
|
+
gateway,
|
|
125
|
+
chainName
|
|
126
|
+
};
|
|
127
|
+
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
128
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
|
|
129
|
+
chmodSync(CONFIG_PATH, 384);
|
|
130
|
+
outro(`Config saved to ${CONFIG_PATH}`);
|
|
131
|
+
});
|
|
132
|
+
program.command("register").description("Register a new datasource as an agent.").argument("<name>", "Name of the datasource").option("-s, --skip-card", "Skip agent card creation").option("-e, --skip-erc", "Skip ERC-8007 registrion").option("-d, --skip-ds", "Skip datasource registrion").action(async (name, options) => {
|
|
133
|
+
try {
|
|
134
|
+
intro("Chain selection");
|
|
135
|
+
const chain = await selectChain();
|
|
136
|
+
outro(`Selected chain ${chain.name}`);
|
|
137
|
+
let registerDatasource = options.skipDs ? false : true;
|
|
138
|
+
let createAgentCard = options.skipCard ? false : true;
|
|
139
|
+
let erc8004Registration = options.skipErc ? false : true;
|
|
140
|
+
let description = "";
|
|
141
|
+
const s = spinner();
|
|
142
|
+
let datasourceAgentId;
|
|
143
|
+
if (createAgentCard) {
|
|
144
|
+
intro(`Agent Card Creation for ${chain.name}`);
|
|
145
|
+
while (createAgentCard) {
|
|
146
|
+
let builder = agentCardBuilder();
|
|
147
|
+
builder.name(name);
|
|
148
|
+
description = await text({ message: "Description of the Datasource:" });
|
|
149
|
+
handleCancel(description);
|
|
150
|
+
builder.description(description);
|
|
151
|
+
const version = await text({
|
|
152
|
+
message: "Agent Version:",
|
|
153
|
+
placeholder: "1.0.0"
|
|
154
|
+
});
|
|
155
|
+
handleCancel(version);
|
|
156
|
+
builder.version(version);
|
|
157
|
+
const url = await text({
|
|
158
|
+
message: "Base URL of the resource server:",
|
|
159
|
+
placeholder: "https://example.com"
|
|
160
|
+
});
|
|
161
|
+
handleCancel(url);
|
|
162
|
+
builder.url(url);
|
|
163
|
+
const provider = await text({ message: "Organization name:" });
|
|
164
|
+
handleCancel(provider);
|
|
165
|
+
const providerUrl = await text({ message: "Provider URL:" });
|
|
166
|
+
handleCancel(providerUrl);
|
|
167
|
+
builder.provider(provider, providerUrl);
|
|
168
|
+
let addSkill = true;
|
|
169
|
+
while (addSkill) {
|
|
170
|
+
const id = await text({ message: "ID of the skill (this must be unique):" });
|
|
171
|
+
handleCancel(id);
|
|
172
|
+
const skillName = await text({ message: "Name of the skill:" });
|
|
173
|
+
handleCancel(skillName);
|
|
174
|
+
const skillDescription = await text({ message: "Skill description:" });
|
|
175
|
+
handleCancel(skillDescription);
|
|
176
|
+
const tagsString = await text({ message: "Skill Tags (comma separated - spaces will be removed):" });
|
|
177
|
+
handleCancel(tagsString);
|
|
178
|
+
const tagsArray = tagsString.replaceAll(" ", "").split(",");
|
|
179
|
+
builder.addSkill(id, skillName, skillDescription, tagsArray);
|
|
180
|
+
addSkill = await confirm({ message: "Would you like to add another skill?" });
|
|
181
|
+
handleCancel(addSkill);
|
|
182
|
+
}
|
|
183
|
+
const agentCard = builder.build();
|
|
184
|
+
note(JSON.stringify(agentCard, null, 2), "Your agent card:");
|
|
185
|
+
const continueRegistration = await confirm({ message: "Does everything look correct? If not, agent card creation will start over." });
|
|
186
|
+
handleCancel(continueRegistration);
|
|
187
|
+
createAgentCard = !continueRegistration;
|
|
188
|
+
}
|
|
189
|
+
outro("Agent Card Creation is Complete.");
|
|
190
|
+
} else note("You are choosing to skip agent card creation. For ERC-8004 registration, we recommend you have an agent card either avaialbe\nat a url like: https://this.example.com/.well-known/agent-card.json\nThis allows for the automatic population of the agent's skills and indexes their capabilities for search.\nSimilarly, if your agent will have tools available via an MCP endpoint we recommend that you have the server running to allow for population of tools, prompts, and resources.");
|
|
191
|
+
intro(`Agent Registration for ${chain.name}`);
|
|
192
|
+
let cfg = loadConfig();
|
|
193
|
+
let agent0Sdk;
|
|
194
|
+
const ipfsOrHttp = await select({
|
|
195
|
+
message: "Choose your registration flow",
|
|
196
|
+
options: [{
|
|
197
|
+
value: "ipfs",
|
|
198
|
+
label: "IPFS (Pinata)"
|
|
199
|
+
}, {
|
|
200
|
+
value: "http",
|
|
201
|
+
label: "HTTP"
|
|
202
|
+
}]
|
|
203
|
+
});
|
|
204
|
+
handleCancel(ipfsOrHttp);
|
|
205
|
+
if (chain.id === 421614) {
|
|
206
|
+
const registryOverrides = { 421614: {
|
|
207
|
+
IDENTITY: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
|
|
208
|
+
REPUTATION: "0x8004B663056A597Dffe9eCcC1965A193B7388713"
|
|
209
|
+
} };
|
|
210
|
+
const subgraphOverrides = { 421614: "https://api.studio.thegraph.com/query/1742225/erc-8004-arbitrum-sepolia/version/latest" };
|
|
211
|
+
if (ipfsOrHttp === "ipfs") {
|
|
212
|
+
note("You have chosen to register using the IPFS route. It is assumed that your Pinata JWT and Pinata Gateway are stored in your .env file.", "INFO");
|
|
213
|
+
agent0Sdk = new SDK({
|
|
214
|
+
chainId: 421614,
|
|
215
|
+
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
216
|
+
subgraphUrl: "https://api.studio.thegraph.com/query/1742225/erc-8004-arbitrum-sepolia/version/latest",
|
|
217
|
+
registryOverrides,
|
|
218
|
+
subgraphOverrides,
|
|
219
|
+
ipfs: "pinata",
|
|
220
|
+
pinataJwt: cfg.jwt,
|
|
221
|
+
privateKey: cfg.privateKey
|
|
222
|
+
});
|
|
223
|
+
} else agent0Sdk = new SDK({
|
|
224
|
+
chainId: 421614,
|
|
225
|
+
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
226
|
+
subgraphUrl: "https://api.studio.thegraph.com/query/1742225/erc-8004-arbitrum-sepolia/version/latest",
|
|
227
|
+
registryOverrides,
|
|
228
|
+
subgraphOverrides,
|
|
229
|
+
privateKey: cfg.privateKey
|
|
230
|
+
});
|
|
231
|
+
} else if (ipfsOrHttp === "ipfs") {
|
|
232
|
+
note("You have chosen to register using the IPFS route. It is assumed that your Pinata JWT and Pinata Gateway are stored in your .env file.", "INFO");
|
|
233
|
+
agent0Sdk = new SDK({
|
|
234
|
+
chainId: chain.id,
|
|
235
|
+
rpcUrl: chain.rpcUrls.default.http[0],
|
|
236
|
+
ipfs: "pinata",
|
|
237
|
+
pinataJwt: cfg.jwt,
|
|
238
|
+
privateKey: cfg.privateKey
|
|
239
|
+
});
|
|
240
|
+
} else agent0Sdk = new SDK({
|
|
241
|
+
chainId: chain.id,
|
|
242
|
+
rpcUrl: chain.rpcUrls.default.http[0],
|
|
243
|
+
privateKey: cfg.privateKey
|
|
244
|
+
});
|
|
245
|
+
let agent;
|
|
246
|
+
while (erc8004Registration) {
|
|
247
|
+
if (description) {
|
|
248
|
+
const reuseDescription = await confirm({ message: "Would you like to re-use the description you submitted for your agent card?" });
|
|
249
|
+
handleCancel(reuseDescription);
|
|
250
|
+
if (!reuseDescription) {
|
|
251
|
+
description = await text({ message: "Description of the Datasource:" });
|
|
252
|
+
handleCancel(description);
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
description = await text({ message: "Description of the Datasource:" });
|
|
256
|
+
handleCancel(description);
|
|
257
|
+
}
|
|
258
|
+
agent = agent0Sdk.createAgent(name, description);
|
|
259
|
+
const agentCardAvailable = await confirm({ message: createAgentCard ? "Did you upload your agent card already?" : "Does your agent have an agent card?" });
|
|
260
|
+
handleCancel(agentCardAvailable);
|
|
261
|
+
if (agentCardAvailable) {
|
|
262
|
+
const agentCardLocation = await text({
|
|
263
|
+
message: "Location of agent card:",
|
|
264
|
+
placeholder: "https://example.com/.well-known/agentcard.json"
|
|
265
|
+
});
|
|
266
|
+
handleCancel(agentCardLocation);
|
|
267
|
+
s.start("Calling A2A endpoint to retrieve skills and capabilities");
|
|
268
|
+
await agent.setA2A(agentCardLocation);
|
|
269
|
+
s.stop("A2A fetch complete");
|
|
270
|
+
}
|
|
271
|
+
const mcpAvailable = await confirm({ message: "Does your agent have an MCP endpoint?" });
|
|
272
|
+
handleCancel(mcpAvailable);
|
|
273
|
+
if (mcpAvailable) {
|
|
274
|
+
const mcpEndpoint = await text({
|
|
275
|
+
message: "Location of MCP endpoint:",
|
|
276
|
+
placeholder: "https://example.com/mcp"
|
|
277
|
+
});
|
|
278
|
+
handleCancel(mcpEndpoint);
|
|
279
|
+
s.start("Retrieving tools, prompts, and resources");
|
|
280
|
+
await agent.setMCP(mcpEndpoint);
|
|
281
|
+
s.stop("MCP fetch complete");
|
|
282
|
+
}
|
|
283
|
+
const ensAvailable = await confirm({ message: "Does your agent have an ENS?" });
|
|
284
|
+
handleCancel(ensAvailable);
|
|
285
|
+
if (ensAvailable) {
|
|
286
|
+
const ens = await text({
|
|
287
|
+
message: "Agent's ENS:",
|
|
288
|
+
placeholder: "myagent.eth"
|
|
289
|
+
});
|
|
290
|
+
handleCancel(ens);
|
|
291
|
+
agent.setENS(ens);
|
|
292
|
+
}
|
|
293
|
+
let selectTrustModels = true;
|
|
294
|
+
while (selectTrustModels) {
|
|
295
|
+
const trustModels = await multiselect({
|
|
296
|
+
message: "(Optional) Select trust models (use Space for selection and Enter for submission):",
|
|
297
|
+
options: [
|
|
298
|
+
{
|
|
299
|
+
value: "reputation",
|
|
300
|
+
label: "Reputation"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
value: "cryptoEconomic",
|
|
304
|
+
label: "Crypto Economic"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
value: "teeAttestation",
|
|
308
|
+
label: "TEE Attestation"
|
|
309
|
+
}
|
|
310
|
+
],
|
|
311
|
+
required: false
|
|
312
|
+
});
|
|
313
|
+
handleCancel(trustModels);
|
|
314
|
+
if (!(trustModels.length > 0)) {
|
|
315
|
+
selectTrustModels = !await confirm({ message: "You have chosen no trust models. Is this correct?" });
|
|
316
|
+
handleCancel(selectTrustModels);
|
|
317
|
+
if (!selectTrustModels) agent.setTrust(trustModels.includes("reputation"), trustModels.includes("cryptoEconomic"), trustModels.includes("teeAttestation"));
|
|
318
|
+
} else {
|
|
319
|
+
selectTrustModels = false;
|
|
320
|
+
agent.setTrust(trustModels.includes("reputation"), trustModels.includes("cryptoEconomic"), trustModels.includes("teeAttestation"));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
let setMetadata = await confirm({ message: "Would you like to set metadata?" });
|
|
324
|
+
handleCancel(setMetadata);
|
|
325
|
+
if (setMetadata) {
|
|
326
|
+
const metadata = {};
|
|
327
|
+
while (setMetadata) {
|
|
328
|
+
const key = await text({
|
|
329
|
+
message: "Key:",
|
|
330
|
+
placeholder: "examples: version/category/etc."
|
|
331
|
+
});
|
|
332
|
+
handleCancel(key);
|
|
333
|
+
const value = await text({
|
|
334
|
+
message: "Value:",
|
|
335
|
+
placeholder: "examples: 1.0.0/datasource/etc."
|
|
336
|
+
});
|
|
337
|
+
handleCancel(value);
|
|
338
|
+
metadata[key] = value;
|
|
339
|
+
setMetadata = await confirm({ message: "Would you like to add more metadata?" });
|
|
340
|
+
}
|
|
341
|
+
agent.setMetadata(metadata);
|
|
342
|
+
}
|
|
343
|
+
agent.setActive(true);
|
|
344
|
+
agent.setX402Support(true);
|
|
345
|
+
note(JSON.stringify(agent.getRegistrationFile(), null, 2), "Your ERC-8004 registration:");
|
|
346
|
+
const completeRegistration = await confirm({ message: "Does everything look correct? If not, ERC registration will start over." });
|
|
347
|
+
handleCancel(completeRegistration);
|
|
348
|
+
if (completeRegistration) {
|
|
349
|
+
erc8004Registration = false;
|
|
350
|
+
if (ipfsOrHttp === "http") {
|
|
351
|
+
note("You have chosen to use http to host your registration file. It is recommended to use https://example.com/.well-known/agent-registration.json for verifiers to treat you endpoint domain as \"Verified\"", "INFO");
|
|
352
|
+
note(JSON.stringify(agent.getRegistrationFile()), "Your Registration File");
|
|
353
|
+
} else {
|
|
354
|
+
s.start("Registering with ERC-8004 registry");
|
|
355
|
+
const regTx = await agent.registerIPFS();
|
|
356
|
+
s.stop();
|
|
357
|
+
s.start("Waiting for registration transaction to be confirmed");
|
|
358
|
+
const { result: registrationFile } = await regTx.waitConfirmed();
|
|
359
|
+
s.stop();
|
|
360
|
+
datasourceAgentId = registrationFile.agentId;
|
|
361
|
+
note(`Agent registration complete for agent name ${name}. They have the ID: ${datasourceAgentId}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
outro(`Agent Registration is Complete for ${chain.name}`);
|
|
366
|
+
if (registerDatasource) {
|
|
367
|
+
if (!datasourceAgentId) {
|
|
368
|
+
const agentsList = await agent0Sdk.searchAgents({ name });
|
|
369
|
+
if (agentsList.length > 0) datasourceAgentId = agentsList[0].agentId;
|
|
370
|
+
else throw new Error(`Agent with name ${name} was not found on the ERC-8004 on ${chain.name}`);
|
|
371
|
+
}
|
|
372
|
+
note(`Data source ${name} registered with id = ${await (await getFangorn(chain)).registerDataSource(name, datasourceAgentId)}`);
|
|
373
|
+
}
|
|
374
|
+
process.exit(0);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
console.error("Failed to register:", err.message);
|
|
377
|
+
process.exit(1);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
program.command("upload").description("Upload file(s) to a data source").argument("<name>", "Data source name").argument("<files...>", "File path(s) to upload").option("-c, --chain <chain>", "The chain to use as the backend (arbitrumSepolia or baseSepolia)").option("-g, --gadget <type(args)>", "Gadget to use (e.g. Payment(0.000001))").option("-o --overwrite", "Overwrite existing data source contents").action(async (name, files, options) => {
|
|
381
|
+
try {
|
|
382
|
+
const owner = getAccount().address;
|
|
383
|
+
const fangorn = await getFangorn(getChain(options.chain));
|
|
384
|
+
const filedata = files.map((filepath) => {
|
|
385
|
+
const data = readFileSync(filepath);
|
|
386
|
+
const tag = basename(filepath);
|
|
387
|
+
const extension = extname(filepath);
|
|
388
|
+
return {
|
|
389
|
+
tag,
|
|
390
|
+
data: data.toString("base64"),
|
|
391
|
+
price: options.price,
|
|
392
|
+
extension,
|
|
393
|
+
fileType: getMimeType(extension)
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
const cid = await fangorn.upload(name, filedata, async (file) => {
|
|
397
|
+
if (options.gadget) {
|
|
398
|
+
const { type, args } = parseGadgetArg(options.gadget);
|
|
399
|
+
const def = GADGET_REGISTRY[type];
|
|
400
|
+
if (!def) throw new Error(`Unknown gadget type: ${type}`);
|
|
401
|
+
const params = {};
|
|
402
|
+
def.argSchema.forEach((key, i) => {
|
|
403
|
+
params[key] = args[i];
|
|
404
|
+
});
|
|
405
|
+
params.commitment = fieldToHex(await computeTagCommitment(owner, name, file.tag, options.price));
|
|
406
|
+
params.chainName = options.chain;
|
|
407
|
+
params.settlementTrackerContractAddress = options.chain === "arbitrumSepolia" ? "0x7c6ae9eb3398234eb69b2f3acfae69065505ff69" : "0x708751829f5f5f584da4142b62cd5cc9235c8a18";
|
|
408
|
+
params.pinataJwt = loadConfig().jwt;
|
|
409
|
+
return def.build(params);
|
|
410
|
+
}
|
|
411
|
+
return selectGadget(owner, name, file.tag, options.price);
|
|
412
|
+
}, options.overwrite);
|
|
413
|
+
console.log(`Upload complete! Manifest CID: ${cid}`);
|
|
414
|
+
process.exit(0);
|
|
415
|
+
} catch (err) {
|
|
416
|
+
console.error("Failed to upload:", err.message);
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
program.command("list").description("List contents (index) of a data source").argument("<name>", "Data source name").option("-c, --chain <chain>", "The chain to use as the backend (arbitrumSepolia or baseSepolia)").action(async (name, options) => {
|
|
421
|
+
try {
|
|
422
|
+
const owner = getAccount().address;
|
|
423
|
+
const manifest = await (await getFangorn(getChain(options.chain))).getManifest(owner, name);
|
|
424
|
+
if (!manifest) {
|
|
425
|
+
console.log("The data source is empty. \n");
|
|
426
|
+
console.log("Upload data with `fangorn upload <dataSourceName> <file> --price <set-price>");
|
|
427
|
+
process.exit(0);
|
|
428
|
+
}
|
|
429
|
+
console.log(`Datasource: ${name} (${owner})`);
|
|
430
|
+
console.log(`Entries (${manifest.entries.length}):`);
|
|
431
|
+
for (const entry of manifest.entries) console.log(` - ${entry.tag} | gadget descriptor: ${JSON.stringify(entry.gadgetDescriptor)} | cid: ${entry.cid}`);
|
|
432
|
+
process.exit(0);
|
|
433
|
+
} catch (err) {
|
|
434
|
+
console.error("Failed to list vault:", err.message);
|
|
435
|
+
process.exit(1);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
program.command("info").description("Get data source info from contract").argument("<name>", "Data source name").option("-c, --chain <chain>", "The chain to use as the backend (arbitrumSepolia or baseSepolia)").action(async (name, options) => {
|
|
439
|
+
try {
|
|
440
|
+
const owner = getAccount().address;
|
|
441
|
+
const vault = await (await getFangorn(getChain(options.chain))).getDataSource(owner, name);
|
|
442
|
+
console.log(`Datasource: ${name} (${owner})`);
|
|
443
|
+
console.log(`Owner: ${vault.owner}`);
|
|
444
|
+
console.log(`Manifest CID: ${vault.manifestCid == "" ? "Upload data with `fangorn upload <vaultName> <file> --price <set-price>`" : vault.manifestCid}`);
|
|
445
|
+
process.exit(0);
|
|
446
|
+
} catch (err) {
|
|
447
|
+
console.error("Failed to get vault info:", err.message);
|
|
448
|
+
process.exit(1);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
program.command("entry").description("Get info about a specific entry").argument("<name>", "Vault name").argument("<tag>", "File tag").option("-c, --chain <chain>", "The chain to use as the backend (arbitrumSepolia or baseSepolia").action(async (name, tag, options) => {
|
|
452
|
+
try {
|
|
453
|
+
const owner = getAccount().address;
|
|
454
|
+
const entry = await (await getFangorn(getChain(options.chain))).getDataSourceData(owner, name, tag);
|
|
455
|
+
console.log(`Entry: ${tag}`);
|
|
456
|
+
console.log(` CID: ${entry.cid}`);
|
|
457
|
+
console.log(` Gadget Descriptor: ${JSON.stringify(entry.gadgetDescriptor)}`);
|
|
458
|
+
process.exit(0);
|
|
459
|
+
} catch (err) {
|
|
460
|
+
console.error("Failed to get entry:", err.message);
|
|
461
|
+
process.exit(1);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
program.command("decrypt").description("Decrypt a file from a vault").argument("<owner>", "The owner of the datasource").argument("<name>", "The name of the datasource").argument("<tag>", "File tag").option("-c, --chain <chain>", "The chain to use as the backend (arbitrumSepolia or baseSepolia").option("-o, --output <path>", "Output file path").action(async (owner, name, tag, options) => {
|
|
465
|
+
try {
|
|
466
|
+
const decrypted = await (await getFangorn(getChain(options.chain))).decryptFile(owner, name, tag);
|
|
467
|
+
if (options.output) {
|
|
468
|
+
writeFileSync(options.output, Buffer.from(decrypted));
|
|
469
|
+
console.log(`Decrypted file saved to: ${options.output}`);
|
|
470
|
+
} else {
|
|
471
|
+
const buf = Buffer.from(decrypted);
|
|
472
|
+
process.stdout.write(atob(buf.toString()));
|
|
473
|
+
process.stdout.write("\n");
|
|
474
|
+
}
|
|
475
|
+
process.exit(0);
|
|
476
|
+
} catch (err) {
|
|
477
|
+
console.error("Failed to decrypt:", err.message);
|
|
478
|
+
process.exit(1);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
function getMimeType(ext) {
|
|
482
|
+
return {
|
|
483
|
+
".txt": "text/plain",
|
|
484
|
+
".json": "application/json",
|
|
485
|
+
".html": "text/html",
|
|
486
|
+
".css": "text/css",
|
|
487
|
+
".js": "application/javascript",
|
|
488
|
+
".png": "image/png",
|
|
489
|
+
".jpg": "image/jpeg",
|
|
490
|
+
".jpeg": "image/jpeg",
|
|
491
|
+
".gif": "image/gif",
|
|
492
|
+
".pdf": "application/pdf",
|
|
493
|
+
".mp3": "audio/mpeg",
|
|
494
|
+
".mp4": "video/mp4"
|
|
495
|
+
}[ext.toLowerCase()] || "application/octet-stream";
|
|
496
|
+
}
|
|
497
|
+
program.parse();
|
|
498
|
+
|
|
499
|
+
//#endregion
|
|
500
|
+
export { };
|