-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INJICERT-434] compute svg template multibase&sha256 per spec (#125)
* [INJICERT-434] compute svg template multibase&sha256 per spec ref: https://w3c-ccg.github.io/vc-render-method/#svgrenderingtemplate Signed-off-by: Harsh Vardhan <[email protected]> * [INJICERT-434] only fetch SVG template if VC 2.0 is requested Signed-off-by: Harsh Vardhan <[email protected]> --------- Signed-off-by: Harsh Vardhan <[email protected]>
- Loading branch information
Showing
8 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
certify-core/src/main/java/io/mosip/certify/core/constants/VCDM1Constants.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,6 +1,7 @@ | ||
package io.mosip.certify.core.constants; | ||
|
||
public class VCDM1Constants { | ||
public static final String URL = "https://www.w3.org/2018/credentials/v1"; | ||
public static final String ISSUANCE_DATE = "issuanceDate"; | ||
public static final String EXPIRATION_DATE = "expirationDate"; | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
certify-service/src/main/java/io/mosip/certify/services/SVGRenderUtils.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,31 @@ | ||
package io.mosip.certify.services; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import io.ipfs.multibase.Multibase; | ||
|
||
public class SVGRenderUtils { | ||
/** | ||
* Generate SVG digest for @param svg image as per spec. | ||
* ref: https://w3c-ccg.github.io/vc-render-method/#svgrenderingtemplate | ||
* | ||
* @param svg | ||
* @return | ||
*/ | ||
public static String getDigestMultibase(String svg) { | ||
/* | ||
digestMultibase: An optional multibase-encoded multihash of the SVG image. | ||
The multibase value MUST be z and the multihash value MUST | ||
be SHA-2 with 256-bits of output (0x12). | ||
*/ | ||
try { | ||
MessageDigest digest = MessageDigest.getInstance("SHA-256"); | ||
byte[] sha256 = digest.digest(svg.getBytes(StandardCharsets.UTF_8)); | ||
return Multibase.encode(Multibase.Base.Base58BTC, sha256); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...rvice/src/main/java/io/mosip/certify/services/templating/VelocityTemplatingConstants.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,7 @@ | ||
package io.mosip.certify.services.templating; | ||
|
||
public class VelocityTemplatingConstants { | ||
public static final String TEMPLATE_NAME = "templateName"; | ||
public static final String ISSUER_URI = "issuerURI"; | ||
public static final String SVG_TEMPLATE = "svgTemplate"; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
certify-service/src/test/java/io/mosip/certify/services/SVGRenderUtilsTest.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,19 @@ | ||
package io.mosip.certify.services; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class SVGRenderUtilsTest { | ||
|
||
@Test | ||
void getDigestMultibase() { | ||
String svg = """ | ||
<svg viewBox=".5 .5 3 4" fill="none" stroke="#20b2a" stroke-linecap="round"> <path d=" M1 4h-.001 V1h2v.001 M1 2.6 h1v.001"/> </svg> | ||
"""; | ||
String actual = SVGRenderUtils.getDigestMultibase(svg); | ||
String expected = "z4po9QkJj1fhMt6cxHSnDnAUat4PEVrerUGGsPHLxJnK5"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
} |