@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.
- package/dist/adapters/ethers/client.cjs +75 -33
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +6 -6
- package/dist/adapters/ethers/index.cjs +122 -73
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/sdk.cjs +26 -13
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +7 -7
- package/dist/adapters/viem/client.cjs +75 -33
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.js +4 -4
- package/dist/adapters/viem/index.cjs +122 -73
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/sdk.cjs +45 -34
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-GIXLOHLK.js → chunk-3GFCAGGI.js} +1430 -7
- package/dist/{chunk-KAMEGD6I.js → chunk-5V2JRM5J.js} +1 -1
- package/dist/{chunk-EWLA4NUE.js → chunk-63DNJXS3.js} +7 -8
- package/dist/{chunk-NCR42O6O.js → chunk-C3AGOEHR.js} +11 -1
- package/dist/{chunk-NGXRO2ZX.js → chunk-FGXRG2JS.js} +4 -4
- package/dist/{chunk-VRL6Y4YJ.js → chunk-L343N56B.js} +1 -1
- package/dist/{chunk-KRIRXY74.js → chunk-LNIEQ7AN.js} +7 -8
- package/dist/{chunk-NNFWIAVG.js → chunk-NODVRI3E.js} +2 -2
- package/dist/{chunk-GNERKUWO.js → chunk-NVULC4JB.js} +2 -2
- package/dist/{chunk-7VP6742W.js → chunk-ODMBZ2VX.js} +3 -3
- package/dist/{chunk-P5PIWVEO.js → chunk-QZVYN3YA.js} +30 -7
- package/dist/{chunk-WY36Z6YB.js → chunk-SHQQI3UD.js} +57 -19
- package/dist/core/abi.d.ts +5 -0
- package/dist/core/constants.cjs +10 -0
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +10 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +1673 -184
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.js +5 -5
- package/dist/core/internal/abis/IERC7786Attributes.d.ts +42 -0
- package/dist/core/internal/abis/IInteropCenter.d.ts +211 -0
- package/dist/core/internal/abis/IInteropHandler.d.ts +166 -0
- package/dist/core/internal/abis/InteropCenter.d.ts +578 -0
- package/dist/core/internal/abis/InteropRootStorage.d.ts +20 -0
- package/dist/core/internal/abis/L2MessageVerification.d.ts +277 -0
- package/dist/core/resources/interop/attributes/bundle.d.ts +6 -0
- package/dist/core/resources/interop/attributes/call.d.ts +6 -0
- package/dist/core/resources/interop/attributes/index.d.ts +4 -0
- package/dist/core/resources/interop/attributes/resource.d.ts +12 -0
- package/dist/core/resources/interop/attributes/types.d.ts +6 -0
- package/dist/core/resources/interop/events.d.ts +7 -0
- package/dist/core/resources/interop/finalization.d.ts +61 -0
- package/dist/core/resources/interop/plan.d.ts +39 -0
- package/dist/core/resources/interop/route.d.ts +15 -0
- package/dist/core/rpc/types.d.ts +9 -0
- package/dist/core/types/errors.d.ts +43 -2
- package/dist/core/types/flows/base.d.ts +1 -1
- package/dist/core/types/flows/interop.d.ts +231 -0
- package/dist/core/types/flows/withdrawals.d.ts +0 -8
- package/dist/core/types/transactions.d.ts +10 -0
- package/dist/core/utils/addr.d.ts +2 -2
- package/dist/core/utils/events.d.ts +12 -0
- package/dist/core/utils/hash.d.ts +5 -0
- package/dist/core/utils/index.d.ts +5 -0
- package/dist/core/utils/number.d.ts +2 -0
- package/dist/index.cjs +1683 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -5
- package/package.json +6 -2
- package/dist/core/resources/withdrawals/events.d.ts +0 -9
|
@@ -11,6 +11,16 @@ function makeTransportFromEthers(provider) {
|
|
|
11
11
|
return (m, p = []) => provider.send(m, p);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// src/core/utils/number.ts
|
|
15
|
+
var isNumber = (x) => typeof x === "number" && Number.isFinite(x);
|
|
16
|
+
var isBigint = (x) => typeof x === "bigint";
|
|
17
|
+
var k256hex = (s) => `0x${utils.bytesToHex(sha3.keccak_256(utils.utf8ToBytes(s)))}`.toLowerCase();
|
|
18
|
+
var L2_ASSET_ROUTER_ADDRESS = "0x0000000000000000000000000000000000010003";
|
|
19
|
+
var L2_NATIVE_TOKEN_VAULT_ADDRESS = "0x0000000000000000000000000000000000010004";
|
|
20
|
+
var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
|
|
21
|
+
k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
22
|
+
k256hex("L1MessageSent(address,bytes32,bytes)");
|
|
23
|
+
|
|
14
24
|
// src/core/errors/formatter.ts
|
|
15
25
|
function elideMiddle(s, max = 96) {
|
|
16
26
|
if (s.length <= max) return s;
|
|
@@ -21,7 +31,7 @@ function shortJSON(v, max = 240) {
|
|
|
21
31
|
try {
|
|
22
32
|
const s = JSON.stringify(
|
|
23
33
|
v,
|
|
24
|
-
(_k, val) =>
|
|
34
|
+
(_k, val) => isBigint(val) ? `${val.toString()}n` : val
|
|
25
35
|
);
|
|
26
36
|
return s.length > max ? elideMiddle(s, max) : s;
|
|
27
37
|
} catch {
|
|
@@ -41,7 +51,7 @@ function formatContextLine(ctx) {
|
|
|
41
51
|
if (txHash !== void 0)
|
|
42
52
|
parts.push(`txHash=${typeof txHash === "string" ? txHash : shortJSON(txHash, 96)}`);
|
|
43
53
|
if (nonce !== void 0) {
|
|
44
|
-
const nonceStr = typeof nonce === "string" ||
|
|
54
|
+
const nonceStr = typeof nonce === "string" || isNumber(nonce) || isBigint(nonce) ? String(nonce) : shortJSON(nonce, 48);
|
|
45
55
|
parts.push(`nonce=${nonceStr}`);
|
|
46
56
|
}
|
|
47
57
|
return parts.length ? ` ${kv("Context", parts.join(" \u2022 "))}` : void 0;
|
|
@@ -71,17 +81,17 @@ function formatCause(c) {
|
|
|
71
81
|
const head = [];
|
|
72
82
|
if (obj.name !== void 0) {
|
|
73
83
|
const nameVal = obj.name;
|
|
74
|
-
const nameStr = typeof nameVal === "string" ||
|
|
84
|
+
const nameStr = typeof nameVal === "string" || isNumber(nameVal) || isBigint(nameVal) || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
|
|
75
85
|
head.push(`name=${nameStr}`);
|
|
76
86
|
}
|
|
77
87
|
if (obj.code !== void 0) {
|
|
78
88
|
const codeVal = obj.code;
|
|
79
|
-
const codeStr = typeof codeVal === "string" ||
|
|
89
|
+
const codeStr = typeof codeVal === "string" || isNumber(codeVal) || isBigint(codeVal) || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
|
|
80
90
|
head.push(`code=${codeStr}`);
|
|
81
91
|
}
|
|
82
92
|
if (head.length) out.push(` ${kv("Cause", head.join(" "))}`);
|
|
83
93
|
if (obj.message) {
|
|
84
|
-
const messageStr = typeof obj.message === "string" ||
|
|
94
|
+
const messageStr = typeof obj.message === "string" || isNumber(obj.message) || isBigint(obj.message) || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
|
|
85
95
|
out.push(` message=${elideMiddle(messageStr, 600)}`);
|
|
86
96
|
}
|
|
87
97
|
if (obj.data) {
|
|
@@ -160,20 +170,20 @@ function createError(type, input) {
|
|
|
160
170
|
return new ZKsyncError({ ...input, type });
|
|
161
171
|
}
|
|
162
172
|
function shapeCause(err) {
|
|
163
|
-
const
|
|
173
|
+
const isRecord2 = (x) => x !== null && typeof x === "object";
|
|
164
174
|
let data = void 0;
|
|
165
|
-
if (
|
|
175
|
+
if (isRecord2(err)) {
|
|
166
176
|
const r2 = err;
|
|
167
177
|
const d = r2.data;
|
|
168
|
-
if (
|
|
178
|
+
if (isRecord2(d) && "data" in d) {
|
|
169
179
|
data = d.data;
|
|
170
|
-
} else if ("error" in r2 &&
|
|
180
|
+
} else if ("error" in r2 && isRecord2(r2.error) && "data" in r2.error) {
|
|
171
181
|
data = r2.error.data;
|
|
172
182
|
} else if ("data" in r2) {
|
|
173
183
|
data = r2.data;
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
|
-
const r =
|
|
186
|
+
const r = isRecord2(err) ? err : void 0;
|
|
177
187
|
const name = r && typeof r.name === "string" ? r.name : void 0;
|
|
178
188
|
const message = r && typeof r.message === "string" ? r.message : r && typeof r.shortMessage === "string" ? r.shortMessage : void 0;
|
|
179
189
|
const code = r && "code" in r ? r.code : void 0;
|
|
@@ -227,7 +237,7 @@ function normalizeProof(p) {
|
|
|
227
237
|
context: { keys: Object.keys(raw ?? {}) }
|
|
228
238
|
});
|
|
229
239
|
}
|
|
230
|
-
const toBig = (x) =>
|
|
240
|
+
const toBig = (x) => isBigint(x) ? x : isNumber(x) ? BigInt(x) : typeof x === "string" ? BigInt(x) : (() => {
|
|
231
241
|
throw createError("RPC", {
|
|
232
242
|
resource: "zksrpc",
|
|
233
243
|
operation: "zksrpc.normalizeProof",
|
|
@@ -238,7 +248,8 @@ function normalizeProof(p) {
|
|
|
238
248
|
return {
|
|
239
249
|
id: toBig(idRaw),
|
|
240
250
|
batchNumber: toBig(bnRaw),
|
|
241
|
-
proof: toHexArray(raw?.proof)
|
|
251
|
+
proof: toHexArray(raw?.proof),
|
|
252
|
+
root: raw.root
|
|
242
253
|
};
|
|
243
254
|
} catch (e) {
|
|
244
255
|
if (isZKsyncError(e)) throw e;
|
|
@@ -263,8 +274,8 @@ function ensureHex(value, field, context) {
|
|
|
263
274
|
function ensureNumber(value, field, opts) {
|
|
264
275
|
const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
|
|
265
276
|
const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
|
|
266
|
-
if (
|
|
267
|
-
if (
|
|
277
|
+
if (isNumber(value)) return value;
|
|
278
|
+
if (isBigint(value)) return Number(value);
|
|
268
279
|
if (typeof value === "string" && value.trim() !== "") {
|
|
269
280
|
const parsed = Number(value);
|
|
270
281
|
if (Number.isFinite(parsed)) return parsed;
|
|
@@ -279,8 +290,8 @@ function ensureNumber(value, field, opts) {
|
|
|
279
290
|
function ensureBigInt(value, field, opts) {
|
|
280
291
|
const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
|
|
281
292
|
const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
|
|
282
|
-
if (
|
|
283
|
-
if (
|
|
293
|
+
if (isBigint(value)) return value;
|
|
294
|
+
if (isNumber(value)) {
|
|
284
295
|
if (!Number.isInteger(value)) {
|
|
285
296
|
throw createError("RPC", {
|
|
286
297
|
resource: "zksrpc",
|
|
@@ -304,6 +315,9 @@ function ensureBigInt(value, field, opts) {
|
|
|
304
315
|
context: { field, valueType: typeof value }
|
|
305
316
|
});
|
|
306
317
|
}
|
|
318
|
+
function isRecord(x) {
|
|
319
|
+
return !!x && typeof x === "object" && !Array.isArray(x);
|
|
320
|
+
}
|
|
307
321
|
function normalizeContractTuple(tuple, index) {
|
|
308
322
|
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
309
323
|
throw createError("RPC", {
|
|
@@ -319,7 +333,7 @@ function normalizeContractTuple(tuple, index) {
|
|
|
319
333
|
bytecode: ensureHex(bytecodeRaw, "initial_contracts.bytecode", { index })
|
|
320
334
|
};
|
|
321
335
|
}
|
|
322
|
-
function
|
|
336
|
+
function normalizeRawStorageTuple(tuple, index) {
|
|
323
337
|
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
324
338
|
throw createError("RPC", {
|
|
325
339
|
resource: "zksrpc",
|
|
@@ -330,10 +344,53 @@ function normalizeStorageTuple(tuple, index) {
|
|
|
330
344
|
}
|
|
331
345
|
const [keyRaw, valueRaw] = tuple;
|
|
332
346
|
return {
|
|
347
|
+
format: "raw",
|
|
333
348
|
key: ensureHex(keyRaw, "additional_storage.key", { index }),
|
|
334
349
|
value: ensureHex(valueRaw, "additional_storage.value", { index })
|
|
335
350
|
};
|
|
336
351
|
}
|
|
352
|
+
function normalizeAdditionalStorage(value, record) {
|
|
353
|
+
const effective = value ?? record["additional_storage_raw"];
|
|
354
|
+
if (Array.isArray(effective)) {
|
|
355
|
+
return effective.map((entry, index) => {
|
|
356
|
+
const kv2 = normalizeRawStorageTuple(entry, index);
|
|
357
|
+
return { format: "raw", key: kv2.key, value: kv2.value };
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (isRecord(effective)) {
|
|
361
|
+
const out = [];
|
|
362
|
+
for (const [addrRaw, slotsRaw] of Object.entries(effective)) {
|
|
363
|
+
const address = ensureHex(addrRaw, "additional_storage.address", {});
|
|
364
|
+
if (!isRecord(slotsRaw)) {
|
|
365
|
+
throw createError("RPC", {
|
|
366
|
+
resource: "zksrpc",
|
|
367
|
+
operation: "zksrpc.normalizeGenesis",
|
|
368
|
+
message: "Malformed genesis response: additional_storage[address] must be an object map.",
|
|
369
|
+
context: { address, valueType: typeof slotsRaw }
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
for (const [slotRaw, valRaw] of Object.entries(slotsRaw)) {
|
|
373
|
+
out.push({
|
|
374
|
+
format: "pretty",
|
|
375
|
+
address,
|
|
376
|
+
key: ensureHex(slotRaw, "additional_storage.key", { address }),
|
|
377
|
+
value: ensureHex(valRaw, "additional_storage.value", { address, key: slotRaw })
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return out;
|
|
382
|
+
}
|
|
383
|
+
throw createError("RPC", {
|
|
384
|
+
resource: "zksrpc",
|
|
385
|
+
operation: "zksrpc.normalizeGenesis",
|
|
386
|
+
message: "Malformed genesis response: additional_storage must be an array (raw) or an object map (pretty).",
|
|
387
|
+
context: {
|
|
388
|
+
valueType: typeof effective,
|
|
389
|
+
hasAdditionalStorage: "additional_storage" in record,
|
|
390
|
+
hasAdditionalStorageRaw: "additional_storage_raw" in record
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
337
394
|
function normalizeGenesis(raw) {
|
|
338
395
|
try {
|
|
339
396
|
if (!raw || typeof raw !== "object") {
|
|
@@ -354,21 +411,12 @@ function normalizeGenesis(raw) {
|
|
|
354
411
|
context: { valueType: typeof contractsRaw }
|
|
355
412
|
});
|
|
356
413
|
}
|
|
357
|
-
const storageRaw = record["additional_storage"];
|
|
358
|
-
if (!Array.isArray(storageRaw)) {
|
|
359
|
-
throw createError("RPC", {
|
|
360
|
-
resource: "zksrpc",
|
|
361
|
-
operation: "zksrpc.normalizeGenesis",
|
|
362
|
-
message: "Malformed genesis response: additional_storage must be an array.",
|
|
363
|
-
context: { valueType: typeof storageRaw }
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
414
|
const executionVersion = ensureNumber(record["execution_version"], "execution_version");
|
|
367
415
|
const genesisRoot = ensureHex(record["genesis_root"], "genesis_root", {});
|
|
368
416
|
const initialContracts = contractsRaw.map(
|
|
369
417
|
(entry, index) => normalizeContractTuple(entry, index)
|
|
370
418
|
);
|
|
371
|
-
const additionalStorage =
|
|
419
|
+
const additionalStorage = normalizeAdditionalStorage(record["additional_storage"], record);
|
|
372
420
|
return {
|
|
373
421
|
initialContracts,
|
|
374
422
|
additionalStorage,
|
|
@@ -553,12 +601,6 @@ function zksRpcFromEthers(l2Provider) {
|
|
|
553
601
|
}
|
|
554
602
|
return createZksRpc(makeTransportFromEthers(maybe));
|
|
555
603
|
}
|
|
556
|
-
var k256hex = (s) => `0x${utils.bytesToHex(sha3.keccak_256(utils.utf8ToBytes(s)))}`.toLowerCase();
|
|
557
|
-
var L2_ASSET_ROUTER_ADDRESS = "0x0000000000000000000000000000000000010003";
|
|
558
|
-
var L2_NATIVE_TOKEN_VAULT_ADDRESS = "0x0000000000000000000000000000000000010004";
|
|
559
|
-
var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
|
|
560
|
-
k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
561
|
-
k256hex("L1MessageSent(address,bytes32,bytes)");
|
|
562
604
|
|
|
563
605
|
// src/core/internal/abis/IBridgehub.ts
|
|
564
606
|
var IBridgehubABI = [
|