mirror of
https://github.com/CryptKeeperZK/Docs.git
synced 2026-01-07 20:03:57 -05:00
3.0 KiB
3.0 KiB
🆔 Create identity
By default, CryptKeeper uses MetaMask to create a new Semaphore Identity [link].
- In MetaMask, a user signs a message with the private key of their Ethereum account.
- In your dapp, the user creates a deterministic identity [link] with the signed message.
- The user can now recreate their Semaphore identity whenever they want by signing the same message with their Ethereum account in Metamask.
Semaphore identities can also be created using other data (such as web2 reputations from Interep) or using random numbers.
this.add(
RPCAction.CREATE_IDENTITY,
LockService.ensure,
async (payload: NewIdentityRequest) => {
try {
const { strategy, messageSignature, options } = payload
if (!strategy) throw new Error('strategy not provided')
const numOfIdentites = await this.identityService.getNumOfIdentites()
const config: any = {
...options,
name: options?.name || `Account # ${numOfIdentites}`
}
if (strategy === 'interrep') {
console.log("CREATE_IDENTITY: 1")
config.messageSignature = messageSignature;
console.log("CREATE_IDENTITY: 2")
}
const identity: ZkIdentityWrapper | undefined = await identityFactory(strategy, config)
console.log("CREATE_IDENTITY: 4", identity);
if (!identity) {
throw new Error('Identity not created, make sure to check strategy')
}
await this.identityService.insert(identity)
return true
} catch (error: any) {
console.log("CREATE_IDENTITY: Error", error);
throw new Error(error.message)
}
}
)
- Import the
ZkKeeperControllerclass and initialize an instance of it. - Use the
RPCAction.CREATE_IDENTITYmethod, which is a function provided by theZkKeeperControllerclass, and pass in the necessary parameters as the payload. The payload should include astrategy,messageSignature, andoptionsobject. - The
strategyparameter is a string that specifies the type of identity you want to create. - The
messageSignatureparameter is a string that is the signature of some message that is used to verify the authenticity of the client. - The
optionsobject contains additional options for creating the identity including anidentityNamefield which is a string that sets the name of the newly created identity. - The function returns a promise that resolves to the new identity's commitment. Once the identity is created, it can be used to generate ZK proofs