Skip to content

Commit 0b45405

Browse files
[SDK] Accept pre-signed authorizations for 7702 account transactions (#8038)
1 parent dc1f7ab commit 0b45405

File tree

3 files changed

+49
-27
lines changed

3 files changed

+49
-27
lines changed

.changeset/cuddly-turkeys-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Accept pre signed authorizations for 7702 account transactions

packages/thirdweb/src/extensions/erc7702/account/createSessionKey.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { BaseTransactionOptions } from "../../../transaction/types.js";
1+
import type {
2+
BaseTransactionOptions,
3+
WithOverrides,
4+
} from "../../../transaction/types.js";
25
import { randomBytesHex } from "../../../utils/random.js";
36
import type { Account } from "../../../wallets/interfaces/wallet.js";
47
import {
@@ -68,7 +71,7 @@ export type CreateSessionKeyOptions = {
6871
* @extension ERC7702
6972
*/
7073
export function createSessionKey(
71-
options: BaseTransactionOptions<CreateSessionKeyOptions>,
74+
options: BaseTransactionOptions<WithOverrides<CreateSessionKeyOptions>>,
7275
) {
7376
const {
7477
contract,
@@ -161,6 +164,7 @@ export function createSessionKey(
161164
return { sessionSpec: req, signature };
162165
},
163166
contract,
167+
overrides: options.overrides,
164168
});
165169
}
166170

packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.ts

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -180,36 +180,49 @@ 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 (
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;
211225
}
212-
authorization = auth;
213226
}
214227
if (sponsorGas) {
215228
// send transaction from executor, needs signature

0 commit comments

Comments
 (0)