mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
Switch from tiny-bip39 to bip39 crate (#2084)
Switch from: https://crates.io/crates/tiny-bip39 to: https://crates.io/crates/bip39 Required for: https://github.com/paritytech/polkadot-sdk/pull/2044
This commit is contained in:
committed by
GitHub
parent
30f3ad2eef
commit
a69da4a85f
@@ -19,9 +19,11 @@
|
||||
|
||||
use crate::{ed25519, sr25519};
|
||||
#[cfg(feature = "std")]
|
||||
use bip39::{Language, Mnemonic, MnemonicType};
|
||||
use bip39::{Language, Mnemonic};
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
#[cfg(feature = "std")]
|
||||
use itertools::Itertools;
|
||||
#[cfg(feature = "std")]
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
#[cfg(feature = "std")]
|
||||
use regex::Regex;
|
||||
@@ -870,9 +872,9 @@ pub trait Pair: CryptoType + Sized {
|
||||
/// the key from the current session.
|
||||
#[cfg(feature = "std")]
|
||||
fn generate_with_phrase(password: Option<&str>) -> (Self, String, Self::Seed) {
|
||||
let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English);
|
||||
let phrase = mnemonic.phrase();
|
||||
let (pair, seed) = Self::from_phrase(phrase, password)
|
||||
let mnemonic = Mnemonic::generate(12).expect("Mnemonic generation always works; qed");
|
||||
let phrase = mnemonic.word_iter().join(" ");
|
||||
let (pair, seed) = Self::from_phrase(&phrase, password)
|
||||
.expect("All phrases generated by Mnemonic are valid; qed");
|
||||
(pair, phrase.to_owned(), seed)
|
||||
}
|
||||
@@ -883,10 +885,12 @@ pub trait Pair: CryptoType + Sized {
|
||||
phrase: &str,
|
||||
password: Option<&str>,
|
||||
) -> Result<(Self, Self::Seed), SecretStringError> {
|
||||
let mnemonic = Mnemonic::from_phrase(phrase, Language::English)
|
||||
let mnemonic = Mnemonic::parse_in(Language::English, phrase)
|
||||
.map_err(|_| SecretStringError::InvalidPhrase)?;
|
||||
|
||||
let (entropy, entropy_len) = mnemonic.to_entropy_array();
|
||||
let big_seed =
|
||||
substrate_bip39::seed_from_entropy(mnemonic.entropy(), password.unwrap_or(""))
|
||||
substrate_bip39::seed_from_entropy(&entropy[0..entropy_len], password.unwrap_or(""))
|
||||
.map_err(|_| SecretStringError::InvalidSeed)?;
|
||||
let mut seed = Self::Seed::default();
|
||||
let seed_slice = seed.as_mut();
|
||||
|
||||
Reference in New Issue
Block a user