Skip to content

Commit

Permalink
[INJICERT-434] add optional id field
Browse files Browse the repository at this point in the history
As per the published VC DM 1.1 spec, the ID field must be a URI but
other first party implementations require ID field to be present for
some other functions, hence this feature is being added temporarily.

Signed-off-by: Harsh Vardhan <[email protected]>
  • Loading branch information
vharsh committed Nov 19, 2024
1 parent 4214d39 commit 0a7992b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class VCDMConstants {
// the below assertionMethods are common b/w VC 1.1 & VC 2.0
public static final String ASSERTION_METHOD = "assertionMethod";
public static final String PROOF = "proof";
public static final String ID = "id";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import io.mosip.certify.api.spi.VCFormatter;
import io.mosip.certify.core.constants.Constants;
import io.mosip.certify.core.constants.VCDM2Constants;
import io.mosip.certify.core.constants.VCDMConstants;
import io.mosip.certify.core.exception.TemplateException;
import io.mosip.certify.core.repository.TemplateRepository;
import io.mosip.certify.core.spi.SvgTemplateService;
import io.mosip.certify.services.SVGRenderUtils;
import jakarta.annotation.PostConstruct;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
Expand All @@ -46,6 +48,8 @@ public class VelocityTemplatingEngineImpl implements VCFormatter {
SvgTemplateService svgTemplateService;
@Value("${mosip.certify.vcformat.vc.expiry:true}")
boolean shouldHaveDates;
@Value("${mosip.certify.issuer.id.field.prefix.url:}")
String idPrefix;

@PostConstruct
public void initialize() {
Expand Down Expand Up @@ -126,6 +130,11 @@ public String format(JSONObject templateInput, Map<String, Object> defaultSettin
}
VelocityContext context = new VelocityContext(finalTemplate);
engine.evaluate(context, writer, /*logTag */ templateName,t.toString());
if (StringUtils.isNotEmpty(idPrefix)) {
JSONObject j = new JSONObject(writer.toString());
j.put(VCDMConstants.ID, idPrefix + UUID.randomUUID());
return j.toString();
}
return writer.toString();
}
}

0 comments on commit 0a7992b

Please sign in to comment.