@fangorn-network/sdk 0.1.0 → 0.1.2
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.
- package/README.md +1 -1
- package/lib/cli/cli.js +126 -325
- package/lib/cli/index.d.ts +2 -3
- package/lib/cli/index.js +10 -15
- package/lib/cli/sell.d.ts +28 -0
- package/lib/cli/sell.js +95 -0
- package/lib/cli/stage.d.ts +19 -0
- package/lib/cli/stage.js +94 -0
- package/lib/config.d.ts +71 -81
- package/lib/config.js +22 -38
- package/lib/contracts/data-registry/abi.d.ts +195 -19
- package/lib/contracts/data-registry/abi.js +409 -206
- package/lib/contracts/data-registry/index.d.ts +126 -2
- package/lib/contracts/data-registry/index.js +174 -1
- package/lib/contracts/index.d.ts +4 -7
- package/lib/contracts/index.js +4 -7
- package/lib/contracts/logs.d.ts +1 -1
- package/lib/contracts/logs.js +1 -1
- package/lib/contracts/{membership-registry → settlement-registry}/abi.d.ts +301 -636
- package/lib/contracts/settlement-registry/abi.js +962 -0
- package/lib/contracts/settlement-registry/index.d.ts +143 -0
- package/lib/contracts/settlement-registry/index.js +213 -0
- package/lib/crypto/aes.d.ts +2 -2
- package/lib/crypto/aes.js +4 -4
- package/lib/crypto/encryption.d.ts +8 -109
- package/lib/crypto/encryption.js +16 -114
- package/lib/crypto/paid.d.ts +104 -0
- package/lib/crypto/paid.js +147 -0
- package/lib/engine/car.d.ts +5 -1
- package/lib/engine/car.js +2 -2
- package/lib/engine/index.d.ts +33 -14
- package/lib/engine/index.js +98 -41
- package/lib/engine/records.d.ts +19 -8
- package/lib/engine/records.js +81 -7
- package/lib/engine/test-helpers.d.ts +2 -3
- package/lib/engine/test-helpers.js +7 -5
- package/lib/erc8004.js +6 -6
- package/lib/fangorn.d.ts +65 -86
- package/lib/fangorn.js +115 -153
- package/lib/feed.d.ts +7 -8
- package/lib/feed.js +7 -8
- package/lib/index.d.ts +10 -13
- package/lib/index.js +10 -13
- package/lib/providers/storage/signed-url.d.ts +2 -10
- package/lib/providers/storage/signed-url.js +5 -15
- package/lib/providers/storage/types.d.ts +1 -1
- package/lib/providers/storage/utils.js +5 -3
- package/lib/test/key-server.d.ts +12 -0
- package/lib/test/key-server.js +30 -0
- package/lib/test/mem-registry.d.ts +14 -19
- package/lib/test/mem-registry.js +44 -37
- package/lib/test/sdk-suite.d.ts +1 -4
- package/lib/test/sdk-suite.js +16 -87
- package/lib/test/testbed.d.ts +12 -22
- package/lib/test/testbed.js +29 -56
- package/lib/types/index.d.ts +6 -11
- package/package.json +1 -1
- package/lib/contracts/app-registry/abi.d.ts +0 -1265
- package/lib/contracts/app-registry/abi.js +0 -1454
- package/lib/contracts/app-registry/index.d.ts +0 -161
- package/lib/contracts/app-registry/index.js +0 -274
- package/lib/contracts/membership-registry/abi.js +0 -1333
- package/lib/contracts/membership-registry/index.d.ts +0 -79
- package/lib/contracts/membership-registry/index.js +0 -104
- package/lib/contracts/types.d.ts +0 -10
- package/lib/contracts/types.js +0 -12
- package/lib/harness/examples/hackmd/build-markdown-graph.d.ts +0 -1
- package/lib/harness/examples/hackmd/build-markdown-graph.js +0 -17
- package/lib/harness/index.d.ts +0 -58
- package/lib/harness/index.js +0 -73
- package/lib/registry.d.ts +0 -118
- package/lib/registry.js +0 -184
package/lib/test/testbed.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { FangornConfig } from "../config.js";
|
|
2
2
|
import { PinataBackend } from "../providers/storage/pinata.js";
|
|
3
|
-
import { APP_REGISTRY_ABI } from "../contracts/app-registry/abi.js";
|
|
4
3
|
import { DATA_REGISTRY_ABI } from "../contracts/data-registry/abi.js";
|
|
4
|
+
import { SETTLEMENT_REGISTRY_ABI } from "../contracts/settlement-registry/abi.js";
|
|
5
5
|
import "../contracts/index.js";
|
|
6
6
|
import { Fangorn } from "../fangorn.js";
|
|
7
7
|
import { MemLedger, MemRegistry } from "./mem-registry.js";
|
|
8
8
|
import { MemStorage } from "../engine/test-helpers.js";
|
|
9
|
-
import { createTestClient, encodeFunctionData, getAddress, http, parseEther, publicActions, walletActions } from "viem";
|
|
10
9
|
import { foundry } from "viem/chains";
|
|
10
|
+
import { createTestClient, encodeFunctionData, getAddress, http, parseEther, publicActions, walletActions } from "viem";
|
|
11
11
|
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
12
12
|
import { spawn, spawnSync } from "node:child_process";
|
|
13
13
|
import { existsSync, readFileSync } from "node:fs";
|
|
14
14
|
import { resolve } from "node:path";
|
|
15
15
|
|
|
16
16
|
//#region src/test/testbed.ts
|
|
17
|
-
/** The app every client is accepted into unless told otherwise. */
|
|
18
|
-
const TEST_APP = "test-app";
|
|
19
17
|
function memoryNetwork(Registry = MemRegistry) {
|
|
20
18
|
const ledger = new MemLedger();
|
|
21
19
|
const storage = new MemStorage();
|
|
@@ -23,20 +21,16 @@ function memoryNetwork(Registry = MemRegistry) {
|
|
|
23
21
|
name: "memory",
|
|
24
22
|
ledger,
|
|
25
23
|
storage,
|
|
26
|
-
client(
|
|
27
|
-
|
|
24
|
+
client(sk = generatePrivateKey(), R = Registry) {
|
|
25
|
+
return Promise.resolve(Fangorn.create({
|
|
28
26
|
privateKey: sk,
|
|
29
|
-
appId: app ?? void 0,
|
|
30
27
|
config: {
|
|
31
28
|
...FangornConfig,
|
|
32
|
-
|
|
29
|
+
fromBlock: 0n
|
|
33
30
|
},
|
|
34
31
|
storage: { backend: storage },
|
|
35
32
|
registry: new R(privateKeyToAccount(sk).address, ledger)
|
|
36
|
-
});
|
|
37
|
-
const id = f.getAppId();
|
|
38
|
-
if (id) ledger.members.add(`${id}/${f.getAddress().toLowerCase()}`);
|
|
39
|
-
return Promise.resolve(f);
|
|
33
|
+
}));
|
|
40
34
|
},
|
|
41
35
|
clock: () => Promise.resolve(ledger.t),
|
|
42
36
|
stop: () => void 0
|
|
@@ -52,8 +46,6 @@ const has = (cmd) => spawnSync(cmd, ["--version"]).status === 0;
|
|
|
52
46
|
const skipChain = !(has("anvil") && has("forge") && existsSync(CONTRACTS)) && !process.env.CI;
|
|
53
47
|
/** anvil's first prefunded account: the deployer, and the protocol admin. */
|
|
54
48
|
const ADMIN_KEY = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
|
|
55
|
-
/** No contract: fees are zero, so the token is never called. */
|
|
56
|
-
const NO_TOKEN = "0x000000000000000000000000000000000000dEaD";
|
|
57
49
|
async function startAnvil(chainId) {
|
|
58
50
|
const anvil = spawn("anvil", [
|
|
59
51
|
"--port",
|
|
@@ -81,8 +73,9 @@ async function startAnvil(chainId) {
|
|
|
81
73
|
anvil
|
|
82
74
|
};
|
|
83
75
|
}
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
/** `file`: the .sol it is in, when that isn't `name`.sol. */
|
|
77
|
+
function artifact(name, file = name) {
|
|
78
|
+
const json = JSON.parse(readFileSync(`${CONTRACTS}/out/${file}.sol/${name}.json`, "utf-8"));
|
|
86
79
|
return {
|
|
87
80
|
abi: json.abi,
|
|
88
81
|
bytecode: json.bytecode.object
|
|
@@ -97,7 +90,7 @@ function e2eStorage() {
|
|
|
97
90
|
}
|
|
98
91
|
/**
|
|
99
92
|
* A fresh anvil with the contracts deployed from source, each behind its
|
|
100
|
-
* ERC-1967 proxy as Deploy.s.sol does, and wired to each other.
|
|
93
|
+
* ERC-1967 proxy as Deploy.s.sol does, and wired to each other.
|
|
101
94
|
* Call `stop` from `afterAll`.
|
|
102
95
|
*/
|
|
103
96
|
async function chainNetwork() {
|
|
@@ -115,8 +108,8 @@ async function chainNetwork() {
|
|
|
115
108
|
transport: http(rpcUrl)
|
|
116
109
|
}).extend(publicActions).extend(walletActions);
|
|
117
110
|
const admin = privateKeyToAccount(ADMIN_KEY);
|
|
118
|
-
const deploy = async (name, args) => {
|
|
119
|
-
const { abi, bytecode } = artifact(name);
|
|
111
|
+
const deploy = async (name, args, file) => {
|
|
112
|
+
const { abi, bytecode } = artifact(name, file);
|
|
120
113
|
const hash = await chain.deployContract({
|
|
121
114
|
account: admin,
|
|
122
115
|
abi,
|
|
@@ -128,34 +121,27 @@ async function chainNetwork() {
|
|
|
128
121
|
return getAddress(contractAddress);
|
|
129
122
|
};
|
|
130
123
|
const proxied = async (name, init) => deploy("ERC1967Proxy", [await deploy(name, []), init]);
|
|
131
|
-
const
|
|
132
|
-
abi:
|
|
124
|
+
const data = await proxied("DataRegistry", encodeFunctionData({
|
|
125
|
+
abi: DATA_REGISTRY_ABI,
|
|
126
|
+
functionName: "initialize",
|
|
127
|
+
args: [admin.address]
|
|
128
|
+
}));
|
|
129
|
+
const usdc = await deploy("MockUSDC", [], "Mocks");
|
|
130
|
+
const settlement = await proxied("SettlementRegistry", encodeFunctionData({
|
|
131
|
+
abi: SETTLEMENT_REGISTRY_ABI,
|
|
133
132
|
functionName: "initialize",
|
|
134
133
|
args: [
|
|
135
134
|
admin.address,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
30n * 24n * 3600n
|
|
135
|
+
usdc,
|
|
136
|
+
await deploy("MockSemaphore", [], "Mocks")
|
|
139
137
|
]
|
|
140
138
|
}));
|
|
141
|
-
const data = await proxied("DataRegistry", encodeFunctionData({
|
|
142
|
-
abi: DATA_REGISTRY_ABI,
|
|
143
|
-
functionName: "initialize",
|
|
144
|
-
args: [admin.address, apps]
|
|
145
|
-
}));
|
|
146
|
-
await chain.waitForTransactionReceipt({ hash: await chain.writeContract({
|
|
147
|
-
account: admin,
|
|
148
|
-
address: apps,
|
|
149
|
-
abi: APP_REGISTRY_ABI,
|
|
150
|
-
functionName: "setDataRegistry",
|
|
151
|
-
args: [data]
|
|
152
|
-
}) });
|
|
153
139
|
const config = {
|
|
154
140
|
...FangornConfig,
|
|
155
141
|
rpcUrl,
|
|
156
|
-
appRegistryContractAddress: apps,
|
|
157
142
|
dataRegistryContractAddress: data,
|
|
158
|
-
|
|
143
|
+
settlementRegistryContractAddress: settlement,
|
|
144
|
+
fromBlock: 0n
|
|
159
145
|
};
|
|
160
146
|
const storage = e2eStorage();
|
|
161
147
|
/** A wallet with gas: `sk`, or a new one. */
|
|
@@ -166,37 +152,24 @@ async function chainNetwork() {
|
|
|
166
152
|
});
|
|
167
153
|
return sk;
|
|
168
154
|
};
|
|
169
|
-
/** A client
|
|
170
|
-
const
|
|
155
|
+
/** A client with gas. */
|
|
156
|
+
const client = async (sk) => Fangorn.create({
|
|
171
157
|
privateKey: await wallet(sk),
|
|
172
158
|
config,
|
|
173
|
-
appId: app,
|
|
174
159
|
storage: { backend: storage }
|
|
175
160
|
});
|
|
176
|
-
const owners = /* @__PURE__ */ new Map();
|
|
177
161
|
return {
|
|
178
162
|
name: "chain",
|
|
179
163
|
storage,
|
|
180
164
|
config,
|
|
181
165
|
chain,
|
|
182
|
-
|
|
166
|
+
usdc,
|
|
183
167
|
wallet,
|
|
184
|
-
|
|
185
|
-
owner: (app = TEST_APP) => owners.get(app),
|
|
186
|
-
async client(app = TEST_APP, sk) {
|
|
187
|
-
const f = await raw(app ?? void 0, sk);
|
|
188
|
-
if (app === null) return f;
|
|
189
|
-
const owner = owners.get(app);
|
|
190
|
-
if (!owner) {
|
|
191
|
-
await f.getAppRegistry().registerApp();
|
|
192
|
-
owners.set(app, f);
|
|
193
|
-
} else await owner.getAppRegistry().acceptPublisher(f.getAddress());
|
|
194
|
-
return f;
|
|
195
|
-
},
|
|
168
|
+
client,
|
|
196
169
|
clock: () => chain.getBlockNumber({ cacheTime: 0 }),
|
|
197
170
|
stop: () => anvil.kill()
|
|
198
171
|
};
|
|
199
172
|
}
|
|
200
173
|
|
|
201
174
|
//#endregion
|
|
202
|
-
export { MemLedger, MemRegistry,
|
|
175
|
+
export { MemLedger, MemRegistry, chainNetwork, memoryNetwork, skipChain };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Registry } from "../contracts/data-registry/index.js";
|
|
2
|
+
import "../contracts/index.js";
|
|
3
3
|
import { MetadataStorage } from "../providers/storage/types.js";
|
|
4
|
+
import { NetworkConfig } from "../config.js";
|
|
4
5
|
import { Hex, PublicClient, WalletClient } from "viem";
|
|
5
6
|
|
|
6
7
|
//#region src/types/index.d.ts
|
|
7
8
|
interface FangornContext {
|
|
8
|
-
config:
|
|
9
|
+
config: NetworkConfig;
|
|
9
10
|
walletClient: WalletClient;
|
|
10
11
|
publicClient: PublicClient;
|
|
11
12
|
metadataStorage: MetadataStorage | undefined;
|
|
12
|
-
/** Heads
|
|
13
|
+
/** Heads and the update log (WHITEPAPER_1 §3.2). */
|
|
13
14
|
registry: Registry;
|
|
14
|
-
/**
|
|
15
|
-
* The app this client reads and publishes under (the paper's context). Unset,
|
|
16
|
-
* reads are each publisher's latest head, and hosted uploads are refused.
|
|
17
|
-
*/
|
|
18
|
-
appId: Hex | undefined;
|
|
19
15
|
}
|
|
20
16
|
type StorageConfig = {
|
|
21
17
|
pinata: {
|
|
@@ -32,8 +28,7 @@ type StorageConfig = {
|
|
|
32
28
|
};
|
|
33
29
|
interface FangornCreateOptions {
|
|
34
30
|
storage?: StorageConfig;
|
|
35
|
-
config?:
|
|
36
|
-
appId?: string;
|
|
31
|
+
config?: NetworkConfig;
|
|
37
32
|
privateKey?: Hex;
|
|
38
33
|
walletClient?: WalletClient;
|
|
39
34
|
registry?: Registry;
|