Skip to content

Commit

Permalink
rustfmt: Run on util/message_signing.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Sep 19, 2024
1 parent bd28ad0 commit c1495ef
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lightning/src/util/message_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn sigrec_decode(sig_rec: Vec<u8>) -> Result<RecoverableSignature, Error> {

match RecoveryId::from_i32(rid) {
Ok(x) => RecoverableSignature::from_compact(rsig, x),
Err(e) => Err(e)
Err(e) => Err(e),
}
}

Expand All @@ -63,18 +63,18 @@ pub fn sign(msg: &[u8], sk: &SecretKey) -> String {
}

/// Recovers the PublicKey of the signer of the message given the message and the signature.
pub fn recover_pk(msg: &[u8], sig: &str) -> Result<PublicKey, Error> {
pub fn recover_pk(msg: &[u8], sig: &str) -> Result<PublicKey, Error> {
let secp_ctx = Secp256k1::verification_only();
let msg_hash = sha256d::Hash::hash(&[LN_MESSAGE_PREFIX, msg].concat());

match base32::Alphabet::ZBase32.decode(&sig) {
Ok(sig_rec) => {
match sigrec_decode(sig_rec) {
Ok(sig) => secp_ctx.recover_ecdsa(&Message::from_digest(msg_hash.to_byte_array()), &sig),
Err(e) => Err(e)
}
Ok(sig_rec) => match sigrec_decode(sig_rec) {
Ok(sig) => {
secp_ctx.recover_ecdsa(&Message::from_digest(msg_hash.to_byte_array()), &sig)
},
Err(e) => Err(e),
},
Err(_) => Err(Error::InvalidSignature)
Err(_) => Err(Error::InvalidSignature),
}
}

Expand All @@ -83,16 +83,16 @@ pub fn recover_pk(msg: &[u8], sig: &str) -> Result<PublicKey, Error> {
pub fn verify(msg: &[u8], sig: &str, pk: &PublicKey) -> bool {
match recover_pk(msg, sig) {
Ok(x) => x == *pk,
Err(_) => false
Err(_) => false,
}
}

#[cfg(test)]
mod test {
use core::str::FromStr;
use crate::util::message_signing::{sign, recover_pk, verify};
use crate::util::message_signing::{recover_pk, sign, verify};
use bitcoin::secp256k1::constants::ONE;
use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
use core::str::FromStr;

#[test]
fn test_sign() {
Expand Down Expand Up @@ -148,4 +148,3 @@ mod test {
}
}
}

0 comments on commit c1495ef

Please sign in to comment.