Skip to content

Commit

Permalink
add default key pair to GenesisConfiguration
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 18, 2022
1 parent 713e0ed commit e9ced83
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
16 changes: 13 additions & 3 deletions core/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub mod config {
/// Configuration of the genesis block and the process of its submission.
pub struct GenesisConfiguration {
/// The genesis account public key, should be supplied to all peers.
/// The type is `Option` just because it might be loaded from environment variables and not from `config.json`.
/// The type is `Option` just because it might be loaded from environment variables and not from `config.json`
#[config(serde_as_str)]
pub account_public_key: Option<PublicKey>,
/// Genesis account private key, only needed on the peer that submits the genesis block.
Expand All @@ -340,11 +340,21 @@ pub mod config {
pub genesis_submission_delay_ms: u64,
}

#[allow(clippy::expect_used)]
impl Default for GenesisConfiguration {
fn default() -> Self {
let public_key: PublicKey =
"ed01204cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf"
.parse()
.expect("Public key not in mulithash format");
let private_key = PrivateKey::from_hex(
iroha_crypto::Algorithm::Ed25519,
"d748e18ce60cb30dea3e73c9019b7af45a8d465e3d71bcc9a5ef99a008205e534cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf"
).expect("Private key not hex encoded");

Self {
account_public_key: None,
account_private_key: None,
account_public_key: Some(public_key),
account_private_key: Some(private_key),
wait_for_peers_retry_count: DEFAULT_WAIT_FOR_PEERS_RETRY_COUNT,
wait_for_peers_retry_period_ms: DEFAULT_WAIT_FOR_PEERS_RETRY_PERIOD_MS,
genesis_submission_delay_ms: DEFAULT_GENESIS_SUBMISSION_DELAY_MS,
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<T> MerkleTree<T> {
}

/// Return the `Hash` of the root node.
pub fn root_hash(&self) -> HashOf<Self> {
pub const fn root_hash(&self) -> HashOf<Self> {
self.root_node.hash().transmute()
}

Expand Down Expand Up @@ -165,7 +165,7 @@ impl<T> Node<T> {
}

/// Return the `Hash` of the root node.
pub fn hash(&self) -> HashOf<Self> {
pub const fn hash(&self) -> HashOf<Self> {
match self {
Node::Subtree(Subtree { hash, .. }) => *hash,
Node::Leaf(Leaf { hash }) => (*hash).transmute(),
Expand Down
18 changes: 8 additions & 10 deletions crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Signature {
public_key: PublicKey,
/// Actual signature payload is placed here.
#[getset(skip)]
signature: Payload,
payload: Payload,
}

impl Signature {
Expand Down Expand Up @@ -83,7 +83,7 @@ impl Signature {

Ok(Self {
public_key,
signature,
payload: signature,
})
}

Expand All @@ -106,14 +106,12 @@ impl Signature {
let public_key = UrsaPublicKey(self.public_key.payload.clone());

match algorithm {
Algorithm::Ed25519 => {
Ed25519Sha512::new().verify(payload, &self.signature, &public_key)
}
Algorithm::Ed25519 => Ed25519Sha512::new().verify(payload, &self.payload, &public_key),
Algorithm::Secp256k1 => {
EcdsaSecp256k1Sha256::new().verify(payload, &self.signature, &public_key)
EcdsaSecp256k1Sha256::new().verify(payload, &self.payload, &public_key)
}
Algorithm::BlsSmall => BlsSmall::new().verify(payload, &self.signature, &public_key),
Algorithm::BlsNormal => BlsNormal::new().verify(payload, &self.signature, &public_key),
Algorithm::BlsSmall => BlsSmall::new().verify(payload, &self.payload, &public_key),
Algorithm::BlsNormal => BlsNormal::new().verify(payload, &self.payload, &public_key),
}?;

Ok(())
Expand All @@ -124,7 +122,7 @@ impl fmt::Debug for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct(core::any::type_name::<Self>())
.field("public_key", &self.public_key)
.field("signature", &hex::encode_upper(self.signature.as_slice()))
.field("signature", &hex::encode_upper(self.payload.as_slice()))
.finish()
}
}
Expand All @@ -133,7 +131,7 @@ impl From<Signature> for (PublicKey, Payload) {
fn from(
Signature {
public_key,
signature,
payload: signature,
}: Signature,
) -> Self {
(public_key, signature)
Expand Down
21 changes: 15 additions & 6 deletions docs/source/references/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ The following is the default configuration used by Iroha.
"TERMINAL_COLORS": true
},
"GENESIS": {
"ACCOUNT_PUBLIC_KEY": null,
"ACCOUNT_PRIVATE_KEY": null,
"ACCOUNT_PUBLIC_KEY": "ed01204cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf",
"ACCOUNT_PRIVATE_KEY": {
"digest_function": "ed25519",
"payload": "d748e18ce60cb30dea3e73c9019b7af45a8d465e3d71bcc9a5ef99a008205e534cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf"
},
"WAIT_FOR_PEERS_RETRY_COUNT": 100,
"WAIT_FOR_PEERS_RETRY_PERIOD_MS": 500,
"GENESIS_SUBMISSION_DELAY_MS": 1000
Expand Down Expand Up @@ -167,8 +170,11 @@ Has type `GenesisConfiguration`. Can be configured via environment variable `IRO

```json
{
"ACCOUNT_PRIVATE_KEY": null,
"ACCOUNT_PUBLIC_KEY": null,
"ACCOUNT_PRIVATE_KEY": {
"digest_function": "ed25519",
"payload": "d748e18ce60cb30dea3e73c9019b7af45a8d465e3d71bcc9a5ef99a008205e534cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf"
},
"ACCOUNT_PUBLIC_KEY": "ed01204cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf",
"GENESIS_SUBMISSION_DELAY_MS": 1000,
"WAIT_FOR_PEERS_RETRY_COUNT": 100,
"WAIT_FOR_PEERS_RETRY_PERIOD_MS": 500
Expand All @@ -182,7 +188,10 @@ Genesis account private key, only needed on the peer that submits the genesis bl
Has type `Option<PrivateKey>`. Can be configured via environment variable `IROHA_GENESIS_ACCOUNT_PRIVATE_KEY`

```json
null
{
"digest_function": "ed25519",
"payload": "d748e18ce60cb30dea3e73c9019b7af45a8d465e3d71bcc9a5ef99a008205e534cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf"
}
```

### `genesis.account_public_key`
Expand All @@ -192,7 +201,7 @@ The genesis account public key, should be supplied to all peers.
Has type `Option<PublicKey>`. Can be configured via environment variable `IROHA_GENESIS_ACCOUNT_PUBLIC_KEY`

```json
null
"ed01204cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf"
```

### `genesis.genesis_submission_delay_ms`
Expand Down

0 comments on commit e9ced83

Please sign in to comment.