Updated on 2026-08-14

This commit is contained in:
Tangem 2018-12-07 17:38:02 +03:00
parent e1984e63aa
commit 4a27600ede
7 changed files with 397 additions and 101 deletions

6
.idea/kotlinc.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JsCompilerArguments">
<option name="sourceMapEmbedSources" />
</component>
</project>

View file

@ -124,11 +124,16 @@ public class ServerApiElectrum {
BitcoinCashNode bitcoinCashNode = BitcoinCashNode.values()[new Random().nextInt(BitcoinCashNode.values().length)]; BitcoinCashNode bitcoinCashNode = BitcoinCashNode.values()[new Random().nextInt(BitcoinCashNode.values().length)];
host = bitcoinCashNode.getHost(); host = bitcoinCashNode.getHost();
port = bitcoinCashNode.getPort(); port = bitcoinCashNode.getPort();
proto = bitcoinCashNode.getProto();
this.host = host; this.host = host;
this.port = port; this.port = port;
return doElectrumRequestTcp(electrumRequest, host, port); if (proto.equals("tcp")) {
return doElectrumRequestTcp(electrumRequest, host, port);
} else {
return doElectrumRequestSsl(electrumRequest, host, port);
}
} else if (card.getBlockchain() == Blockchain.Bitcoin) { } else if (card.getBlockchain() == Blockchain.Bitcoin) {
BitcoinNode bitcoinNode = BitcoinNode.values()[new Random().nextInt(BitcoinNode.values().length)]; BitcoinNode bitcoinNode = BitcoinNode.values()[new Random().nextInt(BitcoinNode.values().length)];
@ -136,15 +141,12 @@ public class ServerApiElectrum {
port = bitcoinNode.getPort(); port = bitcoinNode.getPort();
proto = bitcoinNode.getProto(); proto = bitcoinNode.getProto();
if (proto.equals("tcp")) { this.host = host;
this.host = host; this.port = port;
this.port = port;
if (proto.equals("tcp")) {
return doElectrumRequestTcp(electrumRequest, host, port); return doElectrumRequestTcp(electrumRequest, host, port);
} else { } else {
this.host = host;
this.port = port;
return doElectrumRequestSsl(electrumRequest, host, port); return doElectrumRequestSsl(electrumRequest, host, port);
} }
} }

View file

