Skip to content

Commit

Permalink
fix: fixed failing test cases and added more test cases for getting d…
Browse files Browse the repository at this point in the history
…ata from the raw data
  • Loading branch information
sksadjad committed Feb 28, 2024
1 parent 55a3721 commit 6f5b50b
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 56 deletions.
184 changes: 178 additions & 6 deletions packages/data-store/src/__tests__/digitalCredential.entities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
CredentialCorrelationType,
CredentialDocumentFormat,
CredentialType,
NonPersistedDigitalCredential
NonPersistedDigitalCredential,
} from '../types/digitalCredential/digitalCredential'
import { computeEntryHash } from '@veramo/utils'
import { AddDigitalCredentialArgs } from '../types/digitalCredential/IAbstractDigitalCredentialStore'
import {nonPersistedDigitalCredentialEntityFromAddArgs} from "../utils/digitalCredential/MappingUtils";
import { nonPersistedDigitalCredentialEntityFromAddArgs } from '../utils/digitalCredential/MappingUtils'

describe('Database entities tests', (): void => {
let dbConnection: DataSource
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('Database entities tests', (): void => {
const fromDb: DigitalCredentialEntity = await dbConnection.getRepository(DigitalCredentialEntity).save(digitalCredentialEntity)
expect(fromDb).toBeDefined()
expect(fromDb?.id).not.toBeNull()
expect(fromDb?.credentialType).toEqual(CredentialType.C)
expect(fromDb?.credentialType).toEqual(CredentialType.VC)
expect(fromDb?.documentFormat).toEqual(CredentialDocumentFormat.JWT)
expect(fromDb?.raw).toEqual(rawCredential)
expect(fromDb?.hash).toEqual(computeEntryHash(rawCredential))
Expand All @@ -60,7 +60,7 @@ describe('Database entities tests', (): void => {
expect(fromDb?.tenantId).toEqual('urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj')
})

it('should assign correct values to DigitalCredential', () => {
it('should assign correct values to DigitalCredential: jwt credential 1', () => {
const digitalCredential: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs({
raw: 'eyJraWQiOiJkaWQ6a2V5Ono2TWtyaGt5M3B1c20yNk1laUZhWFUzbjJuZWtyYW13RlVtZ0dyZUdHa0RWNnpRaiN6Nk1rcmhreTNwdXNtMjZNZWlGYVhVM24ybmVrcmFtd0ZVbWdHcmVHR2tEVjZ6UWoiLCJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vc3BoZXJlb24tb3BlbnNvdXJjZS5naXRodWIuaW8vc3NpLW1vYmlsZS13YWxsZXQvY29udGV4dC9zcGhlcmVvbi13YWxsZXQtaWRlbnRpdHktdjEuanNvbmxkIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJTcGhlcmVvbldhbGxldElkZW50aXR5Q3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJmaXJzdE5hbWUiOiJTIiwibGFzdE5hbWUiOiJLIiwiZW1haWxBZGRyZXNzIjoic0BrIn19LCJzdWIiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJqdGkiOiJ1cm46dXVpZDpkZGE3YmYyNC04ZTdhLTQxZjgtYjY2Yy1hNDhkYmM1YjEwZmEiLCJuYmYiOjE3MDg0NDA4MDgsImlzcyI6ImRpZDprZXk6ejZNa3Joa3kzcHVzbTI2TWVpRmFYVTNuMm5la3JhbXdGVW1nR3JlR0drRFY2elFqIn0.G0M84XVAxSmzGY-NQuB9NBofNrINSn6lvxW6761Vlq6ypvYgtc2xNdpiRmw8ryVNfnpzrr4Z5cB1RlrC05rJAw',
issuerCorrelationType: CredentialCorrelationType.DID,
Expand All @@ -69,7 +69,179 @@ describe('Database entities tests', (): void => {
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
})
expect(digitalCredential.credentialType).toEqual(CredentialType.C)
expect(digitalCredential.createdAt).toEqual(new Date())
expect(digitalCredential.credentialType).toEqual(CredentialType.VC)
expect(digitalCredential.issuedAt).toEqual(new Date('2024-02-20T14:53:28.000Z'))
expect(digitalCredential.documentFormat).toEqual(CredentialDocumentFormat.JWT)
expect(digitalCredential.expiresAt).toEqual(undefined)
})

it('should assign correct values to DigitalCredential: jwt credential 2', () => {
const digitalCredential: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs({
raw: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDpleGFtcGxlOmFiZmUxM2Y3MTIxMjA0MzFjMjc2ZTEyZWNhYiNrZXlzLTEifQ.eyJzdWIiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsImlzcyI6Imh0dHBzOi8vZXhhbXBsZS5jb20va2V5cy9mb28uandrIiwibmJmIjoxNTQxNDkzNzI0LCJpYXQiOjE1NDE0OTM3MjQsImV4cCI6MTU3MzAyOTcyMywibm9uY2UiOiI2NjAhNjM0NUZTZXIiLCJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJVbml2ZXJzaXR5RGVncmVlQ3JlZGVudGlhbCJdLCJjcmVkZW50aWFsU3ViamVjdCI6eyJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IjxzcGFuIGxhbmc9J2ZyLUNBJz5CYWNjYWxhdXLDqWF0IGVuIG11c2lxdWVzIG51bcOpcmlxdWVzPC9zcGFuPiJ9fX19.KLJo5GAyBND3LDTn9H7FQokEsUEi8jKwXhGvoN3JtRa51xrNDgXDb0cq1UTYB-rK4Ft9YVmR1NI_ZOF8oGc_7wAp8PHbF2HaWodQIoOBxxT-4WNqAxft7ET6lkH-4S6Ux3rSGAmczMohEEf8eCeN-jC8WekdPl6zKZQj0YPB1rx6X0-xlFBs7cl6Wt8rfBP_tZ9YgVWrQmUWypSioc0MUyiphmyEbLZagTyPlUyflGlEdqrZAv6eSe6RtxJy6M1-lD7a5HTzanYTWBPAUHDZGyGKXdJw-W_x0IWChBzI8t3kpG253fg6V3tPgHeKXE94fz_QpYfg--7kLsyBAfQGbg',
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
})
expect(digitalCredential.credentialType).toEqual(CredentialType.VC)
expect(digitalCredential.issuedAt).toEqual(new Date('2018-11-06T08:42:04.000Z'))
expect(digitalCredential.documentFormat).toEqual(CredentialDocumentFormat.JWT)
expect(digitalCredential.expiresAt).toEqual(new Date('2019-11-06T08:42:03.000Z'))
})

it('should assign correct values to DigitalCredential: signed ldb credential', () => {
const digitalCredential: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs({
raw: JSON.stringify({
id: 'cred:gatc:NjMxNjc0NTA0ZjVmZmYwY2U0Y2M3NTRk',
type: ['VerifiableCredential', 'emailCredential'],
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://www.w3.org/2018/credentials/examples/v1'],
issuer: 'did:gatc:24gsRbsURij3edoveHv81jt9EnhggrnR',
issuanceDate: '2022-01-07T11:54:12.000Z',
credentialSubject: {
email: '[email protected]',
id: 'did:gatc:YzQxNjRjM2U4YTUzZGVkNjhmNjAxYzk5',
},
credentialStatus: {
id: 'https://backbone.gataca.io/api/v1/group/otp/status',
type: 'CredentialStatusList2017',
},
credentialSchema: [],
proof: [
{
created: '2022-01-07T11:53:21Z',
creator: 'did:gatc:24gsRbsURij3edoveHv81jt9EnhggrnR#keys-1',
domain: 'gataca.io',
nonce: 'sUzybVzzg1ZXFw-xDqSeMP3-TiZqKOtxszk0K4Ag5X8=',
proofPurpose: 'assertionMethod',
signatureValue: 'qGIh5JLxollEek5l1yFUcwmHj2H1ZYn3PR8uTa5bDtIcpW6MKKJDpc5_YQjqHGVUKbre8EMDI7e07lgR1ZJ9Bg',
type: 'JcsEd25519Signature2020',
verificationMethod: 'did:gatc:24gsRbsURij3edoveHv81jt9EnhggrnR#keys-1',
},
],
}),
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
})
expect(digitalCredential.credentialType).toEqual(CredentialType.VC)
expect(digitalCredential.issuedAt).toEqual(new Date('2022-01-07T11:54:12.000Z'))
expect(digitalCredential.documentFormat).toEqual(CredentialDocumentFormat.JSON_LD)
expect(digitalCredential.expiresAt).toEqual(undefined)
})

it('should assign correct values to DigitalCredential: signed ldb presentation', () => {
const digitalCredential: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs({
raw: JSON.stringify({
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://identity.foundation/presentation-exchange/submission/v1'],
type: ['VerifiablePresentation'],
verifiableCredential: [
{
iss: 'did:example:123',
vc: {
'@context': 'https://eu.com/claims/DriversLicense',
id: 'https://eu.com/claims/DriversLicense',
type: ['EUDriversLicense'],
issuer: 'did:example:123',
issuanceDate: '2010-01-01T19:73:24Z',
credentialSubject: {
id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
accounts: [
{
id: '1234567890',
route: 'DE-9876543210',
},
{
id: '2457913570',
route: 'DE-0753197542',
},
],
},
},
proof: {
type: 'EcdsaSecp256k1VerificationKey2019',
created: '2017-06-18T21:19:10Z',
proofPurpose: 'assertionMethod',
verificationMethod: 'https://example.edu/issuers/keys/1',
jws: '...',
},
},
{
'@context': 'https://business-standards.org/schemas/employment-history.json',
id: 'https://business-standards.org/schemas/employment-history.json',
type: ['VerifiableCredential', 'GenericEmploymentCredential'],
issuer: 'did:foo:123',
issuanceDate: '2010-01-01T19:73:24Z',
credentialSubject: {
id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
active: true,
},
proof: {
type: 'EcdsaSecp256k1VerificationKey2019',
created: '2017-06-18T21:19:10Z',
proofPurpose: 'assertionMethod',
verificationMethod: 'https://example.edu/issuers/keys/1',
jws: '...',
},
},
{
'@context': 'https://www.w3.org/2018/credentials/v1',
id: 'https://eu.com/claims/DriversLicense',
type: ['EUDriversLicense'],
issuer: 'did:foo:123',
issuanceDate: '2010-01-01T19:73:24Z',
credentialSubject: {
id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
license: {
number: '34DGE352',
dob: '07/13/80',
},
},
proof: {
type: 'RsaSignature2018',
created: '2017-06-18T21:19:10Z',
proofPurpose: 'assertionMethod',
verificationMethod: 'https://example.edu/issuers/keys/1',
jws: '...',
},
},
],
proof: {
type: 'RsaSignature2018',
created: '2018-09-14T21:19:10Z',
proofPurpose: 'authentication',
verificationMethod: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',
challenge: '1f44d55f-f161-4938-a659-f8026467f126',
domain: '4jt78h47fh47',
jws: '...',
},
}),
issuerCorrelationType: CredentialCorrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
})
expect(digitalCredential.credentialType).toEqual(CredentialType.VP)
expect(digitalCredential.issuedAt).toEqual(new Date('2018-09-14T21:19:10.000Z'))
expect(digitalCredential.documentFormat).toEqual(CredentialDocumentFormat.JSON_LD)
expect(digitalCredential.expiresAt).toEqual(undefined)
})

it('should assign correct values to DigitalCredential: signed sd_jwt credential', () => {
const digitalCredential: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs({
raw: 'eyJhbGciOiJFZERTQSIsInR5cCI6InZjK3NkLWp3dCIsImtpZCI6IiN6Nk1rdHF0WE5HOENEVVk5UHJydG9TdEZ6ZUNuaHBNbWd4WUwxZ2lrY1czQnp2TlcifQ.eyJ2Y3QiOiJJZGVudGl0eUNyZWRlbnRpYWwiLCJmYW1pbHlfbmFtZSI6IkRvZSIsInBob25lX251bWJlciI6IisxLTIwMi01NTUtMDEwMSIsImFkZHJlc3MiOnsic3RyZWV0X2FkZHJlc3MiOiIxMjMgTWFpbiBTdCIsImxvY2FsaXR5IjoiQW55dG93biIsIl9zZCI6WyJOSm5tY3QwQnFCTUUxSmZCbEM2alJRVlJ1ZXZwRU9OaVl3N0E3TUh1SnlRIiwib201Wnp0WkhCLUdkMDBMRzIxQ1ZfeE00RmFFTlNvaWFPWG5UQUpOY3pCNCJdfSwiY25mIjp7Imp3ayI6eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6Im9FTlZzeE9VaUg1NFg4d0pMYVZraWNDUmswMHdCSVE0c1JnYms1NE44TW8ifX0sImlzcyI6ImRpZDprZXk6ejZNa3RxdFhORzhDRFVZOVBycnRvU3RGemVDbmhwTW1neFlMMWdpa2NXM0J6dk5XIiwiaWF0IjoxNjk4MTUxNTMyLCJfc2RfYWx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orrelationType.DID,
subjectCorrelationType: CredentialCorrelationType.DID,
issuerCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
subjectCorrelationId: 'did:key:z6Mkrhky3pusm26MeiFaXU3n2nekramwFUmgGreGGkDV6zQj',
tenantId: 'urn:uuid:nnag4b43-1e7a-98f8-a32c-a48dbc5b10mj',
})
expect(digitalCredential.credentialType).toEqual(CredentialType.VC)
expect(digitalCredential.issuedAt).toEqual(new Date('2023-10-24T12:45:32.000Z'))
expect(digitalCredential.documentFormat).toEqual(CredentialDocumentFormat.SD_JWT)
expect(digitalCredential.expiresAt).toEqual(undefined)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('Database entities tests', (): void => {
const savedDigitalCredential2: DigitalCredential = await digitalCredentialStore.addDigitalCredential(addCredentialArgs2)
expect(savedDigitalCredential2).toBeDefined()
const args: GetDigitalCredentialsArgs = {
filter: [{ credentialType: CredentialType.VC }],
filter: [{ credentialType: CredentialType.VP }],
}
const result: Array<DigitalCredentialEntity> = await digitalCredentialStore.getDigitalCredentials(args)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
UpdateDigitalCredentialStateArgs,
} from '../types/digitalCredential/IAbstractDigitalCredentialStore'
import { OrPromise } from '@sphereon/ssi-types'
import { DataSource, Repository} from 'typeorm'
import { DataSource, Repository } from 'typeorm'
import Debug from 'debug'
import {DigitalCredentialEntity} from '../entities/digitalCredential/DigitalCredentialEntity'
import {nonPersistedDigitalCredentialEntityFromAddArgs} from '../utils/digitalCredential/MappingUtils'
import {FindOptionsWhere} from 'typeorm/find-options/FindOptionsWhere'
import {CredentialStateType, DigitalCredential, NonPersistedDigitalCredential} from '../types/digitalCredential/digitalCredential'
import { DigitalCredentialEntity } from '../entities/digitalCredential/DigitalCredentialEntity'
import { nonPersistedDigitalCredentialEntityFromAddArgs } from '../utils/digitalCredential/MappingUtils'
import { FindOptionsWhere } from 'typeorm/find-options/FindOptionsWhere'
import { CredentialStateType, DigitalCredential, NonPersistedDigitalCredential } from '../types/digitalCredential/digitalCredential'

const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:credential-store')

Expand Down Expand Up @@ -45,7 +45,7 @@ export class DigitalCredentialStore extends AbstractDigitalCredentialStore {

getDigitalCredentials = async (args?: GetDigitalCredentialsArgs): Promise<Array<DigitalCredentialEntity>> => {
const result: Array<DigitalCredentialEntity> = await (await this.dbConnection).getRepository(DigitalCredentialEntity).find({
...(args?.filter && {where: args?.filter}),
...(args?.filter && { where: args?.filter }),
})
if (!result) {
return Promise.reject(Error(`No credential found for arg: ${args?.toString()}`))
Expand Down Expand Up @@ -97,7 +97,7 @@ export class DigitalCredentialStore extends AbstractDigitalCredentialStore {
...credential,
verificationDate: args.verificationDate ?? new Date(),
lastUpdatedAt: new Date(),
...(args.verifiedState === CredentialStateType.REVOKED && {revocationDate: args.verificationDate ?? new Date()}),
...(args.verifiedState === CredentialStateType.REVOKED && { revocationDate: args.verificationDate ?? new Date() }),
verifiedState: args.verifiedState,
}
debug('Updating credential', credential)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
PartyRelationship,
PartyType,
PartyTypeEnum,
PhysicalAddress
PhysicalAddress,
} from './contact'

export type FindPartyArgs = Array<PartialParty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export type AddDigitalCredentialArgs = {
revocationDate?: Date
}

export type UpdateDigitalCredentialStateArgs = GetDigitalCredentialArgs & { verifiedState: CredentialStateType, verificationDate?: Date }
export type UpdateDigitalCredentialStateArgs = GetDigitalCredentialArgs & { verifiedState: CredentialStateType; verificationDate?: Date }

export type RemoveDigitalCredentialArgs = GetDigitalCredentialArgs
Loading

0 comments on commit 6f5b50b

Please sign in to comment.