mirror of
https://github.com/fluencelabs/trust-graph-test
synced 2025-04-25 06:22:20 +00:00
wip
This commit is contained in:
parent
cbcca20566
commit
190fcc16e7
529
Cargo.lock
generated
529
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -19,14 +19,17 @@ log = "0.4.11"
|
|||||||
ref-cast = "1.0.2"
|
ref-cast = "1.0.2"
|
||||||
derivative = "2.1.1"
|
derivative = "2.1.1"
|
||||||
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
|
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
|
||||||
rand = "0.7.0"
|
|
||||||
signature = "1.3.0"
|
signature = "1.3.0"
|
||||||
serde_with = "1.6.0"
|
serde_with = "1.6.0"
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.23"
|
||||||
libsecp256k1 = "0.3.5"
|
libsecp256k1 = "0.3.5"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
ring = "0.16.20"
|
ring = "0.16.20"
|
||||||
|
rand = "0.7.0"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"identity"
|
"identity",
|
||||||
|
"service"
|
||||||
]
|
]
|
||||||
|
@ -19,12 +19,14 @@ serde_with = "1.6.0"
|
|||||||
thiserror = "1.0.23"
|
thiserror = "1.0.23"
|
||||||
lazy_static = "1.2"
|
lazy_static = "1.2"
|
||||||
libsecp256k1 = "0.3.5"
|
libsecp256k1 = "0.3.5"
|
||||||
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
|
|
||||||
asn1_der = "0.6.1"
|
asn1_der = "0.6.1"
|
||||||
sha2 = "0.9.1"
|
sha2 = "0.9.1"
|
||||||
zeroize = "1"
|
zeroize = "1"
|
||||||
serde_bytes = "0.11"
|
serde_bytes = "0.11"
|
||||||
libp2p-core = { package = "fluence-fork-libp2p-core", version = "0.27.2" }
|
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]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9.0"
|
quickcheck = "0.9.0"
|
||||||
|
0
wasm/Cargo.lock → service/Cargo.lock
generated
0
wasm/Cargo.lock → service/Cargo.lock
generated
@ -11,15 +11,16 @@ name = "trust-graph"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
trust-graph = { version = "0.2.1", path = "../" }
|
trust-graph = { version = "0.2.6", path = "../." }
|
||||||
fluence-identity = { version = "0.2.1", path = "../identity" }
|
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"
|
log = "0.4.8"
|
||||||
fluence = { version = "0.2.18", features = ["logger"] }
|
|
||||||
anyhow = "1.0.31"
|
anyhow = "1.0.31"
|
||||||
boolinator = "2.4.0"
|
boolinator = "2.4.0"
|
||||||
once_cell = "1.4.1"
|
once_cell = "1.4.1"
|
||||||
parking_lot = "0.11.1"
|
parking_lot = "0.11.1"
|
||||||
fce-sqlite-connector = "0.1.3"
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
bs58 = "0.3.1"
|
bs58 = "0.3.1"
|
||||||
rmp-serde = "0.15.0"
|
rmp-serde = "0.15.0"
|
14
service/build.sh
Executable file
14
service/build.sh
Executable 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
5
service/run-repl.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
./build.sh
|
||||||
|
RUST_LOG="info" fce-repl Config.toml
|
@ -1,6 +1,5 @@
|
|||||||
use fluence::fce;
|
use marine_rs_sdk::marine;
|
||||||
use fluence_identity::public_key::PKError;
|
use fluence_identity::error::DecodingError;
|
||||||
use fluence_identity::signature::SignatureError;
|
|
||||||
use fluence_identity::{PublicKey, Signature};
|
use fluence_identity::{PublicKey, Signature};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -18,17 +17,11 @@ pub enum DtoConversionError {
|
|||||||
PublicKeyDecodeError(
|
PublicKeyDecodeError(
|
||||||
#[from]
|
#[from]
|
||||||
#[source]
|
#[source]
|
||||||
PKError,
|
DecodingError,
|
||||||
),
|
|
||||||
#[error("Cannot convert string to PublicKey: {0}")]
|
|
||||||
SignatureDecodeError(
|
|
||||||
#[from]
|
|
||||||
#[source]
|
|
||||||
SignatureError,
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
pub struct Certificate {
|
pub struct Certificate {
|
||||||
pub chain: Vec<Trust>,
|
pub chain: Vec<Trust>,
|
||||||
}
|
}
|
||||||
@ -54,7 +47,7 @@ impl TryFrom<Certificate> for trust_graph::Certificate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
pub struct Trust {
|
pub struct Trust {
|
||||||
/// For whom this certificate is issued, base58
|
/// For whom this certificate is issued, base58
|
||||||
pub issued_for: String,
|
pub issued_for: String,
|
||||||
@ -73,7 +66,7 @@ impl TryFrom<Trust> for trust_graph::Trust {
|
|||||||
fn try_from(t: Trust) -> Result<Self, Self::Error> {
|
fn try_from(t: Trust) -> Result<Self, Self::Error> {
|
||||||
let issued_for = PublicKey::from_base58(&t.issued_for)?;
|
let issued_for = PublicKey::from_base58(&t.issued_for)?;
|
||||||
let signature = bs58::decode(&t.signature).into_vec()?;
|
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 expires_at = Duration::from_secs(t.expires_at);
|
||||||
let issued_at = Duration::from_secs(t.issued_at);
|
let issued_at = Duration::from_secs(t.issued_at);
|
||||||
return Ok(trust_graph::Trust {
|
return Ok(trust_graph::Trust {
|
||||||
@ -87,8 +80,8 @@ impl TryFrom<Trust> for trust_graph::Trust {
|
|||||||
|
|
||||||
impl From<trust_graph::Trust> for Trust {
|
impl From<trust_graph::Trust> for Trust {
|
||||||
fn from(t: trust_graph::Trust) -> Self {
|
fn from(t: trust_graph::Trust) -> Self {
|
||||||
let issued_for = bs58::encode(t.issued_for.to_bytes()).into_string();
|
let issued_for = bs58::encode(t.issued_for.encode()).into_string();
|
||||||
let signature = bs58::encode(t.signature.to_bytes()).into_string();
|
let signature = bs58::encode(t.signature.encode()).into_string();
|
||||||
let expires_at = t.expires_at.as_secs();
|
let expires_at = t.expires_at.as_secs();
|
||||||
let issued_at = t.issued_at.as_secs();
|
let issued_at = t.issued_at.as_secs();
|
||||||
return Trust {
|
return Trust {
|
@ -1,4 +1,4 @@
|
|||||||
use fluence::WasmLoggerBuilder;
|
use marine_rs_sdk::WasmLoggerBuilder;
|
||||||
|
|
||||||
mod dto;
|
mod dto;
|
||||||
mod results;
|
mod results;
|
||||||
@ -8,7 +8,7 @@ mod storage_impl;
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
WasmLoggerBuilder::new()
|
WasmLoggerBuilder::new()
|
||||||
.with_log_level(log::Level::Info)
|
.with_log_level(log::LevelFilter::Info)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
use crate::dto::Certificate;
|
use crate::dto::Certificate;
|
||||||
use crate::service_impl::ServiceError;
|
use crate::service_impl::ServiceError;
|
||||||
use fluence::fce;
|
use marine_rs_sdk::marine;
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
pub struct InsertResult {
|
pub struct InsertResult {
|
||||||
pub ret_code: u32,
|
pub ret_code: u32,
|
||||||
pub error: String,
|
pub error: String,
|
||||||
@ -23,7 +23,7 @@ impl From<Result<(), ServiceError>> for InsertResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
pub struct WeightResult {
|
pub struct WeightResult {
|
||||||
pub ret_code: u32,
|
pub ret_code: u32,
|
||||||
pub weight: Vec<u32>,
|
pub weight: Vec<u32>,
|
||||||
@ -47,7 +47,7 @@ impl From<Result<Option<u32>, ServiceError>> for WeightResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
pub struct AllCertsResult {
|
pub struct AllCertsResult {
|
||||||
pub ret_code: u32,
|
pub ret_code: u32,
|
||||||
pub certificates: Vec<Certificate>,
|
pub certificates: Vec<Certificate>,
|
||||||
@ -71,7 +71,7 @@ impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
pub struct AddRootResult {
|
pub struct AddRootResult {
|
||||||
pub ret_code: u32,
|
pub ret_code: u32,
|
||||||
pub error: String,
|
pub error: String,
|
@ -3,9 +3,9 @@ use crate::results::{AddRootResult, AllCertsResult, InsertResult, WeightResult};
|
|||||||
use crate::service_impl::{
|
use crate::service_impl::{
|
||||||
add_root_impl, get_all_certs_impl, get_weight_impl, insert_cert_impl, insert_cert_impl_raw,
|
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
|
/// add a certificate in string representation to trust graph if it is valid
|
||||||
/// see `trust_graph::Certificate` class for string encoding/decoding
|
/// see `trust_graph::Certificate` class for string encoding/decoding
|
||||||
// TODO change `current_time` to time service
|
// 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()
|
insert_cert_impl_raw(certificate, current_time).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
/// add a certificate in JSON representation to trust graph if it is valid
|
/// add a certificate in JSON representation to trust graph if it is valid
|
||||||
/// see `dto::Certificate` class for structure
|
/// see `dto::Certificate` class for structure
|
||||||
fn insert_cert(certificate: Certificate, current_time: u64) -> InsertResult {
|
fn insert_cert(certificate: Certificate, current_time: u64) -> InsertResult {
|
||||||
insert_cert_impl(certificate, current_time).into()
|
insert_cert_impl(certificate, current_time).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
fn get_weight(public_key: String) -> WeightResult {
|
fn get_weight(public_key: String) -> WeightResult {
|
||||||
get_weight_impl(public_key).into()
|
get_weight_impl(public_key).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
fn get_all_certs(issued_for: String) -> AllCertsResult {
|
fn get_all_certs(issued_for: String) -> AllCertsResult {
|
||||||
get_all_certs_impl(issued_for).into()
|
get_all_certs_impl(issued_for).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[marine]
|
||||||
/// could add only a host of a trust graph service
|
/// could add only a host of a trust graph service
|
||||||
fn add_root(pk: String, weight: u32) -> AddRootResult {
|
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();
|
let init_peer_id = call_parameters.init_peer_id.clone();
|
||||||
if call_parameters.host_id == init_peer_id {
|
if call_parameters.host_id == init_peer_id {
|
||||||
add_root_impl(pk, weight).into()
|
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
|
// TODO rewrite test after #[marine_test] will be implemented
|
||||||
// #[fce]
|
// #[marine_test]
|
||||||
// fn test() -> String {
|
// fn test() -> String {
|
||||||
// let mut tg = get_data().lock();
|
// let mut tg = get_data().lock();
|
||||||
//
|
//
|
@ -1,6 +1,6 @@
|
|||||||
use crate::dto::{Certificate, DtoConversionError};
|
use crate::dto::{Certificate, DtoConversionError};
|
||||||
use crate::storage_impl::get_data;
|
use crate::storage_impl::get_data;
|
||||||
use fluence_identity::public_key::PKError;
|
use fluence_identity::error::DecodingError;
|
||||||
use fluence_identity::PublicKey;
|
use fluence_identity::PublicKey;
|
||||||
use std::convert::{Into, TryInto};
|
use std::convert::{Into, TryInto};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -14,7 +14,7 @@ pub enum ServiceError {
|
|||||||
PublicKeyDecodeError(
|
PublicKeyDecodeError(
|
||||||
#[from]
|
#[from]
|
||||||
#[source]
|
#[source]
|
||||||
PKError,
|
DecodingError,
|
||||||
),
|
),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
TGError(
|
TGError(
|
@ -7,10 +7,10 @@ use crate::storage_impl::SQLiteStorageError::{
|
|||||||
WeightConversionDB,
|
WeightConversionDB,
|
||||||
};
|
};
|
||||||
use core::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
use fce_sqlite_connector;
|
use marine_sqlite_connector;
|
||||||
use fce_sqlite_connector::Connection;
|
use marine_sqlite_connector::Connection;
|
||||||
use fce_sqlite_connector::Error as InternalSqliteError;
|
use marine_sqlite_connector::Error as InternalSqliteError;
|
||||||
use fce_sqlite_connector::Value;
|
use marine_sqlite_connector::Value;
|
||||||
use fluence_identity::public_key::PublicKey;
|
use fluence_identity::public_key::PublicKey;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@ -29,7 +29,7 @@ static INSTANCE: OnceCell<Mutex<TrustGraph<SQLiteStorage>>> = OnceCell::new();
|
|||||||
pub fn get_data() -> &'static Mutex<TrustGraph<SQLiteStorage>> {
|
pub fn get_data() -> &'static Mutex<TrustGraph<SQLiteStorage>> {
|
||||||
INSTANCE.get_or_init(|| {
|
INSTANCE.get_or_init(|| {
|
||||||
let db_path = "/tmp/users123123.sqlite";
|
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(
|
let init_sql = "CREATE TABLE IF NOT EXISTS trustnodes(
|
||||||
public_key TEXT PRIMARY KEY,
|
public_key TEXT PRIMARY KEY,
|
@ -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
|
|
Loading…
x
Reference in New Issue
Block a user