@fangorn-network/sdk 2026.3.11 → 2026.3.28

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 (89) hide show
  1. package/README.md +311 -198
  2. package/lib/builders/a2aCardBuilder.js +1 -0
  3. package/lib/cli/cli.d.ts +0 -0
  4. package/lib/cli/cli.js +399 -380
  5. package/lib/cli/index.d.ts +170 -170
  6. package/lib/cli/index.js +1 -4
  7. package/lib/config.d.ts +543 -163
  8. package/lib/config.js +11 -8
  9. package/lib/fangorn.d.ts +31 -43
  10. package/lib/fangorn.js +101 -117
  11. package/lib/index.d.ts +8 -5
  12. package/lib/index.js +8 -7
  13. package/lib/modules/encryption/index.d.ts +4 -3
  14. package/lib/modules/encryption/lit.d.ts +3 -18
  15. package/lib/modules/encryption/lit.js +20 -49
  16. package/lib/modules/encryption/rand.js +2 -2
  17. package/lib/modules/encryption/types.d.ts +23 -8
  18. package/lib/modules/gadgets/settledGadget.d.ts +31 -0
  19. package/lib/modules/gadgets/settledGadget.js +75 -0
  20. package/lib/modules/gadgets/types.d.ts +16 -4
  21. package/lib/providers/storage/index.d.ts +15 -4
  22. package/lib/providers/storage/pinata/index.d.ts +5 -4
  23. package/lib/providers/storage/pinata/index.js +17 -2
  24. package/lib/providers/storage/storacha/index.d.ts +13 -0
  25. package/lib/providers/storage/storacha/index.js +49 -0
  26. package/lib/providers/storage/storacha/readOnly.d.ts +8 -0
  27. package/lib/providers/storage/storacha/readOnly.js +16 -0
  28. package/lib/{interface → registries}/datasource-registry/abi.d.ts +29 -43
  29. package/lib/registries/datasource-registry/abi.js +16 -0
  30. package/lib/registries/datasource-registry/index.d.ts +24 -0
  31. package/lib/{interface/datasource-registry/dataSourceRegistry.js → registries/datasource-registry/index.js} +35 -34
  32. package/lib/registries/index.d.ts +3 -0
  33. package/lib/registries/index.js +4 -0
  34. package/lib/registries/schema-registry/abi.d.ts +127 -0
  35. package/lib/registries/schema-registry/abi.js +19 -0
  36. package/lib/registries/schema-registry/index.d.ts +29 -0
  37. package/lib/registries/schema-registry/index.js +114 -0
  38. package/lib/registries/settlement-registry/abi.d.ts +228 -0
  39. package/lib/registries/settlement-registry/abi.js +29 -0
  40. package/lib/registries/settlement-registry/index.d.ts +72 -0
  41. package/lib/registries/settlement-registry/index.js +316 -0
  42. package/lib/registries/settlement-registry/types.d.ts +51 -0
  43. package/lib/roles/consumer/index.d.ts +64 -0
  44. package/lib/roles/consumer/index.js +114 -0
  45. package/lib/roles/consumer/types.d.ts +66 -0
  46. package/lib/roles/index.js +1 -0
  47. package/lib/roles/publisher/index.d.ts +68 -0
  48. package/lib/roles/publisher/index.js +205 -0
  49. package/lib/roles/publisher/types.d.ts +93 -0
  50. package/lib/roles/publisher/types.js +1 -0
  51. package/lib/roles/schema/index.d.ts +44 -0
  52. package/lib/roles/schema/index.js +137 -0
  53. package/lib/roles/schema/types.d.ts +67 -0
  54. package/lib/roles/schema/types.js +1 -0
  55. package/lib/test/index.d.ts +5 -2
  56. package/lib/test/index.js +5 -3
  57. package/lib/test/testbed.d.ts +52 -32
  58. package/lib/test/testbed.js +138 -137
  59. package/lib/types/index.d.ts +65 -21
  60. package/lib/types/index.js +1 -12
  61. package/lib/utils/index.d.ts +2 -3
  62. package/lib/utils/index.js +4 -18
  63. package/package.json +85 -81
  64. package/lib/cli/registry.d.ts +0 -29
  65. package/lib/cli/registry.js +0 -53
  66. package/lib/deployContract.d.ts +0 -23
  67. package/lib/deployContract.js +0 -78
  68. package/lib/interface/datasource-registry/abi.js +0 -110
  69. package/lib/interface/datasource-registry/dataSourceRegistry.d.ts +0 -24
  70. package/lib/interface/index.d.ts +0 -3
  71. package/lib/interface/index.js +0 -4
  72. package/lib/interface/manifest.d.ts +0 -7
  73. package/lib/interface/manifest.js +0 -10
  74. package/lib/interface/settlement-tracker/abi.d.ts +0 -26
  75. package/lib/interface/settlement-tracker/abi.js +0 -88
  76. package/lib/interface/settlement-tracker/settlementTracker.d.ts +0 -32
  77. package/lib/interface/settlement-tracker/settlementTracker.js +0 -64
  78. package/lib/modules/gadgets/acc/gadgets.d.ts +0 -7
  79. package/lib/modules/gadgets/acc/gadgets.js +0 -10
  80. package/lib/modules/gadgets/acc.d.ts +0 -15
  81. package/lib/modules/gadgets/acc.js +0 -24
  82. package/lib/modules/gadgets/builder.d.ts +0 -1
  83. package/lib/modules/gadgets/payment.d.ts +0 -23
  84. package/lib/modules/gadgets/payment.js +0 -88
  85. package/lib/test/test-gadget.d.ts +0 -7
  86. package/lib/test/test-gadget.js +0 -10
  87. /package/lib/{modules/gadgets/builder.js → registries/settlement-registry/types.js} +0 -0
  88. /package/lib/{providers/storage/s3/index.js → roles/consumer/types.js} +0 -0
  89. /package/lib/{providers/storage/s3 → roles}/index.d.ts +0 -0
