@fangorn-network/sdk 2026.3.29 → 2026.4.7

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.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);
53
+ return this._schema ??= new SchemaRole(this.ctx.schemaRegistry, this.ctx.storage, this.ctx.walletClient, this.ctx.schemaRoleConfig);
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, this.ctx.config);
61
+ 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
62
  }
63
63
  /**
64
64
  * Consumer: purchase, claim, and decrypt data.
@@ -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";
@@ -11,6 +12,12 @@ interface SettledGadgetParams {
11
12
  /** "arbitrumSepolia" | "baseSepolia" */
12
13
  chainName: string;
13
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;
14
21
  declare class SettledGadget implements Gadget {
15
22
  private readonly params;
16
23
  readonly type = "settled";
@@ -21,4 +28,4 @@ declare class SettledGadget implements Gadget {
21
28
  toDescriptor(): GadgetDescriptor;
22
29
  }
23
30
  //#endregion
24
- 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 viem429 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/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<viem429.TransactionReceipt>;
21
+ waitForTransaction(hash: Hash): Promise<viem257.TransactionReceipt>;
22
22
  }
23
23
  //#endregion
24
24
  export { DataSource, DataSourceRegistry };
@@ -1,4 +1,4 @@
1
- import * as viem430 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/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<viem430.TransactionReceipt>;
25
+ waitForTransaction(hash: Hash): Promise<viem258.TransactionReceipt>;
26
26
  private resolveId;
27
27
  }
28
28
  //#endregion
@@ -1,4 +1,5 @@
1
1
  import { AppConfig } from "../../config.js";
2
+ import { SchemaRegistry } from "../../registries/schema-registry/index.js";
2
3
  import { WritableStorage } 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";
@@ -10,12 +11,14 @@ 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: WritableStorage<unknown>, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
19
22
  /**
20
23
  * Encrypt and Upload data with Fangorn
21
24
  * Validate records against the schema, encrypt encrypted
@@ -44,12 +47,17 @@ declare class PublisherRole {
44
47
  getManifest(schemaId: Hex): Promise<Manifest | undefined>;
45
48
  getEntry(schemaId: Hex, tag: string): Promise<ManifestEntry>;
46
49
  private requireAccount;
50
+ /**
51
+ * Resolve the schema def and id by name
52
+ * @param name The name of the schema
53
+ * @returns The schema and id if they exist
54
+ */
55
+ private resolveSchema;
47
56
  /**
48
57
  * Resolve a PublishRecord into a ManifestEntry by processing each field
49
58
  * according to the schema definition:
50
59
  * - plain fields are stored as-is
51
- * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced
52
- * with a handle + gadgetDescriptor
60
+ * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced with a handle + gadgetDescriptor
53
61
  */
54
62
  private resolveRecord;
55
63
  /**
@@ -1,12 +1,14 @@
1
1
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
2
- import { SettledGadget } from "../../modules/gadgets/settledGadget.js";
2
+ import { makeSettledGadgetFactory } from "../../modules/gadgets/settledGadget.js";
3
3
 
4
4
  //#region src/roles/publisher/index.ts
5
5
  var PublisherRole = class {
6
6
  pendingEntries = /* @__PURE__ */ new Map();
