Struct hdwallet::extended_key::ExtendedPubKey
source · pub struct ExtendedPubKey {
pub public_key: PublicKey,
pub chain_code: Vec<u8>,
}
Expand description
ExtendedPubKey is used for public child key derivation. See secp256k1 crate documentation for PublicKey signatures usage.
Examples
use hdwallet::{ExtendedPrivKey, ExtendedPubKey, KeyIndex};
use rand;
let mut rng = rand::thread_rng();
let priv_key = ExtendedPrivKey::random(&mut rng).unwrap();
let pub_key = ExtendedPubKey::from_private_key(&priv_key);
// Public hardened child key derivation from parent public key is impossible
let hardened_key_index = KeyIndex::hardened_from_normalize_index(0).unwrap();
assert!(pub_key.derive_public_key(hardened_key_index).is_err());
// Derive public normal child key
let normal_key_index = KeyIndex::Normal(0);
assert!(pub_key.derive_public_key(normal_key_index).is_ok());
Fields§
§public_key: PublicKey
§chain_code: Vec<u8>
Implementations§
source§impl ExtendedPubKey
impl ExtendedPubKey
sourcepub fn derive_public_key(
&self,
key_index: KeyIndex
) -> Result<ExtendedPubKey, Error>
pub fn derive_public_key( &self, key_index: KeyIndex ) -> Result<ExtendedPubKey, Error>
Derive public normal child key from ExtendedPubKey, will return error if key_index is a hardened key.
sourcepub fn from_private_key(extended_key: &ExtendedPrivKey) -> Self
pub fn from_private_key(extended_key: &ExtendedPrivKey) -> Self
ExtendedPubKey from ExtendedPrivKey
Trait Implementations§
source§impl Clone for ExtendedPubKey
impl Clone for ExtendedPubKey
source§fn clone(&self) -> ExtendedPubKey
fn clone(&self) -> ExtendedPubKey
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for ExtendedPubKey
impl Debug for ExtendedPubKey
source§impl Deserialize<&[u8], Error> for ExtendedPubKey
impl Deserialize<&[u8], Error> for ExtendedPubKey
source§impl PartialEq<ExtendedPubKey> for ExtendedPubKey
impl PartialEq<ExtendedPubKey> for ExtendedPubKey
source§fn eq(&self, other: &ExtendedPubKey) -> bool
fn eq(&self, other: &ExtendedPubKey) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.