Generate local priv key
This commit is contained in:
parent
b82bdaaafc
commit
87535b3f24
5 changed files with 61 additions and 78 deletions
|
|
@ -4,7 +4,9 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
$scope.dateRange = 'last30Days';
|
$scope.dateRange = 'last30Days';
|
||||||
$scope.network = bitpayCardService.getEnvironment();
|
bitpayCardService.getEnvironment(function(err, network) {
|
||||||
|
$scope.network = network;
|
||||||
|
});
|
||||||
|
|
||||||
var getFromCache = function(cb) {
|
var getFromCache = function(cb) {
|
||||||
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
|
bitpayCardService.getBitpayDebitCardsHistory($scope.cardId, function(err, data) {
|
||||||
|
|
|
||||||
|
|
@ -203,11 +203,11 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
||||||
|
|
||||||
var bitpayCardCache = function() {
|
var bitpayCardCache = function() {
|
||||||
bitpayCardService.getBitpayDebitCards(function(err, data) {
|
bitpayCardService.getBitpayDebitCards(function(err, data) {
|
||||||
if (err) return;
|
if (err || lodash.isEmpty(data)) return;
|
||||||
$scope.bitpayCards = data.cards;
|
$scope.bitpayCards = data.cards;
|
||||||
});
|
});
|
||||||
bitpayCardService.getBitpayDebitCardsHistory(null, function(err, data) {
|
bitpayCardService.getBitpayDebitCardsHistory(null, function(err, data) {
|
||||||
if (err || lodash.isEmpty(data)) return;
|
if (err || lodash.isEmpty(data)) return;
|
||||||
$scope.cardsHistory = data;
|
$scope.cardsHistory = data;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,38 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
var bpSession = {};
|
var bpSession = {};
|
||||||
var pubkey, sin;
|
var pubkey, sin;
|
||||||
|
|
||||||
var _setCredentials = function() {
|
var _setCredentials = function(cb) {
|
||||||
if (!$window.externalServices || !$window.externalServices.bitpayCard) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bitpayCard = $window.externalServices.bitpayCard;
|
|
||||||
/*
|
/*
|
||||||
* Development: 'testnet'
|
* Development: 'testnet'
|
||||||
* Production: 'livenet'
|
* Production: 'livenet'
|
||||||
*/
|
*/
|
||||||
credentials.NETWORK = 'livenet';
|
credentials.NETWORK = 'testnet';
|
||||||
if (credentials.NETWORK == 'testnet') {
|
if (credentials.NETWORK == 'testnet') {
|
||||||
credentials.BITPAY_PRIV_KEY = bitpayCard.sandbox.secret;
|
credentials.BITPAY_API_URL = 'https://gustavo.bp:8088';
|
||||||
credentials.BITPAY_API_URL = bitpayCard.sandbox.host;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
credentials.BITPAY_PRIV_KEY = bitpayCard.production.secret;
|
credentials.BITPAY_API_URL = 'https://bitpay.com';
|
||||||
credentials.BITPAY_API_URL = bitpayCard.production.host;
|
|
||||||
}
|
}
|
||||||
try {
|
storageService.getBitpayDebitCardSin(credentials.NETWORK, function(err, data) {
|
||||||
pubkey = bitauthService.getPublicKeyFromPrivateKey(credentials.BITPAY_PRIV_KEY);
|
if (err) return cb(err);
|
||||||
sin = bitauthService.getSinFromPublicKey(pubkey);
|
if (lodash.isString(data)) {
|
||||||
}
|
data = JSON.parse(data);
|
||||||
catch (e) {
|
}
|
||||||
$log.error(e);
|
data = data || {};
|
||||||
};
|
if (lodash.isEmpty(data) || (data && !data.priv)) {
|
||||||
|
data = bitauthService.generateSin();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
credentials.BITPAY_PRIV_KEY = data.priv
|
||||||
|
pubkey = bitauthService.getPublicKeyFromPrivateKey(credentials.BITPAY_PRIV_KEY);
|
||||||
|
sin = bitauthService.getSinFromPublicKey(pubkey);
|
||||||
|
storageService.setBitpayDebitCardSin(credentials.NETWORK, JSON.stringify(data), function(err) {});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
$log.error(e);
|
||||||
|
return cb(e);
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var _setError = function(msg, e) {
|
var _setError = function(msg, e) {
|
||||||
|
|
@ -41,7 +47,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
};
|
};
|
||||||
|
|
||||||
var _getSession = function(cb) {
|
var _getSession = function(cb) {
|
||||||
_setCredentials();
|
_setCredentials(cb);
|
||||||
$http({
|
$http({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: credentials.BITPAY_API_URL + '/api/session',
|
url: credentials.BITPAY_API_URL + '/api/session',
|
||||||
|
|
@ -50,15 +56,13 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
}
|
}
|
||||||
}).then(function(data) {
|
}).then(function(data) {
|
||||||
$log.info('BitPay Get Session: SUCCESS');
|
$log.info('BitPay Get Session: SUCCESS');
|
||||||
bpSession = data.data.data;
|
return cb(data.data.error, data.data.data);
|
||||||
return cb(null, bpSession);
|
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
return cb(_setError('BitPay Card Error: Get Session', data));
|
return cb(_setError('BitPay Card Error: Get Session', data));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var _getBitPay = function(endpoint) {
|
var _getBitPay = function(endpoint) {
|
||||||
_setCredentials();
|
|
||||||
return {
|
return {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: credentials.BITPAY_API_URL + endpoint,
|
url: credentials.BITPAY_API_URL + endpoint,
|
||||||
|
|
@ -69,33 +73,13 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var _postBitPay = function(endpoint, data) {
|
root.getEnvironment = function(cb) {
|
||||||
_setCredentials();
|
_setCredentials(cb);
|
||||||
return {
|
return cb(null, credentials.NETWORK);
|
||||||
method: 'POST',
|
|
||||||
url: credentials.BITPAY_API_URL + endpoint,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'x-csrf-token': bpSession.csrfToken
|
|
||||||
},
|
|
||||||
data: data
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
root.getEnvironment = function() {
|
|
||||||
_setCredentials();
|
|
||||||
return credentials.NETWORK;
|
|
||||||
};
|
|
||||||
|
|
||||||
root.getApiUrl = function() {
|
|
||||||
_setCredentials();
|
|
||||||
return credentials.BITPAY_API_URL;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.testSession = function(cb) {
|
root.testSession = function(cb) {
|
||||||
_getSession(function(err, session) {
|
_getSession(cb);
|
||||||
return cb(err, session);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var _postBitAuth = function(endpoint, data) {
|
var _postBitAuth = function(endpoint, data) {
|
||||||
|
|
@ -209,6 +193,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
method: 'getInvoiceHistory',
|
method: 'getInvoiceHistory',
|
||||||
params: JSON.stringify(params)
|
params: JSON.stringify(params)
|
||||||
};
|
};
|
||||||
|
_setCredentials(cb);
|
||||||
root.getBitpayDebitCards(function(err, data) {
|
root.getBitpayDebitCards(function(err, data) {
|
||||||
var card = lodash.find(data.cards, {id : cardId});
|
var card = lodash.find(data.cards, {id : cardId});
|
||||||
if (!card) return cb(_setError('No card available'));
|
if (!card) return cb(_setError('No card available'));
|
||||||
|
|
@ -240,6 +225,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
method: 'generateTopUpInvoice',
|
method: 'generateTopUpInvoice',
|
||||||
params: JSON.stringify(params)
|
params: JSON.stringify(params)
|
||||||
};
|
};
|
||||||
|
_setCredentials(cb);
|
||||||
root.getBitpayDebitCards(function(err, data) {
|
root.getBitpayDebitCards(function(err, data) {
|
||||||
var card = lodash.find(data.cards, {id : cardId});
|
var card = lodash.find(data.cards, {id : cardId});
|
||||||
if (!card) return cb(_setError('No card available'));
|
if (!card) return cb(_setError('No card available'));
|
||||||
|
|
@ -254,6 +240,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getInvoice = function(id, cb) {
|
root.getInvoice = function(id, cb) {
|
||||||
|
_setCredentials(cb);
|
||||||
$http(_getBitPay('/invoices/' + id)).then(function(data) {
|
$http(_getBitPay('/invoices/' + id)).then(function(data) {
|
||||||
$log.info('BitPay Get Invoice: SUCCESS');
|
$log.info('BitPay Get Invoice: SUCCESS');
|
||||||
return cb(null, data.data.data);
|
return cb(null, data.data.data);
|
||||||
|
|
@ -263,7 +250,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getBitpayDebitCards = function(cb) {
|
root.getBitpayDebitCards = function(cb) {
|
||||||
_setCredentials();
|
_setCredentials(cb);
|
||||||
storageService.getBitpayDebitCards(credentials.NETWORK, function(err, data) {
|
storageService.getBitpayDebitCards(credentials.NETWORK, function(err, data) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (lodash.isString(data)) {
|
if (lodash.isString(data)) {
|
||||||
|
|
@ -275,7 +262,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setBitpayDebitCards = function(data, cb) {
|
root.setBitpayDebitCards = function(data, cb) {
|
||||||
_setCredentials();
|
_setCredentials(cb);
|
||||||
data = JSON.stringify(data);
|
data = JSON.stringify(data);
|
||||||
storageService.setBitpayDebitCards(credentials.NETWORK, data, function(err) {
|
storageService.setBitpayDebitCards(credentials.NETWORK, data, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
@ -283,16 +270,8 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.removeBitpayDebitCards = function(cb) {
|
|
||||||
_setCredentials();
|
|
||||||
storageService.removeBitpayDebitCards(credentials.NETWORK, function(err) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
root.getBitpayDebitCardsHistory = function(cardId, cb) {
|
root.getBitpayDebitCardsHistory = function(cardId, cb) {
|
||||||
_setCredentials();
|
_setCredentials(cb);
|
||||||
storageService.getBitpayDebitCardsHistory(credentials.NETWORK, function(err, data) {
|
storageService.getBitpayDebitCardsHistory(credentials.NETWORK, function(err, data) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (lodash.isString(data)) {
|
if (lodash.isString(data)) {
|
||||||
|
|
@ -305,7 +284,7 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setBitpayDebitCardsHistory = function(cardId, data, opts, cb) {
|
root.setBitpayDebitCardsHistory = function(cardId, data, opts, cb) {
|
||||||
_setCredentials();
|
_setCredentials(cb);
|
||||||
storageService.getBitpayDebitCardsHistory(credentials.NETWORK, function(err, oldData) {
|
storageService.getBitpayDebitCardsHistory(credentials.NETWORK, function(err, oldData) {
|
||||||
if (lodash.isString(oldData)) {
|
if (lodash.isString(oldData)) {
|
||||||
oldData = JSON.parse(oldData);
|
oldData = JSON.parse(oldData);
|
||||||
|
|
@ -326,20 +305,14 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.removeBitpayDebitCardsHistory = function(cb) {
|
|
||||||
_setCredentials();
|
|
||||||
storageService.removeBitpayDebitCardsHistory(credentials.NETWORK, function(err) {
|
|
||||||
if (err) return cb(err);
|
|
||||||
return cb();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
root.remove = function(cb) {
|
root.remove = function(cb) {
|
||||||
_setCredentials();
|
_setCredentials(cb);
|
||||||
storageService.removeBitpayDebitCards(credentials.NETWORK, function(err) {
|
storageService.removeBitpayDebitCardSin(credentials.NETWORK, function(err) {
|
||||||
storageService.removeBitpayDebitCardsHistory(credentials.NETWORK, function(err) {
|
storageService.removeBitpayDebitCards(credentials.NETWORK, function(err) {
|
||||||
$log.info('BitPay Debit Cards Removed: SUCCESS');
|
storageService.removeBitpayDebitCardsHistory(credentials.NETWORK, function(err) {
|
||||||
return cb();
|
$log.info('BitPay Debit Cards Removed: SUCCESS');
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -349,6 +349,18 @@ angular.module('copayApp.services')
|
||||||
storage.remove('bitpayDebitCards-' + network, cb);
|
storage.remove('bitpayDebitCards-' + network, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.setBitpayDebitCardSin = function(network, data, cb) {
|
||||||
|
storage.set('bitpayDebitCardSin-' + network, data, cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getBitpayDebitCardSin = function(network, cb) {
|
||||||
|
storage.get('bitpayDebitCardSin-' + network, cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.removeBitpayDebitCardSin = function(network, cb) {
|
||||||
|
storage.remove('bitpayDebitCardSin-' + network, cb);
|
||||||
|
};
|
||||||
|
|
||||||
root.removeAllWalletData = function(walletId, cb) {
|
root.removeAllWalletData = function(walletId, cb) {
|
||||||
root.clearLastAddress(walletId, function(err) {
|
root.clearLastAddress(walletId, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,6 @@ if (externalServices.glidera &&
|
||||||
if (externalServices.glidera &&
|
if (externalServices.glidera &&
|
||||||
(externalServices.glidera.sandbox.mobile.client_id || externalServices.glidera.sandbox.desktop.client_id))
|
(externalServices.glidera.sandbox.mobile.client_id || externalServices.glidera.sandbox.desktop.client_id))
|
||||||
console.log('Glidera Sandbox Enabled');
|
console.log('Glidera Sandbox Enabled');
|
||||||
if (externalServices.bitpayCard && externalServices.bitpayCard.production.secret)
|
|
||||||
console.log('BitPay Card Production Enabled');
|
|
||||||
if (externalServices.bitpayCard && externalServices.bitpayCard.sandbox.secret)
|
|
||||||
console.log('BitPay Card Sandbox Enabled');
|
|
||||||
|
|
||||||
var content = 'window.externalServices=' + JSON.stringify(externalServices) + ';';
|
var content = 'window.externalServices=' + JSON.stringify(externalServices) + ';';
|
||||||
fs.writeFileSync("./src/js/externalServices.js", content);
|
fs.writeFileSync("./src/js/externalServices.js", content);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue