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\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<()>
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(
&self,
address: Address,
message: String,
hash: Vec<u8>
) -> Result<bool, RecoveryError>
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);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.