Skip to content

Commit

Permalink
Add did-from-tx and did-submit-tx
Browse files Browse the repository at this point in the history
  • Loading branch information
clehner committed Mar 2, 2022
1 parent 2e5eae9 commit f456a38
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
18 changes: 17 additions & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,27 @@ Construct a [DID method transaction][] to deactivate a DID, if supported by the
#### Output
A [DID method transaction][] for a DID Deactivate operation.

### `didkit did-from-tx`

Reads a [DID method transaction][] on standard input, and extracts or derives its DID.

#### Output

The DID corresponding to the input transaction.

### `didkit did-submit-tx <did>`

Reads a [DID method transaction][] on standard input, and submits it in a method-specific way. Returns exit status zero if the transaction was successfully submitted.

#### Output

A method-specific data structure.

## Concepts

### DID method transaction

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.
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, using the [did-submit-tx](#didkit-did-submit-tx-did) subcommand.

## Examples

Expand Down
38 changes: 37 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use didkit::{
JWK, URI,
};
use didkit_cli::opts::ResolverOptions;
use ssi::did::{Service, ServiceEndpoint, VerificationRelationship};
use ssi::did::{DIDMethodTransaction, Service, ServiceEndpoint, VerificationRelationship};
use ssi::one_or_many::OneOrMany;

#[derive(StructOpt, Debug)]
Expand Down Expand Up @@ -97,6 +97,16 @@ pub enum DIDKit {
options: Vec<MetadataProperty>,
},

/// Get DID from DID method transaction
///
/// Reads from standard input. Outputs DID on success.
DIDFromTx,

/// Submit a DID method transaction
///
/// Reads from standard input.
DIDSubmitTx,

/// Update a DID.
DIDUpdate {
/// New JWK file for next DID Update operation
Expand Down Expand Up @@ -1018,6 +1028,32 @@ fn main() -> AResult<()> {
println!("");
}

DIDKit::DIDFromTx => {
let stdin_reader = BufReader::new(stdin());
let tx: DIDMethodTransaction = serde_json::from_reader(stdin_reader).unwrap();
let method = DID_METHODS
.get(&tx.did_method)
.ok_or(anyhow!("Unable to get DID method"))?;
let did = method
.did_from_transaction(tx)
.context("Get DID from transaction")?;
println!("{}", did);
}

DIDKit::DIDSubmitTx => {
let stdin_reader = BufReader::new(stdin());
let tx: DIDMethodTransaction = serde_json::from_reader(stdin_reader).unwrap();
let method = DID_METHODS
.get(&tx.did_method)
.ok_or(anyhow!("Unable to get DID method"))?;
let result = rt
.block_on(method.submit_transaction(tx))
.context("Submit DID transaction")?;
let stdout_writer = BufWriter::new(stdout());
serde_json::to_writer_pretty(stdout_writer, &result).unwrap();
println!("");
}

DIDKit::DIDUpdate {
new_update_key,
update_key,
Expand Down

0 comments on commit f456a38

Please sign in to comment.