Skip to content

Commit

Permalink
fix: notify user when verification fails due to no watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
edytapawlak committed Nov 29, 2024
1 parent e3609e1 commit e9ae4f0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use config_file::ConfigFileError;
use keri_controller::identifier::query::WatcherResponseError;
use keri_controller::{identifier::query::WatcherResponseError, IdentifierPrefix};
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -47,4 +47,6 @@ pub enum CliError {
KelGetting(Vec<WatcherResponseError>),
#[error("{0}")]
IdentifierCommand(#[from] IdentifierSubcommandError),
#[error("No watchers are configured for identifier {0}. Can't find TEL")]
NoWatchers(IdentifierPrefix),
}
11 changes: 9 additions & 2 deletions src/subcommands/data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use clap::Subcommand;

use crate::{
expand, sign::handle_sign, tel::handle_issue, verification_status::VerificationStatus,
verify::handle_verify, CliError,
expand,
sign::handle_sign,
tel::handle_issue,
verification_status::VerificationStatus,
verify::{handle_verify, VerifyHandleError},
CliError,
};

#[derive(Subcommand)]
Expand Down Expand Up @@ -55,6 +59,9 @@ pub async fn process_data_command(command: DataCommand) -> Result<(), CliError>
.await
{
Ok(result) => VerificationStatus::from(result),
Err(VerifyHandleError::NoWatchersConfigured(id)) => {
return Err(CliError::NoWatchers(id))
}
Err(e) => VerificationStatus::from(e),
};
match &status {
Expand Down
49 changes: 39 additions & 10 deletions src/verify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{sync::Arc, thread::sleep, time::Duration};

use keri_controller::{
communication::SendingError, error::ControllerError, IdentifierPrefix, Oobi, TelState,
communication::SendingError, error::ControllerError, identifier, IdentifierPrefix, Oobi,
TelState,
};
use keri_core::{
event::sections::seal::EventSeal,
Expand Down Expand Up @@ -35,6 +36,8 @@ pub enum VerifyHandleError {
List(ErrorList),
#[error("Signature doesn't match provided data")]
FaultySignatures,
#[error("No watchers are configured for {0}")]
NoWatchersConfigured(IdentifierPrefix),
}

impl From<VerificationError> for VerifyHandleError {
Expand Down Expand Up @@ -123,9 +126,13 @@ pub async fn handle_verify(
match who_id.verify_from_cesr(&message) {
Ok(_) => Ok(ACDCState::VerificationSuccess),
Err(ControllerError::VerificationError(e)) => {
if e.iter()
.any(|(_e, _)| matches!(VerificationError::VerificationFailure, _e))
{
if e.iter().any(|(e, _)| {
if let VerificationError::VerificationFailure = e {
true
} else {
false
}
}) {
return Err(VerifyHandleError::FaultySignatures);
};
let err_list = ErrorList(
Expand Down Expand Up @@ -168,6 +175,24 @@ pub async fn handle_verify(
let issuer: IdentifierPrefix = fields.issuer_identifier.parse().unwrap();
let said: SelfAddressingIdentifier = fields.digest.parse().unwrap();
let registry_id: SelfAddressingIdentifier = fields.registry_id.parse().unwrap();
// Try to verify vc
match who_id.find_vc_state(&said) {
Ok(Some(state)) => {
return match_tel_state(Some(state));
}
_ => {
// check if any watcher was configured
match who_id.watchers() {
Ok(watchers) if watchers.is_empty() => {
return Err(VerifyHandleError::NoWatchersConfigured(who_id.id().clone()))
}
Ok(_watchers) => {}
Err(_) => {
return Err(VerifyHandleError::NoWatchersConfigured(who_id.id().clone()))
}
};
}
}

let signer = Arc::new(load_signer(alias).unwrap());
for _i in 0..5 {
Expand All @@ -183,12 +208,16 @@ pub async fn handle_verify(
}

let st = who_id.find_vc_state(&said).unwrap();
match st {
Some(TelState::Issued(_said)) => Ok(ACDCState::Issued),
Some(TelState::NotIssued) => Ok(ACDCState::NotFound),
Some(TelState::Revoked) => Ok(ACDCState::Revoked),
None => Ok(ACDCState::NotFound),
}
match_tel_state(st)
}
}

fn match_tel_state(ts: Option<TelState>) -> Result<ACDCState, VerifyHandleError> {
match ts {
Some(TelState::Issued(_said)) => Ok(ACDCState::Issued),
Some(TelState::NotIssued) => Ok(ACDCState::NotFound),
Some(TelState::Revoked) => Ok(ACDCState::Revoked),
None => Ok(ACDCState::NotFound),
}
}

Expand Down

0 comments on commit e9ae4f0

Please sign in to comment.