@fangorn-network/sdk 2026.3.27 → 2026.3.29

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
@@ -50,7 +50,7 @@ var Fangorn = class Fangorn {
50
50
  */
51
51
  get schema() {
52
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);
53
+ return this._schema ??= new SchemaRole(this.ctx.schemaRegistry, this.ctx.storage, this.ctx.walletClient);
54
54
  }
55
55
  /**
56
56
  * Publisher: encrypt, stage, and commit data under a schema.
@@ -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;
@@ -10,8 +10,6 @@ interface SettledGadgetParams {
10
10
  settlementRegistryAddress: Address;
11
11
  /** "arbitrumSepolia" | "baseSepolia" */
12
12
  chainName: string;
13
- /** Pinata JWT — used only on the first instantiation to upload the Lit action */
14
- pinataJwt: string;
15
13
  }
16
14
  declare class SettledGadget implements Gadget {
17
15
  private readonly params;
@@ -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/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<viem429.TransactionReceipt>;
22
22
  }
23
23
  //#endregion
24
24
  export { DataSource, DataSourceRegistry };
@@ -1,4 +1,4 @@
1
- import * as viem0 from "viem";
1
+ import * as viem430 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<viem430.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 viem431 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<viem431.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 { SettledGadget } 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,25 @@ 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 = (tag) => {
29
+ return new SettledGadget({
30
+ resourceId: SettlementRegistry.deriveResourceId(address, schemaId, tag),
31
+ settlementRegistryAddress: this.config.settlementRegistryContractAddress,
32
+ chainName: this.config.chainName
33
+ });
34
+ };
25
35
  for (const record of records) {
26
- console.log("validating " + JSON.stringify(records[0]));
27
36
  this.validateRecord(record, schema);
28
- const gadget = await gadgetFactory(record.tag);
37
+ const resourceId = SettlementRegistry.deriveResourceId(address, schemaId, record.tag);
38
+ console.log("using resource Id" + resourceId);
39
+ const gadget = gadgetFactory(record.tag);
29
40
  const entry = await this.resolveRecord(record, schema, gadget, gateway);
30
41
  this.pendingEntries.set(record.tag, entry);
31
42
  }
32
43
  return this.commit(schemaId, price, options?.overwrite ?? false);
33
44
  }
34
- /**
35
- * Stage a pre-resolved entry manually (advanced use).
36
- * Prefer upload() for the standard flow.
37
- */
38
45
  stage(entry) {
39
46
  this.pendingEntries.set(entry.tag, entry);
40
47
  }
@@ -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.
@@ -8,12 +8,7 @@ declare class SchemaRole {
8
8
  private readonly schemaRegistry;
9
9
  private readonly storage;
10
10
  private readonly walletClient;
11
- private readonly agent0;
12
- constructor(schemaRegistry: SchemaRegistry, storage: WritableStorage<unknown>, walletClient: WalletClient, config?: SchemaRoleConfig);
13
- /**
14
- * Register an agent identity via the agent0-sdk / ERC-8004.
15
- */
16
- registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
11
+ constructor(schemaRegistry: SchemaRegistry, storage: WritableStorage<unknown>, walletClient: WalletClient);
17
12
  /**
18
13
  * Register a schema on-chain, tied to an existing agent identity.
19
14
  *
@@ -38,7 +33,6 @@ declare class SchemaRole {
38
33
  */
39
34
  validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
40
35
  private requireAccount;
41
- private requireAgent0;
42
36
  }
43
37
  //#endregion
44
38
  export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
@@ -1,36 +1,9 @@
1
- import { SDK } from "agent0-sdk";
2
-
3
1
  //#region src/roles/schema/index.ts
4
2
  var SchemaRole = class {
5
- agent0;
6
- constructor(schemaRegistry, storage, walletClient, config) {
3
+ constructor(schemaRegistry, storage, walletClient) {
7
4
  this.schemaRegistry = schemaRegistry;
8
5
  this.storage = storage;
9
6
  this.walletClient = walletClient;
10
- this.agent0 = config ? new SDK({
11
- chainId: config.chainId,
12
- rpcUrl: config.rpcUrl,
13
- privateKey: config.privateKey,
14
- ipfs: "pinata",
15
- pinataJwt: config.pinataJwt,
16
- ...config.registryOverrides && { registryOverrides: config.registryOverrides },
17
- ...config.subgraphOverrides && { subgraphOverrides: config.subgraphOverrides }
18
- }) : null;
19
- }
20
- /**
21
- * Register an agent identity via the agent0-sdk / ERC-8004.
22
- */
23
- async registerAgent(params) {
24
- const agent = this.requireAgent0().createAgent(params.name, params.description);
25
- if (params.a2aUrl) await agent.setA2A(params.a2aUrl);
26
- if (params.mcpEndpoint) await agent.setMCP(params.mcpEndpoint);
27
- if (params.ens) agent.setENS(params.ens);
28
- agent.setActive(true);
29
- agent.setX402Support(true);
30
- const { result: registrationFile } = await (await agent.registerIPFS()).waitConfirmed();
31
- const agentId = registrationFile.agentId;
32
- if (!agentId) throw new Error("ERC-8004 registration did not return an agentId");
33
- return { agentId };
34
7
  }
35
8
  /**
36
9
  * Register a schema on-chain, tied to an existing agent identity.
@@ -127,10 +100,6 @@ var SchemaRole = class {
127
100
  if (!address) throw new Error("No account connected to wallet client");
128
101
  return address;
129
102
  }
130
- requireAgent0() {
131
- if (!this.agent0) throw new Error("registerAgent() requires AgentConfig (privateKey + pinataJwt). Pass agentConfig to Fangorn.init() to enable ERC-8004 registration.");
132
- return this.agent0;
133
- }
134
103
  };
135
104
 
136
105
  //#endregion
@@ -1,4 +1,4 @@
1
- import { RegisterAgentParams, RegisteredAgent, SchemaDefinition } from "../roles/schema/types.js";
1
+ import { SchemaDefinition } from "../roles/schema/types.js";
2
2
  import "../roles/schema/index.js";
3
3
  import { PrepareSettleResult, TransferWithAuthPayload } from "../registries/settlement-registry/types.js";
4
4
  import { SettlementRegistry } from "../registries/settlement-registry/index.js";
@@ -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,8 +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>;
39
- registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
36
+ static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number): Promise<TestBed>;
40
37
  registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
41
38
  /**
42
39
  * Upload files encrypted under SettledGadget.
@@ -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,10 +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);
69
- }
70
- async registerAgent(params) {
71
- return this.delegatorFangorn.schema.registerAgent(params);
62
+ return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
72
63
  }
73
64
  async registerSchema(name, definition, agentId) {
74
65
  const { schemaId } = await this.delegatorFangorn.schema.register({
@@ -86,18 +77,11 @@ var TestBed = class TestBed {
86
77
  * full purchase → claim flow for each specific tag before decrypting.
87
78
  */
88
79
  async fileUpload(records, schema, schemaId, gateway, price) {
89
- const owner = this.delegatorFangorn.getAddress();
90
80
  const { manifestCid } = await this.delegatorFangorn.publisher.upload({
91
81
  records,
92
82
  schema,
93
83
  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
- })
84
+ gateway
101
85
  }, price);
102
86
  return manifestCid;
103
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.03.27",
3
+ "version": "2026.03.29",
4
4
  "description": "A zero-knowledge conditional access control framework",
5
5
  "repository": {
6
6
  "type": "git",