Skip to content

Commit

Permalink
fix(data-store): match claims by credential hash when deleting creden…
Browse files Browse the repository at this point in the history
…tial (#1270)

fixes #1269
  • Loading branch information
mirceanis authored Oct 6, 2023
1 parent 7afe010 commit 4ee626d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import messageHandler from './shared/messageHandler'
import utils from './shared/utils'
import { JsonFileStore } from './utils/json-file-store'
import credentialStatus from './shared/credentialStatus'
import dbInitOptions from "./shared/dbInitOptions";

jest.setTimeout(120000)

Expand Down Expand Up @@ -238,4 +239,5 @@ describe('Local json-data-store integration tests', () => {
didCommPacking(testContext)
utils(testContext)
credentialStatus(testContext)
dbInitOptions(testContext)
})
47 changes: 47 additions & 0 deletions __tests__/shared/dbInitOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,53 @@ export default (testContext: {
})
expect(retrievedCredential.length).toBeGreaterThan(0)
})

it('should delete credentials without clearing the claims table', async () => {
const credA = await agent.createVerifiableCredential({
proofFormat: 'jwt',
credential: {
type: ['Important'],
credentialSubject: {
important: 'yes',
serious: true,
},
issuer: identifier.did,
},
})
const credB = await agent.createVerifiableCredential({
proofFormat: 'jwt',
credential: {
type: ['Unimportant'],
credentialSubject: {
bla: 'bla',
},
issuer: identifier.did,
},
})

const credAhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credA })
const credBhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credB })

const queryBeforeDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({
where: [
{ column: 'type', value: ['important'] },
{ column: 'value', value: ['yes'] },
],
})
expect(queryBeforeDelete.length).toBeGreaterThan(0)
expect(queryBeforeDelete[0].hash).toEqual(credAhash)

await agent.dataStoreDeleteVerifiableCredential({ hash: credBhash })

const queryAfterDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({
where: [
{ column: 'type', value: ['important'] },
{ column: 'value', value: ['yes'] },
],
})
expect(queryAfterDelete.length).toBeGreaterThan(0)
expect(queryAfterDelete[0].hash).toEqual(credAhash)
})
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/data-store/src/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class DataStore implements IAgentPlugin {

const claims = await (await getConnectedDb(this.dbConnection))
.getRepository(Claim)
.find({ where: { credential: { id: credentialEntity.id } } as any })
.find({ where: { credential: { hash: credentialEntity.hash } } })

await (await getConnectedDb(this.dbConnection)).getRepository(Claim).remove(claims)

Expand Down

0 comments on commit 4ee626d

Please sign in to comment.