@fangorn-network/sdk 2026.3.28 → 2026.4.7-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 (34) hide show
  1. package/README.md +24 -31
  2. package/lib/cli/cli.d.ts +0 -0
  3. package/lib/cli/index.d.ts +170 -170
  4. package/lib/config.d.ts +257 -254
  5. package/lib/config.js +4 -2
  6. package/lib/fangorn.d.ts +0 -8
  7. package/lib/fangorn.js +12 -29
  8. package/lib/index.d.ts +3 -3
  9. package/lib/index.js +3 -3
  10. package/lib/providers/storage/index.d.ts +12 -12
  11. package/lib/providers/storage/index.js +47 -2
  12. package/lib/providers/storage/pinata.d.ts +11 -0
  13. package/lib/providers/storage/pinata.js +24 -0
  14. package/lib/registries/datasource-registry/index.d.ts +2 -1
  15. package/lib/registries/datasource-registry/index.js +14 -2
  16. package/lib/registries/schema-registry/index.d.ts +2 -2
  17. package/lib/registries/settlement-registry/index.d.ts +2 -2
  18. package/lib/roles/consumer/index.d.ts +2 -24
  19. package/lib/roles/consumer/index.js +5 -26
  20. package/lib/roles/publisher/index.d.ts +17 -15
  21. package/lib/roles/publisher/index.js +39 -27
  22. package/lib/roles/publisher/types.d.ts +5 -7
  23. package/lib/roles/schema/index.d.ts +3 -2
  24. package/lib/roles/schema/index.js +4 -2
  25. package/lib/test/testbed.d.ts +1 -1
  26. package/lib/test/testbed.js +9 -8
  27. package/lib/types/index.d.ts +10 -20
  28. package/package.json +72 -85
  29. package/lib/providers/storage/pinata/index.d.ts +0 -13
  30. package/lib/providers/storage/pinata/index.js +0 -41
  31. package/lib/providers/storage/storacha/index.d.ts +0 -13
  32. package/lib/providers/storage/storacha/index.js +0 -49
  33. package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
  34. package/lib/providers/storage/storacha/readOnly.js +0 -16
package/lib/config.js CHANGED
@@ -32,7 +32,8 @@ const FangornConfig = {
32
32
  chainName: "arbitrumSepolia",
33
33
  chain: arbitrumSepolia,
34
34
  rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
35
- caip2: 421614
35
+ caip2: 421614,
36
+ ipfsGateway: "https://ipfs.io"
36
37
  },
37
38
  BaseSepolia: {
38
39
  dataSourceRegistryContractAddress: "0x6fd0e50073dbd8169bcaf066bb4a4991bfa48eeb",
@@ -41,7 +42,8 @@ const FangornConfig = {
41
42
  chainName: "baseSepolia",
42
43
  chain: baseSepolia,
43
44
  rpcUrl: "https://sepolia.base.org",
44
- caip2: 84532
45
+ caip2: 84532,
46
+ ipfsGateway: "https://ipfs.io"
45
47
  }
46
48
  };
47
49
 
