Export Key
Reconstruct and export the full private key of the MPC wallet by combining the shares. Use this to move a wallet out of MPC, for example into another wallet ecosystem. Gate this behind strong user authentication.
Once the private key is exported, the MPC security guarantees are lost.
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 exportKey = 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 privateKeyHex = await session.export({
keyshare,
});
console.log('Exported private key: ', privateKeyHex);
};
App.tsx
import { type EddsaSession } from '@silencelaboratories/silent-shard-sdk/eddsa';
export const exportKey = async (session: EddsaSession) => {
// Creating a new keyshare. In real application, you can use an existing keyshare.
const keyshare = await session.keygen();
console.log('Keyshare: ', keyshare.keyIdHex);
const privateKeyHex = await session.export({
keyshare,
});
console.log('Exported private key: ', privateKeyHex);
};
- The
exportmethod takes a EcdsaExportConfig object as an argument.keyshareis of type Keyshare and represents the client's share of the MPC wallet
privateKeyHex: The exported private key in hex format.
Please refer to the Session creation section to learn how to create a new session.
Full Example
- ECDSA
- EdDSA
- Taproot
main.dart
import 'dart:io';
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
const port = 8080;
final nodeUri = Platform.isAndroid ? '10.0.2.2:$port' : '0.0.0.0:$port';
Future<String> exportKey(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 privateKey = await session.export(keyId: keyshare.keyId);
print('Exported private key: $privateKey');
return privateKey;
}
main.dart
import 'dart:io';
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
const port = 8080;
final nodeUri = Platform.isAndroid ? '10.0.2.2:$port' : '0.0.0.0:$port';
Future<void> exportKey(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 privateKey = await session.export(keyId: keyshare.keyId);
print('Exported private key: $privateKey');
}
main.dart
import 'package:convert/convert.dart';
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
Future<String> exportKey(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('Keyshare created, public key: ${keyshare.publicKeyHex}');
// Trio export uses a server-coordinated WebSocket protocol — no HTTP call needed.
final privateKeyBytes = await session.trioExport(keyshare: keyshare);
final privateKey = hex.encode(privateKeyBytes);
print('Exported private key: $privateKey');
return privateKey;
}
- The
exportmethod takes an argument.keyshareis of type DklsKeyshare and represents the client's share of the MPC wallet.
privateKey: The exported private key in hex format.
Users can at any time request to "export" their keys into a private key.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Export
- Call trioSession.export() with the
keyIdwhich returnsResultofSuccesswith the exported private key asByteArrayorFailurewith exception.
Example
Example.kt
// export reconstructs the raw private key of the key addressed by keyId.
// Treat the result like any private key — encrypt it at rest; bring it back
// under MPC later with import.
suspend fun exportPrivateKey(keyId: String, trioSession: TrioSession): ByteArray {
return withContext(Dispatchers.IO) {
trioSession.export(
keyId = keyId
).getOrThrow()
}
}
keyId: Identifies the key to export; it is returned by keygen and addresses the client's keyshare in your storage.
Users can at any time request to "export" their keys into a private key.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Export
- Call trioSession.export() with the
keyIdwhich returnsResultofSuccesswith the exported private key bytes asDataorFailurewitherror.
Example
Example.swift
// export reconstructs the raw private key for the key addressed by keyId (the
// SDK handles backup encryption internally, with no HTTP roundtrip). Treat the
// result like any private key — encrypt it at rest — and bring it back under
// MPC later with trioSession.import(keysharePrivateKey:).
func exportPrivateKey(keyId: String, trioSession: TrioSession) async -> Data? {
let result = await trioSession.export(keyId: keyId)
// returns nil if the operation fails, or handle it however your flow needs
switch result {
case .success(let privateKeyBytes):
// do something with the reconstructed private-key bytes
Swift.print(privateKeyBytes)
return privateKeyBytes
case .failure(let error):
// show the error to the user or abort the process
Swift.print(error)
return nil
}
}
keyId: Identifies the client's (In this case mobile) key to export. The SDK loads the keyshare from your StorageClient and handles the backup encryption internally.