@fangorn-network/sdk 2026.4.7 → 2026.4.10

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.
Files changed (49) hide show
  1. package/README.md +30 -26
  2. package/lib/cli/cli.js +115 -153
  3. package/lib/cli/index.d.ts +170 -170
  4. package/lib/config.d.ts +260 -257
  5. package/lib/config.js +7 -5
  6. package/lib/fangorn.d.ts +0 -3
  7. package/lib/fangorn.js +16 -28
  8. package/lib/index.d.ts +3 -3
  9. package/lib/index.js +4 -5
  10. package/lib/modules/encryption/lit.d.ts +0 -1
  11. package/lib/modules/encryption/lit.js +1 -7
  12. package/lib/modules/gadgets/settledGadget.d.ts +1 -8
  13. package/lib/modules/gadgets/settledGadget.js +1 -13
  14. package/lib/providers/storage/index.d.ts +12 -12
  15. package/lib/providers/storage/index.js +49 -2
  16. package/lib/providers/storage/pinata.d.ts +11 -0
  17. package/lib/providers/storage/pinata.js +24 -0
  18. package/lib/registries/datasource-registry/abi.d.ts +116 -43
  19. package/lib/registries/datasource-registry/abi.js +190 -12
  20. package/lib/registries/datasource-registry/index.d.ts +12 -6
  21. package/lib/registries/datasource-registry/index.js +96 -20
  22. package/lib/registries/index.js +1 -1
  23. package/lib/registries/schema-registry/abi.d.ts +157 -66
  24. package/lib/registries/schema-registry/abi.js +242 -15
  25. package/lib/registries/schema-registry/index.d.ts +8 -3
  26. package/lib/registries/schema-registry/index.js +82 -17
  27. package/lib/registries/settlement-registry/abi.d.ts +199 -145
  28. package/lib/registries/settlement-registry/abi.js +331 -25
  29. package/lib/registries/settlement-registry/index.d.ts +36 -39
  30. package/lib/registries/settlement-registry/index.js +125 -91
  31. package/lib/registries/settlement-registry/types.d.ts +6 -3
  32. package/lib/roles/consumer/index.d.ts +8 -29
  33. package/lib/roles/consumer/index.js +25 -45
  34. package/lib/roles/consumer/types.d.ts +4 -4
  35. package/lib/roles/publisher/index.d.ts +26 -29
  36. package/lib/roles/publisher/index.js +70 -77
  37. package/lib/roles/publisher/types.d.ts +7 -3
  38. package/lib/roles/schema/index.d.ts +3 -8
  39. package/lib/roles/schema/index.js +6 -34
  40. package/lib/test/testbed.d.ts +7 -32
  41. package/lib/test/testbed.js +22 -45
  42. package/lib/types/index.d.ts +10 -20
  43. package/package.json +1 -1
  44. package/lib/providers/storage/pinata/index.d.ts +0 -13
  45. package/lib/providers/storage/pinata/index.js +0 -41
  46. package/lib/providers/storage/storacha/index.d.ts +0 -13
  47. package/lib/providers/storage/storacha/index.js +0 -49
  48. package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
  49. package/lib/providers/storage/storacha/readOnly.js +0 -16
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Intent-bound encrypted data for the agentic web.
4
4
 
5
- Fangorn lets you publish data encrypted under programmable access conditions — called **gadgets** — so it can only be decrypted by a party that satisfies them. Data is organized by **schemas**, enabling agent-based discovery across any number of publishers.
5
+ Fangorn lets you publish data encrypted under programmable access conditions using **gadgets**. A gadget defines an NP-relation that must must be provably satisfied in order to recover the plaintext (decrypt). Data is organized by **schemas**, enabling agent-based discovery across any number of publishers.
6
6
 
7
7
  ## Supported Networks
8
8
 
@@ -123,11 +123,10 @@ const fangorn = await Fangorn.create({
123
123
 
124
124
  **Storage options:**
125
125
 
126
- | Config | Mode |
127
- | ---------------------------------- | ------------ |
128
- | `{ pinata: { jwt, gateway } }` | Read + write |
129
- | `{ storacha: { email } }` | Read + write |
130
- | `{ storacha: { readOnly: true } }` | Read only |
126
+ | Config | Mode |
127
+ | ------------------------------ | ------------ |
128
+ | `{ pinata: { jwt, gateway } }` | Read + write |
129
+ | undefined | Read only |
131
130
 
132
131
  ### Schemas
133
132
 
@@ -235,7 +234,7 @@ const identity = new Identity();
235
234
 
236
235
  // Sign ERC-3009 authorization with the burner wallet
237
236
  const preparedRegister = await fangorn.consumer.prepareRegister({
238
- burnerPrivateKey: "0x...",
237
+ walletClient,
239
238
  paymentRecipient: ownerAddress,
240
239
  amount: 1n,
241
240
  usdcAddress: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
@@ -322,9 +321,9 @@ See the [gadgets](./src/modules/gadgets/README.md) docs for details on implement
322
321
 
323
322
  | Contract | Address |
324
323
  | ------------------- | -------------------------------------------- |
325
- | DataSource Registry | `0x3941c7d50caa56f7f676554bc4e78d77aaf27ebb` |
326
- | Schema Registry | `0x49ab3d52b997e63ad56c91178df48263fd80b2dc` |
327
- | Settlement Registry | `0x4536881306ee355c2f18ae81658771c4488139a3` |
324
+ | DataSource Registry | `0xdb82c131a9d51f6e7695e744bb2bd7774cbb224c` |
325
+ | Schema Registry | `0x35b67934f9c75bfef6ff3f4d61ff406d81420066` |
326
+ | Settlement Registry | `0x6aff8212e126ed3232958fd228bc58a202b8f590` |
328
327
 
329
328
  ---
330
329
 
@@ -347,19 +346,19 @@ pnpm test:e2e
347
346
 
348
347
  Required variables:
349
348
 
350
- | Variable | Description |
351
- | --------------------------- | ----------------------------------------- |
352
- | `DELEGATOR_ETH_PRIVATE_KEY` | Publisher private key (needs testnet ETH) |
353
- | `DELEGATEE_ETH_PRIVATE_KEY` | Consumer private key |
354
- | `PINATA_JWT` | Pinata API JWT |
355
- | `PINATA_GATEWAY` | Pinata gateway URL |
356
- | `CHAIN_NAME` | `arbitrumSepolia` |
357
- | `CAIP2` | `421614` |
358
- | `CHAIN_RPC_URL` | RPC endpoint |
359
- | `USDC_CONTRACT_ADDRESS` | USDC contract address |
360
- | `DS_REGISTRY_ADDR` | DataSourceRegistry address |
361
- | `SCHEMA_REGISTRY_ADDR` | SchemaRegistry address |
362
- | `SETTLEMENT_TRACKER_ADDR` | SettlementTracker address |
349
+ | Variable | Description |
350
+ | ------------------------------ | ----------------------------------------- |
351
+ | `DELEGATOR_ETH_PRIVATE_KEY` | Publisher private key (needs testnet ETH) |
352
+ | `DELEGATEE_ETH_PRIVATE_KEY` | Consumer private key |
353
+ | `PINATA_JWT` | Pinata API JWT |
354
+ | `PINATA_GATEWAY` | Pinata gateway URL |
355
+ | `CHAIN_NAME` | `arbitrumSepolia` |
356
+ | `CAIP2` | `421614` |
357
+ | `CHAIN_RPC_URL` | RPC endpoint |
358
+ | `USDC_CONTRACT_ADDRESS` | USDC contract address |
359
+ | `DATA_SOURCE_REGISTRY_ADDRESS` | DataSourceRegistry address |
360
+ | `SCHEMA_REGISTRY_ADDRESS` | SchemaRegistry address |
361
+ | `SETTLEMENT_REGISTRY_ADDRESS` | SettlementTracker address |
363
362
 
364
363
  Sample `.env` for Arbitrum Sepolia:
365
364
 
@@ -368,15 +367,20 @@ CHAIN_NAME=arbitrumSepolia
368
367
  CAIP2=421614
369
368
  CHAIN_RPC_URL=https://sepolia-rollup.arbitrum.io/rpc
370
369
  USDC_CONTRACT_ADDRESS=0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d
371
- DS_REGISTRY_ADDR=0x6fb3579bfd504cce85b923db335dfc096d912478
372
- SCHEMA_REGISTRY_ADDR=0x49ab3d52b997e63ad56c91178df48263fd80b2dc
373
- SETTLEMENT_TRACKER_ADDR=0x7c6ae9eb3398234eb69b2f3acfae69065505ff69
370
+ SETTLEMENT_REGISTRY_ADDRESS=0x6aff8212e126ed3232958fd228bc58a202b8f590
371
+ SCHEMA_REGISTRY_ADDRESS=0x35b67934f9c75bfef6ff3f4d61ff406d81420066
372
+ DATA_SOURCE_REGISTRY_ADDRESS=0xdb82c131a9d51f6e7695e744bb2bd7774cbb224c
374
373
  ```
375
374
 
376
375
  E2E tests deploy any contracts not defined in `.env`, register a test schema, publish manifests, and verify the full purchase → claim → decrypt cycle end-to-end.
377
376
 
378
377
  ---
379
378
 
379
+ ## Limitations/Future Work
380
+
381
+ - Schema validation is **client-side** only, meaning there is no on-chain validation at all, instead operating on a 'trust me' basis. This will be addressed in the future.
382
+ - Schema validation only works with Uint8Array inputs currently.
383
+
380
384
  ## License
381
385
 
382
386
  MIT
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 { SettlementRegistry } from "../registries/settlement-registry/index.js";
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,51 +19,42 @@ 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 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
- };
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 jwt = process.env.PINATA_JWT;
38
- const gateway = process.env.PINATA_GATEWAY;
29
+ const pinataJwt = process.env.PINATA_JWT;
30
+ const pinataGateway = process.env.PINATA_GATEWAY;
39
31
  const chainName = process.env.CHAIN_NAME;
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
- }
32
+ if (privateKey || pinataJwt || pinataGateway || chainName) {
33
+ const missing = [];
34
+ if (!privateKey) missing.push("DELEGATOR_ETH_PRIVATE_KEY");
35
+ if (!pinataJwt) missing.push("PINATA_JWT");
36
+ if (!pinataGateway) missing.push("PINATA_GATEWAY");
37
+ if (!chainName) missing.push("CHAIN_NAME");
38
+ 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.`);
39
+ _config = {
40
+ privateKey,
41
+ cfg: resolveAppConfig(chainName ?? ""),
42
+ pinataJwt: pinataJwt ?? "",
43
+ pinataGateway: pinataGateway ?? ""
44
+ };
45
+ return _config;
61
46
  }
62
47
  if (existsSync(CONFIG_PATH)) {
63
- _config = buildConfig(JSON.parse(readFileSync(CONFIG_PATH, "utf-8")));
48
+ const stored = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
49
+ _config = {
50
+ privateKey: stored.privateKey,
51
+ cfg: resolveAppConfig(stored.chainName),
52
+ pinataJwt: stored.pinataJwt,
53
+ pinataGateway: stored.pinataGateway
54
+ };
64
55
  return _config;
65
56
  }
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");
57
+ 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
58
  }
68
59
  function getAccount() {
69
60
  if (_account) return _account;
@@ -75,15 +66,14 @@ async function getFangorn() {
75
66
  const cfg = loadConfig();
76
67
  const agentConfig = {
77
68
  privateKey: cfg.privateKey,
78
- pinataJwt: cfg.jwt ?? ""
69
+ pinataJwt: cfg.pinataJwt
79
70
  };
80
- const storage = cfg.storage === "storacha" ? { storacha: { email: cfg.storachaEmail ?? "" } } : { pinata: {
81
- jwt: cfg.jwt ?? "",
82
- gateway: cfg.gateway ?? ""
83
- } };
84
71
  _fangorn = await Fangorn.create({
85
72
  privateKey: cfg.privateKey,
86
- storage,
73
+ storage: { pinata: {
74
+ jwt: cfg.pinataJwt,
75
+ gateway: cfg.pinataGateway
76
+ } },
87
77
  encryption: { lit: true },
88
78
  domain: "localhost",
89
79
  config: cfg.cfg,
@@ -91,11 +81,16 @@ async function getFangorn() {
91
81
  });
92
82
  return _fangorn;
93
83
  }
94
- async function resolveSchemaId(fangorn, schemaName) {
84
+ /**
85
+ * Resolves a schema name or bytes32 ID to an on-chain schemaId.
86
+ * Accepts either a human-readable name (e.g. "fangorn.music.v1") or a
87
+ * 0x-prefixed 32-byte hex string — the SchemaRegistry handles both.
88
+ */
89
+ async function resolveSchemaId(fangorn, schemaNameOrId) {
95
90
  try {
96
- return await fangorn.getSchemaRegistry().schemaId(typeof schemaName === "string" && !/^0x[0-9a-fA-F]{64}$/.test(schemaName) ? schemaName : schemaName);
91
+ return await fangorn.getSchemaRegistry().schemaId(/^0x[0-9a-fA-F]{64}$/.test(schemaNameOrId) ? schemaNameOrId : schemaNameOrId);
97
92
  } catch {
98
- throw new Error(`Schema "${schemaName}" not found on-chain. Register it with \`fangorn schema register\`.`);
93
+ throw new Error(`Schema "${schemaNameOrId}" not found on-chain. Register it with \`fangorn schema register\`.`);
99
94
  }
100
95
  }
101
96
  const program = new Command();
@@ -122,79 +117,39 @@ program.command("init").description("Configure your Fangorn credentials").action
122
117
  }]
123
118
  });
124
119
  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
- }]
120
+ const pinataJwt = await text({
121
+ message: "Pinata JWT:",
122
+ validate: (v) => {
123
+ if (!v) return "Required";
124
+ }
125
+ });
126
+ handleCancel(pinataJwt);
127
+ const pinataGateway = await text({
128
+ message: "Pinata Gateway URL:",
129
+ placeholder: "https://your-gateway.mypinata.cloud",
130
+ validate: (v) => {
131
+ if (!v) return "Required";
132
+ }
134
133
  });
135
- handleCancel(storageChoice);
134
+ handleCancel(pinataGateway);
136
135
  const stored = {
137
136
  privateKey,
138
137
  chainName,
139
- storage: storageChoice
138
+ pinataJwt,
139
+ pinataGateway
140
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
- }
170
141
  if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
171
142
  writeFileSync(CONFIG_PATH, JSON.stringify(stored, null, 2), "utf-8");
172
143
  chmodSync(CONFIG_PATH, 384);
173
144
  outro(`Config saved to ${CONFIG_PATH}`);
174
145
  });
175
146
  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) => {
147
+ schemaCmd.command("register").description("Register an agent identity and/or a schema on-chain").argument("<name>", "Schema / agent name").action(async (name) => {
177
148
  try {
178
149
  intro("Chain selection");
179
150
  outro(`Selected chain: ${(await selectChain()).name}`);
180
151
  const fangorn = await getFangorn();
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
- }
152
+ const datasourceAgentId = "";
198
153
  intro("Schema Registration");
199
154
  const schemaFilePath = await text({
200
155
  message: "Path to your JSON schema file:",
@@ -206,13 +161,7 @@ schemaCmd.command("register").description("Register an agent identity and/or a s
206
161
  }
207
162
  });
208
163
  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
- });
164
+ const schemaName = name;
216
165
  handleCancel(schemaName);
217
166
  let definition;
218
167
  try {
@@ -228,7 +177,7 @@ schemaCmd.command("register").description("Register an agent identity and/or a s
228
177
  process.exit(0);
229
178
  }
230
179
  const s = spinner();
231
- s.start("Registering schema");
180
+ s.start("Registering schema...");
232
181
  const { schemaId, schemaCid } = await fangorn.schema.register({
233
182
  name: schemaName,
234
183
  definition,
@@ -242,7 +191,7 @@ schemaCmd.command("register").description("Register an agent identity and/or a s
242
191
  process.exit(1);
243
192
  }
244
193
  });
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) => {
194
+ schemaCmd.command("get").description("Fetch a registered schema by name").argument("<name>", "Schema name (e.g. fangorn.music.v1)").action(async (name) => {
246
195
  try {
247
196
  const fangorn = await getFangorn();
248
197
  const s = spinner();
@@ -250,7 +199,7 @@ schemaCmd.command("get").description("Fetch a registered schema by name").argume
250
199
  const schema = await fangorn.schema.get(name);
251
200
  s.stop();
252
201
  if (!schema) {
253
- console.log(`Schema "${name}" not found.`);
202
+ log.error(`Schema "${name}" not found.`);
254
203
  process.exit(1);
255
204
  }
256
205
  note(JSON.stringify(schema, null, 2), `Schema: ${name}`);
@@ -261,14 +210,12 @@ schemaCmd.command("get").description("Fetch a registered schema by name").argume
261
210
  }
262
211
  });
263
212
  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) => {
213
+ publishCmd.command("upload").description("Encrypt and publish file(s) under a schema").argument("<files...>", "File path(s) to upload").requiredOption("-s, --schema <schemaName>", "Schema name (e.g. fangorn.music.v1) 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
214
  try {
266
215
  const fangorn = await getFangorn();
267
216
  const cfg = loadConfig();
268
217
  const price = BigInt(options.price);
269
218
  const s = spinner();
270
- const schemaId = await resolveSchemaId(fangorn, options.schema);
271
- const schema = (await fangorn.schema.get(options.schema))?.definition ?? {};
272
219
  const records = files.flatMap((filepath) => {
273
220
  const data = readFileSync(filepath, "utf-8");
274
221
  const parsed = JSON.parse(data, (key, value) => {
@@ -283,13 +230,11 @@ publishCmd.command("upload").description("Encrypt and publish file(s) under a sc
283
230
  });
284
231
  return Array.isArray(parsed) ? parsed : [parsed];
285
232
  });
286
- const gateway = cfg.storage === "pinata" ? cfg.gateway ?? "" : "";
287
233
  s.start("Encrypting and publishing...");
288
234
  const result = await fangorn.publisher.upload({
289
235
  records,
290
- schema,
291
- schemaId,
292
- gateway,
236
+ schemaName: options.schema,
237
+ gateway: cfg.pinataGateway,
293
238
  options: { overwrite: options.overwrite }
294
239
  }, price);
295
240
  s.stop();
@@ -300,25 +245,25 @@ publishCmd.command("upload").description("Encrypt and publish file(s) under a sc
300
245
  process.exit(1);
301
246
  }
302
247
  });
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) => {
248
+ publishCmd.command("list").description("List your manifest entries for a schema").requiredOption("-s, --schema <schemaName>", "Schema name or bytes32 ID").action(async (options) => {
304
249
  try {
305
250
  const fangorn = await getFangorn();
306
251
  const schemaId = await resolveSchemaId(fangorn, options.schema);
307
- const manifest = await fangorn.publisher.getManifest(schemaId);
252
+ const manifest = await fangorn.publisher.getManifest(schemaId, options.schema);
308
253
  if (!manifest) {
309
- console.log("No manifest found. Upload with `fangorn publish upload <files> -s <schema>`.");
254
+ log.warn("No manifest found. Upload with `fangorn publish upload <files> -s <schema>`.");
310
255
  process.exit(0);
311
256
  }
312
257
  console.log(`Schema: ${options.schema}`);
313
258
  console.log(`Entries (${manifest.entries.length.toString()}):`);
314
- for (const entry of manifest.entries) console.log(` - ${entry.tag}`);
259
+ for (const entry of manifest.entries) console.log(` - ${entry.name}`);
315
260
  process.exit(0);
316
261
  } catch (err) {
317
262
  console.error("Failed:", err.message);
318
263
  process.exit(1);
319
264
  }
320
265
  });
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) => {
266
+ 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
267
  try {
323
268
  const fangorn = await getFangorn();
324
269
  const schemaId = await resolveSchemaId(fangorn, options.schema);
@@ -331,26 +276,26 @@ publishCmd.command("entry").description("Show details for one of your manifest e
331
276
  }
332
277
  });
333
278
  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) => {
279
+ 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
280
  try {
336
281
  const fangorn = await getFangorn();
337
282
  const schemaId = await resolveSchemaId(fangorn, options.schema);
338
- const manifest = await fangorn.consumer.getManifest(options.owner, schemaId);
283
+ const manifest = await fangorn.consumer.getManifest(options.owner, schemaId, options.schema);
339
284
  if (!manifest) {
340
- console.log("No manifest found.");
285
+ log.warn("No manifest found.");
341
286
  process.exit(0);
342
287
  }
343
288
  console.log(`Owner: ${options.owner}`);
344
289
  console.log(`Schema: ${options.schema}`);
345
290
  console.log(`Entries (${manifest.entries.length.toString()}):`);
346
- for (const entry of manifest.entries) console.log(` - ${entry.tag}`);
291
+ for (const entry of manifest.entries) console.log(` - ${entry.name}`);
347
292
  process.exit(0);
348
293
  } catch (err) {
349
294
  console.error("Failed:", err.message);
350
295
  process.exit(1);
351
296
  }
352
297
  });
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) => {
298
+ 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
299
  try {
355
300
  const fangorn = await getFangorn();
356
301
  const schemaId = await resolveSchemaId(fangorn, options.schema);
@@ -366,18 +311,25 @@ consumeCmd.command("entry").description("Show a publisher's manifest entry").arg
366
311
  * consume purchase
367
312
  *
368
313
  * Phase 1 — sign ERC-3009 authorization + join Semaphore group.
369
- * Prints the identity export string; user must save it for `claim` + `decrypt`.
314
+ * Prints the identity export string; the user must save it for `claim` + `decrypt`.
370
315
  */
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) => {
316
+ 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
317
  try {
373
318
  const fangorn = await getFangorn();
319
+ const cfg = loadConfig();
374
320
  const schemaId = await resolveSchemaId(fangorn, options.schema);
375
- const relayerKey = loadConfig().privateKey;
321
+ const relayerKey = cfg.privateKey;
376
322
  const s = spinner();
377
323
  const identity = new Identity();
324
+ const chain = getChain(cfg.cfg.chainName);
325
+ const walletClient = createWalletClient({
326
+ account: privateKeyToAccount(options.burnerKey),
327
+ chain,
328
+ transport: http(cfg.cfg.rpcUrl)
329
+ });
378
330
  s.start("Preparing ERC-3009 authorization...");
379
331
  const preparedRegister = await fangorn.consumer.prepareRegister({
380
- burnerPrivateKey: options.burnerKey,
332
+ walletClient,
381
333
  paymentRecipient: owner,
382
334
  amount: BigInt(options.amount),
383
335
  usdcAddress: options.usdc,
@@ -389,21 +341,25 @@ consumeCmd.command("purchase").description("Phase 1: pay and join the access gro
389
341
  const { txHash } = await fangorn.consumer.register({
390
342
  owner,
391
343
  schemaId,
392
- tag,
344
+ name,
393
345
  identityCommitment: identity.commitment,
394
346
  relayerPrivateKey: relayerKey,
395
347
  preparedRegister
396
348
  });
397
349
  s.stop();
350
+ const exported = identity.export();
398
351
  note([
399
- `Tx: ${txHash}`,
352
+ `Tx: ${txHash}`,
400
353
  ``,
401
- `Save this identity string — required for claim and decrypt:`,
354
+ `⚠️ Save this identity string — you will need it for \`claim\` and \`decrypt\`:`,
402
355
  ``,
403
- ` ${identity.export()}`,
356
+ ` ${exported}`,
404
357
  ``,
405
- `Next: fangorn consume claim ${owner} ${tag} -s ${options.schema} \\`,
406
- ` --identity '<above>' --stealth <your-stealth-address>`
358
+ `Next:`,
359
+ ` fangorn consume claim ${owner} ${name} \\`,
360
+ ` -s ${options.schema} \\`,
361
+ ` --identity '${exported}' \\`,
362
+ ` --stealth <your-stealth-address>`
407
363
  ].join("\n"), "Purchase complete ✓");
408
364
  process.exit(0);
409
365
  } catch (err) {
@@ -417,7 +373,7 @@ consumeCmd.command("purchase").description("Phase 1: pay and join the access gro
417
373
  * Phase 2 — generate Groth16 ZK proof of group membership and fire the
418
374
  * SettlementRegistry hook. Prints the nullifier for use in `decrypt`.
419
375
  */
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) => {
376
+ 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
377
  try {
422
378
  const fangorn = await getFangorn();
423
379
  const schemaId = await resolveSchemaId(fangorn, options.schema);
@@ -426,7 +382,7 @@ consumeCmd.command("claim").description("Phase 2: prove membership and claim acc
426
382
  const s = spinner();
427
383
  s.start("Generating ZK proof...");
428
384
  const preparedSettle = await fangorn.consumer.prepareSettle({
429
- resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
385
+ resourceId: DataSourceRegistry.resourceIdLocal(owner, schemaId, name),
430
386
  identity,
431
387
  stealthAddress: options.stealth
432
388
  });
@@ -435,7 +391,7 @@ consumeCmd.command("claim").description("Phase 2: prove membership and claim acc
435
391
  const { txHash, nullifier } = await fangorn.consumer.claim({
436
392
  owner,
437
393
  schemaId,
438
- tag,
394
+ name,
439
395
  relayerPrivateKey: relayerKey,
440
396
  preparedSettle
441
397
  });
@@ -444,8 +400,13 @@ consumeCmd.command("claim").description("Phase 2: prove membership and claim acc
444
400
  `Tx: ${txHash}`,
445
401
  `Nullifier: ${nullifier.toString()}`,
446
402
  ``,
447
- `Next: fangorn consume decrypt ${owner} ${tag} -s ${options.schema} \\`,
448
- ` -f <field> --nullifier ${nullifier.toString()} --stealth-key <key> -o out.mp3`
403
+ `Next:`,
404
+ ` fangorn consume decrypt ${owner} ${name} \\`,
405
+ ` -s ${options.schema} \\`,
406
+ ` -f <field> \\`,
407
+ ` --nullifier ${nullifier.toString()} \\`,
408
+ ` --stealth-key <stealth-private-key> \\`,
409
+ ` -o out.mp3`
449
410
  ].join("\n"), "Claim complete ✓");
450
411
  process.exit(0);
451
412
  } catch (err) {
@@ -459,16 +420,17 @@ consumeCmd.command("claim").description("Phase 2: prove membership and claim acc
459
420
  * Decrypt a field after a completed purchase + claim cycle.
460
421
  * The stealth wallet is used to create the Lit auth context.
461
422
  */
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) => {
423
+ consumeCmd.command("decrypt").description("Decrypt 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 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("-o, --output <path>", "Write decrypted output to file (default: stdout)").action(async (owner, name, options) => {
463
424
  try {
464
- const chain = getChain(options.chain);
425
+ const cfg = loadConfig();
426
+ const chain = getChain(cfg.cfg.chainName);
465
427
  const fangorn = await getFangorn();
466
428
  const schemaId = await resolveSchemaId(fangorn, options.schema);
467
429
  const s = spinner();
468
430
  const walletClient = createWalletClient({
469
431
  account: privateKeyToAccount(options.stealthKey),
470
432
  chain,
471
- transport: http(loadConfig().cfg.rpcUrl)
433
+ transport: http(cfg.cfg.rpcUrl)
472
434
  });
473
435
  const identity = options.identity ? new Identity(options.identity) : void 0;
474
436
  s.start("Decrypting...");
@@ -477,7 +439,7 @@ consumeCmd.command("decrypt").description("Decrypt a field after purchase and cl
477
439
  walletClient,
478
440
  schemaId,
479
441
  nullifierHash: BigInt(options.nullifier),
480
- tag,
442
+ name,
481
443
  field: options.field,
482
444
  identity,
483
445
  skipSettlementCheck: !!options.skipSettlementCheck
@@ -496,13 +458,13 @@ consumeCmd.command("decrypt").description("Decrypt a field after purchase and cl
496
458
  process.exit(1);
497
459
  }
498
460
  });
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) => {
461
+ 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
462
  try {
501
463
  const self = getAccount().address;
502
464
  const owner = options.owner ?? self;
503
465
  const fangorn = await getFangorn();
504
466
  const schemaId = await resolveSchemaId(fangorn, options.schema);
505
- const ds = await fangorn.getDatasourceRegistry().getManifest(owner, schemaId);
467
+ const ds = await fangorn.getDatasourceRegistry().get(owner, schemaId, options.schema);
506
468
  console.log(`Owner: ${owner}`);
507
469
  console.log(`Schema ID: ${schemaId}`);
508
470
  console.log(`Version: ${String(ds.version)}`);