7
- constructor(dataSourceRegistry, settlementRegistry, storage, encryptionService, walletClient, config) {
7
+ schemaCache = /* @__PURE__ */ new Map();
8
+ constructor(dataSourceRegistry, settlementRegistry, schemaRegistry, storage, encryptionService, walletClient, config) {
8
9
  this.dataSourceRegistry = dataSourceRegistry;
9
10
  this.settlementRegistry = settlementRegistry;
11
+ this.schemaRegistry = schemaRegistry;
10
12
  this.storage = storage;
11
13
  this.encryptionService = encryptionService;
12
14
  this.walletClient = walletClient;
@@ -23,20 +25,17 @@ var PublisherRole = class {
23
25
  * only need to purchase + decrypt for encrypted fields.
24
26
  */
25
27
  async upload(params, price) {
26
- const { records, schema, schemaId, gateway, options } = params;
28
+ const { records, schemaName, gateway, options } = params;
27
29
  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
- };
30
+ const { schema, schemaId } = await this.resolveSchema(schemaName);
31
+ console.log("got the schemaId " + schemaId);
32
+ console.log("got the schema " + JSON.stringify(schema));
33
+ const gadgetFactory = params.gadgetFactory ?? ((resourceId) => {
34
+ return makeSettledGadgetFactory(this.config)(resourceId);
35
+ });
35
36
  for (const record of records) {
36
37
  this.validateRecord(record, schema);
37
- const resourceId = SettlementRegistry.deriveResourceId(address, schemaId, record.tag);
38
- console.log("using resource Id" + resourceId);
39
- const gadget = gadgetFactory(record.tag);
38
+ const gadget = await gadgetFactory(SettlementRegistry.deriveResourceId(address, schemaId, record.tag));
40
39
  const entry = await this.resolveRecord(record, schema, gadget, gateway);
41
40
  this.pendingEntries.set(record.tag, entry);
42
41
  }
@@ -118,11 +117,30 @@ var PublisherRole = class {
118
117
  return address;
119
118
  }
120
119
  /**
120
+ * Resolve the schema def and id by name
121
+ * @param name The name of the schema
122
+ * @returns The schema and id if they exist
123
+ */
124
+ resolveSchema(name) {
125
+ if (!this.schemaCache.has(name)) {
126
+ const p = Promise.all([this.schemaRegistry.getSchema(name), this.schemaRegistry.schemaId(name)]).then(async ([{ cid }, schemaId]) => {
127
+ return {
128
+ schema: (await this.storage.retrieve(cid)).definition,
129
+ schemaId
130
+ };
131
+ }).catch((err) => {
132
+ this.schemaCache.delete(name);
133
+ throw err;
134
+ });
135
+ this.schemaCache.set(name, p);
136
+ }
137
+ return this.schemaCache.get(name);
138
+ }
139
+ /**
121
140
  * Resolve a PublishRecord into a ManifestEntry by processing each field
122
141
  * according to the schema definition:
123
142
  * - plain fields are stored as-is
124
- * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced
125
- * with a handle + gadgetDescriptor
143
+ * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced with a handle + gadgetDescriptor
126
144
  */
127
145
  async resolveRecord(record, schema, gadget, gateway) {
128
146
  const resolvedFields = {};
@@ -1,4 +1,3 @@
1
- import { SchemaDefinition } from "../schema/types.js";
2
1
  import { Gadget, GadgetDescriptor } from "../../modules/gadgets/types.js";
3
2
  import "../../modules/gadgets/index.js";
4
3
  import { Address, Hex } from "viem";
@@ -57,12 +56,7 @@ interface Manifest {
57
56
  }
58
57
  interface UploadParams {
59
58
  records: PublishRecord[];
60
- /**
61
- * The schema the records must conform to. Required — field-level encryption
62
- * decisions are driven by the schema definition.
63
- */
64
- schema: SchemaDefinition;
65
- schemaId: Hex;
59
+ schemaName: string;
66
60
  /**
67
61
  * Called once per record to produce the gadget for that record's encrypted
68
62
  * fields. All encrypted fields within a record share the same gadget —
@@ -8,7 +8,12 @@ declare class SchemaRole {
8
8
  private readonly schemaRegistry;
9
9
  private readonly storage;
10
10
  private readonly walletClient;
11
- constructor(schemaRegistry: SchemaRegistry, storage: WritableStorage<unknown>, walletClient: 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>;
12
17
  /**
13
18
  * Register a schema on-chain, tied to an existing agent identity.
14
19
  *
@@ -33,6 +38,7 @@ declare class SchemaRole {
33
38
  */
34
39
  validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
35
40
  private requireAccount;
41
+ private requireAgent0;
36
42
  }
37
43
  //#endregion
38
44
  export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
@@ -1,9 +1,36 @@
1
+ import { SDK } from "agent0-sdk";
2
+
1
3
  //#region src/roles/schema/index.ts
2
4
  var SchemaRole = class {
3
- constructor(schemaRegistry, storage, walletClient) {
5
+ agent0;
6
+ constructor(schemaRegistry, storage, walletClient, config) {
4
7
  this.schemaRegistry = schemaRegistry;
5
8
  this.storage = storage;
6
9
  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 };
7
34
  }
8
35
  /**
9
36
  * Register a schema on-chain, tied to an existing agent identity.
@@ -100,6 +127,10 @@ var SchemaRole = class {
100
127
  if (!address) throw new Error("No account connected to wallet client");
101
128
  return address;
102
129
  }
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
+ }
103
134
  };
104
135
 
105
136
  //#endregion
@@ -1,4 +1,4 @@
1
- import { SchemaDefinition } from "../roles/schema/types.js";
1
+ import { RegisterAgentParams, RegisteredAgent, 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";
@@ -34,6 +34,7 @@ declare class TestBed {
34
34
  * @returns The testbed client
35
35
  */
36
36
  static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number): Promise<TestBed>;
37
+ registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
37
38
  registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
38
39
  /**
39
40
  * Upload files encrypted under SettledGadget.
@@ -42,7 +43,7 @@ declare class TestBed {
42
43
  * which is baked into the ACC at encryption time. A buyer must complete the
43
44
  * full purchase → claim flow for each specific tag before decrypting.
44
45
  */
45
- fileUpload(records: PublishRecord[], schema: SchemaDefinition, schemaId: Hex, gateway: string, price: bigint): Promise<string>;
46
+ fileUpload(records: PublishRecord[], schemaName: string, gateway: string, price: bigint): Promise<string>;
46
47
  prepareRegister(burnerPrivateKey: Hex, paymentRecipient: Address, amount: bigint): Promise<TransferWithAuthPayload>;
47
48
  register(owner: Address, schemaId: Hex, tag: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
48
49
  prepareSettle(owner: Address, schemaId: Hex, tag: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
@@ -42,14 +42,16 @@ var TestBed = class TestBed {
42
42
  rpcUrl,
43
43
  caip2
44
44
  };
45
- const agentConfig = void 0;
46
45
  const delegatorFangorn = await Fangorn.create({
47
46
  privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
48
- storage: { storacha: { "email": process.env.TEST_EMAIL_ADDR ?? "" } },
47
+ storage: { pinata: {
48
+ jwt: process.env.PINATA_JWT ?? "",
49
+ gateway: process.env.PINATA_GATEWAY ?? ""
50
+ } },
49
51
  encryption: { lit: true },
50
52
  config,
51
53
  domain: "localhost",
52
- agentConfig
54
+ agentConfig: void 0
53
55
  });
54
56
  const delegateeFangorn = await Fangorn.create({
55
57
  privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
@@ -61,6 +63,9 @@ var TestBed = class TestBed {
61
63
  if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
62
64
  return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
63
65
  }
66
+ async registerAgent(params) {
67
+ return this.delegatorFangorn.schema.registerAgent(params);
68
+ }
64
69
  async registerSchema(name, definition, agentId) {
65
70
  const { schemaId } = await this.delegatorFangorn.schema.register({
66
71
  name,
@@ -76,11 +81,10 @@ var TestBed = class TestBed {
76
81
  * which is baked into the ACC at encryption time. A buyer must complete the
77
82
  * full purchase → claim flow for each specific tag before decrypting.
78
83
  */
79
- async fileUpload(records, schema, schemaId, gateway, price) {
84
+ async fileUpload(records, schemaName, gateway, price) {
80
85
  const { manifestCid } = await this.delegatorFangorn.publisher.upload({
81
86
  records,
82
- schema,
83
- schemaId,
87
+ schemaName,
84
88
  gateway
85
89
  }, price);
86
90
  return manifestCid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.03.29",
3
+ "version": "2026.04.07",
4
4
  "description": "A zero-knowledge conditional access control framework",
5
5
  "repository": {
6
6
  "type": "git",