mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 23:30:19 +00:00
push it till it compiles, WIP
serde to structs, wip implementing sqlite requests
This commit is contained in:
parent
0b1b0a82a7
commit
0e2590d894
81
Cargo.lock
generated
81
Cargo.lock
generated
@ -191,6 +191,41 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.3.1"
|
||||
@ -232,6 +267,7 @@ version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"signature",
|
||||
]
|
||||
|
||||
@ -245,6 +281,7 @@ dependencies = [
|
||||
"ed25519",
|
||||
"rand 0.7.3",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"sha2 0.9.2",
|
||||
"zeroize",
|
||||
]
|
||||
@ -580,6 +617,12 @@ dependencies = [
|
||||
"hmac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.0"
|
||||
@ -1160,6 +1203,15 @@ dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bytes"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.118"
|
||||
@ -1182,6 +1234,28 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15f6201e064705553ece353a736a64be975680bd244908cf63e8fa71e478a51a"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_with_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with_macros"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1197ff7de45494f290c1e3e1a6f80e108974681984c87a3e480991ef3d0f1950"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.8.2"
|
||||
@ -1237,6 +1311,12 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "1.0.0"
|
||||
@ -1345,6 +1425,7 @@ dependencies = [
|
||||
"ref-cast",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"signature",
|
||||
]
|
||||
|
||||
|
@ -9,6 +9,7 @@ license = "Apache-2.0"
|
||||
[dependencies]
|
||||
libp2p-core = { package = "fluence-fork-libp2p-core", version = "0.26.0" }
|
||||
serde = { version = "=1.0.118", features = ["derive"] }
|
||||
|
||||
fluence-identity = { path = "identity" }
|
||||
serde_json = "1.0.58"
|
||||
bs58 = "0.3.1"
|
||||
@ -16,6 +17,7 @@ failure = "0.1.6"
|
||||
log = "0.4.11"
|
||||
ref-cast = "1.0.2"
|
||||
derivative = "2.1.1"
|
||||
ed25519-dalek = "1.0.1"
|
||||
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
|
||||
rand = "0.7.0"
|
||||
signature = "1.3.0"
|
||||
serde_with = "1.6.0"
|
||||
|
82
bin/Cargo.lock
generated
82
bin/Cargo.lock
generated
@ -197,6 +197,41 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.3.1"
|
||||
@ -238,6 +273,7 @@ version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"signature",
|
||||
]
|
||||
|
||||
@ -251,6 +287,7 @@ dependencies = [
|
||||
"ed25519",
|
||||
"rand 0.7.3",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"sha2 0.9.2",
|
||||
"zeroize",
|
||||
]
|
||||
@ -639,6 +676,12 @@ dependencies = [
|
||||
"hmac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.0"
|
||||
@ -1219,6 +1262,15 @@ dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bytes"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.118"
|
||||
@ -1241,6 +1293,28 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15f6201e064705553ece353a736a64be975680bd244908cf63e8fa71e478a51a"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_with_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_with_macros"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1197ff7de45494f290c1e3e1a6f80e108974681984c87a3e480991ef3d0f1950"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.8.2"
|
||||
@ -1296,6 +1370,12 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "1.0.0"
|
||||
@ -1404,6 +1484,7 @@ dependencies = [
|
||||
"ref-cast",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"signature",
|
||||
]
|
||||
|
||||
@ -1419,6 +1500,7 @@ dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"serde_json",
|
||||
"trust-graph",
|
||||
]
|
||||
|
||||
|
@ -20,3 +20,4 @@ boolinator = "2.4.0"
|
||||
once_cell = "1.4.1"
|
||||
parking_lot = "0.11.1"
|
||||
fce-sqlite-connector = "0.1.3"
|
||||
serde_json = "1.0"
|
||||
|
@ -1,7 +1,7 @@
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
mod storage_impl;
|
||||
mod service_api;
|
||||
mod storage_impl;
|
||||
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new()
|
||||
|
@ -2,13 +2,14 @@
|
||||
// check if trust is already in list before adding
|
||||
// if there is an older trust - don't add received trust
|
||||
|
||||
use trust_graph::{Storage, TrustGraph, PublicKeyHashable, TrustNode, Weight, Auth, Revoke};
|
||||
use fce_sqlite_connector;
|
||||
use fce_sqlite_connector::Value;
|
||||
use fce_sqlite_connector::{Connection, State};
|
||||
use fluence_identity::public_key::PublicKey;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use std::time::Duration;
|
||||
use fce_sqlite_connector;
|
||||
use fce_sqlite_connector::{State, Connection};
|
||||
use trust_graph::{Auth, PublicKeyHashable, Revoke, Storage, TrustGraph, TrustNode, Weight};
|
||||
|
||||
static INSTANCE: OnceCell<Mutex<TrustGraph>> = OnceCell::new();
|
||||
|
||||
@ -26,12 +27,12 @@ struct SqliteStorage {
|
||||
|
||||
impl SqliteStorage {
|
||||
pub fn init(&self) {
|
||||
let init_sql = "CREATE TABLE IF NOT EXISTS trusts(\
|
||||
peer_id TEXT PRIMARY KEY,\
|
||||
relay TEXT NOT NULL,\
|
||||
sig TEXT NOT NULL,\
|
||||
name TEXT NOT NULL\
|
||||
let init_sql = "CREATE TABLE IF NOT EXISTS trustnodes(\
|
||||
public_key TEXT PRIMARY KEY,\
|
||||
trustnode TEXT NOT NULL,\
|
||||
);";
|
||||
|
||||
self.connection.execute(init_sql).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,22 +40,38 @@ impl Storage for SqliteStorage {
|
||||
fn get(&self, pk: &PublicKeyHashable) -> Option<&TrustNode> {
|
||||
None
|
||||
}
|
||||
fn insert(&mut self, pk: PublicKeyHashable, node: TrustNode) {
|
||||
|
||||
fn insert(&mut self, pk: PublicKeyHashable, node: TrustNode) {
|
||||
let mut cursor = self
|
||||
.connection
|
||||
.prepare("INSERT INTO trustnodes VALUES (?, ?)")
|
||||
.unwrap()
|
||||
.cursor();
|
||||
|
||||
let tn_str = serde_json::to_string(&node).unwrap();
|
||||
|
||||
cursor.bind(&[Value::String(format!("{}", pk))]).unwrap();
|
||||
cursor
|
||||
.bind(&[Value::String(format!("{}", tn_str))])
|
||||
.unwrap();
|
||||
|
||||
cursor.next().unwrap();
|
||||
}
|
||||
|
||||
fn get_root_weight(&self, pk: &PublicKeyHashable) -> Option<&Weight> {
|
||||
None
|
||||
}
|
||||
fn add_root_weight(&mut self, pk: PublicKeyHashable, weight: Weight) {
|
||||
|
||||
}
|
||||
fn add_root_weight(&mut self, pk: PublicKeyHashable, weight: Weight) {}
|
||||
|
||||
fn root_keys(&self) -> Vec<PublicKeyHashable> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn revoke(&mut self, pk: &PublicKeyHashable, revoke: Revoke) -> Result<(), String> {
|
||||
Err("not implemented".to_string())
|
||||
}
|
||||
|
||||
fn update_auth(
|
||||
&mut self,
|
||||
pk: &PublicKeyHashable,
|
||||
@ -62,6 +79,5 @@ impl Storage for SqliteStorage {
|
||||
issued_for: &PublicKey,
|
||||
cur_time: Duration,
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
11
identity/Cargo.lock
generated
11
identity/Cargo.lock
generated
@ -192,6 +192,7 @@ version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"signature",
|
||||
]
|
||||
|
||||
@ -205,6 +206,7 @@ dependencies = [
|
||||
"ed25519",
|
||||
"rand 0.7.3",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"sha2 0.9.2",
|
||||
"zeroize",
|
||||
]
|
||||
@ -1050,6 +1052,15 @@ dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bytes"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.118"
|
||||
|
@ -11,7 +11,7 @@ libp2p-core = { package = "fluence-fork-libp2p-core", version = "0.26.0" }
|
||||
serde = { version = "=1.0.118", features = ["derive"] }
|
||||
serde_json = "1.0.58"
|
||||
bs58 = "0.3.1"
|
||||
ed25519-dalek = "1.0.1"
|
||||
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
|
||||
rand = "0.7.0"
|
||||
signature = "1.3.0"
|
||||
ed25519 = "1.0.3"
|
||||
|
@ -17,8 +17,9 @@
|
||||
use crate::signature::Signature;
|
||||
use core::fmt::Debug;
|
||||
use ed25519_dalek::SignatureError;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Copy, Clone, Default, Eq, PartialEq)]
|
||||
#[derive(Copy, Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PublicKey(pub(crate) ed25519_dalek::PublicKey);
|
||||
|
||||
impl Debug for PublicKey {
|
||||
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
|
||||
use ed25519_dalek::SignatureError;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SecretKey(ed25519_dalek::SecretKey);
|
||||
|
||||
impl SecretKey {
|
||||
|
@ -15,8 +15,9 @@
|
||||
*/
|
||||
|
||||
use signature::Signature as SigSignature;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Signature(pub ed25519_dalek::Signature);
|
||||
|
||||
pub const SIGNATURE_LENGTH: usize = 64;
|
||||
|
@ -22,6 +22,7 @@ use std::{
|
||||
fmt::{Display, Formatter},
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
use serde::ser::{Serializer};
|
||||
|
||||
/// Wrapper to use PublicKey in HashMap
|
||||
#[derive(PartialEq, Eq, Debug, Clone, RefCast)]
|
||||
@ -79,6 +80,14 @@ impl Display for PublicKeyHashable {
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for PublicKeyHashable {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer {
|
||||
serializer.serialize_bytes(&self.0.to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> serde::Deserialize<'de> for PublicKeyHashable {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
|
@ -19,10 +19,11 @@ use fluence_identity::key_pair::KeyPair;
|
||||
use fluence_identity::public_key::PublicKey;
|
||||
use fluence_identity::signature::Signature;
|
||||
use std::time::Duration;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
/// "A document" that cancels trust created before.
|
||||
/// TODO delete pk from Revoke (it is already in a trust node)
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Revoke {
|
||||
/// who is revoked
|
||||
pub pk: PublicKey,
|
||||
|
@ -20,6 +20,7 @@ use fluence_identity::public_key::PublicKey;
|
||||
use fluence_identity::signature::Signature;
|
||||
use std::convert::TryInto;
|
||||
use std::time::Duration;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
pub const SIG_LEN: usize = 64;
|
||||
pub const PK_LEN: usize = 32;
|
||||
@ -30,7 +31,7 @@ pub const TRUST_LEN: usize = SIG_LEN + PK_LEN + EXPIRATION_LEN + ISSUED_LEN;
|
||||
|
||||
/// One element in chain of trust in a certificate.
|
||||
/// TODO delete pk from Trust (it is already in a trust node)
|
||||
#[derive(Clone, PartialEq, Derivative, Eq)]
|
||||
#[derive(Clone, PartialEq, Derivative, Eq, Serialize, Deserialize)]
|
||||
#[derivative(Debug)]
|
||||
pub struct Trust {
|
||||
/// For whom this certificate is issued
|
||||
|
@ -20,8 +20,10 @@ use crate::trust::Trust;
|
||||
use failure::_core::time::Duration;
|
||||
use fluence_identity::public_key::PublicKey;
|
||||
use std::collections::HashMap;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_with::serde_as;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
enum TrustRelation {
|
||||
Auth(Auth),
|
||||
Revoke(Revoke),
|
||||
@ -46,7 +48,7 @@ impl TrustRelation {
|
||||
}
|
||||
|
||||
/// Represents who give a certificate
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Auth {
|
||||
/// proof of this authorization
|
||||
pub trust: Trust,
|
||||
@ -56,12 +58,14 @@ pub struct Auth {
|
||||
|
||||
/// An element of trust graph that store relations (trust or revoke)
|
||||
/// that given by some owners of public keys.
|
||||
#[derive(Debug)]
|
||||
#[serde_as]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct TrustNode {
|
||||
/// identity key of this element
|
||||
pub pk: PublicKey,
|
||||
|
||||
/// one public key could be authorized or revoked by multiple certificates
|
||||
#[serde_as(as = "Vec<(_, _)>")]
|
||||
trust_relations: HashMap<PublicKeyHashable, TrustRelation>,
|
||||
|
||||
/// for maintain
|
||||
|
Loading…
Reference in New Issue
Block a user