Commit 92ea9689 authored by pokkst's avatar pokkst

Ability to sweep and/or import BIP38 private keys

parent 5c8966f9
No preview for this file type
......@@ -37,6 +37,7 @@ class AdvancedSettingsActivity : AppCompatActivity() {
if (Constants.ACTION_CLEAR_SWEEP_TEXT == intent.action) {
this@AdvancedSettingsActivity.privKeyText.text = null
this@AdvancedSettingsActivity.bip38PrivateKeyPassword.text = null
this@AdvancedSettingsActivity.bip38Layout.visibility = View.GONE
}
}
}
......@@ -138,12 +139,12 @@ class AdvancedSettingsActivity : AppCompatActivity() {
if (data != null) {
val scanData = data.getStringExtra(Constants.QR_SCAN_RESULT)
if (scanData != null) {
println("IN ACTIVITY RESULT")
if(!WalletManager.isEncryptedBIP38Key(scanData)) {
privKeyText.setText(scanData)
this.privKeyText.setText(scanData)
this.bip38Layout.visibility = View.GONE
} else {
bip38Layout.visibility = View.VISIBLE
privKeyText.setText(scanData)
this.bip38Layout.visibility = View.VISIBLE
this.privKeyText.setText(scanData)
}
}
}
......
......@@ -22,6 +22,7 @@ import app.crescentcash.src.utils.Constants
import app.crescentcash.src.utils.PrefsUtil
import org.bitcoinj.core.CashAddressFactory
import org.bitcoinj.core.ECKey
import org.bitcoinj.crypto.BIP38PrivateKey
import java.util.*
import kotlin.collections.set
......@@ -31,6 +32,8 @@ class KeysListActivity : AppCompatActivity() {
lateinit var keyToImportText: EditText
private lateinit var btnImportKey: Button
private lateinit var btnImportKeyScan: ImageView
lateinit var bip38ImportKeyPassword: EditText
lateinit var bip38ImportLayout: LinearLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -51,6 +54,8 @@ class KeysListActivity : AppCompatActivity() {
keyToImportText = this.findViewById(R.id.keyToImportText)
btnImportKey = this.findViewById(R.id.btnImportKey)
btnImportKeyScan = this.findViewById(R.id.btnImportKeyScan)
bip38ImportKeyPassword = this.findViewById(R.id.bip38ImportKeyPassword)
bip38ImportLayout = this.findViewById(R.id.bip38ImportLayout)
}
private fun initListeners() {
......@@ -62,10 +67,37 @@ class KeysListActivity : AppCompatActivity() {
UIManager.startActivity(this, ManageKeyActivity::class.java)
}
this.btnImportKey.setOnClickListener {
if (!TextUtils.isEmpty(keyToImportText.text.toString())) {
WalletManager.importPrivateKey(keyToImportText.text.toString())
keyToImportText.text = null
refreshKeys()
val privKey = this.keyToImportText.text.toString()
if (!TextUtils.isEmpty(privKey)) {
if (!WalletManager.isEncryptedBIP38Key(privKey)) {
WalletManager.importPrivateKey(privKey)
UIManager.showToastMessage(this, "Imported key!")
this.keyToImportText.text = null
this.bip38ImportLayout.visibility = View.GONE
refreshKeys()
} else {
if(this.bip38ImportLayout.visibility == View.GONE) {
this.bip38ImportLayout.visibility = View.VISIBLE
} else {
val bip38Password = this.bip38ImportKeyPassword.text.toString()
if(!TextUtils.isEmpty(bip38Password)) {
val encryptedKey = BIP38PrivateKey.fromBase58(WalletManager.parameters, privKey)
try {
val ecKey = encryptedKey.decrypt(bip38Password)
WalletManager.importPrivateKey(ecKey.getPrivateKeyAsWiF(WalletManager.parameters))
UIManager.showToastMessage(this, "Imported key!")
this.keyToImportText.text = null
this.bip38ImportKeyPassword.text = null
this.bip38ImportLayout.visibility = View.GONE
refreshKeys()
} catch (e: BIP38PrivateKey.BadPassphraseException) {
UIManager.showToastMessage(this, "Incorrect password!")
}
} else {
UIManager.showToastMessage(this, "Please enter a password!")
}
}
}
}
}
this.keysList.setOnItemLongClickListener { parent, view, position, id ->
......@@ -179,7 +211,14 @@ class KeysListActivity : AppCompatActivity() {
val scanData = data.getStringExtra(Constants.QR_SCAN_RESULT)
if (scanData != null) {
if (requestCode == Constants.REQUEST_CODE_IMPORT_SCAN) {
this.keyToImportText.setText(scanData)
if(!WalletManager.isEncryptedBIP38Key(scanData)) {
this.keyToImportText.setText(scanData)
this.bip38ImportLayout.visibility = View.GONE
} else {
bip38ImportLayout.visibility = View.VISIBLE
this.keyToImportText.setText(scanData)
}
}
}
}
......
......@@ -122,7 +122,6 @@ class SendActivity : AppCompatActivity() {
WalletManager.send(this@SendActivity)
}
}
this.btnSend_AM.onSlideCompleteListener = slideBCHListener
val listener: RecipientTextListener = object : RecipientTextListener {
override fun onUpdate() {
......@@ -132,10 +131,8 @@ class SendActivity : AppCompatActivity() {
processScanOrPaste(clipboardText)
}
}
this.setMaxCoins.setOnClickListener { setMaxCoins() }
this.contactsBtn.setOnClickListener { showContactSelectionScreen() }
this.tvRecipientAddress_AM.addListener(listener)
this.donateBtn.setOnClickListener { this.displayRecipientAddress(Constants.DONATION_ADDRESS) }
this.qrScan.setOnClickListener { UIManager.clickScanQR(this, Constants.REQUEST_CODE_SCAN_PAY_TO) }
......
......@@ -362,7 +362,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
......
......@@ -73,6 +73,51 @@
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="10dp" />
<LinearLayout
android:id="@+id/bip38ImportLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/bip38ImportKeyPassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/circle_button"
android:backgroundTint="?attr/textboxOnWhite"
android:hint="Password"
android:inputType="textPassword"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textColorHint="?attr/textHintOnWhite"
android:textCursorDrawable="@null"
android:textSize="14sp" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="10dp" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment