diff --git a/lib/index.js b/lib/index.js index 45f8fcc9..9d734eaf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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.');