viem 1.14.0 → 1.15.0

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 (73) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/_cjs/chains/definitions/arbitrumSepolia.js +36 -0
  3. package/_cjs/chains/definitions/arbitrumSepolia.js.map +1 -0
  4. package/_cjs/chains/definitions/fuse.js +7 -1
  5. package/_cjs/chains/definitions/fuse.js.map +1 -1
  6. package/_cjs/chains/index.js +5 -3
  7. package/_cjs/chains/index.js.map +1 -1
  8. package/_cjs/errors/node.js +11 -11
  9. package/_cjs/errors/node.js.map +1 -1
  10. package/_cjs/errors/rpc.js +18 -18
  11. package/_cjs/errors/rpc.js.map +1 -1
  12. package/_cjs/errors/version.js +1 -1
  13. package/_cjs/index.js +11 -3
  14. package/_cjs/index.js.map +1 -1
  15. package/_cjs/utils/signature/compactSignatureToHex.js +10 -0
  16. package/_cjs/utils/signature/compactSignatureToHex.js.map +1 -0
  17. package/_cjs/utils/signature/compactSignatureToSignature.js +15 -0
  18. package/_cjs/utils/signature/compactSignatureToSignature.js.map +1 -0
  19. package/_cjs/utils/signature/hexToCompactSignature.js +14 -0
  20. package/_cjs/utils/signature/hexToCompactSignature.js.map +1 -0
  21. package/_cjs/utils/signature/signatureToCompactSignature.js +17 -0
  22. package/_cjs/utils/signature/signatureToCompactSignature.js.map +1 -0
  23. package/_esm/chains/definitions/arbitrumSepolia.js +33 -0
  24. package/_esm/chains/definitions/arbitrumSepolia.js.map +1 -0
  25. package/_esm/chains/definitions/fuse.js +7 -1
  26. package/_esm/chains/definitions/fuse.js.map +1 -1
  27. package/_esm/chains/index.js +1 -0
  28. package/_esm/chains/index.js.map +1 -1
  29. package/_esm/errors/node.js +11 -22
  30. package/_esm/errors/node.js.map +1 -1
  31. package/_esm/errors/rpc.js +18 -36
  32. package/_esm/errors/rpc.js.map +1 -1
  33. package/_esm/errors/version.js +1 -1
  34. package/_esm/index.js +4 -0
  35. package/_esm/index.js.map +1 -1
  36. package/_esm/utils/signature/compactSignatureToHex.js +19 -0
  37. package/_esm/utils/signature/compactSignatureToHex.js.map +1 -0
  38. package/_esm/utils/signature/compactSignatureToSignature.js +28 -0
  39. package/_esm/utils/signature/compactSignatureToSignature.js.map +1 -0
  40. package/_esm/utils/signature/hexToCompactSignature.js +20 -0
  41. package/_esm/utils/signature/hexToCompactSignature.js.map +1 -0
  42. package/_esm/utils/signature/signatureToCompactSignature.js +30 -0
  43. package/_esm/utils/signature/signatureToCompactSignature.js.map +1 -0
  44. package/_types/chains/definitions/arbitrumSepolia.d.ts +32 -0
  45. package/_types/chains/definitions/arbitrumSepolia.d.ts.map +1 -0
  46. package/_types/chains/definitions/fuse.d.ts +7 -1
  47. package/_types/chains/definitions/fuse.d.ts.map +1 -1
  48. package/_types/chains/index.d.ts +1 -0
  49. package/_types/chains/index.d.ts.map +1 -1
  50. package/_types/errors/version.d.ts +1 -1
  51. package/_types/index.d.ts +5 -1
  52. package/_types/index.d.ts.map +1 -1
  53. package/_types/types/misc.d.ts +4 -0
  54. package/_types/types/misc.d.ts.map +1 -1
  55. package/_types/utils/signature/compactSignatureToHex.d.ts +19 -0
  56. package/_types/utils/signature/compactSignatureToHex.d.ts.map +1 -0
  57. package/_types/utils/signature/compactSignatureToSignature.d.ts +24 -0
  58. package/_types/utils/signature/compactSignatureToSignature.d.ts.map +1 -0
  59. package/_types/utils/signature/hexToCompactSignature.d.ts +16 -0
  60. package/_types/utils/signature/hexToCompactSignature.d.ts.map +1 -0
  61. package/_types/utils/signature/signatureToCompactSignature.d.ts +23 -0
  62. package/_types/utils/signature/signatureToCompactSignature.d.ts.map +1 -0
  63. package/chains/definitions/arbitrumSepolia.ts +33 -0
  64. package/chains/definitions/fuse.ts +7 -1
  65. package/chains/index.ts +1 -0
  66. package/errors/version.ts +1 -1
  67. package/index.ts +17 -0
  68. package/package.json +15 -48
  69. package/types/misc.ts +6 -0
  70. package/utils/signature/compactSignatureToHex.ts +29 -0
  71. package/utils/signature/compactSignatureToSignature.ts +37 -0
  72. package/utils/signature/hexToCompactSignature.ts +28 -0
  73. package/utils/signature/signatureToCompactSignature.ts +44 -0
