-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SC to verify an address and accept an invitation
- Loading branch information
1 parent
ccd893e
commit bfc26f7
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/zevm-app-contracts/contracts/zeta-points/Reference.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
packages/zevm-app-contracts/contracts/zeta-points/Register.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |