Skip to content

Commit

Permalink
Merge pull request #46 from uport-project/refactor/remove-deprecated-…
Browse files Browse the repository at this point in the history
…modules

Refactor/remove deprecated modules
  • Loading branch information
mirceanis committed Mar 21, 2020
2 parents 37e7b76 + a980351 commit 208d9f1
Show file tree
Hide file tree
Showing 43 changed files with 47 additions and 1,746 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
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ We currently support the following DID methods:
- [`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 Down Expand Up @@ -90,7 +89,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 +114,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 Down Expand Up @@ -146,7 +143,6 @@ 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.3.6
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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"
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
24 changes: 11 additions & 13 deletions ethr-did/src/test/java/me/uport/sdk/ethrdid/EthrDIDResolverTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import kotlinx.coroutines.runBlocking
import me.uport.sdk.core.HttpClient
import me.uport.sdk.core.Networks
import me.uport.sdk.core.hexToBigInteger
import me.uport.sdk.ethrdid.EthereumDIDRegistry.Events.DIDOwnerChanged
import me.uport.sdk.ethrdid.Erc1056Contract.Events.DIDOwnerChanged
import me.uport.sdk.ethrdid.EthrDIDResolver.Companion.DEFAULT_REGISTRY_ADDRESS
import me.uport.sdk.jsonrpc.JsonRPC
import me.uport.sdk.jsonrpc.model.JsonRpcLogItem
import me.uport.sdk.jsonrpc.model.exceptions.JSON_RPC_INTERNAL_ERROR_CODE
Expand Down Expand Up @@ -90,7 +91,6 @@ class EthrDIDResolverTest {
assertThat(lastChanged.hexToBigInteger()).isNotEqualTo(BigInteger.ZERO)
}


@Test
fun `can parse getLogs response`() = runBlocking {
val http = mockk<HttpClient>()
Expand Down Expand Up @@ -386,7 +386,7 @@ class EthrDIDResolverTest {
val identity = "0xf3beac30c498d9e26865f34fcaa57dbb935b0d74"
val owner = identity

val event = EthereumDIDRegistry.Events.DIDAttributeChanged.Arguments(
val event = Erc1056Contract.Events.DIDAttributeChanged.Arguments(
identity = Solidity.Address(identity.hexToBigInteger()),
name = Solidity.Bytes32("did/pub/Secp256k1/veriKey/base64".toByteArray()),
value = Solidity.Bytes("0x02b97c30de767f084ce3080168ee293053ba33b235d7116a3263d29f1450936b71".hexToByteArray()),
Expand Down Expand Up @@ -470,7 +470,6 @@ class EthrDIDResolverTest {
"did:ethr:0x01:0xB9C5714089478a327F09197987f16f9E5d936E8a#owner"
)


val invalidDids = listOf(
"0xb9c5714089478a327f09197987f16f9e5d936e",
"B9C5714089478a327F09197987f16f9E5d936E8a",
Expand Down Expand Up @@ -601,7 +600,6 @@ class EthrDIDResolverTest {
)
} returns """{"jsonrpc":"2.0","id":1,"result":[]}"""


val resolver = EthrDIDResolver.Builder()
.addNetwork(EthrDIDNetwork("mainnet", "mockregistry", rpc, "0x1"))
.build()
Expand Down Expand Up @@ -642,7 +640,6 @@ class EthrDIDResolverTest {
)
} returns """{"jsonrpc":"2.0","id":1,"result":[]}"""


val resolver = EthrDIDResolver.Builder()
.addNetwork(EthrDIDNetwork("mainnet", "0xregistry", rpc, "0x1"))
.addNetwork(EthrDIDNetwork("rinkeby", "0xregistry", rpc, "0x4"))
Expand Down Expand Up @@ -701,7 +698,6 @@ class EthrDIDResolverTest {
)
} returns """{"jsonrpc":"2.0","id":1,"result":[]}"""


val resolver = EthrDIDResolver.Builder()
.addNetwork(EthrDIDNetwork("__default__", "0xregistry", rpc, "0x01"))
.build()
Expand Down Expand Up @@ -807,26 +803,28 @@ class EthrDIDResolverTest {
}
}


@Test
fun `throws when registry is not configured`() {
val rpc = mockk<JsonRPC>()
fun `throws when registry address is not configured`() {
val resolver =
EthrDIDResolver.Builder()
.addNetwork(EthrDIDNetwork("", "", rpc, "0x1"))
.addNetwork(EthrDIDNetwork("", "", mockk(), "0x1"))
.build()
coAssert {
resolver.resolve("did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a")
}.isFailure().all {
isInstanceOf(IllegalArgumentException::class)
hasMessage(
"The registryAddress configured for network `` is blank. " +
"Please check the configuration you use in your EthrDIDResolver.Builder"
)
}
}

@Test
fun `parses attribute changed event with trailing null chars`() = runBlocking {
val resolver = EthrDIDResolver.Builder().build()

val event = EthereumDIDRegistry.Events.DIDAttributeChanged.Arguments(
val event = Erc1056Contract.Events.DIDAttributeChanged.Arguments(
identity = Solidity.Address(BigInteger("1318742768210968905798991064222156353846287247782")),
name = Solidity.Bytes32("0x6469642f7075622f736563703235366b312f766572694b65792f686578000000".hexToByteArray()),
value = Solidity.Bytes("0x0295dda1dca7f80e308ef60155ddeac00e46b797fd40ef407f422e88d2467a27eb".hexToByteArray()),
Expand Down Expand Up @@ -862,7 +860,7 @@ class EthrDIDResolverTest {
} throws JsonRpcException(JSON_RPC_INTERNAL_ERROR_CODE, "fake error")

val resolver = EthrDIDResolver.Builder()
.addNetwork(EthrDIDNetwork("", "0xregistry", rpc, "0x1")).build()
.addNetwork(EthrDIDNetwork("", DEFAULT_REGISTRY_ADDRESS, rpc, "0x1")).build()
coAssert {
resolver.lastChanged("0xb9c5714089478a327f09197987f16f9e5d936e8a", rpc, "0xregistry")
}.isFailure().all {
Expand Down
1 change: 0 additions & 1 deletion ethr-status/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ apply plugin: "com.jfrog.bintray"

project.ext.description = "Ethr implementation of credential-status"


dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api "com.github.uport-project.kotlin-common:jsonrpc:$uport_kotlin_common_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.kethereum.keccakshortcut.keccak
import pm.gnosis.model.Solidity
import java.math.BigInteger


/**
* Ethr Implementation of the [StatusResolver]
* This class enables users check the revocation status of a credential
Expand Down
Loading

0 comments on commit 208d9f1

Please sign in to comment.