Browse Source

btc only

V1.1.0-btc-release
ZhangJun 5 years ago
parent
commit
1c1190cd85
  1. 360
      app/schemas/com.cobo.cold.db.AppDatabase/3.json
  2. 13
      app/src/main/assets/bundleMap.json
  3. 59
      app/src/main/assets/script/BCH.bundle.js
  4. 30
      app/src/main/assets/script/DASH.bundle.js
  5. 2
      app/src/main/assets/script/DCR.bundle.js
  6. 2
      app/src/main/assets/script/EOS.bundle_d0f384b2cc63ac78f25e.js
  7. 2
      app/src/main/assets/script/ETC.bundle_b0d7ccb0dc5138935dc7.js
  8. 2
      app/src/main/assets/script/ETH.bundle_b0d7ccb0dc5138935dc7.js
  9. 2
      app/src/main/assets/script/IOST.bundle_010b6f92f916b495faad.js
  10. 30
      app/src/main/assets/script/LTC.bundle.js
  11. 2
      app/src/main/assets/script/TRON.bundle.js
  12. 38
      app/src/main/assets/script/XRP.bundle.js
  13. 2
      app/src/main/assets/script/XZC.bundle.js
  14. 12
      app/src/main/java/com/cobo/cold/db/AppDatabase.java
  15. 2
      app/src/main/java/com/cobo/cold/db/entity/CoinEntity.java
  16. 4
      app/src/main/java/com/cobo/cold/ui/MainActivity.java
  17. 2
      app/src/main/java/com/cobo/cold/ui/fragment/PassphraseFragment.java
  18. 10
      app/src/main/java/com/cobo/cold/ui/fragment/main/ManageCoinFragment.java
  19. 16
      app/src/main/java/com/cobo/cold/ui/fragment/main/TxConfirmFragment.java
  20. 16
      app/src/main/java/com/cobo/cold/ui/fragment/main/TxFragment.java
  21. 2
      app/src/main/java/com/cobo/cold/ui/fragment/setup/ConfirmMnemonicFragment.java
  22. 2
      app/src/main/java/com/cobo/cold/ui/fragment/setup/MnemonicInputFragment.java
  23. 2
      app/src/main/java/com/cobo/cold/ui/fragment/whitelist/AddWhiteListFragment.java
  24. 1
      app/src/main/java/com/cobo/cold/ui/views/DrawerAdapter.java
  25. 14
      app/src/main/java/com/cobo/cold/viewmodel/CoinListViewModel.java
  26. 15
      app/src/main/java/com/cobo/cold/viewmodel/PublicKeyViewModel.java
  27. 25
      app/src/main/java/com/cobo/cold/viewmodel/TxConfirmViewModel.java
  28. BIN
      app/src/main/res/drawable-xhdpi/coin_ada.png
  29. BIN
      app/src/main/res/drawable-xhdpi/coin_bch.png
  30. BIN
      app/src/main/res/drawable-xhdpi/coin_dash.png
  31. BIN
      app/src/main/res/drawable-xhdpi/coin_dcr.png
  32. BIN
      app/src/main/res/drawable-xhdpi/coin_eos.png
  33. BIN
      app/src/main/res/drawable-xhdpi/coin_eos_token.png
  34. BIN
      app/src/main/res/drawable-xhdpi/coin_etc.png
  35. BIN
      app/src/main/res/drawable-xhdpi/coin_eth.png
  36. BIN
      app/src/main/res/drawable-xhdpi/coin_eth_token.png
  37. BIN
      app/src/main/res/drawable-xhdpi/coin_iost.png
  38. BIN
      app/src/main/res/drawable-xhdpi/coin_iost_token.png
  39. BIN
      app/src/main/res/drawable-xhdpi/coin_lbtc.png
  40. BIN
      app/src/main/res/drawable-xhdpi/coin_ltc.png
  41. BIN
      app/src/main/res/drawable-xhdpi/coin_tron.png
  42. BIN
      app/src/main/res/drawable-xhdpi/coin_tron_token.png
  43. BIN
      app/src/main/res/drawable-xhdpi/coin_xrp.png
  44. BIN
      app/src/main/res/drawable-xhdpi/coin_xzc.png
  45. 2
      app/src/main/res/layout/add_white_list.xml
  46. 22
      app/src/main/res/navigation/nav_graph_main.xml
  47. 20
      app/src/main/res/navigation/nav_graph_setup.xml
  48. 81
      coinlib/src/main/java/com/cobo/coinlib/coins/BCH/Bch.java
  49. 80
      coinlib/src/main/java/com/cobo/coinlib/coins/DASH/Dash.java
  50. 121
      coinlib/src/main/java/com/cobo/coinlib/coins/DCR/Dcr.java
  51. 116
      coinlib/src/main/java/com/cobo/coinlib/coins/EOS/Eos.java
  52. 47
      coinlib/src/main/java/com/cobo/coinlib/coins/ETC/Etc.java
  53. 172
      coinlib/src/main/java/com/cobo/coinlib/coins/ETH/Eth.java
  54. 83
      coinlib/src/main/java/com/cobo/coinlib/coins/IOST/Iost.java
  55. 75
      coinlib/src/main/java/com/cobo/coinlib/coins/LTC/Ltc.java
  56. 107
      coinlib/src/main/java/com/cobo/coinlib/coins/TRON/Tron.java
  57. 75
      coinlib/src/main/java/com/cobo/coinlib/coins/XRP/Xrp.java
  58. 83
      coinlib/src/main/java/com/cobo/coinlib/coins/XZC/Xzc.java
  59. 15
      coinlib/src/main/java/com/cobo/coinlib/interfaces/Signer.java
  60. 53
      coinlib/src/main/java/com/cobo/coinlib/utils/Coins.java
  61. 8
      coinlib/src/main/java/com/cobo/coinlib/v8/CoinImpl.java
  62. 18
      coinlib/src/test/java/com/cobo/coinlib/CoinsTest.java
  63. 50
      coinlib/src/test/java/com/cobo/coinlib/coin/BchTest.java
  64. 60
      coinlib/src/test/java/com/cobo/coinlib/coin/DashTest.java
  65. 60
      coinlib/src/test/java/com/cobo/coinlib/coin/DcrTest.java
  66. 46
      coinlib/src/test/java/com/cobo/coinlib/coin/EosTest.java
  67. 60
      coinlib/src/test/java/com/cobo/coinlib/coin/EtcTest.java
  68. 60
      coinlib/src/test/java/com/cobo/coinlib/coin/EthTest.java
  69. 46
      coinlib/src/test/java/com/cobo/coinlib/coin/IostTest.java
  70. 50
      coinlib/src/test/java/com/cobo/coinlib/coin/LtcTest.java
  71. 60
      coinlib/src/test/java/com/cobo/coinlib/coin/TronTest.java
  72. 60
      coinlib/src/test/java/com/cobo/coinlib/coin/XrpTest.java
  73. 60
      coinlib/src/test/java/com/cobo/coinlib/coin/XzcTest.java

360
app/schemas/com.cobo.cold.db.AppDatabase/3.json

@ -0,0 +1,360 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "227b9fc6314e81dc9cb31e45d4d443b1",
"entities": [
{
"tableName": "coins",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `coinId` TEXT, `name` TEXT, `iconResId` INTEGER NOT NULL, `show` INTEGER NOT NULL, `addressCount` INTEGER NOT NULL, `coinCode` TEXT, `exPub` TEXT, `belongTo` TEXT, `index` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "coinId",
"columnName": "coinId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "iconResId",
"columnName": "iconResId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "show",
"columnName": "show",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "addressCount",
"columnName": "addressCount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "coinCode",
"columnName": "coinCode",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "exPub",
"columnName": "exPub",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "belongTo",
"columnName": "belongTo",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "index",
"columnName": "index",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_coins_id",
"unique": false,
"columnNames": [
"id"
],
"createSql": "CREATE INDEX `index_coins_id` ON `${TABLE_NAME}` (`id`)"
}
],
"foreignKeys": []
},
{
"tableName": "addresses",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `path` TEXT, `coinId` TEXT, `addressString` TEXT, `name` TEXT, `index` INTEGER NOT NULL, `belongTo` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "path",
"columnName": "path",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "coinId",
"columnName": "coinId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "addressString",
"columnName": "addressString",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "index",
"columnName": "index",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "belongTo",
"columnName": "belongTo",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "txs",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`txId` TEXT NOT NULL, `coinId` TEXT, `coinCode` TEXT, `amount` TEXT, `from` TEXT, `to` TEXT, `fee` TEXT, `signedHex` TEXT, `timeStamp` INTEGER NOT NULL, `memo` TEXT, `signId` TEXT, `belongTo` TEXT, PRIMARY KEY(`txId`))",
"fields": [
{
"fieldPath": "txId",
"columnName": "txId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "coinId",
"columnName": "coinId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "coinCode",
"columnName": "coinCode",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "amount",
"columnName": "amount",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "from",
"columnName": "from",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "to",
"columnName": "to",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "fee",
"columnName": "fee",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "signedHex",
"columnName": "signedHex",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "timeStamp",
"columnName": "timeStamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "memo",
"columnName": "memo",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "signId",
"columnName": "signId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "belongTo",
"columnName": "belongTo",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"txId"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_txs_txId",
"unique": false,
"columnNames": [
"txId"
],
"createSql": "CREATE INDEX `index_txs_txId` ON `${TABLE_NAME}` (`txId`)"
}
],
"foreignKeys": []
},
{
"tableName": "white_list",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `addr` TEXT, `addrName` TEXT, `coinCode` TEXT, `memo` TEXT, `belongTo` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "addr",
"columnName": "addr",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "addrName",
"columnName": "addrName",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "coinCode",
"columnName": "coinCode",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "memo",
"columnName": "memo",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "belongTo",
"columnName": "belongTo",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "accounts",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `hdPath` TEXT, `exPub` TEXT, `addressLength` INTEGER NOT NULL, `isMultiSign` INTEGER NOT NULL, `coinId` INTEGER NOT NULL, FOREIGN KEY(`coinId`) REFERENCES `coins`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "hdPath",
"columnName": "hdPath",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "exPub",
"columnName": "exPub",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "addressLength",
"columnName": "addressLength",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isMultiSign",
"columnName": "isMultiSign",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "coinId",
"columnName": "coinId",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": [
{
"table": "coins",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"coinId"
],
"referencedColumns": [
"id"
]
}
]
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '227b9fc6314e81dc9cb31e45d4d443b1')"
]
}
}

