2. User signs up
Should connect to a deployed contract first.
import { getUnirepContract } from '@unirep/contracts'
// user can connect the Unirep smart contract with getUnirepContract
const contract = await getUnirepContract(
UNIREP_CONTRACT_ADDRESS,
signer
)
Use the Semaphore identity commitment to sign up in UniRep smart contract.
import { ZkIdentity } from '@unirep/crypto'
// generate a Semaphore identity
const identity = new ZkIdentity()
// sign up in UniRep smart contract with Semaphore identity commitment
const tx = await contract['userSignUp(uint256)'](
identity.genIdentityCommitment()
)
Save the serialized Semaphore identity.
// print the Semaphore identity and save it
console.log(identity.serializeIdentity())
// Example output:
// {"identityNullifier":"27d1ae5c98aab64b851a9c668a7eec0d835867a17d4b9454a8bf9824836271d6","identityTrapdoor":"2596ecc2a1e1f6a8f279e097464e6edc3b18b946d934398dfe52a34c4e414e67","secret":["27d1ae5c98aab64b851a9c668a7eec0d835867a17d4b9454a8bf9824836271d6","2596ecc2a1e1f6a8f279e097464e6edc3b18b946d934398dfe52a34c4e414e67"]}
info
See: @unirep/crypto