@fangorn-network/sdk 2026.9.22-dev → 2026.10.19-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 (89) hide show
  1. package/README.md +177 -192
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +165 -194
  4. package/lib/config.d.ts +32 -27
  5. package/lib/config.js +17 -7
  6. package/lib/contracts/app-registry/abi.d.ts +1033 -277
  7. package/lib/contracts/app-registry/abi.js +1214 -335
  8. package/lib/contracts/app-registry/index.d.ts +105 -65
  9. package/lib/contracts/app-registry/index.js +182 -175
  10. package/lib/contracts/data-registry/abi.d.ts +166 -187
  11. package/lib/contracts/data-registry/abi.js +207 -237
  12. package/lib/contracts/data-registry/index.d.ts +4 -151
  13. package/lib/contracts/data-registry/index.js +5 -279
  14. package/lib/contracts/index.d.ts +6 -7
  15. package/lib/contracts/index.js +6 -8
  16. package/lib/contracts/logs.d.ts +4 -1
  17. package/lib/contracts/logs.js +9 -2
  18. package/lib/contracts/membership-registry/abi.d.ts +1145 -0
  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 +3 -1
  23. package/lib/contracts/types.js +3 -1
  24. package/lib/contracts/write.d.ts +34 -2
  25. package/lib/contracts/write.js +48 -1
  26. package/lib/crypto/encryption.js +4 -4
  27. package/lib/engine/car.d.ts +2 -2
  28. package/lib/engine/car.js +10 -5
  29. package/lib/engine/index.d.ts +99 -143
  30. package/lib/engine/index.js +156 -295
  31. package/lib/engine/records.d.ts +110 -0
  32. package/lib/engine/records.js +165 -0
  33. package/lib/engine/test-helpers.d.ts +7 -14
  34. package/lib/engine/test-helpers.js +7 -18
  35. package/lib/fangorn.d.ts +129 -156
  36. package/lib/fangorn.js +250 -250
  37. package/lib/feed.d.ts +7 -4
  38. package/lib/feed.js +4 -1
  39. package/lib/index.d.ts +9 -9
  40. package/lib/index.js +8 -9
  41. package/lib/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.js +77 -0
  42. package/lib/node_modules/@vitest/expect/dist/index.js +1414 -0
  43. package/lib/node_modules/@vitest/pretty-format/dist/index.js +858 -0
  44. package/lib/node_modules/@vitest/runner/dist/chunk-tasks.js +51 -0
  45. package/lib/node_modules/@vitest/runner/dist/index.js +1199 -0
  46. package/lib/node_modules/@vitest/runner/dist/utils.js +3 -0
  47. package/lib/node_modules/@vitest/snapshot/dist/index.js +1075 -0
  48. package/lib/node_modules/@vitest/spy/dist/index.js +353 -0
  49. package/lib/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +7 -0
  50. package/lib/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.js +81 -0
  51. package/lib/node_modules/@vitest/utils/dist/diff.js +1345 -0
  52. package/lib/node_modules/@vitest/utils/dist/display.js +534 -0
  53. package/lib/node_modules/@vitest/utils/dist/error.js +30 -0
  54. package/lib/node_modules/@vitest/utils/dist/helpers.js +118 -0
  55. package/lib/node_modules/@vitest/utils/dist/serialize.js +76 -0
  56. package/lib/node_modules/@vitest/utils/dist/source-map.js +93 -0
  57. package/lib/node_modules/@vitest/utils/dist/timers.js +36 -0
  58. package/lib/node_modules/chai/index.js +2874 -0
  59. package/lib/node_modules/magic-string/dist/magic-string.es.js +939 -0
  60. package/lib/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +81 -0
  61. package/lib/node_modules/tinyrainbow/dist/index.js +85 -0
  62. package/lib/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js +5 -0
  63. package/lib/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js +50 -0
  64. package/lib/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js +44 -0
  65. package/lib/node_modules/vitest/dist/chunks/vi.2VT5v0um.js +2578 -0
  66. package/lib/providers/storage/signed-url.d.ts +16 -6
  67. package/lib/providers/storage/signed-url.js +20 -8
  68. package/lib/registry.d.ts +116 -0
  69. package/lib/registry.js +182 -0
  70. package/lib/test/mem-registry.d.ts +51 -0
  71. package/lib/test/mem-registry.js +107 -0
  72. package/lib/test/sdk-suite.d.ts +13 -0
  73. package/lib/test/sdk-suite.js +226 -0
  74. package/lib/test/testbed.d.ts +16411 -61
  75. package/lib/test/testbed.js +190 -84
  76. package/lib/types/index.d.ts +13 -11
  77. package/package.json +89 -73
  78. package/lib/contracts/data-registry/test.d.ts +0 -1
  79. package/lib/contracts/data-registry/test.js +0 -1
  80. package/lib/contracts/settlement-registry/abi.d.ts +0 -466
  81. package/lib/contracts/settlement-registry/abi.js +0 -535
  82. package/lib/contracts/settlement-registry/index.d.ts +0 -163
  83. package/lib/contracts/settlement-registry/index.js +0 -264
  84. package/lib/contracts/subscription-registry/abi.d.ts +0 -179
  85. package/lib/contracts/subscription-registry/abi.js +0 -195
  86. package/lib/contracts/subscription-registry/index.d.ts +0 -59
  87. package/lib/contracts/subscription-registry/index.js +0 -116
  88. package/lib/engine/graph.d.ts +0 -70
  89. package/lib/engine/graph.js +0 -73
