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\nEphemeral address: 0x8b7E12dBE632f22D6B2c5Fc6789E02d27896Cb43\nExpiration: 2023-05-03T11:52:56.132Z",
        "signature": "0x42f5f7bc74c2934e6608627fa72a6078d470bfb12eb75063f5e4c878e176a5f265389606415a8dbe1b0914e75d58a2440840c5de3f325b8a5026dd8db0b397451b"
      },
      {
        "type": "ECDSA_SIGNED_ENTITY",
        "payload": "signed message",
        "signature": "0x60d35a5a5d0bacc7d5439101b1c502b175c6f35b3f3dea00ed2d81445f3ece0e796e8175a90a2ec4826d7baea44fc297c881c9163c9247daa9c347cd81c41a781c"
      }
    ]"#).unwrap();

    let address =  Address::try_from("0x84452bbfa4ca14b7828e2f3bbd106a2bd495cd34").unwrap();
    let owner =  chain.owner().unwrap();
    let result = authenticator.verify_signature(&chain, "signed message").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( &self, address: Address, message: String, hash: Vec<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("0xb92702b3EeFB3c2049aEB845B0335b283e11E9c6").unwrap();
    let message = "Decentraland Login\nEphemeral address: 0xF5E49370d9754924C9f082077ec6ad49F3113150\nExpiration: 2023-05-02T02:20:12.026Z".to_string();
    let hash = PersonalSignature::try_from("0xb2985d12400f9ee87091156b5951ee0e745efda50f503bbdcee3a3e7fc8adbb051b20ce386f7b400ae5865e7263c6a7155decda1af433287bceff911994849e81c").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.

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

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