From de9d83589e48d6231e062a44ed477551605c86dd Mon Sep 17 00:00:00 2001
From: Filip <filip26@gmail.com>
Date: Thu, 15 Feb 2024 21:47:38 +0100
Subject: [PATCH] Enforce @context array to issued VCs

---
 src/main/java/com/apicatalog/vc/processor/Issuer.java       | 4 ++--
 src/test/resources/com/apicatalog/vc/issuer/0201-out.jsonld | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/apicatalog/vc/processor/Issuer.java b/src/main/java/com/apicatalog/vc/processor/Issuer.java
index fccbd851..826e4876 100644
--- a/src/main/java/com/apicatalog/vc/processor/Issuer.java
+++ b/src/main/java/com/apicatalog/vc/processor/Issuer.java
@@ -174,10 +174,10 @@ JsonObject postCompact(final JsonObject source) {
         JsonObject compacted = source;
 
         // TODO use options
-        // make sure @context is the first key
+        // make sure @context is the first key and an array
         if (!compacted.keySet().iterator().next().equals(Keywords.CONTEXT)) {
             final JsonObjectBuilder builder = Json.createObjectBuilder()
-                    .add(Keywords.CONTEXT, compacted.get(Keywords.CONTEXT));
+                    .add(Keywords.CONTEXT, JsonUtils.toJsonArray(compacted.get(Keywords.CONTEXT)));
 
             compacted.entrySet().stream()
                     .filter(entry -> !Keywords.CONTEXT.equals(entry.getKey()))
diff --git a/src/test/resources/com/apicatalog/vc/issuer/0201-out.jsonld b/src/test/resources/com/apicatalog/vc/issuer/0201-out.jsonld
index 73050691..0ae184d5 100644
--- a/src/test/resources/com/apicatalog/vc/issuer/0201-out.jsonld
+++ b/src/test/resources/com/apicatalog/vc/issuer/0201-out.jsonld
@@ -1,5 +1,5 @@
 {
-	"@context": "https://www.w3.org/ns/credentials/v2",
+	"@context": ["https://www.w3.org/ns/credentials/v2"],
 	"id": "https://apicatalog/com/vc/test-credentials#0001",
 	"type": "VerifiableCredential",
 	"issuer": "https://github.com/filip26/iron-verifiable-credentials/issuer/1",