-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ATL-1342] feat(pollux): initialise VC JWT (#42)
- Loading branch information
1 parent
1ce272c
commit 71b7116
Showing
8 changed files
with
113 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# macOS | ||
.DS_Store | ||
|
||
# sbt specific | ||
dist/* | ||
target/ | ||
lib_managed/ | ||
src_managed/ | ||
project/boot/ | ||
project/plugins/project/ | ||
project/local-plugins.sbt | ||
.history | ||
.ensime | ||
.ensime_cache/ | ||
.sbt-scripted/ | ||
local.sbt | ||
|
||
# Bloop | ||
.bsp | ||
|
||
# VS Code | ||
.vscode/ | ||
|
||
# Metals | ||
.bloop/ | ||
.metals/ | ||
metals.sbt | ||
|
||
# IDEA | ||
.idea | ||
.idea_modules | ||
/.worksheet/ |
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,4 @@ | ||
version = 3.5.8 | ||
runner.dialect = scala3 | ||
|
||
maxColumn = 120 |
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,8 @@ | ||
## sbt project compiled with Scala 3 | ||
|
||
### Usage | ||
|
||
This is a normal sbt project. You can compile code with `sbt compile`, run it with `sbt run`, and `sbt console` will start a Scala 3 REPL. | ||
|
||
For more information on the sbt-dotty plugin, see the | ||
[scala3-example-project](https://github.com/scala/scala3-example-project/blob/main/README.md). |
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,12 @@ | ||
import Dependencies._ | ||
|
||
ThisBuild / version := "0.1.0-SNAPSHOT" | ||
ThisBuild / scalaVersion := "3.1.3" | ||
ThisBuild / organization := "io.iohk.atala" | ||
|
||
lazy val root = project | ||
.in(file(".")) | ||
.settings( | ||
name := "pollux-vc-jwt", | ||
libraryDependencies ++= polluxVcJwtDependencies | ||
) |
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 @@ | ||
import sbt._ | ||
|
||
object Dependencies { | ||
object Versions { | ||
val circeVersion = "0.14.3" | ||
val jwtCirceVersion = "9.1.1" | ||
} | ||
|
||
private lazy val coreJwtCirce = "io.circe" %% "circe-core" % Versions.circeVersion | ||
private lazy val genericJwtCirce = "io.circe" %% "circe-generic" % Versions.circeVersion | ||
private lazy val parserJwtCirce = "io.circe" %% "circe-parser" % Versions.circeVersion | ||
|
||
private lazy val jwtCirce = "com.github.jwt-scala" %% "jwt-circe" % Versions.jwtCirceVersion | ||
|
||
private lazy val test = "org.scalameta" %% "munit" % "0.7.29" % Test | ||
|
||
// Dependency Modules | ||
private lazy val circeDependencies: Seq[ModuleID] = Seq(coreJwtCirce, genericJwtCirce, parserJwtCirce) | ||
private lazy val baseDependencies: Seq[ModuleID] = circeDependencies :+ jwtCirce :+ test | ||
|
||
// Project Dependencies | ||
lazy val polluxVcJwtDependencies: Seq[ModuleID] = baseDependencies | ||
} |
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 @@ | ||
sbt.version=1.7.1 |
24 changes: 24 additions & 0 deletions
24
pollux/vc-jwt/src/main/scala/io/iohk/atala/pollux/vc/jwt/Main.scala
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,24 @@ | ||
package io.iohk.atala.pollux.vc.jwt | ||
import io.circe.* | ||
import pdi.jwt.JwtClaim | ||
import pdi.jwt.{JwtAlgorithm, JwtCirce} | ||
|
||
import java.security.* | ||
import java.security.spec.* | ||
import java.time.Instant | ||
|
||
@main def jwtDemo(): Unit = | ||
val keyGen = KeyPairGenerator.getInstance("EC") | ||
val ecSpec = ECGenParameterSpec("secp256r1") | ||
keyGen.initialize(ecSpec, SecureRandom()) | ||
val keyPair = keyGen.generateKeyPair() | ||
val privateKey = keyPair.getPrivate | ||
val publicKey = keyPair.getPublic | ||
|
||
val Right(claimJson) = jawn.parse(s"""{"expires":${Instant.now.getEpochSecond}}""") | ||
|
||
val jwt = JwtCirce.encode(claimJson, privateKey, JwtAlgorithm.ES256) | ||
|
||
println(jwt) | ||
|
||
println(s"Is Valid: ${JwtCirce.isValid(jwt, publicKey)}") |
9 changes: 9 additions & 0 deletions
9
pollux/vc-jwt/src/test/scala/io/iohk/atala/pollux/vc/jwt/MySuite.scala
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,9 @@ | ||
package io.iohk.atala.pollux.vc.jwt | ||
|
||
class MySuite extends munit.FunSuite { | ||
test("example test that succeeds") { | ||
val obtained = 42 | ||
val expected = 42 | ||
assertEquals(obtained, expected) | ||
} | ||
} |