Skip to main content

Export Key

Please refer to the Session creation section to learn how to create a new session.

Users can at any time request to "export" their keys into a private key (EOA) and stop using an MPC wallet.

warning

Once the private key is exported, the guarantees of MPC are lost.

info

Since this operation is a sensitive operations, we don't expose it directly in the SDK. Instead we provide an endpoint in the cloud node /v3/export-key that can be used to get the encrypted share of the cloud node. We provide a method in the client SDK to combine the client and server shares to recover the full private key.

It's the responsibility of the company using the SDK to expose this endpoint to the user in a secure way.

For e.g:

  • When the user requests to export the private key. The backend can request additional authentication from the user (e.g: 2FA) before exporting the private key.
  • Once the user is authenticated, the backend can get the encrypted share from the cloud node and pass it to the user.
  • The user can decrypt the share and recover the full private key using the ecdsaKeyExport() method.

Get the encrypted share of the cloud node by making a POST request to the /v3/export-key endpoint.

warning

The /v3/export-key endpoint is not exposed directly in the SDK. Here for the sake of simplicity, we will use the fetch method to make the request from the client. Do NOT expose this endpoint to the user directly in a production application.

Full Example

App.tsx
import { ecdsaKeyExport, EcdsaSession } from '@silencelaboratories/silent-shard-sdk';
import * as duo from '@silencelaboratories/dkls-sdk';
import { Platform } from 'react-native';

const CLOUD_NODE_URI = Platform.select({ android: '10.0.2.2', ios: 'localhost' }) + ':8080';

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.keyIdBase64Url);

// Export
const encryptionKey = await duo.EncryptionKey.create();
const exportRes = await fetch(`http://${CLOUD_NODE_URI}/v3/export-key`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
key_id: keyshare.keyIdBase64Url, // Use base64-url version of keyId for server request
client_enc_pubkey: encryptionKey.publicKeyB64,
}),
});

const exportJson = await exportRes.json();

const exportConfig = {
keyshare: keyshare,
client_secret_key: encryptionKey.privateKeyB64,
server_public_key: exportJson.server_public_key,
encrypted_server_share: exportJson.enc_server_share,
};

const privateKeyB64 = await ecdsaKeyExport(exportConfig);
console.log('Exported private key: ', privateKeyB64);
};
  • The request body format is documented in the export-key endpoint.
  • key_id: The key ID of the keyshare. Unique identifier for a wallet, 32 byte base64Url encoded string.
  • client_enc_pubkey: The encryption public key of the client. Base64 encoded string.
  • exportJson: The response from the export-key endpoint. It contains the encrypted share of the cloud node.
  • ExportConfig object has the following properties:
    • keyshare: The client's share of the MPC wallet.
    • client_dec_key: The decryption key for decrypting the server response.
    • server_enc_pubkey: The server's encryption public key. (This is included in the response from the export-key endpoint)
    • encrypted_server_share: The encrypted server share. (This is included in the response from the export-key endpoint)
  • privateKeyHex: The expored private key in hex format.