add private key creation control

This commit is contained in:
Javier 2015-10-02 15:56:59 -03:00
parent 10b46ad31b
commit 50a0c8ffd4
1 changed files with 18 additions and 2 deletions

View File

@ -1,15 +1,22 @@
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;
var fc = profileService.focusedClient;
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) {
$scope.privateKey = data;
}
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.scanning = true;
$timeout(function() {
@ -30,6 +37,15 @@ angular.module('copayApp.controllers').controller('paperWalletController',
}, 100);
};
self.checkPrivateKey = function(privateKey) {
try {
new bitcore.PrivateKey(privateKey, 'livenet');
} catch (err) {
return err.toString();
}
return true;
}
self.getRawTx = function(privateKey, passphrase, cb) {
if (privateKey.charAt(0) == 6) {
fc.decryptBIP38PrivateKey(privateKey, passphrase, null, function(err, privateKey) {