viem 0.2.0-jxom-local-accounts.20230321T212822 → 0.2.0-jxom-local-accounts.20230327T004031
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/abi.d.ts +3 -3
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/accounts/index.d.ts +62 -5
- package/dist/accounts/index.js +79 -16
- package/dist/accounts/index.js.map +1 -1
- package/dist/accounts/index.mjs +74 -11
- package/dist/accounts/index.mjs.map +1 -1
- package/dist/{chain-f8db473f.d.ts → chain-40443542.d.ts} +1 -1
- package/dist/{chain-75b0942e.d.ts → chain-4af995bf.d.ts} +63 -27
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +63 -63
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-NJSAEA2H.js → chunk-CGTZNR2R.js} +507 -3
- package/dist/chunk-CGTZNR2R.js.map +1 -0
- package/dist/{chunk-IVRML3IK.mjs → chunk-HWVZ6VEQ.mjs} +506 -2
- package/dist/chunk-HWVZ6VEQ.mjs.map +1 -0
- package/dist/{chunk-FNVFGFWN.mjs → chunk-PVK5TA2L.mjs} +2 -2
- package/dist/chunk-PVK5TA2L.mjs.map +1 -0
- package/dist/{chunk-6UKHPIXX.mjs → chunk-UCNDS4FE.mjs} +2 -2
- package/dist/chunk-UCNDS4FE.mjs.map +1 -0
- package/dist/{chunk-LYQKHD7R.js → chunk-VSAG2LPH.js} +19 -19
- package/dist/chunk-VSAG2LPH.js.map +1 -0
- package/dist/{chunk-FQM5MF6U.js → chunk-XLIQDCZW.js} +6 -6
- package/dist/chunk-XLIQDCZW.js.map +1 -0
- package/dist/contract.d.ts +8 -8
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createClient-f87255c1.d.ts → createClient-1f19be8d.d.ts} +23 -9
- package/dist/{createPublicClient-d2c37c92.d.ts → createPublicClient-b53e3c3d.d.ts} +116 -116
- package/dist/{eip1193-ae706fd8.d.ts → eip1193-210ab776.d.ts} +1 -1
- package/dist/{encodeFunctionResult-4792a6a3.d.ts → encodeFunctionResult-a252fba1.d.ts} +1 -1
- package/dist/{encodePacked-3fcdd54b.d.ts → encodePacked-a9464e97.d.ts} +1 -1
- package/dist/ens.d.ts +5 -5
- package/dist/ens.js +3 -3
- package/dist/ens.mjs +2 -2
- package/dist/ethers.d.ts +3 -3
- package/dist/ethers.js +4 -4
- package/dist/ethers.mjs +2 -2
- package/dist/{formatAbiItem-765ebc53.d.ts → formatAbiItem-6ed70dbd.d.ts} +1 -1
- package/dist/{getAbiItem-693e6e1b.d.ts → getAbiItem-1ff0f41a.d.ts} +1 -1
- package/dist/index.d.ts +21 -15
- package/dist/index.js +127 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -42
- package/dist/index.mjs.map +1 -1
- package/dist/{parseAccount-2d7ea01d.d.ts → parseAccount-8e131c73.d.ts} +1 -1
- package/dist/{parseGwei-377678bc.d.ts → parseGwei-b3a175f7.d.ts} +51 -7
- package/dist/public.d.ts +5 -5
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/test-e28db435.d.ts +198 -0
- package/dist/test.d.ts +11 -11
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/{typedData-ade018d6.d.ts → typedData-848139b1.d.ts} +11 -11
- package/dist/utils/index.d.ts +16 -36
- package/dist/utils/index.js +18 -2
- package/dist/utils/index.mjs +17 -1
- package/dist/wallet.d.ts +5 -5
- package/dist/wallet.js +2 -2
- package/dist/wallet.mjs +1 -1
- package/dist/window.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-6UKHPIXX.mjs.map +0 -1
- package/dist/chunk-FNVFGFWN.mjs.map +0 -1
- package/dist/chunk-FQM5MF6U.js.map +0 -1
- package/dist/chunk-IVRML3IK.mjs.map +0 -1
- package/dist/chunk-LYQKHD7R.js.map +0 -1
- package/dist/chunk-NJSAEA2H.js.map +0 -1
- package/dist/test-98c0b642.d.ts +0 -206
@@ -629,6 +629,12 @@ var ChainNotFoundError = class extends BaseError {
|
|
629
629
|
__publicField(this, "name", "ChainNotFoundError");
|
630
630
|
}
|
631
631
|
};
|
632
|
+
var InvalidChainIdError = class extends BaseError {
|
633
|
+
constructor({ chainId }) {
|
634
|
+
super(`Chain ID "${chainId}" is invalid.`);
|
635
|
+
__publicField(this, "name", "InvalidChainIdError");
|
636
|
+
}
|
637
|
+
};
|
632
638
|
|
633
639
|
// src/constants/abis.ts
|
634
640
|
var multicall3Abi = [
|
@@ -743,6 +749,69 @@ var FeeConflictError = class extends BaseError {
|
|
743
749
|
__publicField(this, "name", "FeeConflictError");
|
744
750
|
}
|
745
751
|
};
|
752
|
+
var InvalidLegacyVError = class extends BaseError {
|
753
|
+
constructor({ v }) {
|
754
|
+
super(`Invalid \`v\` value "${v}". Expected 27 or 28.`);
|
755
|
+
__publicField(this, "name", "InvalidLegacyVError");
|
756
|
+
}
|
757
|
+
};
|
758
|
+
var InvalidSerializableTransactionError = class extends BaseError {
|
759
|
+
constructor({ transaction }) {
|
760
|
+
super("Cannot infer a transaction type from provided transaction.", {
|
761
|
+
metaMessages: [
|
762
|
+
"Provided Transaction:",
|
763
|
+
"{",
|
764
|
+
prettyPrint(transaction),
|
765
|
+
"}",
|
766
|
+
"",
|
767
|
+
"To infer the type, either provide:",
|
768
|
+
"- a `type` to the Transaction, or",
|
769
|
+
"- an EIP-1559 Transaction with `maxFeePerGas`, or",
|
770
|
+
"- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
|
771
|
+
"- a Legacy Transaction with `gasPrice`"
|
772
|
+
]
|
773
|
+
});
|
774
|
+
__publicField(this, "name", "InvalidSerializableTransactionError");
|
775
|
+
}
|
776
|
+
};
|
777
|
+
var InvalidSerializedTransactionTypeError = class extends BaseError {
|
778
|
+
constructor({ serializedType }) {
|
779
|
+
super(`Serialized transaction type "${serializedType}" is invalid.`);
|
780
|
+
__publicField(this, "name", "InvalidSerializedTransactionType");
|
781
|
+
__publicField(this, "serializedType");
|
782
|
+
this.serializedType = serializedType;
|
783
|
+
}
|
784
|
+
};
|
785
|
+
var InvalidSerializedTransactionError = class extends BaseError {
|
786
|
+
constructor({
|
787
|
+
attributes,
|
788
|
+
serializedTransaction,
|
789
|
+
type
|
790
|
+
}) {
|
791
|
+
const missing = Object.entries(attributes).map(([key, value]) => typeof value === "undefined" ? key : void 0).filter(Boolean);
|
792
|
+
super(`Invalid serialized transaction of type "${type}" was provided.`, {
|
793
|
+
metaMessages: [
|
794
|
+
`Serialized Transaction: "${serializedTransaction}"`,
|
795
|
+
missing.length > 0 ? `Missing Attributes: ${missing.join(", ")}` : ""
|
796
|
+
].filter(Boolean)
|
797
|
+
});
|
798
|
+
__publicField(this, "name", "InvalidSerializedTransactionError");
|
799
|
+
__publicField(this, "serializedTransaction");
|
800
|
+
__publicField(this, "type");
|
801
|
+
this.serializedTransaction = serializedTransaction;
|
802
|
+
this.type = type;
|
803
|
+
}
|
804
|
+
};
|
805
|
+
var InvalidStorageKeySizeError = class extends BaseError {
|
806
|
+
constructor({ storageKey }) {
|
807
|
+
super(
|
808
|
+
`Size for storage key "${storageKey}" is invalid. Expected 32 bytes. Got ${Math.floor(
|
809
|
+
(storageKey.length - 2) / 2
|
810
|
+
)} bytes.`
|
811
|
+
);
|
812
|
+
__publicField(this, "name", "InvalidStorageKeySizeError");
|
813
|
+
}
|
814
|
+
};
|
746
815
|
var TransactionExecutionError = class extends BaseError {
|
747
816
|
constructor(cause, {
|
748
817
|
account,
|
@@ -1858,7 +1927,7 @@ function parse2(value) {
|
|
1858
1927
|
function format2(bytes, to) {
|
1859
1928
|
if (Array.isArray(bytes))
|
1860
1929
|
return bytes.map((b) => format2(b, to));
|
1861
|
-
return to === "hex" ?
|
1930
|
+
return to === "hex" ? bytesToHex(bytes) : bytes;
|
1862
1931
|
}
|
1863
1932
|
function rlpToBytes(bytes, offset = 0) {
|
1864
1933
|
if (bytes.length === 0)
|
@@ -1968,6 +2037,11 @@ var getEventSelector = (event) => hashFunction(event);
|
|
1968
2037
|
// src/utils/hash/getFunctionSelector.ts
|
1969
2038
|
var getFunctionSelector = (fn) => slice(hashFunction(fn), 0, 4);
|
1970
2039
|
|
2040
|
+
// src/utils/hash/isHash.ts
|
2041
|
+
function isHash(hash2) {
|
2042
|
+
return hash2.startsWith("0x") && size(hash2) === 32;
|
2043
|
+
}
|
2044
|
+
|
1971
2045
|
// src/utils/address/isAddress.ts
|
1972
2046
|
var addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
1973
2047
|
function isAddress(address) {
|
@@ -3857,6 +3931,32 @@ function assertRequest(args) {
|
|
3857
3931
|
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
3858
3932
|
}
|
3859
3933
|
|
3934
|
+
// src/utils/transaction/getSerializedTransactionType.ts
|
3935
|
+
function getSerializedTransactionType(serializedTransaction) {
|
3936
|
+
const serializedType = sliceHex(serializedTransaction, 0, 1);
|
3937
|
+
if (serializedType === "0x02")
|
3938
|
+
return "eip1559";
|
3939
|
+
if (serializedType === "0x01")
|
3940
|
+
return "eip2930";
|
3941
|
+
if (serializedType !== "0x" && hexToNumber(serializedType) >= 192)
|
3942
|
+
return "legacy";
|
3943
|
+
throw new InvalidSerializedTransactionTypeError({ serializedType });
|
3944
|
+
}
|
3945
|
+
|
3946
|
+
// src/utils/transaction/getTransactionType.ts
|
3947
|
+
function getTransactionType(transaction) {
|
3948
|
+
if (transaction.type)
|
3949
|
+
return transaction.type;
|
3950
|
+
if ("maxFeePerGas" in transaction || "maxPriorityFeePerGas" in transaction)
|
3951
|
+
return "eip1559";
|
3952
|
+
if ("gasPrice" in transaction) {
|
3953
|
+
if ("accessList" in transaction)
|
3954
|
+
return "eip2930";
|
3955
|
+
return "legacy";
|
3956
|
+
}
|
3957
|
+
throw new InvalidSerializableTransactionError({ transaction });
|
3958
|
+
}
|
3959
|
+
|
3860
3960
|
// src/actions/public/call.ts
|
3861
3961
|
async function call(client, args) {
|
3862
3962
|
const {
|
@@ -5601,6 +5701,400 @@ async function prepareRequest(client, args) {
|
|
5601
5701
|
return request;
|
5602
5702
|
}
|
5603
5703
|
|
5704
|
+
// src/utils/transaction/assertTransaction.ts
|
5705
|
+
function assertTransactionEIP1559(transaction) {
|
5706
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
5707
|
+
if (chainId <= 0)
|
5708
|
+
throw new InvalidChainIdError({ chainId });
|
5709
|
+
if (to && !isAddress(to))
|
5710
|
+
throw new InvalidAddressError({ address: to });
|
5711
|
+
if (gasPrice)
|
5712
|
+
throw new BaseError(
|
5713
|
+
"`gasPrice` is not a valid EIP-1559 Transaction attribute."
|
5714
|
+
);
|
5715
|
+
if (maxFeePerGas && maxFeePerGas > 2n ** 256n - 1n)
|
5716
|
+
throw new FeeCapTooHighError({ maxFeePerGas });
|
5717
|
+
if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
|
5718
|
+
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
5719
|
+
}
|
5720
|
+
function assertTransactionEIP2930(transaction) {
|
5721
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
5722
|
+
if (chainId <= 0)
|
5723
|
+
throw new InvalidChainIdError({ chainId });
|
5724
|
+
if (to && !isAddress(to))
|
5725
|
+
throw new InvalidAddressError({ address: to });
|
5726
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
5727
|
+
throw new BaseError(
|
5728
|
+
"`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute."
|
5729
|
+
);
|
5730
|
+
if (gasPrice && gasPrice > 2n ** 256n - 1n)
|
5731
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
5732
|
+
}
|
5733
|
+
function assertTransactionLegacy(transaction) {
|
5734
|
+
const {
|
5735
|
+
chainId,
|
5736
|
+
maxPriorityFeePerGas,
|
5737
|
+
gasPrice,
|
5738
|
+
maxFeePerGas,
|
5739
|
+
to,
|
5740
|
+
accessList
|
5741
|
+
} = transaction;
|
5742
|
+
if (to && !isAddress(to))
|
5743
|
+
throw new InvalidAddressError({ address: to });
|
5744
|
+
if (typeof chainId !== "undefined" && chainId <= 0)
|
5745
|
+
throw new InvalidChainIdError({ chainId });
|
5746
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
5747
|
+
throw new BaseError(
|
5748
|
+
"`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute."
|
5749
|
+
);
|
5750
|
+
if (gasPrice && gasPrice > 2n ** 256n - 1n)
|
5751
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
5752
|
+
if (accessList)
|
5753
|
+
throw new BaseError(
|
5754
|
+
"`accessList` is not a valid Legacy Transaction attribute."
|
5755
|
+
);
|
5756
|
+
}
|
5757
|
+
|
5758
|
+
// src/utils/transaction/parseTransaction.ts
|
5759
|
+
function parseTransaction(serializedTransaction) {
|
5760
|
+
const type = getSerializedTransactionType(serializedTransaction);
|
5761
|
+
if (type === "eip1559")
|
5762
|
+
return parseTransactionEIP1559(
|
5763
|
+
serializedTransaction
|
5764
|
+
);
|
5765
|
+
if (type === "eip2930")
|
5766
|
+
return parseTransactionEIP2930(
|
5767
|
+
serializedTransaction
|
5768
|
+
);
|
5769
|
+
return parseTransactionLegacy(
|
5770
|
+
serializedTransaction
|
5771
|
+
);
|
5772
|
+
}
|
5773
|
+
function parseTransactionEIP1559(serializedTransaction) {
|
5774
|
+
const transactionArray = fromRlp(
|
5775
|
+
`0x${serializedTransaction.slice(4)}`,
|
5776
|
+
"hex"
|
5777
|
+
);
|
5778
|
+
const [
|
5779
|
+
chainId,
|
5780
|
+
nonce,
|
5781
|
+
maxPriorityFeePerGas,
|
5782
|
+
maxFeePerGas,
|
5783
|
+
gas,
|
5784
|
+
to,
|
5785
|
+
value,
|
5786
|
+
data,
|
5787
|
+
accessList,
|
5788
|
+
v,
|
5789
|
+
r,
|
5790
|
+
s
|
5791
|
+
] = transactionArray;
|
5792
|
+
if (!(transactionArray.length === 9 || transactionArray.length === 12))
|
5793
|
+
throw new InvalidSerializedTransactionError({
|
5794
|
+
attributes: {
|
5795
|
+
chainId,
|
5796
|
+
nonce,
|
5797
|
+
maxPriorityFeePerGas,
|
5798
|
+
maxFeePerGas,
|
5799
|
+
gas,
|
5800
|
+
to,
|
5801
|
+
value,
|
5802
|
+
data,
|
5803
|
+
accessList,
|
5804
|
+
...transactionArray.length > 9 ? {
|
5805
|
+
v,
|
5806
|
+
r,
|
5807
|
+
s
|
5808
|
+
} : {}
|
5809
|
+
},
|
5810
|
+
serializedTransaction,
|
5811
|
+
type: "eip1559"
|
5812
|
+
});
|
5813
|
+
let transaction = {
|
5814
|
+
chainId: hexToNumber(chainId),
|
5815
|
+
type: "eip1559"
|
5816
|
+
};
|
5817
|
+
if (isHex(to) && to !== "0x")
|
5818
|
+
transaction.to = to;
|
5819
|
+
if (isHex(gas) && gas !== "0x")
|
5820
|
+
transaction.gas = hexToBigInt(gas);
|
5821
|
+
if (isHex(data) && data !== "0x")
|
5822
|
+
transaction.data = data;
|
5823
|
+
if (isHex(nonce) && nonce !== "0x")
|
5824
|
+
transaction.nonce = hexToNumber(nonce);
|
5825
|
+
if (isHex(value) && value !== "0x")
|
5826
|
+
transaction.value = hexToBigInt(value);
|
5827
|
+
if (isHex(maxFeePerGas) && maxFeePerGas !== "0x")
|
5828
|
+
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas);
|
5829
|
+
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== "0x")
|
5830
|
+
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas);
|
5831
|
+
if (accessList.length !== 0 && accessList !== "0x")
|
5832
|
+
transaction.accessList = parseAccessList(accessList);
|
5833
|
+
assertTransactionEIP1559(transaction);
|
5834
|
+
const signature = transactionArray.length === 12 ? parseEIP155Signature(transactionArray) : void 0;
|
5835
|
+
return { ...signature, ...transaction };
|
5836
|
+
}
|
5837
|
+
function parseTransactionEIP2930(serializedTransaction) {
|
5838
|
+
const transactionArray = fromRlp(
|
5839
|
+
`0x${serializedTransaction.slice(4)}`,
|
5840
|
+
"hex"
|
5841
|
+
);
|
5842
|
+
const [chainId, nonce, gasPrice, gas, to, value, data, accessList, v, r, s] = transactionArray;
|
5843
|
+
if (!(transactionArray.length === 8 || transactionArray.length === 11))
|
5844
|
+
throw new InvalidSerializedTransactionError({
|
5845
|
+
attributes: {
|
5846
|
+
chainId,
|
5847
|
+
nonce,
|
5848
|
+
gasPrice,
|
5849
|
+
gas,
|
5850
|
+
to,
|
5851
|
+
value,
|
5852
|
+
data,
|
5853
|
+
accessList,
|
5854
|
+
...transactionArray.length > 8 ? {
|
5855
|
+
v,
|
5856
|
+
r,
|
5857
|
+
s
|
5858
|
+
} : {}
|
5859
|
+
},
|
5860
|
+
serializedTransaction,
|
5861
|
+
type: "eip2930"
|
5862
|
+
});
|
5863
|
+
let transaction = {
|
5864
|
+
chainId: hexToNumber(chainId),
|
5865
|
+
type: "eip2930"
|
5866
|
+
};
|
5867
|
+
if (isHex(to) && to !== "0x")
|
5868
|
+
transaction.to = to;
|
5869
|
+
if (isHex(gas) && gas !== "0x")
|
5870
|
+
transaction.gas = hexToBigInt(gas);
|
5871
|
+
if (isHex(data) && data !== "0x")
|
5872
|
+
transaction.data = data;
|
5873
|
+
if (isHex(nonce) && nonce !== "0x")
|
5874
|
+
transaction.nonce = hexToNumber(nonce);
|
5875
|
+
if (isHex(value) && value !== "0x")
|
5876
|
+
transaction.value = hexToBigInt(value);
|
5877
|
+
if (isHex(gasPrice) && gasPrice !== "0x")
|
5878
|
+
transaction.gasPrice = hexToBigInt(gasPrice);
|
5879
|
+
if (accessList.length !== 0 && accessList !== "0x")
|
5880
|
+
transaction.accessList = parseAccessList(accessList);
|
5881
|
+
assertTransactionEIP2930(transaction);
|
5882
|
+
const signature = transactionArray.length === 11 ? parseEIP155Signature(transactionArray) : void 0;
|
5883
|
+
return { ...signature, ...transaction };
|
5884
|
+
}
|
5885
|
+
function parseTransactionLegacy(serializedTransaction) {
|
5886
|
+
const transactionArray = fromRlp(serializedTransaction, "hex");
|
5887
|
+
const [nonce, gasPrice, gas, to, value, data, chainIdOrV_, r, s] = transactionArray;
|
5888
|
+
if (!(transactionArray.length === 6 || transactionArray.length === 9))
|
5889
|
+
throw new InvalidSerializedTransactionError({
|
5890
|
+
attributes: {
|
5891
|
+
nonce,
|
5892
|
+
gasPrice,
|
5893
|
+
gas,
|
5894
|
+
to,
|
5895
|
+
value,
|
5896
|
+
data,
|
5897
|
+
...transactionArray.length > 6 ? {
|
5898
|
+
v: chainIdOrV_,
|
5899
|
+
r,
|
5900
|
+
s
|
5901
|
+
} : {}
|
5902
|
+
},
|
5903
|
+
serializedTransaction,
|
5904
|
+
type: "legacy"
|
5905
|
+
});
|
5906
|
+
let transaction = {
|
5907
|
+
type: "legacy"
|
5908
|
+
};
|
5909
|
+
if (isHex(to) && to !== "0x")
|
5910
|
+
transaction.to = to;
|
5911
|
+
if (isHex(gas) && gas !== "0x")
|
5912
|
+
transaction.gas = hexToBigInt(gas);
|
5913
|
+
if (isHex(data) && data !== "0x")
|
5914
|
+
transaction.data = data;
|
5915
|
+
if (isHex(nonce) && nonce !== "0x")
|
5916
|
+
transaction.nonce = hexToNumber(nonce);
|
5917
|
+
if (isHex(value) && value !== "0x")
|
5918
|
+
transaction.value = hexToBigInt(value);
|
5919
|
+
if (isHex(gasPrice) && gasPrice !== "0x")
|
5920
|
+
transaction.gasPrice = hexToBigInt(gasPrice);
|
5921
|
+
assertTransactionLegacy(transaction);
|
5922
|
+
if (transactionArray.length === 6)
|
5923
|
+
return transaction;
|
5924
|
+
const chainIdOrV = isHex(chainIdOrV_) && chainIdOrV_ !== "0x" ? hexToBigInt(chainIdOrV_) : 0n;
|
5925
|
+
if (s === "0x" && r === "0x") {
|
5926
|
+
if (chainIdOrV > 0)
|
5927
|
+
transaction.chainId = Number(chainIdOrV);
|
5928
|
+
return transaction;
|
5929
|
+
}
|
5930
|
+
const v = chainIdOrV;
|
5931
|
+
let chainId = Number((v - 35n) / 2n);
|
5932
|
+
if (chainId > 0)
|
5933
|
+
transaction.chainId = chainId;
|
5934
|
+
else if (v !== 27n && v !== 28n)
|
5935
|
+
throw new InvalidLegacyVError({ v });
|
5936
|
+
transaction.v = v;
|
5937
|
+
transaction.s = s;
|
5938
|
+
transaction.r = r;
|
5939
|
+
return transaction;
|
5940
|
+
}
|
5941
|
+
function parseAccessList(accessList_) {
|
5942
|
+
let accessList = [];
|
5943
|
+
for (let i = 0; i < accessList_.length; i++) {
|
5944
|
+
const [address, storageKeys] = accessList_[i];
|
5945
|
+
if (!isAddress(address))
|
5946
|
+
throw new InvalidAddressError({ address });
|
5947
|
+
accessList.push({
|
5948
|
+
address,
|
5949
|
+
storageKeys: storageKeys.map((key) => isHash(key) ? key : trim(key))
|
5950
|
+
});
|
5951
|
+
}
|
5952
|
+
return accessList;
|
5953
|
+
}
|
5954
|
+
function parseEIP155Signature(transactionArray) {
|
5955
|
+
const signature = transactionArray.slice(-3);
|
5956
|
+
const v = signature[0] === "0x" || hexToBigInt(signature[0]) === 0n ? 27n : 28n;
|
5957
|
+
return {
|
5958
|
+
r: padHex(signature[1], { size: 32 }),
|
5959
|
+
s: padHex(signature[2], { size: 32 }),
|
5960
|
+
v,
|
5961
|
+
yParity: v === 27n ? 0 : 1
|
5962
|
+
};
|
5963
|
+
}
|
5964
|
+
|
5965
|
+
// src/utils/transaction/serializeTransaction.ts
|
5966
|
+
function serializeTransaction(transaction, signature) {
|
5967
|
+
const type = getTransactionType(transaction);
|
5968
|
+
if (type === "eip1559")
|
5969
|
+
return serializeTransactionEIP1559(
|
5970
|
+
transaction,
|
5971
|
+
signature
|
5972
|
+
);
|
5973
|
+
if (type === "eip2930")
|
5974
|
+
return serializeTransactionEIP2930(
|
5975
|
+
transaction,
|
5976
|
+
signature
|
5977
|
+
);
|
5978
|
+
return serializeTransactionLegacy(
|
5979
|
+
transaction,
|
5980
|
+
signature
|
5981
|
+
);
|
5982
|
+
}
|
5983
|
+
function serializeTransactionEIP1559(transaction, signature) {
|
5984
|
+
const {
|
5985
|
+
chainId,
|
5986
|
+
gas,
|
5987
|
+
nonce,
|
5988
|
+
to,
|
5989
|
+
value,
|
5990
|
+
maxFeePerGas,
|
5991
|
+
maxPriorityFeePerGas,
|
5992
|
+
accessList,
|
5993
|
+
data
|
5994
|
+
} = transaction;
|
5995
|
+
assertTransactionEIP1559(transaction);
|
5996
|
+
const serializedAccessList = serializeAccessList(accessList);
|
5997
|
+
const serializedTransaction = [
|
5998
|
+
toHex(chainId),
|
5999
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6000
|
+
typeof maxPriorityFeePerGas !== "undefined" ? toHex(maxPriorityFeePerGas) : "0x",
|
6001
|
+
typeof maxFeePerGas !== "undefined" ? toHex(maxFeePerGas) : "0x",
|
6002
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6003
|
+
to ?? "0x",
|
6004
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6005
|
+
data ?? "0x",
|
6006
|
+
serializedAccessList
|
6007
|
+
];
|
6008
|
+
if (signature)
|
6009
|
+
serializedTransaction.push(
|
6010
|
+
signature.v === 27n ? "0x" : toHex(1),
|
6011
|
+
// yParity
|
6012
|
+
signature.r,
|
6013
|
+
signature.s
|
6014
|
+
);
|
6015
|
+
return concatHex([
|
6016
|
+
"0x02",
|
6017
|
+
toRlp(serializedTransaction)
|
6018
|
+
]);
|
6019
|
+
}
|
6020
|
+
function serializeTransactionEIP2930(transaction, signature) {
|
6021
|
+
const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction;
|
6022
|
+
assertTransactionEIP2930(transaction);
|
6023
|
+
const serializedAccessList = serializeAccessList(accessList);
|
6024
|
+
const serializedTransaction = [
|
6025
|
+
toHex(chainId),
|
6026
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6027
|
+
typeof gasPrice !== "undefined" ? toHex(gasPrice) : "0x",
|
6028
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6029
|
+
to ?? "0x",
|
6030
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6031
|
+
data ?? "0x",
|
6032
|
+
serializedAccessList
|
6033
|
+
];
|
6034
|
+
if (signature)
|
6035
|
+
serializedTransaction.push(
|
6036
|
+
signature.v === 27n ? "0x" : toHex(1),
|
6037
|
+
// yParity
|
6038
|
+
signature.r,
|
6039
|
+
signature.s
|
6040
|
+
);
|
6041
|
+
return concatHex([
|
6042
|
+
"0x01",
|
6043
|
+
toRlp(serializedTransaction)
|
6044
|
+
]);
|
6045
|
+
}
|
6046
|
+
function serializeTransactionLegacy(transaction, signature) {
|
6047
|
+
const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
|
6048
|
+
assertTransactionLegacy(transaction);
|
6049
|
+
let serializedTransaction = [
|
6050
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6051
|
+
typeof gasPrice !== "undefined" ? toHex(gasPrice) : "0x",
|
6052
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6053
|
+
to ?? "0x",
|
6054
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6055
|
+
data ?? "0x"
|
6056
|
+
];
|
6057
|
+
if (signature) {
|
6058
|
+
let v = 27n + (signature.v === 27n ? 0n : 1n);
|
6059
|
+
if (chainId > 0)
|
6060
|
+
v = BigInt(chainId * 2) + BigInt(35n + signature.v - 27n);
|
6061
|
+
else if (signature.v !== v)
|
6062
|
+
throw new InvalidLegacyVError({ v: signature.v });
|
6063
|
+
serializedTransaction = [
|
6064
|
+
...serializedTransaction,
|
6065
|
+
toHex(v),
|
6066
|
+
signature.r,
|
6067
|
+
signature.s
|
6068
|
+
];
|
6069
|
+
} else if (chainId > 0) {
|
6070
|
+
serializedTransaction = [
|
6071
|
+
...serializedTransaction,
|
6072
|
+
toHex(chainId),
|
6073
|
+
"0x",
|
6074
|
+
"0x"
|
6075
|
+
];
|
6076
|
+
}
|
6077
|
+
return toRlp(serializedTransaction);
|
6078
|
+
}
|
6079
|
+
function serializeAccessList(accessList) {
|
6080
|
+
if (!accessList || accessList.length === 0)
|
6081
|
+
return [];
|
6082
|
+
let serializedAccessList = [];
|
6083
|
+
for (let i = 0; i < accessList.length; i++) {
|
6084
|
+
const { address, storageKeys } = accessList[i];
|
6085
|
+
for (let j = 0; j < storageKeys.length; j++) {
|
6086
|
+
if (storageKeys[j].length - 2 !== 64) {
|
6087
|
+
throw new InvalidStorageKeySizeError({ storageKey: storageKeys[j] });
|
6088
|
+
}
|
6089
|
+
}
|
6090
|
+
if (!isAddress(address)) {
|
6091
|
+
throw new InvalidAddressError({ address });
|
6092
|
+
}
|
6093
|
+
serializedAccessList.push([address, storageKeys]);
|
6094
|
+
}
|
6095
|
+
return serializedAccessList;
|
6096
|
+
}
|
6097
|
+
|
5604
6098
|
// src/utils/unit/formatUnits.ts
|
5605
6099
|
function formatUnits(value, decimals) {
|
5606
6100
|
let display = value.toString();
|
@@ -5656,11 +6150,13 @@ export {
|
|
5656
6150
|
InvalidAddressError,
|
5657
6151
|
BlockNotFoundError,
|
5658
6152
|
ChainDoesNotSupportContract,
|
6153
|
+
InvalidChainIdError,
|
5659
6154
|
multicall3Abi,
|
5660
6155
|
panicReasons,
|
5661
6156
|
etherUnits,
|
5662
6157
|
gweiUnits,
|
5663
6158
|
weiUnits,
|
6159
|
+
InvalidLegacyVError,
|
5664
6160
|
TransactionExecutionError,
|
5665
6161
|
TransactionNotFoundError,
|
5666
6162
|
TransactionReceiptNotFoundError,
|
@@ -5755,6 +6251,7 @@ export {
|
|
5755
6251
|
keccak256,
|
5756
6252
|
getEventSelector,
|
5757
6253
|
getFunctionSelector,
|
6254
|
+
isHash,
|
5758
6255
|
isAddress,
|
5759
6256
|
checksumAddress,
|
5760
6257
|
getAddress,
|
@@ -5818,6 +6315,8 @@ export {
|
|
5818
6315
|
verifyMessage,
|
5819
6316
|
verifyTypedData,
|
5820
6317
|
assertRequest,
|
6318
|
+
getSerializedTransactionType,
|
6319
|
+
getTransactionType,
|
5821
6320
|
call,
|
5822
6321
|
simulateContract,
|
5823
6322
|
createPendingTransactionFilter,
|
@@ -5895,9 +6394,14 @@ export {
|
|
5895
6394
|
parseUnits,
|
5896
6395
|
parseGwei,
|
5897
6396
|
prepareRequest,
|
6397
|
+
assertTransactionEIP1559,
|
6398
|
+
assertTransactionEIP2930,
|
6399
|
+
assertTransactionLegacy,
|
6400
|
+
parseTransaction,
|
6401
|
+
serializeTransaction,
|
5898
6402
|
formatUnits,
|
5899
6403
|
formatEther,
|
5900
6404
|
formatGwei,
|
5901
6405
|
parseEther
|
5902
6406
|
};
|
5903
|
-
//# sourceMappingURL=chunk-
|
6407
|
+
//# sourceMappingURL=chunk-HWVZ6VEQ.mjs.map
|