Implement TryFrom<&[u8] for ExternalPubKey.

This commit is contained in:
therealyingtong 2022-01-21 12:25:28 +08:00 committed by Kris Nuttycombe
parent 6f776aacc3
commit a7ea5f0bc1
1 changed files with 10 additions and 1 deletions

View File

@ -1,5 +1,5 @@
use crate::{legacy::TransparentAddress, sapling::keys::prf_expand_vec};
use hdwallet::{ExtendedPrivKey, ExtendedPubKey};
use hdwallet::{traits::Deserialize, ExtendedPrivKey, ExtendedPubKey};
use sha2::{Digest, Sha256};
use std::convert::TryInto;
@ -31,6 +31,15 @@ pub fn pubkey_to_address(pubkey: &secp256k1::key::PublicKey) -> TransparentAddre
#[derive(Clone, Debug)]
pub struct ExternalPubKey(pub ExtendedPubKey);
impl std::convert::TryFrom<&[u8]> for ExternalPubKey {
type Error = hdwallet::error::Error;
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
let ext_pub_key = ExtendedPubKey::deserialize(data)?;
Ok(Self(ext_pub_key))
}
}
impl ExternalPubKey {
/// Returns the transparent address corresponding to
/// this public key.