Skip to content

Commit

Permalink
Implement request auth ticket method
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Jun 14, 2024
1 parent 5865eb5 commit c04d395
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/bioauth-flow-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ pub trait Bioauth<Timestamp, TxHash> {
/// Authenticate with provided liveness data.
#[method(name = "bioauth_authenticate")]
async fn authenticate(&self, liveness_data: LivenessData) -> RpcResult<TxHash>;

/// Request auth ticket based on provided liveness data.
#[method(name = "bioauth_requestAuthTicket")]
async fn request_auth_ticket(&self, liveness_data: LivenessData) -> RpcResult<Box<[u8]>>;
}

/// The RPC implementation.
Expand Down Expand Up @@ -484,4 +488,32 @@ where

Ok(tx_hash)
}

async fn request_auth_ticket(&self, liveness_data: LivenessData) -> RpcResult<Box<[u8]>> {
self.deny_unsafe.check_if_safe()?;

info!("Bioauth flow - authentication in progress");

let errtype = |val: errors::authenticate::Error<TransactionPool::Error>| { val };

let public_key = rpc_validator_key_logic::validator_public_key(&self.validator_key_extractor).map_err(AuthenticateError::KeyExtraction).map_err(errtype)?;
let (opaque_liveness_data, signature) = self.sign(public_key, &liveness_data).await
.map_err(AuthenticateError::Sign).map_err(errtype)?;

let response = self
.robonode_client
.as_ref()
.authenticate(AuthenticateRequest {
liveness_data: opaque_liveness_data.as_ref(),
liveness_data_signature: signature.as_ref(),
})
.await
.map_err(AuthenticateError::Robonode).map_err(errtype)?;

info!("Bioauth flow - authentication complete");

info!(message = "We've obtained an auth ticket", auth_ticket = ?response.auth_ticket);

Ok(response.auth_ticket)
}
}

0 comments on commit c04d395

Please sign in to comment.