/
index.ts
38 lines (36 loc) · 1.37 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Unirep, Unirep__factory as UnirepFactory } from '../typechain'
import { ethers } from '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
*/
export const getUnirepContract = (
address: string,
signerOrProvider: ethers.Signer | ethers.providers.Provider
): Unirep => {
return UnirepFactory.connect(address, signerOrProvider)
}
export { Unirep, UnirepFactory }
/**
* 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
*/
export const genSignature = async (
unirepAddress: string,
attester: ethers.Signer | ethers.Wallet,
epochLength: number,
chainId: bigint | number
): Promise<string> => {
const attesterAddress = await attester.getAddress()
const message = ethers.utils.solidityKeccak256(
['address', 'address', 'uint256', 'uint256'],
[unirepAddress, attesterAddress, epochLength, chainId]
)
return attester.signMessage(ethers.utils.arrayify(message))
}