Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"mwm": 5,
"local_pow": true,
"api_port": 8080,
"seed": null
"seed": null,
"pre_shared_key": "SubscriberPreSharedKey"
}
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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);

Expand Down
19 changes: 15 additions & 4 deletions src/streams/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,10 +21,11 @@ pub struct ChannelAuthor {
author: Author<Client>,
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<ChannelAuthor> {
pub fn new(seed: &str, node: &str, psk_str: &str) -> Result<ChannelAuthor> {

// Create Client instance
let mut client = Client::new_from_url(node);
Expand All @@ -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
})
}

Expand Down Expand Up @@ -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()]
)?;

Expand Down