Struct dcl_crypto::authenticator::Authenticator
source · 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<()>
impl Authenticator<()>
pub fn new() -> Authenticator<WithoutTransport>
pub fn with_transport<T: Transport>(transport: T) -> Authenticator<T>
source§impl Authenticator<WithoutTransport>
impl Authenticator<WithoutTransport>
pub fn add_transport<T: Transport>(&self, transport: T) -> Authenticator<T>
source§impl<T: Transport> Authenticator<T>
impl<T: Transport> Authenticator<T>
sourcepub fn validate_personal<M: AsRef<[u8]>>(
&self,
address: &Address,
message: M,
hash: &[u8]
) -> Result<bool, RecoveryError>
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);
sourcepub async fn verify_signature_at<'a>(
&self,
chain: &'a AuthChain,
last_authority: &str,
expiration: &DateTime<Utc>
) -> Result<&'a Address, AuthenticatorError>
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.
sourcepub async fn verify_signature<'a>(
&self,
chain: &'a AuthChain,
last_authority: &str
) -> Result<&'a Address, AuthenticatorError>
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.
sourcepub fn create_signature<M: AsRef<str>>(
&self,
identity: &Identity,
payload: M
) -> PersonalSignature
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.
sourcepub fn sign_payload<M: AsRef<str>>(
&self,
identity: &Identity,
payload: M
) -> AuthChain
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more