Merge remote-tracking branch 'origin/wallet/task/351' into wallet/task/366
# Conflicts: # src/js/services/storageService.js
This commit is contained in:
commit
e4983d3604
5 changed files with 133 additions and 18 deletions
|
|
@ -72,6 +72,8 @@
|
|||
<plugin name="cordova-plugin-queries-schemes" spec="~0.1.5" />
|
||||
<plugin name="cordova-plugin-firebase" spec="https://github.com/arnesson/cordova-plugin-firebase.git" />
|
||||
<plugin name="cordova-plugin-wkwebview-inputfocusfix" spec="https://github.com/onderceylan/cordova-plugin-wkwebview-inputfocusfix.git" />
|
||||
<!-- Changes in error descriptions may break the use of cordova-plugin-secure-storage -->
|
||||
<plugin name="cordova-plugin-secure-storage" spec="2.6.8" />
|
||||
<!-- Supported Platforms -->
|
||||
<engine name="ios" spec="~4.5.3" />
|
||||
<engine name="android" spec="~6.3.0" />
|
||||
|
|
|
|||
6
src/js/services/desktopSecureStorageService.js
Normal file
6
src/js/services/desktopSecureStorageService.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('desktopSecureStorageService', function($log) {
|
||||
// Placeholder
|
||||
return {};
|
||||
});
|
||||
88
src/js/services/mobileSecureStorageService.js
Normal file
88
src/js/services/mobileSecureStorageService.js
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('mobileSecureStorageService', function($log, appConfigService, platformInfo) {
|
||||
var root = {};
|
||||
|
||||
var isReady = false;
|
||||
var initialisationFailed = false;
|
||||
var pending = [];
|
||||
|
||||
var storage = null;
|
||||
|
||||
if (platformInfo.isCordova) {
|
||||
storage = new cordova.plugins.SecureStorage(
|
||||
function () {
|
||||
isReady = true;
|
||||
for (var i = 0; i < pending.length; i++) {
|
||||
pending[i]();
|
||||
}
|
||||
pending = [];
|
||||
},
|
||||
function (error) {
|
||||
initialisationFailed = true;
|
||||
},
|
||||
appConfigService.packageNameId);
|
||||
}
|
||||
|
||||
root.get = function(key, cb) {
|
||||
|
||||
if (!platformInfo.isMobile) {
|
||||
cb(new Error('mobileSecureStorageService is only available on mobile.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isReady) {
|
||||
if (initialisationFailed) {
|
||||
cb(new Error('mobileSecureStorageService initialisation failed.'));
|
||||
} else {
|
||||
pending.push(function(){ root.get(key, cb); });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
storage.get(
|
||||
function (value) {
|
||||
cb(null, value);
|
||||
},
|
||||
function (error) {
|
||||
$log.debug('mss get failed. ' + error);
|
||||
if (error.message === 'Failure in SecureStorage.get() - The specified item could not be found in the keychain' || // iOS
|
||||
error.message === 'Key [_SS_profile] not found.') { // Android
|
||||
// The callback expects no error, but also no value, if it cannot be found.
|
||||
cb(null, null);
|
||||
} else {
|
||||
cb(new Error(error));
|
||||
}
|
||||
},
|
||||
key);
|
||||
};
|
||||
|
||||
root.set = function(key, value, cb) {
|
||||
|
||||
if (!platformInfo.isMobile) {
|
||||
cb(new Error('mobileSecureStorageService is only available on mobile.'));
|
||||
}
|
||||
|
||||
if (!isReady) {
|
||||
if (initialisationFailed) {
|
||||
cb(new Error('mobileSecureStorageService initialisation failed.'));
|
||||
} else {
|
||||
pending.push(function(){ root.set(key, value, cb); });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
storage.set(
|
||||
function (value) {
|
||||
cb();
|
||||
},
|
||||
function (error) {
|
||||
cb(new Error(error));
|
||||
},
|
||||
key, value);
|
||||
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
||||
32
src/js/services/secureStorageService.js
Normal file
32
src/js/services/secureStorageService.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('secureStorageService', function(desktopSecureStorageService, localStorageService, $log, mobileSecureStorageService, platformInfo) {
|
||||
var root = {};
|
||||
|
||||
// To make wrong code look wrong
|
||||
function alteredKeyIndicatingDesireForSecureStorage(key) {
|
||||
return key + ":desiredSecure";
|
||||
}
|
||||
|
||||
root.get = function(k, cb) {
|
||||
if (platformInfo.isMobile) {
|
||||
mobileSecureStorageService.get(k, cb);
|
||||
} else if (platformInfo.isNW) {
|
||||
desktopSecureStorageService.get(k, cb);
|
||||
} else { // Browser
|
||||
localStorageService.get(alteredKeyIndicatingDesireForSecureStorage(k), cb);
|
||||
}
|
||||
}
|
||||
|
||||
root.set = function(k, v, cb) {
|
||||
if (platformInfo.isMobile) {
|
||||
mobileSecureStorageService.set(k, v, cb);
|
||||
} else if (platformInfo.isNW) {
|
||||
desktopSecureStorageService.set(k, v, cb);
|
||||
} else { // Browser
|
||||
localStorageService.set(alteredKeyIndicatingDesireForSecureStorage(k), v, cb);
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services')
|
||||
.factory('storageService', function(logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, $timeout, desktopSecureStorageService) {
|
||||
.factory('storageService', function(logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, secureStorageService, $timeout) {
|
||||
|
||||
var root = {};
|
||||
var storage;
|
||||
var profileStorage;
|
||||
var isNW = platformInfo.isNW;
|
||||
|
||||
// File storage is not supported for writing according to
|
||||
// https://github.com/apache/cordova-plugin-file/#supported-platforms
|
||||
|
|
@ -19,7 +17,6 @@ angular.module('copayApp.services')
|
|||
storage = localStorageService;
|
||||
}
|
||||
|
||||
profileStorage = storage;
|
||||
/* migration script */
|
||||
// var migratingProfile = false;
|
||||
// if (isNW) {
|
||||
|
|
@ -147,16 +144,16 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.storeNewProfile = function(profile, cb) {
|
||||
profileStorage.create('profile', profile.toObj(), cb);
|
||||
secureStorageService.set('profile', profile.toObj(), cb);
|
||||
};
|
||||
|
||||
root.storeProfile = function(profile, cb) {
|
||||
profileStorage.set('profile', profile.toObj(), cb);
|
||||
secureStorageService.set('profile', profile.toObj(), cb);
|
||||
};
|
||||
|
||||
root.getProfile = function(cb) {
|
||||
// if (!migratingProfile) {
|
||||
profileStorage.get('profile', function(err, str) {
|
||||
secureStorageService.get('profile', function(err, str) {
|
||||
|
||||
if (err || !str)
|
||||
return cb(err);
|
||||
|
||||
|
|
@ -172,16 +169,6 @@ angular.module('copayApp.services')
|
|||
return cb(err, p);
|
||||
});
|
||||
});
|
||||
// } else {
|
||||
// setTimeout(function() {
|
||||
// $log.debug('Wait for a while.. Migrating..');
|
||||
// root.getProfile(cb);
|
||||
// }, 500);
|
||||
// }
|
||||
};
|
||||
|
||||
root.deleteProfile = function(cb) {
|
||||
profileStorage.remove('profile', cb);
|
||||
};
|
||||
|
||||
root.setFeedbackInfo = function(feedbackValues, cb) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue