This commit is contained in:
Alexey Proshutinskiy 2021-08-01 16:31:13 +03:00
parent cbcca20566
commit 190fcc16e7
15 changed files with 425 additions and 220 deletions

529
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -19,14 +19,17 @@ log = "0.4.11"
ref-cast = "1.0.2"
derivative = "2.1.1"
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
rand = "0.7.0"
signature = "1.3.0"
serde_with = "1.6.0"
thiserror = "1.0.23"
libsecp256k1 = "0.3.5"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ring = "0.16.20"
rand = "0.7.0"
[workspace]
members = [
"identity"
"identity",
"service"
]

View File

@ -19,12 +19,14 @@ serde_with = "1.6.0"
thiserror = "1.0.23"
lazy_static = "1.2"
libsecp256k1 = "0.3.5"
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
asn1_der = "0.6.1"
sha2 = "0.9.1"
zeroize = "1"
serde_bytes = "0.11"
libp2p-core = { package = "fluence-fork-libp2p-core", version = "0.27.2" }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
[dev-dependencies]
quickcheck = "0.9.0"

View File

@ -11,15 +11,16 @@ name = "trust-graph"
path = "src/main.rs"
[dependencies]
trust-graph = { version = "0.2.1", path = "../" }
fluence-identity = { version = "0.2.1", path = "../identity" }
trust-graph = { version = "0.2.6", path = "../." }
fluence-identity = { version = "0.3.0", path = "../identity" }
marine-rs-sdk = { version = "0.6.11", features = ["logger"] }
marine-sqlite-connector = "0.5.0"
log = "0.4.8"
fluence = { version = "0.2.18", features = ["logger"] }
anyhow = "1.0.31"
boolinator = "2.4.0"
once_cell = "1.4.1"
parking_lot = "0.11.1"
fce-sqlite-connector = "0.1.3"
serde_json = "1.0"
bs58 = "0.3.1"
rmp-serde = "0.15.0"

