@fangorn-network/sdk 2026.4.7-0 → 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 (39) hide show
  1. package/README.md +30 -26
  2. package/lib/cli/cli.js +115 -153
  3. package/lib/config.d.ts +241 -241
  4. package/lib/config.js +3 -3
  5. package/lib/fangorn.d.ts +5 -0
  6. package/lib/fangorn.js +13 -8
  7. package/lib/index.js +1 -2
  8. package/lib/modules/encryption/lit.d.ts +0 -1
  9. package/lib/modules/encryption/lit.js +1 -7
  10. package/lib/modules/gadgets/settledGadget.d.ts +1 -8
  11. package/lib/modules/gadgets/settledGadget.js +1 -13
  12. package/lib/providers/storage/index.d.ts +1 -1
  13. package/lib/providers/storage/index.js +3 -1
  14. package/lib/providers/storage/pinata.js +1 -1
  15. package/lib/registries/datasource-registry/abi.d.ts +116 -43
  16. package/lib/registries/datasource-registry/abi.js +190 -12
  17. package/lib/registries/datasource-registry/index.d.ts +11 -6
  18. package/lib/registries/datasource-registry/index.js +89 -25
  19. package/lib/registries/index.js +1 -1
  20. package/lib/registries/schema-registry/abi.d.ts +157 -66
  21. package/lib/registries/schema-registry/abi.js +242 -15
  22. package/lib/registries/schema-registry/index.d.ts +8 -3
  23. package/lib/registries/schema-registry/index.js +82 -17
  24. package/lib/registries/settlement-registry/abi.d.ts +199 -145
  25. package/lib/registries/settlement-registry/abi.js +331 -25
  26. package/lib/registries/settlement-registry/index.d.ts +35 -38
  27. package/lib/registries/settlement-registry/index.js +125 -91
  28. package/lib/registries/settlement-registry/types.d.ts +6 -3
  29. package/lib/roles/consumer/index.d.ts +6 -5
  30. package/lib/roles/consumer/index.js +21 -20
  31. package/lib/roles/consumer/types.d.ts +4 -4
  32. package/lib/roles/publisher/index.d.ts +22 -19
  33. package/lib/roles/publisher/index.js +63 -59
  34. package/lib/roles/publisher/types.d.ts +3 -3
  35. package/lib/roles/schema/index.d.ts +1 -7
  36. package/lib/roles/schema/index.js +4 -34
  37. package/lib/test/testbed.d.ts +7 -32
  38. package/lib/test/testbed.js +20 -43
  39. package/package.json +1 -1
@@ -1,14 +1,13 @@
1
1
  import { retrieveByCid } from "../../providers/storage/index.js";
2
- import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
3
- import { makeSettledGadgetFactory } from "../../modules/gadgets/settledGadget.js";
2
+ import { DataSourceRegistry } from "../../registries/datasource-registry/index.js";
3
+ import { SettledGadget } from "../../modules/gadgets/settledGadget.js";
4
4
 
5
5
  //#region src/roles/publisher/index.ts
