diff --git a/app/src/main/cpp/monerujo.cpp b/app/src/main/cpp/monerujo.cpp index b7a178e..abdf0ef 100644 --- a/app/src/main/cpp/monerujo.cpp +++ b/app/src/main/cpp/monerujo.cpp @@ -291,41 +291,48 @@ 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 mnemonic, + jstring path, jstring password, + jstring mnemonic, jboolean isTestNet, jlong restoreHeight) { const char *_path = env->GetStringUTFChars(path, NULL); + const char *_password = env->GetStringUTFChars(password, NULL); const char *_mnemonic = env->GetStringUTFChars(mnemonic, NULL); Bitmonero::Wallet *wallet = Bitmonero::WalletManagerFactory::getWalletManager()->recoveryWallet( std::string(_path), + std::string(_password), std::string(_mnemonic), isTestNet, restoreHeight); env->ReleaseStringUTFChars(path, _path); + env->ReleaseStringUTFChars(password, _password); env->ReleaseStringUTFChars(mnemonic, _mnemonic); return reinterpret_cast(wallet); } JNIEXPORT jlong JNICALL -Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromKeysJ(JNIEnv *env, jobject instance, - jstring path, jstring language, +Java_com_m2049r_xmrwallet_model_WalletManager_createWalletWithKeysJ(JNIEnv *env, jobject instance, + jstring path, jstring password, + jstring language, jboolean isTestNet, jlong restoreHeight, jstring addressString, jstring viewKeyString, jstring spendKeyString) { const char *_path = env->GetStringUTFChars(path, NULL); + const char *_password = env->GetStringUTFChars(password, NULL); const char *_language = env->GetStringUTFChars(language, NULL); const char *_addressString = env->GetStringUTFChars(addressString, NULL); const char *_viewKeyString = env->GetStringUTFChars(viewKeyString, NULL); const char *_spendKeyString = env->GetStringUTFChars(spendKeyString, NULL); Bitmonero::Wallet *wallet = - Bitmonero::WalletManagerFactory::getWalletManager()->createWalletFromKeys( + Bitmonero::WalletManagerFactory::getWalletManager()->createWalletWithKeys( std::string(_path), + std::string(_password), std::string(_language), isTestNet, restoreHeight, @@ -334,6 +341,7 @@ Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromKeysJ(JNIEnv *env, std::string(_spendKeyString)); env->ReleaseStringUTFChars(path, _path); + env->ReleaseStringUTFChars(password, _password); env->ReleaseStringUTFChars(language, _language); env->ReleaseStringUTFChars(addressString, _addressString); env->ReleaseStringUTFChars(viewKeyString, _viewKeyString); diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java index 77cc83e..50d1d88 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java @@ -778,13 +778,14 @@ public class LoginActivity extends SecureActivity static final String MNEMONIC_LANGUAGE = "English"; // see mnemonics/electrum-words.cpp for more private class AsyncCreateWallet extends AsyncTask { - String walletName; - String walletPassword; - WalletCreator walletCreator; + final String walletName; + final String walletPassword; + final WalletCreator walletCreator; File newWalletFile; - public AsyncCreateWallet(String name, String password, WalletCreator walletCreator) { + public AsyncCreateWallet(final String name, final String password, + final WalletCreator walletCreator) { super(); this.walletName = name; this.walletPassword = password; @@ -814,12 +815,7 @@ public class LoginActivity extends SecureActivity return false; } - File newWalletFolder = Helper.getNewWalletDir(getApplicationContext()); - if (!newWalletFolder.isDirectory()) { - Timber.e("New Wallet dir " + newWalletFolder.getAbsolutePath() + "is not a directory"); - return false; - } - newWalletFile = new File(newWalletFolder, walletName); + newWalletFile = new File(walletFolder, walletName); boolean success = walletCreator.createWallet(newWalletFile, walletPassword); if (success) { return true; @@ -844,7 +840,8 @@ public class LoginActivity extends SecureActivity } } - public void createWallet(String name, String password, WalletCreator walletCreator) { + public void createWallet(final String name, final String password, + final WalletCreator walletCreator) { new AsyncCreateWallet(name, password, walletCreator) .executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR); } @@ -865,7 +862,7 @@ public class LoginActivity extends SecureActivity } @Override - public void onGenerate(String name, String password) { + public void onGenerate(final String name, final String password) { createWallet(name, password, new WalletCreator() { public boolean createWallet(File aFile, String password) { @@ -883,16 +880,15 @@ public class LoginActivity extends SecureActivity } @Override - public void onGenerate(String name, String password, final String seed, final long restoreHeight) { + public void onGenerate(final String name, final String password, final String seed, + final long restoreHeight) { createWallet(name, password, new WalletCreator() { public boolean createWallet(File aFile, String password) { - Wallet newWallet = WalletManager.getInstance().recoveryWallet(aFile, seed, restoreHeight); + Wallet newWallet = WalletManager.getInstance(). + recoveryWallet(aFile, password, seed, restoreHeight); boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok); - if (success) { - newWallet.setPassword(password); - success = success && newWallet.store(); - } else { + if (!success) { Timber.e(newWallet.getErrorString()); toast(newWallet.getErrorString()); } @@ -903,19 +899,17 @@ public class LoginActivity extends SecureActivity } @Override - public void onGenerate(String name, String password, - final String address, final String viewKey, final String spendKey, final long restoreHeight) { + public void onGenerate(final String name, final String password, + final String address, final String viewKey, final String spendKey, + final long restoreHeight) { createWallet(name, password, new WalletCreator() { public boolean createWallet(File aFile, String password) { Wallet newWallet = WalletManager.getInstance() - .createWalletFromKeys(aFile, MNEMONIC_LANGUAGE, restoreHeight, + .createWalletWithKeys(aFile, password, MNEMONIC_LANGUAGE, restoreHeight, address, viewKey, spendKey); boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok); - if (success) { - newWallet.setPassword(password); - success = success && newWallet.store(); - } else { + if (!success) { Timber.e(newWallet.getErrorString()); toast(newWallet.getErrorString()); } @@ -936,16 +930,10 @@ public class LoginActivity extends SecureActivity @Override public void onAccept(final String name, final String password) { - File newWalletFile = new File(Helper.getNewWalletDir(getApplicationContext()), name); - Timber.d("New Wallet %s", newWalletFile.getAbsolutePath()); - newWalletFile.delete(); // when recovering wallets, the cache seems corrupt - // TODO: figure out why this is so? Only for a private testnet? - - // now copy the new wallet to the wallet folder - File walletFile = new File(getStorageRoot(), name); - Timber.d("Wallet %s", walletFile.getAbsolutePath()); - copyWallet(newWalletFile, walletFile, false, true); - deleteWallet(newWalletFile); // delete it no matter what (can't recover from this anyway) + File walletFolder = getStorageRoot(); + File walletFile = new File(walletFolder, name); + Timber.d("New Wallet %s", walletFile.getAbsolutePath()); + walletFile.delete(); // when recovering wallets, the cache seems corrupt boolean rc = testWallet(walletFile.getAbsolutePath(), password) == Wallet.Status.Status_Ok; diff --git a/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java b/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java index e72b1cf..e098a27 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java +++ b/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java @@ -86,31 +86,33 @@ public class WalletManager { private native long openWalletJ(String path, String password, boolean isTestNet); - public Wallet recoveryWallet(File aFile, String mnemonic) { - Wallet wallet = recoveryWallet(aFile, mnemonic, 0); - manageWallet(wallet); - return wallet; + public Wallet recoveryWallet(File aFile, String password, String mnemonic) { + return recoveryWallet(aFile, password, mnemonic, 0); } - public Wallet recoveryWallet(File aFile, String mnemonic, long restoreHeight) { - long walletHandle = recoveryWalletJ(aFile.getAbsolutePath(), mnemonic, isTestNet(), restoreHeight); + public Wallet recoveryWallet(File aFile, String password, String mnemonic, long restoreHeight) { + long walletHandle = recoveryWalletJ(aFile.getAbsolutePath(), password, mnemonic, + isTestNet(), restoreHeight); Wallet wallet = new Wallet(walletHandle); manageWallet(wallet); return wallet; } - private native long recoveryWalletJ(String path, String mnemonic, boolean isTestNet, long restoreHeight); + private native long recoveryWalletJ(String path, String password, String mnemonic, + boolean isTestNet, long restoreHeight); - public Wallet createWalletFromKeys(File aFile, String language, long restoreHeight, + public Wallet createWalletWithKeys(File aFile, String password, String language, long restoreHeight, String addressString, String viewKeyString, String spendKeyString) { - long walletHandle = createWalletFromKeysJ(aFile.getAbsolutePath(), language, isTestNet(), restoreHeight, + long walletHandle = createWalletWithKeysJ(aFile.getAbsolutePath(), password, + language, isTestNet(), restoreHeight, addressString, viewKeyString, spendKeyString); Wallet wallet = new Wallet(walletHandle); manageWallet(wallet); return wallet; } - private native long createWalletFromKeysJ(String path, String language, + private native long createWalletWithKeysJ(String path, String password, + String language, boolean isTestNet, long restoreHeight, String addressString, diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java index 118b7b0..b771b6c 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java @@ -58,17 +58,6 @@ public class Helper { static public int DISPLAY_DIGITS_INFO = 5; - static public File getNewWalletDir(Context context) { - File newWalletDir = context.getDir("new", Context.MODE_PRIVATE); - Timber.d("new wallet directory is %s", newWalletDir.getAbsolutePath()); - if (!newWalletDir.exists() || !newWalletDir.isDirectory()) { - String msg = newWalletDir.getAbsolutePath() + " is not a directory!"; - Timber.e(msg); - throw new IllegalStateException(msg); - } - return newWalletDir; - } - static public File getStorageRoot(Context context) { if (!isExternalStorageWritable()) { String msg = context.getString(R.string.message_strorage_not_writable); diff --git a/external-libs/monero/include/wallet2_api.h b/external-libs/monero/include/wallet2_api.h index 7a5e01a..fc2131f 100644 --- a/external-libs/monero/include/wallet2_api.h +++ b/external-libs/monero/include/wallet2_api.h @@ -630,6 +630,18 @@ struct WalletManager virtual Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) = 0; /*! + * \brief recovers existing wallet using memo (electrum seed) + * \param path Name of wallet file to be created + * \param password Password of wallet file + * \param memo memo (25 words electrum seed) + * \param testnet testnet + * \param restoreHeight restore from start height + * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully) + */ + virtual Wallet * recoveryWallet(const std::string &path, const std::string &password, const std::string &memo, bool testnet = false, uint64_t restoreHeight = 0) = 0; + + /*! + * \deprecated this method creates a wallet WITHOUT a psssphrase, use the alternate recoverWallet() method * \brief recovers existing wallet using memo (electrum seed) * \param path Name of wallet file to be created * \param memo memo (25 words electrum seed) @@ -639,18 +651,40 @@ struct WalletManager */ virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet = false, uint64_t restoreHeight = 0) = 0; - /*! - * \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted - * \param path Name of wallet file to be created - * \param language language - * \param testnet testnet - * \param restoreHeight restore from start height - * \param addressString public address - * \param viewKeyString view key - * \param spendKeyString spend key (optional) - * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully) - */ - virtual Wallet * createWalletFromKeys(const std::string &path, + /*! + * \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted + * \param path Name of wallet file to be created + * \param password Password of wallet file + * \param language language + * \param testnet testnet + * \param restoreHeight restore from start height + * \param addressString public address + * \param viewKeyString view key + * \param spendKeyString spend key (optional) + * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully) + */ + virtual Wallet * createWalletWithKeys(const std::string &path, + const std::string &password, + const std::string &language, + bool testnet, + uint64_t restoreHeight, + const std::string &addressString, + const std::string &viewKeyString, + const std::string &spendKeyString = "") = 0; + + /*! + * \deprecated this method creates a wallet WITHOUT a psssphrase, use createWalletWithKeys() instead + * \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted + * \param path Name of wallet file to be created + * \param language language + * \param testnet testnet + * \param restoreHeight restore from start height + * \param addressString public address + * \param viewKeyString view key + * \param spendKeyString spend key (optional) + * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully) + */ + virtual Wallet * createWalletFromKeys(const std::string &path, const std::string &language, bool testnet, uint64_t restoreHeight, diff --git a/external-libs/monero/lib/armeabi-v7a/libblockchain_db.a b/external-libs/monero/lib/armeabi-v7a/libblockchain_db.a index dc51983..0ab9c3d 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libblockchain_db.a and b/external-libs/monero/lib/armeabi-v7a/libblockchain_db.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libblocks.a b/external-libs/monero/lib/armeabi-v7a/libblocks.a index b302238..8fb914b 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libblocks.a and b/external-libs/monero/lib/armeabi-v7a/libblocks.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libcncrypto.a b/external-libs/monero/lib/armeabi-v7a/libcncrypto.a index 4b88f4c..57ce2c3 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libcncrypto.a and b/external-libs/monero/lib/armeabi-v7a/libcncrypto.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libcommon.a b/external-libs/monero/lib/armeabi-v7a/libcommon.a index af6267a..8137fd7 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libcommon.a and b/external-libs/monero/lib/armeabi-v7a/libcommon.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libcryptonote_basic.a b/external-libs/monero/lib/armeabi-v7a/libcryptonote_basic.a index 4d9509e..a02122d 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libcryptonote_basic.a and b/external-libs/monero/lib/armeabi-v7a/libcryptonote_basic.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libcryptonote_core.a b/external-libs/monero/lib/armeabi-v7a/libcryptonote_core.a index 020059c..5777d1f 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libcryptonote_core.a and b/external-libs/monero/lib/armeabi-v7a/libcryptonote_core.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libcryptonote_protocol.a b/external-libs/monero/lib/armeabi-v7a/libcryptonote_protocol.a index ba52c27..38ba507 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libcryptonote_protocol.a and b/external-libs/monero/lib/armeabi-v7a/libcryptonote_protocol.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libdaemonizer.a b/external-libs/monero/lib/armeabi-v7a/libdaemonizer.a index 5a99e32..daedb9f 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libdaemonizer.a and b/external-libs/monero/lib/armeabi-v7a/libdaemonizer.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libeasylogging.a b/external-libs/monero/lib/armeabi-v7a/libeasylogging.a index 6127c84..4a17209 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libeasylogging.a and b/external-libs/monero/lib/armeabi-v7a/libeasylogging.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libepee.a b/external-libs/monero/lib/armeabi-v7a/libepee.a index 00fe057..f703a51 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libepee.a and b/external-libs/monero/lib/armeabi-v7a/libepee.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/liblmdb.a b/external-libs/monero/lib/armeabi-v7a/liblmdb.a index cf85578..21b6b54 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/liblmdb.a and b/external-libs/monero/lib/armeabi-v7a/liblmdb.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libminiupnpc.a b/external-libs/monero/lib/armeabi-v7a/libminiupnpc.a index 55ba3a5..c6c1359 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libminiupnpc.a and b/external-libs/monero/lib/armeabi-v7a/libminiupnpc.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libmnemonics.a b/external-libs/monero/lib/armeabi-v7a/libmnemonics.a index a632f93..727e617 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libmnemonics.a and b/external-libs/monero/lib/armeabi-v7a/libmnemonics.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libp2p.a b/external-libs/monero/lib/armeabi-v7a/libp2p.a index 870550d..990ef12 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libp2p.a and b/external-libs/monero/lib/armeabi-v7a/libp2p.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libringct.a b/external-libs/monero/lib/armeabi-v7a/libringct.a index 26d0828..bf6ab9a 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libringct.a and b/external-libs/monero/lib/armeabi-v7a/libringct.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/librpc.a b/external-libs/monero/lib/armeabi-v7a/librpc.a index d81b42b..5ad09a6 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/librpc.a and b/external-libs/monero/lib/armeabi-v7a/librpc.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libunbound.a b/external-libs/monero/lib/armeabi-v7a/libunbound.a index 6f930d0..65ac41a 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libunbound.a and b/external-libs/monero/lib/armeabi-v7a/libunbound.a differ diff --git a/external-libs/monero/lib/armeabi-v7a/libwallet.a b/external-libs/monero/lib/armeabi-v7a/libwallet.a index 63b9117..b38be22 100644 Binary files a/external-libs/monero/lib/armeabi-v7a/libwallet.a and b/external-libs/monero/lib/armeabi-v7a/libwallet.a differ