Skip to content

Commit

Permalink
Upgrade ssi to v0.5.0 (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel committed Dec 15, 2022
1 parent 0a7ab5e commit b4491bf
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 30 deletions.
10 changes: 6 additions & 4 deletions 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;

Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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<String>,
pub type_: Option<ProofSuiteType>,
#[clap(env, short, long)]
pub verification_method: Option<URI>,
#[clap(env, short, long)]
Expand Down
4 changes: 2 additions & 2 deletions http/Cargo.toml
Expand Up @@ -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" }
18 changes: 9 additions & 9 deletions lib/Cargo.toml
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions lib/src/did_methods.rs
Expand Up @@ -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! {
Expand Down Expand Up @@ -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
};
}
3 changes: 2 additions & 1 deletion lib/src/ssh_agent.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
26 changes: 21 additions & 5 deletions lib/web/src/lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -217,7 +217,11 @@ async fn complete_issue_credential(
) -> Result<String, Error> {
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)
Expand Down Expand Up @@ -380,7 +384,11 @@ async fn complete_issue_presentation(
) -> Result<String, Error> {
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)
Expand Down Expand Up @@ -613,7 +621,11 @@ async fn complete_delegate_capability(
) -> Result<String, Error> {
let capability: Delegation<Value, Value> = 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)
}
Expand Down Expand Up @@ -740,7 +752,11 @@ async fn complete_invoke_capability(
) -> Result<String, Error> {
let invocation: Invocation<Value> = 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)
}
Expand Down

0 comments on commit b4491bf

Please sign in to comment.