diff --git a/app/src/main/java/com/tangem/domain/BitcoinCashNode.kt b/app/src/main/java/com/tangem/domain/BitcoinCashNode.kt new file mode 100644 index 0000000000..93af538d28 --- /dev/null +++ b/app/src/main/java/com/tangem/domain/BitcoinCashNode.kt @@ -0,0 +1,8 @@ +package com.tangem.domain + +enum class BitcoinCashNode(val host: String, val port: Int) { + n1("electrumx-bch.cryptonermal.net", 50001), + n2("abc1.hsmiths.com", 60001), + n3("electrum.imaginary.cash", 50001), + n4("35.157.238.5", 51001), +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/domain/LitecoinNode.kt b/app/src/main/java/com/tangem/domain/LitecoinNode.kt new file mode 100644 index 0000000000..5b4cad42dd --- /dev/null +++ b/app/src/main/java/com/tangem/domain/LitecoinNode.kt @@ -0,0 +1,13 @@ +package com.tangem.domain + +enum class LitecoinNode(val host: String, val port: Int) { + n1("ltc.rentonisk.com", 50001), + n2("backup.electrum-ltc.org", 50001), + n3("node.ispol.sk", 50003), + n4("electrum-ltc.wilv.in", 50001), + n5("ltc01.knas.systems", 50003), + n6("electrumx.nmdps.net", 9433), + n7("e-3.claudioboxx.com", 50003), + n8("electrum.ltc.xurious.com", 50001), + n9("e-1.claudioboxx.com", 50003), +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashAddressDecodedParts.java b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashAddressDecodedParts.java new file mode 100644 index 0000000000..afca389706 --- /dev/null +++ b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashAddressDecodedParts.java @@ -0,0 +1,37 @@ +package com.tangem.domain.wallet.BitcoinCash; + +// Helper class for CashAddr + +public class BitcoinCashAddressDecodedParts { + + String prefix; + + BitcoinCashAddressType addressType; + + byte[] hash; + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public BitcoinCashAddressType getAddressType() { + return addressType; + } + + public void setAddressType(BitcoinCashAddressType addressType) { + this.addressType = addressType; + } + + public byte[] getHash() { + return hash; + } + + public void setHash(byte[] hash) { + this.hash = hash; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashAddressType.java b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashAddressType.java new file mode 100644 index 0000000000..169f9008a5 --- /dev/null +++ b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashAddressType.java @@ -0,0 +1,23 @@ +package com.tangem.domain.wallet.BitcoinCash; + + +/** + * Copyright (c) 2018 Tobias Brandt + * + * Distributed under the MIT software license, see the accompanying file LICENSE + * or http://www.opensource.org/licenses/mit-license.php. + */ +public enum BitcoinCashAddressType { + + P2PKH((byte) 0), P2SH((byte) 8); + + private final byte versionByte; + + BitcoinCashAddressType(byte versionByte) { + this.versionByte = versionByte; + } + + public byte getVersionByte() { + return versionByte; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashBase32.java b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashBase32.java new file mode 100644 index 0000000000..82e7d6b359 --- /dev/null +++ b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashBase32.java @@ -0,0 +1,74 @@ +package com.tangem.domain.wallet.BitcoinCash; + +import java.util.HashMap; +import java.util.Map; + +/** + * Copyright (c) 2018 Tobias Brandt + * + * Distributed under the MIT software license, see the accompanying file LICENSE + * or http://www.opensource.org/licenses/mit-license.php. + */ +public class BitcoinCashBase32 { + + public static final String CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; + + private static final char[] CHARS = CHARSET.toCharArray(); + + private static Map charPositionMap; + static { + charPositionMap = new HashMap<>(); + for (int i = 0; i < CHARS.length; i++) { + charPositionMap.put(CHARS[i], i); + } + if (charPositionMap.size() != 32) { + throw new RuntimeException("The charset must contain 32 unique characters."); + } + } + + /** + * Encode a byte array as base32 string. This method assumes that all bytes + * are only from 0-31 + * + * @param byteArray + * @return + */ + public static String encode(byte[] byteArray) { + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < byteArray.length; i++) { + int val = (int) byteArray[i]; + + if (val < 0 || val > 31) { + throw new RuntimeException("This method assumes that all bytes are only from 0-31. Was: " + val); + } + + sb.append(CHARS[val]); + } + + return sb.toString(); + } + + /** + * Decode a base32 string back to the byte array representation + * + * @param base32String + * @return + */ + public static byte[] decode(String base32String) { + byte[] bytes = new byte[base32String.length()]; + + char[] charArray = base32String.toCharArray(); + for (int i = 0; i < charArray.length; i++) { + Integer position = charPositionMap.get(charArray[i]); + if (position == null) { + throw new RuntimeException("There seems to be an invalid char: " + charArray[i]); + } + bytes[i] = (byte) ((int) position); + } + + return bytes; + } +} + + \ No newline at end of file diff --git a/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashBitArrayConverter.java b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashBitArrayConverter.java new file mode 100644 index 0000000000..43d5b19de8 --- /dev/null +++ b/app/src/main/java/com/tangem/domain/wallet/BitcoinCash/BitcoinCashBitArrayConverter.java @@ -0,0 +1,60 @@ +package com.tangem.domain.wallet.BitcoinCash; +/** + * Copyright (c) 2018 Tobias Brandt + * + * Copyright (c) 2017 Pieter Wuille + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +public class BitcoinCashBitArrayConverter { + + public static byte[] convertBits(byte[] bytes8Bits, int from, int to, boolean strictMode) { + int length = (int) (strictMode ? Math.floor((double) bytes8Bits.length * from / to) + : Math.ceil((double) bytes8Bits.length * from / to)); + int mask = ((1 << to) - 1) & 0xff; + byte[] result = new byte[length]; + int index = 0; + int accumulator = 0; + int bits = 0; + for (int i = 0; i < bytes8Bits.length; i++) { + byte value = bytes8Bits[i]; + accumulator = (((accumulator & 0xff) << from) | (value & 0xff)); + bits += from; + while (bits >= to) { + bits -= to; + result[index] = (byte) ((accumulator >> bits) & mask); + ++index; + } + } + if (!strictMode) { + if (bits > 0) { + result[index] = (byte) ((accumulator << (to - bits)) & mask); + ++index; + } + } else { + if (!(bits < from && ((accumulator << (to - bits)) & mask) == 0)) { + throw new RuntimeException("Strict mode was used but input couldn't be converted without padding"); + } + } + + return result; + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/card_ru024.png b/app/src/main/res/drawable/card_ru024.png new file mode 100644 index 0000000000..f7804188e5 Binary files /dev/null and b/app/src/main/res/drawable/card_ru024.png differ diff --git a/app/src/main/res/drawable/card_ru028.png b/app/src/main/res/drawable/card_ru028.png new file mode 100644 index 0000000000..1b67e6ad40 Binary files /dev/null and b/app/src/main/res/drawable/card_ru028.png differ diff --git a/app/src/main/res/drawable/card_ru029.png b/app/src/main/res/drawable/card_ru029.png new file mode 100644 index 0000000000..4f3a822bed Binary files /dev/null and b/app/src/main/res/drawable/card_ru029.png differ diff --git a/app/src/main/res/drawable/card_ru030.png b/app/src/main/res/drawable/card_ru030.png new file mode 100644 index 0000000000..e796707d5e Binary files /dev/null and b/app/src/main/res/drawable/card_ru030.png differ