Skip to content

Commit 0844e57

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 b649842 commit 0844e57

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
@@ -139,7 +139,7 @@ pub struct DescriptorXKey<K: InnerXKey> {
139139

140140
impl DescriptorSinglePriv {
141141
/// Returns the public key of this key
142-
fn as_public<C: Signing>(
142+
fn to_public<C: Signing>(
143143
&self,
144144
secp: &Secp256k1<C>,
145145
) -> Result<DescriptorSinglePub, DescriptorKeyParseError> {
@@ -159,7 +159,7 @@ impl DescriptorXKey<bip32::ExtendedPrivKey> {
159159
/// If the key already has an origin, the derivation steps applied will be appended to the path
160160
/// already present, otherwise this key will be treated as a master key and an origin will be
161161
/// added with this key's fingerprint and the derivation steps applied.
162-
fn as_public<C: Signing>(
162+
fn to_public<C: Signing>(
163163
&self,
164164
secp: &Secp256k1<C>,
165165
) -> Result<DescriptorXKey<bip32::ExtendedPubKey>, DescriptorKeyParseError> {
@@ -244,22 +244,22 @@ impl fmt::Display for DescriptorPublicKey {
244244

245245
impl DescriptorSecretKey {
246246
/// Return the public version of this key, by applying either
247-
/// [`DescriptorSinglePriv::as_public`] or [`DescriptorXKey<bip32::ExtendedPrivKey>::as_public`]
247+
/// [`DescriptorSinglePriv::to_public`] or [`DescriptorXKey<bip32::ExtendedPrivKey>::to_public`]
248248
/// depending on the type of key.
249249
///
250250
/// If the key is an "XPrv", the hardened derivation steps will be applied before converting it
251-
/// to a public key. See the documentation of [`DescriptorXKey<bip32::ExtendedPrivKey>::as_public`]
251+
/// to a public key. See the documentation of [`DescriptorXKey<bip32::ExtendedPrivKey>::to_public`]
252252
/// for more details.
253-
pub fn as_public<C: Signing>(
253+
pub fn to_public<C: Signing>(
254254
&self,
255255
secp: &Secp256k1<C>,
256256
) -> Result<DescriptorPublicKey, DescriptorKeyParseError> {
257257
Ok(match self {
258258
&DescriptorSecretKey::SinglePriv(ref sk) => {
259-
DescriptorPublicKey::SinglePub(sk.as_public(secp)?)
259+
DescriptorPublicKey::SinglePub(sk.to_public(secp)?)
260260
}
261261
&DescriptorSecretKey::XPrv(ref xprv) => {
262-
DescriptorPublicKey::XPub(xprv.as_public(secp)?)
262+
DescriptorPublicKey::XPub(xprv.to_public(secp)?)
263263
}
264264
})
265265
}
@@ -479,7 +479,7 @@ impl DescriptorPublicKey {
479479
///
480480
/// To ensure there are no wildcards, call `.derive(0)` or similar;
481481
/// to avoid hardened derivation steps, start from a `DescriptorSecretKey`
482-
/// and call `as_public`, or call `TranslatePk2::translate_pk2` with
482+
/// and call `to_public`, or call `TranslatePk2::translate_pk2` with
483483
/// some function which has access to secret key data.
484484
pub fn derive_public_key<C: secp256k1::Verification>(
485485
&self,
@@ -850,32 +850,32 @@ mod test {
850850
let secp = secp256k1::Secp256k1::signing_only();
851851

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

859859
let secret_key = DescriptorSecretKey::from_str("tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0'/1'/2'").unwrap();
860-
let public_key = secret_key.as_public(&secp).unwrap();
860+
let public_key = secret_key.to_public(&secp).unwrap();
861861
assert_eq!(public_key.to_string(), "[2cbe2a6d/0'/1'/2']tpubDDPuH46rv4dbFtmF6FrEtJEy1CvLZonyBoVxF6xsesHdYDdTBrq2mHhm8AbsPh39sUwL2nZyxd6vo4uWNTU9v4t893CwxjqPnwMoUACLvMV");
862862
assert_eq!(public_key.master_fingerprint().to_string(), "2cbe2a6d");
863863
assert_eq!(public_key.full_derivation_path().to_string(), "m/0'/1'/2'");
864864

865865
let secret_key = DescriptorSecretKey::from_str("tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0/1/2").unwrap();
866-
let public_key = secret_key.as_public(&secp).unwrap();
866+
let public_key = secret_key.to_public(&secp).unwrap();
867867
assert_eq!(public_key.to_string(), "tpubD6NzVbkrYhZ4WQdzxL7NmJN7b85ePo4p6RSj9QQHF7te2RR9iUeVSGgnGkoUsB9LBRosgvNbjRv9bcsJgzgBd7QKuxDm23ZewkTRzNSLEDr/0/1/2");
868868
assert_eq!(public_key.master_fingerprint().to_string(), "2cbe2a6d");
869869
assert_eq!(public_key.full_derivation_path().to_string(), "m/0/1/2");
870870

871871
let secret_key = DescriptorSecretKey::from_str("[aabbccdd]tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/0/1/2").unwrap();
872-
let public_key = secret_key.as_public(&secp).unwrap();
872+
let public_key = secret_key.to_public(&secp).unwrap();
873873
assert_eq!(public_key.to_string(), "[aabbccdd]tpubD6NzVbkrYhZ4WQdzxL7NmJN7b85ePo4p6RSj9QQHF7te2RR9iUeVSGgnGkoUsB9LBRosgvNbjRv9bcsJgzgBd7QKuxDm23ZewkTRzNSLEDr/0/1/2");
874874
assert_eq!(public_key.master_fingerprint().to_string(), "aabbccdd");
875875
assert_eq!(public_key.full_derivation_path().to_string(), "m/0/1/2");
876876

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

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl Descriptor<DescriptorPublicKey> {
704704
key_map: &mut KeyMap|
705705
-> Result<DescriptorPublicKey, DescriptorKeyParseError> {
706706
let (public_key, secret_key) = match DescriptorSecretKey::from_str(s) {
707-
Ok(sk) => (sk.as_public(&secp)?, Some(sk)),
707+
Ok(sk) => (sk.to_public(&secp)?, Some(sk)),
708708
Err(_) => (DescriptorPublicKey::from_str(s)?, None),
709709
};
710710

0 commit comments

Comments
 (0)