Skip to content

Commit

Permalink
feat: add revoke command
Browse files Browse the repository at this point in the history
  • Loading branch information
edytapawlak committed Jan 16, 2025
1 parent d2abdfc commit 274d241
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/keri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,30 @@ pub async fn issue(

Ok(())
}


pub async fn revoke(
identifier: &mut Identifier,
cred_said: &SelfAddressingIdentifier,
km: Arc<Signer>,
) -> Result<(), KeriError> {
let ixn = identifier.revoke(&cred_said)?;
let signature = SelfSigningPrefix::new(
cesrox::primitives::codes::self_signing::SelfSigning::Ed25519Sha512,
km.sign(&ixn)?,
);
identifier.finalize_anchor(&ixn, signature).await?;

identifier.notify_witnesses().await?;
let witnesses = identifier
.find_state(identifier.id())?
.witness_config
.witnesses;
for witness in witnesses {
let _qry = query_mailbox(identifier, km.clone(), &witness).await?;
}

identifier.notify_backers().await?;

Ok(())
}
29 changes: 28 additions & 1 deletion src/subcommands/data.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use clap::Subcommand;
use said::SelfAddressingIdentifier;
use std::io::{self, IsTerminal, Read};

use crate::{
inspect,
sign::handle_sign,
tel::handle_issue,
tel::{extract_said, handle_issue, handle_revoke},
verification_status::VerificationStatus,
verify::{handle_verify, VerifyHandleError},
CliError,
Expand Down Expand Up @@ -44,6 +45,17 @@ pub enum DataCommand {
#[arg(short, long)]
message: String,
},
/// Revoke credential
Revoke {
#[arg(short, long)]
alias: String,
/// ACDC credential payload in JSON format
#[arg(short, long)]
credential: Option<String>,
/// ACDC SAID
#[arg(short, long)]
said: Option<SelfAddressingIdentifier>,
},
}

pub async fn process_data_command(command: DataCommand) -> Result<(), CliError> {
Expand Down Expand Up @@ -134,6 +146,21 @@ pub async fn process_data_command(command: DataCommand) -> Result<(), CliError>
alias,
message: credential_json,
} => handle_issue(&alias, &credential_json).await?,
DataCommand::Revoke {
alias,
credential: credential_json,
said,
} => {
match (credential_json, said) {
(None, None) => println!("Credential or its SAID in expected"),
(None, Some(said)) => handle_revoke(&alias, &said).await?,
(Some(cred), None) => {
let said = extract_said(&cred)?;
handle_revoke(&alias, &said).await?
},
(Some(_), Some(_)) => println!("Only one of credential or its SAID is expected"),
}
}
}
Ok(())
}
27 changes: 26 additions & 1 deletion src/tel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use keri_controller::{EndRole, IdentifierPrefix, Oobi};
use keri_core::actor::prelude::SelfAddressingIdentifier;

use crate::{
keri::{issue, query_tel},
keri::{issue, query_tel, revoke},
said::{compute_and_update_digest, SaidError},
utils::{load, load_signer, working_directory},
CliError,
Expand Down Expand Up @@ -66,6 +66,31 @@ pub async fn handle_issue(alias: &str, data: &str) -> Result<(), CliError> {
Ok(())
}


pub fn extract_said(data: &str) -> Result<SelfAddressingIdentifier, CliError> {
if let Ok(root) =
serde_json::from_str::<indexmap::IndexMap<String, serde_json::Value>>(data)
{
let digest: &str = root
.get("d")
.and_then(|v| v.as_str())
.ok_or(CliError::MissingDigest)?;
Ok(digest.parse().map_err(SaidError::InvalidSaid)?)
} else {
println!("Wrong json format: {}", data);
Err(CliError::JsonExpected)
}
}

pub async fn handle_revoke(alias: &str, said: &SelfAddressingIdentifier) -> Result<(), CliError> {
let mut id = load(alias)?;
let signer = Arc::new(load_signer(alias)?);
revoke(&mut id, said, signer).await?;
println!("Revoked {}", said);

Ok(())
}

fn insert_issuer_and_registry(
issuer: &IdentifierPrefix,
registry: &IdentifierPrefix,
Expand Down

0 comments on commit 274d241

Please sign in to comment.