Updated on 2026-08-14
This commit is contained in:
parent
cbfc4de67b
commit
7ba040e317
5 changed files with 29 additions and 16 deletions
|
|
@ -39,7 +39,6 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.security.NoSuchProviderException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.CompletableObserver;
|
||||
import io.reactivex.SingleObserver;
|
||||
|
|
@ -425,8 +424,6 @@ public class BtcCashEngine extends CoinEngine {
|
|||
@Override
|
||||
public byte[][] getHashesToSign() throws Exception {
|
||||
byte[][] dataForSign = new byte[unspentOutputs.size()][];
|
||||
if (txForSign.length > 10)
|
||||
throw new Exception("To much hashes in one transaction!");
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
dataForSign[i] = bodyDoubleHash[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -517,8 +517,6 @@ public class BtcEngine extends CoinEngine {
|
|||
@Override
|
||||
public byte[][] getHashesToSign() throws Exception {
|
||||
byte[][] dataForSign = new byte[unspentOutputs.size()][];
|
||||
if (txForSign.length > 10)
|
||||
throw new Exception("To much hashes in one transaction!");
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
dataForSign[i] = bodyDoubleHash[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,9 @@ import android.util.Log;
|
|||
|
||||
import com.tangem.App;
|
||||
import com.tangem.data.network.ServerApiBitcore;
|
||||
import com.tangem.data.network.ServerApiInsight;
|
||||
import com.tangem.data.network.model.BitcoreBalanceAndUnspents;
|
||||
import com.tangem.data.network.model.BitcoreSendResponse;
|
||||
import com.tangem.data.network.model.BitcoreUtxo;
|
||||
import com.tangem.data.network.model.InsightResponse;
|
||||
import com.tangem.data.network.model.InsightUtxo;
|
||||
import com.tangem.tangem_card.data.TangemCard;
|
||||
import com.tangem.tangem_card.reader.CardProtocol;
|
||||
import com.tangem.tangem_card.tasks.SignTask;
|
||||
|
|
@ -39,7 +36,6 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.security.NoSuchProviderException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.SingleObserver;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
|
|
@ -449,8 +445,6 @@ public class DucatusEngine extends BtcEngine {
|
|||
@Override
|
||||
public byte[][] getHashesToSign() throws Exception {
|
||||
byte[][] dataForSign = new byte[unspentOutputs.size()][];
|
||||
if (txForSign.length > 10)
|
||||
throw new Exception("To much hashes in one transaction!");
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
dataForSign[i] = bodyDoubleHash[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -450,8 +450,6 @@ public class LtcEngine extends BtcEngine {
|
|||
@Override
|
||||
public byte[][] getHashesToSign() throws Exception {
|
||||
byte[][] dataForSign = new byte[unspentOutputs.size()][];
|
||||
if (txForSign.length > 10)
|
||||
throw new Exception("To much hashes in one transaction!");
|
||||
for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
dataForSign[i] = bodyDoubleHash[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import java.io.ByteArrayOutputStream;
|
|||
public class SignTask extends CustomReadCardTask {
|
||||
public static final String TAG = SignTask.class.getSimpleName();
|
||||
|
||||
private static final int MAX_HASHES_TO_SIGN = 10;
|
||||
|
||||
/**
|
||||
* Transaction Engine request/notifications during sign process
|
||||
*/
|
||||
|
|
@ -58,13 +60,31 @@ public class SignTask extends CustomReadCardTask {
|
|||
TLVList signResult;
|
||||
switch (mCard.getSigningMethod()) {
|
||||
case Sign_Hash:
|
||||
signResult = protocol.run_SignHashes(pinsProvider.getPIN2(), transactionToSign.getHashesToSign(), null, null, null);
|
||||
break;
|
||||
byte[][] remainingHashes = transactionToSign.getHashesToSign();
|
||||
ByteArrayOutputStream signatures = new ByteArrayOutputStream();
|
||||
while (remainingHashes.length > 0) {
|
||||
byte[][] hashesToSign;
|
||||
if (remainingHashes.length <= MAX_HASHES_TO_SIGN) {
|
||||
hashesToSign = remainingHashes.clone();
|
||||
remainingHashes = new byte[0][];
|
||||
} else {
|
||||
hashesToSign = new byte[MAX_HASHES_TO_SIGN][];
|
||||
System.arraycopy(remainingHashes, 0, hashesToSign, 0, MAX_HASHES_TO_SIGN);
|
||||
remainingHashes = removeFirstTenEntries(remainingHashes);
|
||||
}
|
||||
|
||||
signResult = protocol.run_SignHashes(pinsProvider.getPIN2(), hashesToSign, null, null, null);
|
||||
signatures.write(signResult.getTLV(TLV.Tag.TAG_Signature).Value);
|
||||
}
|
||||
mNotifications.onReadProgress(protocol, 100);
|
||||
transactionToSign.onSignCompleted(signatures.toByteArray());
|
||||
return;
|
||||
|
||||
case Sign_Hash_Validated_By_Issuer:
|
||||
case Sign_Hash_Validated_By_Issuer_And_WriteIssuerData:
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
byte[][] hashes = transactionToSign.getHashesToSign();
|
||||
if (hashes.length > 10) throw new CardProtocol.TangemException("To much hashes in one transaction!");
|
||||
if (hashes.length > MAX_HASHES_TO_SIGN) throw new CardProtocol.TangemException("To much hashes in one transaction!");
|
||||
for (int i = 0; i < hashes.length; i++) {
|
||||
if (i != 0 && hashes[0].length != hashes[i].length)
|
||||
throw new CardProtocol.TangemException("Hashes length must be identical!");
|
||||
|
|
@ -89,4 +109,10 @@ public class SignTask extends CustomReadCardTask {
|
|||
mNotifications.onReadProgress(protocol, 100);
|
||||
|
||||
}
|
||||
|
||||
private byte[][] removeFirstTenEntries(byte[][] array) {
|
||||
byte[][] temp = new byte[array.length - MAX_HASHES_TO_SIGN][];
|
||||
System.arraycopy(array, MAX_HASHES_TO_SIGN, temp, 0, temp.length);
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue