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

fix: remove JSON.stringify for string credential #1176

Merged

Conversation

martines3000
Copy link
Contributor

What issue is this PR fixing

Fixes issue where a credential in string format is encoded as a string twice.

What is being changed

Removes JSON.stringify for string credential.

Quality

Check all that apply:

  • I want these changes to be integrated
  • I successfully ran pnpm i, pnpm build, pnpm test, pnpm test:browser locally.
  • I allow my PR to be updated by the reviewers (to speed up the review process).
  • I added unit tests.
  • I added integration tests.
  • I did not add automated tests because _________, and I am aware that a PR without tests will likely get rejected.

Comment on lines 218 to 222
if (typeof cred !== 'string' && cred.proof.jwt) {
return cred.proof.jwt
} else {
return JSON.stringify(cred)
return cred
}
Copy link
Member

@mirceanis mirceanis May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 cases here, and we were indeed not handling them properly:

  • credential is already a string (JWT). return it directly
  • credential is an Object but it's a JwtProof2020 proof, which is only used for convenience. The actual credential is in cred.proof.jwt, so return that instead
  • credential is an Object with any other JSON-LD/EIP712 proof. In this case return JSON.stringify(credential)

The reason for this extra processing is that EIP712 proofs don't support heterogenous objects in an array, so the "quick fix" is to turn them all into strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR with separate checks for all 3 cases.

@martines3000 martines3000 force-pushed the fix/presentation-creation branch from 4f3f998 to 972e97e Compare May 12, 2023 11:14
Copy link
Member

@mirceanis mirceanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for contributing this!

@mirceanis mirceanis merged commit 469dcd9 into decentralized-identity:next May 15, 2023
@martines3000 martines3000 deleted the fix/presentation-creation branch May 16, 2023 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants