Keygen
This distributed key generation forms the basis for all subsequent MPC operations, providing a secure foundation for the wallet with enhanced privacy and security guarantees.
Step 1 : Create Session
- Create DuoSession if you haven't already.
Step 2 : Perform Keygen
- Call duoSession.keygen() which returns a
ResultofSuccesswith the generatedkeyId(aString) orFailurewith an error. The keyshare itself is persisted to your storage client, addressed by thiskeyId.
Example
Example.swift
// keygen returns the new keyId (a String). The keyshare is persisted to your
// StorageClient — keep the keyId to address it in later operations.
func performKeygen(duoSession: DuoSession) async -> String? {
let result: Result<String, any Error> = await duoSession.keygen()
// returns nil if the operation fails, or handle it however your flow needs
switch result {
case .success(let keyId):
// do something with the keyId
Swift.print(keyId)
return keyId
case .failure(let error):
// show the error to the user or abort the process
Swift.print(error)
return nil
}
}
- duoSession.keygen() performs message exchange between mobile and server to generate a new MPC wallet.
- Two new "shares" are generated: one for the client(on mobile) and one for the server(on server). Both shares together form the MPC wallet.
- Result of duoSession.keygen() could be a
Successwith akeyId(String) addressing the newly created keyshare in your storage client, orFailurewitherror - SilentShard.ECDSA.getKeysharePublicKey() or SilentShard.EdDSA.getKeysharePublicKey() could be used to get the compressed public key of the MPC wallet (read the keyshare bytes from your storage client by
keyIdfirst). Refer to SDK-Reference for additional Info and Utils.