diff --git a/ica-rs/src/client.rs b/ica-rs/src/client.rs new file mode 100644 index 0000000..2a85d13 --- /dev/null +++ b/ica-rs/src/client.rs @@ -0,0 +1,26 @@ +use ed25519_dalek::{Signature, Signer, SigningKey}; +use rust_socketio::{ClientBuilder, Event, Payload, RawClient}; + +pub struct IcalinguaSinger { + pub host: String, + pub pub_key: SigningKey, +} + +impl IcalinguaSinger { + pub fn new(host: String, pub_key: &str) -> Self { + let array_key: [u8; 32] = hex::decode(pub_key).unwrap().try_into().unwrap(); + + let signing_key: SigningKey = SigningKey::from_bytes(&array_key); + Self { + host, + pub_key: signing_key, + } + } + + pub fn sign_for_salt(&self, salt: String) -> Vec { + let salt: Vec = hex::decode(salt).unwrap(); + let signature: Signature = self.pub_key.sign(salt.as_slice()); + + signature.to_bytes().to_vec() + } +} diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index c8d4de7..e80964f 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -1,3 +1,5 @@ +mod client; + use ed25519_dalek::{Signature, Signer, SigningKey}; use rust_socketio::{ClientBuilder, Payload, RawClient, Event}; use std::time::Duration;