@fangorn-network/sdk 2026.4.10 → 2026.4.22

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 (44) hide show
  1. package/README.md +126 -144
  2. package/lib/cli/cli.js +42 -96
  3. package/lib/cli/index.d.ts +170 -170
  4. package/lib/config.d.ts +257 -257
  5. package/lib/config.js +3 -3
  6. package/lib/fangorn.d.ts +3 -17
  7. package/lib/fangorn.js +12 -37
  8. package/lib/index.d.ts +3 -7
  9. package/lib/index.js +3 -5
  10. package/lib/modules/encryption/aes.d.ts +3 -3
  11. package/lib/modules/encryption/index.d.ts +1 -28
  12. package/lib/modules/encryption/index.js +1 -3
  13. package/lib/modules/encryption/types.d.ts +1 -48
  14. package/lib/providers/storage/index.d.ts +4 -21
  15. package/lib/providers/storage/index.js +3 -49
  16. package/lib/providers/storage/pinata.d.ts +8 -5
  17. package/lib/providers/storage/pinata.js +16 -8
  18. package/lib/providers/storage/types.d.ts +37 -0
  19. package/lib/providers/storage/utils.d.ts +12 -0
  20. package/lib/providers/storage/utils.js +50 -0
  21. package/lib/registries/datasource-registry/index.d.ts +2 -2
  22. package/lib/registries/schema-registry/index.d.ts +2 -2
  23. package/lib/registries/settlement-registry/index.d.ts +2 -2
  24. package/lib/roles/consumer/index.d.ts +14 -18
  25. package/lib/roles/consumer/index.js +73 -24
  26. package/lib/roles/consumer/types.d.ts +13 -32
  27. package/lib/roles/publisher/index.d.ts +17 -32
  28. package/lib/roles/publisher/index.js +37 -74
  29. package/lib/roles/publisher/types.d.ts +36 -41
  30. package/lib/roles/schema/index.d.ts +4 -25
  31. package/lib/roles/schema/index.js +5 -30
  32. package/lib/roles/schema/types.d.ts +16 -2
  33. package/lib/test/testbed.d.ts +6 -5
  34. package/lib/test/testbed.js +16 -26
  35. package/lib/types/index.d.ts +12 -45
  36. package/package.json +1 -6
  37. package/lib/modules/encryption/lit.d.ts +0 -20
  38. package/lib/modules/encryption/lit.js +0 -121
  39. package/lib/modules/gadgets/index.d.ts +0 -2
  40. package/lib/modules/gadgets/index.js +0 -1
  41. package/lib/modules/gadgets/settledGadget.d.ts +0 -24
  42. package/lib/modules/gadgets/settledGadget.js +0 -63
  43. package/lib/modules/gadgets/types.d.ts +0 -27
  44. /package/lib/{modules/gadgets → providers/storage}/types.js +0 -0
package/lib/config.js CHANGED
@@ -26,9 +26,9 @@ function getNetwork(name) {
26
26
  }