@@ -7,9 +7,15 @@ export const fuse = /*#__PURE__*/ defineChain({
7
7
  nativeCurrency: { name: 'Fuse', symbol: 'FUSE', decimals: 18 },
8
8
  rpcUrls: {
9
9
  default: { http: ['https://rpc.fuse.io'] },
10
- public: { http: ['https://fuse-mainnet.chainstacklabs.com'] },
10
+ public: { http: ['https://rpc.fuse.io'] },
11
11
  },
12
12
  blockExplorers: {
13
13
  default: { name: 'Fuse Explorer', url: 'https://explorer.fuse.io' },
14
14
  },
15
+ contracts: {
16
+ multicall3: {
17
+ address: '0xca11bde05977b3631167028862be2a173976ca11',
18
+ blockCreated: 16146628,
19
+ },
20
+ },
15
21
  })
package/chains/index.ts CHANGED
@@ -3,6 +3,7 @@ export type { Chain } from '../types/chain.js'
3
3
  export { arbitrum } from './definitions/arbitrum.js'
4
4
  export { arbitrumGoerli } from './definitions/arbitrumGoerli.js'
5
5
  export { arbitrumNova } from './definitions/arbitrumNova.js'
6
+ export { arbitrumSepolia } from './definitions/arbitrumSepolia.js'
6
7
  export { aurora } from './definitions/aurora.js'
7
8
  export { auroraTestnet } from './definitions/auroraTestnet.js'
8
9
  export { avalanche } from './definitions/avalanche.js'
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.13.2'
1
+ export const version = '1.15.0'
package/index.ts CHANGED
@@ -886,6 +886,7 @@ export type {
886
886
  Hex,
887
887
  LogTopic,
888
888
  Signature,
889
+ CompactSignature,
889
890
  SignableMessage,
890
891
  } from './types/misc.js'
891
892
  export type { GetChain } from './types/chain.js'
@@ -1077,6 +1078,14 @@ export {
1077
1078
  hashDomain,
1078
1079
  hashTypedData,
1079
1080
  } from './utils/signature/hashTypedData.js'
