viem 0.2.0-jxom-async-verify-message.20230321T000803 → 0.2.0-jxom-local-accounts.20230321T210352

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 (58) hide show
  1. package/dist/abi.d.ts +3 -3
  2. package/dist/abi.js +2 -2
  3. package/dist/abi.mjs +1 -1
  4. package/dist/{chain-b2e88e30.d.ts → chain-75b0942e.d.ts} +60 -60
  5. package/dist/{chain-c4f924cf.d.ts → chain-f8db473f.d.ts} +1 -1
  6. package/dist/chains.d.ts +3 -3
  7. package/dist/chains.js +63 -63
  8. package/dist/chains.mjs +1 -1
  9. package/dist/{chunk-22BDIC7J.js → chunk-FHJTO6BQ.js} +1369 -1349
  10. package/dist/chunk-FHJTO6BQ.js.map +1 -0
  11. package/dist/{chunk-OZCG5IO7.mjs → chunk-IXGTN6B7.mjs} +2 -2
  12. package/dist/{chunk-2NJCP2DN.js → chunk-K66BKQUH.js} +19 -19
  13. package/dist/{chunk-FEPL5HFW.mjs → chunk-PB263D6W.mjs} +1171 -1151
  14. package/dist/chunk-PB263D6W.mjs.map +1 -0
  15. package/dist/contract.d.ts +8 -8
  16. package/dist/contract.js +2 -2
  17. package/dist/contract.mjs +1 -1
  18. package/dist/{createClient-d4f1dea1.d.ts → createClient-f87255c1.d.ts} +2 -2
  19. package/dist/{createPublicClient-3a714a8d.d.ts → createPublicClient-62c74ebc.d.ts} +12 -5
  20. package/dist/{eip1193-cd3e872a.d.ts → eip1193-ae706fd8.d.ts} +1 -1
  21. package/dist/{encodeFunctionResult-750c9055.d.ts → encodeFunctionResult-4792a6a3.d.ts} +1 -1
  22. package/dist/{encodePacked-de74201f.d.ts → encodePacked-3fcdd54b.d.ts} +1 -1
  23. package/dist/ens.d.ts +5 -5
  24. package/dist/ens.js +3 -3
  25. package/dist/ens.mjs +2 -2
  26. package/dist/ethers.d.ts +4 -4
  27. package/dist/ethers.js +5 -5
  28. package/dist/ethers.js.map +1 -1
  29. package/dist/ethers.mjs +5 -5
  30. package/dist/ethers.mjs.map +1 -1
  31. package/dist/{formatAbiItem-fdbdda39.d.ts → formatAbiItem-765ebc53.d.ts} +1 -1
  32. package/dist/{getAbiItem-9d709e3b.d.ts → getAbiItem-693e6e1b.d.ts} +1 -1
  33. package/dist/index.d.ts +14 -14
  34. package/dist/index.js +91 -91
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.mjs +4 -4
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/{parseGwei-b138c041.d.ts → parseGwei-7efc43fc.d.ts} +15 -16
  39. package/dist/public.d.ts +5 -5
  40. package/dist/public.js +2 -2
  41. package/dist/public.mjs +1 -1
  42. package/dist/{test-c70126a6.d.ts → test-98c0b642.d.ts} +3 -3
  43. package/dist/test.d.ts +5 -5
  44. package/dist/test.js +2 -2
  45. package/dist/test.mjs +1 -1
  46. package/dist/{account-07d04222.d.ts → typedData-0514bb3c.d.ts} +29 -27
  47. package/dist/utils/index.d.ts +14 -14
  48. package/dist/utils/index.js +2 -4
  49. package/dist/utils/index.mjs +3 -5
  50. package/dist/wallet.d.ts +5 -5
  51. package/dist/wallet.js +2 -2
  52. package/dist/wallet.mjs +1 -1
  53. package/dist/window.d.ts +2 -2
  54. package/package.json +3 -1
  55. package/dist/chunk-22BDIC7J.js.map +0 -1
  56. package/dist/chunk-FEPL5HFW.mjs.map +0 -1
  57. /package/dist/{chunk-OZCG5IO7.mjs.map → chunk-IXGTN6B7.mjs.map} +0 -0
  58. /package/dist/{chunk-2NJCP2DN.js.map → chunk-K66BKQUH.js.map} +0 -0
@@ -142,6 +142,8 @@ var package_default = {
142
142
  dependencies: {
143
143
  "@noble/hashes": "^1.1.2",
144
144
  "@noble/secp256k1": "^1.7.1",
145
+ "@scure/bip32": "^1.2.0",
146
+ "@scure/bip39": "^1.1.1",
145
147
  "@wagmi/chains": "~0.2.11",
146
148
  abitype: "~0.7.1",
147
149
  "idna-uts46-hx": "^4.1.2",
@@ -614,178 +616,735 @@ var ChainNotFoundError = class extends BaseError {
614
616
  }
615
617
  };
616
618
 
617
- // src/constants/abis.ts
618
- var multicall3Abi = [
619
- {
620
- inputs: [
621
- {
622
- components: [
623
- {
624
- name: "target",
625
- type: "address"
626
- },
627
- {
628
- name: "allowFailure",
629
- type: "bool"
630
- },
631
- {
632
- name: "callData",
633
- type: "bytes"
634
- }
635
- ],
636
- name: "calls",
637
- type: "tuple[]"
638
- }
639
- ],
640
- name: "aggregate3",
641
- outputs: [
642
- {
643
- components: [
644
- {
645
- name: "success",
646
- type: "bool"
647
- },
648
- {
649
- name: "returnData",
650
- type: "bytes"
651
- }
652
- ],
653
- name: "returnData",
654
- type: "tuple[]"
655
- }
656
- ],
657
- stateMutability: "view",
658
- type: "function"
619
+ // src/accounts/index.ts
620
+ import { HDKey } from "@scure/bip32";
621
+
622
+ // src/accounts/utils/parseAccount.ts
623
+ function parseAccount(account) {
624
+ if (typeof account === "string")
625
+ return { address: account, type: "json-rpc" };
626
+ return account;
627
+ }
628
+
629
+ // src/utils/data/concat.ts
630
+ function concat(values) {
631
+ if (typeof values[0] === "string")
632
+ return concatHex(values);
633
+ return concatBytes(values);
634
+ }
635
+ function concatBytes(values) {
636
+ let length = 0;
637
+ for (const arr of values) {
638
+ length += arr.length;
659
639
  }
660
- ];
640
+ const result = new Uint8Array(length);
641
+ let offset = 0;
642
+ for (const arr of values) {
643
+ result.set(arr, offset);
644
+ offset += arr.length;
645
+ }
646
+ return result;
647
+ }
648
+ function concatHex(values) {
649
+ return `0x${values.reduce(
650
+ (acc, x) => acc + x.replace("0x", ""),
651
+ ""
652
+ )}`;
653
+ }
661
654
 
662
- // src/constants/solidity.ts
663
- var panicReasons = {
664
- 1: "An `assert` condition failed.",
665
- 17: "Arithmic operation resulted in underflow or overflow.",
666
- 18: "Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).",
667
- 33: "Attempted to convert to an invalid type.",
668
- 34: "Attempted to access a storage byte array that is incorrectly encoded.",
669
- 49: "Performed `.pop()` on an empty array",
670
- 50: "Array index is out of bounds.",
671
- 65: "Allocated too much memory or created an array which is too large.",
672
- 81: "Attempted to call a zero-initialized variable of internal function type."
673
- };
674
- var solidityError = {
675
- inputs: [
676
- {
677
- name: "message",
678
- type: "string"
679
- }
680
- ],
681
- name: "Error",
682
- type: "error"
683
- };
684
- var solidityPanic = {
685
- inputs: [
686
- {
687
- name: "reason",
688
- type: "uint256"
689
- }
690
- ],
691
- name: "Panic",
692
- type: "error"
693
- };
655
+ // src/utils/data/isBytes.ts
656
+ function isBytes(value) {
657
+ if (!value)
658
+ return false;
659
+ if (typeof value !== "object")
660
+ return false;
661
+ if (!("BYTES_PER_ELEMENT" in value))
662
+ return false;
663
+ return value.BYTES_PER_ELEMENT === 1 && value.constructor.name === "Uint8Array";
664
+ }
694
665
 
695
- // src/constants/unit.ts
696
- var etherUnits = {
697
- gwei: 9,
698
- wei: 18
699
- };
700
- var gweiUnits = {
701
- ether: -9,
702
- wei: 9
703
- };
704
- var weiUnits = {
705
- ether: -18,
706
- gwei: -9
707
- };
666
+ // src/utils/data/isHex.ts
667
+ function isHex(value) {
668
+ if (!value)
669
+ return false;
670
+ if (typeof value !== "string")
671
+ return false;
672
+ return /^0x[0-9a-fA-F]*$/.test(value);
673
+ }
708
674
 
709
- // src/errors/transaction.ts
710
- function prettyPrint(args) {
711
- const entries = Object.entries(args).map(([key, value]) => {
712
- if (value === void 0 || value === false)
713
- return null;
714
- return [key, value];
715
- }).filter(Boolean);
716
- const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0);
717
- return entries.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`).join("\n");
675
+ // src/utils/data/pad.ts
676
+ function pad(hexOrBytes, { dir, size: size2 = 32 } = {}) {
677
+ if (typeof hexOrBytes === "string")
678
+ return padHex(hexOrBytes, { dir, size: size2 });
679
+ return padBytes(hexOrBytes, { dir, size: size2 });
718
680
  }
719
- var FeeConflictError = class extends BaseError {
720
- constructor() {
721
- super(
722
- [
723
- "Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.",
724
- "Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."
725
- ].join("\n")
726
- );
727
- __publicField(this, "name", "FeeConflictError");
728
- }
729
- };
730
- var TransactionExecutionError = class extends BaseError {
731
- constructor(cause, {
732
- account,
733
- docsPath: docsPath6,
734
- chain,
735
- data,
736
- gas,
737
- gasPrice,
738
- maxFeePerGas,
739
- maxPriorityFeePerGas,
740
- nonce,
741
- to,
742
- value
743
- }) {
744
- const prettyArgs = prettyPrint({
745
- chain: chain && `${chain?.name} (id: ${chain?.id})`,
746
- from: account?.address,
747
- to,
748
- value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
749
- data,
750
- gas,
751
- gasPrice: typeof gasPrice !== "undefined" && `${formatGwei(gasPrice)} gwei`,
752
- maxFeePerGas: typeof maxFeePerGas !== "undefined" && `${formatGwei(maxFeePerGas)} gwei`,
753
- maxPriorityFeePerGas: typeof maxPriorityFeePerGas !== "undefined" && `${formatGwei(maxPriorityFeePerGas)} gwei`,
754
- nonce
681
+ function padHex(hex_, { dir, size: size2 = 32 } = {}) {
682
+ if (size2 === null)
683
+ return hex_;
684
+ let hex = hex_.replace("0x", "");
685
+ if (hex.length > size2 * 2)
686
+ throw new SizeExceedsPaddingSizeError({
687
+ size: Math.ceil(hex.length / 2),
688
+ targetSize: size2,
689
+ type: "hex"
755
690
  });
756
- super(cause.shortMessage, {
757
- cause,
758
- docsPath: docsPath6,
759
- metaMessages: [
760
- ...cause.metaMessages ? [...cause.metaMessages, " "] : [],
761
- "Request Arguments:",
762
- prettyArgs
763
- ].filter(Boolean)
691
+ return `0x${hex[dir === "right" ? "padEnd" : "padStart"](
692
+ size2 * 2,
693
+ "0"
694
+ )}`;
695
+ }
696
+ function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
697
+ if (size2 === null)
698
+ return bytes;
699
+ if (bytes.length > size2)
700
+ throw new SizeExceedsPaddingSizeError({
701
+ size: bytes.length,
702
+ targetSize: size2,
703
+ type: "bytes"
764
704
  });
765
- __publicField(this, "cause");
766
- __publicField(this, "name", "TransactionExecutionError");
767
- this.cause = cause;
705
+ const paddedBytes = new Uint8Array(size2);
706
+ for (let i = 0; i < size2; i++) {
707
+ const padEnd = dir === "right";
708
+ paddedBytes[padEnd ? i : size2 - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
768
709
  }
769
- };
770
- var TransactionNotFoundError = class extends BaseError {
771
- constructor({
772
- blockHash,
773
- blockNumber,
774
- blockTag,
775
- hash: hash2,
776
- index
777
- }) {
778
- let identifier = "Transaction";
779
- if (blockTag && index !== void 0)
780
- identifier = `Transaction at block time "${blockTag}" at index "${index}"`;
781
- if (blockHash && index !== void 0)
782
- identifier = `Transaction at block hash "${blockHash}" at index "${index}"`;
783
- if (blockNumber && index !== void 0)
784
- identifier = `Transaction at block number "${blockNumber}" at index "${index}"`;
785
- if (hash2)
786
- identifier = `Transaction with hash "${hash2}"`;
787
- super(`${identifier} could not be found.`);
788
- __publicField(this, "name", "TransactionNotFoundError");
710
+ return paddedBytes;
711
+ }
712
+
713
+ // src/utils/data/trim.ts
714
+ function trim(hexOrBytes, { dir = "left" } = {}) {
715
+ let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
716
+ let sliceLength = 0;
717
+ for (let i = 0; i < data.length - 1; i++) {
718
+ if (data[dir === "left" ? i : data.length - i - 1].toString() === "0")
719
+ sliceLength++;
720
+ else
721
+ break;
722
+ }
723
+ data = dir === "left" ? data.slice(sliceLength) : data.slice(0, data.length - sliceLength);
724
+ if (typeof hexOrBytes === "string") {
725
+ if (data.length === 1 && dir === "right")
726
+ data = `${data}0`;
727
+ return `0x${data}`;
728
+ }
729
+ return data;
730
+ }
731
+
732
+ // src/utils/data/size.ts
733
+ function size(value) {
734
+ if (isHex(value))
735
+ return Math.ceil((value.length - 2) / 2);
736
+ return value.length;
737
+ }
738
+
739
+ // src/utils/data/slice.ts
740
+ function slice(value, start, end) {
741
+ if (isHex(value))
742
+ return sliceHex(value, start, end);
743
+ return sliceBytes(value, start, end);
744
+ }
745
+ function assertStartOffset(value, start) {
746
+ if (typeof start === "number" && start > 0 && start > size(value) - 1)
747
+ throw new Error(
748
+ `Slice starting at offset "${start}" is out-of-bounds (size: ${size(
749
+ value
750
+ )}).`
751
+ );
752
+ }
753
+ function sliceBytes(value, start, end) {
754
+ assertStartOffset(value, start);
755
+ return value.slice(start, end);
756
+ }
757
+ function sliceHex(value_, start, end) {
758
+ assertStartOffset(value_, start);
759
+ const value = value_.replace("0x", "").slice((start ?? 0) * 2, (end ?? value_.length) * 2);
760
+ return `0x${value}`;
761
+ }
762
+
763
+ // src/utils/encoding/toHex.ts
764
+ var hexes = Array.from(
765
+ { length: 256 },
766
+ (_v, i) => i.toString(16).padStart(2, "0")
767
+ );
768
+ function boolToHex(value) {
769
+ return `0x${Number(value)}`;
770
+ }
771
+ function bytesToHex(value) {
772
+ let hex = "";
773
+ for (let i = 0; i < value.length; i++) {
774
+ hex += hexes[value[i]];
775
+ }
776
+ return `0x${hex}`;
777
+ }
778
+ function toHex(value) {
779
+ if (typeof value === "number" || typeof value === "bigint")
780
+ return numberToHex(value);
781
+ if (typeof value === "string") {
782
+ return stringToHex(value);
783
+ }
784
+ if (typeof value === "boolean")
785
+ return boolToHex(value);
786
+ return bytesToHex(value);
787
+ }
788
+ function numberToHex(value_, opts = {}) {
789
+ const { signed, size: size2 } = opts;
790
+ let value = BigInt(value_);
791
+ let maxValue;
792
+ if (size2) {
793
+ if (signed)
794
+ maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n;
795
+ else
796
+ maxValue = 2n ** (BigInt(size2) * 8n) - 1n;
797
+ } else if (typeof value_ === "number") {
798
+ maxValue = BigInt(Number.MAX_SAFE_INTEGER);
799
+ }
800
+ const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
801
+ if (maxValue && value > maxValue || value < minValue) {
802
+ const suffix = typeof value_ === "bigint" ? "n" : "";
803
+ throw new IntegerOutOfRangeError({
804
+ max: maxValue ? `${maxValue}${suffix}` : void 0,
805
+ min: `${minValue}${suffix}`,
806
+ signed,
807
+ size: size2,
808
+ value: `${value_}${suffix}`
809
+ });
810
+ }
811
+ const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
812
+ if (size2)
813
+ return pad(hex, { size: size2 });
814
+ return hex;
815
+ }
816
+ var encoder = new TextEncoder();
817
+ function stringToHex(value_) {
818
+ const value = encoder.encode(value_);
819
+ return toHex(value);
820
+ }
821
+
822
+ // src/utils/encoding/toBytes.ts
823
+ var encoder2 = new TextEncoder();
824
+ function toBytes(value) {
825
+ if (typeof value === "number" || typeof value === "bigint")
826
+ return numberToBytes(value);
827
+ if (typeof value === "boolean")
828
+ return boolToBytes(value);
829
+ if (value.startsWith("0x"))
830
+ return hexToBytes(value);
831
+ return stringToBytes(value);
832
+ }
833
+ function boolToBytes(value) {
834
+ const bytes = new Uint8Array(1);
835
+ bytes[0] = Number(value);
836
+ return bytes;
837
+ }
838
+ function hexToBytes(hex_) {
839
+ let hex = hex_.slice(2);
840
+ if (hex.length % 2)
841
+ hex = `0${hex}`;
842
+ const bytes = new Uint8Array(hex.length / 2);
843
+ for (let index = 0; index < bytes.length; index++) {
844
+ const start = index * 2;
845
+ const hexByte = hex.slice(start, start + 2);
846
+ const byte = Number.parseInt(hexByte, 16);
847
+ if (Number.isNaN(byte) || byte < 0)
848
+ throw new BaseError(`Invalid byte sequence ("${hexByte}" in "${hex}").`);
849
+ bytes[index] = byte;
850
+ }
851
+ return bytes;
852
+ }
853
+ function numberToBytes(value, opts) {
854
+ const hex = numberToHex(value, opts);
855
+ return hexToBytes(hex);
856
+ }
857
+ function stringToBytes(value) {
858
+ return encoder2.encode(value);
859
+ }
860
+
861
+ // src/utils/encoding/toRlp.ts
862
+ function toRlp(hexOrBytes, to_) {
863
+ const to = to_ || "hex";
864
+ return format(bytesToRlp(parse(hexOrBytes)), to);
865
+ }
866
+ function parse(hexOrBytes) {
867
+ if (Array.isArray(hexOrBytes))
868
+ return hexOrBytes.map(parse);
869
+ return typeof hexOrBytes === "string" ? toBytes(hexOrBytes) : hexOrBytes;
870
+ }
871
+ function format(bytes, type = "bytes") {
872
+ return type === "hex" ? bytesToHex(bytes) : bytes;
873
+ }
874
+ function bytesToRlp(bytes) {
875
+ if (Array.isArray(bytes)) {
876
+ const encoded = concat(bytes.map(bytesToRlp));
877
+ return new Uint8Array([...encodeLength(encoded.length, 192), ...encoded]);
878
+ }
879
+ if (bytes.length === 1 && bytes[0] < 128)
880
+ return bytes;
881
+ return new Uint8Array([...encodeLength(bytes.length, 128), ...bytes]);
882
+ }
883
+ function encodeLength(length, offset) {
884
+ if (length < 56)
885
+ return [offset + length];
886
+ return [toBytes(length).length + offset + 55, ...toBytes(length)];
887
+ }
888
+
889
+ // src/utils/encoding/fromHex.ts
890
+ function fromHex(hex, to) {
891
+ if (to === "number")
892
+ return hexToNumber(hex);
893
+ if (to === "bigint")
894
+ return hexToBigInt(hex);
895
+ if (to === "string")
896
+ return hexToString(hex);
897
+ if (to === "boolean")
898
+ return hexToBool(hex);
899
+ return hexToBytes(hex);
900
+ }
901
+ function hexToBigInt(hex, opts = {}) {
902
+ const { signed } = opts;
903
+ const value = BigInt(hex);
904
+ if (!signed)
905
+ return value;
906
+ const size2 = (hex.length - 2) / 2;
907
+ const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
908
+ if (value <= max)
909
+ return value;
910
+ return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
911
+ }
912
+ function hexToBool(hex) {
913
+ if (trim(hex) === "0x0")
914
+ return false;
915
+ if (trim(hex) === "0x1")
916
+ return true;
917
+ throw new InvalidHexBooleanError(hex);
918
+ }
919
+ function hexToNumber(hex, opts = {}) {
920
+ return Number(hexToBigInt(hex, opts));
921
+ }
922
+ function hexToString(hex) {
923
+ const bytes = hexToBytes(hex);
924
+ return new TextDecoder().decode(bytes);
925
+ }
926
+
927
+ // src/utils/encoding/fromBytes.ts
928
+ function fromBytes(bytes, to) {
929
+ if (to === "number")
930
+ return bytesToNumber(bytes);
931
+ if (to === "bigint")
932
+ return bytesToBigint(bytes);
933
+ if (to === "boolean")
934
+ return bytesToBool(bytes);
935
+ if (to === "string")
936
+ return bytesToString(bytes);
937
+ return bytesToHex(bytes);
938
+ }
939
+ function bytesToBigint(bytes) {
940
+ const hex = bytesToHex(bytes);
941
+ return hexToBigInt(hex);
942
+ }
943
+ function bytesToBool(bytes) {
944
+ if (bytes.length > 1 || bytes[0] > 1)
945
+ throw new InvalidBytesBooleanError(bytes);
946
+ return Boolean(bytes[0]);
947
+ }
948
+ function bytesToNumber(bytes) {
949
+ const hex = bytesToHex(bytes);
950
+ return hexToNumber(hex);
951
+ }
952
+ function bytesToString(bytes) {
953
+ return new TextDecoder().decode(bytes);
954
+ }
955
+
956
+ // src/utils/encoding/fromRlp.ts
957
+ function fromRlp(value, to) {
958
+ const bytes = parse2(value);
959
+ const [data, consumed] = rlpToBytes(bytes);
960
+ if (consumed < bytes.length)
961
+ throw new DataLengthTooLongError({
962
+ consumed,
963
+ length: bytes.length
964
+ });
965
+ return format2(data, to);
966
+ }
967
+ function parse2(value) {
968
+ if (typeof value === "string") {
969
+ if (value.length > 3 && value.length % 2 !== 0)
970
+ throw new InvalidHexValueError(value);
971
+ return hexToBytes(value);
972
+ }
973
+ return value;
974
+ }
975
+ function format2(bytes, to) {
976
+ if (Array.isArray(bytes))
977
+ return bytes.map((b) => format2(b, to));
978
+ return to === "hex" ? trim(bytesToHex(bytes)) : bytes;
979
+ }
980
+ function rlpToBytes(bytes, offset = 0) {
981
+ if (bytes.length === 0)
982
+ return [new Uint8Array([]), 0];
983
+ const prefix = bytes[offset];
984
+ if (prefix <= 127)
985
+ return [new Uint8Array([bytes[offset]]), 1];
986
+ if (prefix <= 183) {
987
+ const length2 = prefix - 128;
988
+ const offset_ = offset + 1;
989
+ if (offset_ + length2 > bytes.length)
990
+ throw new DataLengthTooShortError({
991
+ length: offset_ + length2,
992
+ dataLength: bytes.length
993
+ });
994
+ return [bytes.slice(offset_, offset_ + length2), 1 + length2];
995
+ }
996
+ if (prefix <= 191) {
997
+ const lengthOfLength2 = prefix - 183;
998
+ const offset_ = offset + 1;
999
+ const length2 = bytesToNumber(bytes.slice(offset_, offset_ + lengthOfLength2));
1000
+ if (offset_ + lengthOfLength2 + length2 > bytes.length)
1001
+ throw new DataLengthTooShortError({
1002
+ length: lengthOfLength2 + length2,
1003
+ dataLength: bytes.length - lengthOfLength2
1004
+ });
1005
+ return [
1006
+ bytes.slice(offset_ + lengthOfLength2, offset_ + lengthOfLength2 + length2),
1007
+ 1 + lengthOfLength2 + length2
1008
+ ];
1009
+ }
1010
+ let lengthOfLength = 0;
1011
+ let length = prefix - 192;
1012
+ if (prefix > 247) {
1013
+ lengthOfLength = prefix - 247;
1014
+ length = bytesToNumber(bytes.slice(offset + 1, offset + 1 + lengthOfLength));
1015
+ }
1016
+ let nextOffset = offset + 1 + lengthOfLength;
1017
+ if (nextOffset > bytes.length)
1018
+ throw new DataLengthTooShortError({
1019
+ length: nextOffset,
1020
+ dataLength: bytes.length
1021
+ });
1022
+ let consumed = 1 + lengthOfLength + length;
1023
+ let result = [];
1024
+ while (nextOffset < offset + consumed) {
1025
+ const decoded = rlpToBytes(bytes, nextOffset);
1026
+ result.push(decoded[0]);
1027
+ nextOffset += decoded[1];
1028
+ if (nextOffset > offset + consumed)
1029
+ throw new OffsetOutOfBoundsError({
1030
+ nextOffset,
1031
+ offset: offset + consumed
1032
+ });
1033
+ }
1034
+ return [result, consumed];
1035
+ }
1036
+
1037
+ // src/utils/contract/extractFunctionParts.ts
1038
+ var paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/;
1039
+ function extractFunctionParts(def) {
1040
+ const parts = def.match(paramsRegex);
1041
+ const type = parts?.[2] || void 0;
1042
+ const name = parts?.[3];
1043
+ const params = parts?.[5] || void 0;
1044
+ return { type, name, params };
1045
+ }
1046
+ function extractFunctionName(def) {
1047
+ return extractFunctionParts(def).name;
1048
+ }
1049
+ function extractFunctionParams(def) {
1050
+ const params = extractFunctionParts(def).params;
1051
+ const splitParams = params?.split(",").map((x) => x.trim().split(" "));
1052
+ return splitParams?.map((param) => ({
1053
+ type: param[0],
1054
+ name: param[1] === "indexed" ? param[2] : param[1],
1055
+ ...param[1] === "indexed" ? { indexed: true } : {}
1056
+ }));
1057
+ }
1058
+ function extractFunctionType(def) {
1059
+ return extractFunctionParts(def).type;
1060
+ }
1061
+
1062
+ // src/utils/hash/keccak256.ts
1063
+ import { keccak_256 } from "@noble/hashes/sha3";
1064
+ function keccak256(value, to_) {
1065
+ const to = to_ || "hex";
1066
+ const bytes = keccak_256(isHex(value) ? toBytes(value) : value);
1067
+ if (to === "bytes")
1068
+ return bytes;
1069
+ return toHex(bytes);
1070
+ }
1071
+
1072
+ // src/utils/hash/hashFunction.ts
1073
+ var hash = (value) => keccak256(toBytes(value));
1074
+ function hashFunction(def) {
1075
+ const name = extractFunctionName(def);
1076
+ const params = extractFunctionParams(def);
1077
+ if (!params || params.length === 0)
1078
+ return hash(def.replace(/ /g, ""));
1079
+ return hash(`${name}(${params.map(({ type }) => type).join(",")})`);
1080
+ }
1081
+
1082
+ // src/utils/hash/getEventSelector.ts
1083
+ var getEventSelector = (event) => hashFunction(event);
1084
+
1085
+ // src/utils/hash/getFunctionSelector.ts
1086
+ var getFunctionSelector = (fn) => slice(hashFunction(fn), 0, 4);
1087
+
1088
+ // src/utils/address/isAddress.ts
1089
+ var addressRegex = /^0x[a-fA-F0-9]{40}$/;
1090
+ function isAddress(address) {
1091
+ return addressRegex.test(address);
1092
+ }
1093
+
1094
+ // src/utils/address/getAddress.ts
1095
+ function checksumAddress(address_) {
1096
+ const hexAddress = address_.substring(2).toLowerCase();
1097
+ const hash2 = keccak256(stringToBytes(hexAddress), "bytes");
1098
+ let address = hexAddress.split("");
1099
+ for (let i = 0; i < 40; i += 2) {
1100
+ if (hash2[i >> 1] >> 4 >= 8 && address[i]) {
1101
+ address[i] = address[i].toUpperCase();
1102
+ }
1103
+ if ((hash2[i >> 1] & 15) >= 8 && address[i + 1]) {
1104
+ address[i + 1] = address[i + 1].toUpperCase();
1105
+ }
1106
+ }
1107
+ return `0x${address.join("")}`;
1108
+ }
1109
+ function getAddress(address) {
1110
+ if (!isAddress(address))
1111
+ throw new InvalidAddressError({ address });
1112
+ return checksumAddress(address);
1113
+ }
1114
+
1115
+ // src/utils/address/getContractAddress.ts
1116
+ function getContractAddress2(opts) {
1117
+ if (opts.opcode === "CREATE2")
1118
+ return getCreate2Address(opts);
1119
+ return getCreateAddress(opts);
1120
+ }
1121
+ function getCreateAddress(opts) {
1122
+ const from = toBytes(getAddress(opts.from));
1123
+ let nonce = toBytes(opts.nonce);
1124
+ if (nonce[0] === 0)
1125
+ nonce = new Uint8Array([]);
1126
+ return getAddress(
1127
+ `0x${keccak256(toRlp([from, nonce], "bytes")).slice(26)}`
1128
+ );
1129
+ }
1130
+ function getCreate2Address(opts) {
1131
+ const from = toBytes(getAddress(opts.from));
1132
+ const salt = pad(isBytes(opts.salt) ? opts.salt : toBytes(opts.salt), {
1133
+ size: 32
1134
+ });
1135
+ const bytecodeHash = toBytes(
1136
+ keccak256(
1137
+ isBytes(opts.bytecode) ? opts.bytecode : toBytes(opts.bytecode)
1138
+ )
1139
+ );
1140
+ return getAddress(
1141
+ slice(keccak256(concat([toBytes("0xff"), from, salt, bytecodeHash])), 12)
1142
+ );
1143
+ }
1144
+
1145
+ // src/utils/address/isAddressEqual.ts
1146
+ function isAddressEqual(a, b) {
1147
+ if (!isAddress(a))
1148
+ throw new InvalidAddressError({ address: a });
1149
+ if (!isAddress(b))
1150
+ throw new InvalidAddressError({ address: b });
1151
+ return a.toLowerCase() === b.toLowerCase();
1152
+ }
1153
+
1154
+ // src/accounts/toAccount.ts
1155
+ function toAccount(source) {
1156
+ if (typeof source === "string") {
1157
+ if (!isAddress(source))
1158
+ throw new InvalidAddressError({ address: source });
1159
+ return {
1160
+ address: source,
1161
+ type: "json-rpc"
1162
+ };
1163
+ }
1164
+ if (!isAddress(source.address))
1165
+ throw new InvalidAddressError({ address: source.address });
1166
+ return {
1167
+ address: source.address,
1168
+ signMessage: source.signMessage,
1169
+ signTransaction: source.signTransaction,
1170
+ signTypedData: source.signTypedData,
1171
+ source: "custom",
1172
+ type: "local"
1173
+ };
1174
+ }
1175
+
1176
+ // src/constants/abis.ts
1177
+ var multicall3Abi = [
1178
+ {
1179
+ inputs: [
1180
+ {
1181
+ components: [
1182
+ {
1183
+ name: "target",
1184
+ type: "address"
1185
+ },
1186
+ {
1187
+ name: "allowFailure",
1188
+ type: "bool"
1189
+ },
1190
+ {
1191
+ name: "callData",
1192
+ type: "bytes"
1193
+ }
1194
+ ],
1195
+ name: "calls",
1196
+ type: "tuple[]"
1197
+ }
1198
+ ],
1199
+ name: "aggregate3",
1200
+ outputs: [
1201
+ {
1202
+ components: [
1203
+ {
1204
+ name: "success",
1205
+ type: "bool"
1206
+ },
1207
+ {
1208
+ name: "returnData",
1209
+ type: "bytes"
1210
+ }
1211
+ ],
1212
+ name: "returnData",
1213
+ type: "tuple[]"
1214
+ }
1215
+ ],
1216
+ stateMutability: "view",
1217
+ type: "function"
1218
+ }
1219
+ ];
1220
+
1221
+ // src/constants/solidity.ts
1222
+ var panicReasons = {
1223
+ 1: "An `assert` condition failed.",
1224
+ 17: "Arithmic operation resulted in underflow or overflow.",
1225
+ 18: "Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).",
1226
+ 33: "Attempted to convert to an invalid type.",
1227
+ 34: "Attempted to access a storage byte array that is incorrectly encoded.",
1228
+ 49: "Performed `.pop()` on an empty array",
1229
+ 50: "Array index is out of bounds.",
1230
+ 65: "Allocated too much memory or created an array which is too large.",
1231
+ 81: "Attempted to call a zero-initialized variable of internal function type."
1232
+ };
1233
+ var solidityError = {
1234
+ inputs: [
1235
+ {
1236
+ name: "message",
1237
+ type: "string"
1238
+ }
1239
+ ],
1240
+ name: "Error",
1241
+ type: "error"
1242
+ };
1243
+ var solidityPanic = {
1244
+ inputs: [
1245
+ {
1246
+ name: "reason",
1247
+ type: "uint256"
1248
+ }
1249
+ ],
1250
+ name: "Panic",
1251
+ type: "error"
1252
+ };
1253
+
1254
+ // src/constants/unit.ts
1255
+ var etherUnits = {
1256
+ gwei: 9,
1257
+ wei: 18
1258
+ };
1259
+ var gweiUnits = {
1260
+ ether: -9,
1261
+ wei: 9
1262
+ };
1263
+ var weiUnits = {
1264
+ ether: -18,
1265
+ gwei: -9
1266
+ };
1267
+
1268
+ // src/errors/transaction.ts
1269
+ function prettyPrint(args) {
1270
+ const entries = Object.entries(args).map(([key, value]) => {
1271
+ if (value === void 0 || value === false)
1272
+ return null;
1273
+ return [key, value];
1274
+ }).filter(Boolean);
1275
+ const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0);
1276
+ return entries.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`).join("\n");
1277
+ }
1278
+ var FeeConflictError = class extends BaseError {
1279
+ constructor() {
1280
+ super(
1281
+ [
1282
+ "Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.",
1283
+ "Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."
1284
+ ].join("\n")
1285
+ );
1286
+ __publicField(this, "name", "FeeConflictError");
1287
+ }
1288
+ };
1289
+ var TransactionExecutionError = class extends BaseError {
1290
+ constructor(cause, {
1291
+ account,
1292
+ docsPath: docsPath6,
1293
+ chain,
1294
+ data,
1295
+ gas,
1296
+ gasPrice,
1297
+ maxFeePerGas,
1298
+ maxPriorityFeePerGas,
1299
+ nonce,
1300
+ to,
1301
+ value
1302
+ }) {
1303
+ const prettyArgs = prettyPrint({
1304
+ chain: chain && `${chain?.name} (id: ${chain?.id})`,
1305
+ from: account?.address,
1306
+ to,
1307
+ value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
1308
+ data,
1309
+ gas,
1310
+ gasPrice: typeof gasPrice !== "undefined" && `${formatGwei(gasPrice)} gwei`,
1311
+ maxFeePerGas: typeof maxFeePerGas !== "undefined" && `${formatGwei(maxFeePerGas)} gwei`,
1312
+ maxPriorityFeePerGas: typeof maxPriorityFeePerGas !== "undefined" && `${formatGwei(maxPriorityFeePerGas)} gwei`,
1313
+ nonce
1314
+ });
1315
+ super(cause.shortMessage, {
1316
+ cause,
1317
+ docsPath: docsPath6,
1318
+ metaMessages: [
1319
+ ...cause.metaMessages ? [...cause.metaMessages, " "] : [],
1320
+ "Request Arguments:",
1321
+ prettyArgs
1322
+ ].filter(Boolean)
1323
+ });
1324
+ __publicField(this, "cause");
1325
+ __publicField(this, "name", "TransactionExecutionError");
1326
+ this.cause = cause;
1327
+ }
1328
+ };
1329
+ var TransactionNotFoundError = class extends BaseError {
1330
+ constructor({
1331
+ blockHash,
1332
+ blockNumber,
1333
+ blockTag,
1334
+ hash: hash2,
1335
+ index
1336
+ }) {
1337
+ let identifier = "Transaction";
1338
+ if (blockTag && index !== void 0)
1339
+ identifier = `Transaction at block time "${blockTag}" at index "${index}"`;
1340
+ if (blockHash && index !== void 0)
1341
+ identifier = `Transaction at block hash "${blockHash}" at index "${index}"`;
1342
+ if (blockNumber && index !== void 0)
1343
+ identifier = `Transaction at block number "${blockNumber}" at index "${index}"`;
1344
+ if (hash2)
1345
+ identifier = `Transaction with hash "${hash2}"`;
1346
+ super(`${identifier} could not be found.`);
1347
+ __publicField(this, "name", "TransactionNotFoundError");
789
1348
  }
790
1349
  };
791
1350
  var TransactionReceiptNotFoundError = class extends BaseError {
@@ -1094,929 +1653,404 @@ var FilterTypeNotSupportedError = class extends BaseError {
1094
1653
  super(`Filter type "${type}" is not supported.`);
1095
1654
  __publicField(this, "name", "FilterTypeNotSupportedError");
1096
1655
  }
1097
- };
1098
-
1099
- // src/errors/node.ts
1100
- var ExecutionRevertedError = class extends BaseError {
1101
- constructor({
1102
- cause,
1103
- message
1104
- } = {}) {
1105
- const reason = message?.replace("execution reverted: ", "")?.replace("execution reverted", "");
1106
- super(
1107
- `Execution reverted ${reason ? `with reason: ${reason}` : "for an unknown reason"}.`,
1108
- {
1109
- cause
1110
- }
1111
- );
1112
- __publicField(this, "name", "ExecutionRevertedError");
1113
- }
1114
- };
1115
- __publicField(ExecutionRevertedError, "code", 3);
1116
- __publicField(ExecutionRevertedError, "nodeMessage", /execution reverted/);
1117
- var FeeCapTooHighError = class extends BaseError {
1118
- constructor({
1119
- cause,
1120
- maxFeePerGas
1121
- } = {}) {
1122
- super(
1123
- `The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`,
1124
- {
1125
- cause
1126
- }
1127
- );
1128
- __publicField(this, "name", "FeeCapTooHigh");
1129
- }
1130
- };
1131
- __publicField(FeeCapTooHighError, "nodeMessage", /max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/);
1132
- var FeeCapTooLowError = class extends BaseError {
1133
- constructor({
1134
- cause,
1135
- maxFeePerGas
1136
- } = {}) {
1137
- super(
1138
- `The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)}` : ""} gwei) cannot be lower than the block base fee.`,
1139
- {
1140
- cause
1141
- }
1142
- );
1143
- __publicField(this, "name", "FeeCapTooLow");
1144
- }
1145
- };
1146
- __publicField(FeeCapTooLowError, "nodeMessage", /max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/);
1147
- var NonceTooHighError = class extends BaseError {
1148
- constructor({ cause, nonce } = {}) {
1149
- super(
1150
- `Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is higher than the next one expected.`,
1151
- { cause }
1152
- );
1153
- __publicField(this, "name", "NonceTooHighError");
1154
- }
1155
- };
1156
- __publicField(NonceTooHighError, "nodeMessage", /nonce too high/);
1157
- var NonceTooLowError = class extends BaseError {
1158
- constructor({ cause, nonce } = {}) {
1159
- super(
1160
- [
1161
- `Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is lower than the current nonce of the account.`,
1162
- "Try increasing the nonce or find the latest nonce with `getTransactionCount`."
1163
- ].join("\n"),
1164
- { cause }
1165
- );
1166
- __publicField(this, "name", "NonceTooLowError");
1167
- }
1168
- };
1169
- __publicField(NonceTooLowError, "nodeMessage", /nonce too low|transaction already imported/);
1170
- var NonceMaxValueError = class extends BaseError {
1171
- constructor({ cause, nonce } = {}) {
1172
- super(
1173
- `Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}exceeds the maximum allowed nonce.`,
1174
- { cause }
1175
- );
1176
- __publicField(this, "name", "NonceMaxValueError");
1177
- }
1178
- };
1179
- __publicField(NonceMaxValueError, "nodeMessage", /nonce has max value/);
1180
- var InsufficientFundsError = class extends BaseError {
1181
- constructor({ cause } = {}) {
1182
- super(
1183
- [
1184
- "The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."
1185
- ].join("\n"),
1186
- {
1187
- cause,
1188
- metaMessages: [
1189
- "This error could arise when the account does not have enough funds to:",
1190
- " - pay for the total gas fee,",
1191
- " - pay for the value to send.",
1192
- " ",
1193
- "The cost of the transaction is calculated as `gas * gas fee + value`, where:",
1194
- " - `gas` is the amount of gas needed for transaction to execute,",
1195
- " - `gas fee` is the gas fee,",
1196
- " - `value` is the amount of ether to send to the recipient."
1197
- ]
1198
- }
1199
- );
1200
- __publicField(this, "name", "InsufficientFundsError");
1201
- }
1202
- };
1203
- __publicField(InsufficientFundsError, "nodeMessage", /insufficient funds/);
1204
- var IntrinsicGasTooHighError = class extends BaseError {
1205
- constructor({ cause, gas } = {}) {
1656
+ };
1657
+
1658
+ // src/errors/node.ts
1659
+ var ExecutionRevertedError = class extends BaseError {
1660
+ constructor({
1661
+ cause,
1662
+ message
1663
+ } = {}) {
1664
+ const reason = message?.replace("execution reverted: ", "")?.replace("execution reverted", "");
1206
1665
  super(
1207
- `The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction exceeds the limit allowed for the block.`,
1666
+ `Execution reverted ${reason ? `with reason: ${reason}` : "for an unknown reason"}.`,
1208
1667
  {
1209
1668
  cause
1210
1669
  }
1211
1670
  );
1212
- __publicField(this, "name", "IntrinsicGasTooHighError");
1671
+ __publicField(this, "name", "ExecutionRevertedError");
1213
1672
  }
1214
1673
  };
1215
- __publicField(IntrinsicGasTooHighError, "nodeMessage", /intrinsic gas too high|gas limit reached/);
1216
- var IntrinsicGasTooLowError = class extends BaseError {
1217
- constructor({ cause, gas } = {}) {
1674
+ __publicField(ExecutionRevertedError, "code", 3);
1675
+ __publicField(ExecutionRevertedError, "nodeMessage", /execution reverted/);
1676
+ var FeeCapTooHighError = class extends BaseError {
1677
+ constructor({
1678
+ cause,
1679
+ maxFeePerGas
1680
+ } = {}) {
1218
1681
  super(
1219
- `The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction is too low.`,
1682
+ `The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`,
1220
1683
  {
1221
1684
  cause
1222
1685
  }
1223
1686
  );
1224
- __publicField(this, "name", "IntrinsicGasTooLowError");
1225
- }
1226
- };
1227
- __publicField(IntrinsicGasTooLowError, "nodeMessage", /intrinsic gas too low/);
1228
- var TransactionTypeNotSupportedError = class extends BaseError {
1229
- constructor({ cause }) {
1230
- super("The transaction type is not supported for this chain.", {
1231
- cause
1232
- });
1233
- __publicField(this, "name", "TransactionTypeNotSupportedError");
1687
+ __publicField(this, "name", "FeeCapTooHigh");
1234
1688
  }
1235
1689
  };
1236
- __publicField(TransactionTypeNotSupportedError, "nodeMessage", /transaction type not valid/);
1237
- var TipAboveFeeCapError = class extends BaseError {
1690
+ __publicField(FeeCapTooHighError, "nodeMessage", /max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/);
1691
+ var FeeCapTooLowError = class extends BaseError {
1238
1692
  constructor({
1239
1693
  cause,
1240
- maxPriorityFeePerGas,
1241
1694
  maxFeePerGas
1242
1695
  } = {}) {
1243
1696
  super(
1244
- [
1245
- `The provided tip (\`maxPriorityFeePerGas\`${maxPriorityFeePerGas ? ` = ${formatGwei(maxPriorityFeePerGas)} gwei` : ""}) cannot be higher than the fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}).`
1246
- ].join("\n"),
1697
+ `The fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)}` : ""} gwei) cannot be lower than the block base fee.`,
1247
1698
  {
1248
1699
  cause
1249
1700
  }
1250
1701
  );
1251
- __publicField(this, "name", "TipAboveFeeCapError");
1252
- }
1253
- };
1254
- __publicField(TipAboveFeeCapError, "nodeMessage", /max priority fee per gas higher than max fee per gas|tip higher than fee cap/);
1255
- var UnknownNodeError = class extends BaseError {
1256
- constructor({ cause }) {
1257
- super(`An error occurred while executing: ${cause?.message}`, {
1258
- cause
1259
- });
1260
- __publicField(this, "name", "UnknownNodeError");
1261
- }
1262
- };
1263
-
1264
- // src/errors/request.ts
1265
- var RequestError = class extends BaseError {
1266
- constructor(err, {
1267
- docsPath: docsPath6,
1268
- metaMessages,
1269
- shortMessage
1270
- }) {
1271
- super(shortMessage, {
1272
- cause: err,
1273
- docsPath: docsPath6,
1274
- metaMessages
1275
- });
1276
- this.name = err.name;
1277
- }
1278
- };
1279
- var RpcRequestError = class extends RequestError {
1280
- constructor(err, { docsPath: docsPath6, shortMessage }) {
1281
- super(err, { docsPath: docsPath6, metaMessages: err.metaMessages, shortMessage });
1282
- __publicField(this, "code");
1283
- this.code = err.code;
1284
- this.name = err.name;
1285
- }
1286
- };
1287
- var ParseRpcError = class extends RpcRequestError {
1288
- constructor(err) {
1289
- super(err, {
1290
- shortMessage: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."
1291
- });
1292
- __publicField(this, "name", "ParseRpcError");
1293
- __publicField(this, "code", -32700);
1294
- }
1295
- };
1296
- var InvalidRequestRpcError = class extends RpcRequestError {
1297
- constructor(err) {
1298
- super(err, { shortMessage: "JSON is not a valid request object." });
1299
- __publicField(this, "name", "InvalidRequestRpcError");
1300
- __publicField(this, "code", -32600);
1301
- }
1302
- };
1303
- var MethodNotFoundRpcError = class extends RpcRequestError {
1304
- constructor(err) {
1305
- super(err, {
1306
- shortMessage: "The method does not exist / is not available."
1307
- });
1308
- __publicField(this, "name", "MethodNotFoundRpcError");
1309
- __publicField(this, "code", -32601);
1310
- }
1311
- };
1312
- var InvalidParamsRpcError = class extends RpcRequestError {
1313
- constructor(err) {
1314
- super(err, {
1315
- shortMessage: [
1316
- "Invalid parameters were provided to the RPC method.",
1317
- "Double check you have provided the correct parameters."
1318
- ].join("\n")
1319
- });
1320
- __publicField(this, "name", "InvalidParamsRpcError");
1321
- __publicField(this, "code", -32602);
1322
- }
1323
- };
1324
- var InternalRpcError = class extends RpcRequestError {
1325
- constructor(err) {
1326
- super(err, { shortMessage: "An internal error was received." });
1327
- __publicField(this, "name", "InternalRpcError");
1328
- __publicField(this, "code", -32603);
1329
- }
1330
- };
1331
- var InvalidInputRpcError = class extends RpcRequestError {
1332
- constructor(err) {
1333
- super(err, {
1334
- shortMessage: [
1335
- "Missing or invalid parameters.",
1336
- "Double check you have provided the correct parameters."
1337
- ].join("\n")
1338
- });
1339
- __publicField(this, "name", "InvalidInputRpcError");
1340
- __publicField(this, "code", -32e3);
1341
- }
1342
- };
1343
- var ResourceNotFoundRpcError = class extends RpcRequestError {
1344
- constructor(err) {
1345
- super(err, { shortMessage: "Requested resource not found." });
1346
- __publicField(this, "name", "ResourceNotFoundRpcError");
1347
- __publicField(this, "code", -32001);
1348
- }
1349
- };
1350
- var ResourceUnavailableRpcError = class extends RpcRequestError {
1351
- constructor(err) {
1352
- super(err, { shortMessage: "Requested resource not available." });
1353
- __publicField(this, "name", "ResourceUnavailableRpcError");
1354
- __publicField(this, "code", -32002);
1355
- }
1356
- };
1357
- var TransactionRejectedRpcError = class extends RpcRequestError {
1358
- constructor(err) {
1359
- super(err, { shortMessage: "Transaction creation failed." });
1360
- __publicField(this, "name", "TransactionRejectedRpcError");
1361
- __publicField(this, "code", -32003);
1362
- }
1363
- };
1364
- var MethodNotSupportedRpcError = class extends RpcRequestError {
1365
- constructor(err) {
1366
- super(err, { shortMessage: "Method is not implemented." });
1367
- __publicField(this, "name", "MethodNotSupportedRpcError");
1368
- __publicField(this, "code", -32004);
1369
- }
1370
- };
1371
- var LimitExceededRpcError = class extends RpcRequestError {
1372
- constructor(err) {
1373
- super(err, { shortMessage: "Request exceeds defined limit." });
1374
- __publicField(this, "name", "LimitExceededRpcError");
1375
- __publicField(this, "code", -32005);
1376
- }
1377
- };
1378
- var JsonRpcVersionUnsupportedError = class extends RpcRequestError {
1379
- constructor(err) {
1380
- super(err, {
1381
- shortMessage: "Version of JSON-RPC protocol is not supported."
1382
- });
1383
- __publicField(this, "name", "JsonRpcVersionUnsupportedError");
1384
- __publicField(this, "code", -32006);
1702
+ __publicField(this, "name", "FeeCapTooLow");
1385
1703
  }
1386
1704
  };
1387
- var UserRejectedRequestError = class extends RpcRequestError {
1388
- constructor(err) {
1389
- super(err, {
1390
- shortMessage: "User rejected the request."
1391
- });
1392
- __publicField(this, "name", "UserRejectedRequestError");
1393
- __publicField(this, "code", 4001);
1705
+ __publicField(FeeCapTooLowError, "nodeMessage", /max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/);
1706
+ var NonceTooHighError = class extends BaseError {
1707
+ constructor({ cause, nonce } = {}) {
1708
+ super(
1709
+ `Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is higher than the next one expected.`,
1710
+ { cause }
1711
+ );
1712
+ __publicField(this, "name", "NonceTooHighError");
1394
1713
  }
1395
1714
  };
1396
- var SwitchChainError = class extends RpcRequestError {
1397
- constructor(err) {
1398
- super(err, {
1399
- shortMessage: "An error occurred when attempting to switch chain."
1400
- });
1401
- __publicField(this, "name", "SwitchChainError");
1402
- __publicField(this, "code", 4902);
1715
+ __publicField(NonceTooHighError, "nodeMessage", /nonce too high/);
1716
+ var NonceTooLowError = class extends BaseError {
1717
+ constructor({ cause, nonce } = {}) {
1718
+ super(
1719
+ [
1720
+ `Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}is lower than the current nonce of the account.`,
1721
+ "Try increasing the nonce or find the latest nonce with `getTransactionCount`."
1722
+ ].join("\n"),
1723
+ { cause }
1724
+ );
1725
+ __publicField(this, "name", "NonceTooLowError");
1403
1726
  }
1404
1727
  };
1405
- var UnknownRpcError = class extends RequestError {
1406
- constructor(err) {
1407
- super(err, {
1408
- shortMessage: "An unknown RPC error occurred."
1409
- });
1410
- __publicField(this, "name", "UnknownRpcError");
1728
+ __publicField(NonceTooLowError, "nodeMessage", /nonce too low|transaction already imported/);
1729
+ var NonceMaxValueError = class extends BaseError {
1730
+ constructor({ cause, nonce } = {}) {
1731
+ super(
1732
+ `Nonce provided for the transaction ${nonce ? `(${nonce}) ` : ""}exceeds the maximum allowed nonce.`,
1733
+ { cause }
1734
+ );
1735
+ __publicField(this, "name", "NonceMaxValueError");
1411
1736
  }
1412
1737
  };
1413
-
1414
- // src/errors/rpc.ts
1415
- var HttpRequestError = class extends BaseError {
1416
- constructor({
1417
- body,
1418
- details,
1419
- headers,
1420
- status,
1421
- url
1422
- }) {
1423
- super("HTTP request failed.", {
1424
- details,
1425
- metaMessages: [
1426
- status && `Status: ${status}`,
1427
- `URL: ${getUrl(url)}`,
1428
- `Request body: ${stringify(body)}`
1429
- ].filter(Boolean)
1430
- });
1431
- __publicField(this, "name", "HttpRequestError");
1432
- __publicField(this, "body");
1433
- __publicField(this, "headers");
1434
- __publicField(this, "status");
1435
- __publicField(this, "url");
1436
- this.body = body;
1437
- this.headers = headers;
1438
- this.status = status;
1439
- this.url = url;
1738
+ __publicField(NonceMaxValueError, "nodeMessage", /nonce has max value/);
1739
+ var InsufficientFundsError = class extends BaseError {
1740
+ constructor({ cause } = {}) {
1741
+ super(
1742
+ [
1743
+ "The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."
1744
+ ].join("\n"),
1745
+ {
1746
+ cause,
1747
+ metaMessages: [
1748
+ "This error could arise when the account does not have enough funds to:",
1749
+ " - pay for the total gas fee,",
1750
+ " - pay for the value to send.",
1751
+ " ",
1752
+ "The cost of the transaction is calculated as `gas * gas fee + value`, where:",
1753
+ " - `gas` is the amount of gas needed for transaction to execute,",
1754
+ " - `gas fee` is the gas fee,",
1755
+ " - `value` is the amount of ether to send to the recipient."
1756
+ ]
1757
+ }
1758
+ );
1759
+ __publicField(this, "name", "InsufficientFundsError");
1440
1760
  }
1441
1761
  };
1442
- var WebSocketRequestError = class extends BaseError {
1443
- constructor({
1444
- body,
1445
- details,
1446
- url
1447
- }) {
1448
- super("WebSocket request failed.", {
1449
- details,
1450
- metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
1451
- });
1452
- __publicField(this, "name", "WebSocketRequestError");
1762
+ __publicField(InsufficientFundsError, "nodeMessage", /insufficient funds/);
1763
+ var IntrinsicGasTooHighError = class extends BaseError {
1764
+ constructor({ cause, gas } = {}) {
1765
+ super(
1766
+ `The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction exceeds the limit allowed for the block.`,
1767
+ {
1768
+ cause
1769
+ }
1770
+ );
1771
+ __publicField(this, "name", "IntrinsicGasTooHighError");
1453
1772
  }
1454
1773
  };
1455
- var RpcError = class extends BaseError {
1456
- constructor({
1457
- body,
1458
- error,
1459
- url
1460
- }) {
1461
- super("RPC Request failed.", {
1462
- cause: error,
1463
- details: error.message,
1464
- metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
1465
- });
1466
- __publicField(this, "code");
1467
- __publicField(this, "name", "RpcError");
1468
- this.code = error.code;
1774
+ __publicField(IntrinsicGasTooHighError, "nodeMessage", /intrinsic gas too high|gas limit reached/);
1775
+ var IntrinsicGasTooLowError = class extends BaseError {
1776
+ constructor({ cause, gas } = {}) {
1777
+ super(
1778
+ `The amount of gas ${gas ? `(${gas}) ` : ""}provided for the transaction is too low.`,
1779
+ {
1780
+ cause
1781
+ }
1782
+ );
1783
+ __publicField(this, "name", "IntrinsicGasTooLowError");
1469
1784
  }
1470
1785
  };
1471
- var TimeoutError = class extends BaseError {
1472
- constructor({
1473
- body,
1474
- url
1475
- }) {
1476
- super("The request took too long to respond.", {
1477
- details: "The request timed out.",
1478
- metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
1786
+ __publicField(IntrinsicGasTooLowError, "nodeMessage", /intrinsic gas too low/);
1787
+ var TransactionTypeNotSupportedError = class extends BaseError {
1788
+ constructor({ cause }) {
1789
+ super("The transaction type is not supported for this chain.", {
1790
+ cause
1479
1791
  });
1480
- __publicField(this, "name", "TimeoutError");
1792
+ __publicField(this, "name", "TransactionTypeNotSupportedError");
1481
1793
  }
1482
1794
  };
1483
-
1484
- // src/errors/transport.ts
1485
- var UrlRequiredError = class extends BaseError {
1486
- constructor() {
1795
+ __publicField(TransactionTypeNotSupportedError, "nodeMessage", /transaction type not valid/);
1796
+ var TipAboveFeeCapError = class extends BaseError {
1797
+ constructor({
1798
+ cause,
1799
+ maxPriorityFeePerGas,
1800
+ maxFeePerGas
1801
+ } = {}) {
1487
1802
  super(
1488
- "No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.",
1803
+ [
1804
+ `The provided tip (\`maxPriorityFeePerGas\`${maxPriorityFeePerGas ? ` = ${formatGwei(maxPriorityFeePerGas)} gwei` : ""}) cannot be higher than the fee cap (\`maxFeePerGas\`${maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ""}).`
1805
+ ].join("\n"),
1489
1806
  {
1490
- docsPath: "/docs/clients/intro"
1807
+ cause
1491
1808
  }
1492
1809
  );
1810
+ __publicField(this, "name", "TipAboveFeeCapError");
1493
1811
  }
1494
1812
  };
1495
-
1496
- // src/utils/data/concat.ts
1497
- function concat(values) {
1498
- if (typeof values[0] === "string")
1499
- return concatHex(values);
1500
- return concatBytes(values);
1501
- }
1502
- function concatBytes(values) {
1503
- let length = 0;
1504
- for (const arr of values) {
1505
- length += arr.length;
1506
- }
1507
- const result = new Uint8Array(length);
1508
- let offset = 0;
1509
- for (const arr of values) {
1510
- result.set(arr, offset);
1511
- offset += arr.length;
1512
- }
1513
- return result;
1514
- }
1515
- function concatHex(values) {
1516
- return `0x${values.reduce(
1517
- (acc, x) => acc + x.replace("0x", ""),
1518
- ""
1519
- )}`;
1520
- }
1521
-
1522
- // src/utils/data/isBytes.ts
1523
- function isBytes(value) {
1524
- if (!value)
1525
- return false;
1526
- if (typeof value !== "object")
1527
- return false;
1528
- if (!("BYTES_PER_ELEMENT" in value))
1529
- return false;
1530
- return value.BYTES_PER_ELEMENT === 1 && value.constructor.name === "Uint8Array";
1531
- }
1532
-
1533
- // src/utils/data/isHex.ts
1534
- function isHex(value) {
1535
- if (!value)
1536
- return false;
1537
- if (typeof value !== "string")
1538
- return false;
1539
- return /^0x[0-9a-fA-F]*$/.test(value);
1540
- }
1541
-
1542
- // src/utils/data/pad.ts
1543
- function pad(hexOrBytes, { dir, size: size2 = 32 } = {}) {
1544
- if (typeof hexOrBytes === "string")
1545
- return padHex(hexOrBytes, { dir, size: size2 });
1546
- return padBytes(hexOrBytes, { dir, size: size2 });
1547
- }
1548
- function padHex(hex_, { dir, size: size2 = 32 } = {}) {
1549
- if (size2 === null)
1550
- return hex_;
1551
- let hex = hex_.replace("0x", "");
1552
- if (hex.length > size2 * 2)
1553
- throw new SizeExceedsPaddingSizeError({
1554
- size: Math.ceil(hex.length / 2),
1555
- targetSize: size2,
1556
- type: "hex"
1557
- });
1558
- return `0x${hex[dir === "right" ? "padEnd" : "padStart"](
1559
- size2 * 2,
1560
- "0"
1561
- )}`;
1562
- }
1563
- function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
1564
- if (size2 === null)
1565
- return bytes;
1566
- if (bytes.length > size2)
1567
- throw new SizeExceedsPaddingSizeError({
1568
- size: bytes.length,
1569
- targetSize: size2,
1570
- type: "bytes"
1813
+ __publicField(TipAboveFeeCapError, "nodeMessage", /max priority fee per gas higher than max fee per gas|tip higher than fee cap/);
1814
+ var UnknownNodeError = class extends BaseError {
1815
+ constructor({ cause }) {
1816
+ super(`An error occurred while executing: ${cause?.message}`, {
1817
+ cause
1571
1818
  });
1572
- const paddedBytes = new Uint8Array(size2);
1573
- for (let i = 0; i < size2; i++) {
1574
- const padEnd = dir === "right";
1575
- paddedBytes[padEnd ? i : size2 - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
1576
- }
1577
- return paddedBytes;
1578
- }
1579
-
1580
- // src/utils/data/trim.ts
1581
- function trim(hexOrBytes, { dir = "left" } = {}) {
1582
- let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
1583
- let sliceLength = 0;
1584
- for (let i = 0; i < data.length - 1; i++) {
1585
- if (data[dir === "left" ? i : data.length - i - 1].toString() === "0")
1586
- sliceLength++;
1587
- else
1588
- break;
1589
- }
1590
- data = dir === "left" ? data.slice(sliceLength) : data.slice(0, data.length - sliceLength);
1591
- if (typeof hexOrBytes === "string") {
1592
- if (data.length === 1 && dir === "right")
1593
- data = `${data}0`;
1594
- return `0x${data}`;
1819
+ __publicField(this, "name", "UnknownNodeError");
1595
1820
  }
1596
- return data;
1597
- }
1598
-
1599
- // src/utils/data/size.ts
1600
- function size(value) {
1601
- if (isHex(value))
1602
- return Math.ceil((value.length - 2) / 2);
1603
- return value.length;
1604
- }
1605
-
1606
- // src/utils/data/slice.ts
1607
- function slice(value, start, end) {
1608
- if (isHex(value))
1609
- return sliceHex(value, start, end);
1610
- return sliceBytes(value, start, end);
1611
- }
1612
- function assertStartOffset(value, start) {
1613
- if (typeof start === "number" && start > 0 && start > size(value) - 1)
1614
- throw new Error(
1615
- `Slice starting at offset "${start}" is out-of-bounds (size: ${size(
1616
- value
1617
- )}).`
1618
- );
1619
- }
1620
- function sliceBytes(value, start, end) {
1621
- assertStartOffset(value, start);
1622
- return value.slice(start, end);
1623
- }
1624
- function sliceHex(value_, start, end) {
1625
- assertStartOffset(value_, start);
1626
- const value = value_.replace("0x", "").slice((start ?? 0) * 2, (end ?? value_.length) * 2);
1627
- return `0x${value}`;
1628
- }
1821
+ };
1629
1822
 
1630
- // src/utils/encoding/toHex.ts
1631
- var hexes = Array.from(
1632
- { length: 256 },
1633
- (_v, i) => i.toString(16).padStart(2, "0")
1634
- );
1635
- function boolToHex(value) {
1636
- return `0x${Number(value)}`;
1637
- }
1638
- function bytesToHex(value) {
1639
- let hex = "";
1640
- for (let i = 0; i < value.length; i++) {
1641
- hex += hexes[value[i]];
1823
+ // src/errors/request.ts
1824
+ var RequestError = class extends BaseError {
1825
+ constructor(err, {
1826
+ docsPath: docsPath6,
1827
+ metaMessages,
1828
+ shortMessage
1829
+ }) {
1830
+ super(shortMessage, {
1831
+ cause: err,
1832
+ docsPath: docsPath6,
1833
+ metaMessages
1834
+ });
1835
+ this.name = err.name;
1642
1836
  }
1643
- return `0x${hex}`;
1644
- }
1645
- function toHex(value) {
1646
- if (typeof value === "number" || typeof value === "bigint")
1647
- return numberToHex(value);
1648
- if (typeof value === "string") {
1649
- return stringToHex(value);
1837
+ };
1838
+ var RpcRequestError = class extends RequestError {
1839
+ constructor(err, { docsPath: docsPath6, shortMessage }) {
1840
+ super(err, { docsPath: docsPath6, metaMessages: err.metaMessages, shortMessage });
1841
+ __publicField(this, "code");
1842
+ this.code = err.code;
1843
+ this.name = err.name;
1650
1844
  }
1651
- if (typeof value === "boolean")
1652
- return boolToHex(value);
1653
- return bytesToHex(value);
1654
- }
1655
- function numberToHex(value_, opts = {}) {
1656
- const { signed, size: size2 } = opts;
1657
- let value = BigInt(value_);
1658
- let maxValue;
1659
- if (size2) {
1660
- if (signed)
1661
- maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n;
1662
- else
1663
- maxValue = 2n ** (BigInt(size2) * 8n) - 1n;
1664
- } else if (typeof value_ === "number") {
1665
- maxValue = BigInt(Number.MAX_SAFE_INTEGER);
1845
+ };
1846
+ var ParseRpcError = class extends RpcRequestError {
1847
+ constructor(err) {
1848
+ super(err, {
1849
+ shortMessage: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."
1850
+ });
1851
+ __publicField(this, "name", "ParseRpcError");
1852
+ __publicField(this, "code", -32700);
1666
1853
  }
1667
- const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
1668
- if (maxValue && value > maxValue || value < minValue) {
1669
- const suffix = typeof value_ === "bigint" ? "n" : "";
1670
- throw new IntegerOutOfRangeError({
1671
- max: maxValue ? `${maxValue}${suffix}` : void 0,
1672
- min: `${minValue}${suffix}`,
1673
- signed,
1674
- size: size2,
1675
- value: `${value_}${suffix}`
1854
+ };
1855
+ var InvalidRequestRpcError = class extends RpcRequestError {
1856
+ constructor(err) {
1857
+ super(err, { shortMessage: "JSON is not a valid request object." });
1858
+ __publicField(this, "name", "InvalidRequestRpcError");
1859
+ __publicField(this, "code", -32600);
1860
+ }
1861
+ };
1862
+ var MethodNotFoundRpcError = class extends RpcRequestError {
1863
+ constructor(err) {
1864
+ super(err, {
1865
+ shortMessage: "The method does not exist / is not available."
1676
1866
  });
1867
+ __publicField(this, "name", "MethodNotFoundRpcError");
1868
+ __publicField(this, "code", -32601);
1677
1869
  }
1678
- const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
1679
- if (size2)
1680
- return pad(hex, { size: size2 });
1681
- return hex;
1682
- }
1683
- var encoder = new TextEncoder();
1684
- function stringToHex(value_) {
1685
- const value = encoder.encode(value_);
1686
- return toHex(value);
1687
- }
1688
-
1689
- // src/utils/encoding/toBytes.ts
1690
- var encoder2 = new TextEncoder();
1691
- function toBytes(value) {
1692
- if (typeof value === "number" || typeof value === "bigint")
1693
- return numberToBytes(value);
1694
- if (typeof value === "boolean")
1695
- return boolToBytes(value);
1696
- if (value.startsWith("0x"))
1697
- return hexToBytes(value);
1698
- return stringToBytes(value);
1699
- }
1700
- function boolToBytes(value) {
1701
- const bytes = new Uint8Array(1);
1702
- bytes[0] = Number(value);
1703
- return bytes;
1704
- }
1705
- function hexToBytes(hex_) {
1706
- let hex = hex_.slice(2);
1707
- if (hex.length % 2)
1708
- hex = `0${hex}`;
1709
- const bytes = new Uint8Array(hex.length / 2);
1710
- for (let index = 0; index < bytes.length; index++) {
1711
- const start = index * 2;
1712
- const hexByte = hex.slice(start, start + 2);
1713
- const byte = Number.parseInt(hexByte, 16);
1714
- if (Number.isNaN(byte) || byte < 0)
1715
- throw new BaseError(`Invalid byte sequence ("${hexByte}" in "${hex}").`);
1716
- bytes[index] = byte;
1870
+ };
1871
+ var InvalidParamsRpcError = class extends RpcRequestError {
1872
+ constructor(err) {
1873
+ super(err, {
1874
+ shortMessage: [
1875
+ "Invalid parameters were provided to the RPC method.",
1876
+ "Double check you have provided the correct parameters."
1877
+ ].join("\n")
1878
+ });
1879
+ __publicField(this, "name", "InvalidParamsRpcError");
1880
+ __publicField(this, "code", -32602);
1717
1881
  }
1718
- return bytes;
1719
- }
1720
- function numberToBytes(value, opts) {
1721
- const hex = numberToHex(value, opts);
1722
- return hexToBytes(hex);
1723
- }
1724
- function stringToBytes(value) {
1725
- return encoder2.encode(value);
1726
- }
1727
-
1728
- // src/utils/encoding/toRlp.ts
1729
- function toRlp(hexOrBytes, to_) {
1730
- const to = to_ || "hex";
1731
- return format(bytesToRlp(parse(hexOrBytes)), to);
1732
- }
1733
- function parse(hexOrBytes) {
1734
- if (Array.isArray(hexOrBytes))
1735
- return hexOrBytes.map(parse);
1736
- return typeof hexOrBytes === "string" ? toBytes(hexOrBytes) : hexOrBytes;
1737
- }
1738
- function format(bytes, type = "bytes") {
1739
- return type === "hex" ? bytesToHex(bytes) : bytes;
1740
- }
1741
- function bytesToRlp(bytes) {
1742
- if (Array.isArray(bytes)) {
1743
- const encoded = concat(bytes.map(bytesToRlp));
1744
- return new Uint8Array([...encodeLength(encoded.length, 192), ...encoded]);
1882
+ };
1883
+ var InternalRpcError = class extends RpcRequestError {
1884
+ constructor(err) {
1885
+ super(err, { shortMessage: "An internal error was received." });
1886
+ __publicField(this, "name", "InternalRpcError");
1887
+ __publicField(this, "code", -32603);
1745
1888
  }
1746
- if (bytes.length === 1 && bytes[0] < 128)
1747
- return bytes;
1748
- return new Uint8Array([...encodeLength(bytes.length, 128), ...bytes]);
1749
- }
1750
- function encodeLength(length, offset) {
1751
- if (length < 56)
1752
- return [offset + length];
1753
- return [toBytes(length).length + offset + 55, ...toBytes(length)];
1754
- }
1755
-
1756
- // src/utils/encoding/fromHex.ts
1757
- function fromHex(hex, to) {
1758
- if (to === "number")
1759
- return hexToNumber(hex);
1760
- if (to === "bigint")
1761
- return hexToBigInt(hex);
1762
- if (to === "string")
1763
- return hexToString(hex);
1764
- if (to === "boolean")
1765
- return hexToBool(hex);
1766
- return hexToBytes(hex);
1767
- }
1768
- function hexToBigInt(hex, opts = {}) {
1769
- const { signed } = opts;
1770
- const value = BigInt(hex);
1771
- if (!signed)
1772
- return value;
1773
- const size2 = (hex.length - 2) / 2;
1774
- const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
1775
- if (value <= max)
1776
- return value;
1777
- return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
1778
- }
1779
- function hexToBool(hex) {
1780
- if (trim(hex) === "0x0")
1781
- return false;
1782
- if (trim(hex) === "0x1")
1783
- return true;
1784
- throw new InvalidHexBooleanError(hex);
1785
- }
1786
- function hexToNumber(hex, opts = {}) {
1787
- return Number(hexToBigInt(hex, opts));
1788
- }
1789
- function hexToString(hex) {
1790
- const bytes = hexToBytes(hex);
1791
- return new TextDecoder().decode(bytes);
1792
- }
1793
-
1794
- // src/utils/encoding/fromBytes.ts
1795
- function fromBytes(bytes, to) {
1796
- if (to === "number")
1797
- return bytesToNumber(bytes);
1798
- if (to === "bigint")
1799
- return bytesToBigint(bytes);
1800
- if (to === "boolean")
1801
- return bytesToBool(bytes);
1802
- if (to === "string")
1803
- return bytesToString(bytes);
1804
- return bytesToHex(bytes);
1805
- }
1806
- function bytesToBigint(bytes) {
1807
- const hex = bytesToHex(bytes);
1808
- return hexToBigInt(hex);
1809
- }
1810
- function bytesToBool(bytes) {
1811
- if (bytes.length > 1 || bytes[0] > 1)
1812
- throw new InvalidBytesBooleanError(bytes);
1813
- return Boolean(bytes[0]);
1814
- }
1815
- function bytesToNumber(bytes) {
1816
- const hex = bytesToHex(bytes);
1817
- return hexToNumber(hex);
1818
- }
1819
- function bytesToString(bytes) {
1820
- return new TextDecoder().decode(bytes);
1821
- }
1822
-
1823
- // src/utils/encoding/fromRlp.ts
1824
- function fromRlp(value, to) {
1825
- const bytes = parse2(value);
1826
- const [data, consumed] = rlpToBytes(bytes);
1827
- if (consumed < bytes.length)
1828
- throw new DataLengthTooLongError({
1829
- consumed,
1830
- length: bytes.length
1889
+ };
1890
+ var InvalidInputRpcError = class extends RpcRequestError {
1891
+ constructor(err) {
1892
+ super(err, {
1893
+ shortMessage: [
1894
+ "Missing or invalid parameters.",
1895
+ "Double check you have provided the correct parameters."
1896
+ ].join("\n")
1831
1897
  });
1832
- return format2(data, to);
1833
- }
1834
- function parse2(value) {
1835
- if (typeof value === "string") {
1836
- if (value.length > 3 && value.length % 2 !== 0)
1837
- throw new InvalidHexValueError(value);
1838
- return hexToBytes(value);
1898
+ __publicField(this, "name", "InvalidInputRpcError");
1899
+ __publicField(this, "code", -32e3);
1900
+ }
1901
+ };
1902
+ var ResourceNotFoundRpcError = class extends RpcRequestError {
1903
+ constructor(err) {
1904
+ super(err, { shortMessage: "Requested resource not found." });
1905
+ __publicField(this, "name", "ResourceNotFoundRpcError");
1906
+ __publicField(this, "code", -32001);
1839
1907
  }
1840
- return value;
1841
- }
1842
- function format2(bytes, to) {
1843
- if (Array.isArray(bytes))
1844
- return bytes.map((b) => format2(b, to));
1845
- return to === "hex" ? trim(bytesToHex(bytes)) : bytes;
1846
- }
1847
- function rlpToBytes(bytes, offset = 0) {
1848
- if (bytes.length === 0)
1849
- return [new Uint8Array([]), 0];
1850
- const prefix = bytes[offset];
1851
- if (prefix <= 127)
1852
- return [new Uint8Array([bytes[offset]]), 1];
1853
- if (prefix <= 183) {
1854
- const length2 = prefix - 128;
1855
- const offset_ = offset + 1;
1856
- if (offset_ + length2 > bytes.length)
1857
- throw new DataLengthTooShortError({
1858
- length: offset_ + length2,
1859
- dataLength: bytes.length
1860
- });
1861
- return [bytes.slice(offset_, offset_ + length2), 1 + length2];
1908
+ };
1909
+ var ResourceUnavailableRpcError = class extends RpcRequestError {
1910
+ constructor(err) {
1911
+ super(err, { shortMessage: "Requested resource not available." });
1912
+ __publicField(this, "name", "ResourceUnavailableRpcError");
1913
+ __publicField(this, "code", -32002);
1862
1914
  }
1863
- if (prefix <= 191) {
1864
- const lengthOfLength2 = prefix - 183;
1865
- const offset_ = offset + 1;
1866
- const length2 = bytesToNumber(bytes.slice(offset_, offset_ + lengthOfLength2));
1867
- if (offset_ + lengthOfLength2 + length2 > bytes.length)
1868
- throw new DataLengthTooShortError({
1869
- length: lengthOfLength2 + length2,
1870
- dataLength: bytes.length - lengthOfLength2
1871
- });
1872
- return [
1873
- bytes.slice(offset_ + lengthOfLength2, offset_ + lengthOfLength2 + length2),
1874
- 1 + lengthOfLength2 + length2
1875
- ];
1915
+ };
1916
+ var TransactionRejectedRpcError = class extends RpcRequestError {
1917
+ constructor(err) {
1918
+ super(err, { shortMessage: "Transaction creation failed." });
1919
+ __publicField(this, "name", "TransactionRejectedRpcError");
1920
+ __publicField(this, "code", -32003);
1876
1921
  }
1877
- let lengthOfLength = 0;
1878
- let length = prefix - 192;
1879
- if (prefix > 247) {
1880
- lengthOfLength = prefix - 247;
1881
- length = bytesToNumber(bytes.slice(offset + 1, offset + 1 + lengthOfLength));
1922
+ };
1923
+ var MethodNotSupportedRpcError = class extends RpcRequestError {
1924
+ constructor(err) {
1925
+ super(err, { shortMessage: "Method is not implemented." });
1926
+ __publicField(this, "name", "MethodNotSupportedRpcError");
1927
+ __publicField(this, "code", -32004);
1882
1928
  }
1883
- let nextOffset = offset + 1 + lengthOfLength;
1884
- if (nextOffset > bytes.length)
1885
- throw new DataLengthTooShortError({
1886
- length: nextOffset,
1887
- dataLength: bytes.length
1929
+ };
1930
+ var LimitExceededRpcError = class extends RpcRequestError {
1931
+ constructor(err) {
1932
+ super(err, { shortMessage: "Request exceeds defined limit." });
1933
+ __publicField(this, "name", "LimitExceededRpcError");
1934
+ __publicField(this, "code", -32005);
1935
+ }
1936
+ };
1937
+ var JsonRpcVersionUnsupportedError = class extends RpcRequestError {
1938
+ constructor(err) {
1939
+ super(err, {
1940
+ shortMessage: "Version of JSON-RPC protocol is not supported."
1888
1941
  });
1889
- let consumed = 1 + lengthOfLength + length;
1890
- let result = [];
1891
- while (nextOffset < offset + consumed) {
1892
- const decoded = rlpToBytes(bytes, nextOffset);
1893
- result.push(decoded[0]);
1894
- nextOffset += decoded[1];
1895
- if (nextOffset > offset + consumed)
1896
- throw new OffsetOutOfBoundsError({
1897
- nextOffset,
1898
- offset: offset + consumed
1899
- });
1942
+ __publicField(this, "name", "JsonRpcVersionUnsupportedError");
1943
+ __publicField(this, "code", -32006);
1900
1944
  }
1901
- return [result, consumed];
1902
- }
1903
-
1904
- // src/utils/contract/extractFunctionParts.ts
1905
- var paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/;
1906
- function extractFunctionParts(def) {
1907
- const parts = def.match(paramsRegex);
1908
- const type = parts?.[2] || void 0;
1909
- const name = parts?.[3];
1910
- const params = parts?.[5] || void 0;
1911
- return { type, name, params };
1912
- }
1913
- function extractFunctionName(def) {
1914
- return extractFunctionParts(def).name;
1915
- }
1916
- function extractFunctionParams(def) {
1917
- const params = extractFunctionParts(def).params;
1918
- const splitParams = params?.split(",").map((x) => x.trim().split(" "));
1919
- return splitParams?.map((param) => ({
1920
- type: param[0],
1921
- name: param[1] === "indexed" ? param[2] : param[1],
1922
- ...param[1] === "indexed" ? { indexed: true } : {}
1923
- }));
1924
- }
1925
- function extractFunctionType(def) {
1926
- return extractFunctionParts(def).type;
1927
- }
1928
-
1929
- // src/utils/hash/keccak256.ts
1930
- import { keccak_256 } from "@noble/hashes/sha3";
1931
- function keccak256(value, to_) {
1932
- const to = to_ || "hex";
1933
- const bytes = keccak_256(isHex(value) ? toBytes(value) : value);
1934
- if (to === "bytes")
1935
- return bytes;
1936
- return toHex(bytes);
1937
- }
1938
-
1939
- // src/utils/hash/hashFunction.ts
1940
- var hash = (value) => keccak256(toBytes(value));
1941
- function hashFunction(def) {
1942
- const name = extractFunctionName(def);
1943
- const params = extractFunctionParams(def);
1944
- if (!params || params.length === 0)
1945
- return hash(def.replace(/ /g, ""));
1946
- return hash(`${name}(${params.map(({ type }) => type).join(",")})`);
1947
- }
1948
-
1949
- // src/utils/hash/getEventSelector.ts
1950
- var getEventSelector = (event) => hashFunction(event);
1951
-
1952
- // src/utils/hash/getFunctionSelector.ts
1953
- var getFunctionSelector = (fn) => slice(hashFunction(fn), 0, 4);
1954
-
1955
- // src/utils/address/isAddress.ts
1956
- var addressRegex = /^0x[a-fA-F0-9]{40}$/;
1957
- function isAddress(address) {
1958
- return addressRegex.test(address);
1959
- }
1960
-
1961
- // src/utils/address/getAddress.ts
1962
- function checksumAddress(address_) {
1963
- const hexAddress = address_.substring(2).toLowerCase();
1964
- const hash2 = keccak256(stringToBytes(hexAddress), "bytes");
1965
- let address = hexAddress.split("");
1966
- for (let i = 0; i < 40; i += 2) {
1967
- if (hash2[i >> 1] >> 4 >= 8 && address[i]) {
1968
- address[i] = address[i].toUpperCase();
1969
- }
1970
- if ((hash2[i >> 1] & 15) >= 8 && address[i + 1]) {
1971
- address[i + 1] = address[i + 1].toUpperCase();
1972
- }
1945
+ };
1946
+ var UserRejectedRequestError = class extends RpcRequestError {
1947
+ constructor(err) {
1948
+ super(err, {
1949
+ shortMessage: "User rejected the request."
1950
+ });
1951
+ __publicField(this, "name", "UserRejectedRequestError");
1952
+ __publicField(this, "code", 4001);
1973
1953
  }
1974
- return `0x${address.join("")}`;
1975
- }
1976
- function getAddress(address) {
1977
- if (!isAddress(address))
1978
- throw new InvalidAddressError({ address });
1979
- return checksumAddress(address);
1980
- }
1954
+ };
1955
+ var SwitchChainError = class extends RpcRequestError {
1956
+ constructor(err) {
1957
+ super(err, {
1958
+ shortMessage: "An error occurred when attempting to switch chain."
1959
+ });
1960
+ __publicField(this, "name", "SwitchChainError");
1961
+ __publicField(this, "code", 4902);
1962
+ }
1963
+ };
1964
+ var UnknownRpcError = class extends RequestError {
1965
+ constructor(err) {
1966
+ super(err, {
1967
+ shortMessage: "An unknown RPC error occurred."
1968
+ });
1969
+ __publicField(this, "name", "UnknownRpcError");
1970
+ }
1971
+ };
1981
1972
 
1982
- // src/utils/address/getContractAddress.ts
1983
- function getContractAddress2(opts) {
1984
- if (opts.opcode === "CREATE2")
1985
- return getCreate2Address(opts);
1986
- return getCreateAddress(opts);
1987
- }
1988
- function getCreateAddress(opts) {
1989
- const from = toBytes(getAddress(opts.from));
1990
- let nonce = toBytes(opts.nonce);
1991
- if (nonce[0] === 0)
1992
- nonce = new Uint8Array([]);
1993
- return getAddress(
1994
- `0x${keccak256(toRlp([from, nonce], "bytes")).slice(26)}`
1995
- );
1996
- }
1997
- function getCreate2Address(opts) {
1998
- const from = toBytes(getAddress(opts.from));
1999
- const salt = pad(isBytes(opts.salt) ? opts.salt : toBytes(opts.salt), {
2000
- size: 32
2001
- });
2002
- const bytecodeHash = toBytes(
2003
- keccak256(
2004
- isBytes(opts.bytecode) ? opts.bytecode : toBytes(opts.bytecode)
2005
- )
2006
- );
2007
- return getAddress(
2008
- slice(keccak256(concat([toBytes("0xff"), from, salt, bytecodeHash])), 12)
2009
- );
2010
- }
1973
+ // src/errors/rpc.ts
1974
+ var HttpRequestError = class extends BaseError {
1975
+ constructor({
1976
+ body,
1977
+ details,
1978
+ headers,
1979
+ status,
1980
+ url
1981
+ }) {
1982
+ super("HTTP request failed.", {
1983
+ details,
1984
+ metaMessages: [
1985
+ status && `Status: ${status}`,
1986
+ `URL: ${getUrl(url)}`,
1987
+ `Request body: ${stringify(body)}`
1988
+ ].filter(Boolean)
1989
+ });
1990
+ __publicField(this, "name", "HttpRequestError");
1991
+ __publicField(this, "body");
1992
+ __publicField(this, "headers");
1993
+ __publicField(this, "status");
1994
+ __publicField(this, "url");
1995
+ this.body = body;
1996
+ this.headers = headers;
1997
+ this.status = status;
1998
+ this.url = url;
1999
+ }
2000
+ };
2001
+ var WebSocketRequestError = class extends BaseError {
2002
+ constructor({
2003
+ body,
2004
+ details,
2005
+ url
2006
+ }) {
2007
+ super("WebSocket request failed.", {
2008
+ details,
2009
+ metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
2010
+ });
2011
+ __publicField(this, "name", "WebSocketRequestError");
2012
+ }
2013
+ };
2014
+ var RpcError = class extends BaseError {
2015
+ constructor({
2016
+ body,
2017
+ error,
2018
+ url
2019
+ }) {
2020
+ super("RPC Request failed.", {
2021
+ cause: error,
2022
+ details: error.message,
2023
+ metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
2024
+ });
2025
+ __publicField(this, "code");
2026
+ __publicField(this, "name", "RpcError");
2027
+ this.code = error.code;
2028
+ }
2029
+ };
2030
+ var TimeoutError = class extends BaseError {
2031
+ constructor({
2032
+ body,
2033
+ url
2034
+ }) {
2035
+ super("The request took too long to respond.", {
2036
+ details: "The request timed out.",
2037
+ metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
2038
+ });
2039
+ __publicField(this, "name", "TimeoutError");
2040
+ }
2041
+ };
2011
2042
 
2012
- // src/utils/address/isAddressEqual.ts
2013
- function isAddressEqual(a, b) {
2014
- if (!isAddress(a))
2015
- throw new InvalidAddressError({ address: a });
2016
- if (!isAddress(b))
2017
- throw new InvalidAddressError({ address: b });
2018
- return a.toLowerCase() === b.toLowerCase();
2019
- }
2043
+ // src/errors/transport.ts
2044
+ var UrlRequiredError = class extends BaseError {
2045
+ constructor() {
2046
+ super(
2047
+ "No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.",
2048
+ {
2049
+ docsPath: "/docs/clients/intro"
2050
+ }
2051
+ );
2052
+ }
2053
+ };
2020
2054
 
2021
2055
  // src/utils/abi/encodeAbiParameters.ts
2022
2056
  function encodeAbiParameters(params, values) {
@@ -2859,32 +2893,6 @@ function formatAbiItemWithArgs({
2859
2893
  ).join(", ")})`;
2860
2894
  }
2861
2895
 
2862
- // src/utils/account.ts
2863
- function getAccount(source) {
2864
- if (typeof source === "string") {
2865
- if (!isAddress(source))
2866
- throw new InvalidAddressError({ address: source });
2867
- return {
2868
- address: source,
2869
- type: "json-rpc"
2870
- };
2871
- }
2872
- if (!isAddress(source.address))
2873
- throw new InvalidAddressError({ address: source.address });
2874
- return {
2875
- address: source.address,
2876
- signMessage: source.signMessage,
2877
- signTransaction: source.signTransaction,
2878
- signTypedData: source.signTypedData,
2879
- type: "local"
2880
- };
2881
- }
2882
- function parseAccount(account) {
2883
- if (typeof account === "string")
2884
- return { address: account, type: "json-rpc" };
2885
- return account;
2886
- }
2887
-
2888
2896
  // src/utils/promise/withCache.ts
2889
2897
  var promiseCache = /* @__PURE__ */ new Map();
2890
2898
  var responseCache = /* @__PURE__ */ new Map();
@@ -3549,13 +3557,59 @@ ${messageBytes.length}`
3549
3557
  return keccak256(concat([prefixBytes, messageBytes]), to_);
3550
3558
  }
3551
3559
 
3560
+ // src/utils/typedData.ts
3561
+ function validateTypedData({
3562
+ domain,
3563
+ message,
3564
+ primaryType,
3565
+ types: types_
3566
+ }) {
3567
+ const types = types_;
3568
+ const validateData = (struct, value_) => {
3569
+ for (const param of struct) {
3570
+ const { name, type: type_ } = param;
3571
+ const type = type_;
3572
+ const value = value_[name];
3573
+ const integerMatch = type.match(integerRegex);
3574
+ if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
3575
+ const [_type, base, size_] = integerMatch;
3576
+ numberToHex(value, {
3577
+ signed: base === "int",
3578
+ size: parseInt(size_) / 8
3579
+ });
3580
+ }
3581
+ if (type === "address" && typeof value === "string" && !isAddress(value))
3582
+ throw new InvalidAddressError({ address: value });
3583
+ const bytesMatch = type.match(bytesRegex);
3584
+ if (bytesMatch) {
3585
+ const [_type, size_] = bytesMatch;
3586
+ if (size_ && size(value) !== parseInt(size_))
3587
+ throw new BytesSizeMismatchError({
3588
+ expectedSize: parseInt(size_),
3589
+ givenSize: size(value)
3590
+ });
3591
+ }
3592
+ const struct2 = types[type];
3593
+ if (struct2)
3594
+ validateData(struct2, value);
3595
+ }
3596
+ };
3597
+ if (types["EIP712Domain"] && domain)
3598
+ validateData(types["EIP712Domain"], domain);
3599
+ if (primaryType !== "EIP712Domain") {
3600
+ const type = types[primaryType];
3601
+ validateData(type, message);
3602
+ }
3603
+ }
3604
+
3552
3605
  // src/utils/signature/hashTypedData.ts
3553
3606
  function hashTypedData({
3554
- domain,
3607
+ domain: domain_,
3555
3608
  message,
3556
3609
  primaryType,
3557
3610
  types: types_
3558
3611
  }) {
3612
+ const domain = typeof domain_ === "undefined" ? {} : domain_;
3559
3613
  const types = {
3560
3614
  EIP712Domain: [
3561
3615
  domain?.name && { name: "name", type: "string" },
@@ -3569,6 +3623,12 @@ function hashTypedData({
3569
3623
  ].filter(Boolean),
3570
3624
  ...types_
3571
3625
  };
3626
+ validateTypedData({
3627
+ domain,
3628
+ message,
3629
+ primaryType,
3630
+ types
3631
+ });
3572
3632
  let parts = ["0x1901"];
3573
3633
  if (domain)
3574
3634
  parts.push(
@@ -3707,14 +3767,14 @@ function encodeField({
3707
3767
  }
3708
3768
 
3709
3769
  // src/utils/signature/recoverAddress.ts
3710
- async function recoverAddress({
3770
+ import { recoverPublicKey } from "@noble/secp256k1";
3771
+ function recoverAddress({
3711
3772
  hash: hash2,
3712
3773
  signature
3713
3774
  }) {
3714
3775
  const signatureHex = isHex(signature) ? signature : toHex(signature);
3715
3776
  const hashHex = isHex(hash2) ? hash2 : toHex(hash2);
3716
3777
  const v = hexToNumber(`0x${signatureHex.slice(130)}`);
3717
- const { recoverPublicKey } = await import("@noble/secp256k1");
3718
3778
  const publicKey = toHex(
3719
3779
  recoverPublicKey(
3720
3780
  hashHex.substring(2),
@@ -3727,7 +3787,7 @@ async function recoverAddress({
3727
3787
  }
3728
3788
 
3729
3789
  // src/utils/signature/recoverMessageAddress.ts
3730
- async function recoverMessageAddress({
3790
+ function recoverMessageAddress({
3731
3791
  message,
3732
3792
  signature
3733
3793
  }) {
@@ -3735,7 +3795,7 @@ async function recoverMessageAddress({
3735
3795
  }
3736
3796
 
3737
3797
  // src/utils/signature/recoverTypedDataAddress.ts
3738
- async function recoverTypedDataAddress({
3798
+ function recoverTypedDataAddress({
3739
3799
  domain,
3740
3800
  message,
3741
3801
  primaryType,
@@ -3754,19 +3814,19 @@ async function recoverTypedDataAddress({
3754
3814
  }
3755
3815
 
3756
3816
  // src/utils/signature/verifyMessage.ts
3757
- async function verifyMessage({
3817
+ function verifyMessage({
3758
3818
  address,
3759
3819
  message,
3760
3820
  signature
3761
3821
  }) {
3762
3822
  return isAddressEqual(
3763
3823
  getAddress(address),
3764
- await recoverMessageAddress({ message, signature })
3824
+ recoverMessageAddress({ message, signature })
3765
3825
  );
3766
3826
  }
3767
3827
 
3768
3828
  // src/utils/signature/verifyTypedData.ts
3769
- async function verifyTypedData({
3829
+ function verifyTypedData({
3770
3830
  address,
3771
3831
  domain,
3772
3832
  message,
@@ -3776,7 +3836,7 @@ async function verifyTypedData({
3776
3836
  }) {
3777
3837
  return isAddressEqual(
3778
3838
  getAddress(address),
3779
- await recoverTypedDataAddress({
3839
+ recoverTypedDataAddress({
3780
3840
  domain,
3781
3841
  message,
3782
3842
  primaryType,
@@ -5365,7 +5425,7 @@ async function sendTransaction(client, args) {
5365
5425
  }
5366
5426
 
5367
5427
  // src/actions/wallet/signMessage.ts
5368
- async function signMessage(client, {
5428
+ async function signMessage2(client, {
5369
5429
  account: account_ = client.account,
5370
5430
  data,
5371
5431
  message
@@ -5377,7 +5437,7 @@ async function signMessage(client, {
5377
5437
  const account = parseAccount(account_);
5378
5438
  const message_ = message || data;
5379
5439
  if (account.type === "local")
5380
- return account.signMessage(message_);
5440
+ return account.signMessage({ message: message_ });
5381
5441
  return client.request({
5382
5442
  method: "personal_sign",
5383
5443
  params: [toHex(message_), account.address]
@@ -5432,47 +5492,6 @@ async function signTypedData(client, {
5432
5492
  params: [account.address, typedData]
5433
5493
  });
5434
5494
  }
5435
- function validateTypedData({
5436
- domain,
5437
- message,
5438
- primaryType,
5439
- types: types_
5440
- }) {
5441
- const types = types_;
5442
- const validateData = (struct, value_) => {
5443
- for (const param of struct) {
5444
- const { name, type: type_ } = param;
5445
- const type2 = type_;
5446
- const value = value_[name];
5447
- const integerMatch = type2.match(integerRegex);
5448
- if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
5449
- const [_type, base, size_] = integerMatch;
5450
- numberToHex(value, {
5451
- signed: base === "int",
5452
- size: parseInt(size_) / 8
5453
- });
5454
- }
5455
- if (type2 === "address" && typeof value === "string" && !isAddress(value))
5456
- throw new InvalidAddressError({ address: value });
5457
- const bytesMatch = type2.match(bytesRegex);
5458
- if (bytesMatch) {
5459
- const [_type, size_] = bytesMatch;
5460
- if (size_ && size(value) !== parseInt(size_))
5461
- throw new BytesSizeMismatchError({
5462
- expectedSize: parseInt(size_),
5463
- givenSize: size(value)
5464
- });
5465
- }
5466
- const struct2 = types[type2];
5467
- if (struct2)
5468
- validateData(struct2, value);
5469
- }
5470
- };
5471
- if (types["EIP712Domain"] && domain)
5472
- validateData(types["EIP712Domain"], domain);
5473
- const type = types[primaryType];
5474
- validateData(type, message);
5475
- }
5476
5495
 
5477
5496
  // src/actions/wallet/switchChain.ts
5478
5497
  async function switchChain(client, { id: id2 }) {
@@ -5648,6 +5667,56 @@ export {
5648
5667
  InvalidAddressError,
5649
5668
  BlockNotFoundError,
5650
5669
  ChainDoesNotSupportContract,
5670
+ parseAccount,
5671
+ concat,
5672
+ concatBytes,
5673
+ concatHex,
5674
+ isBytes,
5675
+ isHex,
5676
+ pad,
5677
+ padHex,
5678
+ padBytes,
5679
+ trim,
5680
+ size,
5681
+ slice,
5682
+ sliceBytes,
5683
+ sliceHex,
5684
+ boolToHex,
5685
+ bytesToHex,
5686
+ toHex,
5687
+ numberToHex,
5688
+ stringToHex,
5689
+ toBytes,
5690
+ boolToBytes,
5691
+ hexToBytes,
5692
+ numberToBytes,
5693
+ stringToBytes,
5694
+ toRlp,
5695
+ fromHex,
5696
+ hexToBigInt,
5697
+ hexToBool,
5698
+ hexToNumber,
5699
+ hexToString,
5700
+ fromBytes,
5701
+ bytesToBigint,
5702
+ bytesToBool,
5703
+ bytesToNumber,
5704
+ bytesToString,
5705
+ fromRlp,
5706
+ extractFunctionParts,
5707
+ extractFunctionName,
5708
+ extractFunctionParams,
5709
+ extractFunctionType,
5710
+ keccak256,
5711
+ getEventSelector,
5712
+ getFunctionSelector,
5713
+ isAddress,
5714
+ getAddress,
5715
+ getContractAddress2 as getContractAddress,
5716
+ getCreateAddress,
5717
+ getCreate2Address,
5718
+ isAddressEqual,
5719
+ toAccount,
5651
5720
  multicall3Abi,
5652
5721
  panicReasons,
5653
5722
  etherUnits,
@@ -5705,54 +5774,6 @@ export {
5705
5774
  RpcError,
5706
5775
  TimeoutError,
5707
5776
  UrlRequiredError,
5708
- concat,
5709
- concatBytes,
5710
- concatHex,
5711
- isBytes,
5712
- isHex,
5713
- pad,
5714
- padHex,
5715
- padBytes,
5716
- trim,
5717
- size,
5718
- slice,
5719
- sliceBytes,
5720
- sliceHex,
5721
- boolToHex,
5722
- bytesToHex,
5723
- toHex,
5724
- numberToHex,
5725
- stringToHex,
5726
- toBytes,
5727
- boolToBytes,
5728
- hexToBytes,
5729
- numberToBytes,
5730
- stringToBytes,
5731
- toRlp,
5732
- fromHex,
5733
- hexToBigInt,
5734
- hexToBool,
5735
- hexToNumber,
5736
- hexToString,
5737
- fromBytes,
5738
- bytesToBigint,
5739
- bytesToBool,
5740
- bytesToNumber,
5741
- bytesToString,
5742
- fromRlp,
5743
- extractFunctionParts,
5744
- extractFunctionName,
5745
- extractFunctionParams,
5746
- extractFunctionType,
5747
- keccak256,
5748
- getEventSelector,
5749
- getFunctionSelector,
5750
- isAddress,
5751
- getAddress,
5752
- getContractAddress2 as getContractAddress,
5753
- getCreateAddress,
5754
- getCreate2Address,
5755
- isAddressEqual,
5756
5777
  encodeAbiParameters,
5757
5778
  decodeAbiParameters,
5758
5779
  formatAbiItem,
@@ -5775,8 +5796,6 @@ export {
5775
5796
  parseAbiItem,
5776
5797
  parseAbiParameter,
5777
5798
  parseAbiParameters,
5778
- getAccount,
5779
- parseAccount,
5780
5799
  isDeterministicError,
5781
5800
  buildRequest,
5782
5801
  defineChain,
@@ -5802,6 +5821,7 @@ export {
5802
5821
  getSocket,
5803
5822
  rpc,
5804
5823
  hashMessage,
5824
+ validateTypedData,
5805
5825
  hashTypedData,
5806
5826
  recoverAddress,
5807
5827
  recoverMessageAddress,
@@ -5878,7 +5898,7 @@ export {
5878
5898
  requestAddresses,
5879
5899
  requestPermissions,
5880
5900
  sendTransaction,
5881
- signMessage,
5901
+ signMessage2 as signMessage,
5882
5902
  signTypedData,
5883
5903
  switchChain,
5884
5904
  watchAsset,
@@ -5891,4 +5911,4 @@ export {
5891
5911
  formatGwei,
5892
5912
  parseEther
5893
5913
  };
5894
- //# sourceMappingURL=chunk-FEPL5HFW.mjs.map
5914
+ //# sourceMappingURL=chunk-PB263D6W.mjs.map