package/lib/fangorn.d.ts CHANGED
@@ -17,24 +17,16 @@ declare class Fangorn {
17
17
  private constructor();
18
18
  /**
19
19
  * Schema owner: register agents, register schemas, validate definitions.
20
- * Requires writable storage.
21
20
  */
22
21
  get schema(): SchemaRole;
23
22
  /**
24
23
  * Publisher: encrypt, stage, and commit data under a schema.
25
- * Requires writable storage.
26
24
  */
27
25
  get publisher(): PublisherRole;
28
26
  /**
29
27
  * Consumer: purchase, claim, and decrypt data.
30
- * Works with both readable and writable storage.
31
28
  */
32
29
  get consumer(): ConsumerRole;
33
- /**
34
- * Create a new Fangorn instance
35
- * @param options
36
- * @returns
37
- */
38
30
  static create(options: FangornCreateOptions): Promise<Fangorn>;
39
31
  getConfig(): AppConfig;
40
32
  getSchemaRegistry(): SchemaRegistry;
package/lib/fangorn.js CHANGED
@@ -1,40 +1,29 @@
1
1
  import { FangornConfig } from "./config.js";
2
2
  import { LitEncryptionService } from "./modules/encryption/lit.js";
3
3
  import "./modules/encryption/index.js";
4
+ import { PinataStorage } from "./providers/storage/pinata.js";
5
+ import "./providers/storage/index.js";
4
6
  import { SchemaRole } from "./roles/schema/index.js";
5
7
  import { SettlementRegistry } from "./registries/settlement-registry/index.js";
6
8
  import { PublisherRole } from "./roles/publisher/index.js";
7
9
  import { ConsumerRole } from "./roles/consumer/index.js";
8
10
  import { SchemaRegistry } from "./registries/schema-registry/index.js";
9
11
  import { DataSourceRegistry } from "./registries/datasource-registry/index.js";
10
- import { PinataStorage } from "./providers/storage/pinata/index.js";
11
- import "./providers/storage/index.js";
12
- import { StorachaStorage } from "./providers/storage/storacha/index.js";
13
- import { ReadOnlyStorachaStorage } from "./providers/storage/storacha/readOnly.js";
14
12
  import { createPublicClient, createWalletClient, http } from "viem";
15
13
  import { privateKeyToAccount } from "viem/accounts";
16
14
 
17
15
  //#region src/fangorn.ts
16
+ const DEFAULT_IPFS_GATEWAY = "https://gateway.pinata.cloud";
18
17
  function isEncryptionService(e) {
19
18
  return typeof e.encrypt === "function";
20
19
  }
21
20
  function isPinataConfig(s) {
22
21
  return "pinata" in s;
23
22
  }
24
- function isStorachaReadOnly(s) {
25
- return "storacha" in s && "readOnly" in s.storacha;
26
- }
27
- function isStorachaConfig(s) {
28
- return "storacha" in s && "email" in s.storacha;
29
- }
30
- function isWritable(s) {
31
- return "store" in s && "delete" in s;
32
- }
33
23
  async function resolveStorage(storage) {
24
+ if (!storage) return void 0;
34
25
  if (isPinataConfig(storage)) return new PinataStorage(storage.pinata.jwt, storage.pinata.gateway);
35
- if (isStorachaReadOnly(storage)) return new ReadOnlyStorachaStorage();
36
- if (isStorachaConfig(storage)) return StorachaStorage.create(storage.storacha.email);
37
- throw new Error("Invalid storage config: must be a StorageProvider instance, a { pinata } object, or a { storacha } object.");
26
+ throw new Error("Invalid storage config: must be { pinata: { jwt, gateway } }.");
38
27
  }
39
28
  var Fangorn = class Fangorn {
40
29
  ctx;
@@ -46,32 +35,24 @@ var Fangorn = class Fangorn {
46
35
  }
47
36
  /**
48
37
  * Schema owner: register agents, register schemas, validate definitions.
49
- * Requires writable storage.
50
38
  */
51
39
  get schema() {
52
- if (!isWritable(this.ctx.storage)) throw new Error("fangorn.schema requires writable storage. Use { storacha: { email } } or { pinata: { ... } }");
53
- return this._schema ??= new SchemaRole(this.ctx.schemaRegistry, this.ctx.storage, this.ctx.walletClient, this.ctx.schemaRoleConfig);
40
+ if (!this.ctx.storage) throw new Error("fangorn.schema requires storage. Pass { pinata: { ... } } to Fangorn.create()");
41
+ return this._schema ??= new SchemaRole(this.ctx.schemaRegistry, this.ctx.storage, this.ctx.walletClient, this.ctx.ipfsGateway, this.ctx.schemaRoleConfig);
54
42
  }
55
43
  /**
56
44
  * Publisher: encrypt, stage, and commit data under a schema.
57
- * Requires writable storage.
58
45
  */
59
46
  get publisher() {
60
- if (!isWritable(this.ctx.storage)) throw new Error("fangorn.publisher requires writable storage. Use { storacha: { email } } or { pinata: { ... } }");
61
- return this._publisher ??= new PublisherRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.storage, this.ctx.encryption, this.ctx.walletClient, this.ctx.config);
47
+ if (!this.ctx.storage) throw new Error("fangorn.publisher requires storage. Pass { pinata: { ... } } to Fangorn.create()");
48
+ return this._publisher ??= new PublisherRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.schemaRegistry, this.ctx.storage, this.ctx.encryption, this.ctx.walletClient, this.ctx.config);
62
49
  }
