@fangorn-network/sdk 2026.3.29 → 2026.4.0-8.dev

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 (37) hide show
  1. package/README.md +24 -31
  2. package/lib/cli/cli.js +18 -2
  3. package/lib/config.d.ts +241 -238
  4. package/lib/config.js +4 -2
  5. package/lib/fangorn.d.ts +0 -3
  6. package/lib/fangorn.js +12 -24
  7. package/lib/index.d.ts +3 -3
  8. package/lib/index.js +3 -3
  9. package/lib/modules/encryption/lit.d.ts +0 -1
  10. package/lib/modules/encryption/lit.js +1 -7
  11. package/lib/modules/gadgets/settledGadget.d.ts +8 -1
  12. package/lib/modules/gadgets/settledGadget.js +13 -1
  13. package/lib/providers/storage/index.d.ts +12 -12
  14. package/lib/providers/storage/index.js +47 -2
  15. package/lib/providers/storage/pinata.d.ts +11 -0
  16. package/lib/providers/storage/pinata.js +24 -0
  17. package/lib/registries/datasource-registry/index.d.ts +4 -3
  18. package/lib/registries/datasource-registry/index.js +17 -2
  19. package/lib/registries/settlement-registry/index.js +11 -13
  20. package/lib/registries/settlement-registry/types.d.ts +6 -3
  21. package/lib/roles/consumer/index.d.ts +2 -24
  22. package/lib/roles/consumer/index.js +5 -26
  23. package/lib/roles/publisher/index.d.ts +19 -17
  24. package/lib/roles/publisher/index.js +45 -38
  25. package/lib/roles/publisher/types.d.ts +5 -7
  26. package/lib/roles/schema/index.d.ts +9 -2
  27. package/lib/roles/schema/index.js +35 -2
  28. package/lib/test/testbed.d.ts +3 -2
  29. package/lib/test/testbed.js +18 -9
  30. package/lib/types/index.d.ts +10 -20
  31. package/package.json +1 -1
  32. package/lib/providers/storage/pinata/index.d.ts +0 -13
  33. package/lib/providers/storage/pinata/index.js +0 -41
  34. package/lib/providers/storage/storacha/index.d.ts +0 -13
  35. package/lib/providers/storage/storacha/index.js +0 -49
  36. package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
  37. package/lib/providers/storage/storacha/readOnly.js +0 -16
@@ -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,21 +11,23 @@ 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 schema-conformant data
24
+ * Validates records against the schema, encrypts fields as required,
25
+ * stages all resolved entries, then commits to IPFS and publishes onchain.
23
26
  *
24
27
  * Each encrypted field within a record is stored as a separate IPFS object
25
- * (the ciphertext). The manifest entry stores the handle (CID + gateway)
26
- * alongside the plain fields. Consumers can read plain fields freely and
27
- * only need to purchase + decrypt for encrypted fields.
28
+ * (the ciphertext). The manifest entry stores the handle (CID and gateway)
29
+ * alongside plain fields. Consumers can read plain fields freely and
30
+ * only need to purchase and decrypt for encrypted fields.
28
31
  */
29
32
  upload(params: UploadParams, price: bigint): Promise<CommitResult>;
30
33
  stage(entry: ManifestEntry): void;
@@ -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
  }
@@ -1,42 +1,40 @@
1
+ import { retrieveByCid } from "../../providers/storage/index.js";
1
2
  import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
2
- import { SettledGadget } from "../../modules/gadgets/settledGadget.js";
3
+ import { makeSettledGadgetFactory } from "../../modules/gadgets/settledGadget.js";
3
4
 
4
5
  //#region src/roles/publisher/index.ts
5
6
  var PublisherRole = class {
6
7
  pendingEntries = /* @__PURE__ */ new Map();
7
- constructor(dataSourceRegistry, settlementRegistry, storage, encryptionService, walletClient, config) {
8
+ schemaCache = /* @__PURE__ */ new Map();
9
+ constructor(dataSourceRegistry, settlementRegistry, schemaRegistry, storage, encryptionService, walletClient, config) {
8
10
  this.dataSourceRegistry = dataSourceRegistry;
9
11
  this.settlementRegistry = settlementRegistry;
12
+ this.schemaRegistry = schemaRegistry;
10
13
  this.storage = storage;
11
14
  this.encryptionService = encryptionService;
12
15
  this.walletClient = walletClient;
13
16
  this.config = config;
14
17
  }
15
18
  /**
16
- * Encrypt and Upload data with Fangorn
17
- * Validate records against the schema, encrypt encrypted
18
- * fields, stage all resolved entries, then commit to IPFS + on-chain.
19
+ * Encrypt and upload schema-conformant data
20
+ * Validates records against the schema, encrypts fields as required,
21
+ * stages all resolved entries, then commits to IPFS and publishes onchain.
19
22
  *
20
23
  * Each encrypted field within a record is stored as a separate IPFS object
21
- * (the ciphertext). The manifest entry stores the handle (CID + gateway)
22
- * alongside the plain fields. Consumers can read plain fields freely and
23
- * only need to purchase + decrypt for encrypted fields.
24
+ * (the ciphertext). The manifest entry stores the handle (CID and gateway)
25
+ * alongside plain fields. Consumers can read plain fields freely and
26
+ * only need to purchase and decrypt for encrypted fields.
24
27
  */
25
28
  async upload(params, price) {
26
- const { records, schema, schemaId, gateway, options } = params;
29
+ const { records, schemaName, gateway, options } = params;
27
30
  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
- };
31
+ const { schema, schemaId } = await this.resolveSchema(schemaName);
32
+ const gadgetFactory = params.gadgetFactory ?? ((resourceId) => {
33
+ return makeSettledGadgetFactory(this.config)(resourceId);
34
+ });
35
35
  for (const record of records) {
36
36
  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);
37
+ const gadget = await gadgetFactory(SettlementRegistry.deriveResourceId(address, schemaId, record.tag));
40
38
  const entry = await this.resolveRecord(record, schema, gadget, gateway);
41
39
  this.pendingEntries.set(record.tag, entry);
42
40
  }
@@ -57,11 +55,6 @@ var PublisherRole = class {
57
55
  /**
58
56
  * Serialize all staged entries into a manifest, create SettlementRegistry
59
57
  * resources for each entry, pin the manifest to IPFS, and publish on-chain.
60
- *
61
- * @param schemaId: The unique id of the schema
62
- * @param price: The USDC price required to register with the sempaphore group
63
- * @param overwrite: If true, overwrite manifest data, else append (default: false)
64
- *
65
58
  */
66
59
  async commit(schemaId, price, overwrite) {
67
60
  const owner = this.requireAccount();
@@ -77,8 +70,8 @@ var PublisherRole = class {
77
70
  }
78
71
  }
79
72
  if (!overwrite) {
80
- const vals = (await this.loadExistingManifest(owner, schemaId)).values();
81
- entries = [...Array.from(vals), ...entries];
73
+ const existingEntriesMap = await this.loadExistingManifest(owner, schemaId);
74
+ entries = [...Array.from(existingEntriesMap.values()), ...entries];
82
75
  }
83
76
  const manifest = {
84
77
  version: 1,
@@ -100,7 +93,7 @@ var PublisherRole = class {
100
93
  try {
101
94
  const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
102
95
  if (!ds.manifestCid || ds.manifestCid === "") return void 0;
103
- return await this.storage.retrieve(ds.manifestCid);
96
+ return retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
104
97
  } catch {
105
98
  return;
106
99
  }
@@ -118,10 +111,30 @@ var PublisherRole = class {
118
111
  return address;
119
112
  }
120
113
  /**
114
+ * Resolve the schema definition and id by name, with in-memory caching.
115
+ * Schema resolution is concurrent-safe — parallel calls for the same name
116
+ * share a single in-flight promise.
117
+ */
118
+ resolveSchema(name) {
119
+ if (!this.schemaCache.has(name)) {
120
+ const p = Promise.all([this.schemaRegistry.getSchema(name), this.schemaRegistry.schemaId(name)]).then(async ([{ cid }, schemaId]) => {
121
+ return {
122
+ schema: (await retrieveByCid(cid, this.config.ipfsGateway)).definition,
123
+ schemaId
124
+ };
125
+ }).catch((err) => {
126
+ this.schemaCache.delete(name);
127
+ throw err;
128
+ });
129
+ this.schemaCache.set(name, p);
130
+ }
131
+ return this.schemaCache.get(name);
132
+ }
133
+ /**
121
134
  * Resolve a PublishRecord into a ManifestEntry by processing each field
122
135
  * according to the schema definition:
123
136
  * - plain fields are stored as-is
124
- * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced
137
+ * - encrypted fields are encrypted, pinned to IPFS, and replaced
125
138
  * with a handle + gadgetDescriptor
126
139
  */
127
140
  async resolveRecord(record, schema, gadget, gateway) {
@@ -137,14 +150,13 @@ var PublisherRole = class {
137
150
  fileType: input.fileType ?? "application/octet-stream"
138
151
  }, gadget);
139
152
  const cid = await this.storage.store(encrypted, { metadata: { name: `${record.tag}:${fieldName}` } });
140
- const gadgetDescriptor = gadget.toDescriptor();
141
153
  resolvedFields[fieldName] = {
142
154
  "@type": "encrypted",
143
155
  handle: {
144
156
  cid,
145
157
  gateway
146
158
  },
147
- gadgetDescriptor
159
+ gadgetDescriptor: gadget.toDescriptor()
148
160
  };
149
161
  } else resolvedFields[fieldName] = value;
150
162
  }
@@ -155,14 +167,10 @@ var PublisherRole = class {
155
167
  }
156
168
  /**
157
169
  * Validate that a record's fields match the schema before touching IPFS.
158
- * Catches type mismatches and missing required fields early.
159
170
  */
160
171
  validateRecord(record, schema) {
161
172
  const errors = [];
162
- for (const [fieldName, fieldDef] of Object.entries(schema)) {
163
- const value = record.fields[fieldName];
164
- this.validateField(record.tag, fieldName, fieldDef, value, errors);
165
- }
173
+ for (const [fieldName, fieldDef] of Object.entries(schema)) this.validateField(record.tag, fieldName, fieldDef, record.fields[fieldName], errors);
166
174
  for (const fieldName of Object.keys(record.fields)) if (!(fieldName in schema)) console.warn(`Record "${record.tag}": field "${fieldName}" is not in the schema and will be ignored`);
167
175
  if (errors.length > 0) throw new Error(`Validation failed for record "${record.tag}":\n` + errors.map((e) => ` • ${e}`).join("\n"));
168
176
  }
@@ -186,15 +194,14 @@ var PublisherRole = class {
186
194
  }
187
195
  }
188
196
  /**
189
- * Load the existing manifest into pending entries for merge behaviour.
190
- * Unpins the old manifest CID
197
+ * Load the existing manifest for merge behaviour and unpin the old CID.
191
198
  */
192
199
  async loadExistingManifest(owner, schemaId) {
193
200
  const entries = /* @__PURE__ */ new Map();
194
201
  try {
195
202
  const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
196
203
  if (!ds.manifestCid) return entries;
197
- const manifest = await this.storage.retrieve(ds.manifestCid);
204
+ const manifest = await retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
198
205
  for (const entry of manifest.entries) entries.set(entry.tag, entry);
199
206
  try {
200
207
  await this.storage.delete(ds.manifestCid);
@@ -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,18 +56,17 @@ 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 —
69
63
  * and therefore the same resourceId and access condition.
70
64
  */
71
65
  gadgetFactory?: (tag: string) => Gadget | Promise<Gadget>;
66
+ /**
67
+ * Configurable gas for sending the call
68
+ */
69
+ gas?: bigint;
72
70
  /**
73
71
  * IPFS gateway URL written into each encrypted field handle so consumers
74
72
  * can retrieve ciphertexts without knowing the storage provider.
@@ -1,5 +1,5 @@
1
1
  import { SchemaRegistry } from "../../registries/schema-registry/index.js";
2
- import { WritableStorage } from "../../providers/storage/index.js";
2
+ import { PinningService } from "../../providers/storage/index.js";
3
3
  import { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig } from "./types.js";
4
4
  import { WalletClient } from "viem";
5
5
 
@@ -8,7 +8,13 @@ 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 ipfsGateway;
12
+ private readonly agent0;
13
+ constructor(schemaRegistry: SchemaRegistry, storage: PinningService, walletClient: WalletClient, ipfsGateway: string, config?: SchemaRoleConfig);
14
+ /**
15
+ * Register an agent identity via the agent0-sdk / ERC-8004.
16
+ */
17
+ registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
12
18
  /**
13
19
  * Register a schema on-chain, tied to an existing agent identity.
14
20
  *
@@ -33,6 +39,7 @@ declare class SchemaRole {
33
39
  */
34
40
  validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
35
41
  private requireAccount;
42
+ private requireAgent0;
36
43
  }
37
44
  //#endregion
38
45
  export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
@@ -1,9 +1,38 @@
1
+ import { retrieveByCid } from "../../providers/storage/index.js";
2
+ import { SDK } from "agent0-sdk";
3
+
1
4
  //#region src/roles/schema/index.ts
2
5
  var SchemaRole = class {
3
- constructor(schemaRegistry, storage, walletClient) {
6
+ agent0;
7
+ constructor(schemaRegistry, storage, walletClient, ipfsGateway, config) {
4
8
  this.schemaRegistry = schemaRegistry;
5
9
  this.storage = storage;
6
10
  this.walletClient = walletClient;
11
+ this.ipfsGateway = ipfsGateway;
12
+ this.agent0 = config ? new SDK({
13
+ chainId: config.chainId,
14
+ rpcUrl: config.rpcUrl,
15
+ privateKey: config.privateKey,
16
+ ipfs: "pinata",
17
+ pinataJwt: config.pinataJwt,
18
+ ...config.registryOverrides && { registryOverrides: config.registryOverrides },
19
+ ...config.subgraphOverrides && { subgraphOverrides: config.subgraphOverrides }
20
+ }) : null;
21
+ }
22
+ /**
23
+ * Register an agent identity via the agent0-sdk / ERC-8004.
24
+ */
25
+ async registerAgent(params) {
26
+ const agent = this.requireAgent0().createAgent(params.name, params.description);
27
+ if (params.a2aUrl) await agent.setA2A(params.a2aUrl);
28
+ if (params.mcpEndpoint) await agent.setMCP(params.mcpEndpoint);
29
+ if (params.ens) agent.setENS(params.ens);
30
+ agent.setActive(true);
31
+ agent.setX402Support(true);
32
+ const { result: registrationFile } = await (await agent.registerIPFS()).waitConfirmed();
33
+ const agentId = registrationFile.agentId;
34
+ if (!agentId) throw new Error("ERC-8004 registration did not return an agentId");
35
+ return { agentId };
7
36
  }
8
37
  /**
9
38
  * Register a schema on-chain, tied to an existing agent identity.
@@ -41,7 +70,7 @@ var SchemaRole = class {
41
70
  const schemaId = await this.schemaRegistry.schemaId(typeof nameOrId === "string" && !/^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : nameOrId);
42
71
  const record = await this.schemaRegistry.getSchema(nameOrId);
43
72
  if (!record.cid) return void 0;
44
- const blob = await this.storage.retrieve(record.cid);
73
+ const blob = await retrieveByCid(record.cid, this.ipfsGateway);
45
74
  return {
46
75
  schemaId,
47
76
  schemaCid: record.cid,
@@ -100,6 +129,10 @@ var SchemaRole = class {
100
129
  if (!address) throw new Error("No account connected to wallet client");
101
130
  return address;
102
131
  }
132
+ requireAgent0() {
133
+ if (!this.agent0) throw new Error("registerAgent() requires AgentConfig (privateKey + pinataJwt). Pass agentConfig to Fangorn.init() to enable ERC-8004 registration.");
134
+ return this.agent0;
135
+ }
103
136
  };
104
137
 
105
138
  //#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>;
@@ -40,20 +40,22 @@ var TestBed = class TestBed {
40
40
  chainName: chain,
41
41
  chain: chainImpl,
42
42
  rpcUrl,
43
- caip2
43
+ caip2,
44
+ ipfsGateway: "https://gateway.pinata.cloud"
44
45
  };
45
- const agentConfig = void 0;
46
46
  const delegatorFangorn = await Fangorn.create({
47
47
  privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
48
- storage: { storacha: { "email": process.env.TEST_EMAIL_ADDR ?? "" } },
48
+ storage: { pinata: {
49
+ jwt: process.env.PINATA_JWT ?? "",
50
+ gateway: process.env.PINATA_GATEWAY ?? ""
51
+ } },
49
52
  encryption: { lit: true },
50
53
  config,
51
54
  domain: "localhost",
52
- agentConfig
55
+ agentConfig: void 0
53
56
  });
54
57
  const delegateeFangorn = await Fangorn.create({
55
58
  privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
56
- storage: { storacha: { "readOnly": true } },
57
59
  encryption: { lit: true },
58
60
  config,
59
61
  domain: "localhost"
@@ -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,18 +81,22 @@ 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;
87
91
  }
88
92
  async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
93
+ const walletClient = createWalletClient({
94
+ account: privateKeyToAccount(burnerPrivateKey),
95
+ chain: arbitrumSepolia,
96
+ transport: http(process.env.RPC_URL ?? "")
97
+ });
89
98
  return this.delegateeFangorn.consumer.prepareRegister({
90
- burnerPrivateKey,
99
+ walletClient,
91
100
  paymentRecipient,
92
101
  amount,
93
102
  usdcAddress: this.usdcContractAddress,
@@ -1,6 +1,6 @@
1
1
  import { AppConfig } from "../config.js";
2
2
  import { SchemaRegistry } from "../registries/schema-registry/index.js";
3
- import { ReadableStorage, WritableStorage } from "../providers/storage/index.js";
3
+ import { PinningService } from "../providers/storage/index.js";
4
4
  import { SchemaRoleConfig } from "../roles/schema/types.js";
5
5
  import "../roles/schema/index.js";
6
6
  import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
@@ -29,29 +29,22 @@ interface EncryptedData {
29
29
  authTag: Uint8Array<ArrayBuffer>;
30
30
  salt: Uint8Array<ArrayBuffer>;
31
31
  }
32
- /**
33
- * Credentials required to enable ERC-8004 agent registration via agent0-sdk.
34
- * Optional: omit if thewill throw. caller only needs publisher or consumer functionality.
35
- * When omitted, fangorn.schema.register() and fangorn.schema.get() still work;
36
- * only fangorn.schema.registerAgent()
37
- */
38
32
  interface AgentConfig {
39
33
  privateKey: Hex;
40
34
  pinataJwt: string;
41
- /** Override ERC-8004 registry addresses per chainId (e.g. for Arbitrum Sepolia) */
42
35
  registryOverrides?: Record<number, {
43
36
  IDENTITY: string;
44
37
  REPUTATION: string;
45
38
  }>;
46
- /** Override subgraph URLs per chainId */
47
39
  subgraphOverrides?: Record<number, string>;
48
40
  }
49
41
  interface FangornContext {
50
42
  config: AppConfig;
51
43
  walletClient: WalletClient;
52
- storage: ReadableStorage<unknown> | WritableStorage<unknown>;
44
+ storage: PinningService | undefined;
53
45
  encryption: EncryptionService;
54
46
  domain: string;
47
+ ipfsGateway: string;
55
48
  schemaRegistry: SchemaRegistry;
56
49
  dataSourceRegistry: DataSourceRegistry;
57
50
  settlementRegistry: SettlementRegistry;
@@ -62,21 +55,18 @@ type StorageConfig = {
62
55
  jwt: string;
63
56
  gateway: string;
64
57
  };
65
- } | {
66
- storacha: {
67
- email: string;
68
- };
69
- } | {
70
- storacha: {
71
- readOnly: true;
72
- };
73
- } | ReadableStorage<unknown>;
58
+ };
74
59
  type EncryptionConfig = {
75
60
  lit: true;
76
61
  } | EncryptionService;
77
62
  interface FangornCreateOptions {
78
- storage: StorageConfig;
63
+ /**
64
+ * Pinning service config. Required for publisher and schema roles.
65
+ * Omit for consumer-only usage — reads always go through the public IPFS gateway.
66
+ */
67
+ storage?: StorageConfig;
79
68
  encryption: EncryptionConfig;
69
+ ipfsGateway?: string;
80
70
  config?: AppConfig;
81
71
  domain?: string;
82
72
  agentConfig?: AgentConfig;
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.08.dev",
4
4
  "description": "A zero-knowledge conditional access control framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,13 +0,0 @@
1
- import { WritableStorage } from "../index.js";
2
-
3
- //#region src/providers/storage/pinata/index.d.ts
4
- declare class PinataStorage implements WritableStorage<unknown> {
5
- private pinata;
6
- private gateway;
7
- constructor(pinataJwt: string, pinataGateway: string);
8
- store(data: unknown, metadata?: Record<string, string>): Promise<string>;
9
- retrieve(cid: string): Promise<unknown>;
10
- delete(cid: string): Promise<void>;
11
- }
12
- //#endregion
13
- export { PinataStorage };
@@ -1,41 +0,0 @@
1
- import { PinataSDK } from "pinata";
2
-
3
- //#region src/providers/storage/pinata/index.ts
4
- var PinataStorage = class {
5
- pinata;
6
- gateway;
7
- constructor(pinataJwt, pinataGateway) {
8
- this.pinata = new PinataSDK({
9
- pinataJwt,
10
- pinataGateway
11
- });
12
- this.gateway = pinataGateway.replace(/\/$/, "");
13
- }
14
- async store(data, metadata) {
15
- const content = typeof data === "string" ? data : JSON.stringify(data, (_key, value) => {
16
- if (value instanceof Uint8Array) return {
17
- __type: "Uint8Array",
18
- data: Buffer.from(value).toString("base64")
19
- };
20
- return value;
21
- });
22
- const file = new File([content], metadata?.name ?? "file", { type: "text/plain" });
23
- return (await this.pinata.upload.public.file(file, { metadata })).cid;
24
- }
25
- async retrieve(cid) {
26
- const url = `https://${this.gateway}/ipfs/${cid}`;
27
- const response = await fetch(url);
28
- const text = await response.text();
29
- if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
30
- return JSON.parse(text, (_key, value) => {
31
- if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
32
- return value;
33
- });
34
- }
35
- async delete(cid) {
36
- await this.pinata.files.public.delete([cid]);
37
- }
38
- };
39
-
40
- //#endregion
41
- export { PinataStorage };
@@ -1,13 +0,0 @@
1
- import { WritableStorage } from "../index.js";
2
-
3
- //#region src/providers/storage/storacha/index.d.ts
4
- declare class StorachaStorage implements WritableStorage<unknown> {
5
- private client;
6
- private constructor();
7
- static create(email: string): Promise<StorachaStorage>;
8
- store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
9
- retrieve(cid: string): Promise<unknown>;
10
- delete(cid: string): Promise<void>;
11
- }
12
- //#endregion
13
- export { StorachaStorage };
@@ -1,49 +0,0 @@
1
- import { create } from "@storacha/client";
2
-
3
- //#region src/providers/storage/storacha/index.ts
4
- var StorachaStorage = class StorachaStorage {
5
- client;
6
- constructor(client) {
7
- this.client = client;
8
- }
9
- static async create(email) {
10
- const client = await create();
11
- const account = await client.login(email);
12
- if (!(await account.plan.get()).ok) await account.plan.wait();
13
- const spaces = client.spaces();
14
- if (spaces.length > 0) await client.setCurrentSpace(spaces[0].did());
15
- else {
16
- const space = await client.createSpace("fangorn", { account });
17
- await client.setCurrentSpace(space.did());
18
- }
19
- return new StorachaStorage(client);
20
- }
21
- async store(data, metadata) {
22
- const content = typeof data === "string" ? data : JSON.stringify(data, (_key, value) => {
23
- if (value instanceof Uint8Array) return {
24
- __type: "Uint8Array",
25
- data: Buffer.from(value).toString("base64")
26
- };
27
- return value;
28
- });
29
- const name = typeof metadata?.name === "string" ? metadata.name : "file";
30
- const file = new File([content], name, { type: "text/plain" });
31
- return (await this.client.uploadFile(file)).toString();
32
- }
33
- async retrieve(cid) {
34
- const url = `https://${cid}.ipfs.w3s.link`;
35
- const response = await fetch(url);
36
- if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
37
- const text = await response.text();
38
- return JSON.parse(text, (_key, value) => {
39
- if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
40
- return value;
41
- });
42
- }
43
- async delete(cid) {
44
- await this.client.remove(cid);
45
- }
46
- };
47
-
48
- //#endregion
49
- export { StorachaStorage };