Skip to content

Commit

Permalink
Don't return a Result
Browse files Browse the repository at this point in the history
  • Loading branch information
Sosthene00 authored and cygnet3 committed Jun 3, 2024
1 parent dc365d5 commit 28d30bd
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/find_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let pubkeys_ref: Vec<&PublicKey> = input_pubkeys.iter().collect();
let tweak_data = calculate_tweak_data(&pubkeys_ref, &outpoints)?;
let ecdh_shared_secret = calculate_ecdh_shared_secret(&tweak_data, &scan_privkey)?;
let ecdh_shared_secret = calculate_ecdh_shared_secret(&tweak_data, &scan_privkey);

let pubkeys_to_check: Vec<_> = tx
.output
Expand Down
2 changes: 1 addition & 1 deletion src/sending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub fn generate_recipient_pubkeys(
if let Some((_, payments)) = silent_payment_groups.get_mut(&B_scan) {
payments.push(address);
} else {
let ecdh_shared_secret = calculate_ecdh_shared_secret(&B_scan, &partial_secret)?;
let ecdh_shared_secret = calculate_ecdh_shared_secret(&B_scan, &partial_secret);

silent_payment_groups.insert(B_scan, (ecdh_shared_secret, vec![address]));
}
Expand Down
7 changes: 2 additions & 5 deletions src/utils/receiving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ pub fn calculate_tweak_data(
/// This function will error if:
///
/// * Elliptic curve computation results in an invalid public key.
pub fn calculate_ecdh_shared_secret(
tweak_data: &PublicKey,
b_scan: &SecretKey,
) -> Result<PublicKey> {
pub fn calculate_ecdh_shared_secret(tweak_data: &PublicKey, b_scan: &SecretKey) -> PublicKey {
let mut ss_bytes = [0u8; 65];
ss_bytes[0] = 0x04;

// Using `shared_secret_point` to ensure the multiplication is constant time
ss_bytes[1..].copy_from_slice(&shared_secret_point(&tweak_data, &b_scan));

Ok(PublicKey::from_slice(&ss_bytes)?)
PublicKey::from_slice(&ss_bytes).expect("guaranteed to be a point on the curve")
}

/// Get the public keys from a set of input data.
Expand Down
7 changes: 2 additions & 5 deletions src/utils/sending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,14 @@ pub fn calculate_partial_secret(
/// This function will error if:
///
/// * Elliptic curve computation results in an invalid public key.
pub fn calculate_ecdh_shared_secret(
B_scan: &PublicKey,
partial_secret: &SecretKey,
) -> Result<PublicKey> {
pub fn calculate_ecdh_shared_secret(B_scan: &PublicKey, partial_secret: &SecretKey) -> PublicKey {
let mut ss_bytes = [0u8; 65];
ss_bytes[0] = 0x04;

// Using `shared_secret_point` to ensure the multiplication is constant time
ss_bytes[1..].copy_from_slice(&shared_secret_point(B_scan, partial_secret));

Ok(PublicKey::from_slice(&ss_bytes)?)
PublicKey::from_slice(&ss_bytes).expect("guaranteed to be a point on the curve")
}

fn get_a_sum_secret_keys(input: &[(SecretKey, bool)]) -> Result<SecretKey> {
Expand Down
2 changes: 1 addition & 1 deletion tests/vector_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
assert_eq!(set1, set2);

let tweak_data = calculate_tweak_data(&input_pub_keys, &outpoints).unwrap();
let ecdh_shared_secret = calculate_ecdh_shared_secret(&tweak_data, &b_scan).unwrap();
let ecdh_shared_secret = calculate_ecdh_shared_secret(&tweak_data, &b_scan);

let scanned_outputs_received = sp_receiver
.scan_transaction(&ecdh_shared_secret, outputs_to_check)
Expand Down

0 comments on commit 28d30bd

Please sign in to comment.