1081
+ export {
1082
+ type CompactSignatureToSignatureErrorType,
1083
+ compactSignatureToSignature,
1084
+ } from './utils/signature/compactSignatureToSignature.js'
1085
+ export {
1086
+ type HexToCompactSignatureErrorType,
1087
+ hexToCompactSignature,
1088
+ } from './utils/signature/hexToCompactSignature.js'
1080
1089
  export {
1081
1090
  type HexToSignatureErrorType,
1082
1091
  hexToSignature,
@@ -1105,6 +1114,14 @@ export {
1105
1114
  type RecoverTypedDataAddressReturnType,
1106
1115
  recoverTypedDataAddress,
1107
1116
  } from './utils/signature/recoverTypedDataAddress.js'
1117
+ export {
1118
+ type SignatureToCompactSignatureErrorType,
1119
+ signatureToCompactSignature,
1120
+ } from './utils/signature/signatureToCompactSignature.js'
1121
+ export {
1122
+ type CompactSignatureToHexErrorType,
1123
+ compactSignatureToHex,
1124
+ } from './utils/signature/compactSignatureToHex.js'
1108
1125
  export {
1109
1126
  type SignatureToHexErrorType,
1110
1127
  signatureToHex,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "1.14.0",
4
+ "version": "1.15.0",
5
5
  "type": "module",
6
6
  "main": "./_cjs/index.js",
7
7
  "module": "./_esm/index.js",
@@ -86,42 +86,18 @@
86
86
  },
87
87
  "typesVersions": {
88
88
  "*": {
89
- "abi": [
90
- "./_types/abi/index.d.ts"
91
- ],
92
- "accounts": [
93
- "./_types/accounts/index.d.ts"
94
- ],
95
- "actions": [
96
- "./_types/actions/index.d.ts"
97
- ],
98
- "chains": [
99
- "./_types/chains/index.d.ts"
100
- ],
101
- "chains/utils": [
102
- "./_types/chains/utils/index.d.ts"
103
- ],
104
- "contract": [
105
- "./_types/contract/index.d.ts"
106
- ],
107
- "ens": [
108
- "./_types/ens/index.d.ts"
109
- ],
110
- "public": [
111
- "./_types/public/index.d.ts"
112
- ],
113
- "test": [
114
- "./_types/test/index.d.ts"
115
- ],
116
- "utils": [
117
- "./_types/utils/index.d.ts"
118
- ],
119
- "wallet": [
120
- "./_types/wallet/index.d.ts"
121
- ],
122
- "window": [
123
- "./_types/window/index.d.ts"
124
- ]
89
+ "abi": ["./_types/abi/index.d.ts"],
90
+ "accounts": ["./_types/accounts/index.d.ts"],
91
+ "actions": ["./_types/actions/index.d.ts"],
92
+ "chains": ["./_types/chains/index.d.ts"],
93
+ "chains/utils": ["./_types/chains/utils/index.d.ts"],
94
+ "contract": ["./_types/contract/index.d.ts"],
95
+ "ens": ["./_types/ens/index.d.ts"],
96
+ "public": ["./_types/public/index.d.ts"],
97
+ "test": ["./_types/test/index.d.ts"],
98
+ "utils": ["./_types/utils/index.d.ts"],
99
+ "wallet": ["./_types/wallet/index.d.ts"],
100
+ "window": ["./_types/window/index.d.ts"]
125
101
  }
126
102
  },
127
103
  "peerDependencies": {
@@ -145,21 +121,12 @@
145
121
  },
146
122
  "license": "MIT",
147
123
  "repository": "wagmi-dev/viem",
148
- "authors": [
149
- "awkweb.eth",
150
- "jxom.eth"
151
- ],
124
+ "authors": ["awkweb.eth", "jxom.eth"],
152
125
  "funding": [
153
126
  {
154
127
  "type": "github",
155
128
  "url": "https://github.com/sponsors/wagmi-dev"
156
129
  }
157
130
  ],
158
- "keywords": [
159
- "eth",
160
- "ethereum",
161
- "dapps",
162
- "wallet",
163
- "web3"
164
- ]
131
+ "keywords": ["eth", "ethereum", "dapps", "wallet", "web3"]
165
132
  }
package/types/misc.ts CHANGED
@@ -16,3 +16,9 @@ export type Signature = {
16
16
  // TODO(v2): `v` to `recovery`
17
17
  v: bigint
18
18
  }
