@corpus-core/colibri-stateless 0.1.20 → 0.2.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/index.js CHANGED
@@ -96,6 +96,19 @@ export async function handle_request(req, conf) {
96
96
  if (conf.debug)
97
97
  log(`::: ${path} (Error: ${last_error})`);
98
98
  }
99
+ function check_trusted_blockhashes(trusted_block_hashes, c4w, chainId) {
100
+ const blockhashes = new Uint8Array(32 * trusted_block_hashes.length);
101
+ for (let i = 0; i < trusted_block_hashes.length; i++) {
102
+ if (trusted_block_hashes[i].length != 66 || !trusted_block_hashes[i].startsWith("0x"))
103
+ throw new Error("Invalid trustedblockhash : " + trusted_block_hashes[i]);
104
+ for (let j = 0; j < 32; j++)
105
+ blockhashes[i * 32 + j] = parseInt(trusted_block_hashes[i].slice(2 + j * 2, 4 + j * 2), 16);
106
+ }
107
+ const ptr = copy_to_c(blockhashes, c4w);
108
+ c4w._c4w_set_trusted_blockhashes(BigInt(chainId), ptr, blockhashes.length);
109
+ c4w._free(ptr);
110
+ trusted_block_hashes.length = 0;
111
+ }
99
112
  export default class C4Client {
100
113
  config;
101
114
  constructor(config) {
@@ -105,7 +118,7 @@ export default class C4Client {
105
118
  beacon_apis: ["https://lodestar-mainnet.chainsafe.io"], // Default beacon API
106
119
  rpcs: ["https://rpc.ankr.com/eth"], // Default RPC
107
120
  trusted_block_hashes: [],
108
- proofer: ["https://c4.incubed.net"],
121
+ proofer: ["https://mainnet.colibri-proof.tech"],
109
122
  }, ...config
110
123
  };
111
124
  }
@@ -169,6 +182,8 @@ export default class C4Client {
169
182
  const free_buffers = [];
170
183
  let ctx = 0;
171
184
  try {
185
+ if (this.config.trusted_block_hashes && this.config.trusted_block_hashes.length > 0)
186
+ check_trusted_blockhashes(this.config.trusted_block_hashes, c4w, this.config.chainId);
172
187
  // Call the C function
173
188
  ctx = c4w._c4w_create_verify_ctx(copy_to_c(proof, c4w, free_buffers), proof.length, as_char_ptr(method, c4w, free_buffers), as_char_ptr(JSON.stringify(args), c4w, free_buffers), BigInt(this.config.chainId));
174
189
  while (true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corpus-core/colibri-stateless",
3
- "version": "0.1.20",
3
+ "version": "0.2.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/wasm.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface C4W {
6
6
  _c4w_req_set_response: (reqPtr: number, data: number, len: number, node_index: number) => void;
7
7
  _c4w_req_set_error: (reqPtr: number, error: number, node_index: number) => void;
8
8
  _c4w_get_method_type: (chain_id: bigint, method: number) => number;
9
+ _c4w_set_trusted_blockhashes: (chain_id: bigint, blockhashes: number, len: number) => void;
9
10
  _c4w_create_verify_ctx: (proof: number, proof_len: number, method: number, args: number, chain_id: bigint) => number;
10
11
  _c4w_free_verify_ctx: (verifyCtx: number) => void;
11
12
  _c4w_verify_proof: (verifyCtx: number) => number;