API Reference
StealthKeypair
A spending keypair derived for a specific stealth payment. Used to sign transactions and claim funds from stealth addresses.
Structure
cloak_sdk::spend
pub struct StealthKeypair {
keypair: Keypair, // Solana keypair (internal)
}
// Security notes:
// - Implements Zeroize for secure memory cleanup
// - No Serialize trait (prevents accidental persistence)
// - No Debug output of private keysMethods
derive(meta, ephemeral_pubkey) → Result<StealthKeypair>
Derive the spending keypair for a payment from the meta-address and the ephemeral public key published on-chain.
let keypair = StealthKeypair::derive(&meta, &ephemeral_pubkey)?;
assert_eq!(keypair.address(), expected_stealth_address);from_payment(meta, payment) → Result<StealthKeypair>
Convenience method that extracts the ephemeral key from a DetectedPayment.
let keypair = StealthKeypair::from_payment(&meta, &detected_payment)?;address() → Pubkey
Get the Solana public key (stealth address) for this keypair.
let stealth_addr = keypair.address();pubkey_bytes() → [u8; 32]
Get the raw 32-byte public key.
to_solana_keypair() → Result<Keypair>
Convert to a Solana SDK Keypair for signing transactions.
let solana_kp = keypair.to_solana_keypair()?;to_bytes() → [u8; 64]
Get the raw 64 bytes (32 secret + 32 public).
Example: SOL transfer
spend_sol.rs
use cloak_sdk::StealthKeypair;
use solana_sdk::{transaction::Transaction, system_instruction};
let keypair = StealthKeypair::derive(&meta, &ephemeral_pubkey)?;
let solana_kp = keypair.to_solana_keypair()?;
// Transfer all SOL to destination
let balance = client.get_balance(&keypair.address())?;
let ix = system_instruction::transfer(
&keypair.address(),
&destination,
balance - 5000, // leave for fees
);
let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&keypair.address()),
&[&solana_kp],
client.get_latest_blockhash()?,
);
client.send_and_confirm_transaction(&tx)?;Example: SPL token transfer
spend_spl.rs
use spl_token::instruction::transfer as spl_transfer;
use spl_associated_token_account::get_associated_token_address;
let source_ata = get_associated_token_address(&keypair.address(), &mint);
let dest_ata = get_associated_token_address(&destination, &mint);
let ix = spl_transfer(
&spl_token::id(),
&source_ata,
&dest_ata,
&keypair.address(),
&[],
token_amount,
)?;
let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&keypair.address()),
&[&solana_kp],
recent_blockhash,
);