Activate the memo functionality in SendTransactionFragment.

The memo encryption was not working properly for two reasons, there is a number called nonce used to encrypt the memo and it has to be positive. The app was sometimes using a negative nonce which caused encryption problems. The second problem was that the nonce was being serialized as an hexadecimal but the node was expecting a decimal so it was not able to convert back the nonce from string to decimal.
master
Severiano Jaramillo 2019-01-15 11:08:15 -06:00
parent 98cfbbf90a
commit 33f45a6775
3 changed files with 29 additions and 18 deletions

View File

@ -30,6 +30,7 @@ import cy.agorise.graphenej.api.calls.BroadcastTransaction
import cy.agorise.graphenej.api.calls.GetAccountByName import cy.agorise.graphenej.api.calls.GetAccountByName
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties
import cy.agorise.graphenej.api.calls.GetRequiredFees import cy.agorise.graphenej.api.calls.GetRequiredFees
import cy.agorise.graphenej.crypto.SecureRandomGenerator
import cy.agorise.graphenej.models.AccountProperties import cy.agorise.graphenej.models.AccountProperties
import cy.agorise.graphenej.models.DynamicGlobalProperties import cy.agorise.graphenej.models.DynamicGlobalProperties
import cy.agorise.graphenej.models.JsonRpcResponse import cy.agorise.graphenej.models.JsonRpcResponse
@ -49,15 +50,22 @@ import java.util.concurrent.TimeUnit
import javax.crypto.AEADBadTagException import javax.crypto.AEADBadTagException
class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHandler { class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHandler {
private val TAG = this.javaClass.simpleName
companion object {
private const val TAG = "SendTransactionFragment"
/** The account used to send the fees */
private val FEE_ACCOUNT = UserAccount("1.2.390320", "agorise")
// Camera Permission // Camera Permission
private val REQUEST_CAMERA_PERMISSION = 1 private const val REQUEST_CAMERA_PERMISSION = 1
private val RESPONSE_GET_ACCOUNT_BY_NAME = 1 // Constants used to organize NetworkService requests
private val RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS = 2 private const val RESPONSE_GET_ACCOUNT_BY_NAME = 1
private val RESPONSE_GET_REQUIRED_FEES = 3 private const val RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS = 2
private val RESPONSE_BROADCAST_TRANSACTION = 4 private const val RESPONSE_GET_REQUIRED_FEES = 3
private const val RESPONSE_BROADCAST_TRANSACTION = 4
}
private var isCameraPreviewVisible = false private var isCameraPreviewVisible = false
private var isToAccountCorrect = false private var isToAccountCorrect = false
@ -350,7 +358,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
amount += nextItem.quantity * nextItem.price amount += nextItem.quantity * nextItem.price
} }
// TODO Improve pattern to account for different asset precisions // TODO Improve pattern to account for different asset precisions
val df = DecimalFormat("####.#####") val df = DecimalFormat("####.########")
df.roundingMode = RoundingMode.CEILING df.roundingMode = RoundingMode.CEILING
df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault()) df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault())
tietAmount.setText(df.format(amount)) tietAmount.setText(df.format(amount))
@ -415,15 +423,15 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
val privateKey = ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, wifKey).key.privKeyBytes) val privateKey = ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, wifKey).key.privKeyBytes)
// Add memo if exists TODO enable memo // Add memo if exists TODO enable memo
// val memoMsg = tietMemo.text.toString() val memoMsg = tietMemo.text.toString()
// if (memoMsg.isNotEmpty()) { if (memoMsg.isNotEmpty()) {
// val nonce = SecureRandomGenerator.getSecureRandom().nextLong().toBigInteger() val nonce = Math.abs(SecureRandomGenerator.getSecureRandom().nextLong()).toBigInteger()
// val encryptedMemo = Memo.encryptMessage(privateKey, destinationPublicKey!!, nonce, memoMsg) val encryptedMemo = Memo.encryptMessage(privateKey, destinationPublicKey!!, nonce, memoMsg)
// val from = Address(ECKey.fromPublicOnly(privateKey.pubKey)) val from = Address(ECKey.fromPublicOnly(privateKey.pubKey))
// val to = Address(destinationPublicKey!!.key) val to = Address(destinationPublicKey!!.key)
// val memo = Memo(from, to, nonce, encryptedMemo) val memo = Memo(from, to, nonce, encryptedMemo)
// operationBuilder.setMemo(memo) operationBuilder.setMemo(memo)
// } }
val operations = ArrayList<BaseOperation>() val operations = ArrayList<BaseOperation>()
operations.add(operationBuilder.build()) operations.add(operationBuilder.build())

View File

@ -23,6 +23,9 @@ object Constants {
/** The user selected encrypted PIN */ /** The user selected encrypted PIN */
const val KEY_ENCRYPTED_PIN = "key_encrypted_pin" const val KEY_ENCRYPTED_PIN = "key_encrypted_pin"
/** The fee to send in every transfer (0.01%) */
const val FEE_PERCENTAGE = 0.0001
/** /**
* LTM accounts come with an expiration date expressed as this string. * LTM accounts come with an expiration date expressed as this string.
* This is used to recognize such accounts from regular ones. * This is used to recognize such accounts from regular ones.

@ -1 +1 @@
Subproject commit 13faf6c25369d047037b639f4b838220ace916b3 Subproject commit 4c7c7b29b2d403e8f44a2a955e0ba22169d02a48