@fangorn-network/sdk 2026.5.10 → 2026.6.16
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 +87 -37
- package/lib/ crypto/constants.d.ts +4 -0
- package/lib/ crypto/constants.js +5 -0
- package/lib/ crypto/merkle.d.ts +10 -0
- package/lib/ crypto/merkle.js +34 -0
- package/lib/ crypto/utils.d.ts +1 -0
- package/lib/ crypto/utils.js +1 -0
- package/lib/cli/cli.js +61 -156
- package/lib/cli/index.d.ts +171 -170
- package/lib/config.d.ts +258 -257
- package/lib/config.js +3 -3
- package/lib/fangorn.js +2 -2
- package/lib/index.d.ts +1 -3
- package/lib/index.js +1 -3
- package/lib/modules/encryption/rand.d.ts +1 -1
- package/lib/providers/storage/pinata.d.ts +5 -1
- package/lib/providers/storage/pinata.js +24 -3
- package/lib/providers/storage/types.d.ts +8 -0
- package/lib/providers/storage/utils.js +2 -1
- package/lib/registries/datasource-registry/abi.d.ts +34 -4
- package/lib/registries/datasource-registry/abi.js +40 -5
- package/lib/registries/datasource-registry/index.d.ts +22 -13
- package/lib/registries/datasource-registry/index.js +76 -76
- package/lib/registries/index.d.ts +1 -1
- package/lib/registries/schema-registry/index.d.ts +3 -3
- package/lib/registries/schema-registry/index.js +1 -1
- package/lib/registries/settlement-registry/index.d.ts +2 -2
- package/lib/roles/consumer/index.d.ts +3 -3
- package/lib/roles/consumer/index.js +19 -12
- package/lib/roles/publisher/builders/bundle.d.ts +32 -0
- package/lib/roles/publisher/builders/bundle.js +137 -0
- package/lib/roles/publisher/builders/record-set.d.ts +17 -0
- package/lib/roles/publisher/builders/record-set.js +55 -0
- package/lib/roles/publisher/builders/types.d.ts +38 -0
- package/lib/roles/publisher/builders/types.js +1 -0
- package/lib/roles/publisher/builders/utils.d.ts +9 -0
- package/lib/roles/publisher/builders/utils.js +29 -0
- package/lib/roles/publisher/encryption.d.ts +18 -0
- package/lib/roles/publisher/encryption.js +38 -0
- package/lib/roles/publisher/index.d.ts +54 -36
- package/lib/roles/publisher/index.js +137 -174
- package/lib/roles/publisher/types.d.ts +61 -46
- package/lib/roles/schema/index.d.ts +30 -4
- package/lib/roles/schema/index.js +81 -47
- package/lib/roles/schema/types.d.ts +59 -37
- package/lib/roles/schema/validate.d.ts +9 -0
- package/lib/roles/schema/validate.js +128 -0
- package/lib/test/cleanup-embeddings-testdata.d.ts +1 -0
- package/lib/test/cleanup-embeddings-testdata.js +104 -0
- package/lib/test/publish_mb_bundle.d.ts +1 -0
- package/lib/test/publish_mb_bundle.js +296 -0
- package/lib/test/setup-embeddings-testdata.d.ts +13 -0
- package/lib/test/setup-embeddings-testdata.js +209 -0
- package/lib/test/testbed.d.ts +14 -8
- package/lib/test/testbed.js +28 -24
- package/package.json +16 -2
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Fangorn SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
commit → index → discover → prove → settle → fetch
|
|
4
|
+
|
|
5
|
+
Intent-bound data for the agentic web.
|
|
4
6
|
|
|
5
7
|
Fangorn lets you publish data under programmable access conditions. Access is enforced on-chain through settlement verification, so your content is only retrievable by those who have provably paid for it. Data is organized by schemas, enabling agent-based discovery across any number of publishers.
|
|
6
8
|
Content is stored in your own storage backend (Cloudflare R2, IPFS, or any compatible future backend). The Fangorn protocol coordinates access without ever touching your content directly.
|
|
@@ -166,50 +168,98 @@ const schema = await fangorn.schema.get("schema.name.v1");
|
|
|
166
168
|
|
|
167
169
|
### Publishing
|
|
168
170
|
|
|
169
|
-
|
|
171
|
+
Fangorn supports two manifest kinds, selected by which builder you pass to `publisher.publish()`.
|
|
172
|
+
|
|
173
|
+
#### Record-set
|
|
174
|
+
|
|
175
|
+
Upload content to your R2 bucket out-of-band, then publish a manifest pointing at it. The SDK stores the manifest on IPFS and commits the Merkle root on-chain.
|
|
170
176
|
|
|
171
177
|
```ts
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
},
|
|
178
|
+
// Convenience wrapper — equivalent to publish({ builder: new RecordSetBuilder(), ... })
|
|
179
|
+
await fangorn.publisher.publishRecords({
|
|
180
|
+
schemaName: "schema.name.v1",
|
|
181
|
+
records: [
|
|
182
|
+
{
|
|
183
|
+
name: "track1",
|
|
184
|
+
fields: {
|
|
185
|
+
title: "Locura",
|
|
186
|
+
artist: "Alice",
|
|
187
|
+
audio: { "@type": "handle", uri: "r2://my-dir/locura.mp3" },
|
|
182
188
|
},
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Legacy alias still works
|
|
194
|
+
await fangorn.publisher.upload({ schemaName: "schema.name.v1", records: [...] });
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The resulting manifest has `kind: "record-set"` and `version: 2`. Plain fields (`title`, `artist`) are publicly readable from the manifest; handle fields require a valid on-chain settlement to retrieve via the access worker.
|
|
198
|
+
|
|
199
|
+
#### Bundle
|
|
200
|
+
|
|
201
|
+
A bundle is a small typed subgraph spanning multiple schemas. Define the shape once via a bundle schema, then publish node + edge data against it. This is the right primitive for linked data (e.g. tracks + taxonomy + edges between them).
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
// 1. Register node schemas (idempotent)
|
|
205
|
+
await fangorn.schema.register({ name: "my.track.v1", definition: trackSchema });
|
|
206
|
+
await fangorn.schema.register({ name: "my.taxonomy.v1", definition: taxonomySchema });
|
|
207
|
+
|
|
208
|
+
// 2. Register the bundle shape (idempotent)
|
|
209
|
+
await fangorn.schema.register({
|
|
210
|
+
kind: "bundle",
|
|
211
|
+
name: "my.bundle.v1",
|
|
212
|
+
bundle: {
|
|
213
|
+
nodes: { Track: "my.track.v1", Taxonomy: "my.taxonomy.v1" },
|
|
214
|
+
edges: [{ rel: "hasTaxonomy", from: "Track", to: "Taxonomy", min: 1, max: 1 }],
|
|
185
215
|
},
|
|
186
|
-
|
|
187
|
-
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// 3. Publish data
|
|
219
|
+
await fangorn.publisher.publishBundle({
|
|
220
|
+
bundleName: "my.bundle.v1",
|
|
221
|
+
nodes: [
|
|
222
|
+
{ id: "t1", type: "Track", fields: { trackId: "t1", title: "Locura", ... } },
|
|
223
|
+
{ id: "x1", type: "Taxonomy", fields: { trackId: "t1", genres: ["electronic"] } },
|
|
224
|
+
],
|
|
225
|
+
edges: [
|
|
226
|
+
{ rel: "hasTaxonomy", from: "t1", to: "x1" },
|
|
227
|
+
],
|
|
228
|
+
datasetName: "my-dataset-v1",
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Legacy alias still works
|
|
232
|
+
await fangorn.publisher.uploadBundle({ bundleName: "my.bundle.v1", nodes: [...], edges: [...] });
|
|
188
233
|
```
|
|
189
234
|
|
|
190
|
-
The manifest stored on
|
|
235
|
+
The resulting manifest has `kind: "bundle"` and `version: 3`. Node chunks and the edge chunk are stored separately on IPFS and committed together under a single Merkle root.
|
|
191
236
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
237
|
+
#### Custom builders
|
|
238
|
+
|
|
239
|
+
Both `RecordSetBuilder` and `BundleBuilder` implement the `ManifestBuilder` interface. You can implement your own:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import {
|
|
243
|
+
ManifestBuilder, BuildContext, ChunkDraft, ChunkRef,
|
|
244
|
+
BaseManifest, ResolvedSchemaShape,
|
|
245
|
+
} from "@fangorn-network/sdk";
|
|
246
|
+
|
|
247
|
+
class MyBuilder implements ManifestBuilder<MyInput, MyManifest> {
|
|
248
|
+
readonly kind = "my-kind";
|
|
249
|
+
readonly version = 1;
|
|
250
|
+
validate(schema, input) { /* ... */ }
|
|
251
|
+
async *chunk(input, schema) { yield { name: "chunk:0", data: [...] }; }
|
|
252
|
+
compareChunks(a, b) { return a.cid.localeCompare(b.cid); }
|
|
253
|
+
assemble(ctx, input, schema): MyManifest { /* ... */ }
|
|
209
254
|
}
|
|
210
|
-
```
|
|
211
255
|
|
|
212
|
-
|
|
256
|
+
await fangorn.publisher.publish({
|
|
257
|
+
schemaName: "my.schema.v1",
|
|
258
|
+
builder: new MyBuilder(),
|
|
259
|
+
input: myInput,
|
|
260
|
+
datasetName: "my-dataset",
|
|
261
|
+
});
|
|
262
|
+
```
|
|
213
263
|
|
|
214
264
|
### Consuming
|
|
215
265
|
|
|
@@ -234,7 +284,7 @@ const { txHash } = await fangorn.consumer.register({
|
|
|
234
284
|
schemaId,
|
|
235
285
|
name: "track1",
|
|
236
286
|
identityCommitment: identity.commitment,
|
|
237
|
-
relayerPrivateKey: "0x...",
|
|
287
|
+
relayerPrivateKey: "0x...",
|
|
238
288
|
preparedRegister,
|
|
239
289
|
});
|
|
240
290
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/ crypto/merkle.d.ts
|
|
2
|
+
declare function hashCidToField(cid: string): bigint;
|
|
3
|
+
declare function getProof(layers: bigint[][], index: number): {
|
|
4
|
+
path: bigint[];
|
|
5
|
+
indices: number[];
|
|
6
|
+
};
|
|
7
|
+
declare function fieldToHex(field: bigint): `0x${string}`;
|
|
8
|
+
declare function hexToField(hex: string): bigint;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { fieldToHex, getProof, hashCidToField, hexToField };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TREE_DEPTH } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ crypto/merkle.ts
|
|
4
|
+
function hashCidToField(cid) {
|
|
5
|
+
const bytes = new TextEncoder().encode(cid);
|
|
6
|
+
let value = 0n;
|
|
7
|
+
for (let i = 0; i < Math.min(bytes.length, 31); i++) value = value << 8n | BigInt(bytes[i]);
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function getProof(layers, index) {
|
|
11
|
+
const path = [];
|
|
12
|
+
const indices = [];
|
|
13
|
+
for (let i = 0; i < TREE_DEPTH; i++) {
|
|
14
|
+
const isRight = index % 2 === 1;
|
|
15
|
+
const siblingIndex = isRight ? index - 1 : index + 1;
|
|
16
|
+
path.push(layers[i][siblingIndex] ?? 0n);
|
|
17
|
+
indices.push(isRight ? 1 : 0);
|
|
18
|
+
index = Math.floor(index / 2);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
path,
|
|
22
|
+
indices
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function fieldToHex(field) {
|
|
26
|
+
return `0x${field.toString(16).padStart(64, "0")}`;
|
|
27
|
+
}
|
|
28
|
+
function hexToField(hex) {
|
|
29
|
+
const cleanHex = hex.startsWith("0x") ? hex : `0x${hex}`;
|
|
30
|
+
return BigInt(cleanHex);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { fieldToHex, getProof, hashCidToField, hexToField };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/lib/cli/cli.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { FangornConfig, SupportedNetworks } from "../config.js";
|
|
3
|
-
import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
|
|
4
3
|
import { Fangorn } from "../fangorn.js";
|
|
5
|
-
import {
|
|
6
|
-
import { createWalletClient, http } from "viem";
|
|
4
|
+
import { handleCancel, selectChain } from "./index.js";
|
|
7
5
|
import { privateKeyToAccount } from "viem/accounts";
|
|
8
6
|
import { Command } from "commander";
|
|
9
7
|
import { confirm, intro, log, note, outro, select, spinner, text } from "@clack/prompts";
|
|
10
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
8
|
+
import { chmodSync, closeSync, createReadStream, existsSync, mkdirSync, openSync, readFileSync, readSync, writeFileSync } from "fs";
|
|
9
|
+
import streamArray from "stream-json/streamers/stream-array.js";
|
|
11
10
|
import { extname, join } from "path";
|
|
12
11
|
import { homedir } from "os";
|
|
13
|
-
import { Identity } from "@semaphore-protocol/identity";
|
|
14
12
|
import "dotenv/config";
|
|
15
13
|
|
|
16
14
|
//#region src/cli/cli.ts
|
|
@@ -67,6 +65,7 @@ function getAccount() {
|
|
|
67
65
|
function getFangorn() {
|
|
68
66
|
if (_fangorn) return _fangorn;
|
|
69
67
|
const cfg = loadConfig();
|
|
68
|
+
console.log(JSON.stringify(cfg));
|
|
70
69
|
const agentConfig = {
|
|
71
70
|
privateKey: cfg.privateKey,
|
|
72
71
|
pinataJwt: cfg.pinataJwt
|
|
@@ -90,9 +89,9 @@ async function resolveSchemaId(fangorn, schemaNameOrId) {
|
|
|
90
89
|
throw new Error(`Schema "${schemaNameOrId}" not found on-chain. Register it with \`fangorn schema register\`.`);
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
|
-
const program = new Command();
|
|
94
|
-
program.name("fangorn").description("Fangorn Network CLI").version("0.2.
|
|
95
|
-
program.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
92
|
+
const program$1 = new Command();
|
|
93
|
+
program$1.name("fangorn").description("Fangorn Network CLI").version("0.2.1");
|
|
94
|
+
program$1.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
96
95
|
intro("Fangorn Setup");
|
|
97
96
|
const privateKey = await text({
|
|
98
97
|
message: "Wallet private key (stored locally, never transmitted):",
|
|
@@ -149,7 +148,7 @@ program.command("init").description("Configure your Fangorn credentials").action
|
|
|
149
148
|
chmodSync(CONFIG_PATH, 384);
|
|
150
149
|
outro(`Config saved to ${CONFIG_PATH}`);
|
|
151
150
|
});
|
|
152
|
-
const schemaCmd = program.command("schema").description("Schema registry operations");
|
|
151
|
+
const schemaCmd = program$1.command("schema").description("Schema registry operations");
|
|
153
152
|
schemaCmd.command("register").description("Register a schema on-chain").argument("<name>", "Schema name").action(async (name) => {
|
|
154
153
|
try {
|
|
155
154
|
intro("Chain selection");
|
|
@@ -183,8 +182,7 @@ schemaCmd.command("register").description("Register a schema on-chain").argument
|
|
|
183
182
|
s.start("Registering schema...");
|
|
184
183
|
const { schemaId, schemaCid } = await fangorn.schema.register({
|
|
185
184
|
name,
|
|
186
|
-
definition
|
|
187
|
-
agentId: ""
|
|
185
|
+
definition
|
|
188
186
|
});
|
|
189
187
|
s.stop();
|
|
190
188
|
note(`Schema ID: ${schemaId}\nCID: ${schemaCid}`, "Schema registered");
|
|
@@ -212,23 +210,54 @@ schemaCmd.command("get").description("Fetch a registered schema by name").argume
|
|
|
212
210
|
process.exit(1);
|
|
213
211
|
}
|
|
214
212
|
});
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
/**
|
|
214
|
+
* Cheaply read the first non-whitespace byte of a file without loading it.
|
|
215
|
+
* Used to decide between streaming an array ("[") and reading a single object.
|
|
216
|
+
*/
|
|
217
|
+
function peekFirstNonWsByte(filepath) {
|
|
218
|
+
const fd = openSync(filepath, "r");
|
|
219
|
+
try {
|
|
220
|
+
const buf = Buffer.alloc(64);
|
|
221
|
+
let offset = 0;
|
|
222
|
+
for (;;) {
|
|
223
|
+
const bytesRead = readSync(fd, buf, 0, buf.length, offset);
|
|
224
|
+
if (bytesRead === 0) return void 0;
|
|
225
|
+
for (let i = 0; i < bytesRead; i++) {
|
|
226
|
+
const b = buf[i];
|
|
227
|
+
if (b !== 32 && b !== 9 && b !== 10 && b !== 13) return b;
|
|
228
|
+
}
|
|
229
|
+
offset += bytesRead;
|
|
230
|
+
}
|
|
231
|
+
} finally {
|
|
232
|
+
closeSync(fd);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const publishCmd = program$1.command("publish").description("Publisher operations");
|
|
236
|
+
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").requiredOption("-d, --dataset <datasetName>", "Dataset name (groups entries under a manifest)").option("--chunk-size <n>", "Records per chunk (default 1000)", (v) => parseInt(v, 10)).option("--concurrency <n>", "Parallel chunk uploads (default 10)", (v) => parseInt(v, 10)).action(async (files, options) => {
|
|
217
237
|
try {
|
|
218
238
|
const fangorn = getFangorn();
|
|
219
|
-
const price = BigInt(options.price);
|
|
220
239
|
const s = spinner();
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
240
|
+
let published = 0;
|
|
241
|
+
async function* streamRecords() {
|
|
242
|
+
for (const filepath of files) if (peekFirstNonWsByte(filepath) === 91) {
|
|
243
|
+
const pipeline = createReadStream(filepath).pipe(streamArray.withParserAsStream());
|
|
244
|
+
for await (const { value } of pipeline) {
|
|
245
|
+
yield value;
|
|
246
|
+
if (++published % 1e4 === 0) s.message(`Publishing... ${published.toLocaleString()} records read`);
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
yield JSON.parse(readFileSync(filepath, "utf-8"));
|
|
250
|
+
published++;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
226
253
|
s.start("Publishing...");
|
|
227
|
-
const result = await fangorn.publisher.
|
|
228
|
-
records,
|
|
254
|
+
const result = await fangorn.publisher.publishRecords({
|
|
255
|
+
records: streamRecords(),
|
|
229
256
|
schemaName: options.schema,
|
|
230
|
-
|
|
231
|
-
|
|
257
|
+
datasetName: options.dataset,
|
|
258
|
+
chunkSize: options.chunkSize,
|
|
259
|
+
concurrency: options.concurrency
|
|
260
|
+
});
|
|
232
261
|
s.stop();
|
|
233
262
|
note(`Manifest URI: ${result.manifestUri}\nEntries: ${result.entryCount.toString()}\nSchema: ${result.schemaId}`, "Upload complete");
|
|
234
263
|
process.exit(0);
|
|
@@ -237,11 +266,13 @@ publishCmd.command("upload").description("Publish file handle(s) under a schema"
|
|
|
237
266
|
process.exit(1);
|
|
238
267
|
}
|
|
239
268
|
});
|
|
240
|
-
publishCmd.command("entry").description("Show details for one of your manifest entries").argument("<tag>", "Entry tag / name").requiredOption("-s, --schema <schemaName>", "Schema name
|
|
269
|
+
publishCmd.command("entry").description("Show details for one of your manifest entries").argument("<tag>", "Entry tag / name").requiredOption("-s, --schema <schemaName>", "Schema name").requiredOption("-d, --dataset <datasetName>", "Dataset name").action(async (tag, options) => {
|
|
241
270
|
try {
|
|
242
271
|
const fangorn = getFangorn();
|
|
243
|
-
const
|
|
244
|
-
|
|
272
|
+
const s = spinner();
|
|
273
|
+
s.start(`Fetching entry "${tag}"...`);
|
|
274
|
+
const entry = await fangorn.publisher.getEntry(options.schema, options.dataset, tag);
|
|
275
|
+
s.stop();
|
|
245
276
|
note(JSON.stringify(entry, null, 2), `Entry: ${tag}`);
|
|
246
277
|
process.exit(0);
|
|
247
278
|
} catch (err) {
|
|
@@ -249,20 +280,17 @@ publishCmd.command("entry").description("Show details for one of your manifest e
|
|
|
249
280
|
process.exit(1);
|
|
250
281
|
}
|
|
251
282
|
});
|
|
252
|
-
const consumeCmd = program.command("consume").description("Consumer operations");
|
|
283
|
+
const consumeCmd = program$1.command("consume").description("Consumer operations");
|
|
253
284
|
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) => {
|
|
254
285
|
try {
|
|
255
286
|
const fangorn = getFangorn();
|
|
256
287
|
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
257
|
-
|
|
258
|
-
if (!manifest) {
|
|
288
|
+
if (!await fangorn.consumer.getEntry(options.owner, schemaId, options.schema)) {
|
|
259
289
|
log.warn("No manifest found.");
|
|
260
290
|
process.exit(0);
|
|
261
291
|
}
|
|
262
292
|
console.log(`Owner: ${options.owner}`);
|
|
263
293
|
console.log(`Schema: ${options.schema}`);
|
|
264
|
-
console.log(`Entries (${manifest.entries.length.toString()}):`);
|
|
265
|
-
for (const entry of manifest.entries) console.log(` - ${entry.name}`);
|
|
266
294
|
process.exit(0);
|
|
267
295
|
} catch (err) {
|
|
268
296
|
console.error("Failed:", err.message);
|
|
@@ -281,130 +309,7 @@ consumeCmd.command("entry").description("Show a publisher's manifest entry").arg
|
|
|
281
309
|
process.exit(1);
|
|
282
310
|
}
|
|
283
311
|
});
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
const fangorn = getFangorn();
|
|
287
|
-
const cfg = loadConfig();
|
|
288
|
-
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
289
|
-
const relayerKey = cfg.privateKey;
|
|
290
|
-
const s = spinner();
|
|
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
|
-
});
|
|
298
|
-
s.start("Preparing ERC-3009 authorization...");
|
|
299
|
-
const preparedRegister = await fangorn.consumer.prepareRegister({
|
|
300
|
-
walletClient,
|
|
301
|
-
paymentRecipient: owner,
|
|
302
|
-
amount: BigInt(options.amount),
|
|
303
|
-
usdcAddress: options.usdc,
|
|
304
|
-
usdcDomainName: "USD Coin",
|
|
305
|
-
usdcDomainVersion: "2"
|
|
306
|
-
});
|
|
307
|
-
s.stop();
|
|
308
|
-
s.start("Submitting registration...");
|
|
309
|
-
const { txHash } = await fangorn.consumer.register({
|
|
310
|
-
owner,
|
|
311
|
-
schemaId,
|
|
312
|
-
name,
|
|
313
|
-
identityCommitment: identity.commitment,
|
|
314
|
-
relayerPrivateKey: relayerKey,
|
|
315
|
-
preparedRegister
|
|
316
|
-
});
|
|
317
|
-
s.stop();
|
|
318
|
-
const exported = identity.export();
|
|
319
|
-
note([
|
|
320
|
-
`Tx: ${txHash}`,
|
|
321
|
-
``,
|
|
322
|
-
`⚠️ Save this identity string — you will need it for \`claim\`:`,
|
|
323
|
-
``,
|
|
324
|
-
` ${exported}`,
|
|
325
|
-
``,
|
|
326
|
-
`Next:`,
|
|
327
|
-
` fangorn consume claim ${owner} ${name} \\`,
|
|
328
|
-
` -s ${options.schema} \\`,
|
|
329
|
-
` --identity '${exported}' \\`,
|
|
330
|
-
` --stealth <your-stealth-address>`
|
|
331
|
-
].join("\n"), "Purchase complete ✓");
|
|
332
|
-
process.exit(0);
|
|
333
|
-
} catch (err) {
|
|
334
|
-
console.error("Failed:", err.message);
|
|
335
|
-
process.exit(1);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
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) => {
|
|
339
|
-
try {
|
|
340
|
-
const fangorn = getFangorn();
|
|
341
|
-
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
342
|
-
const relayerKey = loadConfig().privateKey;
|
|
343
|
-
const identity = new Identity(options.identity);
|
|
344
|
-
const s = spinner();
|
|
345
|
-
s.start("Generating ZK proof...");
|
|
346
|
-
const preparedSettle = await fangorn.consumer.prepareSettle({
|
|
347
|
-
resourceId: DataSourceRegistry.resourceIdLocal(owner, schemaId, name),
|
|
348
|
-
identity,
|
|
349
|
-
stealthAddress: options.stealth
|
|
350
|
-
});
|
|
351
|
-
s.stop();
|
|
352
|
-
s.start("Submitting settlement...");
|
|
353
|
-
const { txHash, nullifier } = await fangorn.consumer.claim({
|
|
354
|
-
owner,
|
|
355
|
-
schemaId,
|
|
356
|
-
name,
|
|
357
|
-
relayerPrivateKey: relayerKey,
|
|
358
|
-
preparedSettle
|
|
359
|
-
});
|
|
360
|
-
s.stop();
|
|
361
|
-
note([
|
|
362
|
-
`Tx: ${txHash}`,
|
|
363
|
-
`Nullifier: ${nullifier.toString()}`,
|
|
364
|
-
``,
|
|
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`
|
|
372
|
-
].join("\n"), "Claim complete ✓");
|
|
373
|
-
process.exit(0);
|
|
374
|
-
} catch (err) {
|
|
375
|
-
console.error("Failed:", err.message);
|
|
376
|
-
process.exit(1);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
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) => {
|
|
380
|
-
try {
|
|
381
|
-
const cfg = loadConfig();
|
|
382
|
-
const chain = getChain(cfg.cfg.chainName);
|
|
383
|
-
const fangorn = getFangorn();
|
|
384
|
-
const schemaId = await resolveSchemaId(fangorn, options.schema);
|
|
385
|
-
const s = spinner();
|
|
386
|
-
const walletClient = createWalletClient({
|
|
387
|
-
account: privateKeyToAccount(options.stealthKey),
|
|
388
|
-
chain,
|
|
389
|
-
transport: http(cfg.cfg.rpcUrl)
|
|
390
|
-
});
|
|
391
|
-
s.start("Fetching...");
|
|
392
|
-
const { data } = await fangorn.consumer.fetchField(owner, schemaId, name, options.field, options.nullifier, walletClient);
|
|
393
|
-
s.stop();
|
|
394
|
-
if (options.output) {
|
|
395
|
-
writeFileSync(options.output, Buffer.from(data));
|
|
396
|
-
console.log(`Saved to: ${options.output}`);
|
|
397
|
-
} else {
|
|
398
|
-
process.stdout.write(Buffer.from(data));
|
|
399
|
-
process.stdout.write("\n");
|
|
400
|
-
}
|
|
401
|
-
process.exit(0);
|
|
402
|
-
} catch (err) {
|
|
403
|
-
console.error("Failed:", err.message);
|
|
404
|
-
process.exit(1);
|
|
405
|
-
}
|
|
406
|
-
});
|
|
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) => {
|
|
312
|
+
program$1.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) => {
|
|
408
313
|
try {
|
|
409
314
|
const self = getAccount().address;
|
|
410
315
|
const owner = options.owner ?? self;
|
|
@@ -421,7 +326,7 @@ program.command("datasource").description("Data source registry queries").comman
|
|
|
421
326
|
process.exit(1);
|
|
422
327
|
}
|
|
423
328
|
});
|
|
424
|
-
program.parse();
|
|
329
|
+
program$1.parse();
|
|
425
330
|
|
|
426
331
|
//#endregion
|
|
427
332
|
export { };
|