11import type * as ox__TypedData from "ox/TypedData" ;
22import { 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" ;
74import type { Chain } from "../../../chains/types.js" ;
85import 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" ;
137import { encode } from "../../../transaction/actions/encode.js" ;
14- import { readContract } from "../../../transaction/read-contract.js" ;
158import { encodeAbiParameters } from "../../../utils/abi/encodeAbiParameters.js" ;
169import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed.js" ;
17- import type { Hex } from "../../../utils/encoding/hex.js" ;
1810import { hashMessage } from "../../../utils/hashing/hashMessage.js" ;
1911import { hashTypedData } from "../../../utils/hashing/hashTypedData.js" ;
2012import type { SignableMessage } from "../../../utils/types.js" ;
@@ -40,33 +32,24 @@ export async function smartAccountSignMessage({
4032 message : SignableMessage ;
4133} ) {
4234 const originalMsgHash = hashMessage ( message ) ;
43- const is712Factory = await checkFor712Factory ( {
44- accountContract,
45- factoryContract,
46- originalMsgHash,
47- } ) ;
4835
4936 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+ ) ;
5541
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+ } ) ;
7053
7154 const isDeployed = await isContractDeployed ( accountContract ) ;
7255 if ( isDeployed ) {
@@ -96,19 +79,7 @@ export async function smartAccountSignMessage({
9679 signature : sig ,
9780 } ) ;
9881
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 ;
11283 }
11384}
11485
@@ -138,33 +109,23 @@ export async function smartAccountSignTypedData<
138109 }
139110
140111 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- } ) ;
147112
148113 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+ } ) ;
168129
169130 const isDeployed = await isContractDeployed ( accountContract ) ;
170131 if ( isDeployed ) {
@@ -194,21 +155,7 @@ export async function smartAccountSignTypedData<
194155 signature : sig ,
195156 } ) ;
196157
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 ;
212159 }
213160}
214161
@@ -233,40 +180,6 @@ export async function confirmContractDeployment(args: {
233180 }
234181}
235182
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-
270183/**
271184 * Deployes a smart account via a dummy transaction. If the account is already deployed, this will do nothing.
272185 *
0 commit comments