#[path = "common/suite.rs"]
mod suite;
use clap::Parser;
use didwebvh_rs::{did_key::generate_did_key, prelude::*};
use serde_json::json;
use std::sync::Arc;
use suite::Suite;
#[derive(Parser, Debug)]
#[command(about = "Create a new did:webvh DID with a chosen cryptographic suite.")]
struct Args {
#[arg(short = 'k', long, value_enum, default_value_t = Suite::default())]
key_type: Suite,
}
#[tokio::main]
async fn main() {
let args = Args::parse();
let (_did, signing_key) = generate_did_key(args.key_type.key_type()).unwrap();
let parameters = Parameters {
update_keys: Some(Arc::new(vec![Multibase::new(
signing_key.get_public_keymultibase().unwrap(),
)])),
portable: Some(true),
..Default::default()
};
let did_document = json!({
"id": "{DID}",
"@context": ["https://www.w3.org/ns/did/v1"],
"verificationMethod": [{
"id": "{DID}#key-0",
"type": "Multikey",
"publicKeyMultibase": signing_key.get_public_keymultibase().unwrap(),
"controller": "{DID}"
}],
"authentication": ["{DID}#key-0"],
"assertionMethod": ["{DID}#key-0"],
});
let config = CreateDIDConfig::builder()
.address("https://example.com:8080/a/path")
.authorization_key(signing_key)
.did_document(did_document)
.parameters(parameters)
.also_known_as_web(true)
.also_known_as_scid(true)
.build()
.unwrap();
let result = create_did(config).await.unwrap();
println!("DID: {}", result.did());
println!(
"Log Entry: {}",
serde_json::to_string_pretty(result.log_entry()).unwrap()
);
}