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

Types are saved as string, not as array #1234

Open
cre8 opened this issue Aug 30, 2023 · 1 comment
Open

Types are saved as string, not as array #1234

cre8 opened this issue Aug 30, 2023 · 1 comment
Labels
bug Something isn't working pinned don't close this just for being stale

Comments

@cre8
Copy link
Contributor

cre8 commented Aug 30, 2023

Bug severity
2

Describe the bug
The dataStoreORMGetVerifiableCredentialsCount can be used to count all VCs that have the same type. According to the Implementation the field value from where needs an array like:

agent.dataStoreORMGetVerifiableCredentialsCount({
        where: [
          {
            column: 'type',
            value: ['VerifiableCredential', 'StatusList2021'],
          },
        ],
      });

But this will always return 0 since the values of the field type are stored as a joined string and not as an array:
image

There is also no mentioning in the documentation about this handling...

To Reproduce
Steps to reproduce the behaviour:

  1. Insert a credential that has more than one type:
agent.createVerifiableCredential({
        credential: {
          '@context': [
            'https://www.w3.org/2018/credentials/v1',
            'https://w3id.org/vc/status-list/v1',
          ],
          id,
          type: ['VerifiableCredential', 'StatusList2021'],
          issuer: this.configService.get('ISSUER_DID') as string,
          credentialSubject: {
            id: `${id}#list`,
            encodedList,
          },
        },
        proofFormat: 'jwt',
      });
    const res = await this.agentService.agent.dataStoreSaveVerifiableCredential(
      {
        verifiableCredential,
      },
    );
  1. count for the VCs with this type
agent.dataStoreORMGetVerifiableCredentialsCount({
        where: [
          {
            column: 'type',
            value: ['VerifiableCredential', 'StatusList2021'],
          },
        ],
      });

Joining the value fields works:

agent.dataStoreORMGetVerifiableCredentialsCount({
        where: [
          {
            column: 'type',
            value: ['VerifiableCredential,StatusList2021'],
          },
        ],
      });

Observed behaviour
According to the specs the @context field "MUST" be an ordered set, so an array without nested structures should be the case here.

Expected behaviour
Treating the field as a json field and not a string should solve the problem

Versions (please complete the following information):

  • Veramo: 5.4.1
  • Node Version 18.7.1
@cre8 cre8 added the bug Something isn't working label Aug 30, 2023
@mirceanis mirceanis added triage pinned don't close this just for being stale labels Aug 30, 2023
@mirceanis
Copy link
Member

mirceanis commented Sep 21, 2023

We chose to use the simple-array column type defined by TypeORM for the type and @context properties of credentials and presentations because it works essentially with any database driver that TypeORM supports.
Otherwise we would be limited to PostgreSQL or CockroachDB only.

Knowing this, here are some example queries to get credentials by type:

Using the "In" operator (default), or "Equal"

const credentialsEqual = await agent.dataStoreORMGetVerifiableCredentials({
        where: [
          {
            column: 'type',
            value: ['VerifiableCredential,StatusList2021'], // join the strings
            op: 'Equal' // if `op` is not specified, "In" is implied
          },
        ],
      });
const credentialsLike = await agent.dataStoreORMGetVerifiableCredentials({
        where: [
          {
            column: 'type',
            value: ['%StatusList2021%'], // use the Like operation with `%` as the wildcard character
            op: 'Like'
          },
        ],
      });

@mirceanis mirceanis removed the triage label Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned don't close this just for being stale
Projects
None yet
Development

No branches or pull requests

2 participants