@fangorn-network/sdk 2026.10.27-dev → 2026.11.3-dev
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 +36 -642
- package/lib/cli/cli.js +47 -322
- package/lib/cli/index.d.ts +1 -4
- package/lib/cli/index.js +2 -20
- package/lib/config.d.ts +15 -78
- package/lib/config.js +8 -35
- package/lib/contracts/data-registry/abi.d.ts +195 -19
- package/lib/contracts/data-registry/abi.js +223 -20
- 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 +5 -8
- 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 +288 -637
- package/lib/contracts/{membership-registry → settlement-registry}/abi.js +326 -712
- package/lib/contracts/settlement-registry/index.d.ts +141 -0
- package/lib/contracts/settlement-registry/index.js +209 -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/index.d.ts +23 -12
- package/lib/engine/index.js +68 -29
- package/lib/engine/records.d.ts +4 -7
- package/lib/engine/records.js +6 -6
- package/lib/engine/test-helpers.d.ts +2 -3
- package/lib/engine/test-helpers.js +7 -5
- package/lib/erc8004.js +1 -4
- package/lib/fangorn.d.ts +64 -85
- package/lib/fangorn.js +106 -148
- package/lib/feed.d.ts +7 -8
- package/lib/feed.js +7 -8
- package/lib/index.d.ts +10 -14
- package/lib/index.js +9 -13
- package/lib/providers/storage/signed-url.d.ts +2 -10
- package/lib/providers/storage/signed-url.js +4 -14
- 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 +5216 -5226
- package/lib/test/testbed.js +29 -56
- package/lib/types/index.d.ts +6 -11
- package/package.json +1 -4
- package/lib/contracts/app-registry/abi.d.ts +0 -1317
- package/lib/contracts/app-registry/abi.js +0 -1510
- package/lib/contracts/app-registry/index.d.ts +0 -173
- package/lib/contracts/app-registry/index.js +0 -294
- 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
|
@@ -9,6 +9,28 @@ const DATA_REGISTRY_ABI = [
|
|
|
9
9
|
"inputs": [],
|
|
10
10
|
"stateMutability": "nonpayable"
|
|
11
11
|
},
|
|
12
|
+
{
|
|
13
|
+
"type": "function",
|
|
14
|
+
"name": "EPOCH_SECONDS",
|
|
15
|
+
"inputs": [],
|
|
16
|
+
"outputs": [{
|
|
17
|
+
"name": "",
|
|
18
|
+
"type": "uint64",
|
|
19
|
+
"internalType": "uint64"
|
|
20
|
+
}],
|
|
21
|
+
"stateMutability": "view"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"type": "function",
|
|
25
|
+
"name": "UPDATE_TYPEHASH",
|
|
26
|
+
"inputs": [],
|
|
27
|
+
"outputs": [{
|
|
28
|
+
"name": "",
|
|
29
|
+
"type": "bytes32",
|
|
30
|
+
"internalType": "bytes32"
|
|
31
|
+
}],
|
|
32
|
+
"stateMutability": "view"
|
|
33
|
+
},
|
|
12
34
|
{
|
|
13
35
|
"type": "function",
|
|
14
36
|
"name": "UPGRADE_INTERFACE_VERSION",
|
|
@@ -20,6 +42,17 @@ const DATA_REGISTRY_ABI = [
|
|
|
20
42
|
}],
|
|
21
43
|
"stateMutability": "view"
|
|
22
44
|
},
|
|
45
|
+
{
|
|
46
|
+
"type": "function",
|
|
47
|
+
"name": "WINDOW",
|
|
48
|
+
"inputs": [],
|
|
49
|
+
"outputs": [{
|
|
50
|
+
"name": "",
|
|
51
|
+
"type": "uint64",
|
|
52
|
+
"internalType": "uint64"
|
|
53
|
+
}],
|
|
54
|
+
"stateMutability": "view"
|
|
55
|
+
},
|
|
23
56
|
{
|
|
24
57
|
"type": "function",
|
|
25
58
|
"name": "admin",
|
|
@@ -33,12 +66,60 @@ const DATA_REGISTRY_ABI = [
|
|
|
33
66
|
},
|
|
34
67
|
{
|
|
35
68
|
"type": "function",
|
|
36
|
-
"name": "
|
|
69
|
+
"name": "commitHead",
|
|
70
|
+
"inputs": [
|
|
71
|
+
{
|
|
72
|
+
"name": "repo",
|
|
73
|
+
"type": "string",
|
|
74
|
+
"internalType": "string"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "epoch",
|
|
78
|
+
"type": "uint64",
|
|
79
|
+
"internalType": "uint64"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "parent",
|
|
83
|
+
"type": "bytes32",
|
|
84
|
+
"internalType": "bytes32"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "root",
|
|
88
|
+
"type": "bytes32",
|
|
89
|
+
"internalType": "bytes32"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"name": "car",
|
|
93
|
+
"type": "bytes",
|
|
94
|
+
"internalType": "bytes"
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"outputs": [{
|
|
98
|
+
"name": "",
|
|
99
|
+
"type": "bytes32",
|
|
100
|
+
"internalType": "bytes32"
|
|
101
|
+
}],
|
|
102
|
+
"stateMutability": "pure"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"type": "function",
|
|
106
|
+
"name": "currentEpoch",
|
|
107
|
+
"inputs": [],
|
|
108
|
+
"outputs": [{
|
|
109
|
+
"name": "",
|
|
110
|
+
"type": "uint64",
|
|
111
|
+
"internalType": "uint64"
|
|
112
|
+
}],
|
|
113
|
+
"stateMutability": "view"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"type": "function",
|
|
117
|
+
"name": "domainSeparator",
|
|
37
118
|
"inputs": [],
|
|
38
119
|
"outputs": [{
|
|
39
120
|
"name": "",
|
|
40
|
-
"type": "
|
|
41
|
-
"internalType": "
|
|
121
|
+
"type": "bytes32",
|
|
122
|
+
"internalType": "bytes32"
|
|
42
123
|
}],
|
|
43
124
|
"stateMutability": "view"
|
|
44
125
|
},
|
|
@@ -72,14 +153,47 @@ const DATA_REGISTRY_ABI = [
|
|
|
72
153
|
"name": "admin_",
|
|
73
154
|
"type": "address",
|
|
74
155
|
"internalType": "address"
|
|
75
|
-
}, {
|
|
76
|
-
"name": "appRegistry_",
|
|
77
|
-
"type": "address",
|
|
78
|
-
"internalType": "address"
|
|
79
156
|
}],
|
|
80
157
|
"outputs": [],
|
|
81
158
|
"stateMutability": "nonpayable"
|
|
82
159
|
},
|
|
160
|
+
{
|
|
161
|
+
"type": "function",
|
|
162
|
+
"name": "logLength",
|
|
163
|
+
"inputs": [],
|
|
164
|
+
"outputs": [{
|
|
165
|
+
"name": "",
|
|
166
|
+
"type": "uint64",
|
|
167
|
+
"internalType": "uint64"
|
|
168
|
+
}],
|
|
169
|
+
"stateMutability": "view"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"type": "function",
|
|
173
|
+
"name": "logRoot",
|
|
174
|
+
"inputs": [],
|
|
175
|
+
"outputs": [{
|
|
176
|
+
"name": "",
|
|
177
|
+
"type": "bytes32",
|
|
178
|
+
"internalType": "bytes32"
|
|
179
|
+
}],
|
|
180
|
+
"stateMutability": "view"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"type": "function",
|
|
184
|
+
"name": "peaks",
|
|
185
|
+
"inputs": [{
|
|
186
|
+
"name": "",
|
|
187
|
+
"type": "uint256",
|
|
188
|
+
"internalType": "uint256"
|
|
189
|
+
}],
|
|
190
|
+
"outputs": [{
|
|
191
|
+
"name": "",
|
|
192
|
+
"type": "bytes32",
|
|
193
|
+
"internalType": "bytes32"
|
|
194
|
+
}],
|
|
195
|
+
"stateMutability": "view"
|
|
196
|
+
},
|
|
83
197
|
{
|
|
84
198
|
"type": "function",
|
|
85
199
|
"name": "proxiableUUID",
|
|
@@ -93,20 +207,43 @@ const DATA_REGISTRY_ABI = [
|
|
|
93
207
|
},
|
|
94
208
|
{
|
|
95
209
|
"type": "function",
|
|
96
|
-
"name": "
|
|
210
|
+
"name": "repoCount",
|
|
97
211
|
"inputs": [{
|
|
98
|
-
"name": "
|
|
212
|
+
"name": "publisher",
|
|
99
213
|
"type": "address",
|
|
100
214
|
"internalType": "address"
|
|
101
215
|
}],
|
|
102
|
-
"outputs": [
|
|
103
|
-
|
|
216
|
+
"outputs": [{
|
|
217
|
+
"name": "",
|
|
218
|
+
"type": "uint256",
|
|
219
|
+
"internalType": "uint256"
|
|
220
|
+
}],
|
|
221
|
+
"stateMutability": "view"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"type": "function",
|
|
225
|
+
"name": "repoIds",
|
|
226
|
+
"inputs": [{
|
|
227
|
+
"name": "",
|
|
228
|
+
"type": "address",
|
|
229
|
+
"internalType": "address"
|
|
230
|
+
}, {
|
|
231
|
+
"name": "",
|
|
232
|
+
"type": "uint256",
|
|
233
|
+
"internalType": "uint256"
|
|
234
|
+
}],
|
|
235
|
+
"outputs": [{
|
|
236
|
+
"name": "",
|
|
237
|
+
"type": "bytes32",
|
|
238
|
+
"internalType": "bytes32"
|
|
239
|
+
}],
|
|
240
|
+
"stateMutability": "view"
|
|
104
241
|
},
|
|
105
242
|
{
|
|
106
243
|
"type": "function",
|
|
107
|
-
"name": "
|
|
244
|
+
"name": "setAdmin",
|
|
108
245
|
"inputs": [{
|
|
109
|
-
"name": "
|
|
246
|
+
"name": "new_admin",
|
|
110
247
|
"type": "address",
|
|
111
248
|
"internalType": "address"
|
|
112
249
|
}],
|
|
@@ -122,18 +259,79 @@ const DATA_REGISTRY_ABI = [
|
|
|
122
259
|
"type": "string",
|
|
123
260
|
"internalType": "string"
|
|
124
261
|
},
|
|
262
|
+
{
|
|
263
|
+
"name": "epoch",
|
|
264
|
+
"type": "uint64",
|
|
265
|
+
"internalType": "uint64"
|
|
266
|
+
},
|
|
125
267
|
{
|
|
126
268
|
"name": "parent",
|
|
127
269
|
"type": "bytes32",
|
|
128
270
|
"internalType": "bytes32"
|
|
129
271
|
},
|
|
130
272
|
{
|
|
131
|
-
"name": "
|
|
273
|
+
"name": "root",
|
|
132
274
|
"type": "bytes32",
|
|
133
275
|
"internalType": "bytes32"
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"name": "car",
|
|
279
|
+
"type": "bytes",
|
|
280
|
+
"internalType": "bytes"
|
|
134
281
|
}
|
|
135
282
|
],
|
|
136
|
-
"outputs": [
|
|
283
|
+
"outputs": [{
|
|
284
|
+
"name": "",
|
|
285
|
+
"type": "bytes32",
|
|
286
|
+
"internalType": "bytes32"
|
|
287
|
+
}],
|
|
288
|
+
"stateMutability": "nonpayable"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"type": "function",
|
|
292
|
+
"name": "updateBySig",
|
|
293
|
+
"inputs": [
|
|
294
|
+
{
|
|
295
|
+
"name": "publisher",
|
|
296
|
+
"type": "address",
|
|
297
|
+
"internalType": "address"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"name": "repo",
|
|
301
|
+
"type": "string",
|
|
302
|
+
"internalType": "string"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"name": "epoch",
|
|
306
|
+
"type": "uint64",
|
|
307
|
+
"internalType": "uint64"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"name": "parent",
|
|
311
|
+
"type": "bytes32",
|
|
312
|
+
"internalType": "bytes32"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
"name": "root",
|
|
316
|
+
"type": "bytes32",
|
|
317
|
+
"internalType": "bytes32"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
"name": "car",
|
|
321
|
+
"type": "bytes",
|
|
322
|
+
"internalType": "bytes"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
"name": "signature",
|
|
326
|
+
"type": "bytes",
|
|
327
|
+
"internalType": "bytes"
|
|
328
|
+
}
|
|
329
|
+
],
|
|
330
|
+
"outputs": [{
|
|
331
|
+
"name": "",
|
|
332
|
+
"type": "bytes32",
|
|
333
|
+
"internalType": "bytes32"
|
|
334
|
+
}],
|
|
137
335
|
"stateMutability": "nonpayable"
|
|
138
336
|
},
|
|
139
337
|
{
|
|
@@ -241,6 +439,11 @@ const DATA_REGISTRY_ABI = [
|
|
|
241
439
|
"internalType": "address"
|
|
242
440
|
}]
|
|
243
441
|
},
|
|
442
|
+
{
|
|
443
|
+
"type": "error",
|
|
444
|
+
"name": "BadSignature",
|
|
445
|
+
"inputs": []
|
|
446
|
+
},
|
|
244
447
|
{
|
|
245
448
|
"type": "error",
|
|
246
449
|
"name": "ERC1967InvalidImplementation",
|
|
@@ -255,6 +458,11 @@ const DATA_REGISTRY_ABI = [
|
|
|
255
458
|
"name": "ERC1967NonPayable",
|
|
256
459
|
"inputs": []
|
|
257
460
|
},
|
|
461
|
+
{
|
|
462
|
+
"type": "error",
|
|
463
|
+
"name": "EpochOutOfWindow",
|
|
464
|
+
"inputs": []
|
|
465
|
+
},
|
|
258
466
|
{
|
|
259
467
|
"type": "error",
|
|
260
468
|
"name": "FailedCall",
|
|
@@ -293,11 +501,6 @@ const DATA_REGISTRY_ABI = [
|
|
|
293
501
|
"type": "error",
|
|
294
502
|
"name": "Unauthorized",
|
|
295
503
|
"inputs": []
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
"type": "error",
|
|
299
|
-
"name": "ZeroHead",
|
|
300
|
-
"inputs": []
|
|
301
504
|
}
|
|
302
505
|
];
|
|
303
506
|
|
|
@@ -1,7 +1,131 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PreparedTx } from "../write.js";
|
|
2
|
+
import { Address, Hash, Hex, PublicClient, TypedDataDomain, WalletClient } from "viem";
|
|
2
3
|
|
|
3
4
|
//#region src/contracts/data-registry/index.d.ts
|
|
4
5
|
/** A repo's on-chain id: keccak256 of its name's UTF-8 bytes, never of the name as hex. */
|
|
5
6
|
declare function repoId(repo: string): Hex;
|
|
7
|
+
declare const ZERO_HEAD: Hex;
|
|
8
|
+
/** η: epoch length in seconds. e(t) = ⌊t / η⌋. */
|
|
9
|
+
declare const EPOCH_SECONDS = 3600;
|
|
10
|
+
/** W: how many epochs a commit may lag the ordering's clock. */
|
|
11
|
+
declare const WINDOW = 24;
|
|
12
|
+
declare function epochOf(unixSeconds: number | bigint): number;
|
|
13
|
+
/** What an update carries: the commit's fields, from which the registry computes its head. */
|
|
14
|
+
interface CommitUpdate {
|
|
15
|
+
repo: string;
|
|
16
|
+
epoch: number;
|
|
17
|
+
/** digest of the parent commit, or ZERO_HEAD */
|
|
18
|
+
parent: Hex;
|
|
19
|
+
/** digest of the state root */
|
|
20
|
+
root: Hex;
|
|
21
|
+
/** the CAR's CID, as bytes */
|
|
22
|
+
car: Hex;
|
|
23
|
+
}
|
|
24
|
+
declare const UPDATE_TYPES: {
|
|
25
|
+
readonly Update: readonly [{
|
|
26
|
+
readonly name: "publisher";
|
|
27
|
+
readonly type: "address";
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "repo";
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "epoch";
|
|
33
|
+
readonly type: "uint64";
|
|
34
|
+
}, {
|
|
35
|
+
readonly name: "parent";
|
|
36
|
+
readonly type: "bytes32";
|
|
37
|
+
}, {
|
|
38
|
+
readonly name: "root";
|
|
39
|
+
readonly type: "bytes32";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "car";
|
|
42
|
+
readonly type: "bytes";
|
|
43
|
+
}];
|
|
44
|
+
};
|
|
45
|
+
declare const dataDomain: (chainId: number, registry: Address) => TypedDataDomain;
|
|
46
|
+
declare const updateMessage: (publisher: Address, u: CommitUpdate) => {
|
|
47
|
+
publisher: `0x${string}`;
|
|
48
|
+
repo: string;
|
|
49
|
+
epoch: bigint;
|
|
50
|
+
parent: `0x${string}`;
|
|
51
|
+
root: `0x${string}`;
|
|
52
|
+
car: `0x${string}`;
|
|
53
|
+
};
|
|
54
|
+
/** ρ = (P, s): one publisher's repo. */
|
|
55
|
+
interface RepoRef {
|
|
56
|
+
publisher: Address;
|
|
57
|
+
repo: string;
|
|
58
|
+
}
|
|
59
|
+
/** One entry of the update log U, (P, s, i, h, t): a repo's head moved from `parent` to `head`. */
|
|
60
|
+
interface UpdateEntry {
|
|
61
|
+
publisher: Address;
|
|
62
|
+
repo: string;
|
|
63
|
+
/** The head's position in the repo's history, from 1. */
|
|
64
|
+
pos: number;
|
|
65
|
+
parent: Hex;
|
|
66
|
+
head: Hex;
|
|
67
|
+
/** The block the entry is in: where log scans and cursors resume. */
|
|
68
|
+
t: bigint;
|
|
69
|
+
/** That block's timestamp: the `t` of the paper's entry, and what the contract's log leaf hashes. */
|
|
70
|
+
timestamp: bigint;
|
|
71
|
+
/** Unique per entry, for de-duplication across catch-up and live. */
|
|
72
|
+
id: string;
|
|
73
|
+
}
|
|
74
|
+
/** A slice of the update log: every repo, one publisher's, one repo name across publishers, or one repo. */
|
|
75
|
+
interface LogFilter {
|
|
76
|
+
publisher?: Address;
|
|
77
|
+
repo?: string;
|
|
78
|
+
}
|
|
79
|
+
interface Registry {
|
|
80
|
+
/** e(t) at the ordering's current clock. A commit's epoch must be within W of it. */
|
|
81
|
+
epoch(): Promise<number>;
|
|
82
|
+
/** H(ρ): the committed head, or ZERO_HEAD for a repo never written. */
|
|
83
|
+
head(ref: RepoRef): Promise<Hex>;
|
|
84
|
+
/** Moves the signer's repo to the commit `u`. Valid only while `u.parent` is the head (Theorem 3). */
|
|
85
|
+
update(u: CommitUpdate): Promise<Hash>;
|
|
86
|
+
/** `update` as an unsigned transaction for `publisher` to sign. */
|
|
87
|
+
prepareUpdate(publisher: Address, u: CommitUpdate): Promise<PreparedTx>;
|
|
88
|
+
/** The signer's EIP-712 signature over `u`, for `updateBySig`. */
|
|
89
|
+
signUpdate(u: CommitUpdate): Promise<Hex>;
|
|
90
|
+
/** `update` for `publisher`, on its signature. Anyone may submit it. */
|
|
91
|
+
updateBySig(publisher: Address, u: CommitUpdate, signature: Hex): Promise<Hash>;
|
|
92
|
+
/** The entries of a log between two clock values, oldest first. */
|
|
93
|
+
log(filter: LogFilter, from: bigint, to?: bigint): Promise<UpdateEntry[]>;
|
|
94
|
+
/** Follow the log live. Returns an unsubscribe function. */
|
|
95
|
+
watch(filter: LogFilter, onEntry: (entry: UpdateEntry) => void, onError?: (err: Error) => void, pollingInterval?: number): () => void;
|
|
96
|
+
/** The ordering's current clock value (a block number). */
|
|
97
|
+
clock(): Promise<bigint>;
|
|
98
|
+
}
|
|
99
|
+
interface ChainRegistryConfig {
|
|
100
|
+
dataRegistryContractAddress: Address;
|
|
101
|
+
logWindow?: bigint;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The registry on the DataRegistry contract.
|
|
105
|
+
*
|
|
106
|
+
* Gap against Definition 3.7: the log is read as events through a trusted RPC,
|
|
107
|
+
* not proven against the contract's mountain range.
|
|
108
|
+
*/
|
|
109
|
+
declare class ChainRegistry implements Registry {
|
|
110
|
+
private publicClient;
|
|
111
|
+
private walletClient?;
|
|
112
|
+
private readonly data;
|
|
113
|
+
private readonly logWindow?;
|
|
114
|
+
constructor(config: ChainRegistryConfig, publicClient: PublicClient, walletClient?: WalletClient | undefined);
|
|
115
|
+
epoch(): Promise<number>;
|
|
116
|
+
head(ref: RepoRef): Promise<Hex>;
|
|
117
|
+
update(u: CommitUpdate): Promise<Hash>;
|
|
118
|
+
prepareUpdate(publisher: Address, u: CommitUpdate): Promise<PreparedTx>;
|
|
119
|
+
signUpdate(u: CommitUpdate): Promise<Hex>;
|
|
120
|
+
updateBySig(publisher: Address, u: CommitUpdate, signature: Hex): Promise<Hash>;
|
|
121
|
+
private write;
|
|
122
|
+
/** U's `Updated` events, narrowed on-chain by publisher and repo. */
|
|
123
|
+
private source;
|
|
124
|
+
log(filter: LogFilter, from: bigint, to?: bigint): Promise<UpdateEntry[]>;
|
|
125
|
+
/** Logs don't carry their block's timestamp: one block read per distinct block. */
|
|
126
|
+
private withTimestamps;
|
|
127
|
+
watch(filter: LogFilter, onEntry: (entry: UpdateEntry) => void, onError?: (err: Error) => void, pollingInterval?: number): () => void;
|
|
128
|
+
clock(): Promise<bigint>;
|
|
129
|
+
}
|
|
6
130
|
//#endregion
|
|
7
|
-
export { repoId };
|
|
131
|
+
export { ChainRegistry, ChainRegistryConfig, CommitUpdate, EPOCH_SECONDS, LogFilter, Registry, RepoRef, UPDATE_TYPES, UpdateEntry, WINDOW, ZERO_HEAD, dataDomain, epochOf, repoId, updateMessage };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { DATA_REGISTRY_ABI } from "./abi.js";
|
|
2
|
+
import { getLogsInWindows } from "../logs.js";
|
|
3
|
+
import { prepareWrite, requireWallet, sendWrite } from "../write.js";
|
|
1
4
|
import { keccak256, toHex } from "viem";
|
|
2
5
|
|
|
3
6
|
//#region src/contracts/data-registry/index.ts
|
|
@@ -5,6 +8,176 @@ import { keccak256, toHex } from "viem";
|
|
|
5
8
|
function repoId(repo) {
|
|
6
9
|
return keccak256(toHex(repo));
|
|
7
10
|
}
|
|
11
|
+
const ZERO_HEAD = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
12
|
+
/** η: epoch length in seconds. e(t) = ⌊t / η⌋. */
|
|
13
|
+
const EPOCH_SECONDS = 3600;
|
|
14
|
+
/** W: how many epochs a commit may lag the ordering's clock. */
|
|
15
|
+
const WINDOW = 24;
|
|
16
|
+
function epochOf(unixSeconds) {
|
|
17
|
+
return Math.floor(Number(unixSeconds) / EPOCH_SECONDS);
|
|
18
|
+
}
|
|
19
|
+
const UPDATE_TYPES = { Update: [
|
|
20
|
+
{
|
|
21
|
+
name: "publisher",
|
|
22
|
+
type: "address"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "repo",
|
|
26
|
+
type: "string"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "epoch",
|
|
30
|
+
type: "uint64"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "parent",
|
|
34
|
+
type: "bytes32"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "root",
|
|
38
|
+
type: "bytes32"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "car",
|
|
42
|
+
type: "bytes"
|
|
43
|
+
}
|
|
44
|
+
] };
|
|
45
|
+
const dataDomain = (chainId, registry) => ({
|
|
46
|
+
name: "Fangorn Data",
|
|
47
|
+
version: "1",
|
|
48
|
+
chainId,
|
|
49
|
+
verifyingContract: registry
|
|
50
|
+
});
|
|
51
|
+
const updateMessage = (publisher, u) => ({
|
|
52
|
+
publisher,
|
|
53
|
+
repo: u.repo,
|
|
54
|
+
epoch: BigInt(u.epoch),
|
|
55
|
+
parent: u.parent,
|
|
56
|
+
root: u.root,
|
|
57
|
+
car: u.car
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* The registry on the DataRegistry contract.
|
|
61
|
+
*
|
|
62
|
+
* Gap against Definition 3.7: the log is read as events through a trusted RPC,
|
|
63
|
+
* not proven against the contract's mountain range.
|
|
64
|
+
*/
|
|
65
|
+
var ChainRegistry = class {
|
|
66
|
+
data;
|
|
67
|
+
logWindow;
|
|
68
|
+
constructor(config, publicClient, walletClient) {
|
|
69
|
+
this.publicClient = publicClient;
|
|
70
|
+
this.walletClient = walletClient;
|
|
71
|
+
this.data = config.dataRegistryContractAddress;
|
|
72
|
+
this.logWindow = config.logWindow;
|
|
73
|
+
}
|
|
74
|
+
async epoch() {
|
|
75
|
+
return epochOf((await this.publicClient.getBlock()).timestamp);
|
|
76
|
+
}
|
|
77
|
+
async head(ref) {
|
|
78
|
+
const [, head] = await this.publicClient.readContract({
|
|
79
|
+
address: this.data,
|
|
80
|
+
abi: DATA_REGISTRY_ABI,
|
|
81
|
+
functionName: "getHead",
|
|
82
|
+
args: [ref.publisher, repoId(ref.repo)]
|
|
83
|
+
});
|
|
84
|
+
return head;
|
|
85
|
+
}
|
|
86
|
+
update(u) {
|
|
87
|
+
return this.write("update", updateArgs(u));
|
|
88
|
+
}
|
|
89
|
+
prepareUpdate(publisher, u) {
|
|
90
|
+
return prepareWrite(this.publicClient, publisher, this.data, DATA_REGISTRY_ABI, "update", updateArgs(u), { fallbackGas: 300000n });
|
|
91
|
+
}
|
|
92
|
+
async signUpdate(u) {
|
|
93
|
+
const wallet = requireWallet(this.walletClient, "signUpdate");
|
|
94
|
+
if (!wallet.account) throw new Error("signUpdate: the wallet client has no account");
|
|
95
|
+
return wallet.signTypedData({
|
|
96
|
+
account: wallet.account,
|
|
97
|
+
domain: dataDomain(await this.publicClient.getChainId(), this.data),
|
|
98
|
+
types: UPDATE_TYPES,
|
|
99
|
+
primaryType: "Update",
|
|
100
|
+
message: updateMessage(wallet.account.address, u)
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
updateBySig(publisher, u, signature) {
|
|
104
|
+
return this.write("updateBySig", [
|
|
105
|
+
publisher,
|
|
106
|
+
...updateArgs(u),
|
|
107
|
+
signature
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
write(fn, args) {
|
|
111
|
+
return sendWrite(this.publicClient, requireWallet(this.walletClient, fn), this.data, DATA_REGISTRY_ABI, fn, args);
|
|
112
|
+
}
|
|
113
|
+
/** U's `Updated` events, narrowed on-chain by publisher and repo. */
|
|
114
|
+
source(filter) {
|
|
115
|
+
const ids = filter.repo === void 0 ? {} : { repo_id: repoId(filter.repo) };
|
|
116
|
+
const who = filter.publisher === void 0 ? {} : { publisher: filter.publisher };
|
|
117
|
+
return {
|
|
118
|
+
address: this.data,
|
|
119
|
+
abi: DATA_REGISTRY_ABI,
|
|
120
|
+
eventName: "Updated",
|
|
121
|
+
args: {
|
|
122
|
+
...who,
|
|
123
|
+
...ids
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async log(filter, from, to) {
|
|
128
|
+
const sorted = (await getLogsInWindows(this.publicClient, from, to, (fromBlock, toBlock) => this.publicClient.getContractEvents({
|
|
129
|
+
...this.source(filter),
|
|
130
|
+
fromBlock,
|
|
131
|
+
toBlock,
|
|
132
|
+
strict: true
|
|
133
|
+
}), this.logWindow)).sort((a, b) => a.blockNumber === b.blockNumber ? a.logIndex - b.logIndex : a.blockNumber < b.blockNumber ? -1 : 1);
|
|
134
|
+
return this.withTimestamps(sorted);
|
|
135
|
+
}
|
|
136
|
+
/** Logs don't carry their block's timestamp: one block read per distinct block. */
|
|
137
|
+
async withTimestamps(logs) {
|
|
138
|
+
const blocks = [...new Set(logs.map((l) => l.blockNumber))];
|
|
139
|
+
const times = new Map(await Promise.all(blocks.map(async (n) => [n, (await this.publicClient.getBlock({ blockNumber: n })).timestamp])));
|
|
140
|
+
return logs.map((l) => toEntry(l, times.get(l.blockNumber) ?? 0n));
|
|
141
|
+
}
|
|
142
|
+
watch(filter, onEntry, onError, pollingInterval) {
|
|
143
|
+
let queue = Promise.resolve();
|
|
144
|
+
return this.publicClient.watchContractEvent({
|
|
145
|
+
...this.source(filter),
|
|
146
|
+
strict: true,
|
|
147
|
+
pollingInterval,
|
|
148
|
+
onLogs: (logs) => {
|
|
149
|
+
queue = queue.then(() => this.withTimestamps(logs)).then((entries) => {
|
|
150
|
+
for (const e of entries) onEntry(e);
|
|
151
|
+
}).catch((e) => onError?.(e));
|
|
152
|
+
},
|
|
153
|
+
onError
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
clock() {
|
|
157
|
+
return this.publicClient.getBlockNumber({ cacheTime: 0 });
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
function updateArgs(u) {
|
|
161
|
+
return [
|
|
162
|
+
u.repo,
|
|
163
|
+
BigInt(u.epoch),
|
|
164
|
+
u.parent,
|
|
165
|
+
u.root,
|
|
166
|
+
u.car
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
function toEntry(log, timestamp) {
|
|
170
|
+
return {
|
|
171
|
+
publisher: log.args.publisher,
|
|
172
|
+
repo: log.args.repo,
|
|
173
|
+
pos: Number(log.args.pos),
|
|
174
|
+
parent: log.args.parent,
|
|
175
|
+
head: log.args.head,
|
|
176
|
+
t: log.blockNumber,
|
|
177
|
+
timestamp,
|
|
178
|
+
id: `${log.transactionHash}:${log.logIndex.toString()}`
|
|
179
|
+
};
|
|
180
|
+
}
|
|
8
181
|
|
|
9
182
|
//#endregion
|
|
10
|
-
export { repoId };
|
|
183
|
+
export { ChainRegistry, EPOCH_SECONDS, UPDATE_TYPES, WINDOW, ZERO_HEAD, dataDomain, epochOf, repoId, updateMessage };
|
package/lib/contracts/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
|
|
2
|
-
import { PublisherStatus } from "./types.js";
|
|
3
|
-
import { PreparedTx } from "./write.js";
|
|
4
|
-
import { AppAccess, AppAgentLog, AppRegistryClient } from "./app-registry/index.js";
|
|
5
1
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
2
|
+
import { PreparedTx } from "./write.js";
|
|
3
|
+
import { ChainRegistry, ChainRegistryConfig, CommitUpdate, EPOCH_SECONDS, LogFilter, Registry, RepoRef, UPDATE_TYPES, UpdateEntry, WINDOW, ZERO_HEAD, dataDomain, epochOf, repoId, updateMessage } from "./data-registry/index.js";
|
|
4
|
+
import { RegisterArgs, SettleArgs, SettlementPayment, SettlementRegistryClient, TERMS_TYPES, Terms, TermsJson, WHOLE_REPO, recordKey, registerNonce, settlementDomain, subjectOf, termsFromJson, termsToJson } from "./settlement-registry/index.js";
|
|
5
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
|
|
6
|
+
export { ChainRegistry, ChainRegistryConfig, CommitUpdate, DATA_REGISTRY_ABI, EPOCH_SECONDS, LogFilter, type PreparedTx, RegisterArgs, Registry, RepoRef, SETTLEMENT_REGISTRY_ABI, SettleArgs, SettlementPayment, SettlementRegistryClient, TERMS_TYPES, Terms, TermsJson, UPDATE_TYPES, UpdateEntry, WHOLE_REPO, WINDOW, ZERO_HEAD, dataDomain, epochOf, recordKey, registerNonce, repoId, settlementDomain, subjectOf, termsFromJson, termsToJson, updateMessage };
|
package/lib/contracts/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { APP_REGISTRY_ABI } from "./app-registry/abi.js";
|
|
2
|
-
import { AppRegistryClient } from "./app-registry/index.js";
|
|
3
|
-
import { repoId } from "./data-registry/index.js";
|
|
4
1
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { ChainRegistry, EPOCH_SECONDS, UPDATE_TYPES, WINDOW, ZERO_HEAD, dataDomain, epochOf, repoId, updateMessage } from "./data-registry/index.js";
|
|
3
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
|
|
4
|
+
import { SettlementRegistryClient, TERMS_TYPES, WHOLE_REPO, recordKey, registerNonce, settlementDomain, subjectOf, termsFromJson, termsToJson } from "./settlement-registry/index.js";
|
|
8
5
|
|
|
9
|
-
export {
|
|
6
|
+
export { ChainRegistry, DATA_REGISTRY_ABI, EPOCH_SECONDS, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, TERMS_TYPES, UPDATE_TYPES, WHOLE_REPO, WINDOW, ZERO_HEAD, dataDomain, epochOf, recordKey, registerNonce, repoId, settlementDomain, subjectOf, termsFromJson, termsToJson, updateMessage };
|
package/lib/contracts/logs.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { PublicClient } from "viem";
|
|
|
9
9
|
* RPC providers limit how many blocks one `eth_getLogs` call can cover (the
|
|
10
10
|
* Base Sepolia one 50,000, sepolia.base.org 200), and a call past the limit fails
|
|
11
11
|
* outright, taking whatever depends on it (a catch-up, a directory listing) with
|
|
12
|
-
* it. Each network's config says what its RPC takes (`
|
|
12
|
+
* it. Each network's config says what its RPC takes (`NetworkConfig.logWindow`, passed
|
|
13
13
|
* here as `defaultWindow`); `FANGORN_LOG_WINDOW` overrides it, for a private RPC.
|
|
14
14
|
*/
|
|
15
15
|
declare function getLogsInWindows<T>(publicClient: PublicClient, fromBlock: bigint, toBlock: bigint | undefined, fetch: (fromBlock: bigint, toBlock: bigint) => Promise<T[]>, defaultWindow?: bigint | undefined): Promise<T[]>;
|
package/lib/contracts/logs.js
CHANGED
|
@@ -8,7 +8,7 @@ import { nonBlank } from "../config.js";
|
|
|
8
8
|
* RPC providers limit how many blocks one `eth_getLogs` call can cover (the
|
|
9
9
|
* Base Sepolia one 50,000, sepolia.base.org 200), and a call past the limit fails
|
|
10
10
|
* outright, taking whatever depends on it (a catch-up, a directory listing) with
|
|
11
|
-
* it. Each network's config says what its RPC takes (`
|
|
11
|
+
* it. Each network's config says what its RPC takes (`NetworkConfig.logWindow`, passed
|
|
12
12
|
* here as `defaultWindow`); `FANGORN_LOG_WINDOW` overrides it, for a private RPC.
|
|
13
13
|
*/
|
|
14
14
|
async function getLogsInWindows(publicClient, fromBlock, toBlock, fetch, defaultWindow = 1000n) {
|