@fangorn-network/sdk 2026.3.11

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 (71) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +276 -0
  3. package/lib/builders/a2aCardBuilder.d.ts +28 -0
  4. package/lib/builders/a2aCardBuilder.js +104 -0
  5. package/lib/cli/cli.d.ts +2 -0
  6. package/lib/cli/cli.js +500 -0
  7. package/lib/cli/index.d.ts +738 -0
  8. package/lib/cli/index.js +36 -0
  9. package/lib/cli/registry.d.ts +29 -0
  10. package/lib/cli/registry.js +53 -0
  11. package/lib/config.d.ts +761 -0
  12. package/lib/config.js +46 -0
  13. package/lib/deployContract.d.ts +23 -0
  14. package/lib/deployContract.js +78 -0
  15. package/lib/fangorn.d.ts +59 -0
  16. package/lib/fangorn.js +145 -0
  17. package/lib/index.d.ts +9 -0
  18. package/lib/index.js +11 -0
  19. package/lib/interface/datasource-registry/abi.d.ts +97 -0
  20. package/lib/interface/datasource-registry/abi.js +110 -0
  21. package/lib/interface/datasource-registry/dataSourceRegistry.d.ts +24 -0
  22. package/lib/interface/datasource-registry/dataSourceRegistry.js +81 -0
  23. package/lib/interface/index.d.ts +3 -0
  24. package/lib/interface/index.js +4 -0
  25. package/lib/interface/manifest.d.ts +7 -0
  26. package/lib/interface/manifest.js +10 -0
  27. package/lib/interface/settlement-tracker/abi.d.ts +26 -0
  28. package/lib/interface/settlement-tracker/abi.js +88 -0
  29. package/lib/interface/settlement-tracker/settlementTracker.d.ts +32 -0
  30. package/lib/interface/settlement-tracker/settlementTracker.js +64 -0
  31. package/lib/modules/encryption/actions.d.ts +4 -0
  32. package/lib/modules/encryption/actions.js +18 -0
  33. package/lib/modules/encryption/aes.d.ts +10 -0
  34. package/lib/modules/encryption/aes.js +51 -0
  35. package/lib/modules/encryption/index.d.ts +27 -0
  36. package/lib/modules/encryption/index.js +3 -0
  37. package/lib/modules/encryption/lit.d.ts +36 -0
  38. package/lib/modules/encryption/lit.js +156 -0
  39. package/lib/modules/encryption/rand.d.ts +5 -0
  40. package/lib/modules/encryption/rand.js +16 -0
  41. package/lib/modules/encryption/types.d.ts +55 -0
  42. package/lib/modules/encryption/types.js +1 -0
  43. package/lib/modules/gadgets/acc/gadgets.d.ts +7 -0
  44. package/lib/modules/gadgets/acc/gadgets.js +10 -0
  45. package/lib/modules/gadgets/acc.d.ts +15 -0
  46. package/lib/modules/gadgets/acc.js +24 -0
  47. package/lib/modules/gadgets/builder.d.ts +1 -0
  48. package/lib/modules/gadgets/builder.js +1 -0
  49. package/lib/modules/gadgets/index.d.ts +2 -0
  50. package/lib/modules/gadgets/index.js +1 -0
  51. package/lib/modules/gadgets/payment.d.ts +23 -0
  52. package/lib/modules/gadgets/payment.js +88 -0
  53. package/lib/modules/gadgets/types.d.ts +15 -0
  54. package/lib/modules/gadgets/types.js +1 -0
  55. package/lib/providers/storage/index.d.ts +10 -0
  56. package/lib/providers/storage/index.js +3 -0
  57. package/lib/providers/storage/pinata/index.d.ts +12 -0
  58. package/lib/providers/storage/pinata/index.js +26 -0
  59. package/lib/providers/storage/s3/index.d.ts +1 -0
  60. package/lib/providers/storage/s3/index.js +1 -0
  61. package/lib/test/index.d.ts +7 -0
  62. package/lib/test/index.js +25 -0
  63. package/lib/test/test-gadget.d.ts +7 -0
  64. package/lib/test/test-gadget.js +10 -0
  65. package/lib/test/testbed.d.ts +43 -0
  66. package/lib/test/testbed.js +174 -0
  67. package/lib/types/index.d.ts +43 -0
  68. package/lib/types/index.js +12 -0
  69. package/lib/utils/index.d.ts +12 -0
  70. package/lib/utils/index.js +43 -0
  71. package/package.json +83 -0
