@fangorn-network/sdk 2026.3.27 → 2026.3.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/lib/fangorn.d.ts CHANGED
@@ -30,6 +30,11 @@ declare class Fangorn {
30
30
  * Works with both readable and writable storage.
31
31
  */
32
32
  get consumer(): ConsumerRole;
33
+ /**
34
+ * Create a new Fangorn instance
35
+ * @param options
36
+ * @returns
37
+ */
33
38
  static create(options: FangornCreateOptions): Promise<Fangorn>;
34
39
  getConfig(): AppConfig;
35
40
  getSchemaRegistry(): SchemaRegistry;
package/lib/fangorn.js CHANGED
@@ -58,7 +58,7 @@ var Fangorn = class Fangorn {
58
58
  */
59
59
  get publisher() {
60
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);
61
+ return this._publisher ??= new PublisherRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.storage, this.ctx.encryption, this.ctx.walletClient, this.ctx.config);
62
62
  }
63
63
  /**
64
64
  * Consumer: purchase, claim, and decrypt data.
@@ -67,6 +67,11 @@ var Fangorn = class Fangorn {
67
67
  get consumer() {
68
68
  return this._consumer ??= new ConsumerRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.storage, this.ctx.encryption, this.ctx.domain);
69
69
  }
70
+ /**
71
+ * Create a new Fangorn instance
72
+ * @param options
73
+ * @returns
74
+ */
70
75
  static async create(options) {
71
76
  if (!options.privateKey && !options.walletClient) throw new Error("Either privateKey or walletClient must be provided");
72
77
  const resolvedConfig = options.config ?? FangornConfig.ArbitrumSepolia;
@@ -1,3 +1,4 @@
1
+ import { AppConfig } from "../../config.js";
1
2
  import { Gadget, GadgetDescriptor } from "./types.js";
2
3
  import { Address, Hex } from "viem";
3
4
  import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
@@ -10,9 +11,13 @@ interface SettledGadgetParams {
10
11
  settlementRegistryAddress: Address;
11
12
  /** "arbitrumSepolia" | "baseSepolia" */
12
13
  chainName: string;
13
- /** Pinata JWT — used only on the first instantiation to upload the Lit action */
14
- pinataJwt: string;
15
14
  }
15
+ /**
16
+ * Build a new default gadget from the given config
17
+ * @param config : AppConfig
18
+ * @returns the configured gadget
19
+ */
20
+ declare function makeSettledGadgetFactory(config: AppConfig): (resourceId: Hex) => SettledGadget;
16
21
  declare class SettledGadget implements Gadget {
17
22
  private readonly params;
18
23
  readonly type = "settled";
@@ -23,4 +28,4 @@ declare class SettledGadget implements Gadget {
23
28
  toDescriptor(): GadgetDescriptor;
24
29
  }
25
30
  //#endregion
26
- export { SettledGadget, SettledGadgetParams };
31
+ export { SettledGadget, SettledGadgetParams, makeSettledGadgetFactory };
@@ -2,6 +2,18 @@ import { zeroAddress } from "viem";
2
2
  import { createAccBuilder } from "@lit-protocol/access-control-conditions";
3
3
 
4
4
  //#region src/modules/gadgets/settledGadget.ts
5
+ /**
6
+ * Build a new default gadget from the given config
7
+ * @param config : AppConfig
8
+ * @returns the configured gadget
9
+ */
10
+ function makeSettledGadgetFactory(config) {
11
+ return (resourceId) => new SettledGadget({
12
+ resourceId,
13
+ settlementRegistryAddress: config.settlementRegistryContractAddress,
14
+ chainName: config.chainName
15
+ });
16
+ }
5
17
  var SettledGadget = class {
6
18
  type = "settled";
7
19
  constructor(params) {
@@ -60,4 +72,4 @@ var SettledGadget = class {
60
72
  };
61
73
 
62
74
  //#endregion
63
- export { SettledGadget };
75
+ export { SettledGadget, makeSettledGadgetFactory };
@@ -1,4 +1,4 @@
1
- import * as viem0 from "viem";
1
+ import * as viem431 from "viem";
2
2
  import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
3
 
4
4
  //#region src/registries/datasource-registry/index.d.ts
@@ -18,7 +18,7 @@ declare class DataSourceRegistry {
18
18
  publishManifest(manifestCid: string, schemaId: Hex): Promise<Hash>;
19
19
  getManifest(owner: Address, schemaId: Hex): Promise<DataSource>;
20
20
  getVersion(owner: Address, schemaId: Hex): Promise<bigint>;
21
- waitForTransaction(hash: Hash): Promise<viem0.TransactionReceipt>;
21
+ waitForTransaction(hash: Hash): Promise<viem431.TransactionReceipt>;
22
22
  }
23
23
  //#endregion
24
24
  export { DataSource, DataSourceRegistry };
@@ -1,4 +1,4 @@
1
- import * as viem0 from "viem";
1
+ import * as viem429 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<viem0.TransactionReceipt>;
25
+ waitForTransaction(hash: Hash): Promise<viem429.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 viem1 from "viem";
2
+ import * as viem430 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<viem1.TransactionReceipt>;
69
+ waitForTransaction(hash: Hex): Promise<viem430.TransactionReceipt>;
70
70
  }
71
71
  //#endregion
72
72
  export { SettlementRegistry };
@@ -1,3 +1,4 @@
1
+ import { AppConfig } from "../../config.js";
1
2
  import { WritableStorage } from "../../providers/storage/index.js";
2
3
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
3
4
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
@@ -12,8 +13,9 @@ declare class PublisherRole {
12
13
  private readonly storage;
13
14
  private readonly encryptionService;
14
15
  private readonly walletClient;
16
+ private readonly config;
15
17
  private pendingEntries;
16
- constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, storage: WritableStorage<unknown>, encryptionService: EncryptionService, walletClient: WalletClient);
18
+ constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, storage: WritableStorage<unknown>, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
17
19
  /**
18
20
  * Encrypt and Upload data with Fangorn
19
21
  * Validate records against the schema, encrypt encrypted
@@ -25,10 +27,6 @@ declare class PublisherRole {
25
27
  * only need to purchase + decrypt for encrypted fields.
26
28
  */
27
29
  upload(params: UploadParams, price: bigint): Promise<CommitResult>;
28
- /**
29
- * Stage a pre-resolved entry manually (advanced use).
30
- * Prefer upload() for the standard flow.
31
- */
32
30
  stage(entry: ManifestEntry): void;
33
31
  remove(tag: string): boolean;
34
32
  getPending(): ManifestEntry[];
@@ -1,14 +1,16 @@
1
1
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
2
+ import { makeSettledGadgetFactory } from "../../modules/gadgets/settledGadget.js";
2
3
 
3
4
  //#region src/roles/publisher/index.ts
4
5
  var PublisherRole = class {
5
6
  pendingEntries = /* @__PURE__ */ new Map();
6
- constructor(dataSourceRegistry, settlementRegistry, storage, encryptionService, walletClient) {
7
+ constructor(dataSourceRegistry, settlementRegistry, storage, encryptionService, walletClient, config) {
7
8
  this.dataSourceRegistry = dataSourceRegistry;
8
9
  this.settlementRegistry = settlementRegistry;
9
10
  this.storage = storage;
10
11
  this.encryptionService = encryptionService;
11
12
  this.walletClient = walletClient;
13
+ this.config = config;
12
14
  }
13
15
  /**
14
16
  * Encrypt and Upload data with Fangorn
@@ -21,20 +23,20 @@ var PublisherRole = class {
21
23
  * only need to purchase + decrypt for encrypted fields.
22
24
  */
23
25
  async upload(params, price) {
24
- const { records, schema, schemaId, gadgetFactory, gateway, options } = params;
26
+ const { records, schema, schemaId, gateway, options } = params;
27
+ const address = this.requireAccount();
28
+ const gadgetFactory = params.gadgetFactory ?? ((tag) => {
29
+ const resourceId = SettlementRegistry.deriveResourceId(address, schemaId, tag);
30
+ return makeSettledGadgetFactory(this.config)(resourceId);
31
+ });
25
32
  for (const record of records) {
26
- console.log("validating " + JSON.stringify(records[0]));
27
33
  this.validateRecord(record, schema);
28
- const gadget = await gadgetFactory(record.tag);
34
+ const gadget = await gadgetFactory(SettlementRegistry.deriveResourceId(address, schemaId, record.tag));
29
35
  const entry = await this.resolveRecord(record, schema, gadget, gateway);
30
36
  this.pendingEntries.set(record.tag, entry);
31
37
  }
32
38
  return this.commit(schemaId, price, options?.overwrite ?? false);
33
39
  }
34
- /**
35
- * Stage a pre-resolved entry manually (advanced use).
36
- * Prefer upload() for the standard flow.
37
- */
38
40
  stage(entry) {
39
41
  this.pendingEntries.set(entry.tag, entry);
40
42
  }
@@ -68,7 +68,7 @@ interface UploadParams {
68
68
  * fields. All encrypted fields within a record share the same gadget —
69
69
  * and therefore the same resourceId and access condition.
70
70
  */
71
- gadgetFactory: (tag: string) => Gadget | Promise<Gadget>;
71
+ gadgetFactory?: (tag: string) => Gadget | Promise<Gadget>;
72
72
  /**
73
73
  * IPFS gateway URL written into each encrypted field handle so consumers
74
74
  * can retrieve ciphertexts without knowing the storage provider.
@@ -13,10 +13,8 @@ declare class TestBed {
13
13
  private readonly delegatorAddress;
14
14
  private readonly delegatorFangorn;
15
15
  private readonly delegateeFangorn;
16
- private readonly config;
17
16
  private readonly usdcContractAddress;
18
17
  private readonly usdcDomainName;
19
- private readonly pinataJwt;
20
18
  private constructor();
21
19
  /**
22
20
  * Init the testbed client
@@ -35,7 +33,7 @@ declare class TestBed {
35
33
  * @param delegatorPrivateKey
36
34
  * @returns The testbed client
37
35
  */
38
- static init(delegatorWalletClient: WalletClient, delegateeWalletClient: WalletClient, jwt: string, gateway: string, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number, delegatorPrivateKey?: Hex): Promise<TestBed>;
36
+ static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number): Promise<TestBed>;
39
37
  registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
40
38
  registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
41
39
  /**
@@ -1,20 +1,17 @@
1
1
  import { SettlementRegistry } from "../registries/settlement-registry/index.js";
2
2
  import { Fangorn } from "../fangorn.js";
3
- import { SettledGadget } from "../modules/gadgets/settledGadget.js";
4
3
  import { arbitrumSepolia, baseSepolia } from "viem/chains";
5
4
  import { createWalletClient, http } from "viem";
6
5
  import { privateKeyToAccount } from "viem/accounts";
7
6
 
8
7
  //#region src/test/testbed.ts
9
8
  var TestBed = class TestBed {
10
- constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, config, usdcContractAddress, usdcDomainName, pinataJwt) {
9
+ constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName) {
11
10
  this.delegatorAddress = delegatorAddress;
12
11
  this.delegatorFangorn = delegatorFangorn;
13
12
  this.delegateeFangorn = delegateeFangorn;
14
- this.config = config;
15
13
  this.usdcContractAddress = usdcContractAddress;
16
14
  this.usdcDomainName = usdcDomainName;
17
- this.pinataJwt = pinataJwt;
18
15
  }
19
16
  /**
20
17
  * Init the testbed client
@@ -33,7 +30,7 @@ var TestBed = class TestBed {
33
30
  * @param delegatorPrivateKey
34
31
  * @returns The testbed client
35
32
  */
36
- static async init(delegatorWalletClient, delegateeWalletClient, jwt, gateway, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2, delegatorPrivateKey) {
33
+ static async init(delegatorWalletClient, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2) {
37
34
  let chainImpl = arbitrumSepolia;
38
35
  if (chain === "baseSepolia") chainImpl = baseSepolia;
39
36
  const config = {
@@ -45,13 +42,10 @@ var TestBed = class TestBed {
45
42
  rpcUrl,
46
43
  caip2
47
44
  };
48
- const agentConfig = delegatorPrivateKey ? {
49
- privateKey: delegatorPrivateKey,
50
- pinataJwt: jwt
51
- } : void 0;
45
+ const agentConfig = void 0;
52
46
  const delegatorFangorn = await Fangorn.create({
53
47
  privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
54
- storage: { storacha: { "email": "driemworks@fangorn.network" } },
48
+ storage: { storacha: { "email": process.env.TEST_EMAIL_ADDR ?? "" } },
55
49
  encryption: { lit: true },
56
50
  config,
57
51
  domain: "localhost",
@@ -65,7 +59,7 @@ var TestBed = class TestBed {
65
59
  domain: "localhost"
66
60
  });
67
61
  if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
68
- return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, config, usdcContractAddress, usdcDomainName, jwt);
62
+ return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
69
63
  }
70
64
  async registerAgent(params) {
71
65
  return this.delegatorFangorn.schema.registerAgent(params);
@@ -86,18 +80,11 @@ var TestBed = class TestBed {
86
80
  * full purchase → claim flow for each specific tag before decrypting.
87
81
  */
88
82
  async fileUpload(records, schema, schemaId, gateway, price) {
89
- const owner = this.delegatorFangorn.getAddress();
90
83
  const { manifestCid } = await this.delegatorFangorn.publisher.upload({
91
84
  records,
92
85
  schema,
93
86
  schemaId,
94
- gateway,
95
- gadgetFactory: (tag) => new SettledGadget({
96
- resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
97
- settlementRegistryAddress: this.config.settlementRegistryContractAddress,
98
- chainName: this.config.chainName,
99
- pinataJwt: this.pinataJwt
100
- })
87
+ gateway
101
88
  }, price);
102
89
  return manifestCid;
103
90
  }
package/package.json CHANGED
@@ -1,74 +1,87 @@
1
1
  {
2
- "name": "@fangorn-network/sdk",
3
- "version": "2026.03.27",
4
- "description": "A zero-knowledge conditional access control framework",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/fangorn-network/fangorn.git"
8
- },
9
- "bin": {
10
- "fangorn": "lib/cli/cli.js"
11
- },
12
- "license": "MIT",
13
- "type": "module",
14
- "main": "lib/index.js",
15
- "files": [
16
- "lib/"
17
- ],
18
- "lint-staged": {
19
- "*": "prettier --ignore-unknown --write"
20
- },
21
- "devDependencies": {
22
- "@dotenvx/dotenvx": "^1.51.1",
23
- "@eslint/js": "9.39.1",
24
- "@types/node": "24.10.1",
25
- "@vitest/coverage-v8": "4.0.15",
26
- "@vitest/eslint-plugin": "1.5.1",
27
- "eslint": "9.39.1",
28
- "husky": "9.1.7",
29
- "lint-staged": "16.2.7",
30
- "prettier": "3.7.3",
31
- "tsdown": "0.16.8",
32
- "tsx": "^4.21.0",
33
- "typescript": "5.8.3",
34
- "typescript-eslint": "8.48.1",
35
- "vitest": "^4.0.18"
36
- },
37
- "engines": {
38
- "node": ">=20.19.0"
39
- },
40
- "dependencies": {
41
- "@a2a-js/sdk": "^0.3.10",
42
- "@clack/prompts": "^1.0.1",
43
- "@lit-protocol/access-control-conditions": "^8.0.2",
44
- "@lit-protocol/auth": "^8.2.2",
45
- "@lit-protocol/auth-helpers": "^8.2.1",
46
- "@lit-protocol/lit-client": "^8.3.1",
47
- "@lit-protocol/networks": "^8.4.1",
48
- "@semaphore-protocol/group": "^4.14.2",
49
- "@semaphore-protocol/identity": "^4.14.2",
50
- "@semaphore-protocol/proof": "^4.14.2",
51
- "@storacha/client": "^2.1.3",
52
- "agent0-sdk": "^1.5.3",
53
- "commander": "^14.0.3",
54
- "dotenv": "^17.2.3",
55
- "ethers": "^6.16.0",
56
- "pinata": "^2.5.2",
57
- "solc": "^0.8.28",
58
- "viem": "^2.47.1"
59
- },
60
- "overrides": {
61
- "viem": "$viem"
62
- },
63
- "scripts": {
64
- "build": "tsdown",
65
- "format": "prettier . --write",
66
- "lint": "eslint . --max-warnings 0",
67
- "test": "dotenvx run -f .env -- vitest run",
68
- "test:e2e": "dotenvx run -f .env -- vitest run --config vitest.e2e.config.ts",
69
- "tsc": "tsc",
70
- "deploy": "dotenvx run -f .env -- tsx deploy.ts",
71
- "prepare:cli": "npm run build",
72
- "fangorn": "dotenvx run -f .env -- node dist/src/cli/cli.js"
73
- }
2
+ "name": "@fangorn-network/sdk",
3
+ "version": "2026.03.28",
4
+ "description": "A zero-knowledge conditional access control framework",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/fangorn-network/fangorn.git"
8
+ },
9
+ "bin": {
10
+ "fangorn": "lib/cli/cli.js"
11
+ },
12
+ "license": "MIT",
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "files": [
16
+ "lib/"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsdown",
20
+ "format": "prettier . --write",
21
+ "lint": "eslint . --max-warnings 0",
22
+ "prepare": "husky",
23
+ "test": "dotenvx run -f .env -- vitest run",
24
+ "test:e2e": "dotenvx run -f .env -- vitest run --config vitest.e2e.config.ts",
25
+ "tsc": "tsc",
26
+ "deploy": "dotenvx run -f .env -- tsx deploy.ts",
27
+ "prepare:cli": "npm run build",
28
+ "fangorn": "dotenvx run -f .env -- node dist/src/cli/cli.js"
29
+ },
30
+ "lint-staged": {
31
+ "*": "prettier --ignore-unknown --write"
32
+ },
33
+ "devDependencies": {
34
+ "@dotenvx/dotenvx": "^1.51.1",
35
+ "@eslint/js": "9.39.1",
36
+ "@types/node": "24.10.1",
37
+ "@vitest/coverage-v8": "4.0.15",
38
+ "@vitest/eslint-plugin": "1.5.1",
39
+ "eslint": "9.39.1",
40
+ "husky": "9.1.7",
41
+ "lint-staged": "16.2.7",
42
+ "prettier": "3.7.3",
43
+ "tsdown": "0.16.8",
44
+ "tsx": "^4.21.0",
45
+ "typescript": "5.8.3",
46
+ "typescript-eslint": "8.48.1",
47
+ "vitest": "^4.0.18"
48
+ },
49
+ "packageManager": "pnpm@10.4.0",
50
+ "engines": {
51
+ "node": ">=20.19.0"
52
+ },
53
+ "dependencies": {
54
+ "@a2a-js/sdk": "^0.3.10",
55
+ "@clack/prompts": "^1.0.1",
56
+ "@lit-protocol/access-control-conditions": "^8.0.2",
57
+ "@lit-protocol/auth": "^8.2.2",
58
+ "@lit-protocol/auth-helpers": "^8.2.1",
59
+ "@lit-protocol/lit-client": "^8.3.1",
60
+ "@lit-protocol/networks": "^8.4.1",
61
+ "@semaphore-protocol/group": "^4.14.2",
62
+ "@semaphore-protocol/identity": "^4.14.2",
63
+ "@semaphore-protocol/proof": "^4.14.2",
64
+ "@storacha/client": "^2.1.3",
65
+ "agent0-sdk": "^1.5.3",
66
+ "commander": "^14.0.3",
67
+ "dotenv": "^17.2.3",
68
+ "ethers": "^6.16.0",
69
+ "pinata": "^2.5.2",
70
+ "solc": "^0.8.28",
71
+ "viem": "^2.47.1"
72
+ },
73
+ "overrides": {
74
+ "viem": "$viem"
75
+ },
76
+ "pnpm": {
77
+ "overrides": {
78
+ "write-file-atomic": "7.0.0"
79
+ },
80
+ "peerDependencyRules": {
81
+ "allowedVersions": {
82
+ "viem": ">=2.38.3",
83
+ "ethers": ">=5.7.2"
84
+ }
85
+ }
86
+ }
74
87
  }