-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INJICERT-434] add optional id URI to json-ld VC
Signed-off-by: Harsh Vardhan <[email protected]>
- Loading branch information
Showing
11 changed files
with
128 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
certify-integration-api/src/main/java/io/mosip/certify/api/spi/VCModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.mosip.certify.api.spi; | ||
|
||
import org.json.JSONObject; | ||
|
||
/** | ||
* VCModifier is a modifier which takes @param templateInput and | ||
* returns a modified VC as per configuration. | ||
* | ||
* Some implementations include | ||
* - add an id which is a UUID | ||
* | ||
* Future possible implementations: | ||
* - Support for SD-JWT | ||
* - Support for additional validations | ||
*/ | ||
public interface VCModifier { | ||
JSONObject perform(String templateInput); | ||
} |
3 changes: 2 additions & 1 deletion
3
certify-integration-api/src/main/java/io/mosip/certify/api/spi/VCSigner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package io.mosip.certify.api.spi; | ||
|
||
import io.mosip.certify.api.dto.VCResult; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* VCSigner can sign any VC provided a vcHash & Signer inputs | ||
*/ | ||
public interface VCSigner { | ||
VCResult<?> perform(String templatedVC); | ||
VCResult<?> perform(JSONObject templatedVC); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
certify-service/src/main/java/io/mosip/certify/services/ConfigurableJSONLDvcModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.mosip.certify.services; | ||
|
||
import io.mosip.certify.api.spi.VCModifier; | ||
import io.mosip.certify.core.constants.ErrorConstants; | ||
import io.mosip.certify.core.exception.CertifyException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@Slf4j | ||
@ConditionalOnProperty(name = "mosip.certify.issuer.modifier.enabled", value = "AddID") | ||
public class ConfigurableJSONLDvcModifier implements VCModifier { | ||
// TODO: Add support for more configurable "AddOns" to update the VC later | ||
@Override | ||
public JSONObject perform(String templateInput) { | ||
JSONObject j; | ||
try { | ||
j = new JSONObject(templateInput); | ||
j.put("id", "did:rcw:" + UUID.randomUUID()); | ||
return j; | ||
} catch (JSONException e) { | ||
log.error("Received JSON: " + templateInput); | ||
log.error(e.getMessage()); | ||
throw new CertifyException(ErrorConstants.JSON_TEMPLATING_ERROR); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
certify-service/src/main/java/io/mosip/certify/services/NoOpVCModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.mosip.certify.services; | ||
|
||
import io.mosip.certify.api.spi.VCModifier; | ||
import io.mosip.certify.core.constants.ErrorConstants; | ||
import io.mosip.certify.core.exception.CertifyException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
@ConditionalOnProperty(name = "mosip.certify.issuer.modifier.enabled", value = "NoOp") | ||
public class NoOpVCModifier implements VCModifier { | ||
@Override | ||
public JSONObject perform(String templateInput) { | ||
try { | ||
JSONObject j = new JSONObject(templateInput); | ||
return j; | ||
} catch (JSONException e) { | ||
log.error("Received JSON: " + templateInput); | ||
log.error(e.getMessage()); | ||
throw new CertifyException(ErrorConstants.JSON_TEMPLATING_ERROR); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ify-service/src/test/java/io/mosip/certify/services/ConfigurableJSONLDvcModifierTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.mosip.certify.services; | ||
|
||
import lombok.SneakyThrows; | ||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ConfigurableJSONLDvcModifierTest { | ||
ConfigurableJSONLDvcModifier modifier = new ConfigurableJSONLDvcModifier(); | ||
@SneakyThrows | ||
@Test | ||
void perform() { | ||
JSONObject json = new JSONObject(); | ||
json.put("item", "apple"); | ||
JSONObject actual = modifier.perform(json.toString()); | ||
assertDoesNotThrow(() -> URI.create(actual.get("id").toString())); | ||
assertTrue(actual.has("item")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters