diff --git a/cli/src/main.rs b/cli/src/main.rs index 222791a0..53bdc138 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,13 +1,15 @@ use std::convert::TryFrom; use std::fs::File; use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; +use std::ops::Deref; use std::path::PathBuf; use std::str::FromStr; use anyhow::{anyhow, bail, Context, Error as AError, Result as AResult}; use chrono::prelude::*; use clap::{AppSettings, ArgGroup, Parser, StructOpt}; -use serde::Serialize; +use didkit::ssi::ldp::ProofSuiteType; +use serde::{Deserialize, Serialize}; use serde_json::Value; use sshkeys::PublicKey; @@ -294,7 +296,7 @@ impl IdAndDid { let method = DID_METHODS .get_method(&id.did) .map_err(|e| anyhow!("Unable to get DID method: {}", e))?; - Ok((*method, did.unwrap_or_else(|| id.did.clone()), id)) + Ok((method.deref(), did.unwrap_or_else(|| id.did.clone()), id)) } } @@ -407,12 +409,12 @@ pub enum DIDUpdateCmd { RemoveVerificationMethod(IdAndDid), } -#[derive(StructOpt, Debug)] +#[derive(StructOpt, Debug, Deserialize)] #[non_exhaustive] pub struct ProofOptions { // Options as in vc-api (vc-http-api) #[clap(env, short, long)] - pub type_: Option, + pub type_: Option, #[clap(env, short, long)] pub verification_method: Option, #[clap(env, short, long)] diff --git a/http/Cargo.toml b/http/Cargo.toml index e7bcce1a..79ac27df 100644 --- a/http/Cargo.toml +++ b/http/Cargo.toml @@ -30,8 +30,8 @@ serde_urlencoded = "0.7" hyper = { version = "0.14", features = ["server", "client", "http1", "http2", "stream"] } tower-service = "0.3" futures-util = { version = "0.3", default-features = false } -ssi = { version = "0.4", path = "../../ssi", default-features = false } +ssi = { version = "0.5", path = "../../ssi", default-features = false } percent-encoding = "2.1" [dev-dependencies] -did-method-key = { version = "0.1", path = "../../ssi/did-key" } +did-method-key = { version = "0.2", path = "../../ssi/did-key" } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 28d40c6a..5f149c7e 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -39,16 +39,16 @@ http-did = ["ssi/http-did"] ring = ["ssi/ring"] [dependencies] -ssi = { version = "0.4", path = "../../ssi", default-features = false } -did-method-key = { version = "^0.1.2", path = "../../ssi/did-key", default-features = false } -did-tz = { version = "^0.1.1", path = "../../ssi/did-tezos" } -did-ethr = { version = "0.1", path = "../../ssi/did-ethr", default-features = false } -did-pkh = { version = "0.1", path = "../../ssi/did-pkh", default-features = false } +ssi = { version = "0.5", path = "../../ssi", default-features = false } +did-method-key = { version = "0.2.0", path = "../../ssi/did-key", default-features = false } +did-tz = { version = "0.2.0", path = "../../ssi/did-tezos" } +did-ethr = { version = "0.2", path = "../../ssi/did-ethr", default-features = false } +did-pkh = { version = "0.2", path = "../../ssi/did-pkh", default-features = false } #did-sol = { version = "0.0.1", path = "../../ssi/did-sol" } -did-web = { version = "^0.1.1", path = "../../ssi/did-web", default-features = false } -did-webkey = { version = "0.1", path = "../../ssi/did-webkey", default-features = false } -did-onion = { version = "^0.1.1", path = "../../ssi/did-onion", default-features = false } -did-ion = { version = "^0.1.0", path = "../../ssi/did-ion", default-features = false } +did-web = { version = "0.2.0", path = "../../ssi/did-web", default-features = false } +did-webkey = { version = "0.2", path = "../../ssi/did-webkey", default-features = false } +did-onion = { version = "0.2.0", path = "../../ssi/did-onion", default-features = false } +did-ion = { version = "0.2.0", path = "../../ssi/did-ion", default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" # TODO feature-gate JNI, or extract it in another crate like we do for Python (and probably WASM as well) diff --git a/lib/src/did_methods.rs b/lib/src/did_methods.rs index 228e918d..fcdef243 100644 --- a/lib/src/did_methods.rs +++ b/lib/src/did_methods.rs @@ -7,7 +7,7 @@ use did_ion::DIDION; use did_tz::DIDTz; use did_web::DIDWeb; use did_webkey::DIDWebKey; -use ssi::did::{DIDMethod, DIDMethods}; +use ssi::did::DIDMethods; use std::env::VarError; lazy_static! { @@ -38,15 +38,15 @@ lazy_static! { ); pub static ref DID_METHODS: DIDMethods<'static> = { let mut methods = DIDMethods::default(); - methods.insert(&DIDKey); - methods.insert(&*DIDTZ); - methods.insert(&DIDEthr); + methods.insert(Box::new(DIDKey)); + methods.insert(Box::new(DIDTZ.clone())); + methods.insert(Box::new(DIDEthr)); // methods.insert(&DIDSol); - methods.insert(&DIDWeb); - methods.insert(&DIDWebKey); - methods.insert(&DIDPKH); - methods.insert(&*DIDONION); - methods.insert(&*ION); + methods.insert(Box::new(DIDWeb)); + methods.insert(Box::new(DIDWebKey)); + methods.insert(Box::new(DIDPKH)); + methods.insert(Box::new(DIDONION.clone())); + methods.insert(Box::new(ION.clone())); methods }; } diff --git a/lib/src/ssh_agent.rs b/lib/src/ssh_agent.rs index 4ed4a5b3..eaa1e997 100644 --- a/lib/src/ssh_agent.rs +++ b/lib/src/ssh_agent.rs @@ -4,6 +4,7 @@ use sshkeys::PublicKey; use ssi::jsonld::ContextLoader; use ssi::jwk::{Algorithm, JWK}; use ssi::ldp::LinkedDataProofs; +use ssi::ldp::ProofSuite; use std::convert::TryFrom; use thiserror::Error; use tokio::io::AsyncReadExt; @@ -323,6 +324,6 @@ pub async fn generate_proof( }; let sig = sign(ssh_agent_sock, &pk, &signing_input_bytes, alg).await?; let sig_b64 = base64::encode_config(sig, base64::URL_SAFE_NO_PAD); - let proof = prep.complete(&sig_b64).await?; + let proof = prep.proof.type_.complete(&prep, &sig_b64).await?; Ok(proof) } diff --git a/lib/web/src/lib.rs b/lib/web/src/lib.rs index 697b7e3a..702e7c2d 100644 --- a/lib/web/src/lib.rs +++ b/lib/web/src/lib.rs @@ -9,7 +9,7 @@ use didkit::error::Error; #[cfg(doc)] use didkit::error::{didkit_error_code, didkit_error_message}; use didkit::get_verification_method; -use didkit::ssi; +use didkit::ssi::{self, ldp::ProofSuite}; use didkit::LinkedDataProofOptions; use didkit::ProofPreparation; use didkit::Source; @@ -217,7 +217,11 @@ async fn complete_issue_credential( ) -> Result { let mut credential = VerifiableCredential::from_json_unsigned(&credential)?; let preparation: ProofPreparation = serde_json::from_str(&preparation)?; - let proof = preparation.complete(&signature).await?; + let proof = preparation + .proof + .type_ + .complete(&preparation, &signature) + .await?; credential.add_proof(proof); let vc_json = serde_json::to_string(&credential)?; Ok(vc_json) @@ -380,7 +384,11 @@ async fn complete_issue_presentation( ) -> Result { let mut presentation = VerifiablePresentation::from_json_unsigned(&presentation)?; let preparation: ProofPreparation = serde_json::from_str(&preparation)?; - let proof = preparation.complete(&signature).await?; + let proof = preparation + .proof + .type_ + .complete(&preparation, &signature) + .await?; presentation.add_proof(proof); let vc_json = serde_json::to_string(&presentation)?; Ok(vc_json) @@ -613,7 +621,11 @@ async fn complete_delegate_capability( ) -> Result { let capability: Delegation = serde_json::from_str(&capability)?; let preparation: ProofPreparation = serde_json::from_str(&preparation)?; - let proof = preparation.complete(&signature).await?; + let proof = preparation + .proof + .type_ + .complete(&preparation, &signature) + .await?; let json = serde_json::to_string(&capability.set_proof(proof))?; Ok(json) } @@ -740,7 +752,11 @@ async fn complete_invoke_capability( ) -> Result { let invocation: Invocation = serde_json::from_str(&invocation)?; let preparation: ProofPreparation = serde_json::from_str(&preparation)?; - let proof = preparation.complete(&signature).await?; + let proof = preparation + .proof + .type_ + .complete(&preparation, &signature) + .await?; let json = serde_json::to_string(&invocation.set_proof(proof))?; Ok(json) }