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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#![allow(dead_code)]
#![allow(clippy::from_over_into)]
#![allow(clippy::upper_case_acronyms)]

/// An interface for implementing the stronghold engine. Using the Riker Actor model, this library provides a
/// mechanism to manage secret data between multiple users. Stronghold may be accessed via the `Stronghold`
/// object. The interface contains methods to access the secure runtime environment and methods to write to the
/// Stronghold. Each Stronghold contains a collection of versioned records, identified as Vaults. Each Vault
/// contains a set of versioned records of like data. Multiple clients can be spawned with Stronghold, each of
/// which can hold multiple vaults (See the `Location` API for more details). The Stronghold interface also
/// contains a generic insecure key/value store which can be accessed as a `Store`. Each client contains a single
/// store and the same location may be used across multiple clients.
// TODO: Synchronization via 4th actor and status type.
// TODO: Add supervisors
// TODO: Add documentation
// TODO: Handshake
// TODO: ~~O(1) comparison for IDS.~~
// TODO: ~~Add ability to name snapshots~~
// TODO: ~~Add ability to read and revoke records not on the head of the chain.~~
// TODO: Add Reference types for the RecordIds and VaultIds to expose to the External programs.
// TODO: Add Handshake Messages.
// TODO: Add Responses for each Message.
// TODO: Remove #[allow(dead_code)]
use thiserror::Error as DeriveError;

mod actors;
mod interface;
mod internals;
mod state;
mod utils;

// Tests exist as a sub-module because they need to be able to test internal concepts without exposing them publicly.
#[cfg(test)]
mod tests;

pub use crate::{
    actors::{ProcResult, Procedure, SLIP10DeriveInput},
    interface::Stronghold,
    internals::Provider,
    utils::{Location, ResultMessage, StatusMessage, StrongholdFlags, VaultFlags},
};

#[cfg(feature = "communication")]
pub use crate::actors::SHRequestPermission;
#[cfg(feature = "communication")]
pub use communication::{
    actor::RelayDirection,
    libp2p::{Multiaddr, PeerId},
};

pub use engine::snapshot::{
    files::{home_dir, snapshot_dir},
    kdf::naive_kdf,
    Key,
};

pub use engine::vault::RecordHint;

/// TODO: Should be replaced with proper errors.
#[macro_export]
macro_rules! line_error {
    () => {
        concat!("Error at ", file!(), ":", line!())
    };
    ($str:expr) => {
        concat!($str, " @", file!(), ":", line!())
    };
}

pub type Result<T> = anyhow::Result<T, Error>;

#[derive(DeriveError, Debug)]
pub enum Error {
    #[error("Id Error")]
    IDError,
    #[error("Engine Error: {0}")]
    EngineError(#[from] engine::Error),
}