Import Key
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 DuoSession if you haven't already.
Step 2 : Perform Import
- Call duoSession.import() with all the required params (as explained below) which returns a
ResultofSuccesswith the generatedkeyId(aString) orFailurewitherror. The imported keyshare is persisted to your storage client.
Example
Example.swift
// import brings a raw private key back under two-party MPC and returns a new
// keyId (a String). The resulting keyshare is persisted to your StorageClient;
// keep the keyId to address it in later operations.
func performImport(keysharePrivateKey: Data, duoSession: DuoSession) async -> String? {
let result = await duoSession.import(
keysharePrivateKey: keysharePrivateKey,
rootChainCode: getRootChainCode()
)
// 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.rootChainCode: This is the BIP32 root chain code used along with this private key, passed as aString. If it doesn't exist, please use a cryptographically secure random 32-byte chain code.
You have now successfully imported an existing private key into an MPC wallet! 🎉