Desktop secure storage update, fallback to previous storage on error
This commit is contained in:
parent
80299cd99d
commit
900630807a
2 changed files with 19 additions and 3 deletions
|
|
@ -1,12 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('desktopSecureStorageService', function($log, appConfigService, platformInfo, lodash) {
|
||||
angular.module('copayApp.services').factory('desktopSecureStorageService', function($log, appConfigService, platformInfo, lodash, localStorageService) {
|
||||
var root = {};
|
||||
var storage = null;
|
||||
var serviceName = appConfigService.packageNameId;
|
||||
var initialisationFailed = false;
|
||||
|
||||
if (platformInfo.isNW) {
|
||||
storage = require('keytar');
|
||||
try {
|
||||
var os = require('os');
|
||||
var arch = (os.arch() === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) ? 'x64':'ia32';
|
||||
var file = './keytar/keytar-prebuild-v4.1.1-node-v51-'+process.platform+'-'+arch+'.node';
|
||||
storage = require('keytar');
|
||||
storage.setKeytarInstance(require(file));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
initialisationFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
root.get = function(key, cb) {
|
||||
|
|
@ -15,6 +25,9 @@ angular.module('copayApp.services').factory('desktopSecureStorageService', funct
|
|||
return;
|
||||
}
|
||||
|
||||
if (initialisationFailed)
|
||||
return localStorageService.get(key, cb);
|
||||
|
||||
storage.getPassword(serviceName, key).then(function(result) {
|
||||
return cb(null, result); // XX SP: result is null if no value is found as it should
|
||||
}).catch(function (error) {
|
||||
|
|
@ -28,6 +41,9 @@ angular.module('copayApp.services').factory('desktopSecureStorageService', funct
|
|||
return;
|
||||
}
|
||||
|
||||
if (initialisationFailed)
|
||||
return localStorageService.set(key, value, cb);
|
||||
|
||||
if (lodash.isObject(value)) {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue