From 7ab5d938af58155ecc7bf96601b4d1eacd52257e Mon Sep 17 00:00:00 2001 From: Jan Christoph Ebersbach Date: Tue, 27 Jun 2023 10:23:15 +0200 Subject: [PATCH] fix(credential): unify normalization of context --- lib/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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.');