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(credential): unify normalization of context #146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,12 @@ export function _checkCredential({credential, now = new Date()}) {
if(typeof now === 'string') {
now = new Date(now);
}
// normalize to an array to allow the common case of context being a string
const context = Array.isArray(credential['@context']) ?
credential['@context'] : [credential['@context']];

// ensure first context is 'https://www.w3.org/2018/credentials/v1'
if(credential['@context'][0] !== CREDENTIALS_CONTEXT_V1_URL) {
if(context[0] !== CREDENTIALS_CONTEXT_V1_URL) {
throw new Error(
`"${CREDENTIALS_CONTEXT_V1_URL}" needs to be first in the ` +
'list of contexts.');
Expand Down