add: sync encrypt and decrypt (#71)

add: sync encrypt and decrypt
This commit is contained in:
Sean Yesmunt 2019-10-21 12:37:46 -04:00 committed by GitHub
commit b4063b7684
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 1 deletions

27
dist/bundle.es.js vendored
View file

@ -2578,6 +2578,32 @@ function doResetSync() {
resolve();
});
}
function doSyncEncryptAndDecrypt(oldPassword, newPassword, encrypt) {
return dispatch => {
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,
data: syncGetResponse.data
});
}).then(() => {
if (encrypt) {
dispatch(lbryRedux.doWalletEncrypt(newPassword));
} else {
dispatch(lbryRedux.doWalletDecrypt());
}
}).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 = {
@ -3285,6 +3311,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;

33
dist/bundle.js vendored
View file

@ -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);
@ -4145,6 +4148,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 */

View file

@ -73,6 +73,7 @@ export {
doSetDefaultAccount,
doSyncApply,
doResetSync,
doSyncEncryptAndDecrypt,
} from 'redux/actions/sync';
// reducers

View file

@ -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 => {
@ -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));
@ -228,3 +229,30 @@ export function doResetSync() {
resolve();
});
}
export function doSyncEncryptAndDecrypt(oldPassword, newPassword, encrypt) {
return dispatch => {
const data = {};
return Lbry.sync_hash()
.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) {
return dispatch(doSetSync(data.oldHash, syncApplyResponse.hash, syncApplyResponse.data));
}
})
.catch(console.error);
};
}