diff --git a/Cargo.toml b/Cargo.toml index 874a924..23f6e88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] tokio = { version = "0.2.22", features = ["full"] } anyhow = { version = "1.0.38", default-features = false } -iota-streams = { git = "https://github.com/iotaledger/streams", branch = "chrysalis-2" } +iota-streams = { git = "https://github.com/iotaledger/streams", branch = "v1.1.0" } rand = "0.7.3" hyper = "0.13" json = "0.12.4" diff --git a/config.json b/config.json index 305afd1..855a19f 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,6 @@ "mwm": 5, "local_pow": true, "api_port": 8080, - "seed": null + "seed": null, + "pre_shared_key": "SubscriberPreSharedKey" } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 15d351e..18d05cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,9 @@ async fn main() -> Result<()> { seed = config["seed"].as_str().unwrap().to_string() } - let mwm = config["mwm"].as_u64().unwrap() as u8; let node = config["node"].as_str().unwrap(); - let local_pow = config["local_pow"].as_bool().unwrap(); let port = config["api_port"].as_u64().unwrap() as u16; + let psk = config["pre_shared_key"].as_str().unwrap(); let annotation_store = Arc::new(Mutex::new(AnnotationStore::new())); @@ -32,7 +31,7 @@ async fn main() -> Result<()> { println!("Making Streams channel..."); println!("node = {}", config["node"]); println!("seed = {}", seed.as_str()); - let author = Arc::new(Mutex::new(ChannelAuthor::new(seed.as_str(), mwm, local_pow, node).unwrap())); + let author = Arc::new(Mutex::new(ChannelAuthor::new(seed.as_str(), node, psk).unwrap())); let channel_address = author.lock().unwrap().get_announcement_id().unwrap(); println!("\nChannel Address - {}:{}\n", channel_address.0, channel_address.1); diff --git a/src/streams/author.rs b/src/streams/author.rs index 12b351c..2557c9f 100644 --- a/src/streams/author.rs +++ b/src/streams/author.rs @@ -6,7 +6,12 @@ use iota_streams::app::transport::{ MsgId, } }; -use iota_streams::app_channels::api::tangle::{Address, Author, ChannelAddress, MessageContent}; +use iota_streams::app_channels::api::{ + pskid_from_psk, + psk_from_seed, + PskId, + tangle::{Address, Author, ChannelAddress, MessageContent} +}; use iota_streams::core_edsig::signature::ed25519::PublicKey; use std::str::FromStr; @@ -16,10 +21,11 @@ pub struct ChannelAuthor { author: Author, announcement_id: Address, channel_address: ChannelAddress, + subscriber_key_id: PskId, } impl ChannelAuthor { - pub fn new(seed: &str, mwm: u8, local_pow: bool, node: &str) -> Result { + pub fn new(seed: &str, node: &str, psk_str: &str) -> Result { // Create Client instance let mut client = Client::new_from_url(node); @@ -28,10 +34,15 @@ impl ChannelAuthor { let mut author = Author::new(seed, "utf-8", PAYLOAD_BYTES, true, client); let announcement_id = author.send_announce()?; + let psk = psk_from_seed(psk_str.as_bytes()); + let pskid = pskid_from_psk(&psk); + author.store_psk(pskid, psk); + Ok(ChannelAuthor { author: author, announcement_id: announcement_id.clone(), - channel_address: announcement_id.appinst.clone() + channel_address: announcement_id.appinst.clone(), + subscriber_key_id: pskid }) } @@ -59,7 +70,7 @@ impl ChannelAuthor { let keyload = self.author.send_keyload( &self.announcement_id, - &vec![], + &vec![self.subscriber_key_id], &vec![PublicKey::from_bytes(pk).unwrap()] )?;