@fangorn-network/sdk 2026.4.7 → 2026.4.10

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 (49) hide show
  1. package/README.md +30 -26
  2. package/lib/cli/cli.js +115 -153
  3. package/lib/cli/index.d.ts +170 -170
  4. package/lib/config.d.ts +260 -257
  5. package/lib/config.js +7 -5
  6. package/lib/fangorn.d.ts +0 -3
  7. package/lib/fangorn.js +16 -28
  8. package/lib/index.d.ts +3 -3
  9. package/lib/index.js +4 -5
  10. package/lib/modules/encryption/lit.d.ts +0 -1
  11. package/lib/modules/encryption/lit.js +1 -7
  12. package/lib/modules/gadgets/settledGadget.d.ts +1 -8
  13. package/lib/modules/gadgets/settledGadget.js +1 -13
  14. package/lib/providers/storage/index.d.ts +12 -12
  15. package/lib/providers/storage/index.js +49 -2
  16. package/lib/providers/storage/pinata.d.ts +11 -0
  17. package/lib/providers/storage/pinata.js +24 -0
  18. package/lib/registries/datasource-registry/abi.d.ts +116 -43
  19. package/lib/registries/datasource-registry/abi.js +190 -12
  20. package/lib/registries/datasource-registry/index.d.ts +12 -6
  21. package/lib/registries/datasource-registry/index.js +96 -20
  22. package/lib/registries/index.js +1 -1
  23. package/lib/registries/schema-registry/abi.d.ts +157 -66
  24. package/lib/registries/schema-registry/abi.js +242 -15
  25. package/lib/registries/schema-registry/index.d.ts +8 -3
  26. package/lib/registries/schema-registry/index.js +82 -17
  27. package/lib/registries/settlement-registry/abi.d.ts +199 -145
  28. package/lib/registries/settlement-registry/abi.js +331 -25
  29. package/lib/registries/settlement-registry/index.d.ts +36 -39
  30. package/lib/registries/settlement-registry/index.js +125 -91
  31. package/lib/registries/settlement-registry/types.d.ts +6 -3
  32. package/lib/roles/consumer/index.d.ts +8 -29
  33. package/lib/roles/consumer/index.js +25 -45
  34. package/lib/roles/consumer/types.d.ts +4 -4
  35. package/lib/roles/publisher/index.d.ts +26 -29
  36. package/lib/roles/publisher/index.js +70 -77
  37. package/lib/roles/publisher/types.d.ts +7 -3
  38. package/lib/roles/schema/index.d.ts +3 -8
  39. package/lib/roles/schema/index.js +6 -34
  40. package/lib/test/testbed.d.ts +7 -32
  41. package/lib/test/testbed.js +22 -45
  42. package/lib/types/index.d.ts +10 -20
  43. package/package.json +1 -1
  44. package/lib/providers/storage/pinata/index.d.ts +0 -13
  45. package/lib/providers/storage/pinata/index.js +0 -41
  46. package/lib/providers/storage/storacha/index.d.ts +0 -13
  47. package/lib/providers/storage/storacha/index.js +0 -49
  48. package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
  49. package/lib/providers/storage/storacha/readOnly.js +0 -16
@@ -1,4 +1,4 @@
1
- import { SettlementRegistry } from "../registries/settlement-registry/index.js";
1
+ import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
2
2
  import { Fangorn } from "../fangorn.js";
3
3
  import { arbitrumSepolia, baseSepolia } from "viem/chains";
4
4
  import { createWalletClient, http } from "viem";
@@ -13,23 +13,6 @@ var TestBed = class TestBed {
13
13
  this.usdcContractAddress = usdcContractAddress;
14
14
  this.usdcDomainName = usdcDomainName;
15
15
  }
16
- /**
17
- * Init the testbed client
18
- * @param delegatorWalletClient
19
- * @param delegateeWalletClient
20
- * @param jwt
21
- * @param gateway
22
- * @param dataSourceRegistryContractAddress
23
- * @param schemaRegistryContractAddress
24
- * @param settlementRegistryContractAddress
25
- * @param usdcContractAddress
26
- * @param usdcDomainName
27
- * @param rpcUrl
28
- * @param chain
29
- * @param caip2
30
- * @param delegatorPrivateKey
31
- * @returns The testbed client
32
- */
33
16
  static async init(delegatorWalletClient, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2) {
34
17
  let chainImpl = arbitrumSepolia;
35
18
  if (chain === "baseSepolia") chainImpl = baseSepolia;
@@ -40,7 +23,8 @@ var TestBed = class TestBed {
40
23
  chainName: chain,
41
24
  chain: chainImpl,
42
25
  rpcUrl,
43
- caip2
26
+ caip2,
27
+ ipfsGateway: "https://gateway.pinata.cloud"
44
28
  };
45
29
  const delegatorFangorn = await Fangorn.create({
46
30
  privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
@@ -50,12 +34,10 @@ var TestBed = class TestBed {
50
34
  } },
51
35
  encryption: { lit: true },
52
36
  config,
53
- domain: "localhost",
54
- agentConfig: void 0
37
+ domain: "localhost"
55
38
  });
56
39
  const delegateeFangorn = await Fangorn.create({
57
40
  privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
58
- storage: { storacha: { "readOnly": true } },
59
41
  encryption: { lit: true },
60
42
  config,
61
43
  domain: "localhost"
@@ -63,9 +45,6 @@ var TestBed = class TestBed {
63
45
  if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
64
46
  return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
65
47
  }
66
- async registerAgent(params) {
67
- return this.delegatorFangorn.schema.registerAgent(params);
68
- }
69
48
  async registerSchema(name, definition, agentId) {
70
49
  const { schemaId } = await this.delegatorFangorn.schema.register({
71
50
  name,
@@ -74,13 +53,6 @@ var TestBed = class TestBed {
74
53
  });
75
54
  return schemaId;
76
55
  }
77
- /**
78
- * Upload files encrypted under SettledGadget.
79
- *
80
- * Each file gets its own resourceId derived from (owner, schemaId, file.tag),
81
- * which is baked into the ACC at encryption time. A buyer must complete the
82
- * full purchase → claim flow for each specific tag before decrypting.
83
- */
84
56
  async fileUpload(records, schemaName, gateway, price) {
85
57
  const { manifestCid } = await this.delegatorFangorn.publisher.upload({
86
58
  records,
@@ -90,8 +62,13 @@ var TestBed = class TestBed {
90
62
  return manifestCid;
91
63
  }
92
64
  async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
65
+ const walletClient = createWalletClient({
66
+ account: privateKeyToAccount(burnerPrivateKey),
67
+ chain: arbitrumSepolia,
68
+ transport: http(process.env.RPC_URL ?? "")
69
+ });
93
70
  return this.delegateeFangorn.consumer.prepareRegister({
94
- burnerPrivateKey,
71
+ walletClient,
95
72
  paymentRecipient,
96
73
  amount,
97
74
  usdcAddress: this.usdcContractAddress,
@@ -99,29 +76,29 @@ var TestBed = class TestBed {
99
76
  usdcDomainVersion: "2"
100
77
  });
101
78
  }
102
- async register(owner, schemaId, tag, identityCommitment, relayerPrivateKey, preparedRegister) {
79
+ async register(owner, schemaId, name, identityCommitment, relayerPrivateKey, preparedRegister) {
103
80
  const { txHash } = await this.delegateeFangorn.consumer.register({
104
81
  owner,
105
82
  schemaId,
106
- tag,
83
+ name,
107
84
  identityCommitment,
108
85
  relayerPrivateKey,
109
86
  preparedRegister
110
87
  });
111
88
  return txHash;
112
89
  }
113
- async prepareSettle(owner, schemaId, tag, identity, stealthAddress) {
90
+ async prepareSettle(owner, schemaId, name, identity, stealthAddress) {
114
91
  return this.delegateeFangorn.consumer.prepareSettle({
115
- resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
92
+ resourceId: DataSourceRegistry.resourceIdLocal(owner, schemaId, name),
116
93
  identity,
117
94
  stealthAddress
118
95
  });
119
96
  }
120
- async settle(owner, schemaId, tag, relayerPrivateKey, preparedSettle) {
97
+ async settle(owner, schemaId, name, relayerPrivateKey, preparedSettle) {
121
98
  const { txHash, nullifier } = await this.delegateeFangorn.consumer.claim({
122
99
  owner,
123
100
  schemaId,
124
- tag,
101
+ name,
125
102
  relayerPrivateKey,
126
103
  preparedSettle
127
104
  });
@@ -130,7 +107,7 @@ var TestBed = class TestBed {
130
107
  nullifier
131
108
  };
132
109
  }
133
- async tryDecrypt(owner, nullifierHash, stealthSecretKey, schemaId, tag, field, rpcUrl, identity, requireSettlement = true) {
110
+ async tryDecrypt(owner, nullifierHash, stealthSecretKey, schemaId, name, field, rpcUrl, identity, requireSettlement = true) {
134
111
  const walletClient = createWalletClient({
135
112
  account: privateKeyToAccount(stealthSecretKey),
136
113
  chain: arbitrumSepolia,
@@ -141,18 +118,18 @@ var TestBed = class TestBed {
141
118
  walletClient,
142
119
  schemaId,
143
120
  nullifierHash,
144
- tag,
121
+ name,
145
122
  field,
146
123
  identity,
147
124
  skipSettlementCheck: !requireSettlement
148
125
  });
149
126
  }
150
- async checkManifestExists(who, schemaId) {
151
- return await this.delegatorFangorn.consumer.getManifest(who, schemaId) !== void 0;
127
+ async checkManifestExists(who, schemaId, name) {
128
+ return await this.delegatorFangorn.consumer.getManifest(who, schemaId, name) !== void 0;
152
129
  }
153
- async checkEntryExists(who, schemaId, tag) {
130
+ async checkEntryExists(who, schemaId, name) {
154
131
  try {
155
- await this.delegatorFangorn.consumer.getEntry(who, schemaId, tag);
132
+ await this.delegatorFangorn.consumer.getEntry(who, schemaId, name);
156
133
  return true;
157
134
  } catch {
158
135
  return false;
@@ -1,6 +1,6 @@
1
1
  import { AppConfig } from "../config.js";
2
2
  import { SchemaRegistry } from "../registries/schema-registry/index.js";
3
- import { ReadableStorage, WritableStorage } from "../providers/storage/index.js";
3
+ import { PinningService } from "../providers/storage/index.js";
4
4
  import { SchemaRoleConfig } from "../roles/schema/types.js";
5
5
  import "../roles/schema/index.js";
6
6
  import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
@@ -29,29 +29,22 @@ interface EncryptedData {
29
29
  authTag: Uint8Array<ArrayBuffer>;
30
30
  salt: Uint8Array<ArrayBuffer>;
31
31
  }
32
- /**
33
- * Credentials required to enable ERC-8004 agent registration via agent0-sdk.
34
- * Optional: omit if thewill throw. caller only needs publisher or consumer functionality.
35
- * When omitted, fangorn.schema.register() and fangorn.schema.get() still work;
36
- * only fangorn.schema.registerAgent()
37
- */
38
32
  interface AgentConfig {
39
33
  privateKey: Hex;
40
34
  pinataJwt: string;
41
- /** Override ERC-8004 registry addresses per chainId (e.g. for Arbitrum Sepolia) */
42
35
  registryOverrides?: Record<number, {
43
36
  IDENTITY: string;
44
37
  REPUTATION: string;
45
38
  }>;
46
- /** Override subgraph URLs per chainId */
47
39
  subgraphOverrides?: Record<number, string>;
48
40
  }
49
41
  interface FangornContext {
50
42
  config: AppConfig;
51
43
  walletClient: WalletClient;
52
- storage: ReadableStorage<unknown> | WritableStorage<unknown>;
44
+ storage: PinningService | undefined;
53
45
  encryption: EncryptionService;
54
46
  domain: string;
47
+ ipfsGateway: string;
55
48
  schemaRegistry: SchemaRegistry;
56
49
  dataSourceRegistry: DataSourceRegistry;
57
50
  settlementRegistry: SettlementRegistry;
@@ -62,21 +55,18 @@ type StorageConfig = {
62
55
  jwt: string;
63
56
  gateway: string;
64
57
  };
65
- } | {
66
- storacha: {
67
- email: string;
68
- };
69
- } | {
70
- storacha: {
71
- readOnly: true;
72
- };
73
- } | ReadableStorage<unknown>;
58
+ };
74
59
  type EncryptionConfig = {
75
60
  lit: true;
76
61
  } | EncryptionService;
77
62
  interface FangornCreateOptions {
78
- storage: StorageConfig;
63
+ /**
64
+ * Pinning service config. Required for publisher and schema roles.
65
+ * Omit for consumer-only usage — reads always go through the public IPFS gateway.
66
+ */
67
+ storage?: StorageConfig;
79
68
  encryption: EncryptionConfig;
69
+ ipfsGateway?: string;
80
70
  config?: AppConfig;
81
71
  domain?: string;
82
72
  agentConfig?: AgentConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.04.07",
3
+ "version": "2026.04.10",
4
4
  "description": "A zero-knowledge conditional access control framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,13 +0,0 @@
1
- import { WritableStorage } from "../index.js";
2
-
3
- //#region src/providers/storage/pinata/index.d.ts
4
- declare class PinataStorage implements WritableStorage<unknown> {
5
- private pinata;
6
- private gateway;
7
- constructor(pinataJwt: string, pinataGateway: string);
8
- store(data: unknown, metadata?: Record<string, string>): Promise<string>;
9
- retrieve(cid: string): Promise<unknown>;
10
- delete(cid: string): Promise<void>;
11
- }
12
- //#endregion
13
- export { PinataStorage };
@@ -1,41 +0,0 @@
1
- import { PinataSDK } from "pinata";
2
-
3
- //#region src/providers/storage/pinata/index.ts
4
- var PinataStorage = class {
5
- pinata;
6
- gateway;
7
- constructor(pinataJwt, pinataGateway) {
8
- this.pinata = new PinataSDK({
9
- pinataJwt,
10
- pinataGateway
11
- });
12
- this.gateway = pinataGateway.replace(/\/$/, "");
13
- }
14
- async store(data, metadata) {
15
- const content = typeof data === "string" ? data : JSON.stringify(data, (_key, value) => {
16
- if (value instanceof Uint8Array) return {
17
- __type: "Uint8Array",
18
- data: Buffer.from(value).toString("base64")
19
- };
20
- return value;
21
- });
22
- const file = new File([content], metadata?.name ?? "file", { type: "text/plain" });
23
- return (await this.pinata.upload.public.file(file, { metadata })).cid;
24
- }
25
- async retrieve(cid) {
26
- const url = `https://${this.gateway}/ipfs/${cid}`;
27
- const response = await fetch(url);
28
- const text = await response.text();
29
- if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
30
- return JSON.parse(text, (_key, value) => {
31
- if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
32
- return value;
33
- });
34
- }
35
- async delete(cid) {
36
- await this.pinata.files.public.delete([cid]);
37
- }
38
- };
39
-
40
- //#endregion
41
- export { PinataStorage };
@@ -1,13 +0,0 @@
1
- import { WritableStorage } from "../index.js";
2
-
3
- //#region src/providers/storage/storacha/index.d.ts
4
- declare class StorachaStorage implements WritableStorage<unknown> {
5
- private client;
6
- private constructor();
7
- static create(email: string): Promise<StorachaStorage>;
8
- store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
9
- retrieve(cid: string): Promise<unknown>;
10
- delete(cid: string): Promise<void>;
11
- }
12
- //#endregion
13
- export { StorachaStorage };
@@ -1,49 +0,0 @@
1
- import { create } from "@storacha/client";
2
-
3
- //#region src/providers/storage/storacha/index.ts
4
- var StorachaStorage = class StorachaStorage {
5
- client;
6
- constructor(client) {
7
- this.client = client;
8
- }
9
- static async create(email) {
10
- const client = await create();
11
- const account = await client.login(email);
12
- if (!(await account.plan.get()).ok) await account.plan.wait();
13
- const spaces = client.spaces();
14
- if (spaces.length > 0) await client.setCurrentSpace(spaces[0].did());
15
- else {
16
- const space = await client.createSpace("fangorn", { account });
17
- await client.setCurrentSpace(space.did());
18
- }
19
- return new StorachaStorage(client);
20
- }
21
- async store(data, metadata) {
22
- const content = typeof data === "string" ? data : JSON.stringify(data, (_key, value) => {
23
- if (value instanceof Uint8Array) return {
24
- __type: "Uint8Array",
25
- data: Buffer.from(value).toString("base64")
26
- };
27
- return value;
28
- });
29
- const name = typeof metadata?.name === "string" ? metadata.name : "file";
30
- const file = new File([content], name, { type: "text/plain" });
31
- return (await this.client.uploadFile(file)).toString();
32
- }
33
- async retrieve(cid) {
34
- const url = `https://${cid}.ipfs.w3s.link`;
35
- const response = await fetch(url);
36
- if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
37
- const text = await response.text();
38
- return JSON.parse(text, (_key, value) => {
39
- if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
40
- return value;
41
- });
42
- }
43
- async delete(cid) {
44
- await this.client.remove(cid);
45
- }
46
- };
47
-
48
- //#endregion
49
- export { StorachaStorage };
@@ -1,8 +0,0 @@
1
- import { ReadableStorage } from "../index.js";
2
-
3
- //#region src/providers/storage/storacha/readOnly.d.ts
4
- declare class ReadOnlyStorachaStorage implements ReadableStorage<unknown> {
5
- retrieve(cid: string): Promise<unknown>;
6
- }
7
- //#endregion
8
- export { ReadOnlyStorachaStorage };
@@ -1,16 +0,0 @@
1
- //#region src/providers/storage/storacha/readOnly.ts
2
- var ReadOnlyStorachaStorage = class {
3
- async retrieve(cid) {
4
- const url = `https://${cid}.ipfs.w3s.link`;
5
- const response = await fetch(url);
6
- if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
7
- const text = await response.text();
8
- return JSON.parse(text, (_key, value) => {
9
- if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
10
- return value;
11
- });
12
- }
13
- };
14
-
15
- //#endregion
16
- export { ReadOnlyStorachaStorage };