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

Validates a message and has correspond to an address.

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

    let authenticator = Authenticator::new();

    let chain = AuthChain::from_json(r#"[
       {
           "type": "SIGNER",
           "payload": "0x84452bbfa4ca14b7828e2f3bbd106a2bd495cd34",
           "signature": ""
       },
       {
           "type": "ECDSA_EPHEMERAL",
           "payload": "Decentraland Login\r\nEphemeral address: 0xB80549D339DCe9834271EcF5F1F1bb141C70AbC2\r\nExpiration: 2123-03-20T12:36:25.522Z",
           "signature": "0x76bf8d3c8ee6798bd488c4bc7ac1298d0ad78759669be39876e63ccfd9af81e31b8c6d8000b892ed2d17eb2f5a2b56fc3edbbf33c6089d3e5148d83cc70ce9001c"
       },
       {
           "type": "ECDSA_SIGNED_ENTITY",
           "payload": "QmUsqJaHc5HQaBrojhBdjF4fr5MQc6CqhwZjqwhVRftNAo",
           "signature": "0xd71fb5511f7d9116d171a12754b2c6f4c795240bee982511049a14aba57f18684b48a08413ab00176801d773eab0436fff5d0c978877b6d05f483ee2ae36efb41b"
       }
    ]"#).unwrap();

    let address =  Address::try_from("0x84452bbfa4ca14b7828e2f3bbd106a2bd495cd34").unwrap();
    let owner =  chain.owner().unwrap();
    let result = authenticator.verify_signature(&chain, "QmUsqJaHc5HQaBrojhBdjF4fr5MQc6CqhwZjqwhVRftNAo").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 dcl_crypto::authenticator::Authenticator;
use dcl_crypto::account::{Address, PersonalSignature};

    let address = Address::try_from("0x84452bbfa4ca14b7828e2f3bbd106a2bd495cd34").unwrap();
    let message = "Decentraland Login\nEphemeral address: 0xe94944439fAB988e5e14b128BbcF6D5502b05f9C\nExpiration: 2020-02-20T00:00:00.000Z";
    let hash = PersonalSignature::try_from("0x2d45e2a3e9e04614cf6bb822951b849458a78037733202d4bda12e60ef1ff4d266b02af7b72caa232c45052520fd440869672da2b0966b29fff21638e3d21ca01b").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> 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.

§

impl<T> Instrument for T

§

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

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

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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