1
1
import type * as ox__TypedData from "ox/TypedData" ;
2
2
import { serializeErc6492Signature } from "../../../auth/serialize-erc6492-signature.js" ;
3
- import {
4
- verifyEip1271Signature ,
5
- verifyHash ,
6
- } from "../../../auth/verify-hash.js" ;
3
+ import { verifyEip1271Signature } from "../../../auth/verify-hash.js" ;
7
4
import type { Chain } from "../../../chains/types.js" ;
8
5
import type { ThirdwebClient } from "../../../client/client.js" ;
9
- import {
10
- getContract ,
11
- type ThirdwebContract ,
12
- } from "../../../contract/contract.js" ;
6
+ import type { ThirdwebContract } from "../../../contract/contract.js" ;
13
7
import { encode } from "../../../transaction/actions/encode.js" ;
14
- import { readContract } from "../../../transaction/read-contract.js" ;
15
8
import { encodeAbiParameters } from "../../../utils/abi/encodeAbiParameters.js" ;
16
9
import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed.js" ;
17
- import type { Hex } from "../../../utils/encoding/hex.js" ;
18
10
import { hashMessage } from "../../../utils/hashing/hashMessage.js" ;
19
11
import { hashTypedData } from "../../../utils/hashing/hashTypedData.js" ;
20
12
import type { SignableMessage } from "../../../utils/types.js" ;
@@ -40,33 +32,24 @@ export async function smartAccountSignMessage({
40
32
message : SignableMessage ;
41
33
} ) {
42
34
const originalMsgHash = hashMessage ( message ) ;
43
- const is712Factory = await checkFor712Factory ( {
44
- accountContract,
45
- factoryContract,
46
- originalMsgHash,
47
- } ) ;
48
35
49
36
let sig : `0x${string } `;
50
- if ( is712Factory ) {
51
- const wrappedMessageHash = encodeAbiParameters (
52
- [ { type : "bytes32" } ] ,
53
- [ originalMsgHash ] ,
54
- ) ;
37
+ const wrappedMessageHash = encodeAbiParameters (
38
+ [ { type : "bytes32" } ] ,
39
+ [ originalMsgHash ] ,
40
+ ) ;
55
41
56
- sig = await options . personalAccount . signTypedData ( {
57
- domain : {
58
- chainId : options . chain . id ,
59
- name : "Account" ,
60
- verifyingContract : accountContract . address ,
61
- version : "1" ,
62
- } ,
63
- message : { message : wrappedMessageHash } ,
64
- primaryType : "AccountMessage" ,
65
- types : { AccountMessage : [ { name : "message" , type : "bytes" } ] } ,
66
- } ) ;
67
- } else {
68
- sig = await options . personalAccount . signMessage ( { message } ) ;
69
- }
42
+ sig = await options . personalAccount . signTypedData ( {
43
+ domain : {
44
+ chainId : options . chain . id ,
45
+ name : "Account" ,
46
+ verifyingContract : accountContract . address ,
47
+ version : "1" ,
48
+ } ,
49
+ message : { message : wrappedMessageHash } ,
50
+ primaryType : "AccountMessage" ,
51
+ types : { AccountMessage : [ { name : "message" , type : "bytes" } ] } ,
52
+ } ) ;
70
53
71
54
const isDeployed = await isContractDeployed ( accountContract ) ;
72
55
if ( isDeployed ) {
@@ -96,19 +79,7 @@ export async function smartAccountSignMessage({
96
79
signature : sig ,
97
80
} ) ;
98
81
99
- // check if the signature is valid
100
- const isValid = await verifyHash ( {
101
- address : accountContract . address ,
102
- chain : accountContract . chain ,
103
- client : accountContract . client ,
104
- hash : originalMsgHash ,
105
- signature : erc6492Sig ,
106
- } ) ;
107
-
108
- if ( isValid ) {
109
- return erc6492Sig ;
110
- }
111
- throw new Error ( "Unable to verify ERC-6492 signature after signing." ) ;
82
+ return erc6492Sig ;
112
83
}
113
84
}
114
85
@@ -138,33 +109,23 @@ export async function smartAccountSignTypedData<
138
109
}
139
110
140
111
const originalMsgHash = hashTypedData ( typedData ) ;
141
- // check if the account contract supports EIP721 domain separator based signing
142
- const is712Factory = await checkFor712Factory ( {
143
- accountContract,
144
- factoryContract,
145
- originalMsgHash,
146
- } ) ;
147
112
148
113
let sig : `0x${string } `;
149
- if ( is712Factory ) {
150
- const wrappedMessageHash = encodeAbiParameters (
151
- [ { type : "bytes32" } ] ,
152
- [ originalMsgHash ] ,
153
- ) ;
154
- sig = await options . personalAccount . signTypedData ( {
155
- domain : {
156
- chainId : options . chain . id ,
157
- name : "Account" ,
158
- verifyingContract : accountContract . address ,
159
- version : "1" ,
160
- } ,
161
- message : { message : wrappedMessageHash } ,
162
- primaryType : "AccountMessage" ,
163
- types : { AccountMessage : [ { name : "message" , type : "bytes" } ] } ,
164
- } ) ;
165
- } else {
166
- sig = await options . personalAccount . signTypedData ( typedData ) ;
167
- }
114
+ const wrappedMessageHash = encodeAbiParameters (
115
+ [ { type : "bytes32" } ] ,
116
+ [ originalMsgHash ] ,
117
+ ) ;
118
+ sig = await options . personalAccount . signTypedData ( {
119
+ domain : {
120
+ chainId : options . chain . id ,
121
+ name : "Account" ,
122
+ verifyingContract : accountContract . address ,
123
+ version : "1" ,
124
+ } ,
125
+ message : { message : wrappedMessageHash } ,
126
+ primaryType : "AccountMessage" ,
127
+ types : { AccountMessage : [ { name : "message" , type : "bytes" } ] } ,
128
+ } ) ;
168
129
169
130
const isDeployed = await isContractDeployed ( accountContract ) ;
170
131
if ( isDeployed ) {
@@ -194,21 +155,7 @@ export async function smartAccountSignTypedData<
194
155
signature : sig ,
195
156
} ) ;
196
157
197
- // check if the signature is valid
198
- const isValid = await verifyHash ( {
199
- address : accountContract . address ,
200
- chain : accountContract . chain ,
201
- client : accountContract . client ,
202
- hash : originalMsgHash ,
203
- signature : erc6492Sig ,
204
- } ) ;
205
-
206
- if ( isValid ) {
207
- return erc6492Sig ;
208
- }
209
- throw new Error (
210
- "Unable to verify signature on smart account, please make sure the admin wallet has permissions and the signature is valid." ,
211
- ) ;
158
+ return erc6492Sig ;
212
159
}
213
160
}
214
161
@@ -233,40 +180,6 @@ export async function confirmContractDeployment(args: {
233
180
}
234
181
}
235
182
236
- async function checkFor712Factory ( {
237
- factoryContract,
238
- accountContract,
239
- originalMsgHash,
240
- } : {
241
- factoryContract : ThirdwebContract ;
242
- accountContract : ThirdwebContract ;
243
- originalMsgHash : Hex ;
244
- } ) {
245
- try {
246
- const implementationAccount = await readContract ( {
247
- contract : factoryContract ,
248
- method : "function accountImplementation() public view returns (address)" ,
249
- } ) ;
250
- // check if the account contract supports EIP721 domain separator or modular based signing
251
- const is712Factory = await readContract ( {
252
- contract : getContract ( {
253
- address : implementationAccount ,
254
- chain : accountContract . chain ,
255
- client : accountContract . client ,
256
- } ) ,
257
- method :
258
- "function getMessageHash(bytes32 _hash) public view returns (bytes32)" ,
259
- params : [ originalMsgHash ] ,
260
- } )
261
- . then ( ( res ) => res !== "0x" )
262
- . catch ( ( ) => false ) ;
263
-
264
- return is712Factory ;
265
- } catch {
266
- return false ;
267
- }
268
- }
269
-
270
183
/**
271
184
* Deployes a smart account via a dummy transaction. If the account is already deployed, this will do nothing.
272
185
*
0 commit comments