@fangorn-network/sdk 2026.6.16 → 2026.7.1-2.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 (105) hide show
  1. package/README.md +210 -266
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/cli.js +261 -167
  4. package/lib/cli/index.d.ts +13 -651
  5. package/lib/config.d.ts +137 -792
  6. package/lib/config.js +6 -22
  7. package/lib/contracts/data-registry/abi.d.ts +38 -0
  8. package/lib/contracts/data-registry/abi.js +237 -0
  9. package/lib/contracts/data-registry/index.d.ts +81 -0
  10. package/lib/contracts/data-registry/index.js +184 -0
  11. package/lib/contracts/index.d.ts +3 -0
  12. package/lib/contracts/index.js +4 -0
  13. package/lib/crypto/aes.d.ts +26 -0
  14. package/lib/crypto/aes.js +58 -0
  15. package/lib/crypto/encryption.d.ts +53 -0
  16. package/lib/crypto/encryption.js +82 -0
  17. package/lib/{modules/encryption → crypto}/rand.d.ts +1 -1
  18. package/lib/{modules/encryption → crypto}/rand.js +1 -1
  19. package/lib/{modules/encryption → crypto}/types.d.ts +1 -1
  20. package/lib/engine/blockstore.d.ts +24 -0
  21. package/lib/engine/blockstore.js +85 -0
  22. package/lib/engine/index.d.ts +180 -0
  23. package/lib/engine/index.js +367 -0
  24. package/lib/fangorn.d.ts +149 -16
  25. package/lib/fangorn.js +256 -37
  26. package/lib/harness/examples/hackmd/build-markdown-graph.js +17 -0
  27. package/lib/harness/index.d.ts +57 -0
  28. package/lib/harness/index.js +67 -0
  29. package/lib/index.d.ts +2 -2
  30. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +218 -0
  31. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +261 -0
  32. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +156 -0
  33. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +299 -0
  34. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +532 -0
  35. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +344 -0
  36. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +137 -0
  37. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +262 -0
  38. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +150 -0
  39. package/lib/providers/storage/car.d.ts +36 -0
  40. package/lib/providers/storage/car.js +80 -0
  41. package/lib/providers/storage/pinata.d.ts +29 -1
  42. package/lib/providers/storage/pinata.js +135 -20
  43. package/lib/providers/storage/types.d.ts +25 -18
  44. package/lib/roles/repo/index.d.ts +56 -0
  45. package/lib/roles/repo/index.js +73 -0
  46. package/lib/test/car_smoke.d.ts +1 -0
  47. package/lib/test/car_smoke.js +81 -0
  48. package/lib/test/cleanup-embeddings-testdata.js +9 -38
  49. package/lib/test/setup-embeddings-testdata.d.ts +4 -6
  50. package/lib/test/setup-embeddings-testdata.js +40 -94
  51. package/lib/test/testbed.d.ts +35 -32
  52. package/lib/test/testbed.js +48 -138
  53. package/lib/types/index.d.ts +3 -19
  54. package/lib/utils/manifest.d.ts +23 -0
  55. package/lib/utils/manifest.js +77 -0
  56. package/package.json +99 -81
  57. package/lib/modules/encryption/actions.d.ts +0 -4
  58. package/lib/modules/encryption/actions.js +0 -18
  59. package/lib/modules/encryption/aes.d.ts +0 -10
  60. package/lib/modules/encryption/aes.js +0 -51
  61. package/lib/registries/datasource-registry/abi.d.ts +0 -186
  62. package/lib/registries/datasource-registry/abi.js +0 -229
  63. package/lib/registries/datasource-registry/index.d.ts +0 -39
  64. package/lib/registries/datasource-registry/index.js +0 -158
  65. package/lib/registries/index.d.ts +0 -3
  66. package/lib/registries/index.js +0 -4
  67. package/lib/registries/schema-registry/abi.d.ts +0 -218
  68. package/lib/registries/schema-registry/abi.js +0 -246
  69. package/lib/registries/schema-registry/index.d.ts +0 -34
  70. package/lib/registries/schema-registry/index.js +0 -179
  71. package/lib/registries/settlement-registry/abi.d.ts +0 -218
  72. package/lib/registries/settlement-registry/abi.js +0 -259
  73. package/lib/registries/settlement-registry/index.d.ts +0 -63
  74. package/lib/registries/settlement-registry/index.js +0 -325
  75. package/lib/registries/settlement-registry/types.d.ts +0 -54
  76. package/lib/registries/settlement-registry/types.js +0 -1
  77. package/lib/roles/consumer/index.d.ts +0 -39
  78. package/lib/roles/consumer/index.js +0 -150
  79. package/lib/roles/consumer/types.d.ts +0 -47
  80. package/lib/roles/consumer/types.js +0 -1
  81. package/lib/roles/publisher/builders/bundle.d.ts +0 -32
  82. package/lib/roles/publisher/builders/bundle.js +0 -137
  83. package/lib/roles/publisher/builders/record-set.d.ts +0 -17
  84. package/lib/roles/publisher/builders/record-set.js +0 -55
  85. package/lib/roles/publisher/builders/types.d.ts +0 -38
  86. package/lib/roles/publisher/builders/types.js +0 -1
  87. package/lib/roles/publisher/builders/utils.d.ts +0 -9
  88. package/lib/roles/publisher/builders/utils.js +0 -29
  89. package/lib/roles/publisher/encryption.d.ts +0 -18
  90. package/lib/roles/publisher/encryption.js +0 -38
  91. package/lib/roles/publisher/index.d.ts +0 -68
  92. package/lib/roles/publisher/index.js +0 -179
  93. package/lib/roles/publisher/types.d.ts +0 -114
  94. package/lib/roles/publisher/types.js +0 -1
  95. package/lib/roles/schema/index.d.ts +0 -44
  96. package/lib/roles/schema/index.js +0 -127
  97. package/lib/roles/schema/types.d.ts +0 -113
  98. package/lib/roles/schema/types.js +0 -1
  99. package/lib/roles/schema/validate.d.ts +0 -9
  100. package/lib/roles/schema/validate.js +0 -128
  101. package/lib/test/publish_mb_bundle.js +0 -296
  102. /package/lib/{modules/encryption/index.d.ts → contracts/data-registry/test.d.ts} +0 -0
  103. /package/lib/{modules/encryption/index.js → contracts/data-registry/test.js} +0 -0
  104. /package/lib/{modules/encryption → crypto}/types.js +0 -0
  105. /package/lib/{test/publish_mb_bundle.d.ts → harness/examples/hackmd/build-markdown-graph.d.ts} +0 -0
