@@ -48,11 +48,11 @@ fn sigrec_decode(sig_rec: Vec<u8>) -> Result<RecoverableSignature, Error> {
48
48
/// Creates a digital signature of a message given a SecretKey, like the node's secret.
49
49
/// 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.
50
50
/// 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 > {
52
52
let secp_ctx = Secp256k1 :: signing_only ( ) ;
53
53
let msg_hash = sha256d:: Hash :: hash ( & [ LN_MESSAGE_PREFIX , msg] . concat ( ) ) ;
54
54
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) ;
56
56
Ok ( zbase32:: encode ( & sigrec_encode ( sig) ) )
57
57
}
58
58
@@ -74,9 +74,9 @@ pub fn recover_pk(msg: &[u8], sig: &str) -> Result<PublicKey, Error> {
74
74
75
75
/// Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature,
76
76
/// 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 {
78
78
match recover_pk ( msg, sig) {
79
- Ok ( x) => x == pk,
79
+ Ok ( x) => x == * pk,
80
80
Err ( _) => false
81
81
}
82
82
}
@@ -91,7 +91,7 @@ mod test {
91
91
#[ test]
92
92
fn test_sign ( ) {
93
93
let message = "test message" ;
94
- let zbase32_sig = sign ( message. as_bytes ( ) , ONE_KEY ) ;
94
+ let zbase32_sig = sign ( message. as_bytes ( ) , & ONE_KEY ) ;
95
95
96
96
assert_eq ! ( zbase32_sig. unwrap( ) , "d9tibmnic9t5y41hg7hkakdcra94akas9ku3rmmj4ag9mritc8ok4p5qzefs78c9pqfhpuftqqzhydbdwfg7u6w6wdxcqpqn4sj4e73e" )
97
97
}
@@ -108,10 +108,10 @@ mod test {
108
108
#[ test]
109
109
fn test_verify ( ) {
110
110
let message = "another message" ;
111
- let sig = sign ( message. as_bytes ( ) , ONE_KEY ) . unwrap ( ) ;
111
+ let sig = sign ( message. as_bytes ( ) , & ONE_KEY ) . unwrap ( ) ;
112
112
let pk = PublicKey :: from_secret_key ( & Secp256k1 :: signing_only ( ) , & ONE_KEY ) ;
113
113
114
- assert ! ( verify( message. as_bytes( ) , & sig, pk) )
114
+ assert ! ( verify( message. as_bytes( ) , & sig, & pk) )
115
115
}
116
116
117
117
#[ test]
@@ -135,7 +135,7 @@ mod test {
135
135
] ;
136
136
137
137
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( ) ) )
139
139
}
140
140
}
141
141
}
0 commit comments