1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::collections::HashSet;

use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

use crate::{
    commons::models::validation::ValidationProof,
    identifier::DigestIdentifier,
    signature::{Signature, Signed},
    Event, KeyDerivator, KeyIdentifier,
};

pub mod errors;
pub mod ledger;
pub mod manager;

#[derive(Debug, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
pub enum LedgerCommand {
    OwnEvent {
        event: Signed<Event>,
        signatures: HashSet<Signature>,
        validation_proof: ValidationProof,
    },
    Genesis {
        event: Signed<Event>,
        signatures: HashSet<Signature>,
        validation_proof: ValidationProof,
    },
    ExternalEvent {
        sender: KeyIdentifier,
        event: Signed<Event>,
        signatures: HashSet<Signature>,
        validation_proof: ValidationProof,
    },
    ExternalIntermediateEvent {
        event: Signed<Event>,
    },
    GetEvent {
        who_asked: KeyIdentifier,
        subject_id: DigestIdentifier,
        sn: u64,
    },
    GetNextGov {
        who_asked: KeyIdentifier,
        subject_id: DigestIdentifier,
        sn: u64,
    },
    GetLCE {
        who_asked: KeyIdentifier,
        subject_id: DigestIdentifier,
    },
    GenerateKey(KeyDerivator),
}

#[derive(Debug, Clone)]
pub enum LedgerResponse {
    GetEvent(Result<Signed<Event>, errors::LedgerError>),
    GetNextGov(Result<(Signed<Event>, HashSet<Signature>), errors::LedgerError>),
    GetLCE(Result<(Signed<Event>, HashSet<Signature>), errors::LedgerError>),
    GenerateKey(Result<KeyIdentifier, errors::LedgerError>),
    NoResponse,
}