@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.
- package/dist/adapters/ethers/client.cjs +170 -48
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +6 -6
- package/dist/adapters/ethers/errors/error-ops.d.ts +26 -19
- package/dist/adapters/ethers/index.cjs +171 -49
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/sdk.cjs +52 -46
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +7 -7
- package/dist/adapters/viem/client.cjs +119 -3
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.js +4 -4
- package/dist/adapters/viem/errors/error-ops.d.ts +26 -19
- package/dist/adapters/viem/index.cjs +171 -49
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/sdk.cjs +52 -46
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-YUK547UF.js → chunk-7VP6742W.js} +3 -3
- package/dist/{chunk-WU2LOG2A.js → chunk-EWLA4NUE.js} +5 -5
- package/dist/{chunk-M5J2MM2U.js → chunk-GIXLOHLK.js} +1 -1
- package/dist/{chunk-XRE7H466.js → chunk-GNERKUWO.js} +3 -47
- package/dist/chunk-KAMEGD6I.js +75 -0
- package/dist/{chunk-2MDK3GLO.js → chunk-KRIRXY74.js} +7 -51
- package/dist/{chunk-F2ENUV3A.js → chunk-NCR42O6O.js} +1 -1
- package/dist/{chunk-3MRGU4HV.js → chunk-NGXRO2ZX.js} +4 -4
- package/dist/{chunk-LL3WKCFJ.js → chunk-NNFWIAVG.js} +2 -2
- package/dist/{chunk-NEC2ZKHI.js → chunk-P5PIWVEO.js} +1 -1
- package/dist/{chunk-NTEIA5KA.js → chunk-VRL6Y4YJ.js} +1 -1
- package/dist/{chunk-6K6VJQAL.js → chunk-WY36Z6YB.js} +122 -5
- package/dist/core/constants.cjs +1 -1
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/errors/error-ops.d.ts +18 -0
- package/dist/core/index.cjs +120 -3
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +5 -5
- package/dist/core/rpc/types.d.ts +5 -0
- package/dist/core/rpc/zks.d.ts +4 -1
- package/dist/index.cjs +121 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-NCAIVYBR.js +0 -23
|
@@ -206,6 +206,8 @@ var METHODS = {
|
|
|
206
206
|
getBridgehub: "zks_getBridgehubContract",
|
|
207
207
|
getL2ToL1LogProof: "zks_getL2ToL1LogProof",
|
|
208
208
|
getReceipt: "eth_getTransactionReceipt",
|
|
209
|
+
getBytecodeSupplier: "zks_getBytecodeSupplierContract",
|
|
210
|
+
getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
|
|
209
211
|
getGenesis: "zks_getGenesis"
|
|
210
212
|
};
|
|
211
213
|
function toHexArray(arr) {
|
|
@@ -258,7 +260,9 @@ function ensureHex(value, field, context) {
|
|
|
258
260
|
context: { field, valueType: typeof value, ...context }
|
|
259
261
|
});
|
|
260
262
|
}
|
|
261
|
-
function ensureNumber(value, field) {
|
|
263
|
+
function ensureNumber(value, field, opts) {
|
|
264
|
+
const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
|
|
265
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
|
|
262
266
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
263
267
|
if (typeof value === "bigint") return Number(value);
|
|
264
268
|
if (typeof value === "string" && value.trim() !== "") {
|
|
@@ -267,8 +271,36 @@ function ensureNumber(value, field) {
|
|
|
267
271
|
}
|
|
268
272
|
throw createError("RPC", {
|
|
269
273
|
resource: "zksrpc",
|
|
270
|
-
operation
|
|
271
|
-
message:
|
|
274
|
+
operation,
|
|
275
|
+
message: `${messagePrefix}: expected numeric value.`,
|
|
276
|
+
context: { field, valueType: typeof value }
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function ensureBigInt(value, field, opts) {
|
|
280
|
+
const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
|
|
281
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
|
|
282
|
+
if (typeof value === "bigint") return value;
|
|
283
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
284
|
+
if (!Number.isInteger(value)) {
|
|
285
|
+
throw createError("RPC", {
|
|
286
|
+
resource: "zksrpc",
|
|
287
|
+
operation,
|
|
288
|
+
message: `${messagePrefix}: expected integer value.`,
|
|
289
|
+
context: { field, valueType: typeof value }
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return BigInt(value);
|
|
293
|
+
}
|
|
294
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
295
|
+
try {
|
|
296
|
+
return BigInt(value);
|
|
297
|
+
} catch {
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
throw createError("RPC", {
|
|
301
|
+
resource: "zksrpc",
|
|
302
|
+
operation,
|
|
303
|
+
message: `${messagePrefix}: expected bigint-compatible value.`,
|
|
272
304
|
context: { field, valueType: typeof value }
|
|
273
305
|
});
|
|
274
306
|
}
|
|
@@ -354,6 +386,57 @@ function normalizeGenesis(raw) {
|
|
|
354
386
|
});
|
|
355
387
|
}
|
|
356
388
|
}
|
|
389
|
+
function normalizeBlockMetadata(raw) {
|
|
390
|
+
try {
|
|
391
|
+
if (!raw || typeof raw !== "object") {
|
|
392
|
+
throw createError("RPC", {
|
|
393
|
+
resource: "zksrpc",
|
|
394
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
395
|
+
message: "Malformed block metadata response: expected object.",
|
|
396
|
+
context: { receivedType: typeof raw }
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
const record = raw;
|
|
400
|
+
const pubdataPricePerByte = ensureBigInt(
|
|
401
|
+
record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
|
|
402
|
+
"pubdata_price_per_byte",
|
|
403
|
+
{
|
|
404
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
405
|
+
messagePrefix: "Malformed block metadata response"
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
const nativePrice = ensureBigInt(
|
|
409
|
+
record["native_price"] ?? record["nativePrice"],
|
|
410
|
+
"native_price",
|
|
411
|
+
{
|
|
412
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
413
|
+
messagePrefix: "Malformed block metadata response"
|
|
414
|
+
}
|
|
415
|
+
);
|
|
416
|
+
const executionVersion = ensureNumber(
|
|
417
|
+
record["execution_version"] ?? record["executionVersion"],
|
|
418
|
+
"execution_version",
|
|
419
|
+
{
|
|
420
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
421
|
+
messagePrefix: "Malformed block metadata response"
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
return {
|
|
425
|
+
pubdataPricePerByte,
|
|
426
|
+
nativePrice,
|
|
427
|
+
executionVersion
|
|
428
|
+
};
|
|
429
|
+
} catch (e) {
|
|
430
|
+
if (isZKsyncError(e)) throw e;
|
|
431
|
+
throw createError("RPC", {
|
|
432
|
+
resource: "zksrpc",
|
|
433
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
434
|
+
message: "Failed to normalize block metadata response.",
|
|
435
|
+
context: { receivedType: typeof raw },
|
|
436
|
+
cause: shapeCause(e)
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
357
440
|
function createZksRpc(transport) {
|
|
358
441
|
return {
|
|
359
442
|
// Fetches the Bridgehub contract address.
|
|
@@ -376,6 +459,26 @@ function createZksRpc(transport) {
|
|
|
376
459
|
}
|
|
377
460
|
);
|
|
378
461
|
},
|
|
462
|
+
// Fetches the Bytecode Supplier contract address.
|
|
463
|
+
async getBytecodeSupplierAddress() {
|
|
464
|
+
return withRpcOp(
|
|
465
|
+
"zksrpc.getBytecodeSupplierAddress",
|
|
466
|
+
"Failed to fetch Bytecode Supplier address.",
|
|
467
|
+
{},
|
|
468
|
+
async () => {
|
|
469
|
+
const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
|
|
470
|
+
if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
|
|
471
|
+
throw createError("RPC", {
|
|
472
|
+
resource: "zksrpc",
|
|
473
|
+
operation: "zksrpc.getBytecodeSupplierAddress",
|
|
474
|
+
message: "Unexpected Bytecode Supplier address response.",
|
|
475
|
+
context: { valueType: typeof addrRaw }
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return addrRaw;
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
},
|
|
379
482
|
// Fetches a proof for an L2→L1 log emitted in the given transaction.
|
|
380
483
|
async getL2ToL1LogProof(txHash, index) {
|
|
381
484
|
return withRpcOp(
|
|
@@ -412,6 +515,19 @@ function createZksRpc(transport) {
|
|
|
412
515
|
}
|
|
413
516
|
);
|
|
414
517
|
},
|
|
518
|
+
// Fetches block metadata for the given block number.
|
|
519
|
+
async getBlockMetadataByNumber(blockNumber) {
|
|
520
|
+
return withRpcOp(
|
|
521
|
+
"zksrpc.getBlockMetadataByNumber",
|
|
522
|
+
"Failed to fetch block metadata.",
|
|
523
|
+
{ blockNumber },
|
|
524
|
+
async () => {
|
|
525
|
+
const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
|
|
526
|
+
if (raw == null) return null;
|
|
527
|
+
return normalizeBlockMetadata(raw);
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
},
|
|
415
531
|
// Fetches the genesis configuration returned by `zks_getGenesis`.
|
|
416
532
|
async getGenesis() {
|
|
417
533
|
return withRpcOp(
|
|
@@ -4931,6 +5047,56 @@ var MailboxABI = [
|
|
|
4931
5047
|
{ type: "error", name: "ZeroGasPriceL1TxZKSyncOS", inputs: [] }
|
|
4932
5048
|
];
|
|
4933
5049
|
var Mailbox_default = MailboxABI;
|
|
5050
|
+
|
|
5051
|
+
// src/core/errors/error-ops.ts
|
|
5052
|
+
function resolveMessage(op, msg) {
|
|
5053
|
+
if (!msg) return `Error during ${op}.`;
|
|
5054
|
+
return typeof msg === "function" ? msg() : msg;
|
|
5055
|
+
}
|
|
5056
|
+
function createErrorOps(decodeRevert2) {
|
|
5057
|
+
function toZKsyncError2(type, base, err) {
|
|
5058
|
+
if (isZKsyncError(err)) return err;
|
|
5059
|
+
const revert = decodeRevert2 ? decodeRevert2(err) : void 0;
|
|
5060
|
+
return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
|
|
5061
|
+
}
|
|
5062
|
+
function createErrorHandlers2(resource) {
|
|
5063
|
+
async function run(kind, operation, fn, opts) {
|
|
5064
|
+
try {
|
|
5065
|
+
return await fn();
|
|
5066
|
+
} catch (e) {
|
|
5067
|
+
if (isZKsyncError(e)) throw e;
|
|
5068
|
+
const message = resolveMessage(operation, opts?.message);
|
|
5069
|
+
throw toZKsyncError2(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
5070
|
+
}
|
|
5071
|
+
}
|
|
5072
|
+
function wrap(operation, fn, opts) {
|
|
5073
|
+
return run("INTERNAL", operation, fn, opts);
|
|
5074
|
+
}
|
|
5075
|
+
function wrapAs2(kind, operation, fn, opts) {
|
|
5076
|
+
return run(kind, operation, fn, opts);
|
|
5077
|
+
}
|
|
5078
|
+
async function toResult(operation, fn, opts) {
|
|
5079
|
+
try {
|
|
5080
|
+
const value = await wrap(operation, fn, opts);
|
|
5081
|
+
return { ok: true, value };
|
|
5082
|
+
} catch (e) {
|
|
5083
|
+
const shaped = isZKsyncError(e) ? e : toZKsyncError2(
|
|
5084
|
+
"INTERNAL",
|
|
5085
|
+
{
|
|
5086
|
+
resource,
|
|
5087
|
+
operation,
|
|
5088
|
+
context: opts?.ctx ?? {},
|
|
5089
|
+
message: resolveMessage(operation, opts?.message)
|
|
5090
|
+
},
|
|
5091
|
+
e
|
|
5092
|
+
);
|
|
5093
|
+
return { ok: false, error: shaped };
|
|
5094
|
+
}
|
|
5095
|
+
}
|
|
5096
|
+
return { wrap, wrapAs: wrapAs2, toResult };
|
|
5097
|
+
}
|
|
5098
|
+
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
5099
|
+
}
|
|
4934
5100
|
var ERROR_IFACES = [];
|
|
4935
5101
|
var IFACE_ERROR_STRING = new ethers.Interface(["error Error(string)"]);
|
|
4936
5102
|
var IFACE_PANIC = new ethers.Interface(["error Panic(uint256)"]);
|
|
@@ -5014,51 +5180,7 @@ function decodeRevert(e) {
|
|
|
5014
5180
|
}
|
|
5015
5181
|
|
|
5016
5182
|
// src/adapters/ethers/errors/error-ops.ts
|
|
5017
|
-
|
|
5018
|
-
if (isZKsyncError(err)) return err;
|
|
5019
|
-
const revert = decodeRevert(err);
|
|
5020
|
-
return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
|
|
5021
|
-
}
|
|
5022
|
-
function resolveMessage(op, msg) {
|
|
5023
|
-
if (!msg) return `Error during ${op}.`;
|
|
5024
|
-
return typeof msg === "function" ? msg() : msg;
|
|
5025
|
-
}
|
|
5026
|
-
function createErrorHandlers(resource) {
|
|
5027
|
-
async function run(kind, operation, fn, opts) {
|
|
5028
|
-
try {
|
|
5029
|
-
return await fn();
|
|
5030
|
-
} catch (e) {
|
|
5031
|
-
if (isZKsyncError(e)) throw e;
|
|
5032
|
-
const message = resolveMessage(operation, opts?.message);
|
|
5033
|
-
throw toZKsyncError(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
5034
|
-
}
|
|
5035
|
-
}
|
|
5036
|
-
function wrap(operation, fn, opts) {
|
|
5037
|
-
return run("INTERNAL", operation, fn, opts);
|
|
5038
|
-
}
|
|
5039
|
-
function wrapAs2(kind, operation, fn, opts) {
|
|
5040
|
-
return run(kind, operation, fn, opts);
|
|
5041
|
-
}
|
|
5042
|
-
async function toResult(operation, fn, opts) {
|
|
5043
|
-
try {
|
|
5044
|
-
const value = await wrap(operation, fn, opts);
|
|
5045
|
-
return { ok: true, value };
|
|
5046
|
-
} catch (e) {
|
|
5047
|
-
const shaped = isZKsyncError(e) ? e : toZKsyncError(
|
|
5048
|
-
"INTERNAL",
|
|
5049
|
-
{
|
|
5050
|
-
resource,
|
|
5051
|
-
operation,
|
|
5052
|
-
context: opts?.ctx ?? {},
|
|
5053
|
-
message: resolveMessage(operation, opts?.message)
|
|
5054
|
-
},
|
|
5055
|
-
e
|
|
5056
|
-
);
|
|
5057
|
-
return { ok: false, error: shaped };
|
|
5058
|
-
}
|
|
5059
|
-
}
|
|
5060
|
-
return { wrap, wrapAs: wrapAs2, toResult };
|
|
5061
|
-
}
|
|
5183
|
+
var { createErrorHandlers } = createErrorOps(decodeRevert);
|
|
5062
5184
|
|
|
5063
5185
|
// src/adapters/ethers/client.ts
|
|
5064
5186
|
var { wrapAs } = createErrorHandlers("client");
|