@fangorn-network/sdk 2026.4.7 → 2026.4.15
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 +137 -150
- package/lib/cli/cli.js +134 -226
- package/lib/cli/index.d.ts +170 -170
- package/lib/config.d.ts +260 -257
- package/lib/config.js +7 -5
- package/lib/fangorn.d.ts +3 -20
- package/lib/fangorn.js +15 -52
- package/lib/index.d.ts +3 -7
- package/lib/index.js +4 -7
- package/lib/modules/encryption/aes.d.ts +3 -3
- package/lib/modules/encryption/index.d.ts +1 -28
- package/lib/modules/encryption/index.js +1 -3
- package/lib/modules/encryption/types.d.ts +1 -48
- package/lib/providers/storage/index.d.ts +4 -21
- package/lib/providers/storage/index.js +3 -2
- package/lib/providers/storage/pinata.d.ts +14 -0
- package/lib/providers/storage/pinata.js +32 -0
- package/lib/providers/storage/types.d.ts +37 -0
- package/lib/providers/storage/utils.d.ts +12 -0
- package/lib/providers/storage/utils.js +50 -0
- package/lib/registries/datasource-registry/abi.d.ts +116 -43
- package/lib/registries/datasource-registry/abi.js +190 -12
- package/lib/registries/datasource-registry/index.d.ts +12 -6
- package/lib/registries/datasource-registry/index.js +96 -20
- package/lib/registries/index.js +1 -1
- package/lib/registries/schema-registry/abi.d.ts +157 -66
- package/lib/registries/schema-registry/abi.js +242 -15
- package/lib/registries/schema-registry/index.d.ts +8 -3
- package/lib/registries/schema-registry/index.js +82 -17
- package/lib/registries/settlement-registry/abi.d.ts +199 -145
- package/lib/registries/settlement-registry/abi.js +331 -25
- package/lib/registries/settlement-registry/index.d.ts +36 -39
- package/lib/registries/settlement-registry/index.js +125 -91
- package/lib/registries/settlement-registry/types.d.ts +6 -3
- package/lib/roles/consumer/index.d.ts +17 -42
- package/lib/roles/consumer/index.js +87 -58
- package/lib/roles/consumer/types.d.ts +15 -34
- package/lib/roles/publisher/index.d.ts +22 -40
- package/lib/roles/publisher/index.js +69 -113
- package/lib/roles/publisher/types.d.ts +40 -41
- package/lib/roles/schema/index.d.ts +4 -30
- package/lib/roles/schema/index.js +7 -60
- package/lib/roles/schema/types.d.ts +16 -2
- package/lib/test/testbed.d.ts +12 -36
- package/lib/test/testbed.js +35 -68
- package/lib/types/index.d.ts +14 -57
- package/package.json +1 -6
- package/lib/modules/encryption/lit.d.ts +0 -21
- package/lib/modules/encryption/lit.js +0 -127
- package/lib/modules/gadgets/index.d.ts +0 -2
- package/lib/modules/gadgets/index.js +0 -1
- package/lib/modules/gadgets/settledGadget.d.ts +0 -31
- package/lib/modules/gadgets/settledGadget.js +0 -75
- package/lib/modules/gadgets/types.d.ts +0 -27
- package/lib/providers/storage/pinata/index.d.ts +0 -13
- package/lib/providers/storage/pinata/index.js +0 -41
- package/lib/providers/storage/storacha/index.d.ts +0 -13
- package/lib/providers/storage/storacha/index.js +0 -49
- package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
- package/lib/providers/storage/storacha/readOnly.js +0 -16
- /package/lib/{modules/gadgets → providers/storage}/types.js +0 -0
package/lib/cli/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { FangornConfig, SupportedNetworks } from "../config.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
|
|
4
4
|
import { Fangorn } from "../fangorn.js";
|
|
5
5
|
import { getChain, handleCancel, selectChain } from "./index.js";
|
|
6
6
|
import { createWalletClient, http } from "viem";
|
|
7
7
|
import { privateKeyToAccount } from "viem/accounts";
|
|
8
8
|
import { Command } from "commander";
|
|
9
|
-
import { confirm, intro, note, outro, select, spinner, text } from "@clack/prompts";
|
|
9
|
+
import { confirm, intro, log, note, outro, select, spinner, text } from "@clack/prompts";
|
|
10
10
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
11
11
|
import { extname, join } from "path";
|
|
12
12
|
import { homedir } from "os";
|
|
@@ -19,83 +19,75 @@ const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
|
19
19
|
let _config = null;
|
|
20
20
|
let _account = null;
|
|
21
21
|
let _fangorn = null;
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
};
|
|
22
|
+
function resolveAppConfig(chainName) {
|
|
23
|
+
if (chainName === SupportedNetworks.ArbitrumSepolia.name) return FangornConfig.ArbitrumSepolia;
|
|
24
|
+
return FangornConfig.BaseSepolia;
|
|
33
25
|
}
|
|
34
26
|
function loadConfig() {
|
|
35
27
|
if (_config) return _config;
|
|
36
28
|
const privateKey = process.env.DELEGATOR_ETH_PRIVATE_KEY;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
29
|
+
const pinataJwt = process.env.PINATA_JWT;
|
|
30
|
+
const pinataGateway = process.env.PINATA_GATEWAY;
|
|
39
31
|
const chainName = process.env.CHAIN_NAME;
|
|
40
|
-
const
|
|
41
|
-
if (privateKey
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
storage: "storacha",
|
|
57
|
-
storachaEmail
|
|
58
|
-
});
|
|
59
|
-
return _config;
|
|
60
|
-
}
|
|
32
|
+
const workerUrl = process.env.WORKER_URL;
|
|
33
|
+
if (privateKey || pinataJwt || pinataGateway || chainName) {
|
|
34
|
+
const missing = [];
|
|
35
|
+
if (!privateKey) missing.push("DELEGATOR_ETH_PRIVATE_KEY");
|
|
36
|
+
if (!pinataJwt) missing.push("PINATA_JWT");
|
|
37
|
+
if (!pinataGateway) missing.push("PINATA_GATEWAY");
|
|
38
|
+
if (!chainName) missing.push("CHAIN_NAME");
|
|
39
|
+
if (missing.length > 0) throw new Error(`Incomplete environment configuration. Missing: ${missing.join(", ")}\nSet all required env vars or run \`fangorn init\` to use a config file.`);
|
|
40
|
+
_config = {
|
|
41
|
+
privateKey,
|
|
42
|
+
cfg: resolveAppConfig(chainName ?? ""),
|
|
43
|
+
pinataJwt: pinataJwt ?? "",
|
|
44
|
+
pinataGateway: pinataGateway ?? "",
|
|
45
|
+
workerUrl: workerUrl ?? ""
|
|
46
|
+
};
|
|
47
|
+
return _config;
|
|
61
48
|
}
|
|
62
49
|
if (existsSync(CONFIG_PATH)) {
|
|
63
|
-
|
|
50
|
+
const stored = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
51
|
+
_config = {
|
|
52
|
+
privateKey: stored.privateKey,
|
|
53
|
+
cfg: resolveAppConfig(stored.chainName),
|
|
54
|
+
pinataJwt: stored.pinataJwt,
|
|
55
|
+
pinataGateway: stored.pinataGateway,
|
|
56
|
+
workerUrl: stored.workerUrl
|
|
57
|
+
};
|
|
64
58
|
return _config;
|
|
65
59
|
}
|
|
66
|
-
throw new Error("No configuration found. Run `fangorn init` or set the required env vars
|
|
60
|
+
throw new Error("No configuration found. Run `fangorn init` or set the required env vars:\n DELEGATOR_ETH_PRIVATE_KEY, PINATA_JWT, PINATA_GATEWAY, CHAIN_NAME");
|
|
67
61
|
}
|
|
68
62
|
function getAccount() {
|
|
69
63
|
if (_account) return _account;
|
|
70
64
|
_account = privateKeyToAccount(loadConfig().privateKey);
|
|
71
65
|
return _account;
|
|
72
66
|
}
|
|
73
|
-
|
|
67
|
+
function getFangorn() {
|
|
74
68
|
if (_fangorn) return _fangorn;
|
|
75
69
|
const cfg = loadConfig();
|
|
76
70
|
const agentConfig = {
|
|
77
71
|
privateKey: cfg.privateKey,
|
|
78
|
-
pinataJwt: cfg.
|
|
72
|
+
pinataJwt: cfg.pinataJwt
|
|
79
73
|
};
|
|
80
|
-
|
|
81
|
-
jwt: cfg.jwt ?? "",
|
|
82
|
-
gateway: cfg.gateway ?? ""
|
|
83
|
-
} };
|
|
84
|
-
_fangorn = await Fangorn.create({
|
|
74
|
+
_fangorn = Fangorn.create({
|
|
85
75
|
privateKey: cfg.privateKey,
|
|
86
|
-
storage
|
|
87
|
-
|
|
76
|
+
storage: { pinata: {
|
|
77
|
+
jwt: cfg.pinataJwt,
|
|
78
|
+
gateway: cfg.pinataGateway
|
|
79
|
+
} },
|
|
88
80
|
domain: "localhost",
|
|
89
81
|
config: cfg.cfg,
|
|
90
82
|
agentConfig
|
|
91
83
|
});
|
|
92
84
|
return _fangorn;
|
|
93
85
|
}
|
|
94
|
-
async function resolveSchemaId(fangorn,
|
|
86
|
+
async function resolveSchemaId(fangorn, schemaNameOrId) {
|
|
95
87
|
try {
|
|
96
|
-
return await fangorn.getSchemaRegistry().schemaId(
|
|
88
|
+
return await fangorn.getSchemaRegistry().schemaId(/^0x[0-9a-fA-F]{64}$/.test(schemaNameOrId) ? schemaNameOrId : schemaNameOrId);
|
|
97
89
|
} catch {
|
|
98
|
-
throw new Error(`Schema "${
|
|
90
|
+
throw new Error(`Schema "${schemaNameOrId}" not found on-chain. Register it with \`fangorn schema register\`.`);
|
|
99
91
|
}
|
|
100
92
|
}
|
|
101
93
|
const program = new Command();
|
|
@@ -122,79 +114,47 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
122
114
|
}]
|
|
123
115
|
});
|
|
124
116
|
handleCancel(chainName);
|
|
125
|
-
const
|
|
126
|
-
message: "
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
117
|
+
const pinataJwt = await text({
|
|
118
|
+
message: "Pinata JWT:",
|
|
119
|
+
validate: (v) => {
|
|
120
|
+
if (!v) return "Required";
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
handleCancel(pinataJwt);
|
|
124
|
+
const pinataGateway = await text({
|
|
125
|
+
message: "Pinata Gateway URL:",
|
|
126
|
+
placeholder: "https://your-gateway.mypinata.cloud",
|
|
127
|
+
validate: (v) => {
|
|
128
|
+
if (!v) return "Required";
|
|
129
|
+
}
|
|
134
130
|
});
|
|
135
|
-
handleCancel(
|
|
131
|
+
handleCancel(pinataGateway);
|
|
132
|
+
const workerUrl = await text({
|
|
133
|
+
message: "Fangorn access worker URL:",
|
|
134
|
+
placeholder: "https://fangorn-access-worker.your-subdomain.workers.dev",
|
|
135
|
+
validate: (v) => {
|
|
136
|
+
if (!v) return "Required";
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
handleCancel(workerUrl);
|
|
136
140
|
const stored = {
|
|
137
141
|
privateKey,
|
|
138
142
|
chainName,
|
|
139
|
-
|
|
143
|
+
pinataJwt,
|
|
144
|
+
pinataGateway,
|
|
145
|
+
workerUrl
|
|
140
146
|
};
|
|
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
|
-
}
|
|
170
147
|
if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
|
|
171
148
|
writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
|
|
172
149
|
chmodSync(CONFIG_PATH, 384);
|
|
173
150
|
outro(`Config saved to ${CONFIG_PATH}`);
|
|
174
151
|
});
|
|
175
152
|
const schemaCmd = program.command("schema").description("Schema registry operations");
|
|
176
|
-
schemaCmd.command("register").description("Register
|
|
153
|
+
schemaCmd.command("register").description("Register a schema on-chain").argument("<name>", "Schema name").action(async (name) => {
|
|
177
154
|
try {
|
|
178
155
|
intro("Chain selection");
|
|
179
156
|
outro(`Selected chain: ${(await selectChain()).name}`);
|
|
180
|
-
const fangorn =
|
|
181
|
-
let datasourceAgentId = "";
|
|
182
|
-
let description = "";
|
|
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
|
|
192
|
-
});
|
|
193
|
-
s$1.stop();
|
|
194
|
-
datasourceAgentId = agentId;
|
|
195
|
-
note(`Agent ID: ${agentId}`, "ERC-8004 registered");
|
|
196
|
-
outro("Agent Registration complete.");
|
|
197
|
-
}
|
|
157
|
+
const fangorn = getFangorn();
|
|
198
158
|
intro("Schema Registration");
|
|
199
159
|
const schemaFilePath = await text({
|
|
200
160
|
message: "Path to your JSON schema file:",
|
|
@@ -206,14 +166,6 @@ schemaCmd.command("register").description("Register an agent identity and/or a s
|
|
|
206
166
|
}
|
|
207
167
|
});
|
|
208
168
|
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";
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
handleCancel(schemaName);
|
|
217
169
|
let definition;
|
|
218
170
|
try {
|
|
219
171
|
definition = JSON.parse(readFileSync(schemaFilePath, "utf-8"));
|
|
@@ -228,11 +180,11 @@ schemaCmd.command("register").description("Register an agent identity and/or a s
|
|
|
228
180
|
process.exit(0);
|
|
229
181
|
}
|
|
230
182
|
const s = spinner();
|
|
231
|
-
s.start("Registering schema");
|
|
183
|
+
s.start("Registering schema...");
|
|
232
184
|
const { schemaId, schemaCid } = await fangorn.schema.register({
|
|
233
|
-
name
|
|
185
|
+
name,
|
|
234
186
|
definition,
|
|
235
|
-
agentId:
|
|
187
|
+
agentId: ""
|
|
236
188
|
});
|
|
237
189
|
s.stop();
|
|
238
190
|
note(`Schema ID: ${schemaId}\nCID: ${schemaCid}`, "Schema registered");
|
|
@@ -242,15 +194,15 @@ schemaCmd.command("register").description("Register an agent identity and/or a s
|
|
|
242
194
|
process.exit(1);
|
|
243
195
|
}
|
|
244
196
|
});
|
|
245
|
-
schemaCmd.command("get").description("Fetch a registered schema by name").argument("<name>", "Schema name
|
|
197
|
+
schemaCmd.command("get").description("Fetch a registered schema by name").argument("<name>", "Schema name").action(async (name) => {
|
|
246
198
|
try {
|
|
247
|
-
const fangorn =
|
|
199
|
+
const fangorn = getFangorn();
|
|
248
200
|
const s = spinner();
|
|
249
201
|
s.start(`Fetching schema "${name}"...`);
|
|
250
202
|
const schema = await fangorn.schema.get(name);
|
|
251
203
|
s.stop();
|
|
252
204
|
if (!schema) {
|
|
253
|
-
|
|
205
|
+
log.error(`Schema "${name}" not found.`);
|
|
254
206
|
process.exit(1);
|
|
255
207
|
}
|
|
256
208
|
note(JSON.stringify(schema, null, 2), `Schema: ${name}`);
|
|
@@ -261,66 +213,33 @@ schemaCmd.command("get").description("Fetch a registered schema by name").argume
|
|
|
261
213
|
}
|
|
262
214
|
});
|
|
263
215
|
const publishCmd = program.command("publish").description("Publisher operations");
|
|
264
|
-
publishCmd.command("upload").description("
|
|
216
|
+
publishCmd.command("upload").description("Publish file handle(s) under a schema").argument("<files...>", "JSON file(s) containing PublishRecord(s)").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").option("-p, --price <USDC>", "Resource price in USDC (smallest unit)", "0").option("-o, --overwrite", "Overwrite existing entries instead of merging", false).action(async (files, options) => {
|
|
265
217
|
try {
|
|
266
|
-
const fangorn =
|
|
267
|
-
const cfg = loadConfig();
|
|
218
|
+
const fangorn = getFangorn();
|
|
268
219
|
const price = BigInt(options.price);
|
|
269
220
|
const s = spinner();
|
|
270
|
-
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
271
|
-
const schema = (await fangorn.schema.get(options.schema))?.definition ?? {};
|
|
272
221
|
const records = files.flatMap((filepath) => {
|
|
273
222
|
const data = readFileSync(filepath, "utf-8");
|
|
274
|
-
const parsed = JSON.parse(data
|
|
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
|
-
});
|
|
223
|
+
const parsed = JSON.parse(data);
|
|
284
224
|
return Array.isArray(parsed) ? parsed : [parsed];
|
|
285
225
|
});
|
|
286
|
-
|
|
287
|
-
s.start("Encrypting and publishing...");
|
|
226
|
+
s.start("Publishing...");
|
|
288
227
|
const result = await fangorn.publisher.upload({
|
|
289
228
|
records,
|
|
290
|
-
schema,
|
|
291
|
-
schemaId,
|
|
292
|
-
gateway,
|
|
229
|
+
schemaName: options.schema,
|
|
293
230
|
options: { overwrite: options.overwrite }
|
|
294
231
|
}, price);
|
|
295
232
|
s.stop();
|
|
296
|
-
note(`Manifest
|
|
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}`);
|
|
233
|
+
note(`Manifest URI: ${result.manifestUri}\nEntries: ${result.entryCount.toString()}\nSchema: ${result.schemaId}`, "Upload complete");
|
|
315
234
|
process.exit(0);
|
|
316
235
|
} catch (err) {
|
|
317
236
|
console.error("Failed:", err.message);
|
|
318
237
|
process.exit(1);
|
|
319
238
|
}
|
|
320
239
|
});
|
|
321
|
-
publishCmd.command("entry").description("Show details for one of your manifest entries").argument("<tag>", "Entry tag").requiredOption("-s, --schema <
|
|
240
|
+
publishCmd.command("entry").description("Show details for one of your manifest entries").argument("<tag>", "Entry tag / name").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").action(async (tag, options) => {
|
|
322
241
|
try {
|
|
323
|
-
const fangorn =
|
|
242
|
+
const fangorn = getFangorn();
|
|
324
243
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
325
244
|
const entry = await fangorn.publisher.getEntry(schemaId, tag);
|
|
326
245
|
note(JSON.stringify(entry, null, 2), `Entry: ${tag}`);
|
|
@@ -331,28 +250,28 @@ publishCmd.command("entry").description("Show details for one of your manifest e
|
|
|
331
250
|
}
|
|
332
251
|
});
|
|
333
252
|
const consumeCmd = program.command("consume").description("Consumer operations");
|
|
334
|
-
consumeCmd.command("list").description("List a publisher's manifest entries").requiredOption("-s, --schema <
|
|
253
|
+
consumeCmd.command("list").description("List a publisher's manifest entries").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").requiredOption("--owner <address>", "Publisher address").action(async (options) => {
|
|
335
254
|
try {
|
|
336
|
-
const fangorn =
|
|
255
|
+
const fangorn = getFangorn();
|
|
337
256
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
338
|
-
const manifest = await fangorn.consumer.getManifest(options.owner, schemaId);
|
|
257
|
+
const manifest = await fangorn.consumer.getManifest(options.owner, schemaId, options.schema);
|
|
339
258
|
if (!manifest) {
|
|
340
|
-
|
|
259
|
+
log.warn("No manifest found.");
|
|
341
260
|
process.exit(0);
|
|
342
261
|
}
|
|
343
262
|
console.log(`Owner: ${options.owner}`);
|
|
344
263
|
console.log(`Schema: ${options.schema}`);
|
|
345
264
|
console.log(`Entries (${manifest.entries.length.toString()}):`);
|
|
346
|
-
for (const entry of manifest.entries) console.log(` - ${entry.
|
|
265
|
+
for (const entry of manifest.entries) console.log(` - ${entry.name}`);
|
|
347
266
|
process.exit(0);
|
|
348
267
|
} catch (err) {
|
|
349
268
|
console.error("Failed:", err.message);
|
|
350
269
|
process.exit(1);
|
|
351
270
|
}
|
|
352
271
|
});
|
|
353
|
-
consumeCmd.command("entry").description("Show a publisher's manifest entry").argument("<tag>", "Entry tag").requiredOption("-s, --schema <
|
|
272
|
+
consumeCmd.command("entry").description("Show a publisher's manifest entry").argument("<tag>", "Entry tag / name").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").requiredOption("--owner <address>", "Publisher address").action(async (tag, options) => {
|
|
354
273
|
try {
|
|
355
|
-
const fangorn =
|
|
274
|
+
const fangorn = getFangorn();
|
|
356
275
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
357
276
|
const entry = await fangorn.consumer.getEntry(options.owner, schemaId, tag);
|
|
358
277
|
note(JSON.stringify(entry, null, 2), `Entry: ${tag}`);
|
|
@@ -362,22 +281,23 @@ consumeCmd.command("entry").description("Show a publisher's manifest entry").arg
|
|
|
362
281
|
process.exit(1);
|
|
363
282
|
}
|
|
364
283
|
});
|
|
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) => {
|
|
284
|
+
consumeCmd.command("purchase").description("Phase 1: pay and join the access group").argument("<owner>", "Publisher address").argument("<name>", "Entry name").requiredOption("-s, --schema <schemaName>", "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").action(async (owner, name, options) => {
|
|
372
285
|
try {
|
|
373
|
-
const fangorn =
|
|
286
|
+
const fangorn = getFangorn();
|
|
287
|
+
const cfg = loadConfig();
|
|
374
288
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
375
|
-
const relayerKey =
|
|
289
|
+
const relayerKey = cfg.privateKey;
|
|
376
290
|
const s = spinner();
|
|
377
291
|
const identity = new Identity();
|
|
292
|
+
const chain = getChain(cfg.cfg.chainName);
|
|
293
|
+
const walletClient = createWalletClient({
|
|
294
|
+
account: privateKeyToAccount(options.burnerKey),
|
|
295
|
+
chain,
|
|
296
|
+
transport: http(cfg.cfg.rpcUrl)
|
|
297
|
+
});
|
|
378
298
|
s.start("Preparing ERC-3009 authorization...");
|
|
379
299
|
const preparedRegister = await fangorn.consumer.prepareRegister({
|
|
380
|
-
|
|
300
|
+
walletClient,
|
|
381
301
|
paymentRecipient: owner,
|
|
382
302
|
amount: BigInt(options.amount),
|
|
383
303
|
usdcAddress: options.usdc,
|
|
@@ -389,21 +309,25 @@ consumeCmd.command("purchase").description("Phase 1: pay and join the access gro
|
|
|
389
309
|
const { txHash } = await fangorn.consumer.register({
|
|
390
310
|
owner,
|
|
391
311
|
schemaId,
|
|
392
|
-
|
|
312
|
+
name,
|
|
393
313
|
identityCommitment: identity.commitment,
|
|
394
314
|
relayerPrivateKey: relayerKey,
|
|
395
315
|
preparedRegister
|
|
396
316
|
});
|
|
397
317
|
s.stop();
|
|
318
|
+
const exported = identity.export();
|
|
398
319
|
note([
|
|
399
|
-
`Tx:
|
|
320
|
+
`Tx: ${txHash}`,
|
|
400
321
|
``,
|
|
401
|
-
|
|
322
|
+
`⚠️ Save this identity string — you will need it for \`claim\`:`,
|
|
402
323
|
``,
|
|
403
|
-
` ${
|
|
324
|
+
` ${exported}`,
|
|
404
325
|
``,
|
|
405
|
-
`Next
|
|
406
|
-
`
|
|
326
|
+
`Next:`,
|
|
327
|
+
` fangorn consume claim ${owner} ${name} \\`,
|
|
328
|
+
` -s ${options.schema} \\`,
|
|
329
|
+
` --identity '${exported}' \\`,
|
|
330
|
+
` --stealth <your-stealth-address>`
|
|
407
331
|
].join("\n"), "Purchase complete ✓");
|
|
408
332
|
process.exit(0);
|
|
409
333
|
} catch (err) {
|
|
@@ -411,22 +335,16 @@ consumeCmd.command("purchase").description("Phase 1: pay and join the access gro
|
|
|
411
335
|
process.exit(1);
|
|
412
336
|
}
|
|
413
337
|
});
|
|
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) => {
|
|
338
|
+
consumeCmd.command("claim").description("Phase 2: prove membership and claim access").argument("<owner>", "Publisher address").argument("<name>", "Entry name").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").requiredOption("--identity <string>", "Exported identity from `consume purchase`").requiredOption("--stealth <address>", "Stealth address to receive the access token").action(async (owner, name, options) => {
|
|
421
339
|
try {
|
|
422
|
-
const fangorn =
|
|
340
|
+
const fangorn = getFangorn();
|
|
423
341
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
424
342
|
const relayerKey = loadConfig().privateKey;
|
|
425
343
|
const identity = new Identity(options.identity);
|
|
426
344
|
const s = spinner();
|
|
427
345
|
s.start("Generating ZK proof...");
|
|
428
346
|
const preparedSettle = await fangorn.consumer.prepareSettle({
|
|
429
|
-
resourceId:
|
|
347
|
+
resourceId: DataSourceRegistry.resourceIdLocal(owner, schemaId, name),
|
|
430
348
|
identity,
|
|
431
349
|
stealthAddress: options.stealth
|
|
432
350
|
});
|
|
@@ -435,7 +353,7 @@ consumeCmd.command("claim").description("Phase 2: prove membership and claim acc
|
|
|
435
353
|
const { txHash, nullifier } = await fangorn.consumer.claim({
|
|
436
354
|
owner,
|
|
437
355
|
schemaId,
|
|
438
|
-
|
|
356
|
+
name,
|
|
439
357
|
relayerPrivateKey: relayerKey,
|
|
440
358
|
preparedSettle
|
|
441
359
|
});
|
|
@@ -444,8 +362,13 @@ consumeCmd.command("claim").description("Phase 2: prove membership and claim acc
|
|
|
444
362
|
`Tx: ${txHash}`,
|
|
445
363
|
`Nullifier: ${nullifier.toString()}`,
|
|
446
364
|
``,
|
|
447
|
-
`Next
|
|
448
|
-
`
|
|
365
|
+
`Next:`,
|
|
366
|
+
` fangorn consume fetch ${owner} ${name} \\`,
|
|
367
|
+
` -s ${options.schema} \\`,
|
|
368
|
+
` -f <field> \\`,
|
|
369
|
+
` --nullifier ${nullifier.toString()} \\`,
|
|
370
|
+
` --stealth-key <stealth-private-key> \\`,
|
|
371
|
+
` -o out.mp3`
|
|
449
372
|
].join("\n"), "Claim complete ✓");
|
|
450
373
|
process.exit(0);
|
|
451
374
|
} catch (err) {
|
|
@@ -453,41 +376,26 @@ consumeCmd.command("claim").description("Phase 2: prove membership and claim acc
|
|
|
453
376
|
process.exit(1);
|
|
454
377
|
}
|
|
455
378
|
});
|
|
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) => {
|
|
379
|
+
consumeCmd.command("fetch").description("Fetch a field after purchase and claim").argument("<owner>", "Publisher address").argument("<name>", "Entry name").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").requiredOption("-f, --field <field>", "Field name to fetch").requiredOption("--nullifier <bigint>", "Nullifier from `consume claim`").requiredOption("--stealth-key <hex>", "Private key of the stealth address").option("-o, --output <path>", "Write output to file (default: stdout)").action(async (owner, name, options) => {
|
|
463
380
|
try {
|
|
464
|
-
const
|
|
465
|
-
const
|
|
381
|
+
const cfg = loadConfig();
|
|
382
|
+
const chain = getChain(cfg.cfg.chainName);
|
|
383
|
+
const fangorn = getFangorn();
|
|
466
384
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
467
385
|
const s = spinner();
|
|
468
386
|
const walletClient = createWalletClient({
|
|
469
387
|
account: privateKeyToAccount(options.stealthKey),
|
|
470
388
|
chain,
|
|
471
|
-
transport: http(
|
|
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
|
|
389
|
+
transport: http(cfg.cfg.rpcUrl)
|
|
484
390
|
});
|
|
391
|
+
s.start("Fetching...");
|
|
392
|
+
const { data } = await fangorn.consumer.fetchField(owner, schemaId, name, options.field, options.nullifier, walletClient);
|
|
485
393
|
s.stop();
|
|
486
394
|
if (options.output) {
|
|
487
|
-
writeFileSync(options.output, Buffer.from(
|
|
395
|
+
writeFileSync(options.output, Buffer.from(data));
|
|
488
396
|
console.log(`Saved to: ${options.output}`);
|
|
489
397
|
} else {
|
|
490
|
-
process.stdout.write(Buffer.from(
|
|
398
|
+
process.stdout.write(Buffer.from(data));
|
|
491
399
|
process.stdout.write("\n");
|
|
492
400
|
}
|
|
493
401
|
process.exit(0);
|
|
@@ -496,13 +404,13 @@ consumeCmd.command("decrypt").description("Decrypt a field after purchase and cl
|
|
|
496
404
|
process.exit(1);
|
|
497
405
|
}
|
|
498
406
|
});
|
|
499
|
-
program.command("datasource").description("Data source registry queries").command("info").description("Show on-chain manifest info for an owner + schema").requiredOption("-s, --schema <
|
|
407
|
+
program.command("datasource").description("Data source registry queries").command("info").description("Show on-chain manifest info for an owner + schema").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").option("--owner <address>", "Owner address (defaults to your wallet)").action(async (options) => {
|
|
500
408
|
try {
|
|
501
409
|
const self = getAccount().address;
|
|
502
410
|
const owner = options.owner ?? self;
|
|
503
|
-
const fangorn =
|
|
411
|
+
const fangorn = getFangorn();
|
|
504
412
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
505
|
-
const ds = await fangorn.getDatasourceRegistry().
|
|
413
|
+
const ds = await fangorn.getDatasourceRegistry().get(owner, schemaId, options.schema);
|
|
506
414
|
console.log(`Owner: ${owner}`);
|
|
507
415
|
console.log(`Schema ID: ${schemaId}`);
|
|
508
416
|
console.log(`Version: ${String(ds.version)}`);
|