-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] Feature: Basic EIP7702 Support (#5801)
<!-- start pr-codex --> ## PR-Codex overview This PR introduces beta support for `EIP-7702` authorization lists, enhancing transaction handling and signing within the `thirdweb` library. ### Detailed summary - Added `style` configuration in `biome.json`. - Introduced `signAuthorization` function for EIP-7702 authorizations. - Updated transaction preparation to include `authorizationList`. - Added tests for `signAuthorization` and transaction serialization. - Modified `serializeTransaction` to handle EIP-7702 transactions. - Enhanced gas estimation and transaction preparation functions to support authorization lists. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
1 parent
ddb6af1
commit 429e112
Showing
26 changed files
with
729 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
"thirdweb": minor | ||
--- | ||
|
||
Feature: Adds beta support for EIP-7702 authorization lists | ||
|
||
```ts | ||
import { prepareTransaction, sendTransaction, signAuthorization } from "thirdweb"; | ||
|
||
const authorization = await signAuthorization({ | ||
request: { | ||
address: "0x...", | ||
chainId: 911867, | ||
nonce: 100n, | ||
}, | ||
account: myAccount, | ||
}); | ||
|
||
const transaction = prepareTransaction({ | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
value: 100n, | ||
to: TEST_WALLET_B, | ||
authorizationList: [authorization], | ||
}); | ||
|
||
const res = await sendTransaction({ | ||
account, | ||
transaction, | ||
}); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ | |
"rules": { | ||
"nursery": { | ||
"noProcessEnv": "off" | ||
}, | ||
"style": { | ||
"noUnusedTemplateLiteral": "off" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/thirdweb/src/transaction/actions/eip7702/authorization.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { TEST_WALLET_B } from "~test/addresses.js"; | ||
import { TEST_ACCOUNT_A } from "~test/test-wallets.js"; | ||
import { signAuthorization } from "./authorization.js"; | ||
|
||
describe("signAuthorization", () => { | ||
it("should sign an authorization", async () => { | ||
const authorization = await signAuthorization({ | ||
account: TEST_ACCOUNT_A, | ||
request: { | ||
address: TEST_WALLET_B, | ||
chainId: 911867, | ||
nonce: 0n, | ||
}, | ||
}); | ||
expect(authorization).toMatchInlineSnapshot(` | ||
{ | ||
"address": "0x0000000000000000000000000000000000000002", | ||
"chainId": 911867, | ||
"nonce": 0n, | ||
"r": 3720526934953059641417422884731844424204826752871127418111522219225437830766n, | ||
"s": 23451045058292828843243765241045958975073226494910356096978666517928790374894n, | ||
"yParity": 1, | ||
} | ||
`); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
packages/thirdweb/src/transaction/actions/eip7702/authorization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type * as ox__Authorization from "ox/Authorization"; | ||
import type { Address } from "../../../utils/address.js"; | ||
import type { Account } from "../../../wallets/interfaces/wallet.js"; | ||
|
||
/** | ||
* An EIP-7702 authorization object fully prepared and ready for signing. | ||
* | ||
* @beta | ||
* @transaction | ||
*/ | ||
export type AuthorizationRequest = { | ||
address: Address; | ||
chainId: number; | ||
nonce: bigint; | ||
}; | ||
|
||
/** | ||
* Represents a signed EIP-7702 authorization object. | ||
* | ||
* @beta | ||
* @transaction | ||
*/ | ||
export type SignedAuthorization = ox__Authorization.ListSigned[number]; | ||
|
||
/** | ||
* Sign the given EIP-7702 authorization object. | ||
* @param options - The options for `signAuthorization` | ||
* Refer to the type [`SignAuthorizationOptions`](https://portal.thirdweb.com/references/typescript/v5/SignAuthorizationOptions) | ||
* @returns The signed authorization object | ||
* | ||
* ```ts | ||
* import { signAuthorization } from "thirdweb"; | ||
* | ||
* const authorization = await signAuthorization({ | ||
* request: { | ||
* address: "0x...", | ||
* chainId: 911867, | ||
* nonce: 100n, | ||
* }, | ||
* account: myAccount, | ||
* }); | ||
* ``` | ||
* | ||
* @beta | ||
* @transaction | ||
*/ | ||
export async function signAuthorization(options: { | ||
account: Account; | ||
request: AuthorizationRequest; | ||
}): Promise<SignedAuthorization> { | ||
const { account, request } = options; | ||
if (typeof account.signAuthorization === "undefined") { | ||
throw new Error( | ||
"This account type does not yet support signing EIP-7702 authorizations", | ||
); | ||
} | ||
return account.signAuthorization(request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.