Crate rustywallet_silent

Crate rustywallet_silent 

Source
Expand description

§rustywallet-silent

Silent Payments (BIP352) implementation for rustywallet.

Silent Payments allow receivers to publish a static address that senders can use to derive unique output addresses, providing privacy without requiring interaction between sender and receiver.

§Features

  • Address Generation: Create Silent Payment addresses with scan and spend keys
  • Sending: Derive unique output addresses for recipients
  • Scanning: Detect incoming payments using scan key
  • Labels: Support multiple addresses from a single Silent Payment address
  • Change Handling: Generate deterministic change outputs

§Quick Start

§Creating a Silent Payment Address

use rustywallet_silent::prelude::*;
use rustywallet_keys::private_key::PrivateKey;

// Generate keys
let scan_key = PrivateKey::random();
let spend_key = PrivateKey::random();

// Create address
let address = SilentPaymentAddress::new(
    &scan_key.public_key(),
    &spend_key.public_key(),
    Network::Mainnet,
).unwrap();

println!("Address: {}", address);

§Sending a Payment

use rustywallet_silent::prelude::*;
use rustywallet_keys::private_key::PrivateKey;

// Sender's input key
let sender_key = PrivateKey::random();

// Recipient's address (normally parsed from string)
let scan_key = PrivateKey::random();
let spend_key = PrivateKey::random();
let recipient = SilentPaymentAddress::new(
    &scan_key.public_key(),
    &spend_key.public_key(),
    Network::Mainnet,
).unwrap();

// Create outputs
let outpoints = vec![([0u8; 32], 0u32)]; // txid, vout
let outputs = create_outputs(
    &[sender_key.to_bytes()],
    &outpoints,
    &[recipient],
).unwrap();

// Use outputs[0].output_pubkey as the taproot output key

§Scanning for Payments

use rustywallet_silent::prelude::*;
use rustywallet_keys::private_key::PrivateKey;

// Receiver's keys
let scan_key = PrivateKey::random();
let spend_key = PrivateKey::random();

// Create scanner
let scanner = SilentPaymentScanner::new(
    &scan_key.to_bytes(),
    &spend_key.to_bytes(),
).unwrap();

// Scan transaction outputs
// let detected = scanner.scan(&output_pubkeys, &input_pubkeys, &outpoints).unwrap();

§BIP352 Compliance

This implementation follows BIP352 specification:

  • Bech32m encoding with sp (mainnet) and tsp (testnet) prefixes
  • ECDH-based shared secret derivation
  • Tagged hashing for domain separation
  • Support for labeled addresses

§Security Considerations

  • Keep scan and spend private keys secure
  • Scan key can be shared with a light client for detection
  • Spend key is required to actually spend received funds
  • Labels provide address separation without additional key material

Re-exports§

pub use address::SilentPaymentAddress;
pub use change::ChangeAddressGenerator;
pub use error::Result;
pub use error::SilentPaymentError;
pub use label::Label;
pub use label::LabelManager;
pub use network::Network;
pub use scanner::DetectedPayment;
pub use scanner::LightScanner;
pub use scanner::SilentPaymentScanner;
pub use sender::create_multiple_outputs;
pub use sender::create_outputs;
pub use sender::SilentPaymentOutput;

Modules§

address
Silent Payment address encoding and parsing.
change
Change address handling for Silent Payments.
error
Error types for Silent Payments.
label
Silent Payment labels for multiple addresses.
network
Network types for Silent Payments.
prelude
Prelude module for convenient imports.
scanner
Silent Payment scanning for receivers.
sender
Silent Payment output creation for senders.