@ -0,0 +1,345 @@
package com.tangem.domain.wallet;
/**
* Created by Ilia on 29.09.2017.
*/
import android.util.Log;
import com.tangem.domain.wallet.btc.BitcoinException;
import com.tangem.domain.wallet.btc.BitcoinOutputStream;
import com.tangem.domain.wallet.btc.BtcData;
import com.tangem.util.CryptoUtil;
import com.tangem.util.FormatUtil;
import com.tangem.tangemcard.util.Util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings({"WeakerAccess", "TryWithIdenticalCatches", "unused"})
public final class BCHUtils {
static final BigInteger LARGEST_PRIVATE_KEY = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16);//SECP256K1_N
public static final long MIN_FEE_PER_KB = 10000;
public static final long MAX_ALLOWED_FEE = FormatUtil.parseValue("0.1");
public static final long MIN_PRIORITY_FOR_NO_FEE = 57600000;
public static final long MIN_MIN_OUTPUT_VALUE_FOR_NO_FEE = 10000000L;
public static final int MAX_TX_LEN_FOR_NO_FEE = 10000;
public static final float EXPECTED_BLOCKS_PER_DAY = 144.0f;//(expected confirmations per day)
public static String toHex(byte[] bytes) {
if (bytes == null) {
return "";
}
final char[] hexArray = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
char[] hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++) {
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
public static byte[] buildTXForSign(String myAddress, String outputAddress, String changeAddress, ArrayList<UnspentOutputInfo> unspentOutputs, int currentInputPos, long amount, long change) throws BitcoinException, IOException {
int inputPos = currentInputPos;
byte[] tx = buildPreimage(outputAddress, changeAddress, unspentOutputs, inputPos, amount, change);
return tx;
}
public static byte[] buildTXForSend(String outputAddress, String changeAddress, ArrayList<UnspentOutputInfo> unspentOutputs, long amount, long change) throws BitcoinException, IOException {
int inputPos = -1;
byte[] tx = buildBodyTX(outputAddress, changeAddress, unspentOutputs, inputPos, amount, change);
return tx;
}
//BIP 143 as reference + script length added
public static byte[] buildPreimage(String outputAddress, String changeAddress, ArrayList<UnspentOutputInfo> unspentOutputs, int inputPos, long amount, long change) throws BitcoinException, IOException {
//nVersion of the transaction (4-byte little endian)
BitcoinOutputStream forSign = new BitcoinOutputStream();
//forSign.writeInt32(0x01);
forSign.write(new byte[]{0x02, 0x00, 0x00, 0x00}); // version
//inputCount
byte inputCount = (byte) unspentOutputs.size();
//hashPrevouts (32-byte hash)
ByteArrayOutputStream prevouts = new ByteArrayOutputStream();
for (int i = 0; i < inputCount; ++i) {
UnspentOutputInfo outPut = unspentOutputs.get(i);
byte[] txHash = BCHUtils.reverse(Util.hexToBytes(outPut.txHashForBuild));//Little-endian txID
byte[] txIndex = BCHUtils.reverse(Util.intToByteArray4(outPut.outputIndex));//Little-endian outputIndex
prevouts.write(txHash);
prevouts.write(txIndex);
}
byte[] hashPrevouts = CryptoUtil.doubleSha256(prevouts.toByteArray());
forSign.write(hashPrevouts);
//hashSequence (32-byte hash), ffffffff only
ByteArrayOutputStream sequences = new ByteArrayOutputStream();
for (int i = 0; i < inputCount; ++i) {
sequences.write(new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff});
}
byte[] hashSequence = CryptoUtil.doubleSha256(sequences.toByteArray());
forSign.write(hashSequence);
//outpoint (32-byte hash + 4-byte little endian)
UnspentOutputInfo outPut = unspentOutputs.get(inputPos);
byte[] txHash = BCHUtils.reverse(Util.hexToBytes(outPut.txHashForBuild));//Little-endian txID
byte[] txIndex = BCHUtils.reverse(Util.intToByteArray4(outPut.outputIndex));//Little-endian outputIndex
forSign.write(txHash);
forSign.write(txIndex);
//scriptCode of the input (serialized as scripts inside CTxOuts)
byte[] scriptCode = Transaction.Script.buildOutput(changeAddress).bytes; //build change out
byte[] scriptLength = Util.intToByteArray(scriptCode.length);
forSign.write(scriptLength);
forSign.write(scriptCode);
//value of the output spent by this input (8-byte little endian)
byte[] outValue = BCHUtils.reverse(Util.longToByteArray8(outPut.value));
forSign.write(outValue);
//nSequence of the input (4-byte little endian), ffffffff only
forSign.write(new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff});
//hashOutputs (32-byte hash)
ByteArrayOutputStream outputs = new ByteArrayOutputStream();
byte[] sendAmount = BCHUtils.reverse(Util.longToByteArray8(amount));
byte[] sendScript = Transaction.Script.buildOutput(outputAddress).bytes; // build out
byte[] sendLength = Util.intToByteArray(sendScript.length);
outputs.write(sendAmount);
outputs.write(sendLength);
outputs.write(sendScript);
//output for change (if any)
if (change != 0) {
byte[] changeAmount = BCHUtils.reverse(Util.longToByteArray8(change));
byte[] changeScript = Transaction.Script.buildOutput(changeAddress).bytes; //build change out
byte[] changeLength = Util.intToByteArray(changeScript.length);
outputs.write(changeAmount);
outputs.write(changeLength);
outputs.write(changeScript);
}
byte[] hashOutputs = CryptoUtil.doubleSha256(outputs.toByteArray());
forSign.write(hashOutputs);
//nLocktime of the transaction (4-byte little endian)
forSign.write(new byte[]{0x00, 0x00, 0x00, 0x00});
//sighash type of the signature (4-byte little endian)
forSign.write(new byte[]{0x41, 0x00, 0x00, 0x00});
byte[] rawData = forSign.toByteArray();
Log.e("Sign_TX_Body", BCHUtils.toHex(rawData));
return rawData;
}
public static byte[] buildBodyTX(String outputAddress, String changeAddress, ArrayList<UnspentOutputInfo> unspentOutputs, int inputPos, long amount, long change) throws BitcoinException, IOException {
//0200000000
BitcoinOutputStream forSign = new BitcoinOutputStream();
//forSign.writeInt32(0x01);
forSign.write(new byte[]{0x02, 0x00, 0x00, 0x00}); // version
//01
byte inputCount = (byte) unspentOutputs.size();
forSign.write(inputCount); // input count
//hex str hash prev btc
for (int i = 0; i < inputCount; ++i) {
UnspentOutputInfo outPut = unspentOutputs.get(i);
int outputIndex = outPut.outputIndex;
byte[] txHash = BCHUtils.reverse(Util.hexToBytes(outPut.txHashForBuild));//Sha256Hash.hash(rawTxByte);
forSign.write(txHash);
forSign.writeInt32(outputIndex); //output index in prev tx
if (inputPos == -1 || i == inputPos) {
// hex str 1976a914....88ac
forSign.write((byte) outPut.scriptForBuild.length);
forSign.write(outPut.scriptForBuild);
} else {
forSign.write(0x00);
}
//ffffffff
forSign.write(new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}); // sequence
}
//02
byte outputCount = (byte) ((change == 0) ? 1 : 2); // outputCount
forSign.write(outputCount);
//8 bytes
forSign.writeInt64(amount); //amount
byte[] sendScript = Transaction.Script.buildOutput(outputAddress).bytes; // build out
//hex str 1976a914....88ac
forSign.write((byte) sendScript.length);
forSign.write(sendScript);
if (change != 0) {
//8 bytes
forSign.writeInt64(change); // change
//hex str 1976a914....88ac
byte[] chancheScript = Transaction.Script.buildOutput(changeAddress).bytes; //build out
forSign.write((byte) chancheScript.length);
forSign.write(chancheScript);
}
//00000000
forSign.write(new byte[]{0x00, 0x00, 0x00, 0x00});
//forSign.write(new byte[]{0x01, 0x00, 0x00, 0x00});
byte[] rawData = forSign.toByteArray();
Log.e("Sign_TX_Body", BCHUtils.toHex(rawData));
return rawData;
}
public static byte[] buildBodyTX(String outputAddress, String changeAddress, int outputIndex, String prevID, long amount, long change, byte[] script) throws BitcoinException, IOException {
//0200000000
BitcoinOutputStream forSign = new BitcoinOutputStream();
forSign.writeInt32(0x01);//write(new byte[]{0x02, 0x00, 0x00, 0x00}); // version
//01
byte inputCount = 1;
forSign.write(inputCount); // input count
//hex str hash prev btc
byte[] txHash = BCHUtils.reverse(Util.hexToBytes(prevID));//Sha256Hash.hash(rawTxByte);
forSign.write(txHash); //previos tx hash
//00000000
//byte indexOutput = outputIndex;
forSign.writeInt32(outputIndex/*indexOutput*/); //output index in prev tx
//forSign.write(0x00);
// hex str 1976a914....88ac
forSign.write((byte) script.length);
forSign.write(script);
//ffffffff
forSign.write(new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}); // sequence
//02
byte outputCount = (byte) ((change == 0) ? 1 : 2); // outputCount
forSign.write(outputCount);
//8 bytes
forSign.writeInt64(amount); //amount
byte[] sendScript = Transaction.Script.buildOutput(outputAddress).bytes; // build out
//hex str 1976a914....88ac
forSign.write((byte) sendScript.length);
forSign.write(sendScript);
if (change != 0) {
//8 bytes
forSign.writeInt64(change); // change
//hex str 1976a914....88ac
byte[] chancheScript = Transaction.Script.buildOutput(changeAddress).bytes; //build out
forSign.write((byte) chancheScript.length);
forSign.write(chancheScript);
}
//00000000
forSign.write(new byte[]{0x00, 0x00, 0x00, 0x00});
byte[] rawData = forSign.toByteArray();
//Log.e("Sign_TX_Body", BCHUtils.toHex(rawData));
return rawData;
}
public static ArrayList<UnspentOutputInfo> getOutputs(List<BtcData.UnspentTransaction> rawTxList, byte[] outputScriptWeAreAbleToSpend) throws BitcoinException {
ArrayList<UnspentOutputInfo> unspentOutputs = new ArrayList<>();
for (BtcData.UnspentTransaction current : rawTxList) {
byte[] rawTxByte = BCHUtils.fromHex(current.Raw);
if (rawTxByte == null || current.Raw.isEmpty()) {
continue;
}
Transaction baseTx = new Transaction(rawTxByte);
if (baseTx.inputs.length == 0 || baseTx.outputs.length == 0)
throw new IllegalArgumentException("Unable to decode given transaction");
byte[] txHash = BCHUtils.reverse(CryptoUtil.doubleSha256(rawTxByte));
String txHashForBuild = current.txID;
byte[] sign = null;
for (int outputIndex = 0; outputIndex < baseTx.outputs.length; outputIndex++) {
Transaction.Output output = baseTx.outputs[outputIndex];
// find outputs
if (Arrays.equals(outputScriptWeAreAbleToSpend, output.script.bytes)) {
unspentOutputs.add(new UnspentOutputInfo(txHash, output.script, output.value, outputIndex, -1, txHashForBuild, sign));
}
}
}
return unspentOutputs;
}
public static byte[] fromHex(String s) {
if (s != null) {
try {
StringBuilder sb = new StringBuilder(s.length());
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (!Character.isWhitespace(ch)) {
sb.append(ch);
}
}
s = sb.toString();
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
int hi = (Character.digit(s.charAt(i), 16) << 4);
int low = Character.digit(s.charAt(i + 1), 16);
if (hi >= 256 || low < 0 || low >= 16) {
return null;
}
data[i / 2] = (byte) (hi | low);
}
return data;
} catch (Exception ignored) {
}
}
return null;
}
public static byte[] reverse(byte[] bytes) {
byte[] result = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) {
result[i] = bytes[bytes.length - i - 1];
}
return result;
}
public static byte[] reverseInPlace(byte[] bytes) {
int len = bytes.length / 2;
for (int i = 0; i < len; i++) {
byte t = bytes[i];
bytes[i] = bytes[bytes.length - i - 1];
bytes[bytes.length - i - 1] = t;
}
return bytes;
}
}

View file

@ -3,6 +3,7 @@ package com.tangem.domain.wallet;
import android.net.Uri; import android.net.Uri;
import android.text.InputFilter; import android.text.InputFilter;
import com.tangem.tangemcard.data.Blockchain;
import com.tangem.tangemcard.reader.CardProtocol; import com.tangem.tangemcard.reader.CardProtocol;
import com.tangem.tangemcard.tasks.SignTask; import com.tangem.tangemcard.tasks.SignTask;
@ -237,7 +238,12 @@ public abstract class CoinEngine {
public void defineWallet() throws CardProtocol.TangemException { public void defineWallet() throws CardProtocol.TangemException {
try { try {
String wallet = calculateAddress(ctx.getCard().getWalletPublicKey()); String wallet;
if (ctx.getBlockchain() == Blockchain.BitcoinCash) {
wallet = calculateAddress(ctx.getCard().getWalletPublicKeyRar());
} else {
wallet = calculateAddress(ctx.getCard().getWalletPublicKey());
}
ctx.getCoinData().setWallet(wallet); ctx.getCoinData().setWallet(wallet);
} }
catch (Exception e) catch (Exception e)

View file

@ -1,8 +1,24 @@
package com.tangem.domain.wallet.bch package com.tangem.domain.wallet.bch
enum class BitcoinCashNode(val host: String, val port: Int) { enum class BitcoinCashNode(val host: String, val port: Int, val proto: String) {
n1("electrumx-bch.cryptonermal.net", 50001), N_001("electrumx.hillsideinternet.com", 50002, "ssl"),
n2("abc1.hsmiths.com", 60001), N_002("bch0.kister.net", 50002, "ssl"),
n3("electrum.imaginary.cash", 50001), N_003("abc1.hsmiths.com", 60002, "ssl"),
n4("35.157.238.5", 51001), N_004("bch.curalle.ovh", 50002, "ssl"),
N_005("207.180.215.112", 52002, "ssl"),
N_006("bch.imaginary.cash", 50002, "ssl"),
N_007("dedi.jochen-hoenicke.de", 51002, "ssl"),
N_008("crypto.mldlabs.com", 50002, "ssl"),
N_009("bch.electrumx.cash", 50002, "ssl"),
N_010("electroncash.cascharia.com", 50002, "ssl"),
N_011("bch.crypto.mldlabs.com", 50002, "ssl"),
N_012("electron-cash.dragon.zone", 50002, "ssl"),
N_013("electron.coinucopia.io", 50002, "ssl"),
N_014("blackie.c3-soft.com", 50002, "ssl"),
N_015("electroncash.ueo.ch", 51002, "ssl"),
N_016("electrum.imaginary.cash", 50002, "ssl"),
N_017("35.157.238.5", 51002, "ssl"),
N_018("bitcoincash.quangld.com", 50002, "ssl"),
N_019("bch.stitthappens.com", 50002, "ssl"),
N_020("electroncash.dk", 50002, "ssl"),
} }

View file

@ -3,6 +3,7 @@ package com.tangem.domain.wallet.bch;
import android.net.Uri; import android.net.Uri;
import android.text.InputFilter; import android.text.InputFilter;
import com.tangem.domain.wallet.BCHUtils;
import com.tangem.tangemcard.data.local.PINStorage; import com.tangem.tangemcard.data.local.PINStorage;
import com.tangem.tangemcard.reader.CardProtocol; import com.tangem.tangemcard.reader.CardProtocol;
import com.tangem.tangemcard.reader.TLV; import com.tangem.tangemcard.reader.TLV;
@ -16,7 +17,6 @@ import com.tangem.tangemcard.data.TangemCard;
import com.tangem.domain.wallet.TangemContext; import com.tangem.domain.wallet.TangemContext;
import com.tangem.domain.wallet.Transaction; import com.tangem.domain.wallet.Transaction;
import com.tangem.domain.wallet.UnspentOutputInfo; import com.tangem.domain.wallet.UnspentOutputInfo;
import com.tangem.domain.wallet.BTCUtils;
import com.tangem.tangemcard.tasks.SignTask; import com.tangem.tangemcard.tasks.SignTask;
import com.tangem.util.CryptoUtil; import com.tangem.util.CryptoUtil;
import com.tangem.util.DecimalDigitsInputFilter; import com.tangem.util.DecimalDigitsInputFilter;
@ -448,7 +448,7 @@ public class BtcCashEngine extends CoinEngine {
byte[] outputScriptWeAreAbleToSpend = Transaction.Script.buildOutput(srcLegacyAddress).bytes; byte[] outputScriptWeAreAbleToSpend = Transaction.Script.buildOutput(srcLegacyAddress).bytes;
// Collect unspent // Collect unspent
ArrayList<UnspentOutputInfo> unspentOutputs = BTCUtils.getOutputs(rawTxList, outputScriptWeAreAbleToSpend); ArrayList<UnspentOutputInfo> unspentOutputs = BCHUtils.getOutputs(rawTxList, outputScriptWeAreAbleToSpend);
long fullAmount = 0; long fullAmount = 0;
for (int i = 0; i < unspentOutputs.size(); ++i) { for (int i = 0; i < unspentOutputs.size(); ++i) {
@ -477,7 +477,7 @@ public class BtcCashEngine extends CoinEngine {
byte[][] bodyDoubleHash= new byte[unspentOutputs.size()][]; byte[][] bodyDoubleHash= new byte[unspentOutputs.size()][];
for (int i = 0; i < unspentOutputs.size(); ++i) { for (int i = 0; i < unspentOutputs.size(); ++i) {
txForSign[i] = BTCUtils.buildTXForSign(srcLegacyAddress, destLegacyAddress, srcLegacyAddress, unspentOutputs, i, amount, change); txForSign[i] = BCHUtils.buildTXForSign(srcLegacyAddress, destLegacyAddress, srcLegacyAddress, unspentOutputs, i, amount, change);
bodyHash[i] = Util.calculateSHA256(txForSign[i]); bodyHash[i] = Util.calculateSHA256(txForSign[i]);
bodyDoubleHash[i] = Util.calculateSHA256(bodyHash[i]); bodyDoubleHash[i] = Util.calculateSHA256(bodyHash[i]);
} }
@ -531,94 +531,10 @@ public class BtcCashEngine extends CoinEngine {
unspentOutputs.get(i).scriptForBuild = DerEncodingUtil.packSignDerBitcoinCash(r, s, pbKey); unspentOutputs.get(i).scriptForBuild = DerEncodingUtil.packSignDerBitcoinCash(r, s, pbKey);
} }
byte[] txForSend=BTCUtils.buildTXForSend(destLegacyAddress, srcLegacyAddress, unspentOutputs, amountFinal, changeFinal); byte[] txForSend=BCHUtils.buildTXForSend(destLegacyAddress, srcLegacyAddress, unspentOutputs, amountFinal, changeFinal);
notifyOnNeedSendPayment(txForSend); notifyOnNeedSendPayment(txForSend);
} }
}; };
} }
// @Override
// public byte[] sign(Amount feeValue, Amount amountValue, boolean IncFee, String destAddress, CardProtocol protocol) throws Exception {
//
// checkBlockchainDataExists();
//
// CoinEngine engine = CoinEngineFactory.INSTANCE.create(ctx);
//
// String srcLegacyAddress = ((BtcCashEngine)engine).convertToLegacyAddress(ctx.getCoinData().getWallet());
// String destLegacyAddress = ((BtcCashEngine)engine).convertToLegacyAddress(destAddress);
// byte[] pbKey = ctx.getCard().getWalletPublicKeyRar(); //ALWAYS USING COMPRESS KEY
//
// // Build script for our address
// List<BtcData.UnspentTransaction> rawTxList = coinData.getUnspentTransactions();
// byte[] outputScriptWeAreAbleToSpend = Transaction.Script.buildOutput(srcLegacyAddress).bytes;
//
// // Collect unspent
// ArrayList<UnspentOutputInfo> unspentOutputs = BTCUtils.getOutputs(rawTxList, outputScriptWeAreAbleToSpend);
//
// long fullAmount = 0;
// for (int i = 0; i < unspentOutputs.size(); ++i) {
// fullAmount += unspentOutputs.get(i).value;
// }
//
//
// long fees = convertToInternalAmount(feeValue).longValueExact();
// long amount = convertToInternalAmount(amountValue).longValueExact();
// long change = fullAmount - amount;
// if (IncFee) {
// amount = amount - fees;
// } else {
// change = change - fees;
// }
//
// if (amount + fees > fullAmount) {
// throw new CardProtocol.TangemException_WrongAmount(String.format("Balance (%d) < change (%d) + amount (%d)", fullAmount, change, amount));
// }
//
// byte[][] dataForSign = new byte[unspentOutputs.size()][];
//
// for (int i = 0; i < unspentOutputs.size(); ++i) {
// byte[] newTX = BTCUtils.buildTXForSign(srcLegacyAddress, destLegacyAddress, srcLegacyAddress, unspentOutputs, i, amount, change);
//
// byte[] hashData = Util.calculateSHA256(newTX);
// byte[] doubleHashData = Util.calculateSHA256(hashData);
//
// unspentOutputs.get(i).bodyDoubleHash = doubleHashData;
// unspentOutputs.get(i).bodyHash = hashData;
//
// if (ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw || ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw_Validated_By_Issuer) {
// dataForSign[i] = newTX;
// } else {
// dataForSign[i] = doubleHashData;
// }
//
// }
//
// byte[] signFromCard;
// if (ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw || ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Raw_Validated_By_Issuer) {
// ByteArrayOutputStream bs = new ByteArrayOutputStream();
// if (dataForSign.length > 10) throw new Exception("To much hashes in one transaction!");
// for (int i = 0; i < dataForSign.length; i++) {
// if (i != 0 && dataForSign[0].length != dataForSign[i].length)
// throw new Exception("Hashes length must be identical!");
// bs.write(dataForSign[i]);
// }
// signFromCard = protocol.run_SignRaw(PINStorage.getPIN2(), "sha-256x2", bs.toByteArray(), null, null, null).getTLV(TLV.Tag.TAG_Signature).Value;
// } else {
// //ctx.getCard().getSigningMethod() == TangemCard.SigningMethod.Sign_Hash_Validated_By_Issuer
// //ctx.getCard().getIssuer()
// signFromCard = protocol.run_SignHashes(PINStorage.getPIN2(), dataForSign, null, null, null).getTLV(TLV.Tag.TAG_Signature).Value;
// // TODO slice signFromCard to hashes.length parts
// }
//
// for (int i = 0; i < unspentOutputs.size(); ++i) {
// BigInteger r = new BigInteger(1, Arrays.copyOfRange(signFromCard, i * 64, 32 + i * 64));
// BigInteger s = new BigInteger(1, Arrays.copyOfRange(signFromCard, 32 + i * 64, 64 + i * 64));
// s = CryptoUtil.toCanonicalised(s);
//
// unspentOutputs.get(i).scriptForBuild = DerEncodingUtil.packSignDerBitcoinCash(r, s, pbKey);
// }
//
// return BTCUtils.buildTXForSend(destLegacyAddress, srcLegacyAddress, unspentOutputs, amount, change);
// }
} }

View file

@ -4,6 +4,8 @@ package com.tangem.domain.wallet.btc;
* Created by Ilia on 29.09.2017. * Created by Ilia on 29.09.2017.
*/ */
import com.tangem.domain.wallet.Transaction;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
@ -40,4 +42,7 @@ public final class BitcoinOutputStream extends ByteArrayOutputStream {
writeInt64(value); writeInt64(value);
} }
} }
public void write(Transaction.Script script) {
}
} }