Hidden Random Card


// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity >=0.8.13 <0.9.0;

import "fhevm@v0.3.0/abstracts/EIP712WithModifier.sol";
import "fhevm@v0.3.0/lib/TFHE.sol";

contract CardDealer is EIP712WithModifier {
    // used for output authorization
    bytes32 private DOMAIN_SEPARATOR;
    mapping (address => euint8) public encryptedCards;

    constructor() EIP712WithModifier("Authorization token", "1") {
    }

    // A random encrypted uint8 is generated
    function getCard() public {
        encryptedCards[msg.sender] = TFHE.randEuint8();
    }

    // EIP 712 signature is required to prove that the user is requesting to view his/her own card
    // card is decrypted then re-encrypted using a publicKey provided by the user client to make sure that RPC cannot peek. 
    // The user can decrypt their card with the respective privateKey (stored on client)
    function viewCard(bytes32 publicKey, bytes calldata signature) public view onlySignedPublicKey(publicKey, signature) returns (bytes memory) {
        return TFHE.reencrypt(encryptedCards[msg.sender], publicKey, 0);
    }
}

Last updated