This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for ERC-4337 accounts (#213)
* docs: add EIP-4337 UserOp support * wip: support 4337 accounts * chore: simplify regex * feat: add `definePattern` helper function * chore: move types to `eth` directory * chore: use `definePattern` to define `UuidV4` type * chore: move user operation sequence diagram * docs: add `eth_signUserOperation` * feat: add `BasicTransaction` type * fix: add index files * feat: add `PreparedUserOperation` type * fix: make `gasLimits` optional * feat: add `EthUserOperationPatch` type * feat: export base ETH types * feat: add `EthKeyring` type * fix: add UserOperation methods to support methods enum * docs: add link to ERC-4337 spec
- Loading branch information
Showing
18 changed files
with
709 additions
and
16 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
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,115 @@ | ||
@startuml "ERC-4337 Account Support" | ||
autonumber | ||
skinparam fontname Arial | ||
|
||
title "ERC-4337 UserOperation Signing" | ||
|
||
participant Dapp | ||
participant MetaMask | ||
participant Snap | ||
|
||
Dapp -> MetaMask ++: ""{""\n\ | ||
"" chainId, // Ignored by MetaMask""\n\ | ||
"" from,""\n\ | ||
"" to,""\n\ | ||
"" value,""\n\ | ||
"" data,""\n\ | ||
} | ||
|
||
note over MetaMask | ||
Currently, only one transaction | ||
per UserOp will be supported | ||
end note | ||
|
||
MetaMask -> Snap ++: ""prepareUserOperation({""\n\ | ||
"" account: account.id,""\n\ | ||
"" scope: `eip155:${chainId}`,""\n\ | ||
"" transactions: [ // List of transactions""\n\ | ||
"" {""\n\ | ||
"" to,""\n\ | ||
"" value,""\n\ | ||
"" data,""\n\ | ||
"" },""\n\ | ||
"" ]""\n\ | ||
}) | ||
|
||
Snap --> MetaMask --: ""{""\n\ | ||
"" callData,""\n\ | ||
"" initCode?,""\n\ | ||
"" nonce,""\n\ | ||
"" gasLimits?: {""\n\ | ||
"" callGasLimit,""\n\ | ||
"" verificationGasLimit,""\n\ | ||
"" preVerificationGas,""\n\ | ||
"" },""\n\ | ||
"" dummySignature?,""\n\ | ||
"" dummyPaymasterAndData?,""\n\ | ||
"" bundler?,""\n\ | ||
""}"" | ||
|
||
MetaMask -> MetaMask: Check if the account is already deployed | ||
|
||
alt The account is already deployed | ||
MetaMask -> MetaMask: Remove the ""initCode"" if set | ||
else The account is not deployed and the ""initCode"" isn't present | ||
MetaMask -> Dapp: Throw an error (without the exact reason) | ||
end | ||
|
||
alt The ""gas"" isn't set | ||
MetaMask -> MetaMask: Estimate and set gas values | ||
end | ||
|
||
MetaMask -> MetaMask: Estimate and set gas fees | ||
|
||
MetaMask -> Snap ++: ""patchUserOperation({""\n\ | ||
"" sender,""\n\ | ||
"" nonce,""\n\ | ||
"" initCode,""\n\ | ||
"" callData,""\n\ | ||
"" callGasLimit,""\n\ | ||
"" verificationGasLimit,""\n\ | ||
"" preVerificationGas,""\n\ | ||
"" maxFeePerGas,""\n\ | ||
"" maxPriorityFeePerGas,""\n\ | ||
"" paymasterAndData, // Dummy value or empty""\n\ | ||
"" signature, // Dummy value or empty""\n\ | ||
""})"" | ||
|
||
Snap --> MetaMask --: ""{""\n\ | ||
"" paymasterAndData?,""\n\ | ||
""}"" | ||
|
||
MetaMask -> MetaMask: Update ""paymasterAndData"" and\n\ | ||
remove the dummy signature | ||
|
||
MetaMask -> MetaMask: Display approval UI | ||
|
||
MetaMask -> Snap ++: ""signUserOperation([""\n\ | ||
"" {""\n\ | ||
"" sender,""\n\ | ||
"" nonce,""\n\ | ||
"" initCode,""\n\ | ||
"" callData,""\n\ | ||
"" callGasLimit,""\n\ | ||
"" verificationGasLimit,""\n\ | ||
"" preVerificationGas,""\n\ | ||
"" maxFeePerGas,""\n\ | ||
"" maxPriorityFeePerGas,""\n\ | ||
"" paymasterAndData,""\n\ | ||
"" signature, // Empty""\n\ | ||
"" },""\n\ | ||
"" entrypoint, // Entrypoint deployed by""\n\ | ||
"" // the Ethereum Foundation""\n\ | ||
""])"" | ||
|
||
Snap --> MetaMask --: ""{""\n\ | ||
"" signature,""\n\ | ||
""}"" | ||
|
||
MetaMask -> MetaMask: Update UserOp's ""signature"" | ||
|
||
MetaMask -> MetaMask: Submit UserOp to bundler and\n\ | ||
wait for transaction hash | ||
|
||
MetaMask --> Dapp --: ""txHash"" | ||
@enduml |
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.