Skip to content

Commit 4ee626d

Browse files
authored
fix(data-store): match claims by credential hash when deleting credential (#1270)
fixes #1269
1 parent 7afe010 commit 4ee626d

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

__tests__/localJsonStoreAgent.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import messageHandler from './shared/messageHandler'
7777
import utils from './shared/utils'
7878
import { JsonFileStore } from './utils/json-file-store'
7979
import credentialStatus from './shared/credentialStatus'
80+
import dbInitOptions from "./shared/dbInitOptions";
8081

8182
jest.setTimeout(120000)
8283

@@ -238,4 +239,5 @@ describe('Local json-data-store integration tests', () => {
238239
didCommPacking(testContext)
239240
utils(testContext)
240241
credentialStatus(testContext)
242+
dbInitOptions(testContext)
241243
})

__tests__/shared/dbInitOptions.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,53 @@ export default (testContext: {
201201
})
202202
expect(retrievedCredential.length).toBeGreaterThan(0)
203203
})
204+
205+
it('should delete credentials without clearing the claims table', async () => {
206+
const credA = await agent.createVerifiableCredential({
207+
proofFormat: 'jwt',
208+
credential: {
209+
type: ['Important'],
210+
credentialSubject: {
211+
important: 'yes',
212+
serious: true,
213+
},
214+
issuer: identifier.did,
215+
},
216+
})
217+
const credB = await agent.createVerifiableCredential({
218+
proofFormat: 'jwt',
219+
credential: {
220+
type: ['Unimportant'],
221+
credentialSubject: {
222+
bla: 'bla',
223+
},
224+
issuer: identifier.did,
225+
},
226+
})
227+
228+
const credAhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credA })
229+
const credBhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credB })
230+
231+
const queryBeforeDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({
232+
where: [
233+
{ column: 'type', value: ['important'] },
234+
{ column: 'value', value: ['yes'] },
235+
],
236+
})
237+
expect(queryBeforeDelete.length).toBeGreaterThan(0)
238+
expect(queryBeforeDelete[0].hash).toEqual(credAhash)
239+
240+
await agent.dataStoreDeleteVerifiableCredential({ hash: credBhash })
241+
242+
const queryAfterDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({
243+
where: [
244+
{ column: 'type', value: ['important'] },
245+
{ column: 'value', value: ['yes'] },
246+
],
247+
})
248+
expect(queryAfterDelete.length).toBeGreaterThan(0)
249+
expect(queryAfterDelete[0].hash).toEqual(credAhash)
250+
})
204251
})
205252
}
206253
})

packages/data-store/src/data-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class DataStore implements IAgentPlugin {
9898

9999
const claims = await (await getConnectedDb(this.dbConnection))
100100
.getRepository(Claim)
101-
.find({ where: { credential: { id: credentialEntity.id } } as any })
101+
.find({ where: { credential: { hash: credentialEntity.hash } } })
102102

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

0 commit comments

Comments
 (0)