@matterlabs/zksync-js 0.0.6 → 0.0.7

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.
Files changed (46) hide show
  1. package/dist/adapters/ethers/client.cjs +170 -48
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.js +6 -6
  4. package/dist/adapters/ethers/errors/error-ops.d.ts +26 -19
  5. package/dist/adapters/ethers/index.cjs +171 -49
  6. package/dist/adapters/ethers/index.cjs.map +1 -1
  7. package/dist/adapters/ethers/index.js +9 -9
  8. package/dist/adapters/ethers/sdk.cjs +52 -46
  9. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  10. package/dist/adapters/ethers/sdk.js +7 -7
  11. package/dist/adapters/viem/client.cjs +119 -3
  12. package/dist/adapters/viem/client.cjs.map +1 -1
  13. package/dist/adapters/viem/client.js +4 -4
  14. package/dist/adapters/viem/errors/error-ops.d.ts +26 -19
  15. package/dist/adapters/viem/index.cjs +171 -49
  16. package/dist/adapters/viem/index.cjs.map +1 -1
  17. package/dist/adapters/viem/index.js +8 -8
  18. package/dist/adapters/viem/sdk.cjs +52 -46
  19. package/dist/adapters/viem/sdk.cjs.map +1 -1
  20. package/dist/adapters/viem/sdk.js +6 -6
  21. package/dist/{chunk-YUK547UF.js → chunk-7VP6742W.js} +3 -3
  22. package/dist/{chunk-WU2LOG2A.js → chunk-EWLA4NUE.js} +5 -5
  23. package/dist/{chunk-M5J2MM2U.js → chunk-GIXLOHLK.js} +1 -1
  24. package/dist/{chunk-XRE7H466.js → chunk-GNERKUWO.js} +3 -47
  25. package/dist/chunk-KAMEGD6I.js +75 -0
  26. package/dist/{chunk-2MDK3GLO.js → chunk-KRIRXY74.js} +7 -51
  27. package/dist/{chunk-F2ENUV3A.js → chunk-NCR42O6O.js} +1 -1
  28. package/dist/{chunk-3MRGU4HV.js → chunk-NGXRO2ZX.js} +4 -4
  29. package/dist/{chunk-LL3WKCFJ.js → chunk-NNFWIAVG.js} +2 -2
  30. package/dist/{chunk-NEC2ZKHI.js → chunk-P5PIWVEO.js} +1 -1
  31. package/dist/{chunk-NTEIA5KA.js → chunk-VRL6Y4YJ.js} +1 -1
  32. package/dist/{chunk-6K6VJQAL.js → chunk-WY36Z6YB.js} +122 -5
  33. package/dist/core/constants.cjs +1 -1
  34. package/dist/core/constants.d.ts +1 -1
  35. package/dist/core/constants.js +1 -1
  36. package/dist/core/errors/error-ops.d.ts +18 -0
  37. package/dist/core/index.cjs +120 -3
  38. package/dist/core/index.cjs.map +1 -1
  39. package/dist/core/index.js +5 -5
  40. package/dist/core/rpc/types.d.ts +5 -0
  41. package/dist/core/rpc/zks.d.ts +4 -1
  42. package/dist/index.cjs +121 -4
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.js +5 -5
  45. package/package.json +1 -1
  46. package/dist/chunk-NCAIVYBR.js +0 -23
@@ -1,7 +1,7 @@
1
- export { createEthersSdk } from '../../chunk-WU2LOG2A.js';
2
- import '../../chunk-XRE7H466.js';
3
- import '../../chunk-LL3WKCFJ.js';
4
- import '../../chunk-NEC2ZKHI.js';
5
- import '../../chunk-NCAIVYBR.js';
6
- import '../../chunk-M5J2MM2U.js';
7
- import '../../chunk-F2ENUV3A.js';
1
+ export { createEthersSdk } from '../../chunk-EWLA4NUE.js';
2
+ import '../../chunk-GNERKUWO.js';
3
+ import '../../chunk-NNFWIAVG.js';
4
+ import '../../chunk-P5PIWVEO.js';
5
+ import '../../chunk-KAMEGD6I.js';
6
+ import '../../chunk-GIXLOHLK.js';
7
+ import '../../chunk-NCR42O6O.js';
@@ -198,6 +198,8 @@ var METHODS = {
198
198
  getBridgehub: "zks_getBridgehubContract",
199
199
  getL2ToL1LogProof: "zks_getL2ToL1LogProof",
200
200
  getReceipt: "eth_getTransactionReceipt",
201
+ getBytecodeSupplier: "zks_getBytecodeSupplierContract",
202
+ getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
201
203
  getGenesis: "zks_getGenesis"
202
204
  };
203
205
  function toHexArray(arr) {
@@ -250,7 +252,9 @@ function ensureHex(value, field, context) {
250
252
  context: { field, valueType: typeof value, ...context }
251
253
  });
252
254
  }
253
- function ensureNumber(value, field) {
255
+ function ensureNumber(value, field, opts) {
256
+ const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
257
+ const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
254
258
  if (typeof value === "number" && Number.isFinite(value)) return value;
255
259
  if (typeof value === "bigint") return Number(value);
256
260
  if (typeof value === "string" && value.trim() !== "") {
@@ -259,8 +263,36 @@ function ensureNumber(value, field) {
259
263
  }
260
264
  throw createError("RPC", {
261
265
  resource: "zksrpc",
262
- operation: "zksrpc.normalizeGenesis",
263
- message: "Malformed genesis response: expected numeric value.",
266
+ operation,
267
+ message: `${messagePrefix}: expected numeric value.`,
268
+ context: { field, valueType: typeof value }
269
+ });
270
+ }
271
+ function ensureBigInt(value, field, opts) {
272
+ const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
273
+ const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
274
+ if (typeof value === "bigint") return value;
275
+ if (typeof value === "number" && Number.isFinite(value)) {
276
+ if (!Number.isInteger(value)) {
277
+ throw createError("RPC", {
278
+ resource: "zksrpc",
279
+ operation,
280
+ message: `${messagePrefix}: expected integer value.`,
281
+ context: { field, valueType: typeof value }
282
+ });
283
+ }
284
+ return BigInt(value);
285
+ }
286
+ if (typeof value === "string" && value.trim() !== "") {
287
+ try {
288
+ return BigInt(value);
289
+ } catch {
290
+ }
291
+ }
292
+ throw createError("RPC", {
293
+ resource: "zksrpc",
294
+ operation,
295
+ message: `${messagePrefix}: expected bigint-compatible value.`,
264
296
  context: { field, valueType: typeof value }
265
297
  });
266
298
  }
@@ -346,6 +378,57 @@ function normalizeGenesis(raw) {
346
378
  });
347
379
  }
348
380
  }
381
+ function normalizeBlockMetadata(raw) {
382
+ try {
383
+ if (!raw || typeof raw !== "object") {
384
+ throw createError("RPC", {
385
+ resource: "zksrpc",
386
+ operation: "zksrpc.normalizeBlockMetadata",
387
+ message: "Malformed block metadata response: expected object.",
388
+ context: { receivedType: typeof raw }
389
+ });
390
+ }
391
+ const record = raw;
392
+ const pubdataPricePerByte = ensureBigInt(
393
+ record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
394
+ "pubdata_price_per_byte",
395
+ {
396
+ operation: "zksrpc.normalizeBlockMetadata",
397
+ messagePrefix: "Malformed block metadata response"
398
+ }
399
+ );
400
+ const nativePrice = ensureBigInt(
401
+ record["native_price"] ?? record["nativePrice"],
402
+ "native_price",
403
+ {
404
+ operation: "zksrpc.normalizeBlockMetadata",
405
+ messagePrefix: "Malformed block metadata response"
406
+ }
407
+ );
408
+ const executionVersion = ensureNumber(
409
+ record["execution_version"] ?? record["executionVersion"],
410
+ "execution_version",
411
+ {
412
+ operation: "zksrpc.normalizeBlockMetadata",
413
+ messagePrefix: "Malformed block metadata response"
414
+ }
415
+ );
416
+ return {
417
+ pubdataPricePerByte,
418
+ nativePrice,
419
+ executionVersion
420
+ };
421
+ } catch (e) {
422
+ if (isZKsyncError(e)) throw e;
423
+ throw createError("RPC", {
424
+ resource: "zksrpc",
425
+ operation: "zksrpc.normalizeBlockMetadata",
426
+ message: "Failed to normalize block metadata response.",
427
+ context: { receivedType: typeof raw },
428
+ cause: shapeCause(e)
429
+ });
430
+ }
431
+ }
349
432
  function createZksRpc(transport) {
350
433
  return {
351
434
  // Fetches the Bridgehub contract address.
@@ -368,6 +451,26 @@ function createZksRpc(transport) {
368
451
  }
369
452
  );
370
453
  },
454
+ // Fetches the Bytecode Supplier contract address.
455
+ async getBytecodeSupplierAddress() {
456
+ return withRpcOp(
457
+ "zksrpc.getBytecodeSupplierAddress",
458
+ "Failed to fetch Bytecode Supplier address.",
459
+ {},
460
+ async () => {
461
+ const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
462
+ if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
463
+ throw createError("RPC", {
464
+ resource: "zksrpc",
465
+ operation: "zksrpc.getBytecodeSupplierAddress",
466
+ message: "Unexpected Bytecode Supplier address response.",
467
+ context: { valueType: typeof addrRaw }
468
+ });
469
+ }
470
+ return addrRaw;
471
+ }
472
+ );
473
+ },
371
474
  // Fetches a proof for an L2→L1 log emitted in the given transaction.
372
475
  async getL2ToL1LogProof(txHash, index) {
373
476
  return withRpcOp(
@@ -404,6 +507,19 @@ function createZksRpc(transport) {
404
507
  }
405
508
  );
406
509
  },
510
+ // Fetches block metadata for the given block number.
511
+ async getBlockMetadataByNumber(blockNumber) {
512
+ return withRpcOp(
513
+ "zksrpc.getBlockMetadataByNumber",
514
+ "Failed to fetch block metadata.",
515
+ { blockNumber },
516
+ async () => {
517
+ const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
518
+ if (raw == null) return null;
519
+ return normalizeBlockMetadata(raw);
520
+ }
521
+ );
522
+ },
407
523
  // Fetches the genesis configuration returned by `zks_getGenesis`.
408
524
  async getGenesis() {
409
525
  return withRpcOp(