From 0d32654e2eccf196e1003b0ca732e6e56580876f Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 16 Oct 2019 19:28:02 -0400 Subject: [PATCH 1/3] for tom --- dist/bundle.es.js | 27 ++++++++++++++++++++++++++- src/index.js | 1 + src/redux/actions/sync.js | 27 ++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 92e2655..b4071a9 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2472,7 +2472,9 @@ function doGetSync(passedPassword, callback) { data }); handleCallback(); - }).catch(() => { + }).catch(err => { + console.log('error', err); + if (data.hasSyncedWallet) { const error = 'Error getting synced wallet'; dispatch({ @@ -2578,6 +2580,28 @@ function doResetSync() { resolve(); }); } +function changeSyncPassword(oldPassword, newPassword) { + return dispatch => { + let data = {}; + return lbryRedux.Lbry.sync_hash().then(hash => { + return Lbryio.call('sync', 'get', { + hash + }, 'post'); + }).then(syncGetResponse => { + data.oldHash = syncGetResponse.hash; + return lbryRedux.Lbry.sync_apply({ + password: oldPassword, + data: syncGetResponse.data + }); + }).then(() => lbryRedux.Lbry.sync_apply({ + password: newPassword + })).then(syncApplyResponse => { + if (syncApplyResponse.hash !== data.oldHash) { + return dispatch(doSetSync(data.oldHash, syncApplyResponse.hash, syncApplyResponse.data)); + } + }).catch(console.error); + }; +} const reducers = {}; const defaultState$1 = { @@ -3245,6 +3269,7 @@ exports.Lbryio = Lbryio; exports.YOUTUBE_STATUSES = youtube; exports.authReducer = authReducer; exports.blacklistReducer = blacklistReducer; +exports.changeSyncPassword = changeSyncPassword; exports.costInfoReducer = costInfoReducer; exports.doAuthenticate = doAuthenticate; exports.doBlackListedOutpointsSubscribe = doBlackListedOutpointsSubscribe; diff --git a/src/index.js b/src/index.js index 670841c..5ce467e 100644 --- a/src/index.js +++ b/src/index.js @@ -73,6 +73,7 @@ export { doSetDefaultAccount, doSyncApply, doResetSync, + changeSyncPassword, } from 'redux/actions/sync'; // reducers diff --git a/src/redux/actions/sync.js b/src/redux/actions/sync.js index d8167e4..ef7942d 100644 --- a/src/redux/actions/sync.js +++ b/src/redux/actions/sync.js @@ -123,6 +123,7 @@ export function doGetSync(passedPassword, callback) { } const { hash: walletHash, data: walletData } = response; + if (walletHash !== data.syncHash) { // different local hash, need to synchronise dispatch(doSetSync(data.syncHash, walletHash, walletData)); @@ -131,7 +132,8 @@ export function doGetSync(passedPassword, callback) { dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); handleCallback(); }) - .catch(() => { + .catch(err => { + console.log('error', err); if (data.hasSyncedWallet) { const error = 'Error getting synced wallet'; dispatch({ @@ -228,3 +230,26 @@ export function doResetSync() { resolve(); }); } + +export function changeSyncPassword(oldPassword, newPassword) { + return dispatch => { + let data = {}; + + return Lbry.sync_hash() + .then(hash => { + return Lbryio.call('sync', 'get', { hash }, 'post'); + }) + .then(syncGetResponse => { + data.oldHash = syncGetResponse.hash; + + return Lbry.sync_apply({ password: oldPassword, data: syncGetResponse.data }); + }) + .then(() => Lbry.sync_apply({ password: newPassword })) + .then(syncApplyResponse => { + if (syncApplyResponse.hash !== data.oldHash) { + return dispatch(doSetSync(data.oldHash, syncApplyResponse.hash, syncApplyResponse.data)); + } + }) + .catch(console.error); + }; +} From 6e5729afd29089e4e96f060330f87667d8d144f5 Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Thu, 17 Oct 2019 00:00:43 -0400 Subject: [PATCH 2/3] fix: encryption and decryption! --- dist/bundle.es.js | 10 ++++++++-- dist/bundle.js | 37 ++++++++++++++++++++++++++++++++++++- src/index.js | 2 +- src/redux/actions/sync.js | 18 +++++++++++------- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index b4071a9..421620f 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2580,7 +2580,7 @@ function doResetSync() { resolve(); }); } -function changeSyncPassword(oldPassword, newPassword) { +function doSyncEncryptAndDecrypt(oldPassword, newPassword, encrypt) { return dispatch => { let data = {}; return lbryRedux.Lbry.sync_hash().then(hash => { @@ -2593,6 +2593,12 @@ function changeSyncPassword(oldPassword, newPassword) { password: oldPassword, data: syncGetResponse.data }); + }).then(() => { + if (encrypt) { + dispatch(lbryRedux.doWalletEncrypt(newPassword)); + } else { + dispatch(lbryRedux.doWalletDecrypt()); + } }).then(() => lbryRedux.Lbry.sync_apply({ password: newPassword })).then(syncApplyResponse => { @@ -3269,7 +3275,6 @@ exports.Lbryio = Lbryio; exports.YOUTUBE_STATUSES = youtube; exports.authReducer = authReducer; exports.blacklistReducer = blacklistReducer; -exports.changeSyncPassword = changeSyncPassword; exports.costInfoReducer = costInfoReducer; exports.doAuthenticate = doAuthenticate; exports.doBlackListedOutpointsSubscribe = doBlackListedOutpointsSubscribe; @@ -3310,6 +3315,7 @@ exports.doSetSync = doSetSync; exports.doSetViewMode = doSetViewMode; exports.doShowSuggestedSubs = doShowSuggestedSubs; exports.doSyncApply = doSyncApply; +exports.doSyncEncryptAndDecrypt = doSyncEncryptAndDecrypt; exports.doUpdateUnreadSubscriptions = doUpdateUnreadSubscriptions; exports.doUserCheckEmailVerified = doUserCheckEmailVerified; exports.doUserEmailNew = doUserEmailNew; diff --git a/dist/bundle.js b/dist/bundle.js index 2f6ea81..b66e5c4 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -234,6 +234,8 @@ __webpack_require__.r(__webpack_exports__); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doResetSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_15__["doResetSync"]; }); +/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doSyncEncryptAndDecrypt", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_15__["doSyncEncryptAndDecrypt"]; }); + /* harmony import */ var redux_reducers_auth__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(29); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "authReducer", function() { return redux_reducers_auth__WEBPACK_IMPORTED_MODULE_16__["authReducer"]; }); @@ -3890,6 +3892,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSyncApply", function() { return doSyncApply; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return doCheckSync; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doResetSync", function() { return doResetSync; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doSyncEncryptAndDecrypt", function() { return doSyncEncryptAndDecrypt; }); /* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); /* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3); /* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4); @@ -4039,7 +4042,9 @@ function doGetSync(passedPassword, callback) { data: data }); handleCallback(); - })["catch"](function () { + })["catch"](function (err) { + console.log('error', err); + if (data.hasSyncedWallet) { var error = 'Error getting synced wallet'; dispatch({ @@ -4145,6 +4150,36 @@ function doResetSync() { }); }; } +function doSyncEncryptAndDecrypt(oldPassword, newPassword, encrypt) { + return function (dispatch) { + var data = {}; + return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_hash().then(function (hash) { + return lbryio__WEBPACK_IMPORTED_MODULE_1__["default"].call('sync', 'get', { + hash: hash + }, 'post'); + }).then(function (syncGetResponse) { + data.oldHash = syncGetResponse.hash; + return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({ + password: oldPassword, + data: syncGetResponse.data + }); + }).then(function () { + if (encrypt) { + dispatch(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_2__["doWalletEncrypt"])(newPassword)); + } else { + dispatch(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_2__["doWalletDecrypt"])()); + } + }).then(function () { + return lbry_redux__WEBPACK_IMPORTED_MODULE_2__["Lbry"].sync_apply({ + password: newPassword + }); + }).then(function (syncApplyResponse) { + if (syncApplyResponse.hash !== data.oldHash) { + return dispatch(doSetSync(data.oldHash, syncApplyResponse.hash, syncApplyResponse.data)); + } + })["catch"](console.error); + }; +} /***/ }), /* 29 */ diff --git a/src/index.js b/src/index.js index 5ce467e..616bd84 100644 --- a/src/index.js +++ b/src/index.js @@ -73,7 +73,7 @@ export { doSetDefaultAccount, doSyncApply, doResetSync, - changeSyncPassword, + doSyncEncryptAndDecrypt, } from 'redux/actions/sync'; // reducers diff --git a/src/redux/actions/sync.js b/src/redux/actions/sync.js index ef7942d..56f67df 100644 --- a/src/redux/actions/sync.js +++ b/src/redux/actions/sync.js @@ -1,6 +1,6 @@ import * as ACTIONS from 'constants/action_types'; import Lbryio from 'lbryio'; -import { Lbry } from 'lbry-redux'; +import { Lbry, doWalletEncrypt, doWalletDecrypt } from 'lbry-redux'; export function doSetDefaultAccount(success, failure) { return dispatch => { @@ -231,19 +231,23 @@ export function doResetSync() { }); } -export function changeSyncPassword(oldPassword, newPassword) { +export function doSyncEncryptAndDecrypt(oldPassword, newPassword, encrypt) { return dispatch => { - let data = {}; - + const data = {}; return Lbry.sync_hash() - .then(hash => { - return Lbryio.call('sync', 'get', { hash }, 'post'); - }) + .then(hash => Lbryio.call('sync', 'get', { hash }, 'post')) .then(syncGetResponse => { data.oldHash = syncGetResponse.hash; return Lbry.sync_apply({ password: oldPassword, data: syncGetResponse.data }); }) + .then(() => { + if (encrypt) { + dispatch(doWalletEncrypt(newPassword)); + } else { + dispatch(doWalletDecrypt()); + } + }) .then(() => Lbry.sync_apply({ password: newPassword })) .then(syncApplyResponse => { if (syncApplyResponse.hash !== data.oldHash) { From 2b968526c8fb5da7abbdee3665c2b1e83124938f Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 21 Oct 2019 12:35:52 -0400 Subject: [PATCH 3/3] remove console logs --- dist/bundle.es.js | 14 +++++--------- dist/bundle.js | 4 +--- src/redux/actions/sync.js | 3 +-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 421620f..e0eabbc 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2472,9 +2472,7 @@ function doGetSync(passedPassword, callback) { data }); handleCallback(); - }).catch(err => { - console.log('error', err); - + }).catch(() => { if (data.hasSyncedWallet) { const error = 'Error getting synced wallet'; dispatch({ @@ -2582,12 +2580,10 @@ function doResetSync() { } function doSyncEncryptAndDecrypt(oldPassword, newPassword, encrypt) { return dispatch => { - let data = {}; - return lbryRedux.Lbry.sync_hash().then(hash => { - return Lbryio.call('sync', 'get', { - hash - }, 'post'); - }).then(syncGetResponse => { + const data = {}; + return lbryRedux.Lbry.sync_hash().then(hash => Lbryio.call('sync', 'get', { + hash + }, 'post')).then(syncGetResponse => { data.oldHash = syncGetResponse.hash; return lbryRedux.Lbry.sync_apply({ password: oldPassword, diff --git a/dist/bundle.js b/dist/bundle.js index b66e5c4..02d57d7 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -4042,9 +4042,7 @@ function doGetSync(passedPassword, callback) { data: data }); handleCallback(); - })["catch"](function (err) { - console.log('error', err); - + })["catch"](function () { if (data.hasSyncedWallet) { var error = 'Error getting synced wallet'; dispatch({ diff --git a/src/redux/actions/sync.js b/src/redux/actions/sync.js index 56f67df..95dfd44 100644 --- a/src/redux/actions/sync.js +++ b/src/redux/actions/sync.js @@ -132,8 +132,7 @@ export function doGetSync(passedPassword, callback) { dispatch({ type: ACTIONS.GET_SYNC_COMPLETED, data }); handleCallback(); }) - .catch(err => { - console.log('error', err); + .catch(() => { if (data.hasSyncedWallet) { const error = 'Error getting synced wallet'; dispatch({