From 24c34933c421319e9aa1c48b3b7108c756e1422f Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Fri, 6 Dec 2024 10:52:49 -0600 Subject: [PATCH] types: add accessors and constructor for PasskeyAuthenticator --- .../sui-sdk-types/src/types/crypto/passkey.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/sui-sdk-types/src/types/crypto/passkey.rs b/crates/sui-sdk-types/src/types/crypto/passkey.rs index e63dc9cf6..323e1aa03 100644 --- a/crates/sui-sdk-types/src/types/crypto/passkey.rs +++ b/crates/sui-sdk-types/src/types/crypto/passkey.rs @@ -1,5 +1,6 @@ use super::Secp256r1PublicKey; use super::Secp256r1Signature; +use super::SimpleSignature; /// An passkey authenticator with parsed fields. See field defition below. Can be initialized from [struct RawPasskeyAuthenticator]. #[derive(Debug, Clone, PartialEq, Eq)] @@ -29,6 +30,23 @@ pub struct PasskeyAuthenticator { client_data_json: String, } +impl PasskeyAuthenticator { + pub fn authenticator_data(&self) -> &[u8] { + &self.authenticator_data + } + + pub fn client_data_json(&self) -> &str { + &self.client_data_json + } + + pub fn signature(&self) -> SimpleSignature { + SimpleSignature::Secp256r1 { + signature: self.signature, + public_key: self.public_key, + } + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct PasskeyPublicKey(Secp256r1PublicKey); @@ -119,6 +137,19 @@ mod serialization { } impl PasskeyAuthenticator { + pub fn new( + authenticator_data: Vec, + client_data_json: String, + signature: SimpleSignature, + ) -> Option { + Self::try_from_raw::(Authenticator { + authenticator_data, + client_data_json, + signature, + }) + .ok() + } + fn try_from_raw( Authenticator { authenticator_data,