@fangorn-network/sdk 2026.10.28 → 2026.11.3

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 (68) hide show
  1. package/README.md +37 -653
  2. package/lib/cli/cli.js +46 -357
  3. package/lib/cli/index.d.ts +1 -4
  4. package/lib/cli/index.js +2 -20
  5. package/lib/cli/sell.d.ts +28 -0
  6. package/lib/cli/sell.js +95 -0
  7. package/lib/config.d.ts +163 -226
  8. package/lib/config.js +8 -35
  9. package/lib/contracts/data-registry/abi.d.ts +206 -6
  10. package/lib/contracts/data-registry/abi.js +415 -186
  11. package/lib/contracts/data-registry/index.d.ts +126 -2
  12. package/lib/contracts/data-registry/index.js +174 -1
  13. package/lib/contracts/index.d.ts +4 -7
  14. package/lib/contracts/index.js +4 -7
  15. package/lib/contracts/logs.d.ts +1 -1
  16. package/lib/contracts/logs.js +1 -1
  17. package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +288 -637
  18. package/lib/contracts/settlement-registry/abi.js +947 -0
  19. package/lib/contracts/settlement-registry/index.d.ts +141 -0
  20. package/lib/contracts/settlement-registry/index.js +209 -0
  21. package/lib/crypto/aes.d.ts +2 -2
  22. package/lib/crypto/aes.js +4 -4
  23. package/lib/crypto/encryption.d.ts +8 -109
  24. package/lib/crypto/encryption.js +16 -114
  25. package/lib/crypto/paid.d.ts +104 -0
  26. package/lib/crypto/paid.js +147 -0
  27. package/lib/engine/index.d.ts +23 -12
  28. package/lib/engine/index.js +68 -29
  29. package/lib/engine/records.d.ts +4 -7
  30. package/lib/engine/records.js +6 -6
  31. package/lib/engine/test-helpers.d.ts +2 -3
  32. package/lib/engine/test-helpers.js +7 -5
  33. package/lib/erc8004.js +7 -10
  34. package/lib/fangorn.d.ts +65 -96
  35. package/lib/fangorn.js +110 -168
  36. package/lib/feed.d.ts +7 -8
  37. package/lib/feed.js +7 -8
  38. package/lib/index.d.ts +10 -13
  39. package/lib/index.js +10 -13
  40. package/lib/providers/storage/signed-url.d.ts +2 -10
  41. package/lib/providers/storage/signed-url.js +5 -15
  42. package/lib/providers/storage/types.d.ts +1 -1
  43. package/lib/providers/storage/utils.js +5 -3
  44. package/lib/test/key-server.d.ts +12 -0
  45. package/lib/test/key-server.js +30 -0
  46. package/lib/test/mem-registry.d.ts +14 -19
  47. package/lib/test/mem-registry.js +44 -37
  48. package/lib/test/sdk-suite.d.ts +1 -4
  49. package/lib/test/sdk-suite.js +16 -87
  50. package/lib/test/testbed.d.ts +35 -45
  51. package/lib/test/testbed.js +29 -56
  52. package/lib/types/index.d.ts +6 -11
  53. package/package.json +2 -5
  54. package/lib/contracts/app-registry/abi.d.ts +0 -1306
  55. package/lib/contracts/app-registry/abi.js +0 -1493
  56. package/lib/contracts/app-registry/index.d.ts +0 -200
  57. package/lib/contracts/app-registry/index.js +0 -325
  58. package/lib/contracts/membership-registry/abi.js +0 -1333
  59. package/lib/contracts/membership-registry/index.d.ts +0 -79
  60. package/lib/contracts/membership-registry/index.js +0 -104
  61. package/lib/contracts/types.d.ts +0 -8
  62. package/lib/contracts/types.js +0 -10
  63. package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
  64. package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
  65. package/lib/harness/index.d.ts +0 -58
  66. package/lib/harness/index.js +0 -73
  67. package/lib/registry.d.ts +0 -118
  68. package/lib/registry.js +0 -184
@@ -0,0 +1,95 @@
1
+ import { repoId } from "../contracts/data-registry/index.js";
2
+ import { WHOLE_REPO, recordKey, termsToJson } from "../contracts/settlement-registry/index.js";
3
+ import { makeDeposit, newRepoKey, requestKey, sealField } from "../crypto/paid.js";
4
+ import { hexToBytes } from "viem";
5
+
6
+ //#region src/cli/sell.ts
7
+ /**
8
+ * Make records sellable: seal `fields` of each record (as JSON, under `field-v1`), and add the
9
+ * publisher's signed terms under "@terms". Returns the records to commit, plus the repo's
10
+ * `@deposit/<generation>` record if the repo had none for this generation.
11
+ *
12
+ * The deposit is read from the repo's on-chain head. Commit and push this before sealing more:
13
+ * a second call before the push makes a second deposit, and the first commit's fields would
14
+ * only open under the deposit it replaced.
15
+ */
16
+ async function sealRecords(fangorn, repo, records, o) {
17
+ const settlement = fangorn.getSettlementRegistry();
18
+ const publisher = fangorn.getAddress();
19
+ const rid = repoId(repo);
20
+ const generation = await settlement.generationOf(publisher, rid);
21
+ const scope = {
22
+ chainId: fangorn.getConfig().chain.id,
23
+ registry: settlement.getAddress(),
24
+ publisher,
25
+ repo: rid,
26
+ generation
27
+ };
28
+ const depositId = `@deposit/${generation.toString()}`;
29
+ const wallet = fangorn.getWalletClient();
30
+ const signer = { signMessage: (m) => wallet.signMessage({
31
+ account: wallet.account ?? publisher,
32
+ ...m
33
+ }) };
34
+ const out = [];
35
+ let kRepo;
36
+ const existing = (await fangorn.engine.readRecord(publisher, repo, depositId).catch(() => null))?.payload;
37
+ if (existing) kRepo = await requestKey({
38
+ deposit: existing,
39
+ key: WHOLE_REPO,
40
+ signer
41
+ });
42
+ else {
43
+ if (!o.keyServer) throw new Error("no key server: pass keyServer (CLI: --key-server)");
44
+ const res = await fetch(`${o.keyServer}/pubkey`);
45
+ if (!res.ok) throw new Error(`key server ${o.keyServer}/pubkey: HTTP ${res.status.toString()}`);
46
+ const { pubkey } = await res.json();
47
+ kRepo = newRepoKey();
48
+ const deposit = makeDeposit({
49
+ kRepo,
50
+ keyServerPubkey: hexToBytes(pubkey),
51
+ keyServer: o.keyServer,
52
+ scope
53
+ });
54
+ out.push({
55
+ id: depositId,
56
+ type: "deposit",
57
+ payload: deposit
58
+ });
59
+ }
60
+ const enc = new TextEncoder();
61
+ for (const r of records) {
62
+ const payload = { ...r.payload };
63
+ const paid = o.fields.filter((f) => f in payload);
64
+ if (!paid.length) {
65
+ out.push(r);
66
+ continue;
67
+ }
68
+ if (!r.id) throw new Error(`a record with paid fields needs an id (type ${r.type})`);
69
+ const key = recordKey(r.id);
70
+ for (const field of paid) payload[field] = await sealField({
71
+ plaintext: enc.encode(JSON.stringify(payload[field])),
72
+ kRepo,
73
+ scope,
74
+ key,
75
+ field,
76
+ storage: fangorn.getStorage()
77
+ });
78
+ payload["@terms"] = termsToJson(await settlement.signTerms({
79
+ repo: rid,
80
+ key,
81
+ price: o.price,
82
+ shareBps: o.shareBps,
83
+ deadline: o.deadline,
84
+ generation
85
+ }));
86
+ out.push({
87
+ ...r,
88
+ payload
89
+ });
90
+ }
91
+ return out;
92
+ }
93
+
94
+ //#endregion
95
+ export { sealRecords };