Import Key
Please refer to the Session creation section to learn how to create a new session.
Import key allows to transit from an EOA wallet to an MPC wallet. This is a common use case in the digital wallet ecosystem where a wallet provider wants to onboard existing users from other wallets.
Although converting an EOA wallet to an MPC wallet increases security, it's important to note that the original private key still exists in full form. Therefore, we cannot provide the same level of security guarantees as with a natively generated MPC wallet, where the full private key is never assembled.
Full example:
- ECDSA
- EdDSA
import { type EcdsaSession } from '@silencelaboratories/silent-shard-sdk/ecdsa';
export const importKey = async (
session: EcdsaSession,
privateKey: string = '<PRIVATE_KEY_YOU_WANT_TO_IMPORT_IN_HEX>'
) => {
const importConfig = {
privateKey,
};
const importedKeyshare = await session.import(importConfig);
console.log('Imported keyshare: ', importedKeyshare.publicKeyHex);
};
import { type EddsaSession } from '@silencelaboratories/silent-shard-sdk/eddsa';
export const importKey = async (
session: EddsaSession,
privateKey: string = '<PRIVATE_KEY_YOU_WANT_TO_IMPORT_IN_HEX>'
) => {
const importConfig = {
privateKey,
};
const importedKeyshare = await session.import(importConfig);
console.log('Imported keyshare: ', importedKeyshare.publicKeyHex);
};
privateKey: This is the private key to be imported. It's a 32 bytes hex string.- The
importConfig(EcdsaImportConfig) contains the required information to import the private key into an MPC wallet. - Import the private key and create a new keyshare(Keyshare) using the
session.import()method.
You have now successfully imported an existing private key into an MPC wallet! 🎉
Please refer to the Session creation section to learn how to create a new session.
Import key allows to transit from an EOA wallet to an MPC wallet. This is a common use case in the digital wallet ecosystem where a wallet provider wants to onboard existing users from other wallets.
Although converting an EOA wallet to an MPC wallet increases security, it's important to note that the original private key still exists in full form. Therefore, we cannot provide the same level of security guarantees as with a natively generated MPC wallet, where the full private key is never assembled.
Full example:
- ECDSA
- EdDSA
- Taproot
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
Future<sdk.DklsKeyshare> importKey(
sdk.EcdsaSession session,
String privateKey, // PRIVATE_KEY_YOU_WANT_TO_IMPORT_IN_HEX
String? rootChainCode, // ROOT_CHAIN_CODE_YOU_WANT_TO_USE_IN_HEX
) async {
final keyshare = await session.import(
privateKey: privateKey,
rootChainCode: rootChainCode,
);
print(
'Imported private key and created keyshare, public key: ${keyshare.publicKeyHex}');
return keyshare;
}
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
Future<void> importKey(
sdk.EddsaSession session,
String privateKey, // PRIVATE_KEY_YOU_WANT_TO_IMPORT_IN_HEX
) async {
final keyshare = await session.import(
privateKey: privateKey,
);
print(
'Imported private key and created keyshare, public key: ${keyshare.publicKeyHex}');
}
import 'package:silent_shard_sdk/silent_shard_sdk.dart' as sdk;
Future<sdk.TaprootKeyshare> importKey(
sdk.TaprootSession session,
String privateKey, // PRIVATE_KEY_YOU_WANT_TO_IMPORT_IN_HEX
) async {
final sdk.TaprootKeyshare keyshare = await session.import(
privateKey: privateKey,
);
print(
'Imported private key and created keyshare, public key: ${keyshare.publicKeyHex}');
return keyshare;
}
- Import the private key and create a new keyshare using the
session.import()method. privateKey: This is the private key to be imported. It's a 32 bytes hex string.rootChainCode: This is the BIP32 root chain code used along with this private key. If it doesn't exist, please use a cryptographically secure random 32 bytes hex string.
You have now successfully imported an existing private key into an MPC wallet! 🎉
Import key allows to transit from an EOA wallet to an MPC wallet. This is a common use case in the digital wallet ecosystem where a wallet provider wants to onboard existing users from other wallets.
Although converting an EOA wallet to an MPC wallet increases security, it's important to note that the original private key still exists in full form. Therefore, we cannot provide the same level of security guarantees as with a natively generated MPC wallet, where the full private key is never assembled.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Import
- Call trioSession.import() with
keysharePrivateKey(explained below) which returns Result of Success with akeyId(String) or Failure with exception.
Example
// import places an existing private key under three-party MPC and returns the
// new keyId. The resulting keyshare is persisted to your StorageClient — keep
// the keyId to address it in later operations.
suspend fun performKeyImport(keysharePrivateKey: ByteArray, trioSession: TrioSession): String {
return withContext(Dispatchers.IO) {
trioSession.import(
keysharePrivateKey = keysharePrivateKey
).getOrThrow()
}
}
keysharePrivateKey: This is the private key to be imported. It's a 32 bytesByteArray.
You have now successfully imported an existing private key into an MPC wallet! 🎉
Import key allows to transit from an EOA wallet to an MPC wallet. This is a common use case in the digital wallet ecosystem where a wallet provider wants to onboard existing users from other wallets.
Although converting an EOA wallet to an MPC wallet increases security, it's important to note that the original private key still exists in full form. Therefore, we cannot provide the same level of security guarantees as with a natively generated MPC wallet, where the full private key is never assembled.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Import
- Call trioSession.import() with
keysharePrivateKey(explained below) which returnsResultofSuccesswith the imported key'skeyIdas aStringorFailurewitherror.
Example
// import places a raw private key back under three-party MPC and returns the
// new keyId. The keyshare is persisted to your StorageClient.
func performKeyImport(keysharePrivateKey: Data, trioSession: TrioSession) async -> String? {
let result: Result<String, any Error> = await trioSession.import(
keysharePrivateKey: keysharePrivateKey
)
// 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
}
}
keysharePrivateKey: This is the private key to be imported. It's a 32 bytes asData.
You have now successfully imported an existing private key into an MPC wallet! 🎉