Skip to content

Commit

Permalink
fix(cli): fix credential verify command for JWT credentials (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Mar 16, 2023
1 parent 0709d7d commit 697a14c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 4 additions & 9 deletions packages/cli/src/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,14 @@ credential
} else {
raw = await readStdin()
}
let credentialAsJSON: any
let parsedCredential: any
try {
credentialAsJSON = json5.parse(raw)
parsedCredential = json5.parse(raw)
} catch (e: any) {
credentialAsJSON = {
proof: {
type: 'JwtProof2020',
jwt: raw,
},
} as any
parsedCredential = raw
}
try {
const result = await agent.verifyCredential({ credential: credentialAsJSON })
const result = await agent.verifyCredential({ credential: parsedCredential })
if (result.verified === true) {
console.log('Credential was verified successfully.')
} else {
Expand Down
6 changes: 4 additions & 2 deletions packages/credential-w3c/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class CredentialPlugin implements IAgentPlugin {
verifiedCredential = verificationResult.verifiableCredential

// if credential was presented with other fields, make sure those fields match what's in the JWT
if (typeof credential !== 'string') {
if (typeof credential !== 'string' && credential.proof.type === 'JwtProof2020') {
const credentialCopy = JSON.parse(JSON.stringify(credential))
delete credentialCopy.proof.jwt

Expand All @@ -300,7 +300,9 @@ export class CredentialPlugin implements IAgentPlugin {

if (canonicalize(credentialCopy) !== canonicalize(verifiedCopy)) {
verificationResult.verified = false
verificationResult.error = new Error('Credential does not match JWT')
verificationResult.error = new Error(
'invalid_credential: Credential JSON does not match JWT payload',
)
}
}
} catch (e: any) {
Expand Down

0 comments on commit 697a14c

Please sign in to comment.