Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Add an endpoint to verify presentations #630

Merged
merged 13 commits into from
Aug 3, 2023

Conversation

decentralgabe
Copy link
Contributor

@decentralgabe decentralgabe commented Aug 3, 2023

fix #631

  • adds an endpoint to verify verifiable presentations
  • refactored the internal/credential package to be a more generic verifier

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2023

Codecov Report

Merging #630 (ba132b3) into main (5710ace) will decrease coverage by 0.10%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #630      +/-   ##
==========================================
- Coverage   26.64%   26.54%   -0.10%     
==========================================
  Files          55       55              
  Lines        5855     5876      +21     
==========================================
  Hits         1560     1560              
- Misses       4023     4044      +21     
  Partials      272      272              
Files Changed Coverage Δ
pkg/server/router/credential.go 2.91% <ø> (ø)
pkg/server/router/presentation.go 2.38% <0.00%> (-0.16%) ⬇️
pkg/service/did/ion.go 62.31% <ø> (ø)

gabe added 2 commits August 3, 2023 09:19
…n-endpoint

* origin/main:
  Update API Docs (#629)
  Retrieve pagination parameters from the correct location (#627)

# Conflicts:
#	doc/swagger.yaml
#	pkg/server/router/credential.go
@decentralgabe decentralgabe force-pushed the issue-615-verification-endpoint branch from 740a33a to ba132b3 Compare August 3, 2023 16:20
Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nits.

Would be nice to add an integration tests for this.

internal/verification/verification.go Outdated Show resolved Hide resolved
internal/verification/verification.go Outdated Show resolved Hide resolved
kid, ok := jwtKID.(string)
if !ok {
return sdkutil.LoggingNewError("JWT kid is not a string")
issuerKey, err := did.GetKeyFromVerificationMethod(issuerDID.Document, issuerKID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issuerPublicKey for clarity of future readers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

internal/verification/verification.go Outdated Show resolved Hide resolved
internal/verification/verification.go Outdated Show resolved Hide resolved
Comment on lines 161 to 169
// for each credential in the presentation, run a set of static verification checks
for _, cred := range vp.VerifiableCredential {
_, _, normalizedCred, err := parsing.ToCredential(cred)
if err != nil {
return errors.Wrapf(err, "error parsing credential in presentation<%v>", cred)
}
if err = v.staticValidationChecks(ctx, *normalizedCred); err != nil {
return errors.Wrapf(err, "error running static validation checks on credential in presentation<%v>", normalizedCred.ID)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reusing some of the stuff we have:

	creds, err := NewCredentialContainerFromArray(vp.VerifiableCredential)
	if err != nil {
		return err
	}
	for _, cred := range creds {
		if err := v.Verify(ctx, cred); err != nil {
			return err
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice forgot about this. ideally some of this logic should move to the sdk to mirror the credential functionality

pkg/server/router/presentation.go Outdated Show resolved Hide resolved
pkg/server/router/presentation.go Outdated Show resolved Hide resolved
Holder: holderDID.String(),
}

// invalid verifiable presentation with no credentials
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere, better to use t.Run("verifying verifiable presentation with no credentials returns false", func ... if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was following the pattern you had below...

t.Run("Create returns error without input descriptors", func(tt *testing.T) {
s := test.ServiceStorage(tt)
pRouter, _ := setupPresentationRouter(tt, s)
tt.Run("Create returns error without input descriptors", func(ttt *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was doing the SQL implementation I realized why this approach isn't great. There is not reason why code should need to access the upper level *testing.T object. In fact, using the incorrect t leads to incorrect setup which is very difficult to catch.

Can you elaborate why it's preferred to use the t, tt, ttt approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is that each test runner should be able to act independently, if we look at what's provided by t *testing.T we see that it's a test context responsible for the lifecycle of a test...so separating it out per running test has a few benefits:

  • a child failing test won't result in a parent failing test (we want to see all failures individually)
  • individual tests can be skipped / toggled by using t.Skip()
  • individual tests can have their own cleanup functions using t.Cleanup()

probably more too. just better isolation/separation of concerns

separately -- I think it's a mistake to couple storage to these tests. I believe we should have a separate set of storage tests that do a kind of "steel thread" for the service's functionality instead of running every test for every storage provider

@decentralgabe
Copy link
Contributor Author

feedback accepted - added an action in this ticket to add an integration test for all verification endpoints #615

@decentralgabe decentralgabe merged commit f1b0954 into main Aug 3, 2023
@decentralgabe decentralgabe deleted the issue-615-verification-endpoint branch August 3, 2023 19:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support verifying Verifiable Presentations
3 participants