API Reference

StealthMetaAddress

The core identity type. Contains spending and viewing keypairs for generating and receiving stealth payments.

Structure

cloak_sdk::keys
rust
pub struct StealthMetaAddress {
    spending_key: [u8; 32],      // Private — keep secret
    viewing_key: [u8; 32],       // Private — can delegate
    spending_pubkey: [u8; 32],   // Public — share freely
    viewing_pubkey: [u8; 32],    // Public — share freely
}

Methods

generate() → StealthMetaAddress

Create a new stealth identity with cryptographically random keys. Uses domain-separated key derivation.

let meta = StealthMetaAddress::generate();

save_to_file(path) → Result<()>

Persist the full meta-address (including private keys) to a JSON file.

meta.save_to_file("~/.cloak/keys.json")?;

load_from_file(path) → Result<StealthMetaAddress>

Load a meta-address from a JSON file.

let meta = StealthMetaAddress::load_from_file("~/.cloak/keys.json")?;

public_meta_address() → PublicMetaAddress

Extract only the public keys as a PublicMetaAddress (safe to share).

let public = meta.public_meta_address();

to_public_string() → String

Encode the public meta-address as a shareable string.

let addr = meta.to_public_string();
// → "stealth1:sol:<spending_pubkey>:<viewing_pubkey>"

Accessors

meta.spending_key()    // → &[u8; 32] (private)
meta.viewing_key()     // → &[u8; 32] (private)
meta.spending_pubkey() // → &[u8; 32] (public)
meta.viewing_pubkey()  // → &[u8; 32] (public)

derive_spend_key(ephemeral_pubkey) → Result<[u8; 32]>

Derive the spending key seed for a specific payment. Used internally by StealthKeypair::derive().

let seed = meta.derive_spend_key(&ephemeral_pubkey)?;

compute_shared_secret(ephemeral_pubkey) → Result<[u8; 32]>

Compute the ECDH shared secret with an ephemeral public key. Used internally for payment detection.

let secret = meta.compute_shared_secret(&ephemeral_pubkey)?;

PublicMetaAddress

Contains only the public keys. Safe to share and distribute.

pub struct PublicMetaAddress {
    spending_pubkey: [u8; 32],
    viewing_pubkey: [u8; 32],
}

// Parse from string
let recipient = PublicMetaAddress::from_string("stealth1:sol:...")?;

// Access public keys
recipient.spending_pubkey() // → &[u8; 32]
recipient.viewing_pubkey()  // → &[u8; 32]