Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix(cli): fix credential verify command for JWT credentials #1148

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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