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