@fangorn-network/sdk 2026.10.27-dev → 2026.11.3-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 (65) hide show
  1. package/README.md +36 -642
  2. package/lib/cli/cli.js +47 -322
  3. package/lib/cli/index.d.ts +1 -4
  4. package/lib/cli/index.js +2 -20
  5. package/lib/config.d.ts +15 -78
  6. package/lib/config.js +8 -35
  7. package/lib/contracts/data-registry/abi.d.ts +195 -19
  8. package/lib/contracts/data-registry/abi.js +223 -20
  9. package/lib/contracts/data-registry/index.d.ts +126 -2
  10. package/lib/contracts/data-registry/index.js +174 -1
  11. package/lib/contracts/index.d.ts +5 -8
  12. package/lib/contracts/index.js +4 -7
  13. package/lib/contracts/logs.d.ts +1 -1
  14. package/lib/contracts/logs.js +1 -1
  15. package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +288 -637
  16. package/lib/contracts/{membership-registry → settlement-registry}/abi.js +326 -712
  17. package/lib/contracts/settlement-registry/index.d.ts +141 -0
  18. package/lib/contracts/settlement-registry/index.js +209 -0
  19. package/lib/crypto/aes.d.ts +2 -2
  20. package/lib/crypto/aes.js +4 -4
  21. package/lib/crypto/encryption.d.ts +8 -109
  22. package/lib/crypto/encryption.js +16 -114
  23. package/lib/crypto/paid.d.ts +104 -0
  24. package/lib/crypto/paid.js +147 -0
  25. package/lib/engine/index.d.ts +23 -12
  26. package/lib/engine/index.js +68 -29
  27. package/lib/engine/records.d.ts +4 -7
  28. package/lib/engine/records.js +6 -6
  29. package/lib/engine/test-helpers.d.ts +2 -3
  30. package/lib/engine/test-helpers.js +7 -5
  31. package/lib/erc8004.js +1 -4
  32. package/lib/fangorn.d.ts +64 -85
  33. package/lib/fangorn.js +106 -148
  34. package/lib/feed.d.ts +7 -8
  35. package/lib/feed.js +7 -8
  36. package/lib/index.d.ts +10 -14
  37. package/lib/index.js +9 -13
  38. package/lib/providers/storage/signed-url.d.ts +2 -10
  39. package/lib/providers/storage/signed-url.js +4 -14
  40. package/lib/providers/storage/types.d.ts +1 -1
  41. package/lib/providers/storage/utils.js +5 -3
  42. package/lib/test/key-server.d.ts +12 -0
  43. package/lib/test/key-server.js +30 -0
  44. package/lib/test/mem-registry.d.ts +14 -19
  45. package/lib/test/mem-registry.js +44 -37
  46. package/lib/test/sdk-suite.d.ts +1 -4
  47. package/lib/test/sdk-suite.js +16 -87
  48. package/lib/test/testbed.d.ts +5216 -5226
  49. package/lib/test/testbed.js +29 -56
  50. package/lib/types/index.d.ts +6 -11
  51. package/package.json +1 -4
  52. package/lib/contracts/app-registry/abi.d.ts +0 -1317
  53. package/lib/contracts/app-registry/abi.js +0 -1510
  54. package/lib/contracts/app-registry/index.d.ts +0 -173
  55. package/lib/contracts/app-registry/index.js +0 -294
  56. package/lib/contracts/membership-registry/index.d.ts +0 -79
  57. package/lib/contracts/membership-registry/index.js +0 -104
  58. package/lib/contracts/types.d.ts +0 -10
  59. package/lib/contracts/types.js +0 -12
  60. package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
  61. package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
  62. package/lib/harness/index.d.ts +0 -58
  63. package/lib/harness/index.js +0 -73
  64. package/lib/registry.d.ts +0 -118
  65. package/lib/registry.js +0 -184
@@ -1,21 +1,19 @@
1
1
  import { FangornConfig } from "../config.js";
2
2
  import { PinataBackend } from "../providers/storage/pinata.js";
3
- import { APP_REGISTRY_ABI } from "../contracts/app-registry/abi.js";
4
3
  import { DATA_REGISTRY_ABI } from "../contracts/data-registry/abi.js";
4
+ import { SETTLEMENT_REGISTRY_ABI } from "../contracts/settlement-registry/abi.js";
5
5
  import "../contracts/index.js";
6
6
  import { Fangorn } from "../fangorn.js";
7
7
  import { MemLedger, MemRegistry } from "./mem-registry.js";
8
8
  import { MemStorage } from "../engine/test-helpers.js";
9
- import { createTestClient, encodeFunctionData, getAddress, http, parseEther, publicActions, walletActions } from "viem";
10
9
  import { foundry } from "viem/chains";
10
+ import { createTestClient, encodeFunctionData, getAddress, http, parseEther, publicActions, walletActions } from "viem";
11
11
  import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
12
12
  import { spawn, spawnSync } from "node:child_process";
13
13
  import { existsSync, readFileSync } from "node:fs";
14
14
  import { resolve } from "node:path";
15
15
 
16
16
  //#region src/test/testbed.ts
17
- /** The app every client is accepted into unless told otherwise. */
18
- const TEST_APP = "test-app";
19
17
  function memoryNetwork(Registry = MemRegistry) {
20
18
  const ledger = new MemLedger();
21
19
  const storage = new MemStorage();
@@ -23,20 +21,16 @@ function memoryNetwork(Registry = MemRegistry) {
23
21
  name: "memory",
24
22
  ledger,
25
23
  storage,
26
- client(app = TEST_APP, sk = generatePrivateKey(), R = Registry) {
27
- const f = Fangorn.create({
24
+ client(sk = generatePrivateKey(), R = Registry) {
25
+ return Promise.resolve(Fangorn.create({
28
26
  privateKey: sk,
29
- appId: app ?? void 0,
30
27
  config: {
31
28
  ...FangornConfig,
32
- appRegistryFromBlock: 0n
29
+ fromBlock: 0n
33
30
  },
34
31
  storage: { backend: storage },
35
32
  registry: new R(privateKeyToAccount(sk).address, ledger)
36
- });
37
- const id = f.getAppId();
38
- if (id) ledger.members.add(`${id}/${f.getAddress().toLowerCase()}`);
39
- return Promise.resolve(f);
33
+ }));
40
34
  },
41
35
  clock: () => Promise.resolve(ledger.t),
42
36
  stop: () => void 0
@@ -52,8 +46,6 @@ const has = (cmd) => spawnSync(cmd, ["--version"]).status === 0;
52
46
  const skipChain = !(has("anvil") && has("forge") && existsSync(CONTRACTS)) && !process.env.CI;
53
47
  /** anvil's first prefunded account: the deployer, and the protocol admin. */
54
48
  const ADMIN_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
55
- /** No contract: fees are zero, so the token is never called. */
56
- const NO_TOKEN = "0x000000000000000000000000000000000000dEaD";
57
49
  async function startAnvil(chainId) {
58
50
  const anvil = spawn("anvil", [
59
51
  "--port",
@@ -81,8 +73,9 @@ async function startAnvil(chainId) {
81
73
  anvil
82
74
  };
83
75
  }
84
- function artifact(name) {
85
- const json = JSON.parse(readFileSync(`${CONTRACTS}/out/${name}.sol/${name}.json`, "utf-8"));
76
+ /** `file`: the .sol it is in, when that isn't `name`.sol. */
77
+ function artifact(name, file = name) {
78
+ const json = JSON.parse(readFileSync(`${CONTRACTS}/out/${file}.sol/${name}.json`, "utf-8"));
86
79
  return {
87
80
  abi: json.abi,
88
81
  bytecode: json.bytecode.object
@@ -97,7 +90,7 @@ function e2eStorage() {
97
90
  }
98
91
  /**
99
92
  * A fresh anvil with the contracts deployed from source, each behind its
100
- * ERC-1967 proxy as Deploy.s.sol does, and wired to each other. Fees are zero.
93
+ * ERC-1967 proxy as Deploy.s.sol does, and wired to each other.
101
94
  * Call `stop` from `afterAll`.
102
95
  */
103
96
  async function chainNetwork() {
@@ -115,8 +108,8 @@ async function chainNetwork() {
115
108
  transport: http(rpcUrl)
116
109
  }).extend(publicActions).extend(walletActions);
117
110
  const admin = privateKeyToAccount(ADMIN_KEY);
118
- const deploy = async (name, args) => {
119
- const { abi, bytecode } = artifact(name);
111
+ const deploy = async (name, args, file) => {
112
+ const { abi, bytecode } = artifact(name, file);
120
113
  const hash = await chain.deployContract({
121
114
  account: admin,
122
115
  abi,
@@ -128,34 +121,27 @@ async function chainNetwork() {
128
121
  return getAddress(contractAddress);
129
122
  };
130
123
  const proxied = async (name, init) => deploy("ERC1967Proxy", [await deploy(name, []), init]);
131
- const apps = await proxied("AppRegistry", encodeFunctionData({
132
- abi: APP_REGISTRY_ABI,
124
+ const data = await proxied("DataRegistry", encodeFunctionData({
125
+ abi: DATA_REGISTRY_ABI,
126
+ functionName: "initialize",
127
+ args: [admin.address]
128
+ }));
129
+ const usdc = await deploy("MockUSDC", [], "Mocks");
130
+ const settlement = await proxied("SettlementRegistry", encodeFunctionData({
131
+ abi: SETTLEMENT_REGISTRY_ABI,
133
132
  functionName: "initialize",
134
133
  args: [
135
134
  admin.address,
136
- NO_TOKEN,
137
- 0n,
138
- 30n * 24n * 3600n
135
+ usdc,
136
+ await deploy("MockSemaphore", [], "Mocks")
139
137
  ]
140
138
  }));
141
- const data = await proxied("DataRegistry", encodeFunctionData({
142
- abi: DATA_REGISTRY_ABI,
143
- functionName: "initialize",
144
- args: [admin.address, apps]
145
- }));
146
- await chain.waitForTransactionReceipt({ hash: await chain.writeContract({
147
- account: admin,
148
- address: apps,
149
- abi: APP_REGISTRY_ABI,
150
- functionName: "setDataRegistry",
151
- args: [data]
152
- }) });
153
139
  const config = {
154
140
  ...FangornConfig,
155
141
  rpcUrl,
156
- appRegistryContractAddress: apps,
157
142
  dataRegistryContractAddress: data,
158
- appRegistryFromBlock: 0n
143
+ settlementRegistryContractAddress: settlement,
144
+ fromBlock: 0n
159
145
  };
160
146
  const storage = e2eStorage();
161
147
  /** A wallet with gas: `sk`, or a new one. */
@@ -166,37 +152,24 @@ async function chainNetwork() {
166
152
  });
167
153
  return sk;
168
154
  };
169
- /** A client and nothing more: no app claimed or accepted into. */
170
- const raw = async (app, sk) => Fangorn.create({
155
+ /** A client with gas. */
156
+ const client = async (sk) => Fangorn.create({
171
157
  privateKey: await wallet(sk),
172
158
  config,
173
- appId: app,
174
159
  storage: { backend: storage }
175
160
  });
176
- const owners = /* @__PURE__ */ new Map();
177
161
  return {
178
162
  name: "chain",
179
163
  storage,
180
164
  config,
181
165
  chain,
182
- adminKey: ADMIN_KEY,
166
+ usdc,
183
167
  wallet,
184
- raw,
185
- owner: (app = TEST_APP) => owners.get(app),
186
- async client(app = TEST_APP, sk) {
187
- const f = await raw(app ?? void 0, sk);
188
- if (app === null) return f;
189
- const owner = owners.get(app);
190
- if (!owner) {
191
- await f.getAppRegistry().registerApp();
192
- owners.set(app, f);
193
- } else await owner.getAppRegistry().acceptPublisher(f.getAddress());
194
- return f;
195
- },
168
+ client,
196
169
  clock: () => chain.getBlockNumber({ cacheTime: 0 }),
197
170
  stop: () => anvil.kill()
198
171
  };
199
172
  }
200
173
 
201
174
  //#endregion
202
- export { MemLedger, MemRegistry, TEST_APP, chainNetwork, memoryNetwork, skipChain };
175
+ export { MemLedger, MemRegistry, chainNetwork, memoryNetwork, skipChain };
@@ -1,21 +1,17 @@
1
- import { AppConfig } from "../config.js";
2
- import { Registry } from "../registry.js";
1
+ import { NetworkConfig } from "../config.js";
2
+ import { Registry } from "../contracts/data-registry/index.js";
3
+ import "../contracts/index.js";
3
4
  import { MetadataStorage } from "../providers/storage/types.js";
4
5
  import { Hex, PublicClient, WalletClient } from "viem";
5
6
 
6
7
  //#region src/types/index.d.ts
7
8
  interface FangornContext {
8
- config: AppConfig;
9
+ config: NetworkConfig;
9
10
  walletClient: WalletClient;
10
11
  publicClient: PublicClient;
11
12
  metadataStorage: MetadataStorage | undefined;
12
- /** Heads, membership, exclusions and logs (WHITEPAPER_1 §3.2). */
13
+ /** Heads and the update log (WHITEPAPER_1 §3.2). */
13
14
  registry: Registry;
14
- /**
15
- * The app this client reads and publishes under (the paper's context). Unset,
16
- * reads are each publisher's latest head, and hosted uploads are refused.
17
- */
18
- appId: Hex | undefined;
19
15
  }
20
16
  type StorageConfig = {
21
17
  pinata: {
@@ -32,8 +28,7 @@ type StorageConfig = {
32
28
  };
33
29
  interface FangornCreateOptions {
34
30
  storage?: StorageConfig;
35
- config?: AppConfig;
36
- appId?: string;
31
+ config?: NetworkConfig;
37
32
  privateKey?: Hex;
38
33
  walletClient?: WalletClient;
39
34
  registry?: Registry;
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
-
2
1
  {
3
2
  "name": "@fangorn-network/sdk",
4
- "version": "2026.10.27-dev",
3
+ "version": "2026.11.03-dev",
5
4
  "description": "decentralized, verifiable and platformless content management framework",
6
5
  "repository": {
7
6
  "type": "git",
@@ -23,7 +22,6 @@
23
22
  "prepare": "husky",
24
23
  "test": "dotenvx run -f .env -- vitest run",
25
24
  "test:e2e": "dotenvx run -f .env -- vitest run --config vitest.e2e.config.ts",
26
- "test:admin": "vitest run --config vitest.e2e.config.ts src/e2e/admin.e2e.test.ts",
27
25
  "test:live": "vitest run --config vitest.e2e.config.ts src/e2e/live.e2e.test.ts",
28
26
  "abis": "scripts/gen-abis.sh",
29
27
  "tsc": "tsc",
@@ -70,7 +68,6 @@
70
68
  "dotenv": "^17.2.3",
71
69
  "multiformats": "^14.0.0",
72
70
  "pinata": "^2.5.2",
73
- "solc": "^0.8.28",
74
71
  "viem": "^2.47.1"
75
72
  },
76
73
  "overrides": {