The following is a demo to show how to use Openfort EIP-7702 with ERC-4337. It uses the new Delegation Contract from Openfort with Viem. This demo includes: WebAuthn, sponsored transactions, batch transactions, and session keys.
Initialize an account
Firstly, we will initialize an Account (EOA). You can either click on "Register" to create a new Account, or "Sign In" to sign into an existing one that you have created previously.
Your wallet
By clicking the "Register" button above, behind the scenes it will:
Generate an Account (EOA) with a random private key.
Prompt the end-user to create a WebAuthn key (e.g. Passkey).
Sign an EIP-7702 Authorization to designate the Delegation contract onto the Account.
Send an EIP-7702 Transaction with the Authorization from Step 3, and authorize the WebAuthn public key on the Account.
Store the account address we are using in local storage.
Execute a sponsored transaction
Next, let's demonstrate executing a contract call using our Account (EOA) that is controlled by our WebAuthn key.
Mint tokens
The mint transaction is coordinating with the paymaster to sponsor the transaction.
Prompting the end-user to sign over the call with their WebAuthn key (e.g. Passkey)
Invoking the mint function on the Account (which uses a paymaster) with the calldata and the WebAuthn signature. The Delegation contract uses the RIP-7212 P256 Precompile to verify the WebAuthn signature.
Upon invoking the mint function, we are broadcasting a userop to the bundler.
Using a session key
Now, let's demonstrate how to use a session key to perform the same action. A session key is a temporary key that can be used to sign transactions on behalf of the user without requiring them to sign each transaction individually.
This time, we generate a temporary key (a non-extractable P256 key) and use it as an account session key. The session key is then stored in IndexedDB (as an example implementation) and authorized along with the WebAuthn P256 key.
The session key is used to sign the transaction, and it is limited to a certain number of actions (e.g. 10 actions for this demo).
Create a session key
Mint with session key
Session keys are solving user experience issues with prompt fatigue and reviewing signature requests. With this example, once you create a session key, you are free to perform actions without getting prompted for signatures.
This allows you to perform multiple actions (batch transaction) with the session key without needing to sign each transaction.