@fangorn-network/sdk 2026.3.11 → 2026.3.27

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 (87) hide show
  1. package/README.md +311 -198
  2. package/lib/builders/a2aCardBuilder.js +1 -0
  3. package/lib/cli/cli.js +406 -379
  4. package/lib/cli/index.d.ts +170 -170
  5. package/lib/cli/index.js +1 -4
  6. package/lib/config.d.ts +543 -163
  7. package/lib/config.js +11 -8
  8. package/lib/fangorn.d.ts +28 -45
  9. package/lib/fangorn.js +98 -119
  10. package/lib/index.d.ts +8 -5
  11. package/lib/index.js +8 -7
  12. package/lib/modules/encryption/index.d.ts +4 -3
  13. package/lib/modules/encryption/lit.d.ts +3 -18
  14. package/lib/modules/encryption/lit.js +20 -49
  15. package/lib/modules/encryption/rand.js +2 -2
  16. package/lib/modules/encryption/types.d.ts +23 -8
  17. package/lib/modules/gadgets/settledGadget.d.ts +26 -0
  18. package/lib/modules/gadgets/settledGadget.js +63 -0
  19. package/lib/modules/gadgets/types.d.ts +16 -4
  20. package/lib/providers/storage/index.d.ts +15 -4
  21. package/lib/providers/storage/pinata/index.d.ts +5 -4
  22. package/lib/providers/storage/pinata/index.js +17 -2
  23. package/lib/providers/storage/storacha/index.d.ts +13 -0
  24. package/lib/providers/storage/storacha/index.js +49 -0
  25. package/lib/providers/storage/storacha/readOnly.d.ts +8 -0
  26. package/lib/providers/storage/storacha/readOnly.js +16 -0
  27. package/lib/{interface → registries}/datasource-registry/abi.d.ts +29 -43
  28. package/lib/registries/datasource-registry/abi.js +16 -0
  29. package/lib/{interface/datasource-registry/dataSourceRegistry.d.ts → registries/datasource-registry/index.d.ts} +9 -9
  30. package/lib/{interface/datasource-registry/dataSourceRegistry.js → registries/datasource-registry/index.js} +35 -34
  31. package/lib/registries/index.d.ts +3 -0
  32. package/lib/registries/index.js +4 -0
  33. package/lib/registries/schema-registry/abi.d.ts +127 -0
  34. package/lib/registries/schema-registry/abi.js +19 -0
  35. package/lib/registries/schema-registry/index.d.ts +29 -0
  36. package/lib/registries/schema-registry/index.js +114 -0
  37. package/lib/registries/settlement-registry/abi.d.ts +228 -0
  38. package/lib/registries/settlement-registry/abi.js +29 -0
  39. package/lib/registries/settlement-registry/index.d.ts +72 -0
  40. package/lib/registries/settlement-registry/index.js +316 -0
  41. package/lib/registries/settlement-registry/types.d.ts +51 -0
  42. package/lib/roles/consumer/index.d.ts +64 -0
  43. package/lib/roles/consumer/index.js +114 -0
  44. package/lib/roles/consumer/types.d.ts +66 -0
  45. package/lib/roles/index.js +1 -0
  46. package/lib/roles/publisher/index.d.ts +70 -0
  47. package/lib/roles/publisher/index.js +203 -0
  48. package/lib/roles/publisher/types.d.ts +93 -0
  49. package/lib/roles/publisher/types.js +1 -0
  50. package/lib/roles/schema/index.d.ts +44 -0
  51. package/lib/roles/schema/index.js +137 -0
  52. package/lib/roles/schema/types.d.ts +67 -0
  53. package/lib/roles/schema/types.js +1 -0
  54. package/lib/test/index.d.ts +5 -2
  55. package/lib/test/index.js +5 -3
  56. package/lib/test/testbed.d.ts +54 -32
  57. package/lib/test/testbed.js +149 -135
  58. package/lib/types/index.d.ts +65 -21
  59. package/lib/types/index.js +1 -12
  60. package/lib/utils/index.d.ts +2 -3
  61. package/lib/utils/index.js +4 -18
  62. package/package.json +9 -18
  63. package/lib/cli/registry.d.ts +0 -29
  64. package/lib/cli/registry.js +0 -53
  65. package/lib/deployContract.d.ts +0 -23
  66. package/lib/deployContract.js +0 -78
  67. package/lib/interface/datasource-registry/abi.js +0 -110
  68. package/lib/interface/index.d.ts +0 -3
  69. package/lib/interface/index.js +0 -4
  70. package/lib/interface/manifest.d.ts +0 -7
  71. package/lib/interface/manifest.js +0 -10
  72. package/lib/interface/settlement-tracker/abi.d.ts +0 -26
  73. package/lib/interface/settlement-tracker/abi.js +0 -88
  74. package/lib/interface/settlement-tracker/settlementTracker.d.ts +0 -32
  75. package/lib/interface/settlement-tracker/settlementTracker.js +0 -64
  76. package/lib/modules/gadgets/acc/gadgets.d.ts +0 -7
  77. package/lib/modules/gadgets/acc/gadgets.js +0 -10
  78. package/lib/modules/gadgets/acc.d.ts +0 -15
  79. package/lib/modules/gadgets/acc.js +0 -24
  80. package/lib/modules/gadgets/builder.d.ts +0 -1
  81. package/lib/modules/gadgets/payment.d.ts +0 -23
  82. package/lib/modules/gadgets/payment.js +0 -88
  83. package/lib/test/test-gadget.d.ts +0 -7
  84. package/lib/test/test-gadget.js +0 -10
  85. /package/lib/{modules/gadgets/builder.js → registries/settlement-registry/types.js} +0 -0
  86. /package/lib/{providers/storage/s3/index.js → roles/consumer/types.js} +0 -0
  87. /package/lib/{providers/storage/s3 → roles}/index.d.ts +0 -0
