Account
This directory includes contracts to build accounts for ERC-4337.
Core
AccountCore
import "@openzeppelin/contracts/account/AccountCore.sol";
A simple ERC4337 account implementation. This base implementation only includes the minimal logic to process user operations.
Developers must implement the AbstractSigner._rawSignatureValidation
function to define the account’s validation logic.
Implementing a mechanism to validate signatures is a security-sensitive operation as it may allow an
attacker to bypass the account’s security measures. Check out SignerECDSA , SignerP256 , or SignerRSA for
digital signature validation implementations.
|
-
onlyEntryPointOrSelf()
-
onlyEntryPoint()
-
entryPoint()
-
getNonce()
-
getNonce(key)
-
validateUserOp(userOp, userOpHash, missingAccountFunds)
-
executeUserOp(userOp, )
-
_signableUserOpHash(userOp, )
-
_payPrefund(missingAccountFunds)
-
_checkEntryPoint()
-
_checkEntryPointOrSelf()
-
receive()
-
_domainSeparatorV4()
-
_hashTypedDataV4(structHash)
-
eip712Domain()
-
_EIP712Name()
-
_EIP712Version()
-
_rawSignatureValidation(hash, signature)
-
EIP712DomainChanged()
-
AccountUnauthorized(sender)
-
bytes32 constant _PACKED_USER_OPERATION
entryPoint() → contract IEntryPoint
public
Canonical entry point for the account that forwards and validates user operations.
validateUserOp(struct PackedUserOperation userOp, bytes32 userOpHash, uint256 missingAccountFunds) → uint256
public
Validates a user operation.
-
MUST validate the caller is a trusted EntryPoint
-
MUST validate that the signature is a valid signature of the userOpHash, and SHOULD return SIG_VALIDATION_FAILED (and not revert) on signature mismatch. Any other error MUST revert.
-
MUST pay the entryPoint (caller) at least the “missingAccountFunds” (which might be zero, in case the current account’s deposit is high enough)
Returns an encoded packed validation data that is composed of the following elements:
-
authorizer
(address
): 0 for success, 1 for failure, otherwise the address of an authorizer contract -
validUntil
(uint48
): The UserOp is valid only up to this time. Zero for “infinite”. -
validAfter
(uint48
): The UserOp is valid only after this time.
_signableUserOpHash(struct PackedUserOperation userOp, bytes32) → bytes32
internal
Returns the digest used by an offchain signer instead of the opaque userOpHash
.
Given the userOpHash
calculation is defined by ERC-4337, offchain signers
may need to sign again this hash by rehashing it with other schemes (e.g. ERC-191).
Returns a typehash following EIP-712 typed data hashing for readability.
_payPrefund(uint256 missingAccountFunds)
internal
Sends the missing funds for executing the user operation to the entryPoint
.
The missingAccountFunds
must be defined by the entrypoint when calling validateUserOp
.
_checkEntryPoint()
internal
Ensures the caller is the entryPoint
.
_checkEntryPointOrSelf()
internal
Ensures the caller is the entryPoint
or the account itself.
Account
import "@openzeppelin/contracts/account/Account.sol";
Extension of AccountCore
with recommended feature that most account abstraction implementation will want:
-
{ERC721Holder} and {ERC1155Holder} to accept ERC-712 and ERC-1155 token transfers transfers.
-
ERC7739Signer
for ERC-1271 signature support with ERC-7739 replay protection
To use this contract, the {ERC7739Signer-_rawSignatureValidation} function must be
implemented using a specific signature verification algorithm. See SignerECDSA , SignerP256 or SignerRSA .
|
-
isValidSignature(hash, signature)
-
supportsInterface(interfaceId)
-
onERC1155Received(, , , , )
-
onERC1155BatchReceived(, , , , )
-
onERC721Received(, , , )
-
entryPoint()
-
getNonce()
-
getNonce(key)
-
validateUserOp(userOp, userOpHash, missingAccountFunds)
-
executeUserOp(userOp, )
-
_signableUserOpHash(userOp, )
-
_payPrefund(missingAccountFunds)
-
_checkEntryPoint()
-
_checkEntryPointOrSelf()
-
receive()
-
_domainSeparatorV4()
-
_hashTypedDataV4(structHash)
-
eip712Domain()
-
_EIP712Name()
-
_EIP712Version()
-
_rawSignatureValidation(hash, signature)
-
EIP712DomainChanged()
-
AccountUnauthorized(sender)
Extensions
AccountSignerERC7702
import "@openzeppelin/contracts/account/extensions/AccountSignerERC7702.sol";
Account
implementation whose low-level signature validation is done by an EOA.
-
_rawSignatureValidation(hash, signature)
-
entryPoint()
-
getNonce()
-
getNonce(key)
-
validateUserOp(userOp, userOpHash, missingAccountFunds)
-
executeUserOp(userOp, )
-
_signableUserOpHash(userOp, )
-
_payPrefund(missingAccountFunds)
-
_checkEntryPoint()
-
_checkEntryPointOrSelf()
-
receive()
-
_domainSeparatorV4()
-
_hashTypedDataV4(structHash)
-
eip712Domain()
-
_EIP712Name()
-
_EIP712Version()
-
EIP712DomainChanged()
-
AccountUnauthorized(sender)