Skip to content

Commit

Permalink
allow seed offset generation & wallet restore (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2049r authored Jan 2, 2022
1 parent 341df6c commit 0712efe
Show file tree
Hide file tree
Showing 35 changed files with 413 additions and 123 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.m2049r.xmrwallet"
minSdkVersion 21
targetSdkVersion 30
versionCode 1201
versionName "2.2.1 'René'"
versionCode 1301
versionName "2.3.1 'Doménikos'"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
23 changes: 15 additions & 8 deletions app/src/main/cpp/monerujo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ std::vector<std::string> java2cpp(JNIEnv *env, jobject arrayList) {
return result;
}

jobject cpp2java(JNIEnv *env, const std::vector<std::string>& vector) {
jobject cpp2java(JNIEnv *env, const std::vector<std::string> &vector) {

jmethodID java_util_ArrayList_ = env->GetMethodID(class_ArrayList, "<init>", "(I)V");
jmethodID java_util_ArrayList_add = env->GetMethodID(class_ArrayList, "add",
Expand Down Expand Up @@ -301,12 +301,13 @@ Java_com_m2049r_xmrwallet_model_WalletManager_openWalletJ(JNIEnv *env, jobject i
JNIEXPORT jlong JNICALL
Java_com_m2049r_xmrwallet_model_WalletManager_recoveryWalletJ(JNIEnv *env, jobject instance,
jstring path, jstring password,
jstring mnemonic,
jstring mnemonic, jstring offset,
jint networkType,
jlong restoreHeight) {
const char *_path = env->GetStringUTFChars(path, nullptr);
const char *_password = env->GetStringUTFChars(password, nullptr);
const char *_mnemonic = env->GetStringUTFChars(mnemonic, nullptr);
const char *_offset = env->GetStringUTFChars(offset, nullptr);
Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);

Bitmonero::Wallet *wallet =
Expand All @@ -315,11 +316,14 @@ Java_com_m2049r_xmrwallet_model_WalletManager_recoveryWalletJ(JNIEnv *env, jobje
std::string(_password),
std::string(_mnemonic),
_networkType,
(uint64_t) restoreHeight);
(uint64_t) restoreHeight,
1, // kdf_rounds
std::string(_offset));

env->ReleaseStringUTFChars(path, _path);
env->ReleaseStringUTFChars(password, _password);
env->ReleaseStringUTFChars(mnemonic, _mnemonic);
env->ReleaseStringUTFChars(offset, _offset);
return reinterpret_cast<jlong>(wallet);
}

Expand Down Expand Up @@ -533,7 +537,7 @@ Java_com_m2049r_xmrwallet_model_WalletManager_resolveOpenAlias(JNIEnv *env, jobj

JNIEXPORT jboolean JNICALL
Java_com_m2049r_xmrwallet_model_WalletManager_setProxy(JNIEnv *env, jobject instance,
jstring address) {
jstring address) {
const char *_address = env->GetStringUTFChars(address, nullptr);
bool rc =
Bitmonero::WalletManagerFactory::getWalletManager()->setProxy(std::string(_address));
Expand Down Expand Up @@ -570,9 +574,12 @@ Java_com_m2049r_xmrwallet_model_WalletManager_closeJ(JNIEnv *env, jobject instan
/**********************************/

JNIEXPORT jstring JNICALL
Java_com_m2049r_xmrwallet_model_Wallet_getSeed(JNIEnv *env, jobject instance) {
Java_com_m2049r_xmrwallet_model_Wallet_getSeed(JNIEnv *env, jobject instance, jstring seedOffset) {
const char *_seedOffset = env->GetStringUTFChars(seedOffset, nullptr);
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
return env->NewStringUTF(wallet->seed().c_str());
jstring seed = env->NewStringUTF(wallet->seed(std::string(_seedOffset)).c_str());
env->ReleaseStringUTFChars(seedOffset, _seedOffset);
return seed;
}

JNIEXPORT jstring JNICALL
Expand Down Expand Up @@ -740,7 +747,7 @@ Java_com_m2049r_xmrwallet_model_Wallet_getConnectionStatusJ(JNIEnv *env, jobject

JNIEXPORT jboolean JNICALL
Java_com_m2049r_xmrwallet_model_Wallet_setProxy(JNIEnv *env, jobject instance,
jstring address) {
jstring address) {
const char *_address = env->GetStringUTFChars(address, nullptr);
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
bool rc = wallet->setProxy(std::string(_address));
Expand Down Expand Up @@ -1262,7 +1269,7 @@ jobject newTransactionInfo(JNIEnv *env, Bitmonero::TransactionInfo *info) {
#include <stdio.h>
#include <stdlib.h>

jobject cpp2java(JNIEnv *env, const std::vector<Bitmonero::TransactionInfo *>& vector) {
jobject cpp2java(JNIEnv *env, const std::vector<Bitmonero::TransactionInfo *> &vector) {

jmethodID java_util_ArrayList_ = env->GetMethodID(class_ArrayList, "<init>", "(I)V");
jmethodID java_util_ArrayList_add = env->GetMethodID(class_ArrayList, "add",
Expand Down
26 changes: 23 additions & 3 deletions app/src/main/java/com/m2049r/xmrwallet/GenerateFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public class GenerateFragment extends Fragment {
private TextInputLayout etWalletRestoreHeight;
private Button bGenerate;

private Button bSeedOffset;
private TextInputLayout etSeedOffset;

private String type = null;

private void clearErrorOnTextEntry(final TextInputLayout textInputLayout) {
Expand Down Expand Up @@ -118,6 +121,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
etWalletSpendKey = view.findViewById(R.id.etWalletSpendKey);
etWalletRestoreHeight = view.findViewById(R.id.etWalletRestoreHeight);
bGenerate = view.findViewById(R.id.bGenerate);
bSeedOffset = view.findViewById(R.id.bSeedOffset);
etSeedOffset = view.findViewById(R.id.etSeedOffset);

etWalletAddress.getEditText().setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
etWalletViewKey.getEditText().setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Expand Down Expand Up @@ -222,6 +227,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}
return false;
});
bSeedOffset.setVisibility(View.VISIBLE);
bSeedOffset.setOnClickListener(v -> toggleSeedOffset());
break;
case TYPE_KEY:
case TYPE_VIEWONLY:
Expand Down Expand Up @@ -288,6 +295,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return view;
}

void toggleSeedOffset() {
if (etSeedOffset.getVisibility() == View.VISIBLE) {
etSeedOffset.getEditText().getText().clear();
etSeedOffset.setVisibility(View.GONE);
bSeedOffset.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_baseline_keyboard_arrow_down_24, 0, 0, 0);
} else {
etSeedOffset.setVisibility(View.VISIBLE);
bSeedOffset.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_baseline_keyboard_arrow_up_24, 0, 0, 0);
etSeedOffset.requestFocusFromTouch();
}
}

private boolean checkName() {
String name = etWalletName.getEditText().getText().toString();
boolean ok = true;
Expand Down Expand Up @@ -422,12 +441,13 @@ private void generateWallet() {
break;
case TYPE_SEED:
if (!checkMnemonic()) return;
String seed = etWalletMnemonic.getEditText().getText().toString();
final String seed = etWalletMnemonic.getEditText().getText().toString();
bGenerate.setEnabled(false);
if (fingerprintAuthAllowed) {
KeyStoreHelper.saveWalletUserPass(requireActivity(), name, password);
}
activityCallback.onGenerate(name, crazyPass, seed, height);
final String offset = etSeedOffset.getEditText().getText().toString();
activityCallback.onGenerate(name, crazyPass, seed, offset, height);
break;
case TYPE_LEDGER:
bGenerate.setEnabled(false);
Expand Down Expand Up @@ -491,7 +511,7 @@ String getType() {
public interface Listener {
void onGenerate(String name, String password);

void onGenerate(String name, String password, String seed, long height);
void onGenerate(String name, String password, String seed, String offset, long height);

void onGenerate(String name, String password, String address, String viewKey, String spendKey, long height);

Expand Down
Loading

0 comments on commit 0712efe

Please sign in to comment.