Skip to content

Commit 2e5eae9

Browse files
committed
Add DID deactivate subcommand
1 parent c7288e5 commit 2e5eae9

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

‎cli/README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,22 @@ Construct a [DID method transaction][] to perform a DID recover operation ([DID
298298

299299
A [DID method transaction][] for a DID Recover operation.
300300

301+
### `didkit did-deactivate <did>`
302+
303+
Construct a [DID method transaction][] to deactivate a DID, if supported by the DID method.
304+
305+
#### Options
306+
- `-k, --key <key>` - JWK file to perform the DID Deactivate operation
307+
- `-o <name=value>` - Options for DID deactivate operation.
308+
309+
#### Output
310+
A [DID method transaction][] for a DID Deactivate operation.
311+
301312
## Concepts
302313

303314
### DID method transaction
304315

305-
DIDKit's DID method operation commands ([create](#didkit-did-create-did-method), [update](#didkit-did-update-subcommand), [recover](#didkit-did-recover-did)) do not fully perform the respective operation; instead, they return a data structure representing the partially applied operation, called a **DID method transaction**. The transaction is a verifiable message created by a DID controller to perform a [DID method operation][method-operations]. The transaction can be submitted, published, and/or fully performed, per the DID method.
316+
DIDKit's DID method operation commands ([create](#didkit-did-create-did-method), [update](#didkit-did-update-subcommand), [recover](#didkit-did-recover-did), [deactivate](#didkit-did-deactivate-did)) do not fully perform the respective operation; instead, they return a data structure representing the partially applied operation, called a **DID method transaction**. The transaction is a verifiable message created by a DID controller to perform a [DID method operation][method-operations]. The transaction can be submitted, published, and/or fully performed, per the DID method.
306317

307318
## Examples
308319

‎cli/src/main.rs‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ use sshkeys::PublicKey;
1414
use did_method_key::DIDKey;
1515
use didkit::generate_proof;
1616
use didkit::{
17-
dereference, get_verification_method, runtime, DIDCreate, DIDDocumentOperation, DIDMethod,
18-
DIDRecover, DIDResolver, DIDUpdate, DereferencingInputMetadata, Error, LinkedDataProofOptions,
19-
Metadata, ProofFormat, ProofPurpose, ResolutionInputMetadata, ResolutionResult, Source,
20-
VerifiableCredential, VerifiablePresentation, DIDURL, DID_METHODS, JWK, URI,
17+
dereference, get_verification_method, runtime, DIDCreate, DIDDeactivate, DIDDocumentOperation,
18+
DIDMethod, DIDRecover, DIDResolver, DIDUpdate, DereferencingInputMetadata, Error,
19+
LinkedDataProofOptions, Metadata, ProofFormat, ProofPurpose, ResolutionInputMetadata,
20+
ResolutionResult, Source, VerifiableCredential, VerifiablePresentation, DIDURL, DID_METHODS,
21+
JWK, URI,
2122
};
2223
use didkit_cli::opts::ResolverOptions;
2324
use ssi::did::{Service, ServiceEndpoint, VerificationRelationship};
@@ -180,9 +181,20 @@ pub enum DIDKit {
180181
resolver_options: ResolverOptions,
181182
},
182183

183-
/*
184184
/// Deactivate a DID.
185-
DIDDeactivate {},
185+
DIDDeactivate {
186+
did: String,
187+
188+
/// Filename of JWK to perform the DID Deactivate operation
189+
#[clap(short, long, parse(from_os_str))]
190+
key: Option<PathBuf>,
191+
192+
#[clap(short = 'o', name = "name=value")]
193+
/// Options for DID deactivate operation
194+
options: Vec<MetadataProperty>,
195+
},
196+
197+
/*
186198
/// Create a Signed IETF JSON Patch to update a DID document.
187199
DIDPatch {},
188200
*/
@@ -1155,6 +1167,27 @@ fn main() -> AResult<()> {
11551167
println!("");
11561168
}
11571169

1170+
DIDKit::DIDDeactivate { did, key, options } => {
1171+
let method = DID_METHODS
1172+
.get_method(&did)
1173+
.map_err(|e| anyhow!("Unable to get DID method: {}", e))?;
1174+
let key = read_jwk_file_opt(&key).context("Read key for DID deactivation")?;
1175+
let options = metadata_properties_to_value(options)
1176+
.context("Parse options for DID deactivation")?;
1177+
let options = serde_json::from_value(options).context("Unable to convert options")?;
1178+
1179+
let tx = method
1180+
.deactivate(DIDDeactivate {
1181+
did: did.clone(),
1182+
key,
1183+
options,
1184+
})
1185+
.context("DID deactivation failed")?;
1186+
let stdout_writer = BufWriter::new(stdout());
1187+
serde_json::to_writer_pretty(stdout_writer, &tx).unwrap();
1188+
println!("");
1189+
}
1190+
11581191
DIDKit::DIDResolve {
11591192
did,
11601193
with_metadata,

‎lib/src/lib.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ extern crate lazy_static;
1515
pub use crate::did_methods::DID_METHODS;
1616
pub use crate::error::Error;
1717
pub use ssi::did::{
18-
DIDCreate, DIDDocumentOperation, DIDMethod, DIDRecover, DIDUpdate, Document, Source, DIDURL,
18+
DIDCreate, DIDDeactivate, DIDDocumentOperation, DIDMethod, DIDRecover, DIDUpdate, Document,
19+
Source, DIDURL,
1920
};
2021
#[cfg(feature = "http-did")]
2122
pub use ssi::did_resolve::HTTPDIDResolver;

0 commit comments

Comments
 (0)