@fangorn-network/sdk 2026.8.12-dev → 2026.9.22-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.
Files changed (40) hide show
  1. package/README.md +175 -62
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +348 -17
  4. package/lib/cli/index.d.ts +13 -13
  5. package/lib/config.d.ts +28 -352
  6. package/lib/config.js +11 -20
  7. package/lib/contracts/app-registry/abi.d.ts +509 -0
  8. package/lib/contracts/app-registry/abi.js +575 -0
  9. package/lib/contracts/app-registry/index.d.ts +120 -0
  10. package/lib/contracts/app-registry/index.js +266 -0
  11. package/lib/contracts/data-registry/abi.d.ts +124 -125
  12. package/lib/contracts/data-registry/abi.js +145 -142
  13. package/lib/contracts/data-registry/index.d.ts +20 -27
  14. package/lib/contracts/data-registry/index.js +32 -78
  15. package/lib/contracts/index.d.ts +8 -3
  16. package/lib/contracts/index.js +8 -3
  17. package/lib/contracts/logs.d.ts +18 -0
  18. package/lib/contracts/logs.js +25 -0
  19. package/lib/contracts/settlement-registry/abi.d.ts +430 -11
  20. package/lib/contracts/settlement-registry/abi.js +528 -41
  21. package/lib/contracts/settlement-registry/index.d.ts +148 -10
  22. package/lib/contracts/settlement-registry/index.js +233 -9
  23. package/lib/contracts/subscription-registry/abi.d.ts +179 -0
  24. package/lib/contracts/subscription-registry/abi.js +195 -0
  25. package/lib/contracts/subscription-registry/index.d.ts +59 -0
  26. package/lib/contracts/subscription-registry/index.js +116 -0
  27. package/lib/contracts/types.d.ts +8 -0
  28. package/lib/contracts/types.js +10 -0
  29. package/lib/contracts/write.d.ts +27 -0
  30. package/lib/contracts/write.js +55 -0
  31. package/lib/crypto/encryption.js +4 -4
  32. package/lib/engine/index.d.ts +14 -12
  33. package/lib/engine/index.js +13 -7
  34. package/lib/fangorn.d.ts +71 -6
  35. package/lib/fangorn.js +86 -7
  36. package/lib/index.d.ts +9 -4
  37. package/lib/index.js +9 -4
  38. package/lib/test/testbed.js +9 -3
  39. package/lib/types/index.d.ts +6 -0
  40. package/package.json +73 -85
package/lib/fangorn.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { AppConfig } from "./config.js";
2
2
  import { DataRegistryClient, PreparedTx } from "./contracts/data-registry/index.js";
3
+ import { AppRegistryClient } from "./contracts/app-registry/index.js";
4
+ import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
5
+ import { SubscriptionRegistryClient } from "./contracts/subscription-registry/index.js";
3
6
  import "./contracts/index.js";
4
7
  import { MetadataStorage } from "./providers/storage/types.js";
5
8
  import { CommitDiff, FangornEngine, MetagraphRegistry, NamespaceContents, NamespaceDiff } from "./engine/index.js";
@@ -8,16 +11,12 @@ import { AppFeed } from "./feed.js";
8
11
  import { Hex, WalletClient } from "viem";
9
12
 
10
13
  //#region src/fangorn.d.ts
11
- /** One namespace-scoped update surfaced by `subscribe`. */
12
14
  interface NamespaceChange extends NamespaceDiff {
13
15
  namespace: string;
14
16
  owner: Hex;
15
- /** The commit CID (string) this update settled to — the new on-chain tip. */
16
17
  commitCid: string;
17
- /** Raw on-chain roots this delta spans (`oldRoot` → `newRoot`). */
18
18
  oldRoot: Hex;
19
19
  newRoot: Hex;
20
- /** Block the `StateCommitted` event landed in — persist as the resume cursor. */
21
20
  blockNumber: bigint;
22
21
  }
