Compare commits

...

3 Commits

Author SHA1 Message Date
Dave Hrycyszyn c3a66c32ca wip 2022-12-05 16:41:55 +00:00
Dave Hrycyszyn 60884849d4 Merge branch 'develop' into feature/rust-sdk 2022-12-02 12:00:35 +00:00
Dave Hrycyszyn ef4accdfa0 Starting with Rust sdk 2022-11-29 16:52:24 +00:00
7 changed files with 132 additions and 0 deletions
Generated
+9
View File
@@ -3352,6 +3352,15 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "nym-sdk"
version = "0.1.0"
dependencies = [
"client-core",
"rand 0.7.3",
"tokio",
]
[[package]] [[package]]
name = "nym-socks5-client" name = "nym-socks5-client"
version = "1.1.1" version = "1.1.1"
+1
View File
@@ -72,6 +72,7 @@ members = [
"gateway/gateway-requests", "gateway/gateway-requests",
"integrations/bity", "integrations/bity",
"mixnode", "mixnode",
"sdk/rust/nym-sdk",
"service-providers/network-requester", "service-providers/network-requester",
"service-providers/network-statistics", "service-providers/network-statistics",
"validator-api", "validator-api",
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "nym-sdk"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
client-core = { path = "../../../clients/client-core" }
rand = { version = "0.7.3" }
[dev-dependencies]
tokio = { version = "1", features = ["full"] }
@@ -0,0 +1,24 @@
use std::path::PathBuf;
use nym_sdk::mixnet;
#[tokio::main]
async fn main() {
// specify some config options
let keys = Some(PathBuf::from("~/.nym/clients/superfoomp"));
let config = mixnet::Config { keys };
let client = mixnet::Client::new(Some(config)); // passing a config allows the user to set values
// let show_receive = move || println!("got a message from the mixnet: {}", message); // might need to bury this in a struct as a `FnOnce`, see https://stackoverflow.com/questions/41081240/idiomatic-callbacks-in-rust
// client.on_receive(show_receive); // have some way to pipe any received info to a function for processing
// connect to the mixnet, now we're listening for incoming
client.connect_to_mixnet();
// be able to get our client address
println!("Our client address is {}", client.nym_address);
// send important info up the pipe to a buddy
client.send_str("foo.bar@blah", "flappappa");
}
+22
View File
@@ -0,0 +1,22 @@
use nym_sdk::mixnet;
#[tokio::main]
async fn main() {
// here's what I'd actually like to write
let client = mixnet::Client::new(None); // passing no config makes the client fire up an ephemeral session and figure shit out on its own
// let show_receive = move || println!("got a message from the mixnet: {}", message); // might need to bury this in a struct as a `FnMut`, see https://stackoverflow.com/questions/41081240/idiomatic-callbacks-in-rust
// connect to the mixnet, now we're listening for incoming
client.connect_to_mixnet();
// be able to get our client address
println!("Our client address is {}", client.nym_address);
// send important string info up the pipe to a buddy
client.send_str("foo.bar@blah", "flappappa");
// send some bytes to a buddy
client.send_bytes("foo.bar@blah", "flappappa".as_bytes().to_vec());
}
+1
View File
@@ -0,0 +1 @@
pub mod mixnet;
+62
View File
@@ -0,0 +1,62 @@
use std::path::PathBuf;
pub struct Client {
pub nym_address: String,
config: Config,
}
impl Client {
/// Create a new mixnet client. If no config options are supplied, creates a new client with ephemeral keys
/// stored in RAM, which will be discarded at application close.
///
/// Callers have the option of supplying futher parameters to store persistent identities at a location on-disk,
/// if desired.
pub fn new(config_option: Option<Config>) -> Client {
if config_option.is_none() {
let config = Self::some_minimal_config();
let nym_address = Self::new_nym_address();
Client {
config,
nym_address,
}
} else {
let self_address = Self::new_nym_address();
let nym_address = Self::new_nym_address();
Client {
config: config_option.unwrap(),
nym_address,
}
}
}
/// Connects to the mixnet via the gateway in the client config
pub fn connect_to_mixnet(&self) {}
/// Sets the callback function which is run when the client receives a message
/// from the mixnet
pub fn on_receive(&mut self, message: &str) {
println!("Message received: {}", message);
}
/// Sends stringy data to the supplied Nym address
pub fn send_str(&self, address: &str, message: &str) {}
/// Sends bytes to the supplied Nym address
pub fn send_bytes(&self, address: &str, message: Vec<u8>) {}
fn new_nym_address() -> String {
"the.nym@address".to_string()
}
fn some_minimal_config() -> Config {
let mut keys_path = PathBuf::new();
Config {
keys: Some(keys_path),
}
}
}
pub struct Config {
pub keys: Option<PathBuf>,
}