Skip to content

Commit

Permalink
SC to verify an address and accept an invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Oct 9, 2023
1 parent ccd893e commit bfc26f7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/zevm-app-contracts/contracts/zeta-points/Reference.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

contract Reference {
/* An ECDSA signature. */
struct Sig {
uint8 v;
bytes32 r;
bytes32 s;
}

mapping(address => mapping(address => uint256)) public invitations;

error InvalidInvitation();
event Invitation(address indexed inviter, address indexed invitee);

function validateInvitation(address inviter, address invitee, Sig calldata sig) private view {
bytes32 payloadHash = keccak256(abi.encode(inviter, invitee));
bytes32 messageHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", payloadHash));

address actualSigner = ecrecover(messageHash, sig.v, sig.r, sig.s);
if (inviter != actualSigner) revert InvalidInvitation();
}

function acceptInvitation(address inviter, Sig calldata sig) external {
if (invitations[inviter][msg.sender] != address(0)) revert InvalidInvitation();
validateInvitation(inviter, msg.sender, sig);
invitations[inviter][msg.sender] = block.timestamp;
emit Invitation(inviter, msg.sender);
}
}
21 changes: 21 additions & 0 deletions packages/zevm-app-contracts/contracts/zeta-points/Register.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

contract Register {
mapping(address => uint256) public verified;

event UserVerification(address indexed user, uint256 timestamp);

function verify() external {
verified[msg.sender] = block.timestamp;
emit UserVerification(msg.sender, block.timestamp);
}

function isVerified(address addr) external view returns (bool) {
return verified[addr] > 0;
}

function whenVerified(address addr) external view returns (uint256) {
return verified[addr];
}
}

0 comments on commit bfc26f7

Please sign in to comment.