@fangorn-network/sdk 2026.7.27 → 2026.7.28
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.
- package/README.md +163 -8
- package/lib/cli/cli.js +16 -11
- package/lib/cli/index.d.ts +13 -13
- package/lib/config.d.ts +86 -79
- package/lib/config.js +11 -2
- package/lib/contracts/data-registry/abi.d.ts +80 -2
- package/lib/contracts/data-registry/abi.js +107 -12
- package/lib/contracts/data-registry/index.d.ts +91 -19
- package/lib/contracts/data-registry/index.js +153 -24
- package/lib/contracts/index.d.ts +2 -2
- package/lib/contracts/index.js +2 -2
- package/lib/engine/index.d.ts +36 -12
- package/lib/engine/index.js +51 -19
- package/lib/engine/test-helpers.d.ts +7 -4
- package/lib/engine/test-helpers.js +9 -6
- package/lib/fangorn.d.ts +76 -12
- package/lib/fangorn.js +102 -32
- package/lib/index.d.ts +7 -2
- package/lib/index.js +7 -2
- package/lib/test/testbed.d.ts +21 -3
- package/lib/test/testbed.js +38 -7
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { AppConfig, FangornConfig, SupportedNetworks } from "./config.js";
|
|
1
|
+
import { AppConfig, FangornConfig, SupportedNetworks, appId } from "./config.js";
|
|
2
|
+
import { DATA_REGISTRY_ABI } from "./contracts/data-registry/abi.js";
|
|
3
|
+
import { CommitFilter, DataRegistryClient, PreparedTx, PublisherStatus, StateCommittedLog, namespaceKey, subspaceId } from "./contracts/data-registry/index.js";
|
|
4
|
+
import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
|
|
5
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./contracts/settlement-registry/abi.js";
|
|
6
|
+
import "./contracts/index.js";
|
|
2
7
|
import { AccessRequest, AccessSigner, DecryptHandleParams, EncryptAndUploadParams, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, X25519_PUBKEY_LENGTH, accessMessageHash, buildAccessRequest, decryptHandle, encryptAndUpload, seal, sealSelf, sha256Hex, unseal, unsealSelf } from "./crypto/encryption.js";
|
|
3
8
|
import { FangornContext, FangornCreateOptions, StorageConfig } from "./types/index.js";
|
|
4
9
|
import { Fangorn, NamespaceChange, SubscribeOptions } from "./fangorn.js";
|
|
@@ -6,4 +11,4 @@ import { AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, Edge, FileFaca
|
|
|
6
11
|
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
7
12
|
import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend, SignedUrlSigner } from "./providers/storage/signed-url.js";
|
|
8
13
|
import { MAX_UPLOAD_ATTEMPTS, deserialize, fetchRawByCid, isTransientUpload, retrieveByCid, serialize, withUploadRetry } from "./providers/storage/utils.js";
|
|
9
|
-
export { AccessRequest, AccessSigner, AppConfig, AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, DEFAULT_SIGNED_URL_WORKER, DecryptHandleParams, Edge, EncryptAndUploadParams, Fangorn, FangornConfig, FangornContext, FangornCreateOptions, FileFacade, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, MAX_UPLOAD_ATTEMPTS, NamespaceChange, PinataBackend, ProcessorResult, SignedUrlBackend, SignedUrlSigner, StorageConfig, SubscribeOptions, SupportedNetworks, Vertex, X25519_PUBKEY_LENGTH, accessMessageHash, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, retrieveByCid, seal, sealSelf, serialize, sha256Hex, unseal, unsealSelf, withUploadRetry };
|
|
14
|
+
export { AccessRequest, AccessSigner, AppConfig, AssetProcessor, BuildAssetGraphOptions, CommitFileGraph, CommitFilter, DATA_REGISTRY_ABI, DEFAULT_SIGNED_URL_WORKER, DataRegistryClient, DecryptHandleParams, Edge, EncryptAndUploadParams, Fangorn, FangornConfig, FangornContext, FangornCreateOptions, FileFacade, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, Gadget, HandleFieldInput, MAX_UPLOAD_ATTEMPTS, NamespaceChange, PinataBackend, PreparedTx, ProcessorResult, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, SignedUrlBackend, SignedUrlSigner, StateCommittedLog, StorageConfig, SubscribeOptions, SupportedNetworks, Vertex, X25519_PUBKEY_LENGTH, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, namespaceKey, retrieveByCid, seal, sealSelf, serialize, sha256Hex, subspaceId, unseal, unsealSelf, withUploadRetry };
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { FangornConfig, SupportedNetworks } from "./config.js";
|
|
1
|
+
import { FangornConfig, SupportedNetworks, appId } from "./config.js";
|
|
2
2
|
import { DEFAULT_SIGNED_URL_WORKER, SignedUrlBackend } from "./providers/storage/signed-url.js";
|
|
3
3
|
import { MAX_UPLOAD_ATTEMPTS, deserialize, fetchRawByCid, isTransientUpload, retrieveByCid, serialize, withUploadRetry } from "./providers/storage/utils.js";
|
|
4
4
|
import { PinataBackend } from "./providers/storage/pinata.js";
|
|
5
|
+
import { DATA_REGISTRY_ABI } from "./contracts/data-registry/abi.js";
|
|
6
|
+
import { DataRegistryClient, PublisherStatus, namespaceKey, subspaceId } from "./contracts/data-registry/index.js";
|
|
7
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./contracts/settlement-registry/abi.js";
|
|
8
|
+
import { SettlementRegistryClient } from "./contracts/settlement-registry/index.js";
|
|
9
|
+
import "./contracts/index.js";
|
|
5
10
|
import { Fangorn } from "./fangorn.js";
|
|
6
11
|
import { buildAssetGraph, buildMarkdownGraph, extractMarkdownLinks } from "./harness/index.js";
|
|
7
12
|
import { GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, X25519_PUBKEY_LENGTH, accessMessageHash, buildAccessRequest, decryptHandle, encryptAndUpload, seal, sealSelf, sha256Hex, unseal, unsealSelf } from "./crypto/encryption.js";
|
|
8
13
|
|
|
9
|
-
export { DEFAULT_SIGNED_URL_WORKER, Fangorn, FangornConfig, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, MAX_UPLOAD_ATTEMPTS, PinataBackend, SignedUrlBackend, SupportedNetworks, X25519_PUBKEY_LENGTH, accessMessageHash, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, retrieveByCid, seal, sealSelf, serialize, sha256Hex, unseal, unsealSelf, withUploadRetry };
|
|
14
|
+
export { DATA_REGISTRY_ABI, DEFAULT_SIGNED_URL_WORKER, DataRegistryClient, Fangorn, FangornConfig, GADGET_SELF_HKDF_V1, GADGET_WORKER_USDC_V1, MAX_UPLOAD_ATTEMPTS, PinataBackend, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, SignedUrlBackend, SupportedNetworks, X25519_PUBKEY_LENGTH, accessMessageHash, appId, buildAccessRequest, buildAssetGraph, buildMarkdownGraph, decryptHandle, deserialize, encryptAndUpload, extractMarkdownLinks, fetchRawByCid, isTransientUpload, namespaceKey, retrieveByCid, seal, sealSelf, serialize, sha256Hex, subspaceId, unseal, unsealSelf, withUploadRetry };
|
package/lib/test/testbed.d.ts
CHANGED
|
@@ -6,9 +6,23 @@ import { Hex } from "viem";
|
|
|
6
6
|
declare class TestBed {
|
|
7
7
|
private readonly f_list;
|
|
8
8
|
private constructor();
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param sks one wallet per publisher in the forest
|
|
11
|
+
* @param appName the app namespace to publish under; defaults to the SDK's
|
|
12
|
+
* own. Pass an unclaimed name to exercise the AppNotFound path.
|
|
13
|
+
*/
|
|
14
|
+
static init(sks: Hex[], appName?: string): TestBed;
|
|
10
15
|
getFangorn(index: number): Fangorn;
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Claim the configured app namespace, if nobody has yet.
|
|
18
|
+
*
|
|
19
|
+
* Orthogonal to `register`: an app claims a unique namespace prefix that
|
|
20
|
+
* publishers may write under, while a publisher registers for the right to
|
|
21
|
+
* write at all. Neither implies the other — one app hosts many publishers,
|
|
22
|
+
* and one publisher writes into many apps. Idempotent, and safe when someone
|
|
23
|
+
* else already owns it: apps are shared, not per-test.
|
|
24
|
+
*/
|
|
25
|
+
registerApp(index: number): Promise<void>;
|
|
12
26
|
register(index: number): Promise<void>;
|
|
13
27
|
initRepo(index: number, name: string): Promise<{
|
|
14
28
|
cid: undefined;
|
|
@@ -39,11 +53,15 @@ declare class TestBed {
|
|
|
39
53
|
txHash: `0x${string}`;
|
|
40
54
|
vertexCids: Record<string, string>;
|
|
41
55
|
}>;
|
|
42
|
-
fetch(index: number, cid: string): Promise<{
|
|
56
|
+
fetch(index: number, cid: string, namespace: string): Promise<{
|
|
43
57
|
cid: string;
|
|
44
58
|
schemaId: SchemaID;
|
|
45
59
|
payload: Record<string, unknown>;
|
|
46
60
|
}>;
|
|
61
|
+
/** Owner of the configured app namespace, or the zero address if unclaimed. */
|
|
62
|
+
appOwner(index: number): Promise<`0x${string}`>;
|
|
63
|
+
/** The raw on-chain head of one namespace — the slot the CAS actually guards. */
|
|
64
|
+
head(index: number, namespace: string): Promise<`0x${string}`>;
|
|
47
65
|
inspect(index: number, namespace: string): Promise<NamespaceContents>;
|
|
48
66
|
}
|
|
49
67
|
//#endregion
|
package/lib/test/testbed.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FangornConfig, appId } from "../config.js";
|
|
1
2
|
import { Fangorn } from "../fangorn.js";
|
|
2
3
|
|
|
3
4
|
//#region src/test/testbed.ts
|
|
@@ -5,11 +6,21 @@ var TestBed = class TestBed {
|
|
|
5
6
|
constructor(f_list) {
|
|
6
7
|
this.f_list = f_list;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param sks one wallet per publisher in the forest
|
|
11
|
+
* @param appName the app namespace to publish under; defaults to the SDK's
|
|
12
|
+
* own. Pass an unclaimed name to exercise the AppNotFound path.
|
|
13
|
+
*/
|
|
14
|
+
static init(sks, appName) {
|
|
15
|
+
const config = appName ? {
|
|
16
|
+
...FangornConfig,
|
|
17
|
+
appId: appId(appName)
|
|
18
|
+
} : FangornConfig;
|
|
9
19
|
const f_list = [];
|
|
10
20
|
sks.forEach((sk) => {
|
|
11
21
|
f_list.push(Fangorn.create({
|
|
12
22
|
privateKey: sk,
|
|
23
|
+
config,
|
|
13
24
|
storage: { pinata: {
|
|
14
25
|
jwt: process.env.PINATA_JWT ?? "",
|
|
15
26
|
gateway: process.env.PINATA_GATEWAY ?? ""
|
|
@@ -22,10 +33,21 @@ var TestBed = class TestBed {
|
|
|
22
33
|
if (index > this.f_list.length) throw new Error("index out of bounds");
|
|
23
34
|
return this.f_list[index];
|
|
24
35
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Claim the configured app namespace, if nobody has yet.
|
|
38
|
+
*
|
|
39
|
+
* Orthogonal to `register`: an app claims a unique namespace prefix that
|
|
40
|
+
* publishers may write under, while a publisher registers for the right to
|
|
41
|
+
* write at all. Neither implies the other — one app hosts many publishers,
|
|
42
|
+
* and one publisher writes into many apps. Idempotent, and safe when someone
|
|
43
|
+
* else already owns it: apps are shared, not per-test.
|
|
44
|
+
*/
|
|
45
|
+
async registerApp(index) {
|
|
46
|
+
const registry = this.getFangorn(index).getDataRegistry();
|
|
47
|
+
if (await registry.getAppOwner() === "0x0000000000000000000000000000000000000000") {
|
|
48
|
+
console.log(`Registering app ${registry.getAppId()} on-chain...`);
|
|
49
|
+
await registry.registerApp();
|
|
50
|
+
}
|
|
29
51
|
}
|
|
30
52
|
async register(index) {
|
|
31
53
|
const fangorn = this.getFangorn(index);
|
|
@@ -45,9 +67,18 @@ var TestBed = class TestBed {
|
|
|
45
67
|
async uploadBatch(index, namespace, vertices, edges = []) {
|
|
46
68
|
return this.getFangorn(index).uploadBatch(namespace, vertices, edges);
|
|
47
69
|
}
|
|
48
|
-
async fetch(index, cid) {
|
|
70
|
+
async fetch(index, cid, namespace) {
|
|
71
|
+
const fangorn = this.getFangorn(index);
|
|
72
|
+
return fangorn.engine.readVertex(cid, fangorn.getAddress(), namespace);
|
|
73
|
+
}
|
|
74
|
+
/** Owner of the configured app namespace, or the zero address if unclaimed. */
|
|
75
|
+
async appOwner(index) {
|
|
76
|
+
return this.getFangorn(index).getDataRegistry().getAppOwner();
|
|
77
|
+
}
|
|
78
|
+
/** The raw on-chain head of one namespace — the slot the CAS actually guards. */
|
|
79
|
+
async head(index, namespace) {
|
|
49
80
|
const fangorn = this.getFangorn(index);
|
|
50
|
-
return fangorn.
|
|
81
|
+
return fangorn.getDataRegistry().getNamespaceHead(fangorn.getAddress(), namespace);
|
|
51
82
|
}
|
|
52
83
|
async inspect(index, namespace) {
|
|
53
84
|
return this.getFangorn(index).inspectNamespace(namespace);
|