├── .gitignore ├── README.md └── contracts └── Algoz.sol /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algoz Contracts 2 | -------------------------------------------------------------------------------- /contracts/Algoz.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.4; 3 | 4 | import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; 5 | import "@openzeppelin/contracts/utils/math/SafeMath.sol"; 6 | 7 | contract Algoz { 8 | using ECDSA for bytes32; 9 | using ECDSA for bytes; 10 | 11 | mapping(bytes32 => bool) public consumed_token; 12 | address public token_verifier; 13 | bool public verify_enabled; 14 | uint public proof_ttl; 15 | 16 | constructor(address _token_verifier, bool _verify_enabled, uint _proof_ttl) { 17 | require(_proof_ttl>0, "AlgozInvalidTokenTTL"); 18 | token_verifier = _token_verifier; 19 | verify_enabled = _verify_enabled; // should be true if the contract wants to use Algoz 20 | proof_ttl = _proof_ttl; // ideally set this value to 3 21 | } 22 | 23 | function validate_token(bytes32 expiry_token, bytes32 auth_token, bytes calldata signature_token) public { 24 | if(!verify_enabled) return; // skip verification if verify_enabled is false 25 | require(!consumed_token[auth_token], "AlgozConsumedTokenError"); // verify if the token has been used in the past 26 | require(SafeMath.add(uint256(expiry_token), proof_ttl) >= block.number, "AlgozTokenExpiredError"); // expire this proof if the current blocknumber > the expiry blocknumber 27 | require(abi.encodePacked(expiry_token, auth_token).toEthSignedMessageHash().recover(signature_token) == token_verifier, "AlgozSignatureError"); // verify if the token has been used in the past 28 | consumed_token[auth_token] = true; 29 | } 30 | } 31 | --------------------------------------------------------------------------------