spruceid / ssi

Core library for decentralized identity.
https://spruceid.dev
Apache License 2.0
193 stars 61 forks source link

Verifier simplification. #559

Closed timothee-haudebourg closed 3 months ago

timothee-haudebourg commented 3 months ago

Currently the VerifiableClaims::verify function (or more precisely verify_with) takes a "verifier" and an "environment". The "verifier" is in fact a public key resolver (W3C verification method resolver or JWK resolver, etc), while the environment provides any other resource required to validate the claims and signature.

I realized there is no real reason to separate the resolver from the environment. Merging them into a single verifier allows us to remove an input argument to many functions (including VerifiableClaims::verify) and remove a type parameter to some traits. This is the purpose of this PR.

Here is an overview of the changes:

The only downside is that the verify function must take an actual verifier as parameter, and not just the public key resolver. A verifier can be built from a resolver using Verifier::from_resolver. It's one more step, but I also think it makes more sense while making customizing the verifier easier. For instance its possible to customize the JSON-LD context loader while constructing the verifier with one line:

// Create verifier with custom LD loader.
let verifier = Verifier::from_resolver(my_resolver).with_json_ld_loader(my_custom_loader);

// Verify the claims.
vc.verify(&verifier).await;

Before, you would need to construct your own verification environment and use verify_with instead of verify.

timothee-haudebourg commented 3 months ago

Also, I renamed the DIDResolver::with_default_options function into into_vm_resolver to make it clear that it turns a DID resolver into a verification method resolver.

timothee-haudebourg commented 3 months ago

I've renamed all the *Environment traits into *Provider, added a dedicated verify function for each secured claim type (CompactJWS, DecodedJWS and DataIntegrity), renamed Verifier into VerificationParameters and added more documentation about verification parameters.