decentralized-identity / veramo

A JavaScript Framework for Verifiable Data
https://veramo.io
Apache License 2.0
431 stars 131 forks source link

remote agents returns VCs three times #1285

Closed cre8 closed 10 months ago

cre8 commented 11 months ago

Bug severity 5

Describe the bug When using the remote agent plugin, each VC is included three times in the http response:

image

image

To Reproduce Steps to reproduce the behaviour: 1 include the remote and client plugin 2 write a credential to the database 3 request it via the remote client

When I fetch the credentials directly in the backend code, I get two credentials back. So the problem is not in the dataStoreORMGetVerifiableCredentials, but in the usage when used via the remote call.

Observed behaviour Results do not match. I haven't checked if other functions behave the same or if it's only the dataStoreORMGetVerifiableCredentials call.

Expected behaviour That the remote call returns the same result as the "normal" call.

Details If applicable, add screenshots, error messages or stack traces to help explain your problem.

Additional context Add any other context about the problem here.

Versions (please complete the following information):

mirceanis commented 10 months ago

The method you are using based on the screenshot seems to be dataStoreORMGetVerifiableCredentialsByClaims (I know, we probably could pick a better name). But what happens is that when a credential is stored, an entry is also added to the claims table for each property of the credentialSubject. Then, if multiple claims from a credential are matching (like when you aren't adding any conditions to the query), you get a credential result for each match, which happens to be the same credential.

This is indeed a bug, as the method name suggests that credentials are returned, so they should be unique.

The fix should be simple as the credentials can be grouped by hash here: https://github.com/decentralized-identity/veramo/blob/462735d138bc4984c0fcf3f72ca7d49e3187ceb7/packages/data-store/src/data-store-orm.ts#L205C36-L205C36

I think the bug doesn't appear in @veramo/data-store-json as credentials from the claim query are first added to a Set before being mapped to the result.

Do you have bandwidth to propose a PR with a fix?


Also, what tool are you using to look at the database? perhaps we can suggest it as a debugging tool in our docs

cre8 commented 10 months ago

I think I can assign the issue to myself.

I used an extension for vscode called sqltools