6
6
  var PublisherRole = class {
7
7
  pendingEntries = /* @__PURE__ */ new Map();
8
8
  schemaCache = /* @__PURE__ */ new Map();
9
- constructor(dataSourceRegistry, settlementRegistry, schemaRegistry, storage, encryptionService, walletClient, config) {
9
+ constructor(dataSourceRegistry, schemaRegistry, storage, encryptionService, walletClient, config) {
10
10
  this.dataSourceRegistry = dataSourceRegistry;
11
- this.settlementRegistry = settlementRegistry;
12
11
  this.schemaRegistry = schemaRegistry;
13
12
  this.storage = storage;
14
13
  this.encryptionService = encryptionService;
@@ -16,35 +15,40 @@ var PublisherRole = class {
16
15
  this.config = config;
17
16
  }
18
17
  /**
19
- * Encrypt and upload data with Fangorn.
20
- * Validates records against the schema, encrypts encrypted fields,
21
- * stages all resolved entries, then commits to IPFS + on-chain.
18
+ * Encrypt and upload schema-conformant data.
22
19
  *
23
- * Each encrypted field within a record is stored as a separate IPFS object
24
- * (the ciphertext). The manifest entry stores the handle (CID + gateway)
25
- * alongside plain fields. Consumers can read plain fields freely and
26
- * 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.
27
27
  */
28
28
  async upload(params, price) {
29
29
  const { records, schemaName, gateway, options } = params;
30
30
  const address = this.requireAccount();
31
31
  const { schema, schemaId } = await this.resolveSchema(schemaName);
32
- const gadgetFactory = params.gadgetFactory ?? ((resourceId) => {
33
- return makeSettledGadgetFactory(this.config)(resourceId);
34
- });
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
+ };
35
39
  for (const record of records) {
36
40
  this.validateRecord(record, schema);
37
- const gadget = await gadgetFactory(SettlementRegistry.deriveResourceId(address, schemaId, record.tag));
41
+ const gadget = gadgetFactory(record.name);
38
42
  const entry = await this.resolveRecord(record, schema, gadget, gateway);
39
- this.pendingEntries.set(record.tag, entry);
43
+ this.pendingEntries.set(record.name, entry);
40
44
  }
41
45
  return this.commit(schemaId, price, options?.overwrite ?? false);
42
46
  }
43
47
  stage(entry) {
44
- this.pendingEntries.set(entry.tag, entry);
48
+ this.pendingEntries.set(entry.name, entry);
45
49
  }
46
- remove(tag) {
47
- return this.pendingEntries.delete(tag);
50
+ remove(name) {
51
+ return this.pendingEntries.delete(name);
48
52
  }
49
53
  getPending() {
50
54
  return Array.from(this.pendingEntries.values());
@@ -53,24 +57,17 @@ var PublisherRole = class {
53
57
  this.pendingEntries.clear();
54
58
  }
55
59
  /**
56
- * Serialize all staged entries into a manifest, create SettlementRegistry
57
- * resources for each entry, pin the manifest to IPFS, and publish on-chain.
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.
58
64
  */
59
65
  async commit(schemaId, price, overwrite) {
60
66
  const owner = this.requireAccount();
61
67
  if (this.pendingEntries.size === 0) throw new Error("Nothing to commit. Stage at least one record.");
62
68
  let entries = Array.from(this.pendingEntries.values());
63
- for (const entry of entries) {
64
- const resourceId = SettlementRegistry.deriveResourceId(owner, schemaId, entry.tag);
65
- try {
66
- await this.settlementRegistry.createResource(resourceId, price);
67
- } catch (e) {
68
- const msg = e instanceof Error ? e.message : String(e);
69
- if (!msg.includes("ResourceAlreadyExists") && !msg.includes("AlreadyExists")) console.warn("Failed to create the resource: already exists!");
70
- }
71
- }
72
69
  if (!overwrite) {
73
- const existingEntriesMap = await this.loadExistingManifest(owner, schemaId);
70
+ const existingEntriesMap = await this.loadExistingEntries(owner, schemaId, entries);
74
71
  entries = [...Array.from(existingEntriesMap.values()), ...entries];
75
72
  }
76
73
  const manifest = {
@@ -79,7 +76,7 @@ var PublisherRole = class {
79
76
  entries
80
77
  };
81
78
  const manifestCid = await this.storage.store(manifest, { metadata: { name: `manifest:${schemaId}` } });
82
- await this.dataSourceRegistry.publishManifest(manifestCid, schemaId);
79
+ for (const entry of entries) await this.dataSourceRegistry.publish(manifestCid, schemaId, entry.name, price);
83
80
  this.pendingEntries.clear();
84
81
  return {
85
82
  manifestCid,
@@ -88,21 +85,21 @@ var PublisherRole = class {
88
85
  entryCount: entries.length
89
86
  };
90
87
  }
91
- async getManifest(schemaId) {
88
+ async getManifest(schemaId, name) {
92
89
  const owner = this.requireAccount();
93
90
  try {
94
- const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
91
+ const ds = await this.dataSourceRegistry.get(owner, schemaId, name);
95
92
  if (!ds.manifestCid || ds.manifestCid === "") return void 0;
96
- return retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
93
+ return await retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
97
94
  } catch {
98
95
  return;
99
96
  }
100
97
  }
101
- async getEntry(schemaId, tag) {
102
- const manifest = await this.getManifest(schemaId);
103
- if (!manifest) throw new Error(`No manifest found for schemaId ${schemaId}`);
104
- const entry = manifest.entries.find((e) => e.tag === tag);
105
- 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}"`);
106
103
  return entry;
107
104
  }
108
105
  requireAccount() {
@@ -112,14 +109,13 @@ var PublisherRole = class {
112
109
  }
113
110
  /**
114
111
  * 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.
112
+ * Concurrent calls for the same name share a single in-flight promise.
117
113
  */
118
114
  resolveSchema(name) {
119
115
  if (!this.schemaCache.has(name)) {
120
- 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]) => {
121
117
  return {
122
- schema: (await retrieveByCid(cid, this.config.ipfsGateway)).definition,
118
+ schema: (await retrieveByCid(specCid, this.config.ipfsGateway)).definition,
123
119
  schemaId
124
120
  };
125
121
  }).catch((err) => {
@@ -128,7 +124,9 @@ var PublisherRole = class {
128
124
  });
129
125
  this.schemaCache.set(name, p);
130
126
  }
131
- 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;
132
130
  }
133
131
  /**
134
132
  * Resolve a PublishRecord into a ManifestEntry by processing each field
@@ -144,12 +142,12 @@ var PublisherRole = class {
144
142
  if (fieldDef["@type"] === "encrypted") {
145
143
  const input = value;
146
144
  const encrypted = await this.encryptionService.encrypt({
147
- tag: `${record.tag}:${fieldName}`,
145
+ tag: `${record.name}:${fieldName}`,
148
146
  data: input.data,
149
147
  extension: input.extension ?? "",
150
148
  fileType: input.fileType ?? "application/octet-stream"
151
149
  }, gadget);
152
- const cid = await this.storage.store(encrypted, { metadata: { name: `${record.tag}:${fieldName}` } });
150
+ const cid = await this.storage.store(encrypted, { metadata: { name: `${record.name}:${fieldName}` } });
153
151
  resolvedFields[fieldName] = {
154
152
  "@type": "encrypted",
155
153
  handle: {
@@ -161,7 +159,7 @@ var PublisherRole = class {
161
159
  } else resolvedFields[fieldName] = value;
162
160
  }
163
161
  return {
164
- tag: record.tag,
162
+ name: record.name,
165
163
  fields: resolvedFields
166
164
  };
167
165
  }
@@ -170,11 +168,11 @@ var PublisherRole = class {
170
168
  */
171
169
  validateRecord(record, schema) {
172
170
  const errors = [];
173
- for (const [fieldName, fieldDef] of Object.entries(schema)) this.validateField(record.tag, fieldName, fieldDef, record.fields[fieldName], errors);
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`);
175
- 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"));
176
174
  }
177
- validateField(tag, fieldName, fieldDef, value, errors) {
175
+ validateField(name, fieldName, fieldDef, value, errors) {
178
176
  switch (fieldDef["@type"]) {
179
177
  case "string":
180
178
  if (typeof value !== "string") errors.push(`"${fieldName}" must be a string, got ${typeof value}`);
@@ -194,22 +192,28 @@ var PublisherRole = class {
194
192
  }
195
193
  }
196
194
  /**
197
- * Load the existing manifest for merge behaviour and unpin the old 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.
198
199
  */
199
- async loadExistingManifest(owner, schemaId) {
200
- 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;
201
205
  try {
202
- const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
203
- if (!ds.manifestCid) return entries;
206
+ const ds = await this.dataSourceRegistry.get(owner, schemaId, firstName);
207
+ if (!ds.manifestCid) return existingMap;
204
208
  const manifest = await retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
205
- for (const entry of manifest.entries) entries.set(entry.tag, entry);
209
+ for (const entry of manifest.entries) if (!pendingNames.has(entry.name)) existingMap.set(entry.name, entry);
206
210
  try {
207
211
  await this.storage.delete(ds.manifestCid);
208
212
  } catch (e) {
209
213
  console.warn(`Failed to unpin old manifest ${ds.manifestCid}:`, e);
210
214
  }
211
215
  } catch {}
212
- return entries;
216
+ return existingMap;
213
217
  }
214
218
  };
215
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 {
@@ -9,12 +9,7 @@ declare class SchemaRole {
9
9
  private readonly storage;
10
10
  private readonly walletClient;
11
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
+ constructor(schemaRegistry: SchemaRegistry, storage: PinningService, walletClient: WalletClient, ipfsGateway: string);
18
13
  /**
19
14
  * Register a schema on-chain, tied to an existing agent identity.
20
15
  *
@@ -39,7 +34,6 @@ declare class SchemaRole {
39
34
  */
40
35
  validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
41
36
  private requireAccount;
42
- private requireAgent0;
43
37
  }
44
38
  //#endregion
45
39
  export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
@@ -1,38 +1,12 @@
1
1
  import { retrieveByCid } from "../../providers/storage/index.js";
2
- import { SDK } from "agent0-sdk";
3
2
 
4
3
  //#region src/roles/schema/index.ts
5
4
  var SchemaRole = class {
6
- agent0;
7
- constructor(schemaRegistry, storage, walletClient, ipfsGateway, config) {
5
+ constructor(schemaRegistry, storage, walletClient, ipfsGateway) {
8
6
  this.schemaRegistry = schemaRegistry;
9
7
  this.storage = storage;
10
8
  this.walletClient = walletClient;
11
9
  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 };
36
10
  }
37
11
  /**
38
12
  * Register a schema on-chain, tied to an existing agent identity.
@@ -69,11 +43,11 @@ var SchemaRole = class {
69
43
  try {
70
44
  const schemaId = await this.schemaRegistry.schemaId(typeof nameOrId === "string" && !/^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : nameOrId);
71
45
  const record = await this.schemaRegistry.getSchema(nameOrId);
72
- if (!record.cid) return void 0;
73
- const blob = await retrieveByCid(record.cid, this.ipfsGateway);
46
+ if (!record.specCid) return void 0;
47
+ const blob = await retrieveByCid(record.specCid, this.ipfsGateway);
74
48
  return {
75
49
  schemaId,
76
- schemaCid: record.cid,
50
+ schemaCid: record.specCid,
77
51
  definition: blob.definition,
78
52
  name: blob.name,
79
53
  agentId: blob.agentId,
@@ -129,10 +103,6 @@ var SchemaRole = class {
129
103
  if (!address) throw new Error("No account connected to wallet client");
130
104
  return address;
131
105
  }
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
- }
136
106
  };
137
107
 
138
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;
@@ -1,4 +1,4 @@
1
- import { SettlementRegistry } from "../registries/settlement-registry/index.js";
1
+ import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
2
2
  import { Fangorn } from "../fangorn.js";
3
3
  import { arbitrumSepolia, baseSepolia } from "viem/chains";
4
4
  import { createWalletClient, http } from "viem";
@@ -13,23 +13,6 @@ var TestBed = class TestBed {
13
13
  this.usdcContractAddress = usdcContractAddress;
14
14
  this.usdcDomainName = usdcDomainName;
15
15
  }
16
- /**
17
- * Init the testbed client
18
- * @param delegatorWalletClient
19
- * @param delegateeWalletClient
20
- * @param jwt
21
- * @param gateway
22
- * @param dataSourceRegistryContractAddress
23
- * @param schemaRegistryContractAddress
24
- * @param settlementRegistryContractAddress
25
- * @param usdcContractAddress
26
- * @param usdcDomainName
27
- * @param rpcUrl
28
- * @param chain
29
- * @param caip2
30
- * @param delegatorPrivateKey
31
- * @returns The testbed client
32
- */
33
16
  static async init(delegatorWalletClient, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2) {
34
17
  let chainImpl = arbitrumSepolia;
35
18
  if (chain === "baseSepolia") chainImpl = baseSepolia;
@@ -51,8 +34,7 @@ var TestBed = class TestBed {
51
34
  } },
52
35
  encryption: { lit: true },
53
36
  config,
54
- domain: "localhost",
55
- agentConfig: void 0
37
+ domain: "localhost"
56
38
  });
57
39
  const delegateeFangorn = await Fangorn.create({
58
40
  privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
@@ -63,9 +45,6 @@ var TestBed = class TestBed {
63
45
  if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
64
46
  return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
65
47
  }
66
- async registerAgent(params) {
67
- return this.delegatorFangorn.schema.registerAgent(params);
68
- }
69
48
  async registerSchema(name, definition, agentId) {
70
49
  const { schemaId } = await this.delegatorFangorn.schema.register({
71
50
  name,
@@ -74,13 +53,6 @@ var TestBed = class TestBed {
74
53
  });
75
54
  return schemaId;
76
55
  }
77
- /**
78
- * Upload files encrypted under SettledGadget.
79
- *
80
- * Each file gets its own resourceId derived from (owner, schemaId, file.tag),
81
- * which is baked into the ACC at encryption time. A buyer must complete the
82
- * full purchase → claim flow for each specific tag before decrypting.
83
- */
84
56
  async fileUpload(records, schemaName, gateway, price) {
85
57
  const { manifestCid } = await this.delegatorFangorn.publisher.upload({
86
58
  records,
@@ -90,8 +62,13 @@ var TestBed = class TestBed {
90
62
  return manifestCid;
91
63
  }
92
64
  async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
65
+ const walletClient = createWalletClient({
66
+ account: privateKeyToAccount(burnerPrivateKey),
67
+ chain: arbitrumSepolia,
68
+ transport: http(process.env.RPC_URL ?? "")
69
+ });
93
70
  return this.delegateeFangorn.consumer.prepareRegister({
94
- burnerPrivateKey,
71
+ walletClient,
95
72
  paymentRecipient,
96
73
  amount,
97
74
  usdcAddress: this.usdcContractAddress,
@@ -99,29 +76,29 @@ var TestBed = class TestBed {
99
76
  usdcDomainVersion: "2"
100
77
  });
101
78
  }
102
- async register(owner, schemaId, tag, identityCommitment, relayerPrivateKey, preparedRegister) {
79
+ async register(owner, schemaId, name, identityCommitment, relayerPrivateKey, preparedRegister) {
103
80
  const { txHash } = await this.delegateeFangorn.consumer.register({
104
81
  owner,
105
82
  schemaId,
106
- tag,
83
+ name,
107
84
  identityCommitment,
108
85
  relayerPrivateKey,
109
86
  preparedRegister
110
87
  });
111
88
  return txHash;
112
89
  }
113
- async prepareSettle(owner, schemaId, tag, identity, stealthAddress) {
90
+ async prepareSettle(owner, schemaId, name, identity, stealthAddress) {
114
91
  return this.delegateeFangorn.consumer.prepareSettle({
115
- resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
92
+ resourceId: DataSourceRegistry.resourceIdLocal(owner, schemaId, name),
116
93
  identity,
117
94
  stealthAddress
118
95
  });
119
96
  }
120
- async settle(owner, schemaId, tag, relayerPrivateKey, preparedSettle) {
97
+ async settle(owner, schemaId, name, relayerPrivateKey, preparedSettle) {
121
98
  const { txHash, nullifier } = await this.delegateeFangorn.consumer.claim({
122
99
  owner,
123
100
  schemaId,
124
- tag,
101
+ name,
125
102
  relayerPrivateKey,
126
103
  preparedSettle
127
104
  });
@@ -130,7 +107,7 @@ var TestBed = class TestBed {
130
107
  nullifier
131
108
  };
132
109
  }
133
- async tryDecrypt(owner, nullifierHash, stealthSecretKey, schemaId, tag, field, rpcUrl, identity, requireSettlement = true) {
110
+ async tryDecrypt(owner, nullifierHash, stealthSecretKey, schemaId, name, field, rpcUrl, identity, requireSettlement = true) {
134
111
  const walletClient = createWalletClient({
135
112
  account: privateKeyToAccount(stealthSecretKey),
136
113
  chain: arbitrumSepolia,
@@ -141,18 +118,18 @@ var TestBed = class TestBed {
141
118
  walletClient,
142
119
  schemaId,
143
120
  nullifierHash,
144
- tag,
121
+ name,
145
122
  field,
146
123
  identity,
147
124
  skipSettlementCheck: !requireSettlement
148
125
  });
149
126
  }
150
- async checkManifestExists(who, schemaId) {
151
- return await this.delegatorFangorn.consumer.getManifest(who, schemaId) !== void 0;
127
+ async checkManifestExists(who, schemaId, name) {
128
+ return await this.delegatorFangorn.consumer.getManifest(who, schemaId, name) !== void 0;
152
129
  }
153
- async checkEntryExists(who, schemaId, tag) {
130
+ async checkEntryExists(who, schemaId, name) {
154
131
  try {
155
- await this.delegatorFangorn.consumer.getEntry(who, schemaId, tag);
132
+ await this.delegatorFangorn.consumer.getEntry(who, schemaId, name);
156
133
  return true;
157
134
  } catch {
158
135
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.04.07-0",
3
+ "version": "2026.04.10",
4
4
  "description": "A zero-knowledge conditional access control framework",
5
5
  "repository": {
6
6
  "type": "git",