Authenticator

Struct Authenticator 

Source
pub struct Authenticator<T> { /* private fields */ }
Expand description

Validates a message and has correspond to an address.

use mtv_crypto::authenticator::Authenticator;
use mtv_crypto::account::Address;
use mtv_crypto::chain::AuthChain;

    let authenticator = Authenticator::new();

    let chain = AuthChain::from_json(r#"[
       {
           "type": "SIGNER",
           "payload": "0x13FE90239bfda363eC33a849b716616958c04f0F",
           "signature": ""
       },
       {
           "type": "ECDSA_EPHEMERAL",
           "payload": "Memetaverse Login\nEphemeral address: 0x68560651BD91509EB22b90f6F748422A26CA3425\nExpiration: 8020-07-29T01:23:42.610Z",
           "signature": "0xed50177b6d0607ef94e4dd507e99387624dfd480d781073ba7462240edfc930b64347f1e46d5db22bcd55f7e94c788415a0ac195928fb308b728d57c1c9b93b41c"
       },
       {
           "type": "ECDSA_SIGNED_ENTITY",
           "payload": "test",
           "signature": "0xc2542c9344635322aab27d0acf94c4d27fde0ac9d8ba4e760312703d6aeb519f5ed23c3291247375d74c4a7f057b75ec76ae8bdf25a499279044cc04bda159201c"
       }
    ]"#).unwrap();

    let address =  Address::try_from("0x13fe90239bfda363ec33a849b716616958c04f0f").unwrap();
    let owner =  chain.owner().unwrap();
    let result = authenticator.verify_signature(&chain, "test").await.unwrap();
    assert_eq!(result, &address);
    assert_eq!(result, owner);

Implementations§

Source§

impl Authenticator<()>

Source§

impl Authenticator<WithoutTransport>

Source

pub fn add_transport<T: Transport>(&self, transport: T) -> Authenticator<T>

Source§

impl<T: Transport> Authenticator<T>

Source

pub fn validate_personal<M: AsRef<[u8]>>( &self, address: &Address, message: M, hash: &[u8], ) -> Result<bool, RecoveryError>

Validates a message and has correspond to an address.

use mtv_crypto::authenticator::Authenticator;
use mtv_crypto::account::{Address, PersonalSignature};

    let address = Address::try_from("0x13FE90239bfda363eC33a849b716616958c04f0F").unwrap();
    let message = "Memetaverse Login\nEphemeral address: 0x68560651BD91509EB22b90f6F748422A26CA3425\nExpiration: 8020-07-28T11:11:08.989Z";
    let hash = PersonalSignature::try_from("0xaf237ccf4690d21c671c03a65aae48d1cbf94afdcfa3ed7569c20eb5769f2e273d4249c19e4a138acf063e5dff2b925e78a6c057fa864737ebaf65d9f1f464741c").unwrap().to_vec();

    let result = Authenticator::new().validate_personal(&address, &message, &hash).unwrap();
    assert_eq!(result, true);
Source

pub async fn verify_signature_at<'a>( &self, chain: &'a AuthChain, last_authority: &str, expiration: &DateTime<Utc>, ) -> Result<&'a Address, AuthenticatorError>

Verifies and authchain is valid, not expired at a given date and corresponds to the last_authority, otherwise, returns an error.

Source

pub async fn verify_signature<'a>( &self, chain: &'a AuthChain, last_authority: &str, ) -> Result<&'a Address, AuthenticatorError>

Verifies and authchain is valid, not expired and corresponds to the last_authority, otherwise, returns an error.

Source

pub fn create_signature<M: AsRef<str>>( &self, identity: &Identity, payload: M, ) -> PersonalSignature

Creates a personal signature from a given identity and payload. This method is intended to maintain parity with the JS implementation.

Source

pub fn sign_payload<M: AsRef<str>>( &self, identity: &Identity, payload: M, ) -> AuthChain

Creates an authchain from a given identity and payload. This method is intended to maintain parity with the JS implementation.

Auto Trait Implementations§

§

impl<T> Freeze for Authenticator<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Authenticator<T>
where T: RefUnwindSafe,

§

impl<T> Send for Authenticator<T>
where T: Send,

§

impl<T> Sync for Authenticator<T>
where T: Sync,

§

impl<T> Unpin for Authenticator<T>
where T: Unpin,

§

impl<T> UnwindSafe for Authenticator<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more