Skip to content

METADIUM/identity-hub-client-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

identity-hub-client-java

Get it

Maven

Add the JitPack repository to build file

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Add dependency

<dependency>
    <groupId>com.github.METADIUM</groupId>
    <artifactId>identity-hub-client-java</artifactId>
    <version>0.1.9</version>
</dependency>

Gradle

Add root build.gradle

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Add dependency

dependencies {
    implementation 'com.github.METADIUM:identity-hub-client-java:0.1.9'
}

Use it

Register DID in Metadium

Initialize hub client

String did = "{did of client}";
String keyId = "{id of key to sign}";
BCECPrivateKey privateKey = ..;
ECDSASigner signer = new ECDSASigner(privateKey); // signer with client private key 
IdentityHub hubClient = new IdentityHub(true, did, keyId, signer);

Get Verifiable Credential or Presentation of user from Identity-Hub

String did = "{did of user}";


// Get verifiable credential
List<String> typesOfCrendential = Arrays.asList("VerifiableCredential", "NameCredential");
List<CommitObject> commitObjects = hubClient.getDecryptedCommitsOfObjects(did, typesOfCrendential, privateKey);
SignedJWT signedVc = commitObjects.get(0).getPayload().toSignedJWT();
VerifiableCrendentail vc = (VerifiableCrendentail)VerifiableSignedJWT.toVerifiable(signedVc);


// Get verifiable presentation
List<String> typesOfPresentation = Arrays.asList("VerifiablePresentation", "ServicePresentation");
List<CommitObject> commitObjects = hubClient.getDecryptedCommitsOfObjects(did, typesOfPresentation, privateKey);
SignedJWT signedVp = commitObject.get(0).getPayload().toSignedJWT();
VerifiablePresentation vp = (VerifiablePresentation)VerifiableSignedJWT.toVerifiable(signedVp);

// Get verifiable credential of verifiable presentation
for (Object vc : verifiedVp.getVerifiableCredentials()) {
   SignedJWT signedVc = SignedJWT.parse((String)vc);
   VerifiableCredential vc = (VerifiableCredential)VerifiableSignedJWT.toVerifiable(signedVc);
}