Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mirceanis
Copy link
Contributor

@mirceanis mirceanis commented Jul 12, 2019

This is a test of a wrapper for did-jwt usable in a JAVA 8 app.

This is a java compatible did-jwt library built by wrapping the kotlin variant.

in your build.gradle:

dependencies {
    implementation "com.github.uport-project.kotlin-did-jwt:jwt-java:c872ff3"
}

The wrapper exposes the same signature as the kotlin variant so they are not usable in the same project.
This is not set in stone so if needed, they can be differentiated, because it's likely there need to be different calling conventions for Java (builder pattern since there are no default params).

As opposed to the coroutines of the kotlin variant, the wrapper methods result in CompletableFuture<*> so they are usable in a Java 8 context.

create a token

HashMap<String, Object> payload = new HashMap<>();
put.put("claim", "something something");

KPSigner signer = new KPSigner("0x65fc670d9351cb87d1f56702fb56a7832ae2aab3427be944ab8c9f2a0ab87960");
String issuer = "did:ethr:" + signer.getAddress();

CompletableFuture<String> jwtFuture = new JWTTools().createJWT(
        payload,
        issuer,
        signer,
        -1,
        JwtHeader.ES256K);

//...sometime later
String jwtToken = jwtFuture.join();

verify a token

JWTTools tools = new JWTTools();
CompletableFuture<JwtPayload> jwtPayloadCompletableFuture =
        tools.verify(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJoZWxsbyI6IndvcmxkIiwiaWF0IjoxNTYxOTcxMTE5LCJpc3MiOiJkaWQ6ZXRocjoweGNmMDNkZDBhODk0ZWY3OWNiNWI2MDFhNDNjNGIyNWUzYWU0YzY3ZWQifQ.t5o1vzZExArlrrTVHmwtti7fnicXqvWrX6SS3F-Lu3budH7p6zQHjG8X7EvUTRUxhvr-eENCbXeteSE4rgF7MA",
                false,
                null);

//...sometime later
JwtPayload result = jwtPayloadCompletableFuture.join();

Also, there's a test artifact that can be used to mock some EthrDID doc calls.
testImplementation "com.github.uport-project.kotlin-did-jwt:jwt-test:eb45524e15"

@mirceanis mirceanis requested a review from ajunge July 12, 2019 16:25
@mirceanis mirceanis changed the title Support/166983459 java calling conventions [Support][WIP] java calling conventions Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants