Commit b923a4c8 authored by pokkst's avatar pokkst

Initial upload

parent efe457b7
File added
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="CrescentCashAndroid" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="CrescentPayAndroid" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
# Crescent Cash
# CrescentCash
A non-custodial Bitcoin wallet that allows you to send or receive Bitcoin using a Cash Account or Bitcoin address.
\ No newline at end of file
File added
This diff is collapsed.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "app.crescentcash.src"
minSdkVersion 21
targetSdkVersion 28
versionCode 24
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'lib/x86_64/darwin/libscrypt.dylib'
exclude 'lib/x86_64/freebsd/libscrypt.so'
exclude 'lib/x86_64/linux/libscrypt.so'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.github.kenglxn.QRGen:android:2.2.0'
implementation 'com.journeyapps:zxing-android-embedded:[email protected]'
implementation 'com.google.zxing:core:3.3.0'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":24,"versionName":"1.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="app.crescentcash.src">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- This is for API below 21 -->
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:roundIcon="@drawable/app_icon"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="portrait"
tools:replace="android:screenOrientation"
android:stateNotNeeded="true"/>
</application>
</manifest>
\ No newline at end of file
package app.crescentcash.src;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.protocols.payments.PaymentProtocolException;
import org.bitcoinj.protocols.payments.PaymentSession;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import app.crescentcash.src.net.NetHelper;
import app.crescentcash.src.ui.UIHelper;
import app.crescentcash.src.utils.Constants;
import app.crescentcash.src.utils.PermissionHelper;
import app.crescentcash.src.wallet.WalletHelper;
public class MainActivity extends AppCompatActivity {
public static MainActivity INSTANCE;
public UIHelper uiHelper;
public WalletHelper walletHelper;
public NetHelper netHelper;
public ArrayList<Transaction> txList;
public SharedPreferences prefs = null;
public static boolean isNewUser = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
INSTANCE = this;
this.setContentView(R.layout.activity_main);
this.uiHelper = new UIHelper();
this.netHelper = new NetHelper();
this.walletHelper = new WalletHelper();
this.prefs = getSharedPreferences("app.crescentcash.src", MODE_PRIVATE);
isNewUser = this.prefs.getBoolean("isNewUser", true);
if(isNewUser) {
this.uiHelper.newuser.setVisibility(View.VISIBLE);
} else {
this.walletHelper.setupWalletKit(null, "", false);
this.uiHelper.displayDownloadContent(true);
String cashAcct = MainActivity.INSTANCE.prefs.getString("cashAccount", "");
assert cashAcct != null;
if(!cashAcct.equals("") && cashAcct.contains("#???")) {
String plainName = cashAcct.replace("#???", "");
this.walletHelper.registeredBlock = "???";
String cashAcctTx = MainActivity.INSTANCE.prefs.getString("cashAcctTx", "null");
this.walletHelper.registeredTxHash = cashAcctTx;
this.netHelper.initialAccountIdentityCheck(plainName);
this.walletHelper.timer = new CountDownTimer(150000, 20) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
try{
netHelper.checkForAccountIdentity(plainName);
}catch(Exception e){
Log.e("Error", "Error: " + e.toString());
}
}
}.start();
}
}
PermissionHelper permissionHelper = new PermissionHelper();
permissionHelper.askForPermissions(this, this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (scanResult != null) {
String address = scanResult.getContents();
if(address != null) {
if (address.contains(Constants.IS_PRODUCTION ? "bitcoincash:" : "bchtest:")) {
String addressFixed = address.replace(Constants.IS_PRODUCTION ? "bitcoincash:" : "bchtest:", "");
//url variable for BitPay invoice IDs
if (addressFixed.contains("?r=")) {
String addressFixed2 = addressFixed.replace("?r=", "");
this.uiHelper.displayRecipientAddress(addressFixed2);
String url = addressFixed2;
ListenableFuture<PaymentSession> future;
if (url.startsWith("https")) {
try {
future = PaymentSession.createFromUrl(url);
PaymentSession session = future.get();
Coin amountWanted = session.getValue();
this.runOnUiThread(() -> uiHelper.getAmountText().setText(amountWanted.toPlainString()));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (PaymentProtocolException e) {
e.printStackTrace();
}
}
}
else
{
this.uiHelper.displayRecipientAddress(addressFixed);
}
} else {
this.uiHelper.displayRecipientAddress(address);
}
}
}
}
@Override
public void onBackPressed() {
if(this.uiHelper.new_wallet.getVisibility() == View.VISIBLE) {
this.uiHelper.new_wallet.setVisibility(View.GONE);
this.uiHelper.newuser.setVisibility(View.VISIBLE);
}
else if(this.uiHelper.restore_wallet.getVisibility() == View.VISIBLE) {
this.uiHelper.restore_wallet.setVisibility(View.GONE);
this.uiHelper.newuser.setVisibility(View.VISIBLE);
}
else if(this.uiHelper.sendWindow.getVisibility() == View.VISIBLE) {
this.uiHelper.sendWindow.setVisibility(View.GONE);
}
else if(this.uiHelper.receiveWindow.getVisibility() == View.VISIBLE) {
this.uiHelper.receiveWindow.setVisibility(View.GONE);
}
else if(this.uiHelper.historyWindow.getVisibility() == View.VISIBLE) {
this.uiHelper.historyWindow.setVisibility(View.GONE);
}
else if(this.uiHelper.walletSettings.getVisibility() == View.VISIBLE) {
this.uiHelper.walletSettings.setVisibility(View.GONE);
}
else {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
package app.crescentcash.src.hash;
import org.spongycastle.util.encoders.Hex;
import java.security.MessageDigest;
public class HashHelper {
public static String SHA256(String value)
{
try{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(value.getBytes());
return bytesToHex(md.digest());
} catch(Exception ex){
throw new RuntimeException(ex);
}
}
private static String SHA256_Hex(String value)
{
try{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(Hex.decode(value.getBytes()));
return bytesToHex(md.digest());
} catch(Exception ex){
throw new RuntimeException(ex);
}
}
private static String bytesToHex(byte[] bytes)
{
StringBuilder result = new StringBuilder();
for (byte b : bytes) result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
return result.toString();
}
public String getCashAccountCollision(String block, String txHash) {
String collisionNumber;
System.out.println(block);
System.out.println(txHash);
String concatenatedTest = block.toLowerCase() + txHash.toLowerCase();
System.out.println(concatenatedTest);
String hashedConcatenated = SHA256_Hex(concatenatedTest);
System.out.println(hashedConcatenated);
String firstFourBytes = hashedConcatenated.substring(0, 8);
System.out.println(firstFourBytes);
long decimalNotation = getUnsignedInt(hexToDecimal(firstFourBytes));
System.out.println(decimalNotation);
String reverseDecimalNotation = new StringBuilder(decimalNotation+"").reverse().toString();
System.out.println(reverseDecimalNotation);
String paddedDecimal = padString(reverseDecimalNotation);
System.out.println(paddedDecimal);
collisionNumber = paddedDecimal;
return collisionNumber;
}
private int hexToDecimal(String hex){
String digits = "0123456789ABCDEF";
hex = hex.toUpperCase();
int val = 0;
for (int i = 0; i < hex.length(); i++)
{
char c = hex.charAt(i);
int d = digits.indexOf(c);
val = 16*val + d;
}
return val;
}
/*
Using Long.parseUnsignedLong(hexString, 16); instead would require a higher minimum API in the build.gradle file, which means fewer supported devices
So, we are using this amazing hack.
*/
private long getUnsignedInt(int x) {
return x & 0x00000000ffffffffL;
}
private String padString(String input)
{
int length = input.length();
StringBuilder newString = new StringBuilder(input);
if(length < 10)
{
for(int x = length; x < 10; x++)
newString.append("0");
}
return newString.toString();
}
}
package app.crescentcash.src.json;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.Reader;
public class JSONHelper {
public static String readJSONFile(Reader rd) throws IOException {
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) {
sb.append((char) cp);
}
return sb.toString();
}
public String getRegisterTxHash(String jsonResponse)
{
String hash = "";
try {
JSONObject json = new JSONObject(jsonResponse);
hash = json.getString("txid");
} catch (JSONException e) {
e.printStackTrace();
}
return hash;
}
}
This diff is collapsed.
package app.crescentcash.src.qr;
import android.support.v7.app.AppCompatActivity;
import com.google.zxing.integration.android.IntentIntegrator;
import com.journeyapps.barcodescanner.CaptureActivity;
public class QRHelper
{
public QRHelper()
{
}
public void startQRScan(AppCompatActivity activity) {
new IntentIntegrator(activity).setPrompt("Scan QR").setOrientationLocked(false).setCameraId(0).setCaptureActivity(CaptureActivity.class).initiateScan();
}
}
package app.crescentcash.src.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;
public class NonScrollListView extends ListView {
public NonScrollListView(Context context) {
super(context);
}
public NonScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
\ No newline at end of file
This diff is collapsed.
package app.crescentcash.src.utils;
public class Constants {
public static final String WALLET_NAME = "users_wallet";
public static boolean IS_PRODUCTION = true;
public static int CASH_ACCOUNT_GENESIS_MODIFIED = 563620;
}
package app.crescentcash.src.utils;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
public class PermissionHelper {
public PermissionHelper()
{
}
public void askForPermissions(Context context, Activity activity)
{
if (ContextCompat.checkSelfPermission(context, Manifest.permission.NFC) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED)
{
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE) || !ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA) || !ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.NFC) || !ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) || !ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.VIBRATE))
{
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.VIBRATE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.NFC}, 5);
}
}
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="@android:color/darker_gray"
android:width="1dp" />
<corners android:radius="8dp"/>
<solid android:color="@android:color/white"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="#eee" />
<stroke
android:width="2dip"
android:color="#eee" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M9.4,10.5l4.77,-8.26C13.47,2.09 12.75,2 12,2c-2.4,0 -4.6,0.85 -6.32,2.25l3.66,6.35 0.06,-0.1zM21.54,9c-0.92,-2.92 -3.15,-5.26 -6,-6.34L11.88,9h9.66zM21.8,10h-7.49l0.29,0.5 4.76,8.25C21,16.97 22,14.61 22,12c0,-0.69 -0.07,-1.35 -0.2,-2zM8.54,12l-3.9,-6.75C3.01,7.03 2,9.39 2,12c0,0.69 0.07,1.35 0.2,2h7.49l-1.15,-2zM2.46,15c0.92,2.92 3.15,5.26 6,6.34L12.12,15L2.46,15zM13.73,15l-3.9,6.76c0.7,0.15 1.42,0.24 2.17,0.24 2.4,0 4.6,-0.85 6.32,-2.25l-3.66,-6.35 -0.93,1.6z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"