Skip to content

Commit ab6e1d8

Browse files
committed
Re-name as_public -> to_public
According to Rust naming convention this method should use the `to_` prefix because it converts from a borrowed->owned (non-`Copy`) type. Re-name the conversion methods for converting from various private/secret keys to the associated public keys to `to_public`.
1 parent 5c1614a commit ab6e1d8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/descriptor/key.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub enum Wildcard {
138138

139139
impl SinglePriv {
140140
/// Returns the public key of this key
141-
fn as_public<C: Signing>(
141+
fn to_public<C: Signing>(
142142
&self,
143143
secp: &Secp256k1<C>,
144144
) -> Result<SinglePub, DescriptorKeyParseError> {
@@ -158,7 +158,7 @@ impl DescriptorXKey<bip32::ExtendedPrivKey> {
158158
/// If the key already has an origin, the derivation steps applied will be appended to the path
159159
/// already present, otherwise this key will be treated as a master key and an origin will be
160160
/// added with this key's fingerprint and the derivation steps applied.
161-
fn as_public<C: Signing>(
161+
fn to_public<C: Signing>(
162162
&self,
163163
secp: &Secp256k1<C>,
164164
) -> Result<DescriptorXKey<bip32::ExtendedPubKey>, DescriptorKeyParseError> {
@@ -243,22 +243,22 @@ impl fmt::Display for DescriptorPublicKey {
243243

244244
impl DescriptorSecretKey {
245245
/// Return the public version of this key, by applying either
246-
/// [`SinglePriv::as_public`] or [`DescriptorXKey<bip32::ExtendedPrivKey>::as_public`]
246+
/// [`SinglePriv::to_public`] or [`DescriptorXKey<bip32::ExtendedPrivKey>::to_public`]
247247
/// depending on the type of key.
248248
///
249249
/// If the key is an "XPrv", the hardened derivation steps will be applied before converting it
250-
/// to a public key. See the documentation of [`DescriptorXKey<bip32::ExtendedPrivKey>::as_public`]
250+
/// to a public key. See the documentation of [`DescriptorXKey<bip32::ExtendedPrivKey>::to_public`]
251251
/// for more details.
252-
pub fn as_public<C: Signing>(
252+
pub fn to_public<C: Signing>(
253253
&self,
254254
secp: &Secp256k1<C>,
255255
) -> Result<DescriptorPublicKey, DescriptorKeyParseError> {
256256
Ok(match self {
257257
&DescriptorSecretKey::Single(ref sk) => {
258-
DescriptorPublicKey::Single(sk.as_public(secp)?)
258+
DescriptorPublicKey::Single(sk.to_public(secp)?)
259259
}
260260
&DescriptorSecretKey::XPrv(ref xprv) => {
261-
DescriptorPublicKey::XPub(xprv.as_public(secp)?)
261+
DescriptorPublicKey::XPub(xprv.to_public(secp)?)
262262
}
263263
})
264264
}
@@ -475,7 +475,7 @@ impl DescriptorPublicKey {
475475
///
476476
/// To ensure there are no wildcards, call `.derive(0)` or similar;
477477
/// to avoid hardened derivation steps, start from a `DescriptorSecretKey`
478-
/// and call `as_public`, or call `TranslatePk2::translate_pk2` with
478+
/// and call `to_public`, or call `TranslatePk2::translate_pk2` with
479479
/// some function which has access to secret key data.
480480
pub fn derive_public_key<C: secp256k1::Verification>(
481481
&self,
@@ -846,32 +846,32 @@ mod test {
846846
let secp = secp256k1::Secp256k1::signing_only();
847847

848848
let secret_key = DescriptorSecretKey::from_str("tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0'/1'/2").unwrap();
849-
let public_key = secret_key.as_public(&secp).unwrap();
849+
let public_key = secret_key.to_public(&secp).unwrap();
850850
assert_eq!(public_key.to_string(), "[2cbe2a6d/0'/1']tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/2");
851851
assert_eq!(public_key.master_fingerprint().to_string(), "2cbe2a6d");
852852
assert_eq!(public_key.full_derivation_path().to_string(), "m/0'/1'/2");
853853
assert_eq!(public_key.is_deriveable(), false);
854854

855855
let secret_key = DescriptorSecretKey::from_str("tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0'/1'/2'").unwrap();
856-
let public_key = secret_key.as_public(&secp).unwrap();
856+
let public_key = secret_key.to_public(&secp).unwrap();
857857
assert_eq!(public_key.to_string(), "[2cbe2a6d/0'/1'/2']tpubDDPuH46rv4dbFtmF6FrEtJEy1CvLZonyBoVxF6xsesHdYDdTBrq2mHhm8AbsPh39sUwL2nZyxd6vo4uWNTU9v4t893CwxjqPnwMoUACLvMV");
858858
assert_eq!(public_key.master_fingerprint().to_string(), "2cbe2a6d");
859859
assert_eq!(public_key.full_derivation_path().to_string(), "m/0'/1'/2'");
860860

861861
let secret_key = DescriptorSecretKey::from_str("tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0/1/2").unwrap();
862-
let public_key = secret_key.as_public(&secp).unwrap();
862+
let public_key = secret_key.to_public(&secp).unwrap();
863863
assert_eq!(public_key.to_string(), "tpubD6NzVbkrYhZ4WQdzxL7NmJN7b85ePo4p6RSj9QQHF7te2RR9iUeVSGgnGkoUsB9LBRosgvNbjRv9bcsJgzgBd7QKuxDm23ZewkTRzNSLEDr/0/1/2");
864864
assert_eq!(public_key.master_fingerprint().to_string(), "2cbe2a6d");
865865
assert_eq!(public_key.full_derivation_path().to_string(), "m/0/1/2");
866866

867867
let secret_key = DescriptorSecretKey::from_str("[aabbccdd]tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0/1/2").unwrap();
868-
let public_key = secret_key.as_public(&secp).unwrap();
868+
let public_key = secret_key.to_public(&secp).unwrap();
869869
assert_eq!(public_key.to_string(), "[aabbccdd]tpubD6NzVbkrYhZ4WQdzxL7NmJN7b85ePo4p6RSj9QQHF7te2RR9iUeVSGgnGkoUsB9LBRosgvNbjRv9bcsJgzgBd7QKuxDm23ZewkTRzNSLEDr/0/1/2");
870870
assert_eq!(public_key.master_fingerprint().to_string(), "aabbccdd");
871871
assert_eq!(public_key.full_derivation_path().to_string(), "m/0/1/2");
872872

873873
let secret_key = DescriptorSecretKey::from_str("[aabbccdd/90']tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0'/1'/2").unwrap();
874-
let public_key = secret_key.as_public(&secp).unwrap();
874+
let public_key = secret_key.to_public(&secp).unwrap();
875875
assert_eq!(public_key.to_string(), "[aabbccdd/90'/0'/1']tpubDBrgjcxBxnXyL575sHdkpKohWu5qHKoQ7TJXKNrYznh5fVEGBv89hA8ENW7A8MFVpFUSvgLqc4Nj1WZcpePX6rrxviVtPowvMuGF5rdT2Vi/2");
876876
assert_eq!(public_key.master_fingerprint().to_string(), "aabbccdd");
877877
assert_eq!(

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ impl Descriptor<DescriptorPublicKey> {
722722
key_map: &mut KeyMap|
723723
-> Result<DescriptorPublicKey, DescriptorKeyParseError> {
724724
let (public_key, secret_key) = match DescriptorSecretKey::from_str(s) {
725-
Ok(sk) => (sk.as_public(&secp)?, Some(sk)),
725+
Ok(sk) => (sk.to_public(&secp)?, Some(sk)),
726726
Err(_) => (DescriptorPublicKey::from_str(s)?, None),
727727
};
728728

0 commit comments

Comments
 (0)