The library provides a convenient function that generates a JSON object based on the EIP-712 standard. This JSON object includes a public key and is specifically designed to facilitate data reencryption in a smart contract environment.
By utilizing this JSON object and having it signed by the user, a secure process of reencrypting data becomes possible within a smart contract. The signed JSON includes the necessary information, including the public key, which allows for seamless reencryption of the data.
FhevmInstance.generateToken
Parameters
options (required):
verifyingContract: string (required): The address of the contract
name: string (optional): The name used in the EIP712
version: string (optional): The version used in the EIP712
This method allows you to store the signature of a public key for a specific contract, in order to retrieve it later. The signature is also serialized in serializeKeypairs.
Parameters
contractAddress: string (required): address of the contract
signature: string (required): the signature of the EIP-712 token
Example
const instance = await createInstance({ chainId, publicKey });
const generatedToken = instance.generateToken({
name: "Authentication",
verifyingContract: "0x1c786b8ca49D932AFaDCEc00827352B503edf16c",
});
// Ask for user to sign the token
const params = [userAddress, JSON.stringify(generatedToken.token)];
const sign = await window.ethereum.request({
method: "eth_signTypedData_v4",
params,
});
// Store signature
instance.setTokenSignature(contractAddress, sign);
FhevmInstance.hasKeypair
This method returns true if contract has a keypair and a signature.
Parameters
contractAddress: string (required): address of the contract
This method returns the saved public key and signature for a specific contract. If the contract has no keypair or no signature, this method returns null.
Parameters
contractAddress: string (required): address of the contract