@@ -0,0 +1,53 @@
1
+ import { Hex } from "viem";
2
+
3
+ //#region src/crypto/encryption.d.ts
4
+ /** A TEE-sealed field handle: where the ciphertext lives and how to verify/decrypt it. */
5
+ interface HandleFieldInput {
6
+ "@type": "handle";
7
+ uri: string;
8
+ workerUrl: string;
9
+ encryption: {
10
+ gadget: string;
11
+ ciphertextHash: Hex;
12
+ teePubkey: Hex;
13
+ };
14
+ }
15
+ /** Length of an X25519 public key, in bytes. */
16
+ declare const X25519_PUBKEY_LENGTH = 32;
17
+ declare const sha256Hex: (bytes: Uint8Array) => Hex;
18
+ /**
19
+ * Ephemeral-static ECDH to the TEE's static key, keyed to the resourceId.
20
+ *
21
+ * ciphertext = ephemeralPub(32) || nonce(12) || aes-256-gcm-ct
22
+ *
23
+ * Only the holder of the secret matching `teePubkey` can derive the same AES
24
+ * key, and only with the matching `resourceId`.
25
+ */
26
+ declare function seal(plaintext: Uint8Array, teePubkey: Uint8Array, resourceId: Hex): Uint8Array;
27
+ /**
28
+ * Inverse of {@link seal}. Recovers the plaintext given the TEE's static secret
29
+ * and the same resourceId. This is the operation the real TEE performs after the
30
+ * settlement gate passes; exposed here for parity testing and local tooling.
31
+ */
32
+ declare function unseal(ciphertext: Uint8Array, teeSecret: Uint8Array, resourceId: Hex): Uint8Array;
33
+ interface EncryptAndUploadParams {
34
+ plaintext: Uint8Array;
35
+ /** 32-byte resource identifier the ciphertext is bound to (HKDF info + settlement key). */
36
+ resourceId: Hex;
37
+ storage: {
38
+ workerUrl: string;
39
+ authToken: string;
40
+ contentType: string;
41
+ };
42
+ /** TEE's static X25519 public key (32 bytes). */
43
+ teePubkey: Uint8Array;
44
+ gadget?: string;
45
+ }
46
+ /**
47
+ * Seal `plaintext` to the TEE, upload the opaque ciphertext to the storage
48
+ * worker, and return the manifest handle describing where to fetch it and how
49
+ * to verify/decrypt it.
50
+ */
51
+ declare function encryptAndUpload(params: EncryptAndUploadParams): Promise<HandleFieldInput>;
52
+ //#endregion
53
+ export { EncryptAndUploadParams, HandleFieldInput, X25519_PUBKEY_LENGTH, encryptAndUpload, seal, sha256Hex, unseal };
@@ -0,0 +1,82 @@
1
+ import { getRandomValues } from "./rand.js";
2
+ import { GCM_NONCE_LENGTH, aesGcmDecrypt, aesGcmEncrypt } from "./aes.js";
3
+ import { x25519 } from "../node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js";
4
+ import { bytesToHex, hexToBytes } from "viem";
5
+ import { sha256 } from "@noble/hashes/sha2.js";
6
+ import { hkdf } from "@noble/hashes/hkdf.js";
7
+
8
+ //#region src/crypto/encryption.ts
9
+ /** Length of an X25519 public key, in bytes. */
10
+ const X25519_PUBKEY_LENGTH = 32;
11
+ const utf8 = (s) => new TextEncoder().encode(s);
12
+ function concat(...parts) {
13
+ const total = parts.reduce((n, p) => n + p.length, 0);
14
+ const out = new Uint8Array(total);
15
+ let off = 0;
16
+ for (const p of parts) {
17
+ out.set(p, off);
18
+ off += p.length;
19
+ }
20
+ return out;
21
+ }
22
+ const hkdfSha256 = (ikm, salt, info, length) => hkdf(sha256, ikm, salt, info, length);
23
+ const sha256Hex = (bytes) => bytesToHex(sha256(bytes));
24
+ const sealInfo = (resourceId) => concat(hexToBytes(resourceId), utf8(":sealed"));
25
+ /**
26
+ * Ephemeral-static ECDH to the TEE's static key, keyed to the resourceId.
27
+ *
28
+ * ciphertext = ephemeralPub(32) || nonce(12) || aes-256-gcm-ct
29
+ *
30
+ * Only the holder of the secret matching `teePubkey` can derive the same AES
31
+ * key, and only with the matching `resourceId`.
32
+ */
33
+ function seal(plaintext, teePubkey, resourceId) {
34
+ const ephSec = x25519.utils.randomSecretKey();
35
+ const ephPub = x25519.getPublicKey(ephSec);
36
+ const aesKey = hkdfSha256(x25519.getSharedSecret(ephSec, teePubkey), void 0, sealInfo(resourceId), 32);
37
+ const nonce = getRandomValues(new Uint8Array(GCM_NONCE_LENGTH));
38
+ return concat(ephPub, nonce, aesGcmEncrypt(aesKey, plaintext, nonce));
39
+ }
40
+ /**
41
+ * Inverse of {@link seal}. Recovers the plaintext given the TEE's static secret
42
+ * and the same resourceId. This is the operation the real TEE performs after the
43
+ * settlement gate passes; exposed here for parity testing and local tooling.
44
+ */
45
+ function unseal(ciphertext, teeSecret, resourceId) {
46
+ const ephPub = ciphertext.slice(0, X25519_PUBKEY_LENGTH);
47
+ const nonce = ciphertext.slice(X25519_PUBKEY_LENGTH, X25519_PUBKEY_LENGTH + GCM_NONCE_LENGTH);
48
+ const aesCt = ciphertext.slice(X25519_PUBKEY_LENGTH + GCM_NONCE_LENGTH);
49
+ return aesGcmDecrypt(hkdfSha256(x25519.getSharedSecret(teeSecret, ephPub), void 0, sealInfo(resourceId), 32), aesCt, nonce);
50
+ }
51
+ /**
52
+ * Seal `plaintext` to the TEE, upload the opaque ciphertext to the storage
53
+ * worker, and return the manifest handle describing where to fetch it and how
54
+ * to verify/decrypt it.
55
+ */
56
+ async function encryptAndUpload(params) {
57
+ const { plaintext, resourceId, storage, teePubkey, gadget = "tee-aes-v1" } = params;
58
+ const ciphertext = seal(plaintext, teePubkey, resourceId);
59
+ const uploadRes = await fetch(`${storage.workerUrl}/upload`, {
60
+ method: "POST",
61
+ headers: {
62
+ Authorization: `Bearer ${storage.authToken}`,
63
+ "Content-Type": storage.contentType
64
+ },
65
+ body: ciphertext
66
+ });
67
+ if (!uploadRes.ok) throw new Error(`upload failed: ${uploadRes.status}`);
68
+ const { objectKey } = await uploadRes.json();
69
+ return {
70
+ "@type": "handle",
71
+ uri: objectKey,
72
+ workerUrl: storage.workerUrl,
73
+ encryption: {
74
+ gadget,
75
+ ciphertextHash: sha256Hex(ciphertext),
76
+ teePubkey: bytesToHex(teePubkey)
77
+ }
78
+ };
79
+ }
80
+
81
+ //#endregion
82
+ export { X25519_PUBKEY_LENGTH, encryptAndUpload, seal, sha256Hex, unseal };
@@ -1,4 +1,4 @@
1
- //#region src/modules/encryption/rand.d.ts
1
+ //#region src/crypto/rand.d.ts
2
2
  declare function getSubtleCrypto(): SubtleCrypto;
3
3
  declare function getRandomValues(array: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- //#region src/modules/encryption/rand.ts
1
+ //#region src/crypto/rand.ts
2
2
  function getCrypto() {
3
3
  if (typeof globalThis.crypto !== "undefined") return globalThis.crypto;
4
4
  throw new Error("No crypto available - are you in Node < 19?");
@@ -1,4 +1,4 @@
1
- //#region src/modules/encryption/types.d.ts
1
+ //#region src/crypto/types.d.ts
2
2
  interface AesEncryptedData {
3
3
  ciphertext: Uint8Array<ArrayBuffer>;
4
4
  iv: Uint8Array<ArrayBuffer>;
@@ -0,0 +1,24 @@
1
+ import { MetadataStorage } from "../providers/storage/types.js";
2
+ import "../providers/storage/index.js";
3
+ import { Blockstore } from "interface-blockstore";
4
+
5
+ //#region src/engine/blockstore.d.ts
6
+ declare class StorageBlockstoreAdapter implements Blockstore<any, any, any, any, any, any, any, any> {
7
+ private storage;
8
+ private memoryCache;
9
+ private pendingCids;
10
+ constructor(storage: MetadataStorage);
11
+ put(key: any, val: Uint8Array, options?: any): Promise<any>;
12
+ /** Uploads every block written locally since the last flush to the remote backend. */
13
+ flush(): Promise<void>;
14
+ get(key: any, options?: any): AsyncGenerator<Uint8Array, void, unknown>;
15
+ has(key: any, options?: any): Promise<boolean>;
16
+ delete(key: any, options?: any): Promise<void>;
17
+ putMany(blocks: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
18
+ getMany(cids: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
19
+ deleteMany(cids: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
20
+ blocks(options?: any): AsyncGenerator<any, void, unknown>;
21
+ getAll(options?: any): AsyncGenerator<any, void, unknown>;
22
+ }
23
+ //#endregion
24
+ export { StorageBlockstoreAdapter };
@@ -0,0 +1,85 @@
1
+ import { CID } from "multiformats/cid";
2
+
3
+ //#region src/engine/blockstore.ts
4
+ var StorageBlockstoreAdapter = class {
5
+ memoryCache = /* @__PURE__ */ new Map();
6
+ pendingCids = /* @__PURE__ */ new Map();
7
+ constructor(storage) {
8
+ this.storage = storage;
9
+ }
10
+ async put(key, val, options) {
11
+ const cleanBytes = val.byteOffset === 0 && val.byteLength === val.buffer.byteLength ? val : val.slice();
12
+ const cid = key instanceof CID ? key : CID.parse(key.toString());
13
+ const lookupKey = cid.toString();
14
+ this.memoryCache.set(lookupKey, cleanBytes);
15
+ this.pendingCids.set(lookupKey, cid);
16
+ return key;
17
+ }
18
+ /** Uploads every block written locally since the last flush to the remote backend. */
19
+ async flush() {
20
+ if (this.pendingCids.size === 0) return;
21
+ const blocks = Array.from(this.pendingCids.values()).map((cid) => ({
22
+ cid,
23
+ bytes: this.memoryCache.get(cid.toString())
24
+ }));
25
+ await this.storage.putBlocks(blocks);
26
+ this.pendingCids.clear();
27
+ }
28
+ async *get(key, options) {
29
+ const lookupKey = key instanceof CID ? key.toString() : String(key);
30
+ if (this.memoryCache.has(lookupKey)) {
31
+ yield this.memoryCache.get(lookupKey);
32
+ return;
33
+ }
34
+ const remoteBytes = await this.storage.getRawBlock(lookupKey);
35
+ if (!remoteBytes) throw new Error(`Block payload missing for key: ${lookupKey}`);
36
+ this.memoryCache.set(lookupKey, remoteBytes);
37
+ yield remoteBytes;
38
+ }
39
+ async has(key, options) {
40
+ const lookupKey = key instanceof CID ? key.toString() : String(key);
41
+ if (this.memoryCache.has(lookupKey)) return true;
42
+ try {
43
+ return !(await this.get(key, options).next()).done;
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
48
+ async delete(key, options) {
49
+ const lookupKey = key instanceof CID ? key.toString() : String(key);
50
+ this.memoryCache.delete(lookupKey);
51
+ }
52
+ async *putMany(blocks, options) {
53
+ for await (const { cid, block } of blocks) {
54
+ await this.put(cid, block, options);
55
+ yield cid;
56
+ }
57
+ }
58
+ async *getMany(cids, options) {
59
+ for await (const cid of cids) {
60
+ const chunks = [];
61
+ for await (const chunk of this.get(cid, options)) chunks.push(chunk);
62
+ const flatBytes = new Uint8Array(chunks.reduce((acc, c) => acc + c.length, 0));
63
+ let offset = 0;
64
+ for (const chunk of chunks) {
65
+ flatBytes.set(chunk, offset);
66
+ offset += chunk.length;
67
+ }
68
+ yield {
69
+ cid,
70
+ block: flatBytes
71
+ };
72
+ }
73
+ }
74
+ async *deleteMany(cids, options) {
75
+ for await (const cid of cids) {
76
+ this.delete(cid);
77
+ yield cid;
78
+ }
79
+ }
80
+ async *blocks(options) {}
81
+ async *getAll(options) {}
82
+ };
83
+
84
+ //#endregion
85
+ export { StorageBlockstoreAdapter };
@@ -0,0 +1,180 @@
1
+ import { DataRegistryClient } from "../contracts/data-registry/index.js";
2
+ import "../contracts/index.js";
3
+ import { Address, Hash } from "viem";
4
+ import { CID } from "multiformats/cid";
5
+ import { Blockstore } from "interface-blockstore";
6
+
7
+ //#region src/engine/index.d.ts
8
+ type SchemaID = string;
9
+ type RelationLabel = string;
10
+ type NamespaceID = string;
11
+ interface Vertex {
12
+ schemaId: SchemaID;
13
+ payload: Record<string, any>;
14
+ }
15
+ interface Edge {
16
+ sourceCid: string;
17
+ relation: RelationLabel;
18
+ targetCid: string;
19
+ }
20
+ interface VertexSchema {
21
+ id: SchemaID;
22
+ requiredFields: string[];
23
+ }
24
+ interface EdgeSchema {
25
+ sourceSchema: SchemaID;
26
+ relation: RelationLabel;
27
+ targetSchema: SchemaID;
28
+ }
29
+ interface CommitObject {
30
+ pailRoot: CID;
31
+ parents: CID[];
32
+ timestamp: number;
33
+ message: string;
34
+ }
35
+ interface NamespaceContents {
36
+ vertices: {
37
+ cid: string;
38
+ schemaId: SchemaID;
39
+ payload: Record<string, any>;
40
+ }[];
41
+ edges: Edge[];
42
+ }
43
+ /** Net change to one namespace between two on-chain roots (see `namespaceDiff`). */
44
+ interface NamespaceDiff {
45
+ /** Vertices new or re-pointed vs. the old root, decoded to their payloads. */
46
+ addedVertices: NamespaceContents['vertices'];
47
+ /** Edges new vs. the old root. */
48
+ addedEdges: Edge[];
49
+ /** CIDs of vertices present at the old root but gone at the new one. */
50
+ removedVertexCids: string[];
51
+ /** Edges present at the old root but gone at the new one. */
52
+ removedEdges: Edge[];
53
+ }
54
+ declare class MetagraphRegistry {
55
+ private vertexSchemas;
56
+ private edgeSchemas;
57
+ registerVertex(namespace: NamespaceID, schema: VertexSchema): void;
58
+ hasVertexSchema(namespace: NamespaceID, schemaId: SchemaID): boolean;
59
+ registerEdge(namespace: NamespaceID, rule: EdgeSchema): void;
60
+ hasEdgeSchema(namespace: NamespaceID, sourceSchema: SchemaID, relation: RelationLabel, targetSchema: SchemaID): boolean;
61
+ validateVertex(namespace: NamespaceID, schemaId: SchemaID, payload: Record<string, any>): boolean;
62
+ validateEdge(namespace: NamespaceID, sourceSchema: SchemaID, relation: RelationLabel, targetSchema: SchemaID): boolean;
63
+ }
64
+ /** One line of a commit's diff against its first parent. */
65
+ interface CommitDiff {
66
+ message: string;
67
+ parents: string[];
68
+ timestamp: number;
69
+ pailRoot: string;
70
+ /** namespaced keys (`<ns>/v/...`, `<ns>/e/...`) whose value is new or changed vs. the parent. */
71
+ added: string[];
72
+ /** namespaced keys present in the parent but gone in this commit. */
73
+ removed: string[];
74
+ }
75
+ declare class FangornEngine {
76
+ private blockstore;
77
+ private metagraph;
78
+ private registryClient;
79
+ constructor(blockstore: Blockstore<any, any, any, any, any, any, any, any>, metagraph: MetagraphRegistry, registryClient: DataRegistryClient);
80
+ private encodeBlock;
81
+ private readBlockBytes;
82
+ /**
83
+ * Reconstructs the CID a commit's raw digest hex refers to. The contract only
84
+ * stores the bare 32-byte sha256 digest (see commitBatch), so rebuilding the
85
+ * CID must wrap that digest directly via Digest.create — hashing it again
86
+ * with sha256.digest() would produce an unrelated CID pointing at nothing.
87
+ */
88
+ private hexToRootCid;
89
+ /** Reconstruct the publisher's current on-chain head as a commit CID, or null if none. */
90
+ resolveHeadCommit(publisher: Address): Promise<CID | null>;
91
+ /** Read and decode a commit object by CID. */
92
+ getCommit(commitCid: CID): Promise<CommitObject>;
93
+ /** Resolve the pail tree root behind the publisher's on-chain head commit, or null. */
94
+ private resolvePailRoot;
95
+ /**
96
+ * Open a Pail write batch over `basePailRoot` (or a fresh empty tree when
97
+ * null). Pure/local — never reads the chain, so callers control exactly which
98
+ * historical root a new commit builds on (on-chain tip vs. a local HEAD).
99
+ */
100
+ openBatch(basePailRoot: CID | null): Promise<any>;
101
+ /**
102
+ * Open a batch that continues the publisher's on-chain head (immediate-write
103
+ * path). Returns the base commit CID and raw head hex so the caller can parent
104
+ * the next commit and pass the expected old root to the on-chain CAS.
105
+ */
106
+ createBatch(publisher: Address): Promise<{
107
+ batch: any;
108
+ contractHeadHex: string;
109
+ baseCommitCid: CID | null;
110
+ }>;
111
+ stageVertex(batch: any, namespace: NamespaceID, schemaId: SchemaID, payload: Record<string, any>): Promise<string>;
112
+ stageEdge(batch: any, namespace: NamespaceID, edge: Edge, sourceSchema: SchemaID, targetSchema: SchemaID): Promise<void>;
113
+ /**
114
+ * Seal a write batch into a new commit *locally*: flatten the pail tree, then
115
+ * wrap its root in a CommitObject parented on `parents`. Writes blocks to the
116
+ * blockstore but does NOT touch the chain — the git `commit` step. The
117
+ * returned commit isn't on-chain until pushCommit() settles it.
118
+ */
119
+ sealBatch(batch: any, parents: CID[], message: string): Promise<{
120
+ commitCid: CID;
121
+ pailRoot: CID;
122
+ }>;
123
+ /** Build, encode and store a CommitObject block; returns its CID. */
124
+ private writeCommit;
125
+ /** Upload every block written locally since the last flush to the remote backend. */
126
+ flush(): Promise<void>;
127
+ /**
128
+ * Settle a local commit as the publisher's on-chain head — the permissioned,
129
+ * git `push` step. Flushes pending blocks to remote storage first (so the
130
+ * commit resolves for anyone reading the chain), then does the compare-and-swap
131
+ * against the current head. Unless `force`, the on-chain head must be an
132
+ * ancestor of `commitCid` (fast-forward only).
133
+ */
134
+ pushCommit(publisher: Address, commitCid: CID, opts?: {
135
+ force?: boolean;
136
+ }): Promise<{
137
+ txHash: Hash;
138
+ onChainTip: CID;
139
+ }>;
140
+ /** Walk the first-parent chain from `tip` toward the root, newest first. */
141
+ walkParents(tip: CID, max?: number): AsyncGenerator<{
142
+ cid: CID;
143
+ commit: CommitObject;
144
+ }>;
145
+ /** True if `ancestor` appears on the first-parent chain of `tip`. */
146
+ private isAncestor;
147
+ /** The commit CID string a raw on-chain root hex points at. */
148
+ commitCidFromRootHex(hex: string): string;
149
+ /**
150
+ * Net change to a single namespace between two on-chain roots — the core of
151
+ * the subscription light-client. Resolves the pail tree behind each commit
152
+ * root and diffs only the `<namespace>/` slice, so pushes that touched *other*
153
+ * namespaces of the same publisher produce an empty diff.
154
+ *
155
+ * Diffing root-to-root (rather than walking commits) is deliberately robust:
156
+ * it yields the correct net delta even across a force-push / non-fast-forward
157
+ * reorg — exactly what an index builder needs (which vertices to (re)embed,
158
+ * which to evict). Added vertices are decoded to their payloads; removed items
159
+ * and all edges are recovered from the pail key alone (no extra fetch), since
160
+ * an edge key already encodes `source|relation|target`.
161
+ */
162
+ namespaceDiff(oldRootHex: string | null, newRootHex: string, namespace: NamespaceID): Promise<NamespaceDiff>;
163
+ /** Recover an Edge from its pail key `<ns>/e/<source>|<relation>|<target>`. */
164
+ private edgeFromKey;
165
+ /** Diff a commit against its first parent, by namespaced pail key. */
166
+ diffCommit(commitCid: CID): Promise<CommitDiff>;
167
+ /** Every content-linked pail key → linked CID string, under an optional prefix. */
168
+ private entriesAt;
169
+ /**
170
+ * Cheap existence check: does anything (including the bare `sys/init`
171
+ * marker) exist under this namespace prefix yet? Short-circuits on the
172
+ * first entry found instead of decoding the whole namespace, unlike
173
+ * listNamespace (which also skips non-CID values like the marker itself).
174
+ */
175
+ namespaceExists(namespace: NamespaceID, publisher: Address): Promise<boolean>;
176
+ /** Lists every vertex and edge currently staged under a namespace, resolved from the on-chain root. */
177
+ listNamespace(namespace: NamespaceID, publisher: Address): Promise<NamespaceContents>;
178
+ }
179
+ //#endregion
180
+ export { CommitDiff, CommitObject, Edge, EdgeSchema, FangornEngine, MetagraphRegistry, NamespaceContents, NamespaceDiff, NamespaceID, RelationLabel, SchemaID, Vertex, VertexSchema };