[][src]Module exonum::messages

Tools for messages authenticated with the Ed25519 public-key crypto system. These messages are used by the P2P networking and for transaction authentication by external clients.

Every message passes through three phases:

  1. Vec<u8>: raw bytes as received from the network
  2. SignedMessage: integrity and the signature of the message has been verified
  3. impl IntoMessage: the message has been completely parsed

Graphical representation of the message processing flow:

+---------+             +---------------+                  +------------------+
| Vec<u8> |--(verify)-->| SignedMessage |--(deserialize)-->| impl IntoMessage |-->(handle)
+---------+     |       +---------------+        |         +------------------+
                |                                |
                V                                V
             (drop)                           (drop)

Examples

A new signed message can be created as follows.

let keypair = KeyPair::random();
// For example, let's create a `Precommit` message.
let payload = Precommit::new(
    ValidatorId(0),
    Height(15),
    Round::first(),
    hash(b"propose_hash"),
    hash(b"block_hash"),
    Utc::now(),
);
// Sign the message with some keypair to get a trusted `Precommit` message.
let signed_payload = Verified::from_value(payload, keypair.public_key(), keypair.secret_key());
// Further, convert the trusted message into a raw signed message and send
// it through the network.
let raw_signed_message = signed_payload.into_raw();
send(raw_signed_message);

A signed message can be verified as follows:

// Assume you have some signed message.
let raw: SignedMessage = get_signed_message();
// You know that this is a type of `CoreMessage`, so you can
// verify its signature and convert it into `CoreMessage`.
let verified = raw.into_verified::<CoreMessage>().expect("verification failed");
// Further, check whether it is a `Precommit` message.
assert_matches!(
    verified.payload(),
    CoreMessage::Precommit(ref precommit) if precommit.epoch == Height(15)
);

Modules

schema

Module with protobuf generated files from schema/exonum.

Structs

AnyTx

Transaction with the information required to dispatch it to a service.

Precommit

Pre-commit for a block, essentially meaning that a validator node endorses the block. The consensus algorithm ensures that once a Byzantine majority of validators has endorsed a block, no other block at the same height may be endorsed at any point in the future. Thus, such a block can be considered committed.

SignedMessage

Protobuf-based container for an arbitrary signed message.

Verified

Wraps a payload together with the corresponding SignedMessage.

Enums

CoreMessage

Subset of Exonum messages defined in the Exonum core.

Traits

IntoMessage

Message that can be converted into a unambiguous presentation for signing.