@fangorn-network/sdk 0.1.0-dev → 0.1.0

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 (96) hide show
  1. package/lib/cli/cli.js +328 -128
  2. package/lib/cli/index.d.ts +4 -1
  3. package/lib/cli/index.js +20 -2
  4. package/lib/config.d.ts +111 -48
  5. package/lib/config.js +39 -11
  6. package/lib/contracts/app-registry/abi.d.ts +1265 -0
  7. package/lib/contracts/app-registry/abi.js +1454 -0
  8. package/lib/contracts/app-registry/index.d.ts +161 -0
  9. package/lib/contracts/app-registry/index.js +274 -0
  10. package/lib/contracts/data-registry/abi.d.ts +19 -195
  11. package/lib/contracts/data-registry/abi.js +206 -409
  12. package/lib/contracts/data-registry/index.d.ts +2 -126
  13. package/lib/contracts/data-registry/index.js +1 -174
  14. package/lib/contracts/index.d.ts +7 -4
  15. package/lib/contracts/index.js +7 -4
  16. package/lib/contracts/logs.d.ts +1 -1
  17. package/lib/contracts/logs.js +1 -1
  18. package/lib/contracts/{settlement-registry → membership-registry}/abi.d.ts +636 -301
  19. package/lib/contracts/membership-registry/abi.js +1333 -0
  20. package/lib/contracts/membership-registry/index.d.ts +79 -0
  21. package/lib/contracts/membership-registry/index.js +104 -0
  22. package/lib/contracts/types.d.ts +10 -0
  23. package/lib/contracts/types.js +12 -0
  24. package/lib/crypto/aes.d.ts +2 -2
  25. package/lib/crypto/aes.js +4 -4
  26. package/lib/crypto/encryption.d.ts +109 -8
  27. package/lib/crypto/encryption.js +114 -16
  28. package/lib/engine/car.d.ts +1 -5
  29. package/lib/engine/car.js +2 -2
  30. package/lib/engine/index.d.ts +14 -33
  31. package/lib/engine/index.js +41 -98
  32. package/lib/engine/records.d.ts +8 -19
  33. package/lib/engine/records.js +7 -81
  34. package/lib/engine/test-helpers.d.ts +3 -2
  35. package/lib/engine/test-helpers.js +5 -7
  36. package/lib/erc8004.js +10 -7
  37. package/lib/fangorn.d.ts +86 -65
  38. package/lib/fangorn.js +153 -115
  39. package/lib/feed.d.ts +8 -7
  40. package/lib/feed.js +8 -7
  41. package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +1 -0
  42. package/lib/harness/examples/hackmd/build-markdown-graph.js +17 -0
  43. package/lib/harness/index.d.ts +58 -0
  44. package/lib/harness/index.js +73 -0
  45. package/lib/index.d.ts +13 -10
  46. package/lib/index.js +13 -10
  47. package/lib/node_modules/{@jridgewell → .pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell}/sourcemap-codec/dist/sourcemap-codec.js +1 -1
  48. package/lib/node_modules/{@vitest → .pnpm/@vitest_expect@4.0.18/node_modules/@vitest}/expect/dist/index.js +8 -8
  49. package/lib/node_modules/{@vitest → .pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest}/pretty-format/dist/index.js +2 -2
  50. package/lib/node_modules/{@vitest → .pnpm/@vitest_runner@4.0.18/node_modules/@vitest}/runner/dist/chunk-tasks.js +2 -2
  51. package/lib/node_modules/{@vitest → .pnpm/@vitest_runner@4.0.18/node_modules/@vitest}/runner/dist/index.js +4 -4
  52. package/lib/node_modules/{@vitest → .pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest}/snapshot/dist/index.js +4 -4
  53. package/lib/node_modules/{@vitest → .pnpm/@vitest_spy@4.0.18/node_modules/@vitest}/spy/dist/index.js +1 -1
  54. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/chunk-_commonjsHelpers.js +1 -1
  55. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/chunk-pathe.M-eThtNZ.js +1 -1
  56. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/diff.js +3 -3
  57. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/display.js +2 -2
  58. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/error.js +2 -2
  59. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/helpers.js +1 -1
  60. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/serialize.js +1 -1
  61. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/source-map.js +1 -1
  62. package/lib/node_modules/{@vitest → .pnpm/@vitest_utils@4.0.18/node_modules/@vitest}/utils/dist/timers.js +1 -1
  63. package/lib/node_modules/{chai → .pnpm/chai@6.2.2/node_modules/chai}/index.js +1 -1
  64. package/lib/node_modules/{magic-string → .pnpm/magic-string@0.30.21/node_modules/magic-string}/dist/magic-string.es.js +2 -2
  65. package/lib/node_modules/{pathe → .pnpm/pathe@2.0.3/node_modules/pathe}/dist/shared/pathe.M-eThtNZ.js +1 -1
  66. package/lib/node_modules/{tinyrainbow → .pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow}/dist/index.js +1 -1
  67. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/_commonjsHelpers.D26ty3Ew.js +1 -1
  68. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/date.Bq6ZW5rf.js +1 -1
  69. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/utils.DvEY5TfP.js +2 -2
  70. package/lib/node_modules/{vitest → .pnpm/vitest@4.0.18_@types_node@24.10.1_jiti@2.6.1_terser@5.51.2_tsx@4.21.0_yaml@2.8.2/node_modules/vitest}/dist/chunks/vi.2VT5v0um.js +11 -11
  71. package/lib/providers/storage/signed-url.d.ts +10 -2
  72. package/lib/providers/storage/signed-url.js +15 -5
  73. package/lib/providers/storage/types.d.ts +1 -1
  74. package/lib/providers/storage/utils.js +3 -5
  75. package/lib/registry.d.ts +118 -0
  76. package/lib/registry.js +184 -0
  77. package/lib/test/mem-registry.d.ts +19 -14
  78. package/lib/test/mem-registry.js +37 -44
  79. package/lib/test/sdk-suite.d.ts +4 -1
  80. package/lib/test/sdk-suite.js +89 -18
  81. package/lib/test/testbed.d.ts +5227 -5218
  82. package/lib/test/testbed.js +56 -29
  83. package/lib/types/index.d.ts +11 -6
  84. package/package.json +1 -1
  85. package/lib/cli/sell.d.ts +0 -28
  86. package/lib/cli/sell.js +0 -95
  87. package/lib/cli/stage.d.ts +0 -19
  88. package/lib/cli/stage.js +0 -94
  89. package/lib/contracts/settlement-registry/abi.js +0 -962
  90. package/lib/contracts/settlement-registry/index.d.ts +0 -143
  91. package/lib/contracts/settlement-registry/index.js +0 -213
  92. package/lib/crypto/paid.d.ts +0 -104
  93. package/lib/crypto/paid.js +0 -147
  94. package/lib/test/key-server.d.ts +0 -12
  95. package/lib/test/key-server.js +0 -30
  96. /package/lib/node_modules/{@vitest → .pnpm/@vitest_runner@4.0.18/node_modules/@vitest}/runner/dist/utils.js +0 -0
package/lib/fangorn.d.ts CHANGED
@@ -1,13 +1,14 @@
1
+ import { AppConfig } from "./config.js";
1
2
  import { PreparedTx } from "./contracts/write.js";
2
- import { Registry } from "./contracts/data-registry/index.js";
3
- import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
3
+ import { AppRegistryClient } from "./contracts/app-registry/index.js";
4
+ import { MembershipRegistryClient } from "./contracts/membership-registry/index.js";
4
5
  import "./contracts/index.js";
6
+ import { Registry } from "./registry.js";
5
7
  import { MetadataStorage } from "./providers/storage/types.js";
6
- import { CommitDiff, FangornEngine, RecordInput, RepoContents, RepoDiff, SignedUpdate } from "./engine/index.js";
7
- import { NetworkConfig } from "./config.js";
8
- import { FangornCreateOptions, StorageConfig } from "./types/index.js";
8
+ import { CommitDiff, FangornEngine, RecordInput, RepoContents, RepoDiff } from "./engine/index.js";
9
9
  import { AgentCard as AgentCard$1 } from "./erc8004.js";
10
- import { CommitFeed } from "./feed.js";
10
+ import { FangornCreateOptions, StorageConfig } from "./types/index.js";
11
+ import { AppFeed } from "./feed.js";
11
12
  import { Hash, Hex, WalletClient } from "viem";
12
13
  import { CID } from "multiformats/cid";
13
14
 
@@ -22,6 +23,10 @@ interface RepoChange extends RepoDiff {
22
23
  }
23
24
  interface SubscribeOptions {
24
25
  repo: string;
26
+ /**
27
+ * Under an app, the stream follows what the app presents (its members' updates,
28
+ * less exclusions); with no app, every update the publisher commits.
29
+ */
25
30
  /** Publisher whose repo to watch (defaults to this wallet's address). */
26
31
  owner?: Hex;
27
32
  /**
@@ -35,19 +40,10 @@ interface SubscribeOptions {
35
40
  /** Abort to stop the subscription and release the watch. */
36
41
  signal?: AbortSignal;
37
42
  }
43
+ /** The A2A extension a Fangorn app's agent card carries: it names the app the card speaks for. */
44
+ declare const FANGORN_APP_EXTENSION = "https://fangorn.network/a2a/app/v1";
38
45
  /**
39
- * The A2A extension a repo's agent card carries. Its params name the repo the
40
- * card speaks for: `{ chainId, dataRegistry, publisher, repo }`.
41
- */
42
- declare const FANGORN_REPO_EXTENSION = "https://fangorn.network/a2a/repo/v1";
43
- /**
44
- * The record that binds a repo to its agent card: `{ url }`, at this id in the
45
- * repo. Only the publisher can commit it, so it plays the part an on-chain
46
- * pointer would.
47
- */
48
- declare const CARD_RECORD = "@card";
49
- /**
50
- * The part of an A2A agent card `discoverCard` reads. A card's other fields
46
+ * The part of an A2A agent card `discoverApp` reads. A card's other fields
51
47
  * (skills, endpoints and so on) pass through untouched.
52
48
  */
