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
2 changes: 1 addition & 1 deletion silentpayments/src/send/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ impl XprivSilentPaymentSender {
let partial_secret =
create_silentpayment_partial_secret(&lex_min.bytes()?, &spks_with_keys)?;

create_silentpayment_scriptpubkeys(partial_secret, outputs)
Ok(create_silentpayment_scriptpubkeys(partial_secret, outputs))
}
}
2 changes: 1 addition & 1 deletion silentpayments/src/send/bip352.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ impl SpSender {
let partial_secret =
create_silentpayment_partial_secret(&lex_min.bytes()?, &spks_with_keys)?;

create_silentpayment_scriptpubkeys(partial_secret, outputs)
Ok(create_silentpayment_scriptpubkeys(partial_secret, outputs))
}
}
9 changes: 9 additions & 0 deletions silentpayments/src/send/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ pub enum SpSendError {
IndexError(bitcoin::blockdata::transaction::OutputsIndexError),
/// PSBT missing silent payment placeholder script
MissingPlaceholderScript,
/// Error while requesting keys
KeyError,
/// There are not enough silent payment derivations for all targeted outputs
MissingDerivations,
/// There are not enough outputs for the silent payments derived
MissingOutputs,
}

impl From<crate::LexMinError> for SpSendError {
Expand Down Expand Up @@ -49,11 +55,14 @@ impl std::fmt::Display for SpSendError {
Self::Secp256k1Error(e) => write!(f, "Silent payment sending error: {e}"),
Self::IndexError(e) => write!(f, "From PSBT: {e}"),
Self::NoOutpoints(e) => write!(f, "Silent payment sending error: {e}"),
Self::KeyError => write!(f, "Silent payment sending error: error while requesting private keys from key provider"),
Self::MissingInputsForSharedSecretDerivation => write!(f, "No available inputs for shared secret derivation"),
Self::MissingWitness => write!(
f,
"From PSBT, missing witness to get public key to derive silent payment output"
),
Self::MissingDerivations => write!(f, "From PSBT, there are not enough silent payment derivations for all targeted outputs"),
Self::MissingOutputs => write!(f, "From PSBT, there are not enough outputs for the silent payments derived"),
Self::MissingPrevout => write!(f, "From PSBT, unable to extract prevout script pubkey"),
Self::MissingPlaceholderScript => write!(f, "From PSBT, missing placeholder script pubkey for associated silent payment recipient."),
}
Expand Down
31 changes: 11 additions & 20 deletions silentpayments/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn create_silentpayment_partial_secret(
pub fn create_silentpayment_scriptpubkeys(
partial_secret: SecretKey,
outputs: &[SilentPaymentCode],
) -> Result<HashMap<SilentPaymentCode, Vec<XOnlyPublicKey>>, SpSendError> {
) -> HashMap<SilentPaymentCode, Vec<XOnlyPublicKey>> {
let secp = Secp256k1::new();

// Cache to avoid recomputing ecdh shared secret for each B_scan and track the k to get the
Expand Down Expand Up @@ -117,7 +117,7 @@ pub fn create_silentpayment_scriptpubkeys(
}
}

Ok(payments)
payments
}

#[cfg(test)]
Expand Down Expand Up @@ -308,8 +308,7 @@ mod tests {
fn test_create_silentpayment_spk_base() {
let (partial_secret, sp_codes) = setup_test_data();

let result =
create_silentpayment_scriptpubkeys(partial_secret, &sp_codes).expect("should succeed");
let result = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes);

assert_eq!(result.len(), 3);

Expand All @@ -324,8 +323,7 @@ mod tests {
let (partial_secret, _) = setup_test_data();
let empty_outputs: Vec<SilentPaymentCode> = vec![];

let result = create_silentpayment_scriptpubkeys(partial_secret, &empty_outputs)
.expect("should succeed with empty outputs");
let result = create_silentpayment_scriptpubkeys(partial_secret, &empty_outputs);

assert!(result.is_empty());
}
Expand All @@ -336,8 +334,7 @@ mod tests {

assert_eq!(sp_codes[0].scan, sp_codes[2].scan);

let result =
create_silentpayment_scriptpubkeys(partial_secret, &sp_codes).expect("should succeed");
let result = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes);

// Get the pubkeys for codes with the same scan key
let pubkeys_1 = &result[&sp_codes[0]];
Expand All @@ -353,10 +350,8 @@ mod tests {
let (partial_secret, sp_codes) = setup_test_data();

// Generate sp_codes twice with the same inputs
let result_1 =
create_silentpayment_scriptpubkeys(partial_secret, &sp_codes).expect("should succeed");
let result_2 =
create_silentpayment_scriptpubkeys(partial_secret, &sp_codes).expect("should succeed");
let result_1 = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes);
let result_2 = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes);

// Results should be identical
assert_eq!(result_1.len(), result_2.len());
Expand All @@ -373,8 +368,7 @@ mod tests {
// Add a duplicate of the first code
sp_codes.push(sp_codes[0].clone());

let result = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes)
.expect("should succeed with duplicates");
let result = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes);

// Should still have only 3 unique entries
assert_eq!(result.len(), 3);
Expand Down Expand Up @@ -403,8 +397,7 @@ mod tests {
sp_codes.push(code);
}

let result = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes)
.expect("should succeed with many sp_codes");
let result = create_silentpayment_scriptpubkeys(partial_secret, &sp_codes);

// Should have generated the correct number of sp_codes
assert_eq!(result.len(), 100);
Expand All @@ -421,10 +414,8 @@ mod tests {
let partial_secret_2 =
SecretKey::from_str(PARTIAL_SECRET_2).expect("creating from constant");

let result_1 = create_silentpayment_scriptpubkeys(partial_secret_1, &sp_codes)
.expect("should succeed");
let result_2 = create_silentpayment_scriptpubkeys(partial_secret_2, &sp_codes)
.expect("should succeed");
let result_1 = create_silentpayment_scriptpubkeys(partial_secret_1, &sp_codes);
let result_2 = create_silentpayment_scriptpubkeys(partial_secret_2, &sp_codes);

// Results should be different with different partial secrets
for sp_code in &sp_codes {
Expand Down
128 changes: 0 additions & 128 deletions silentpayments/src/send/psbt.rs

This file was deleted.

Loading
Loading