@@ -48,11 +48,11 @@ fn sigrec_decode(sig_rec: Vec<u8>) -> Result<RecoverableSignature, Error> {
4848/// Creates a digital signature of a message given a SecretKey, like the node's secret.
4949/// A receiver knowing the PublicKey (e.g. the node's id) and the message can be sure that the signature was generated by the caller.
5050/// Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.
51- pub fn sign ( msg : & [ u8 ] , sk : SecretKey ) -> Result < String , Error > {
51+ pub fn sign ( msg : & [ u8 ] , sk : & SecretKey ) -> Result < String , Error > {
5252 let secp_ctx = Secp256k1 :: signing_only ( ) ;
5353 let msg_hash = sha256d:: Hash :: hash ( & [ LN_MESSAGE_PREFIX , msg] . concat ( ) ) ;
5454
55- let sig = secp_ctx. sign_recoverable ( & Message :: from_slice ( & msg_hash) ?, & sk) ;
55+ let sig = secp_ctx. sign_recoverable ( & Message :: from_slice ( & msg_hash) ?, sk) ;
5656 Ok ( zbase32:: encode ( & sigrec_encode ( sig) ) )
5757}
5858
@@ -74,9 +74,9 @@ pub fn recover_pk(msg: &[u8], sig: &str) -> Result<PublicKey, Error> {
7474
7575/// Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature,
7676/// and the PublicKey.
77- pub fn verify ( msg : & [ u8 ] , sig : & str , pk : PublicKey ) -> bool {
77+ pub fn verify ( msg : & [ u8 ] , sig : & str , pk : & PublicKey ) -> bool {
7878 match recover_pk ( msg, sig) {
79- Ok ( x) => x == pk,
79+ Ok ( x) => x == * pk,
8080 Err ( _) => false
8181 }
8282}
@@ -91,7 +91,7 @@ mod test {
9191 #[ test]
9292 fn test_sign ( ) {
9393 let message = "test message" ;
94- let zbase32_sig = sign ( message. as_bytes ( ) , ONE_KEY ) ;
94+ let zbase32_sig = sign ( message. as_bytes ( ) , & ONE_KEY ) ;
9595
9696 assert_eq ! ( zbase32_sig. unwrap( ) , "d9tibmnic9t5y41hg7hkakdcra94akas9ku3rmmj4ag9mritc8ok4p5qzefs78c9pqfhpuftqqzhydbdwfg7u6w6wdxcqpqn4sj4e73e" )
9797 }
@@ -108,10 +108,10 @@ mod test {
108108 #[ test]
109109 fn test_verify ( ) {
110110 let message = "another message" ;
111- let sig = sign ( message. as_bytes ( ) , ONE_KEY ) . unwrap ( ) ;
111+ let sig = sign ( message. as_bytes ( ) , & ONE_KEY ) . unwrap ( ) ;
112112 let pk = PublicKey :: from_secret_key ( & Secp256k1 :: signing_only ( ) , & ONE_KEY ) ;
113113
114- assert ! ( verify( message. as_bytes( ) , & sig, pk) )
114+ assert ! ( verify( message. as_bytes( ) , & sig, & pk) )
115115 }
116116
117117 #[ test]
@@ -135,7 +135,7 @@ mod test {
135135 ] ;
136136
137137 for c in & corpus {
138- assert ! ( verify( c[ 1 ] . as_bytes( ) , c[ 2 ] , PublicKey :: from_str( c[ 3 ] ) . unwrap( ) ) )
138+ assert ! ( verify( c[ 1 ] . as_bytes( ) , c[ 2 ] , & PublicKey :: from_str( c[ 3 ] ) . unwrap( ) ) )
139139 }
140140 }
141141}
0 commit comments