@@ -1,43 +1,63 @@
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 usdcContractAddress;
17
+ private readonly usdcDomainName;
18
+ private constructor();
21
19
  /**
22
- * Upload files with empty wallet gadget
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
23
35
  */
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}`;
36
+ static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number): Promise<TestBed>;
37
+ registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
38
+ 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
+ fileUpload(records: PublishRecord[], schema: SchemaDefinition, schemaId: Hex, gateway: string, price: bigint): Promise<string>;
47
+ 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<{
51
+ txHash: Hex;
52
+ nullifier: bigint;
38
53
  }>;
39
- payForFile(owner: Address, name: string, tag: string, amount: string, usdcDomainName: string, settlementTrackerAddress: Address, walletClient: WalletClient, rpcUrl: string): Promise<void>;
40
- private parseSignature;
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>;
57
+ getDelegatorAddress(): Address;
58
+ getDelegatorFangorn(): Fangorn;
59
+ getDelegateeFangorn(): Fangorn;
60
+ getSettlementRegistry(): SettlementRegistry;
41
61
  }
42
62
  //#endregion
43
63
  export { TestBed };
@@ -1,172 +1,173 @@
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";
8
3
  import { arbitrumSepolia, baseSepolia } from "viem/chains";
9
- import { createPublicClient, http, keccak256, parseUnits, toHex } from "viem";
4
+ import { createWalletClient, http } from "viem";
5
+ import { privateKeyToAccount } from "viem/accounts";
10
6
 
11
7
  //#region src/test/testbed.ts
12
8
  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) {
9
+ constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName) {
22
10
  this.delegatorAddress = delegatorAddress;
23
11
  this.delegatorFangorn = delegatorFangorn;
24
12
  this.delegateeFangorn = delegateeFangorn;
25
- this.vaultIds = /* @__PURE__ */ new Map();
26
- this.config = config;
27
- this.litChain = litChain;
28
- this.storage = storage;
29
13
  this.usdcContractAddress = usdcContractAddress;
14
+ this.usdcDomainName = usdcDomainName;
30
15
  }
31
- static async init(delegatorWalletClient, delegateeWalletClient, jwt, gateway, dataSourceRegistryContractAddress, usdcContractAddress, rpcUrl, chain, litChain, caip2) {
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
+ static async init(delegatorWalletClient, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2) {
32
34
  let chainImpl = arbitrumSepolia;
33
35
  if (chain === "baseSepolia") chainImpl = baseSepolia;
34
36
  const config = {
35
37
  dataSourceRegistryContractAddress,
38
+ schemaRegistryContractAddress,
39
+ settlementRegistryContractAddress,
36
40
  chainName: chain,
37
41
  chain: chainImpl,
38
42
  rpcUrl,
39
43
  caip2
40
44
  };
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;
45
+ const agentConfig = void 0;
46
+ const delegatorFangorn = await Fangorn.create({
47
+ privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
48
+ storage: { storacha: { "email": process.env.TEST_EMAIL_ADDR ?? "" } },
49
+ encryption: { lit: true },
50
+ config,
51
+ domain: "localhost",
52
+ agentConfig
53
+ });
54
+ const delegateeFangorn = await Fangorn.create({
55
+ privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
56
+ storage: { storacha: { "readOnly": true } },
57
+ encryption: { lit: true },
58
+ config,
59
+ domain: "localhost"
60
+ });
61
+ if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
62
+ return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
56
63
  }
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));
62
- }
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
- });
64
+ async registerAgent(params) {
65
+ return this.delegatorFangorn.schema.registerAgent(params);
66
+ }
67
+ async registerSchema(name, definition, agentId) {
68
+ const { schemaId } = await this.delegatorFangorn.schema.register({
69
+ name,
70
+ definition,
71
+ agentId
72
72
  });
73
+ return schemaId;
73
74
  }
74
- async tryDecrypt(owner, name, tag) {
75
- return await this.delegateeFangorn.decryptFile(owner, name, tag);
75
+ /**
76
+ * Upload files encrypted under SettledGadget.
77
+ *
78
+ * Each file gets its own resourceId derived from (owner, schemaId, file.tag),
79
+ * which is baked into the ACC at encryption time. A buyer must complete the
80
+ * full purchase → claim flow for each specific tag before decrypting.
81
+ */
82
+ async fileUpload(records, schema, schemaId, gateway, price) {
83
+ const { manifestCid } = await this.delegatorFangorn.publisher.upload({
84
+ records,
85
+ schema,
86
+ schemaId,
87
+ gateway
88
+ }, price);
89
+ return manifestCid;
76
90
  }
77
- async tryDecryptDelegator(owner, name, tag) {
78
- return await this.delegatorFangorn.decryptFile(owner, name, tag);
91
+ async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
92
+ return this.delegateeFangorn.consumer.prepareRegister({
93
+ burnerPrivateKey,
94
+ paymentRecipient,
95
+ amount,
96
+ usdcAddress: this.usdcContractAddress,
97
+ usdcDomainName: this.usdcDomainName,
98
+ usdcDomainVersion: "2"
99
+ });
79
100
  }
80
- async checkDatasourceRegistryExistence(who, name) {
81
- const datasource = await this.delegatorFangorn.getDataSource(who, name);
82
- return datasource.owner == who.toString() && datasource.name == name;
101
+ async register(owner, schemaId, tag, identityCommitment, relayerPrivateKey, preparedRegister) {
102
+ const { txHash } = await this.delegateeFangorn.consumer.register({
103
+ owner,
104
+ schemaId,
105
+ tag,
106
+ identityCommitment,
107
+ relayerPrivateKey,
108
+ preparedRegister
109
+ });
110
+ return txHash;
83
111
  }
84
- async checkDataExistence(who, name, tag) {
85
- await this.delegatorFangorn.getDataSourceData(who, name, tag);
112
+ async prepareSettle(owner, schemaId, tag, identity, stealthAddress) {
113
+ return this.delegateeFangorn.consumer.prepareSettle({
114
+ resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
115
+ identity,
116
+ stealthAddress
117
+ });
86
118
  }
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
- }
119
+ async settle(owner, schemaId, tag, relayerPrivateKey, preparedSettle) {
120
+ const { txHash, nullifier } = await this.delegateeFangorn.consumer.claim({
121
+ owner,
122
+ schemaId,
123
+ tag,
124
+ relayerPrivateKey,
125
+ preparedSettle
137
126
  });
138
127
  return {
139
- from: account.address,
140
- to: recipient,
141
- amount: value,
142
- validAfter: 0n,
143
- validBefore: 281474976710655n,
144
- nonce,
145
- signature
128
+ txHash,
129
+ nullifier
146
130
  };
147
131
  }
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)
132
+ async tryDecrypt(owner, nullifierHash, stealthSecretKey, schemaId, tag, field, rpcUrl, identity, requireSettlement = true) {
133
+ const walletClient = createWalletClient({
134
+ account: privateKeyToAccount(stealthSecretKey),
135
+ chain: arbitrumSepolia,
136
+ transport: http(rpcUrl)
137
+ });
138
+ return this.delegateeFangorn.consumer.decrypt({
139
+ owner,
140
+ walletClient,
141
+ schemaId,
142
+ nullifierHash,
143
+ tag,
144
+ field,
145
+ identity,
146
+ skipSettlementCheck: !requireSettlement
160
147
  });
161
148
  }
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
- };
149
+ async checkManifestExists(who, schemaId) {
150
+ return await this.delegatorFangorn.consumer.getManifest(who, schemaId) !== void 0;
151
+ }
152
+ async checkEntryExists(who, schemaId, tag) {
153
+ try {
154
+ await this.delegatorFangorn.consumer.getEntry(who, schemaId, tag);
155
+ return true;
156
+ } catch {
157
+ return false;
158
+ }
159
+ }
160
+ getDelegatorAddress() {
161
+ return this.delegatorAddress;
162
+ }
163
+ getDelegatorFangorn() {
164
+ return this.delegatorFangorn;
165
+ }
166
+ getDelegateeFangorn() {
167
+ return this.delegateeFangorn;
168
+ }
169
+ getSettlementRegistry() {
170
+ return this.delegatorFangorn.getSettlementRegistry();
170
171
  }
171
172
  };
172
173
 
@@ -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 };