[−][src]Struct keyphrase::KeyPhrase
Human readable backup phrases which contain most of the information needed to recreate your EARTH addresses.
To create a new KeyPhrase
from a randomly generated key, call KeyPhrase::new()
.
To get a KeyPhrase
instance for an existing keyphrase, including
those generated by other software or hardware wallets, use KeyPhrase::from_phrase()
.
You can get the HD wallet Seed
from a KeyPhrase
by calling Seed::new()
.
From there you can either get the raw byte value with Seed::as_bytes()
, or the hex
representation using Rust formatting: format!("{:X}", seed)
.
You can also get the original entropy value back from a KeyPhrase
with KeyPhrase::entropy()
,
but beware that the entropy value is not the same thing as an HD wallet seed, and should
never be used that way.
Methods
impl KeyPhrase
[src]
pub fn new(keyphrase_type: KeyPhraseType, lang: Language) -> KeyPhrase
[src]
Generates a new KeyPhrase
Use KeyPhrase::phrase()
to get an str
slice of the generated phrase.
Example
use keyphrase::{KeyPhrase, KeyPhraseType, Language}; let keyphrase = KeyPhrase::new(KeyPhraseType::Words12, Language::English); let phrase = keyphrase.phrase(); println!("phrase: {}", phrase); assert_eq!(phrase.split(" ").count(), 12);
pub fn from_entropy(entropy: &[u8], lang: Language) -> Result<KeyPhrase, Error>
[src]
Create a KeyPhrase
from pre-generated entropy
Example
use keyphrase::{KeyPhrase, KeyPhraseType, Language}; let entropy = &[0x33, 0xE4, 0x6B, 0xB1, 0x3A, 0x74, 0x6E, 0xA4, 0x1C, 0xDD, 0xE4, 0x5C, 0x90, 0x84, 0x6A, 0x79]; let keyphrase = KeyPhrase::from_entropy(entropy, Language::English).unwrap(); assert_eq!("crop cash unable insane eight faith inflict route frame loud box vibrant", keyphrase.phrase()); assert_eq!("33E46BB13A746EA41CDDE45C90846A79", format!("{:X}", keyphrase));
pub fn from_phrase<S>(phrase: S, lang: Language) -> Result<KeyPhrase, Error> where
S: Into<String>,
[src]
S: Into<String>,
Create a KeyPhrase
from an existing keyphrase
The phrase supplied will be checked for word length and validated according to the checksum specified in the KeyPhrase Spec
Example
use keyphrase::{KeyPhrase, Language}; let phrase = "park remain person kitchen mule spell knee armed position rail grid ankle"; let keyphrase = KeyPhrase::from_phrase(phrase, Language::English).unwrap(); assert_eq!(phrase, keyphrase.phrase());
pub fn validate(phrase: &str, lang: Language) -> Result<(), Error>
[src]
Validate a keyphrase
The phrase supplied will be checked for word length and validated according to the checksum specified in the KeyPhrase Spec.
Example
use keyphrase::{KeyPhrase, Language}; let test_keyphrase = "park remain person kitchen mule spell knee armed position rail grid ankle"; assert!(KeyPhrase::validate(test_keyphrase, Language::English).is_ok());
pub fn phrase(&self) -> &str
[src]
Get the keyphrase as a string reference.
Example
use keyphrase::{KeyPhrase, KeyPhraseType, Language}; let keyphrase = KeyPhrase::new(KeyPhraseType::Words12, Language::English); let phrase = keyphrase.phrase();
pub fn into_phrase(self) -> String
[src]
Consume the KeyPhrase
and return the phrase as a String
.
This operation doesn't perform any allocations.
Example
use keyphrase::{KeyPhrase, KeyPhraseType, Language}; let keyphrase = KeyPhrase::new(KeyPhraseType::Words12, Language::English); let phrase = keyphrase.into_phrase();
pub fn entropy(&self) -> &[u8]
[src]
Get the original entropy value of the keyphrase as a slice.
Example
use keyphrase::{KeyPhrase, Language}; let phrase = "park remain person kitchen mule spell knee armed position rail grid ankle"; let keyphrase = KeyPhrase::from_phrase(phrase, Language::English).unwrap(); let entropy: &[u8] = keyphrase.entropy();
Note: You shouldn't use the generated entropy as secrets, for that generate a new
Seed
from the KeyPhrase
.
pub fn language(&self) -> Language
[src]
Get the Language
Trait Implementations
impl AsRef<str> for KeyPhrase
[src]
impl From<KeyPhrase> for String
[src]
impl Clone for KeyPhrase
[src]
impl Debug for KeyPhrase
[src]
impl Display for KeyPhrase
[src]
impl LowerHex for KeyPhrase
[src]
impl UpperHex for KeyPhrase
[src]
Auto Trait Implementations
impl Send for KeyPhrase
impl Sync for KeyPhrase
impl Unpin for KeyPhrase
impl UnwindSafe for KeyPhrase
impl RefUnwindSafe for KeyPhrase
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self