@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/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ # MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # Fangorn
2
+
3
+ Programmable data.
4
+
5
+ ## Overview
6
+
7
+ Fangorn is a programmable data framework that lets you **register datasources** and **publish encrypted data** under public conditions, or predicates, such that it can only be decrypted if you meet the condition(s).
8
+
9
+ ## Supported Networks
10
+
11
+ Fangorn can be deployed on any EVM chain that has a brige to Lit protocol. Currently, contracts are deployed to both Arbitrum Sepolia and Base Sepolia. See the [contracts](#contracts) section for more info.
12
+
13
+ ## Usage
14
+
15
+ Fangorn is a programmable data framework. It provides tools to register data sources that can be accessed based on owner-defined conditions, like payment.
16
+
17
+ ## CLI/Quickstart
18
+
19
+ To install the fangorn-sdk from NPM, run:
20
+
21
+ ```shell
22
+ npm i -g fangorn-sdk
23
+ ```
24
+
25
+ ### Register a Datasource
26
+
27
+ First register a datasource
28
+
29
+ ```sh
30
+ fangorn register name-of-your-datasource-agent
31
+ ```
32
+
33
+ ### Upload Data
34
+
35
+ On upload, data is encrypted under a user-specified **gadget**. For now, the CLI only supports the payment gadget, which is used by specifying the argument `-g "Payment(amount)"`. The minimum amount is `0.000001`.
36
+
37
+ For `-c`, the CLI supports both arbitrumSepolia and baseSepolia.
38
+
39
+ ```sh
40
+ fangorn upload name-of-your-datasource-agent file-to-upload.ext -c arbitrumSepolia -g "Payment(0.0001)"
41
+ ```
42
+
43
+ ### Decrypt and Download
44
+
45
+ ```sh
46
+ fangorn decrypt [owner] [datasourceName] [tag] -c arbitrumSepolia
47
+ ```
48
+
49
+ ## Full Guide
50
+
51
+ ### Build
52
+
53
+ `pnpm i`
54
+
55
+ ### Setup
56
+
57
+ ```js
58
+ // provide the account, rpcurl, and chain externally
59
+ // Initalize a wallet client
60
+ const walletClient = createWalletClient({
61
+ account,
62
+ transport: http(rpcUrl),
63
+ chain,
64
+ });
65
+ // For ArbSep, also supports BaseSepolia (wallet client must match)
66
+ const config: AppConfig = FangornConfig.ArbitrumSepolia;
67
+ // and the encryption service
68
+ const encryptionService = new LitEncryptionService(chain);
69
+
70
+ // setup the storage client
71
+ const pinata = new PinataSDK({
72
+ pinataJwt: jwt,
73
+ pinataGateway: gateway,
74
+ });
75
+ // we only support pinata right now, more to come
76
+ const storage = new PinataStorage(pinata);
77
+
78
+ // the domain/webserver where Fangorn is used
79
+ const domain = "localhost";
80
+
81
+ const fangorn = await Fangorn.init(
82
+ walletClient,
83
+ storage,
84
+ encryptionService,
85
+ domain,
86
+ config,
87
+ );
88
+ ```
89
+
90
+ ### Datasource Registration
91
+
92
+ Now that you have a Fangorn client, you can create a _datasource_. A datasource is an on-chain asset that stores a commitment to its storage root along with an optional `agentId` field for associating the datasource with an ERC-8004 identity.
93
+
94
+ ```js
95
+ const name = "demo";
96
+ // id = sha256(name || owner), agentId = ""
97
+ const id = await this.delegatorFangorn.registerDataSource(name, "");
98
+ ```
99
+
100
+ ### Encryption
101
+
102
+ Once a datasource exists, the owner can update its storage root to point it to data. Fangorn leverages Lit protocol for encryption and access control.
103
+
104
+ Encryption works by specifying a [gadget](./src/modules/gadgets/README.md), code that represents a logical statement that you want to encrypt under. The gadgets framework is extensible and customizable, allowing for easy custom implementations. For now, we have three gadgets:
105
+
106
+ - empty wallet: must have an empty wallet to decrypt
107
+ - identity: must have a specific identity to decrypt
108
+ - payment: must submit a specific payment to decrypt
109
+
110
+ ```js
111
+ // configure data using a json array, note that all data in this array will be encrypted under the same condition
112
+ // each entry has as (tag, data, extension, fileTpe)
113
+ let filedata = [
114
+ {
115
+ tag: "test0",
116
+ data: "content0",
117
+ extension: ".txt",
118
+ fileType: "text/plain",
119
+ },
120
+ {
121
+ tag: "test1",
122
+ data: "content1",
123
+ extension: ".png",
124
+ fileType: "image/png",
125
+ },
126
+ ];
127
+
128
+ // this encrypts the file under a USDC payment condition, useful for x402
129
+ await fangorn.upload(datasourceName, filedata, async (file) => {
130
+ const commitment = await computeTagCommitment(
131
+ this.delegatorAddress,
132
+ datasourceName,
133
+ file.tag,
134
+ usdcPrice,
135
+ );
136
+ return new PaymentGadget({
137
+ commitment: fieldToHex(commitment),
138
+ chainName: this.config.chainName,
139
+ settlementTrackerContractAddress,
140
+ usdcPrice,
141
+ });
142
+ });
143
+ ```
144
+
145
+ ### Decryption
146
+
147
+ Decryption mandates that the caller has met the condition specified by the ciphertext. If unknown, the condition can be decoded by fetching the entry from storage (pinata) in which we store a `gadgetDescriptor`, providing pertinent information about the gadget used to encrypt the plaintext and how to satisfy it.
148
+
149
+ ```js
150
+ // the address of the owner of the datasource
151
+ const owner = "0xabc123...";
152
+ // the name of the datasource
153
+ const name = "demo";
154
+ // the tag of the data we want to fetch
155
+ const tag = "test0";
156
+
157
+ const plaintext = await fangorn.decryptFile(owner, name, tag);
158
+ const outputAsString = new TextDecoder().decode(output);
159
+ console.log("we got the plaintext " + outputAsString);
160
+ ```
161
+
162
+ ## Testing
163
+
164
+ ### Unit Tests
165
+
166
+ Run the tests with:
167
+
168
+ ```sh
169
+ pnpm test
170
+ ```
171
+
172
+ ### E2E tests
173
+
174
+ #### Setup
175
+
176
+ The e2e test suite requires various environment variables that must be manually configured. In addition, it must be executed on an actual testnet in order to establish comms with Lit protocol.
177
+
178
+ Testnet tokens (ETH on Base Sepolia) can be obtained from Coinbase's official faucet https://portal.cdp.coinbase.com/
179
+
180
+ 1. `cp .env.example .env`
181
+ 2. Fill in the ENVs:
182
+ - `DELEGATOR_ETH_PRIVATE_KEY`: The private key of the delegator account
183
+ - Needs to have a balance of test ETH to send transactions
184
+ - `DELEGATEE_ETH_PRIVATE_KEY`: The private key of the delegatee account
185
+ - Needs to have a balance of test ETH to send transactions
186
+
187
+ - `PINATA_JWT`: The JWT for Pinata
188
+ - Can be obtained from: https://app.pinata.cloud/developers/api-keys
189
+ - `PINATA_GATEWAY`: The gateway for Pinata
190
+ - Can use your own gateway or the default 'https://gateway.pinata.cloud'
191
+ - `CHAIN_NAME`: arbitrumSepolia or baseSepolia
192
+ - `CAIP2`: The CAIP-2 identifier for the network.
193
+ - 421614 for Arbitrum Sepolia, 84532 for Base Sepolia
194
+ - `CHAIN_RPC_URL`: The RPC URL of the chain
195
+ - Expected to be Base sepolia testnet: https://base-sepolia-public.nodies.app or Arbitrum Sepolia: https://sepolia-rollup.arbitrum.io/rpc
196
+ - `USDC_CONTRACT_ADDRESS`: The address of the deployed USDC contract
197
+ - 0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d for Arbitrum Sepolia 0x036CbD53842c5426634e7929541eC2318f3dCF7e for Base Sepolia
198
+ - `DS_REGISTRY_ADDR`: The address of the deployed data registry contract
199
+ - Can be deployed by the test script, else use 0x5bd547ce3b5964c2fc0325f523679f66de391d6f for Arbitrum Sepolia and 0x6fd0e50073dbd8169bcaf066bb4a4991bfa48eeb on Base Sepolia
200
+ - `SETTLEMENT_TRACKER_ADDR`: The address of the deployed settlement tracker contract address. This is only needed if you plan to run tests using the payment gadget.
201
+ - Can be deployed by the test script, else use 0x7c6ae9eb3398234eb69b2f3acfae69065505ff69 for Arbitrum Sepolia
202
+
203
+ Sample:
204
+
205
+ For Arbitrum Sepolia
206
+
207
+ ```sh
208
+ CHAIN_NAME=arbitrumSepolia
209
+ CAIP2=421614
210
+ CHAIN_RPC_URL=https://sepolia-rollup.arbitrum.io/rpc
211
+ USDC_CONTRACT_ADDRESS=0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d
212
+ DS_REGISTRY_ADDR=0x602aedafe1096004d4db591b6537bc39d7ac71a6
213
+ SETTLEMENT_TRACKER_ADDR=0x7c6ae9eb3398234eb69b2f3acfae69065505ff69
214
+ ```
215
+
216
+ For Base Sepolia
217
+
218
+ ```sh
219
+ CHAIN_NAME=baseSepolia
220
+ CAIP2=84532
221
+ CHAIN_RPC_URL=https://base-sepolia-public.nodies.app
222
+ USDC_CONTRACT_ADDRESS=0x036CbD53842c5426634e7929541eC2318f3dCF7e
223
+ DS_REGISTRY_ADDR=0x6fd0e50073dbd8169bcaf066bb4a4991bfa48eeb
224
+ SETTLEMENT_TRACKER_ADDR=0x708751829f5f5f584da4142b62cd5cc9235c8a18
225
+ ```
226
+
227
+ ### Running the tests
228
+
229
+ `pnpm test:e2e`
230
+
231
+ The tests will:
232
+
233
+ 1. Build and deploy the solidity verifier to base sepolia (unless it is defined in .env)
234
+ 2. Upload the Lit Action to IPFS (unless it is defined in .env)
235
+
236
+ ## Contracts
237
+
238
+ | | Arbitrum Sepolia | Base Sepolia |
239
+ | -------------------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------- |
240
+ | Datsource Registry Contract Deployment | 0x602aedafe1096004d4db591b6537bc39d7ac71a6 | 0x6fd0e50073dbd8169bcaf066bb4a4991bfa48eeb |
241
+ | Datsource Registry Contract Code | [lib.rs](./contracts/arbitrum/DatasourceRegistry/src/lib.rs) | [DSRegistry.sol](./contracts/src/DSRegistry.sol) |
242
+ | Settlement Tracker Contract Deployment | 0x7c6ae9eb3398234eb69b2f3acfae69065505ff69 | 0x708751829f5f5f584da4142b62cd5cc9235c8a18 |
243
+ | Settlement Tracker Contract Code | [lib.rs](./contracts/arbitrum/SettlementTracker//src/lib.rs) | [SettlementTracker.sol](./contracts/src/SettlementTracker.sol) |
244
+
245
+ ## CLI
246
+
247
+ To install locally:
248
+
249
+ ```sh
250
+ chmod +x update_cli.sh
251
+ ./update_cli.sh
252
+ ```
253
+
254
+ ```sh
255
+ Usage: Fangorn [options] [command]
256
+
257
+ CLI for Fangorn
258
+
259
+ Options:
260
+ -V, --version output the version number
261
+ -h, --help display help for command
262
+
263
+ Commands:
264
+ init Configure your Fangorn credentials
265
+ register [options] <name> Register a new datasource as an agent.
266
+ upload [options] <name> <files...> Upload file(s) to a data source
267
+ list [options] <name> List contents (index) of a data source
268
+ info [options] <name> Get data source info from contract
269
+ entry [options] <name> <tag> Get info about a specific entry
270
+ decrypt [options] <owner> <name> <tag> Decrypt a file from a vault
271
+ help [command] display help for command
272
+ ```
273
+
274
+ ## License
275
+
276
+ MIT
@@ -0,0 +1,28 @@
1
+ import { AgentCard } from "@a2a-js/sdk";
2
+
3
+ //#region src/builders/a2aCardBuilder.d.ts
4
+ declare class AgentCardBuilder {
5
+ private card;
6
+ name(name: string): this;
7
+ description(description: string): this;
8
+ version(version: string): this;
9
+ url(url: string): this;
10
+ protocolVersion(protocolVersion: string): this;
11
+ capabilities(opts: {
12
+ streaming?: boolean;
13
+ pushNotifications?: boolean;
14
+ stateTransitionHistory?: boolean;
15
+ }): this;
16
+ streaming(enabled?: boolean): this;
17
+ pushNotifications(enabled?: boolean): this;
18
+ stateTransitionHistory(enabled?: boolean): this;
19
+ inputModes(modes: string[]): this;
20
+ outputModes(modes: string[]): this;
21
+ addSkill(id: string, name: string, description: string, tags: string[], examples?: string[]): this;
22
+ provider(organization: string, url: string): this;
23
+ documentationUrl(url: string): this;
24
+ build(): AgentCard;
25
+ }
26
+ declare const agentCardBuilder: () => AgentCardBuilder;
27
+ //#endregion
28
+ export { AgentCardBuilder, agentCardBuilder };
@@ -0,0 +1,104 @@
1
+ //#region src/builders/a2aCardBuilder.ts
2
+ var AgentCardBuilder = class {
3
+ card = {
4
+ capabilities: {
5
+ streaming: false,
6
+ pushNotifications: false,
7
+ stateTransitionHistory: false
8
+ },
9
+ defaultInputModes: ["text/plain", "application/json"],
10
+ defaultOutputModes: ["text/plain", "application/json"],
11
+ skills: []
12
+ };
13
+ name(name) {
14
+ this.card.name = name;
15
+ return this;
16
+ }
17
+ description(description) {
18
+ this.card.description = description;
19
+ return this;
20
+ }
21
+ version(version) {
22
+ this.card.version = version;
23
+ return this;
24
+ }
25
+ url(url) {
26
+ this.card.url = url;
27
+ return this;
28
+ }
29
+ protocolVersion(protocolVersion) {
30
+ this.card.protocolVersion = protocolVersion;
31
+ return this;
32
+ }
33
+ capabilities(opts) {
34
+ this.card.capabilities = {
35
+ ...this.card.capabilities,
36
+ ...opts
37
+ };
38
+ return this;
39
+ }
40
+ streaming(enabled = true) {
41
+ this.card.capabilities = {
42
+ ...this.card.capabilities,
43
+ streaming: enabled
44
+ };
45
+ return this;
46
+ }
47
+ pushNotifications(enabled = true) {
48
+ this.card.capabilities = {
49
+ ...this.card.capabilities,
50
+ pushNotifications: enabled
51
+ };
52
+ return this;
53
+ }
54
+ stateTransitionHistory(enabled = true) {
55
+ this.card.capabilities = {
56
+ ...this.card.capabilities,
57
+ stateTransitionHistory: enabled
58
+ };
59
+ return this;
60
+ }
61
+ inputModes(modes) {
62
+ this.card.defaultInputModes = modes;
63
+ return this;
64
+ }
65
+ outputModes(modes) {
66
+ this.card.defaultOutputModes = modes;
67
+ return this;
68
+ }
69
+ addSkill(id, name, description, tags, examples) {
70
+ const skill = {
71
+ id,
72
+ name,
73
+ description,
74
+ tags
75
+ };
76
+ if (examples) skill.examples = examples;
77
+ this.card.skills.push(skill);
78
+ return this;
79
+ }
80
+ provider(organization, url) {
81
+ this.card.provider = {
82
+ organization,
83
+ url
84
+ };
85
+ return this;
86
+ }
87
+ documentationUrl(url) {
88
+ this.card.documentationUrl = url;
89
+ return this;
90
+ }
91
+ build() {
92
+ for (const field of [
93
+ "name",
94
+ "description",
95
+ "version",
96
+ "url"
97
+ ]) if (!this.card[field]) throw new Error(`AgentCard requires '${field}'`);
98
+ return this.card;
99
+ }
100
+ };
101
+ const agentCardBuilder = () => new AgentCardBuilder();
102
+
103
+ //#endregion
104
+ export { AgentCardBuilder, agentCardBuilder };
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "dotenv/config";