@@ -1,116 +0,0 @@
1
- import { requireWallet, sendWrite } from "../write.js";
2
- import { SUBSCRIPTION_REGISTRY_ABI } from "./abi.js";
3
-
4
- //#region src/contracts/subscription-registry/index.ts
5
- /**
6
- * Client for the SubscriptionRegistry — the publisher-side storage paywall.
7
- *
8
- * Deliberately does NOT decide whether a subscription is currently valid. The
9
- * contract stores only when it was last paid; the active window and any free tier
10
- * are the gate's policy, and keeping them off-chain means changing them is a config
11
- * edit rather than a redeploy. `isActiveAt` is offered as the obvious default, with
12
- * the window passed in.
13
- */
14
- var SubscriptionRegistryClient = class {
15
- constructor(contractAddress, publicClient, walletClient) {
16
- this.contractAddress = contractAddress;
17
- this.publicClient = publicClient;
18
- this.walletClient = walletClient;
19
- }
20
- getAddress() {
21
- return this.contractAddress;
22
- }
23
- executeWrite(functionName, args) {
24
- return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, SUBSCRIPTION_REGISTRY_ABI, functionName, args);
25
- }
26
- /**
27
- * Open or renew this wallet's subscription.
28
- *
29
- * The fee is pulled in USDC, so the caller must have `approve`d this contract
30
- * for at least `subscriptionFee()` first — otherwise the call reverts
31
- * `SubscriptionFeeRequired`, which reads like a pricing error but is really an
32
- * allowance one. Renewing while still active is allowed and simply re-stamps
33
- * the timestamp, so there is no window to lose by renewing early.
34
- */
35
- async subscribe() {
36
- return this.executeWrite("subscribe", []);
37
- }
38
- /** The single oracle the upload gate reads. */
39
- async access(publisher) {
40
- const [registered, paidAt] = await this.publicClient.readContract({
41
- address: this.contractAddress,
42
- abi: SUBSCRIPTION_REGISTRY_ABI,
43
- functionName: "access",
44
- args: [publisher]
45
- });
46
- return {
47
- registered,
48
- paidAt
49
- };
50
- }
51
- /**
52
- * Registered, paid, and inside `windowSeconds` of that payment — the whole
53
- * gate policy in one call. `now` is injectable so a caller can evaluate against
54
- * block time rather than wall-clock skew.
55
- */
56
- async isActiveAt(publisher, windowSeconds, now = BigInt(Math.floor(Date.now() / 1e3))) {
57
- const { registered, paidAt } = await this.access(publisher);
58
- return registered && paidAt > 0n && now < paidAt + windowSeconds;
59
- }
60
- async subscribedAt(publisher) {
61
- return this.publicClient.readContract({
62
- address: this.contractAddress,
63
- abi: SUBSCRIPTION_REGISTRY_ABI,
64
- functionName: "subscribedAt",
65
- args: [publisher]
66
- });
67
- }
68
- /** The fee in USDC's smallest unit (6 decimals), not wei. */
69
- async subscriptionFee() {
70
- return this.publicClient.readContract({
71
- address: this.contractAddress,
72
- abi: SUBSCRIPTION_REGISTRY_ABI,
73
- functionName: "subscriptionFee"
74
- });
75
- }
76
- async usdc() {
77
- return this.publicClient.readContract({
78
- address: this.contractAddress,
79
- abi: SUBSCRIPTION_REGISTRY_ABI,
80
- functionName: "usdc"
81
- });
82
- }
83
- /** The DataRegistry this contract cross-calls for `isRegistered`. */
84
- async dataRegistry() {
85
- return this.publicClient.readContract({
86
- address: this.contractAddress,
87
- abi: SUBSCRIPTION_REGISTRY_ABI,
88
- functionName: "dataRegistry"
89
- });
90
- }
91
- async admin() {
92
- return this.publicClient.readContract({
93
- address: this.contractAddress,
94
- abi: SUBSCRIPTION_REGISTRY_ABI,
95
- functionName: "admin"
96
- });
97
- }
98
- async setSubscriptionFee(fee) {
99
- return this.executeWrite("setSubscriptionFee", [fee]);
100
- }
101
- async setUsdc(token) {
102
- return this.executeWrite("setUsdc", [token]);
103
- }
104
- async setDataRegistry(registry) {
105
- return this.executeWrite("setDataRegistry", [registry]);
106
- }
107
- async withdrawUsdc(to, amount) {
108
- return this.executeWrite("withdrawUsdc", [to, amount]);
109
- }
110
- async withdrawEth(to, amount) {
111
- return this.executeWrite("withdrawEth", [to, amount]);
112
- }
113
- };
114
-
115
- //#endregion
116
- export { SubscriptionRegistryClient };
@@ -1,70 +0,0 @@
1
- import { CID } from "multiformats/cid";
2
-
3
- //#region src/engine/graph.d.ts
4
- /** A content-addressed IPLD block. */
5
- interface Block {
6
- cid: CID;
7
- bytes: Uint8Array;
8
- }
9
- /** Encode any value as canonical dag-cbor and derive its CIDv1 (sha256). */
10
- declare function encodeBlock(obj: unknown): Promise<Block>;
11
- declare function decodeBlock<T>(bytes: Uint8Array): T;
12
- /** Vertex block: a JSON payload tagged by a free-form schema id. */
13
- interface VertexBlock {
14
- schemaId: string;
15
- payload: Record<string, unknown>;
16
- }
17
- /** Edge block: a labeled relation between two vertex blocks, as native links. */
18
- interface EdgeBlock {
19
- source: CID;
20
- relation: string;
21
- target: CID;
22
- }
23
- /**
24
- * Namespace tree: the complete current contents of one namespace, as pages of
25
- * sorted vertex/edge links. Paged so a namespace of any size never produces a
26
- * single oversized block; sorted so the same set of links always builds the
27
- * same pages (deterministic CIDs → structural sharing across commits).
28
- */
29
- interface NamespaceTree {
30
- vertices: CID[];
31
- edges: CID[];
32
- }
33
- /**
34
- * Average links per page. Boundaries are content-defined (a link closes its
35
- * page when its digest satisfies a 1-in-TARGET_PAGE_SIZE condition), so an
36
- * insertion into the sorted link set only rewrites the page it lands in —
37
- * NOT every page after it, as fixed-size chunking would. That keeps the CAR
38
- * delta of an incremental commit proportional to the delta, not to the
39
- * accumulated namespace size. Kept small (256 links ≈ 10KB) so the unit of
40
- * rewrite is cheap; a large staged delta touches many pages, but never costs
41
- * more than the namespace's total page bytes.
42
- */
43
- declare const TARGET_PAGE_SIZE = 256;
44
- /** Hard cap so a pathological digest run can't produce an oversized page block. */
45
- declare const MAX_PAGE_SIZE: number;
46
- /** Root map: every namespace this publisher has, each pointing at its tree. */
47
- type RootMap = Record<string, CID>;
48
- /**
49
- * Commit block: the git-like history object the on-chain digest points at.
50
- * `car` is the opaque storage URI of the CAR file holding every block this
51
- * commit introduced — the commit block itself is stored OUTSIDE that CAR
52
- * (individually addressable), so a reader goes digest → commit → CAR with no
53
- * index lookups.
54
- */
55
- interface CommitBlock {
56
- root: CID;
57
- parents: CID[];
58
- timestamp: number;
59
- message: string;
60
- car: string;
61
- }
62
- /** Build the page blocks for a set of links; returns the page links in tree order. */
63
- declare function buildPages(links: Iterable<CID>): Promise<{
64
- pages: Block[];
65
- pageLinks: CID[];
66
- }>;
67
- /** Read every link out of a tree's pages via `getBlock`. */
68
- declare function readPages(pageLinks: CID[], getBlock: (cid: CID) => Promise<Uint8Array>): Promise<CID[]>;
69
- //#endregion
70
- export { Block, CommitBlock, EdgeBlock, MAX_PAGE_SIZE, NamespaceTree, RootMap, TARGET_PAGE_SIZE, VertexBlock, buildPages, decodeBlock, encodeBlock, readPages };
@@ -1,73 +0,0 @@
1
- import { CID } from "multiformats/cid";
2
- import * as dagCbor from "@ipld/dag-cbor";
3
- import { sha256 } from "multiformats/hashes/sha2";
4
-
5
- //#region src/engine/graph.ts
6
- /** Encode any value as canonical dag-cbor and derive its CIDv1 (sha256). */
7
- async function encodeBlock(obj) {
8
- const bytes = dagCbor.encode(obj);
9
- const hash = await sha256.digest(bytes);
10
- return {
11
- cid: CID.createV1(dagCbor.code, hash),
12
- bytes
13
- };
14
- }
15
- function decodeBlock(bytes) {
16
- return dagCbor.decode(bytes);
17
- }
18
- /**
19
- * Average links per page. Boundaries are content-defined (a link closes its
20
- * page when its digest satisfies a 1-in-TARGET_PAGE_SIZE condition), so an
21
- * insertion into the sorted link set only rewrites the page it lands in —
22
- * NOT every page after it, as fixed-size chunking would. That keeps the CAR
23
- * delta of an incremental commit proportional to the delta, not to the
24
- * accumulated namespace size. Kept small (256 links ≈ 10KB) so the unit of
25
- * rewrite is cheap; a large staged delta touches many pages, but never costs
26
- * more than the namespace's total page bytes.
27
- */
28
- const TARGET_PAGE_SIZE = 256;
29
- /** Hard cap so a pathological digest run can't produce an oversized page block. */
30
- const MAX_PAGE_SIZE = 4 * TARGET_PAGE_SIZE;
31
- /** Content-defined boundary: last two digest bytes mod the target size. */
32
- function isPageBoundary(link) {
33
- const d = link.multihash.digest;
34
- return (d[d.length - 2] << 8 | d[d.length - 1]) % TARGET_PAGE_SIZE === 0;
35
- }
36
- /** Sort link strings the way pages are ordered (plain lexicographic CID text). */
37
- function sortedUnique(links) {
38
- const byStr = /* @__PURE__ */ new Map();
39
- for (const l of links) byStr.set(l.toString(), l);
40
- return [...byStr.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, c]) => c);
41
- }
42
- /** Build the page blocks for a set of links; returns the page links in tree order. */
43
- async function buildPages(links) {
44
- const sorted = sortedUnique(links);
45
- const pages = [];
46
- const pageLinks = [];
47
- let current = [];
48
- const close = async () => {
49
- if (current.length === 0) return;
50
- const page = await encodeBlock(current);
51
- pages.push(page);
52
- pageLinks.push(page.cid);
53
- current = [];
54
- };
55
- for (const link of sorted) {
56
- current.push(link);
57
- if (isPageBoundary(link) || current.length >= MAX_PAGE_SIZE) await close();
58
- }
59
- await close();
60
- return {
61
- pages,
62
- pageLinks
63
- };
64
- }
65
- /** Read every link out of a tree's pages via `getBlock`. */
66
- async function readPages(pageLinks, getBlock) {
67
- const out = [];
68
- for (const link of pageLinks) out.push(...decodeBlock(await getBlock(link)));
69
- return out;
70
- }
71
-
72
- //#endregion
73
- export { MAX_PAGE_SIZE, TARGET_PAGE_SIZE, buildPages, decodeBlock, encodeBlock, readPages };