@fangorn-network/sdk 2026.6.16 → 2026.7.1-2.1
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 +210 -266
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +261 -167
- package/lib/cli/index.d.ts +13 -651
- package/lib/config.d.ts +137 -792
- package/lib/config.js +6 -22
- package/lib/contracts/data-registry/abi.d.ts +38 -0
- package/lib/contracts/data-registry/abi.js +237 -0
- package/lib/contracts/data-registry/index.d.ts +81 -0
- package/lib/contracts/data-registry/index.js +184 -0
- package/lib/contracts/index.d.ts +3 -0
- package/lib/contracts/index.js +4 -0
- package/lib/crypto/aes.d.ts +26 -0
- package/lib/crypto/aes.js +58 -0
- package/lib/crypto/encryption.d.ts +53 -0
- package/lib/crypto/encryption.js +82 -0
- package/lib/{modules/encryption → crypto}/rand.d.ts +1 -1
- package/lib/{modules/encryption → crypto}/rand.js +1 -1
- package/lib/{modules/encryption → crypto}/types.d.ts +1 -1
- package/lib/engine/blockstore.d.ts +24 -0
- package/lib/engine/blockstore.js +85 -0
- package/lib/engine/index.d.ts +180 -0
- package/lib/engine/index.js +367 -0
- package/lib/fangorn.d.ts +149 -16
- package/lib/fangorn.js +256 -37
- package/lib/harness/examples/hackmd/build-markdown-graph.js +17 -0
- package/lib/harness/index.d.ts +57 -0
- package/lib/harness/index.js +67 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +2 -1
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +218 -0
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +261 -0
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +156 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +299 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +532 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +344 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +137 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +262 -0
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +150 -0
- package/lib/providers/storage/car.d.ts +36 -0
- package/lib/providers/storage/car.js +80 -0
- package/lib/providers/storage/pinata.d.ts +29 -1
- package/lib/providers/storage/pinata.js +135 -20
- package/lib/providers/storage/types.d.ts +25 -18
- package/lib/roles/repo/index.d.ts +56 -0
- package/lib/roles/repo/index.js +73 -0
- package/lib/test/car_smoke.d.ts +1 -0
- package/lib/test/car_smoke.js +81 -0
- package/lib/test/cleanup-embeddings-testdata.js +9 -38
- package/lib/test/setup-embeddings-testdata.d.ts +4 -6
- package/lib/test/setup-embeddings-testdata.js +40 -94
- package/lib/test/testbed.d.ts +35 -32
- package/lib/test/testbed.js +48 -138
- package/lib/types/index.d.ts +3 -19
- package/lib/utils/manifest.d.ts +23 -0
- package/lib/utils/manifest.js +77 -0
- package/package.json +99 -81
- package/lib/modules/encryption/actions.d.ts +0 -4
- package/lib/modules/encryption/actions.js +0 -18
- package/lib/modules/encryption/aes.d.ts +0 -10
- package/lib/modules/encryption/aes.js +0 -51
- package/lib/registries/datasource-registry/abi.d.ts +0 -186
- package/lib/registries/datasource-registry/abi.js +0 -229
- package/lib/registries/datasource-registry/index.d.ts +0 -39
- package/lib/registries/datasource-registry/index.js +0 -158
- package/lib/registries/index.d.ts +0 -3
- package/lib/registries/index.js +0 -4
- package/lib/registries/schema-registry/abi.d.ts +0 -218
- package/lib/registries/schema-registry/abi.js +0 -246
- package/lib/registries/schema-registry/index.d.ts +0 -34
- package/lib/registries/schema-registry/index.js +0 -179
- package/lib/registries/settlement-registry/abi.d.ts +0 -218
- package/lib/registries/settlement-registry/abi.js +0 -259
- package/lib/registries/settlement-registry/index.d.ts +0 -63
- package/lib/registries/settlement-registry/index.js +0 -325
- package/lib/registries/settlement-registry/types.d.ts +0 -54
- package/lib/registries/settlement-registry/types.js +0 -1
- package/lib/roles/consumer/index.d.ts +0 -39
- package/lib/roles/consumer/index.js +0 -150
- package/lib/roles/consumer/types.d.ts +0 -47
- package/lib/roles/consumer/types.js +0 -1
- package/lib/roles/publisher/builders/bundle.d.ts +0 -32
- package/lib/roles/publisher/builders/bundle.js +0 -137
- package/lib/roles/publisher/builders/record-set.d.ts +0 -17
- package/lib/roles/publisher/builders/record-set.js +0 -55
- package/lib/roles/publisher/builders/types.d.ts +0 -38
- package/lib/roles/publisher/builders/types.js +0 -1
- package/lib/roles/publisher/builders/utils.d.ts +0 -9
- package/lib/roles/publisher/builders/utils.js +0 -29
- package/lib/roles/publisher/encryption.d.ts +0 -18
- package/lib/roles/publisher/encryption.js +0 -38
- package/lib/roles/publisher/index.d.ts +0 -68
- package/lib/roles/publisher/index.js +0 -179
- package/lib/roles/publisher/types.d.ts +0 -114
- package/lib/roles/publisher/types.js +0 -1
- package/lib/roles/schema/index.d.ts +0 -44
- package/lib/roles/schema/index.js +0 -127
- package/lib/roles/schema/types.d.ts +0 -113
- package/lib/roles/schema/types.js +0 -1
- package/lib/roles/schema/validate.d.ts +0 -9
- package/lib/roles/schema/validate.js +0 -128
- package/lib/test/publish_mb_bundle.js +0 -296
- /package/lib/{modules/encryption/index.d.ts → contracts/data-registry/test.d.ts} +0 -0
- /package/lib/{modules/encryption/index.js → contracts/data-registry/test.js} +0 -0
- /package/lib/{modules/encryption → crypto}/types.js +0 -0
- /package/lib/{test/publish_mb_bundle.d.ts → harness/examples/hackmd/build-markdown-graph.d.ts} +0 -0
package/lib/config.js
CHANGED
|
@@ -16,35 +16,19 @@ const SupportedNetworks = {
|
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
18
|
* Get the network based on the string name
|
|
19
|
-
* @param name "arbitrumSepolia"
|
|
19
|
+
* @param name "arbitrumSepolia" is the only one supported right now
|
|
20
20
|
* @returns The corresponding network if it is supported, otherwise an error
|
|
21
21
|
*/
|
|
22
22
|
function getNetwork(name) {
|
|
23
23
|
if (name === SupportedNetworks.ArbitrumSepolia.name) return arbitrumSepolia;
|
|
24
|
-
else if (name === SupportedNetworks.BaseSepolia.name) return baseSepolia;
|
|
25
24
|
throw new Error(`Chain ${name} is not supported`);
|
|
26
25
|
}
|
|
27
26
|
const FangornConfig = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
chain: arbitrumSepolia,
|
|
34
|
-
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
35
|
-
caip2: 421614,
|
|
36
|
-
ipfsGateway: "https://ipfs.io"
|
|
37
|
-
},
|
|
38
|
-
BaseSepolia: {
|
|
39
|
-
dataSourceRegistryContractAddress: "0x6fd0e50073dbd8169bcaf066bb4a4991bfa48eeb",
|
|
40
|
-
schemaRegistryContractAddress: "0x0",
|
|
41
|
-
settlementRegistryContractAddress: "0x0",
|
|
42
|
-
chainName: "baseSepolia",
|
|
43
|
-
chain: baseSepolia,
|
|
44
|
-
rpcUrl: "https://sepolia.base.org",
|
|
45
|
-
caip2: 84532,
|
|
46
|
-
ipfsGateway: "https://ipfs.io"
|
|
47
|
-
}
|
|
27
|
+
dataRegistryContractAddress: "0x9a3811b365a4aeea1626eaad185b273424ae5e48",
|
|
28
|
+
chain: arbitrumSepolia,
|
|
29
|
+
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
30
|
+
caip2: 421614,
|
|
31
|
+
ipfsGateway: "https://ipfs.io"
|
|
48
32
|
};
|
|
49
33
|
|
|
50
34
|
//#endregion
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/contracts/data-registry/abi.d.ts
|
|
2
|
+
declare const DATA_REGISTRY_ABI: ({
|
|
3
|
+
inputs: never[];
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
anonymous?: undefined;
|
|
7
|
+
outputs?: undefined;
|
|
8
|
+
stateMutability?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
anonymous: boolean;
|
|
11
|
+
inputs: {
|
|
12
|
+
indexed: boolean;
|
|
13
|
+
internalType: string;
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
}[];
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
outputs?: undefined;
|
|
20
|
+
stateMutability?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
inputs: {
|
|
23
|
+
internalType: string;
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}[];
|
|
27
|
+
name: string;
|
|
28
|
+
outputs: {
|
|
29
|
+
internalType: string;
|
|
30
|
+
name: string;
|
|
31
|
+
type: string;
|
|
32
|
+
}[];
|
|
33
|
+
stateMutability: string;
|
|
34
|
+
type: string;
|
|
35
|
+
anonymous?: undefined;
|
|
36
|
+
})[];
|
|
37
|
+
//#endregion
|
|
38
|
+
export { DATA_REGISTRY_ABI };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
//#region src/contracts/data-registry/abi.ts
|
|
2
|
+
const DATA_REGISTRY_ABI = [
|
|
3
|
+
{
|
|
4
|
+
"inputs": [],
|
|
5
|
+
"name": "AlreadyRegistered",
|
|
6
|
+
"type": "error"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"inputs": [],
|
|
10
|
+
"name": "NotRegistered",
|
|
11
|
+
"type": "error"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"inputs": [],
|
|
15
|
+
"name": "PublisherSuspendedErr",
|
|
16
|
+
"type": "error"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"inputs": [],
|
|
20
|
+
"name": "RegistrationFeeRequired",
|
|
21
|
+
"type": "error"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"inputs": [],
|
|
25
|
+
"name": "StaleStateRoot",
|
|
26
|
+
"type": "error"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"inputs": [],
|
|
30
|
+
"name": "Unauthorized",
|
|
31
|
+
"type": "error"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"anonymous": false,
|
|
35
|
+
"inputs": [{
|
|
36
|
+
"indexed": true,
|
|
37
|
+
"internalType": "address",
|
|
38
|
+
"name": "publisher",
|
|
39
|
+
"type": "address"
|
|
40
|
+
}, {
|
|
41
|
+
"indexed": false,
|
|
42
|
+
"internalType": "bytes32",
|
|
43
|
+
"name": "initial_root",
|
|
44
|
+
"type": "bytes32"
|
|
45
|
+
}],
|
|
46
|
+
"name": "PublisherRegistered",
|
|
47
|
+
"type": "event"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"anonymous": false,
|
|
51
|
+
"inputs": [{
|
|
52
|
+
"indexed": true,
|
|
53
|
+
"internalType": "address",
|
|
54
|
+
"name": "publisher",
|
|
55
|
+
"type": "address"
|
|
56
|
+
}, {
|
|
57
|
+
"indexed": false,
|
|
58
|
+
"internalType": "bytes32",
|
|
59
|
+
"name": "current_root",
|
|
60
|
+
"type": "bytes32"
|
|
61
|
+
}],
|
|
62
|
+
"name": "PublisherReactivated",
|
|
63
|
+
"type": "event"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"anonymous": false,
|
|
67
|
+
"inputs": [{
|
|
68
|
+
"indexed": true,
|
|
69
|
+
"internalType": "address",
|
|
70
|
+
"name": "publisher",
|
|
71
|
+
"type": "address"
|
|
72
|
+
}],
|
|
73
|
+
"name": "PublisherSuspended",
|
|
74
|
+
"type": "event"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"anonymous": false,
|
|
78
|
+
"inputs": [{
|
|
79
|
+
"indexed": false,
|
|
80
|
+
"internalType": "uint256",
|
|
81
|
+
"name": "fee",
|
|
82
|
+
"type": "uint256"
|
|
83
|
+
}],
|
|
84
|
+
"name": "RegistrationFeeChanged",
|
|
85
|
+
"type": "event"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"anonymous": false,
|
|
89
|
+
"inputs": [
|
|
90
|
+
{
|
|
91
|
+
"indexed": true,
|
|
92
|
+
"internalType": "address",
|
|
93
|
+
"name": "publisher",
|
|
94
|
+
"type": "address"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"indexed": true,
|
|
98
|
+
"internalType": "bytes32",
|
|
99
|
+
"name": "old_root",
|
|
100
|
+
"type": "bytes32"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"indexed": true,
|
|
104
|
+
"internalType": "bytes32",
|
|
105
|
+
"name": "new_root",
|
|
106
|
+
"type": "bytes32"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"name": "StateCommitted",
|
|
110
|
+
"type": "event"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"inputs": [],
|
|
114
|
+
"name": "admin",
|
|
115
|
+
"outputs": [{
|
|
116
|
+
"internalType": "address",
|
|
117
|
+
"name": "",
|
|
118
|
+
"type": "address"
|
|
119
|
+
}],
|
|
120
|
+
"stateMutability": "view",
|
|
121
|
+
"type": "function"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"inputs": [{
|
|
125
|
+
"internalType": "bytes32",
|
|
126
|
+
"name": "old_root",
|
|
127
|
+
"type": "bytes32"
|
|
128
|
+
}, {
|
|
129
|
+
"internalType": "bytes32",
|
|
130
|
+
"name": "new_root",
|
|
131
|
+
"type": "bytes32"
|
|
132
|
+
}],
|
|
133
|
+
"name": "commitStateRoot",
|
|
134
|
+
"outputs": [],
|
|
135
|
+
"stateMutability": "nonpayable",
|
|
136
|
+
"type": "function"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"inputs": [{
|
|
140
|
+
"internalType": "address",
|
|
141
|
+
"name": "publisher",
|
|
142
|
+
"type": "address"
|
|
143
|
+
}],
|
|
144
|
+
"name": "getNamespaceHead",
|
|
145
|
+
"outputs": [{
|
|
146
|
+
"internalType": "bytes32",
|
|
147
|
+
"name": "",
|
|
148
|
+
"type": "bytes32"
|
|
149
|
+
}],
|
|
150
|
+
"stateMutability": "view",
|
|
151
|
+
"type": "function"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"inputs": [{
|
|
155
|
+
"internalType": "address",
|
|
156
|
+
"name": "publisher",
|
|
157
|
+
"type": "address"
|
|
158
|
+
}],
|
|
159
|
+
"name": "getPublisherStatus",
|
|
160
|
+
"outputs": [{
|
|
161
|
+
"internalType": "uint8",
|
|
162
|
+
"name": "",
|
|
163
|
+
"type": "uint8"
|
|
164
|
+
}],
|
|
165
|
+
"stateMutability": "view",
|
|
166
|
+
"type": "function"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"inputs": [{
|
|
170
|
+
"internalType": "address",
|
|
171
|
+
"name": "publisher",
|
|
172
|
+
"type": "address"
|
|
173
|
+
}],
|
|
174
|
+
"name": "isRegistered",
|
|
175
|
+
"outputs": [{
|
|
176
|
+
"internalType": "bool",
|
|
177
|
+
"name": "",
|
|
178
|
+
"type": "bool"
|
|
179
|
+
}],
|
|
180
|
+
"stateMutability": "view",
|
|
181
|
+
"type": "function"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"inputs": [],
|
|
185
|
+
"name": "publisherCount",
|
|
186
|
+
"outputs": [{
|
|
187
|
+
"internalType": "uint64",
|
|
188
|
+
"name": "",
|
|
189
|
+
"type": "uint64"
|
|
190
|
+
}],
|
|
191
|
+
"stateMutability": "view",
|
|
192
|
+
"type": "function"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"inputs": [],
|
|
196
|
+
"name": "register",
|
|
197
|
+
"outputs": [],
|
|
198
|
+
"stateMutability": "payable",
|
|
199
|
+
"type": "function"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"inputs": [],
|
|
203
|
+
"name": "registrationFee",
|
|
204
|
+
"outputs": [{
|
|
205
|
+
"internalType": "uint256",
|
|
206
|
+
"name": "",
|
|
207
|
+
"type": "uint256"
|
|
208
|
+
}],
|
|
209
|
+
"stateMutability": "view",
|
|
210
|
+
"type": "function"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"inputs": [{
|
|
214
|
+
"internalType": "uint256",
|
|
215
|
+
"name": "fee",
|
|
216
|
+
"type": "uint256"
|
|
217
|
+
}],
|
|
218
|
+
"name": "setRegistrationFee",
|
|
219
|
+
"outputs": [],
|
|
220
|
+
"stateMutability": "nonpayable",
|
|
221
|
+
"type": "function"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"inputs": [{
|
|
225
|
+
"internalType": "address",
|
|
226
|
+
"name": "publisher",
|
|
227
|
+
"type": "address"
|
|
228
|
+
}],
|
|
229
|
+
"name": "suspendPublisher",
|
|
230
|
+
"outputs": [],
|
|
231
|
+
"stateMutability": "nonpayable",
|
|
232
|
+
"type": "function"
|
|
233
|
+
}
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
//#endregion
|
|
237
|
+
export { DATA_REGISTRY_ABI };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
|
|
2
|
+
|
|
3
|
+
//#region src/contracts/data-registry/index.d.ts
|
|
4
|
+
declare enum PublisherStatus {
|
|
5
|
+
UNREGISTERED = 0,
|
|
6
|
+
ACTIVE = 1,
|
|
7
|
+
SUSPENDED = 2,
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A decoded `StateCommitted(publisher, old_root, new_root)` log — the single
|
|
11
|
+
* on-chain signal that a publisher's state root advanced. `logId` uniquely
|
|
12
|
+
* identifies the emitting log (tx + index) so consumers can dedupe across the
|
|
13
|
+
* catch-up (getLogs) and live (watch) paths.
|
|
14
|
+
*/
|
|
15
|
+
interface StateCommittedLog {
|
|
16
|
+
oldRoot: Hex;
|
|
17
|
+
newRoot: Hex;
|
|
18
|
+
blockNumber: bigint;
|
|
19
|
+
logId: string;
|
|
20
|
+
}
|
|
21
|
+
declare class DataRegistryClient {
|
|
22
|
+
private contractAddress;
|
|
23
|
+
private publicClient;
|
|
24
|
+
private walletClient;
|
|
25
|
+
constructor(contractAddress: Address, publicClient: PublicClient, walletClient: WalletClient);
|
|
26
|
+
private getWriteConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Internal helper to execute state-mutating transactions
|
|
29
|
+
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
30
|
+
*/
|
|
31
|
+
private executeWrite;
|
|
32
|
+
/**
|
|
33
|
+
* Register as a new data publisher or reactivate a suspended account.
|
|
34
|
+
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
35
|
+
*/
|
|
36
|
+
register(): Promise<Hash>;
|
|
37
|
+
/**
|
|
38
|
+
* The single mutating state gateway route.
|
|
39
|
+
* Enforces the sequential Compare-And-Swap (CAS) timeline rule.
|
|
40
|
+
*/
|
|
41
|
+
commitStateRoot(oldRoot: Hex, newRoot: Hex): Promise<Hash>;
|
|
42
|
+
/**
|
|
43
|
+
* Obtains the authoritative timeline tracking anchor for a specific publisher's tree.
|
|
44
|
+
*/
|
|
45
|
+
getNamespaceHead(publisher: Address): Promise<Hex>;
|
|
46
|
+
/**
|
|
47
|
+
* Reads the explicit enum lifecycle state from the registry status machine.
|
|
48
|
+
*/
|
|
49
|
+
getPublisherStatus(publisher: Address): Promise<PublisherStatus>;
|
|
50
|
+
/**
|
|
51
|
+
* Helper boolean view returning true if a publisher can currently commit data.
|
|
52
|
+
*/
|
|
53
|
+
isRegistered(publisher: Address): Promise<boolean>;
|
|
54
|
+
/** Current chain head block number — the default "start here" for a fresh subscription. */
|
|
55
|
+
currentBlock(): Promise<bigint>;
|
|
56
|
+
/**
|
|
57
|
+
* Historical `StateCommitted` logs for one publisher, oldest → newest — the
|
|
58
|
+
* catch-up path for a subscriber resuming from a saved block cursor. Node-side
|
|
59
|
+
* filtered by the indexed `publisher` topic, so no indexer is involved.
|
|
60
|
+
*/
|
|
61
|
+
getStateCommittedLogs(publisher: Address, fromBlock: bigint, toBlock?: bigint): Promise<StateCommittedLog[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Live-watch `StateCommitted` for one publisher. Returns an unsubscribe
|
|
64
|
+
* function. Uses the client's transport (polling over HTTP, push over a
|
|
65
|
+
* WebSocket transport) — reads logs straight from the RPC node, no subgraph.
|
|
66
|
+
*/
|
|
67
|
+
watchStateCommitted(publisher: Address, onCommit: (log: StateCommittedLog) => void, onError?: (err: Error) => void, pollingInterval?: number): () => void;
|
|
68
|
+
publisherCount(): Promise<bigint>;
|
|
69
|
+
registrationFee(): Promise<bigint>;
|
|
70
|
+
admin(): Promise<Address>;
|
|
71
|
+
/**
|
|
72
|
+
* Allows governance or protocol administrator to immediately freeze a publisher namespace.
|
|
73
|
+
*/
|
|
74
|
+
suspendPublisher(publisher: Address): Promise<Hash>;
|
|
75
|
+
/**
|
|
76
|
+
* Adjusts the current native/token onboarding collateral tier.
|
|
77
|
+
*/
|
|
78
|
+
setRegistrationFee(fee: bigint): Promise<Hash>;
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { DataRegistryClient, PublisherStatus, StateCommittedLog };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { DATA_REGISTRY_ABI } from "./abi.js";
|
|
2
|
+
|
|
3
|
+
//#region src/contracts/data-registry/index.ts
|
|
4
|
+
let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
|
|
5
|
+
PublisherStatus$1[PublisherStatus$1["UNREGISTERED"] = 0] = "UNREGISTERED";
|
|
6
|
+
PublisherStatus$1[PublisherStatus$1["ACTIVE"] = 1] = "ACTIVE";
|
|
7
|
+
PublisherStatus$1[PublisherStatus$1["SUSPENDED"] = 2] = "SUSPENDED";
|
|
8
|
+
return PublisherStatus$1;
|
|
9
|
+
}({});
|
|
10
|
+
function decodeStateCommitted(log) {
|
|
11
|
+
return {
|
|
12
|
+
oldRoot: log.args.old_root,
|
|
13
|
+
newRoot: log.args.new_root,
|
|
14
|
+
blockNumber: log.blockNumber,
|
|
15
|
+
logId: `${log.transactionHash}:${String(log.logIndex)}`
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var DataRegistryClient = class {
|
|
19
|
+
constructor(contractAddress, publicClient, walletClient) {
|
|
20
|
+
this.contractAddress = contractAddress;
|
|
21
|
+
this.publicClient = publicClient;
|
|
22
|
+
this.walletClient = walletClient;
|
|
23
|
+
}
|
|
24
|
+
getWriteConfig() {
|
|
25
|
+
if (!this.walletClient.chain) throw new Error("Chain required");
|
|
26
|
+
if (!this.walletClient.account) throw new Error("Account required");
|
|
27
|
+
return {
|
|
28
|
+
chain: this.walletClient.chain,
|
|
29
|
+
account: this.walletClient.account
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Internal helper to execute state-mutating transactions
|
|
34
|
+
* matching the exact gas buffer and aggressive fee styling of the protocol.
|
|
35
|
+
*/
|
|
36
|
+
async executeWrite(functionName, args, value) {
|
|
37
|
+
const { chain, account } = this.getWriteConfig();
|
|
38
|
+
const fees = await this.publicClient.estimateFeesPerGas();
|
|
39
|
+
const gas = await this.publicClient.estimateContractGas({
|
|
40
|
+
address: this.contractAddress,
|
|
41
|
+
abi: DATA_REGISTRY_ABI,
|
|
42
|
+
functionName,
|
|
43
|
+
args,
|
|
44
|
+
account,
|
|
45
|
+
value
|
|
46
|
+
});
|
|
47
|
+
const hash = await this.walletClient.writeContract({
|
|
48
|
+
address: this.contractAddress,
|
|
49
|
+
abi: DATA_REGISTRY_ABI,
|
|
50
|
+
functionName,
|
|
51
|
+
args,
|
|
52
|
+
chain,
|
|
53
|
+
account,
|
|
54
|
+
gas: gas * 130n / 100n,
|
|
55
|
+
maxFeePerGas: (fees.maxFeePerGas ?? 0n) * 3n,
|
|
56
|
+
maxPriorityFeePerGas: fees.maxPriorityFeePerGas,
|
|
57
|
+
value
|
|
58
|
+
});
|
|
59
|
+
await this.publicClient.waitForTransactionReceipt({ hash });
|
|
60
|
+
return hash;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Register as a new data publisher or reactivate a suspended account.
|
|
64
|
+
* Automatically reads the required on-chain fee and attaches it to the call.
|
|
65
|
+
*/
|
|
66
|
+
async register() {
|
|
67
|
+
const fee = await this.registrationFee();
|
|
68
|
+
return this.executeWrite("register", [], fee);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The single mutating state gateway route.
|
|
72
|
+
* Enforces the sequential Compare-And-Swap (CAS) timeline rule.
|
|
73
|
+
*/
|
|
74
|
+
async commitStateRoot(oldRoot, newRoot) {
|
|
75
|
+
return this.executeWrite("commitStateRoot", [oldRoot, newRoot]);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Obtains the authoritative timeline tracking anchor for a specific publisher's tree.
|
|
79
|
+
*/
|
|
80
|
+
async getNamespaceHead(publisher) {
|
|
81
|
+
return this.publicClient.readContract({
|
|
82
|
+
address: this.contractAddress,
|
|
83
|
+
abi: DATA_REGISTRY_ABI,
|
|
84
|
+
functionName: "getNamespaceHead",
|
|
85
|
+
args: [publisher]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Reads the explicit enum lifecycle state from the registry status machine.
|
|
90
|
+
*/
|
|
91
|
+
async getPublisherStatus(publisher) {
|
|
92
|
+
const status = await this.publicClient.readContract({
|
|
93
|
+
address: this.contractAddress,
|
|
94
|
+
abi: DATA_REGISTRY_ABI,
|
|
95
|
+
functionName: "getPublisherStatus",
|
|
96
|
+
args: [publisher]
|
|
97
|
+
});
|
|
98
|
+
return Number(status);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Helper boolean view returning true if a publisher can currently commit data.
|
|
102
|
+
*/
|
|
103
|
+
async isRegistered(publisher) {
|
|
104
|
+
return this.publicClient.readContract({
|
|
105
|
+
address: this.contractAddress,
|
|
106
|
+
abi: DATA_REGISTRY_ABI,
|
|
107
|
+
functionName: "isRegistered",
|
|
108
|
+
args: [publisher]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Current chain head block number — the default "start here" for a fresh subscription. */
|
|
112
|
+
async currentBlock() {
|
|
113
|
+
return this.publicClient.getBlockNumber();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Historical `StateCommitted` logs for one publisher, oldest → newest — the
|
|
117
|
+
* catch-up path for a subscriber resuming from a saved block cursor. Node-side
|
|
118
|
+
* filtered by the indexed `publisher` topic, so no indexer is involved.
|
|
119
|
+
*/
|
|
120
|
+
async getStateCommittedLogs(publisher, fromBlock, toBlock) {
|
|
121
|
+
return (await this.publicClient.getContractEvents({
|
|
122
|
+
address: this.contractAddress,
|
|
123
|
+
abi: DATA_REGISTRY_ABI,
|
|
124
|
+
eventName: "StateCommitted",
|
|
125
|
+
args: { publisher },
|
|
126
|
+
fromBlock,
|
|
127
|
+
toBlock: toBlock ?? "latest"
|
|
128
|
+
})).map(decodeStateCommitted).sort((a, b) => a.blockNumber === b.blockNumber ? a.logId.localeCompare(b.logId) : a.blockNumber < b.blockNumber ? -1 : 1);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Live-watch `StateCommitted` for one publisher. Returns an unsubscribe
|
|
132
|
+
* function. Uses the client's transport (polling over HTTP, push over a
|
|
133
|
+
* WebSocket transport) — reads logs straight from the RPC node, no subgraph.
|
|
134
|
+
*/
|
|
135
|
+
watchStateCommitted(publisher, onCommit, onError, pollingInterval) {
|
|
136
|
+
return this.publicClient.watchContractEvent({
|
|
137
|
+
address: this.contractAddress,
|
|
138
|
+
abi: DATA_REGISTRY_ABI,
|
|
139
|
+
eventName: "StateCommitted",
|
|
140
|
+
args: { publisher },
|
|
141
|
+
pollingInterval,
|
|
142
|
+
onLogs: (logs) => {
|
|
143
|
+
for (const log of logs) onCommit(decodeStateCommitted(log));
|
|
144
|
+
},
|
|
145
|
+
onError
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async publisherCount() {
|
|
149
|
+
return this.publicClient.readContract({
|
|
150
|
+
address: this.contractAddress,
|
|
151
|
+
abi: DATA_REGISTRY_ABI,
|
|
152
|
+
functionName: "publisherCount"
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async registrationFee() {
|
|
156
|
+
return this.publicClient.readContract({
|
|
157
|
+
address: this.contractAddress,
|
|
158
|
+
abi: DATA_REGISTRY_ABI,
|
|
159
|
+
functionName: "registrationFee"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async admin() {
|
|
163
|
+
return this.publicClient.readContract({
|
|
164
|
+
address: this.contractAddress,
|
|
165
|
+
abi: DATA_REGISTRY_ABI,
|
|
166
|
+
functionName: "admin"
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Allows governance or protocol administrator to immediately freeze a publisher namespace.
|
|
171
|
+
*/
|
|
172
|
+
async suspendPublisher(publisher) {
|
|
173
|
+
return this.executeWrite("suspendPublisher", [publisher]);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Adjusts the current native/token onboarding collateral tier.
|
|
177
|
+
*/
|
|
178
|
+
async setRegistrationFee(fee) {
|
|
179
|
+
return this.executeWrite("setRegistrationFee", [fee]);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
export { DataRegistryClient, PublisherStatus };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AesEncryptedData } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/crypto/aes.d.ts
|
|
4
|
+
/** AES-256 key length, in bytes. */
|
|
5
|
+
declare const AES_KEY_LENGTH = 32;
|
|
6
|
+
/** GCM nonce (IV) length, in bytes. The standard 96-bit nonce. */
|
|
7
|
+
declare const GCM_NONCE_LENGTH = 12;
|
|
8
|
+
/** GCM authentication tag length, in bytes. */
|
|
9
|
+
declare const GCM_TAG_LENGTH = 16;
|
|
10
|
+
/**
|
|
11
|
+
* AES-256-GCM encrypt. Returns the ciphertext with the 16-byte auth tag
|
|
12
|
+
* appended (noble's convention) — i.e. `ciphertext || tag`.
|
|
13
|
+
*/
|
|
14
|
+
declare function aesGcmEncrypt(key: Uint8Array, plaintext: Uint8Array, nonce: Uint8Array): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* AES-256-GCM decrypt. `sealed` is `ciphertext || tag` as produced by
|
|
17
|
+
* {@link aesGcmEncrypt}. Throws if the tag does not verify.
|
|
18
|
+
*/
|
|
19
|
+
declare function aesGcmDecrypt(key: Uint8Array, sealed: Uint8Array, nonce: Uint8Array): Uint8Array;
|
|
20
|
+
declare function encryptData(data: string | Uint8Array): Promise<{
|
|
21
|
+
encryptedData: AesEncryptedData;
|
|
22
|
+
keyMaterial: Uint8Array<ArrayBuffer>;
|
|
23
|
+
}>;
|
|
24
|
+
declare function decryptData(encryptedData: AesEncryptedData, keyMaterial: Uint8Array<ArrayBuffer>): Promise<Uint8Array>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { AES_KEY_LENGTH, GCM_NONCE_LENGTH, GCM_TAG_LENGTH, aesGcmDecrypt, aesGcmEncrypt, decryptData, encryptData };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { gcm } from "../node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js";
|
|
2
|
+
import { getRandomValues } from "./rand.js";
|
|
3
|
+
|
|
4
|
+
//#region src/crypto/aes.ts
|
|
5
|
+
/** AES-256 key length, in bytes. */
|
|
6
|
+
const AES_KEY_LENGTH = 32;
|
|
7
|
+
/** GCM nonce (IV) length, in bytes. The standard 96-bit nonce. */
|
|
8
|
+
const GCM_NONCE_LENGTH = 12;
|
|
9
|
+
/** GCM authentication tag length, in bytes. */
|
|
10
|
+
const GCM_TAG_LENGTH = 16;
|
|
11
|
+
/**
|
|
12
|
+
* AES-256-GCM encrypt. Returns the ciphertext with the 16-byte auth tag
|
|
13
|
+
* appended (noble's convention) — i.e. `ciphertext || tag`.
|
|
14
|
+
*/
|
|
15
|
+
function aesGcmEncrypt(key, plaintext, nonce) {
|
|
16
|
+
return gcm(key, nonce).encrypt(plaintext);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* AES-256-GCM decrypt. `sealed` is `ciphertext || tag` as produced by
|
|
20
|
+
* {@link aesGcmEncrypt}. Throws if the tag does not verify.
|
|
21
|
+
*/
|
|
22
|
+
function aesGcmDecrypt(key, sealed, nonce) {
|
|
23
|
+
return gcm(key, nonce).decrypt(sealed);
|
|
24
|
+
}
|
|
25
|
+
async function encryptData(data) {
|
|
26
|
+
const salt = getRandomValues(new Uint8Array(16));
|
|
27
|
+
const iv = getRandomValues(new Uint8Array(GCM_NONCE_LENGTH));
|
|
28
|
+
const keyMaterial = getRandomValues(new Uint8Array(AES_KEY_LENGTH));
|
|
29
|
+
const sealed = aesGcmEncrypt(keyMaterial, typeof data === "string" ? new TextEncoder().encode(data) : data, iv);
|
|
30
|
+
const ciphertext = sealed.slice(0, sealed.length - GCM_TAG_LENGTH);
|
|
31
|
+
const authTag = sealed.slice(sealed.length - GCM_TAG_LENGTH);
|
|
32
|
+
return {
|
|
33
|
+
encryptedData: {
|
|
34
|
+
ciphertext: new Uint8Array(ciphertext),
|
|
35
|
+
iv,
|
|
36
|
+
authTag: new Uint8Array(authTag),
|
|
37
|
+
salt
|
|
38
|
+
},
|
|
39
|
+
keyMaterial
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function decryptData(encryptedData, keyMaterial) {
|
|
43
|
+
const ciphertext = toUint8Array(encryptedData.ciphertext);
|
|
44
|
+
const iv = toUint8Array(encryptedData.iv);
|
|
45
|
+
const authTag = toUint8Array(encryptedData.authTag);
|
|
46
|
+
const sealed = new Uint8Array(ciphertext.length + authTag.length);
|
|
47
|
+
sealed.set(ciphertext, 0);
|
|
48
|
+
sealed.set(authTag, ciphertext.length);
|
|
49
|
+
return aesGcmDecrypt(keyMaterial, sealed, iv);
|
|
50
|
+
}
|
|
51
|
+
function toUint8Array(data) {
|
|
52
|
+
if (data instanceof Uint8Array) return data;
|
|
53
|
+
if (Array.isArray(data)) return new Uint8Array(data);
|
|
54
|
+
return new Uint8Array(Object.values(data));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { AES_KEY_LENGTH, GCM_NONCE_LENGTH, GCM_TAG_LENGTH, aesGcmDecrypt, aesGcmEncrypt, decryptData, encryptData };
|