@fangorn-network/sdk 2026.3.11 → 2026.3.28
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 +311 -198
- package/lib/builders/a2aCardBuilder.js +1 -0
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +399 -380
- package/lib/cli/index.d.ts +170 -170
- package/lib/cli/index.js +1 -4
- package/lib/config.d.ts +543 -163
- package/lib/config.js +11 -8
- package/lib/fangorn.d.ts +31 -43
- package/lib/fangorn.js +101 -117
- package/lib/index.d.ts +8 -5
- package/lib/index.js +8 -7
- package/lib/modules/encryption/index.d.ts +4 -3
- package/lib/modules/encryption/lit.d.ts +3 -18
- package/lib/modules/encryption/lit.js +20 -49
- package/lib/modules/encryption/rand.js +2 -2
- package/lib/modules/encryption/types.d.ts +23 -8
- package/lib/modules/gadgets/settledGadget.d.ts +31 -0
- package/lib/modules/gadgets/settledGadget.js +75 -0
- package/lib/modules/gadgets/types.d.ts +16 -4
- package/lib/providers/storage/index.d.ts +15 -4
- package/lib/providers/storage/pinata/index.d.ts +5 -4
- package/lib/providers/storage/pinata/index.js +17 -2
- package/lib/providers/storage/storacha/index.d.ts +13 -0
- package/lib/providers/storage/storacha/index.js +49 -0
- package/lib/providers/storage/storacha/readOnly.d.ts +8 -0
- package/lib/providers/storage/storacha/readOnly.js +16 -0
- package/lib/{interface → registries}/datasource-registry/abi.d.ts +29 -43
- package/lib/registries/datasource-registry/abi.js +16 -0
- package/lib/registries/datasource-registry/index.d.ts +24 -0
- package/lib/{interface/datasource-registry/dataSourceRegistry.js → registries/datasource-registry/index.js} +35 -34
- package/lib/registries/index.d.ts +3 -0
- package/lib/registries/index.js +4 -0
- package/lib/registries/schema-registry/abi.d.ts +127 -0
- package/lib/registries/schema-registry/abi.js +19 -0
- package/lib/registries/schema-registry/index.d.ts +29 -0
- package/lib/registries/schema-registry/index.js +114 -0
- package/lib/registries/settlement-registry/abi.d.ts +228 -0
- package/lib/registries/settlement-registry/abi.js +29 -0
- package/lib/registries/settlement-registry/index.d.ts +72 -0
- package/lib/registries/settlement-registry/index.js +316 -0
- package/lib/registries/settlement-registry/types.d.ts +51 -0
- package/lib/roles/consumer/index.d.ts +64 -0
- package/lib/roles/consumer/index.js +114 -0
- package/lib/roles/consumer/types.d.ts +66 -0
- package/lib/roles/index.js +1 -0
- package/lib/roles/publisher/index.d.ts +68 -0
- package/lib/roles/publisher/index.js +205 -0
- package/lib/roles/publisher/types.d.ts +93 -0
- package/lib/roles/publisher/types.js +1 -0
- package/lib/roles/schema/index.d.ts +44 -0
- package/lib/roles/schema/index.js +137 -0
- package/lib/roles/schema/types.d.ts +67 -0
- package/lib/roles/schema/types.js +1 -0
- package/lib/test/index.d.ts +5 -2
- package/lib/test/index.js +5 -3
- package/lib/test/testbed.d.ts +52 -32
- package/lib/test/testbed.js +138 -137
- package/lib/types/index.d.ts +65 -21
- package/lib/types/index.js +1 -12
- package/lib/utils/index.d.ts +2 -3
- package/lib/utils/index.js +4 -18
- package/package.json +85 -81
- package/lib/cli/registry.d.ts +0 -29
- package/lib/cli/registry.js +0 -53
- package/lib/deployContract.d.ts +0 -23
- package/lib/deployContract.js +0 -78
- package/lib/interface/datasource-registry/abi.js +0 -110
- package/lib/interface/datasource-registry/dataSourceRegistry.d.ts +0 -24
- package/lib/interface/index.d.ts +0 -3
- package/lib/interface/index.js +0 -4
- package/lib/interface/manifest.d.ts +0 -7
- package/lib/interface/manifest.js +0 -10
- package/lib/interface/settlement-tracker/abi.d.ts +0 -26
- package/lib/interface/settlement-tracker/abi.js +0 -88
- package/lib/interface/settlement-tracker/settlementTracker.d.ts +0 -32
- package/lib/interface/settlement-tracker/settlementTracker.js +0 -64
- package/lib/modules/gadgets/acc/gadgets.d.ts +0 -7
- package/lib/modules/gadgets/acc/gadgets.js +0 -10
- package/lib/modules/gadgets/acc.d.ts +0 -15
- package/lib/modules/gadgets/acc.js +0 -24
- package/lib/modules/gadgets/builder.d.ts +0 -1
- package/lib/modules/gadgets/payment.d.ts +0 -23
- package/lib/modules/gadgets/payment.js +0 -88
- package/lib/test/test-gadget.d.ts +0 -7
- package/lib/test/test-gadget.js +0 -10
- /package/lib/{modules/gadgets/builder.js → registries/settlement-registry/types.js} +0 -0
- /package/lib/{providers/storage/s3/index.js → roles/consumer/types.js} +0 -0
- /package/lib/{providers/storage/s3 → roles}/index.d.ts +0 -0
package/lib/cli/cli.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { FangornConfig, SupportedNetworks } from "../config.js";
|
|
3
|
+
import { SettlementRegistry } from "../registries/settlement-registry/index.js";
|
|
3
4
|
import { Fangorn } from "../fangorn.js";
|
|
4
|
-
import {
|
|
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";
|
|
5
|
+
import { getChain, handleCancel, selectChain } from "./index.js";
|
|
13
6
|
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
7
|
import { privateKeyToAccount } from "viem/accounts";
|
|
18
|
-
import "
|
|
19
|
-
import {
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
import { confirm, intro, note, outro, select, spinner, text } from "@clack/prompts";
|
|
10
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
11
|
+
import { extname, join } from "path";
|
|
20
12
|
import { homedir } from "os";
|
|
13
|
+
import { Identity } from "@semaphore-protocol/identity";
|
|
14
|
+
import "dotenv/config";
|
|
21
15
|
|
|
22
16
|
//#region src/cli/cli.ts
|
|
23
17
|
const CONFIG_DIR = join(homedir(), ".fangorn");
|
|
@@ -25,88 +19,98 @@ const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
|
25
19
|
let _config = null;
|
|
26
20
|
let _account = null;
|
|
27
21
|
let _fangorn = null;
|
|
22
|
+
function buildConfig(stored) {
|
|
23
|
+
let cfg = FangornConfig.BaseSepolia;
|
|
24
|
+
if (stored.chainName === SupportedNetworks.ArbitrumSepolia.name) cfg = FangornConfig.ArbitrumSepolia;
|
|
25
|
+
return {
|
|
26
|
+
privateKey: stored.privateKey,
|
|
27
|
+
cfg,
|
|
28
|
+
storage: stored.storage,
|
|
29
|
+
jwt: stored.jwt,
|
|
30
|
+
gateway: stored.gateway,
|
|
31
|
+
storachaEmail: stored.storachaEmail
|
|
32
|
+
};
|
|
33
|
+
}
|
|
28
34
|
function loadConfig() {
|
|
29
35
|
if (_config) return _config;
|
|
30
36
|
const privateKey = process.env.DELEGATOR_ETH_PRIVATE_KEY;
|
|
31
37
|
const jwt = process.env.PINATA_JWT;
|
|
32
38
|
const gateway = process.env.PINATA_GATEWAY;
|
|
33
39
|
const chainName = process.env.CHAIN_NAME;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const storachaEmail = process.env.STORACHA_EMAIL;
|
|
41
|
+
if (privateKey && chainName) {
|
|
42
|
+
if (jwt && gateway) {
|
|
43
|
+
_config = buildConfig({
|
|
44
|
+
privateKey,
|
|
45
|
+
chainName,
|
|
46
|
+
storage: "pinata",
|
|
47
|
+
jwt,
|
|
48
|
+
gateway
|
|
49
|
+
});
|
|
50
|
+
return _config;
|
|
51
|
+
}
|
|
52
|
+
if (storachaEmail) {
|
|
53
|
+
_config = buildConfig({
|
|
54
|
+
privateKey,
|
|
55
|
+
chainName,
|
|
56
|
+
storage: "storacha",
|
|
57
|
+
storachaEmail
|
|
58
|
+
});
|
|
59
|
+
return _config;
|
|
60
|
+
}
|
|
42
61
|
}
|
|
43
62
|
if (existsSync(CONFIG_PATH)) {
|
|
44
63
|
_config = buildConfig(JSON.parse(readFileSync(CONFIG_PATH, "utf-8")));
|
|
45
64
|
return _config;
|
|
46
65
|
}
|
|
47
|
-
throw new Error("No configuration found. Run `fangorn init`
|
|
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
|
-
};
|
|
66
|
+
throw new Error("No configuration found. Run `fangorn init` or set the required env vars.\n Pinata: DELEGATOR_ETH_PRIVATE_KEY, PINATA_JWT, PINATA_GATEWAY, CHAIN_NAME\n Storacha: DELEGATOR_ETH_PRIVATE_KEY, STORACHA_EMAIL, CHAIN_NAME");
|
|
58
67
|
}
|
|
59
68
|
function getAccount() {
|
|
60
69
|
if (_account) return _account;
|
|
61
70
|
_account = privateKeyToAccount(loadConfig().privateKey);
|
|
62
71
|
return _account;
|
|
63
72
|
}
|
|
64
|
-
async function getFangorn(
|
|
73
|
+
async function getFangorn() {
|
|
65
74
|
if (_fangorn) return _fangorn;
|
|
66
75
|
const cfg = loadConfig();
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
const agentConfig = {
|
|
77
|
+
privateKey: cfg.privateKey,
|
|
78
|
+
pinataJwt: cfg.jwt ?? ""
|
|
79
|
+
};
|
|
80
|
+
const storage = cfg.storage === "storacha" ? { storacha: { email: cfg.storachaEmail ?? "" } } : { pinata: {
|
|
81
|
+
jwt: cfg.jwt ?? "",
|
|
82
|
+
gateway: cfg.gateway ?? ""
|
|
83
|
+
} };
|
|
84
|
+
_fangorn = await Fangorn.create({
|
|
85
|
+
privateKey: cfg.privateKey,
|
|
86
|
+
storage,
|
|
87
|
+
encryption: { lit: true },
|
|
88
|
+
domain: "localhost",
|
|
89
|
+
config: cfg.cfg,
|
|
90
|
+
agentConfig
|
|
71
91
|
});
|
|
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
92
|
return _fangorn;
|
|
82
93
|
}
|
|
94
|
+
async function resolveSchemaId(fangorn, schemaName) {
|
|
95
|
+
try {
|
|
96
|
+
return await fangorn.getSchemaRegistry().schemaId(typeof schemaName === "string" && !/^0x[0-9a-fA-F]{64}$/.test(schemaName) ? schemaName : schemaName);
|
|
97
|
+
} catch {
|
|
98
|
+
throw new Error(`Schema "${schemaName}" not found on-chain. Register it with \`fangorn schema register\`.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
83
101
|
const program = new Command();
|
|
84
|
-
program.name("
|
|
102
|
+
program.name("fangorn").description("Fangorn Network CLI").version("0.1.0");
|
|
85
103
|
program.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
86
104
|
intro("Fangorn Setup");
|
|
87
105
|
const privateKey = await text({
|
|
88
|
-
message: "
|
|
106
|
+
message: "Wallet private key (stored locally, never transmitted):",
|
|
89
107
|
placeholder: "0x...",
|
|
90
108
|
validate: (v) => {
|
|
109
|
+
if (!v) return "Required";
|
|
91
110
|
if (!v.startsWith("0x") || v.length !== 66) return "Must be a valid 0x-prefixed 32-byte hex key";
|
|
92
111
|
}
|
|
93
112
|
});
|
|
94
113
|
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
114
|
const chainName = await select({
|
|
111
115
|
message: "Default chain:",
|
|
112
116
|
options: [{
|
|
@@ -118,382 +122,397 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
118
122
|
}]
|
|
119
123
|
});
|
|
120
124
|
handleCancel(chainName);
|
|
125
|
+
const storageChoice = await select({
|
|
126
|
+
message: "Storage provider:",
|
|
127
|
+
options: [{
|
|
128
|
+
value: "pinata",
|
|
129
|
+
label: "Pinata"
|
|
130
|
+
}, {
|
|
131
|
+
value: "storacha",
|
|
132
|
+
label: "Storacha"
|
|
133
|
+
}]
|
|
134
|
+
});
|
|
135
|
+
handleCancel(storageChoice);
|
|
121
136
|
const stored = {
|
|
122
137
|
privateKey,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
chainName
|
|
138
|
+
chainName,
|
|
139
|
+
storage: storageChoice
|
|
126
140
|
};
|
|
141
|
+
if (storageChoice === "pinata") {
|
|
142
|
+
const jwt = await text({
|
|
143
|
+
message: "Pinata JWT:",
|
|
144
|
+
validate: (v) => {
|
|
145
|
+
if (!v) return "Required";
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
handleCancel(jwt);
|
|
149
|
+
const gateway = await text({
|
|
150
|
+
message: "Pinata Gateway URL:",
|
|
151
|
+
placeholder: "https://your-gateway.mypinata.cloud",
|
|
152
|
+
validate: (v) => {
|
|
153
|
+
if (!v) return "Required";
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
handleCancel(gateway);
|
|
157
|
+
stored.jwt = jwt;
|
|
158
|
+
stored.gateway = gateway;
|
|
159
|
+
} else {
|
|
160
|
+
const storachaEmail = await text({
|
|
161
|
+
message: "Storacha email:",
|
|
162
|
+
placeholder: "you@example.com",
|
|
163
|
+
validate: (v) => {
|
|
164
|
+
if (!v) return "Required";
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
handleCancel(storachaEmail);
|
|
168
|
+
stored.storachaEmail = storachaEmail;
|
|
169
|
+
}
|
|
127
170
|
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
128
171
|
writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
|
|
129
172
|
chmodSync(CONFIG_PATH, 384);
|
|
130
173
|
outro(`Config saved to ${CONFIG_PATH}`);
|
|
131
174
|
});
|
|
132
|
-
program.command("
|
|
175
|
+
const schemaCmd = program.command("schema").description("Schema registry operations");
|
|
176
|
+
schemaCmd.command("register").description("Register an agent identity and/or a schema on-chain").argument("<name>", "Schema / agent name").option("-e, --skip-erc", "Skip ERC-8004 agent registration").action(async (name, options) => {
|
|
133
177
|
try {
|
|
134
178
|
intro("Chain selection");
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
let
|
|
138
|
-
let createAgentCard = options.skipCard ? false : true;
|
|
139
|
-
let erc8004Registration = options.skipErc ? false : true;
|
|
179
|
+
outro(`Selected chain: ${(await selectChain()).name}`);
|
|
180
|
+
const fangorn = await getFangorn();
|
|
181
|
+
let datasourceAgentId = "";
|
|
140
182
|
let description = "";
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
183
|
+
if (!options.skipErc) {
|
|
184
|
+
intro("ERC-8004 Agent Registration");
|
|
185
|
+
description = await text({ message: "Agent description:" });
|
|
186
|
+
handleCancel(description);
|
|
187
|
+
const s$1 = spinner();
|
|
188
|
+
s$1.start("Registering agent...");
|
|
189
|
+
const { agentId } = await fangorn.schema.registerAgent({
|
|
190
|
+
name,
|
|
191
|
+
description
|
|
230
192
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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);
|
|
193
|
+
s$1.stop();
|
|
194
|
+
datasourceAgentId = agentId;
|
|
195
|
+
note(`Agent ID: ${agentId}`, "ERC-8004 registered");
|
|
196
|
+
outro("Agent Registration complete.");
|
|
197
|
+
}
|
|
198
|
+
intro("Schema Registration");
|
|
199
|
+
const schemaFilePath = await text({
|
|
200
|
+
message: "Path to your JSON schema file:",
|
|
201
|
+
placeholder: "./schema.json",
|
|
202
|
+
validate: (v) => {
|
|
203
|
+
if (!v) return "Required";
|
|
204
|
+
if (!existsSync(v)) return `File not found: ${v}`;
|
|
205
|
+
if (extname(v).toLowerCase() !== ".json") return "Must be a .json file";
|
|
342
206
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
}
|
|
207
|
+
});
|
|
208
|
+
handleCancel(schemaFilePath);
|
|
209
|
+
const schemaName = await text({
|
|
210
|
+
message: "Schema name (e.g. fangorn.music.v1):",
|
|
211
|
+
placeholder: "fangorn.myapp.v1",
|
|
212
|
+
validate: (v) => {
|
|
213
|
+
if (!v) return "Required";
|
|
363
214
|
}
|
|
215
|
+
});
|
|
216
|
+
handleCancel(schemaName);
|
|
217
|
+
let definition;
|
|
218
|
+
try {
|
|
219
|
+
definition = JSON.parse(readFileSync(schemaFilePath, "utf-8"));
|
|
220
|
+
} catch {
|
|
221
|
+
throw new Error(`Failed to parse ${schemaFilePath} as JSON`);
|
|
364
222
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
223
|
+
note(JSON.stringify(definition, null, 2), "Schema definition:");
|
|
224
|
+
const ok = await confirm({ message: "Register this schema?" });
|
|
225
|
+
handleCancel(ok);
|
|
226
|
+
if (!ok) {
|
|
227
|
+
outro("Cancelled.");
|
|
228
|
+
process.exit(0);
|
|
229
|
+
}
|
|
230
|
+
const s = spinner();
|
|
231
|
+
s.start("Registering schema");
|
|
232
|
+
const { schemaId, schemaCid } = await fangorn.schema.register({
|
|
233
|
+
name: schemaName,
|
|
234
|
+
definition,
|
|
235
|
+
agentId: datasourceAgentId
|
|
236
|
+
});
|
|
237
|
+
s.stop();
|
|
238
|
+
note(`Schema ID: ${schemaId}\nCID: ${schemaCid}`, "Schema registered");
|
|
239
|
+
process.exit(0);
|
|
240
|
+
} catch (err) {
|
|
241
|
+
console.error("Failed:", err.message);
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
schemaCmd.command("get").description("Fetch a registered schema by name").argument("<name>", "Schema name (e.g. fangorn.music.v1)").option("-c, --chain <chain>", "Chain to use").action(async (name) => {
|
|
246
|
+
try {
|
|
247
|
+
const fangorn = await getFangorn();
|
|
248
|
+
const s = spinner();
|
|
249
|
+
s.start(`Fetching schema "${name}"...`);
|
|
250
|
+
const schema = await fangorn.schema.get(name);
|
|
251
|
+
s.stop();
|
|
252
|
+
if (!schema) {
|
|
253
|
+
console.log(`Schema "${name}" not found.`);
|
|
254
|
+
process.exit(1);
|
|
373
255
|
}
|
|
256
|
+
note(JSON.stringify(schema, null, 2), `Schema: ${name}`);
|
|
374
257
|
process.exit(0);
|
|
375
258
|
} catch (err) {
|
|
376
|
-
console.error("Failed
|
|
259
|
+
console.error("Failed:", err.message);
|
|
377
260
|
process.exit(1);
|
|
378
261
|
}
|
|
379
262
|
});
|
|
380
|
-
program.command("
|
|
263
|
+
const publishCmd = program.command("publish").description("Publisher operations");
|
|
264
|
+
publishCmd.command("upload").description("Encrypt and publish file(s) under a schema").argument("<files...>", "File path(s) to upload").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID (e.g. 0x...)").option("-c, --chain <chain>", "Chain to use").option("-p, --price <USDC>", "Resource price in USDC", "0").option("-o, --overwrite", "If true, overwrite any existing data", false).action(async (files, options) => {
|
|
381
265
|
try {
|
|
382
|
-
const
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
266
|
+
const fangorn = await getFangorn();
|
|
267
|
+
const cfg = loadConfig();
|
|
268
|
+
const price = BigInt(options.price);
|
|
269
|
+
const s = spinner();
|
|
270
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
271
|
+
const schema = (await fangorn.schema.get(options.schema))?.definition ?? {};
|
|
272
|
+
const records = files.flatMap((filepath) => {
|
|
273
|
+
const data = readFileSync(filepath, "utf-8");
|
|
274
|
+
const parsed = JSON.parse(data, (key, value) => {
|
|
275
|
+
if (key === "data") {
|
|
276
|
+
if (Array.isArray(value)) return new Uint8Array(value.map((v) => Number(v)));
|
|
277
|
+
if (typeof value === "object" && value !== null) {
|
|
278
|
+
const obj = value;
|
|
279
|
+
return new Uint8Array(Object.values(obj).map((v) => Number(v)));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return value;
|
|
283
|
+
});
|
|
284
|
+
return Array.isArray(parsed) ? parsed : [parsed];
|
|
395
285
|
});
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
286
|
+
const gateway = cfg.storage === "pinata" ? cfg.gateway ?? "" : "";
|
|
287
|
+
s.start("Encrypting and publishing...");
|
|
288
|
+
const result = await fangorn.publisher.upload({
|
|
289
|
+
records,
|
|
290
|
+
schema,
|
|
291
|
+
schemaId,
|
|
292
|
+
gateway,
|
|
293
|
+
options: { overwrite: options.overwrite }
|
|
294
|
+
}, price);
|
|
295
|
+
s.stop();
|
|
296
|
+
note(`Manifest CID: ${result.manifestCid}\nEntries: ${result.entryCount.toString()}\nSchema: ${result.schemaId}`, "Upload complete");
|
|
297
|
+
process.exit(0);
|
|
298
|
+
} catch (err) {
|
|
299
|
+
console.error("Failed:", err.message);
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
publishCmd.command("list").description("List your manifest entries for a schema").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").option("-c, --chain <chain>", "Chain to use").action(async (options) => {
|
|
304
|
+
try {
|
|
305
|
+
const fangorn = await getFangorn();
|
|
306
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
307
|
+
const manifest = await fangorn.publisher.getManifest(schemaId);
|
|
308
|
+
if (!manifest) {
|
|
309
|
+
console.log("No manifest found. Upload with `fangorn publish upload <files> -s <schema>`.");
|
|
310
|
+
process.exit(0);
|
|
311
|
+
}
|
|
312
|
+
console.log(`Schema: ${options.schema}`);
|
|
313
|
+
console.log(`Entries (${manifest.entries.length.toString()}):`);
|
|
314
|
+
for (const entry of manifest.entries) console.log(` - ${entry.tag}`);
|
|
315
|
+
process.exit(0);
|
|
316
|
+
} catch (err) {
|
|
317
|
+
console.error("Failed:", err.message);
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
publishCmd.command("entry").description("Show details for one of your manifest entries").argument("<tag>", "Entry tag").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").option("-c, --chain <chain>", "Chain to use").action(async (tag, options) => {
|
|
322
|
+
try {
|
|
323
|
+
const fangorn = await getFangorn();
|
|
324
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
325
|
+
const entry = await fangorn.publisher.getEntry(schemaId, tag);
|
|
326
|
+
note(JSON.stringify(entry, null, 2), `Entry: ${tag}`);
|
|
414
327
|
process.exit(0);
|
|
415
328
|
} catch (err) {
|
|
416
|
-
console.error("Failed
|
|
329
|
+
console.error("Failed:", err.message);
|
|
417
330
|
process.exit(1);
|
|
418
331
|
}
|
|
419
332
|
});
|
|
420
|
-
program.command("
|
|
333
|
+
const consumeCmd = program.command("consume").description("Consumer operations");
|
|
334
|
+
consumeCmd.command("list").description("List a publisher's manifest entries").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").requiredOption("--owner <address>", "Publisher address").option("-c, --chain <chain>", "Chain to use").action(async (options) => {
|
|
421
335
|
try {
|
|
422
|
-
const
|
|
423
|
-
const
|
|
336
|
+
const fangorn = await getFangorn();
|
|
337
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
338
|
+
const manifest = await fangorn.consumer.getManifest(options.owner, schemaId);
|
|
424
339
|
if (!manifest) {
|
|
425
|
-
console.log("
|
|
426
|
-
console.log("Upload data with `fangorn upload <dataSourceName> <file> --price <set-price>");
|
|
340
|
+
console.log("No manifest found.");
|
|
427
341
|
process.exit(0);
|
|
428
342
|
}
|
|
429
|
-
console.log(`
|
|
430
|
-
console.log(`
|
|
431
|
-
|
|
343
|
+
console.log(`Owner: ${options.owner}`);
|
|
344
|
+
console.log(`Schema: ${options.schema}`);
|
|
345
|
+
console.log(`Entries (${manifest.entries.length.toString()}):`);
|
|
346
|
+
for (const entry of manifest.entries) console.log(` - ${entry.tag}`);
|
|
432
347
|
process.exit(0);
|
|
433
348
|
} catch (err) {
|
|
434
|
-
console.error("Failed
|
|
349
|
+
console.error("Failed:", err.message);
|
|
435
350
|
process.exit(1);
|
|
436
351
|
}
|
|
437
352
|
});
|
|
438
|
-
|
|
353
|
+
consumeCmd.command("entry").description("Show a publisher's manifest entry").argument("<tag>", "Entry tag").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").requiredOption("--owner <address>", "Publisher address").option("-c, --chain <chain>", "Chain to use").action(async (tag, options) => {
|
|
439
354
|
try {
|
|
440
|
-
const
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
355
|
+
const fangorn = await getFangorn();
|
|
356
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
357
|
+
const entry = await fangorn.consumer.getEntry(options.owner, schemaId, tag);
|
|
358
|
+
note(JSON.stringify(entry, null, 2), `Entry: ${tag}`);
|
|
359
|
+
process.exit(0);
|
|
360
|
+
} catch (err) {
|
|
361
|
+
console.error("Failed:", err.message);
|
|
362
|
+
process.exit(1);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
/**
|
|
366
|
+
* consume purchase
|
|
367
|
+
*
|
|
368
|
+
* Phase 1 — sign ERC-3009 authorization + join Semaphore group.
|
|
369
|
+
* Prints the identity export string; user must save it for `claim` + `decrypt`.
|
|
370
|
+
*/
|
|
371
|
+
consumeCmd.command("purchase").description("Phase 1: pay and join the access group").argument("<owner>", "Publisher address").argument("<tag>", "Entry tag").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").requiredOption("--burner-key <hex>", "Burner wallet private key (pays USDC)").requiredOption("--amount <usdc>", "USDC amount in smallest unit").requiredOption("--usdc <address>", "USDC contract address").option("-c, --chain <chain>", "Chain to use").action(async (owner, tag, options) => {
|
|
372
|
+
try {
|
|
373
|
+
const fangorn = await getFangorn();
|
|
374
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
375
|
+
const relayerKey = loadConfig().privateKey;
|
|
376
|
+
const s = spinner();
|
|
377
|
+
const identity = new Identity();
|
|
378
|
+
s.start("Preparing ERC-3009 authorization...");
|
|
379
|
+
const preparedRegister = await fangorn.consumer.prepareRegister({
|
|
380
|
+
burnerPrivateKey: options.burnerKey,
|
|
381
|
+
paymentRecipient: owner,
|
|
382
|
+
amount: BigInt(options.amount),
|
|
383
|
+
usdcAddress: options.usdc,
|
|
384
|
+
usdcDomainName: "USD Coin",
|
|
385
|
+
usdcDomainVersion: "2"
|
|
386
|
+
});
|
|
387
|
+
s.stop();
|
|
388
|
+
s.start("Submitting registration...");
|
|
389
|
+
const { txHash } = await fangorn.consumer.register({
|
|
390
|
+
owner,
|
|
391
|
+
schemaId,
|
|
392
|
+
tag,
|
|
393
|
+
identityCommitment: identity.commitment,
|
|
394
|
+
relayerPrivateKey: relayerKey,
|
|
395
|
+
preparedRegister
|
|
396
|
+
});
|
|
397
|
+
s.stop();
|
|
398
|
+
note([
|
|
399
|
+
`Tx: ${txHash}`,
|
|
400
|
+
``,
|
|
401
|
+
`Save this identity string — required for claim and decrypt:`,
|
|
402
|
+
``,
|
|
403
|
+
` ${identity.export()}`,
|
|
404
|
+
``,
|
|
405
|
+
`Next: fangorn consume claim ${owner} ${tag} -s ${options.schema} \\`,
|
|
406
|
+
` --identity '<above>' --stealth <your-stealth-address>`
|
|
407
|
+
].join("\n"), "Purchase complete ✓");
|
|
445
408
|
process.exit(0);
|
|
446
409
|
} catch (err) {
|
|
447
|
-
console.error("Failed
|
|
410
|
+
console.error("Failed:", err.message);
|
|
448
411
|
process.exit(1);
|
|
449
412
|
}
|
|
450
413
|
});
|
|
451
|
-
|
|
414
|
+
/**
|
|
415
|
+
* consume claim
|
|
416
|
+
*
|
|
417
|
+
* Phase 2 — generate Groth16 ZK proof of group membership and fire the
|
|
418
|
+
* SettlementRegistry hook. Prints the nullifier for use in `decrypt`.
|
|
419
|
+
*/
|
|
420
|
+
consumeCmd.command("claim").description("Phase 2: prove membership and claim access").argument("<owner>", "Publisher address").argument("<tag>", "Entry tag").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").requiredOption("--identity <string>", "Exported identity from `consume purchase`").requiredOption("--stealth <address>", "Stealth address to receive the access token").option("-c, --chain <chain>", "Chain to use").action(async (owner, tag, options) => {
|
|
452
421
|
try {
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
422
|
+
const fangorn = await getFangorn();
|
|
423
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
424
|
+
const relayerKey = loadConfig().privateKey;
|
|
425
|
+
const identity = new Identity(options.identity);
|
|
426
|
+
const s = spinner();
|
|
427
|
+
s.start("Generating ZK proof...");
|
|
428
|
+
const preparedSettle = await fangorn.consumer.prepareSettle({
|
|
429
|
+
resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
|
|
430
|
+
identity,
|
|
431
|
+
stealthAddress: options.stealth
|
|
432
|
+
});
|
|
433
|
+
s.stop();
|
|
434
|
+
s.start("Submitting settlement...");
|
|
435
|
+
const { txHash, nullifier } = await fangorn.consumer.claim({
|
|
436
|
+
owner,
|
|
437
|
+
schemaId,
|
|
438
|
+
tag,
|
|
439
|
+
relayerPrivateKey: relayerKey,
|
|
440
|
+
preparedSettle
|
|
441
|
+
});
|
|
442
|
+
s.stop();
|
|
443
|
+
note([
|
|
444
|
+
`Tx: ${txHash}`,
|
|
445
|
+
`Nullifier: ${nullifier.toString()}`,
|
|
446
|
+
``,
|
|
447
|
+
`Next: fangorn consume decrypt ${owner} ${tag} -s ${options.schema} \\`,
|
|
448
|
+
` -f <field> --nullifier ${nullifier.toString()} --stealth-key <key> -o out.mp3`
|
|
449
|
+
].join("\n"), "Claim complete ✓");
|
|
458
450
|
process.exit(0);
|
|
459
451
|
} catch (err) {
|
|
460
|
-
console.error("Failed
|
|
452
|
+
console.error("Failed:", err.message);
|
|
461
453
|
process.exit(1);
|
|
462
454
|
}
|
|
463
455
|
});
|
|
464
|
-
|
|
456
|
+
/**
|
|
457
|
+
* consume decrypt
|
|
458
|
+
*
|
|
459
|
+
* Decrypt a field after a completed purchase + claim cycle.
|
|
460
|
+
* The stealth wallet is used to create the Lit auth context.
|
|
461
|
+
*/
|
|
462
|
+
consumeCmd.command("decrypt").description("Decrypt a field after purchase and claim").argument("<owner>", "Publisher address").argument("<tag>", "Entry tag").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").requiredOption("-f, --field <field>", "Field name to decrypt").requiredOption("--nullifier <bigint>", "Nullifier from `consume claim`").requiredOption("--stealth-key <hex>", "Private key of the stealth address").option("--identity <string>", "Exported identity (required unless --skip-settlement-check)").option("--skip-settlement-check", "Skip on-chain registration verification").option("-c, --chain <chain>", "Chain to use").option("-o, --output <path>", "Write output to file (defaults to stdout)").action(async (owner, tag, options) => {
|
|
465
463
|
try {
|
|
466
|
-
const
|
|
464
|
+
const chain = getChain(options.chain);
|
|
465
|
+
const fangorn = await getFangorn();
|
|
466
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
467
|
+
const s = spinner();
|
|
468
|
+
const walletClient = createWalletClient({
|
|
469
|
+
account: privateKeyToAccount(options.stealthKey),
|
|
470
|
+
chain,
|
|
471
|
+
transport: http(loadConfig().cfg.rpcUrl)
|
|
472
|
+
});
|
|
473
|
+
const identity = options.identity ? new Identity(options.identity) : void 0;
|
|
474
|
+
s.start("Decrypting...");
|
|
475
|
+
const decrypted = await fangorn.consumer.decrypt({
|
|
476
|
+
owner,
|
|
477
|
+
walletClient,
|
|
478
|
+
schemaId,
|
|
479
|
+
nullifierHash: BigInt(options.nullifier),
|
|
480
|
+
tag,
|
|
481
|
+
field: options.field,
|
|
482
|
+
identity,
|
|
483
|
+
skipSettlementCheck: !!options.skipSettlementCheck
|
|
484
|
+
});
|
|
485
|
+
s.stop();
|
|
467
486
|
if (options.output) {
|
|
468
487
|
writeFileSync(options.output, Buffer.from(decrypted));
|
|
469
|
-
console.log(`
|
|
488
|
+
console.log(`Saved to: ${options.output}`);
|
|
470
489
|
} else {
|
|
471
|
-
|
|
472
|
-
process.stdout.write(atob(buf.toString()));
|
|
490
|
+
process.stdout.write(Buffer.from(decrypted));
|
|
473
491
|
process.stdout.write("\n");
|
|
474
492
|
}
|
|
475
493
|
process.exit(0);
|
|
476
494
|
} catch (err) {
|
|
477
|
-
console.error("Failed
|
|
495
|
+
console.error("Failed:", err.message);
|
|
496
|
+
process.exit(1);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
program.command("datasource").description("Data source registry queries").command("info").description("Show on-chain manifest info for an owner + schema").requiredOption("-s, --schema <schemaOrId>", "Schema name or bytes32 ID").option("-c, --chain <chain>", "Chain to use").option("--owner <address>", "Owner address (defaults to your own)").action(async (options) => {
|
|
500
|
+
try {
|
|
501
|
+
const self = getAccount().address;
|
|
502
|
+
const owner = options.owner ?? self;
|
|
503
|
+
const fangorn = await getFangorn();
|
|
504
|
+
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
505
|
+
const ds = await fangorn.getDatasourceRegistry().getManifest(owner, schemaId);
|
|
506
|
+
console.log(`Owner: ${owner}`);
|
|
507
|
+
console.log(`Schema ID: ${schemaId}`);
|
|
508
|
+
console.log(`Version: ${String(ds.version)}`);
|
|
509
|
+
console.log(`Manifest CID: ${ds.manifestCid || "(none yet)"}`);
|
|
510
|
+
process.exit(0);
|
|
511
|
+
} catch (err) {
|
|
512
|
+
console.error("Failed:", err.message);
|
|
478
513
|
process.exit(1);
|
|
479
514
|
}
|
|
480
515
|
});
|
|
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
516
|
program.parse();
|
|
498
517
|
|
|
499
518
|
//#endregion
|