diff --git a/CHANGELOG.md b/CHANGELOG.md index b594e84..0026b7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* 0.4.1 + * fix - okhttp dependency ( 4ac0e8d1 )( 4f2839f4 ) + * 0.4.0 * feat - easy configuration with infuraProjectID ( #8 ) * feat - find networks by name after configuration ( #9 ) diff --git a/README.md b/README.md index 3fac1e0..8f87eeb 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ allprojects { In your module `build.gradle` file, add: ```groovy -def uport_kotlin_common_version = "0.4.0" +def uport_kotlin_common_version = "0.4.1" dependencies { //... // core lib diff --git a/build.gradle b/build.gradle index 54f7701..8b2aece 100644 --- a/build.gradle +++ b/build.gradle @@ -3,23 +3,24 @@ buildscript { ext { - kotlin_version = '1.3.50' - kotlin_serialization_version = '0.12.0' - coroutines_version = "1.3.0" + kotlin_version = '1.3.70' + kotlin_serialization_version = '0.20.0' + coroutines_version = "1.3.5" junit_version = "4.12" mockk_version = "1.9.3" assertk_version = "0.13" - detekt_version = "1.0.0-RC14" + detekt_version = "1.6.0" jacoco_version = "0.8.4" - okhttp_version = "3.14.1" + okhttp_version = "4.4.1" spongycastle_version = "1.58.0.0" - kethereum_version = "0.76.2" - khex_version = "1.0.0-RC3" + kethereum_version = "0.81.4" + khex_version = "1.0.0-RC6" + khash_version = "1.0.0-RC5" - current_release_version = "0.4.0" + current_release_version = "0.4.1" } repositories { @@ -51,7 +52,7 @@ detekt { "$projectDir" ) //config = "${projectDir}/detekt.yml" - filters = ".*test.*,.*/resources/.*,.*/tmp/.*,.*/build/.*" +// exclude = ".*test.*,.*/resources/.*,.*/tmp/.*,.*/build/.*" parallel = true reports { xml { @@ -65,6 +66,10 @@ detekt { } } +tasks.withType(io.gitlab.arturbosch.detekt.Detekt) { + exclude("**/test/**") +} + allprojects { apply plugin: 'jacoco' diff --git a/core/build.gradle b/core/build.gradle index 8a82123..f4a7e42 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -10,8 +10,9 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" - implementation "com.squareup.okhttp3:okhttp:$okhttp_version" - api "com.github.komputing.khex:extensions-jvm:$khex_version" + api "com.squareup.okhttp3:okhttp:$okhttp_version" + api "com.github.komputing.khex:extensions:$khex_version" + api "com.github.komputing.kethereum:extensions_kotlin:$kethereum_version" implementation "com.madgag.spongycastle:core:$spongycastle_version" testImplementation "junit:junit:$junit_version" diff --git a/core/src/main/java/me/uport/sdk/core/Extensions.kt b/core/src/main/java/me/uport/sdk/core/Extensions.kt index c84fb6f..bbf5dd7 100644 --- a/core/src/main/java/me/uport/sdk/core/Extensions.kt +++ b/core/src/main/java/me/uport/sdk/core/Extensions.kt @@ -2,8 +2,18 @@ package me.uport.sdk.core +import org.kethereum.extensions.hexToBigInteger +import org.komputing.khex.extensions.clean0xPrefix +import org.komputing.khex.extensions.hexToByteArray +import org.komputing.khex.extensions.prepend0xPrefix +import org.komputing.khex.model.HexString import org.spongycastle.util.encoders.Base64 +fun String.clean0xPrefix() = HexString(this).clean0xPrefix().string +fun String.prepend0xPrefix() = HexString(this).prepend0xPrefix().string +fun String.hexToBigInteger() = HexString(this).hexToBigInteger() +fun String.hexToByteArray() = HexString(this).hexToByteArray() + //using spongy castle implementation because the android one can't be used properly in tests /** * Creates a base64 representation of the given byteArray, without padding diff --git a/core/src/main/java/me/uport/sdk/core/HttpClient.kt b/core/src/main/java/me/uport/sdk/core/HttpClient.kt index dc62b05..c23ad84 100644 --- a/core/src/main/java/me/uport/sdk/core/HttpClient.kt +++ b/core/src/main/java/me/uport/sdk/core/HttpClient.kt @@ -2,10 +2,10 @@ package me.uport.sdk.core import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import java.io.IOException /** @@ -24,9 +24,9 @@ class HttpClient { * @throws [IOException] if the request could not be executed due to cancellation, disconnect or timeout */ suspend fun urlPost(url: String, jsonBody: String, authToken: String? = null): String { - val contentType = MediaType.parse("application/json") + val contentType = "application/json".toMediaTypeOrNull() - val body = RequestBody.create(contentType, jsonBody) + val body = jsonBody.toRequestBody(contentType) val request = Request.Builder().apply { url(url) addHeader("Accept", "application/json") @@ -37,13 +37,13 @@ class HttpClient { post(body) }.build() - val response = okClient.newCall(request).execute() + val response = withContext(Dispatchers.IO) { okClient.newCall(request).execute() } if (response.isSuccessful) { - return withContext(Dispatchers.IO) { response.body()?.string() } + return withContext(Dispatchers.IO) { response.body?.string() } ?: throw IOException("got a null response body") } else { - val code = response.code() + val code = response.code throw IOException("server responded with HTTP $code") } } @@ -63,13 +63,13 @@ class HttpClient { } }.build() - val response = okClient.newCall(request).execute() + val response = withContext(Dispatchers.IO) { okClient.newCall(request).execute() } if (response.isSuccessful) { - return withContext(Dispatchers.IO) { response.body()?.string() } + return withContext(Dispatchers.IO) { response.body?.string() } ?: throw IOException("got a null response body") } else { - val code = response.code() + val code = response.code throw IOException("server responded with HTTP $code") } } diff --git a/core/src/main/java/me/uport/sdk/core/Networks.kt b/core/src/main/java/me/uport/sdk/core/Networks.kt index 1fa9877..6ec432d 100644 --- a/core/src/main/java/me/uport/sdk/core/Networks.kt +++ b/core/src/main/java/me/uport/sdk/core/Networks.kt @@ -4,6 +4,7 @@ package me.uport.sdk.core import org.komputing.khex.extensions.clean0xPrefix import org.komputing.khex.extensions.prepend0xPrefix +import org.komputing.khex.model.HexString /** * Convenience singleton that holds URLs and addresses for different eth networks. @@ -116,12 +117,11 @@ object Networks { fun registerNetwork(network: EthNetwork) { val normalizedId = cleanId(network.networkId) - //TODO: check if [network] has necessary fields NETWORK_CONFIG[normalizedId] = network } /** - * Gets an [EthNetwork] based on a [networkId] or [name] + * Gets an [EthNetwork] based on a networkId or name */ fun get(nameOrId: String): EthNetwork { val cleanNetId = cleanId(nameOrId) @@ -139,7 +139,12 @@ object Networks { return NETWORK_CONFIG.values.find { it.name.toLowerCase() == queryName } } - private fun cleanId(id: String) = id.clean0xPrefix().trimStart('0').prepend0xPrefix() + private fun cleanId(id: String) : String { + val str = HexString(id) + .clean0xPrefix().string + .trimStart('0') + return HexString(str).prepend0xPrefix().string + } } diff --git a/jsonrpc/build.gradle b/jsonrpc/build.gradle index 413c681..870299f 100644 --- a/jsonrpc/build.gradle +++ b/jsonrpc/build.gradle @@ -17,8 +17,8 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialization_version" - api "com.github.komputing.kethereum:extensions:$kethereum_version" - api "com.github.komputing.khex:extensions-jvm:$khex_version" + api "com.github.komputing.kethereum:extensions_kotlin:$kethereum_version" + api "com.github.komputing.khex:extensions:$khex_version" api project(":core") diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/JsonRPC.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/JsonRPC.kt index d420df3..3e8d20c 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/JsonRPC.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/JsonRPC.kt @@ -2,10 +2,12 @@ package me.uport.sdk.jsonrpc +import kotlinx.serialization.builtins.list +import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.Json -import kotlinx.serialization.list -import kotlinx.serialization.serializer +import kotlinx.serialization.json.JsonConfiguration import me.uport.sdk.core.HttpClient +import me.uport.sdk.core.hexToBigInteger import me.uport.sdk.jsonrpc.model.JsonRpcLogItem import me.uport.sdk.jsonrpc.model.TransactionInformation import me.uport.sdk.jsonrpc.model.TransactionReceipt @@ -15,7 +17,6 @@ import me.uport.sdk.jsonrpc.model.request.EthCallParams import me.uport.sdk.jsonrpc.model.request.JsonRpcLogsRequestParams import me.uport.sdk.jsonrpc.model.request.JsonRpcRequest import me.uport.sdk.jsonrpc.model.response.JsonRpcResponse -import org.kethereum.extensions.hexToBigInteger import java.io.IOException import java.math.BigInteger @@ -27,6 +28,14 @@ open class JsonRPC( private val httpClient: HttpClient = HttpClient() ) { + private val lenientJson = Json( + JsonConfiguration.Stable.copy( + isLenient = true, + ignoreUnknownKeys = true, + useArrayPolymorphism = true + ) + ) + //============================= // eth_call //============================= @@ -90,7 +99,7 @@ open class JsonRPC( val rawResult = httpClient.urlPost(rpcEndpoint, payloadRequest) - val parsedResponse = Json.nonstrict.parse( + val parsedResponse = lenientJson.parse( JsonRpcResponse.serializer(JsonRpcLogItem.serializer().list), rawResult ) @@ -201,7 +210,7 @@ open class JsonRPC( val rawResult = httpClient.urlPost(rpcEndpoint, payloadRequest) - val parsedResponse = Json.nonstrict.parse( + val parsedResponse = lenientJson.parse( JsonRpcResponse.serializer(TransactionReceipt.serializer()), rawResult ) @@ -235,7 +244,7 @@ open class JsonRPC( val rawResult = httpClient.urlPost(rpcEndpoint, payloadRequest) - val parsedResponse = Json.nonstrict.parse( + val parsedResponse = lenientJson.parse( JsonRpcResponse.serializer(TransactionInformation.serializer()), rawResult ) @@ -287,7 +296,7 @@ open class JsonRPC( private suspend fun jsonRpcGenericCall(url: String, payloadRequest: String): String { val rawResult = httpClient.urlPost(url, payloadRequest) - val parsedResponse = Json.nonstrict.parse( + val parsedResponse = lenientJson.parse( JsonRpcResponse.serializer(String.serializer()), rawResult ) @@ -298,6 +307,3 @@ open class JsonRPC( } } - - - diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/JsonRpcLogItem.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/JsonRpcLogItem.kt index a81996e..49a1193 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/JsonRpcLogItem.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/JsonRpcLogItem.kt @@ -20,4 +20,4 @@ data class JsonRpcLogItem( val blockHash: String, val logIndex: BigInteger, val removed: Boolean -) \ No newline at end of file +) diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/Serializers.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/Serializers.kt index a1073ac..3285768 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/Serializers.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/Serializers.kt @@ -1,11 +1,16 @@ package me.uport.sdk.jsonrpc.model -import kotlinx.serialization.* -import kotlinx.serialization.internal.StringDescriptor -import org.kethereum.extensions.hexToBigInteger +import kotlinx.serialization.Decoder +import kotlinx.serialization.Encoder +import kotlinx.serialization.KSerializer +import kotlinx.serialization.PrimitiveDescriptor +import kotlinx.serialization.PrimitiveKind +import kotlinx.serialization.SerialDescriptor +import kotlinx.serialization.Serializer +import me.uport.sdk.core.clean0xPrefix +import me.uport.sdk.core.hexToBigInteger +import me.uport.sdk.core.hexToByteArray import org.kethereum.extensions.toHexString -import org.komputing.khex.extensions.clean0xPrefix -import org.komputing.khex.extensions.hexToByteArray import org.komputing.khex.extensions.toHexString import java.math.BigInteger @@ -16,10 +21,10 @@ import java.math.BigInteger @Serializer(forClass = BigInteger::class) object BigIntegerSerializer : KSerializer { override val descriptor: SerialDescriptor = - StringDescriptor.withName("BigIntegerSerializer") + PrimitiveDescriptor("BigIntegerSerializer", PrimitiveKind.STRING) - override fun serialize(encoder: Encoder, obj: BigInteger) { - encoder.encodeString(obj.toHexString()) + override fun serialize(encoder: Encoder, value: BigInteger) { + encoder.encodeString(value.toHexString()) } override fun deserialize(decoder: Decoder): BigInteger = decoder @@ -42,10 +47,10 @@ object BigIntegerSerializer : KSerializer { @Serializer(forClass = ByteArray::class) object ByteArraySerializer : KSerializer { override val descriptor: SerialDescriptor = - StringDescriptor.withName("ByteArraySerializer") + PrimitiveDescriptor("ByteArraySerializer", PrimitiveKind.STRING) - override fun serialize(encoder: Encoder, obj: ByteArray) { - encoder.encodeString(obj.toHexString()) + override fun serialize(encoder: Encoder, value: ByteArray) { + encoder.encodeString(value.toHexString()) } override fun deserialize(decoder: Decoder): ByteArray = decoder @@ -58,4 +63,4 @@ object ByteArraySerializer : KSerializer { } } .hexToByteArray() -} \ No newline at end of file +} diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionInformation.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionInformation.kt index 489d50c..ab28f72 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionInformation.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionInformation.kt @@ -31,6 +31,7 @@ data class TransactionInformation( ) { + @Suppress("ComplexMethod") @Generated override fun equals(other: Any?): Boolean { if (this === other) return true @@ -74,6 +75,4 @@ data class TransactionInformation( result = 31 * result + s.hashCode() return result } - - -} \ No newline at end of file +} diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionReceipt.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionReceipt.kt index 7f1ecf7..f564da6 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionReceipt.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/TransactionReceipt.kt @@ -23,4 +23,4 @@ data class TransactionReceipt( val logs: List? = null, val logsBloom: String? = "", val status: BigInteger = BigInteger.ZERO -) \ No newline at end of file +) diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/exceptions/JsonRpcInvalidArgumentException.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/exceptions/JsonRpcInvalidArgumentException.kt index df76e65..7111297 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/exceptions/JsonRpcInvalidArgumentException.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/exceptions/JsonRpcInvalidArgumentException.kt @@ -6,4 +6,4 @@ package me.uport.sdk.jsonrpc.model.exceptions class JsonRpcInvalidArgumentException( override val code : Int, override val message : String -) : JsonRpcException(code, message) \ No newline at end of file +) : JsonRpcException(code, message) diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/EthCallParams.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/EthCallParams.kt index 28dc621..6ae0a98 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/EthCallParams.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/EthCallParams.kt @@ -9,4 +9,4 @@ import kotlinx.serialization.Serializable internal class EthCallParams( private val to: String, private val data: String -) \ No newline at end of file +) diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/JsonRpcLogsRequestParams.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/JsonRpcLogsRequestParams.kt index 9b1903d..a6197d2 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/JsonRpcLogsRequestParams.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/request/JsonRpcLogsRequestParams.kt @@ -17,4 +17,4 @@ internal class JsonRpcLogsRequestParams( private val toBlock: BigInteger, private val address: String, private val topics: List -) \ No newline at end of file +) diff --git a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/response/JsonRpcResponse.kt b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/response/JsonRpcResponse.kt index 70a4982..8699c05 100644 --- a/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/response/JsonRpcResponse.kt +++ b/jsonrpc/src/main/java/me/uport/sdk/jsonrpc/model/response/JsonRpcResponse.kt @@ -13,4 +13,4 @@ import me.uport.sdk.jsonrpc.model.exceptions.JsonRpcError internal class JsonRpcResponse( val result: T? = null, val error: JsonRpcError? = null -) \ No newline at end of file +) diff --git a/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRPCTest.kt b/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRPCTest.kt index 1505521..3d5fac4 100644 --- a/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRPCTest.kt +++ b/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRPCTest.kt @@ -11,6 +11,7 @@ import io.mockk.spyk 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.jsonrpc.model.JsonRpcLogItem import me.uport.sdk.jsonrpc.model.TransactionInformation import me.uport.sdk.jsonrpc.model.TransactionReceipt @@ -19,7 +20,6 @@ import me.uport.sdk.jsonrpc.model.exceptions.JsonRpcInvalidArgumentException import me.uport.sdk.jsonrpc.model.exceptions.TransactionNotFoundException import me.uport.sdk.testhelpers.coAssert import org.junit.Test -import org.kethereum.extensions.hexToBigInteger import java.math.BigInteger class JsonRPCTest { diff --git a/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRpcBaseResponseTest.kt b/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRpcBaseResponseTest.kt index fe36521..35e8fe3 100644 --- a/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRpcBaseResponseTest.kt +++ b/jsonrpc/src/test/java/me/uport/sdk/jsonrpc/JsonRpcBaseResponseTest.kt @@ -9,6 +9,7 @@ import io.mockk.coEvery import io.mockk.mockk import kotlinx.coroutines.runBlocking import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonConfiguration import me.uport.sdk.core.HttpClient import me.uport.sdk.core.Networks import me.uport.sdk.jsonrpc.model.JsonRpcLogItem @@ -37,7 +38,7 @@ class JsonRpcBaseResponseTest { @Test fun `can deserialize log item json`() { - val item = Json.nonstrict.parse(JsonRpcLogItem.serializer(), logItemJson) + val item = Json(JsonConfiguration.Stable).parse(JsonRpcLogItem.serializer(), logItemJson) assertThat(item).isNotNull() diff --git a/signer-common/build.gradle b/signer-common/build.gradle index 206fe82..2a09065 100644 --- a/signer-common/build.gradle +++ b/signer-common/build.gradle @@ -11,12 +11,12 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" api project(":core") - api "com.github.komputing.khex:extensions-jvm:$khex_version" - api "com.github.komputing.kethereum:extensions:$kethereum_version" + api "com.github.komputing.khex:extensions:$khex_version" + api "com.github.komputing.kethereum:extensions_kotlin:$kethereum_version" api "com.github.komputing.kethereum:model:$kethereum_version" - implementation "com.github.komputing.kethereum:functions:$kethereum_version" + implementation "com.github.komputing.kethereum:extensions_transactions:$kethereum_version" implementation "com.github.komputing.kethereum:crypto:$kethereum_version" - implementation "com.github.komputing.kethereum:hashes:$kethereum_version" + implementation "com.github.komputing.khash:sha256:$khash_version" implementation "com.github.komputing.kethereum:crypto_impl_spongycastle:$kethereum_version" implementation "com.madgag.spongycastle:core:$spongycastle_version" diff --git a/signer-common/src/main/java/me/uport/sdk/signer/Extensions.kt b/signer-common/src/main/java/me/uport/sdk/signer/Extensions.kt index cd8e9b7..26bd152 100644 --- a/signer-common/src/main/java/me/uport/sdk/signer/Extensions.kt +++ b/signer-common/src/main/java/me/uport/sdk/signer/Extensions.kt @@ -2,17 +2,21 @@ package me.uport.sdk.signer +import me.uport.sdk.core.clean0xPrefix import me.uport.sdk.core.decodeBase64 import me.uport.sdk.core.padBase64 +import me.uport.sdk.core.prepend0xPrefix import me.uport.sdk.core.toBase64 import me.uport.sdk.core.toBase64UrlSafe import org.kethereum.crypto.decompressKey import org.kethereum.extensions.toBigInteger import org.kethereum.extensions.toBytesPadded import org.kethereum.extensions.toHexStringNoPrefix -import org.kethereum.model.* -import org.komputing.khex.extensions.clean0xPrefix -import org.komputing.khex.extensions.prepend0xPrefix +import org.kethereum.model.ECKeyPair +import org.kethereum.model.PRIVATE_KEY_SIZE +import org.kethereum.model.PUBLIC_KEY_SIZE +import org.kethereum.model.PublicKey +import org.kethereum.model.SignatureData import org.komputing.khex.extensions.toNoPrefixHexString import org.spongycastle.asn1.ASN1EncodableVector import org.spongycastle.asn1.ASN1Encoding @@ -96,7 +100,8 @@ fun SignatureData.getJoseEncoded(recoverable: Boolean = false): String { * Decodes a JOSE encoded signature string. * @param recoveryParam can be used in case the signature is non recoverable to be added as recovery byte */ -fun String.decodeJose(recoveryParam: Byte = 27): SignatureData = this.decodeBase64().decodeJose(recoveryParam) +fun String.decodeJose(recoveryParam: Byte = 27): SignatureData = + this.decodeBase64().decodeJose(recoveryParam) /** * Decodes a JOSE encoded signature ByteArray. diff --git a/signer-common/src/main/java/me/uport/sdk/signer/KPSigner.kt b/signer-common/src/main/java/me/uport/sdk/signer/KPSigner.kt index a44a210..0c3d6f3 100644 --- a/signer-common/src/main/java/me/uport/sdk/signer/KPSigner.kt +++ b/signer-common/src/main/java/me/uport/sdk/signer/KPSigner.kt @@ -1,13 +1,13 @@ package me.uport.sdk.signer +import me.uport.sdk.core.hexToBigInteger import org.kethereum.crypto.signMessage import org.kethereum.crypto.signMessageHash import org.kethereum.crypto.toAddress import org.kethereum.crypto.toECKeyPair -import org.kethereum.extensions.hexToBigInteger -import org.kethereum.hashes.sha256 import org.kethereum.model.PrivateKey import org.kethereum.model.SignatureData +import org.komputing.khash.sha256.extensions.sha256 /** * Simple [Signer] implementation that holds the KeyPair in memory. @@ -19,7 +19,10 @@ class KPSigner(privateKey: String) : Signer { private val keyPair = PrivateKey(privateKey.hexToBigInteger()).toECKeyPair() - override fun signJWT(rawPayload: ByteArray, callback: (err: Exception?, sigData: SignatureData) -> Unit) { + override fun signJWT( + rawPayload: ByteArray, + callback: (err: Exception?, sigData: SignatureData) -> Unit + ) { try { val sigData = signMessageHash(rawPayload.sha256(), keyPair, false) callback(null, sigData) @@ -30,7 +33,10 @@ class KPSigner(privateKey: String) : Signer { override fun getAddress() = keyPair.toAddress().hex - override fun signETH(rawMessage: ByteArray, callback: (err: Exception?, sigData: SignatureData) -> Unit) { + override fun signETH( + rawMessage: ByteArray, + callback: (err: Exception?, sigData: SignatureData) -> Unit + ) { try { val sigData = keyPair.signMessage(rawMessage) diff --git a/signer-common/src/main/java/me/uport/sdk/signer/Signer.kt b/signer-common/src/main/java/me/uport/sdk/signer/Signer.kt index e837242..0f32bbd 100644 --- a/signer-common/src/main/java/me/uport/sdk/signer/Signer.kt +++ b/signer-common/src/main/java/me/uport/sdk/signer/Signer.kt @@ -1,6 +1,6 @@ package me.uport.sdk.signer -import org.kethereum.functions.encodeRLP +import org.kethereum.extensions.transactions.encodeRLP import org.kethereum.model.SignatureData import org.kethereum.model.Transaction import kotlin.coroutines.resume diff --git a/signer-common/src/test/java/me/uport/sdk/signer/KPSignerTests.kt b/signer-common/src/test/java/me/uport/sdk/signer/KPSignerTests.kt index faa0e57..7bac1a3 100644 --- a/signer-common/src/test/java/me/uport/sdk/signer/KPSignerTests.kt +++ b/signer-common/src/test/java/me/uport/sdk/signer/KPSignerTests.kt @@ -4,10 +4,10 @@ import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isNull import kotlinx.coroutines.runBlocking +import me.uport.sdk.core.hexToBigInteger +import me.uport.sdk.core.hexToByteArray import org.junit.Test -import org.kethereum.extensions.hexToBigInteger import org.kethereum.model.SignatureData -import org.komputing.khex.extensions.hexToByteArray class KPSignerTests { diff --git a/signer-common/src/test/java/me/uport/sdk/signer/SignatureTests.kt b/signer-common/src/test/java/me/uport/sdk/signer/SignatureTests.kt index cbed1c8..0b51a3e 100644 --- a/signer-common/src/test/java/me/uport/sdk/signer/SignatureTests.kt +++ b/signer-common/src/test/java/me/uport/sdk/signer/SignatureTests.kt @@ -4,8 +4,8 @@ import assertk.assertThat import assertk.assertions.isEqualTo import kotlinx.coroutines.runBlocking import me.uport.sdk.core.decodeBase64 +import me.uport.sdk.core.hexToBigInteger import org.junit.Test -import org.kethereum.extensions.hexToBigInteger import org.kethereum.model.SignatureData class SignatureTests { @@ -18,7 +18,8 @@ class SignatureTests { "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpc3MiOiIzNHdqc3h3dmR1YW5vN05GQzh1ak5KbkZqYmFjZ1llV0E4bSIsImlhdCI6MTQ4NTMyMTEzMywiY2xhaW1zIjp7Im5hbWUiOiJCb2IifSwiZXhwIjoxNDg1NDA3NTMzfQ" //some base64 encoded TX data - val refTxData = "9oCFC6Q7dACDL+/YlJ4gaMziLeTh6A8Vy3HvQ1ogo7N8iA3gtrOnZAAAiQq83vASNFZ4kByAgA==" + val refTxData = + "9oCFC6Q7dACDL+/YlJ4gaMziLeTh6A8Vy3HvQ1ogo7N8iA3gtrOnZAAAiQq83vASNFZ4kByAgA==" testData.forEach { ref -> @@ -34,7 +35,12 @@ class SignatureTests { } - data class TestVector(val privateKey: String, val address: String, val jwtSig: String, val txSig: SignatureData) + data class TestVector( + val privateKey: String, + val address: String, + val jwtSig: String, + val txSig: SignatureData + ) private val testData = arrayOf( diff --git a/test-helpers/src/main/java/me/uport/sdk/testhelpers/AssertionHelpers.kt b/test-helpers/src/main/java/me/uport/sdk/testhelpers/AssertionHelpers.kt index 8b9e3c9..4b9e0f3 100644 --- a/test-helpers/src/main/java/me/uport/sdk/testhelpers/AssertionHelpers.kt +++ b/test-helpers/src/main/java/me/uport/sdk/testhelpers/AssertionHelpers.kt @@ -32,4 +32,4 @@ fun Assert.isInstanceOf(classes: List>) = transform { act } actual -} \ No newline at end of file +} diff --git a/test-helpers/src/main/java/me/uport/sdk/testhelpers/TestTimeProvider.kt b/test-helpers/src/main/java/me/uport/sdk/testhelpers/TestTimeProvider.kt index 4dd78b6..392baf0 100644 --- a/test-helpers/src/main/java/me/uport/sdk/testhelpers/TestTimeProvider.kt +++ b/test-helpers/src/main/java/me/uport/sdk/testhelpers/TestTimeProvider.kt @@ -8,4 +8,4 @@ import me.uport.sdk.core.ITimeProvider */ class TestTimeProvider(private val currentTimeMs: Long) : ITimeProvider { override fun nowMs(): Long = currentTimeMs -} \ No newline at end of file +} diff --git a/test-helpers/src/test/java/me/uport/sdk/testhelpers/AssertionHelpersKtTest.kt b/test-helpers/src/test/java/me/uport/sdk/testhelpers/AssertionHelpersKtTest.kt index e4db81b..2431d7a 100644 --- a/test-helpers/src/test/java/me/uport/sdk/testhelpers/AssertionHelpersKtTest.kt +++ b/test-helpers/src/test/java/me/uport/sdk/testhelpers/AssertionHelpersKtTest.kt @@ -21,9 +21,9 @@ class AssertionHelpersKtTest { fun `can coAssert on throwing methods`() { coAssert { delay(1) - throw RuntimeException("I'm throwing it") + throw IllegalStateException("I'm throwing it") }.thrownError { - isInstanceOf(RuntimeException::class) + isInstanceOf(IllegalStateException::class) hasMessage("I'm throwing it") } }