Skip to content

Commit

Permalink
set predefined default value for KeyPair
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Apr 12, 2022
1 parent a3cbac3 commit 979a458
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
6 changes: 3 additions & 3 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![allow(missing_docs, clippy::pedantic, clippy::restriction)]

use iroha::samples::get_config;
use iroha_core::{
genesis::{GenesisNetwork, GenesisNetworkTrait, RawGenesisBlock, RawGenesisBlockBuilder},
use iroha_core::genesis::{
GenesisNetwork, GenesisNetworkTrait, RawGenesisBlock, RawGenesisBlockBuilder,
};
use iroha_data_model::prelude::*;
use test_network::{get_key_pair, Peer as TestPeer, TestRuntime};
Expand All @@ -18,7 +18,7 @@ fn main() {
.domain(format!("wonderland-{}", i).parse().expect("Valid"))
.with_account(
format!("Alice-{}", i).parse().expect("Valid"),
key_pair.public_key().clone();
key_pair.public_key().clone(),
)
.with_asset(
format!("xor-{}", i).parse().expect("Valid"),
Expand Down
19 changes: 15 additions & 4 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,19 @@ pub struct KeyPair {

impl Default for KeyPair {
fn default() -> Self {
// TODO: Use one defined key pair here or remove the `KeyPair::generate`
// method in favor of the default implementation as defined here
Self::generate().expect("Valid")
#[cfg(not(feature = "std"))]
use alloc::string::ToString as _;

Self::new(
PublicKey {
digest_function: Algorithm::default().to_string(),
payload: Vec::new(),
},
PrivateKey {
digest_function: Algorithm::default().to_string(),
payload: Vec::new(),
},
)
}
}

Expand Down Expand Up @@ -215,7 +225,6 @@ impl From<NoSuchAlgorithm> for Error {
#[cfg(feature = "std")]
impl std::error::Error for Error {}

#[cfg(feature = "std")]
impl KeyPair {
/// Construct `KeyPair`
pub fn new(public_key: PublicKey, private_key: PrivateKey) -> Self {
Expand All @@ -229,6 +238,7 @@ impl KeyPair {
///
/// # Errors
/// Fails if decoding fails
#[cfg(feature = "std")]
pub fn generate() -> Result<Self, Error> {
Self::generate_with_configuration(KeyGenConfiguration::default())
}
Expand All @@ -237,6 +247,7 @@ impl KeyPair {
///
/// # Errors
/// Fails if decoding fails
#[cfg(feature = "std")]
pub fn generate_with_configuration(configuration: KeyGenConfiguration) -> Result<Self, Error> {
let key_gen_option: Option<UrsaKeyGenOption> = configuration
.key_gen_option
Expand Down
11 changes: 1 addition & 10 deletions crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,6 @@ impl<T> SignaturesOf<T> {
SignaturesOf { signatures }
}

/// Builds container using single signature
fn from_signature(sign: SignatureOf<T>) -> Self {
let mut me = Self {
signatures: btree_map::BTreeMap::new(),
};
me.insert(sign);
me
}

/// Adds a signature. If the signature with this key was present, replaces it.
pub fn insert(&mut self, signature: SignatureOf<T>) {
self.signatures
Expand Down Expand Up @@ -475,7 +466,7 @@ impl<T: Encode> SignaturesOf<T> {
/// # Errors
/// Forwards [`SignatureOf::new`] errors
pub fn new(key_pair: KeyPair, value: &T) -> Result<Self, Error> {
SignatureOf::new(key_pair, value).map(Self::from_signature)
[SignatureOf::new(key_pair, value)?].into_iter().collect()
}

/// Verifies all signatures
Expand Down
18 changes: 9 additions & 9 deletions docs/source/references/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ The following is the default configuration used by Iroha.

```json
{
"PUBLIC_KEY": "ed0120f6c9f00ea385320b2a18ef1a059cb6abb9ecd144ccad1d90e1d10b7214d6e97f",
"PUBLIC_KEY": "ed0100",
"PRIVATE_KEY": {
"digest_function": "ed25519",
"payload": "59b15719c16e55529c886b12b47bbed41d6e12e6e96a1545b06980bb2f0e35bcf6c9f00ea385320b2a18ef1a059cb6abb9ecd144ccad1d90e1d10b7214d6e97f"
"payload": ""
},
"DISABLE_PANIC_TERMINAL_COLORS": false,
"KURA": {
Expand All @@ -23,7 +23,7 @@ The following is the default configuration used by Iroha.
"SUMERAGI": {
"PEER_ID": {
"address": "localhost",
"public_key": "ed01202200393b046a710cd5c96d7dfb2ef5f93d2ad905f5d09f2e795fae05c6659f42"
"public_key": "ed0100"
},
"BLOCK_TIME_MS": 1000,
"TRUSTED_PEERS": [],
Expand Down Expand Up @@ -377,7 +377,7 @@ Has type `PrivateKey`. Can be configured via environment variable `IROHA_PRIVATE
```json
{
"digest_function": "ed25519",
"payload": "35ac0df7882c95fba36a3523beac85f166a93f1cca6c9c9dd31c318b0ef9eeb224b0baf68a733a10aac8e53d5bcdb339c3880dd67c9d99ef9fe11e22fb154b4f"
"payload": ""
}
```

Expand All @@ -388,7 +388,7 @@ Public key of this peer.
Has type `PublicKey`. Can be configured via environment variable `IROHA_PUBLIC_KEY`

```json
"ed01205df619fc88995763c4c97d93b56b191392afecd140ab41ad74d6bd34197944e5"
"ed0100"
```

## `queue`
Expand Down Expand Up @@ -462,7 +462,7 @@ Has type `SumeragiConfiguration`. Can be configured via environment variable `IR
"N_TOPOLOGY_SHIFTS_BEFORE_RESHUFFLE": 1,
"PEER_ID": {
"address": "localhost",
"public_key": "ed0120588a0cf8e5c7a1ebc79b15610d4c015bc3ff93a5f7cf413707474c47221294e1"
"public_key": "ed0100"
},
"TRANSACTION_LIMITS": {
"max_instruction_number": 4096,
Expand Down Expand Up @@ -523,9 +523,9 @@ Has type `KeyPair`. Can be configured via environment variable `SUMERAGI_KEY_PAI
{
"private_key": {
"digest_function": "ed25519",
"payload": "5171f43810689540346c55a69c67ba2926542975346b3f65e0540459b3598fc30d01e6ef03e21c25452954887cb6bceff7a2a9d40824441055e4f170bcaa6990"
"payload": ""
},
"public_key": "ed01200d01e6ef03e21c25452954887cb6bceff7a2a9d40824441055e4f170bcaa6990"
"public_key": "ed0100"
}
```

Expand Down Expand Up @@ -558,7 +558,7 @@ Has type `PeerId`. Can be configured via environment variable `SUMERAGI_PEER_ID`
```json
{
"address": "localhost",
"public_key": "ed012092b443c35719f2fbf3a8870079e430fdb45ef7557e7be03232dd39ea3920913f"
"public_key": "ed0100"
}
```

Expand Down

0 comments on commit 979a458

Please sign in to comment.