fmt, bin sub project for wasm

This commit is contained in:
DieMyst 2021-01-19 17:25:28 +03:00
parent dd761dd61c
commit 37de2ff336
12 changed files with 38 additions and 32 deletions

1
bin/Cargo.lock generated
View File

@ -1400,6 +1400,7 @@ name = "trust-graph-wasm"
version = "0.2.0"
dependencies = [
"fluence",
"log",
"trust-graph",
]

View File

@ -12,4 +12,5 @@ path = "src/main.rs"
[dependencies]
trust-graph = { path = "../" }
log = "0.4.8"
fluence = { version = "0.2.18", features = ["logger"] }

View File

@ -1,7 +1,5 @@
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)

View File

@ -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;
@ -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 },
}
}
}

View File

@ -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)

View File

@ -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)]
@ -82,7 +82,8 @@ impl Display for PublicKeyHashable {
impl<'de> serde::Deserialize<'de> for PublicKeyHashable {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de> {
D: serde::Deserializer<'de>,
{
use serde::de::{Error, Visitor};
struct PKVisitor;
@ -102,7 +103,9 @@ impl <'de>serde::Deserialize<'de> for PublicKeyHashable {
.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>

View File

@ -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.

View File

@ -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())
}

View File

@ -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 {

View File

@ -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;