Trait sp_core::crypto::Pair [−][src]
Trait suitable for typical cryptographic PKI key pair type.
For now it just specifies how to create a key from a phrase and derivation path.
Associated Types
type Public: Public + Hash
[src]
The type which is used to encode a public key.
type Seed: Default + AsRef<[u8]> + AsMut<[u8]> + Clone
[src]
The type used to (minimally) encode the data required to securely create a new key pair.
type Signature: AsRef<[u8]>
[src]
The type used to represent a signature. Can be created from a key pair and a message and verified with the message and a public key.
type DeriveError
[src]
Error returned from the derive
function.
Required methods
fn generate_with_phrase(password: Option<&str>) -> (Self, String, Self::Seed)
[src]
Generate new secure (random) key pair and provide the recovery phrase.
You can recover the same key later with from_phrase
.
This is generally slower than generate()
, so prefer that unless you need to persist
the key from the current session.
fn from_phrase(
phrase: &str,
password: Option<&str>
) -> Result<(Self, Self::Seed), SecretStringError>
[src]
phrase: &str,
password: Option<&str>
) -> Result<(Self, Self::Seed), SecretStringError>
Returns the KeyPair from the English BIP39 seed phrase
, or None
if it’s invalid.
fn derive<Iter: Iterator<Item = DeriveJunction>>(
&self,
path: Iter,
seed: Option<Self::Seed>
) -> Result<(Self, Option<Self::Seed>), Self::DeriveError>
[src]
&self,
path: Iter,
seed: Option<Self::Seed>
) -> Result<(Self, Option<Self::Seed>), Self::DeriveError>
Derive a child key from a series of given junctions.
fn from_seed(seed: &Self::Seed) -> Self
[src]
Generate new key pair from the provided seed
.
@WARNING: THIS WILL ONLY BE SECURE IF THE seed
IS SECURE. If it can be guessed
by an attacker then they can also derive your key.
fn from_seed_slice(seed: &[u8]) -> Result<Self, SecretStringError>
[src]
Make a new key pair from secret seed material. The slice must be the correct size or
it will return None
.
@WARNING: THIS WILL ONLY BE SECURE IF THE seed
IS SECURE. If it can be guessed
by an attacker then they can also derive your key.
fn sign(&self, message: &[u8]) -> Self::Signature
[src]
Sign a message.
fn verify<M: AsRef<[u8]>>(
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
[src]
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
Verify a signature on a message. Returns true if the signature is good.
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(
sig: &[u8],
message: M,
pubkey: P
) -> bool
[src]
sig: &[u8],
message: M,
pubkey: P
) -> bool
Verify a signature on a message. Returns true if the signature is good.
fn public(&self) -> Self::Public
[src]
Get the public key.
fn to_raw_vec(&self) -> Vec<u8>ⓘ
[src]
Return a vec filled with raw data.
Provided methods
fn generate() -> (Self, Self::Seed)
[src]
Generate new secure (random) key pair.
This is only for ephemeral keys really, since you won’t have access to the secret key
for storage. If you want a persistent key pair, use generate_with_phrase
instead.
fn from_string_with_seed(
s: &str,
password_override: Option<&str>
) -> Result<(Self, Option<Self::Seed>), SecretStringError>
[src]
s: &str,
password_override: Option<&str>
) -> Result<(Self, Option<Self::Seed>), SecretStringError>
Interprets the string s
in order to generate a key Pair. Returns both the pair and an optional seed, in the
case that the pair can be expressed as a direct derivation from a seed (some cases, such as Sr25519 derivations
with path components, cannot).
This takes a helper function to do the key generation from a phrase, password and junction iterator.
- If
s
is a possibly0x
prefixed 64-digit hex string, then it will be interpreted directly as aMiniSecretKey
(aka “seed” insubkey
). - If
s
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.
- the phrase may be followed by one or more items delimited by
- If
s
begins with a/
character it is prefixed with the Substrate publicDEV_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.
None
is returned if no matches are found.
fn from_string(
s: &str,
password_override: Option<&str>
) -> Result<Self, SecretStringError>
[src]
s: &str,
password_override: Option<&str>
) -> Result<Self, SecretStringError>
Interprets the string s
in order to generate a key pair.
See from_string_with_seed
for more extensive documentation.
Implementors
impl Pair for Dummy
[src]
type Public = Dummy
type Seed = Dummy
type Signature = Dummy
type DeriveError = ()
fn generate_with_phrase(_: Option<&str>) -> (Self, String, Self::Seed)
[src]
fn from_phrase(
_: &str,
_: Option<&str>
) -> Result<(Self, Self::Seed), SecretStringError>
[src]
_: &str,
_: Option<&str>
) -> Result<(Self, Self::Seed), SecretStringError>
fn derive<Iter: Iterator<Item = DeriveJunction>>(
&self,
_: Iter,
_: Option<Dummy>
) -> Result<(Self, Option<Dummy>), Self::DeriveError>
[src]
&self,
_: Iter,
_: Option<Dummy>
) -> Result<(Self, Option<Dummy>), Self::DeriveError>
fn from_seed(_: &Self::Seed) -> Self
[src]
fn from_seed_slice(_: &[u8]) -> Result<Self, SecretStringError>
[src]
fn sign(&self, _: &[u8]) -> Self::Signature
[src]
fn verify<M: AsRef<[u8]>>(_: &Self::Signature, _: M, _: &Self::Public) -> bool
[src]
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(_: &[u8], _: M, _: P) -> bool
[src]
fn public(&self) -> Self::Public
[src]
fn to_raw_vec(&self) -> Vec<u8>ⓘ
[src]
impl Pair for sp_core::ecdsa::Pair
[src]
type Public = Public
type Seed = [u8; 32]
type Signature = Signature
type DeriveError = DeriveError
fn generate_with_phrase(password: Option<&str>) -> (Pair, String, [u8; 32])
[src]
Generate new secure (random) key pair and provide the recovery phrase.
You can recover the same key later with from_phrase
.
fn from_phrase(
phrase: &str,
password: Option<&str>
) -> Result<(Pair, [u8; 32]), SecretStringError>
[src]
phrase: &str,
password: Option<&str>
) -> Result<(Pair, [u8; 32]), SecretStringError>
Generate key pair from given recovery phrase and password.
fn from_seed(seed: &[u8; 32]) -> Pair
[src]
Make a new key pair from secret seed material.
You should never need to use this; generate(), generate_with_phrase
fn from_seed_slice(seed_slice: &[u8]) -> Result<Pair, SecretStringError>
[src]
Make a new key pair from secret seed material. The slice must be 32 bytes long or it
will return None
.
You should never need to use this; generate(), generate_with_phrase
fn derive<Iter: Iterator<Item = DeriveJunction>>(
&self,
path: Iter,
_seed: Option<[u8; 32]>
) -> Result<(Pair, Option<[u8; 32]>), DeriveError>
[src]
&self,
path: Iter,
_seed: Option<[u8; 32]>
) -> Result<(Pair, Option<[u8; 32]>), DeriveError>
Derive a child key from a series of given junctions.
fn public(&self) -> Public
[src]
Get the public key.
fn sign(&self, message: &[u8]) -> Signature
[src]
Sign a message.
fn verify<M: AsRef<[u8]>>(
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
[src]
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
Verify a signature on a message. Returns true if the signature is good.
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(
sig: &[u8],
message: M,
pubkey: P
) -> bool
[src]
sig: &[u8],
message: M,
pubkey: P
) -> bool
Verify a signature on a message. Returns true if the signature is good.
This doesn’t use the type system to ensure that sig
and pubkey
are the correct
size. Use it only if you’re coming from byte buffers and need the speed.
fn to_raw_vec(&self) -> Vec<u8>ⓘ
[src]
Return a vec filled with raw data.
impl Pair for sp_core::ed25519::Pair
[src]
type Public = Public
type Seed = [u8; 32]
type Signature = Signature
type DeriveError = DeriveError
fn generate_with_phrase(password: Option<&str>) -> (Pair, String, [u8; 32])
[src]
Generate new secure (random) key pair and provide the recovery phrase.
You can recover the same key later with from_phrase
.
fn from_phrase(
phrase: &str,
password: Option<&str>
) -> Result<(Pair, [u8; 32]), SecretStringError>
[src]
phrase: &str,
password: Option<&str>
) -> Result<(Pair, [u8; 32]), SecretStringError>
Generate key pair from given recovery phrase and password.
fn from_seed(seed: &[u8; 32]) -> Pair
[src]
Make a new key pair from secret seed material.
You should never need to use this; generate(), generate_with_phrase
fn from_seed_slice(seed_slice: &[u8]) -> Result<Pair, SecretStringError>
[src]
Make a new key pair from secret seed material. The slice must be 32 bytes long or it
will return None
.
You should never need to use this; generate(), generate_with_phrase
fn derive<Iter: Iterator<Item = DeriveJunction>>(
&self,
path: Iter,
_seed: Option<[u8; 32]>
) -> Result<(Pair, Option<[u8; 32]>), DeriveError>
[src]
&self,
path: Iter,
_seed: Option<[u8; 32]>
) -> Result<(Pair, Option<[u8; 32]>), DeriveError>
Derive a child key from a series of given junctions.
fn public(&self) -> Public
[src]
Get the public key.
fn sign(&self, message: &[u8]) -> Signature
[src]
Sign a message.
fn verify<M: AsRef<[u8]>>(
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
[src]
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
Verify a signature on a message. Returns true if the signature is good.
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(
sig: &[u8],
message: M,
pubkey: P
) -> bool
[src]
sig: &[u8],
message: M,
pubkey: P
) -> bool
Verify a signature on a message. Returns true if the signature is good.
This doesn’t use the type system to ensure that sig
and pubkey
are the correct
size. Use it only if you’re coming from byte buffers and need the speed.
fn to_raw_vec(&self) -> Vec<u8>ⓘ
[src]
Return a vec filled with raw data.
impl Pair for sp_core::sr25519::Pair
[src]
type Public = Public
type Seed = [u8; 32]
type Signature = Signature
type DeriveError = Infallible
fn from_seed(seed: &[u8; 32]) -> Pair
[src]
Make a new key pair from raw secret seed material.
This is generated using schnorrkel’s Mini-Secret-Keys.
A MiniSecretKey is literally what Ed25519 calls a SecretKey, which is just 32 random bytes.
fn public(&self) -> Public
[src]
Get the public key.
fn from_seed_slice(seed: &[u8]) -> Result<Pair, SecretStringError>
[src]
Make a new key pair from secret seed material. The slice must be 32 bytes long or it
will return None
.
You should never need to use this; generate(), generate_with_phrase(), from_phrase()
fn generate_with_phrase(password: Option<&str>) -> (Pair, String, [u8; 32])
[src]
fn from_phrase(
phrase: &str,
password: Option<&str>
) -> Result<(Pair, [u8; 32]), SecretStringError>
[src]
phrase: &str,
password: Option<&str>
) -> Result<(Pair, [u8; 32]), SecretStringError>
fn derive<Iter: Iterator<Item = DeriveJunction>>(
&self,
path: Iter,
seed: Option<[u8; 32]>
) -> Result<(Pair, Option<[u8; 32]>), Self::DeriveError>
[src]
&self,
path: Iter,
seed: Option<[u8; 32]>
) -> Result<(Pair, Option<[u8; 32]>), Self::DeriveError>
fn sign(&self, message: &[u8]) -> Signature
[src]
fn verify<M: AsRef<[u8]>>(
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
[src]
sig: &Self::Signature,
message: M,
pubkey: &Self::Public
) -> bool
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(
sig: &[u8],
message: M,
pubkey: P
) -> bool
[src]
sig: &[u8],
message: M,
pubkey: P
) -> bool