53
49
  interface AgentCard {
@@ -66,7 +62,8 @@ declare class Fangorn {
66
62
  private readonly ctx;
67
63
  private _engine;
68
64
  private _feed;
69
- private _settlement;
65
+ private _apps;
66
+ private _membership;
70
67
  /**
71
68
  * The repo cache
72
69
  * Insertion order = LRU order
@@ -139,6 +136,7 @@ declare class Fangorn {
139
136
  records?: RecordInput[];
140
137
  deletes?: string[];
141
138
  parent?: string;
139
+ message: string;
142
140
  /** Snapshot semantics: the staged records replace the repo's previous contents. */
143
141
  replace?: boolean;
144
142
  }): Promise<{
@@ -166,6 +164,7 @@ declare class Fangorn {
166
164
  repo: string;
167
165
  records?: RecordInput[];
168
166
  deletes?: string[];
167
+ message: string;
169
168
  /** Snapshot semantics: the staged records replace the repo's contents. */
170
169
  replace?: boolean;
171
170
  }): Promise<{
@@ -188,16 +187,13 @@ declare class Fangorn {
188
187
  txHash: string;
189
188
  onChainTip: string;
190
189
  }>;
191
- /**
192
- * `push`, signed instead of sent: anyone holding the result can settle it with
193
- * `relayPush`, paying the gas.
194
- */
195
- signPush(repo: string, commitCid: string): Promise<SignedUpdate>;
196
- relayPush(signed: SignedUpdate): Promise<Hash>;
197
190
  /** The owner's current on-chain tip for a repo, or null if they have none. */
198
191
  onChainTip(owner: Hex, repo: string): Promise<string | null>;
199
192
  /**
200
- * A publisher's repo at its latest head, cached against that head.
193
+ * A publisher's repo as this client presents it, cached against its tip:
194
+ * the publisher's latest head, or, under an app, nothing unless the app
195
+ * presents the publisher (provides its storage) and excludes neither it nor
196
+ * the repo.
201
197
  *
202
198
  * Reading a repo walks its whole record tree from the root. The tip is one
203
199
  * cheap contract read and only moves on publish, so it doubles as the cache
@@ -213,16 +209,21 @@ declare class Fangorn {
213
209
  tip: string | null;
214
210
  contents: RepoContents;
215
211
  }>;
216
- /** The commit at a repo's head, or null for a repo never written. */
217
- private headCommit;
212
+ /** The commit this client presents of a repo, or null for none (see `readRepo`). */
213
+ private presentedTip;
214
+ /** Does `app` present `ref`: it presents the publisher, and excludes neither it nor the repo? */
215
+ private presentsRepo;
218
216
  /**
219
- * Every (publisher, repo) at its latest head, from one scan of the update log.
220
- * Narrow it with `repo` (every publisher's `docs`) or `owner`, filtered on-chain.
217
+ * Every (publisher, repo) this client's app presents, at its latest head, less
218
+ * what it excludes — the app's directory, from ONE `getLogs` over the update
219
+ * log, kept to the publishers the app presents.
221
220
  *
222
- * ponytail: scans the whole log from `fromBlock`; an indexer's sub-log once
223
- * that is too slow.
221
+ * ponytail: reads every publisher's updates and drops non-members, so it costs
222
+ * what the network writes, not what the app holds. Filter on-chain by the
223
+ * app's members (a `publisher` topic list) once that is too slow.
224
+ * Narrow it with `repo` (every publisher's `docs`) or `owner`, filtered on-chain.
224
225
  */
225
- repos(opts?: {
226
+ appRepos(opts?: {
226
227
  repo?: string;
227
228
  owner?: Hex;
228
229
  fromBlock?: bigint;
@@ -233,38 +234,36 @@ declare class Fangorn {
233
234
  blockNumber: bigint;
234
235
  }[]>;
235
236
  /**
236
- * Resolve a repo from its agent card URL alone, and prove the card speaks for it.
237
+ * Resolve an app from its agent card URL alone, and prove the card speaks for it.
237
238
  *
238
- * The card names its repo in the `FANGORN_REPO_EXTENSION` A2A extension, but
239
- * anyone can serve a card that names any repo. So the card is trusted only if
240
- * the repo's `@card` record, which only its publisher can commit, points
239
+ * The card names its app in the `FANGORN_APP_EXTENSION` A2A extension, but
240
+ * anyone can serve a card that names any app. So the card is trusted only if
241
+ * the app's on-chain `agent_uri`, which only the app owner can set, points
241
242
  * back at this exact URL. The comparison is exact string equality, so a
242
243
  * trailing slash or a different host counts as a different card.
244
+ *
245
+ * Doesn't touch this client's app. Pass `appId` to `setAppId` to read under it.
243
246
  */
244
- discoverCard(cardUrl: string): Promise<{
247
+ discoverApp(cardUrl: string): Promise<{
245
248
  card: AgentCard;
246
- publisher: Hex;
247
- repo: string;
249
+ appId: Hex;
250
+ fromBlock: bigint;
251
+ repos: string[];
248
252
  }>;
249
- /** The card URL a repo's `@card` record points at, or undefined for none. */
250
- cardOf(publisher: Hex, repo: string): Promise<string | undefined>;
251
253
  /**
252
- * Point one of your repos at its agent card, by committing its `@card` record.
253
- * Returns the transaction, or undefined if it already points there.
254
+ * The app's commit stream as ONE shared, ref-counted subscription (see
255
+ * `AppFeed`). Prefer this over `subscribeApp` anywhere more than one consumer
256
+ * wants the same feed — a server fanning out to connections, say.
254
257
  */
255
- setCard(repo: string, cardUrl: string): Promise<Hash | undefined>;
256
- /**
257
- * `subscribeAll` as ONE shared, ref-counted subscription (see `CommitFeed`), for
258
- * anywhere more than one consumer wants the same stream.
259
- */
260
- feed(opts?: {
258
+ appFeed(opts?: {
261
259
  pollingInterval?: number;
262
- }): CommitFeed;
260
+ }): AppFeed;
263
261
  /** Walk commit history from `head` (newest first). */
264
262
  log(head: string, max?: number): AsyncGenerator<{
265
263
  cid: string;
266
264
  parent: string | null;
267
265
  epoch: number;
266
+ message: string;
268
267
  root: string;
269
268
  }>;
270
269
  /** Show a commit and what it changed vs. its parent. */
@@ -283,17 +282,19 @@ declare class Fangorn {
283
282
  */
284
283
  subscribe(opts: SubscribeOptions): AsyncGenerator<RepoChange>;
285
284
  /**
286
- * Stream changes to every repo of every publisher. Narrow it with `repo`
287
- * (every publisher's `docs`) or `owner` (one publisher's repos).
285
+ * Stream changes across the *whole app* — every repo of every publisher it
286
+ * presents, less its exclusions. Narrow it with `repo` (every publisher's `docs`) or
287
+ * `owner` (one publisher's whole app footprint). With no app, every update by
288
+ * anyone: a firehose.
288
289
  */
289
- subscribeAll(opts?: Omit<SubscribeOptions, "repo"> & {
290
+ subscribeApp(opts?: Omit<SubscribeOptions, "repo"> & {
290
291
  repo?: string;
291
292
  }): AsyncGenerator<RepoChange>;
292
- /** Shared catch-up-then-live loop behind `subscribe` and `subscribeAll`. */
293
+ /** Shared catch-up-then-live loop behind `subscribe` and `subscribeApp`. */
293
294
  private streamCommits;
294
295
  /**
295
- * Resolve a log entry into a repo change, or null if the repo's records did
296
- * not change.
296
+ * Resolve a log entry into a repo change, or null if nothing presented
297
+ * changed: the repo slice was untouched, or the app excludes it.
297
298
  *
298
299
  * The commit itself names its repo, which must be the one the entry was
299
300
  * logged under, or the publisher settled a commit for one repo against
@@ -305,21 +306,27 @@ declare class Fangorn {
305
306
  * dropped entry changed.
306
307
  */
307
308
  private toRepoChange;
308
- getConfig(): NetworkConfig;
309
- /** Heads and the update log: the registry of WHITEPAPER_1 §3.2. */
309
+ getConfig(): AppConfig;
310
+ /** Heads, membership, exclusions and logs: the registry of WHITEPAPER_1 §3.2. */
310
311
  getRegistry(): Registry;
311
- getSettlementRegistry(): SettlementRegistryClient;
312
312
  /**
313
- * Register a repo as an ERC-8004 agent from its card, and point the repo at
314
- * the card (`setCard`). The registration file is pinned with this client's storage, so a
313
+ * App management: claiming an app (its storage subscription), terms,
314
+ * invitations and membership, the agent card, and the protocol admin's powers.
315
+ * The owner accepts a publisher (`acceptPublisher()`); from then its uploads
316
+ * bill the app's subscription, and the app presents its repos.
317
+ */
318
+ getAppRegistry(): AppRegistryClient;
319
+ getMembershipRegistry(): MembershipRegistryClient;
320
+ /**
321
+ * Register the app as an ERC-8004 agent from its card, and point the app at the card
322
+ * (owner only). The registration file is pinned with this client's storage, so a
315
323
  * browser wallet on signed-URL storage needs no Pinata JWT.
316
324
  *
317
325
  * `update` re-files an agent already minted (its token id) from the card as it is
318
326
  * now, minting nothing. `skipRegister` only binds the card. A binding that already
319
327
  * points at `cardUrl` is left alone.
320
328
  */
321
- registerAgent(cardUrl: string, opts: {
322
- repo: string;
329
+ registerAgent(cardUrl: string, opts?: {
323
330
  mcp?: string;
324
331
  update?: bigint;
325
332
  skipRegister?: boolean;
@@ -328,6 +335,20 @@ declare class Fangorn {
328
335
  agentId?: bigint;
329
336
  txHash?: Hash;
330
337
  }>;
338
+ /** The app this client reads and publishes under, or undefined for none. */
339
+ getAppId(): Hex | undefined;
340
+ private requireApp;
341
+ /**
342
+ * Point this client at a different app — by name (`"my-app"`) or by app id —
343
+ * or at none, without rebuilding it. Every read, publish and subscription
344
+ * after this call is in the new context.
345
+ *
346
+ * Repo reads are dropped from the cache (its keys are app-agnostic) and
347
+ * the shared `appFeed` is released: a feed watches one app's commit stream, so
348
+ * the next `appFeed()` opens a fresh subscription. Generators already running
349
+ * from `subscribe`/`subscribeApp` keep their original filter until aborted.
350
+ */
351
+ setAppId(nameOrId: string | undefined): void;
331
352
  getStorage(): MetadataStorage;
332
353
  /**
333
354
  * Swap the storage backend at runtime — e.g. move from access-worker signed
@@ -339,4 +360,4 @@ declare class Fangorn {
339
360
  getAddress(): Hex;
340
361
  }
341
362
  //#endregion
342
- export { AgentCard, CARD_RECORD, FANGORN_REPO_EXTENSION, Fangorn, RepoChange, SubscribeOptions };
363
+ export { AgentCard, FANGORN_APP_EXTENSION, Fangorn, RepoChange, SubscribeOptions };