From 4d911a976c8a9c07d3614dd14be89421eea33433 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 12 Oct 2020 13:18:03 +0200 Subject: [PATCH 01/13] remove calls to deprecated methods, optimize imports --- .../main/java/im/status/keycard/connect/Registry.kt | 7 +++++-- .../im/status/keycard/connect/card/InitCommand.kt | 5 ++++- .../keycard/connect/card/OpenSecureChannelCommand.kt | 2 -- .../java/im/status/keycard/connect/card/Script.kt | 1 - .../status/keycard/connect/card/VerifyPINCommand.kt | 5 ++++- .../java/im/status/keycard/connect/data/PINCache.kt | 1 - .../im/status/keycard/connect/data/PairingManager.kt | 8 ++++---- .../java/im/status/keycard/connect/net/EthereumRPC.kt | 1 - .../im/status/keycard/connect/net/WalletConnect.kt | 11 ++++++++--- .../im/status/keycard/connect/ui/ChangePINActivity.kt | 2 +- .../im/status/keycard/connect/ui/ChangePUKActivity.kt | 2 +- .../connect/ui/ChangePairingPasswordActivity.kt | 2 +- .../java/im/status/keycard/connect/ui/InitActivity.kt | 6 +++--- .../im/status/keycard/connect/ui/LoadKeyActivity.kt | 2 +- .../java/im/status/keycard/connect/ui/MainActivity.kt | 8 ++++---- .../java/im/status/keycard/connect/ui/PINActivity.kt | 2 +- .../java/im/status/keycard/connect/ui/PUKActivity.kt | 2 +- .../im/status/keycard/connect/ui/PairingActivity.kt | 4 ++-- .../im/status/keycard/connect/ui/ReinstallActivity.kt | 2 +- .../im/status/keycard/connect/ui/SettingsActivity.kt | 2 +- .../status/keycard/connect/ui/ShowMnemonicActivity.kt | 2 +- .../status/keycard/connect/ui/SignMessageActivity.kt | 2 +- .../keycard/connect/ui/SignTransactionActivity.kt | 2 +- 23 files changed, 45 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/im/status/keycard/connect/Registry.kt b/app/src/main/java/im/status/keycard/connect/Registry.kt index a5dd03c..5d60261 100644 --- a/app/src/main/java/im/status/keycard/connect/Registry.kt +++ b/app/src/main/java/im/status/keycard/connect/Registry.kt @@ -6,8 +6,11 @@ import android.nfc.NfcAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import im.status.keycard.android.NFCCardManager -import im.status.keycard.connect.card.* -import im.status.keycard.connect.data.* +import im.status.keycard.connect.card.CardScriptExecutor +import im.status.keycard.connect.card.ScriptListener +import im.status.keycard.connect.data.PINCache +import im.status.keycard.connect.data.PairingManager +import im.status.keycard.connect.data.SettingsManager import im.status.keycard.connect.net.EthereumRPC import im.status.keycard.connect.net.WalletConnect diff --git a/app/src/main/java/im/status/keycard/connect/card/InitCommand.kt b/app/src/main/java/im/status/keycard/connect/card/InitCommand.kt index 6949f5e..87c44e9 100644 --- a/app/src/main/java/im/status/keycard/connect/card/InitCommand.kt +++ b/app/src/main/java/im/status/keycard/connect/card/InitCommand.kt @@ -3,7 +3,10 @@ package im.status.keycard.connect.card import android.app.Activity import android.content.Intent import im.status.keycard.connect.Registry -import im.status.keycard.connect.data.* +import im.status.keycard.connect.data.INIT_ACTIVITY_PAIRING +import im.status.keycard.connect.data.INIT_ACTIVITY_PIN +import im.status.keycard.connect.data.INIT_ACTIVITY_PUK +import im.status.keycard.connect.data.REQ_INTERACTIVE_SCRIPT import im.status.keycard.connect.ui.InitActivity import im.status.keycard.io.APDUException import java.io.IOException diff --git a/app/src/main/java/im/status/keycard/connect/card/OpenSecureChannelCommand.kt b/app/src/main/java/im/status/keycard/connect/card/OpenSecureChannelCommand.kt index 74c9421..39cdfcd 100644 --- a/app/src/main/java/im/status/keycard/connect/card/OpenSecureChannelCommand.kt +++ b/app/src/main/java/im/status/keycard/connect/card/OpenSecureChannelCommand.kt @@ -7,8 +7,6 @@ import im.status.keycard.connect.Registry import im.status.keycard.connect.data.PAIRING_ACTIVITY_PASSWORD import im.status.keycard.connect.data.REQ_INTERACTIVE_SCRIPT import im.status.keycard.connect.ui.PairingActivity -import im.status.keycard.io.APDUException -import java.io.IOException class OpenSecureChannelCommand : CardCommand { private var pairingPassword: String? = null diff --git a/app/src/main/java/im/status/keycard/connect/card/Script.kt b/app/src/main/java/im/status/keycard/connect/card/Script.kt index 4c7b3b3..3bb3608 100644 --- a/app/src/main/java/im/status/keycard/connect/card/Script.kt +++ b/app/src/main/java/im/status/keycard/connect/card/Script.kt @@ -1,7 +1,6 @@ package im.status.keycard.connect.card import java.io.IOException -import java.lang.Exception fun scriptWithSecureChannel(): List = listOf(SelectCommand(), InitCommand(), OpenSecureChannelCommand()) fun scriptWithAuthentication(): List = scriptWithSecureChannel().plus(VerifyPINCommand()) diff --git a/app/src/main/java/im/status/keycard/connect/card/VerifyPINCommand.kt b/app/src/main/java/im/status/keycard/connect/card/VerifyPINCommand.kt index 43f9668..46b705f 100644 --- a/app/src/main/java/im/status/keycard/connect/card/VerifyPINCommand.kt +++ b/app/src/main/java/im/status/keycard/connect/card/VerifyPINCommand.kt @@ -3,7 +3,10 @@ package im.status.keycard.connect.card import android.app.Activity import android.content.Intent import im.status.keycard.connect.Registry -import im.status.keycard.connect.data.* +import im.status.keycard.connect.data.PIN_ACTIVITY_ATTEMPTS +import im.status.keycard.connect.data.PIN_ACTIVITY_CARD_UID +import im.status.keycard.connect.data.PUK_ACTIVITY_ATTEMPTS +import im.status.keycard.connect.data.REQ_INTERACTIVE_SCRIPT import im.status.keycard.connect.ui.PINActivity import im.status.keycard.connect.ui.PUKActivity import im.status.keycard.io.APDUException diff --git a/app/src/main/java/im/status/keycard/connect/data/PINCache.kt b/app/src/main/java/im/status/keycard/connect/data/PINCache.kt index 1fa253a..99c98cc 100644 --- a/app/src/main/java/im/status/keycard/connect/data/PINCache.kt +++ b/app/src/main/java/im/status/keycard/connect/data/PINCache.kt @@ -3,7 +3,6 @@ package im.status.keycard.connect.data import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.TimeUnit -import kotlin.collections.HashMap class PINCache { //TODO: don't use Strings, the memory should be cleared before release. For this the entire diff --git a/app/src/main/java/im/status/keycard/connect/data/PairingManager.kt b/app/src/main/java/im/status/keycard/connect/data/PairingManager.kt index 41d49e3..07f5a26 100644 --- a/app/src/main/java/im/status/keycard/connect/data/PairingManager.kt +++ b/app/src/main/java/im/status/keycard/connect/data/PairingManager.kt @@ -5,9 +5,9 @@ import android.content.SharedPreferences import android.util.Base64 import android.util.Base64.NO_PADDING import android.util.Base64.NO_WRAP -import im.status.keycard.applet.Pairing import androidx.security.crypto.EncryptedSharedPreferences -import androidx.security.crypto.MasterKeys +import androidx.security.crypto.MasterKey +import im.status.keycard.applet.Pairing class PairingManager(context: Context) { private val sharedPreferences: SharedPreferences @@ -17,8 +17,8 @@ class PairingManager(context: Context) { } init { - val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC) - sharedPreferences = EncryptedSharedPreferences.create("pairings", masterKeyAlias, context, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM) + val masterKey = MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build() + sharedPreferences = EncryptedSharedPreferences.create(context,"pairings", masterKey, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM) } fun getPairing(instanceUID: ByteArray): Pairing? { diff --git a/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt b/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt index 67cd2a8..0a52027 100644 --- a/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt +++ b/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt @@ -6,7 +6,6 @@ import com.squareup.moshi.Types import okhttp3.OkHttpClient import okhttp3.Request import org.kethereum.rpc.HttpEthereumRPC -import java.lang.Exception import java.lang.reflect.Type import java.math.BigInteger diff --git a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt index f17120e..47b2ce9 100644 --- a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt +++ b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt @@ -24,7 +24,10 @@ import org.kethereum.extensions.transactions.getTokenTransferTo import org.kethereum.extensions.transactions.getTokenTransferValue import org.kethereum.extensions.transactions.isTokenTransfer import org.kethereum.keccakshortcut.keccak -import org.kethereum.model.* +import org.kethereum.model.Address +import org.kethereum.model.SignatureData +import org.kethereum.model.SignedTransaction +import org.kethereum.model.Transaction import org.komputing.khex.encode import org.komputing.khex.extensions.hexToByteArray import org.komputing.khex.extensions.toHexString @@ -32,9 +35,11 @@ import org.komputing.khex.extensions.toNoPrefixHexString import org.komputing.khex.model.HexString import org.walletconnect.Session import org.walletconnect.Session.Config.Companion.fromWCUri -import org.walletconnect.impls.* +import org.walletconnect.impls.FileWCSessionStore +import org.walletconnect.impls.MoshiPayloadAdapter +import org.walletconnect.impls.OkHttpTransport +import org.walletconnect.impls.WCSession import java.io.File -import java.lang.Exception class WalletConnect(var bip32Path: String, var chainID: Long) : ExportKeyCommand.Listener, SignCommand.Listener, Session.Callback { diff --git a/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt index cc844f1..c2f458c 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt @@ -1,9 +1,9 @@ package im.status.keycard.connect.ui -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.EditText +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.card.ChangePINCommand diff --git a/app/src/main/java/im/status/keycard/connect/ui/ChangePUKActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/ChangePUKActivity.kt index 95e9ccf..fe78b2c 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/ChangePUKActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/ChangePUKActivity.kt @@ -1,9 +1,9 @@ package im.status.keycard.connect.ui -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.EditText +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.card.ChangePUKCommand diff --git a/app/src/main/java/im/status/keycard/connect/ui/ChangePairingPasswordActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/ChangePairingPasswordActivity.kt index 24c69df..6907f23 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/ChangePairingPasswordActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/ChangePairingPasswordActivity.kt @@ -1,9 +1,9 @@ package im.status.keycard.connect.ui -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.EditText +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.card.ChangePairingPasswordCommand diff --git a/app/src/main/java/im/status/keycard/connect/ui/InitActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/InitActivity.kt index c9185fc..aec81d7 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/InitActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/InitActivity.kt @@ -2,18 +2,18 @@ package im.status.keycard.connect.ui import android.app.Activity import android.content.Intent -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Base64 -import android.view.View -import im.status.keycard.globalplatform.Crypto import android.util.Base64.NO_PADDING import android.util.Base64.NO_WRAP +import android.view.View import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.data.INIT_ACTIVITY_PAIRING import im.status.keycard.connect.data.INIT_ACTIVITY_PIN import im.status.keycard.connect.data.INIT_ACTIVITY_PUK +import im.status.keycard.globalplatform.Crypto class InitActivity : AppCompatActivity() { private lateinit var pin: String diff --git a/app/src/main/java/im/status/keycard/connect/ui/LoadKeyActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/LoadKeyActivity.kt index 27b3703..0c0dd61 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/LoadKeyActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/LoadKeyActivity.kt @@ -2,10 +2,10 @@ package im.status.keycard.connect.ui import android.app.Activity import android.content.Intent -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.EditText +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.data.* import java.util.* diff --git a/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt index 9b7a932..91497f3 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/MainActivity.kt @@ -1,20 +1,20 @@ package im.status.keycard.connect.ui import android.app.Activity +import android.content.Intent import android.nfc.NfcAdapter import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import android.content.Intent import android.view.LayoutInflater import android.view.View import android.widget.ViewSwitcher +import androidx.appcompat.app.AppCompatActivity +import com.google.zxing.client.android.Intents import com.google.zxing.integration.android.IntentIntegrator import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.card.* -import kotlin.reflect.KClass -import com.google.zxing.client.android.Intents import im.status.keycard.connect.data.* +import kotlin.reflect.KClass class MainActivity : AppCompatActivity(), ScriptListener { private lateinit var viewSwitcher: ViewSwitcher diff --git a/app/src/main/java/im/status/keycard/connect/ui/PINActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/PINActivity.kt index 5f0b5b2..08ed061 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/PINActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/PINActivity.kt @@ -1,11 +1,11 @@ package im.status.keycard.connect.ui import android.app.Activity -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.EditText import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.data.PIN_ACTIVITY_ATTEMPTS diff --git a/app/src/main/java/im/status/keycard/connect/ui/PUKActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/PUKActivity.kt index bc06825..3f63cb5 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/PUKActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/PUKActivity.kt @@ -1,11 +1,11 @@ package im.status.keycard.connect.ui import android.app.Activity -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.EditText import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.data.PUK_ACTIVITY_ATTEMPTS diff --git a/app/src/main/java/im/status/keycard/connect/ui/PairingActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/PairingActivity.kt index 4039ecc..c036be8 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/PairingActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/PairingActivity.kt @@ -1,11 +1,11 @@ package im.status.keycard.connect.ui import android.app.Activity -import androidx.appcompat.app.AppCompatActivity +import android.content.Intent import android.os.Bundle import android.view.View import android.widget.EditText -import android.content.Intent +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.data.PAIRING_ACTIVITY_PASSWORD diff --git a/app/src/main/java/im/status/keycard/connect/ui/ReinstallActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/ReinstallActivity.kt index df2f38e..f11576b 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/ReinstallActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/ReinstallActivity.kt @@ -1,10 +1,10 @@ package im.status.keycard.connect.ui import android.content.Intent -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.CheckBox +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.card.ReinstallCommand diff --git a/app/src/main/java/im/status/keycard/connect/ui/SettingsActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/SettingsActivity.kt index 872ef5c..5bd2c15 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/SettingsActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/SettingsActivity.kt @@ -1,11 +1,11 @@ package im.status.keycard.connect.ui -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.ArrayAdapter import android.widget.EditText import android.widget.Spinner +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.data.CHAIN_IDS diff --git a/app/src/main/java/im/status/keycard/connect/ui/ShowMnemonicActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/ShowMnemonicActivity.kt index d22b8e4..720b015 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/ShowMnemonicActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/ShowMnemonicActivity.kt @@ -1,9 +1,9 @@ package im.status.keycard.connect.ui -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.data.MNEMONIC_PHRASE diff --git a/app/src/main/java/im/status/keycard/connect/ui/SignMessageActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/SignMessageActivity.kt index 2ddf8c3..e23f158 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/SignMessageActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/SignMessageActivity.kt @@ -1,10 +1,10 @@ package im.status.keycard.connect.ui import android.app.Activity -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.data.SIGN_TEXT_MESSAGE diff --git a/app/src/main/java/im/status/keycard/connect/ui/SignTransactionActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/SignTransactionActivity.kt index 20cf4b6..8efbbb6 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/SignTransactionActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/SignTransactionActivity.kt @@ -1,10 +1,10 @@ package im.status.keycard.connect.ui import android.app.Activity -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import im.status.keycard.connect.R import im.status.keycard.connect.data.SIGN_TX_AMOUNT import im.status.keycard.connect.data.SIGN_TX_CURRENCY From 85fdae61542420f083397f429578e4f824e59d52 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 12 Oct 2020 14:45:41 +0200 Subject: [PATCH 02/13] support EIP-712 tx --- README.md | 2 +- app/build.gradle | 2 ++ .../keycard/connect/net/WalletConnect.kt | 22 ++++++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1ff0885..e21682b 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ At the moment all dApps tested worked fine. The implemented functions are: * eth_sendRawTransaction * eth_signTransaction * eth_sign +* eth_signTypedData * personal_sign ### Seed management @@ -36,7 +37,6 @@ At the moment all dApps tested worked fine. The implemented functions are: * allow switching account (BIP32 path) on card and used network (for WalletConnect) ## What needs to be done for 1.0 -* implement signedTypedData (WalletConnect integration) * design and implement a user-friendly UI ## Future plans (after 1.0) diff --git a/app/build.gradle b/app/build.gradle index a63f48e..109ce9c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -68,6 +68,8 @@ dependencies { implementation "com.github.komputing.kethereum:extensions_kotlin:$kethereum_version" implementation "com.github.komputing.kethereum:keccak_shortcut:$kethereum_version" implementation 'com.github.komputing:khex:1.0.0' + implementation 'com.github.gnosis.svalinn-kotlin:eip712-adapter-moshi:v0.13.0' + implementation 'com.github.gnosis.svalinn-kotlin:eip712:v0.13.0' testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' diff --git a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt index 47b2ce9..003e596 100644 --- a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt +++ b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt @@ -39,7 +39,11 @@ import org.walletconnect.impls.FileWCSessionStore import org.walletconnect.impls.MoshiPayloadAdapter import org.walletconnect.impls.OkHttpTransport import org.walletconnect.impls.WCSession +import pm.gnosis.eip712.EIP712JsonParser +import pm.gnosis.eip712.adapters.moshi.MoshiAdapter +import pm.gnosis.eip712.typedDataHash import java.io.File +import kotlin.reflect.typeOf class WalletConnect(var bip32Path: String, var chainID: Long) : ExportKeyCommand.Listener, SignCommand.Listener, Session.Callback { @@ -91,7 +95,7 @@ class WalletConnect(var bip32Path: String, var chainID: Long) : ExportKeyCommand private fun onCustomCall(call: Session.MethodCall.Custom) { when(call.method) { "personal_sign" -> runOnValidParam(call, 0) { signText(call.id, it) } - "eth_signTypedData" -> { runOnValidParam>(call, 1) { @Suppress("UNCHECKED_CAST") signTypedData(call.id, it as Map) } } + "eth_signTypedData" -> { runOnValidParam(call, 1) { @Suppress("UNCHECKED_CAST") signTypedData(call.id, it) } } "eth_signTransaction" -> { runOnValidParam>(call, 0) { signTransaction(call.id, toTransaction(toSendTransaction(call.id, it)), false)} } "eth_sendRawTransaction" -> { runOnValidParam(call, 0) { relayTX(call.id, it) } } else -> session?.rejectRequest(call.id, 1L, "Not implemented") @@ -140,9 +144,21 @@ class WalletConnect(var bip32Path: String, var chainID: Long) : ExportKeyCommand Registry.mainActivity.startActivityForResult(intent, REQ_WALLETCONNECT) } - private fun signTypedData(id: Long, message: Map) { + private fun signTypedData(id: Long, message: String) { requestId = id - session?.rejectRequest(id, 1L, "Not implemented yet") + uiAction = { + val domainWithMessage = EIP712JsonParser(MoshiAdapter()).parseMessage(message) + val hash = typedDataHash(domainWithMessage.message, domainWithMessage.domain) + Registry.scriptExecutor.runScript(scriptWithAuthentication().plus(SignCommand(Registry.walletConnect, hash))) + } + + signAction = { session?.approveRequest(requestId, "0x${it.r.toNoPrefixHexString()}${it.s.toNoPrefixHexString()}${encode((it.recId + 27).toByte())}") } + + val intent = Intent(Registry.mainActivity, SignMessageActivity::class.java).apply { + putExtra(SIGN_TEXT_MESSAGE, message) + } + + Registry.mainActivity.startActivityForResult(intent, REQ_WALLETCONNECT) } private fun signTransaction(id: Long, tx: Transaction, send: Boolean) { From 916f6940c5bd5d413b42d89dcd3ebac7e8c04295 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 12 Oct 2020 14:50:24 +0200 Subject: [PATCH 03/13] remove unused import --- app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt index 003e596..e4f5062 100644 --- a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt +++ b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt @@ -43,7 +43,6 @@ import pm.gnosis.eip712.EIP712JsonParser import pm.gnosis.eip712.adapters.moshi.MoshiAdapter import pm.gnosis.eip712.typedDataHash import java.io.File -import kotlin.reflect.typeOf class WalletConnect(var bip32Path: String, var chainID: Long) : ExportKeyCommand.Listener, SignCommand.Listener, Session.Callback { From 5f658eb049b3764cd08eed80dfe83879f713572a Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Tue, 13 Oct 2020 10:17:09 +0200 Subject: [PATCH 04/13] add PIN/PUK/pairing validation/confirmation --- README.md | 2 +- .../status/keycard/connect/data/PINUtils.kt | 4 ++++ .../status/keycard/connect/net/EthereumRPC.kt | 2 +- .../keycard/connect/ui/ChangePINActivity.kt | 16 ++++++++++++- .../keycard/connect/ui/ChangePUKActivity.kt | 16 ++++++++++++- .../ui/ChangePairingPasswordActivity.kt | 16 ++++++++++++- .../activity_change_pairing_password.xml | 20 +++++++++++++--- .../main/res/layout/activity_change_pin.xml | 19 ++++++++++++--- .../main/res/layout/activity_change_puk.xml | 23 +++++++++++++++---- build.gradle | 2 +- 10 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/im/status/keycard/connect/data/PINUtils.kt diff --git a/README.md b/README.md index e21682b..714807e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **NOTE**: _This app is a prototype. While it seems to work reasonably well and stable, the UI has not received any thought yet. It is fine to use but keep in mind that there isn't much error reporting, no progress indicators and some screens are crammed with info_ -Keycard Connect's main function is to enable using the Keycard with dApps outside of a web3 browser using WalletConnect. The dApp must of course support WalletConnect for this to work. Additionally, this app is a little toolbox for Keycardm allowing things like changing PIN, initializing cards, changing seed etc. +Keycard Connect's main function is to enable using the Keycard with dApps outside of a web3 browser using WalletConnect. The dApp must of course support WalletConnect for this to work. Additionally, this app is a little toolbox for Keycard, allowing things like changing PIN, initializing cards, changing seed etc. ## What works diff --git a/app/src/main/java/im/status/keycard/connect/data/PINUtils.kt b/app/src/main/java/im/status/keycard/connect/data/PINUtils.kt new file mode 100644 index 0000000..b11c7e1 --- /dev/null +++ b/app/src/main/java/im/status/keycard/connect/data/PINUtils.kt @@ -0,0 +1,4 @@ +package im.status.keycard.connect.data + +fun isValidPIN(pin: String) : Boolean = pin.length == 6 && pin.all { it.isDigit() } +fun isValidPUK(puk: String) : Boolean = puk.length == 12 && puk.all { it.isDigit() } diff --git a/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt b/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt index 0a52027..a9db78d 100644 --- a/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt +++ b/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt @@ -18,7 +18,7 @@ class EthereumRPC(endpointURL: String) { init { val moshi = Moshi.Builder().build() val type: Type = Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java) - ethplorerJSONAdapter = moshi.adapter>(type) + ethplorerJSONAdapter = moshi.adapter(type) } fun changeEndpoint(endpointURL: String) { diff --git a/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt index c2f458c..c056ca3 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt @@ -2,18 +2,25 @@ package im.status.keycard.connect.ui import android.os.Bundle import android.view.View +import android.widget.Button import android.widget.EditText import androidx.appcompat.app.AppCompatActivity +import androidx.core.widget.doAfterTextChanged import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.card.ChangePINCommand import im.status.keycard.connect.card.scriptWithAuthentication +import im.status.keycard.connect.data.isValidPIN class ChangePINActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { - //TODO: pin validation and confirmation super.onCreate(savedInstanceState) setContentView(R.layout.activity_change_pin) + + val pinText = findViewById(R.id.newPINText) + val pinConfirmation = findViewById(R.id.pinConfirmation) + pinText.doAfterTextChanged { validatePIN() } + pinConfirmation.doAfterTextChanged { validatePIN() } } fun ok(@Suppress("UNUSED_PARAMETER") view: View) { @@ -26,4 +33,11 @@ class ChangePINActivity : AppCompatActivity() { fun cancel(@Suppress("UNUSED_PARAMETER") view: View) { finish() } + + private fun validatePIN() { + val pinText = findViewById(R.id.newPINText).text.toString() + val pinConfirmation = findViewById(R.id.pinConfirmation).text.toString() + val button = findViewById