19
+ export type CompactSignature = {
20
+ // TODO(v2): Make `bigint`
21
+ r: Hex
22
+ // TODO(v2): Make `bigint`
23
+ yParityAndS: Hex
24
+ }
@@ -0,0 +1,29 @@
1
+ import { secp256k1 } from '@noble/curves/secp256k1'
2
+ import type { ErrorType } from '../../errors/utils.js'
3
+ import type { CompactSignature, Hex } from '../../types/misc.js'
4
+ import { type HexToBigIntErrorType, hexToBigInt } from '../encoding/fromHex.js'
5
+
6
+ export type CompactSignatureToHexErrorType = HexToBigIntErrorType | ErrorType
7
+
8
+ /**
9
+ * @description Converts an [EIP-2098 compact signature](https://eips.ethereum.org/EIPS/eip-2098) into hex format.
10
+ *
11
+ * @param signature The compact signature to convert.
12
+ * @returns The compact signature in hex format.
13
+ *
14
+ * @example
15
+ * compactSignatureToHex({
16
+ * r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
17
+ * yParityAndS: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
18
+ * })
19
+ * // "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c"
20
+ */
21
+ export function compactSignatureToHex({
22
+ r,
23
+ yParityAndS,
24
+ }: CompactSignature): Hex {
25
+ return `0x${new secp256k1.Signature(
26
+ hexToBigInt(r),
27
+ hexToBigInt(yParityAndS),
28
+ ).toCompactHex()}`
29
+ }
@@ -0,0 +1,37 @@
1
+ import type { ErrorType } from '../../errors/utils.js'
2
+ import type { CompactSignature, Signature } from '../../types/misc.js'
3
+ import { type HexToBytesErrorType, hexToBytes } from '../encoding/toBytes.js'
4
+ import { type BytesToHexErrorType, bytesToHex } from '../encoding/toHex.js'
5
+
6
+ export type CompactSignatureToSignatureErrorType =
7
+ | BytesToHexErrorType
8
+ | HexToBytesErrorType
9
+ | ErrorType
10
+
11
+ /**
12
+ * @description Converts an [EIP-2098 compact signature](https://eips.ethereum.org/EIPS/eip-2098) into signature format.
13
+ *
14
+ * @param signature The compact signature to convert.
15
+ * @returns The compact signature in signature format.
16
+ *
17
+ * @example
18
+ * compactSignatureToHex({
19
+ * r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
20
+ * yParityAndS: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
21
+ * })
22
+ * // {
23
+ * // r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
24
+ * // s: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
25
+ * // v: 27n
26
+ * // }
27
+ */
28
+ export function compactSignatureToSignature({
29
+ r,
30
+ yParityAndS,
31
+ }: CompactSignature): Signature {
32
+ const yParityAndS_bytes = hexToBytes(yParityAndS)
33
+ const v = yParityAndS_bytes[0] & 0x80 ? 28n : 27n
34
+ const s = yParityAndS_bytes
35
+ if (v === 28n) s[0] &= 0x7f
36
+ return { r, s: bytesToHex(s), v }
37
+ }
@@ -0,0 +1,28 @@
1
+ import { secp256k1 } from '@noble/curves/secp256k1'
2
+
3
+ import type { ErrorType } from '../../errors/utils.js'
4
+ import type { CompactSignature, Hex } from '../../types/misc.js'
5
+ import {
6
+ type NumberToHexErrorType,
7
+ numberToHex,
8
+ } from '../../utils/encoding/toHex.js'
9
+
10
+ export type HexToCompactSignatureErrorType = NumberToHexErrorType | ErrorType
11
+
12
+ /**
13
+ * @description Parses a hex formatted compact signature into a structured compact signature.
14
+ *
15
+ * @param signatureHex Signature in hex format.
16
+ * @returns The structured signature.
17
+ *
18
+ * @example
19
+ * hexToCompactSignature('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c')
20
+ * // { r: '0x...', yParityAndS: '0x...' }
21
+ */
22
+ export function hexToCompactSignature(signatureHex: Hex): CompactSignature {
23
+ const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130))
24
+ return {
25
+ r: numberToHex(r, { size: 32 }),
26
+ yParityAndS: numberToHex(s, { size: 32 }),
27
+ }
28
+ }
@@ -0,0 +1,44 @@
1
+ import type { ErrorType } from '../../errors/utils.js'
2
+ import type { CompactSignature, Signature } from '../../types/misc.js'
3
+ import {
4
+ type BytesToHexErrorType,
5
+ type HexToBytesErrorType,
6
+ bytesToHex,
7
+ hexToBytes,
8
+ } from '../index.js'
9
+
10
+ export type SignatureToCompactSignatureErrorType =
11
+ | HexToBytesErrorType
12
+ | BytesToHexErrorType
13
+ | ErrorType
14
+
15
+ /**
16
+ * @description Converts a signature into an [EIP-2098 compact signature](https://eips.ethereum.org/EIPS/eip-2098).
17
+ *
18
+ * @param signature The signature to convert.
19
+ * @returns The signature in compact format.
20
+ *
21
+ * @example
22
+ * signatureToCompactSignature({
23
+ * r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
24
+ * s: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
25
+ * v: 27n
26
+ * })
27
+ * // {
28
+ * // r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
29
+ * // yParityAndS: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'
30
+ * // }
31
+ */
32
+ export function signatureToCompactSignature(
33
+ signature: Signature,
34
+ ): CompactSignature {
35
+ const { r, s, v } = signature
36
+ const yParity = v - 27n
37
+ let yParityAndS = s
38
+ if (yParity === 1n) {
39
+ const bytes = hexToBytes(s)
40
+ bytes[0] |= 0x80
41
+ yParityAndS = bytesToHex(bytes)
42
+ }
43
+ return { r, yParityAndS }
44
+ }