Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enum for proof suites #489

Merged
merged 5 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions did-ethr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ mod tests {
use serde_json::json;
use ssi_dids::did_resolve::ResolutionInputMetadata;
use ssi_jwk::JWK;
use ssi_ldp::{ProofSuite, ProofSuiteType};

#[test]
fn jwk_to_did_ethr() {
Expand Down Expand Up @@ -471,8 +472,7 @@ mod tests {
// Check that proof JWK must match proof verificationMethod
let mut vc_wrong_key = vc_no_proof.clone();
let other_key = JWK::generate_ed25519().unwrap();
use ssi_ldp::ProofSuite;
let proof_bad = ssi_ldp::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
let proof_bad = ProofSuiteType::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
.sign(
&vc_no_proof,
&issue_options,
Expand Down
1 change: 1 addition & 0 deletions did-ion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use sidetree::{is_secp256k1, Sidetree, SidetreeClient, SidetreeError};

pub const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

#[derive(Clone)]
pub struct ION;

/// did:ion Method
Expand Down
1 change: 1 addition & 0 deletions did-ion/src/sidetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ impl<S: Sidetree> HTTPSidetreeDIDResolver<S> {
}

/// Sidetree DID Method client implementation
#[derive(Clone)]
pub struct SidetreeClient<S: Sidetree> {
pub resolver: Option<HTTPSidetreeDIDResolver<S>>,
pub endpoint: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions did-onion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const TOR_SOCKS_PORT: usize = 9050;
///
/// [Specification](https://blockchaincommons.github.io/did-method-onion/)
#[non_exhaustive]
#[derive(Clone)]
pub struct DIDOnion {
pub proxy_url: String,
}
Expand Down
30 changes: 15 additions & 15 deletions did-pkh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ mod tests {
use serde_json::{from_str, from_value, json};
use ssi_core::one_or_many::OneOrMany;
use ssi_jwk::Algorithm;
use ssi_ldp::{Proof, ProofSuite};
use ssi_ldp::{Proof, ProofSuite, ProofSuiteType};

fn test_generate(jwk_value: Value, type_: &str, did_expected: &str) {
let jwk: JWK = from_value(jwk_value).unwrap();
Expand Down Expand Up @@ -1101,7 +1101,7 @@ mod tests {
eprintln!("sig: {}", sig);

// Complete issuance
let proof = proof_suite.complete(prep, &sig).await.unwrap();
let proof = proof_suite.complete(&prep, &sig).await.unwrap();
println!("{}", serde_json::to_string_pretty(&proof).unwrap());
vc.add_proof(proof);
vc.validate().unwrap();
Expand Down Expand Up @@ -1178,7 +1178,7 @@ mod tests {
.await
.unwrap();
let sig = sign_tezos(&prep, algorithm, &key);
let vp_proof = proof_suite.complete(prep, &sig).await.unwrap();
let vp_proof = proof_suite.complete(&prep, &sig).await.unwrap();
vp.add_proof(vp_proof);
println!("VP: {}", serde_json::to_string_pretty(&vp).unwrap());
vp.validate().unwrap();
Expand Down Expand Up @@ -1250,7 +1250,7 @@ mod tests {
other_key_secp256k1.clone(),
"eip155",
"#blockchainAccountId",
&ssi_ldp::EcdsaSecp256k1RecoverySignature2020,
&ProofSuiteType::EcdsaSecp256k1RecoverySignature2020,
None,
None,
)
Expand All @@ -1262,7 +1262,7 @@ mod tests {
other_key_secp256k1.clone(),
"eip155",
"#blockchainAccountId",
&ssi_ldp::Eip712Signature2021,
&ProofSuiteType::Eip712Signature2021,
None,
None,
)
Expand All @@ -1274,7 +1274,7 @@ mod tests {
other_key_secp256k1.clone(),
"eip155",
"#blockchainAccountId",
&ssi_ldp::EthereumPersonalSignature2021,
&ProofSuiteType::EthereumPersonalSignature2021,
None,
None,
)
Expand Down Expand Up @@ -1370,7 +1370,7 @@ mod tests {
other_key_secp256k1.clone(),
"eip155",
"#blockchainAccountId",
&ssi_ldp::EthereumEip712Signature2021,
&ProofSuiteType::EthereumEip712Signature2021,
Some(eip712_domain),
Some(vp_eip712_domain),
)
Expand All @@ -1382,7 +1382,7 @@ mod tests {
other_key_secp256k1.clone(),
"eip155",
"#blockchainAccountId",
&ssi_ldp::Eip712Signature2021,
&ProofSuiteType::Eip712Signature2021,
None,
None,
)
Expand All @@ -1396,7 +1396,7 @@ mod tests {
other_key_ed25519.clone(),
"tz",
"#blockchainAccountId",
&ssi_ldp::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021,
&ProofSuiteType::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021,
None,
None,
)
Expand All @@ -1423,7 +1423,7 @@ mod tests {
other_key_p256.clone(),
"tz",
"#blockchainAccountId",
&ssi_ldp::P256BLAKE2BDigestSize20Base58CheckEncodedSignature2021,
&ProofSuiteType::P256BLAKE2BDigestSize20Base58CheckEncodedSignature2021,
None,
None,
)
Expand All @@ -1437,7 +1437,7 @@ mod tests {
other_key_ed25519.clone(),
"sol",
"#controller",
&ssi_ldp::Ed25519Signature2018,
&ProofSuiteType::Ed25519Signature2018,
None,
None,
)
Expand All @@ -1461,7 +1461,7 @@ mod tests {
other_key_secp256k1.clone(),
"btc",
"#blockchainAccountId",
&ssi_ldp::EcdsaSecp256k1RecoverySignature2020,
&ProofSuiteType::EcdsaSecp256k1RecoverySignature2020,
None,
None,
)
Expand All @@ -1473,7 +1473,7 @@ mod tests {
other_key_secp256k1.clone(),
"doge",
"#blockchainAccountId",
&ssi_ldp::EcdsaSecp256k1RecoverySignature2020,
&ProofSuiteType::EcdsaSecp256k1RecoverySignature2020,
None,
None,
)
Expand All @@ -1488,7 +1488,7 @@ mod tests {
other_key_ed25519.clone(),
"tz",
"#TezosMethod2021",
&ssi_ldp::TezosSignature2021,
&ProofSuiteType::TezosSignature2021,
)
.await;
key_ed25519.algorithm = Some(Algorithm::EdDSA);
Expand Down Expand Up @@ -1516,7 +1516,7 @@ mod tests {
other_key_p256.clone(),
"tz",
"#TezosMethod2021",
&ssi_ldp::TezosSignature2021,
&ProofSuiteType::TezosSignature2021,
)
.await;
key_p256.algorithm = Some(Algorithm::ES256);
Expand Down
4 changes: 2 additions & 2 deletions did-sol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ mod tests {
use serde_json::json;
use ssi_dids::did_resolve::ResolutionInputMetadata;
use ssi_jwk::JWK;
use ssi_ldp::{ProofSuite, ProofSuiteType};

#[test]
fn key_to_did_sol() {
Expand Down Expand Up @@ -299,8 +300,7 @@ mod tests {
// Check that proof JWK must match proof verificationMethod
let mut vc_wrong_key = vc_no_proof.clone();
let other_key = JWK::generate_ed25519().unwrap();
use ssi_ldp::ProofSuite;
let proof_bad = ssi_ldp::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
let proof_bad = ProofSuiteType::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
.sign(
&vc_no_proof,
&issue_options,
Expand Down
12 changes: 5 additions & 7 deletions did-tezos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod explorer;
/// did:tz DID Method
///
/// [Specification](https://github.com/spruceid/did-tezos/)
#[derive(Default)]
#[derive(Default, Clone)]
pub struct DIDTz {
tzkt_url: Option<String>,
}
Expand Down Expand Up @@ -563,6 +563,7 @@ mod tests {
use ssi_dids::did_resolve::ResolutionInputMetadata;
use ssi_dids::ServiceEndpoint;
use ssi_jws::encode_sign;
use ssi_ldp::{ProofSuite, ProofSuiteType};
use std::collections::BTreeMap as Map;

const TZ1: &str = "did:tz:tz1YwA1FwpgLtc1G8DKbbZ6e6PTb1dQMRn5x";
Expand Down Expand Up @@ -856,8 +857,7 @@ mod tests {
// Check that proof JWK must match proof verificationMethod
let mut vc_wrong_key = vc_no_proof.clone();
let other_key = JWK::generate_ed25519().unwrap();
use ssi_ldp::ProofSuite;
let proof_bad = ssi_ldp::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
let proof_bad = ProofSuiteType::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
.sign(
&vc_no_proof,
&issue_options,
Expand Down Expand Up @@ -1052,8 +1052,7 @@ mod tests {
// Check that proof JWK must match proof verificationMethod
let mut vc_wrong_key = vc_no_proof.clone();
let other_key = JWK::generate_ed25519().unwrap();
use ssi_ldp::ProofSuite;
let proof_bad = ssi_ldp::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
let proof_bad = ProofSuiteType::Ed25519BLAKE2BDigestSize20Base58CheckEncodedSignature2021
.sign(
&vc_no_proof,
&issue_options,
Expand Down Expand Up @@ -1520,8 +1519,7 @@ mod tests {
// Check that proof JWK must match proof verificationMethod
let mut vc_wrong_key = vc_no_proof.clone();
let other_key = JWK::generate_p256().unwrap();
use ssi_ldp::ProofSuite;
let proof_bad = ssi_ldp::P256BLAKE2BDigestSize20Base58CheckEncodedSignature2021
let proof_bad = ProofSuiteType::P256BLAKE2BDigestSize20Base58CheckEncodedSignature2021
.sign(
&vc_no_proof,
&issue_options,
Expand Down
2 changes: 1 addition & 1 deletion examples/zcap_invocation.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "urn:uuid:ad86cb2c-e9db-434a-beae-71b82120a8a4",
"capabilityAction": "Drive",
"proof": {
"type": "RsaSignature2016",
"type": "Ed25519Signature2018",
"proofPurpose": "capabilityInvocation",
"capability": "https://whatacar.example/a-fancy-car/proc/7a397d7b",
"created": "2016-02-08T17:13:48Z",
Expand Down
26 changes: 22 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,56 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg), feature(doc_cfg))]

// maintain old structure here
pub use ssi_caips as caips;
#[deprecated = "Use ssi::caips::caip10"]
pub use ssi_caips::caip10;
#[deprecated = "Use ssi::caips::caip2"]
pub use ssi_caips::caip2;
pub use ssi_core as core;
#[deprecated = "Use ssi::core::one_or_many"]
pub use ssi_core::one_or_many;
pub use ssi_crypto as crypto;
#[deprecated = "Use ssi::crypto::hashes"]
pub use ssi_crypto::hashes as hash;
#[cfg(feature = "eip")]
#[deprecated = "Use ssi::crypto::hashes::keccak"]
pub use ssi_crypto::hashes::keccak;
#[cfg(feature = "bbs")]
#[deprecated = "Use ssi::crypto::signatures::bbs"]
pub use ssi_crypto::signatures::bbs;
pub use ssi_dids as did;
#[deprecated = "Use ssi::did::did_resolve"]
pub use ssi_dids::did_resolve;
pub use ssi_json_ld as jsonld;
#[deprecated = "Use ssi::jsonld::rdf"]
pub use ssi_json_ld::rdf;
#[deprecated = "Use ssi::jsonld::urdna2015"]
pub use ssi_json_ld::urdna2015;
pub use ssi_jwk as jwk;
#[cfg(feature = "aleo")]
#[deprecated = "Use ssi::jwk::aleo"]
pub use ssi_jwk::aleo;
#[deprecated = "Use ssi::jwk::blakesig"]
pub use ssi_jwk::blakesig;
#[deprecated = "Use ssi::jwk::der"]
pub use ssi_jwk::der;
#[cfg(feature = "ripemd-160")]
#[deprecated = "Use ssi::jwk::ripemd160"]
pub use ssi_jwk::ripemd160 as ripemd;
pub use ssi_jws as jws;
pub use ssi_jwt as jwt;
pub use ssi_ldp as ldp;
#[cfg(feature = "eip")]
#[deprecated = "Use ssi::ldp::eip712"]
pub use ssi_ldp::eip712;
#[deprecated = "Use ssi::ldp::soltx"]
pub use ssi_ldp::soltx;
pub use ssi_ssh as ssh;
pub use ssi_tzkey as tzkey;
pub use ssi_ucan as ucan;
pub use ssi_vc as vc;
#[deprecated = "Use ssi::vc::revocation"]
pub use ssi_vc::revocation;
pub use ssi_zcap_ld as zcap;
pub use vc::revocation;

#[cfg(feature = "aleo")]
pub use ssi_jwk::aleo;

pub const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
2 changes: 1 addition & 1 deletion ssi-dids/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ pub enum DIDMethodError {
/// Registries](https://www.w3.org/TR/did-spec-registries/#did-methods).
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait DIDMethod: Sync {
pub trait DIDMethod: Sync + Send {
/// Get the DID method's name.
///
/// `method-name` in [DID Syntax](https://w3c.github.io/did-core/#did-syntax).
Expand Down
4 changes: 2 additions & 2 deletions ssi-jws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ pub fn prepare_detached_unencoded_payload(
Ok((header, signing_input))
}

pub fn complete_sign_unencoded_payload(header: Header, sig_b64: &str) -> Result<String, Error> {
let header_b64 = base64_encode_json(&header)?;
pub fn complete_sign_unencoded_payload(header: &Header, sig_b64: &str) -> Result<String, Error> {
let header_b64 = base64_encode_json(header)?;
let jws = header_b64 + ".." + sig_b64;
Ok(jws)
}
Expand Down
1 change: 1 addition & 0 deletions ssi-ldp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ aleo = ["ssi-jws/aleo", "ssi-caips/aleo"]
solana = []

example-http-issuer = []
test = []

[dependencies]
thiserror = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions ssi-ldp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub enum Error {
UnsupportedNonDIDIssuer(String),
#[error("Missing proof purpose")]
MissingProofPurpose,
#[error("Linked Data Proof type not implemented")]
ProofTypeNotImplemented,
#[error("Linked Data Proof type not implemented or not enabled by feature")]
ProofTypeNotSupported,
#[error("Unsupported curve")]
UnsupportedCurve,
#[error("Missing type")]
Expand Down
Loading