@matterlabs/zksync-js 0.0.5 → 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 +194 -50
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/resources/withdrawals/index.d.ts +11 -0
- package/dist/adapters/ethers/sdk.cjs +75 -47
- 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 +194 -50
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/resources/withdrawals/index.d.ts +11 -0
- package/dist/adapters/viem/sdk.cjs +75 -47
- 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-NBJEQAOE.js → chunk-EWLA4NUE.js} +28 -6
- 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-JXUFGIJG.js → chunk-KRIRXY74.js} +30 -52
- 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
package/dist/core/index.cjs
CHANGED
|
@@ -4703,6 +4703,7 @@ function shapeCause(err) {
|
|
|
4703
4703
|
var zks_exports = {};
|
|
4704
4704
|
__export(zks_exports, {
|
|
4705
4705
|
createZksRpc: () => createZksRpc,
|
|
4706
|
+
normalizeBlockMetadata: () => normalizeBlockMetadata,
|
|
4706
4707
|
normalizeGenesis: () => normalizeGenesis,
|
|
4707
4708
|
normalizeProof: () => normalizeProof
|
|
4708
4709
|
});
|
|
@@ -4728,6 +4729,8 @@ var METHODS = {
|
|
|
4728
4729
|
getBridgehub: "zks_getBridgehubContract",
|
|
4729
4730
|
getL2ToL1LogProof: "zks_getL2ToL1LogProof",
|
|
4730
4731
|
getReceipt: "eth_getTransactionReceipt",
|
|
4732
|
+
getBytecodeSupplier: "zks_getBytecodeSupplierContract",
|
|
4733
|
+
getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
|
|
4731
4734
|
getGenesis: "zks_getGenesis"
|
|
4732
4735
|
};
|
|
4733
4736
|
function toHexArray(arr) {
|
|
@@ -4780,7 +4783,9 @@ function ensureHex(value, field, context) {
|
|
|
4780
4783
|
context: { field, valueType: typeof value, ...context }
|
|
4781
4784
|
});
|
|
4782
4785
|
}
|
|
4783
|
-
function ensureNumber(value, field) {
|
|
4786
|
+
function ensureNumber(value, field, opts) {
|
|
4787
|
+
const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
|
|
4788
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
|
|
4784
4789
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
4785
4790
|
if (typeof value === "bigint") return Number(value);
|
|
4786
4791
|
if (typeof value === "string" && value.trim() !== "") {
|
|
@@ -4789,8 +4794,36 @@ function ensureNumber(value, field) {
|
|
|
4789
4794
|
}
|
|
4790
4795
|
throw createError("RPC", {
|
|
4791
4796
|
resource: "zksrpc",
|
|
4792
|
-
operation
|
|
4793
|
-
message:
|
|
4797
|
+
operation,
|
|
4798
|
+
message: `${messagePrefix}: expected numeric value.`,
|
|
4799
|
+
context: { field, valueType: typeof value }
|
|
4800
|
+
});
|
|
4801
|
+
}
|
|
4802
|
+
function ensureBigInt(value, field, opts) {
|
|
4803
|
+
const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
|
|
4804
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
|
|
4805
|
+
if (typeof value === "bigint") return value;
|
|
4806
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
4807
|
+
if (!Number.isInteger(value)) {
|
|
4808
|
+
throw createError("RPC", {
|
|
4809
|
+
resource: "zksrpc",
|
|
4810
|
+
operation,
|
|
4811
|
+
message: `${messagePrefix}: expected integer value.`,
|
|
4812
|
+
context: { field, valueType: typeof value }
|
|
4813
|
+
});
|
|
4814
|
+
}
|
|
4815
|
+
return BigInt(value);
|
|
4816
|
+
}
|
|
4817
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
4818
|
+
try {
|
|
4819
|
+
return BigInt(value);
|
|
4820
|
+
} catch {
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4823
|
+
throw createError("RPC", {
|
|
4824
|
+
resource: "zksrpc",
|
|
4825
|
+
operation,
|
|
4826
|
+
message: `${messagePrefix}: expected bigint-compatible value.`,
|
|
4794
4827
|
context: { field, valueType: typeof value }
|
|
4795
4828
|
});
|
|
4796
4829
|
}
|
|
@@ -4876,6 +4909,57 @@ function normalizeGenesis(raw) {
|
|
|
4876
4909
|
});
|
|
4877
4910
|
}
|
|
4878
4911
|
}
|
|
4912
|
+
function normalizeBlockMetadata(raw) {
|
|
4913
|
+
try {
|
|
4914
|
+
if (!raw || typeof raw !== "object") {
|
|
4915
|
+
throw createError("RPC", {
|
|
4916
|
+
resource: "zksrpc",
|
|
4917
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4918
|
+
message: "Malformed block metadata response: expected object.",
|
|
4919
|
+
context: { receivedType: typeof raw }
|
|
4920
|
+
});
|
|
4921
|
+
}
|
|
4922
|
+
const record = raw;
|
|
4923
|
+
const pubdataPricePerByte = ensureBigInt(
|
|
4924
|
+
record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
|
|
4925
|
+
"pubdata_price_per_byte",
|
|
4926
|
+
{
|
|
4927
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4928
|
+
messagePrefix: "Malformed block metadata response"
|
|
4929
|
+
}
|
|
4930
|
+
);
|
|
4931
|
+
const nativePrice = ensureBigInt(
|
|
4932
|
+
record["native_price"] ?? record["nativePrice"],
|
|
4933
|
+
"native_price",
|
|
4934
|
+
{
|
|
4935
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4936
|
+
messagePrefix: "Malformed block metadata response"
|
|
4937
|
+
}
|
|
4938
|
+
);
|
|
4939
|
+
const executionVersion = ensureNumber(
|
|
4940
|
+
record["execution_version"] ?? record["executionVersion"],
|
|
4941
|
+
"execution_version",
|
|
4942
|
+
{
|
|
4943
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4944
|
+
messagePrefix: "Malformed block metadata response"
|
|
4945
|
+
}
|
|
4946
|
+
);
|
|
4947
|
+
return {
|
|
4948
|
+
pubdataPricePerByte,
|
|
4949
|
+
nativePrice,
|
|
4950
|
+
executionVersion
|
|
4951
|
+
};
|
|
4952
|
+
} catch (e) {
|
|
4953
|
+
if (isZKsyncError(e)) throw e;
|
|
4954
|
+
throw createError("RPC", {
|
|
4955
|
+
resource: "zksrpc",
|
|
4956
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
4957
|
+
message: "Failed to normalize block metadata response.",
|
|
4958
|
+
context: { receivedType: typeof raw },
|
|
4959
|
+
cause: shapeCause(e)
|
|
4960
|
+
});
|
|
4961
|
+
}
|
|
4962
|
+
}
|
|
4879
4963
|
function createZksRpc(transport) {
|
|
4880
4964
|
return {
|
|
4881
4965
|
// Fetches the Bridgehub contract address.
|
|
@@ -4898,6 +4982,26 @@ function createZksRpc(transport) {
|
|
|
4898
4982
|
}
|
|
4899
4983
|
);
|
|
4900
4984
|
},
|
|
4985
|
+
// Fetches the Bytecode Supplier contract address.
|
|
4986
|
+
async getBytecodeSupplierAddress() {
|
|
4987
|
+
return withRpcOp(
|
|
4988
|
+
"zksrpc.getBytecodeSupplierAddress",
|
|
4989
|
+
"Failed to fetch Bytecode Supplier address.",
|
|
4990
|
+
{},
|
|
4991
|
+
async () => {
|
|
4992
|
+
const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
|
|
4993
|
+
if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
|
|
4994
|
+
throw createError("RPC", {
|
|
4995
|
+
resource: "zksrpc",
|
|
4996
|
+
operation: "zksrpc.getBytecodeSupplierAddress",
|
|
4997
|
+
message: "Unexpected Bytecode Supplier address response.",
|
|
4998
|
+
context: { valueType: typeof addrRaw }
|
|
4999
|
+
});
|
|
5000
|
+
}
|
|
5001
|
+
return addrRaw;
|
|
5002
|
+
}
|
|
5003
|
+
);
|
|
5004
|
+
},
|
|
4901
5005
|
// Fetches a proof for an L2→L1 log emitted in the given transaction.
|
|
4902
5006
|
async getL2ToL1LogProof(txHash, index) {
|
|
4903
5007
|
return withRpcOp(
|
|
@@ -4934,6 +5038,19 @@ function createZksRpc(transport) {
|
|
|
4934
5038
|
}
|
|
4935
5039
|
);
|
|
4936
5040
|
},
|
|
5041
|
+
// Fetches block metadata for the given block number.
|
|
5042
|
+
async getBlockMetadataByNumber(blockNumber) {
|
|
5043
|
+
return withRpcOp(
|
|
5044
|
+
"zksrpc.getBlockMetadataByNumber",
|
|
5045
|
+
"Failed to fetch block metadata.",
|
|
5046
|
+
{ blockNumber },
|
|
5047
|
+
async () => {
|
|
5048
|
+
const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
|
|
5049
|
+
if (raw == null) return null;
|
|
5050
|
+
return normalizeBlockMetadata(raw);
|
|
5051
|
+
}
|
|
5052
|
+
);
|
|
5053
|
+
},
|
|
4937
5054
|
// Fetches the genesis configuration returned by `zks_getGenesis`.
|
|
4938
5055
|
async getGenesis() {
|
|
4939
5056
|
return withRpcOp(
|