Skip to content

Commit

Permalink
[ATL-1342] feat(pollux): initialise VC JWT (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoKnightIOG authored Sep 28, 2022
1 parent 1ce272c commit 71b7116
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pollux/vc-jwt/.gitignore
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/
4 changes: 4 additions & 0 deletions pollux/vc-jwt/.scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = 3.5.8
runner.dialect = scala3

maxColumn = 120
8 changes: 8 additions & 0 deletions pollux/vc-jwt/README.md
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).
12 changes: 12 additions & 0 deletions pollux/vc-jwt/build.sbt
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
)
23 changes: 23 additions & 0 deletions pollux/vc-jwt/project/Dependencies.scala
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
}
1 change: 1 addition & 0 deletions pollux/vc-jwt/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.7.1
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)}")
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)
}
}

0 comments on commit 71b7116

Please sign in to comment.