27
27
  const FangornConfig = {
28
28
  ArbitrumSepolia: {
29
- dataSourceRegistryContractAddress: "0xdb82c131a9d51f6e7695e744bb2bd7774cbb224c",
30
- schemaRegistryContractAddress: "0x35b67934f9c75bfef6ff3f4d61ff406d81420066",
31
- settlementRegistryContractAddress: "0x6aff8212e126ed3232958fd228bc58a202b8f590",
29
+ dataSourceRegistryContractAddress: "0x0e61ca2dbba225580aeab641ab43d623bf5c7e5f",
30
+ schemaRegistryContractAddress: "0x4615b03ccaf5e834490a94211e129e6ee8ec6604",
31
+ settlementRegistryContractAddress: "0x0309df3ccb232023934b68c9ed068dec74be42cc",
32
32
  chainName: "arbitrumSepolia",
33
33
  chain: arbitrumSepolia,
34
34
  rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
package/lib/fangorn.d.ts CHANGED
@@ -2,10 +2,10 @@ import { AppConfig } from "./config.js";
2
2
  import { SchemaRegistry } from "./registries/schema-registry/index.js";
3
3
  import { SchemaRole } from "./roles/schema/index.js";
4
4
  import { DataSourceRegistry } from "./registries/datasource-registry/index.js";
5
- import { SettlementRegistry } from "./registries/settlement-registry/index.js";
6
- import { FangornCreateOptions } from "./types/index.js";
7
5
  import { PublisherRole } from "./roles/publisher/index.js";
6
+ import { SettlementRegistry } from "./registries/settlement-registry/index.js";
8
7
  import { ConsumerRole } from "./roles/consumer/index.js";
8
+ import { FangornCreateOptions } from "./types/index.js";
9
9
  import { Hex, WalletClient } from "viem";
10
10
 
11
11
  //#region src/fangorn.d.ts
@@ -15,24 +15,10 @@ declare class Fangorn {
15
15
  private _publisher;
16
16
  private _consumer;
17
17
  private constructor();
18
- /**
19
- * Schema owner: register agents, register schemas, validate definitions.
20
- */
21
18
  get schema(): SchemaRole;
22
- /**
23
- * Publisher: encrypt, stage, and commit data under a schema.
24
- */
25
19
  get publisher(): PublisherRole;
26
- /**
27
- * Consumer: purchase, claim, and decrypt data.
28
- */
29
20
  get consumer(): ConsumerRole;
30
- /**
31
- * Create a new Fangorn instance
32
- * @param options
33
- * @returns
34
- */
35
- static create(options: FangornCreateOptions): Promise<Fangorn>;
21
+ static create(options: FangornCreateOptions): Fangorn;
36
22
  getConfig(): AppConfig;
37
23
  getSchemaRegistry(): SchemaRegistry;
38
24
  getDatasourceRegistry(): DataSourceRegistry;
package/lib/fangorn.js CHANGED
@@ -1,11 +1,8 @@
1
1
  import { FangornConfig } from "./config.js";
2
- import { LitEncryptionService } from "./modules/encryption/lit.js";
3
- import "./modules/encryption/index.js";
4
- import { PinataStorage } from "./providers/storage/pinata.js";
5
- import "./providers/storage/index.js";
6
2
  import { SchemaRole } from "./roles/schema/index.js";
7
- import { DataSourceRegistry } from "./registries/datasource-registry/index.js";
8
3
  import { PublisherRole } from "./roles/publisher/index.js";
4
+ import { DataSourceRegistry } from "./registries/datasource-registry/index.js";
5
+ import { PinataBackend } from "./providers/storage/pinata.js";
9
6
  import { ConsumerRole } from "./roles/consumer/index.js";
10
7
  import { SchemaRegistry } from "./registries/schema-registry/index.js";
11
8
  import { SettlementRegistry } from "./registries/settlement-registry/index.js";
@@ -13,17 +10,13 @@ import { createPublicClient, createWalletClient, http } from "viem";
13
10
  import { privateKeyToAccount } from "viem/accounts";
14
11
 
15
12
  //#region src/fangorn.ts
16
- const DEFAULT_IPFS_GATEWAY = "https://ipfs.io";
17
- function isEncryptionService(e) {
18
- return typeof e.encrypt === "function";
19
- }
20
13
  function isPinataConfig(s) {
21
14
  return "pinata" in s;
22
15
  }
23
16
  function resolveStorage(storage) {
24
17
  if (!storage) return void 0;
25
- if (isPinataConfig(storage)) return new PinataStorage(storage.pinata.jwt, storage.pinata.gateway);
26
- throw new Error(`Invalid storage config: must be { pinata: { jwt, gateway } }, but was ${JSON.stringify(storage)}`);
18
+ if (isPinataConfig(storage)) return new PinataBackend(storage.pinata.jwt, storage.pinata.gateway);
19
+ throw new Error(`Invalid storage config: must be { pinata: { jwt, gateway } }, got ${JSON.stringify(storage)}`);
27
20
  }
28
21
  var Fangorn = class Fangorn {
29
22
  ctx;
@@ -33,32 +26,18 @@ var Fangorn = class Fangorn {
33
26
  constructor(ctx) {
34
27
  this.ctx = ctx;
35
28
  }
36
- /**
37
- * Schema owner: register agents, register schemas, validate definitions.
38
- */
39
29
  get schema() {
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);
30
+ if (!this.ctx.metadataStorage) throw new Error("fangorn.schema requires storage. Pass { pinata: { ... } } to Fangorn.create()");
31
+ return this._schema ??= new SchemaRole(this.ctx.schemaRegistry, this.ctx.metadataStorage, this.ctx.walletClient);
42
32
  }
43
- /**
44
- * Publisher: encrypt, stage, and commit data under a schema.
45
- */
46
33
  get publisher() {
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.schemaRegistry, this.ctx.storage, this.ctx.encryption, this.ctx.walletClient, this.ctx.config);
34
+ if (!this.ctx.metadataStorage) throw new Error("fangorn.publisher requires storage. Pass { pinata: { ... } } to Fangorn.create()");
35
+ return this._publisher ??= new PublisherRole(this.ctx.dataSourceRegistry, this.ctx.schemaRegistry, this.ctx.metadataStorage, this.ctx.walletClient, this.ctx.config);
49
36
  }
50
- /**
51
- * Consumer: purchase, claim, and decrypt data.
52
- */
53
37
  get consumer() {
54
- return this._consumer ??= new ConsumerRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.encryption, this.ctx.domain, this.ctx.ipfsGateway);
38
+ return this._consumer ??= new ConsumerRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry);
55
39
  }
56
- /**
57
- * Create a new Fangorn instance
58
- * @param options
59
- * @returns
60
- */
61
- static async create(options) {
40
+ static create(options) {
62
41
  if (!options.privateKey && !options.walletClient) throw new Error("Either privateKey or walletClient must be provided");
63
42
  const resolvedConfig = options.config ?? FangornConfig.ArbitrumSepolia;
64
43
  const walletClient = options.walletClient ?? createWalletClient({
@@ -66,17 +45,13 @@ var Fangorn = class Fangorn {
66
45
  chain: resolvedConfig.chain,
67
46
  transport: http(resolvedConfig.rpcUrl)
68
47
  });
69
- const storage = resolveStorage(options.storage);
70
- const encryption = isEncryptionService(options.encryption) ? options.encryption : await LitEncryptionService.init(resolvedConfig.chainName);
48
+ const metadataStorage = resolveStorage(options.storage);
71
49
  const domain = options.domain ?? new URL(resolvedConfig.rpcUrl).hostname;
72
- const ipfsGateway = options.ipfsGateway ?? DEFAULT_IPFS_GATEWAY;
73
50
  const publicClient = createPublicClient({ transport: http(resolvedConfig.rpcUrl) });
74
51
  return new Fangorn({
75
52
  walletClient,
76
- storage,
77
- encryption,
53
+ metadataStorage,
78
54
  domain,
79
- ipfsGateway,
80
55
  schemaRegistry: new SchemaRegistry(resolvedConfig.schemaRegistryContractAddress, publicClient, walletClient),
81
56
  dataSourceRegistry: new DataSourceRegistry(resolvedConfig.dataSourceRegistryContractAddress, publicClient, walletClient),
82
57
  settlementRegistry: new SettlementRegistry(resolvedConfig.settlementRegistryContractAddress, publicClient, walletClient),
package/lib/index.d.ts CHANGED
@@ -1,12 +1,8 @@
1
1
  import { AppConfig, FangornConfig, SupportedNetworks } from "./config.js";
2
- import { PinataStorage } from "./providers/storage/pinata.js";
3
- import { PinningService, deserialize, retrieveByCid, serialize } from "./providers/storage/index.js";
4
- import { Gadget } from "./modules/gadgets/types.js";
5
- import "./modules/gadgets/index.js";
6
- import { LitEncryptionService } from "./modules/encryption/lit.js";
7
- import { AuthContext, AuthSig, EncryptionService } from "./modules/encryption/index.js";
8
2
  import { Fangorn } from "./fangorn.js";
3
+ import { PinataBackend } from "./providers/storage/pinata.js";
4
+ import { deserialize, retrieveByCid, serialize } from "./providers/storage/utils.js";
9
5
  import { SETTLEMENT_REGISTRY_ABI } from "./registries/settlement-registry/abi.js";
10
6
  import { DS_REGISTRY_ABI } from "./registries/datasource-registry/abi.js";
11
7
  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, PinningService, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
8
+ export { AppConfig, DS_REGISTRY_ABI, Fangorn, FangornConfig, PinataBackend, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
package/lib/index.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { FangornConfig, SupportedNetworks } from "./config.js";
2
- import { LitEncryptionService } from "./modules/encryption/lit.js";
3
- import "./modules/encryption/index.js";
4
- import { PinataStorage } from "./providers/storage/pinata.js";
5
- import { deserialize, retrieveByCid, serialize } from "./providers/storage/index.js";
6
2
  import { DS_REGISTRY_ABI } from "./registries/datasource-registry/abi.js";
3
+ import { deserialize, retrieveByCid, serialize } from "./providers/storage/utils.js";
4
+ import { PinataBackend } from "./providers/storage/pinata.js";
7
5
  import { SETTLEMENT_REGISTRY_ABI } from "./registries/settlement-registry/abi.js";
8
6
  import { Fangorn } from "./fangorn.js";
9
7
  import { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
10
8
 
11
- export { DS_REGISTRY_ABI, Fangorn, FangornConfig, LitEncryptionService, PinataStorage, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
9
+ export { DS_REGISTRY_ABI, Fangorn, FangornConfig, PinataBackend, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
@@ -1,10 +1,10 @@
1
- import { EncryptedData } from "../../types/index.js";
1
+ import { AesEncryptedData } from "./types.js";
2
2
 
3
3
  //#region src/modules/encryption/aes.d.ts
4
4
  declare function encryptData(data: string | Uint8Array): Promise<{
5
- encryptedData: EncryptedData;
5
+ encryptedData: AesEncryptedData;
6
6
  keyMaterial: Uint8Array<ArrayBuffer>;
7
7
  }>;
8
- declare function decryptData(encryptedData: EncryptedData, keyMaterial: Uint8Array<ArrayBuffer>): Promise<Uint8Array>;
8
+ declare function decryptData(encryptedData: AesEncryptedData, keyMaterial: Uint8Array<ArrayBuffer>): Promise<Uint8Array>;
9
9
  //#endregion
10
10
  export { decryptData, encryptData };
@@ -1,28 +1 @@
1
- import { Gadget } from "../gadgets/types.js";
2
- import { Filedata } from "../../types/index.js";
3
- import "../gadgets/index.js";
4
- import { DecryptedPayload, EncryptedPayload } from "./types.js";
5
- import { LitEncryptionService } from "./lit.js";
6
- import { WalletClient } from "viem";
7
-
8
- //#region src/modules/encryption/index.d.ts
9
- interface EncryptionService {
10
- encrypt(file: Filedata, gadget: Gadget): Promise<EncryptedPayload>;
11
- decrypt(payload: EncryptedPayload, authContext: AuthContext): Promise<DecryptedPayload>;
12
- createAuthContext(walletClient: WalletClient, domain: string, nullifierHash: bigint): Promise<AuthContext>;
13
- }
14
- /**
15
- * Auth context needed for Lit decryption
16
- */
17
- interface AuthContext {
18
- authSig: AuthSig;
19
- sessionContext?: unknown;
20
- }
21
- interface AuthSig {
22
- sig: string;
23
- derivedVia: string;
24
- signedMessage: string;
25
- address: string;
26
- }
27
- //#endregion
28
- export { AuthContext, AuthSig, EncryptionService, LitEncryptionService };
1
+ export { };
@@ -1,3 +1 @@
1
- import { LitEncryptionService } from "./lit.js";
2
-
3
- export { LitEncryptionService };
1
+ export { };
@@ -1,60 +1,13 @@
1
- import { createAuthManager } from "@lit-protocol/auth";
2
- import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
3
-
4
1
  //#region src/modules/encryption/types.d.ts
5
- type EoaAuthContext = Awaited<ReturnType<ReturnType<typeof createAuthManager>["createEoaAuthContext"]>>;
6
2
  interface AesEncryptedData {
7
3
  ciphertext: Uint8Array<ArrayBuffer>;
8
4
  iv: Uint8Array<ArrayBuffer>;
9
5
  authTag: Uint8Array<ArrayBuffer>;
10
6
  salt: Uint8Array<ArrayBuffer>;
11
7
  }
12
- interface LitEncryptedData {
13
- ciphertext: string;
14
- dataToEncryptHash: string;
15
- }
16
- interface EncryptedPayload {
17
- /** Locally AES-encrypted file bytes */
18
- data: AesEncryptedData;
19
- /** Lit-threshold-encrypted AES key */
20
- key: {
21
- ciphertext: string;
22
- dataToEncryptHash: string;
23
- };
24
- /**
25
- * The ACC used to encrypt the key — stored here so decrypt() can
26
- * reconstruct the exact conditions without re-deriving them from
27
- * the gadget. The gadget is a publisher-time concept; the consumer
28
- * only has the payload.
29
- */
30
- acc: UnifiedAccessControlCondition[];
31
- }
32
8
  interface DecryptedPayload {
33
9
  data: Uint8Array;
34
10
  }
35
- /**
36
- * Lit's access control condition structure
37
- * Using a loose type since Lit's ACC shape is complex and varies by condition type
38
- */
39
- type AccessControlCondition = Record<string, unknown>;
40
- /**
41
- * Auth signature for Lit
42
- */
43
- interface AuthSig {
44
- sig: string;
45
- derivedVia: string;
46
- signedMessage: string;
47
- address: string;
48
- }
49
- /**
50
- * Context needed to authenticate with Lit for decryption
51
- */
52
- interface AuthContextWrapper {
53
- authSig: AuthSig;
54
- sessionContext: EoaAuthContext;
55
- chainName: string;
56
- nullifierHash?: string;
57
- }
58
11
  /**
59
12
  * Result of successful decryption
60
13
  */
@@ -67,4 +20,4 @@ interface DecryptedPayload {
67
20
  };
68
21
  }
69
22
  //#endregion
70
- export { AccessControlCondition, AesEncryptedData, AuthContextWrapper, AuthSig, DecryptedPayload, EncryptedPayload, EoaAuthContext, LitEncryptedData };
23
+ export { AesEncryptedData, DecryptedPayload };
@@ -1,21 +1,4 @@
1
- import { PinataStorage } from "./pinata.js";
2
-
3
- //#region src/providers/storage/index.d.ts
4
-
5
- /**
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
- */
9
- interface PinningService {
10
- store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
11
- delete(cid: string): Promise<void>;
12
- }
13
- declare function serialize(data: unknown): string;
14
- declare function deserialize(text: string): unknown;
15
- /**
16
- * Fetch any content by CID from a public IPFS gateway.
17
- * No auth required — all Fangorn content is public; privacy is cryptographic.
18
- */
19
- declare function retrieveByCid<T>(cid: string, gateway?: string): Promise<T>;
20
- //#endregion
21
- export { PinataStorage, PinningService, deserialize, retrieveByCid, serialize };
1
+ import { MetadataStorage, StorageMeta } from "./types.js";
2
+ import { PinataBackend } from "./pinata.js";
3
+ import { deserialize, retrieveByCid, serialize } from "./utils.js";
4
+ export { type MetadataStorage, PinataBackend, type StorageMeta, deserialize, retrieveByCid, serialize };
@@ -1,50 +1,4 @@
1
- import { PinataStorage } from "./pinata.js";
1
+ import { deserialize, retrieveByCid, serialize } from "./utils.js";
2
+ import { PinataBackend } from "./pinata.js";
2
3
 
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(() => {
35
- controller.abort();
36
- }, 1e4);
37
- try {
38
- const res = await fetch(url, { signal: controller.signal });
39
- if (!res.ok) throw new Error(`Failed to retrieve ${cid}: ${res.statusText}`);
40
- return deserialize(await res.text());
41
- } catch (err) {
42
- if (err.name === "AbortError") throw new Error(`Timed out retrieving ${cid} from ${url}`);
43
- throw err;
44
- } finally {
45
- clearTimeout(timeout);
46
- }
47
- }
48
-
49
- //#endregion
50
- export { PinataStorage, deserialize, retrieveByCid, serialize };
4
+ export { PinataBackend, deserialize, retrieveByCid, serialize };
@@ -1,11 +1,14 @@
1
- import { PinningService } from "./index.js";
1
+ import { MetadataStorage, StorageMeta } from "./types.js";
2
2
 
3
3
  //#region src/providers/storage/pinata.d.ts
4
- declare class PinataStorage implements PinningService {
4
+ declare class PinataBackend implements MetadataStorage {
5
5
  private pinata;
6
+ private gateway;
6
7
  constructor(pinataJwt: string, pinataGateway: string);
7
- store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
8
- delete(cid: string): Promise<void>;
8
+ put(data: unknown, meta?: StorageMeta): Promise<string>;
9
+ get<T>(uri: string): Promise<T>;
10
+ static getStatic<T>(uri: string): Promise<T>;
11
+ delete(uri: string): Promise<void>;
9
12
  }
10
13
  //#endregion
11
- export { PinataStorage };
14
+ export { PinataBackend };
@@ -1,24 +1,32 @@
1
- import { serialize } from "./index.js";
1
+ import { retrieveByCid, serialize } from "./utils.js";
2
2
  import { PinataSDK } from "pinata";
3
3
 
4
4
  //#region src/providers/storage/pinata.ts
5
- var PinataStorage = class {
5
+ var PinataBackend = class {
6
6
  pinata;
7
+ gateway;
7
8
  constructor(pinataJwt, pinataGateway) {
8
9
  this.pinata = new PinataSDK({
9
10
  pinataJwt,
10
11
  pinataGateway
11
12
  });
13
+ this.gateway = pinataGateway;
12
14
  }
13
- async store(data, metadata) {
15
+ async put(data, meta) {
14
16
  const content = serialize(data);
15
- const file = new File([content], (metadata ?? { name: "file" }).name, { type: "text/plain" });
16
- return (await this.pinata.upload.public.file(file, { metadata })).cid;
17
+ const file = new File([content], meta?.name ?? "file", { type: "text/plain" });
18
+ return (await this.pinata.upload.public.file(file, { metadata: meta })).cid;
17
19
  }
18
- async delete(cid) {
19
- await this.pinata.files.public.delete([cid]);
20
+ async get(uri) {
21
+ return retrieveByCid(uri);
22
+ }
23
+ static async getStatic(uri) {
24
+ return retrieveByCid(uri);
25
+ }
26
+ async delete(uri) {
27
+ await this.pinata.files.public.delete([uri]);
20
28
  }
21
29
  };
22
30
 
23
31
  //#endregion
24
- export { PinataStorage };
32
+ export { PinataBackend };
@@ -0,0 +1,37 @@
1
+ //#region src/providers/storage/types.d.ts
2
+ /**
3
+ * StorageBackend — backend-agnostic interface for storing and retrieving
4
+ * opaque content. The URI returned by put() is the only thing callers
5
+ * hold onto; get() knows how to resolve it.
6
+ */
7
+ interface StorageMeta {
8
+ name?: string;
9
+ [key: string]: unknown;
10
+ }
11
+ interface MetadataStorage {
12
+ /**
13
+ * Store content and return an opaque URI.
14
+ * Callers never construct or parse URIs — treat them as handles.
15
+ */
16
+ put(data: unknown, meta?: StorageMeta): Promise<string>;
17
+ /**
18
+ * Retrieve content by URI previously returned from put().
19
+ */
20
+ get<T>(uri: string): Promise<T>;
21
+ /**
22
+ * Delete content by URI. Best-effort — implementations may no-op.
23
+ */
24
+ delete(uri: string): Promise<void>;
25
+ }
26
+ /**
27
+ * Proof required by access-controlled backends (e.g. R2 via the Fangorn worker).
28
+ * Plain backends (e.g. IPFS) ignore this entirely.
29
+ */
30
+ interface AccessProof {
31
+ nullifier: string;
32
+ resourceId: string;
33
+ timestamp: number;
34
+ signature: `0x${string}`;
35
+ }
36
+ //#endregion
37
+ export { AccessProof, MetadataStorage, StorageMeta };
@@ -0,0 +1,12 @@
1
+ import { PinataBackend } from "./pinata.js";
2
+
3
+ //#region src/providers/storage/utils.d.ts
4
+ declare function serialize(data: unknown): string;
5
+ declare function deserialize(text: string): unknown;
6
+ /**
7
+ * Fetch any content by CID from a public IPFS gateway.
8
+ * No auth required — all Fangorn content is public; privacy is cryptographic.
9
+ */
10
+ declare function retrieveByCid<T>(cid: string, gateway?: string, timeoutSecond?: number): Promise<T>;
11
+ //#endregion
12
+ export { PinataBackend, deserialize, retrieveByCid, serialize };
@@ -0,0 +1,50 @@
1
+ import { PinataBackend } from "./pinata.js";
2
+
3
+ //#region src/providers/storage/utils.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", timeoutSecond = 16e3) {
32
+ const url = `${gateway.replace(/\/$/, "")}/ipfs/${cid}`;
33
+ const controller = new AbortController();
34
+ const timeout = setTimeout(() => {
35
+ controller.abort();
36
+ }, timeoutSecond);
37
+ try {
38
+ const res = await fetch(url, { signal: controller.signal });
39
+ if (!res.ok) throw new Error(`Failed to retrieve ${cid}: ${res.statusText}`);
40
+ return deserialize(await res.text());
41
+ } catch (err) {
42
+ if (err.name === "AbortError") throw new Error(`Timed out retrieving ${cid} from ${url}`);
43
+ throw err;
44
+ } finally {
45
+ clearTimeout(timeout);
46
+ }
47
+ }
48
+
49
+ //#endregion
50
+ export { PinataBackend, deserialize, retrieveByCid, serialize };
@@ -1,4 +1,4 @@
1
- import * as viem0 from "viem";
1
+ import * as viem258 from "viem";
2
2
  import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
3
 
4
4
  //#region src/registries/datasource-registry/index.d.ts
@@ -23,7 +23,7 @@ declare class DataSourceRegistry {
23
23
  resourceId(owner: Address, schemaId: Hex, name: string): Promise<Hex>;
24
24
  static resourceIdLocal(owner: Address, schemaId: Hex, name: string): Hex;
25
25
  hashName(name: string): Hex;
26
- waitForTransaction(hash: Hash): Promise<viem0.TransactionReceipt>;
26
+ waitForTransaction(hash: Hash): Promise<viem258.TransactionReceipt>;
27
27
  private estimateGas;
28
28
  }
29
29
  //#endregion
@@ -1,4 +1,4 @@
1
- import * as viem173 from "viem";
1
+ import * as viem257 from "viem";
2
2
  import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
3
 
4
4
  //#region src/registries/schema-registry/index.d.ts
@@ -27,7 +27,7 @@ declare class SchemaRegistry {
27
27
  hasPublishers(nameOrId: string): Promise<boolean>;
28
28
  isPublisher(nameOrId: string, publisher: Address): Promise<boolean>;
29
29
  getPublisherCount(nameOrId: string): Promise<bigint>;
30
- waitForTransaction(hash: Hash): Promise<viem173.TransactionReceipt>;
30
+ waitForTransaction(hash: Hash): Promise<viem257.TransactionReceipt>;
31
31
  private resolveId;
32
32
  }
33
33
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { PrepareSettleParams, PrepareSettleResult, RegisterParams, SettleParams, TransferWithAuthParams, TransferWithAuthPayload } from "./types.js";
2
- import * as viem0 from "viem";
2
+ import * as viem431 from "viem";
3
3
  import { Address, Hex, PublicClient, WalletClient } from "viem";
4
4
 
5
5
  //#region src/registries/settlement-registry/index.d.ts
@@ -59,7 +59,7 @@ declare class SettlementRegistry {
59
59
  getGroupId(resourceId: Hex): Promise<bigint>;
60
60
  getPrice(resourceId: Hex): Promise<bigint>;
61
61
  getOwner(resourceId: Hex): Promise<Address>;
62
- waitForTransaction(hash: Hex): Promise<viem0.TransactionReceipt>;
62
+ waitForTransaction(hash: Hex): Promise<viem431.TransactionReceipt>;
63
63
  /**
64
64
  * Reconstruct the Semaphore group from MemberRegistered events.
65
65
  */
@@ -1,41 +1,37 @@
1
1
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
2
+ import { Manifest, ManifestEntry } from "../publisher/types.js";
2
3
  import { PrepareSettleParams, PrepareSettleResult, TransferWithAuthParams, TransferWithAuthPayload } from "../../registries/settlement-registry/types.js";
3
4
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
4
- import { EncryptionService } from "../../modules/encryption/index.js";
5
- import { Manifest, ManifestEntry } from "../publisher/types.js";
6
- import { ClaimParams, ClaimResult, DecryptParams, PurchaseParams, PurchaseResult } from "./types.js";
7
- import { Address, Hex } from "viem";
5
+ import { ClaimParams, ClaimResult, FetchParams, FetchResult, PurchaseParams, PurchaseResult } from "./types.js";
6
+ import { Address, Hex, WalletClient } from "viem";
8
7
  import { Identity } from "@semaphore-protocol/identity";
9
8
 
10
9
  //#region src/roles/consumer/index.d.ts
11
-
12
- /**
13
- * The consumer namespace encapsulates all functionality relative to
14
- * accessing and consuming data.
15
- */
16
10
  declare class ConsumerRole {
17
11
  private readonly dataSourceRegistry;
18
12
  private readonly settlementRegistry;
19
- private readonly encryptionService;
20
- private readonly domain;
21
- private readonly ipfsGateway;
22
- constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, encryptionService: EncryptionService, domain: string, ipfsGateway: string);
13
+ constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry);
23
14
  prepareRegister(params: TransferWithAuthParams): Promise<TransferWithAuthPayload>;
24
15
  prepareSettle(params: PrepareSettleParams): Promise<PrepareSettleResult>;
25
16
  register(params: PurchaseParams): Promise<PurchaseResult>;
26
17
  claim(params: ClaimParams): Promise<ClaimResult>;
27
18
  /**
28
- * Decrypt a specific encrypted field within a record.
19
+ * Fetch a handle field's content from the Fangorn access worker.
29
20
  *
30
- * One purchase + claim unlocks ALL encrypted fields in the record —
31
- * the resource is at the record (name) level, not the field level.
32
- * This method can be called once per encrypted field without re-purchasing.
21
+ * The consumer signs { nullifier, resourceId, objectKey, timestamp } with
22
+ * their stealth address private key. The worker recovers the address,
23
+ * verifies is_settled() on-chain, and proxies the R2 bytes.
33
24
  *
34
25
  * Plain fields can be read freely via getEntry() without any of this.
35
26
  */
36
- decrypt(params: DecryptParams): Promise<Uint8Array>;
27
+ fetch(params: FetchParams): Promise<FetchResult>;
37
28
  getManifest(owner: Address, schemaId: Hex, name: string): Promise<Manifest | undefined>;
38
29
  getEntry(owner: Address, schemaId: Hex, name: string): Promise<ManifestEntry>;
30
+ /**
31
+ * Resolves the handle URI for a specific field
32
+ * and fetches it via the worker in one call.
33
+ */
34
+ fetchField(owner: Address, schemaId: Hex, name: string, field: string, nullifier: string, walletClient: WalletClient): Promise<FetchResult>;
39
35
  isRegistered(owner: Address, schemaId: Hex, name: string, identity: Identity): Promise<boolean>;
40
36
  private deriveResourceId;
41
37
  }