@unirep/contracts
Version:
Client library for contracts related functions which are used in UniRep protocol.
31 lines (30 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.genSignature = exports.UnirepFactory = exports.getUnirepContract = void 0;
const typechain_1 = require("../typechain");
Object.defineProperty(exports, "UnirepFactory", { enumerable: true, get: function () { return typechain_1.Unirep__factory; } });
const ethers_1 = require("ethers");
/**
* Get Unirep smart contract from a given address
* @param address The address if the Unirep contract
* @param signerOrProvider The signer or provider that will connect to the Unirep smart contract
* @returns The Unirep smart contract
*/
const getUnirepContract = (address, signerOrProvider) => {
return typechain_1.Unirep__factory.connect(address, signerOrProvider);
};
exports.getUnirepContract = getUnirepContract;
/**
* Generate attester sign up signature
* @param unirepAddress The address of UniRep smart contract
* @param attester The address of the attester
* @param epochLength Epoch length specified by the attester
* @param chainId The current chain id of the UniRep smart contract
* @returns An sign up signature for the attester
*/
const genSignature = async (unirepAddress, attester, epochLength, chainId) => {
const attesterAddress = await attester.getAddress();
const message = ethers_1.ethers.utils.solidityKeccak256(['address', 'address', 'uint256', 'uint256'], [unirepAddress, attesterAddress, epochLength, chainId]);
return attester.signMessage(ethers_1.ethers.utils.arrayify(message));
};
exports.genSignature = genSignature;