14
service/build.sh Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
# set current working directory to script directory to run script from everywhere
cd "$(dirname "$0")"
# build trust-graph.wasm
cargo update
marine build --release
# copy .wasm to artifacts
rm -f artifacts/*
mkdir -p artifacts
cp ../target/wasm32-wasi/release/trust-graph.wasm artifacts/

5
service/run-repl.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
./build.sh
RUST_LOG="info" fce-repl Config.toml

View File

@ -1,6 +1,5 @@
use fluence::fce;
use fluence_identity::public_key::PKError;
use fluence_identity::signature::SignatureError;
use marine_rs_sdk::marine;
use fluence_identity::error::DecodingError;
use fluence_identity::{PublicKey, Signature};
use std::convert::TryFrom;
use std::time::Duration;
@ -18,17 +17,11 @@ pub enum DtoConversionError {
PublicKeyDecodeError(
#[from]
#[source]
PKError,
),
#[error("Cannot convert string to PublicKey: {0}")]
SignatureDecodeError(
#[from]
#[source]
SignatureError,
DecodingError,
),
}
#[fce]
#[marine]
pub struct Certificate {
pub chain: Vec<Trust>,
}
@ -54,7 +47,7 @@ impl TryFrom<Certificate> for trust_graph::Certificate {
}
}
#[fce]
#[marine]
pub struct Trust {
/// For whom this certificate is issued, base58
pub issued_for: String,
@ -73,7 +66,7 @@ impl TryFrom<Trust> for trust_graph::Trust {
fn try_from(t: Trust) -> Result<Self, Self::Error> {
let issued_for = PublicKey::from_base58(&t.issued_for)?;
let signature = bs58::decode(&t.signature).into_vec()?;
let signature = Signature::from_bytes(&signature)?;
let signature = Signature::decode(signature)?;
let expires_at = Duration::from_secs(t.expires_at);
let issued_at = Duration::from_secs(t.issued_at);
return Ok(trust_graph::Trust {
@ -87,8 +80,8 @@ impl TryFrom<Trust> for trust_graph::Trust {
impl From<trust_graph::Trust> for Trust {
fn from(t: trust_graph::Trust) -> Self {
let issued_for = bs58::encode(t.issued_for.to_bytes()).into_string();
let signature = bs58::encode(t.signature.to_bytes()).into_string();
let issued_for = bs58::encode(t.issued_for.encode()).into_string();
let signature = bs58::encode(t.signature.encode()).into_string();
let expires_at = t.expires_at.as_secs();
let issued_at = t.issued_at.as_secs();
return Trust {

View File

@ -1,4 +1,4 @@
use fluence::WasmLoggerBuilder;
use marine_rs_sdk::WasmLoggerBuilder;
mod dto;
mod results;
@ -8,7 +8,7 @@ mod storage_impl;
pub fn main() {
WasmLoggerBuilder::new()
.with_log_level(log::Level::Info)
.with_log_level(log::LevelFilter::Info)
.build()
.unwrap();
}

View File

@ -1,8 +1,8 @@
use crate::dto::Certificate;
use crate::service_impl::ServiceError;
use fluence::fce;
use marine_rs_sdk::marine;
#[fce]
#[marine]
pub struct InsertResult {
pub ret_code: u32,
pub error: String,
@ -23,7 +23,7 @@ impl From<Result<(), ServiceError>> for InsertResult {
}
}
#[fce]
#[marine]
pub struct WeightResult {
pub ret_code: u32,
pub weight: Vec<u32>,
@ -47,7 +47,7 @@ impl From<Result<Option<u32>, ServiceError>> for WeightResult {
}
}
#[fce]
#[marine]
pub struct AllCertsResult {
pub ret_code: u32,
pub certificates: Vec<Certificate>,
@ -71,7 +71,7 @@ impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
}
}
#[fce]
#[marine]
pub struct AddRootResult {
pub ret_code: u32,
pub error: String,

View File

@ -3,9 +3,9 @@ use crate::results::{AddRootResult, AllCertsResult, InsertResult, WeightResult};
use crate::service_impl::{
add_root_impl, get_all_certs_impl, get_weight_impl, insert_cert_impl, insert_cert_impl_raw,
};
use fluence::{fce, CallParameters};
use marine_rs_sdk::{CallParameters, marine};
#[fce]
#[marine]
/// add a certificate in string representation to trust graph if it is valid
/// see `trust_graph::Certificate` class for string encoding/decoding
// TODO change `current_time` to time service
@ -13,27 +13,27 @@ fn insert_cert_raw(certificate: String, current_time: u64) -> InsertResult {
insert_cert_impl_raw(certificate, current_time).into()
}
#[fce]
#[marine]
/// add a certificate in JSON representation to trust graph if it is valid
/// see `dto::Certificate` class for structure
fn insert_cert(certificate: Certificate, current_time: u64) -> InsertResult {
insert_cert_impl(certificate, current_time).into()
}
#[fce]
#[marine]
fn get_weight(public_key: String) -> WeightResult {
get_weight_impl(public_key).into()
}
#[fce]
#[marine]
fn get_all_certs(issued_for: String) -> AllCertsResult {
get_all_certs_impl(issued_for).into()
}
#[fce]
#[marine]
/// could add only a host of a trust graph service
fn add_root(pk: String, weight: u32) -> AddRootResult {
let call_parameters: CallParameters = fluence::get_call_parameters();
let call_parameters: CallParameters = marine_rs_sdk::get_call_parameters();
let init_peer_id = call_parameters.init_peer_id.clone();
if call_parameters.host_id == init_peer_id {
add_root_impl(pk, weight).into()
@ -45,8 +45,8 @@ fn add_root(pk: String, weight: u32) -> AddRootResult {
}
}
// TODO rewrite test after #[fce_test] will be implemented
// #[fce]
// TODO rewrite test after #[marine_test] will be implemented
// #[marine_test]
// fn test() -> String {
// let mut tg = get_data().lock();
//

View File

@ -1,6 +1,6 @@
use crate::dto::{Certificate, DtoConversionError};
use crate::storage_impl::get_data;
use fluence_identity::public_key::PKError;
use fluence_identity::error::DecodingError;
use fluence_identity::PublicKey;
use std::convert::{Into, TryInto};
use std::str::FromStr;
@ -14,7 +14,7 @@ pub enum ServiceError {
PublicKeyDecodeError(
#[from]
#[source]
PKError,
DecodingError,
),
#[error("{0}")]
TGError(

View File

@ -7,10 +7,10 @@ use crate::storage_impl::SQLiteStorageError::{
WeightConversionDB,
};
use core::convert::TryFrom;
use fce_sqlite_connector;
use fce_sqlite_connector::Connection;
use fce_sqlite_connector::Error as InternalSqliteError;
use fce_sqlite_connector::Value;
use marine_sqlite_connector;
use marine_sqlite_connector::Connection;
use marine_sqlite_connector::Error as InternalSqliteError;
use marine_sqlite_connector::Value;
use fluence_identity::public_key::PublicKey;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
@ -29,7 +29,7 @@ static INSTANCE: OnceCell<Mutex<TrustGraph<SQLiteStorage>>> = OnceCell::new();
pub fn get_data() -> &'static Mutex<TrustGraph<SQLiteStorage>> {
INSTANCE.get_or_init(|| {
let db_path = "/tmp/users123123.sqlite";
let connection = fce_sqlite_connector::open(db_path).unwrap();
let connection = marine_sqlite_connector::open(db_path).unwrap();
let init_sql = "CREATE TABLE IF NOT EXISTS trustnodes(
public_key TEXT PRIMARY KEY,

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
fce build
rm artifacts/trust-graph.wasm
mv -f target/wasm32-wasi/debug/trust-graph.wasm artifacts/
RUST_LOG="info" fce-repl Config.toml