@fangorn-network/sdk 2026.8.18-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.
@@ -0,0 +1,25 @@
1
+ //#region src/contracts/logs.ts
2
+ /**
3
+ * Run `fetch` over [fromBlock, toBlock] in consecutive block windows and
4
+ * concatenate the results, oldest window first.
5
+ *
6
+ * RPC providers limit how many blocks one `eth_getLogs` call can cover. The
7
+ * public Arbitrum Sepolia endpoint rejects anything past a couple of thousand
8
+ * blocks with a bare "internal server errror". So a single wide-range call fails
9
+ * outright, and whatever depends on it (a catch-up, a directory listing) fails
10
+ * with it. Tune the window with `FANGORN_LOG_WINDOW`; a private RPC will take far
11
+ * more.
12
+ */
13
+ async function getLogsInWindows(publicClient, fromBlock, toBlock, fetch) {
14
+ const window = BigInt((typeof process !== "undefined" ? process.env.FANGORN_LOG_WINDOW : void 0) ?? 1e3);
15
+ const end = toBlock ?? await publicClient.getBlockNumber({ cacheTime: 0 });
16
+ const out = [];
17
+ for (let start = fromBlock; start <= end; start += window) {
18
+ const stop = start + window - 1n < end ? start + window - 1n : end;
19
+ out.push(...await fetch(start, stop));
20
+ }
21
+ return out;
22
+ }
23
+
24
+ //#endregion
25
+ export { getLogsInWindows };
package/lib/fangorn.d.ts CHANGED
@@ -34,6 +34,24 @@ interface SubscribeOptions {
34
34
  /** Abort to stop the subscription and release the watch. */
35
35
  signal?: AbortSignal;
36
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
+ }
37
55
  declare class Fangorn {
38
56
  private readonly ctx;
39
57
  private _engine;
@@ -241,6 +259,23 @@ declare class Fangorn {
241
259
  root: Hex;
242
260
  blockNumber: bigint;
243
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
+ }>;
244
279
  /**
245
280
  * The app's commit stream as ONE shared, ref-counted subscription (see
246
281
  * `AppFeed`). Prefer this over `subscribeApp` anywhere more than one consumer
@@ -337,4 +372,4 @@ declare class Fangorn {
337
372
  getAddress(): Hex;
338
373
  }
339
374
  //#endregion
340
- export { Fangorn, NamespaceChange, SubscribeOptions };
375
+ export { AgentCard, FANGORN_APP_EXTENSION, Fangorn, NamespaceChange, SubscribeOptions };
package/lib/fangorn.js CHANGED
@@ -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;
@@ -370,6 +372,40 @@ var Fangorn = class Fangorn {
370
372
  return [...latest.values()];
371
373
  }
372
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
+ /**
373
409
  * The app's commit stream as ONE shared, ref-counted subscription (see
374
410
  * `AppFeed`). Prefer this over `subscribeApp` anywhere more than one consumer
375
411
  * wants the same feed — a server fanning out to connections, say.
@@ -580,4 +616,4 @@ var Fangorn = class Fangorn {
580
616
  };
581
617
 
582
618
  //#endregion
583
- export { Fangorn };
619
+ export { FANGORN_APP_EXTENSION, Fangorn };
package/lib/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { AppConfig, DEFAULT_APP, FangornConfig, SupportedNetworks, appId, toAppI
2
2
  import { APP_REGISTRY_ABI } from "./contracts/app-registry/abi.js";
3
3
  import { PublisherStatus } from "./contracts/types.js";
4
4
  import { CommitFilter, DataRegistryClient, PreparedTx, StateCommittedLog, namespaceKey, subspaceId } from "./contracts/data-registry/index.js";
5
- import { AppJoinInfo, AppRegistryClient, needsReacceptance } from "./contracts/app-registry/index.js";
5
+ import { AppAgentLog, AppJoinInfo, AppRegistryClient, needsReacceptance } from "./contracts/app-registry/index.js";
6
6
  import { DATA_REGISTRY_ABI } from "./contracts/data-registry/abi.js";
7
7
  import { Resource, SemaphoreProof, SettlementRegistryClient, TransferAuthorization, packResourceUri, resourceIdOf } from "./contracts/settlement-registry/index.js";
8
8
  import { SETTLEMENT_REGISTRY_ABI } from "./contracts/settlement-registry/abi.js";
@@ -12,9 +12,9 @@ import "./contracts/index.js";
12
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";
13
13
  import { FangornContext, FangornCreateOptions, StorageConfig } from "./types/index.js";
14
14
  import { AppFeed } from "./feed.js";
15
- import { Fangorn, NamespaceChange, SubscribeOptions } from "./fangorn.js";
15
+ import { AgentCard, FANGORN_APP_EXTENSION, Fangorn, NamespaceChange, SubscribeOptions } from "./fangorn.js";
16
16
  import { AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, Edge, FileFacade, ProcessorResult, Vertex, buildAssetGraph, buildMarkdownGraph, extractMarkdownLinks } from "./harness/index.js";
17
17
  import { PinataBackend } from "./providers/storage/pinata.js";
18
18
  import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend, SignedUrlSigner } from "./providers/storage/signed-url.js";
19
19
  import { MAX_UPLOAD_ATTEMPTS, deserialize, fetchRawByCid, isTransientUpload, retrieveByCid, serialize, withUploadRetry } from "./providers/storage/utils.js";
20
- export { APP_REGISTRY_ABI, AccessRequest, AccessSigner, AppConfig, AppFeed, AppJoinInfo, AppRegistryClient, 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, 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 };
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
@@ -13,8 +13,8 @@ import { SUBSCRIPTION_REGISTRY_ABI } from "./contracts/subscription-registry/abi
13
13
  import { SubscriptionRegistryClient } from "./contracts/subscription-registry/index.js";
14
14
  import "./contracts/index.js";
15
15
  import { AppFeed } from "./feed.js";
16
- import { Fangorn } from "./fangorn.js";
16
+ import { FANGORN_APP_EXTENSION, Fangorn } from "./fangorn.js";
17
17
  import { buildAssetGraph, buildMarkdownGraph, extractMarkdownLinks } from "./harness/index.js";
18
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";
19
19
 
20
- export { APP_REGISTRY_ABI, AppFeed, AppRegistryClient, 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, 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 };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.08.18-dev",
3
+ "version": "2026.09.22-dev",
4
4
  "description": "Git for knowledge graphs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,6 +47,7 @@
47
47
  "@noble/ciphers": "^1.3.0",
48
48
  "@noble/curves": "^1.9.7",
49
49
  "@noble/hashes": "^2.2.0",
50
+ "agent0-sdk": "^1.7.1",
50
51
  "commander": "^14.0.3",
51
52
  "dotenv": "^17.2.3",
52
53
  "multiformats": "^14.0.0",