Skip to content

Commit 975c212

Browse files
fixup! Move Signature and SerializedSignature to new ecdsa module
1 parent c7c21be commit 975c212

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

examples/sign_verify_recovery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ fn recover<C: Verification>(secp: &Secp256k1<C>,msg: &[u8],sig: [u8; 64],recover
1111
let id = ecdsa::RecoveryId::from_i32(recovery_id as i32)?;
1212
let sig = ecdsa::RecoverableSignature::from_compact(&sig, id)?;
1313

14-
secp.recover(&msg, &sig)
14+
secp.recover_ecdsa(&msg, &sig)
1515
}
1616

1717
fn sign_recovery<C: Signing>(secp: &Secp256k1<C>, msg: &[u8], seckey: [u8; 32]) -> Result<ecdsa::RecoverableSignature, Error> {
1818
let msg = sha256::Hash::hash(msg);
1919
let msg = Message::from_slice(&msg)?;
2020
let seckey = SecretKey::from_slice(&seckey)?;
21-
Ok(secp.sign_recoverable(&msg, &seckey))
21+
Ok(secp.sign_ecdsa_recoverable(&msg, &seckey))
2222
}
2323

2424
fn main() {

no_std_test/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,22 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
106106
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
107107
let message = Message::from_slice(&[0xab; 32]).expect("32 bytes");
108108

109-
let sig = secp.sign(&message, &secret_key);
110-
assert!(secp.verify(&message, &sig, &public_key).is_ok());
109+
let sig = secp.sign_ecdsa(&message, &secret_key);
110+
assert!(secp.verify_ecdsa(&message, &sig, &public_key).is_ok());
111111

112-
let rec_sig = secp.sign_recoverable(&message, &secret_key);
113-
assert!(secp.verify(&message, &rec_sig.to_standard(), &public_key).is_ok());
114-
assert_eq!(public_key, secp.recover(&message, &rec_sig).unwrap());
112+
let rec_sig = secp.sign_ecdsa_recoverable(&message, &secret_key);
113+
assert!(secp.verify_ecdsa(&message, &rec_sig.to_standard(), &public_key).is_ok());
114+
assert_eq!(public_key, secp.recover_ecdsa(&message, &rec_sig).unwrap());
115115
let (rec_id, data) = rec_sig.serialize_compact();
116-
let new_rec_sig = recovery::RecoverableSignature::from_compact(&data, rec_id).unwrap();
116+
let new_rec_sig = ecdsa::RecoverableSignature::from_compact(&data, rec_id).unwrap();
117117
assert_eq!(rec_sig, new_rec_sig);
118118

119119
let mut cbor_ser = [0u8; 100];
120120
let writer = SliceWrite::new(&mut cbor_ser[..]);
121121
let mut ser = Serializer::new(writer);
122122
sig.serialize(&mut ser).unwrap();
123123
let size = ser.into_inner().bytes_written();
124-
let new_sig: Signature = de::from_mut_slice(&mut cbor_ser[..size]).unwrap();
124+
let new_sig: ecdsa::Signature = de::from_mut_slice(&mut cbor_ser[..size]).unwrap();
125125
assert_eq!(sig, new_sig);
126126

127127
let _ = SharedSecret::new(&public_key, &secret_key);

src/ecdsa/recovery.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,14 @@ impl From<ffi::RecoverableSignature> for RecoverableSignature {
146146
impl<C: Signing> Secp256k1<C> {
147147
/// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce
148148
/// Requires a signing-capable context.
149-
pub fn sign_recoverable(&self, msg: &Message, sk: &key::SecretKey)
150-
-> RecoverableSignature {
149+
#[deprecated(since = "0.21.0", note = "Use sign_ecdsa_recoverable instead.")]
150+
pub fn sign_recoverable(&self, msg: &Message, sk: &key::SecretKey) -> RecoverableSignature {
151+
self.sign_ecdsa_recoverable(msg, sk)
152+
}
151153

154+
/// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce
155+
/// Requires a signing-capable context.
156+
pub fn sign_ecdsa_recoverable(&self, msg: &Message, sk: &key::SecretKey) -> RecoverableSignature {
152157
let mut ret = ffi::RecoverableSignature::new();
153158
unsafe {
154159
// We can assume the return value because it's not possible to construct
@@ -173,7 +178,14 @@ impl<C: Signing> Secp256k1<C> {
173178
impl<C: Verification> Secp256k1<C> {
174179
/// Determines the public key for which `sig` is a valid signature for
175180
/// `msg`. Requires a verify-capable context.
176-
pub fn recover(&self, msg: &Message, sig: &RecoverableSignature)
181+
#[deprecated(since = "0.21.0", note = "Use recover_ecdsa instead.")]
182+
pub fn recover(&self, msg: &Message, sig: &RecoverableSignature) -> Result<key::PublicKey, Error> {
183+
self.recover_ecdsa(msg, sig)
184+
}
185+
186+
/// Determines the public key for which `sig` is a valid signature for
187+
/// `msg`. Requires a verify-capable context.
188+
pub fn recover_ecdsa(&self, msg: &Message, sig: &RecoverableSignature)
177189
-> Result<key::PublicKey, Error> {
178190

179191
unsafe {

0 commit comments

Comments
 (0)