Skip to content

Commit

Permalink
Interactive CLI for demo (#17)
Browse files Browse the repository at this point in the history
* delete pks

* refactor

* update ciphersuite

* add draft cli interface

* add ui

* change to read file

* fix problem with threads, add error handler

* add graceful shutdown
  • Loading branch information
seemenkina authored Jul 18, 2024
1 parent 62f15d2 commit 4774e57
Show file tree
Hide file tree
Showing 16 changed files with 1,547 additions and 1,851 deletions.
20 changes: 17 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,37 @@ openmls_rust_crypto = "=0.2.0"
openmls_traits = "=0.2.0"

# waku-bindings = "0.6.0"
bus = "=2.4.1"
tokio = { version = "=1.38.0", features = ["macros", "rt-multi-thread"] }
tokio = { version = "=1.38.0", features = [
"macros",
"rt-multi-thread",
"full",
] }
tokio-util = "=0.7.11"
alloy = { git = "https://github.com/alloy-rs/alloy", features = [
"providers",
"node-bindings",
"network",
"transports",
"k256",
] }
fred = { version = "=9.0.3", features = ["subscriber-client"] }

rand = "=0.8.5"
serde_json = "=1.0"
url = "=2.5.2"
tls_codec = "=0.3.0"
hex = "=0.4.3"

shlex = "=1.3.0"
clap = { version = "=4.5.8", features = ["derive"] }

anyhow = "=1.0.71"
anyhow = "=1.0.81"
thiserror = "=1.0.61"

crossterm = "=0.27.0"
ratatui = "=0.27.0"
textwrap = "=0.16.1"

ds = { path = "ds" }
sc_key_store = { path = "sc_key_store" }
mls_crypto = { path = "mls_crypto" }
199 changes: 79 additions & 120 deletions crates/bindings/src/deploy.rs

Large diffs are not rendered by default.

461 changes: 179 additions & 282 deletions crates/bindings/src/deploymentconfig.rs

Large diffs are not rendered by default.

583 changes: 229 additions & 354 deletions crates/bindings/src/isckeystore.rs

Large diffs are not rendered by default.

1,001 changes: 336 additions & 665 deletions crates/bindings/src/sckeystore.rs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion ds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ tokio = "=1.38.0"
openmls = { version = "=0.5.0", features = ["test-utils"] }
rand = { version = "^0.8" }

anyhow = "=1.0.71"
anyhow = "=1.0.81"
thiserror = "=1.0.61"

tls_codec = "=0.3.0"
serde_json = "=1.0"
serde = "=1.0.204"

sc_key_store = { path = "../sc_key_store" }
57 changes: 33 additions & 24 deletions ds/src/ds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,44 @@ use fred::{
prelude::*,
types::Message,
};

use serde::{Deserialize, Serialize};
use tokio::sync::broadcast::{error::RecvError, Receiver};

use openmls::{
framing::{MlsMessageIn, MlsMessageOut},
prelude::{TlsDeserializeTrait, TlsSerializeTrait},
};
use openmls::{framing::MlsMessageOut, prelude::TlsSerializeTrait};
// use waku_bindings::*;

pub struct RClient {
group_id: String,
client: RedisClient,
sub_client: SubscriberClient,
broadcaster: Receiver<Message>,
// broadcaster: Receiver<Message>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SenderStruct {
pub sender: String,
pub msg: Vec<u8>,
}

impl RClient {
pub async fn new_for_group(group_id: String) -> Result<Self, DeliveryServiceError> {
pub async fn new_for_group(
group_id: String,
) -> Result<(Self, Receiver<Message>), DeliveryServiceError> {
let redis_client = RedisClient::default();
let subscriber: SubscriberClient =
Builder::default_centralized().build_subscriber_client()?;
redis_client.init().await?;
subscriber.init().await?;
subscriber.subscribe(group_id.clone()).await?;
Ok(RClient {
group_id,
client: redis_client,
sub_client: subscriber.clone(),
broadcaster: subscriber.message_rx(),
})
Ok((
RClient {
group_id,
client: redis_client,
sub_client: subscriber.clone(),
// broadcaster: subscriber.message_rx(),
},
subscriber.message_rx(),
))
}

pub async fn remove_from_group(&mut self) -> Result<(), DeliveryServiceError> {
Expand All @@ -43,30 +51,31 @@ impl RClient {
Ok(())
}

pub async fn msg_send(&mut self, msg: MlsMessageOut) -> Result<(), DeliveryServiceError> {
pub async fn msg_send(
&mut self,
msg: MlsMessageOut,
sender: String,
) -> Result<(), DeliveryServiceError> {
let buf = msg.tls_serialize_detached()?;

let json_value = SenderStruct { sender, msg: buf };
let bytes = serde_json::to_vec(&json_value)?;
self.client
.publish(self.group_id.clone(), buf.as_slice())
.publish(self.group_id.clone(), bytes.as_slice())
.await?;

Ok(())
}

pub async fn msg_recv(&mut self) -> Result<MlsMessageIn, DeliveryServiceError> {
// check only one message
let msg = self.broadcaster.recv().await?;
let bytes: Vec<u8> = msg.value.convert()?;
let res = MlsMessageIn::tls_deserialize_bytes(bytes)?;
Ok(res)
}
}

#[derive(Debug, thiserror::Error)]
pub enum DeliveryServiceError {
#[error("Json error: {0}")]
JsonError(#[from] serde_json::Error),
#[error("Redis error: {0}")]
RedisError(#[from] RedisError),
#[error("Tokio error: {0}")]
TokioRecieveError(#[from] RecvError),
TokioReceiveError(#[from] RecvError),
#[error("Serialization problem: {0}")]
TlsError(#[from] tls_codec::Error),
#[error("Unknown error: {0}")]
Expand Down
8 changes: 3 additions & 5 deletions sc_key_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ edition = "2021"
foundry-contracts.workspace = true
openmls = { version = "=0.5.0", features = ["test-utils"] }
openmls_basic_credential = "=0.2.0"
tls_codec = "=0.3.0"

thiserror = "=1.0.61"
anyhow = "=1.0.71"
anyhow = "=1.0.81"

tls_codec = "=0.3.0"
hex = "0.4.3"
url = "2.5.2"

eyre = "=0.6"
Expand All @@ -27,8 +28,5 @@ alloy = { git = "https://github.com/alloy-rs/alloy", features = [
"transport-http",
"k256",
] }
async-trait = "0.1.80"
p256 = "0.13.2"

mls_crypto = { path = "../mls_crypto" }
hex = "0.4.3"
99 changes: 0 additions & 99 deletions sc_key_store/src/pks.rs

This file was deleted.

4 changes: 2 additions & 2 deletions sc_key_store/src/sc_ks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ mod test {
use openmls::prelude::*;
use openmls_basic_credential::SignatureKeyPair;

use mls_crypto::openmls_provider::MlsCryptoProvider;
use mls_crypto::openmls_provider::{MlsCryptoProvider, CIPHERSUITE};

use crate::{sc_ks::*, UserKeyPackages};

pub(crate) fn test_identity(
address: Address,
crypto: &MlsCryptoProvider,
) -> (UserKeyPackages, SignatureKeyPair) {
let ciphersuite = Ciphersuite::MLS_128_DHKEMP256_AES128GCM_SHA256_P256;
let ciphersuite = CIPHERSUITE;
let signature_keys = SignatureKeyPair::new(ciphersuite.signature_algorithm()).unwrap();
let credential = Credential::new(address.to_vec(), CredentialType::Basic).unwrap();

Expand Down
Loading

0 comments on commit 4774e57

Please sign in to comment.