Skip to content

Commit

Permalink
feat: updated context url of did document and test case
Browse files Browse the repository at this point in the history
  • Loading branch information
thackerronak committed Jul 11, 2023
1 parent 1dc2ab5 commit 0b05e15
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ public record MIWSettings(String host, String encryptionKey, String authorityWal
List<URI> vcContexts, List<URI> summaryVcContexts,
@DateTimeFormat(pattern = "dd-MM-yyyy") Date vcExpiryDate,
Set<String> supportedFrameworkVCTypes,
boolean enforceHttps, String contractTemplatesUrl) {
boolean enforceHttps, String contractTemplatesUrl,
List<URI> didDocumentContextUrls) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.io.StringWriter;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -221,6 +222,16 @@ private Wallet createWallet(CreateWalletRequest request, boolean authority) {
didDocumentBuilder.id(did.toUri());
didDocumentBuilder.verificationMethods(List.of(jwkVerificationMethod));
DidDocument didDocument = didDocumentBuilder.build();
//modify context URLs
List<URI> context = didDocument.getContext();
List<URI> mutableContext = new ArrayList<>();
mutableContext.addAll(context);
miwSettings.didDocumentContextUrls().forEach(uri -> {
if (!mutableContext.contains(uri)) {
mutableContext.add(uri);
}
});
didDocument.put("@context", mutableContext);
didDocument = DidDocument.fromJson(didDocument.toJson());
log.debug("did document created for bpn ->{}", request.getBpn());

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ miw:
supportedFrameworkVCTypes: ${SUPPORTED_FRAMEWORK_VC_TYPES:PcfCredential, SustainabilityCredential, QualityCredential, TraceabilityCredential, BehaviorTwinCredential, ResiliencyCredential}
enforceHttps: ${ENFORCE_HTTPS_IN_DID_RESOLUTION:true}
contractTemplatesUrl: ${CONTRACT_TEMPLATES_URL:https://public.catena-x.org/contracts/}
didDocumentContextUrls: ${DID_DOCUMENT_CONTEXT_URL:https://www.w3.org/ns/did/v1,https://w3c.github.io/vc-jws-2020/contexts/v1}
security:
enabled: true
realm: ${KEYCLOAK_REALM:miw_test}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.springframework.http.*;
import org.springframework.test.context.ContextConfiguration;

import java.net.URI;
import java.util.*;


Expand Down Expand Up @@ -131,6 +132,10 @@ void createWalletTest201() throws JsonProcessingException, JSONException {

Assertions.assertNotNull(response.getBody());
Assertions.assertNotNull(wallet.getDidDocument());
List<URI> context = wallet.getDidDocument().getContext();
miwSettings.didDocumentContextUrls().forEach(uri -> {
Assertions.assertTrue(context.contains(uri));
});
Assertions.assertEquals(wallet.getBpn(), bpn);
Assertions.assertEquals(wallet.getName(), name);

Expand All @@ -139,7 +144,6 @@ void createWalletTest201() throws JsonProcessingException, JSONException {
Assertions.assertEquals(walletFromDB.getName(), name);
Assertions.assertNotNull(walletFromDB);
WalletKey walletKey = walletKeyRepository.getByWalletId(walletFromDB.getId());
Assertions.assertNotNull(wallet.getDidDocument());
Assertions.assertNotNull(walletKey);

Assertions.assertEquals(walletFromDB.getBpn(), bpn);
Expand Down

0 comments on commit 0b05e15

Please sign in to comment.