Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Mar 21, 2020
2 parents 640319c + a52fb2b commit 6642a2a
Show file tree
Hide file tree
Showing 43 changed files with 59 additions and 1,754 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# repo-specific config
publish.properties


# Created by https://www.gitignore.io/api/linux,macos,gradle,windows,android,androidstudio

### Android ###
Expand Down Expand Up @@ -238,5 +237,4 @@ gradle-app.setting
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties


# End of https://www.gitignore.io/api/linux,macos,gradle,windows,android,androidstudio
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is the Kotlin implementation of the basic JWT methods for DID-JWTs

[FAQ and helpdesk support](http://bit.ly/uPort_helpdesk)

# did-jwt
## did-jwt

The kotlin-did-JWT library allows you to sign and verify
[JSON Web Tokens (JWT)](https://tools.ietf.org/html/rfc7519) using ES256K, and ES256K-R algorithms.
Expand All @@ -21,11 +21,9 @@ of the signing identity of the claim, which is passed as the `iss` attribute of
We currently support the following DID methods:

- [`ethr`](https://github.com/uport-project/ethr-did-resolver)
- [`uport`](https://github.com/uport-project/uport-did-resolver)
- [`web`](https://github.com/uport-project/https-did-resolver)
- [`https`](https://github.com/uport-project/https-did-resolver) *DEPRECATED*


Defaults are automatically installed but you can customize to fit your needs.

Support for other DID methods should be simple.
Expand All @@ -40,7 +38,7 @@ val resolver : DIDResolver = DIDResolver.Builder
.build()
```

Once you've verified that it works, please add a PR adding it to the above list so people can find it.
Once you've verified that it works, feel free to advertise it in the list above so people can find it.

If your DID method requires a different signing algorithm than what is already supported,
please create a PR.
Expand All @@ -63,7 +61,7 @@ allprojects {
In your application `build.gradle` file, add:

```groovy
def did_jwt_version = "0.3.6"
def did_jwt_version = "0.4.0"
dependencies {
//...
implementation "com.github.uport-project.kotlin-did-jwt:jwt:$did_jwt_version"
Expand All @@ -90,7 +88,6 @@ val issuerDID = "did:ethr:${signer.getAddress()}"
val token = jwt.createJWT(payload, issuerDID, signer)
```


### 2. Decode a did-JWT

Try decoding the JWT. You can also do this using [jwt.io](https://jwt.io)
Expand All @@ -116,7 +113,6 @@ but that is a more rigid structure and will be phased away in future releases.

### 3. Verify a did-JWT


```kotlin
val resolver = EthrDIDResolver.Builder()
.addNetwork(EthrDIDNetwork("<name>", "<registryAddress>", "<JsonRPC>"))
Expand All @@ -128,6 +124,9 @@ val payload : JwtPayload = JWTTools().verify("<token>", resolver)
If the token is valid, the method returns the decoded payload,
otherwise throws a `InvalidJWTException` or `JWTEncodingException`

> **This behavior is subject to change in an upcoming release**
> The verify() method will return a higher level abstraction that will contain the payload and more.
The function requires a DIDResolver which will be used to resolve DIDs during the verification

Verifying a token means checking that the signature was produced by a
Expand All @@ -146,16 +145,17 @@ This same `aud` DID must be supplied to the `verify()` method for the token to b
Generally your app will have its own DID which should always be passed to the `verify` method
so that only tokens intended for your app are considered valid.


## CHANGELOG

* 0.4.0
- removed deprecated components ( #46 )
* 0.3.6
- fix: okhttp dependency issue (#43)
- docs: mark UportDIDResolver as deprecated
- refactor: code cleanup, enforcing detekt on PRs
- docs: mark UportDIDResolver as deprecated (f5ffad34)
- refactor: code cleanup, enforcing detekt on PRs (#45)
* 0.3.5
- feat: add credential status / revocation support (#35)(#42)
- support: bump dependencies (#44)
- support: bump dependencies (kotlin 1.3.70, kethereum 0.81.4) (#44)
* 0.3.4
- feat: deprecate UniversalResolver singleton (#31)(#34)(#37)
* 0.3.3
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ buildscript {
jacoco_version = "0.8.4"

bivrost_version = "v0.7.1"
kmnid_version = "0.4.4"
kethereum_version = "0.81.4"
khex_version = "1.0.0-RC6"
khash_version = "1.0.0-RC5"
kbase58_version = "0.1"
spongycastle_version = "1.58.0.0"
uport_kotlin_common_version = "0.4.3"

current_release_version = "0.3.6"
current_release_version = "0.4.0"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import me.uport.sdk.universaldid.DIDDocument
**/
interface CredentialStatus


/**
* Represents a status method entry that could be embedded in a W3C Verifiable Credential.
* Normally, only credentials that list a status method would need to be verified by it.
Expand All @@ -20,7 +19,6 @@ interface CredentialStatus
*/
data class StatusEntry(val type: String, val id: String)


/**
*
* The interface expected for status resolvers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ import me.uport.sdk.universaldid.DIDDocument
*/
class UniversalStatusResolver : StatusResolver {


private val resolvers = mapOf<String, StatusResolver>().toMutableMap()


/**
* This universal resolver can't be used for any one particular resolver but for all [StatusResolver]s
* that have been added using [registerResolver]
*/
override val method: String = ""


/**
* Looks for a [StatusResolver] that can check status using the provided [method]
*
Expand All @@ -43,7 +40,6 @@ class UniversalStatusResolver : StatusResolver {
return resolver.checkStatus(credential, didDoc)
}


/**
* Register a resolver for a particular [method]
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass")

package me.uport.sdk.credential_status
package me.uport.sdk.credentialstatus

import assertk.all
import assertk.assertThat
Expand Down
10 changes: 1 addition & 9 deletions detekt_baseline.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" ?>
<SmellBaseline>
<Blacklist></Blacklist>
<Whitelist>
<ID>MaxLineLength:UniversalDID.kt$UniversalDID$ override suspend fun resolve(did: String): DIDDocument</ID>
<ID>MaxLineLength:UniversalDID.kt$UniversalDID$?:</ID>
<ID>MaxLineLength:UniversalDID.kt$UniversalDID$throw IllegalStateException("There is no DIDResolver registered to resolve '$method' DIDs and none of the other ${resolvers.size} registered ones can do it.")</ID>
<ID>MaxLineLength:UportIdentityDocument.kt$UportIdentityDocument$val image: ProfilePicture? = null</ID>
<ID>MaxLineLength:UportIdentityDocument.kt$UportIdentityDocument$val publicEncKey: String? = null</ID>
<ID>MaxLineLength:UportIdentityDocument.kt$UportIdentityDocument$val publicKey: String? = null</ID>
<ID>TooGenericExceptionCaught:UniversalDID.kt$UniversalDID$ex: Exception</ID>
</Whitelist>
<Whitelist></Whitelist>
</SmellBaseline>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("UndocumentedPublicFunction", "UndocumentedPublicClass", "MagicNumber")
@file:Suppress("MagicNumber")

package me.uport.sdk.ethrdid

Expand All @@ -15,7 +15,7 @@ import java.math.BigInteger
* To generate the full interface use the
* [bivrost](https://github.com/gnosis/bivrost-kotlin) tool on `/abi/EthereumDIDRegistry.json`
*/
class EthereumDIDRegistry {
internal class Erc1056Contract {

object Changed {
private const val METHOD_ID: String = "f96d0f9f"
Expand Down
12 changes: 5 additions & 7 deletions ethr-did/src/main/java/me/uport/sdk/ethrdid/EthrDID.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class EthrDID(

private val owner: String? = null


class DelegateOptions(
val delegateType: PublicKeyType = PublicKeyType.veriKey,
val expiresIn: Long = 86400L
Expand All @@ -58,31 +57,30 @@ class EthrDID(
suspend fun lookupOwner(cache: Boolean = true): String {
if (cache && this.owner != null) return this.owner
val encodedCall =
EthereumDIDRegistry.IdentityOwner.encode(Solidity.Address(address.hexToBigInteger()))
Erc1056Contract.IdentityOwner.encode(Solidity.Address(address.hexToBigInteger()))
val rawResult = rpc.ethCall(registry, encodedCall)
return rawResult.substring(rawResult.length - 40).prepend0xPrefix()
}

suspend fun changeOwner(newOwner: String, txOptions: TransactionOptions? = null): String {
val owner = lookupOwner()

val encodedCall = EthereumDIDRegistry.ChangeOwner.encode(
val encodedCall = Erc1056Contract.ChangeOwner.encode(
Solidity.Address(address.hexToBigInteger()),
Solidity.Address(newOwner.hexToBigInteger())
)

return signAndSendContractCall(owner, encodedCall, txOptions)
}


suspend fun addDelegate(
delegate: String,
options: DelegateOptions = DelegateOptions(),
txOptions: TransactionOptions? = null
): String {
val owner = lookupOwner()

val encodedCall = EthereumDIDRegistry.AddDelegate.encode(
val encodedCall = Erc1056Contract.AddDelegate.encode(
Solidity.Address(this.address.hexToBigInteger()),
Solidity.Bytes32(options.delegateType.name.toByteArray(utf8)),
Solidity.Address(delegate.hexToBigInteger()),
Expand All @@ -98,7 +96,7 @@ class EthrDID(
txOptions: TransactionOptions? = null
): String {
val owner = this.lookupOwner()
val encodedCall = EthereumDIDRegistry.RevokeDelegate.encode(
val encodedCall = Erc1056Contract.RevokeDelegate.encode(
Solidity.Address(this.address.hexToBigInteger()),
Solidity.Bytes32(delegateType.name.toByteArray(utf8)),
Solidity.Address(delegate.hexToBigInteger())
Expand All @@ -114,7 +112,7 @@ class EthrDID(
txOptions: TransactionOptions? = null
): String {
val owner = this.lookupOwner()
val encodedCall = EthereumDIDRegistry.SetAttribute.encode(
val encodedCall = Erc1056Contract.SetAttribute.encode(
Solidity.Address(this.address.hexToBigInteger()),
Solidity.Bytes32(key.toByteArray(utf8)),
Solidity.Bytes(value.toByteArray(utf8)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ data class EthrDIDDocument(
}
}


43 changes: 10 additions & 33 deletions ethr-did/src/main/java/me/uport/sdk/ethrdid/EthrDIDResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import me.uport.sdk.core.hexToBigInteger
import me.uport.sdk.core.hexToByteArray
import me.uport.sdk.core.prepend0xPrefix
import me.uport.sdk.core.toBase64
import me.uport.sdk.ethrdid.EthereumDIDRegistry.Events.DIDAttributeChanged
import me.uport.sdk.ethrdid.EthereumDIDRegistry.Events.DIDDelegateChanged
import me.uport.sdk.ethrdid.EthereumDIDRegistry.Events.DIDOwnerChanged
import me.uport.sdk.ethrdid.Erc1056Contract.Events.DIDAttributeChanged
import me.uport.sdk.ethrdid.Erc1056Contract.Events.DIDDelegateChanged
import me.uport.sdk.ethrdid.Erc1056Contract.Events.DIDOwnerChanged
import me.uport.sdk.jsonrpc.JsonRPC
import me.uport.sdk.jsonrpc.model.exceptions.JsonRpcException
import me.uport.sdk.signer.Signer
Expand Down Expand Up @@ -42,34 +42,11 @@ import java.util.*
*
* Example ethr did: "did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a"
*/
open class EthrDIDResolver : DIDResolver {
open class EthrDIDResolver private constructor(registryMap: RegistryMap, clock: ITimeProvider) :
DIDResolver {

private val _registryMap: RegistryMap
private val _timeProvider: ITimeProvider

private constructor(registryMap: RegistryMap, clock: ITimeProvider) {
_timeProvider = clock
this._registryMap = registryMap
}

@Deprecated(
"Constructing the resolver directly has been deprecated " +
"in favor of the Builder pattern that can supply multi-network configurations." +
"This will be removed in the next major release.",
ReplaceWith(
"""EthrDIDResolver.Builder().addNetwork(EthrDIDNetwork("", registryAddress, rpc, "0x1")).build()""",
"me.uport.sdk.ethrdid.EthrDIDResolver.Companion.DEFAULT_REGISTRY_ADDRESS"
)
)
constructor(
rpc: JsonRPC,
registryAddress: String = DEFAULT_REGISTRY_ADDRESS,
timeProvider: ITimeProvider = SystemTimeProvider
) {
val net = EthrDIDNetwork(DEFAULT_NETWORK_NAME, registryAddress, rpc, "0x1")
this._timeProvider = timeProvider
this._registryMap = RegistryMap().registerNetwork(net)
}
private val _registryMap: RegistryMap = registryMap
private val _timeProvider: ITimeProvider = clock

override val method = "ethr"

Expand Down Expand Up @@ -102,7 +79,8 @@ open class EthrDIDResolver : DIDResolver {
val registryAddress = ethNetworkConfig.registryAddress

require(registryAddress.isNotBlank()) {
"The registry address configured for network `$networkIdentifier` is blank."
"The registryAddress configured for network `${ethNetworkConfig.name}` is blank. " +
"Please check the configuration you use in your EthrDIDResolver.Builder"
}

val normalizedDid = normalizeDid(did)
Expand All @@ -125,7 +103,7 @@ open class EthrDIDResolver : DIDResolver {
registryAddress: String
): String {
val encodedCall =
EthereumDIDRegistry.Changed.encode(Solidity.Address(identity.hexToBigInteger()))
Erc1056Contract.Changed.encode(Solidity.Address(identity.hexToBigInteger()))
return try {
rpc.ethCall(registryAddress, encodedCall)
} catch (err: JsonRpcException) {
Expand Down Expand Up @@ -190,7 +168,6 @@ open class EthrDIDResolver : DIDResolver {

}


} while (lastChange != BigInteger.ZERO)

return events
Expand Down
Loading

0 comments on commit 6642a2a

Please sign in to comment.