Enum hdwallet::extended_key::key_index::KeyIndex
source · pub enum KeyIndex {
Normal(u32),
Hardened(u32),
}
Expand description
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
Implementations§
source§impl KeyIndex
impl KeyIndex
sourcepub fn normalize_index(self) -> u32
pub fn normalize_index(self) -> u32
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);
sourcepub fn is_valid(self) -> bool
pub fn is_valid(self) -> bool
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());
sourcepub fn hardened_from_normalize_index(i: u32) -> Result<KeyIndex, Error>
pub fn hardened_from_normalize_index(i: u32) -> Result<KeyIndex, Error>
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));
sourcepub fn from_index(i: u32) -> Result<Self, Error>
pub fn from_index(i: u32) -> Result<Self, Error>
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));