Compare commits
10 commits
master
...
wallet/tas
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3eada5ad7c | ||
|
|
4a97292748 | ||
|
|
c7abf03d54 | ||
|
|
5f4eb9747e | ||
|
|
c40b6c168a | ||
|
|
900630807a | ||
|
|
80299cd99d | ||
|
|
7c5a61a88b | ||
|
|
e4983d3604 | ||
|
|
f70e8607ea |
10 changed files with 93 additions and 10 deletions
|
|
@ -81,6 +81,7 @@
|
|||
"grunt-exec": "^1.0.0",
|
||||
"grunt-nw-builder": "^2.0.3",
|
||||
"grunt-sass": "^1.2.0",
|
||||
"keytar": "git+https://github.com/spasma/node-keytar.git",
|
||||
"load-grunt-tasks": "^3.5.0",
|
||||
"shelljs": "^0.3.0",
|
||||
"android-versions": "^1.2.1",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,82 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('desktopSecureStorageService', function($log) {
|
||||
// Placeholder
|
||||
return {};
|
||||
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) {
|
||||
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) {
|
||||
if (!platformInfo.isNW) {
|
||||
cb(new Error('desktopSecureStorageService is only available on NW.js desktop.'));
|
||||
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) {
|
||||
cb(new Error(error));
|
||||
});
|
||||
};
|
||||
|
||||
root.remove = function(key, cb) {
|
||||
if (!platformInfo.isNW) {
|
||||
cb(new Error('desktopSecureStorageService is only available on NW.js desktop.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (initialisationFailed)
|
||||
return localStorageService.remove(key, cb);
|
||||
|
||||
storage.removePassword(serviceName, key).then(function (value) {
|
||||
cb();
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
cb(new Error(error));
|
||||
})
|
||||
};
|
||||
|
||||
root.set = function(key, value, cb) {
|
||||
if (!platformInfo.isNW) {
|
||||
cb(new Error('desktopSecureStorageService is only available on NW.js desktop.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (initialisationFailed)
|
||||
return localStorageService.set(key, value, cb);
|
||||
|
||||
if (lodash.isObject(value)) {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
if (value && !lodash.isString(value)) {
|
||||
value = value.toString();
|
||||
}
|
||||
|
||||
storage.deletePassword(serviceName, key).then(function (result) {
|
||||
storage.setPassword(serviceName, key, value).then(function (value) {
|
||||
cb();
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
cb(new Error(error));
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
@ -66,5 +66,11 @@ angular.module('copayApp.services').factory('platformInfo', function($window) {
|
|||
ret.versionIntelTEE = getVersionIntelTee();
|
||||
ret.supportsIntelTEE = ret.versionIntelTEE.length > 0;
|
||||
|
||||
ret.isMac = typeof process !== 'undefined'?process.platform === 'darwin':false;
|
||||
ret.isWindows = typeof process !== 'undefined'?process.platform === 'win32':false;
|
||||
ret.isLinux = typeof process !== 'undefined'?process.platform === 'linux':false;
|
||||
|
||||
ret.isDesktopApp = ret.isNW && (ret.isMac || ret.isWindows || ret.isLinux);
|
||||
|
||||
return ret;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ angular.module('copayApp.services')
|
|||
|
||||
var walletId = client.credentials.walletId
|
||||
|
||||
if (!root.profile.addWallet(JSON.parse(client.export())))
|
||||
if (root.profile && !root.profile.addWallet(JSON.parse(client.export())))
|
||||
return cb(gettextCatalog.getString("Wallet already in {{appName}}", {
|
||||
appName: appConfigService.nameCase
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ angular.module('copayApp.services')
|
|||
|
||||
root.storeProfile = function(profile, cb) {
|
||||
var profileString = profile.toObj();
|
||||
if (platformInfo.isNW) {
|
||||
if (platformInfo.isNW && !platformInfo.isMac) {
|
||||
storage.set('profile', profileString, cb);
|
||||
} else {
|
||||
secureStorageService.set('profile', profileString, cb);
|
||||
|
|
@ -205,7 +205,7 @@ angular.module('copayApp.services')
|
|||
* @param {getProfileCallback} cb
|
||||
*/
|
||||
root.getProfile = function(cb) {
|
||||
if (platformInfo.isNW) {
|
||||
if (platformInfo.isNW && !platformInfo.isMac) {
|
||||
storage.get('profile', function(getErr, getStr) {
|
||||
_onOldProfileRetrieved(getErr, getStr, cb);
|
||||
});
|
||||
|
|
@ -728,15 +728,15 @@ angular.module('copayApp.services')
|
|||
|
||||
root.setReceivedTransactions = function(walletId, txIds, cb) {
|
||||
storage.set('receivedTxs-' + walletId, txIds, cb);
|
||||
}
|
||||
};
|
||||
|
||||
root.getReceivedTransactions = function(walletId, cb) {
|
||||
storage.get('receivedTxs-' + walletId, cb);
|
||||
}
|
||||
};
|
||||
|
||||
root.removeReceivedTransactions = function(walletId, cb) {
|
||||
storage.remove('receivedTxs-' + walletId, cb);
|
||||
}
|
||||
};
|
||||
|
||||
root.checkIfFlagIsSet = function(key) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
|
|
@ -748,7 +748,7 @@ angular.module('copayApp.services')
|
|||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-darwin-x64.node
Executable file
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-darwin-x64.node
Executable file
Binary file not shown.
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-linux-ia32.node
Executable file
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-linux-ia32.node
Executable file
Binary file not shown.
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-linux-x64.node
Executable file
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-linux-x64.node
Executable file
Binary file not shown.
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-win32-ia32.node
Normal file
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-win32-ia32.node
Normal file
Binary file not shown.
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-win32-x64.node
Normal file
BIN
www/keytar/keytar-prebuild-v4.1.1-node-v51-win32-x64.node
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue