@fangorn-network/sdk 2026.8.12-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.
Files changed (40) hide show
  1. package/README.md +175 -62
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +348 -17
  4. package/lib/cli/index.d.ts +13 -13
  5. package/lib/config.d.ts +28 -352
  6. package/lib/config.js +11 -20
  7. package/lib/contracts/app-registry/abi.d.ts +509 -0
  8. package/lib/contracts/app-registry/abi.js +575 -0
  9. package/lib/contracts/app-registry/index.d.ts +120 -0
  10. package/lib/contracts/app-registry/index.js +266 -0
  11. package/lib/contracts/data-registry/abi.d.ts +124 -125
  12. package/lib/contracts/data-registry/abi.js +145 -142
  13. package/lib/contracts/data-registry/index.d.ts +20 -27
  14. package/lib/contracts/data-registry/index.js +32 -78
  15. package/lib/contracts/index.d.ts +8 -3
  16. package/lib/contracts/index.js +8 -3
  17. package/lib/contracts/logs.d.ts +18 -0
  18. package/lib/contracts/logs.js +25 -0
  19. package/lib/contracts/settlement-registry/abi.d.ts +430 -11
  20. package/lib/contracts/settlement-registry/abi.js +528 -41
  21. package/lib/contracts/settlement-registry/index.d.ts +148 -10
  22. package/lib/contracts/settlement-registry/index.js +233 -9
  23. package/lib/contracts/subscription-registry/abi.d.ts +179 -0
  24. package/lib/contracts/subscription-registry/abi.js +195 -0
  25. package/lib/contracts/subscription-registry/index.d.ts +59 -0
  26. package/lib/contracts/subscription-registry/index.js +116 -0
  27. package/lib/contracts/types.d.ts +8 -0
  28. package/lib/contracts/types.js +10 -0
  29. package/lib/contracts/write.d.ts +27 -0
  30. package/lib/contracts/write.js +55 -0
  31. package/lib/crypto/encryption.js +4 -4
  32. package/lib/engine/index.d.ts +14 -12
  33. package/lib/engine/index.js +13 -7
  34. package/lib/fangorn.d.ts +71 -6
  35. package/lib/fangorn.js +86 -7
  36. package/lib/index.d.ts +9 -4
  37. package/lib/index.js +9 -4
  38. package/lib/test/testbed.js +9 -3
  39. package/lib/types/index.d.ts +6 -0
  40. package/package.json +73 -85
