From 50a0c8ffd4677e1a84feb91bc32f7c201b0dc0b9 Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 2 Oct 2015 15:56:59 -0300 Subject: [PATCH] add private key creation control --- src/js/controllers/paperWallet.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js index 2eecf1432..44135aa1c 100644 --- a/src/js/controllers/paperWallet.js +++ b/src/js/controllers/paperWallet.js @@ -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) {