Skip to main content

Key Recovery

Restore the client's secret shares to regain access to the wallet without changing its public address or key.

Step 1 : Create Session


Step 2 : Perform Key-Recovery


  • We need to have the key-share's public key to recover the share.
  • Call trioSession.recover() with the keysharePublicKey which returns Result of Success with the recovered key's keyId as a String or Failure with error.

Example


Example.swift
// Recover rebuilds a keyshare lost from this device using the other two parties.
// You address the lost share by its public key, so persist that public key when
// the key is first created (see getKeysharePublicKey below). Recover returns a new
// keyId for the restored share, which the SDK persists to your StorageClient.
func performKeyRecovery(
keysharePublicKey: Data, trioSession: TrioSession
) async -> String? {
let result: Result<String, any Error> = await trioSession.recover(
keysharePublicKey: keysharePublicKey
)
// returns nil if the operation fails, or handle it however your flow needs
switch result {
case .success(let keyId):
// keep the keyId to address the recovered keyshare in later operations
Swift.print(keyId)
return keyId
case .failure(let error):
// show the error to the user or abort the process
Swift.print(error)
return nil
}
}

// Compute the keyshare public key from keyshare bytes. Do this while you still
// have the share — e.g. right after keygen, reading the bytes from your
// StorageClient by keyId — and persist the result so it is available for recovery.
func getKeysharePublicKey(keyshare: Data) async -> Data? {
let result: Result<Data, any Error> = await SilentShard.ECDSA.getKeysharePublicKey(
keyshare
)
// returns nil if the operation fails, or handle it however your flow needs
switch result {
case .success(let publicKeyBytes):
// do something with the keyshare public-key bytes
Swift.print(publicKeyBytes)
return publicKeyBytes
case .failure(let error):
// show the error to the user or abort the process
Swift.print(error)
return nil
}
}
  • trioSession.recover() performs message exchange between mobile and server to "recover" the MPC wallet. Refer to Key Recovery for more details.
  • Result of trioSession.recover() could be a Success with the recovered key's keyId (String) or Failure with error. The recovered keyshare is persisted through your StorageClient, addressed by this keyId.
  • This process enhances the long-term security of the MPC wallet by proactively updating the client's and server's secret shares.
  • The wallet's public address or key remains unchanged during this process.