@@ -1,43 +1,65 @@
1
- import { AppConfig } from "../config.js";
2
- import { Filedata } from "../types/index.js";
3
- import { PinataStorage } from "../providers/storage/pinata/index.js";
1
+ import { RegisterAgentParams, RegisteredAgent, SchemaDefinition } from "../roles/schema/types.js";
2
+ import "../roles/schema/index.js";
3
+ import { PrepareSettleResult, TransferWithAuthPayload } from "../registries/settlement-registry/types.js";
4
+ import { SettlementRegistry } from "../registries/settlement-registry/index.js";
5
+ import { PublishRecord } from "../roles/publisher/types.js";
6
+ import "../roles/publisher/index.js";
4
7
  import { Fangorn } from "../fangorn.js";
5
8
  import { Address, Hex, WalletClient } from "viem";
6
- import { EvmChain } from "@lit-protocol/access-control-conditions";
9
+ import { Identity } from "@semaphore-protocol/identity";
7
10
 
8
11
  //#region src/test/testbed.d.ts
9
12
  declare class TestBed {
10
- private delegatorFangorn;
11
- private delegateeFangorn;
12
- private delegatorAddress;
13
- private storage;
14
- private usdcContractAddress;
15
- private vaultIds;
16
- private config;
17
- private litChain;
18
- constructor(delegatorAddress: Address, delegatorFangorn: Fangorn, delegateeFangorn: Fangorn, storage: PinataStorage, config: AppConfig, litChain: EvmChain, usdcContractAddress: Address);
19
- static init(delegatorWalletClient: WalletClient, delegateeWalletClient: WalletClient, jwt: string, gateway: string, dataSourceRegistryContractAddress: Hex, usdcContractAddress: Hex, rpcUrl: string, chain: string, litChain: EvmChain, caip2: number): Promise<TestBed>;
20
- registerDatasource(name: string): Promise<Hex>;
13
+ private readonly delegatorAddress;
14
+ private readonly delegatorFangorn;
15
+ private readonly delegateeFangorn;
16
+ private readonly config;
17
+ private readonly usdcContractAddress;
18
+ private readonly usdcDomainName;
19
+ private readonly pinataJwt;
20
+ private constructor();
21
21
  /**
22
- * Upload files with empty wallet gadget
22
+ * Init the testbed client
23
+ * @param delegatorWalletClient
24
+ * @param delegateeWalletClient
25
+ * @param jwt
26
+ * @param gateway
27
+ * @param dataSourceRegistryContractAddress
28
+ * @param schemaRegistryContractAddress
29
+ * @param settlementRegistryContractAddress
30
+ * @param usdcContractAddress
31
+ * @param usdcDomainName
32
+ * @param rpcUrl
33
+ * @param chain
34
+ * @param caip2
35
+ * @param delegatorPrivateKey
36
+ * @returns The testbed client
23
37
  */
24
- fileUploadEmptyWallet(datasourceName: string, filedata: Filedata[]): Promise<string>;
25
- fileUploadPaymentGadget(datasourceName: string, filedata: Filedata, usdcPrice: string, settlementTrackerContractAddress: Address, jwt: string): Promise<string>;
26
- tryDecrypt(owner: Address, name: string, tag: string): Promise<Uint8Array>;
27
- tryDecryptDelegator(owner: Address, name: string, tag: string): Promise<Uint8Array>;
28
- checkDatasourceRegistryExistence(who: Address, name: string): Promise<boolean>;
29
- checkDataExistence(who: Address, name: string, tag: string): Promise<void>;
30
- buildUsdcAuthorization(recipient: Address, amount: string, chainId: number, usdcContractName: string, usdcAddress: Address): Promise<{
31
- from: `0x${string}`;
32
- to: `0x${string}`;
33
- amount: bigint;
34
- validAfter: bigint;
35
- validBefore: bigint;
36
- nonce: `0x${string}`;
37
- signature: `0x${string}`;
38
+ static init(delegatorWalletClient: WalletClient, delegateeWalletClient: WalletClient, jwt: string, gateway: string, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number, delegatorPrivateKey?: Hex): Promise<TestBed>;
39
+ registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
40
+ registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
41
+ /**
42
+ * Upload files encrypted under SettledGadget.
43
+ *
44
+ * Each file gets its own resourceId derived from (owner, schemaId, file.tag),
45
+ * which is baked into the ACC at encryption time. A buyer must complete the
46
+ * full purchase → claim flow for each specific tag before decrypting.
47
+ */
48
+ fileUpload(records: PublishRecord[], schema: SchemaDefinition, schemaId: Hex, gateway: string, price: bigint): Promise<string>;
49
+ prepareRegister(burnerPrivateKey: Hex, paymentRecipient: Address, amount: bigint): Promise<TransferWithAuthPayload>;
50
+ register(owner: Address, schemaId: Hex, tag: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
51
+ prepareSettle(owner: Address, schemaId: Hex, tag: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
52
+ settle(owner: Address, schemaId: Hex, tag: string, relayerPrivateKey: Hex, preparedSettle: PrepareSettleResult): Promise<{
53
+ txHash: Hex;
54
+ nullifier: bigint;
38
55
  }>;
39
- payForFile(owner: Address, name: string, tag: string, amount: string, usdcDomainName: string, settlementTrackerAddress: Address, walletClient: WalletClient, rpcUrl: string): Promise<void>;
40
- private parseSignature;
56
+ tryDecrypt(owner: Address, nullifierHash: bigint, stealthSecretKey: Hex, schemaId: Hex, tag: string, field: string, rpcUrl: string, identity?: Identity, requireSettlement?: boolean): Promise<Uint8Array>;
57
+ checkManifestExists(who: Address, schemaId: Hex): Promise<boolean>;
58
+ checkEntryExists(who: Address, schemaId: Hex, tag: string): Promise<boolean>;
59
+ getDelegatorAddress(): Address;
60
+ getDelegatorFangorn(): Fangorn;
61
+ getDelegateeFangorn(): Fangorn;
62
+ getSettlementRegistry(): SettlementRegistry;
41
63
  }
42
64
  //#endregion
43
65
  export { TestBed };
@@ -1,172 +1,186 @@
1
+ import { SettlementRegistry } from "../registries/settlement-registry/index.js";
1
2
  import { Fangorn } from "../fangorn.js";
2
- import { PinataStorage } from "../providers/storage/pinata/index.js";
3
- import { computeTagCommitment, fieldToHex } from "../utils/index.js";
4
- import { LitEncryptionService } from "../modules/encryption/lit.js";
5
- import { PaymentGadget } from "../modules/gadgets/payment.js";
6
- import { emptyWallet } from "./test-gadget.js";
7
- import { SettlementTracker } from "../interface/settlement-tracker/settlementTracker.js";
3
+ import { SettledGadget } from "../modules/gadgets/settledGadget.js";
8
4
  import { arbitrumSepolia, baseSepolia } from "viem/chains";
9
- import { createPublicClient, http, keccak256, parseUnits, toHex } from "viem";
5
+ import { createWalletClient, http } from "viem";
6
+ import { privateKeyToAccount } from "viem/accounts";
10
7
 
11
8
  //#region src/test/testbed.ts
12
9
  var TestBed = class TestBed {
13
- delegatorFangorn;
14
- delegateeFangorn;
15
- delegatorAddress;
16
- storage;
17
- usdcContractAddress;
18
- vaultIds;
19
- config;
20
- litChain;
21
- constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, storage, config, litChain, usdcContractAddress) {
10
+ constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, config, usdcContractAddress, usdcDomainName, pinataJwt) {
22
11
  this.delegatorAddress = delegatorAddress;
23
12
  this.delegatorFangorn = delegatorFangorn;
24
13
  this.delegateeFangorn = delegateeFangorn;
25
- this.vaultIds = /* @__PURE__ */ new Map();
26
14
  this.config = config;
27
- this.litChain = litChain;
28
- this.storage = storage;
29
15
  this.usdcContractAddress = usdcContractAddress;
16
+ this.usdcDomainName = usdcDomainName;
17
+ this.pinataJwt = pinataJwt;
30
18
  }
31
- static async init(delegatorWalletClient, delegateeWalletClient, jwt, gateway, dataSourceRegistryContractAddress, usdcContractAddress, rpcUrl, chain, litChain, caip2) {
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
+ static async init(delegatorWalletClient, delegateeWalletClient, jwt, gateway, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2, delegatorPrivateKey) {
32
37
  let chainImpl = arbitrumSepolia;
33
38
  if (chain === "baseSepolia") chainImpl = baseSepolia;
34
39
  const config = {
35
40
  dataSourceRegistryContractAddress,
41
+ schemaRegistryContractAddress,
42
+ settlementRegistryContractAddress,
36
43
  chainName: chain,
37
44
  chain: chainImpl,
38
45
  rpcUrl,
39
46
  caip2
40
47
  };
41
- const delegatorEncryption = await LitEncryptionService.init(chain);
42
- const delegateeEncryption = await LitEncryptionService.init(chain);
43
- const delegatorStorage = new PinataStorage(jwt, gateway);
44
- const delegateeStorage = new PinataStorage(jwt, gateway);
45
- const domain = "localhost";
46
- const delegatorFangorn = await Fangorn.init(delegatorWalletClient, delegatorStorage, delegatorEncryption, domain, config);
47
- const delegateeFangorn = await Fangorn.init(delegateeWalletClient, delegateeStorage, delegateeEncryption, domain, config);
48
- return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, delegatorStorage, config, litChain, usdcContractAddress);
49
- }
50
- async registerDatasource(name) {
51
- const existing = this.vaultIds.get(name);
52
- if (existing) return existing;
53
- const id = await this.delegatorFangorn.registerDataSource(name, "");
54
- this.vaultIds.set(name, id);
55
- return id;
48
+ const agentConfig = delegatorPrivateKey ? {
49
+ privateKey: delegatorPrivateKey,
50
+ pinataJwt: jwt
51
+ } : void 0;
52
+ const delegatorFangorn = await Fangorn.create({
53
+ privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
54
+ storage: { storacha: { "email": "driemworks@fangorn.network" } },
55
+ encryption: { lit: true },
56
+ config,
57
+ domain: "localhost",
58
+ agentConfig
59
+ });
60
+ const delegateeFangorn = await Fangorn.create({
61
+ privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
62
+ storage: { storacha: { "readOnly": true } },
63
+ encryption: { lit: true },
64
+ config,
65
+ domain: "localhost"
66
+ });
67
+ if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
68
+ return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, config, usdcContractAddress, usdcDomainName, jwt);
56
69
  }
57
- /**
58
- * Upload files with empty wallet gadget
59
- */
60
- async fileUploadEmptyWallet(datasourceName, filedata) {
61
- return await this.delegatorFangorn.upload(datasourceName, filedata, (_file) => emptyWallet(this.litChain));
70
+ async registerAgent(params) {
71
+ return this.delegatorFangorn.schema.registerAgent(params);
62
72
  }
63
- async fileUploadPaymentGadget(datasourceName, filedata, usdcPrice, settlementTrackerContractAddress, jwt) {
64
- return await this.delegatorFangorn.upload(datasourceName, [filedata], async (file) => {
65
- return new PaymentGadget({
66
- commitment: fieldToHex(await computeTagCommitment(this.delegatorAddress, datasourceName, file.tag, usdcPrice)),
67
- chainName: this.config.chainName,
68
- settlementTrackerContractAddress,
69
- usdcPrice,
70
- pinataJwt: jwt
71
- });
73
+ async registerSchema(name, definition, agentId) {
74
+ const { schemaId } = await this.delegatorFangorn.schema.register({
75
+ name,
76
+ definition,
77
+ agentId
72
78
  });
79
+ return schemaId;
73
80
  }
74
- async tryDecrypt(owner, name, tag) {
75
- return await this.delegateeFangorn.decryptFile(owner, name, tag);
81
+ /**
82
+ * Upload files encrypted under SettledGadget.
83
+ *
84
+ * Each file gets its own resourceId derived from (owner, schemaId, file.tag),
85
+ * which is baked into the ACC at encryption time. A buyer must complete the
86
+ * full purchase → claim flow for each specific tag before decrypting.
87
+ */
88
+ async fileUpload(records, schema, schemaId, gateway, price) {
89
+ const owner = this.delegatorFangorn.getAddress();
90
+ const { manifestCid } = await this.delegatorFangorn.publisher.upload({
91
+ records,
92
+ schema,
93
+ schemaId,
94
+ gateway,
95
+ gadgetFactory: (tag) => new SettledGadget({
96
+ resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
97
+ settlementRegistryAddress: this.config.settlementRegistryContractAddress,
98
+ chainName: this.config.chainName,
99
+ pinataJwt: this.pinataJwt
100
+ })
101
+ }, price);
102
+ return manifestCid;
76
103
  }
77
- async tryDecryptDelegator(owner, name, tag) {
78
- return await this.delegatorFangorn.decryptFile(owner, name, tag);
104
+ async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
105
+ return this.delegateeFangorn.consumer.prepareRegister({
106
+ burnerPrivateKey,
107
+ paymentRecipient,
108
+ amount,
109
+ usdcAddress: this.usdcContractAddress,
110
+ usdcDomainName: this.usdcDomainName,
111
+ usdcDomainVersion: "2"
112
+ });
79
113
  }
80
- async checkDatasourceRegistryExistence(who, name) {
81
- const datasource = await this.delegatorFangorn.getDataSource(who, name);
82
- return datasource.owner == who.toString() && datasource.name == name;
114
+ async register(owner, schemaId, tag, identityCommitment, relayerPrivateKey, preparedRegister) {
115
+ const { txHash } = await this.delegateeFangorn.consumer.register({
116
+ owner,
117
+ schemaId,
118
+ tag,
119
+ identityCommitment,
120
+ relayerPrivateKey,
121
+ preparedRegister
122
+ });
123
+ return txHash;
83
124
  }
84
- async checkDataExistence(who, name, tag) {
85
- await this.delegatorFangorn.getDataSourceData(who, name, tag);
125
+ async prepareSettle(owner, schemaId, tag, identity, stealthAddress) {
126
+ return this.delegateeFangorn.consumer.prepareSettle({
127
+ resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
128
+ identity,
129
+ stealthAddress
130
+ });
86
131
  }
87
- async buildUsdcAuthorization(recipient, amount, chainId, usdcContractName, usdcAddress) {
88
- const walletClient = this.delegateeFangorn["walletClient"];
89
- const account = walletClient.account;
90
- const domain = {
91
- name: usdcContractName,
92
- version: "2",
93
- chainId,
94
- verifyingContract: usdcAddress
95
- };
96
- const types = { TransferWithAuthorization: [
97
- {
98
- name: "from",
99
- type: "address"
100
- },
101
- {
102
- name: "to",
103
- type: "address"
104
- },
105
- {
106
- name: "value",
107
- type: "uint256"
108
- },
109
- {
110
- name: "validAfter",
111
- type: "uint256"
112
- },
113
- {
114
- name: "validBefore",
115
- type: "uint256"
116
- },
117
- {
118
- name: "nonce",
119
- type: "bytes32"
120
- }
121
- ] };
122
- const value = parseUnits(amount, 6);
123
- const nonce = keccak256(toHex(crypto.getRandomValues(new Uint8Array(32))));
124
- const signature = await walletClient.signTypedData({
125
- account,
126
- domain,
127
- types,
128
- primaryType: "TransferWithAuthorization",
129
- message: {
130
- from: account.address,
131
- to: recipient,
132
- value,
133
- validAfter: 0n,
134
- validBefore: 281474976710655n,
135
- nonce
136
- }
132
+ async settle(owner, schemaId, tag, relayerPrivateKey, preparedSettle) {
133
+ const { txHash, nullifier } = await this.delegateeFangorn.consumer.claim({
134
+ owner,
135
+ schemaId,
136
+ tag,
137
+ relayerPrivateKey,
138
+ preparedSettle
137
139
  });
138
140
  return {
139
- from: account.address,
140
- to: recipient,
141
- amount: value,
142
- validAfter: 0n,
143
- validBefore: 281474976710655n,
144
- nonce,
145
- signature
141
+ txHash,
142
+ nullifier
146
143
  };
147
144
  }
148
- async payForFile(owner, name, tag, amount, usdcDomainName, settlementTrackerAddress, walletClient, rpcUrl) {
149
- const auth = await this.buildUsdcAuthorization(this.delegatorAddress, amount, this.config.caip2, usdcDomainName, this.usdcContractAddress);
150
- const commitmentHex = fieldToHex(await computeTagCommitment(owner, name, tag, amount));
151
- await new SettlementTracker(settlementTrackerAddress, createPublicClient({ transport: http(rpcUrl) }), walletClient).pay({
152
- commitment: commitmentHex,
153
- from: auth.from,
154
- to: auth.to,
155
- value: auth.amount,
156
- validAfter: auth.validAfter,
157
- validBefore: auth.validBefore,
158
- nonce: auth.nonce,
159
- ...this.parseSignature(auth.signature)
145
+ async tryDecrypt(owner, nullifierHash, stealthSecretKey, schemaId, tag, field, rpcUrl, identity, requireSettlement = true) {
146
+ const walletClient = createWalletClient({
147
+ account: privateKeyToAccount(stealthSecretKey),
148
+ chain: arbitrumSepolia,
149
+ transport: http(rpcUrl)
150
+ });
151
+ return this.delegateeFangorn.consumer.decrypt({
152
+ owner,
153
+ walletClient,
154
+ schemaId,
155
+ nullifierHash,
156
+ tag,
157
+ field,
158
+ identity,
159
+ skipSettlementCheck: !requireSettlement
160
160
  });
161
161
  }
162
- parseSignature(signature) {
163
- const r = `0x${signature.slice(2, 66)}`;
164
- const s = `0x${signature.slice(66, 130)}`;
165
- return {
166
- v: parseInt(signature.slice(130, 132), 16),
167
- r,
168
- s
169
- };
162
+ async checkManifestExists(who, schemaId) {
163
+ return await this.delegatorFangorn.consumer.getManifest(who, schemaId) !== void 0;
164
+ }
165
+ async checkEntryExists(who, schemaId, tag) {
166
+ try {
167
+ await this.delegatorFangorn.consumer.getEntry(who, schemaId, tag);
168
+ return true;
169
+ } catch {
170
+ return false;
171
+ }
172
+ }
173
+ getDelegatorAddress() {
174
+ return this.delegatorAddress;
175
+ }
176
+ getDelegatorFangorn() {
177
+ return this.delegatorFangorn;
178
+ }
179
+ getDelegateeFangorn() {
180
+ return this.delegateeFangorn;
181
+ }
182
+ getSettlementRegistry() {
183
+ return this.delegatorFangorn.getSettlementRegistry();
170
184
  }
171
185
  };
172
186
 
@@ -1,25 +1,15 @@
1
+ import { AppConfig } from "../config.js";
2
+ import { SchemaRegistry } from "../registries/schema-registry/index.js";
3
+ import { ReadableStorage, WritableStorage } from "../providers/storage/index.js";
4
+ import { SchemaRoleConfig } from "../roles/schema/types.js";
5
+ import "../roles/schema/index.js";
6
+ import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
1
7
  import { GadgetDescriptor } from "../modules/gadgets/types.js";
8
+ import { SettlementRegistry } from "../registries/settlement-registry/index.js";
9
+ import { EncryptionService } from "../modules/encryption/index.js";
10
+ import { Hex, WalletClient } from "viem";
2
11
 
3
12
  //#region src/types/index.d.ts
4
- interface VaultEntry {
5
- tag: string;
6
- cid: string;
7
- index: number;
8
- gadgetDescriptor: GadgetDescriptor;
9
- extension: string;
10
- fileType: string;
11
- }
12
- interface VaultManifest {
13
- version: number;
14
- entries: VaultEntry[];
15
- tree?: string[][];
16
- }
17
- interface BuildManifestOptions {
18
- root: string;
19
- entries: VaultEntry[];
20
- tree?: string[][];
21
- }
22
- declare const buildManifest: (options: BuildManifestOptions) => VaultManifest;
23
13
  interface PendingEntry {
24
14
  tag: string;
25
15
  cid: string;
@@ -29,7 +19,7 @@ interface PendingEntry {
29
19
  }
30
20
  interface Filedata {
31
21
  tag: string;
32
- data: string;
22
+ data: Uint8Array;
33
23
  extension: string;
34
24
  fileType: string;
35
25
  }
@@ -39,5 +29,59 @@ interface EncryptedData {
39
29
  authTag: Uint8Array<ArrayBuffer>;
40
30
  salt: Uint8Array<ArrayBuffer>;
41
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
+ interface AgentConfig {
39
+ privateKey: Hex;
40
+ pinataJwt: string;
41
+ /** Override ERC-8004 registry addresses per chainId (e.g. for Arbitrum Sepolia) */
42
+ registryOverrides?: Record<number, {
43
+ IDENTITY: string;
44
+ REPUTATION: string;
45
+ }>;
46
+ /** Override subgraph URLs per chainId */
47
+ subgraphOverrides?: Record<number, string>;
48
+ }
49
+ interface FangornContext {
50
+ config: AppConfig;
51
+ walletClient: WalletClient;
52
+ storage: ReadableStorage<unknown> | WritableStorage<unknown>;
53
+ encryption: EncryptionService;
54
+ domain: string;
55
+ schemaRegistry: SchemaRegistry;
56
+ dataSourceRegistry: DataSourceRegistry;
57
+ settlementRegistry: SettlementRegistry;
58
+ schemaRoleConfig: SchemaRoleConfig | undefined;
59
+ }
60
+ type StorageConfig = {
61
+ pinata: {
62
+ jwt: string;
63
+ gateway: string;
64
+ };
65
+ } | {
66
+ storacha: {
67
+ email: string;
68
+ };
69
+ } | {
70
+ storacha: {
71
+ readOnly: true;
72
+ };
73
+ } | ReadableStorage<unknown>;
74
+ type EncryptionConfig = {
75
+ lit: true;
76
+ } | EncryptionService;
77
+ interface FangornCreateOptions {
78
+ storage: StorageConfig;
79
+ encryption: EncryptionConfig;
80
+ config?: AppConfig;
81
+ domain?: string;
82
+ agentConfig?: AgentConfig;
83
+ privateKey?: Hex;
84
+ walletClient?: WalletClient;
85
+ }
42
86
  //#endregion
43
- export { EncryptedData, Filedata, PendingEntry, VaultEntry, VaultManifest, buildManifest };
87
+ export { AgentConfig, EncryptedData, EncryptionConfig, FangornContext, FangornCreateOptions, Filedata, PendingEntry, StorageConfig };
@@ -1,12 +1 @@
1
- //#region src/types/index.ts
2
- const buildManifest = (options) => {
3
- const { root, entries, tree } = options;
4
- return {
5
- version: 1,
6
- entries,
7
- ...tree && { tree }
8
- };
9
- };
10
-
11
- //#endregion
12
- export { buildManifest };
1
+ export { };
@@ -6,7 +6,6 @@ declare function hexToBytes32Array(hex: `0x${string}`): number[];
6
6
  declare function addressToBytes32Array(address: Address): number[];
7
7
  declare function fieldToHex(field: bigint): `0x${string}`;
8
8
  declare function hexToField(hex: string): bigint;
9
- declare function deriveDatasourceId(name: string, owner: Address): Hex;
10
- declare function computeTagCommitment(owner: Address, name: string, tag: string, price: string): bigint;
9
+ declare function computeSchemaId(name: string): Hex;
11
10
  //#endregion
12
- export { addressToBytes32Array, computeTagCommitment, deriveDatasourceId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
11
+ export { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
@@ -1,4 +1,4 @@
1
- import { encodeAbiParameters, encodePacked, keccak256, parseAbiParameters } from "viem";
1
+ import { encodeAbiParameters, keccak256, parseAbiParameters } from "viem";
2
2
 
3
3
  //#region src/utils/index.ts
4
4
  function stringToBytes32Array(str) {
@@ -21,23 +21,9 @@ function hexToField(hex) {
21
21
  const cleanHex = hex.startsWith("0x") ? hex : `0x${hex}`;
22
22
  return BigInt(cleanHex);
23
23
  }
24
- function deriveDatasourceId(name, owner) {
25
- return keccak256(encodeAbiParameters(parseAbiParameters("string, address"), [name, owner]));
26
- }
27
- function computeTagCommitment(owner, name, tag, price) {
28
- const hash = keccak256(encodePacked([
29
- "bytes32",
30
- "string",
31
- "string",
32
- "string"
33
- ], [
34
- deriveDatasourceId(name, owner),
35
- name,
36
- tag,
37
- price
38
- ]));
39
- return BigInt(hash);
24
+ function computeSchemaId(name) {
25
+ return keccak256(encodeAbiParameters(parseAbiParameters("string"), [name]));
40
26
  }
41
27
 
42
28
  //#endregion
43
- export { addressToBytes32Array, computeTagCommitment, deriveDatasourceId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
29
+ export { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.03.11",
3
+ "version": "2026.03.27",
4
4
  "description": "A zero-knowledge conditional access control framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,27 +21,18 @@
21
21
  "devDependencies": {
22
22
  "@dotenvx/dotenvx": "^1.51.1",
23
23
  "@eslint/js": "9.39.1",
24
- "@release-it/conventional-changelog": "10.0.2",
25
24
  "@types/node": "24.10.1",
26
25
  "@vitest/coverage-v8": "4.0.15",
27
26
  "@vitest/eslint-plugin": "1.5.1",
28
- "blake3-js": "^0.0.5",
29
- "dotenv-cli": "^11.0.0",
30
27
  "eslint": "9.39.1",
31
28
  "husky": "9.1.7",
32
29
  "lint-staged": "16.2.7",
33
- "patch-package": "^8.0.1",
34
- "postinstall-postinstall": "^2.1.0",
35
30
  "prettier": "3.7.3",
36
- "release-it": "19.0.6",
37
31
  "tsdown": "0.16.8",
38
32
  "tsx": "^4.21.0",
39
33
  "typescript": "5.8.3",
40
34
  "typescript-eslint": "8.48.1",
41
- "vite": "^7.2.7",
42
- "vite-plugin-node-polyfills": "0.25.0",
43
- "vitest": "4.0.15",
44
- "write-file-atomic": "5.0.1"
35
+ "vitest": "^4.0.18"
45
36
  },
46
37
  "engines": {
47
38
  "node": ">=20.19.0"
@@ -54,21 +45,21 @@
54
45
  "@lit-protocol/auth-helpers": "^8.2.1",
55
46
  "@lit-protocol/lit-client": "^8.3.1",
56
47
  "@lit-protocol/networks": "^8.4.1",
57
- "@rolldown/binding-linux-x64-gnu": "1.0.0-beta.59",
58
- "@x402/core": "^2.2.0",
59
- "@x402/evm": "^2.2.0",
48
+ "@semaphore-protocol/group": "^4.14.2",
49
+ "@semaphore-protocol/identity": "^4.14.2",
50
+ "@semaphore-protocol/proof": "^4.14.2",
51
+ "@storacha/client": "^2.1.3",
60
52
  "agent0-sdk": "^1.5.3",
61
- "buffer": "^6.0.3",
62
53
  "commander": "^14.0.3",
63
54
  "dotenv": "^17.2.3",
64
55
  "ethers": "^6.16.0",
65
- "imurmurhash": "^0.1.4",
66
- "multiformats": "^13.4.2",
67
- "node-localstorage": "^3.0.5",
68
56
  "pinata": "^2.5.2",
69
57
  "solc": "^0.8.28",
70
58
  "viem": "^2.47.1"
71
59
  },
60
+ "overrides": {
61
+ "viem": "$viem"
62
+ },
72
63
  "scripts": {
73
64
  "build": "tsdown",
74
65
  "format": "prettier . --write",