Skip to content

Commit

Permalink
Merge branch '04-05-add_identity_update_builder' of github.com:xmtp/l…
Browse files Browse the repository at this point in the history
…ibxmtp into 04-05-add_identity_update_builder
  • Loading branch information
neekolas committed Apr 7, 2024
2 parents 609b32d + 9be4a86 commit 98346b1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 40 deletions.
1 change: 1 addition & 0 deletions xmtp_id/src/associations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod builder;
mod hashes;
mod member;
mod signature;
mod signer;
mod state;
#[cfg(test)]
mod test_utils;
Expand Down
35 changes: 35 additions & 0 deletions xmtp_id/src/associations/signer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use thiserror::Error;

use super::{MemberIdentifier, Signature, SignatureKind};

#[derive(Error, Debug)]
pub enum SignerError {
#[error("Signature error {0}")]
Generic(String),
}

#[async_trait::async_trait]
pub trait Signer: SignerClone {
fn signer_identity(&self) -> MemberIdentifier;
fn signature_kind(&self) -> SignatureKind;
fn sign(&self, text: &str) -> Result<Box<dyn Signature>, SignerError>;
}

pub trait SignerClone {
fn clone_box(&self) -> Box<dyn Signer>;
}

impl<T> SignerClone for T
where
T: 'static + Signer + Clone,
{
fn clone_box(&self) -> Box<dyn Signer> {
Box::new(self.clone())
}
}

impl Clone for Box<dyn Signer> {
fn clone(&self) -> Box<dyn Signer> {
self.clone_box()
}
}
41 changes: 1 addition & 40 deletions xmtp_id/src/associations/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use rand::{distributions::Alphanumeric, Rng};

use super::{
// signer::{Signer, SignerClone, SignerError},
MemberIdentifier,
Signature,
SignatureError,
SignatureKind,
};
use super::{MemberIdentifier, Signature, SignatureError, SignatureKind};

pub fn rand_string() -> String {
let v: String = rand::thread_rng()
Expand Down Expand Up @@ -72,36 +66,3 @@ impl Signature for MockSignature {
sig.as_bytes().to_vec()
}
}

// #[derive(Clone)]
// pub struct MockSigner {
// identity: MemberIdentifier,
// signature_kind: SignatureKind,
// }

// impl Signer for MockSigner {
// fn signature_kind(&self) -> SignatureKind {
// self.signature_kind.clone()
// }
// fn signer_identity(&self) -> MemberIdentifier {
// self.identity.clone()
// }

// fn sign(&self, text: &str) -> Result<Box<dyn Signature>, SignerError> {
// Ok(MockSignature::new_boxed(
// true,
// self.signer_identity(),
// self.signature_kind(),
// Some(text.to_string()),
// ))
// }
// }

// impl MockSigner {
// pub fn new_boxed(identity: MemberIdentifier, signature_kind: SignatureKind) -> Box<Self> {
// Box::new(Self {
// identity,
// signature_kind,
// })
// }
// }

0 comments on commit 98346b1

Please sign in to comment.