Skip to content

[SDK] EIP-7702 Session Keys #7432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 28, 2025
Merged

Conversation

0xFirekeeper
Copy link
Member

@0xFirekeeper 0xFirekeeper commented Jun 24, 2025

Closes TOOL-4444


PR-Codex overview

This PR introduces Session Keys to EIP-7702-powered In-App Wallets, enhancing transaction capabilities by allowing specific permissions and time-limited access for session keys.

Detailed summary

  • Updated MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS.
  • Added createSessionKey extension and related types.
  • Introduced LimitType and Condition enums.
  • Added new interfaces for UsageLimitInput, ConstraintInput, CallSpecInput, and TransferSpecInput.
  • Created request structures for UsageLimitRequest, ConstraintRequest, CallSpecRequest, TransferSpecRequest, and SessionSpecRequest.
  • Implemented tests for session key behavior, including adding admin-like and granular session keys.
  • Enhanced createSessionKey function with validation and structured request creation.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Introduced Session Keys for EIP-7702-powered In-App Wallets, enabling creation and management of session keys with customizable permissions and policies.
    • Added support for granular session key permissions, including configurable call and transfer policies, usage limits, and constraints.
    • Provided new functions to create session keys and check for session key support in compatible wallets.
  • Tests

    • Added comprehensive tests to verify session key creation and event emission for both admin-like and granular permission scenarios.
  • Chores

    • Updated wallet exports to include session key management functions and related type definitions.
    • Updated minimal account implementation address for improved compatibility.

@0xFirekeeper 0xFirekeeper requested review from a team as code owners June 24, 2025 19:24
Copy link

linear bot commented Jun 24, 2025

Copy link

changeset-bot bot commented Jun 24, 2025

🦋 Changeset detected

Latest commit: e392604

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jun 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 11:25pm
nebula ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 11:25pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 11:25pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 11:25pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 11:25pm

Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

"""

Walkthrough

This update introduces session key support for ERC-7702-powered accounts in the TypeScript SDK. It adds session key creation functionality, associated type definitions, EIP-712 struct representations, and public exports. A test suite verifies session key creation with both full and granular permissions. The minimal account implementation address is also updated.

Changes

File(s) Change Summary
packages/thirdweb/src/extensions/erc7702/account/createSessionKey.ts New module: Implements session key creation, support check, and related types for ERC-7702 accounts.
packages/thirdweb/src/extensions/erc7702/account/types.ts New file: Defines enums, interfaces, and EIP-712 struct types for session key and policy management.
packages/thirdweb/src/extensions/erc7702/account/sessionkey.test.ts New test suite: Adds tests for admin and granular session key creation and event validation.
packages/thirdweb/src/exports/wallets/in-app.ts
packages/thirdweb/src/exports/wallets/in-app.native.ts
Added exports: Exposes session key creation functions and types in wallet exports.
packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.ts Updated constant: Changes minimal account implementation address.
.changeset/chatty-chairs-mate.md Added changelog entry describing the session key feature addition.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SDK (createSessionKey)
    participant AdminAccount
    participant Contract

    User->>SDK (createSessionKey): Call with session key options
    SDK->>AdminAccount: Prepare session spec, request EIP-712 signature
    AdminAccount-->>SDK: Return signature
    SDK->>Contract: Call createSessionWithSig with spec and signature
    Contract-->>SDK: Emit SessionCreated event
    SDK-->>User: Return transaction result
Loading

Assessment against linked issues

Objective (Issue) Addressed Explanation
Add session key integration in TS sdk (TOOL-4444)

Assessment against linked issues: Out-of-scope changes

Code Change (file_path) Explanation
Update of MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS (packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.ts) Changing the minimal account implementation address is unrelated to session key integration and not referenced in the stated objective.

Possibly related PRs

Suggested reviewers

  • gregfromstl
    """

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • EIP-7702: Entity not found: Issue - Could not find referenced Issue.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79835e0 and e392604.

📒 Files selected for processing (4)
  • packages/thirdweb/src/exports/wallets/in-app.ts (1 hunks)
  • packages/thirdweb/src/extensions/erc7702/account/createSessionKey.ts (1 hunks)
  • packages/thirdweb/src/extensions/erc7702/account/sessionkey.test.ts (1 hunks)
  • packages/thirdweb/src/extensions/erc7702/account/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/thirdweb/src/extensions/erc7702/account/sessionkey.test.ts
  • packages/thirdweb/src/extensions/erc7702/account/createSessionKey.ts
  • packages/thirdweb/src/exports/wallets/in-app.ts
  • packages/thirdweb/src/extensions/erc7702/account/types.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

graphite-app bot commented Jun 24, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (3)
packages/thirdweb/src/extensions/erc7702/account/sessionkey.test.ts (2)

80-122: Consider more realistic test data for granular permissions test.

The second test uses ZERO_ADDRESS and zero values for limits, which may not effectively test the granular permissions functionality. Consider using more realistic values that would demonstrate meaningful constraints.

        callPolicies: [
          {
-            target: ZERO_ADDRESS,
-            selector: "0x00000000",
-            maxValuePerUse: 0n,
+            target: "0xA0b86a33E6411E3037E4827c80F7b79289F7F1C1", // Example ERC20 contract
+            selector: "0xa9059cbb", // transfer(address,uint256)
+            maxValuePerUse: 1000000000000000000n, // 1 ETH max per use
             valueLimit: {
-              limitType: 0,
-              limit: 0n,
-              period: 0n,
+              limitType: 1,
+              limit: 5000000000000000000n, // 5 ETH total limit
+              period: 86400n, // 24 hours
             },
             constraints: [],
           },
         ],

86-86: Avoid session key address conflicts between tests.

Both tests use the same session key address (TEST_ACCOUNT_A.address). Consider using different addresses to avoid potential conflicts, especially if tests run in parallel or if the session keys persist between test runs.

-        sessionKeyAddress: TEST_ACCOUNT_A.address,
+        sessionKeyAddress: TEST_ACCOUNT_B.address,
packages/thirdweb/src/extensions/erc7702/account/createSessionKey.ts (1)

114-128: Fix function name inconsistency in documentation.

The JSDoc comment references isAddSessionKeySupported but the actual function name is isCreateSessionKeySupported.

 * @returns A boolean indicating if the `isAddSessionKeySupported` method is supported.
+* @returns A boolean indicating if the `isCreateSessionKeySupported` method is supported.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbff67d and 4386865.

📒 Files selected for processing (4)
  • packages/thirdweb/src/extensions/erc7702/account/createSessionKey.ts (1 hunks)
  • packages/thirdweb/src/extensions/erc7702/account/sessionkey.test.ts (1 hunks)
  • packages/thirdweb/src/extensions/erc7702/account/types.ts (1 hunks)
  • packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.@(ts|tsx)`: Accept a typed 'props' object and export a named function (e.g., export function MyComponent()). Combine class names via 'cn', expose 'className' prop if useful. ...

**/*.@(ts|tsx): Accept a typed 'props' object and export a named function (e.g., export function MyComponent()).
Combine class names via 'cn', expose 'className' prop if useful.
Reuse core UI primitives; avoid re-implementing buttons, cards, modals.
Local state or effects live inside; data fetching happens in hooks.
Merge class names with 'cn' from '@/lib/utils' to keep conditional logic readable.
Stick to design-tokens: background ('bg-card'), borders ('border-border'), muted text ('text-muted-foreground') etc.
Use the 'container' class with a 'max-w-7xl' cap for page width consistency.
Spacing utilities ('px-', 'py-', 'gap-*') are preferred over custom margins.
Responsive helpers follow mobile-first ('max-sm', 'md', 'lg', 'xl').
Never hard-code colors – always go through Tailwind variables.
Tailwind CSS is the styling system – avoid inline styles or CSS modules.
Prefix files with 'import "server-only";' so they never end up in the client bundle (for server-only code).

  • packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.ts
  • packages/thirdweb/src/extensions/erc7702/account/createSessionKey.ts
  • packages/thirdweb/src/extensions/erc7702/account/sessionkey.test.ts
  • packages/thirdweb/src/extensions/erc7702/account/types.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Build Packages
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
packages/thirdweb/src/extensions/erc7702/account/types.ts (1)

1-85: LGTM! Well-structured type definitions.

The TypeScript interfaces and EIP-712 struct definitions are well-organized and follow good practices. The separation between input types and EIP-712 structs is clean, and the type safety with 0x${string} for hex addresses is appropriate.

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

26-27: Verify this breaking change to the implementation address.

Updating the MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS is a significant change that could affect existing deployments and account verification. Ensure this change is coordinated with:

  1. Contract deployments on target networks
  2. Existing user accounts that may reference the old implementation
  3. Any dependent services or applications
#!/bin/bash
# Description: Search for any hardcoded references to the old implementation address
# Expected: Find any remaining references that need updating

# Search for the old address in the codebase
rg -i "0xbaC7e770af15d130Cd72838ff386f14FBF3e9a3D" --type ts --type js --type json

# Search for any other references to minimal account implementation addresses
rg -i "MINIMAL_ACCOUNT_IMPLEMENTATION" --type ts --type js -A 2 -B 2
packages/thirdweb/src/extensions/erc7702/account/sessionkey.test.ts (1)

37-41: Fix syntax error: missing semicolon.

There's a missing semicolon after the wallet connection assignment.

    account = await wallet.connect({
      chain: defineChain(chainId),
      client: TEST_CLIENT,
      strategy: "guest",
-    })
+    });

Likely an incorrect or invalid review comment.

Copy link
Contributor

github-actions bot commented Jun 24, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 63.11 KB (0%) 1.3 s (0%) 565 ms (+56.45% 🔺) 1.9 s
thirdweb (cjs) 352.61 KB (0%) 7.1 s (0%) 2.8 s (+2.16% 🔺) 9.9 s
thirdweb (minimal + tree-shaking) 5.72 KB (0%) 115 ms (0%) 188 ms (+832.39% 🔺) 302 ms
thirdweb/chains (tree-shaking) 530 B (0%) 11 ms (0%) 95 ms (+1231.65% 🔺) 106 ms
thirdweb/react (minimal + tree-shaking) 19.59 KB (0%) 392 ms (0%) 59 ms (+24.75% 🔺) 451 ms

Copy link

codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 81.69014% with 26 lines in your changes missing coverage. Please review.

Project coverage is 51.99%. Comparing base (bbff67d) to head (e392604).
Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
...src/extensions/erc7702/account/createSessionKey.ts 73.46% 25 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7432      +/-   ##
==========================================
- Coverage   52.08%   51.99%   -0.10%     
==========================================
  Files         947      949       +2     
  Lines       63636    64081     +445     
  Branches     4216     4229      +13     
==========================================
+ Hits        33146    33318     +172     
- Misses      30384    30656     +272     
- Partials      106      107       +1     
Flag Coverage Δ
packages 51.99% <81.69%> (-0.10%) ⬇️
Files with missing lines Coverage Δ
...s/thirdweb/src/extensions/erc7702/account/types.ts 100.00% <100.00%> (ø)
...src/wallets/in-app/core/eip7702/minimal-account.ts 80.36% <100.00%> (+3.68%) ⬆️
...src/extensions/erc7702/account/createSessionKey.ts 73.46% <73.46%> (ø)

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@joaquim-verges joaquim-verges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! just needs a lint

@0xFirekeeper
Copy link
Member Author

biome needs to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants