Simple service example
See also: https://github.com/walt-id/waltid-storage-kit/blob/master/src/main/kotlin/id/walt/storagekit/service/ServiceTest.kt
This is a simple service that generates a data request (which is printed to the terminal), and handles acceptance of such data requests.
fun main() {
ServiceMatrix("service-matrix.properties")
val requests = HashMap<String, DataRequest>()
println("[Service example]")
println()
println("Setting up service...")
val keyService = KeyService.getService()
println("Creating key pair...")
val keyId = keyService.generate(KeyAlgorithm.EdDSA_Ed25519)
println()
println("Key pair created: $keyId")
val pem = keyService.toPem(keyId.id, KeyType.PUBLIC)
println("New public key:")
println(pem)
println()
println("Creating service DID...")
val did = DidService.create(DidMethod.key, keyId.id)
println("New service DID: $did")
Javalin.create {
it.enableDevLogging()
}.routes {
post("/accept-request/{id}") {
val resp = it.bodyAsClass<DataResponse>()
println("Our request was accepted, querying EDV...")
//println(resp)
val baseUrl = resp.baseUrl
val edvId = resp.edvId
val docId = resp.filesIndex.keys.first()
val zcap = resp.capabilities.first()
val fileKey = resp.filesIndex.values.first()
val doc = retrieveDocument(edvId, docId, Base58.decode(fileKey), baseUrl, zcap, did)
println(doc.toString())
}
}.start(8000)
println()
println("-------------")
println("Generating data request...")
val reqId = UUID.randomUUID().toString()
val req = DataRequest("Job application", "EuropassCredential", did, "http://localhost:8000/accept-request/$reqId")
requests[reqId] = req
println("Data request $reqId:")
val json = Klaxon().toJsonString(req)
val signed = JwtService.getService().sign(keyId.id, json)
println("JWS: $signed")
}