Giter Club home page Giter Club logo

waltid-ssikit-vclib's Introduction

waltid-ssikit-vclib

Typesafe implementation of W3C Verifiable Credentials in order to facilitate interoperability among various applications.

Setup

Add the dependency using Gradle:

implementation("id.walt:waltid-ssikit-vclib:1.24.0")

or Maven:

<dependency>
    <groupId>id.walt</groupId>
    <artifactId>waltid-ssikit-vclib</artifactId>
    <version>1.24.0</version>
</dependency>

Create a credential

val verifiableAuthorization: VerifiableCredential = VerifiableAuthorization(
    id = "did:ebsi-eth:00000001/credentials/1872",
    issuer = "did:ebsi:000001234",
    issuanceDate = "2020-08-24T14:13:44Z",
    credentialSubject = VerifiableAuthorization.CredentialSubject1(
        "did:ebsi:00000004321",
        VerifiableAuthorization.CredentialSubject1.NaturalPerson("did:example:00001111")
    ),
    proof = Proof(
        "EcdsaSecp256k1Signature2019",
        "2020-08-24T14:13:44Z",
        "assertionMethod",
        "did:ebsi-eth:000001234#key-1",
        "eyJhbGciOiJSUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19."
    )
)

Encode a credential to JSON

val json: String = verifiableAuthorization.encode()
// {"@context" : ["https://www.w3.org/2018/credentials/v1", "https://ess ...

Decode a JSON credential

val unknownJson: String = fromInput()

val credential: VerifiableCredential = unknownJson.toCredential()

val issuer = when (credential) {
    is PermanentResidentCard -> credential.issuer
    is VerifiablePresentation -> {
        val vcsInVP = credential.verifiableCredential
        val permanentResidentCardInVP = vcsInVP.any { it is PermanentResidentCard }

        if (permanentResidentCardInVP) {
            (vcsInVP.first { it is PermanentResidentCard } as PermanentResidentCard).issuer
        } else throw IllegalArgumentException("This VP does not contain a PermanentResidentCard")
    }
    else -> throw IllegalArgumentException("No vc of type PermanentResidentCard was found!")
}

// extendable to e.g. take the users address from the PermanentResidentCard, or an Europass (if supplied), or a VerifiableUtilityBill etc...

Adding VC Templates

  1. Visit https://vc-creator.walt.id to generate a VC template.
  2. Add it to package: id.walt.vclib.credentials.*, compare it to the other templates and complete the implementation.
  3. Add the new class to id.walt.vclib.registry.VcTypeRegistry.
  4. Run all test-cases, which will generate the JsonSchema and the serialized version of the credential template.
  5. Open a Pull-Request on GitHub

License

The VcLib by walt.id is Open Source software released under the Apache 2.0 license.

waltid-ssikit-vclib's People

Contributors

philpotisk avatar severinstampler avatar github-actions[bot] avatar atuffreau-bcd avatar waltkb avatar ohylli avatar fabian-hk avatar kaimeinke avatar ahmedsmiai avatar mplotean avatar henrich-poehls avatar matofeder avatar mikeplotean avatar yassineouahidi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.