Skip to content

Support for new for EIP-1271 verification #571

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

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 26 additions & 2 deletions contracts/prebuilts/account/non-upgradeable/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ contract Account is AccountCore, ContractMetadata, ERC1271, ERC721Holder, ERC115
using ECDSA for bytes32;
using EnumerableSet for EnumerableSet.AddressSet;

bytes32 private constant MSG_TYPEHASH = keccak256("AccountMessage(bytes message)");

/*///////////////////////////////////////////////////////////////
Constructor, Initializer, Modifiers
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -61,14 +63,17 @@ contract Account is AccountCore, ContractMetadata, ERC1271, ERC721Holder, ERC115
}

/// @notice See EIP-1271
function isValidSignature(bytes32 _hash, bytes memory _signature)
function isValidSignature(bytes32 _message, bytes memory _signature)
public
view
virtual
override
returns (bytes4 magicValue)
{
address signer = _hash.recover(_signature);
bytes memory messageData = encodeMessageData(abi.encode(_message));
bytes32 messageHash = keccak256(messageData);

address signer = messageHash.recover(_signature);

if (isAdmin(signer)) {
return MAGICVALUE;
Expand All @@ -87,6 +92,25 @@ contract Account is AccountCore, ContractMetadata, ERC1271, ERC721Holder, ERC115
}
}

/**
* @notice Returns the hash of message that should be signed for EIP1271 verification.
* @param message Message to be hashed
* @return Hashed message
*/
function getMessageHash(bytes memory message) public view returns (bytes32) {
return keccak256(encodeMessageData(message));
}

/**
* @notice Returns encoded message to be hashed
* @param message Message to be encoded
* @return Encoded message to be hashed
*/
function encodeMessageData(bytes memory message) public view returns (bytes memory) {
bytes32 messageHash = keccak256(abi.encode(MSG_TYPEHASH, keccak256(message)));
return abi.encodePacked("\x19\x01", _domainSeparatorV4(), messageHash);
}

/*///////////////////////////////////////////////////////////////
External functions
//////////////////////////////////////////////////////////////*/
Expand Down
28 changes: 26 additions & 2 deletions contracts/prebuilts/account/utils/AccountExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ contract AccountExtension is ContractMetadata, ERC1271, AccountPermissions, ERC7
using ECDSA for bytes32;
using EnumerableSet for EnumerableSet.AddressSet;

bytes32 private constant MSG_TYPEHASH = keccak256("AccountMessage(bytes message)");

/*///////////////////////////////////////////////////////////////
Constructor, Initializer, Modifiers
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -63,14 +65,17 @@ contract AccountExtension is ContractMetadata, ERC1271, AccountPermissions, ERC7
}

/// @notice See EIP-1271
function isValidSignature(bytes32 _hash, bytes memory _signature)
function isValidSignature(bytes32 _message, bytes memory _signature)
public
view
virtual
override
returns (bytes4 magicValue)
{
address signer = _hash.recover(_signature);
bytes memory messageData = encodeMessageData(abi.encode(_message));
bytes32 messageHash = keccak256(messageData);

address signer = messageHash.recover(_signature);

if (isAdmin(signer)) {
return MAGICVALUE;
Expand All @@ -89,6 +94,25 @@ contract AccountExtension is ContractMetadata, ERC1271, AccountPermissions, ERC7
}
}

/**
* @notice Returns the hash of message that should be signed for EIP1271 verification.
* @param message Message to be hashed
* @return Hashed message
*/
function getMessageHash(bytes memory message) public view returns (bytes32) {
return keccak256(encodeMessageData(message));
}

/**
* @notice Returns encoded message to be hashed
* @param message Message to be encoded
* @return Encoded message to be hashed
*/
function encodeMessageData(bytes memory message) public view returns (bytes memory) {
bytes32 messageHash = keccak256(abi.encode(MSG_TYPEHASH, keccak256(message)));
return abi.encodePacked("\x19\x01", _domainSeparatorV4(), messageHash);
}

/*///////////////////////////////////////////////////////////////
External functions
//////////////////////////////////////////////////////////////*/
Expand Down
1 change: 1 addition & 0 deletions lib/aa-benchmark
Submodule aa-benchmark added at 4b8e54
1 change: 1 addition & 0 deletions lib/solady
Submodule solady added at 77809c