Comment on page


This secton explains the functions on the Algoz smart contract


constructor(address _token_verifier, bool _verify_enabled, uint _proof_ttl) {
require(_proof_ttl>0, "AlgozInvalidTokenTTL");
token_verifier = _token_verifier;
verify_enabled = _verify_enabled;
proof_ttl = _proof_ttl;
❇️ In line 2, we require that the proof_ttl is greater than 0 as the signature proof must be valid for at least 1 block.
❇️ Refer to the Variables section to learn more about the parameters.


function validate_token(bytes32 expiry_token, bytes32 auth_token, bytes calldata signature_token) public {
if(!verify_enabled) return;
require(!consumed_token[auth_token], "AlgozConsumedTokenError");
require(SafeMath.add(uint256(expiry_token), proof_ttl) >= block.number, "AlgozTokenExpiredError");
require(abi.encodePacked(expiry_token, auth_token).toEthSignedMessageHash().recover(signature_token) == token_verifier, "AlgozSignatureError");
consumed_token[auth_token] = true;
❇️ Line 1: To learn more about how to receive the function parameters, refer to the section Algoz API.
❇️ Line 2: This line is used to skip the signature validation if the value of verify_enabled is set to false.
❇️ Line 3: The auth_token can be used only once on a contract. This require statement ensures that the auth_token hasn't been consumed in the past.
❇️ Line 4: This line ensures that the expiry_token hasn't expired. More details on proof_ttl can be found under the section Variables.
❇️ Line 5: This line ensures that the signature_token is valid and that it was signed by the token_verifier.
❇️ Line 6: Finally, in this line, we just set the consumed_token mapping for the auth_token to true. This ensures that the auth_token can not be reused for the same application.
Last modified 1yr ago