63
50
  /**
64
51
  * Consumer: purchase, claim, and decrypt data.
65
- * Works with both readable and writable storage.
66
52
  */
67
53
  get consumer() {
68
- return this._consumer ??= new ConsumerRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.storage, this.ctx.encryption, this.ctx.domain);
54
+ return this._consumer ??= new ConsumerRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.encryption, this.ctx.domain, this.ctx.ipfsGateway);
69
55
  }
70
- /**
71
- * Create a new Fangorn instance
72
- * @param options
73
- * @returns
74
- */
75
56
  static async create(options) {
76
57
  if (!options.privateKey && !options.walletClient) throw new Error("Either privateKey or walletClient must be provided");
77
58
  const resolvedConfig = options.config ?? FangornConfig.ArbitrumSepolia;
@@ -83,12 +64,14 @@ var Fangorn = class Fangorn {
83
64
  const storage = await resolveStorage(options.storage);
84
65
  const encryption = isEncryptionService(options.encryption) ? options.encryption : await LitEncryptionService.init(resolvedConfig.chainName);
85
66
  const domain = options.domain ?? new URL(resolvedConfig.rpcUrl).hostname;
67
+ const ipfsGateway = options.ipfsGateway ?? DEFAULT_IPFS_GATEWAY;
86
68
  const publicClient = createPublicClient({ transport: http(resolvedConfig.rpcUrl) });
87
69
  return new Fangorn({
88
70
  walletClient,
89
71
  storage,
90
72
  encryption,
91
73
  domain,
74
+ ipfsGateway,
92
75
  schemaRegistry: new SchemaRegistry(resolvedConfig.schemaRegistryContractAddress, publicClient, walletClient),
93
76
  dataSourceRegistry: new DataSourceRegistry(resolvedConfig.dataSourceRegistryContractAddress, publicClient, walletClient),
94
77
  settlementRegistry: new SettlementRegistry(resolvedConfig.settlementRegistryContractAddress, publicClient, walletClient),
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AppConfig, FangornConfig, SupportedNetworks } from "./config.js";
2
- import { PinataStorage } from "./providers/storage/pinata/index.js";
3
- import { ReadableStorage, WritableStorage } from "./providers/storage/index.js";
2
+ import { PinataStorage } from "./providers/storage/pinata.js";
3
+ import { PinningService, deserialize, retrieveByCid, serialize } from "./providers/storage/index.js";
4
4
  import { Gadget } from "./modules/gadgets/types.js";
5
5
  import "./modules/gadgets/index.js";
6
6
  import { LitEncryptionService } from "./modules/encryption/lit.js";
@@ -9,4 +9,4 @@ import { Fangorn } from "./fangorn.js";
9
9
  import { SETTLEMENT_REGISTRY_ABI } from "./registries/settlement-registry/abi.js";
10
10
  import { DS_REGISTRY_ABI } from "./registries/datasource-registry/abi.js";
11
11
  import { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
12
- export { AppConfig, AuthContext, AuthSig, DS_REGISTRY_ABI, EncryptionService, Fangorn, FangornConfig, Gadget, LitEncryptionService, PinataStorage, ReadableStorage, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, WritableStorage, addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
12
+ export { AppConfig, AuthContext, AuthSig, DS_REGISTRY_ABI, EncryptionService, Fangorn, FangornConfig, Gadget, LitEncryptionService, PinataStorage, PinningService, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
package/lib/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { FangornConfig, SupportedNetworks } from "./config.js";
2
2
  import { LitEncryptionService } from "./modules/encryption/lit.js";
3
3
  import "./modules/encryption/index.js";
4
+ import { PinataStorage } from "./providers/storage/pinata.js";
5
+ import { deserialize, retrieveByCid, serialize } from "./providers/storage/index.js";
4
6
  import { SETTLEMENT_REGISTRY_ABI } from "./registries/settlement-registry/abi.js";
5
7
  import { DS_REGISTRY_ABI } from "./registries/datasource-registry/abi.js";
6
- import { PinataStorage } from "./providers/storage/pinata/index.js";
7
- import "./providers/storage/index.js";
8
8
  import { Fangorn } from "./fangorn.js";
9
9
  import "./registries/index.js";
10
10
  import { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
11
11
 
12
- export { DS_REGISTRY_ABI, Fangorn, FangornConfig, LitEncryptionService, PinataStorage, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
12
+ export { DS_REGISTRY_ABI, Fangorn, FangornConfig, LitEncryptionService, PinataStorage, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
@@ -1,21 +1,21 @@
1
- import { PinataStorage } from "./pinata/index.js";
1
+ import { PinataStorage } from "./pinata.js";
2
2
 
3
3
  //#region src/providers/storage/index.d.ts
4
4
 
5
5
  /**
6
- * Read-only storage (e.g. for a consuming party)
7
- * Does not require any authentication
6
+ * A pinning service that stores content on IPFS and returns a CID.
7
+ * Retrieval is always done via a public gateway — see retrieveByCid.
8
8
  */
9
- interface ReadableStorage<T> {
10
- retrieve(cid: string): Promise<T>;
9
+ interface PinningService {
10
+ store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
11
+ delete(cid: string): Promise<void>;
11
12
  }
13
+ declare function serialize(data: unknown): string;
14
+ declare function deserialize<T>(text: string): T;
12
15
  /**
13
- * Read/Write storage
14
- * (Likely) Requires authentication.
16
+ * Fetch any content by CID from a public IPFS gateway.
17
+ * No auth required — all Fangorn content is public; privacy is cryptographic.
15
18
  */
16
- interface WritableStorage<T> extends ReadableStorage<T> {
17
- store(data: T, metadata?: Record<string, unknown>): Promise<string>;
18
- delete(cid: string): Promise<void>;
19
- }
19
+ declare function retrieveByCid<T>(cid: string, gateway?: string): Promise<T>;
20
20
  //#endregion
21
- export { PinataStorage, ReadableStorage, WritableStorage };
21
+ export { PinataStorage, PinningService, deserialize, retrieveByCid, serialize };
@@ -1,3 +1,48 @@
1
- import { PinataStorage } from "./pinata/index.js";
1
+ import { PinataStorage } from "./pinata.js";
2
2
 
3
- export { PinataStorage };
3
+ //#region src/providers/storage/index.ts
4
+ const REVIVERS = [(_key, value) => {
5
+ if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
6
+ return value;
7
+ }];
8
+ function serialize(data) {
9
+ if (typeof data === "string") return data;
10
+ return JSON.stringify(data, (_key, value) => {
11
+ if (value instanceof Uint8Array) return {
12
+ __type: "Uint8Array",
13
+ data: Buffer.from(value).toString("base64")
14
+ };
15
+ return value;
16
+ });
17
+ }
18
+ function deserialize(text) {
19
+ return JSON.parse(text, (key, value) => {
20
+ for (const reviver of REVIVERS) {
21
+ const result = reviver(key, value);
22
+ if (result !== value) return result;
23
+ }
24
+ return value;
25
+ });
26
+ }
27
+ /**
28
+ * Fetch any content by CID from a public IPFS gateway.
29
+ * No auth required — all Fangorn content is public; privacy is cryptographic.
30
+ */
31
+ async function retrieveByCid(cid, gateway = "https://ipfs.io") {
32
+ const url = `${gateway.replace(/\/$/, "")}/ipfs/${cid}`;
33
+ const controller = new AbortController();
34
+ const timeout = setTimeout(() => controller.abort(), 1e4);
35
+ try {
36
+ const res = await fetch(url, { signal: controller.signal });
37
+ if (!res.ok) throw new Error(`Failed to retrieve ${cid}: ${res.statusText}`);
38
+ return deserialize(await res.text());
39
+ } catch (err) {
40
+ if (err.name === "AbortError") throw new Error(`Timed out retrieving ${cid} from ${url}`);
41
+ throw err;
42
+ } finally {
43
+ clearTimeout(timeout);
44
+ }
45
+ }
46
+
47
+ //#endregion
48
+ export { PinataStorage, deserialize, retrieveByCid, serialize };
@@ -0,0 +1,11 @@
1
+ import { PinningService } from "./index.js";
2
+
3
+ //#region src/providers/storage/pinata.d.ts
4
+ declare class PinataStorage implements PinningService {
5
+ private pinata;
6
+ constructor(pinataJwt: string, pinataGateway: string);
7
+ store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
8
+ delete(cid: string): Promise<void>;
9
+ }
10
+ //#endregion
11
+ export { PinataStorage };
@@ -0,0 +1,24 @@
1
+ import { serialize } from "./index.js";
2
+ import { PinataSDK } from "pinata";
3
+
4
+ //#region src/providers/storage/pinata.ts
5
+ var PinataStorage = class {
6
+ pinata;
7
+ constructor(pinataJwt, pinataGateway) {
8
+ this.pinata = new PinataSDK({
9
+ pinataJwt,
10
+ pinataGateway
11
+ });
12
+ }
13
+ async store(data, metadata) {
14
+ const content = serialize(data);
15
+ const file = new File([content], metadata?.name ?? "file", { type: "text/plain" });
16
+ return (await this.pinata.upload.public.file(file, { metadata })).cid;
17
+ }
18
+ async delete(cid) {
19
+ await this.pinata.files.public.delete([cid]);
20
+ }
21
+ };
22
+
23
+ //#endregion
24
+ export { PinataStorage };
@@ -15,10 +15,11 @@ declare class DataSourceRegistry {
15
15
  private getWriteConfig;
16
16
  getContractAddress(): `0x${string}`;
17
17
  initialize(schemaRegistryAddress: Address): Promise<Hash>;
18
- publishManifest(manifestCid: string, schemaId: Hex): Promise<Hash>;
18
+ publishManifest(manifestCid: string, schemaId: Hex, gas?: bigint): Promise<Hash>;
19
19
  getManifest(owner: Address, schemaId: Hex): Promise<DataSource>;
20
20
  getVersion(owner: Address, schemaId: Hex): Promise<bigint>;
21
21
  waitForTransaction(hash: Hash): Promise<viem431.TransactionReceipt>;
22
+ private estimateGas;
22
23
  }
23
24
  //#endregion
24
25
  export { DataSource, DataSourceRegistry };
@@ -34,15 +34,23 @@ var DataSourceRegistry = class {
34
34
  await this.waitForTransaction(hash);
35
35
  return hash;
36
36
  }
37
- async publishManifest(manifestCid, schemaId) {
37
+ async publishManifest(manifestCid, schemaId, gas) {
38
38
  const { chain, account } = this.getWriteConfig();
39
+ const gasLimit = await this.estimateGas(() => this.publicClient.estimateContractGas({
40
+ address: this.contractAddress,
41
+ abi: DS_REGISTRY_ABI,
42
+ functionName: "publishManifest",
43
+ args: [manifestCid, schemaId],
44
+ account
45
+ }), gas);
39
46
  const hash = await this.walletClient.writeContract({
40
47
  address: this.contractAddress,
41
48
  abi: DS_REGISTRY_ABI,
42
49
  functionName: "publishManifest",
43
50
  args: [manifestCid, schemaId],
44
51
  chain,
45
- account
52
+ account,
53
+ gas: gasLimit
46
54
  });
47
55
  await this.waitForTransaction(hash);
48
56
  return hash;
@@ -76,6 +84,10 @@ var DataSourceRegistry = class {
76
84
  async waitForTransaction(hash) {
77
85
  return this.publicClient.waitForTransactionReceipt({ hash });
78
86
  }
87
+ async estimateGas(fn, override) {
88
+ if (override !== void 0) return override;
89
+ return await fn() * 130n / 100n;
90
+ }
79
91
  };
80
92
 
81
93
  //#endregion
@@ -1,4 +1,4 @@
1
- import * as viem429 from "viem";
1
+ import * as viem0 from "viem";
2
2
  import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
3
 
4
4
  //#region src/registries/schema-registry/index.d.ts
@@ -22,7 +22,7 @@ declare class SchemaRegistry {
22
22
  updateSchema(nameOrId: string, newSpecCid: string, newAgentId: string): Promise<Hash>;
23
23
  getSchema(nameOrId: string): Promise<Schema>;
24
24
  schemaExists(nameOrId: string): Promise<boolean>;
25
- waitForTransaction(hash: Hash): Promise<viem429.TransactionReceipt>;
25
+ waitForTransaction(hash: Hash): Promise<viem0.TransactionReceipt>;
26
26
  private resolveId;
27
27
  }
28
28
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { PrepareSettleParams, PrepareSettleResult, RegisterParams, SettleParams, TransferWithAuthParams, TransferWithAuthPayload } from "./types.js";
2
- import * as viem430 from "viem";
2
+ import * as viem0 from "viem";
3
3
  import { Address, Hex, PublicClient, WalletClient } from "viem";
4
4
 
5
5
  //#region src/registries/settlement-registry/index.d.ts
@@ -66,7 +66,7 @@ declare class SettlementRegistry {
66
66
  * viem topic-encoding edge cases with indexed params.
67
67
  */
68
68
  private fetchGroup;
69
- waitForTransaction(hash: Hex): Promise<viem430.TransactionReceipt>;
69
+ waitForTransaction(hash: Hex): Promise<viem0.TransactionReceipt>;
70
70
  }
71
71
  //#endregion
72
72
  export { SettlementRegistry };
@@ -1,4 +1,3 @@
1
- import { ReadableStorage } from "../../providers/storage/index.js";
2
1
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
3
2
  import { PrepareSettleParams, PrepareSettleResult, TransferWithAuthParams, TransferWithAuthPayload } from "../../registries/settlement-registry/types.js";
4
3
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
@@ -16,34 +15,13 @@ import { Identity } from "@semaphore-protocol/identity";
16
15
  declare class ConsumerRole {
17
16
  private readonly dataSourceRegistry;
18
17
  private readonly settlementRegistry;
19
- private readonly storage;
20
18
  private readonly encryptionService;
21
19
  private readonly domain;
22
- constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, storage: ReadableStorage<unknown>, encryptionService: EncryptionService, domain: string);
23
- /**
24
- * Builds the transfer with auth (ERC-3009) and signs it (EIP-712)
25
- * @param params
26
- * @returns
27
- */
20
+ private readonly ipfsGateway;
21
+ constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, encryptionService: EncryptionService, domain: string, ipfsGateway: string);
28
22
  prepareRegister(params: TransferWithAuthParams): Promise<TransferWithAuthPayload>;
29
- /**
30
- * Builds the zkp to prove you're in a semaphore group
31
- * @param params
32
- * @returns
33
- */
34
23
  prepareSettle(params: PrepareSettleParams): Promise<PrepareSettleResult>;
35
- /**
36
- * Purchase the resource and register in the semaphore group (on success)
37
- * @param params
38
- * @returns
39
- */
40
24
  register(params: PurchaseParams): Promise<PurchaseResult>;
41
- /**
42
- * Claim access to a resource (prove settlement)
43
- * Must register first.
44
- * @param params
45
- * @returns
46
- */
47
25
  claim(params: ClaimParams): Promise<ClaimResult>;
48
26
  /**
49
27
  * Decrypt a specific encrypted field within a record.
@@ -1,3 +1,4 @@
1
+ import { retrieveByCid } from "../../providers/storage/index.js";
1
2
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
2
3
 
3
4
  //#region src/roles/consumer/index.ts
@@ -5,34 +6,19 @@ import { SettlementRegistry } from "../../registries/settlement-registry/index.j
5
6
  * The consumer namespace encapsulates all functionality relative to accessing and consuming data.
6
7
  */
7
8
  var ConsumerRole = class {
8
- constructor(dataSourceRegistry, settlementRegistry, storage, encryptionService, domain) {
9
+ constructor(dataSourceRegistry, settlementRegistry, encryptionService, domain, ipfsGateway) {
9
10
  this.dataSourceRegistry = dataSourceRegistry;
10
11
  this.settlementRegistry = settlementRegistry;
11
- this.storage = storage;
12
12
  this.encryptionService = encryptionService;
13
13
  this.domain = domain;
14
+ this.ipfsGateway = ipfsGateway;
14
15
  }
15
- /**
16
- * Builds the transfer with auth (ERC-3009) and signs it (EIP-712)
17
- * @param params
18
- * @returns
19
- */
20
16
  async prepareRegister(params) {
21
17
  return this.settlementRegistry.prepareTransferWithAuth(params);
22
18
  }
23
- /**
24
- * Builds the zkp to prove you're in a semaphore group
25
- * @param params
26
- * @returns
27
- */
28
19
  async prepareSettle(params) {
29
20
  return this.settlementRegistry.prepareSettle(params);
30
21
  }
31
- /**
32
- * Purchase the resource and register in the semaphore group (on success)
33
- * @param params
34
- * @returns
35
- */
36
22
  async register(params) {
37
23
  const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.tag);
38
24
  return {
@@ -45,12 +31,6 @@ var ConsumerRole = class {
45
31
  resourceId
46
32
  };
47
33
  }
48
- /**
49
- * Claim access to a resource (prove settlement)
50
- * Must register first.
51
- * @param params
52
- * @returns
53
- */
54
34
  async claim(params) {
55
35
  const resourceId = this.deriveResourceId(params.owner, params.schemaId, params.tag);
56
36
  const { hash, nullifier } = await this.settlementRegistry.settle({
@@ -80,8 +60,7 @@ var ConsumerRole = class {
80
60
  }
81
61
  const fieldValue = (await this.getEntry(params.owner, params.schemaId, params.tag)).fields[params.field];
82
62
  if (!fieldValue || typeof fieldValue !== "object") throw new Error(`Field "${params.field}" is missing or invalid`);
83
- const encryptedField = fieldValue;
84
- const encrypted = await this.storage.retrieve(encryptedField.handle.cid);
63
+ const encrypted = await retrieveByCid(fieldValue.handle.cid, this.ipfsGateway);
85
64
  const authContext = params.authContext ?? await this.encryptionService.createAuthContext(params.walletClient, this.domain, params.nullifierHash);
86
65
  return (await this.encryptionService.decrypt(encrypted, authContext)).data;
87
66
  }
@@ -89,7 +68,7 @@ var ConsumerRole = class {
89
68
  try {
90
69
  const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
91
70
  if (!ds.manifestCid || ds.manifestCid === "") return void 0;
92
- return await this.storage.retrieve(ds.manifestCid);
71
+ return retrieveByCid(ds.manifestCid, this.ipfsGateway);
93
72
  } catch {
94
73
  return;
95
74
  }
@@ -1,5 +1,6 @@
1
1
  import { AppConfig } from "../../config.js";
2
- import { WritableStorage } from "../../providers/storage/index.js";
2
+ import { SchemaRegistry } from "../../registries/schema-registry/index.js";
3
+ import { PinningService } from "../../providers/storage/index.js";
3
4
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
4
5
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
5
6
  import { EncryptionService } from "../../modules/encryption/index.js";
@@ -10,20 +11,22 @@ import { Hex, WalletClient } from "viem";
10
11
  declare class PublisherRole {
11
12
  private readonly dataSourceRegistry;
12
13
  private readonly settlementRegistry;
14
+ private readonly schemaRegistry;
13
15
  private readonly storage;
14
16
  private readonly encryptionService;
15
17
  private readonly walletClient;
16
18
  private readonly config;
17
19
  private pendingEntries;
18
- constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, storage: WritableStorage<unknown>, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
20
+ private readonly schemaCache;
21
+ constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, schemaRegistry: SchemaRegistry, storage: PinningService, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
19
22
  /**
20
- * Encrypt and Upload data with Fangorn
21
- * Validate records against the schema, encrypt encrypted
22
- * fields, stage all resolved entries, then commit to IPFS + on-chain.
23
+ * Encrypt and upload data with Fangorn.
24
+ * Validates records against the schema, encrypts encrypted fields,
25
+ * stages all resolved entries, then commits to IPFS + on-chain.
23
26
  *
24
27
  * Each encrypted field within a record is stored as a separate IPFS object
25
28
  * (the ciphertext). The manifest entry stores the handle (CID + gateway)
26
- * alongside the plain fields. Consumers can read plain fields freely and
29
+ * alongside plain fields. Consumers can read plain fields freely and
27
30
  * only need to purchase + decrypt for encrypted fields.
28
31
  */
29
32
  upload(params: UploadParams, price: bigint): Promise<CommitResult>;
@@ -34,33 +37,32 @@ declare class PublisherRole {
34
37
  /**
35
38
  * Serialize all staged entries into a manifest, create SettlementRegistry
36
39
  * resources for each entry, pin the manifest to IPFS, and publish on-chain.
37
- *
38
- * @param schemaId: The unique id of the schema
39
- * @param price: The USDC price required to register with the sempaphore group
40
- * @param overwrite: If true, overwrite manifest data, else append (default: false)
41
- *
42
40
  */
43
41
  commit(schemaId: Hex, price: bigint, overwrite: boolean): Promise<CommitResult>;
44
42
  getManifest(schemaId: Hex): Promise<Manifest | undefined>;
45
43
  getEntry(schemaId: Hex, tag: string): Promise<ManifestEntry>;
46
44
  private requireAccount;
45
+ /**
46
+ * Resolve the schema definition and id by name, with in-memory caching.
47
+ * Schema resolution is concurrent-safe — parallel calls for the same name
48
+ * share a single in-flight promise.
49
+ */
50
+ private resolveSchema;
47
51
  /**
48
52
  * Resolve a PublishRecord into a ManifestEntry by processing each field
49
53
  * according to the schema definition:
50
54
  * - plain fields are stored as-is
51
- * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced
55
+ * - encrypted fields are encrypted, pinned to IPFS, and replaced
52
56
  * with a handle + gadgetDescriptor
53
57
  */
54
58
  private resolveRecord;
55
59
  /**
56
60
  * Validate that a record's fields match the schema before touching IPFS.
57
- * Catches type mismatches and missing required fields early.
58
61
  */
59
62
  private validateRecord;
60
63
  private validateField;
61
64
  /**
62
- * Load the existing manifest into pending entries for merge behaviour.
63
- * Unpins the old manifest CID
65
+ * Load the existing manifest for merge behaviour and unpin the old CID.
64
66
  */
65
67
  private loadExistingManifest;
66
68
  }