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 string is a possibly 0x prefixed 64-digit hex string, then it will be interpreted directly as a MiniSecretKey (aka “seed” in subkey).
  • If string is 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.
  • If string begins with a / character it is prefixed with the Substrate public DEV_PHRASE and 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: SecretString

The 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

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert 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. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Get a reference to the inner from the outer.

Get a mutable reference to the inner from the outer.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The counterpart to unchecked_from.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more