@@ -180,36 +180,45 @@ export const create7702MinimalAccount = (args: {
180180 abi : MinimalAccountAbi ,
181181 } ) ;
182182 // check if account has been delegated already
183- let authorization : SignedAuthorization | undefined ;
183+ let authorization : SignedAuthorization | undefined =
184+ firstTx . authorizationList ?. [ 0 ] ;
184185 const delegationContractAddress = await getDelegationContractAddress ( {
185186 client,
186187 chain,
187188 } ) ;
188- const isMinimalAccount = await is7702MinimalAccount (
189- eoaContract ,
190- delegationContractAddress ,
191- ) ;
192- if ( ! isMinimalAccount ) {
193- // if not, sign authorization
194- let nonce = firstTx . nonce
195- ? BigInt ( firstTx . nonce )
196- : BigInt (
197- await getNonce ( {
198- client,
199- address : adminAccount . address ,
200- chain,
201- } ) ,
202- ) ;
203- nonce += sponsorGas ? 0n : 1n ;
204- const auth = await adminAccount . signAuthorization ?.( {
205- address : getAddress ( delegationContractAddress ) ,
206- chainId : firstTx . chainId ,
207- nonce,
208- } ) ;
209- if ( ! auth ) {
210- throw new Error ( "Failed to sign authorization" ) ;
189+ if ( authorization && authorization . address ?. toLowerCase ( ) !== delegationContractAddress . toLowerCase ( ) ) {
190+ throw new Error (
191+ `Authorization address does not match expected delegation contract address. Expected ${ delegationContractAddress } but got ${ authorization . address } ` ,
192+ ) ;
193+ }
194+ // if the tx already has an authorization, use it, otherwise sign one
195+ if ( ! authorization ) {
196+ const isMinimalAccount = await is7702MinimalAccount (
197+ eoaContract ,
198+ delegationContractAddress ,
199+ ) ;
200+ if ( ! isMinimalAccount ) {
201+ // if not, sign authorization
202+ let nonce = firstTx . nonce
203+ ? BigInt ( firstTx . nonce )
204+ : BigInt (
205+ await getNonce ( {
206+ client,
207+ address : adminAccount . address ,
208+ chain,
209+ } ) ,
210+ ) ;
211+ nonce += sponsorGas ? 0n : 1n ;
212+ const auth = await adminAccount . signAuthorization ?.( {
213+ address : getAddress ( delegationContractAddress ) ,
214+ chainId : firstTx . chainId ,
215+ nonce,
216+ } ) ;
217+ if ( ! auth ) {
218+ throw new Error ( "Failed to sign authorization" ) ;
219+ }
220+ authorization = auth ;
211221 }
212- authorization = auth ;
213222 }
214223 if ( sponsorGas ) {
215224 // send transaction from executor, needs signature
0 commit comments