Skip to main content

Importing a dWallet with Private Key

🚧 Under Construction 🚧
This SDK is still in an experimental phase. We advise you use the SDK with localnet.

Import existing cryptographic keys (generated outside the network) as dWallets. This process creates a dWallet from an existing SECP256K1 keypair.

Prerequisites
  • Initialized IkaClient instance
  • UserShareEncryptionKeys for cryptographic operations
  • Existing SECP256K1 keypair to import
  • IKA and SUI tokens for transaction fees
Important Notes
  • Only SECP256K1 keypairs are currently supported
  • All 4 steps are required to create a functional imported dWallet
  • The original keypair should be securely stored/destroyed after import
  • Always verify the import process in production environments

Step 1: Create Session Identifier​

Create a unique session identifier for the import process:

import { IkaTransaction } from '@ika.xyz/sdk';

const tx = new Transaction();
const ikaTx = new IkaTransaction({
ikaClient,
transaction: tx,
});

const sessionIdentifier = ikaTx.createSessionIdentifier();
tx.transferObjects([sessionIdentifier], signerAddress);

await signAndExecuteTransaction(tx);

Step 2: Register Encryption Key​

Register your encryption key if you haven't done so before:

const tx = new Transaction();
const ikaTx = new IkaTransaction({
ikaClient,
transaction: tx,
userShareEncryptionKeys,
});

await ikaTx.registerEncryptionKey({
curve: Curve.SECP256K1,
});

await signAndExecuteTransaction(tx);

Step 3: Prepare Import Verification​

Prepare the cryptographic data needed to verify key ownership:

import { prepareImportedKeyDWalletVerification } from '@ika.xyz/sdk';

const importDWalletVerificationRequestInput = await prepareImportedKeyDWalletVerification(
ikaClient,
sessionIdentifierPreimage,
userShareEncryptionKeys,
existingKeypair, // Your existing SECP256K1 keypair
);

Step 4: Request Import Verification​

Choose one approach based on whether you want to keep or transfer the dWallet capability:

Keep dWallet Capability​

const tx = new Transaction();
const ikaTx = new IkaTransaction({
ikaClient,
transaction: tx,
userShareEncryptionKeys,
});

const importedKeydWalletCap = await ikaTx.requestImportedKeyDWalletVerification({
importDWalletVerificationRequestInput,
curve: Curve.SECP256K1,
signerPublicKey: signerPublicKeyBytes,
sessionIdentifier: sessionIdentifierObjectId,
ikaCoin: userIkaCoin,
suiCoin: tx.splitCoins(tx.gas, [1000000]),
});

// Use the capability as needed
tx.moveCall({
target: '0x...',
typeArguments: ['0x...'],
function: 'deposit_dwallet_for_user',
arguments: [importedKeydWalletCap],
});

await signAndExecuteTransaction(tx);

Step 5: Accept User Share​

Accept your encrypted share to complete the import process:

const tx = new Transaction();
const ikaTx = new IkaTransaction({
ikaClient,
transaction: tx,
userShareEncryptionKeys,
});

await ikaTx.acceptEncryptedUserShare({
dWallet: awaitingSignaturedWallet,
userPublicOutput: importDWalletVerificationRequestInput.userPublicOutput,
encryptedUserSecretKeyShareId: encryptedUserShareId,
});

await signAndExecuteTransaction(tx);

Complete Example​

For a complete working example of the dWallet import process, see the official example:

Creating Imported dWallet

This example demonstrates the complete flow including all steps with proper error handling, state transitions, and best practices for importing existing keys as dWallets.