@fangorn-network/sdk 2026.4.7 → 2026.4.10

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 (49) hide show
  1. package/README.md +30 -26
  2. package/lib/cli/cli.js +115 -153
  3. package/lib/cli/index.d.ts +170 -170
  4. package/lib/config.d.ts +260 -257
  5. package/lib/config.js +7 -5
  6. package/lib/fangorn.d.ts +0 -3
  7. package/lib/fangorn.js +16 -28
  8. package/lib/index.d.ts +3 -3
  9. package/lib/index.js +4 -5
  10. package/lib/modules/encryption/lit.d.ts +0 -1
  11. package/lib/modules/encryption/lit.js +1 -7
  12. package/lib/modules/gadgets/settledGadget.d.ts +1 -8
  13. package/lib/modules/gadgets/settledGadget.js +1 -13
  14. package/lib/providers/storage/index.d.ts +12 -12
  15. package/lib/providers/storage/index.js +49 -2
  16. package/lib/providers/storage/pinata.d.ts +11 -0
  17. package/lib/providers/storage/pinata.js +24 -0
  18. package/lib/registries/datasource-registry/abi.d.ts +116 -43
  19. package/lib/registries/datasource-registry/abi.js +190 -12
  20. package/lib/registries/datasource-registry/index.d.ts +12 -6
  21. package/lib/registries/datasource-registry/index.js +96 -20
  22. package/lib/registries/index.js +1 -1
  23. package/lib/registries/schema-registry/abi.d.ts +157 -66
  24. package/lib/registries/schema-registry/abi.js +242 -15
  25. package/lib/registries/schema-registry/index.d.ts +8 -3
  26. package/lib/registries/schema-registry/index.js +82 -17
  27. package/lib/registries/settlement-registry/abi.d.ts +199 -145
  28. package/lib/registries/settlement-registry/abi.js +331 -25
  29. package/lib/registries/settlement-registry/index.d.ts +36 -39
  30. package/lib/registries/settlement-registry/index.js +125 -91
  31. package/lib/registries/settlement-registry/types.d.ts +6 -3
  32. package/lib/roles/consumer/index.d.ts +8 -29
  33. package/lib/roles/consumer/index.js +25 -45
  34. package/lib/roles/consumer/types.d.ts +4 -4
  35. package/lib/roles/publisher/index.d.ts +26 -29
  36. package/lib/roles/publisher/index.js +70 -77
  37. package/lib/roles/publisher/types.d.ts +7 -3
  38. package/lib/roles/schema/index.d.ts +3 -8
  39. package/lib/roles/schema/index.js +6 -34
  40. package/lib/test/testbed.d.ts +7 -32
  41. package/lib/test/testbed.js +22 -45
  42. package/lib/types/index.d.ts +10 -20
  43. package/package.json +1 -1
  44. package/lib/providers/storage/pinata/index.d.ts +0 -13
  45. package/lib/providers/storage/pinata/index.js +0 -41
  46. package/lib/providers/storage/storacha/index.d.ts +0 -13
  47. package/lib/providers/storage/storacha/index.js +0 -49
  48. package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
  49. package/lib/providers/storage/storacha/readOnly.js +0 -16
@@ -1,8 +1,7 @@
1
1
  import { AppConfig } from "../../config.js";
2
2
  import { SchemaRegistry } from "../../registries/schema-registry/index.js";
3
- import { WritableStorage } from "../../providers/storage/index.js";
3
+ import { PinningService } from "../../providers/storage/index.js";
4
4
  import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
5
- import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
6
5
  import { EncryptionService } from "../../modules/encryption/index.js";
7
6
  import { CommitResult, EncryptedFieldInput, FieldInput, Manifest, ManifestEntry, PublishRecord, ResolvedEncryptedField, ResolvedField, ResolvedPlainField, UploadParams } from "./types.js";
8
7
  import { Hex, WalletClient } from "viem";
@@ -10,7 +9,6 @@ import { Hex, WalletClient } from "viem";
10
9
  //#region src/roles/publisher/index.d.ts
