Skip to content

Commit

Permalink
Rename with_default_options into into_vm_resolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothee-haudebourg committed Jul 1, 2024
1 parent 992f764 commit c67ad8c
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let jwt = CompactJWSString::from_string(
// public key used to sign the JWT.
// Here we use the example `ExampleDIDResolver` resolver, enabled with the
// `example` feature.
let vm_resolver = ExampleDIDResolver::default().with_default_options::<AnyJwkMethod>();
let vm_resolver = ExampleDIDResolver::default().into_vm_resolver::<AnyJwkMethod>();

// Verify the JWT.
assert!(jwt.verify(&vm_resolver).await.expect("verification failed").is_ok())
Expand All @@ -89,7 +89,7 @@ let vc = ssi::claims::vc::v1::data_integrity::any_credential_from_json_str(

// Setup a verification method resolver, in charge of retrieving the
// public key used to sign the JWT.
let vm_resolver = ExampleDIDResolver::default().with_default_options();
let vm_resolver = ExampleDIDResolver::default().into_vm_resolver();

assert!(vc.verify(&vm_resolver).await.expect("verification failed").is_ok());
```
Expand Down Expand Up @@ -133,7 +133,7 @@ let jwt = claims.sign(&key).await.expect("signature failed");

// Create a verification method resolver, which will be in charge of
// decoding the DID back into a public key.
let vm_resolver = DIDJWK.with_default_options::<AnyJwkMethod>();
let vm_resolver = DIDJWK.into_vm_resolver::<AnyJwkMethod>();

// Verify the JWT.
assert!(jwt.verify(&vm_resolver).await.expect("verification failed").is_ok());
Expand Down Expand Up @@ -181,7 +181,7 @@ let did = DIDJWK::generate_url(&key.to_public());

// Create a verification method resolver, which will be in charge of
// decoding the DID back into a public key.
let vm_resolver = DIDJWK.with_default_options();
let vm_resolver = DIDJWK.into_vm_resolver();

// Create a signer from the secret key.
// Here we use the simple `SingleSecretSigner` signer type which always uses
Expand Down
17 changes: 15 additions & 2 deletions crates/dids/core/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,27 @@ pub trait DIDResolver {
self.dereference_with(did_url, Options::default()).await
}

fn with_options<M>(self, options: Options) -> VerificationMethodDIDResolver<Self, M>
/// Turns this DID resolver into a verification method resolver.
///
/// To resolve a verification method, the output resolver will first
/// resolve the DID using the given `options` then pull the referenced
/// method from the DID document.
fn into_vm_resolver_with<M>(self, options: Options) -> VerificationMethodDIDResolver<Self, M>
where
Self: Sized,
{
VerificationMethodDIDResolver::new_with_options(self, options)
}

fn with_default_options<M>(self) -> VerificationMethodDIDResolver<Self, M>
/// Turns this DID resolver into a verification method resolver.
///
/// To resolve a verification method, the output resolver will first
/// resolve the DID then pull the referenced method from the DID document.
///
/// This is equivalent to calling
/// [`into_vm_resolver_with`](DIDResolver::into_vm_resolver_with)
/// with the default options.
fn into_vm_resolver<M>(self) -> VerificationMethodDIDResolver<Self, M>
where
Self: Sized,
{
Expand Down
4 changes: 2 additions & 2 deletions crates/dids/methods/ethr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ mod tests {
}

async fn credential_prove_verify_did_ethr2(eip712: bool) {
let didethr = DIDEthr.with_default_options();
let didethr = DIDEthr.into_vm_resolver();
let verifier = Verifier::from_resolver(&didethr);
let key: JWK = serde_json::from_value(json!({
"alg": "ES256K-R",
Expand Down Expand Up @@ -592,7 +592,7 @@ mod tests {

#[tokio::test]
async fn credential_verify_eip712vm() {
let didethr = DIDEthr.with_default_options();
let didethr = DIDEthr.into_vm_resolver();
let vc = ssi_claims::vc::v1::data_integrity::any_credential_from_json_str(include_str!(
"../tests/vc.jsonld"
))
Expand Down
2 changes: 1 addition & 1 deletion examples/issue-revocation-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn main() {
let signer = SingleSecretSigner::new(key.clone()).into_local();

// DID resolver.
let resolver = ssi::dids::example::ExampleDIDResolver::default().with_default_options();
let resolver = ssi::dids::example::ExampleDIDResolver::default().into_vm_resolver();
let verifier = Verifier::from_resolver(&resolver);

let mut rl = RevocationList2020::default();
Expand Down
2 changes: 1 addition & 1 deletion examples/issue-status-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() {
let signer = SingleSecretSigner::new(key.clone()).into_local();

// DID resolver.
let resolver = ssi::dids::example::ExampleDIDResolver::default().with_default_options();
let resolver = ssi::dids::example::ExampleDIDResolver::default().into_vm_resolver();
let verifier = Verifier::from_resolver(&resolver);

let mut rl = StatusList2021::new(131072).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use static_iref::iri;
async fn main() {
let key_str = include_str!("../tests/rsa2048-2020-08-25.json");
let key: ssi::jwk::JWK = serde_json::from_str(key_str).unwrap();
let resolver = ssi::dids::example::ExampleDIDResolver::default().with_default_options();
let resolver = ssi::dids::example::ExampleDIDResolver::default().into_vm_resolver();
let verifier = Verifier::from_resolver(&resolver);
let signer = SingleSecretSigner::new(key.clone()).into_local();

Expand Down
2 changes: 1 addition & 1 deletion examples/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn verify(proof_format_in: &str, proof_format_out: &str, input_vc: &str) {
let key_str = include_str!("../tests/ed25519-2020-10-18.json");
let mut key: ssi::jwk::JWK = serde_json::from_str(key_str).unwrap();
key.key_id = Some("did:example:foo#key2".to_string());
let resolver = ssi::dids::example::ExampleDIDResolver::default().with_default_options();
let resolver = ssi::dids::example::ExampleDIDResolver::default().into_vm_resolver();
let verifier = Verifier::from_resolver(&resolver);
let signer = SingleSecretSigner::new(key.clone()).into_local();

Expand Down
2 changes: 1 addition & 1 deletion examples/vc_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn create_verifier() -> Verifier<VerificationMethodDIDResolver<StaticDIDResolver

// Turn the DID resolver into a verification method resolver by setting
// resolution options.
let resolver = did_resolver.with_default_options();
let resolver = did_resolver.into_vm_resolver();

// Create a verifier using the verification method resolver.
Verifier::from_resolver(resolver)
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
//! // public key used to sign the JWT.
//! // Here we use the example `ExampleDIDResolver` resolver, enabled with the
//! // `example` feature.
//! let vm_resolver = ExampleDIDResolver::default().with_default_options::<AnyJwkMethod>();
//! let vm_resolver = ExampleDIDResolver::default().into_vm_resolver::<AnyJwkMethod>();
//!
//! // Create a verifier from our verification method resolver.
//! let verifier = Verifier::from_resolver(vm_resolver);
Expand Down Expand Up @@ -93,7 +93,7 @@
//!
//! // Setup a verification method resolver, in charge of retrieving the
//! // public key used to sign the JWT.
//! let vm_resolver = ExampleDIDResolver::default().with_default_options();
//! let vm_resolver = ExampleDIDResolver::default().into_vm_resolver();
//!
//! // Create a verifier from our verification method resolver.
//! let verifier = Verifier::from_resolver(vm_resolver);
Expand Down Expand Up @@ -143,7 +143,7 @@
//!
//! // Create a verification method resolver, which will be in charge of
//! // decoding the DID back into a public key.
//! let vm_resolver = DIDJWK.with_default_options::<AnyJwkMethod>();
//! let vm_resolver = DIDJWK.into_vm_resolver::<AnyJwkMethod>();
//!
//! // Create a verifier from our verification method resolver.
//! let verifier = Verifier::from_resolver(vm_resolver);
Expand Down Expand Up @@ -198,7 +198,7 @@
//!
//! // Create a verification method resolver, which will be in charge of
//! // decoding the DID back into a public key.
//! let vm_resolver = DIDJWK.with_default_options();
//! let vm_resolver = DIDJWK.into_vm_resolver();
//!
//! // Create a signer from the secret key.
//! // Here we use the simple `SingleSecretSigner` signer type which always uses
Expand Down
2 changes: 1 addition & 1 deletion tests/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn data_integrity_sign_is_send() {

let key = JWK::generate_p256(); // requires the `p256` feature.
let did = DIDJWK::generate_url(&key.to_public());
let vm_resolver = DIDJWK.with_default_options();
let vm_resolver = DIDJWK.into_vm_resolver();
let signer = SingleSecretSigner::new(key.clone()).into_local();
let verification_method = did.into_iri().into();

Expand Down

0 comments on commit c67ad8c

Please sign in to comment.