Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions silentpayments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The library is split up in two parts: sending and receiving.
This library offers granular feature flags to minimize dependencies for different use cases:

- **default**: Enables all features (`encode`, `sending`, `receiving`)
- **encode**: Enables string encoding/decoding for `SilentPaymentAddress` (adds `bech32` dependency)
- **encode**: Enables string encoding/decoding for `SilentPaymentAddressDisplay` (adds `bech32` dependency)
- **serde**: Enables serde serialization/deserialization for types (adds `serde` dependency)
- **sending**: Enables sending functionality (adds `bitcoin_hashes`, `hex` dependencies)
- **receiving**: Enables receiving functionality (adds `bitcoin_hashes`, `hex`, `bimap`, `serde` dependencies)
Expand All @@ -35,7 +35,7 @@ silentpayments = { version = "0.4", default-features = false }

This configuration only pulls in `secp256k1` as a dependency, significantly reducing the dependency tree for applications that only need to work with silent payment addresses without implementing the full protocol.

**Bring Your Own Parser**: Even without the `encode` feature, you can construct a `SilentPaymentAddress` using `SilentPaymentAddress::new()` if you parse the bech32 yourself. This is useful if your application already has a bech32 parser and you want to avoid duplicate dependencies. The constructor documentation includes the complete bech32 format specification.
**Bring Your Own Parser**: Even without the `encode` feature, you can construct a `SilentPaymentAddress` using `SilentPaymentAddress::new()` from pubkeys you parsed yourself. With `encode`, use `SilentPaymentAddressDisplay` for bech32m strings; see `SilentPaymentAddressDisplay::new` for the on-wire format if you parse bech32 yourself.

### Custom Feature Combinations

Expand Down
7 changes: 6 additions & 1 deletion silentpayments/examples/create_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ fn main() -> Result<(), Box<dyn Error>> {
)?;

// Print the receiving address to the console
println!("Receiving address: {}", receiver.get_receiving_address());
println!(
"Receiving address: {}",
receiver
.get_receiving_address()
.to_display_for_network(receiver.network)
);

Ok(())
}
47 changes: 0 additions & 47 deletions silentpayments/examples/custom_parser.rs

This file was deleted.

12 changes: 7 additions & 5 deletions silentpayments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! This library offers granular feature flags to minimize dependencies:
//!
//! - **default**: Enables `encode`, `sending`, and `receiving` features
//! - **encode**: Enables string encoding/decoding for `SilentPaymentAddress` (requires `bech32`)
//! - **encode**: Enables string encoding/decoding for `SilentPaymentAddressDisplay` (requires `bech32`)
//! - **serde**: Enables serde serialization/deserialization for types
//! - **sending**: Enables sending functionality (requires `bitcoin_hashes`, `hex`, and `encode`)
//! - **receiving**: Enables receiving functionality (requires `bitcoin_hashes`, `hex`, `bimap`, `serde`, and `encode`)
Expand All @@ -24,10 +24,10 @@
//! This will only pull in `secp256k1` as a dependency, giving you access to the core types
//! without any encoding, serialization, or protocol functionality.
//!
//! **Note**: Even without the `encode` feature, you can still construct a `SilentPaymentAddress`
//! from its components using `SilentPaymentAddress::new()`. This allows you to use your own
//! bech32 parser (if your application already has one) and avoid duplicate dependencies.
//! See the `SilentPaymentAddress::new()` documentation for the bech32 format specification.
//! **Note**: Without the `encode` feature, construct a [`SilentPaymentAddress`] from
//! parsed pubkeys using [`SilentPaymentAddress::new`]. With `encode`, use
//! [`SilentPaymentAddressDisplay`] for bech32m strings (see [`SilentPaymentAddressDisplay::new`]
//! for the on-wire format if you parse bech32 yourself).
//!
//! ## Examples
//!
Expand Down Expand Up @@ -55,6 +55,8 @@ pub use utils::common::Network;
#[cfg(any(feature = "sending", feature = "receiving"))]
pub use utils::common::SharedSecret;
pub use utils::common::SilentPaymentAddress;
#[cfg(feature = "encode")]
pub use utils::common::SilentPaymentAddressDisplay;
pub use utils::common::SpVersion;

pub type Result<T> = std::result::Result<T, Error>;
2 changes: 1 addition & 1 deletion silentpayments/src/receiving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl Receiver {
}

fn get_silent_payment_address(&self, m_pubkey: PublicKey) -> SilentPaymentAddress {
SilentPaymentAddress::new(self.scan_pubkey, m_pubkey, self.network, self.version)
SilentPaymentAddress::new(self.version, self.scan_pubkey, m_pubkey)
}
}

Expand Down
16 changes: 8 additions & 8 deletions silentpayments/src/sending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use std::collections::HashMap;

use crate::utils::common::calculate_t_n;
use crate::utils::common::SharedSecret;
use crate::utils::common::SilentPaymentAddress;
use crate::utils::sending::calculate_ecdh_shared_secret;
use crate::utils::sending::PartialSecret;
use crate::Result;
use crate::SilentPaymentAddress;

/// Create outputs for a given set of silent payment recipients and their corresponding shared secrets.
///
Expand All @@ -26,7 +26,7 @@ use crate::SilentPaymentAddress;
///
/// # Arguments
///
/// * `recipients` - A [Vec] of silent payment addresses strings to be paid.
/// * `recipients` - A [Vec] of silent payment addresses to be paid.
/// * `partial_secret` - [PartialSecret] that represents the sum of the private keys of eligible inputs of the transaction multiplied by the input hash.
///
/// # Returns
Expand All @@ -38,7 +38,6 @@ use crate::SilentPaymentAddress;
///
/// This function will return an error if:
///
/// * The recipients [Vec] contains a silent payment address with an incorrect format.
/// * Edge cases are hit during elliptic curve computation (extremely unlikely).
pub fn generate_recipient_pubkeys(
recipients: Vec<SilentPaymentAddress>,
Expand All @@ -49,14 +48,15 @@ pub fn generate_recipient_pubkeys(
let mut silent_payment_groups: HashMap<PublicKey, (SharedSecret, Vec<SilentPaymentAddress>)> =
HashMap::new();
for address in recipients {
let B_scan = address.get_scan_key();
let recipient_scan_key = address.scan_key();

if let Some((_, payments)) = silent_payment_groups.get_mut(&B_scan) {
if let Some((_, payments)) = silent_payment_groups.get_mut(&recipient_scan_key) {
payments.push(address);
} else {
let ecdh_shared_secret = calculate_ecdh_shared_secret(&B_scan, &partial_secret);
let ecdh_shared_secret =
calculate_ecdh_shared_secret(&recipient_scan_key, &partial_secret);

silent_payment_groups.insert(B_scan, (ecdh_shared_secret, vec![address]));
silent_payment_groups.insert(recipient_scan_key, (ecdh_shared_secret, vec![address]));
}
}

Expand All @@ -68,7 +68,7 @@ pub fn generate_recipient_pubkeys(
let t_n = calculate_t_n(&ecdh_shared_secret, n as u32)?;

let res = t_n.public_key(&secp);
let reskey = res.combine(&addr.get_spend_key())?;
let reskey = res.combine(&addr.m_pubkey())?;
let (reskey_xonly, _) = reskey.x_only_public_key();

let entry = result.entry(addr).or_default();
Expand Down
Loading
Loading