23
22
  interface SubscribeOptions {
@@ -35,6 +34,24 @@ interface SubscribeOptions {
35
34
  /** Abort to stop the subscription and release the watch. */
36
35
  signal?: AbortSignal;
37
36
  }
37
+ /** The A2A extension a Fangorn app's agent card carries: it names the app the card speaks for. */
38
+ declare const FANGORN_APP_EXTENSION = "https://fangorn.network/a2a/app/v1";
39
+ /**
40
+ * The part of an A2A agent card `discoverApp` reads. A card's other fields
41
+ * (skills, endpoints and so on) pass through untouched.
42
+ */
43
+ interface AgentCard {
44
+ name?: string;
45
+ description?: string;
46
+ url?: string;
47
+ capabilities?: {
48
+ extensions?: {
49
+ uri: string;
50
+ params?: Record<string, unknown>;
51
+ }[];
52
+ };
53
+ [key: string]: unknown;
54
+ }
38
55
  declare class Fangorn {
39
56
  private readonly ctx;
40
57
  private _engine;
@@ -42,12 +59,18 @@ declare class Fangorn {
42
59
  private _feed;
43
60
  /**
44
61
  * The namespace cache
45
- * Insertion order = LRU order; see `readNamespace`.
62
+ * Insertion order = LRU order
46
63
  */
47
64
  private readonly nsCache;
48
65
  private constructor();
49
66
  get engine(): FangornEngine;
50
67
  get metagraph(): MetagraphRegistry;
68
+ /**
69
+ * Static creation of a new Fangorn client
70
+ *
71
+ * @param options
72
+ * @returns the client
73
+ */
51
74
  static create(options: FangornCreateOptions): Fangorn;
52
75
  /**
53
76
  * Resets a namespace's onchain state root to zero.
@@ -56,6 +79,13 @@ declare class Fangorn {
56
79
  */
57
80
  reset(namespace: string): Promise<void>;
58
81
  /**
82
+ * TODO: this isn't really needed here, it's cosmetic
83
+ * instead, what if we moved this to a new paradigm where...
84
+ *
85
+ * each app registers as an ERC-8004 agent with the validation registry
86
+ * pointing to these rules essentially?
87
+ *
88
+ *
59
89
  * Register permissive (no required fields) schemas for every tag/relation a
60
90
  * staged graph uses, unless the caller has already registered stricter rules
61
91
  * via `this.metagraph` directly — schema ids are free-form tags by default.
@@ -229,6 +259,23 @@ declare class Fangorn {
229
259
  root: Hex;
230
260
  blockNumber: bigint;
231
261
  }[]>;
262
+ /**
263
+ * Resolve an app from its agent card URL alone, and prove the card speaks for it.
264
+ *
265
+ * The card names its app in the `FANGORN_APP_EXTENSION` A2A extension, but
266
+ * anyone can serve a card that names any app. So the card is trusted only if
267
+ * the app's on-chain `agent_uri`, which only the app owner can set, points
268
+ * back at this exact URL. The comparison is exact string equality, so a
269
+ * trailing slash or a different host counts as a different card.
270
+ *
271
+ * Doesn't touch this client's app. Pass `appId` to `setAppId` to read under it.
272
+ */
273
+ discoverApp(cardUrl: string): Promise<{
274
+ card: AgentCard;
275
+ appId: Hex;
276
+ fromBlock: bigint;
277
+ namespaces: string[];
278
+ }>;
232
279
  /**
233
280
  * The app's commit stream as ONE shared, ref-counted subscription (see
234
281
  * `AppFeed`). Prefer this over `subscribeApp` anywhere more than one consumer
@@ -283,6 +330,24 @@ declare class Fangorn {
283
330
  private toNamespaceChange;
284
331
  getConfig(): AppConfig;
285
332
  getDataRegistry(): DataRegistryClient;
333
+ /**
334
+ * Apps, their publisher terms, and per-app membership.
335
+ *
336
+ * `commitStateRoot` cross-calls this contract, so joining the app here is a
337
+ * precondition for publishing under it — `registerForApp()` before
338
+ * `commit()`, or the commit reverts `NotRegisteredForApp`.
339
+ */
340
+ getAppRegistry(): AppRegistryClient;
341
+ /**
342
+ * The publisher-side storage paywall. Per-wallet, not per-app: one
343
+ * subscription covers everything this publisher writes, under every app.
344
+ */
345
+ getSubscriptionRegistry(): SubscriptionRegistryClient;
346
+ /**
347
+ * The consumer-side pay-then-read rail. Resources are keyed by owner+uid, so
348
+ * this client is app-agnostic too.
349
+ */
350
+ getSettlementRegistry(): SettlementRegistryClient;
286
351
  /** The app (global namespace) this client publishes and reads under. */
287
352
  getAppId(): Hex;
288
353
  /**
@@ -307,4 +372,4 @@ declare class Fangorn {
307
372
  getAddress(): Hex;
308
373
  }
309
374
  //#endregion
310
- export { Fangorn, NamespaceChange, SubscribeOptions };
375
+ export { AgentCard, FANGORN_APP_EXTENSION, Fangorn, NamespaceChange, SubscribeOptions };
package/lib/fangorn.js CHANGED
@@ -2,7 +2,10 @@ import { DEFAULT_APP, FangornConfig, toAppId } from "./config.js";
2
2
  import { SignedUrlBackend } from "./providers/storage/signed-url.js";
3
3
  import { PinataBackend } from "./providers/storage/pinata.js";
4
4
  import { FangornEngine, MetagraphRegistry, assertValidNamespace, rootHexFromCid } from "./engine/index.js";
5
+ import { AppRegistryClient } from "./contracts/app-registry/index.js";
5
6
  import { DataRegistryClient, subspaceId } from "./contracts/data-registry/index.js";
7
+ import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
8
+ import { SubscriptionRegistryClient } from "./contracts/subscription-registry/index.js";
6
9
  import "./contracts/index.js";
7
10
  import { AppFeed } from "./feed.js";
8
11
  import { createPublicClient, createWalletClient, http } from "viem";
@@ -11,10 +14,7 @@ import { CID } from "multiformats/cid";
11
14
 
12
15
  //#region src/fangorn.ts
13
16
  const ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
14
- /** Max namespaces held in TODO
15
- * `readNamespace`'s tip-keyed cache. */
16
17
  const NS_CACHE_MAX = 256;
17
- /** Build a signer for the access worker's ownership handshake from a wallet. */
18
18
  function walletSigner(walletClient) {
19
19
  const account = walletClient.account;
20
20
  if (!account) throw new Error("Signed-url storage requires a wallet account to sign the access worker's challenge.");
@@ -32,6 +32,8 @@ function resolveStorage(storage, walletClient, config) {
32
32
  if ("signedUrl" in storage) return new SignedUrlBackend(storage.signedUrl.workerUrl, walletSigner(walletClient), storage.signedUrl.gateway ?? config.ipfsGateway);
33
33
  throw new Error(`Invalid storage config: must be { pinata: … } or { signedUrl: … }, got ${JSON.stringify(storage)}`);
34
34
  }
35
+ /** The A2A extension a Fangorn app's agent card carries: it names the app the card speaks for. */
36
+ const FANGORN_APP_EXTENSION = "https://fangorn.network/a2a/app/v1";
35
37
  var Fangorn = class Fangorn {
36
38
  ctx;
37
39
  _engine = null;
@@ -39,7 +41,7 @@ var Fangorn = class Fangorn {
39
41
  _feed = null;
40
42
  /**
41
43
  * The namespace cache
42
- * Insertion order = LRU order; see `readNamespace`.
44
+ * Insertion order = LRU order
43
45
  */
44
46
  nsCache = /* @__PURE__ */ new Map();
45
47
  constructor(ctx) {
@@ -53,6 +55,12 @@ var Fangorn = class Fangorn {
53
55
  get metagraph() {
54
56
  return this._metagraph;
55
57
  }
58
+ /**
59
+ * Static creation of a new Fangorn client
60
+ *
61
+ * @param options
62
+ * @returns the client
63
+ */
56
64
  static create(options) {
57
65
  if (!options.privateKey && !options.walletClient) throw new Error("Either privateKey or walletClient must be provided");
58
66
  const resolvedConfig = options.config ?? FangornConfig;
@@ -64,11 +72,15 @@ var Fangorn = class Fangorn {
64
72
  const metadataStorage = resolveStorage(options.storage, walletClient, resolvedConfig);
65
73
  const domain = options.domain ?? new URL(resolvedConfig.rpcUrl).hostname;
66
74
  const publicClient = createPublicClient({ transport: http(resolvedConfig.rpcUrl) });
75
+ const appId = toAppId(options.appId ?? DEFAULT_APP);
67
76
  return new Fangorn({
68
77
  walletClient,
69
78
  metadataStorage,
70
79
  domain,
71
- dataRegistry: new DataRegistryClient(resolvedConfig.dataRegistryContractAddress, toAppId(options.appId ?? DEFAULT_APP), publicClient, walletClient),
80
+ dataRegistry: new DataRegistryClient(resolvedConfig.dataRegistryContractAddress, appId, publicClient, walletClient),
81
+ appRegistry: new AppRegistryClient(resolvedConfig.appRegistryContractAddress, appId, publicClient, walletClient),
82
+ subscriptionRegistry: new SubscriptionRegistryClient(resolvedConfig.subscriptionRegistryContractAddress, publicClient, walletClient),
83
+ settlementRegistry: new SettlementRegistryClient(resolvedConfig.settlementRegistryContractAddress, publicClient, walletClient),
72
84
  config: resolvedConfig
73
85
  });
74
86
  }
@@ -83,6 +95,13 @@ var Fangorn = class Fangorn {
83
95
  await registry.commitStateRoot(namespace, currentRoot, ZERO_BYTES32);
84
96
  }
85
97
  /**
98
+ * TODO: this isn't really needed here, it's cosmetic
99
+ * instead, what if we moved this to a new paradigm where...
100
+ *
101
+ * each app registers as an ERC-8004 agent with the validation registry
102
+ * pointing to these rules essentially?
103
+ *
104
+ *
86
105
  * Register permissive (no required fields) schemas for every tag/relation a
87
106
  * staged graph uses, unless the caller has already registered stricter rules
88
107
  * via `this.metagraph` directly — schema ids are free-form tags by default.
@@ -353,6 +372,40 @@ var Fangorn = class Fangorn {
353
372
  return [...latest.values()];
354
373
  }
355
374
  /**
375
+ * Resolve an app from its agent card URL alone, and prove the card speaks for it.
376
+ *
377
+ * The card names its app in the `FANGORN_APP_EXTENSION` A2A extension, but
378
+ * anyone can serve a card that names any app. So the card is trusted only if
379
+ * the app's on-chain `agent_uri`, which only the app owner can set, points
380
+ * back at this exact URL. The comparison is exact string equality, so a
381
+ * trailing slash or a different host counts as a different card.
382
+ *
383
+ * Doesn't touch this client's app. Pass `appId` to `setAppId` to read under it.
384
+ */
385
+ async discoverApp(cardUrl) {
386
+ const res = await fetch(cardUrl, { signal: AbortSignal.timeout(1e4) });
387
+ if (!res.ok) throw new Error(`agent card ${cardUrl}: HTTP ${String(res.status)}`);
388
+ const card = await res.json();
389
+ const ext = card.capabilities?.extensions?.find((e) => e.uri === FANGORN_APP_EXTENSION);
390
+ if (!ext) throw new Error(`agent card ${cardUrl} has no ${FANGORN_APP_EXTENSION} extension`);
391
+ const p = ext.params ?? {};
392
+ if (typeof p.appId !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(p.appId)) throw new Error(`agent card ${cardUrl}: appId is not a 32-byte hex string`);
393
+ if (typeof p.fromBlock !== "string" || !/^\d+$/.test(p.fromBlock)) throw new Error(`agent card ${cardUrl}: fromBlock is not a decimal block number`);
394
+ const namespaces = p.namespaces ?? [];
395
+ if (!Array.isArray(namespaces) || !namespaces.every((n) => typeof n === "string")) throw new Error(`agent card ${cardUrl}: namespaces is not a list of strings`);
396
+ const apps = this.getAppRegistry();
397
+ if (p.chainId !== this.ctx.config.caip2 || typeof p.appRegistry !== "string" || p.appRegistry.toLowerCase() !== apps.getAddress().toLowerCase()) throw new Error(`agent card ${cardUrl} is for chain ${String(p.chainId)} / AppRegistry ${String(p.appRegistry)}, not this client's`);
398
+ const appId = p.appId;
399
+ const bound = await apps.appAgentUri(appId);
400
+ if (bound !== cardUrl) throw new Error(`agent card ${cardUrl} is not bound to app ${appId}: its on-chain agent_uri is ${bound ? `"${bound}"` : "unset"}`);
401
+ return {
402
+ card,
403
+ appId,
404
+ fromBlock: BigInt(p.fromBlock),
405
+ namespaces
406
+ };
407
+ }
408
+ /**
356
409
  * The app's commit stream as ONE shared, ref-counted subscription (see
357
410
  * `AppFeed`). Prefer this over `subscribeApp` anywhere more than one consumer
358
411
  * wants the same feed — a server fanning out to connections, say.
@@ -494,6 +547,30 @@ var Fangorn = class Fangorn {
494
547
  getDataRegistry() {
495
548
  return this.ctx.dataRegistry;
496
549
  }
550
+ /**
551
+ * Apps, their publisher terms, and per-app membership.
552
+ *
553
+ * `commitStateRoot` cross-calls this contract, so joining the app here is a
554
+ * precondition for publishing under it — `registerForApp()` before
555
+ * `commit()`, or the commit reverts `NotRegisteredForApp`.
556
+ */
557
+ getAppRegistry() {
558
+ return this.ctx.appRegistry;
559
+ }
560
+ /**
561
+ * The publisher-side storage paywall. Per-wallet, not per-app: one
562
+ * subscription covers everything this publisher writes, under every app.
563
+ */
564
+ getSubscriptionRegistry() {
565
+ return this.ctx.subscriptionRegistry;
566
+ }
567
+ /**
568
+ * The consumer-side pay-then-read rail. Resources are keyed by owner+uid, so
569
+ * this client is app-agnostic too.
570
+ */
571
+ getSettlementRegistry() {
572
+ return this.ctx.settlementRegistry;
573
+ }
497
574
  /** The app (global namespace) this client publishes and reads under. */
498
575
  getAppId() {
499
576
  return this.ctx.dataRegistry.getAppId();
@@ -509,7 +586,9 @@ var Fangorn = class Fangorn {
509
586
  * from `subscribe`/`subscribeApp` keep their original filter until aborted.
510
587
  */
511
588
  setAppId(nameOrId) {
512
- this.ctx.dataRegistry.setAppId(toAppId(nameOrId));
589
+ const appId = toAppId(nameOrId);
590
+ this.ctx.dataRegistry.setAppId(appId);
591
+ this.ctx.appRegistry.setAppId(appId);
513
592
  this.nsCache.clear();
514
593
  this._feed = null;
515
594
  }
@@ -537,4 +616,4 @@ var Fangorn = class Fangorn {
537
616
  };
538
617
 
539
618
  //#endregion
540
- export { Fangorn };
619
+ export { FANGORN_APP_EXTENSION, Fangorn };
package/lib/index.d.ts CHANGED
@@ -1,15 +1,20 @@
1
1
  import { AppConfig, DEFAULT_APP, FangornConfig, SupportedNetworks, appId, toAppId } from "./config.js";
2
+ import { APP_REGISTRY_ABI } from "./contracts/app-registry/abi.js";
3
+ import { PublisherStatus } from "./contracts/types.js";
4
+ import { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId } from "./contracts/data-registry/index.js";
5
+ import { AppAgentLog, AppJoinInfo, AppRegistryClient, needsReacceptance } from "./contracts/app-registry/index.js";
2
6
  import { DATA_REGISTRY_ABI } from "./contracts/data-registry/abi.js";
3
- import { CommitFilter, DataRegistryClient, PreparedTx, PublisherStatus, StateCommittedLog, namespaceKey, subspaceId } from "./contracts/data-registry/index.js";
4
- import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
7
+ import { Resource, SemaphoreProof, SettlementRegistryClient, TransferAuthorization, packResourceUri, resourceIdOf } from "./contracts/settlement-registry/index.js";
5
8
  import { SETTLEMENT_REGISTRY_ABI } from "./contracts/settlement-registry/abi.js";
9
+ import { SubscriptionAccess, SubscriptionRegistryClient } from "./contracts/subscription-registry/index.js";
10
+ import { SUBSCRIPTION_REGISTRY_ABI } from "./contracts/subscription-registry/abi.js";
6
11
  import "./contracts/index.js";
7
12
  import { AccessRequest, AccessSigner, DecryptHandleParams, EncryptAndUploadParams, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, X25519_PUBKEY_LENGTH, accessMessageHash, buildAccessRequest, decryptHandle, encryptAndUpload, seal, sealSelf, sha256Hex, unseal, unsealSelf } from "./crypto/encryption.js";
8
13
  import { FangornContext, FangornCreateOptions, StorageConfig } from "./types/index.js";
9
14
  import { AppFeed } from "./feed.js";
10
- import { Fangorn, NamespaceChange, SubscribeOptions } from "./fangorn.js";
15
+ import { AgentCard, FANGORN_APP_EXTENSION, Fangorn, NamespaceChange, SubscribeOptions } from "./fangorn.js";
11
16
  import { AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, Edge, FileFacade, ProcessorResult, Vertex, buildAssetGraph, buildMarkdownGraph, extractMarkdownLinks } from "./harness/index.js";
12
17
  import { PinataBackend } from "./providers/storage/pinata.js";
13
18
  import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend, SignedUrlSigner } from "./providers/storage/signed-url.js";
14
19
  import { MAX_UPLOAD_ATTEMPTS, deserialize, fetchRawByCid, isTransientUpload, retrieveByCid, serialize, withUploadRetry } from "./providers/storage/utils.js";
15
- export { AccessRequest, AccessSigner, AppConfig, AppFeed, AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, CommitFilter, DATA_REGISTRY_ABI, DEFAULT_APP, DEFAULT_SIGNED_URL_WORKER, DataRegistryClient, DecryptHandleParams, Edge, EncryptAndUploadParams, Fangorn, FangornConfig, FangornContext, FangornCreateOptions, FileFacade, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, MAX_UPLOAD_ATTEMPTS, NamespaceChange, PinataBackend, PreparedTx, ProcessorResult, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, SignedUrlBackend, SignedUrlSigner, StateCommittedLog, StorageConfig, SubscribeOptions, SupportedNetworks, Vertex, X25519_PUBKEY_LENGTH, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, namespaceKey, retrieveByCid, seal, sealSelf, serialize, sha256Hex, subspaceId, toAppId, unseal, unsealSelf, withUploadRetry };
20
+ export { APP_REGISTRY_ABI, AccessRequest, AccessSigner, AgentCard, AppAgentLog, AppConfig, AppFeed, AppJoinInfo, AppRegistryClient, AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, CommitFilter, DATA_REGISTRY_ABI, DEFAULT_APP, DEFAULT_SIGNED_URL_WORKER, DataRegistryClient, DecryptHandleParams, Edge, EncryptAndUploadParams, FANGORN_APP_EXTENSION, Fangorn, FangornConfig, FangornContext, FangornCreateOptions, FileFacade, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, MAX_UPLOAD_ATTEMPTS, NamespaceChange, PinataBackend, PreparedTx, ProcessorResult, PublisherStatus, Resource, SETTLEMENT_REGISTRY_ABI, SUBSCRIPTION_REGISTRY_ABI, SemaphoreProof, SettlementRegistryClient, SignedUrlBackend, SignedUrlSigner, StateCommittedLog, StorageConfig, SubscribeOptions, SubscriptionAccess, SubscriptionRegistryClient, SupportedNetworks, TransferAuthorization, Vertex, X25519_PUBKEY_LENGTH, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, namespaceKey, needsReacceptance, packResourceUri, resourceIdOf, retrieveByCid, seal, sealSelf, serialize, sha256Hex, subspaceId, toAppId, unseal, unsealSelf, withUploadRetry };
package/lib/index.js CHANGED
@@ -2,14 +2,19 @@ import { DEFAULT_APP, FangornConfig, SupportedNetworks, appId, toAppId } from ".
2
2
  import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend } from "./providers/storage/signed-url.js";
3
3
  import { MAX_UPLOAD_ATTEMPTS, deserialize, fetchRawByCid, isTransientUpload, retrieveByCid, serialize, withUploadRetry } from "./providers/storage/utils.js";
4
4
  import { PinataBackend } from "./providers/storage/pinata.js";
5
+ import { APP_REGISTRY_ABI } from "./contracts/app-registry/abi.js";
6
+ import { PublisherStatus } from "./contracts/types.js";
7
+ import { AppRegistryClient, needsReacceptance } from "./contracts/app-registry/index.js";
5
8
  import { DATA_REGISTRY_ABI } from "./contracts/data-registry/abi.js";
6
- import { DataRegistryClient, PublisherStatus, namespaceKey, subspaceId } from "./contracts/data-registry/index.js";
9
+ import { DataRegistryClient, namespaceKey, subspaceId } from "./contracts/data-registry/index.js";
7
10
  import { SETTLEMENT_REGISTRY_ABI } from "./contracts/settlement-registry/abi.js";
8
- import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
11
+ import { SettlementRegistryClient, packResourceUri, resourceIdOf } from "./contracts/settlement-registry/index.js";
12
+ import { SUBSCRIPTION_REGISTRY_ABI } from "./contracts/subscription-registry/abi.js";
13
+ import { SubscriptionRegistryClient } from "./contracts/subscription-registry/index.js";
9
14
  import "./contracts/index.js";
10
15
  import { AppFeed } from "./feed.js";
11
- import { Fangorn } from "./fangorn.js";
16
+ import { FANGORN_APP_EXTENSION, Fangorn } from "./fangorn.js";
12
17
  import { buildAssetGraph, buildMarkdownGraph, extractMarkdownLinks } from "./harness/index.js";
13
18
  import { GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, X25519_PUBKEY_LENGTH, accessMessageHash, buildAccessRequest, decryptHandle, encryptAndUpload, seal, sealSelf, sha256Hex, unseal, unsealSelf } from "./crypto/encryption.js";
14
19
 
15
- export { AppFeed, DATA_REGISTRY_ABI, DEFAULT_APP, DEFAULT_SIGNED_URL_WORKER, DataRegistryClient, Fangorn, FangornConfig, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, MAX_UPLOAD_ATTEMPTS, PinataBackend, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, SignedUrlBackend, SupportedNetworks, X25519_PUBKEY_LENGTH, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, namespaceKey, retrieveByCid, seal, sealSelf, serialize, sha256Hex, subspaceId, toAppId, unseal, unsealSelf, withUploadRetry };
20
+ export { APP_REGISTRY_ABI, AppFeed, AppRegistryClient, DATA_REGISTRY_ABI, DEFAULT_APP, DEFAULT_SIGNED_URL_WORKER, DataRegistryClient, FANGORN_APP_EXTENSION, Fangorn, FangornConfig, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, MAX_UPLOAD_ATTEMPTS, PinataBackend, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SUBSCRIPTION_REGISTRY_ABI, SettlementRegistryClient, SignedUrlBackend, SubscriptionRegistryClient, SupportedNetworks, X25519_PUBKEY_LENGTH, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, namespaceKey, needsReacceptance, packResourceUri, resourceIdOf, retrieveByCid, seal, sealSelf, serialize, sha256Hex, subspaceId, toAppId, unseal, unsealSelf, withUploadRetry };
@@ -2,6 +2,7 @@ import { FangornConfig } from "../config.js";
2
2
  import { Fangorn } from "../fangorn.js";
3
3
 
4
4
  //#region src/test/testbed.ts
5
+ const TESTBED_APP_TERMS = "0x0000000000000000000000000000000000000000000000000000000000000002";
5
6
  var TestBed = class TestBed {
6
7
  constructor(f_list) {
7
8
  this.f_list = f_list;
@@ -40,10 +41,15 @@ var TestBed = class TestBed {
40
41
  * else already owns it: apps are shared, not per-test.
41
42
  */
42
43
  async registerApp(index) {
43
- const registry = this.getFangorn(index).getDataRegistry();
44
+ const registry = this.getFangorn(index).getAppRegistry();
44
45
  if (await registry.getAppOwner() === "0x0000000000000000000000000000000000000000") {
45
46
  console.log(`Registering app ${registry.getAppId()} on-chain...`);
46
- await registry.registerApp();
47
+ await registry.registerApp(TESTBED_APP_TERMS, "https://example.test/terms", 0n);
48
+ }
49
+ const self = this.getFangorn(index).getAddress();
50
+ if (!await registry.isRegisteredForApp(self)) {
51
+ console.log(`Joining app ${registry.getAppId()} as ${self}...`);
52
+ await registry.registerForApp();
47
53
  }
48
54
  }
49
55
  async register(index) {
@@ -70,7 +76,7 @@ var TestBed = class TestBed {
70
76
  }
71
77
  /** Owner of the configured app namespace, or the zero address if unclaimed. */
72
78
  async appOwner(index) {
73
- return this.getFangorn(index).getDataRegistry().getAppOwner();
79
+ return this.getFangorn(index).getAppRegistry().getAppOwner();
74
80
  }
75
81
  /** The raw on-chain head of one namespace — the slot the CAS actually guards. */
76
82
  async head(index, namespace) {
@@ -1,5 +1,8 @@
1
1
  import { AppConfig } from "../config.js";
2
2
  import { DataRegistryClient } from "../contracts/data-registry/index.js";
3
+ import { AppRegistryClient } from "../contracts/app-registry/index.js";
4
+ import { SettlementRegistryClient } from "../contracts/settlement-registry/index.js";
5
+ import { SubscriptionRegistryClient } from "../contracts/subscription-registry/index.js";
3
6
  import { MetadataStorage } from "../providers/storage/types.js";
4
7
  import { Hex, WalletClient } from "viem";
5
8
 
@@ -10,6 +13,9 @@ interface FangornContext {
10
13
  metadataStorage: MetadataStorage | undefined;
11
14
  domain: string;
12
15
  dataRegistry: DataRegistryClient;
16
+ appRegistry: AppRegistryClient;
17
+ subscriptionRegistry: SubscriptionRegistryClient;
18
+ settlementRegistry: SettlementRegistryClient;
13
19
  }
14
20
  type StorageConfig = {
15
21
  pinata: {
package/package.json CHANGED
@@ -1,86 +1,74 @@
1
1
  {
2
- "name": "@fangorn-network/sdk",
3
- "version": "2026.08.12-dev",
4
- "description": "Git for knowledge graphs",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/fangorn-network/fangorn.git"
8
- },
9
- "bin": {
10
- "fangorn": "lib/cli/cli.js"
11
- },
12
- "license": "MIT",
13
- "type": "module",
14
- "main": "lib/index.js",
15
- "files": [
16
- "lib/"
17
- ],
18
- "scripts": {
19
- "build": "tsdown",
20
- "format": "prettier . --write",
21
- "lint": "eslint . --max-warnings 0",
22
- "prepare": "husky",
23
- "test": "dotenvx run -f .env -- vitest run",
24
- "test:e2e": "dotenvx run -f .env -- vitest run --config vitest.e2e.config.ts",
25
- "tsc": "tsc",
26
- "deploy": "dotenvx run -f .env -- tsx deploy.ts",
27
- "setup:embeddings": "dotenvx run -f .env -- tsx src/test/setup-embeddings-testdata.ts",
28
- "cleanup:embeddings": "dotenvx run -f .env -- tsx src/test/cleanup-embeddings-testdata.ts",
29
- "prepare:cli": "npm run build",
30
- "fangorn": "dotenvx run -f .env -- node dist/src/cli/cli.js"
31
- },
32
- "lint-staged": {
33
- "*": "prettier --ignore-unknown --write"
34
- },
35
- "devDependencies": {
36
- "@dotenvx/dotenvx": "^1.51.1",
37
- "@eslint/js": "9.39.1",
38
- "@noble/ciphers": "^1.3.0",
39
- "@noble/curves": "^1.2.0",
40
- "@types/node": "24.10.1",
41
- "@vitest/coverage-v8": "4.0.15",
42
- "@vitest/eslint-plugin": "1.5.1",
43
- "eslint": "9.39.1",
44
- "husky": "9.1.7",
45
- "lint-staged": "16.2.7",
46
- "prettier": "3.7.3",
47
- "tsdown": "0.16.8",
48
- "tsx": "^4.21.0",
49
- "typescript": "5.8.3",
50
- "typescript-eslint": "8.48.1",
51
- "vitest": "^4.0.18"
52
- },
53
- "packageManager": "pnpm@10.4.0",
54
- "engines": {
55
- "node": ">=20.19.0"
56
- },
57
- "dependencies": {
58
- "@clack/prompts": "^1.0.1",
59
- "@ipld/car": "^5.4.6",
60
- "@ipld/dag-cbor": "^10.0.1",
61
- "@ipld/unixfs": "^3.0.0",
62
- "@noble/ciphers": "^1.3.0",
63
- "@noble/curves": "^1.9.7",
64
- "@noble/hashes": "^2.2.0",
65
- "commander": "^14.0.3",
66
- "dotenv": "^17.2.3",
67
- "multiformats": "^14.0.0",
68
- "pinata": "^2.5.2",
69
- "solc": "^0.8.28",
70
- "viem": "^2.47.1"
71
- },
72
- "overrides": {
73
- "viem": "$viem"
74
- },
75
- "pnpm": {
76
- "overrides": {
77
- "write-file-atomic": "7.0.0"
78
- },
79
- "peerDependencyRules": {
80
- "allowedVersions": {
81
- "viem": ">=2.38.3",
82
- "ethers": ">=5.7.2"
83
- }
84
- }
85
- }
86
- }
2
+ "name": "@fangorn-network/sdk",
3
+ "version": "2026.09.22-dev",
4
+ "description": "Git for knowledge graphs",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/fangorn-network/fangorn.git"
8
+ },
9
+ "bin": {
10
+ "fangorn": "lib/cli/cli.js"
11
+ },
12
+ "license": "MIT",
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "files": [
16
+ "lib/"
17
+ ],
18
+ "lint-staged": {
19
+ "*": "prettier --ignore-unknown --write"
20
+ },
21
+ "devDependencies": {
22
+ "@dotenvx/dotenvx": "^1.51.1",
23
+ "@eslint/js": "9.39.1",
24
+ "@noble/ciphers": "^1.3.0",
25
+ "@noble/curves": "^1.2.0",
26
+ "@types/node": "24.10.1",
27
+ "@vitest/coverage-v8": "4.0.15",
28
+ "@vitest/eslint-plugin": "1.5.1",
29
+ "eslint": "9.39.1",
30
+ "husky": "9.1.7",
31
+ "lint-staged": "16.2.7",
32
+ "prettier": "3.7.3",
33
+ "tsdown": "0.16.8",
34
+ "tsx": "^4.21.0",
35
+ "typescript": "5.8.3",
36
+ "typescript-eslint": "8.48.1",
37
+ "vitest": "^4.0.18"
38
+ },
39
+ "engines": {
40
+ "node": ">=20.19.0"
41
+ },
42
+ "dependencies": {
43
+ "@clack/prompts": "^1.0.1",
44
+ "@ipld/car": "^5.4.6",
45
+ "@ipld/dag-cbor": "^10.0.1",
46
+ "@ipld/unixfs": "^3.0.0",
47
+ "@noble/ciphers": "^1.3.0",
48
+ "@noble/curves": "^1.9.7",
49
+ "@noble/hashes": "^2.2.0",
50
+ "agent0-sdk": "^1.7.1",
51
+ "commander": "^14.0.3",
52
+ "dotenv": "^17.2.3",
53
+ "multiformats": "^14.0.0",
54
+ "pinata": "^2.5.2",
55
+ "solc": "^0.8.28",
56
+ "viem": "^2.47.1"
57
+ },
58
+ "overrides": {
59
+ "viem": "$viem"
60
+ },
61
+ "scripts": {
62
+ "build": "tsdown",
63
+ "format": "prettier . --write",
64
+ "lint": "eslint . --max-warnings 0",
65
+ "test": "dotenvx run -f .env -- vitest run",
66
+ "test:e2e": "dotenvx run -f .env -- vitest run --config vitest.e2e.config.ts",
67
+ "tsc": "tsc",
68
+ "deploy": "dotenvx run -f .env -- tsx deploy.ts",
69
+ "setup:embeddings": "dotenvx run -f .env -- tsx src/test/setup-embeddings-testdata.ts",
70
+ "cleanup:embeddings": "dotenvx run -f .env -- tsx src/test/cleanup-embeddings-testdata.ts",
71
+ "prepare:cli": "npm run build",
72
+ "fangorn": "dotenvx run -f .env -- node dist/src/cli/cli.js"
73
+ }
74
+ }