viem 2.15.0 → 2.16.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +28 -0
- package/README.md +17 -11
- package/_cjs/actions/public/verifyHash.js +21 -3
- package/_cjs/actions/public/verifyHash.js.map +1 -1
- package/_cjs/actions/public/verifyMessage.js +3 -1
- package/_cjs/actions/public/verifyMessage.js.map +1 -1
- package/_cjs/actions/public/verifyTypedData.js +3 -1
- package/_cjs/actions/public/verifyTypedData.js.map +1 -1
- package/_cjs/chains/definitions/zetachain.js +6 -0
- package/_cjs/chains/definitions/zetachain.js.map +1 -1
- package/_cjs/chains/definitions/zetachainAthensTestnet.js +6 -0
- package/_cjs/chains/definitions/zetachainAthensTestnet.js.map +1 -1
- package/_cjs/chains/definitions/zircuitTestnet.js +27 -0
- package/_cjs/chains/definitions/zircuitTestnet.js.map +1 -0
- package/_cjs/chains/index.js +3 -1
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/index.js +10 -4
- package/_cjs/experimental/index.js.map +1 -1
- package/_cjs/experimental/solady/actions/signMessage.js +40 -0
- package/_cjs/experimental/solady/actions/signMessage.js.map +1 -0
- package/_cjs/experimental/solady/actions/signTypedData.js +83 -0
- package/_cjs/experimental/solady/actions/signTypedData.js.map +1 -0
- package/_cjs/experimental/solady/decorators/solady.js +16 -0
- package/_cjs/experimental/solady/decorators/solady.js.map +1 -0
- package/_cjs/experimental/solady/types.js +3 -0
- package/_cjs/experimental/solady/types.js.map +1 -0
- package/_cjs/index.js +11 -3
- package/_cjs/index.js.map +1 -1
- package/_cjs/utils/index.js +7 -1
- package/_cjs/utils/index.js.map +1 -1
- package/_cjs/utils/signature/hashMessage.js +2 -12
- package/_cjs/utils/signature/hashMessage.js.map +1 -1
- package/_cjs/utils/signature/hashTypedData.js +3 -1
- package/_cjs/utils/signature/hashTypedData.js.map +1 -1
- package/_cjs/{experimental/erc6492 → utils/signature}/isErc6492Signature.js +1 -1
- package/_cjs/utils/signature/isErc6492Signature.js.map +1 -0
- package/_cjs/{experimental/erc6492 → utils/signature}/parseErc6492Signature.js +1 -1
- package/_cjs/utils/signature/parseErc6492Signature.js.map +1 -0
- package/_cjs/{experimental/erc6492 → utils/signature}/serializeErc6492Signature.js +2 -2
- package/_cjs/utils/signature/serializeErc6492Signature.js.map +1 -0
- package/_cjs/utils/signature/toPrefixedMessage.js +20 -0
- package/_cjs/utils/signature/toPrefixedMessage.js.map +1 -0
- package/_esm/actions/public/getTransactionCount.js +1 -1
- package/_esm/actions/public/verifyHash.js +27 -3
- package/_esm/actions/public/verifyHash.js.map +1 -1
- package/_esm/actions/public/verifyMessage.js +3 -1
- package/_esm/actions/public/verifyMessage.js.map +1 -1
- package/_esm/actions/public/verifyTypedData.js +3 -1
- package/_esm/actions/public/verifyTypedData.js.map +1 -1
- package/_esm/chains/definitions/zetachain.js +6 -0
- package/_esm/chains/definitions/zetachain.js.map +1 -1
- package/_esm/chains/definitions/zetachainAthensTestnet.js +6 -0
- package/_esm/chains/definitions/zetachainAthensTestnet.js.map +1 -1
- package/_esm/chains/definitions/zircuitTestnet.js +24 -0
- package/_esm/chains/definitions/zircuitTestnet.js.map +1 -0
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/index.js +12 -3
- package/_esm/experimental/index.js.map +1 -1
- package/_esm/experimental/solady/actions/signMessage.js +84 -0
- package/_esm/experimental/solady/actions/signMessage.js.map +1 -0
- package/_esm/experimental/solady/actions/signTypedData.js +182 -0
- package/_esm/experimental/solady/actions/signTypedData.js.map +1 -0
- package/_esm/experimental/solady/decorators/solady.js +27 -0
- package/_esm/experimental/solady/decorators/solady.js.map +1 -0
- package/_esm/experimental/solady/types.js +2 -0
- package/_esm/experimental/solady/types.js.map +1 -0
- package/_esm/index.js +4 -0
- package/_esm/index.js.map +1 -1
- package/_esm/utils/index.js +3 -0
- package/_esm/utils/index.js.map +1 -1
- package/_esm/utils/signature/hashMessage.js +2 -12
- package/_esm/utils/signature/hashMessage.js.map +1 -1
- package/_esm/utils/signature/hashTypedData.js +2 -2
- package/_esm/utils/signature/hashTypedData.js.map +1 -1
- package/_esm/{experimental/erc6492 → utils/signature}/isErc6492Signature.js +1 -1
- package/_esm/utils/signature/isErc6492Signature.js.map +1 -0
- package/_esm/{experimental/erc6492 → utils/signature}/parseErc6492Signature.js +1 -1
- package/_esm/utils/signature/parseErc6492Signature.js.map +1 -0
- package/_esm/{experimental/erc6492 → utils/signature}/serializeErc6492Signature.js +2 -2
- package/_esm/utils/signature/serializeErc6492Signature.js.map +1 -0
- package/_esm/utils/signature/toPrefixedMessage.js +16 -0
- package/_esm/utils/signature/toPrefixedMessage.js.map +1 -0
- package/_types/actions/public/getTransactionCount.d.ts +1 -1
- package/_types/actions/public/verifyHash.d.ts +6 -2
- package/_types/actions/public/verifyHash.d.ts.map +1 -1
- package/_types/actions/public/verifyMessage.d.ts +1 -1
- package/_types/actions/public/verifyMessage.d.ts.map +1 -1
- package/_types/actions/public/verifyTypedData.d.ts.map +1 -1
- package/_types/chains/definitions/zetachain.d.ts +6 -8
- package/_types/chains/definitions/zetachain.d.ts.map +1 -1
- package/_types/chains/definitions/zetachainAthensTestnet.d.ts +6 -8
- package/_types/chains/definitions/zetachainAthensTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zircuitTestnet.d.ts +33 -0
- package/_types/chains/definitions/zircuitTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/index.d.ts +30 -3
- package/_types/experimental/index.d.ts.map +1 -1
- package/_types/experimental/solady/actions/signMessage.d.ts +71 -0
- package/_types/experimental/solady/actions/signMessage.d.ts.map +1 -0
- package/_types/experimental/solady/actions/signTypedData.d.ts +125 -0
- package/_types/experimental/solady/actions/signTypedData.d.ts.map +1 -0
- package/_types/experimental/solady/decorators/solady.d.ts +183 -0
- package/_types/experimental/solady/decorators/solady.d.ts.map +1 -0
- package/_types/experimental/solady/types.d.ts +7 -0
- package/_types/experimental/solady/types.d.ts.map +1 -0
- package/_types/index.d.ts +4 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/utils/index.d.ts +3 -0
- package/_types/utils/index.d.ts.map +1 -1
- package/_types/utils/signature/hashMessage.d.ts +1 -3
- package/_types/utils/signature/hashMessage.d.ts.map +1 -1
- package/_types/utils/signature/hashTypedData.d.ts +9 -0
- package/_types/utils/signature/hashTypedData.d.ts.map +1 -1
- package/_types/{experimental/erc6492 → utils/signature}/isErc6492Signature.d.ts +1 -1
- package/_types/utils/signature/isErc6492Signature.d.ts.map +1 -0
- package/_types/{experimental/erc6492 → utils/signature}/parseErc6492Signature.d.ts +1 -1
- package/_types/utils/signature/parseErc6492Signature.d.ts.map +1 -0
- package/_types/utils/signature/serializeErc6492Signature.d.ts.map +1 -0
- package/_types/utils/signature/toPrefixedMessage.d.ts +7 -0
- package/_types/utils/signature/toPrefixedMessage.d.ts.map +1 -0
- package/actions/public/getTransactionCount.ts +1 -1
- package/actions/public/verifyHash.ts +31 -4
- package/actions/public/verifyMessage.ts +10 -1
- package/actions/public/verifyTypedData.ts +4 -0
- package/chains/definitions/zetachain.ts +6 -0
- package/chains/definitions/zetachainAthensTestnet.ts +6 -0
- package/chains/definitions/zircuitTestnet.ts +24 -0
- package/chains/index.ts +1 -0
- package/errors/version.ts +1 -1
- package/experimental/index.ts +33 -3
- package/experimental/solady/actions/signMessage.ts +151 -0
- package/experimental/solady/actions/signTypedData.ts +280 -0
- package/experimental/solady/decorators/solady.ts +232 -0
- package/experimental/solady/types.ts +7 -0
- package/index.ts +22 -0
- package/package.json +3 -3
- package/utils/index.ts +18 -0
- package/utils/signature/hashMessage.ts +3 -23
- package/utils/signature/hashTypedData.ts +2 -2
- package/{experimental/erc6492 → utils/signature}/isErc6492Signature.ts +1 -1
- package/{experimental/erc6492 → utils/signature}/parseErc6492Signature.ts +1 -1
- package/{experimental/erc6492 → utils/signature}/serializeErc6492Signature.ts +2 -2
- package/utils/signature/toPrefixedMessage.ts +27 -0
- package/_cjs/experimental/erc6492/isErc6492Signature.js.map +0 -1
- package/_cjs/experimental/erc6492/parseErc6492Signature.js.map +0 -1
- package/_cjs/experimental/erc6492/serializeErc6492Signature.js.map +0 -1
- package/_esm/experimental/erc6492/isErc6492Signature.js.map +0 -1
- package/_esm/experimental/erc6492/parseErc6492Signature.js.map +0 -1
- package/_esm/experimental/erc6492/serializeErc6492Signature.js.map +0 -1
- package/_types/experimental/erc6492/isErc6492Signature.d.ts.map +0 -1
- package/_types/experimental/erc6492/parseErc6492Signature.d.ts.map +0 -1
- package/_types/experimental/erc6492/serializeErc6492Signature.d.ts.map +0 -1
- /package/_types/{experimental/erc6492 → utils/signature}/serializeErc6492Signature.d.ts +0 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
import type { Address, TypedData } from 'abitype'
|
2
|
+
import type { Client } from '../../../clients/createClient.js'
|
3
|
+
import type { Transport } from '../../../clients/transports/createTransport.js'
|
4
|
+
import type { Account } from '../../../types/account.js'
|
5
|
+
import type { Chain } from '../../../types/chain.js'
|
6
|
+
import {
|
7
|
+
type SignMessageParameters,
|
8
|
+
type SignMessageReturnType,
|
9
|
+
signMessage,
|
10
|
+
} from '../actions/signMessage.js'
|
11
|
+
import {
|
12
|
+
type SignTypedDataParameters,
|
13
|
+
type SignTypedDataReturnType,
|
14
|
+
signTypedData,
|
15
|
+
} from '../actions/signTypedData.js'
|
16
|
+
|
17
|
+
export type SoladyActions<
|
18
|
+
account extends Account | undefined = Account | undefined,
|
19
|
+
verifier extends Address | undefined = Address | undefined,
|
20
|
+
> = {
|
21
|
+
/**
|
22
|
+
* Signs a [EIP-191](https://eips.ethereum.org/EIPS/eip-191) personal sign message via Solady's [ERC1271 `PersonalSign` format](https://github.com/Vectorized/solady/blob/678c9163550810b08f0ffb09624c9f7532392303/src/accounts/ERC1271.sol#L154-L166).
|
23
|
+
*
|
24
|
+
* This Action is suitable to sign messages for Smart Accounts that implement (or conform to) Solady's [ERC1271.sol](https://github.com/Vectorized/solady/blob/main/src/accounts/ERC1271.sol).
|
25
|
+
*
|
26
|
+
* - Docs: https://viem.sh/experimental/solady/signMessage
|
27
|
+
*
|
28
|
+
* With the calculated signature, you can:
|
29
|
+
* - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage) to verify the signature,
|
30
|
+
*
|
31
|
+
* @param client - Client to use
|
32
|
+
* @param parameters - {@link SignMessageParameters}
|
33
|
+
* @returns The signed message. {@link SignMessageReturnType}
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
* ```ts
|
37
|
+
* import { createWalletClient, custom } from 'viem'
|
38
|
+
* import { mainnet } from 'viem/chains'
|
39
|
+
* import { soladyActions } from 'viem/experimental/solady'
|
40
|
+
*
|
41
|
+
* const client = createWalletClient({
|
42
|
+
* chain: mainnet,
|
43
|
+
* transport: custom(window.ethereum),
|
44
|
+
* }).extend(soladyActions())
|
45
|
+
*
|
46
|
+
* const signature = await client.signMessage({
|
47
|
+
* account: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb',
|
48
|
+
* message: 'hello world',
|
49
|
+
* verifier: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
50
|
+
* })
|
51
|
+
* ```
|
52
|
+
*
|
53
|
+
* @example Account & Signer Hoisting
|
54
|
+
* ```ts
|
55
|
+
* import { createWalletClient, custom } from 'viem'
|
56
|
+
* import { mainnet } from 'viem/chains'
|
57
|
+
* import { soladyActions } from 'viem/experimental/solady'
|
58
|
+
*
|
59
|
+
* const client = createWalletClient({
|
60
|
+
* account: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb',
|
61
|
+
* chain: mainnet,
|
62
|
+
* transport: custom(window.ethereum),
|
63
|
+
* }).extend(soladyActions({ verifier: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e' }))
|
64
|
+
*
|
65
|
+
* const signature = await client.signMessage({
|
66
|
+
* message: 'hello world',
|
67
|
+
* })
|
68
|
+
* ```
|
69
|
+
*/
|
70
|
+
signMessage: <accountOverride extends Account | undefined = undefined>(
|
71
|
+
parameters: SignMessageParameters<account, accountOverride, verifier>,
|
72
|
+
) => Promise<SignMessageReturnType>
|
73
|
+
/**
|
74
|
+
* Signs an [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data message via Solady's [ERC1271 `TypedDataSign` format](https://github.com/Vectorized/solady/blob/678c9163550810b08f0ffb09624c9f7532392303/src/accounts/ERC1271.sol#L130-L151).
|
75
|
+
*
|
76
|
+
* This Action is suitable to sign messages for Smart Accounts that implement (or conform to) Solady's [ERC1271.sol](https://github.com/Vectorized/solady/blob/main/src/accounts/ERC1271.sol).
|
77
|
+
*
|
78
|
+
* - Docs: https://viem.sh/experimental/solady/signTypedData
|
79
|
+
*
|
80
|
+
* @param client - Client to use
|
81
|
+
* @param parameters - {@link SignTypedDataParameters}
|
82
|
+
* @returns The signed data. {@link SignTypedDataReturnType}
|
83
|
+
*
|
84
|
+
* @example
|
85
|
+
* ```ts
|
86
|
+
* import { createWalletClient, custom } from 'viem'
|
87
|
+
* import { mainnet } from 'viem/chains'
|
88
|
+
* import { soladyActions } from 'viem/experimental/solady'
|
89
|
+
*
|
90
|
+
* const client = createWalletClient({
|
91
|
+
* chain: mainnet,
|
92
|
+
* transport: custom(window.ethereum),
|
93
|
+
* }).extend(soladyActions())
|
94
|
+
*
|
95
|
+
* const signature = await client.signTypedData({
|
96
|
+
* account: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb',
|
97
|
+
* domain: {
|
98
|
+
* name: 'Ether Mail',
|
99
|
+
* version: '1',
|
100
|
+
* chainId: 1,
|
101
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
102
|
+
* },
|
103
|
+
* types: {
|
104
|
+
* Person: [
|
105
|
+
* { name: 'name', type: 'string' },
|
106
|
+
* { name: 'wallet', type: 'address' },
|
107
|
+
* ],
|
108
|
+
* Mail: [
|
109
|
+
* { name: 'from', type: 'Person' },
|
110
|
+
* { name: 'to', type: 'Person' },
|
111
|
+
* { name: 'contents', type: 'string' },
|
112
|
+
* ],
|
113
|
+
* },
|
114
|
+
* primaryType: 'Mail',
|
115
|
+
* message: {
|
116
|
+
* from: {
|
117
|
+
* name: 'Cow',
|
118
|
+
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
119
|
+
* },
|
120
|
+
* to: {
|
121
|
+
* name: 'Bob',
|
122
|
+
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
123
|
+
* },
|
124
|
+
* contents: 'Hello, Bob!',
|
125
|
+
* },
|
126
|
+
* verifier: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
127
|
+
* })
|
128
|
+
* ```
|
129
|
+
*
|
130
|
+
* @example Account & Signer Hoisting
|
131
|
+
* ```ts
|
132
|
+
* import { createWalletClient, http } from 'viem'
|
133
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
134
|
+
* import { mainnet } from 'viem/chains'
|
135
|
+
* import { soladyActions } from 'viem/experimental/solady'
|
136
|
+
*
|
137
|
+
* const client = createWalletClient({
|
138
|
+
* account: '0xE8Df82fA4E10e6A12a9Dab552bceA2acd26De9bb',
|
139
|
+
* chain: mainnet,
|
140
|
+
* transport: http(),
|
141
|
+
* }).extend(soladyActions({ verifier: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e' }))
|
142
|
+
*
|
143
|
+
* const signature = await client.signTypedData({
|
144
|
+
* domain: {
|
145
|
+
* name: 'Ether Mail',
|
146
|
+
* version: '1',
|
147
|
+
* chainId: 1,
|
148
|
+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
149
|
+
* },
|
150
|
+
* types: {
|
151
|
+
* Person: [
|
152
|
+
* { name: 'name', type: 'string' },
|
153
|
+
* { name: 'wallet', type: 'address' },
|
154
|
+
* ],
|
155
|
+
* Mail: [
|
156
|
+
* { name: 'from', type: 'Person' },
|
157
|
+
* { name: 'to', type: 'Person' },
|
158
|
+
* { name: 'contents', type: 'string' },
|
159
|
+
* ],
|
160
|
+
* },
|
161
|
+
* primaryType: 'Mail',
|
162
|
+
* message: {
|
163
|
+
* from: {
|
164
|
+
* name: 'Cow',
|
165
|
+
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
166
|
+
* },
|
167
|
+
* to: {
|
168
|
+
* name: 'Bob',
|
169
|
+
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
170
|
+
* },
|
171
|
+
* contents: 'Hello, Bob!',
|
172
|
+
* },
|
173
|
+
* })
|
174
|
+
* ```
|
175
|
+
*/
|
176
|
+
signTypedData: <
|
177
|
+
const typedData extends TypedData | Record<string, unknown>,
|
178
|
+
primaryType extends keyof typedData | 'EIP712Domain',
|
179
|
+
accountOverride extends Account | undefined = undefined,
|
180
|
+
>(
|
181
|
+
parameters: SignTypedDataParameters<
|
182
|
+
typedData,
|
183
|
+
primaryType,
|
184
|
+
account,
|
185
|
+
accountOverride
|
186
|
+
>,
|
187
|
+
) => Promise<SignTypedDataReturnType>
|
188
|
+
}
|
189
|
+
|
190
|
+
export type SoladyActionsParameters<
|
191
|
+
verifier extends Account | Address | undefined =
|
192
|
+
| Account
|
193
|
+
| Address
|
194
|
+
| undefined,
|
195
|
+
> = {
|
196
|
+
verifier?: verifier | undefined
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
* A suite of Actions based on [Solady contracts](https://github.com/Vectorized/solady).
|
201
|
+
*
|
202
|
+
* @example
|
203
|
+
* import { createPublicClient, createWalletClient, http } from 'viem'
|
204
|
+
* import { mainnet } from 'viem/chains'
|
205
|
+
* import { soladyActions } from 'viem/experimental'
|
206
|
+
*
|
207
|
+
* const walletClient = createWalletClient({
|
208
|
+
* chain: mainnet,
|
209
|
+
* transport: http(),
|
210
|
+
* }).extend(soladyActions())
|
211
|
+
*
|
212
|
+
* const result = await walletClient.signMessage({...})
|
213
|
+
*/
|
214
|
+
export function soladyActions<verifier extends Address | undefined = undefined>(
|
215
|
+
parameters: SoladyActionsParameters<verifier> = {},
|
216
|
+
) {
|
217
|
+
const { verifier } = parameters
|
218
|
+
return <
|
219
|
+
transport extends Transport,
|
220
|
+
chain extends Chain | undefined = Chain | undefined,
|
221
|
+
account extends Account | undefined = Account | undefined,
|
222
|
+
>(
|
223
|
+
client: Client<transport, chain, account>,
|
224
|
+
): SoladyActions<account, verifier> => {
|
225
|
+
return {
|
226
|
+
signMessage: (parameters) =>
|
227
|
+
signMessage(client, { verifier, ...parameters }),
|
228
|
+
signTypedData: (parameters) =>
|
229
|
+
signTypedData(client, { verifier, ...(parameters as any) }),
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}
|
package/index.ts
CHANGED
@@ -1316,6 +1316,24 @@ export {
|
|
1316
1316
|
type VerifyTypedDataReturnType,
|
1317
1317
|
verifyTypedData,
|
1318
1318
|
} from './utils/signature/verifyTypedData.js'
|
1319
|
+
export {
|
1320
|
+
type ParseErc6492SignatureErrorType,
|
1321
|
+
type ParseErc6492SignatureParameters,
|
1322
|
+
type ParseErc6492SignatureReturnType,
|
1323
|
+
parseErc6492Signature,
|
1324
|
+
} from './utils/signature/parseErc6492Signature.js'
|
1325
|
+
export {
|
1326
|
+
type IsErc6492SignatureErrorType,
|
1327
|
+
type IsErc6492SignatureParameters,
|
1328
|
+
type IsErc6492SignatureReturnType,
|
1329
|
+
isErc6492Signature,
|
1330
|
+
} from './utils/signature/isErc6492Signature.js'
|
1331
|
+
export {
|
1332
|
+
type SerializeErc6492SignatureErrorType,
|
1333
|
+
type SerializeErc6492SignatureParameters,
|
1334
|
+
type SerializeErc6492SignatureReturnType,
|
1335
|
+
serializeErc6492Signature,
|
1336
|
+
} from './utils/signature/serializeErc6492Signature.js'
|
1319
1337
|
export {
|
1320
1338
|
type AssertRequestErrorType,
|
1321
1339
|
assertRequest,
|
@@ -1569,6 +1587,10 @@ export {
|
|
1569
1587
|
type HashMessageErrorType,
|
1570
1588
|
hashMessage,
|
1571
1589
|
} from './utils/signature/hashMessage.js'
|
1590
|
+
export {
|
1591
|
+
type ToPrefixedMessageErrorType,
|
1592
|
+
toPrefixedMessage,
|
1593
|
+
} from './utils/signature/toPrefixedMessage.js'
|
1572
1594
|
export {
|
1573
1595
|
type IsAddressOptions,
|
1574
1596
|
type IsAddressErrorType,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "viem",
|
3
3
|
"description": "TypeScript Interface for Ethereum",
|
4
|
-
"version": "2.
|
4
|
+
"version": "2.16.0",
|
5
5
|
"main": "./_cjs/index.js",
|
6
6
|
"module": "./_esm/index.js",
|
7
7
|
"types": "./_types/index.d.ts",
|
@@ -153,9 +153,9 @@
|
|
153
153
|
"@noble/hashes": "1.3.2",
|
154
154
|
"@scure/bip32": "1.3.2",
|
155
155
|
"@scure/bip39": "1.2.1",
|
156
|
-
"abitype": "1.0.
|
156
|
+
"abitype": "1.0.4",
|
157
157
|
"isows": "1.0.4",
|
158
|
-
"ws": "8.
|
158
|
+
"ws": "8.17.1"
|
159
159
|
},
|
160
160
|
"license": "MIT",
|
161
161
|
"homepage": "https://viem.sh",
|
package/utils/index.ts
CHANGED
@@ -450,6 +450,24 @@ export {
|
|
450
450
|
type HashMessageErrorType,
|
451
451
|
hashMessage,
|
452
452
|
} from './signature/hashMessage.js'
|
453
|
+
export {
|
454
|
+
type ParseErc6492SignatureErrorType,
|
455
|
+
type ParseErc6492SignatureParameters,
|
456
|
+
type ParseErc6492SignatureReturnType,
|
457
|
+
parseErc6492Signature,
|
458
|
+
} from './signature/parseErc6492Signature.js'
|
459
|
+
export {
|
460
|
+
type IsErc6492SignatureErrorType,
|
461
|
+
type IsErc6492SignatureParameters,
|
462
|
+
type IsErc6492SignatureReturnType,
|
463
|
+
isErc6492Signature,
|
464
|
+
} from './signature/isErc6492Signature.js'
|
465
|
+
export {
|
466
|
+
type SerializeErc6492SignatureErrorType,
|
467
|
+
type SerializeErc6492SignatureParameters,
|
468
|
+
type SerializeErc6492SignatureReturnType,
|
469
|
+
serializeErc6492Signature,
|
470
|
+
} from './signature/serializeErc6492Signature.js'
|
453
471
|
export {
|
454
472
|
type GetSerializedTransactionTypeErrorType,
|
455
473
|
type GetSerializedTransactionType,
|
@@ -1,14 +1,7 @@
|
|
1
|
-
import { presignMessagePrefix } from '../../constants/strings.js'
|
2
1
|
import type { ErrorType } from '../../errors/utils.js'
|
3
2
|
import type { ByteArray, Hex, SignableMessage } from '../../types/misc.js'
|
4
|
-
import { type ConcatErrorType, concat } from '../data/concat.js'
|
5
|
-
import {
|
6
|
-
type StringToBytesErrorType,
|
7
|
-
type ToBytesErrorType,
|
8
|
-
stringToBytes,
|
9
|
-
toBytes,
|
10
|
-
} from '../encoding/toBytes.js'
|
11
3
|
import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js'
|
4
|
+
import { toPrefixedMessage } from './toPrefixedMessage.js'
|
12
5
|
|
13
6
|
type To = 'hex' | 'bytes'
|
14
7
|
|
@@ -16,24 +9,11 @@ export type HashMessage<TTo extends To> =
|
|
16
9
|
| (TTo extends 'bytes' ? ByteArray : never)
|
17
10
|
| (TTo extends 'hex' ? Hex : never)
|
18
11
|
|
19
|
-
export type HashMessageErrorType =
|
20
|
-
| ConcatErrorType
|
21
|
-
| Keccak256ErrorType
|
22
|
-
| StringToBytesErrorType
|
23
|
-
| ToBytesErrorType
|
24
|
-
| ErrorType
|
12
|
+
export type HashMessageErrorType = Keccak256ErrorType | ErrorType
|
25
13
|
|
26
14
|
export function hashMessage<TTo extends To = 'hex'>(
|
27
15
|
message: SignableMessage,
|
28
16
|
to_?: TTo | undefined,
|
29
17
|
): HashMessage<TTo> {
|
30
|
-
|
31
|
-
if (typeof message === 'string') return stringToBytes(message)
|
32
|
-
if (message.raw instanceof Uint8Array) return message.raw
|
33
|
-
return toBytes(message.raw)
|
34
|
-
})()
|
35
|
-
const prefixBytes = stringToBytes(
|
36
|
-
`${presignMessagePrefix}${messageBytes.length}`,
|
37
|
-
)
|
38
|
-
return keccak256(concat([prefixBytes, messageBytes]), to_)
|
18
|
+
return keccak256(toPrefixedMessage(message), to_)
|
39
19
|
}
|
@@ -102,7 +102,7 @@ export function hashDomain({
|
|
102
102
|
|
103
103
|
type HashStructErrorType = EncodeDataErrorType | Keccak256ErrorType | ErrorType
|
104
104
|
|
105
|
-
function hashStruct({
|
105
|
+
export function hashStruct({
|
106
106
|
data,
|
107
107
|
primaryType,
|
108
108
|
types,
|
@@ -170,7 +170,7 @@ function hashType({
|
|
170
170
|
|
171
171
|
type EncodeTypeErrorType = FindTypeDependenciesErrorType
|
172
172
|
|
173
|
-
function encodeType({
|
173
|
+
export function encodeType({
|
174
174
|
primaryType,
|
175
175
|
types,
|
176
176
|
}: {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { erc6492MagicBytes } from '../../constants/bytes.js'
|
2
2
|
import type { ErrorType } from '../../errors/utils.js'
|
3
3
|
import type { Hex } from '../../types/misc.js'
|
4
|
-
import { type SliceHexErrorType, sliceHex } from '
|
4
|
+
import { type SliceHexErrorType, sliceHex } from '../data/slice.js'
|
5
5
|
|
6
6
|
export type IsErc6492SignatureParameters = Hex
|
7
7
|
export type IsErc6492SignatureReturnType = boolean
|
@@ -5,7 +5,7 @@ import type { OneOf, Prettify } from '../../types/utils.js'
|
|
5
5
|
import {
|
6
6
|
type DecodeAbiParametersErrorType,
|
7
7
|
decodeAbiParameters,
|
8
|
-
} from '
|
8
|
+
} from '../abi/decodeAbiParameters.js'
|
9
9
|
import {
|
10
10
|
type IsErc6492SignatureErrorType,
|
11
11
|
isErc6492Signature,
|
@@ -2,8 +2,8 @@ import type { Address } from 'abitype'
|
|
2
2
|
import { erc6492MagicBytes } from '../../constants/bytes.js'
|
3
3
|
import type { ErrorType } from '../../errors/utils.js'
|
4
4
|
import type { Hex } from '../../types/misc.js'
|
5
|
-
import { encodeAbiParameters } from '
|
6
|
-
import { concatHex } from '
|
5
|
+
import { encodeAbiParameters } from '../abi/encodeAbiParameters.js'
|
6
|
+
import { concatHex } from '../data/concat.js'
|
7
7
|
|
8
8
|
export type SerializeErc6492SignatureParameters = {
|
9
9
|
/** The ERC-4337 Account Factory address to use for counterfactual verification. */
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { presignMessagePrefix } from '../../constants/strings.js'
|
2
|
+
import type { ErrorType } from '../../errors/utils.js'
|
3
|
+
import type { Hex, SignableMessage } from '../../types/misc.js'
|
4
|
+
import { type ConcatErrorType, concat } from '../data/concat.js'
|
5
|
+
import { size } from '../data/size.js'
|
6
|
+
import {
|
7
|
+
type BytesToHexErrorType,
|
8
|
+
type StringToHexErrorType,
|
9
|
+
bytesToHex,
|
10
|
+
stringToHex,
|
11
|
+
} from '../encoding/toHex.js'
|
12
|
+
|
13
|
+
export type ToPrefixedMessageErrorType =
|
14
|
+
| ConcatErrorType
|
15
|
+
| StringToHexErrorType
|
16
|
+
| BytesToHexErrorType
|
17
|
+
| ErrorType
|
18
|
+
|
19
|
+
export function toPrefixedMessage(message_: SignableMessage): Hex {
|
20
|
+
const message = (() => {
|
21
|
+
if (typeof message_ === 'string') return stringToHex(message_)
|
22
|
+
if (typeof message_.raw === 'string') return message_.raw
|
23
|
+
return bytesToHex(message_.raw)
|
24
|
+
})()
|
25
|
+
const prefix = stringToHex(`${presignMessagePrefix}${size(message)}`)
|
26
|
+
return concat([prefix, message])
|
27
|
+
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"isErc6492Signature.js","sourceRoot":"","sources":["../../../experimental/erc6492/isErc6492Signature.ts"],"names":[],"mappings":";;;AAAA,uDAA4D;AAG5D,wDAA4E;AAO5E,SAAgB,kBAAkB,CAChC,SAAuC;IAEvC,OAAO,IAAA,mBAAQ,EAAC,SAAS,EAAE,CAAC,EAAE,CAAC,KAAK,4BAAiB,CAAA;AACvD,CAAC;AAJD,gDAIC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"parseErc6492Signature.js","sourceRoot":"","sources":["../../../experimental/erc6492/parseErc6492Signature.ts"],"names":[],"mappings":";;;AAIA,mFAG+C;AAC/C,mEAGgC;AA2ChC,SAAgB,qBAAqB,CACnC,SAA0C;IAE1C,IAAI,CAAC,IAAA,0CAAkB,EAAC,SAAS,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,CAAA;IAExD,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,IAAA,4CAAmB,EACrD,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAC3D,SAAS,CACV,CAAA;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAA;AACjD,CAAC;AAVD,sDAUC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"serializeErc6492Signature.js","sourceRoot":"","sources":["../../../experimental/erc6492/serializeErc6492Signature.ts"],"names":[],"mappings":";;;AACA,uDAA4D;AAG5D,mFAA4E;AAC5E,0DAAsD;AAyBtD,SAAgB,yBAAyB,CACvC,UAA+C;IAE/C,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,UAAU,CAAA;IAC/C,OAAO,IAAA,qBAAS,EAAC;QACf,IAAA,4CAAmB,EACjB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAC3D,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAC3B;QACD,4BAAiB;KAClB,CAAC,CAAA;AACJ,CAAC;AAXD,8DAWC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"isErc6492Signature.js","sourceRoot":"","sources":["../../../experimental/erc6492/isErc6492Signature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAG5D,OAAO,EAA0B,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAM5E,uEAAuE;AACvE,MAAM,UAAU,kBAAkB,CAChC,SAAuC;IAEvC,OAAO,QAAQ,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,KAAK,iBAAiB,CAAA;AACvD,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"parseErc6492Signature.js","sourceRoot":"","sources":["../../../experimental/erc6492/parseErc6492Signature.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,mBAAmB,GACpB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAEL,kBAAkB,GACnB,MAAM,yBAAyB,CAAA;AAgChC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CACnC,SAA0C;IAE1C,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,CAAA;IAExD,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,mBAAmB,CACrD,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAC3D,SAAS,CACV,CAAA;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAA;AACjD,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"serializeErc6492Signature.js","sourceRoot":"","sources":["../../../experimental/erc6492/serializeErc6492Signature.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAG5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAetD;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACvC,UAA+C;IAE/C,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,UAAU,CAAA;IAC/C,OAAO,SAAS,CAAC;QACf,mBAAmB,CACjB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAC3D,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,CAC3B;QACD,iBAAiB;KAClB,CAAC,CAAA;AACJ,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"isErc6492Signature.d.ts","sourceRoot":"","sources":["../../../experimental/erc6492/isErc6492Signature.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,KAAK,iBAAiB,EAAY,MAAM,2BAA2B,CAAA;AAE5E,MAAM,MAAM,4BAA4B,GAAG,GAAG,CAAA;AAC9C,MAAM,MAAM,4BAA4B,GAAG,OAAO,CAAA;AAClD,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,GAAG,SAAS,CAAA;AAEvE,uEAAuE;AACvE,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,4BAA4B,GACtC,4BAA4B,CAE9B"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"parseErc6492Signature.d.ts","sourceRoot":"","sources":["../../../experimental/erc6492/parseErc6492Signature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EACL,KAAK,4BAA4B,EAElC,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,yBAAyB,CAAA;AAEhC,MAAM,MAAM,+BAA+B,GAAG,GAAG,CAAA;AAEjD,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CACpD,KAAK,CACD;IACE;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;;OAGG;IACH,IAAI,EAAE,GAAG,CAAA;IACT,8BAA8B;IAC9B,SAAS,EAAE,GAAG,CAAA;CACf,GACD;IACE,8BAA8B;IAC9B,SAAS,EAAE,GAAG,CAAA;CACf,CACJ,CACF,CAAA;AAED,MAAM,MAAM,8BAA8B,GACtC,2BAA2B,GAC3B,4BAA4B,GAC5B,SAAS,CAAA;AAEb;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,+BAA+B,GACzC,+BAA+B,CAQjC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"serializeErc6492Signature.d.ts","sourceRoot":"","sources":["../../../experimental/erc6492/serializeErc6492Signature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAI9C,MAAM,MAAM,mCAAmC,GAAG;IAChD,mFAAmF;IACnF,OAAO,EAAE,OAAO,CAAA;IAChB,4FAA4F;IAC5F,IAAI,EAAE,GAAG,CAAA;IACT,8BAA8B;IAC9B,SAAS,EAAE,GAAG,CAAA;CACf,CAAA;AAED,MAAM,MAAM,mCAAmC,GAAG,GAAG,CAAA;AAErD,MAAM,MAAM,kCAAkC,GAAG,SAAS,CAAA;AAE1D;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,mCAAmC,GAC9C,mCAAmC,CASrC"}
|
File without changes
|