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<()>
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 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);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> 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> 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