11
10
  declare class PublisherRole {
12
11
  private readonly dataSourceRegistry;
13
- private readonly settlementRegistry;
14
12
  private readonly schemaRegistry;
15
13
  private readonly storage;
16
14
  private readonly encryptionService;
@@ -18,59 +16,58 @@ declare class PublisherRole {
18
16
  private readonly config;
19
17
  private pendingEntries;
20
18
  private readonly schemaCache;
21
- constructor(dataSourceRegistry: DataSourceRegistry, settlementRegistry: SettlementRegistry, schemaRegistry: SchemaRegistry, storage: WritableStorage<unknown>, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
19
+ constructor(dataSourceRegistry: DataSourceRegistry, schemaRegistry: SchemaRegistry, storage: PinningService, encryptionService: EncryptionService, walletClient: WalletClient, config: AppConfig);
22
20
  /**
23
- * Encrypt and Upload data with Fangorn
24
- * Validate records against the schema, encrypt encrypted
25
- * fields, stage all resolved entries, then commit to IPFS + on-chain.
21
+ * Encrypt and upload schema-conformant data.
26
22
  *
27
- * Each encrypted field within a record is stored as a separate IPFS object
28
- * (the ciphertext). The manifest entry stores the handle (CID + gateway)
29
- * alongside the plain fields. Consumers can read plain fields freely and
30
- * only need to purchase + decrypt for encrypted fields.
23
+ * Validates records against the schema, encrypts fields as required,
24
+ * stages all resolved entries, then commits to IPFS and publishes on-chain.
25
+ *
26
+ * Each encrypted field within a record is stored as a separate IPFS object.
27
+ * The manifest entry stores the handle (CID + gateway) alongside plain fields.
28
+ * Consumers can read plain fields freely and only need to purchase and decrypt
29
+ * for encrypted fields.
31
30
  */
32
31
  upload(params: UploadParams, price: bigint): Promise<CommitResult>;
33
32
  stage(entry: ManifestEntry): void;
34
- remove(tag: string): boolean;
33
+ remove(name: string): boolean;
35
34
  getPending(): ManifestEntry[];
36
35
  clearPending(): void;
37
36
  /**
38
- * Serialize all staged entries into a manifest, create SettlementRegistry
39
- * resources for each entry, pin the manifest to IPFS, and publish on-chain.
40
- *
41
- * @param schemaId: The unique id of the schema
42
- * @param price: The USDC price required to register with the sempaphore group
43
- * @param overwrite: If true, overwrite manifest data, else append (default: false)
44
- *
37
+ * Serialize all staged entries into a manifest, publish each entry
38
+ * on-chain via the DataSourceRegistry (which calls into the
39
+ * SettlementRegistry to create/update the Semaphore group), pin the
40
+ * manifest to IPFS, and record the manifest CID on-chain.
45
41
  */
46
42
  commit(schemaId: Hex, price: bigint, overwrite: boolean): Promise<CommitResult>;
47
- getManifest(schemaId: Hex): Promise<Manifest | undefined>;
48
- getEntry(schemaId: Hex, tag: string): Promise<ManifestEntry>;
43
+ getManifest(schemaId: Hex, name: string): Promise<Manifest | undefined>;
44
+ getEntry(schemaId: Hex, name: string): Promise<ManifestEntry>;
49
45
  private requireAccount;
50
46
  /**
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
47
+ * Resolve the schema definition and id by name, with in-memory caching.
48
+ * Concurrent calls for the same name share a single in-flight promise.
54
49
  */
55
50
  private resolveSchema;
56
51
  /**
57
52
  * Resolve a PublishRecord into a ManifestEntry by processing each field
58
53
  * according to the schema definition:
59
54
  * - plain fields are stored as-is
60
- * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced with a handle + gadgetDescriptor
55
+ * - encrypted fields are encrypted, pinned to IPFS, and replaced
56
+ * with a handle + gadgetDescriptor
61
57
  */
62
58
  private resolveRecord;
63
59
  /**
64
60
  * Validate that a record's fields match the schema before touching IPFS.
65
- * Catches type mismatches and missing required fields early.
66
61
  */
67
62
  private validateRecord;
68
63
  private validateField;
69
64
  /**
70
- * Load the existing manifest into pending entries for merge behaviour.
71
- * Unpins the old manifest CID
65
+ * Load existing entries for merge behaviour, keyed by name.
66
+ * Unpins the old manifest CID after loading.
67
+ * Pending entries take precedence — existing entries with the same name
68
+ * are overwritten.
72
69
  */
73
- private loadExistingManifest;
70
+ private loadExistingEntries;
74
71
  }
75
72
  //#endregion
76
73
  export { CommitResult, EncryptedFieldInput, FieldInput, Manifest, ManifestEntry, PublishRecord, PublisherRole, ResolvedEncryptedField, ResolvedField, ResolvedPlainField, UploadParams };
@@ -1,13 +1,13 @@
1
- import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
2
- import { makeSettledGadgetFactory } from "../../modules/gadgets/settledGadget.js";
1
+ import { retrieveByCid } from "../../providers/storage/index.js";
2
+ import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
3
+ import { SettledGadget } 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
8
  schemaCache = /* @__PURE__ */ new Map();
8
- constructor(dataSourceRegistry, settlementRegistry, schemaRegistry, storage, encryptionService, walletClient, config) {
9
+ constructor(dataSourceRegistry, schemaRegistry, storage, encryptionService, walletClient, config) {
9
10
  this.dataSourceRegistry = dataSourceRegistry;
10
- this.settlementRegistry = settlementRegistry;
11
11
  this.schemaRegistry = schemaRegistry;
12
12
  this.storage = storage;
13
13
  this.encryptionService = encryptionService;
@@ -15,37 +15,40 @@ var PublisherRole = class {
15
15
  this.config = config;
16
16
  }
17
17
  /**
18
- * Encrypt and Upload data with Fangorn
19
- * Validate records against the schema, encrypt encrypted
20
- * fields, stage all resolved entries, then commit to IPFS + on-chain.
18
+ * Encrypt and upload schema-conformant data.
21
19
  *
22
- * Each encrypted field within a record is stored as a separate IPFS object
23
- * (the ciphertext). The manifest entry stores the handle (CID + gateway)
24
- * alongside the plain fields. Consumers can read plain fields freely and
25
- * only need to purchase + decrypt for encrypted fields.
20
+ * Validates records against the schema, encrypts fields as required,
21
+ * stages all resolved entries, then commits to IPFS and publishes on-chain.
22
+ *
23
+ * Each encrypted field within a record is stored as a separate IPFS object.
24
+ * The manifest entry stores the handle (CID + gateway) alongside plain fields.
25
+ * Consumers can read plain fields freely and only need to purchase and decrypt
26
+ * for encrypted fields.
26
27
  */
27
28
  async upload(params, price) {
28
29
  const { records, schemaName, gateway, options } = params;
29
30
  const address = this.requireAccount();
30
31
  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
- });
32
+ const gadgetFactory = (name) => {
33
+ return new SettledGadget({
34
+ resourceId: DataSourceRegistry.resourceIdLocal(address, schemaId, name),
35
+ settlementRegistryAddress: this.config.settlementRegistryContractAddress,
36
+ chainName: this.config.chainName
37
+ });
38
+ };
36
39
  for (const record of records) {
37
40
  this.validateRecord(record, schema);
38
- const gadget = await gadgetFactory(SettlementRegistry.deriveResourceId(address, schemaId, record.tag));
41
+ const gadget = gadgetFactory(record.name);
39
42
  const entry = await this.resolveRecord(record, schema, gadget, gateway);
40
- this.pendingEntries.set(record.tag, entry);
43
+ this.pendingEntries.set(record.name, entry);
41
44
  }
42
45
  return this.commit(schemaId, price, options?.overwrite ?? false);
43
46
  }
44
47
  stage(entry) {
45
- this.pendingEntries.set(entry.tag, entry);
48
+ this.pendingEntries.set(entry.name, entry);
46
49
  }
47
- remove(tag) {
48
- return this.pendingEntries.delete(tag);
50
+ remove(name) {
51
+ return this.pendingEntries.delete(name);
49
52
  }
50
53
  getPending() {
51
54
  return Array.from(this.pendingEntries.values());
@@ -54,30 +57,18 @@ var PublisherRole = class {
54
57
  this.pendingEntries.clear();
55
58
  }
56
59
  /**
57
- * Serialize all staged entries into a manifest, create SettlementRegistry
58
- * resources for each entry, pin the manifest to IPFS, and publish on-chain.
59
- *
60
- * @param schemaId: The unique id of the schema
61
- * @param price: The USDC price required to register with the sempaphore group
62
- * @param overwrite: If true, overwrite manifest data, else append (default: false)
63
- *
60
+ * Serialize all staged entries into a manifest, publish each entry
61
+ * on-chain via the DataSourceRegistry (which calls into the
62
+ * SettlementRegistry to create/update the Semaphore group), pin the
63
+ * manifest to IPFS, and record the manifest CID on-chain.
64
64
  */
65
65
  async commit(schemaId, price, overwrite) {
66
66
  const owner = this.requireAccount();
67
67
  if (this.pendingEntries.size === 0) throw new Error("Nothing to commit. Stage at least one record.");
68
68
  let entries = Array.from(this.pendingEntries.values());
69
- for (const entry of entries) {
70
- const resourceId = SettlementRegistry.deriveResourceId(owner, schemaId, entry.tag);
71
- try {
72
- await this.settlementRegistry.createResource(resourceId, price);
73
- } catch (e) {
74
- const msg = e instanceof Error ? e.message : String(e);
75
- if (!msg.includes("ResourceAlreadyExists") && !msg.includes("AlreadyExists")) console.warn("Failed to create the resource: already exists!");
76
- }
77
- }
78
69
  if (!overwrite) {
79
- const vals = (await this.loadExistingManifest(owner, schemaId)).values();
80
- entries = [...Array.from(vals), ...entries];
70
+ const existingEntriesMap = await this.loadExistingEntries(owner, schemaId, entries);
71
+ entries = [...Array.from(existingEntriesMap.values()), ...entries];
81
72
  }
82
73
  const manifest = {
83
74
  version: 1,
@@ -85,7 +76,7 @@ var PublisherRole = class {
85
76
  entries
86
77
  };
87
78
  const manifestCid = await this.storage.store(manifest, { metadata: { name: `manifest:${schemaId}` } });
88
- await this.dataSourceRegistry.publishManifest(manifestCid, schemaId);
79
+ for (const entry of entries) await this.dataSourceRegistry.publish(manifestCid, schemaId, entry.name, price);
89
80
  this.pendingEntries.clear();
90
81
  return {
91
82
  manifestCid,
@@ -94,21 +85,21 @@ var PublisherRole = class {
94
85
  entryCount: entries.length
95
86
  };
96
87
  }
97
- async getManifest(schemaId) {
88
+ async getManifest(schemaId, name) {
98
89
  const owner = this.requireAccount();
99
90
  try {
100
- const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
91
+ const ds = await this.dataSourceRegistry.get(owner, schemaId, name);
101
92
  if (!ds.manifestCid || ds.manifestCid === "") return void 0;
102
- return await this.storage.retrieve(ds.manifestCid);
93
+ return await retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
103
94
  } catch {
104
95
  return;
105
96
  }
106
97
  }
107
- async getEntry(schemaId, tag) {
108
- const manifest = await this.getManifest(schemaId);
109
- if (!manifest) throw new Error(`No manifest found for schemaId ${schemaId}`);
110
- const entry = manifest.entries.find((e) => e.tag === tag);
111
- if (!entry) throw new Error(`Entry not found: "${tag}"`);
98
+ async getEntry(schemaId, name) {
99
+ const manifest = await this.getManifest(schemaId, name);
100
+ if (!manifest) throw new Error(`No manifest found for schemaId ${schemaId} / name ${name}`);
101
+ const entry = manifest.entries.find((e) => e.name === name);
102
+ if (!entry) throw new Error(`Entry not found: "${name}"`);
112
103
  return entry;
113
104
  }
114
105
  requireAccount() {
@@ -117,15 +108,14 @@ var PublisherRole = class {
117
108
  return address;
118
109
  }
119
110
  /**
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
111
+ * Resolve the schema definition and id by name, with in-memory caching.
112
+ * Concurrent calls for the same name share a single in-flight promise.
123
113
  */
124
114
  resolveSchema(name) {
125
115
  if (!this.schemaCache.has(name)) {
126
- const p = Promise.all([this.schemaRegistry.getSchema(name), this.schemaRegistry.schemaId(name)]).then(async ([{ cid }, schemaId]) => {
116
+ const p = Promise.all([this.schemaRegistry.getSchema(name), this.schemaRegistry.schemaId(name)]).then(async ([{ specCid }, schemaId]) => {
127
117
  return {
128
- schema: (await this.storage.retrieve(cid)).definition,
118
+ schema: (await retrieveByCid(specCid, this.config.ipfsGateway)).definition,
129
119
  schemaId
130
120
  };
131
121
  }).catch((err) => {
@@ -134,13 +124,16 @@ var PublisherRole = class {
134
124
  });
135
125
  this.schemaCache.set(name, p);
136
126
  }
137
- return this.schemaCache.get(name);
127
+ const cached = this.schemaCache.get(name);
128
+ if (!cached) throw new Error(`Schema not found in cache: ${name}`);
129
+ return cached;
138
130
  }
139
131
  /**
140
132
  * Resolve a PublishRecord into a ManifestEntry by processing each field
141
133
  * according to the schema definition:
142
134
  * - plain fields are stored as-is
143
- * - encrypted fields are AES+Lit encrypted, pinned to IPFS, and replaced with a handle + gadgetDescriptor
135
+ * - encrypted fields are encrypted, pinned to IPFS, and replaced
136
+ * with a handle + gadgetDescriptor
144
137
  */
145
138
  async resolveRecord(record, schema, gadget, gateway) {
146
139
  const resolvedFields = {};
@@ -149,42 +142,37 @@ var PublisherRole = class {
149
142
  if (fieldDef["@type"] === "encrypted") {
150
143
  const input = value;
151
144
  const encrypted = await this.encryptionService.encrypt({
152
- tag: `${record.tag}:${fieldName}`,
145
+ tag: `${record.name}:${fieldName}`,
153
146
  data: input.data,
154
147
  extension: input.extension ?? "",
155
148
  fileType: input.fileType ?? "application/octet-stream"
156
149
  }, gadget);
157
- const cid = await this.storage.store(encrypted, { metadata: { name: `${record.tag}:${fieldName}` } });
158
- const gadgetDescriptor = gadget.toDescriptor();
150
+ const cid = await this.storage.store(encrypted, { metadata: { name: `${record.name}:${fieldName}` } });
159
151
  resolvedFields[fieldName] = {
160
152
  "@type": "encrypted",
161
153
  handle: {
162
154
  cid,
163
155
  gateway
164
156
  },
165
- gadgetDescriptor
157
+ gadgetDescriptor: gadget.toDescriptor()
166
158
  };
167
159
  } else resolvedFields[fieldName] = value;
168
160
  }
169
161
  return {
170
- tag: record.tag,
162
+ name: record.name,
171
163
  fields: resolvedFields
172
164
  };
173
165
  }
174
166
  /**
175
167
  * Validate that a record's fields match the schema before touching IPFS.
176
- * Catches type mismatches and missing required fields early.
177
168
  */
178
169
  validateRecord(record, schema) {
179
170
  const errors = [];
180
- for (const [fieldName, fieldDef] of Object.entries(schema)) {
181
- const value = record.fields[fieldName];
182
- this.validateField(record.tag, fieldName, fieldDef, value, errors);
183
- }
184
- 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`);
185
- if (errors.length > 0) throw new Error(`Validation failed for record "${record.tag}":\n` + errors.map((e) => ` • ${e}`).join("\n"));
171
+ for (const [fieldName, fieldDef] of Object.entries(schema)) this.validateField(record.name, fieldName, fieldDef, record.fields[fieldName], errors);
172
+ for (const fieldName of Object.keys(record.fields)) if (!(fieldName in schema)) console.warn(`Record "${record.name}": field "${fieldName}" is not in the schema and will be ignored`);
173
+ if (errors.length > 0) throw new Error(`Validation failed for record "${record.name}":\n` + errors.map((e) => ` • ${e}`).join("\n"));
186
174
  }
187
- validateField(tag, fieldName, fieldDef, value, errors) {
175
+ validateField(name, fieldName, fieldDef, value, errors) {
188
176
  switch (fieldDef["@type"]) {
189
177
  case "string":
190
178
  if (typeof value !== "string") errors.push(`"${fieldName}" must be a string, got ${typeof value}`);
@@ -204,23 +192,28 @@ var PublisherRole = class {
204
192
  }
205
193
  }
206
194
  /**
207
- * Load the existing manifest into pending entries for merge behaviour.
208
- * Unpins the old manifest CID
195
+ * Load existing entries for merge behaviour, keyed by name.
196
+ * Unpins the old manifest CID after loading.
197
+ * Pending entries take precedence — existing entries with the same name
198
+ * are overwritten.
209
199
  */
210
- async loadExistingManifest(owner, schemaId) {
211
- const entries = /* @__PURE__ */ new Map();
200
+ async loadExistingEntries(owner, schemaId, pendingEntries) {
201
+ const existingMap = /* @__PURE__ */ new Map();
202
+ const pendingNames = new Set(pendingEntries.map((e) => e.name));
203
+ const firstName = pendingEntries[0]?.name;
204
+ if (!firstName) return existingMap;
212
205
  try {
213
- const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
214
- if (!ds.manifestCid) return entries;
215
- const manifest = await this.storage.retrieve(ds.manifestCid);
216
- for (const entry of manifest.entries) entries.set(entry.tag, entry);
206
+ const ds = await this.dataSourceRegistry.get(owner, schemaId, firstName);
207
+ if (!ds.manifestCid) return existingMap;
208
+ const manifest = await retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
209
+ for (const entry of manifest.entries) if (!pendingNames.has(entry.name)) existingMap.set(entry.name, entry);
217
210
  try {
218
211
  await this.storage.delete(ds.manifestCid);
219
212
  } catch (e) {
220
213
  console.warn(`Failed to unpin old manifest ${ds.manifestCid}:`, e);
221
214
  }
222
215
  } catch {}
223
- return entries;
216
+ return existingMap;
224
217
  }
225
218
  };
226
219
 
@@ -20,11 +20,11 @@ interface EncryptedFieldInput {
20
20
  type FieldInput = string | number | boolean | Uint8Array | EncryptedFieldInput;
21
21
  /**
22
22
  * One schema-conformant record to publish.
23
- * `tag` uniquely identifies this record within (owner, schemaId) —
23
+ * `name` uniquely identifies this record within (owner, schemaId) —
24
24
  * it maps to the resourceId in the SettlementRegistry.
25
25
  */
26
26
  interface PublishRecord {
27
- tag: string;
27
+ name: string;
28
28
  fields: Record<string, FieldInput>;
29
29
  }
30
30
  /** A resolved encrypted field — what actually gets stored in the manifest entry */
@@ -46,7 +46,7 @@ type ResolvedField = ResolvedPlainField | ResolvedEncryptedField;
46
46
  * the access condition.
47
47
  */
48
48
  interface ManifestEntry {
49
- tag: string;
49
+ name: string;
50
50
  fields: Record<string, ResolvedField>;
51
51
  }
52
52
  interface Manifest {
@@ -63,6 +63,10 @@ interface UploadParams {
63
63
  * and therefore the same resourceId and access condition.
64
64
  */
65
65
  gadgetFactory?: (tag: string) => Gadget | Promise<Gadget>;
66
+ /**
67
+ * Configurable gas for sending the call
68
+ */
69
+ gas?: bigint;
66
70
  /**
67
71
  * IPFS gateway URL written into each encrypted field handle so consumers
68
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,12 +8,8 @@ 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
+ private readonly ipfsGateway;
12
+ constructor(schemaRegistry: SchemaRegistry, storage: PinningService, walletClient: WalletClient, ipfsGateway: string);
17
13
  /**
18
14
  * Register a schema on-chain, tied to an existing agent identity.
19
15
  *
@@ -38,7 +34,6 @@ declare class SchemaRole {
38
34
  */
39
35
  validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
40
36
  private requireAccount;
41
- private requireAgent0;
42
37
  }
43
38
  //#endregion
44
39
  export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
@@ -1,36 +1,12 @@
1
- import { SDK } from "agent0-sdk";
1
+ import { retrieveByCid } from "../../providers/storage/index.js";
2
2
 
3
3
  //#region src/roles/schema/index.ts
4
4
  var SchemaRole = class {
5
- agent0;
6
- constructor(schemaRegistry, storage, walletClient, config) {
5
+ constructor(schemaRegistry, storage, walletClient, ipfsGateway) {
7
6
  this.schemaRegistry = schemaRegistry;
8
7
  this.storage = storage;
9
8
  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 };
9
+ this.ipfsGateway = ipfsGateway;
34
10
  }
35
11
  /**
36
12
  * Register a schema on-chain, tied to an existing agent identity.
@@ -67,11 +43,11 @@ var SchemaRole = class {
67
43
  try {
68
44
  const schemaId = await this.schemaRegistry.schemaId(typeof nameOrId === "string" && !/^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : nameOrId);
69
45
  const record = await this.schemaRegistry.getSchema(nameOrId);
70
- if (!record.cid) return void 0;
71
- const blob = await this.storage.retrieve(record.cid);
46
+ if (!record.specCid) return void 0;
47
+ const blob = await retrieveByCid(record.specCid, this.ipfsGateway);
72
48
  return {
73
49
  schemaId,
74
- schemaCid: record.cid,
50
+ schemaCid: record.specCid,
75
51
  definition: blob.definition,
76
52
  name: blob.name,
77
53
  agentId: blob.agentId,
@@ -127,10 +103,6 @@ var SchemaRole = class {
127
103
  if (!address) throw new Error("No account connected to wallet client");
128
104
  return address;
129
105
  }
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
106
  };
135
107
 
136
108
  //#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";
@@ -16,44 +16,19 @@ declare class TestBed {
16
16
  private readonly usdcContractAddress;
17
17
  private readonly usdcDomainName;
18
18
  private constructor();
19
- /**
20
- * Init the testbed client
21
- * @param delegatorWalletClient
22
- * @param delegateeWalletClient
23
- * @param jwt
24
- * @param gateway
25
- * @param dataSourceRegistryContractAddress
26
- * @param schemaRegistryContractAddress
27
- * @param settlementRegistryContractAddress
28
- * @param usdcContractAddress
29
- * @param usdcDomainName
30
- * @param rpcUrl
31
- * @param chain
32
- * @param caip2
33
- * @param delegatorPrivateKey
34
- * @returns The testbed client
35
- */
36
19
  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>;
38
20
  registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
39
- /**
40
- * Upload files encrypted under SettledGadget.
41
- *
42
- * Each file gets its own resourceId derived from (owner, schemaId, file.tag),
43
- * which is baked into the ACC at encryption time. A buyer must complete the
44
- * full purchase → claim flow for each specific tag before decrypting.
45
- */
46
21
  fileUpload(records: PublishRecord[], schemaName: string, gateway: string, price: bigint): Promise<string>;
47
22
  prepareRegister(burnerPrivateKey: Hex, paymentRecipient: Address, amount: bigint): Promise<TransferWithAuthPayload>;
48
- register(owner: Address, schemaId: Hex, tag: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
49
- prepareSettle(owner: Address, schemaId: Hex, tag: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
50
- settle(owner: Address, schemaId: Hex, tag: string, relayerPrivateKey: Hex, preparedSettle: PrepareSettleResult): Promise<{
23
+ register(owner: Address, schemaId: Hex, name: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
24
+ prepareSettle(owner: Address, schemaId: Hex, name: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
25
+ settle(owner: Address, schemaId: Hex, name: string, relayerPrivateKey: Hex, preparedSettle: PrepareSettleResult): Promise<{
51
26
  txHash: Hex;
52
27
  nullifier: bigint;
53
28
  }>;
54
- tryDecrypt(owner: Address, nullifierHash: bigint, stealthSecretKey: Hex, schemaId: Hex, tag: string, field: string, rpcUrl: string, identity?: Identity, requireSettlement?: boolean): Promise<Uint8Array>;
55
- checkManifestExists(who: Address, schemaId: Hex): Promise<boolean>;
56
- checkEntryExists(who: Address, schemaId: Hex, tag: string): Promise<boolean>;
29
+ tryDecrypt(owner: Address, nullifierHash: bigint, stealthSecretKey: Hex, schemaId: Hex, name: string, field: string, rpcUrl: string, identity?: Identity, requireSettlement?: boolean): Promise<Uint8Array>;
30
+ checkManifestExists(who: Address, schemaId: Hex, name: string): Promise<boolean>;
31
+ checkEntryExists(who: Address, schemaId: Hex, name: string): Promise<boolean>;
57
32
  getDelegatorAddress(): Address;
58
33
  getDelegatorFangorn(): Fangorn;
59
34
  getDelegateeFangorn(): Fangorn;