@fangorn-network/sdk 2026.7.29-dev → 2026.8.12-dev
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/lib/cli/cli.js +23 -14
- package/lib/config.d.ts +1 -1
- package/lib/config.js +1 -1
- package/lib/contracts/data-registry/index.d.ts +6 -0
- package/lib/contracts/data-registry/index.js +21 -8
- package/lib/engine/index.d.ts +1 -1
- package/lib/engine/index.js +1 -1
- package/lib/fangorn.d.ts +11 -4
- package/lib/fangorn.js +13 -5
- package/package.json +1 -12
package/lib/cli/cli.js
CHANGED
|
@@ -80,7 +80,7 @@ function getFangorn() {
|
|
|
80
80
|
storage,
|
|
81
81
|
domain: "localhost",
|
|
82
82
|
config: cfg.cfg,
|
|
83
|
-
appId: cfg.appId
|
|
83
|
+
appId: program.opts().app ?? cfg.appId
|
|
84
84
|
});
|
|
85
85
|
return _fangorn;
|
|
86
86
|
}
|
|
@@ -131,6 +131,7 @@ var LocalRepo = class LocalRepo {
|
|
|
131
131
|
};
|
|
132
132
|
const program = new Command();
|
|
133
133
|
program.name("fangorn").description("Fangorn Network CLI").version("0.4.0");
|
|
134
|
+
program.option("--app <name-or-id>", "App (global namespace) for this command — overrides the stored app (see `set-app`)");
|
|
134
135
|
program.command("init").description("Configure your Fangorn credentials").action(async () => {
|
|
135
136
|
intro("Fangorn Setup");
|
|
136
137
|
const privateKey = await text({
|
|
@@ -394,22 +395,24 @@ program.command("clone").description("Track an existing on-chain namespace by re
|
|
|
394
395
|
process.exit(1);
|
|
395
396
|
}
|
|
396
397
|
});
|
|
397
|
-
program.command("subscribe").description("Watch on-chain pushes to a namespace and stream JSON diffs (light client — no indexer)").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner, else self)").option("--from-block <n>", "Replay from this block (overrides the saved cursor)", (v) => BigInt(v)).option("--from-start", "Replay this namespace's full history (ignore the saved cursor)").option("--pretty", "Pretty-print each change").action(async (namespaceArg, options) => {
|
|
398
|
+
program.command("subscribe").description("Watch on-chain pushes to a namespace and stream JSON diffs (light client — no indexer)").argument("[namespace]", "Namespace name (default: current repo)").option("--owner <address>", "Owner (publisher) address (default: current repo owner, else self)").option("--from-block <n>", "Replay from this block (overrides the saved cursor)", (v) => BigInt(v)).option("--from-start", "Replay this namespace's full history (ignore the saved cursor)").option("--pretty", "Pretty-print each change").option("--all", "Watch the whole app (every publisher, every namespace); --owner/namespace narrow it").action(async (namespaceArg, options) => {
|
|
398
399
|
try {
|
|
399
400
|
const fangorn = getFangorn();
|
|
400
401
|
let namespace = namespaceArg;
|
|
401
402
|
let owner = options.owner;
|
|
402
|
-
if (!
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
403
|
+
if (!options.all) {
|
|
404
|
+
if (!namespace || !owner) try {
|
|
405
|
+
const repo = LocalRepo.open();
|
|
406
|
+
namespace = namespace ?? repo.namespace();
|
|
407
|
+
owner = owner ?? repo.owner();
|
|
408
|
+
} catch {}
|
|
409
|
+
if (!namespace) throw new Error("namespace required (pass it as an argument, run inside a repo, or use --all)");
|
|
410
|
+
owner = owner ?? fangorn.getAddress();
|
|
411
|
+
}
|
|
409
412
|
const repoDir = join(process.cwd(), ".fangorn");
|
|
410
|
-
const cursorPath = join(repoDir, `subscribe-${owner}-${namespace}.json`);
|
|
413
|
+
const cursorPath = join(repoDir, `subscribe-${owner ?? "app"}-${namespace ?? "all"}.json`);
|
|
411
414
|
const readCursor = () => {
|
|
412
|
-
if (options.fromStart) return
|
|
415
|
+
if (options.fromStart) return 0n;
|
|
413
416
|
if (options.fromBlock !== void 0) return options.fromBlock;
|
|
414
417
|
if (existsSync(cursorPath)) {
|
|
415
418
|
const numInput = JSON.parse(readFileSync(cursorPath, "utf-8")).lastBlock ?? 0;
|
|
@@ -426,7 +429,7 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
|
|
|
426
429
|
};
|
|
427
430
|
const bigintReplacer = (_k, v) => typeof v === "bigint" ? v.toString() : v;
|
|
428
431
|
const fromBlock = readCursor();
|
|
429
|
-
console.error(`Subscribing to "${namespace}" @ ${owner} ` + (fromBlock !== void 0 ? `from block ${fromBlock.toString()}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
|
|
432
|
+
console.error(`Subscribing to "${namespace ?? "*"}" @ ${owner ?? "* (whole app)"} ` + (fromBlock !== void 0 ? `from block ${fromBlock.toString()}` : "(live from current tip)") + ` — Ctrl-C to stop.`);
|
|
430
433
|
const controller = new AbortController();
|
|
431
434
|
process.on("SIGINT", () => {
|
|
432
435
|
controller.abort();
|
|
@@ -434,12 +437,18 @@ program.command("subscribe").description("Watch on-chain pushes to a namespace a
|
|
|
434
437
|
process.on("SIGTERM", () => {
|
|
435
438
|
controller.abort();
|
|
436
439
|
});
|
|
437
|
-
|
|
440
|
+
const stream = options.all ? fangorn.subscribeApp({
|
|
438
441
|
namespace,
|
|
439
442
|
owner,
|
|
440
443
|
fromBlock,
|
|
441
444
|
signal: controller.signal
|
|
442
|
-
})
|
|
445
|
+
}) : fangorn.subscribe({
|
|
446
|
+
namespace: namespace ?? "",
|
|
447
|
+
owner,
|
|
448
|
+
fromBlock,
|
|
449
|
+
signal: controller.signal
|
|
450
|
+
});
|
|
451
|
+
for await (const change of stream) {
|
|
443
452
|
process.stdout.write(JSON.stringify(change, bigintReplacer, options.pretty ? 2 : 0) + "\n");
|
|
444
453
|
writeCursor(change.blockNumber);
|
|
445
454
|
}
|
package/lib/config.d.ts
CHANGED
|
@@ -449,7 +449,7 @@ interface AppConfig {
|
|
|
449
449
|
ipfsGateway: string;
|
|
450
450
|
}
|
|
451
451
|
declare const FangornConfig: {
|
|
452
|
-
dataRegistryContractAddress: "
|
|
452
|
+
dataRegistryContractAddress: "0x9dfa1680e682e0fc79c5904ab453c04c7252572c";
|
|
453
453
|
chain: {
|
|
454
454
|
blockExplorers: {
|
|
455
455
|
readonly default: {
|
package/lib/config.js
CHANGED
|
@@ -41,7 +41,7 @@ function getNetwork(name) {
|
|
|
41
41
|
throw new Error(`Chain ${name} is not supported`);
|
|
42
42
|
}
|
|
43
43
|
const FangornConfig = {
|
|
44
|
-
dataRegistryContractAddress: "
|
|
44
|
+
dataRegistryContractAddress: "0x9dfa1680e682e0fc79c5904ab453c04c7252572c",
|
|
45
45
|
chain: arbitrumSepolia,
|
|
46
46
|
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
47
47
|
caip2: 421614,
|
|
@@ -130,6 +130,12 @@ declare class DataRegistryClient {
|
|
|
130
130
|
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
131
131
|
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
132
132
|
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
133
|
+
*
|
|
134
|
+
* Fetched in windows: RPC providers cap the block span of a single
|
|
135
|
+
* `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
|
|
136
|
+
* couple of thousand blocks with a bare "internal server errror"), so one
|
|
137
|
+
* wide-range call fails outright and takes the whole catch-up with it. Tune
|
|
138
|
+
* the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
|
|
133
139
|
*/
|
|
134
140
|
getStateCommittedLogs(filter: CommitFilter, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
|
|
135
141
|
/**
|
|
@@ -235,16 +235,29 @@ var DataRegistryClient = class {
|
|
|
235
235
|
* Historical `StateCommitted` logs for one slice of this app, oldest →
|
|
236
236
|
* newest — the catch-up path for a subscriber resuming from a saved block
|
|
237
237
|
* cursor. Node-side filtered by indexed topics, so no indexer is involved.
|
|
238
|
+
*
|
|
239
|
+
* Fetched in windows: RPC providers cap the block span of a single
|
|
240
|
+
* `eth_getLogs` (the public Arbitrum Sepolia endpoint rejects anything past a
|
|
241
|
+
* couple of thousand blocks with a bare "internal server errror"), so one
|
|
242
|
+
* wide-range call fails outright and takes the whole catch-up with it. Tune
|
|
243
|
+
* the window with `FANGORN_LOG_WINDOW` — a private RPC will take far more.
|
|
238
244
|
*/
|
|
239
245
|
async getStateCommittedLogs(filter, fromBlock, toBlock) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
const window = BigInt(process.env.FANGORN_LOG_WINDOW ?? 1e3);
|
|
247
|
+
const end = toBlock ?? await this.publicClient.getBlockNumber();
|
|
248
|
+
const logs = [];
|
|
249
|
+
for (let start = fromBlock; start <= end; start += window) {
|
|
250
|
+
const stop = start + window - 1n < end ? start + window - 1n : end;
|
|
251
|
+
logs.push(...await this.publicClient.getContractEvents({
|
|
252
|
+
address: this.contractAddress,
|
|
253
|
+
abi: DATA_REGISTRY_ABI,
|
|
254
|
+
eventName: "StateCommitted",
|
|
255
|
+
args: this.topicsFor(filter),
|
|
256
|
+
fromBlock: start,
|
|
257
|
+
toBlock: stop
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
return logs.map(decodeStateCommitted).filter((log) => matchesFilter(log, filter)).sort((a, b) => a.blockNumber === b.blockNumber ? a.logId.localeCompare(b.logId) : a.blockNumber < b.blockNumber ? -1 : 1);
|
|
248
261
|
}
|
|
249
262
|
/**
|
|
250
263
|
* Live-watch `StateCommitted` for one slice of this app. Returns an
|
package/lib/engine/index.d.ts
CHANGED
|
@@ -79,7 +79,7 @@ declare class MetagraphRegistry {
|
|
|
79
79
|
*/
|
|
80
80
|
declare function rootHexFromCid(commitCid: CID): Hex;
|
|
81
81
|
declare const MAX_NAMESPACE_LENGTH = 256;
|
|
82
|
-
/**
|
|
82
|
+
/** Namespaces must be non-empty strings whose length does not exceed MAX_NAMESPACE_LENGTH */
|
|
83
83
|
declare function assertValidNamespace(namespace: NamespaceID): void;
|
|
84
84
|
/** One line of a commit's diff against its first parent. */
|
|
85
85
|
interface CommitDiff {
|
package/lib/engine/index.js
CHANGED
|
@@ -46,7 +46,7 @@ function rootHexFromCid(commitCid) {
|
|
|
46
46
|
return `0x${Buffer.from(commitCid.multihash.digest).toString("hex")}`;
|
|
47
47
|
}
|
|
48
48
|
const MAX_NAMESPACE_LENGTH = 256;
|
|
49
|
-
/**
|
|
49
|
+
/** Namespaces must be non-empty strings whose length does not exceed MAX_NAMESPACE_LENGTH */
|
|
50
50
|
function assertValidNamespace(namespace) {
|
|
51
51
|
if (typeof namespace !== "string" || namespace.length === 0) throw new Error("namespace must be a non-empty string");
|
|
52
52
|
if (namespace.length > MAX_NAMESPACE_LENGTH) throw new Error(`namespace exceeds the maximum length of ${MAX_NAMESPACE_LENGTH.toString()} characters (got ${namespace.length.toString()}).`);
|
package/lib/fangorn.d.ts
CHANGED
|
@@ -40,12 +40,20 @@ declare class Fangorn {
|
|
|
40
40
|
private _engine;
|
|
41
41
|
private readonly _metagraph;
|
|
42
42
|
private _feed;
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* The namespace cache
|
|
45
|
+
* Insertion order = LRU order; see `readNamespace`.
|
|
46
|
+
*/
|
|
44
47
|
private readonly nsCache;
|
|
45
48
|
private constructor();
|
|
46
49
|
get engine(): FangornEngine;
|
|
47
50
|
get metagraph(): MetagraphRegistry;
|
|
48
51
|
static create(options: FangornCreateOptions): Fangorn;
|
|
52
|
+
/**
|
|
53
|
+
* Resets a namespace's onchain state root to zero.
|
|
54
|
+
* TODO: also unpin all data
|
|
55
|
+
* Use at your own risk.
|
|
56
|
+
*/
|
|
49
57
|
reset(namespace: string): Promise<void>;
|
|
50
58
|
/**
|
|
51
59
|
* Register permissive (no required fields) schemas for every tag/relation a
|
|
@@ -56,9 +64,8 @@ declare class Fangorn {
|
|
|
56
64
|
/** Stage a graph into one commit on top of `base` (engine shapes adapted from CLI shapes). */
|
|
57
65
|
private createCommit;
|
|
58
66
|
/**
|
|
59
|
-
* Allocates a namespace in the publisher's root map.
|
|
60
|
-
* if the namespace is already initialized
|
|
61
|
-
* unconditionally before every publish.
|
|
67
|
+
* Allocates a namespace in the publisher's root map.
|
|
68
|
+
* A no-op (no on-chain tx) if the namespace is already initialized.
|
|
62
69
|
*/
|
|
63
70
|
initRepo(repoName: string): Promise<{
|
|
64
71
|
cid: undefined;
|
package/lib/fangorn.js
CHANGED
|
@@ -11,7 +11,8 @@ import { CID } from "multiformats/cid";
|
|
|
11
11
|
|
|
12
12
|
//#region src/fangorn.ts
|
|
13
13
|
const ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
14
|
-
/** Max namespaces held in
|
|
14
|
+
/** Max namespaces held in TODO
|
|
15
|
+
* `readNamespace`'s tip-keyed cache. */
|
|
15
16
|
const NS_CACHE_MAX = 256;
|
|
16
17
|
/** Build a signer for the access worker's ownership handshake from a wallet. */
|
|
17
18
|
function walletSigner(walletClient) {
|
|
@@ -36,7 +37,10 @@ var Fangorn = class Fangorn {
|
|
|
36
37
|
_engine = null;
|
|
37
38
|
_metagraph = new MetagraphRegistry();
|
|
38
39
|
_feed = null;
|
|
39
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* The namespace cache
|
|
42
|
+
* Insertion order = LRU order; see `readNamespace`.
|
|
43
|
+
*/
|
|
40
44
|
nsCache = /* @__PURE__ */ new Map();
|
|
41
45
|
constructor(ctx) {
|
|
42
46
|
this.ctx = ctx;
|
|
@@ -68,6 +72,11 @@ var Fangorn = class Fangorn {
|
|
|
68
72
|
config: resolvedConfig
|
|
69
73
|
});
|
|
70
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Resets a namespace's onchain state root to zero.
|
|
77
|
+
* TODO: also unpin all data
|
|
78
|
+
* Use at your own risk.
|
|
79
|
+
*/
|
|
71
80
|
async reset(namespace) {
|
|
72
81
|
const registry = this.getDataRegistry();
|
|
73
82
|
const currentRoot = await registry.getNamespaceHead(this.getAddress(), namespace);
|
|
@@ -122,9 +131,8 @@ var Fangorn = class Fangorn {
|
|
|
122
131
|
});
|
|
123
132
|
}
|
|
124
133
|
/**
|
|
125
|
-
* Allocates a namespace in the publisher's root map.
|
|
126
|
-
* if the namespace is already initialized
|
|
127
|
-
* unconditionally before every publish.
|
|
134
|
+
* Allocates a namespace in the publisher's root map.
|
|
135
|
+
* A no-op (no on-chain tx) if the namespace is already initialized.
|
|
128
136
|
*/
|
|
129
137
|
async initRepo(repoName) {
|
|
130
138
|
assertValidNamespace(repoName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fangorn-network/sdk",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.08.12-dev",
|
|
4
4
|
"description": "Git for knowledge graphs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -55,8 +55,6 @@
|
|
|
55
55
|
"node": ">=20.19.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@a2a-js/sdk": "^0.3.10",
|
|
59
|
-
"@aztec/bb.js": "^4.3.0",
|
|
60
58
|
"@clack/prompts": "^1.0.1",
|
|
61
59
|
"@ipld/car": "^5.4.6",
|
|
62
60
|
"@ipld/dag-cbor": "^10.0.1",
|
|
@@ -64,20 +62,11 @@
|
|
|
64
62
|
"@noble/ciphers": "^1.3.0",
|
|
65
63
|
"@noble/curves": "^1.9.7",
|
|
66
64
|
"@noble/hashes": "^2.2.0",
|
|
67
|
-
"@noir-lang/noir_js": "1.0.0-beta.22",
|
|
68
|
-
"@semaphore-protocol/group": "^4.14.2",
|
|
69
|
-
"@semaphore-protocol/identity": "^4.14.2",
|
|
70
|
-
"@semaphore-protocol/proof": "^4.14.2",
|
|
71
|
-
"agent0-sdk": "^1.5.3",
|
|
72
65
|
"commander": "^14.0.3",
|
|
73
66
|
"dotenv": "^17.2.3",
|
|
74
|
-
"ethers": "^6.16.0",
|
|
75
67
|
"multiformats": "^14.0.0",
|
|
76
68
|
"pinata": "^2.5.2",
|
|
77
|
-
"poseidon-lite": "^0.3.0",
|
|
78
69
|
"solc": "^0.8.28",
|
|
79
|
-
"stream-json": "^3.4.0",
|
|
80
|
-
"uint8arrays": "^6.1.1",
|
|
81
70
|
"viem": "^2.47.1"
|
|
82
71
|
},
|
|
83
72
|
"overrides": {
|