From 660694b69d01508b9b61cfc64f4699d3ae78071c Mon Sep 17 00:00:00 2001 From: Joey Harward Date: Wed, 4 Nov 2020 22:10:33 -0500 Subject: [PATCH 1/5] ESR identity request --- buildSrc/src/main/kotlin/Dependencies.kt | 11 +- protonsdk/build.gradle.kts | 2 +- .../com/metallicus/protonsdk/AccountModule.kt | 109 +++++++++++++++++- .../java/com/metallicus/protonsdk/Proton.kt | 44 +++++++ .../protonsdk/api/ESRCallbackService.kt | 41 +++++++ .../protonsdk/api/ProtonChainService.kt | 6 + .../metallicus/protonsdk/di/ProtonModule.kt | 53 ++++++--- .../eosio/commander/ec/EosPrivateKey.java | 24 ++++ .../metallicus/protonsdk/model/ProtonESR.kt | 40 +++++++ .../repository/ChainProviderRepository.kt | 5 + .../protonsdk/repository/ESRRepository.kt | 41 +++++++ protonsdk/src/main/res/values/strings.xml | 1 + 12 files changed, 352 insertions(+), 25 deletions(-) create mode 100644 protonsdk/src/main/java/com/metallicus/protonsdk/api/ESRCallbackService.kt create mode 100644 protonsdk/src/main/java/com/metallicus/protonsdk/model/ProtonESR.kt create mode 100755 protonsdk/src/main/java/com/metallicus/protonsdk/repository/ESRRepository.kt diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 83e3f758..205d7022 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -23,8 +23,8 @@ const val kotlinVersion = "1.4.10" const val orchidVersion = "0.21.1" object ProtonSdk { - const val versionCode = 22 - const val versionName = "0.6.1" + const val versionCode = 23 + const val versionName = "0.7.0" } object BuildPlugins { @@ -49,7 +49,7 @@ object Android { const val minSdk = 21 const val compileSdk = 30 const val targetSdk = compileSdk - const val buildTools = "30.0.1" + const val buildTools = "30.0.2" object Progaurd { const val consumeFile = "consumer-rules.pro" @@ -72,6 +72,7 @@ object Libraries { const val timber = "4.7.1" const val gson = "2.8.6" const val guava = "29.0-jre" + const val esr = "1.0.1" } const val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" @@ -99,9 +100,7 @@ object Libraries { const val orchidKotlindoc = "io.github.javaeden.orchid:OrchidKotlindoc:$orchidVersion" const val orchidPluginDocs = "io.github.javaeden.orchid:OrchidPluginDocs:$orchidVersion" const val orchidGithub = "io.github.javaeden.orchid:OrchidGithub:$orchidVersion" - - // Greymass ESR - //implementation "com.greymass:esrsdk:1.0.1" + const val greymassESR = "com.greymass:esrsdk:${Versions.esr}" } object TestLibraries { diff --git a/protonsdk/build.gradle.kts b/protonsdk/build.gradle.kts index 9b288fb7..83921380 100644 --- a/protonsdk/build.gradle.kts +++ b/protonsdk/build.gradle.kts @@ -96,7 +96,7 @@ dependencies { implementation(Libraries.guava) // Greymass ESR - //implementation "com.greymass:esrsdk:1.0.1" + implementation(Libraries.greymassESR) } // Dokka diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt index 46264ebe..2e2cd3a2 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt @@ -23,8 +23,9 @@ package com.metallicus.protonsdk import android.content.Context import android.util.Base64 -import com.google.gson.Gson -import com.google.gson.JsonSyntaxException +import com.google.gson.* +import com.greymass.esr.ESR +import com.greymass.esr.SigningRequest import com.metallicus.protonsdk.common.SecureKeys import com.metallicus.protonsdk.common.Prefs import com.metallicus.protonsdk.common.Resource @@ -34,6 +35,8 @@ import com.metallicus.protonsdk.eosio.commander.ec.EosPrivateKey import com.metallicus.protonsdk.model.* import com.metallicus.protonsdk.repository.AccountContactRepository import com.metallicus.protonsdk.repository.AccountRepository +import com.metallicus.protonsdk.repository.ChainProviderRepository +import com.metallicus.protonsdk.repository.ESRRepository import timber.log.Timber import javax.inject.Inject @@ -47,9 +50,15 @@ class AccountModule { @Inject lateinit var accountRepository: AccountRepository + @Inject + lateinit var chainProviderRepository: ChainProviderRepository + @Inject lateinit var accountContactRepository: AccountContactRepository + @Inject + lateinit var esrRepository: ESRRepository + @Inject lateinit var prefs: Prefs @@ -389,4 +398,100 @@ class AccountModule { Resource.error(errorMsg) } } + + suspend fun decodeESR(chainAccount: ChainAccount, originalESRUrl: String): ProtonESR { + val originalESRUrlScheme = originalESRUrl.substringBefore(":") + val esrUrl = "esr:" + originalESRUrl.substringAfter(":") + + val chainId = chainAccount.chainProvider.chainId + val chainUrl = chainAccount.chainProvider.chainUrl + + val esr = ESR(context) { account -> + val response = chainProviderRepository.getAbi(chainUrl, account) + if (response.isSuccessful) { + response.body()?.toString() + } else { + response.errorBody()?.toString() + } + } + + val signingRequest = SigningRequest(esr) + signingRequest.load(esrUrl) + + // TODO: need chainId original string from esr request + //val esrChainId = signingRequest.chainId.toVariant() + //if (esrChainId == chainAccount.chainProvider.chainId) { + + val requestAccountName = signingRequest.info["req_account"].orEmpty() + + val requestKey = "" + if (signingRequest.isIdentity) { + val linkStr = signingRequest.info["link"] + + // TODO: deserialize link as LinkCreate obj + } + + val returnPath = signingRequest.info["return_path"].orEmpty() + + val requestAccount: Account? = if (requestAccountName.isNotEmpty()) { + fetchAccount(chainId, chainUrl, requestAccountName) + } else { + null + } + + return ProtonESR( + requestKey, + chainAccount, + signingRequest, + originalESRUrlScheme, + requestAccount, + returnPath + ) + } + + suspend fun cancelAuthorizeESR(protonESR: ProtonESR): Resource { + return try { + val callback = protonESR.signingRequest.callback + + val response = + esrRepository.cancelAuthorizeESR(callback, "User canceled request") + if (response.isSuccessful) { + Resource.success(response.body()) + } else { + val msg = response.errorBody()?.string() + val errorMsg = if (msg.isNullOrEmpty()) { + response.message() + } else { + msg + } + + Resource.error(errorMsg) + } + } catch (e: Exception) { + Resource.error(e.localizedMessage.orEmpty()) + } + } + + suspend fun authorizeESR(protonESR: ProtonESR): Resource { + return try { + val callback = protonESR.signingRequest.callback + + val response = + esrRepository.authorizeESR(callback, "") + if (response.isSuccessful) { + Resource.success(response.body()) + } else { + val msg = response.errorBody()?.string() + val errorMsg = if (msg.isNullOrEmpty()) { + response.message() + } else { + msg + } + + Resource.error(errorMsg) + } + } catch (e: Exception) { + Resource.error(e.localizedMessage.orEmpty()) + } + } } \ No newline at end of file diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/Proton.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/Proton.kt index 2b1b37f2..09488e06 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/Proton.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/Proton.kt @@ -488,4 +488,48 @@ class Proton private constructor(context: Context) { emit(error) } } + + fun decodeESR(esrUri: String): LiveData> = liveData { + emit(Resource.loading()) + + try { + val activeAccount = getActiveAccountAsync() + + emit(Resource.success(accountModule.decodeESR(activeAccount, esrUri))) + } catch (e: ProtonException) { + val error: Resource = Resource.error(e) + emit(error) + } catch (e: Exception) { + val error: Resource = Resource.error(e.localizedMessage.orEmpty()) + emit(error) + } + } + + fun cancelAuthorizeESR(protonESR: ProtonESR): LiveData> = liveData { + emit(Resource.loading()) + + try { + emit(accountModule.cancelAuthorizeESR(protonESR)) + } catch (e: ProtonException) { + val error: Resource = Resource.error(e) + emit(error) + } catch (e: Exception) { + val error: Resource = Resource.error(e.localizedMessage.orEmpty()) + emit(error) + } + } + + fun authorizeESR(protonESR: ProtonESR): LiveData> = liveData { + emit(Resource.loading()) + + try { + emit(accountModule.authorizeESR(protonESR)) + } catch (e: ProtonException) { + val error: Resource = Resource.error(e) + emit(error) + } catch (e: Exception) { + val error: Resource = Resource.error(e.localizedMessage.orEmpty()) + emit(error) + } + } } \ No newline at end of file diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/api/ESRCallbackService.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/api/ESRCallbackService.kt new file mode 100644 index 00000000..1cbf46b7 --- /dev/null +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/api/ESRCallbackService.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 Proton Chain LLC, Delaware + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.metallicus.protonsdk.api + +import com.google.gson.JsonObject +import retrofit2.Response +import retrofit2.http.* + +data class CancelAuthorizeESRBody(val error: String) +data class AuthorizeESRBody(val error: String) + +interface ESRCallbackService { + @POST + suspend fun cancelAuthorizeESR( + @Url url: String, + @Body body: CancelAuthorizeESRBody): Response + + @POST + suspend fun authorizeESR( + @Url url: String, + @Body body: AuthorizeESRBody): Response +} \ No newline at end of file diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/api/ProtonChainService.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/api/ProtonChainService.kt index 92026934..ab6848b9 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/api/ProtonChainService.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/api/ProtonChainService.kt @@ -75,6 +75,12 @@ interface ProtonChainService { @Body body: AccountBody ): Response + @POST//("/v1/chain/get_abi") + fun getAbi( + @Url url: String, + @Body body: AccountBody + ): Response + @GET//("/v2/state/get_tokens?account=") suspend fun getCurrencyBalances( @Url url: String, diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/di/ProtonModule.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/di/ProtonModule.kt index b3b29b46..4d890d0d 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/di/ProtonModule.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/di/ProtonModule.kt @@ -23,9 +23,9 @@ package com.metallicus.protonsdk.di import android.content.Context import androidx.room.Room -import com.google.gson.Gson import com.google.gson.GsonBuilder import com.metallicus.protonsdk.R +import com.metallicus.protonsdk.api.ESRCallbackService import com.metallicus.protonsdk.api.ProtonChainService import com.metallicus.protonsdk.common.SecureKeys import com.metallicus.protonsdk.common.Prefs @@ -33,7 +33,8 @@ import com.metallicus.protonsdk.db.* import com.metallicus.protonsdk.eosio.commander.GsonEosTypeAdapterFactory import dagger.Module import dagger.Provides -import okhttp3.OkHttpClient +import okhttp3.* +import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import java.util.concurrent.TimeUnit @@ -41,17 +42,6 @@ import javax.inject.Singleton @Module class ProtonModule { - @Singleton - @Provides - fun provideGson(): Gson { - return GsonBuilder() - .registerTypeAdapterFactory(GsonEosTypeAdapterFactory()) -// .registerTypeAdapter(ActionTraceAct::class.java, ActionTraceActTypeAdapter()) - .serializeNulls() -// .excludeFieldsWithoutExposeAnnotation() - .create() - } - @Singleton @Provides fun provideDb(context: Context): ProtonDb { @@ -99,17 +89,22 @@ class ProtonModule { @Singleton @Provides - fun provideProtonChainService(context: Context, gson: Gson): ProtonChainService { + fun provideProtonChainService(context: Context): ProtonChainService { // val logging = HttpLoggingInterceptor() // logging.level = HttpLoggingInterceptor.Level.BODY -// val httpClient = OkHttpClient.Builder() -// httpClient.addInterceptor(logging) val httpClient = OkHttpClient.Builder() .callTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) +// .addInterceptor(logging) + + val gson = GsonBuilder() + .registerTypeAdapterFactory(GsonEosTypeAdapterFactory()) + .serializeNulls() +// .excludeFieldsWithoutExposeAnnotation() + .create() return Retrofit.Builder() .baseUrl(context.getString(R.string.defaultProtonChainUrl)) @@ -119,6 +114,32 @@ class ProtonModule { .create(ProtonChainService::class.java) } + @Singleton + @Provides + fun provideESRCallbackService(context: Context): ESRCallbackService { + val logging = HttpLoggingInterceptor() + logging.level = HttpLoggingInterceptor.Level.BODY + + val httpClient = OkHttpClient.Builder() + .callTimeout(30, TimeUnit.SECONDS) + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .addInterceptor(logging) + + val gson = GsonBuilder() + .setLenient() + .serializeNulls() + .create() + + return Retrofit.Builder() + .baseUrl(context.getString(R.string.defaultESRCallbackUrl)) + .addConverterFactory(GsonConverterFactory.create(gson)) + .client(httpClient.build()) + .build() + .create(ESRCallbackService::class.java) + } + @Singleton @Provides fun providePrefs(context: Context): Prefs { diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/ec/EosPrivateKey.java b/protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/ec/EosPrivateKey.java index b2165751..8ab72815 100755 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/ec/EosPrivateKey.java +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/eosio/commander/ec/EosPrivateKey.java @@ -26,11 +26,15 @@ import android.annotation.SuppressLint; +import com.google.common.primitives.Bytes; +import com.google.common.primitives.Longs; import com.metallicus.protonsdk.eosio.commander.Base58; import com.metallicus.protonsdk.eosio.commander.digest.Sha256; +import com.metallicus.protonsdk.eosio.commander.digest.Sha512; import java.math.BigInteger; import java.security.SecureRandom; +import java.util.Arrays; /** @@ -119,6 +123,26 @@ public EosPrivateKey(String base58Str) { mPublicKey = new EosPublicKey(findPubKey(mPrivateKey), mCurveParam); } + public byte[] getSharedSecret(EosPublicKey eosPublicKey, long nonce) { + byte[] r = getBytes(); + byte[] publicKeyBytes = eosPublicKey.getBytes(); + CurveParam param = EcTools.getCurveParam(CurveParam.SECP256_K1); + EcPoint publicKeyPoint = param.getCurve().decodePoint(publicKeyBytes); + EcPoint p = EcTools.multiply(publicKeyPoint, toUnsignedBigInteger(r)); + byte[] encodedx = p.getX().toBigInteger().toByteArray(); + if (encodedx.length > 32) { + encodedx = Arrays.copyOfRange(encodedx, 1, encodedx.length); + } + + byte [] retval = encodedx; + if (nonce != 0L) { + byte[] nonceBytes = Longs.toByteArray(nonce); + retval = Bytes.concat(nonceBytes, encodedx); + } + + Sha512 sha512 = Sha512.from(retval); + return sha512.getBytes(); + } public void clear() { mPrivateKey.multiply(BigInteger.ZERO); diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/model/ProtonESR.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/model/ProtonESR.kt new file mode 100644 index 00000000..92a932d4 --- /dev/null +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/model/ProtonESR.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Proton Chain LLC, Delaware + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.metallicus.protonsdk.model + +import com.greymass.esr.ResolvedSigningRequest +import com.greymass.esr.SigningRequest + +class ProtonESR( + val requestKey: String, + val signingAccount: ChainAccount, + val signingRequest: SigningRequest, + val originESRUrlScheme: String, + val requestAccount: Account? = null, + val returnPath: String? = "", + val resolvedSigningRequest: ResolvedSigningRequest? = null//, + //val actions: List +) { + fun getRequestAccountDisplayName(): String { + return requestAccount?.accountContact?.getDisplayName() ?: "Unknown Requester" + } +} \ No newline at end of file diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/repository/ChainProviderRepository.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/repository/ChainProviderRepository.kt index 77e49020..9af6389d 100755 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/repository/ChainProviderRepository.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/repository/ChainProviderRepository.kt @@ -22,6 +22,7 @@ package com.metallicus.protonsdk.repository import com.google.gson.JsonObject +import com.metallicus.protonsdk.api.AccountBody import com.metallicus.protonsdk.api.ProtonChainService import com.metallicus.protonsdk.db.ChainProviderDao import com.metallicus.protonsdk.model.ChainProvider @@ -49,4 +50,8 @@ class ChainProviderRepository @Inject constructor( suspend fun getChainProvider(id: String): ChainProvider { return chainProviderDao.findById(id) } + + fun getAbi(chainUrl: String, accountName: String): Response { + return protonChainService.getAbi("$chainUrl/v1/get_abi", AccountBody(accountName)) + } } diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/repository/ESRRepository.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/repository/ESRRepository.kt new file mode 100755 index 00000000..2370d084 --- /dev/null +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/repository/ESRRepository.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 Proton Chain LLC, Delaware + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.metallicus.protonsdk.repository + +import com.google.gson.JsonObject +import com.metallicus.protonsdk.api.* +import retrofit2.Response +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class ESRRepository @Inject constructor( + private val esrCallbackService: ESRCallbackService +) { + suspend fun cancelAuthorizeESR(url: String, error: String): Response { + return esrCallbackService.cancelAuthorizeESR(url, CancelAuthorizeESRBody(error)) + } + + suspend fun authorizeESR(url: String, error: String): Response { + return esrCallbackService.authorizeESR(url, AuthorizeESRBody(error)) + } +} diff --git a/protonsdk/src/main/res/values/strings.xml b/protonsdk/src/main/res/values/strings.xml index 449f4215..9a3b809a 100755 --- a/protonsdk/src/main/res/values/strings.xml +++ b/protonsdk/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ 384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0 https://proton.cryptolions.io/ + https://cb.anchor.link/ eosio eosio From 1c36a017a3282504566ce2d3770dec797f56c119 Mon Sep 17 00:00:00 2001 From: Joey Harward Date: Wed, 11 Nov 2020 03:33:44 -0500 Subject: [PATCH 2/5] adding "verified" flag for AccountContact --- .../src/main/java/com/metallicus/protonsdk/AccountModule.kt | 2 ++ .../src/main/java/com/metallicus/protonsdk/ActionsModule.kt | 2 ++ .../java/com/metallicus/protonsdk/db/DefaultTypeConverters.kt | 1 - .../main/java/com/metallicus/protonsdk/model/AccountContact.kt | 3 ++- .../metallicus/protonsdk/workers/InitActiveAccountWorker.kt | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt index 2e2cd3a2..35b143a0 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/AccountModule.kt @@ -147,6 +147,8 @@ class AccountModule { val userInfo = rows?.get(0)?.asJsonObject accountContact.name = userInfo?.get("name")?.asString.orEmpty() accountContact.avatar = userInfo?.get("avatar")?.asString.orEmpty() + val verifiedInt = userInfo?.get("verified")?.asInt ?: 0 + accountContact.verified = verifiedInt == 1 } } else { val msg = response.errorBody()?.string() diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/ActionsModule.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/ActionsModule.kt index dd7f0d09..5bf1496e 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/ActionsModule.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/ActionsModule.kt @@ -109,6 +109,8 @@ class ActionsModule { val userInfo = rows?.get(0)?.asJsonObject accountContact.name = userInfo?.get("name")?.asString.orEmpty() accountContact.avatar = userInfo?.get("avatar")?.asString.orEmpty() + val verifiedInt = userInfo?.get("verified")?.asInt ?: 0 + accountContact.verified = verifiedInt == 1 } } else { val msg = response.errorBody()?.string() diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/db/DefaultTypeConverters.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/db/DefaultTypeConverters.kt index 889e3cdd..6234e058 100755 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/db/DefaultTypeConverters.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/db/DefaultTypeConverters.kt @@ -24,7 +24,6 @@ package com.metallicus.protonsdk.db import androidx.room.TypeConverter import com.google.gson.Gson import com.google.gson.reflect.TypeToken -import com.metallicus.protonsdk.model.AccountContact import timber.log.Timber object DefaultTypeConverters { diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountContact.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountContact.kt index c7bfba5f..d08bff25 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountContact.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/model/AccountContact.kt @@ -35,7 +35,8 @@ import com.metallicus.protonsdk.db.DefaultTypeConverters data class AccountContact( val id: String, // accountName var name: String = "", - var avatar: String = "" + var avatar: String = "", + var verified: Boolean = false ) { lateinit var accountName: String // owner accountName diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/workers/InitActiveAccountWorker.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/workers/InitActiveAccountWorker.kt index be69c39c..7448b9be 100644 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/workers/InitActiveAccountWorker.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/workers/InitActiveAccountWorker.kt @@ -127,6 +127,8 @@ class InitActiveAccountWorker val userInfo = rows?.get(0)?.asJsonObject accountContact.name = userInfo?.get("name")?.asString.orEmpty() accountContact.avatar = userInfo?.get("avatar")?.asString.orEmpty() + val verifiedInt = userInfo?.get("verified")?.asInt ?: 0 + accountContact.verified = verifiedInt == 1 } } else { val msg = response.errorBody()?.string() From 9c24a28ed189fbfaadd57d5c6f3b26a774370be7 Mon Sep 17 00:00:00 2001 From: Joey Harward Date: Thu, 12 Nov 2020 10:47:45 -0500 Subject: [PATCH 3/5] Update DB version and ESR library --- buildSrc/src/main/kotlin/Dependencies.kt | 2 +- protonsdk/src/main/java/com/metallicus/protonsdk/db/ProtonDb.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 205d7022..bc7ea23b 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -72,7 +72,7 @@ object Libraries { const val timber = "4.7.1" const val gson = "2.8.6" const val guava = "29.0-jre" - const val esr = "1.0.1" + const val esr = "1.0.2" } const val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" diff --git a/protonsdk/src/main/java/com/metallicus/protonsdk/db/ProtonDb.kt b/protonsdk/src/main/java/com/metallicus/protonsdk/db/ProtonDb.kt index 4cc68b32..3a0f5167 100755 --- a/protonsdk/src/main/java/com/metallicus/protonsdk/db/ProtonDb.kt +++ b/protonsdk/src/main/java/com/metallicus/protonsdk/db/ProtonDb.kt @@ -33,7 +33,7 @@ import com.metallicus.protonsdk.model.* AccountContact::class, CurrencyBalance::class, Action::class], - version = 19, + version = 20, exportSchema = false ) abstract class ProtonDb : RoomDatabase() { From 7dafc378d705cdae5bad14b14cd983a3d3ae574c Mon Sep 17 00:00:00 2001 From: Joey Harward Date: Fri, 13 Nov 2020 12:02:43 -0500 Subject: [PATCH 4/5] Updating to latest Gradle --- buildSrc/src/main/kotlin/Dependencies.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index bc7ea23b..6959b12f 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -29,8 +29,8 @@ object ProtonSdk { object BuildPlugins { object Versions { - const val gradle = "4.1.0" - const val dokka = "0.10.1" + const val gradle = "4.1.1" + const val dokka = "0.10.1" // TODO: 1.4.0 const val bintray = "1.8.5" } From 69e1db239070fd4b8c04f95149aa44859c3791cf Mon Sep 17 00:00:00 2001 From: Joey Harward Date: Fri, 13 Nov 2020 16:32:21 -0500 Subject: [PATCH 5/5] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0867eb0a..8399f851 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Then add the following dependency to your module's build.gradle ```gradle dependencies { ... - implementation "com.metallicus:protonsdk:0.6.1" + implementation "com.metallicus:protonsdk:0.7.0" } ```