Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

feat: add support for ERC-4337 accounts #213

Merged
merged 17 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ participant Site as Snap Companion Dapp

User ->>+ Dapp: Create new sign request
Dapp ->>+ MetaMask: ethereum.request(request)
alt Is EIP-4337 account?
MetaMask ->>+ Snap: keyring_prepareRequest(request)
Snap ->> Snap: Custom logic to prepare request
Snap -->>- MetaMask: { request }
end
MetaMask ->> MetaMask: Display request to user
User ->> MetaMask: Approve request

Expand Down Expand Up @@ -208,6 +213,11 @@ participant Snap

User ->>+ Dapp: Create new sign request
Dapp ->>+ MetaMask: ethereum.request(request)
alt Is EIP-4337 account?
MetaMask ->>+ Snap: keyring_prepareRequest(request)
Snap ->> Snap: Custom logic to prepare request
Snap -->>- MetaMask: { request }
end
MetaMask ->> MetaMask: Display request to user
User ->> MetaMask: Approve request

Expand Down
115 changes: 115 additions & 0 deletions docs/diagrams/user_operation_signing.puml
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
14 changes: 7 additions & 7 deletions docs/evm-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Adds support to [`eth_sendTransaction`][eth-send-transaction].
- Pattern: `^0x[0-9a-fA-F]{1,2}$`
- `nonce`
- Type: `string`
- Pattern: `^0x([1-9a-f]+[0-9a-f]*|0)$`
- Pattern: `^0x([1-9a-f][0-9a-f]*|0)$`
- `to`
gantunesr marked this conversation as resolved.
Show resolved Hide resolved
- One-of:
- Contract creation
Expand All @@ -118,22 +118,22 @@ Adds support to [`eth_sendTransaction`][eth-send-transaction].
- Pattern: `^0x[0-9a-fA-F]{40}$`
- `value`
- Type: `string`
- Pattern: `^0x([1-9a-f]+[0-9a-f]*|0)$`
- Pattern: `^0x([1-9a-f][0-9a-f]*|0)$`
- `data`
- Type: `string`
- Pattern: `^0x[0-9a-f]*$`
- `gasLimit`
- Type: `string`
- Pattern: `^0x([1-9a-f]+[0-9a-f]*|0)$`
- Pattern: `^0x([1-9a-f][0-9a-f]*|0)$`
- `gasPrice`
- Type: `string`
- Pattern: `^0x([1-9a-f]+[0-9a-f]*|0)$`
- Pattern: `^0x([1-9a-f][0-9a-f]*|0)$`
- `maxPriorityFeePerGas`
- Type: `string`
- Pattern: `^0x([1-9a-f]+[0-9a-f]*|0)$`
- Pattern: `^0x([1-9a-f][0-9a-f]*|0)$`
- `maxFeePerGas`
- Type: `string`
- Pattern: `^0x([1-9a-f]+[0-9a-f]*|0)$`
- Pattern: `^0x([1-9a-f][0-9a-f]*|0)$`
- `accessList`:
- Description: EIP-2930 access list
- Type: `array`
Expand All @@ -150,7 +150,7 @@ Adds support to [`eth_sendTransaction`][eth-send-transaction].
- Pattern: `^0x[0-9a-f]{64}$`
- `chainId`
- Type: `string`
- Pattern: `^0x([1-9a-f]+[0-9a-f]*|0)$`
- Pattern: `^0x([1-9a-f][0-9a-f]*|0)$`

### Returns

Expand Down
Loading