Updated on 2026-08-14
This commit is contained in:
parent
44f8632409
commit
1c45b2980f
6 changed files with 67 additions and 78 deletions
|
|
@ -15,7 +15,7 @@ android {
|
|||
applicationId "com.tangem.wallet"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode 57
|
||||
versionCode 58
|
||||
versionName "0.88.1." + generateVersionName()
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,33 +6,41 @@ public class BalanceValidator {
|
|||
private String firstLine;
|
||||
private String secondLine;
|
||||
private int score;
|
||||
public String GetFirstLine()
|
||||
{
|
||||
|
||||
public String getFirstLine() {
|
||||
return firstLine;
|
||||
}
|
||||
public String GetSecondLine()
|
||||
{
|
||||
if (score>89) { return "Safe to accept. " + secondLine;}
|
||||
else if (score>74) { return "Not fully safe to accept. " + secondLine;}
|
||||
else if (score>30) { return "Not safe to accept. " + secondLine;}
|
||||
else { return "Do not accept! " + secondLine;}
|
||||
}
|
||||
public int GetColor() {
|
||||
if (score>89) { return R.color.confirmed;}
|
||||
else if (score>74) { return android.R.color.holo_orange_light;}
|
||||
else if (score>0) { return android.R.color.holo_orange_dark;}
|
||||
else { return android.R.color.holo_red_light;}
|
||||
|
||||
public String getSecondLine() {
|
||||
if (score > 89) {
|
||||
return "Safe to accept. " + secondLine;
|
||||
} else if (score > 74) {
|
||||
return "Not fully safe to accept. " + secondLine;
|
||||
} else if (score > 30) {
|
||||
return "Not safe to accept. " + secondLine;
|
||||
} else {
|
||||
return "Do not accept! " + secondLine;
|
||||
}
|
||||
}
|
||||
|
||||
public void Check(TangemCard card)
|
||||
{
|
||||
|
||||
public int getColor() {
|
||||
if (score > 89) {
|
||||
return R.color.confirmed;
|
||||
} else if (score > 74) {
|
||||
return android.R.color.holo_orange_light;
|
||||
} else if (score > 0) {
|
||||
return android.R.color.holo_orange_dark;
|
||||
} else {
|
||||
return android.R.color.holo_red_light;
|
||||
}
|
||||
}
|
||||
|
||||
public void Check(TangemCard card) {
|
||||
firstLine = "Verification failed";
|
||||
secondLine = "";
|
||||
|
||||
// rule 1
|
||||
if((!CheckOfflineBalance(card) && !CheckOnlineBalance(card)) || (!CheckOnlineBalance(card) && HasEverSigned(card))) {
|
||||
if ((!CheckOfflineBalance(card) && !CheckOnlineBalance(card)) || (!CheckOnlineBalance(card) && HasEverSigned(card))) {
|
||||
score = 0;
|
||||
firstLine = "Unknown balance";
|
||||
secondLine = "Balance cannot be verified. Swipe down to refresh.";
|
||||
|
|
@ -48,7 +56,7 @@ public class BalanceValidator {
|
|||
// }
|
||||
|
||||
// rule 2.a
|
||||
if(!VerificationWalletKey(card)) {
|
||||
if (!VerificationWalletKey(card)) {
|
||||
score = 0;
|
||||
firstLine = "Verification failed";
|
||||
secondLine = "Wallet verification failed. Tap again.";
|
||||
|
|
@ -56,7 +64,7 @@ public class BalanceValidator {
|
|||
}
|
||||
|
||||
// rule 2.c
|
||||
if(!CheckAttestationServiceResult(card) && CheckAttestationServiceAvailable(card)) {
|
||||
if (!CheckAttestationServiceResult(card) && CheckAttestationServiceAvailable(card)) {
|
||||
score = 0;
|
||||
firstLine = "Not genuine banknote";
|
||||
secondLine = "Tangem Attestation service says the banknote is not genuine.";
|
||||
|
|
@ -64,8 +72,7 @@ public class BalanceValidator {
|
|||
}
|
||||
|
||||
// rule 6
|
||||
if(NotConfirmTransaction(card))
|
||||
{
|
||||
if (NotConfirmTransaction(card)) {
|
||||
score = 0;
|
||||
firstLine = "Unguaranted balance";
|
||||
secondLine = "Loading in progress. Wait for full confirmation in blockchain. ";
|
||||
|
|
@ -73,8 +80,7 @@ public class BalanceValidator {
|
|||
}
|
||||
|
||||
// rule 5
|
||||
if(!isCodeConfirmed(card))
|
||||
{
|
||||
if (!isCodeConfirmed(card)) {
|
||||
score = 0;
|
||||
firstLine = "Not genuine banknote";
|
||||
secondLine = "Firmware binary code verification failed";
|
||||
|
|
@ -82,19 +88,18 @@ public class BalanceValidator {
|
|||
}
|
||||
|
||||
// rule 5
|
||||
if(card.PIN2 == TangemCard.PIN2_Mode.CustomPIN2)
|
||||
{
|
||||
if (card.PIN2 == TangemCard.PIN2_Mode.CustomPIN2) {
|
||||
score = 0;
|
||||
firstLine = "Locked with PIN2";
|
||||
secondLine = "Ask the holder to disable PIN2 before accepting";
|
||||
return;
|
||||
}
|
||||
|
||||
if(card.isBalanceReceived() && card.isBalanceEqual()) {
|
||||
if (card.isBalanceReceived() && card.isBalanceEqual()) {
|
||||
score = 100;
|
||||
firstLine = "Verified balance";
|
||||
secondLine = "Balance confirmed in blockchain. ";
|
||||
if(card.getBalance() == 0) {
|
||||
if (card.getBalance() == 0) {
|
||||
firstLine = "";
|
||||
}
|
||||
}
|
||||
|
|
@ -109,16 +114,14 @@ public class BalanceValidator {
|
|||
// }
|
||||
|
||||
// rule 7
|
||||
if(CheckOfflineBalance(card) && !CheckOnlineBalance(card) && !HasEverSigned(card) && card.getBalance() != 0)
|
||||
{
|
||||
if (CheckOfflineBalance(card) && !CheckOnlineBalance(card) && !HasEverSigned(card) && card.getBalance() != 0) {
|
||||
score = 80;
|
||||
firstLine = "Verified offline balance";
|
||||
secondLine = "Can't obtain balance from blockchain. Restore internet connection to be more confident. ";
|
||||
}
|
||||
|
||||
// rule 2.b
|
||||
if(CheckAttestationServiceAvailable(card))
|
||||
{
|
||||
if (CheckAttestationServiceAvailable(card)) {
|
||||
secondLine += "Verified note identity. ";
|
||||
} else {
|
||||
score = 80;
|
||||
|
|
@ -143,44 +146,36 @@ public class BalanceValidator {
|
|||
|
||||
}
|
||||
|
||||
boolean CheckOfflineBalance(TangemCard card)
|
||||
{
|
||||
boolean CheckOfflineBalance(TangemCard card) {
|
||||
return card.getOfflineBalance() != null;
|
||||
}
|
||||
|
||||
boolean CheckOnlineBalance(TangemCard card)
|
||||
{
|
||||
boolean CheckOnlineBalance(TangemCard card) {
|
||||
return card.isBalanceReceived();
|
||||
}
|
||||
|
||||
boolean VerificationWalletKey(TangemCard card)
|
||||
{
|
||||
boolean VerificationWalletKey(TangemCard card) {
|
||||
return card.isWalletPublicKeyValid();
|
||||
}
|
||||
|
||||
boolean HasEverSigned(TangemCard card)
|
||||
{
|
||||
boolean HasEverSigned(TangemCard card) {
|
||||
// return card.getSignedHashes() != 0 || card.getRemainingSignatures() != card.getMaxSignatures();
|
||||
return card.getRemainingSignatures() != card.getMaxSignatures();
|
||||
}
|
||||
|
||||
boolean CheckAttestationServiceAvailable(TangemCard card)
|
||||
{
|
||||
boolean CheckAttestationServiceAvailable(TangemCard card) {
|
||||
return card.isOnlineVerified() != null;
|
||||
}
|
||||
|
||||
boolean CheckAttestationServiceResult(TangemCard card)
|
||||
{
|
||||
boolean CheckAttestationServiceResult(TangemCard card) {
|
||||
return card.isOnlineVerified() != null && card.isOnlineVerified() == true;
|
||||
}
|
||||
|
||||
boolean NotConfirmTransaction(TangemCard card)
|
||||
{
|
||||
return card.getBalanceUnconfirmed()!=0;
|
||||
boolean NotConfirmTransaction(TangemCard card) {
|
||||
return card.getBalanceUnconfirmed() != 0;
|
||||
}
|
||||
|
||||
boolean isCodeConfirmed(TangemCard card)
|
||||
{
|
||||
boolean isCodeConfirmed(TangemCard card) {
|
||||
return card.isCodeConfirmed() == null || card.isCodeConfirmed();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.domain.wallet;
|
||||
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.util.BTCUtils;
|
||||
|
|
@ -28,7 +27,7 @@ public class EthTransaction {
|
|||
byte[] receiveAddress;
|
||||
byte[] value;
|
||||
byte[] data;
|
||||
Integer chainId;
|
||||
Integer chainId;
|
||||
byte[] rlpRaw;
|
||||
public ECDSASignatureETH signature;
|
||||
byte[] rlpEncoded;
|
||||
|
|
@ -36,8 +35,7 @@ public class EthTransaction {
|
|||
private static final int CHAIN_ID_INC = 35;
|
||||
private static final int LOWER_REAL_V = 27;
|
||||
|
||||
public static EthTransaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice,
|
||||
BigInteger gasLimit, Integer chainId){
|
||||
public static EthTransaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, Integer chainId) {
|
||||
return new EthTransaction(BigIntegers.asUnsignedByteArray(nonce),
|
||||
BigIntegers.asUnsignedByteArray(gasPrice),
|
||||
BigIntegers.asUnsignedByteArray(gasLimit),
|
||||
|
|
@ -47,9 +45,7 @@ public class EthTransaction {
|
|||
chainId);
|
||||
}
|
||||
|
||||
|
||||
public static EthTransaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice,
|
||||
BigInteger gasLimit, Integer chainId, byte[] data){
|
||||
public static EthTransaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, Integer chainId, byte[] data) {
|
||||
return new EthTransaction(BigIntegers.asUnsignedByteArray(nonce),
|
||||
BigIntegers.asUnsignedByteArray(gasPrice),
|
||||
BigIntegers.asUnsignedByteArray(gasLimit),
|
||||
|
|
@ -59,8 +55,7 @@ public class EthTransaction {
|
|||
chainId);
|
||||
}
|
||||
|
||||
public EthTransaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data,
|
||||
Integer chainId) {
|
||||
public EthTransaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data, Integer chainId) {
|
||||
this.nonce = nonce;
|
||||
this.gasPrice = gasPrice;
|
||||
this.gasLimit = gasLimit;
|
||||
|
|
@ -78,18 +73,17 @@ public class EthTransaction {
|
|||
}
|
||||
}
|
||||
|
||||
public enum ChainEnum
|
||||
{
|
||||
public enum ChainEnum {
|
||||
Mainnet(1),
|
||||
Morden(2),
|
||||
Ropsten(3),
|
||||
Rinkeby(4),
|
||||
Rootstock_mainnet(30),
|
||||
Rootstock_testnet (31),
|
||||
Kovan (42),
|
||||
Rootstock_testnet(31),
|
||||
Kovan(42),
|
||||
Ethereum_Classic_mainnet(61),
|
||||
Ethereum_Classic_testnet(62),
|
||||
Geth_private_chains (1337);
|
||||
Geth_private_chains(1337);
|
||||
|
||||
private int value;
|
||||
|
||||
|
|
@ -116,39 +110,36 @@ public class EthTransaction {
|
|||
return kec.digest(plainMsg);
|
||||
}
|
||||
|
||||
public int BruteRecoveryID2(ECDSASignatureETH sig, byte[] messageHash, byte[] thisKey)
|
||||
{
|
||||
public int BruteRecoveryID2(ECDSASignatureETH sig, byte[] messageHash, byte[] thisKey) {
|
||||
Log.e("ETH_KZ", BTCUtils.toHex(thisKey));
|
||||
int recId = -1;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
byte[] recK = CryptoUtil.recoverPubBytesFromSignature(i, sig, messageHash);
|
||||
|
||||
if(recK == null)
|
||||
{
|
||||
if (recK == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Log.e("ETH_k "+String.valueOf(i), BTCUtils.toHex(recK));
|
||||
Log.e("ETH_k " + String.valueOf(i), BTCUtils.toHex(recK));
|
||||
if (Arrays.equals(recK, thisKey)) {
|
||||
recId = i;
|
||||
recId +=27;
|
||||
recId += 27;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return recId;
|
||||
}
|
||||
|
||||
public int BruteRecoveryID(ECKey.ECDSASignature sig, Sha256Hash messageHash, byte[] thisKey)
|
||||
{
|
||||
public int BruteRecoveryID(ECKey.ECDSASignature sig, Sha256Hash messageHash, byte[] thisKey) {
|
||||
Log.e("ETH_KZ", BTCUtils.toHex(thisKey));
|
||||
int recId = -1;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ECKey k = ECKey.recoverFromSignature(i, sig, messageHash, false);
|
||||
|
||||
if(k == null)
|
||||
if (k == null)
|
||||
continue;
|
||||
byte[] recK = k.getPubKey();
|
||||
Log.e("ETH_k "+String.valueOf(i), BTCUtils.toHex(recK));
|
||||
Log.e("ETH_k " + String.valueOf(i), BTCUtils.toHex(recK));
|
||||
if (k != null && Arrays.equals(recK, thisKey)) {
|
||||
recId = i;
|
||||
break;
|
||||
|
|
@ -230,4 +221,5 @@ public class EthTransaction {
|
|||
}
|
||||
return rlpRaw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1560,6 +1560,8 @@ public class TangemCard {
|
|||
return R.drawable.card_eth000;
|
||||
case "0017":
|
||||
return R.drawable.card_qlear200;
|
||||
case "0019":
|
||||
return R.drawable.card_cle100;
|
||||
default:
|
||||
return R.drawable.card_default;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -634,9 +634,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
val validator = BalanceValidator()
|
||||
validator.Check(card)
|
||||
tvBalanceLine1.text = validator.GetFirstLine()
|
||||
tvBalanceLine2.text = validator.GetSecondLine()
|
||||
tvBalanceLine1.setTextColor(ContextCompat.getColor(context!!, validator.GetColor()))
|
||||
tvBalanceLine1.text = validator.firstLine
|
||||
tvBalanceLine2.text = validator.secondLine
|
||||
tvBalanceLine1.setTextColor(ContextCompat.getColor(context!!, validator.color))
|
||||
}
|
||||
|
||||
if (engine!!.hasBalanceInfo(card) || card!!.offlineBalance == null) {
|
||||
|
|
|
|||
BIN
app/src/main/res/drawable/card_cle100.png
Normal file
BIN
app/src/main/res/drawable/card_cle100.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
Loading…
Add table
Add a link
Reference in a new issue