Skip to content
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

feat: proxies, deploy scripts and cleanup #183

Merged
merged 16 commits into from
Nov 22, 2024
Merged
37 changes: 18 additions & 19 deletions packages/contracts/src/handlers/ERC1271Handler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import { SignatureDecoder } from "../libraries/SignatureDecoder.sol";
import { ValidationHandler } from "./ValidationHandler.sol";
import { EIP712 } from "../helpers/EIP712.sol";

/**
* @title ERC1271Handler
* @notice Contract which provides ERC1271 signature validation
* @author https://getclave.io
*/
abstract contract ERC1271Handler is IERC1271Upgradeable, EIP712("Clave1271", "1.0.0"), ValidationHandler {
struct ClaveMessage {
/// @title ERC1271Handler
/// @author Matter Labs
/// @notice Contract which provides ERC1271 signature validation
/// @notice The implementation is inspired by Clave wallet.
abstract contract ERC1271Handler is IERC1271Upgradeable, EIP712("Sso1271", "1.0.0"), ValidationHandler {
struct SsoMessage {
bytes32 signedHash;
}

bytes32 constant _CLAVE_MESSAGE_TYPEHASH = keccak256("ClaveMessage(bytes32 signedHash)");
bytes32 constant _SSO_MESSAGE_TYPEHASH = keccak256("SsoMessage(bytes32 signedHash)");

bytes4 private constant _ERC1271_MAGIC = 0x1626ba7e;

Expand All @@ -33,31 +32,31 @@ abstract contract ERC1271Handler is IERC1271Upgradeable, EIP712("Clave1271", "1.
) public view override returns (bytes4 magicValue) {
(bytes memory signature, address validator) = SignatureDecoder.decodeSignatureNoHookData(signatureAndValidator);

bytes32 eip712Hash = _hashTypedDataV4(_claveMessageHash(ClaveMessage(signedHash)));
bytes32 eip712Hash = _hashTypedDataV4(_ssoMessageHash(SsoMessage(signedHash)));

bool valid = _handleValidation(validator, eip712Hash, signature);

magicValue = valid ? _ERC1271_MAGIC : bytes4(0);
}

/**
* @notice Returns the EIP-712 hash of the Clave message
* @param claveMessage ClaveMessage calldata - The message containing signedHash
* @notice Returns the EIP-712 hash of the Sso message
* @param ssoMessage SsoMessage calldata - The message containing signedHash
* @return bytes32 - EIP712 hash of the message
*/
function getEip712Hash(ClaveMessage calldata claveMessage) external view returns (bytes32) {
return _hashTypedDataV4(_claveMessageHash(claveMessage));
function getEip712Hash(SsoMessage calldata ssoMessage) external view returns (bytes32) {
return _hashTypedDataV4(_ssoMessageHash(ssoMessage));
}

/**
* @notice Returns the typehash for the clave message struct
* @return bytes32 - Clave message typehash
* @notice Returns the typehash for the sso message struct
* @return bytes32 - Sso message typehash
*/
function claveMessageTypeHash() external pure returns (bytes32) {
return _CLAVE_MESSAGE_TYPEHASH;
function ssoMessageTypeHash() external pure returns (bytes32) {
return _SSO_MESSAGE_TYPEHASH;
}

function _claveMessageHash(ClaveMessage memory claveMessage) internal pure returns (bytes32) {
return keccak256(abi.encode(_CLAVE_MESSAGE_TYPEHASH, claveMessage.signedHash));
function _ssoMessageHash(SsoMessage memory ssoMessage) internal pure returns (bytes32) {
return keccak256(abi.encode(_SSO_MESSAGE_TYPEHASH, ssoMessage.signedHash));
}
}
1 change: 0 additions & 1 deletion packages/contracts/src/libraries/SsoStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.24;

library SsoStorage {
//keccak256('clave.contracts.ClaveStorage') - 1
ly0va marked this conversation as resolved.
Show resolved Hide resolved
bytes32 private constant SSO_STORAGE_SLOT = 0x3248da1aeae8bd923cbf26901dc4bfc6bb48bb0fbc5b6102f1151fe7012884f4;

struct Layout {
Expand Down