@@ -180,36 +180,49 @@ export const create7702MinimalAccount = (args: {
180
180
abi : MinimalAccountAbi ,
181
181
} ) ;
182
182
// check if account has been delegated already
183
- let authorization : SignedAuthorization | undefined ;
183
+ let authorization : SignedAuthorization | undefined =
184
+ firstTx . authorizationList ?. [ 0 ] ;
184
185
const delegationContractAddress = await getDelegationContractAddress ( {
185
186
client,
186
187
chain,
187
188
} ) ;
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 (
190
+ authorization &&
191
+ authorization . address ?. toLowerCase ( ) !==
192
+ delegationContractAddress . toLowerCase ( )
193
+ ) {
194
+ throw new Error (
195
+ `Authorization address does not match expected delegation contract address. Expected ${ delegationContractAddress } but got ${ authorization . address } ` ,
196
+ ) ;
197
+ }
198
+ // if the tx already has an authorization, use it, otherwise sign one
199
+ if ( ! authorization ) {
200
+ const isMinimalAccount = await is7702MinimalAccount (
201
+ eoaContract ,
202
+ delegationContractAddress ,
203
+ ) ;
204
+ if ( ! isMinimalAccount ) {
205
+ // if not, sign authorization
206
+ let nonce = firstTx . nonce
207
+ ? BigInt ( firstTx . nonce )
208
+ : BigInt (
209
+ await getNonce ( {
210
+ client,
211
+ address : adminAccount . address ,
212
+ chain,
213
+ } ) ,
214
+ ) ;
215
+ nonce += sponsorGas ? 0n : 1n ;
216
+ const auth = await adminAccount . signAuthorization ?.( {
217
+ address : getAddress ( delegationContractAddress ) ,
218
+ chainId : firstTx . chainId ,
219
+ nonce,
220
+ } ) ;
221
+ if ( ! auth ) {
222
+ throw new Error ( "Failed to sign authorization" ) ;
223
+ }
224
+ authorization = auth ;
211
225
}
212
- authorization = auth ;
213
226
}
214
227
if ( sponsorGas ) {
215
228
// send transaction from executor, needs signature
0 commit comments