Skip to content

Commit

Permalink
feat(credential-w3c): align verification API between formats
Browse files Browse the repository at this point in the history
fixes #935
fixes #954
fixes #375
  • Loading branch information
mirceanis committed Aug 19, 2022
1 parent 06b3147 commit bd7382c
Show file tree
Hide file tree
Showing 21 changed files with 454 additions and 302 deletions.
26 changes: 13 additions & 13 deletions __tests__/shared/credentialStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export default (testContext: {
})
expect(vc).toHaveProperty('proof.jwt')

const verified = await agent.verifyCredential({ credential: vc })
const result = await agent.verifyCredential({ credential: vc })
expect(callsCounter).toHaveBeenCalledTimes(1)
expect(verified).toBeTruthy()
expect(result.verified).toEqual(true)
})

it('should check credentialStatus for revoked JWT credential', async () => {
Expand All @@ -114,9 +114,9 @@ export default (testContext: {
})
expect(vc).toHaveProperty('proof.jwt')

const verified = await agent.verifyCredential({ credential: vc })
const result = await agent.verifyCredential({ credential: vc })
expect(callsCounter).toHaveBeenCalledTimes(1)
expect(verified).toBeFalsy()
expect(result.verified).toEqual(false)
})

it('should fail checking credentialStatus with exception during verification', async () => {
Expand Down Expand Up @@ -152,9 +152,9 @@ export default (testContext: {
})
expect(vc).toHaveProperty('proof.jws')

const verified = await agent.verifyCredential({ credential: vc })
const result = await agent.verifyCredential({ credential: vc })
expect(callsCounter).toHaveBeenCalledTimes(1)
expect(verified).toBeTruthy()
expect(result.verified).toEqual(true)
})

it('should check credentialStatus for revoked JSON-LD credential', async () => {
Expand All @@ -164,9 +164,9 @@ export default (testContext: {
})
expect(vc).toHaveProperty('proof.jws')

const verified = await agent.verifyCredential({ credential: vc })
const result = await agent.verifyCredential({ credential: vc })
expect(callsCounter).toHaveBeenCalledTimes(1)
expect(verified).toBeFalsy()
expect(result.verified).toEqual(false)
})

it('should check credentialStatus for EIP712 credential', async () => {
Expand All @@ -176,9 +176,9 @@ export default (testContext: {
})
expect(vc).toHaveProperty('proof.proofValue')

const verified = await agent.verifyCredential({ credential: vc })
const result = await agent.verifyCredential({ credential: vc })
expect(callsCounter).toHaveBeenCalledTimes(1)
expect(verified).toBeTruthy()
expect(result.verified).toEqual(true)
})

it('should check credentialStatus for revoked EIP712 credential', async () => {
Expand All @@ -188,9 +188,9 @@ export default (testContext: {
})
expect(vc).toHaveProperty('proof.proofValue')

const verified = await agent.verifyCredential({ credential: vc })
const result = await agent.verifyCredential({ credential: vc })
expect(callsCounter).toHaveBeenCalledTimes(1)
expect(verified).toBeFalsy()
expect(result.verified).toEqual(false)
})
})

Expand Down Expand Up @@ -235,7 +235,7 @@ export default (testContext: {

// TODO It`s an exception flow an it'd be better to throw an exception instead of returning false
await expect(agent.verifyCredential({ credential: vc })).rejects.toThrow(
`The credential status can't be verified by the agent`,
`invalid_config: The credential status can't be verified because there is no ICredentialStatusVerifier plugin installed.`,
)
})
})
Expand Down
17 changes: 8 additions & 9 deletions __tests__/shared/verifiableDataLD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default (testContext: {
credential: verifiableCredential,
})

expect(result).toEqual(true)
expect(result.verified).toEqual(true)
})

it('should handleMessage with VC (non-JWT)', async () => {
Expand All @@ -98,20 +98,19 @@ export default (testContext: {
hash: storedCredentialHash,
})

// tamper with credential
verifiableCredential.credentialSubject.name = 'Martin, the not so greats'

try {
await agent.handleMessage({
await expect(
agent.handleMessage({
raw: JSON.stringify({
body: verifiableCredential,
type: 'w3c.vc',
}),
save: false,
metaData: [{ type: 'LDS' }],
})
} catch (e) {
expect(e).toEqual(Error('Error verifying LD Verifiable Credential'))
}
}),
).rejects.toThrow(/Verification error/)
})

it('should sign a verifiable presentation in LD', async () => {
Expand Down Expand Up @@ -164,7 +163,7 @@ export default (testContext: {
domain,
})

expect(result).toBeTruthy()
expect(result.verified).toEqual(true)
})

it('should handleMessage with VPs (non-JWT)', async () => {
Expand Down Expand Up @@ -244,7 +243,7 @@ export default (testContext: {
credential: verifiableCredential,
})

expect(result).toEqual(true)
expect(result.verified).toEqual(true)
})
})
}
2 changes: 1 addition & 1 deletion packages/cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ credential
}
try {
const result = await agent.verifyCredential({ credential: credentialAsJSON })
if (result === true) {
if (result.verified === true) {
console.log('Credential was verified successfully.')
} else {
console.error('Credential could not be verified.')
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
},
"dependencies": {
"debug": "^4.3.3",
"did-jwt-vc": "^2.1.14",
"did-jwt-vc": "3.0.1",
"events": "^3.2.0",
"z-schema": "^5.0.2"
},
"devDependencies": {
"@types/debug": "4.1.7",
"did-resolver": "^4.0.0",
"credential-status": "^2.0.5",
"credential-status": "2.0.5",
"did-resolver": "4.0.0",
"typescript": "4.7.3"
},
"files": [
Expand Down
Loading

0 comments on commit bd7382c

Please sign in to comment.