@@ -0,0 +1,195 @@
1
+ //#region src/contracts/subscription-registry/abi.ts
2
+ /**
3
+ * The SubscriptionRegistry: the publisher-side paywall for storage.
4
+ *
5
+ * A publisher pays a USDC fee to open or renew; the off-chain upload gate reads
6
+ * `access(publisher)` — `(registered, paidAt)` — and applies its own free-tier and
7
+ * active-window policy. The contract deliberately stores no expiry: the window is a
8
+ * policy decision the gate owns, so changing it does not need a migration.
9
+ *
10
+ * `registered` is a cross-call to the DataRegistry, so this contract never
11
+ * duplicates publisher registration; it only prices storage on top of it.
12
+ *
13
+ * Generated from `cargo stylus export-abi --json`; the events are appended by hand
14
+ * because export-abi does not emit `sol!` event definitions.
15
+ */
16
+ const SUBSCRIPTION_REGISTRY_ABI = [
17
+ {
18
+ "inputs": [{
19
+ "internalType": "address",
20
+ "name": "publisher",
21
+ "type": "address"
22
+ }],
23
+ "name": "access",
24
+ "outputs": [{
25
+ "internalType": "bool",
26
+ "name": "",
27
+ "type": "bool"
28
+ }, {
29
+ "internalType": "uint64",
30
+ "name": "",
31
+ "type": "uint64"
32
+ }],
33
+ "stateMutability": "view",
34
+ "type": "function"
35
+ },
36
+ {
37
+ "inputs": [],
38
+ "name": "admin",
39
+ "outputs": [{
40
+ "internalType": "address",
41
+ "name": "",
42
+ "type": "address"
43
+ }],
44
+ "stateMutability": "view",
45
+ "type": "function"
46
+ },
47
+ {
48
+ "inputs": [],
49
+ "name": "dataRegistry",
50
+ "outputs": [{
51
+ "internalType": "address",
52
+ "name": "",
53
+ "type": "address"
54
+ }],
55
+ "stateMutability": "view",
56
+ "type": "function"
57
+ },
58
+ {
59
+ "inputs": [{
60
+ "internalType": "address",
61
+ "name": "registry",
62
+ "type": "address"
63
+ }],
64
+ "name": "setDataRegistry",
65
+ "outputs": [],
66
+ "stateMutability": "nonpayable",
67
+ "type": "function"
68
+ },
69
+ {
70
+ "inputs": [{
71
+ "internalType": "uint256",
72
+ "name": "fee",
73
+ "type": "uint256"
74
+ }],
75
+ "name": "setSubscriptionFee",
76
+ "outputs": [],
77
+ "stateMutability": "nonpayable",
78
+ "type": "function"
79
+ },
80
+ {
81
+ "inputs": [{
82
+ "internalType": "address",
83
+ "name": "token",
84
+ "type": "address"
85
+ }],
86
+ "name": "setUsdc",
87
+ "outputs": [],
88
+ "stateMutability": "nonpayable",
89
+ "type": "function"
90
+ },
91
+ {
92
+ "inputs": [],
93
+ "name": "subscribe",
94
+ "outputs": [],
95
+ "stateMutability": "nonpayable",
96
+ "type": "function"
97
+ },
98
+ {
99
+ "inputs": [{
100
+ "internalType": "address",
101
+ "name": "publisher",
102
+ "type": "address"
103
+ }],
104
+ "name": "subscribedAt",
105
+ "outputs": [{
106
+ "internalType": "uint64",
107
+ "name": "",
108
+ "type": "uint64"
109
+ }],
110
+ "stateMutability": "view",
111
+ "type": "function"
112
+ },
113
+ {
114
+ "inputs": [],
115
+ "name": "subscriptionFee",
116
+ "outputs": [{
117
+ "internalType": "uint256",
118
+ "name": "",
119
+ "type": "uint256"
120
+ }],
121
+ "stateMutability": "view",
122
+ "type": "function"
123
+ },
124
+ {
125
+ "inputs": [],
126
+ "name": "usdc",
127
+ "outputs": [{
128
+ "internalType": "address",
129
+ "name": "",
130
+ "type": "address"
131
+ }],
132
+ "stateMutability": "view",
133
+ "type": "function"
134
+ },
135
+ {
136
+ "inputs": [{
137
+ "internalType": "address",
138
+ "name": "to",
139
+ "type": "address"
140
+ }, {
141
+ "internalType": "uint256",
142
+ "name": "amount",
143
+ "type": "uint256"
144
+ }],
145
+ "name": "withdrawEth",
146
+ "outputs": [],
147
+ "stateMutability": "nonpayable",
148
+ "type": "function"
149
+ },
150
+ {
151
+ "inputs": [{
152
+ "internalType": "address",
153
+ "name": "to",
154
+ "type": "address"
155
+ }, {
156
+ "internalType": "uint256",
157
+ "name": "amount",
158
+ "type": "uint256"
159
+ }],
160
+ "name": "withdrawUsdc",
161
+ "outputs": [],
162
+ "stateMutability": "nonpayable",
163
+ "type": "function"
164
+ },
165
+ {
166
+ "type": "event",
167
+ "name": "Subscribed",
168
+ "anonymous": false,
169
+ "inputs": [{
170
+ "type": "address",
171
+ "name": "publisher",
172
+ "internalType": "address",
173
+ "indexed": true
174
+ }, {
175
+ "type": "uint64",
176
+ "name": "paidAt",
177
+ "internalType": "uint64",
178
+ "indexed": false
179
+ }]
180
+ },
181
+ {
182
+ "type": "event",
183
+ "name": "SubscriptionFeeChanged",
184
+ "anonymous": false,
185
+ "inputs": [{
186
+ "type": "uint256",
187
+ "name": "fee",
188
+ "internalType": "uint256",
189
+ "indexed": false
190
+ }]
191
+ }
192
+ ];
193
+
194
+ //#endregion
195
+ export { SUBSCRIPTION_REGISTRY_ABI };
@@ -0,0 +1,59 @@
1
+ import { Address, Hash, PublicClient, WalletClient } from "viem";
2
+
3
+ //#region src/contracts/subscription-registry/index.d.ts
4
+ /** What the upload gate needs to decide whether to serve a publisher. */
5
+ interface SubscriptionAccess {
6
+ /** Registered in the DataRegistry. Read here via cross-call, so it is never stale. */
7
+ registered: boolean;
8
+ /** Unix seconds of the last payment, or 0 if they never subscribed. */
9
+ paidAt: bigint;
10
+ }
11
+ /**
12
+ * Client for the SubscriptionRegistry — the publisher-side storage paywall.
13
+ *
14
+ * Deliberately does NOT decide whether a subscription is currently valid. The
15
+ * contract stores only when it was last paid; the active window and any free tier
16
+ * are the gate's policy, and keeping them off-chain means changing them is a config
17
+ * edit rather than a redeploy. `isActiveAt` is offered as the obvious default, with
18
+ * the window passed in.
19
+ */
20
+ declare class SubscriptionRegistryClient {
21
+ private contractAddress;
22
+ private publicClient;
23
+ private walletClient?;
24
+ constructor(contractAddress: Address, publicClient: PublicClient, walletClient?: WalletClient | undefined);
25
+ getAddress(): Address;
26
+ private executeWrite;
27
+ /**
28
+ * Open or renew this wallet's subscription.
29
+ *
30
+ * The fee is pulled in USDC, so the caller must have `approve`d this contract
31
+ * for at least `subscriptionFee()` first — otherwise the call reverts
32
+ * `SubscriptionFeeRequired`, which reads like a pricing error but is really an
33
+ * allowance one. Renewing while still active is allowed and simply re-stamps
34
+ * the timestamp, so there is no window to lose by renewing early.
35
+ */
36
+ subscribe(): Promise<Hash>;
37
+ /** The single oracle the upload gate reads. */
38
+ access(publisher: Address): Promise<SubscriptionAccess>;
39
+ /**
40
+ * Registered, paid, and inside `windowSeconds` of that payment — the whole
41
+ * gate policy in one call. `now` is injectable so a caller can evaluate against
42
+ * block time rather than wall-clock skew.
43
+ */
44
+ isActiveAt(publisher: Address, windowSeconds: bigint, now?: bigint): Promise<boolean>;
45
+ subscribedAt(publisher: Address): Promise<bigint>;
46
+ /** The fee in USDC's smallest unit (6 decimals), not wei. */
47
+ subscriptionFee(): Promise<bigint>;
48
+ usdc(): Promise<Address>;
49
+ /** The DataRegistry this contract cross-calls for `isRegistered`. */
50
+ dataRegistry(): Promise<Address>;
51
+ admin(): Promise<Address>;
52
+ setSubscriptionFee(fee: bigint): Promise<Hash>;
53
+ setUsdc(token: Address): Promise<Hash>;
54
+ setDataRegistry(registry: Address): Promise<Hash>;
55
+ withdrawUsdc(to: Address, amount: bigint): Promise<Hash>;
56
+ withdrawEth(to: Address, amount: bigint): Promise<Hash>;
57
+ }
58
+ //#endregion
59
+ export { SubscriptionAccess, SubscriptionRegistryClient };
@@ -0,0 +1,116 @@
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 };
@@ -0,0 +1,8 @@
1
+ //#region src/contracts/types.d.ts
2
+ declare enum PublisherStatus {
3
+ UNREGISTERED = 0,
4
+ ACTIVE = 1,
5
+ SUSPENDED = 2,
6
+ }
7
+ //#endregion
8
+ export { PublisherStatus };
@@ -0,0 +1,10 @@
1
+ //#region src/contracts/types.ts
2
+ let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
3
+ PublisherStatus$1[PublisherStatus$1["UNREGISTERED"] = 0] = "UNREGISTERED";
4
+ PublisherStatus$1[PublisherStatus$1["ACTIVE"] = 1] = "ACTIVE";
5
+ PublisherStatus$1[PublisherStatus$1["SUSPENDED"] = 2] = "SUSPENDED";
6
+ return PublisherStatus$1;
7
+ }({});
8
+
9
+ //#endregion
10
+ export { PublisherStatus };
@@ -0,0 +1,27 @@
1
+ import { Abi, Address, Hash, PublicClient, WalletClient } from "viem";
2
+
3
+ //#region src/contracts/write.d.ts
4
+
5
+ /**
6
+ * The one write path every contract client shares.
7
+ *
8
+ * Each client used to carry its own copy of this, which meant four places to fix
9
+ * whenever the gas or fee policy moved. The type-safe per-function argument
10
+ * checking still happens at the call site, in each client's thin `executeWrite`
11
+ * wrapper — only the body lives here.
12
+ *
13
+ * Two deliberate choices, both about transactions that would otherwise silently
14
+ * fail on a live L2:
15
+ *
16
+ * - **30% gas headroom.** The estimate is taken against the current state; by the
17
+ * time the transaction lands the state has moved. Unused gas is refunded, so
18
+ * the headroom is free and running out of it is not.
19
+ * - **3x maxFeePerGas.** This is a ceiling, not a payment — you pay
20
+ * base + priority. Quoting it tightly is how a transaction gets stuck when the
21
+ * base fee ticks up between estimate and inclusion.
22
+ */
23
+ declare function sendWrite(publicClient: PublicClient, walletClient: WalletClient, address: Address, abi: Abi, functionName: string, args: readonly unknown[], value?: bigint): Promise<Hash>;
24
+ /** Guard for clients that accept a read-only construction. */
25
+ declare function requireWallet(walletClient: WalletClient | undefined, what: string): WalletClient;
26
+ //#endregion
27
+ export { requireWallet, sendWrite };
@@ -0,0 +1,55 @@
1
+ //#region src/contracts/write.ts
2
+ /**
3
+ * The one write path every contract client shares.
4
+ *
5
+ * Each client used to carry its own copy of this, which meant four places to fix
6
+ * whenever the gas or fee policy moved. The type-safe per-function argument
7
+ * checking still happens at the call site, in each client's thin `executeWrite`
8
+ * wrapper — only the body lives here.
9
+ *
10
+ * Two deliberate choices, both about transactions that would otherwise silently
11
+ * fail on a live L2:
12
+ *
13
+ * - **30% gas headroom.** The estimate is taken against the current state; by the
14
+ * time the transaction lands the state has moved. Unused gas is refunded, so
15
+ * the headroom is free and running out of it is not.
16
+ * - **3x maxFeePerGas.** This is a ceiling, not a payment — you pay
17
+ * base + priority. Quoting it tightly is how a transaction gets stuck when the
18
+ * base fee ticks up between estimate and inclusion.
19
+ */
20
+ async function sendWrite(publicClient, walletClient, address, abi, functionName, args, value) {
21
+ if (!walletClient.chain) throw new Error("Chain required");
22
+ if (!walletClient.account) throw new Error("Account required");
23
+ const { chain, account } = walletClient;
24
+ const fees = await publicClient.estimateFeesPerGas();
25
+ const gas = await publicClient.estimateContractGas({
26
+ address,
27
+ abi,
28
+ functionName,
29
+ args,
30
+ account,
31
+ value
32
+ });
33
+ const hash = await walletClient.writeContract({
34
+ address,
35
+ abi,
36
+ functionName,
37
+ args,
38
+ chain,
39
+ account,
40
+ gas: gas * 130n / 100n,
41
+ maxFeePerGas: fees.maxFeePerGas * 3n,
42
+ maxPriorityFeePerGas: fees.maxPriorityFeePerGas,
43
+ value
44
+ });
45
+ await publicClient.waitForTransactionReceipt({ hash });
46
+ return hash;
47
+ }
48
+ /** Guard for clients that accept a read-only construction. */
49
+ function requireWallet(walletClient, what) {
50
+ if (!walletClient) throw new Error(`${what} requires a wallet client; this client is read-only`);
51
+ return walletClient;
52
+ }
53
+
54
+ //#endregion
55
+ export { requireWallet, sendWrite };
@@ -11,7 +11,7 @@ const GADGET_WORKER_USDC_V1 = "worker-usdc-v1";
11
11
  /** Length of an X25519 public key, in bytes. */
12
12
  const X25519_PUBKEY_LENGTH = 32;
13
13
  const utf8 = (s) => new TextEncoder().encode(s);
14
- function concat(...parts) {
14
+ function concat$1(...parts) {
15
15
  const total = parts.reduce((n, p) => n + p.length, 0);
16
16
  const out = new Uint8Array(total);
17
17
  let off = 0;
@@ -23,7 +23,7 @@ function concat(...parts) {
23
23
  }
24
24
  const hkdfSha256 = (ikm, salt, info, length) => hkdf(sha256, ikm, salt, info, length);
25
25
  const sha256Hex = (bytes) => bytesToHex(sha256(bytes));
26
- const sealInfo = (resourceId) => concat(hexToBytes(resourceId), utf8(":sealed"));
26
+ const sealInfo = (resourceId) => concat$1(hexToBytes(resourceId), utf8(":sealed"));
27
27
  /**
28
28
  * worker-usdc-v1 seal: ephemeral-static ECDH to the worker's static key, keyed
29
29
  * to the resourceId.
@@ -38,7 +38,7 @@ function seal(plaintext, workerPubkey, resourceId) {
38
38
  const ephPub = x25519.getPublicKey(ephSec);
39
39
  const aesKey = hkdfSha256(x25519.getSharedSecret(ephSec, workerPubkey), void 0, sealInfo(resourceId), 32);
40
40
  const nonce = getRandomValues(new Uint8Array(GCM_NONCE_LENGTH));
41
- return concat(ephPub, nonce, aesGcmEncrypt(aesKey, plaintext, nonce));
41
+ return concat$1(ephPub, nonce, aesGcmEncrypt(aesKey, plaintext, nonce));
42
42
  }
43
43
  /**
44
44
  * Inverse of {@link seal}. Recovers the plaintext given the worker's static
@@ -62,7 +62,7 @@ function unseal(ciphertext, workerSecret, resourceId) {
62
62
  function sealSelf(plaintext, ownSecret, resourceId) {
63
63
  const aesKey = hkdfSha256(ownSecret, void 0, sealInfo(resourceId), 32);
64
64
  const nonce = getRandomValues(new Uint8Array(GCM_NONCE_LENGTH));
65
- return concat(nonce, aesGcmEncrypt(aesKey, plaintext, nonce));
65
+ return concat$1(nonce, aesGcmEncrypt(aesKey, plaintext, nonce));
66
66
  }
67
67
  /** Inverse of {@link sealSelf}. */
68
68
  function unsealSelf(ciphertext, ownSecret, resourceId) {
@@ -44,17 +44,20 @@ interface NamespaceContents {
44
44
  }[];
45
45
  edges: Edge[];
46
46
  }
47
- /** Net change to one namespace between two on-chain roots (see `namespaceDiff`). */
47
+ /** Namespace diff between a namespace's state graph */
48
48
  interface NamespaceDiff {
49
- /** Vertices new vs. the old root, decoded to their payloads. */
50
49
  addedVertices: NamespaceContents["vertices"];
51
- /** Edges new vs. the old root. */
52
50
  addedEdges: Edge[];
53
- /** CIDs of vertices present at the old root but gone at the new one. */
54
51
  removedVertexCids: string[];
55
- /** Edges present at the old root but gone at the new one. */
56
52
  removedEdges: Edge[];
57
53
  }
54
+ /**
55
+ * The Metagraph registry is a class for building and validating knowledge graphs
56
+ *
57
+ * The vertices each represent a unique piece of data, while the edges
58
+ * represent the relationships that connect them into a graph.
59
+ *
60
+ */
58
61
  declare class MetagraphRegistry {
59
62
  private vertexSchemas;
60
63
  private edgeSchemas;
@@ -70,15 +73,11 @@ declare class MetagraphRegistry {
70
73
  * map block, so this is just a sanity bound keeping that block small and
71
74
  * rejecting garbage input early.
72
75
  */
76
+ declare const MAX_NAMESPACE_LENGTH = 256;
73
77
  /**
74
- * The 32-byte root a commit settles to on-chain.
75
- *
76
- * The contract stores the commit CID's bare multihash digest — NOT a hash of the
77
- * CID. Re-hashing here would produce a root that resolves to nothing, so this is
78
- * the one encoding every caller must share rather than re-derive.
78
+ * The root of the graph, committed to IPFS, as hex
79
79
  */
80
80
  declare function rootHexFromCid(commitCid: CID): Hex;
81
- declare const MAX_NAMESPACE_LENGTH = 256;
82
81
  /** Namespaces must be non-empty strings whose length does not exceed MAX_NAMESPACE_LENGTH */
83
82
  declare function assertValidNamespace(namespace: NamespaceID): void;
84
83
  /** One line of a commit's diff against its first parent. */
@@ -172,6 +171,9 @@ declare class FangornEngine {
172
171
  /** The full vertex/edge link sets one commit records for `namespace`. */
173
172
  private treeLinksAt;
174
173
  /**
174
+ * TODO: revisit the storage model
175
+ * Q: what if CAR is not supported?
176
+ *
175
177
  * Build a new commit on top of `base` — entirely in memory, then persisted
176
178
  * as exactly TWO uploads: one CAR file holding every block this commit
177
179
  * introduced (git's packfile), and the small commit block itself (stored
@@ -228,7 +230,7 @@ declare class FangornEngine {
228
230
  namespaceDiff(oldRootHex: string | null, newRootHex: string, namespace: NamespaceID): Promise<NamespaceDiff>;
229
231
  /** Diff a commit against its first parent, across every namespace. */
230
232
  diffCommit(commitCid: CID): Promise<CommitDiff>;
231
- /** Has this publisher committed to this namespace on-chain yet? */
233
+ /** check if the namespace already exists (head resolves) */
232
234
  namespaceExists(namespace: NamespaceID, publisher: Address): Promise<boolean>;
233
235
  /** Lists every vertex and edge currently committed under a namespace, resolved from the on-chain root. */
234
236
  listNamespace(namespace: NamespaceID, publisher: Address): Promise<NamespaceContents>;
@@ -5,6 +5,13 @@ import { sha256 } from "multiformats/hashes/sha2";
5
5
  import * as Digest from "multiformats/hashes/digest";
6
6
 
7
7
  //#region src/engine/index.ts
8
+ /**
9
+ * The Metagraph registry is a class for building and validating knowledge graphs
10
+ *
11
+ * The vertices each represent a unique piece of data, while the edges
12
+ * represent the relationships that connect them into a graph.
13
+ *
14
+ */
8
15
  var MetagraphRegistry = class {
9
16
  vertexSchemas = /* @__PURE__ */ new Map();
10
17
  edgeSchemas = /* @__PURE__ */ new Set();
@@ -35,17 +42,13 @@ const ZERO_BYTES32 = "0x00000000000000000000000000000000000000000000000000000000
35
42
  * map block, so this is just a sanity bound keeping that block small and
36
43
  * rejecting garbage input early.
37
44
  */
45
+ const MAX_NAMESPACE_LENGTH = 256;
38
46
  /**
39
- * The 32-byte root a commit settles to on-chain.
40
- *
41
- * The contract stores the commit CID's bare multihash digest — NOT a hash of the
42
- * CID. Re-hashing here would produce a root that resolves to nothing, so this is
43
- * the one encoding every caller must share rather than re-derive.
47
+ * The root of the graph, committed to IPFS, as hex
44
48
  */
45
49
  function rootHexFromCid(commitCid) {
46
50
  return `0x${Buffer.from(commitCid.multihash.digest).toString("hex")}`;
47
51
  }
48
- const MAX_NAMESPACE_LENGTH = 256;
49
52
  /** Namespaces must be non-empty strings whose length does not exceed MAX_NAMESPACE_LENGTH */
50
53
  function assertValidNamespace(namespace) {
51
54
  if (typeof namespace !== "string" || namespace.length === 0) throw new Error("namespace must be a non-empty string");
@@ -178,6 +181,9 @@ var FangornEngine = class {
178
181
  };
179
182
  }
180
183
  /**
184
+ * TODO: revisit the storage model
185
+ * Q: what if CAR is not supported?
186
+ *
181
187
  * Build a new commit on top of `base` — entirely in memory, then persisted
182
188
  * as exactly TWO uploads: one CAR file holding every block this commit
183
189
  * introduced (git's packfile), and the small commit block itself (stored
@@ -430,7 +436,7 @@ var FangornEngine = class {
430
436
  removed: removed.sort()
431
437
  };
432
438
  }
433
- /** Has this publisher committed to this namespace on-chain yet? */
439
+ /** check if the namespace already exists (head resolves) */
434
440
  async namespaceExists(namespace, publisher) {
435
441
  const head = await this.resolveHeadCommit(publisher, namespace);
436
442
  if (!head) return false;