mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 15:20:19 +00:00
fmt, bin sub project for wasm
This commit is contained in:
parent
dd761dd61c
commit
37de2ff336
1
bin/Cargo.lock
generated
1
bin/Cargo.lock
generated
@ -1400,6 +1400,7 @@ name = "trust-graph-wasm"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"fluence",
|
||||
"log",
|
||||
"trust-graph",
|
||||
]
|
||||
|
||||
|
@ -12,4 +12,5 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
trust-graph = { path = "../" }
|
||||
log = "0.4.8"
|
||||
fluence = { version = "0.2.18", features = ["logger"] }
|
@ -1,10 +1,8 @@
|
||||
use fluence::WasmLoggerBuilder;
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, errors::HistoryError>;
|
||||
|
||||
pub fn main() {
|
||||
WasmLoggerBuilder::new()
|
||||
.with_log_level(log::Level::Info)
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
}
|
@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::ed25519::{Keypair as Libp2pKeyPair};
|
||||
use crate::ed25519::Keypair as Libp2pKeyPair;
|
||||
use ed25519_dalek::SignatureError;
|
||||
use ed25519_dalek::{PublicKey, Signer, SecretKey};
|
||||
use ed25519_dalek::{PublicKey, SecretKey, Signer};
|
||||
|
||||
use core::fmt::{Debug};
|
||||
use std::fmt;
|
||||
use core::fmt::Debug;
|
||||
use rand::rngs::OsRng;
|
||||
use std::fmt;
|
||||
|
||||
pub type Signature = ed25519_dalek::Signature;
|
||||
|
||||
@ -34,14 +34,14 @@ impl KeyPair {
|
||||
/// Generate a new Ed25519 keypair.
|
||||
#[allow(dead_code)]
|
||||
pub fn generate() -> Self {
|
||||
let mut csprng = OsRng { };
|
||||
let mut csprng = OsRng {};
|
||||
let kp = ed25519_dalek::Keypair::generate(&mut csprng);
|
||||
kp.into()
|
||||
}
|
||||
|
||||
pub fn from_bytes(sk_bytes: &[u8]) -> Result<Self, SignatureError> {
|
||||
let kp = ed25519_dalek::Keypair::from_bytes(sk_bytes)?;
|
||||
Ok(KeyPair {key_pair: kp})
|
||||
Ok(KeyPair { key_pair: kp })
|
||||
}
|
||||
|
||||
/// Encode the keypair into a byte array by concatenating the bytes
|
||||
@ -55,9 +55,7 @@ impl KeyPair {
|
||||
#[allow(dead_code)]
|
||||
pub fn decode(kp: &[u8]) -> Result<KeyPair, SignatureError> {
|
||||
let kp = ed25519_dalek::Keypair::from_bytes(kp)?;
|
||||
Ok(Self {
|
||||
key_pair: kp,
|
||||
})
|
||||
Ok(Self { key_pair: kp })
|
||||
}
|
||||
|
||||
/// Get the public key of this keypair.
|
||||
@ -142,6 +140,8 @@ impl Clone for KeyPair {
|
||||
.expect("ed25519::SecretKey::from_bytes(to_bytes(k)) != k");
|
||||
let public = PublicKey::from_bytes(&self.key_pair.public.to_bytes())
|
||||
.expect("ed25519::PublicKey::from_bytes(to_bytes(k)) != k");
|
||||
KeyPair { key_pair: ed25519_dalek::Keypair { secret, public } }
|
||||
KeyPair {
|
||||
key_pair: ed25519_dalek::Keypair { secret, public },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::trust::{Trust, TRUST_LEN};
|
||||
use ed25519_dalek::PublicKey;
|
||||
use fluence_identity::key_pair::KeyPair;
|
||||
use crate::trust::{Trust, TRUST_LEN};
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
@ -236,8 +236,8 @@ impl FromStr for Certificate {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::misc::current_time;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use fluence_identity::key_pair::KeyPair;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub fn one_second() -> Duration {
|
||||
Duration::from_secs(1)
|
||||
|
@ -16,12 +16,12 @@
|
||||
|
||||
use ed25519_dalek::PublicKey;
|
||||
|
||||
use core::fmt;
|
||||
use ref_cast::RefCast;
|
||||
use std::{
|
||||
fmt::{Display, Formatter},
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
use core::fmt;
|
||||
|
||||
/// Wrapper to use PublicKey in HashMap
|
||||
#[derive(PartialEq, Eq, Debug, Clone, RefCast)]
|
||||
@ -79,10 +79,11 @@ impl Display for PublicKeyHashable {
|
||||
}
|
||||
}
|
||||
|
||||
impl <'de>serde::Deserialize<'de> for PublicKeyHashable {
|
||||
impl<'de> serde::Deserialize<'de> for PublicKeyHashable {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de> {
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
use serde::de::{Error, Visitor};
|
||||
|
||||
struct PKVisitor;
|
||||
@ -95,19 +96,21 @@ impl <'de>serde::Deserialize<'de> for PublicKeyHashable {
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
bs58::decode(s)
|
||||
.into_vec()
|
||||
.map_err(|err| Error::custom(format!("Invalid string '{}': {}", s, err)))
|
||||
.and_then(|v| self.visit_bytes(v.as_slice()))
|
||||
.map_err(|err: E| Error::custom(format!("Parsed string '{}' as base58, but {}", s, err)))
|
||||
.map_err(|err: E| {
|
||||
Error::custom(format!("Parsed string '{}' as base58, but {}", s, err))
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_bytes<E>(self, b: &[u8]) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let pk = PublicKey::from_bytes(b)
|
||||
.map_err(|err| Error::custom(format!("Invalid bytes {:?}: {}", b, err)))?;
|
||||
|
@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::trust::{EXPIRATION_LEN, PK_LEN};
|
||||
use ed25519_dalek::PublicKey;
|
||||
use fluence_identity::key_pair::KeyPair;
|
||||
use fluence_identity::key_pair::Signature;
|
||||
use crate::trust::{EXPIRATION_LEN, PK_LEN};
|
||||
use std::time::Duration;
|
||||
|
||||
/// "A document" that cancels trust created before.
|
||||
|
11
src/trust.rs
11
src/trust.rs
@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use ed25519_dalek::{PublicKey};
|
||||
use fluence_identity::key_pair::{KeyPair, Signature};
|
||||
use derivative::Derivative;
|
||||
use ed25519_dalek::PublicKey;
|
||||
use fluence_identity::key_pair::{KeyPair, Signature};
|
||||
use signature::Signature as SigSignature;
|
||||
use std::convert::TryInto;
|
||||
use std::time::Duration;
|
||||
use signature::{Signature as SigSignature};
|
||||
|
||||
pub const SIG_LEN: usize = 64;
|
||||
pub const PK_LEN: usize = 32;
|
||||
@ -50,7 +50,10 @@ fn show_pubkey(key: &PublicKey, f: &mut std::fmt::Formatter<'_>) -> Result<(), s
|
||||
write!(f, "{}", bs58::encode(&key.to_bytes()).into_string())
|
||||
}
|
||||
|
||||
fn show_sig(sig: &ed25519_dalek::Signature, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
fn show_sig(
|
||||
sig: &ed25519_dalek::Signature,
|
||||
f: &mut std::fmt::Formatter<'_>,
|
||||
) -> Result<(), std::fmt::Error> {
|
||||
write!(f, "{}", bs58::encode(&sig.to_bytes()).into_string())
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
|
||||
use crate::certificate::Certificate;
|
||||
use ed25519_dalek::PublicKey;
|
||||
use crate::public_key_hashable::PublicKeyHashable;
|
||||
use crate::revoke::Revoke;
|
||||
use crate::trust::Trust;
|
||||
use crate::trust_graph_storage::Storage;
|
||||
use crate::trust_node::{Auth, TrustNode};
|
||||
use ed25519_dalek::PublicKey;
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::time::Duration;
|
||||
@ -279,10 +279,10 @@ impl TrustGraph {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use fluence_identity::key_pair::KeyPair;
|
||||
use crate::misc::current_time;
|
||||
use crate::trust_graph_storage::InMemoryStorage;
|
||||
use failure::_core::time::Duration;
|
||||
use fluence_identity::key_pair::KeyPair;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn one_minute() -> Duration {
|
||||
|
@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use ed25519_dalek::PublicKey;
|
||||
use crate::public_key_hashable::PublicKeyHashable;
|
||||
use crate::revoke::Revoke;
|
||||
use crate::trust::Trust;
|
||||
use ed25519_dalek::PublicKey;
|
||||
use failure::_core::time::Duration;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user