LogoLogo
ProductsCommunityGitHubShare Feedback
Storage Kit
Storage Kit
  • WHAT IS THE STORAGE KIT?
    • Introduction
    • Architecture
      • System Architecture
      • Functional Architecture
        • L1 | Data Encryption
        • L2 | Data Sharing, Versioning & Search
        • L3 | HL Server-Side Functions
      • Dependencies
  • Getting started
    • Quick Start
    • CLI | Command Line Interface
    • REST APIs
      • Server
      • Client
      • Service
    • Dependency (JVM)
    • Configurations
    • Build
      • Docker Build
      • Local Build
  • Concepts
    • Basic Concepts
      • Sessions
      • Client Set-up
      • Client Document Upload
      • Service Access
    • Advanced Concepts
      • Searchable Symmetric Encryption (SEE)
      • ZCap-LD (Authorization)
        • (Theory) Authorization Capabilities
        • ZCaps - Caveats Extension
  • Usage / Examples
    • Client CLI Examples
    • Client code examples
    • Simple service example
  • Community
    • Discord
    • Twitter
    • Newsletter
    • GitHub Discussions
  • DEVELOPER RELATIONS
    • Contribute
    • Roadmap
    • Share Feedback
    • Contact
  • Product Editions
    • Open Source | Always Free
    • Enterprise | Self-Managed
    • Cloud Platform | Managed
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Usage / Examples

Simple service example

PreviousClient code examplesNextOpen Source | Always Free

Last updated 1 month ago

Was this helpful?

See also: 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")
}
https://github.com/walt-id/waltid-storage-kit/blob/master/src/main/kotlin/id/walt/storagekit/service/ServiceTest.kt