From 3c61ddf5e1d2801a61b5d8d4c43ec10c401f048a Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Tue, 28 Feb 2017 23:32:16 +0000 Subject: [PATCH 1/3] decode the login key in the offline mode --- README.md | 6 +- html/js/controllers/login.js | 80 +++++++++++++++++++------ html/modals/login.html | 23 +++++++ html/modals/review-account-details.html | 16 ----- 4 files changed, 90 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 5992cc3..61cb3ad 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ They include: - added dynamic fees for testnet. - minimum mixin set to 4 for the next hard fork. - view only mode added. + - ability to offline show your address and private view and spend keys, based on the mnemonic seed, + in case backend is dead. ## Testnet version @@ -176,7 +178,9 @@ Before running `openmonero`: Time library used in Open Monero stores there time zone offsets database that it uses. - edit `config/confing.js` file with your settings. Especially set `frontend-url` and `database` connection details. - - set `apiUrl` in `html\js\config.js`. Last slash `/` in `apiUrl` is important. + - set `apiUrl` in `html\js\config.js` and `testnet` flag. Last slash `/` in `apiUrl` is important. + If running backend for testnet network, frontend `testnet` flag must be set to `true`. + For mainnet, it is set to `false`. - make sure monero daemon is running and fully sync. If using testnet network, use daemon with testnet flag! diff --git a/html/js/controllers/login.js b/html/js/controllers/login.js index d8d18a3..ee20e1f 100755 --- a/html/js/controllers/login.js +++ b/html/js/controllers/login.js @@ -37,35 +37,51 @@ thinwalletCtrls.controller("LoginCtrl", function($scope, $location, AccountServi $scope.mnemonic_language = 'english'; + + var decode_seed = function(mnemonic, language) + { + var seed; + var keys; + + switch (language) { + case 'english': + try { + seed = mn_decode(mnemonic); + } catch (e) { + // Try decoding as an electrum seed, on failure throw the original exception + try { + seed = mn_decode(mnemonic, "electrum"); + } catch (ee) { + throw e; + } + } + break; + default: + seed = mn_decode(mnemonic, language); + break; + } + keys = cnUtil.create_address(seed); + + return [seed, keys]; + }; + + $scope.login_mnemonic = function(mnemonic, language) { $scope.error = ''; var seed; var keys; mnemonic = mnemonic.toLowerCase() || ""; + try { - switch (language) { - case 'english': - try { - seed = mn_decode(mnemonic); - } catch (e) { - // Try decoding as an electrum seed, on failure throw the original exception - try { - seed = mn_decode(mnemonic, "electrum"); - } catch (ee) { - throw e; - } - } - break; - default: - seed = mn_decode(mnemonic, language); - break; - } - keys = cnUtil.create_address(seed); + var seed_key = decode_seed(mnemonic, language); + seed = seed_key[0]; + keys = seed_key[1]; } catch (e) { console.log("Invalid mnemonic!"); $scope.error = e; return; } + AccountService.login(keys.public_addr, keys.view.sec, keys.spend.sec, seed, false) .then(function() { ModalService.hide('login'); @@ -79,6 +95,34 @@ thinwalletCtrls.controller("LoginCtrl", function($scope, $location, AccountServi }); }; + + + $scope.decodeSeed = function(mnemonic, language) + { + $scope.error = ''; + var seed; + var keys; + + mnemonic = mnemonic.toLowerCase() || ""; + + try + { + var seed_key = decode_seed(mnemonic, language); + + seed = seed_key[0]; + keys = seed_key[1]; + + $scope.address = keys.public_addr; + $scope.view_key = keys.view.sec; + $scope.spend_key = keys.spend.sec; + + } catch (e) { + console.log("Invalid mnemonic!"); + $scope.error = e; + return; + } + }; + $scope.login_keys = function(address, view_key, spend_key) { $scope.error = ''; AccountService.login(address, view_key, spend_key, undefined, false) diff --git a/html/modals/login.html b/html/modals/login.html index c9061f1..3444fa0 100755 --- a/html/modals/login.html +++ b/html/modals/login.html @@ -44,7 +44,30 @@
+
+ +
+
+ +
+
{{address}}
+
+ +
+
{{view_key}}
+
+ +
+
{{spend_key}}
+
+ +
+
+

{{error}}

diff --git a/html/modals/review-account-details.html b/html/modals/review-account-details.html index 2bba0f7..8e2c2f9 100755 --- a/html/modals/review-account-details.html +++ b/html/modals/review-account-details.html @@ -24,22 +24,6 @@
{{spend_key}}
-
From a026243a6edbc758a7ee8073241893d13c4477ea Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 1 Mar 2017 00:27:06 +0000 Subject: [PATCH 2/3] private tx key added when sending txs --- html/js/cn_util.js | 5 ++++- html/js/config.js | 2 +- html/js/controllers/send_coins.js | 3 +++ html/partials/send-coins.html | 8 ++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/html/js/cn_util.js b/html/js/cn_util.js index 53c8ed0..d62221e 100644 --- a/html/js/cn_util.js +++ b/html/js/cn_util.js @@ -1452,7 +1452,8 @@ var cnUtil = (function(initConfig) { var hash = this.cn_fast_hash(hashes); return { raw: buf, - hash: hash + hash: hash, + prvkey: tx.prvkey }; }; @@ -1615,6 +1616,7 @@ var cnUtil = (function(initConfig) { unlock_time: unlock_time, version: rct ? CURRENT_TX_VERSION : OLD_TX_VERSION, extra: extra, + prvkey: '', vin: [], vout: [] }; @@ -1624,6 +1626,7 @@ var cnUtil = (function(initConfig) { tx.signatures = []; } tx.extra = this.add_pub_key_to_extra(tx.extra, txkey.pub); + tx.prvkey = txkey.sec; var in_contexts = []; diff --git a/html/js/config.js b/html/js/config.js index 807c872..c733f49 100755 --- a/html/js/config.js +++ b/html/js/config.js @@ -1,6 +1,6 @@ var config = { apiUrl: "http://127.0.0.1:1984/", - testnet: true, + testnet: false, coinUnitPlaces: 12, txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero diff --git a/html/js/controllers/send_coins.js b/html/js/controllers/send_coins.js index c80f120..e9a1890 100644 --- a/html/js/controllers/send_coins.js +++ b/html/js/controllers/send_coins.js @@ -299,6 +299,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS var prevFee = neededFee; var raw_tx = tx_h.raw; var tx_hash = tx_h.hash; + var tx_prvkey = tx_h.prvkey; // work out per-kb fee for transaction var txBlobBytes = raw_tx.length / 2; var numKB = Math.floor((txBlobBytes) / 1024); @@ -340,6 +341,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS amount: realDsts[0].amount, payment_id: payment_id, tx_id: tx_hash, + tx_prvkey: tx_prvkey, tx_fee: neededFee/*.add(getTxCharge(neededFee))*/ }; $scope.success_page = true; @@ -540,6 +542,7 @@ thinwalletCtrls.controller('SendCoinsCtrl', function($scope, $http, $q, AccountS if (signed.version === 1) { raw_tx_and_hash.raw = cnUtil.serialize_tx(signed); raw_tx_and_hash.hash = cnUtil.cn_fast_hash(raw_tx); + raw_tx_and_hash.prvkey = signed.prvkey; } else { raw_tx_and_hash = cnUtil.serialize_rct_tx_with_hash(signed); } diff --git a/html/partials/send-coins.html b/html/partials/send-coins.html index b2db7df..32b8835 100755 --- a/html/partials/send-coins.html +++ b/html/partials/send-coins.html @@ -91,14 +91,18 @@
{{sent_tx.amount | money}} (+{{sent_tx.tx_fee | money}} fee)
- +
{{sent_tx.payment_id || "N/A"}}
- +
{{sent_tx.tx_id}}
+ +
+
{{sent_tx.tx_prvkey}}
+
From 467724becdf038c506cd1f928288d91442b9e3da Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 1 Mar 2017 00:29:23 +0000 Subject: [PATCH 3/3] private tx key added when sending txs --- html/js/config.js | 2 +- html/partials/send-coins.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/html/js/config.js b/html/js/config.js index c733f49..807c872 100755 --- a/html/js/config.js +++ b/html/js/config.js @@ -1,6 +1,6 @@ var config = { apiUrl: "http://127.0.0.1:1984/", - testnet: false, + testnet: true, coinUnitPlaces: 12, txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero diff --git a/html/partials/send-coins.html b/html/partials/send-coins.html index 32b8835..2b6ab81 100755 --- a/html/partials/send-coins.html +++ b/html/partials/send-coins.html @@ -99,7 +99,7 @@
{{sent_tx.tx_id}}
- + label class="send-label" >Transaction Private Key (save it, as it is needed to prove the recipient that you sent him xmr)
{{sent_tx.tx_prvkey}}