@matterlabs/zksync-js 0.0.7 → 0.0.8

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 (71) hide show
  1. package/dist/adapters/ethers/client.cjs +75 -33
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.js +6 -6
  4. package/dist/adapters/ethers/index.cjs +122 -73
  5. package/dist/adapters/ethers/index.cjs.map +1 -1
  6. package/dist/adapters/ethers/index.js +9 -9
  7. package/dist/adapters/ethers/sdk.cjs +26 -13
  8. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  9. package/dist/adapters/ethers/sdk.js +7 -7
  10. package/dist/adapters/viem/client.cjs +75 -33
  11. package/dist/adapters/viem/client.cjs.map +1 -1
  12. package/dist/adapters/viem/client.js +4 -4
  13. package/dist/adapters/viem/index.cjs +122 -73
  14. package/dist/adapters/viem/index.cjs.map +1 -1
  15. package/dist/adapters/viem/index.js +8 -8
  16. package/dist/adapters/viem/sdk.cjs +45 -34
  17. package/dist/adapters/viem/sdk.cjs.map +1 -1
  18. package/dist/adapters/viem/sdk.js +6 -6
  19. package/dist/{chunk-GIXLOHLK.js → chunk-3GFCAGGI.js} +1430 -7
  20. package/dist/{chunk-KAMEGD6I.js → chunk-5V2JRM5J.js} +1 -1
  21. package/dist/{chunk-EWLA4NUE.js → chunk-63DNJXS3.js} +7 -8
  22. package/dist/{chunk-NCR42O6O.js → chunk-C3AGOEHR.js} +11 -1
  23. package/dist/{chunk-NGXRO2ZX.js → chunk-FGXRG2JS.js} +4 -4
  24. package/dist/{chunk-VRL6Y4YJ.js → chunk-L343N56B.js} +1 -1
  25. package/dist/{chunk-KRIRXY74.js → chunk-LNIEQ7AN.js} +7 -8
  26. package/dist/{chunk-NNFWIAVG.js → chunk-NODVRI3E.js} +2 -2
  27. package/dist/{chunk-GNERKUWO.js → chunk-NVULC4JB.js} +2 -2
  28. package/dist/{chunk-7VP6742W.js → chunk-ODMBZ2VX.js} +3 -3
  29. package/dist/{chunk-P5PIWVEO.js → chunk-QZVYN3YA.js} +30 -7
  30. package/dist/{chunk-WY36Z6YB.js → chunk-SHQQI3UD.js} +57 -19
  31. package/dist/core/abi.d.ts +5 -0
  32. package/dist/core/constants.cjs +10 -0
  33. package/dist/core/constants.cjs.map +1 -1
  34. package/dist/core/constants.d.ts +10 -0
  35. package/dist/core/constants.js +1 -1
  36. package/dist/core/index.cjs +1673 -184
  37. package/dist/core/index.cjs.map +1 -1
  38. package/dist/core/index.d.ts +2 -1
  39. package/dist/core/index.js +5 -5
  40. package/dist/core/internal/abis/IERC7786Attributes.d.ts +42 -0
  41. package/dist/core/internal/abis/IInteropCenter.d.ts +211 -0
  42. package/dist/core/internal/abis/IInteropHandler.d.ts +166 -0
  43. package/dist/core/internal/abis/InteropCenter.d.ts +578 -0
  44. package/dist/core/internal/abis/InteropRootStorage.d.ts +20 -0
  45. package/dist/core/internal/abis/L2MessageVerification.d.ts +277 -0
  46. package/dist/core/resources/interop/attributes/bundle.d.ts +6 -0
  47. package/dist/core/resources/interop/attributes/call.d.ts +6 -0
  48. package/dist/core/resources/interop/attributes/index.d.ts +4 -0
  49. package/dist/core/resources/interop/attributes/resource.d.ts +12 -0
  50. package/dist/core/resources/interop/attributes/types.d.ts +6 -0
  51. package/dist/core/resources/interop/events.d.ts +7 -0
  52. package/dist/core/resources/interop/finalization.d.ts +61 -0
  53. package/dist/core/resources/interop/plan.d.ts +39 -0
  54. package/dist/core/resources/interop/route.d.ts +15 -0
  55. package/dist/core/rpc/types.d.ts +9 -0
  56. package/dist/core/types/errors.d.ts +43 -2
  57. package/dist/core/types/flows/base.d.ts +1 -1
  58. package/dist/core/types/flows/interop.d.ts +231 -0
  59. package/dist/core/types/flows/withdrawals.d.ts +0 -8
  60. package/dist/core/types/transactions.d.ts +10 -0
  61. package/dist/core/utils/addr.d.ts +2 -2
  62. package/dist/core/utils/events.d.ts +12 -0
  63. package/dist/core/utils/hash.d.ts +5 -0
  64. package/dist/core/utils/index.d.ts +5 -0
  65. package/dist/core/utils/number.d.ts +2 -0
  66. package/dist/index.cjs +1683 -184
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.ts +2 -1
  69. package/dist/index.js +5 -5
  70. package/package.json +6 -2
  71. package/dist/core/resources/withdrawals/events.d.ts +0 -9
