2018-05-31 17:53:58 +12:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-06-01 10:19:26 +12:00
|
|
|
angular.module('copayApp.services').factory('secureStorageService', function(desktopSecureStorageService, localStorageService, $log, mobileSecureStorageService, platformInfo) {
|
2018-05-31 17:53:58 +12:00
|
|
|
var root = {};
|
|
|
|
|
|
2018-06-01 10:19:26 +12:00
|
|
|
// To make wrong code look wrong
|
|
|
|
|
function alteredKeyIndicatingDesireForSecureStorage(key) {
|
|
|
|
|
return key + ":desiredSecure";
|
|
|
|
|
}
|
2018-05-31 17:53:58 +12:00
|
|
|
|
2018-06-01 10:19:26 +12:00
|
|
|
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);
|
2018-05-31 17:53:58 +12:00
|
|
|
}
|
2018-06-01 10:19:26 +12:00
|
|
|
}
|
2018-05-31 17:53:58 +12:00
|
|
|
|
2018-06-01 10:19:26 +12:00
|
|
|
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);
|
2018-06-01 09:31:14 +12:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-01 10:19:26 +12:00
|
|
|
|
2018-05-31 17:53:58 +12:00
|
|
|
return root;
|
2018-06-01 10:19:26 +12:00
|
|
|
});
|