Skip to content

Commit

Permalink
Update dependants of key_derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
orhoj committed Dec 7, 2023
1 parent 8612d42 commit dc16e78
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 42 deletions.
4 changes: 4 additions & 0 deletions mobile_wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.25.1

- Updated the internal library key_derivation to 2.0.0. This enforces that the seed phrase input must be 12, 15, 18, 21 or 24 words.

## 0.25.0
- Added a function `get_verifiable_credential_keys` for deriving the keys for a verifiable credential.

Expand Down
5 changes: 3 additions & 2 deletions mobile_wallet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mobile_wallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mobile_wallet"
version = "0.25.0"
version = "0.25.1"
authors = ["Concordium AG <[email protected]>"]
edition = "2018"
license-file = "../../LICENSE-APACHE"
Expand All @@ -26,7 +26,7 @@ base64 = "0.21"

[dependencies.key_derivation]
path = "../rust-src/key_derivation"
version = "1.2.0"
version = "2.0.0"

[dependencies.ed25519_hd_key_derivation]
path = "../rust-src/ed25519_hd_key_derivation"
Expand Down
4 changes: 4 additions & 0 deletions rust-bins/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog

## 2.0.2

- Updated the internal library key_derivation to 2.0.0. This enforces that the seed phrase input must be 12, 15, 18, 21 or 24 words.

## 2.0.1
- Fixed bug where the user_cli tool was unable to accept the `account` flag as it conflicted with the `expiry` flag that was always set due to a default value being provided.
5 changes: 3 additions & 2 deletions rust-bins/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust-bins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "misc_tools"
version = "2.0.1"
version = "2.0.2"
authors = ["Concordium AG <[email protected]>"]
edition = "2018"
license-file = "../../LICENSE-APACHE"
Expand Down Expand Up @@ -44,7 +44,7 @@ version = "1.0.0"

[dependencies.key_derivation]
path = "../rust-src/key_derivation"
version = "1.1.0"
version = "2.0.0"

[dependencies.keygen_bls]
path = "../rust-src/keygen_bls"
Expand Down
12 changes: 8 additions & 4 deletions rust-bins/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use concordium_base::{
use dialoguer::{Input, MultiSelect, Select};
use ed25519_dalek as ed25519;
use either::Either::{Left, Right};
use key_derivation::{words_to_seed, ConcordiumHdWallet, CredentialContext, Net};
use key_derivation::{ConcordiumHdWallet, CredentialContext, Net};
use pairing::bls12_381::{Bls12, G1};
use rand::*;
use serde_json::{json, to_value};
Expand Down Expand Up @@ -1335,9 +1335,13 @@ fn handle_create_hd_wallet(chw: CreateHdWallet) {
} else {
Net::Mainnet
};
let wallet = ConcordiumHdWallet {
seed: words_to_seed(&words_str),
net,

let wallet = match ConcordiumHdWallet::from_seed_phrase(&words_str, net) {
Ok(s) => s,
Err(e) => {
eprintln!("An invalid seed phrase was provided. Error: {}", e);
return;
}
};

if let Some(filepath) = chw.out {
Expand Down
45 changes: 20 additions & 25 deletions rust-bins/src/bin/user_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crossterm::{
use dialoguer::{Confirm, Input, MultiSelect, Select};
use ed25519_dalek as ed25519;
use either::Either::{Left, Right};
use key_derivation::{words_to_seed, ConcordiumHdWallet, CredentialContext, Net};
use key_derivation::{ConcordiumHdWallet, CredentialContext, Net};
use rand::*;
use serde_json::{json, to_value};
use std::{collections::btree_map::BTreeMap, convert::TryFrom, path::PathBuf};
Expand Down Expand Up @@ -280,6 +280,21 @@ fn main() -> anyhow::Result<()> {
}
}

fn get_concordium_wallet(
words_str: &str,
use_mainnet: bool,
) -> anyhow::Result<ConcordiumHdWallet, anyhow::Error> {
let net = if use_mainnet {
Net::Mainnet
} else {
Net::Testnet
};
match ConcordiumHdWallet::from_seed_phrase(words_str, net) {
Ok(s) => Ok(s),
Err(e) => bail!(format!("An invalid seed phrase was provided. Error: {}", e)),
}
}

fn handle_start_ip(sip: StartIp) -> anyhow::Result<()> {
let ip_info = read_ip_info(&sip.ip_info).context(format!(
"Could not read the identity provider information from {}.",
Expand Down Expand Up @@ -609,14 +624,7 @@ fn handle_start_ip_v1(sip: StartIpV1) -> anyhow::Result<()> {
randomized_words.join(" ")
};

let wallet = ConcordiumHdWallet {
seed: words_to_seed(&words_str),
net: if use_mainnet {
Net::Mainnet
} else {
Net::Testnet
},
};
let wallet = get_concordium_wallet(&words_str, use_mainnet)?;
let identity_provider_index = ip_info.ip_identity.0;
let identity_index = Input::new()
.with_prompt("Identity index")
Expand Down Expand Up @@ -716,14 +724,8 @@ fn handle_create_credential_v1(cc: CreateCredentialV1) -> anyhow::Result<()> {
input_words.join(" ")
};

let wallet = ConcordiumHdWallet {
seed: words_to_seed(&words_str),
net: if use_mainnet {
Net::Mainnet
} else {
Net::Testnet
},
};
let wallet = get_concordium_wallet(&words_str, use_mainnet)?;

// We ask what identity and regid index they would like to use.
let identity_index = Input::new()
.with_prompt("Identity index")
Expand Down Expand Up @@ -1144,14 +1146,7 @@ fn handle_recovery(girr: GenerateIdRecoveryRequest) -> anyhow::Result<()> {
input_words.join(" ")
};

let wallet = ConcordiumHdWallet {
seed: words_to_seed(&words_str),
net: if use_mainnet {
Net::Mainnet
} else {
Net::Testnet
},
};
let wallet = get_concordium_wallet(&words_str, use_mainnet)?;
// We ask what identity and regid index they would like to use.
let identity_index = Input::new()
.with_prompt("Identity index")
Expand Down
8 changes: 3 additions & 5 deletions rust-src/key_derivation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ impl fmt::Display for Net {
}

#[derive(Debug, Error)]
pub enum MnemonicLengthError {
#[error("Invalid mnemonic length. The length must be 12, 15, 18, 21 or 24.")]
InvalidLength,
}
#[error("Invalid mnemonic length. The length must be 12, 15, 18, 21 or 24.")]
pub struct MnemonicLengthError;

fn bls_key_bytes_from_seed(key_seed: [u8; 32]) -> <ArCurve as Curve>::Scalar {
keygen_bls(&key_seed, b"").expect("All the inputs are of the correct length, this cannot fail.")
Expand All @@ -64,7 +62,7 @@ pub fn words_to_seed_with_passphrase(
let words_count = words.split(' ').collect::<Vec<&str>>().len();
let allowed_word_counts: [usize; 5] = [12, 15, 18, 21, 24];
if !allowed_word_counts.contains(&words_count) {
return Err(MnemonicLengthError::InvalidLength);
return Err(MnemonicLengthError);
}

let mut salt_string: String = "mnemonic".to_owned();
Expand Down

0 comments on commit dc16e78

Please sign in to comment.