Key Recovery
Restore the client's secret shares to regain access to the wallet without changing its public address or key.
Please refer to the Session creation section to learn how to create a new session.
Full example:
- ECDSA
- EdDSA
App.tsx
import { type EcdsaSession } from '@silencelaboratories/silent-shard-sdk/ecdsa';
export const recovery = async (session: EcdsaSession) => {
// Creating a new keyshare for demo purpose. In real application, you can use an existing keyshare.
const keyshare = await session.keygen();
console.log('Keyshare: ', keyshare.keyIdHex);
const recoveredKeyshare = await session.recovery(keyshare.publicKeyHex);
console.log('Recovered keyshare: ', recoveredKeyshare.keyIdHex);
};
App.tsx
import { type EddsaSession } from '@silencelaboratories/silent-shard-sdk/eddsa';
export const recovery = async (session: EddsaSession) => {
// Creating a new keyshare for demo purpose. In real application, you can use an existing keyshare.
const keyshare = await session.keygen();
console.log('Keyshare: ', keyshare.keyIdHex);
const recoveredKeyshare = await session.recovery(keyshare.publicKeyHex);
console.log('Recovered keyshare: ', recoveredKeyshare.keyIdHex);
};
- When
session.recovery(keyshare)is called, the app and the server exchange message to "recover" the MPC wallet. Refer to Key Recovery for more details. publicKeyHexis the public key of the client's share of the MPC wallet to be recovered.- 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.
recoveredKeyshareis of type Keyshare and represents the client's new share of the MPC wallet.
Restore the client's secret shares to regain access to the wallet without changing its public address or key.
Please refer to the Session creation section to learn how to create a new session.
Full example:
- ECDSA
- EdDSA
- Taproot
main.dart
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
Future<void> recovery(sdk.EcdsaSession session) async {
// Creating a new keyshare for demo purpose. In real application, you can use an existing keyshare.
final keyshare = await session.keygen();
print('Keyshare created, public key: ${keyshare.publicKeyHex}');
final recoveredKeyshare =
await session.recovery(publicKey: keyshare.publicKeyHex);
print('Recovered keyshare, public key: ${recoveredKeyshare.publicKeyHex}');
}
main.dart
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
Future<void> recovery(sdk.EddsaSession session) async {
// Creating a new keyshare for demo purpose. In real application, you can use an existing keyshare.
final keyshare = await session.keygen();
final recoveredKeyshare =
await session.recovery(publicKey: await keyshare.publicKeyHex);
print('Recovered keyshare: ${await recoveredKeyshare.publicKeyHex}');
}
main.dart
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
Future<void> keyRecovery(sdk.TaprootSession session) async {
// Creating a new keyshare for demo purpose. In real application, you can use an existing keyshare.
final sdk.TaprootKeyshare keyshare = await session.keygen();
print('Original public key: ${keyshare.publicKeyHex}');
// Recovery reconstructs the mobile share from the two cloud shares.
// Pass the public key hex of the wallet you want to recover.
final recoveredKeyshare = await session.recovery(
publicKey: keyshare.publicKeyHex,
);
print('Recovered keyshare, public key: ${recoveredKeyshare.publicKeyHex}');
}
- When
session.recovery(keyshare_public_key)is called, the app and the server exchange message to "recover" the MPC wallet. Refer to Key Recovery for more details. publicKeyHexis the public key of the client's share of the MPC wallet to be recovered.- 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.
- The
recoveredKeyshareobject is of type DklsKeyshare and represents the client's new share of the MPC wallet.
Restore the client's secret shares to regain access to the wallet without changing its public address or key.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Key-Refresh
- We need the keyshare's public key (
keysharePublicKey) to recover the share. - Call trioSession.recover() which returns Result of Success with a
keyId(String) or Failure with exception.
Example
- ECDSA
- EdDSA
Example.kt
suspend fun performKeyRecovery(trioSession: TrioSession, storageClient: StorageClient): String {
return withContext(Dispatchers.IO) {
//At some point of time you might have done keygen.
val keyId = trioSession.keygen().getOrThrow()
//You might have stored public-key of the keyshare(ECDSA).
//Read the keyshare bytes from your StorageClient by keyId, then extract its public key.
val keyshare = (storageClient.read(keyId) as ReconcileStoreDao).currentKeyshare!!
val keysharePublicKey = SilentShard.ECDSA.getKeysharePublicKey(keyshare).getOrThrow()
// Perform recovery operation
val recoveredKeyId = trioSession.recover(keysharePublicKey = keysharePublicKey).getOrThrow()
recoveredKeyId
}
}
Example.kt
suspend fun performKeyRecovery(trioSession: TrioSession, storageClient: StorageClient): String {
return withContext(Dispatchers.IO) {
//At some point of time you might have done keygen.
val keyId = trioSession.keygen().getOrThrow()
//You might have stored public-key of the keyshare(EdDSA).
//Read the keyshare bytes from your StorageClient by keyId, then extract its public key.
val keyshare = (storageClient.read(keyId) as ReconcileStoreDao).currentKeyshare!!
val keysharePublicKey = SilentShard.EdDSA.getKeysharePublicKey(keyshare).getOrThrow()
// Perform recovery operation
val recoveredKeyId = trioSession.recover(keysharePublicKey = keysharePublicKey).getOrThrow()
recoveredKeyId
}
}
- 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
Successwith aString(the recoveredkeyId) orFailurewithException - 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.
Restore the client's secret shares to regain access to the wallet without changing its public address or key.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Key-Recovery
- We need to have the key-share's public key to recover the share.
- Call trioSession.recover() with the
keysharePublicKeywhich returnsResultofSuccesswith the recovered key'skeyIdas aStringorFailurewitherror.
Example
- ECDSA
- EdDSA
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
}
}
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.EdDSA.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
Successwith the recovered key'skeyId(String) orFailurewitherror. The recovered keyshare is persisted through your StorageClient, addressed by thiskeyId. - 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.