pub struct SecretUri {
pub phrase: SecretString,
pub password: Option<SecretString>,
pub junctions: Vec<DeriveJunction>,
}Expand description
A secret uri (SURI) that can be used to generate a key pair.
The SURI can be parsed from a string. The string is interpreted in the following way:
- If
stringis a possibly0xprefixed 64-digit hex string, then it will be interpreted directly as aMiniSecretKey(aka “seed” insubkey). - If
stringis a valid BIP-39 key phrase of 12, 15, 18, 21 or 24 words, then the key will be derived from it. In this case:- the phrase may be followed by one or more items delimited by
/characters. - the path may be followed by
///, in which case everything after the///is treated as a password.
- the phrase may be followed by one or more items delimited by
- If
stringbegins with a/character it is prefixed with the Substrate publicDEV_PHRASEand interpreted as above.
In this case they are interpreted as HDKD junctions; purely numeric items are interpreted as
integers, non-numeric items as strings. Junctions prefixed with / are interpreted as soft
junctions, and with // as hard junctions.
There is no correspondence mapping between SURI strings and the keys they represent.
Two different non-identical strings can actually lead to the same secret being derived.
Notably, integer junction indices may be legally prefixed with arbitrary number of zeros.
Similarly an empty password (ending the SURI with ///) is perfectly valid and will
generally be equivalent to no password at all.
Example
Parse DEV_PHRASE secret uri with junction:
let suri = SecretUri::from_str("//Alice").expect("Parse SURI");
assert_eq!(vec![DeriveJunction::from("Alice").harden()], suri.junctions);
assert_eq!(DEV_PHRASE, suri.phrase.expose_secret());
assert!(suri.password.is_none());Parse DEV_PHRASE secret ui with junction and password:
let suri = SecretUri::from_str("//Alice///SECRET_PASSWORD").expect("Parse SURI");
assert_eq!(vec![DeriveJunction::from("Alice").harden()], suri.junctions);
assert_eq!(DEV_PHRASE, suri.phrase.expose_secret());
assert_eq!("SECRET_PASSWORD", suri.password.unwrap().expose_secret());Parse DEV_PHRASE secret ui with hex phrase and junction:
let suri = SecretUri::from_str("0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a//Alice").expect("Parse SURI");
assert_eq!(vec![DeriveJunction::from("Alice").harden()], suri.junctions);
assert_eq!("0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", suri.phrase.expose_secret());
assert!(suri.password.is_none());Fields§
§phrase: SecretStringThe phrase to derive the private key.
This can either be a 64-bit hex string or a BIP-39 key phrase.
password: Option<SecretString>Optional password as given as part of the uri.
junctions: Vec<DeriveJunction>The junctions as part of the uri.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for SecretUri
impl Send for SecretUri
impl Sync for SecretUri
impl Unpin for SecretUri
impl UnwindSafe for SecretUri
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.