package/lib/config.js ADDED
@@ -0,0 +1,46 @@
1
+ import { arbitrumSepolia, baseSepolia } from "viem/chains";
2
+
3
+ //#region src/config.ts
4
+ /**
5
+ * The networks supproted by Fangorn currently
6
+ */
7
+ const SupportedNetworks = {
8
+ ArbitrumSepolia: {
9
+ name: "arbitrumSepolia",
10
+ chain: arbitrumSepolia
11
+ },
12
+ BaseSepolia: {
13
+ name: "baseSepolia",
14
+ chain: baseSepolia
15
+ }
16
+ };
17
+ /**
18
+ * Get the network based on the string name
19
+ * @param name "arbitrumSepolia" or "baseSepolia"
20
+ * @returns The corresponding network if it is supported, otherwise an error
21
+ */
22
+ function getNetwork(name) {
23
+ if (name === SupportedNetworks.ArbitrumSepolia.name) return arbitrumSepolia;
24
+ else if (name === SupportedNetworks.BaseSepolia.name) return baseSepolia;
25
+ throw new Error(`Chain ${name} is not supported`);
26
+ }
27
+ let FangornConfig;
28
+ (function(_FangornConfig) {
29
+ _FangornConfig.ArbitrumSepolia = {
30
+ dataSourceRegistryContractAddress: "0x602aedafe1096004d4db591b6537bc39d7ac71a6",
31
+ chainName: "arbitrumSepolia",
32
+ chain: arbitrumSepolia,
33
+ rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
34
+ caip2: 421614
35
+ };
36
+ _FangornConfig.BaseSepolia = {
37
+ dataSourceRegistryContractAddress: "0x6fd0e50073dbd8169bcaf066bb4a4991bfa48eeb",
38
+ chainName: "baseSepolia",
39
+ chain: baseSepolia,
40
+ rpcUrl: "https://sepolia.base.org",
41
+ caip2: 84532
42
+ };
43
+ })(FangornConfig || (FangornConfig = {}));
44
+
45
+ //#endregion
46
+ export { FangornConfig, SupportedNetworks, getNetwork as default };
@@ -0,0 +1,23 @@
1
+ import { Account, Address } from "viem";
2
+
3
+ //#region src/deployContract.d.ts
4
+
5
+ /**
6
+ * Deploys any contract by name from the local contracts directory.
7
+ */
8
+ declare function deployContract({
9
+ account,
10
+ contractName,
11
+ constructorArgs,
12
+ chain
13
+ }: {
14
+ account: Account;
15
+ contractName: string;
16
+ constructorArgs?: any[];
17
+ chain: any;
18
+ }): Promise<{
19
+ address: Address;
20
+ abi: any;
21
+ }>;
22
+ //#endregion
23
+ export { deployContract };
@@ -0,0 +1,78 @@
1
+ import { readFileSync } from "fs";
2
+ import { fileURLToPath } from "url";
3
+ import { dirname, join } from "path";
4
+ import { createPublicClient, createWalletClient, encodeDeployData, http } from "viem";
5
+ import solc from "solc";
6
+
7
+ //#region src/deployContract.ts
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ function compileContract(contractName) {
10
+ const fileName = `${contractName}.sol`;
11
+ const source = readFileSync(join(__dirname, "..", "contracts", "src", fileName), "utf-8");
12
+ const input = {
13
+ language: "Solidity",
14
+ sources: { [fileName]: { content: source } },
15
+ settings: {
16
+ metadata: {
17
+ appendCBOR: false,
18
+ useLiteralContent: false
19
+ },
20
+ optimizer: {
21
+ enabled: true,
22
+ runs: 200
23
+ },
24
+ outputSelection: { "*": { "*": ["abi", "evm.bytecode"] } }
25
+ }
26
+ };
27
+ const output = JSON.parse(solc.compile(JSON.stringify(input)));
28
+ const errors = output.errors?.filter((e) => e.severity === "error");
29
+ if (errors && errors.length > 0) {
30
+ console.error(`Compilation errors in ${fileName}:`, errors);
31
+ throw new Error(`${contractName} compilation failed`);
32
+ }
33
+ const contractData = output.contracts[fileName][contractName];
34
+ return {
35
+ abi: contractData.abi,
36
+ bytecode: contractData.evm.bytecode.object
37
+ };
38
+ }
39
+ /**
40
+ * Deploys any contract by name from the local contracts directory.
41
+ */
42
+ async function deployContract({ account, contractName, constructorArgs = [], chain }) {
43
+ console.log(`Compiling ${contractName}...`);
44
+ const compiled = compileContract(contractName);
45
+ const rpcUrl = process.env.CHAIN_RPC_URL;
46
+ if (!rpcUrl) throw new Error("CHAIN_RPC_URL environment variable required");
47
+ const publicClient = createPublicClient({ transport: http(rpcUrl) });
48
+ const walletClient = createWalletClient({
49
+ account,
50
+ transport: http(rpcUrl)
51
+ });
52
+ console.log(`Deploying ${contractName}...`);
53
+ const deployData = encodeDeployData({
54
+ abi: compiled.abi,
55
+ bytecode: `0x${compiled.bytecode}`,
56
+ args: constructorArgs
57
+ });
58
+ const gasPrice = await publicClient.getGasPrice();
59
+ console.log("the gas price is " + gasPrice);
60
+ const gasEstimate = await publicClient.estimateGas({
61
+ data: deployData,
62
+ account: walletClient.account.address
63
+ });
64
+ const txHash = await walletClient.sendTransaction({
65
+ data: deployData,
66
+ gas: gasEstimate + gasEstimate / 10n,
67
+ chain
68
+ });
69
+ const address = (await publicClient.waitForTransactionReceipt({ hash: txHash })).contractAddress;
70
+ console.log(`${contractName} deployed at: ${address}`);
71
+ return {
72
+ address,
73
+ abi: compiled.abi
74
+ };
75
+ }
76
+
77
+ //#endregion
78
+ export { deployContract };
@@ -0,0 +1,59 @@
1
+ import { Gadget } from "./modules/gadgets/types.js";
2
+ import { AppConfig } from "./config.js";
3
+ import { Filedata, VaultEntry, VaultManifest } from "./types/index.js";
4
+ import { DataSourceRegistry, Vault } from "./interface/datasource-registry/dataSourceRegistry.js";
5
+ import StorageProvider from "./providers/storage/index.js";
6
+ import { EncryptionService } from "./modules/encryption/index.js";
7
+ import { Address, Hex, WalletClient } from "viem";
8
+
9
+ //#region src/fangorn.d.ts
10
+
11
+ /**
12
+ *
13
+ */
14
+ declare class Fangorn {
15
+ private dataSourceRegistry;
16
+ private walletClient;
17
+ private storage;
18
+ private encryptionService;
19
+ private domain;
20
+ private pendingEntries;
21
+ constructor(dataSourceRegistry: DataSourceRegistry, walletClient: WalletClient, storage: StorageProvider<any>, encryptionService: EncryptionService, domain: string);
22
+ static init(walletClient: WalletClient, storage: StorageProvider<any>, encryptionService: EncryptionService, domain: string, config?: AppConfig): Promise<Fangorn>;
23
+ /**
24
+ * Register a new named data source owned by the current wallet.
25
+ */
26
+ registerDataSource(name: string, agentId?: string): Promise<Hex>;
27
+ /**
28
+ * Upload files to a vault with the given gadget for access control.
29
+ */
30
+ upload(name: string, filedata: Filedata[], gadgetFactory: (file: Filedata) => Gadget | Promise<Gadget>, overwrite?: boolean): Promise<string>;
31
+ /**
32
+ * Encrypt and stage a single file.
33
+ * Call commitVault() after adding all files.
34
+ */
35
+ addFile(file: Filedata, gadget: Gadget): Promise<{
36
+ cid: string;
37
+ }>;
38
+ /**
39
+ * Remove a staged file before committing.
40
+ */
41
+ removeFile(tag: string): boolean;
42
+ /**
43
+ * Commit all staged files to the vault.
44
+ */
45
+ commit(name: string): Promise<string>;
46
+ /**
47
+ * Decrypt a file from a vault.
48
+ */
49
+ decryptFile(owner: Address, name: string, tag: string, authContext?: any): Promise<Uint8Array>;
50
+ getDataSource(owner: Address, name: string): Promise<Vault>;
51
+ registry(): DataSourceRegistry;
52
+ getManifest(owner: Address, name: string): Promise<VaultManifest | undefined>;
53
+ getDataSourceData(owner: Address, name: string, tag: string): Promise<VaultEntry>;
54
+ getAddress(): Hex;
55
+ fetchManifest(cid: string): Promise<VaultManifest>;
56
+ private loadManifest;
57
+ }
58
+ //#endregion
59
+ export { Fangorn };
package/lib/fangorn.js ADDED
@@ -0,0 +1,145 @@
1
+ import { FangornConfig } from "./config.js";
2
+ import { DataSourceRegistry } from "./interface/datasource-registry/dataSourceRegistry.js";
3
+ import { createPublicClient, http } from "viem";
4
+
5
+ //#region src/fangorn.ts
6
+ /**
7
+ *
8
+ */
9
+ var Fangorn = class Fangorn {
10
+ pendingEntries = /* @__PURE__ */ new Map();
11
+ constructor(dataSourceRegistry, walletClient, storage, encryptionService, domain) {
12
+ this.dataSourceRegistry = dataSourceRegistry;
13
+ this.walletClient = walletClient;
14
+ this.storage = storage;
15
+ this.encryptionService = encryptionService;
16
+ this.domain = domain;
17
+ }
18
+ static async init(walletClient, storage, encryptionService, domain, config) {
19
+ const resolvedConfig = config || FangornConfig.ArbitrumSepolia;
20
+ const publicClient = createPublicClient({ transport: http(resolvedConfig.rpcUrl) });
21
+ return new Fangorn(new DataSourceRegistry(resolvedConfig.dataSourceRegistryContractAddress, publicClient, walletClient), walletClient, storage, encryptionService, domain);
22
+ }
23
+ /**
24
+ * Register a new named data source owned by the current wallet.
25
+ */
26
+ async registerDataSource(name, agentId) {
27
+ return await this.dataSourceRegistry.registerDataSource(name, agentId || "");
28
+ }
29
+ /**
30
+ * Upload files to a vault with the given gadget for access control.
31
+ */
32
+ async upload(name, filedata, gadgetFactory, overwrite) {
33
+ const who = this.walletClient.account.address;
34
+ const datasource = await this.dataSourceRegistry.getDataSource(who, name);
35
+ if (datasource.manifestCid && !overwrite) {
36
+ const oldManifest = await this.fetchManifest(datasource.manifestCid);
37
+ this.loadManifest(oldManifest);
38
+ try {
39
+ await this.storage.delete(datasource.manifestCid);
40
+ } catch (e) {
41
+ console.warn("Failed to unpin old manifest:", e);
42
+ }
43
+ }
44
+ for (const file of filedata) {
45
+ const gadget = await gadgetFactory(file);
46
+ await this.addFile(file, gadget);
47
+ }
48
+ return await this.commit(name);
49
+ }
50
+ /**
51
+ * Encrypt and stage a single file.
52
+ * Call commitVault() after adding all files.
53
+ */
54
+ async addFile(file, gadget) {
55
+ if (!this.walletClient.account?.address) throw new Error("Wallet not connected");
56
+ const encrypted = await this.encryptionService.encrypt(file, gadget);
57
+ const cid = await this.storage.store(encrypted, { metadata: { name: file.tag } });
58
+ this.pendingEntries.set(file.tag, {
59
+ tag: file.tag,
60
+ cid,
61
+ extension: file.extension,
62
+ fileType: file.fileType,
63
+ gadgetDescriptor: gadget.toDescriptor()
64
+ });
65
+ return { cid };
66
+ }
67
+ /**
68
+ * Remove a staged file before committing.
69
+ */
70
+ removeFile(tag) {
71
+ return this.pendingEntries.delete(tag);
72
+ }
73
+ /**
74
+ * Commit all staged files to the vault.
75
+ */
76
+ async commit(name) {
77
+ if (this.pendingEntries.size === 0) throw new Error("No files to commit");
78
+ const manifest = {
79
+ version: 1,
80
+ entries: Array.from(this.pendingEntries.values()).map((e, i) => ({
81
+ tag: e.tag,
82
+ cid: e.cid,
83
+ index: i,
84
+ extension: e.extension,
85
+ fileType: e.fileType,
86
+ gadgetDescriptor: e.gadgetDescriptor
87
+ })),
88
+ tree: []
89
+ };
90
+ const manifestCid = await this.storage.store(manifest, { metadata: { name: `manifest-${name}` } });
91
+ const hash = await this.dataSourceRegistry.updateDataSource(name, manifestCid);
92
+ await this.dataSourceRegistry.waitForTransaction(hash);
93
+ this.pendingEntries.clear();
94
+ return manifestCid;
95
+ }
96
+ /**
97
+ * Decrypt a file from a vault.
98
+ */
99
+ async decryptFile(owner, name, tag, authContext) {
100
+ const vault = await this.dataSourceRegistry.getDataSource(owner, name);
101
+ const entry = (await this.storage.retrieve(vault.manifestCid)).entries.find((e) => e.tag === tag);
102
+ if (!entry) throw new Error(`Entry not found: ${tag}`);
103
+ const encrypted = await this.storage.retrieve(entry.cid);
104
+ const resolvedAuthContext = authContext ?? await this.encryptionService.createAuthContext(this.walletClient, this.domain);
105
+ return (await this.encryptionService.decrypt(encrypted, resolvedAuthContext)).data;
106
+ }
107
+ async getDataSource(owner, name) {
108
+ return await this.dataSourceRegistry.getDataSource(owner, name);
109
+ }
110
+ registry() {
111
+ return this.dataSourceRegistry;
112
+ }
113
+ async getManifest(owner, name) {
114
+ const vault = await this.getDataSource(owner, name);
115
+ if (!vault.manifestCid || vault.manifestCid === "") return;
116
+ return await this.fetchManifest(vault.manifestCid);
117
+ }
118
+ async getDataSourceData(owner, name, tag) {
119
+ const manifest = await this.getManifest(owner, name);
120
+ if (!manifest) throw new Error("Vault has no manifest");
121
+ const entry = manifest.entries.find((e) => e.tag === tag);
122
+ if (!entry) throw new Error(`Entry not found: ${tag}`);
123
+ return entry;
124
+ }
125
+ getAddress() {
126
+ const account = this.walletClient.account;
127
+ if (!account?.address) throw new Error("Wallet not connected");
128
+ return account.address;
129
+ }
130
+ async fetchManifest(cid) {
131
+ return await this.storage.retrieve(cid);
132
+ }
133
+ loadManifest(oldManifest) {
134
+ for (const entry of oldManifest.entries) this.pendingEntries.set(entry.tag, {
135
+ tag: entry.tag,
136
+ cid: entry.cid,
137
+ extension: entry.extension,
138
+ fileType: entry.fileType,
139
+ gadgetDescriptor: entry.gadgetDescriptor
140
+ });
141
+ }
142
+ };
143
+
144
+ //#endregion
145
+ export { Fangorn };
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { AppConfig, FangornConfig, SupportedNetworks } from "./config.js";
2
+ import { PinataStorage } from "./providers/storage/pinata/index.js";
3
+ import { LitEncryptionService, LitEncryptionServiceConfig } from "./modules/encryption/lit.js";
4
+ import { AuthContext, AuthSig, EncryptionService } from "./modules/encryption/index.js";
5
+ import { Fangorn } from "./fangorn.js";
6
+ import { SETTLEMENT_TRACKER_ABI } from "./interface/settlement-tracker/abi.js";
7
+ import { DS_REGISTRY_ABI } from "./interface/datasource-registry/abi.js";
8
+ import { addressToBytes32Array, computeTagCommitment, deriveDatasourceId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
9
+ export { AppConfig, AuthContext, AuthSig, DS_REGISTRY_ABI, EncryptionService, Fangorn, FangornConfig, LitEncryptionService, LitEncryptionServiceConfig, PinataStorage, SETTLEMENT_TRACKER_ABI, SupportedNetworks, addressToBytes32Array, computeTagCommitment, deriveDatasourceId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
package/lib/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { FangornConfig, SupportedNetworks } from "./config.js";
2
+ import { DS_REGISTRY_ABI } from "./interface/datasource-registry/abi.js";
3
+ import { Fangorn } from "./fangorn.js";
4
+ import { PinataStorage } from "./providers/storage/pinata/index.js";
5
+ import "./providers/storage/index.js";
6
+ import { SETTLEMENT_TRACKER_ABI } from "./interface/settlement-tracker/abi.js";
7
+ import { addressToBytes32Array, computeTagCommitment, deriveDatasourceId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
8
+ import { LitEncryptionService } from "./modules/encryption/lit.js";
9
+ import "./modules/encryption/index.js";
10
+
11
+ export { DS_REGISTRY_ABI, Fangorn, FangornConfig, LitEncryptionService, PinataStorage, SETTLEMENT_TRACKER_ABI, SupportedNetworks, addressToBytes32Array, computeTagCommitment, deriveDatasourceId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
@@ -0,0 +1,97 @@
1
+ //#region src/interface/datasource-registry/abi.d.ts
2
+ declare const DS_REGISTRY_ABI: readonly [{
3
+ readonly name: "registerDataSource";
4
+ readonly type: "function";
5
+ readonly stateMutability: "nonpayable";
6
+ readonly inputs: readonly [{
7
+ readonly name: "name";
8
+ readonly type: "string";
9
+ }, {
10
+ readonly name: "agentId";
11
+ readonly type: "string";
12
+ }];
13
+ readonly outputs: readonly [{
14
+ readonly name: "id";
15
+ readonly type: "bytes32";
16
+ }];
17
+ }, {
18
+ readonly name: "updateDataSource";
19
+ readonly type: "function";
20
+ readonly stateMutability: "nonpayable";
21
+ readonly inputs: readonly [{
22
+ readonly name: "name";
23
+ readonly type: "string";
24
+ }, {
25
+ readonly name: "newManifestCid";
26
+ readonly type: "string";
27
+ }];
28
+ readonly outputs: readonly [];
29
+ }, {
30
+ readonly name: "getDataSource";
31
+ readonly type: "function";
32
+ readonly stateMutability: "view";
33
+ readonly inputs: readonly [{
34
+ readonly name: "owner";
35
+ readonly type: "address";
36
+ }, {
37
+ readonly name: "name";
38
+ readonly type: "string";
39
+ }];
40
+ readonly outputs: readonly [{
41
+ readonly name: "manifestCid";
42
+ readonly type: "string";
43
+ }];
44
+ }, {
45
+ readonly name: "getOwnedDataSources";
46
+ readonly type: "function";
47
+ readonly stateMutability: "view";
48
+ readonly inputs: readonly [{
49
+ readonly name: "owner";
50
+ readonly type: "address";
51
+ }];
52
+ readonly outputs: readonly [{
53
+ readonly type: "bytes32[]";
54
+ }];
55
+ }, {
56
+ readonly name: "DataSourceCreated";
57
+ readonly type: "event";
58
+ readonly inputs: readonly [{
59
+ readonly name: "id";
60
+ readonly type: "bytes32";
61
+ readonly indexed: true;
62
+ }, {
63
+ readonly name: "owner";
64
+ readonly type: "address";
65
+ readonly indexed: true;
66
+ }, {
67
+ readonly name: "name";
68
+ readonly type: "string";
69
+ readonly indexed: false;
70
+ }];
71
+ }, {
72
+ readonly name: "DataSourceUpdated";
73
+ readonly type: "event";
74
+ readonly inputs: readonly [{
75
+ readonly name: "id";
76
+ readonly type: "bytes32";
77
+ readonly indexed: true;
78
+ }, {
79
+ readonly name: "newManifestCid";
80
+ readonly type: "string";
81
+ readonly indexed: false;
82
+ }];
83
+ }, {
84
+ readonly name: "NotOwner";
85
+ readonly type: "error";
86
+ readonly inputs: readonly [];
87
+ }, {
88
+ readonly name: "DataSourceNotFound";
89
+ readonly type: "error";
90
+ readonly inputs: readonly [];
91
+ }, {
92
+ readonly name: "DataSourceAlreadyExists";
93
+ readonly type: "error";
94
+ readonly inputs: readonly [];
95
+ }];
96
+ //#endregion
97
+ export { DS_REGISTRY_ABI };
@@ -0,0 +1,110 @@
1
+ //#region src/interface/datasource-registry/abi.ts
2
+ const DS_REGISTRY_ABI = [
3
+ {
4
+ name: "registerDataSource",
5
+ type: "function",
6
+ stateMutability: "nonpayable",
7
+ inputs: [{
8
+ name: "name",
9
+ type: "string"
10
+ }, {
11
+ name: "agentId",
12
+ type: "string"
13
+ }],
14
+ outputs: [{
15
+ name: "id",
16
+ type: "bytes32"
17
+ }]
18
+ },
19
+ {
20
+ name: "updateDataSource",
21
+ type: "function",
22
+ stateMutability: "nonpayable",
23
+ inputs: [{
24
+ name: "name",
25
+ type: "string"
26
+ }, {
27
+ name: "newManifestCid",
28
+ type: "string"
29
+ }],
30
+ outputs: []
31
+ },
32
+ {
33
+ name: "getDataSource",
34
+ type: "function",
35
+ stateMutability: "view",
36
+ inputs: [{
37
+ name: "owner",
38
+ type: "address"
39
+ }, {
40
+ name: "name",
41
+ type: "string"
42
+ }],
43
+ outputs: [{
44
+ name: "manifestCid",
45
+ type: "string"
46
+ }]
47
+ },
48
+ {
49
+ name: "getOwnedDataSources",
50
+ type: "function",
51
+ stateMutability: "view",
52
+ inputs: [{
53
+ name: "owner",
54
+ type: "address"
55
+ }],
56
+ outputs: [{ type: "bytes32[]" }]
57
+ },
58
+ {
59
+ name: "DataSourceCreated",
60
+ type: "event",
61
+ inputs: [
62
+ {
63
+ name: "id",
64
+ type: "bytes32",
65
+ indexed: true
66
+ },
67
+ {
68
+ name: "owner",
69
+ type: "address",
70
+ indexed: true
71
+ },
72
+ {
73
+ name: "name",
74
+ type: "string",
75
+ indexed: false
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ name: "DataSourceUpdated",
81
+ type: "event",
82
+ inputs: [{
83
+ name: "id",
84
+ type: "bytes32",
85
+ indexed: true
86
+ }, {
87
+ name: "newManifestCid",
88
+ type: "string",
89
+ indexed: false
90
+ }]
91
+ },
92
+ {
93
+ name: "NotOwner",
94
+ type: "error",
95
+ inputs: []
96
+ },
97
+ {
98
+ name: "DataSourceNotFound",
99
+ type: "error",
100
+ inputs: []
101
+ },
102
+ {
103
+ name: "DataSourceAlreadyExists",
104
+ type: "error",
105
+ inputs: []
106
+ }
107
+ ];
108
+
109
+ //#endregion
110
+ export { DS_REGISTRY_ABI };
@@ -0,0 +1,24 @@
1
+ import * as viem0 from "viem";
2
+ import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
+
4
+ //#region src/interface/datasource-registry/dataSourceRegistry.d.ts
5
+ interface Vault {
6
+ manifestCid: string;
7
+ owner: Address;
8
+ name: string;
9
+ }
10
+ declare class DataSourceRegistry {
11
+ private publicClient;
12
+ private walletClient;
13
+ private contractAddress;
14
+ constructor(contractAddress: Address, publicClient: PublicClient, walletClient: WalletClient);
15
+ private getWriteConfig;
16
+ getContractAddress(): `0x${string}`;
17
+ getDataSource(owner: Address, name: string): Promise<Vault>;
18
+ getOwnedDataSources(address: Address): Promise<Hex[]>;
19
+ registerDataSource(name: string, agentId: string): Promise<Hex>;
20
+ updateDataSource(name: string, newManifestCid: string): Promise<Hash>;
21
+ waitForTransaction(hash: Hash): Promise<viem0.TransactionReceipt>;
22
+ }
23
+ //#endregion
24
+ export { DataSourceRegistry, Vault };
@@ -0,0 +1,81 @@
1
+ import { DS_REGISTRY_ABI } from "./abi.js";
2
+ import { parseEventLogs } from "viem";
3
+
4
+ //#region src/interface/datasource-registry/dataSourceRegistry.ts
5
+ var DataSourceRegistry = class {
6
+ publicClient;
7
+ walletClient;
8
+ contractAddress;
9
+ constructor(contractAddress, publicClient, walletClient) {
10
+ this.publicClient = publicClient;
11
+ this.contractAddress = contractAddress;
12
+ this.walletClient = walletClient;
13
+ }
14
+ getWriteConfig() {
15
+ if (!this.walletClient.chain) throw new Error("Chain required");
16
+ if (!this.walletClient.account) throw new Error("Account required");
17
+ return {
18
+ chain: this.walletClient.chain,
19
+ account: this.walletClient.account
20
+ };
21
+ }
22
+ getContractAddress() {
23
+ return this.contractAddress;
24
+ }
25
+ async getDataSource(owner, name) {
26
+ return {
27
+ manifestCid: await this.publicClient.readContract({
28
+ address: this.contractAddress,
29
+ abi: DS_REGISTRY_ABI,
30
+ functionName: "getDataSource",
31
+ args: [owner, name]
32
+ }),
33
+ owner,
34
+ name
35
+ };
36
+ }
37
+ async getOwnedDataSources(address) {
38
+ return await this.publicClient.readContract({
39
+ address: this.contractAddress,
40
+ abi: DS_REGISTRY_ABI,
41
+ functionName: "getOwnedDataSources",
42
+ args: [address]
43
+ });
44
+ }
45
+ async registerDataSource(name, agentId) {
46
+ const { chain, account } = this.getWriteConfig();
47
+ const hash = await this.walletClient.writeContract({
48
+ address: this.contractAddress,
49
+ abi: DS_REGISTRY_ABI,
50
+ functionName: "registerDataSource",
51
+ args: [name, agentId],
52
+ chain,
53
+ account
54
+ });
55
+ const logs = parseEventLogs({
56
+ abi: DS_REGISTRY_ABI,
57
+ logs: (await this.waitForTransaction(hash)).logs
58
+ });
59
+ for (const log of logs) if (log.eventName == "DataSourceCreated") return log.args.id;
60
+ console.error("Something went wrong: no id created!");
61
+ }
62
+ async updateDataSource(name, newManifestCid) {
63
+ const { chain, account } = this.getWriteConfig();
64
+ const hash = await this.walletClient.writeContract({
65
+ address: this.contractAddress,
66
+ abi: DS_REGISTRY_ABI,
67
+ functionName: "updateDataSource",
68
+ args: [name, newManifestCid],
69
+ chain,
70
+ account
71
+ });
72
+ await this.waitForTransaction(hash);
73
+ return hash;
74
+ }
75
+ async waitForTransaction(hash) {
76
+ return this.publicClient.waitForTransactionReceipt({ hash });
77
+ }
78
+ };
79
+
80
+ //#endregion
81
+ export { DataSourceRegistry };
@@ -0,0 +1,3 @@
1
+ import { SETTLEMENT_TRACKER_ABI } from "./settlement-tracker/abi.js";
2
+ import { DS_REGISTRY_ABI } from "./datasource-registry/abi.js";
3
+ export { DS_REGISTRY_ABI, SETTLEMENT_TRACKER_ABI };