@@ -1,7 +1,7 @@
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';
1
+ export { createEthersSdk } from '../../chunk-63DNJXS3.js';
2
+ import '../../chunk-NVULC4JB.js';
3
+ import '../../chunk-NODVRI3E.js';
4
+ import '../../chunk-QZVYN3YA.js';
5
+ import '../../chunk-5V2JRM5J.js';
6
+ import '../../chunk-3GFCAGGI.js';
7
+ import '../../chunk-C3AGOEHR.js';
@@ -6,6 +6,16 @@ var utils = require('@noble/hashes/utils');
6
6
 
7
7
  // src/adapters/viem/client.ts
8
8
 
9
+ // src/core/utils/number.ts
10
+ var isNumber = (x) => typeof x === "number" && Number.isFinite(x);
11
+ var isBigint = (x) => typeof x === "bigint";
12
+ var k256hex = (s) => `0x${utils.bytesToHex(sha3.keccak_256(utils.utf8ToBytes(s)))}`.toLowerCase();
13
+ var L2_ASSET_ROUTER_ADDRESS = "0x0000000000000000000000000000000000010003";
14
+ var L2_NATIVE_TOKEN_VAULT_ADDRESS = "0x0000000000000000000000000000000000010004";
15
+ var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
16
+ k256hex("L1MessageSent(uint256,bytes32,bytes)");
17
+ k256hex("L1MessageSent(address,bytes32,bytes)");
18
+
9
19
  // src/core/errors/formatter.ts
10
20
  function elideMiddle(s, max = 96) {
11
21
  if (s.length <= max) return s;
@@ -16,7 +26,7 @@ function shortJSON(v, max = 240) {
16
26
  try {
17
27
  const s = JSON.stringify(
18
28
  v,
19
- (_k, val) => typeof val === "bigint" ? `${val.toString()}n` : val
29
+ (_k, val) => isBigint(val) ? `${val.toString()}n` : val
20
30
  );
21
31
  return s.length > max ? elideMiddle(s, max) : s;
22
32
  } catch {
@@ -36,7 +46,7 @@ function formatContextLine(ctx) {
36
46
  if (txHash !== void 0)
37
47
  parts.push(`txHash=${typeof txHash === "string" ? txHash : shortJSON(txHash, 96)}`);
38
48
  if (nonce !== void 0) {
39
- const nonceStr = typeof nonce === "string" || typeof nonce === "number" || typeof nonce === "bigint" ? String(nonce) : shortJSON(nonce, 48);
49
+ const nonceStr = typeof nonce === "string" || isNumber(nonce) || isBigint(nonce) ? String(nonce) : shortJSON(nonce, 48);
40
50
  parts.push(`nonce=${nonceStr}`);
41
51
  }
42
52
  return parts.length ? ` ${kv("Context", parts.join(" \u2022 "))}` : void 0;
@@ -66,17 +76,17 @@ function formatCause(c) {
66
76
  const head = [];
67
77
  if (obj.name !== void 0) {
68
78
  const nameVal = obj.name;
69
- const nameStr = typeof nameVal === "string" || typeof nameVal === "number" || typeof nameVal === "bigint" || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
79
+ const nameStr = typeof nameVal === "string" || isNumber(nameVal) || isBigint(nameVal) || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
70
80
  head.push(`name=${nameStr}`);
71
81
  }
72
82
  if (obj.code !== void 0) {
73
83
  const codeVal = obj.code;
74
- const codeStr = typeof codeVal === "string" || typeof codeVal === "number" || typeof codeVal === "bigint" || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
84
+ const codeStr = typeof codeVal === "string" || isNumber(codeVal) || isBigint(codeVal) || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
75
85
  head.push(`code=${codeStr}`);
76
86
  }
77
87
  if (head.length) out.push(` ${kv("Cause", head.join(" "))}`);
78
88
  if (obj.message) {
79
- const messageStr = typeof obj.message === "string" || typeof obj.message === "number" || typeof obj.message === "bigint" || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
89
+ const messageStr = typeof obj.message === "string" || isNumber(obj.message) || isBigint(obj.message) || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
80
90
  out.push(` message=${elideMiddle(messageStr, 600)}`);
81
91
  }
82
92
  if (obj.data) {
@@ -152,20 +162,20 @@ function createError(type, input) {
152
162
  return new ZKsyncError({ ...input, type });
153
163
  }
154
164
  function shapeCause(err) {
155
- const isRecord = (x) => x !== null && typeof x === "object";
165
+ const isRecord2 = (x) => x !== null && typeof x === "object";
156
166
  let data = void 0;
157
- if (isRecord(err)) {
167
+ if (isRecord2(err)) {
158
168
  const r2 = err;
159
169
  const d = r2.data;
160
- if (isRecord(d) && "data" in d) {
170
+ if (isRecord2(d) && "data" in d) {
161
171
  data = d.data;
162
- } else if ("error" in r2 && isRecord(r2.error) && "data" in r2.error) {
172
+ } else if ("error" in r2 && isRecord2(r2.error) && "data" in r2.error) {
163
173
  data = r2.error.data;
164
174
  } else if ("data" in r2) {
165
175
  data = r2.data;
166
176
  }
167
177
  }
168
- const r = isRecord(err) ? err : void 0;
178
+ const r = isRecord2(err) ? err : void 0;
169
179
  const name = r && typeof r.name === "string" ? r.name : void 0;
170
180
  const message = r && typeof r.message === "string" ? r.message : r && typeof r.shortMessage === "string" ? r.shortMessage : void 0;
171
181
  const code = r && "code" in r ? r.code : void 0;
@@ -219,7 +229,7 @@ function normalizeProof(p) {
219
229
  context: { keys: Object.keys(raw ?? {}) }
220
230
  });
221
231
  }
222
- const toBig = (x) => typeof x === "bigint" ? x : typeof x === "number" ? BigInt(x) : typeof x === "string" ? BigInt(x) : (() => {
232
+ const toBig = (x) => isBigint(x) ? x : isNumber(x) ? BigInt(x) : typeof x === "string" ? BigInt(x) : (() => {
223
233
  throw createError("RPC", {
224
234
  resource: "zksrpc",
225
235
  operation: "zksrpc.normalizeProof",
@@ -230,7 +240,8 @@ function normalizeProof(p) {
230
240
  return {
231
241
  id: toBig(idRaw),
232
242
  batchNumber: toBig(bnRaw),
233
- proof: toHexArray(raw?.proof)
243
+ proof: toHexArray(raw?.proof),
244
+ root: raw.root
234
245
  };
235
246
  } catch (e) {
236
247
  if (isZKsyncError(e)) throw e;
@@ -255,8 +266,8 @@ function ensureHex(value, field, context) {
255
266
  function ensureNumber(value, field, opts) {
256
267
  const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
257
268
  const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
258
- if (typeof value === "number" && Number.isFinite(value)) return value;
259
- if (typeof value === "bigint") return Number(value);
269
+ if (isNumber(value)) return value;
270
+ if (isBigint(value)) return Number(value);
260
271
  if (typeof value === "string" && value.trim() !== "") {
261
272
  const parsed = Number(value);
262
273
  if (Number.isFinite(parsed)) return parsed;
@@ -271,8 +282,8 @@ function ensureNumber(value, field, opts) {
271
282
  function ensureBigInt(value, field, opts) {
272
283
  const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
273
284
  const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
274
- if (typeof value === "bigint") return value;
275
- if (typeof value === "number" && Number.isFinite(value)) {
285
+ if (isBigint(value)) return value;
286
+ if (isNumber(value)) {
276
287
  if (!Number.isInteger(value)) {
277
288
  throw createError("RPC", {
278
289
  resource: "zksrpc",
@@ -296,6 +307,9 @@ function ensureBigInt(value, field, opts) {
296
307
  context: { field, valueType: typeof value }
297
308
  });
298
309
  }
310
+ function isRecord(x) {
311
+ return !!x && typeof x === "object" && !Array.isArray(x);
312
+ }
299
313
  function normalizeContractTuple(tuple, index) {
300
314
  if (!Array.isArray(tuple) || tuple.length < 2) {
301
315
  throw createError("RPC", {
@@ -311,7 +325,7 @@ function normalizeContractTuple(tuple, index) {
311
325
  bytecode: ensureHex(bytecodeRaw, "initial_contracts.bytecode", { index })
312
326
  };
313
327
  }
314
- function normalizeStorageTuple(tuple, index) {
328
+ function normalizeRawStorageTuple(tuple, index) {
315
329
  if (!Array.isArray(tuple) || tuple.length < 2) {
316
330
  throw createError("RPC", {
317
331
  resource: "zksrpc",
@@ -322,10 +336,53 @@ function normalizeStorageTuple(tuple, index) {
322
336
  }
323
337
  const [keyRaw, valueRaw] = tuple;
324
338
  return {
339
+ format: "raw",
325
340
  key: ensureHex(keyRaw, "additional_storage.key", { index }),
326
341
  value: ensureHex(valueRaw, "additional_storage.value", { index })
327
342
  };
328
343
  }
344
+ function normalizeAdditionalStorage(value, record) {
345
+ const effective = value ?? record["additional_storage_raw"];
346
+ if (Array.isArray(effective)) {
347
+ return effective.map((entry, index) => {
348
+ const kv2 = normalizeRawStorageTuple(entry, index);
349
+ return { format: "raw", key: kv2.key, value: kv2.value };
350
+ });
351
+ }
352
+ if (isRecord(effective)) {
353
+ const out = [];
354
+ for (const [addrRaw, slotsRaw] of Object.entries(effective)) {
355
+ const address = ensureHex(addrRaw, "additional_storage.address", {});
356
+ if (!isRecord(slotsRaw)) {
357
+ throw createError("RPC", {
358
+ resource: "zksrpc",
359
+ operation: "zksrpc.normalizeGenesis",
360
+ message: "Malformed genesis response: additional_storage[address] must be an object map.",
361
+ context: { address, valueType: typeof slotsRaw }
362
+ });
363
+ }
364
+ for (const [slotRaw, valRaw] of Object.entries(slotsRaw)) {
365
+ out.push({
366
+ format: "pretty",
367
+ address,
368
+ key: ensureHex(slotRaw, "additional_storage.key", { address }),
369
+ value: ensureHex(valRaw, "additional_storage.value", { address, key: slotRaw })
370
+ });
371
+ }
372
+ }
373
+ return out;
374
+ }
375
+ throw createError("RPC", {
376
+ resource: "zksrpc",
377
+ operation: "zksrpc.normalizeGenesis",
378
+ message: "Malformed genesis response: additional_storage must be an array (raw) or an object map (pretty).",
379
+ context: {
380
+ valueType: typeof effective,
381
+ hasAdditionalStorage: "additional_storage" in record,
382
+ hasAdditionalStorageRaw: "additional_storage_raw" in record
383
+ }
384
+ });
385
+ }
329
386
  function normalizeGenesis(raw) {
330
387
  try {
331
388
  if (!raw || typeof raw !== "object") {
@@ -346,21 +403,12 @@ function normalizeGenesis(raw) {
346
403
  context: { valueType: typeof contractsRaw }
347
404
  });
348
405
  }
349
- const storageRaw = record["additional_storage"];
350
- if (!Array.isArray(storageRaw)) {
351
- throw createError("RPC", {
352
- resource: "zksrpc",
353
- operation: "zksrpc.normalizeGenesis",
354
- message: "Malformed genesis response: additional_storage must be an array.",
355
- context: { valueType: typeof storageRaw }
356
- });
357
- }
358
406
  const executionVersion = ensureNumber(record["execution_version"], "execution_version");
359
407
  const genesisRoot = ensureHex(record["genesis_root"], "genesis_root", {});
360
408
  const initialContracts = contractsRaw.map(
361
409
  (entry, index) => normalizeContractTuple(entry, index)
362
410
  );
363
- const additionalStorage = storageRaw.map((entry, index) => normalizeStorageTuple(entry, index));
411
+ const additionalStorage = normalizeAdditionalStorage(record["additional_storage"], record);
364
412
  return {
365
413
  initialContracts,
366
414
  additionalStorage,
@@ -547,12 +595,6 @@ function zksRpcFromViem(l2Client) {
547
595
  };
548
596
  return createZksRpc(makeTransportFromViem(compatible));
549
597
  }
550
- var k256hex = (s) => `0x${utils.bytesToHex(sha3.keccak_256(utils.utf8ToBytes(s)))}`.toLowerCase();
551
- var L2_ASSET_ROUTER_ADDRESS = "0x0000000000000000000000000000000000010003";
552
- var L2_NATIVE_TOKEN_VAULT_ADDRESS = "0x0000000000000000000000000000000000010004";
553
- var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
554
- k256hex("L1MessageSent(uint256,bytes32,bytes)");
555
- k256hex("L1MessageSent(address,bytes32,bytes)");
556
598
 
557
599
  // src/core/internal/abis/IBridgehub.ts
558
600
  var IBridgehubABI = [