add private key creation control

This commit is contained in:
Javier 2015-10-02 15:56:59 -03:00
commit 50a0c8ffd4

View file

@ -1,15 +1,22 @@
angular.module('copayApp.controllers').controller('paperWalletController', angular.module('copayApp.controllers').controller('paperWalletController',
function($scope, $http, $timeout, profileService, go, addressService, isCordova) { function($scope, $http, $timeout, $rootScope, profileService, go, addressService, isCordova, gettext, bitcore) {
self = this; self = this;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var rawTx; var rawTx;
self.isCordova = isCordova;
if (isCordova) self.message = "Decrypting a paper wallet could take around 5 minutes on this device. please be patient and keep the app open."
self.onQrCodeScanned = function(data) { self.onQrCodeScanned = function(data) {
$scope.privateKey = data; $scope.privateKey = data;
} }
self.createTx = function(privateKey, passphrase) { self.createTx = function(privateKey, passphrase) {
if (privateKey.charAt(0) != 6) {
var isValidPrivateKey = self.checkPrivateKey(privateKey);
if (isValidPrivateKey != true) return self.error = isValidPrivateKey;
}
self.error = null; self.error = null;
self.scanning = true; self.scanning = true;
$timeout(function() { $timeout(function() {
@ -30,6 +37,15 @@ angular.module('copayApp.controllers').controller('paperWalletController',
}, 100); }, 100);
}; };
self.checkPrivateKey = function(privateKey) {
try {
new bitcore.PrivateKey(privateKey, 'livenet');
} catch (err) {
return err.toString();
}
return true;
}
self.getRawTx = function(privateKey, passphrase, cb) { self.getRawTx = function(privateKey, passphrase, cb) {
if (privateKey.charAt(0) == 6) { if (privateKey.charAt(0) == 6) {
fc.decryptBIP38PrivateKey(privateKey, passphrase, null, function(err, privateKey) { fc.decryptBIP38PrivateKey(privateKey, passphrase, null, function(err, privateKey) {