13
app/src/main/assets/bundleMap.json

@ -1,14 +1,3 @@
{
"BTC": "BTC.bundle_94e3c1790748ac7fc876.js",
"BCH": "BCH.bundle.js",
"ETH": "ETH.bundle_b0d7ccb0dc5138935dc7.js",
"ETC": "ETC.bundle_b0d7ccb0dc5138935dc7.js",
"DASH": "DASH.bundle.js",
"LTC": "LTC.bundle.js",
"XRP": "XRP.bundle.js",
"XZC": "XZC.bundle.js",
"DCR": "DCR.bundle.js",
"EOS": "EOS.bundle_d0f384b2cc63ac78f25e.js",
"IOST": "IOST.bundle_010b6f92f916b495faad.js",
"TRON": "TRON.bundle.js"
"BTC": "BTC.bundle_94e3c1790748ac7fc876.js"
}

59
app/src/main/assets/script/BCH.bundle.js

File diff suppressed because one or more lines are too long

30
app/src/main/assets/script/DASH.bundle.js

File diff suppressed because one or more lines are too long

2
app/src/main/assets/script/DCR.bundle.js

File diff suppressed because one or more lines are too long

2
app/src/main/assets/script/EOS.bundle_d0f384b2cc63ac78f25e.js

File diff suppressed because one or more lines are too long

2
app/src/main/assets/script/ETC.bundle_b0d7ccb0dc5138935dc7.js

File diff suppressed because one or more lines are too long

2
app/src/main/assets/script/ETH.bundle_b0d7ccb0dc5138935dc7.js

File diff suppressed because one or more lines are too long

2
app/src/main/assets/script/IOST.bundle_010b6f92f916b495faad.js

File diff suppressed because one or more lines are too long

30
app/src/main/assets/script/LTC.bundle.js

File diff suppressed because one or more lines are too long

2
app/src/main/assets/script/TRON.bundle.js

File diff suppressed because one or more lines are too long

38
app/src/main/assets/script/XRP.bundle.js

File diff suppressed because one or more lines are too long

2
app/src/main/assets/script/XZC.bundle.js

File diff suppressed because one or more lines are too long

12
app/src/main/java/com/cobo/cold/db/AppDatabase.java

@ -25,6 +25,7 @@ import androidx.lifecycle.MutableLiveData;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
import com.cobo.cold.AppExecutors;
@ -40,7 +41,7 @@ import com.cobo.cold.db.entity.TxEntity;
import com.cobo.cold.db.entity.WhiteListEntity;
@Database(entities = {CoinEntity.class, AddressEntity.class,
TxEntity.class, WhiteListEntity.class, AccountEntity.class}, version = 2)
TxEntity.class, WhiteListEntity.class, AccountEntity.class}, version = 3)
public abstract class AppDatabase extends RoomDatabase {
private static final String DATABASE_NAME = "cobo-vault-db";
private static AppDatabase sInstance;
@ -85,10 +86,19 @@ public abstract class AppDatabase extends RoomDatabase {
});
}
})
.addMigrations(MIGRATION_2_3)
.fallbackToDestructiveMigration()
.build();
}
static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
//migrate delete all altcoins
database.execSQL("DELETE FROM coins WHERE coinCode != 'BTC'");
}
};
private void updateDatabaseCreated(final Context context) {
if (context.getDatabasePath(DATABASE_NAME).exists()) {
setDatabaseCreated();

2
app/src/main/java/com/cobo/cold/db/entity/CoinEntity.java

@ -38,7 +38,7 @@ public class CoinEntity implements Coin, FilterableItem {
private String coinId;
private String name;
private int iconResId;
private boolean show = false;
private boolean show = true;
private int addressCount;
private String coinCode;
private String exPub;

4
app/src/main/java/com/cobo/cold/ui/MainActivity.java

@ -178,10 +178,6 @@ public class MainActivity extends FullScreenActivity {
case R.id.drawer_wallet:
mNavController.navigateUp();
break;
case R.id.drawer_manage:
mNavController.navigateUp();
mNavController.navigate(R.id.action_to_manageCoinFragment);
break;
case R.id.drawer_sync:
mNavController.navigateUp();
mNavController.navigate(R.id.action_to_syncFragment);

2
app/src/main/java/com/cobo/cold/ui/fragment/PassphraseFragment.java

@ -164,7 +164,7 @@ public class PassphraseFragment extends SetupVaultBaseFragment<PassphraseBinding
startActivity(new Intent(mActivity, MainActivity.class));
} else {
Navigation.findNavController(mActivity, R.id.nav_host_fragment)
.navigate(R.id.action_to_manageCoinFragment, data);
.navigate(R.id.to_assetListFragment, data);
}
};
List<CoinEntity> coins = PresetData.generateCoins(mActivity);

10
app/src/main/java/com/cobo/cold/ui/fragment/main/ManageCoinFragment.java

@ -150,11 +150,11 @@ public class ManageCoinFragment extends BaseFragment<ManageCoinFragmentBinding>
case R.id.action_confirm:
Bundle data = Objects.requireNonNull(getArguments());
if (data.getBoolean(IS_SETUP_VAULT)) {
if (FeatureFlags.ENABLE_WHITE_LIST) {
navigate(R.id.action_manageCoin_to_manageWhiteList, data);
} else {
navigate(R.id.action_manageCoinFragment_to_setupSyncFragment, data);
}
// if (FeatureFlags.ENABLE_WHITE_LIST) {
// navigate(R.id.action_manageCoin_to_manageWhiteList, data);
// } else {
// navigate(R.id.action_manageCoinFragment_to_setupSyncFragment, data);
// }
} else {
startActivity(new Intent(mActivity, MainActivity.class));

16
app/src/main/java/com/cobo/cold/ui/fragment/main/TxConfirmFragment.java

@ -139,8 +139,6 @@ public class TxConfirmFragment extends BaseFragment<TxConfirmFragmentBinding> {
refreshFromList();
refreshReceiveList();
refreshTokenUI();
refreshFeeDisplay();
refreshMemoDisplay();
}
});
@ -173,20 +171,6 @@ public class TxConfirmFragment extends BaseFragment<TxConfirmFragmentBinding> {
});
}
private void refreshMemoDisplay() {
if (txEntity.getCoinCode().equals(Coins.EOS.coinCode())
|| txEntity.getCoinCode().equals(Coins.IOST.coinCode())) {
mBinding.txDetail.memoLabel.setText(R.string.tag);
}
}
private void refreshFeeDisplay() {
if (txEntity.getCoinCode().equals(Coins.EOS.coinCode())
|| txEntity.getCoinCode().equals(Coins.IOST.coinCode())) {
mBinding.txDetail.feeInfo.setVisibility(View.GONE);
}
}
private void refreshAmount() {
SpannableStringBuilder style = new SpannableStringBuilder(txEntity.getAmount());
style.setSpan(new ForegroundColorSpan(mActivity.getColor(R.color.colorAccent)),

16
app/src/main/java/com/cobo/cold/ui/fragment/main/TxFragment.java

@ -68,26 +68,10 @@ public class TxFragment extends BaseFragment<TxBinding> {
refreshFromList();
refreshReceiveList();
refreshTokenUI();
refreshFeeDisplay();
refreshMemoDisplay();
});
}
private void refreshMemoDisplay() {
if (txEntity.getCoinCode().equals(Coins.EOS.coinCode())
|| txEntity.getCoinCode().equals(Coins.IOST.coinCode())) {
mBinding.txDetail.memoLabel.setText(R.string.tag);
}
}
private void refreshFeeDisplay() {
if (txEntity.getCoinCode().equals(Coins.EOS.coinCode())
|| txEntity.getCoinCode().equals(Coins.IOST.coinCode())) {
mBinding.txDetail.feeInfo.setVisibility(View.GONE);
}
}
private void refreshAmount() {
SpannableStringBuilder style = new SpannableStringBuilder(txEntity.getAmount());
style.setSpan(new ForegroundColorSpan(mActivity.getColor(R.color.colorAccent)),

2
app/src/main/java/com/cobo/cold/ui/fragment/setup/ConfirmMnemonicFragment.java

@ -77,7 +77,7 @@ public class ConfirmMnemonicFragment extends MnemonicInputFragment {
Bundle data = new Bundle();
data.putBoolean(IS_SETUP_VAULT, ((SetupVaultActivity) mActivity).isSetupVault);
navigate(R.id.action_add_coin_type1, data);
navigate(R.id.action_to_setupSyncFragment, data);
};
List<CoinEntity> coins = PresetData.generateCoins(mActivity);

2
app/src/main/java/com/cobo/cold/ui/fragment/setup/MnemonicInputFragment.java

@ -101,7 +101,7 @@ public class MnemonicInputFragment extends SetupVaultBaseFragment<MnemonicInputF
}
Bundle data = new Bundle();
data.putBoolean(IS_SETUP_VAULT, ((SetupVaultActivity) mActivity).isSetupVault);
navigate(R.id.action_add_coin_type2, data);
navigate(R.id.action_to_setupSyncFragment, data);
};
List<CoinEntity> coins = PresetData.generateCoins(mActivity);

2
app/src/main/java/com/cobo/cold/ui/fragment/whitelist/AddWhiteListFragment.java

@ -100,7 +100,7 @@ public class AddWhiteListFragment extends BaseFragment<AddWhiteListBinding>
}
private boolean shouldShowMemo(String coinCode) {
return "EOS".equals(coinCode) || "XRP".equals(coinCode);
return false;
}
private void add(View view) {

1
app/src/main/java/com/cobo/cold/ui/views/DrawerAdapter.java

@ -43,7 +43,6 @@ public class DrawerAdapter extends RecyclerView.Adapter<DrawerAdapter.Holder> {
public OnItemClickListener listener;
private final List<DrawerItem> dataList = Arrays.asList(
new DrawerItem(R.id.drawer_wallet, R.drawable.drawer_wallet, R.string.drawer_menu_my_vault),
new DrawerItem(R.id.drawer_manage, R.drawable.drawer_asset_manager, R.string.drawer_menu_add_remove),
new DrawerItem(R.id.drawer_sync, R.drawable.drawer_asset_observation, R.string.drawer_menu_sync),
new DrawerItem(R.id.drawer_sdcard, R.drawable.drawer_sdcard, R.string.read_sdcard),
new DrawerItem(R.id.drawer_settings, R.drawable.drawer_setting, R.string.drawer_menu_setting),

14
app/src/main/java/com/cobo/cold/viewmodel/CoinListViewModel.java

@ -43,19 +43,7 @@ public class CoinListViewModel extends AndroidViewModel {
private final DataRepository mRepository;
private final MediatorLiveData<List<CoinEntity>> mObservableCoins;
public static final Comparator<CoinEntity> coinEntityComparator = (o1, o2) -> {
if (o1.getCoinCode().equals(Coins.BTC.coinCode())) {
return -1;
} else if (o2.getCoinCode().equals(Coins.BTC.coinCode())) {
return 1;
} else if (o1.getCoinCode().equals(Coins.ETH.coinCode())) {
return -1;
} else if (o2.getCoinCode().equals(Coins.ETH.coinCode())) {
return 1;
} else {
return o1.getCoinCode().compareTo(o2.getCoinCode());
}
};
public static final Comparator<CoinEntity> coinEntityComparator = (o1, o2) -> 0;
public CoinListViewModel(@NonNull Application application) {
super(application);

15
app/src/main/java/com/cobo/cold/viewmodel/PublicKeyViewModel.java

@ -24,8 +24,6 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import com.cobo.coinlib.coins.EOS.Eos;
import com.cobo.coinlib.coins.IOST.Iost;
import com.cobo.cold.AppExecutors;
import com.cobo.cold.DataRepository;
import com.cobo.cold.MainApplication;
@ -47,19 +45,6 @@ public class PublicKeyViewModel extends AndroidViewModel {
}
public LiveData<String> calcPubKey(String coinId) {
AppExecutors.getInstance().diskIO().execute(() -> {
CoinEntity coin = mRepo.loadCoinSync(coinId);
List<AccountEntity> accouts = mRepo.loadAccountsForCoin(coin);
String expub = accouts.get(0).getExPub();
String pubKey = null;
if ("eos".equals(coinId)) {
pubKey = new Eos.Deriver().derive(expub, 0, 0);
} else if ("iost".equals(coinId)) {
pubKey = new Iost.Deriver().derive(expub);
}
observablePubKey.postValue(pubKey);
});
return observablePubKey;
}

25
app/src/main/java/com/cobo/cold/viewmodel/TxConfirmViewModel.java

@ -399,9 +399,6 @@ public class TxConfirmViewModel extends AndroidViewModel {
tx.setSignedHex(rawTx);
mRepository.insertTx(tx);
signState.postValue(STATE_SIGN_SUCCESS);
if (Coins.showPublicKey(tx.getCoinCode())) {
persistAddress(tx.getCoinCode(), tx.getCoinId(), tx.getFrom());
}
new ClearTokenCallable().call();
}
@ -412,28 +409,6 @@ public class TxConfirmViewModel extends AndroidViewModel {
};
}
private void persistAddress(String coinCode, String coinId, String address) {
String path;
switch (coinCode) {
case "EOS":
path = "M/44'/194'/0'/0/0";
break;
case "IOST":
path = "M/44'/291'/0'/0'/0'";
break;
default:
return;
}
AddressEntity addressEntity = new AddressEntity();
addressEntity.setPath(path);
addressEntity.setAddressString(address);
addressEntity.setCoinId(coinId);
addressEntity.setIndex(0);
addressEntity.setName(coinCode + "-0");
addressEntity.setBelongTo(Utilities.getCurrentBelongTo(getApplication()));
mRepository.insertAddress(addressEntity);
}
private void signTransaction(@NonNull AbsTx transaction, @NonNull SignCallback callback, Signer... signer) {
callback.startSign();
if (signer == null) {

BIN
app/src/main/res/drawable-xhdpi/coin_ada.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_bch.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_dash.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 840 B

BIN
app/src/main/res/drawable-xhdpi/coin_dcr.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_eos.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_eos_token.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_etc.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_eth.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_eth_token.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_iost.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_iost_token.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_lbtc.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_ltc.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_tron.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_tron_token.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_xrp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

BIN
app/src/main/res/drawable-xhdpi/coin_xzc.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 813 B

2
app/src/main/res/layout/add_white_list.xml

@ -70,7 +70,7 @@
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="ETH" />
tools:text="BTC" />
<com.cobo.cold.ui.views.NoSuggestionEditText
android:id="@+id/name_edit"

22
app/src/main/res/navigation/nav_graph_main.xml

@ -37,9 +37,6 @@
<action
android:id="@+id/action_to_aboutFragment"
app:destination="@id/aboutFragment" />
<action
android:id="@+id/action_to_manageCoinFragment"
app:destination="@id/manageCoinFragment" />
<action
android:id="@+id/action_to_settingFragment"
app:destination="@id/settingFragment" />
@ -108,18 +105,7 @@
android:name="com.cobo.cold.ui.fragment.AboutFragment"
tools:layout="@layout/about_fragment"
android:label="AboutFragment" />
<fragment
android:id="@+id/manageCoinFragment"
android:name="com.cobo.cold.ui.fragment.main.ManageCoinFragment"
tools:layout="@layout/asset_fragment"
android:label="ManageCoinFragment">
<action
android:id="@id/action_to_home"
app:destination="@id/assetListFragment"
app:popUpTo="@id/assetListFragment"
app:popUpToInclusive="false"
app:launchSingleTop="true" />
</fragment>
<fragment
android:id="@+id/settingFragment"
android:name="com.cobo.cold.ui.fragment.setting.SettingFragment"
@ -539,10 +525,8 @@
android:label="passphraseFragment"
tools:layout="@layout/passphrase">
<action
android:id="@id/action_to_manageCoinFragment"
app:destination="@id/manageCoinFragment"
app:popUpTo="@id/assetListFragment"
app:popUpToInclusive="false" />
android:id="@+id/to_assetListFragment"
app:destination="@id/assetListFragment" />
</fragment>
</navigation>

20
app/src/main/res/navigation/nav_graph_setup.xml

@ -79,8 +79,8 @@
android:label="MnemonicInputFragment"
tools:layout="@layout/mnemonic_input_fragment">
<action
android:id="@+id/action_add_coin_type2"
app:destination="@id/manageCoinFragment" />
android:id="@id/action_to_setupSyncFragment"
app:destination="@id/setupSyncFragment" />
</fragment>
<fragment
android:id="@+id/setPasswordFragment"
@ -115,8 +115,8 @@
android:label="ConfirmMnemonicFragment"
tools:layout="@layout/mnemonic_input_fragment">
<action
android:id="@+id/action_add_coin_type1"
app:destination="@id/manageCoinFragment" />
android:id="@+id/action_to_setupSyncFragment"
app:destination="@id/setupSyncFragment" />
</fragment>
<fragment
android:id="@+id/setupSyncFragment"
@ -144,18 +144,6 @@
android:id="@+id/action_webAuthResultFragment_to_setPasswordFragment"
app:destination="@id/setPasswordFragment" />
</fragment>
<fragment
android:id="@id/manageCoinFragment"
tools:layout="@layout/manage_coin_fragment"
android:name="com.cobo.cold.ui.fragment.main.ManageCoinFragment"
android:label="ManageCoinFragment">
<action
android:id="@+id/action_manageCoin_to_manageWhiteList"
app:destination="@id/setupManageWhiteList" />
<action
android:id="@+id/action_manageCoinFragment_to_setupSyncFragment"
app:destination="@id/setupSyncFragment" />
</fragment>
<fragment
android:id="@+id/setupManageWhiteList"

81
coinlib/src/main/java/com/cobo/coinlib/coins/BCH/Bch.java

@ -1,81 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.BCH;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.BTC.Btc;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.crypto.DeterministicKey;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Bch extends Btc {
public Bch(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return "BCH";
}
public static class Tx extends Btc.Tx {
public Tx(JSONObject metaData, String coinCode)
throws JSONException, InvalidTransactionException {
super(metaData, coinCode);
}
@Override
protected void parseInput() throws JSONException, InvalidTransactionException {
JSONArray inputs = metaData.getJSONArray("inputs");
StringBuilder paths = new StringBuilder();
for (int i = 0; i < inputs.length(); i++) {
JSONObject input = inputs.getJSONObject(i);
String path = input.getString("ownerKeyPath");
checkHdPath(path, false);
paths.append(path).append(SEPARATOR);
int index = input.optInt("index");
if (index == 0) {
input.put("index", 0);
}
inputAmount += input.getLong("value");
}
hdPath = paths.deleteCharAt(paths.length() - 1).toString();
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String xPubKey, int changeIndex, int addrIndex) {
DeterministicKey address = getAddrDeterministicKey(xPubKey, changeIndex, addrIndex);
LegacyAddress addr = LegacyAddress.fromPubKeyHash(MAINNET, address.getPubKeyHash());
return addr.toBase58();
}
@Override
public String derive(String xPubKey) {
return LegacyAddress.fromPubKeyHash(MAINNET,
getDeterministicKey(xPubKey).getPubKeyHash()).toBase58();
}
}
}

80
coinlib/src/main/java/com/cobo/coinlib/coins/DASH/Dash.java

@ -1,80 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.DASH;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.BTC.Btc;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.Coins;
import org.bitcoinj.core.Base58;
import org.bitcoinj.crypto.DeterministicKey;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Dash extends Btc {
public Dash(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.DASH.coinCode();
}
public static class Tx extends Btc.Tx {
public Tx(JSONObject metaData, String coinCode) throws JSONException, InvalidTransactionException {
super(metaData, coinCode);
}
@Override
protected void parseInput() throws JSONException, InvalidTransactionException {
JSONArray inputs = metaData.getJSONArray("inputs");
StringBuilder paths = new StringBuilder();
for (int i = 0; i < inputs.length(); i++) {
JSONObject input = inputs.getJSONObject(i);
String path = input.getString("ownerKeyPath");
checkHdPath(path, false);
paths.append(path).append(SEPARATOR);
int index = input.optInt("index");
if (index == 0) {
input.put("index", 0);
}
inputAmount += input.getLong("value");
}
hdPath = paths.deleteCharAt(paths.length() - 1).toString();
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String xPubKey, int changeIndex, int addrIndex) {
DeterministicKey address = getAddrDeterministicKey(xPubKey, changeIndex, addrIndex);
return Base58.encodeChecked(0x4c, address.getPubKeyHash());
}
@Override
public String derive(String xPubKey) {
return Base58.encodeChecked(0x4c, getDeterministicKey(xPubKey).getPubKeyHash());
}
}
}

121
coinlib/src/main/java/com/cobo/coinlib/coins/DCR/Dcr.java

@ -1,121 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.DCR;
import com.cobo.coinlib.coins.AbsCoin;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.AbsTx;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.Coins;
import org.bitcoinj.crypto.DeterministicKey;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import fr.cryptohash.BLAKE256;
import fr.cryptohash.Digest;
import fr.cryptohash.RIPEMD160;
public class Dcr extends AbsCoin implements Coin {
public Dcr(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.DCR.coinCode();
}
public static class Tx extends AbsTx {
public Tx(JSONObject object, String coinCode) throws JSONException, InvalidTransactionException {
super(object, coinCode);
}
@Override
protected void parseMetaData() throws JSONException {
parseInput();
to = metaData.getString("to");
amount = metaData.getLong("amount") / Math.pow(10, decimal);
memo = metaData.optString("memo");
fee = metaData.getLong("fee") / Math.pow(10, decimal);
}
private void parseInput() throws JSONException {
JSONArray inputs = metaData.getJSONArray("inputs");
for (int i = 0; i < inputs.length(); i++) {
JSONObject input = inputs.getJSONObject(i);
int index = input.optInt("outputIndex");
if (index == 0) {
input.put("outputIndex", 0);
}
}
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String xPubKey, int changeIndex, int addrIndex) {
DeterministicKey address = getAddrDeterministicKey(xPubKey, changeIndex, addrIndex);
byte[] hash = blake256Ripemd160(address.getPubKey());
return encodeChecked(hash);
}
@Override
public String derive(String xPubKey) {
return encodeChecked(blake256Ripemd160(getDeterministicKey(xPubKey).getPubKey()));
}
private byte[] blake256Ripemd160(byte[] publicKey) {
Digest digestBlake256 = new BLAKE256().copy();
digestBlake256.update(publicKey);
byte[] hash1 = digestBlake256.digest();
Digest digest160 = new RIPEMD160().copy();
digest160.update(hash1);
return digest160.digest();
}
private String encodeChecked(byte[] payload) {
// A stringified buffer is:
// 2 byte version + data bytes + 4 bytes check code (a truncated hash)
byte[] versionBytes = new byte[]{0x07, 0x3f};
byte[] addressBytes = new byte[2 + payload.length + 4];
addressBytes[0] = versionBytes[0];
addressBytes[1] = versionBytes[1];
System.arraycopy(payload, 0, addressBytes, 2, payload.length);
byte[] checksum = doubleBlake256(addressBytes, 0, payload.length + 2);
System.arraycopy(checksum, 0, addressBytes, payload.length + 2, 4);
return org.bitcoinj.core.Base58.encode(addressBytes);
}
private byte[] doubleBlake256(byte[] data, int offset, int length) {
Digest digest = new BLAKE256().copy();
digest.update(data, offset, length);
return digest.digest(digest.digest());
}
}
}

116
coinlib/src/main/java/com/cobo/coinlib/coins/EOS/Eos.java

@ -1,116 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.EOS;
import android.text.TextUtils;
import com.cobo.coinlib.coins.AbsCoin;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.AbsTx;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import org.bitcoinj.core.Base58;
import org.bitcoinj.crypto.DeterministicKey;
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
import org.json.JSONException;
import org.json.JSONObject;
import static com.cobo.coinlib.Util.concat;
public class Eos extends AbsCoin {
public Eos(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return "EOS";
}
public static class Tx extends AbsTx {
public Tx(JSONObject object, String coinCode) throws JSONException, InvalidTransactionException {
super(object, coinCode);
}
@Override
protected void parseMetaData() throws JSONException {
JSONObject data = metaData.getJSONObject("data");
to = data.getString("to");
from = data.getString("from");
memo = data.optString("memo");
int decimal = data.optInt("decimal");
if (decimal == 0) {
data.put("decimal", this.decimal);
decimal = this.decimal;
}
amount = (double) data.getLong("amount") / Math.pow(10, decimal);
fee = (double) data.optLong("fee") / Math.pow(10, decimal);
String symbol = data.optString("symbol");
if (!TextUtils.isEmpty(symbol) && !"EOS".equals(symbol)) {
isToken = true;
tokenName = symbol;
}
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String accountXpub, int changeIndex, int addressIndex) {
DeterministicKey address = getAddrDeterministicKey(accountXpub, 0, 0);
return getEosPubKey(address);
}
@Override
public String derive(String xPubKey) {
return getEosPubKey(getDeterministicKey(xPubKey));
}
private String getEosPubKey(DeterministicKey address) {
byte[] pubkeyByte = address.getPubKey();
byte[] csum = ripeMD160Hash(pubkeyByte);
csum = copy(csum, 0, 4);
byte[] addy = concat(pubkeyByte, csum);
return "EOS" + Base58.encode(addy);
}
static byte[] ripeMD160Hash(byte[] pubKey) {
RIPEMD160Digest ripemd160 = new RIPEMD160Digest();
ripemd160.update(pubKey, 0, pubKey.length);
byte[] output = new byte[ripemd160.getDigestSize()];
ripemd160.doFinal(output, 0);
return output;
}
public static byte[] copy(byte[] src, int start, int length) {
byte[] c = new byte[length];
System.arraycopy(src, start, c, 0, length);
return c;
}
public static byte[] copy(byte[] src, int start, byte[] dest, int dstart, int length) {
System.arraycopy(src, start, dest, dstart, length);
return dest;
}
}
}

47
coinlib/src/main/java/com/cobo/coinlib/coins/ETC/Etc.java

@ -1,47 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.ETC;
import com.cobo.coinlib.coins.ETH.Eth;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.Coins;
import org.json.JSONException;
import org.json.JSONObject;
public class Etc extends Eth {
public Etc(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.ETC.coinCode();
}
public static class Tx extends Eth.Tx {
public Tx(JSONObject metaData, String coinCode) throws JSONException, InvalidTransactionException {
super(metaData, coinCode);
}
}
public static class Deriver extends Eth.Deriver {
}
}

172
coinlib/src/main/java/com/cobo/coinlib/coins/ETH/Eth.java

@ -1,172 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.ETH;
import android.text.TextUtils;
import com.cobo.coinlib.coins.AbsCoin;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.AbsTx;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.Coins;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.DeterministicKey;
import org.bouncycastle.jcajce.provider.digest.Keccak;
import org.bouncycastle.util.encoders.Hex;
import org.json.JSONException;
import org.json.JSONObject;
import java.math.BigDecimal;
import java.util.Arrays;
import static com.cobo.coinlib.Util.cleanHexPrefix;
import static com.cobo.coinlib.Util.sha3String;
public class Eth extends AbsCoin implements Coin {
public Eth(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.ETH.coinCode();
}
public static class Tx extends AbsTx {
public Tx(JSONObject metaData, String coinCode) throws JSONException, InvalidTransactionException {
super(metaData, coinCode);
}
private int tokenDecimal;
@Override
protected void parseMetaData() throws InvalidTransactionException {
try {
fee = calculateDisplayFee();
if (metaData.has("override")) {
JSONObject override = metaData.getJSONObject("override");
tokenDecimal = override.optInt("decimals", decimal);
isToken = true;
tokenName = override.optString("tokenShortName",
metaData.optString("tokenFullName", coinCode));
String contractAddress = override.optString("contractAddress");
if (TextUtils.isEmpty(contractAddress)) {
throw new InvalidTransactionException("invalid contractAddress");
}
metaData.put("contractAddress", contractAddress);
}
to = metaData.getString("to");
amount = calculateDisplayAmount();
memo = metaData.optString("memo");
boolean enableMemo = false;
if (!TextUtils.isEmpty(memo) && !enableMemo) {
metaData.put("memo", "");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public double getAmount() {
if (isToken) {
return getAmountWithoutFee();
} else {
return super.getAmount();
}
}
private double calculateDisplayFee() throws JSONException {
BigDecimal gasPrice = new BigDecimal(metaData.getString("gasPrice"));
BigDecimal gasLimit = new BigDecimal(metaData.getString("gasLimit"));
return gasLimit.multiply(gasPrice)
.divide(BigDecimal.TEN.pow(decimal), Math.min(decimal, 8), BigDecimal.ROUND_HALF_UP).doubleValue();
}
private double calculateDisplayAmount() throws JSONException {
int decimal = isToken ? tokenDecimal : this.decimal;
String amount = metaData.getString("value");
BigDecimal value = new BigDecimal(amount);
return value.divide(BigDecimal.TEN.pow(decimal), Math.min(decimal, 8), BigDecimal.ROUND_HALF_UP).doubleValue();
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String accountXpub, int changeIndex, int addrIndex) {
DeterministicKey address = getAddrDeterministicKey(accountXpub, changeIndex, addrIndex);
//decompress
ECKey eckey = ECKey.fromPublicOnly(address.getPubKeyPoint());
byte[] pubKey = eckey.decompress().getPubKey();
byte[] hash = new byte[pubKey.length - 1];
System.arraycopy(pubKey, 1, hash, 0, hash.length);
String s = Hex.toHexString(getAddress(hash));
//checksum
return toChecksumAddress(s);
}
@Override
public String derive(String xPubKey) {
DeterministicKey key = getDeterministicKey(xPubKey);
//decompress
ECKey eckey = ECKey.fromPublicOnly(key.getPubKey());
byte[] pubKey = eckey.decompress().getPubKey();
byte[] hash = new byte[pubKey.length - 1];
System.arraycopy(pubKey, 1, hash, 0, hash.length);
String s = Hex.toHexString(getAddress(hash));
//checksum
return toChecksumAddress(s);
}
public static byte[] getAddress(byte[] publicKey) {
byte[] hash = new Keccak.Digest256().digest(publicKey);
return Arrays.copyOfRange(hash, hash.length - 20, hash.length); // right most 160 bits
}
public static String toChecksumAddress(String address) {
String lowercaseAddress = cleanHexPrefix(address).toLowerCase();
String addressHash = cleanHexPrefix(sha3String(lowercaseAddress));
StringBuilder result = new StringBuilder(lowercaseAddress.length() + 2);
result.append("0x");
for (int i = 0; i < lowercaseAddress.length(); i++) {
if (Integer.parseInt(String.valueOf(addressHash.charAt(i)), 16) >= 8) {
result.append(String.valueOf(lowercaseAddress.charAt(i)).toUpperCase());
} else {
result.append(lowercaseAddress.charAt(i));
}
}
return result.toString();
}
}
}

83
coinlib/src/main/java/com/cobo/coinlib/coins/IOST/Iost.java

@ -1,83 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.IOST;
import com.cobo.coinlib.Util;
import com.cobo.coinlib.coins.AbsCoin;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.AbsTx;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.B58;
import com.cobo.coinlib.utils.Coins;
import org.json.JSONException;
import org.json.JSONObject;
import org.spongycastle.util.encoders.Hex;
public class Iost extends AbsCoin {
public Iost(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.IOST.coinCode();
}
public static class Tx extends AbsTx {
public Tx(JSONObject object, String coinCode) throws JSONException, InvalidTransactionException {
super(object, coinCode);
}
@Override
protected void parseMetaData() throws JSONException {
from = metaData.getString("from");
to = metaData.getString("to");
amount = Double.parseDouble(metaData.getString("amount"));
memo = metaData.optString("memo");
fee = Double.parseDouble(metaData.optString("fee", "0"));
tokenName = metaData.optString("tokenName", "iost").toUpperCase();
if (!"IOST".equals(tokenName)) {
isToken = true;
}
}
@Override
protected void checkHdPath() throws InvalidTransactionException {
checkHdPath(hdPath, true);
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String xPubKey, int changeIndex, int addrIndex) {
String pubKeyHex = Util.pubKeyFromExtentPubKey(xPubKey).substring(2);
return new B58().encodeToString(Hex.decode(pubKeyHex));
}
@Override
public String derive(String xPubKey) {
String pubKeyHex = Util.pubKeyFromExtentPubKey(xPubKey).substring(2);
return new B58().encodeToString(Hex.decode(pubKeyHex));
}
}
}

75
coinlib/src/main/java/com/cobo/coinlib/coins/LTC/Ltc.java

@ -1,75 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.LTC;
import com.cobo.coinlib.coins.BTC.Btc;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.Coins;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.crypto.DeterministicKey;
import org.json.JSONException;
import org.json.JSONObject;
public class Ltc extends Btc {
public Ltc(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.LTC.coinCode();
}
public static class Tx extends Btc.Tx {
public Tx(JSONObject metaData, String coinCode) throws JSONException, InvalidTransactionException {
super(metaData, coinCode);
}
}
public static class Deriver extends Btc.Deriver {
static final boolean legacyAddress = true;
@Override
public String derive(String xPubKey, int changeIndex, int addrIndex) {
if (legacyAddress) {
return super.derive(xPubKey, changeIndex, addrIndex);
}
DeterministicKey address = getAddrDeterministicKey(xPubKey, changeIndex, addrIndex);
LegacyAddress addr = LegacyAddress.fromScriptHash(MAINNET,
segWitOutputScript(address.getPubKeyHash()).getPubKeyHash());
return Base58.encodeChecked(0x32, addr.getHash());
}
@Override
public String derive(String xPubKey) {
if (legacyAddress) {
return super.derive(xPubKey);
}
LegacyAddress addr = LegacyAddress.fromScriptHash(MAINNET,
segWitOutputScript(getDeterministicKey(xPubKey).getPubKeyHash()).getPubKeyHash());
return Base58.encodeChecked(0x32, addr.getHash());
}
}
}

107
coinlib/src/main/java/com/cobo/coinlib/coins/TRON/Tron.java

@ -1,107 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.TRON;
import com.cobo.coinlib.coins.AbsCoin;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.AbsTx;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.Coins;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.DeterministicKey;
import org.json.JSONException;
import org.json.JSONObject;
import static com.cobo.coinlib.coins.ETH.Eth.Deriver.getAddress;
public class Tron extends AbsCoin {
public Tron(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.TRON.coinCode();
}
public static class Tx extends AbsTx {
public Tx(JSONObject object, String coinCode) throws JSONException, InvalidTransactionException {
super(object, coinCode);
}
@Override
protected void parseMetaData() throws JSONException {
from = metaData.getString("from");
to = metaData.getString("to");
fee = metaData.getInt("fee") / Math.pow(10, decimal);
amount = metaData.getLong("value") / Math.pow(10, decimal);
memo = metaData.optString("memo");
if ((metaData.has("token") || metaData.has("contractAddress"))
&& metaData.has("override")) {
isToken = true;
JSONObject override = metaData.getJSONObject("override");
tokenName = override.optString("tokenShortName",
metaData.optString("tokenFullName", coinCode));
int tokenDecimals = override.optInt("decimals");
amount = metaData.getLong("value") / Math.pow(10, tokenDecimals);
}
}
@Override
public double getAmount() {
if (isToken) {
return getAmountWithoutFee();
} else {
return super.getAmount();
}
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String accountXpub, int changeIndex, int addrIndex) {
DeterministicKey address = getAddrDeterministicKey(accountXpub, changeIndex, addrIndex);
ECKey eckey = ECKey.fromPublicOnly(address.getPubKeyPoint());
byte[] pubKey = eckey.decompress().getPubKey();
byte[] hash = new byte[pubKey.length - 1];
System.arraycopy(pubKey, 1, hash, 0, hash.length);
byte[] addr = getAddress(hash);
return Base58.encodeChecked(0x41, addr);
}
@Override
public String derive(String xPubKey) {
ECKey eckey = ECKey.fromPublicOnly(getDeterministicKey(xPubKey).getPubKeyPoint());
byte[] pubKey = eckey.decompress().getPubKey();
byte[] hash = new byte[pubKey.length - 1];
System.arraycopy(pubKey, 1, hash, 0, hash.length);
byte[] addr = getAddress(hash);
return Base58.encodeChecked(0x41, addr);
}
}
}

75
coinlib/src/main/java/com/cobo/coinlib/coins/XRP/Xrp.java

@ -1,75 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.XRP;
import com.cobo.coinlib.coins.AbsCoin;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.AbsTx;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.B58;
import com.cobo.coinlib.utils.Coins;
import org.bitcoinj.crypto.DeterministicKey;
import org.json.JSONException;
import org.json.JSONObject;
public class Xrp extends AbsCoin implements Coin {
public static final String DEFAULT_ALPHABET = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
public Xrp(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.XRP.coinCode();
}
public static class Tx extends AbsTx {
public Tx(JSONObject object, String coinCode) throws JSONException, InvalidTransactionException {
super(object, coinCode);
}
@Override
protected void parseMetaData() throws JSONException {
to = metaData.getString("to");
amount = metaData.getLong("amount") / Math.pow(10, decimal);
memo = metaData.optString("memo");
fee = metaData.getLong("fee") / Math.pow(10, decimal);
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String xPubKey, int changeIndex, int addrIndex) {
DeterministicKey address = getAddrDeterministicKey(xPubKey, changeIndex, addrIndex);
return new B58(DEFAULT_ALPHABET).encodeToStringChecked(address.getPubKeyHash(), 0);
}
@Override
public String derive(String xPubKey) {
return new B58(DEFAULT_ALPHABET)
.encodeToStringChecked(getDeterministicKey(xPubKey).getPubKeyHash(), 0);
}
}
}

83
coinlib/src/main/java/com/cobo/coinlib/coins/XZC/Xzc.java

@ -1,83 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coins.XZC;
import com.cobo.coinlib.coins.AbsCoin;
import com.cobo.coinlib.coins.AbsDeriver;
import com.cobo.coinlib.coins.AbsTx;
import com.cobo.coinlib.exception.InvalidTransactionException;
import com.cobo.coinlib.interfaces.Coin;
import com.cobo.coinlib.utils.Coins;
import org.bitcoinj.core.Base58;
import org.bitcoinj.crypto.DeterministicKey;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Xzc extends AbsCoin implements Coin {
public Xzc(Coin impl) {
super(impl);
}
@Override
public String coinCode() {
return Coins.XZC.coinCode();
}
public static class Tx extends AbsTx {
public Tx(JSONObject object, String coinCode) throws JSONException, InvalidTransactionException {
super(object, coinCode);
}
@Override
protected void parseMetaData() throws JSONException {
parseInput();
to = metaData.getString("to");
amount = metaData.getLong("amount") / Math.pow(10, decimal);
memo = metaData.optString("memo");
fee = metaData.getLong("fee") / Math.pow(10, decimal);
}
private void parseInput() throws JSONException {
JSONArray inputs = metaData.getJSONArray("inputs");
for (int i = 0; i < inputs.length(); i++) {
JSONObject input = inputs.getJSONObject(i);
int index = input.optInt("outputIndex");
if (index == 0) {
input.put("outputIndex", 0);
}
}
}
}
public static class Deriver extends AbsDeriver {
@Override
public String derive(String xPubKey, int changeIndex, int addrIndex) {
DeterministicKey address = getAddrDeterministicKey(xPubKey, changeIndex, addrIndex);
return Base58.encodeChecked(0x52, address.getPubKeyHash());
}
@Override
public String derive(String xPubKey) {
return Base58.encodeChecked(0x52, getDeterministicKey(xPubKey).getPubKeyHash());
}
}
}

15
coinlib/src/main/java/com/cobo/coinlib/interfaces/Signer.java

@ -36,19 +36,6 @@ public abstract class Signer {
public abstract String sign(String hex);
public static boolean shouldProvidePublicKey(@NonNull String coinCode) {
switch (coinCode) {
case "BTC":
case "XRP":
case "BCH":
case "LTC":
case "DASH":
case "IOST":
case "XZC":
case "DCR":
return true;
default:
return false;
}
return true;
}
}

53
coinlib/src/main/java/com/cobo/coinlib/utils/Coins.java

@ -24,33 +24,11 @@ import java.util.List;
import java.util.Optional;
public class Coins {
public static final Coin BTC = new Coin("bitcoin", "BTC", "Bitcoin", 0);
public static final Coin BCH = new Coin("bitcoin_cash", "BCH", "Bitcoin Cash", 145);
public static final Coin DASH = new Coin("dash", "DASH", "Dash", 5);
public static final Coin LTC = new Coin("litecoin", "LTC", "Litecoin", 2);
public static final Coin ETH = new Coin("ethereum", "ETH", "Ethereum", 60);
public static final Coin ETC = new Coin("ethereum_classic", "ETC", "Ethereum Classic", 61);
public static final Coin TRON = new Coin("tron", "TRON", "Tron", 195);
public static final Coin DCR = new Coin("dcr", "DCR", "Dcr", 42);
public static final Coin XZC = new Coin("zcoin", "XZC", "Zcoin", 136);
public static final Coin XRP = new Coin("ripple", "XRP", "Ripple", 144);
public static final Coin IOST = new Coin("iost", "IOST", "IOST", 291, CURVE.ED25519);
public static final Coin EOS = new Coin("eos", "EOS", "EOS", 194);
public static final List<Coin> SUPPORTED_COINS = Arrays.asList(
BTC,
ETC,
ETH,
BCH,
DASH,
LTC,
TRON,
DCR,
XZC,
XRP,
IOST,
EOS
BTC
);
public static boolean isCoinSupported(@NonNull String coinCode) {
@ -58,15 +36,7 @@ public class Coins {
}
public static boolean supportMultiSigner(@NonNull String coinCode) {
switch (coinCode) {
case "BTC":
case "BCH":
case "LTC":
case "DASH":
return true;
default:
return false;
}
return true;
}
public static String coinCodeFromCoinId(String coinId) {
@ -153,24 +123,11 @@ public class Coins {
}
public static int purposeNumber(String coinCode) {
switch (coinCode) {
case "BTC":
case "XTN":
case "LTC":
return 49;
default:
return 44;
}
return 49;
}
public static boolean showPublicKey(String coinCode) {
switch (coinCode) {
case "EOS":
case "IOST":
return true;
default:
return false;
}
return false;
}
}

8
coinlib/src/main/java/com/cobo/coinlib/v8/CoinImpl.java

@ -159,13 +159,7 @@ public class CoinImpl implements Coin {
}
private void addOption(V8Array params) {
switch (coinCode) {
case "BTC":
case "LTC":
params.push("P2SH");
case "BCH":
params.push("P2PKH");
}
params.push("P2SH");
}
class SignProviderCallback implements JavaCallback {

18
coinlib/src/test/java/com/cobo/coinlib/CoinsTest.java

@ -26,7 +26,6 @@ import org.junit.Test;
import static com.cobo.coinlib.path.CoinPath.m;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class CoinsTest {
@ -34,7 +33,6 @@ public class CoinsTest {
public void testCoinCode() {
assertEquals(Coins.coinCodeFromCoinId("bitcoin"), "BTC");
assertEquals(Coins.coinIdFromCoinCode("BTC"), "bitcoin");
assertEquals(Coins.coinCodeOfIndex(60), "ETH");
}
@Test
@ -52,32 +50,16 @@ public class CoinsTest {
@Test
public void testCurve() {
assertEquals(Coins.CURVE.SECP256K1, Coins.curveFromCoinCode("BTC"));
assertEquals(Coins.CURVE.ED25519, Coins.curveFromCoinCode("IOST"));
}
@Test
public void purposeNumber() {
assertEquals(Coins.purposeNumber("BTC"), 49);
assertEquals(Coins.purposeNumber("XTN"), 49);
assertEquals(Coins.purposeNumber("LTC"), 49);
assertEquals(Coins.purposeNumber("ETH"), 44);
assertEquals(Coins.purposeNumber("ETC"), 44);
}
@Test
public void testSupportedCoin() {
assertTrue(Coins.isCoinSupported("BTC"));
assertTrue(Coins.isCoinSupported("BCH"));
assertTrue(Coins.isCoinSupported("ETC"));
assertTrue(Coins.isCoinSupported("ETH"));
assertTrue(Coins.isCoinSupported("LTC"));
assertTrue(Coins.isCoinSupported("TRON"));
assertTrue(Coins.isCoinSupported("DASH"));
assertTrue(Coins.isCoinSupported("XZC"));
assertTrue(Coins.isCoinSupported("DCR"));
assertTrue(Coins.isCoinSupported("IOST"));
assertTrue(Coins.isCoinSupported("EOS"));
assertTrue(Coins.isCoinSupported("DASH"));
assertFalse(Coins.isCoinSupported("ABC"));
}
}

50
coinlib/src/test/java/com/cobo/coinlib/coin/BchTest.java

@ -1,50 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.BCH.Bch;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class BchTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"1HXQeKa8YSg1bEoToLqxXcHfm4Wrt4qk3V",
"18ZyEqa4ioSiTztN5zHRNoQCr5ZYtMNTjJ",
"18xv4x9EJzCQ8JGQWdBELL8tJUD7BHNYkf",
"1CGn89GG6o6aLSotHc1YZWoJ6jnKaCiWcH",
"16ruo7A9NGzqwpdatMMKaE1yWA6cfKXmrU",
"1C5QXNRmNVdEyh91nSrKp66TS1tkaFn5Jy",
"1Nk2jDqbMbxQNUcgRw17eiByUBw7s1VbC2",
"1NYx23tK96Utp75rXZGbY3YJfAGqjBdVhn",
"1EVdGw9JLbSFLaRHrWrQp7ULWM4px51725",
"19emQ5tpdoYDKd3aia7wo9PQtwej88bpsz",
"1JBKtGPGXPFb3pDeK1cF8czdgvYMzaxyE5"
};
String pubKey = "xpub6CjD9XYc1hEKcAMsSasAA87Mw8bSUr6WQKrJ1ErLofJPP9sxeZ3sh1dH2S5ywQTRNrXsfXzT686jJNdX2m9KhvMDh4eQM9AdSkkQLLMbDG6";
for (int i = 0 ; i < addr.length; i++) {
String address = new Bch.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

60
coinlib/src/test/java/com/cobo/coinlib/coin/DashTest.java

@ -1,60 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.DASH.Dash;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class DashTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"XciiKrSHgdFkuL9FTT31qRfTPNUVxX4sPc",
"XgTmuNhRLoj4F75TqboUgZQVQ37HCgW9Hf",
"Xpj2zS65KN6r792TQKuAMeJpLMdknrjo1y",
"Xb9LAffWjcxTCN5GMj5kbZiqN5g7nnkgrv",
"XyAT2tRaXhdZ4JvvB44Jy9S4qd6JurzaVo",
"XntqLKJvZbkauFvGLWHsGNMh51K5eiHvHT",
"XuMqWDM3eabLrze4hnLDtwvzBfQVSNjdqk",
"Xj3Q7zDq3BYmiPNHrwMgtPNgSKYQyQTs97",
"XmWeKAdw3DPcFvRFhro8brzhpqPoxvGdny",
"XfYy4fYEXa6ikpfzsSZS537yjoN3Mhstsv",
"XyuGNJoxmUiA1unZ7JKiG2g5WS69sDKFBP",
};
String pubKey = "xpub6DTnbXgbPo6mrRhgim9sg7Jp571onenuioxgfSDJEREH7wudyDQMDSoTdLQiYq3tbvZVkzcPe7nMgL7mbSixQQcShekfhKt3Wdx6dE8MHCk";
for (int i = 0 ; i < addr.length; i++) {
String address = new Dash.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

60
coinlib/src/test/java/com/cobo/coinlib/coin/DcrTest.java

@ -1,60 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.DCR.Dcr;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class DcrTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"DsYvV7Q6ymU2WFzBFdVzNyUk7UXAE2dVyYd",
"DsbTLcGY9NHNqVvQZrJyXLcLN76SVrzBodq",
"DsTznosWuFjz94pjTKoAaEWd8LUVdCYfBfc",
"DsWzdC3CtWPy5ZqY7pTQH35Gm5JhH9mMe2c",
"DsbWz3eYSPRJk8DnehixbaDAXcVhUdz4p9u",
"DsmpowTXxpUxYwtwHgSHoixsCBcJ4gZZCZ7",
"Dsf2hAR1ZainZdRFY4fWi1ZM6vPJevsuXfn",
"DsSHLUANtfo82zVyLiTgi6SWQZdgSXAYrAc",
"Dsa76GyVEETpToSvWATPUtiXSpPbNmQHwg1",
"DsiC8hxMC2ApnouYUwMK1L4c3wbHezq5Gwb",
"DsgKnFzMq6kz4JWYWfaywo3LNhMBhJZZsDS",
};
String pubKey = "xpub6BmQYH48mM1hm8B2TDXg7oDfa7dZfHVgi7pWFMsmSuJ3rVwi2YEgjZMN1cBFQtieHPgmoY3YQx5G85XyxMvppPxJToxmWjo64gaNutTn6iw";
for (int i = 0 ; i < addr.length; i++) {
String address = new Dcr.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

46
coinlib/src/test/java/com/cobo/coinlib/coin/EosTest.java

@ -1,46 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.EOS.Eos;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class EosTest {
@Test
public void deriveAddress() {
String pubKey = "xpub6BffWuUvhRpycrEq9H2gQDNT1xtzu2pfNvaf2j6JMxErTFbwAX7yaL5hCocYJwaKxmYgpNuoXkGFKHQv2brE1XEmX1aneH3AHtUrR8tMV6H";
String address = new Eos.Deriver().derive(pubKey,0,0);
assertEquals(address,"EOS86B1XBB2B7u3QcdM5tuuTdRMLFfVDzsTcjHvDqcFq78MSstUxp");
}
}

60
coinlib/src/test/java/com/cobo/coinlib/coin/EtcTest.java

@ -1,60 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.ETC.Etc;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class EtcTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"0xff1e8f0F67b9C9DEA103ca988831DD9C54acA876",
"0x95662DfB520aaBE3B3E550675F90Ea05d52ecB5D",
"0x50a577fdd4ac9d2e2711C0b9887E518FfE1879d5",
"0xf00A5c61d7411D1Cb8231e9618b7851B4243092c",
"0x4a9B9e31EFbBade790725CE31F257f0d7D7b2f2c",
"0xaEE81b0b6b7c409dbB3cA2839f91C172E75Ab781",
"0xD697eC336A037B047c397464C354982b16fa784B",
"0x2046CfE33bb5B65A183414FCCB9CB9022dff9dA1",
"0xF8F353e88F761faa2a5f721A5eCF71Dcd180c93f",
"0x5c03CC3a68be5e41c7ceBEf47939b6d387E4c5E6",
"0x95554E6679EA8E8681ceB539C733dEa9F28db119",
};
String pubKey = "xpub6BoGYciy75JfrWWm1yJJctrCnEft6RtyECCjHDuhACfmShsSbcSp5ceAZzx1YpMtLfWHCbG6bKqEH9uoUCbvMWAkjSMkMeVuYYf23nWd76X";
for (int i = 0 ; i < addr.length; i++) {
String address = new Etc.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

60
coinlib/src/test/java/com/cobo/coinlib/coin/EthTest.java

@ -1,60 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.ETH.Eth;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class EthTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"0xE410157345be56688F43FF0D9e4B2B38Ea8F7828",
"0xEEACb7a5e53600c144C0b9839A834bb4b39E540c",
"0xA116800A72e56f91cF1677D40C9984f9C9f4B2c7",
"0x4826BadaBC9894B3513e23Be408605611b236C0f",
"0x8a1503beb17Ef02cC4Ff288b0A73583c4ce547c7",
"0x996c7a5c9001da0401B61aD68EFd2424633F728E",
"0xcAC3561d0b4Bec860ADCEBD70f8E6a8A5D45D752",
"0x7173684414e3a9d5347e5d73b1E8718f3020A296",
"0x4AAb5aD4FF70D7388182068a0B74BEEBA28B5068",
"0x824C70B0000Abf51F6db46284dC217579f53f86a",
"0x56FA9453B22867E0292301b68C2A737D8879441B",
};
String pubKey = "xpub6CNhtuXAHDs84AhZj5ALZB6ii4sP5LnDXaKDSjiy6kcBbiysq89cDrLG29poKvZtX9z4FchZKTjTyiPuDeiFMUd1H4g5zViQxt4tpkronJr";
for (int i = 0 ; i < addr.length; i++) {
String address = new Eth.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

46
coinlib/src/test/java/com/cobo/coinlib/coin/IostTest.java

@ -1,46 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.IOST.Iost;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class IostTest {
@Test
public void deriveAddress() {
String pubKey = "xpub6GhXKqoStzyfom3kNWLzMFhLzir4GgPXnzwYMwurCWizsq2yXvZRHJJBny1hzA1YsepvGC9L3dSYPDY3wkuahqDsbK36cHKY4LMtV8DnARm";
String address = new Iost.Deriver().derive(pubKey);
assertEquals(address,"4guFd1weqq2Nvfxt6EDSfztUjp44trRzfJMqXumJ3qRt");
}
}

50
coinlib/src/test/java/com/cobo/coinlib/coin/LtcTest.java

@ -1,50 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.LTC.Ltc;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class LtcTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"3DYRx8E2vK8KaXA9LJ21vV4wGL4hmRYmCL",
"3Qg4Jb6GJM2vk4eDwiyouPQRAukVa5Mbk7",
"3FnRAxvQm2qbAYSWoQnv2Jb1jqruYtFhMr",
"3NAwgFJy5nuMpguT4RM1t2niQe4GDLbU1r",
"3AQR2S4tpfDMPQzj44WC6rcHh5ZbYdBcWt",
"3QkyucsqatrXJHgLoYK7WiHu8BQeBhjuXT",
"3KngFdv9BNwYoAY7uawRs49R1dWwhJM5mD",
"3PgjwKnwxgPzbPbTarLpxCx6WzYufC5DEB",
"3PHP2LRaPoiJYkWt9q6Zf2KJZdonarZVzv",
"3LARJepdkdgcByt7FrKyzBovraY8GHeXht",
"3CAzK2RGXrCMoerQ1UFdmUHDyw5t4QcR33"
};
String pubKey = "xpub6CKt97v4gEsG4FG9E4hEotEUtjmW8rAvVcUJ4jsmdrB437WBZnK8gs8ktzaFQHe9i7NqzcAUkc5SeNXsVoYfVNxd1AwDgbw2up8UdMWq91B";
for (int i = 0 ; i < addr.length; i++) {
String address = new Ltc.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

60
coinlib/src/test/java/com/cobo/coinlib/coin/TronTest.java

@ -1,60 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.TRON.Tron;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class TronTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"TYgXziK4zH4T5dchXFBseTFUpZ8kty6oQy",
"TTgPTW6oaxmRnKz1xFT2qSHx3QNEpP2jZ6",
"TWD5uP9gDo9QJcYhvoN4u4jS4b9pHV25ow",
"TTrMEb1R2iUba67yygVVzu8ny6F1R3NbaE",
"TAGkxJfAd5Xy4D6PL76HAH4WM9W7VVpCDf",
"TGAnfDpv8GhTmi2WXbvQG7LPGguX5cuMcG",
"TXSEwZGP5JDZmU9z75SHBMY1GsB7HCjWyD",
"TB2ibqfKPNxHEqQHHmVUPfVgNGEtXkJ8NL",
"TSbt9gkbJriTUXmUxgVBLxNFwWwx6e4qTw",
"TNLvDnx9jECDPTRq31KaxPkMX4zaMLQeVC",
"TSzi8byHgnEbiHo8h4X5rkcmFXxM3wpZqH",
};
String pubKey = "xpub6BmQYH48mM1hm8B2TDXg7oDfa7dZfHVgi7pWFMsmSuJ3rVwi2YEgjZMN1cBFQtieHPgmoY3YQx5G85XyxMvppPxJToxmWjo64gaNutTn6iw";
for (int i = 0 ; i < addr.length; i++) {
String address = new Tron.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

60
coinlib/src/test/java/com/cobo/coinlib/coin/XrpTest.java

@ -1,60 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.XRP.Xrp;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class XrpTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"rndm7RphBZG6CpZvKcG9AjoFbSvcKhwLCx",
"rrBD4sBsxrpzbohAEYWH4moPSsoxupWLA",
"rsc38kSbRZ74VjiNa8CG8xtkdqw2AWaXBb",
"r4Mh3Hdvk1UJJSs8tjkz9qnbxNyMD5qhYz",
"rsR6GtwgEtcJRaMrW2cNx8nwNqFovnJ32C",
"rhzrij6yt1wCwRAFgQK5VqxyxyhbNw7QR9",
"rNLCXobmiL4LbQkbjFJCWSW6XQm8XDLoCq",
"rKaNnXijwXQhyWegPkmUYchJzAxgKQjry9",
"rJ1gcRd2w38wwFNdSiqqVEuf4jYHU1fpP1",
"rE8fnyfbtdwkbumCm3aRR5dWcTHvS6pnWt",
"rLJYeuBpLdo6CY3xhc3SWt7hzYS6votewa",
};
String pubKey = "xpub6C438jHkPCDoEy5jAH4a9hBtYrcprSwGvEA8L5HNhqDyJa1WZPpZXj9DNNtsRjcHxzsuZJq18sMSkbmqYKqpDacP8aMSK63ExzX2bPoMdAo";
for (int i = 0 ; i < addr.length; i++) {
String address = new Xrp.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}

60
coinlib/src/test/java/com/cobo/coinlib/coin/XzcTest.java

@ -1,60 +0,0 @@
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cobo.coinlib.coin;
import com.cobo.coinlib.coins.XZC.Xzc;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@SuppressWarnings("ALL")
public class XzcTest {
@Test
public void deriveAddress() {
String[] addr = new String[] {
"aJtu4Ztv64yCUZYm9YzQ7b3Hyrii2foaj8",
"aJJvE5kRvBJXJWeBcxScAf2ABr4vZVCotp",
"aGQC2rasPV2tiJnFJTqbevAniozqZDPpcA",
"a6pzbbDbqgCbKupySGuVWX2QewCGcSNFac",
"a3fY53SF4CdKeWAwMcUMQMjf7Y9b9tcxqS",
"aAFzem9L6FTT6peetFMoinJVeaCE2YZWDR",
"aNZUbMNuKEKxNSKvXCdNHt8kUTZoRQ8PM2",
"a6sFxJEsvwFvKCdaxhjGf1LSWYHTAfBwEE",
"aGcTa2jiSkyFLVGsLjtJZG5kCYxtWbbUhB",
"a2gcBybNBzDqsbAU5S78ug8GUKrnm1STwS",
"aBCFtxBN915aLPYbCADQULzUv4qYiXNW3X",
};
String pubKey = "xpub6CKMZBhyfgYMeK7UuVCwF56BXsm1kVbUQwmB7bDU2i2cGx2VXNwR7Z5tnGsuZbjc35LQvhyZJasrX12adMdAqtFno9fLJJxSksPDU7W3SEk";
for (int i = 0 ; i < addr.length; i++) {
String address = new Xzc.Deriver().derive(pubKey,0,i);
assertEquals(address,addr[i]);
}
}
}
Loading…
Cancel
Save