[][src]Enum hdwallet::extended_key::key_index::KeyIndex

pub enum KeyIndex {
    Normal(u32),
    Hardened(u32),
}

KeyIndex indicates the key type and index of a child key.

Variants

Normal(u32)

Normal key, index range is from 0 to 2 ** 31 - 1

Hardened(u32)

Hardened key, index range is from 2 ** 31 to 2 ** 32 - 1

Methods

impl KeyIndex[src]

pub fn raw_index(self) -> u32[src]

Return raw index value

pub fn normalize_index(self) -> u32[src]

Return normalize index, it will return index subtract 2 ** 31 for hardended key.

Examples

use hdwallet::KeyIndex;

assert_eq!(KeyIndex::Normal(0).normalize_index(), 0);
assert_eq!(KeyIndex::Hardened(2_147_483_648).normalize_index(), 0);

pub fn is_valid(self) -> bool[src]

Check index range.

Examples

use hdwallet::KeyIndex;

assert!(KeyIndex::Normal(0).is_valid());
assert!(!KeyIndex::Normal(2_147_483_648).is_valid());
assert!(KeyIndex::Hardened(2_147_483_648).is_valid());

pub fn hardened_from_normalize_index(i: u32) -> Result<KeyIndex, Error>[src]

Generate Hardened KeyIndex from normalize index value.

Examples

use hdwallet::KeyIndex;

// hardended key from zero
let hardened_index_zero = KeyIndex::hardened_from_normalize_index(0).unwrap();
assert_eq!(hardened_index_zero, KeyIndex::Hardened(2_147_483_648));
// also allow raw index for convernient
let hardened_index_zero = KeyIndex::hardened_from_normalize_index(2_147_483_648).unwrap();
assert_eq!(hardened_index_zero, KeyIndex::Hardened(2_147_483_648));

pub fn from_index(i: u32) -> Result<Self, Error>[src]

Generate KeyIndex from raw index value.

Examples

use hdwallet::KeyIndex;

let normal_key = KeyIndex::from_index(0).unwrap();
assert_eq!(normal_key, KeyIndex::Normal(0));
let hardened_key = KeyIndex::from_index(2_147_483_648).unwrap();
assert_eq!(hardened_key, KeyIndex::Hardened(2_147_483_648));

Trait Implementations

impl Copy for KeyIndex[src]

impl PartialEq<KeyIndex> for KeyIndex[src]

impl From<u32> for KeyIndex[src]

impl Clone for KeyIndex[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for KeyIndex[src]

impl Debug for KeyIndex[src]

Auto Trait Implementations

impl Send for KeyIndex

impl Sync for KeyIndex

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]