Commit 081e4b6d authored by Benoit Lavenier's avatar Benoit Lavenier

[fix] Fix WIF/EWIF file generation

[fix] Fix WIF/EWIF QR code scan - fix #728
[fix] Add missing i18n (ES, IT)
[fix] Hide keyfile (and save ID) file generation , on small device
parent 66d257e7
......@@ -2001,11 +2001,11 @@ $ionicon-var-badge-editable: $ionicon-var-edit + "\00a0";
}
@media (max-width: $screen-xs-max) {
.popover.popover-login-methods {
height: 233px;
height: 233px !important;
}
.popover.popover-login-methods.auth {
height: 204px;
height: 233px;
}
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -390,6 +390,7 @@
"SCRYPT_FORM_HELP": "Please enter your credentials. <br> Remember to check the public key for your account.",
"PUBKEY_FORM_HELP": "Please enter a public account key:",
"FILE_FORM_HELP": "Choose the keychain file to use:",
"SCAN_FORM_HELP": "Scan the QR code of a wallet.",
"SALT": "Secret identifier",
"SALT_HELP": "Secret identifier",
"SHOW_SALT": "Display secret identifier?",
......@@ -442,7 +443,8 @@
"BTN_AUTH": "Authenticate",
"GENERAL_HELP": "Please authenticate yourself:",
"EXPECTED_UID_HELP": "Please authenticate to the account <i class=\"ion-person\"></i> {{uid}}:",
"EXPECTED_PUBKEY_HELP": "Please authenticate to the wallet <i class=\"ion-key\"></i> {{pubkey|formatPubkey}}:"
"EXPECTED_PUBKEY_HELP": "Please authenticate to the wallet <i class=\"ion-key\"></i> {{pubkey|formatPubkey}}:",
"SCAN_FORM_HELP": "Scan the QR code of the <b>private key</b> of the wallet."
},
"ACCOUNT": {
"TITLE": "My Account",
......
......@@ -390,6 +390,7 @@
"SCRYPT_FORM_HELP": "Please enter your credentials. <br> Remember to check the public key for your account.",
"PUBKEY_FORM_HELP": "Please enter a public account key:",
"FILE_FORM_HELP": "Choose the keychain file to use:",
"SCAN_FORM_HELP": "Scan the QR code of a wallet.",
"SALT": "Secret identifier",
"SALT_HELP": "Secret identifier",
"SHOW_SALT": "Display secret identifier?",
......@@ -442,7 +443,8 @@
"BTN_AUTH": "Authenticate",
"GENERAL_HELP": "Please authenticate yourself:",
"EXPECTED_UID_HELP": "Please authenticate to the account <i class=\"ion-person\"></i> {{uid}}:",
"EXPECTED_PUBKEY_HELP": "Please authenticate to the wallet <i class=\"ion-key\"></i> {{pubkey|formatPubkey}}:"
"EXPECTED_PUBKEY_HELP": "Please authenticate to the wallet <i class=\"ion-key\"></i> {{pubkey|formatPubkey}}:",
"SCAN_FORM_HELP": "Scan the QR code of the <b>private key</b> of the wallet."
},
"ACCOUNT": {
"TITLE": "My Account",
......
......@@ -380,6 +380,10 @@
},
"LOGIN": {
"TITLE": "<i class=\"icon ion-locked\"></i> Conexión",
"SCRYPT_FORM_HELP": "Ingrese sus credenciales.<br>Recuerde verificar que la clave pública es su cuenta.",
"PUBKEY_FORM_HELP": "Por favor ingrese una clave de cuenta pública:",
"FILE_FORM_HELP": "Elija el archivo de llavero para usar:",
"SCAN_FORM_HELP": "Escanee el código QR de la monedero.",
"SALT": "Identificador secreto",
"SALT_HELP": "Identificador secreto",
"SHOW_SALT": "¿Visualizar el identificador secreto?",
......@@ -389,6 +393,12 @@
"NO_ACCOUNT_QUESTION": "¿Aún no tiene cuenta?",
"CREATE_ACCOUNT": "Crear una cuenta",
"FORGOTTEN_ID": "¿Olvidó su frase secreta?",
"ASSOCIATED_PUBKEY": "Clave pública del llavero:",
"BTN_METHODS": "Otros métodos",
"BTN_METHODS_DOTS": "Método de cambio...",
"METHOD_POPOVER_TITLE": "Métodos",
"MEMORIZE_AUTH_FILE": "Recuerda este llavero al momento de la sesión de navegación",
"SCRYPT_PARAMETERS": "Configuraciones (Scrypt) :",
"AUTO_LOGOUT": {
"TITLE": "Información",
"MESSAGE": "<i class=\"ion-android-time\"></i> Se ha <b>desconectado</b> de forma automática, después de un periodo de inactividad prolongada.",
......@@ -426,7 +436,8 @@
"BTN_AUTH": "Autenticar",
"GENERAL_HELP": "Por favor, autentíquese:",
"EXPECTED_UID_HELP": "Por favor inicie sesión en la cuenta de <i class=\"ion-person\"></i> {{uid}}:",
"EXPECTED_PUBKEY_HELP": "Por favor, autentifíquese en la monedero <i class=\"ion-key\"></i> {{pubkey|formatPubkey}} :"
"EXPECTED_PUBKEY_HELP": "Por favor, autentifíquese en la monedero <i class=\"ion-key\"></i> {{pubkey|formatPubkey}} :",
"SCAN_FORM_HELP": "Escanee el código QR de la <b>clave privada</b> de la monedero."
},
"ACCOUNT": {
"TITLE": "Mi cuenta",
......@@ -510,6 +521,21 @@
"TITLE": "Selección de identidad",
"HELP": "Se han enviado varias <b>identidades diferentes</b> para la clave pública <span class=\"gray\"><i class=\"ion-key\"></i>{{pubkey | formatPubkey}}</span>.<br/>Por favor, selecciona la carpeta para usar:"
},
"SELECT_WALLET_MODAL": {
"TITLE": "Selección de monedero"
},
"WALLET_LIST": {
"TITLE": "Monedero secundario",
"BTN_NEW": "Añadir un monedero",
"NO_WALLET": "Sin monedero secundaria",
"BTN_DELETE": "Eliminar una monedero secundaria...",
"BTN_RENAME": "Renombrar el monedero",
"EDIT_POPOVER": {
"TITLE": "Renombrar el monedero",
"HELP": "Completa el nuevo nombre",
"NAME_HELP": "Nombre de la monedero"
}
},
"SECURITY": {
"ADD_QUESTION": "Añadir una pregunta personalizada",
"BTN_CLEAN": "Limpiar",
......@@ -579,6 +605,7 @@
"POPUP_TITLE": "Error",
"UNKNOWN_ERROR": "Error desconocido",
"CRYPTO_UNKNOWN_ERROR": "Su navegador parece incompatible con las funcionalidades de cryptografía.",
"DOWNLOAD_KEYFILE_FAILED": "Error al generar el archivo de llavero.",
"EQUALS_TO_PSEUDO": "Debe ser diferente del seudónimo.",
"EQUALS_TO_SALT": "Debe ser diferente del identificador secreto.",
"FIELD_REQUIRED": "Campo obligatorio.",
......@@ -677,6 +704,7 @@
"MEMBERSHIP_OUT_SENT": "Anulación enviada",
"NOT_NEED_MEMBERSHIP": "Ya es miembro.",
"IDENTITY_WILL_MISSING_CERTIFICATIONS": "Esta identidad pronto va a necesitar certificaciones (al menos {{willNeedCertificationCount}}).",
"IDENTITY_NEED_MEMBERSHIP": "Esta identidad no envió una solicitud de membresía. Ella tendrá que hacerlo si desea hacerse miembro.",
"REVOCATION_SENT": "Revocación enviada",
"REVOCATION_SENT_WAITING_PROCESS": "La <b>revocación de esta identidad</b> fue solicitada y está en espera de ser procesada.",
"FEATURES_NOT_IMPLEMENTED": "Esta funcionalidad todavía está en proceso de desarrollo.<br/><br/>¿Por qué no <b>contribuir a Cesium</b>, para obtenerla más rápido? ;)",
......@@ -688,12 +716,14 @@
"POPUP_SECURITY_WARNING_TITLE": "<i class=\"icon ion-alert-circled\"></i> <b>Advertencia de seguridad</b>",
"CERTIFY_RULES_TITLE_UID": "Certificar {{uid}}", "CERTIFY_RULES": "<b class=\"assertive\">NO CERTIFICAR</b> una cuenta si piense que :<br/><br/><ul><li>1.) no corresponde a una persona <b>física y viviente</b>.<li>2.) su propietario <b>posee una otra cuenta</b> ya certificada.<li>3.) su propietario viola (voluntariamente o no) la regla 1 o 2 (por ejemplo certificando cuentas falsas o duplicadas).</ul><br/><b>¿Está usted seguro</b> sin embargo querer certificar esta identidad?",
"TRANSFER": "<b>Recapitulativo de la transferencia</b>:<br/><br/><ul><li> - De: {{from}}</li><li> - A: <b>{{to}}</b></li><li> - Importe: <b>{{amount}} {{unit}}</b></li><li> - Comentario: <i>{{comment}}</i></li></ul><br/><b>¿Está usted seguro de querer realizar esta transferencia?</b>",
"TRANSFER_ALL": "<b>Recapitulativo de la transferencia</b>:<br/><br/><ul><li> - De: {{from}}</li><li> - A: <b>{{to}}</b></li><li> - Importe: <b>{{amount}} {{unit}}</b></li><li> - Comentario: <i>{{comment}}</i></li><br/><li> - Resto: <b>{{restAmount}} {{unit}}</b> para <b>{{restTo}}</b></li></ul><br/><b>¿Está usted seguro de querer realizar esta transferencia?</b>",
"MEMBERSHIP_OUT": "Esta operación es <b>irreversible</b>.<br/></br/>¿Está usted seguro querer <b>anular su cuenta miembro</b>?",
"MEMBERSHIP_OUT_2": "¡Esta operación es <b>irreversible</b>!<br/><br/>¿Está usted seguro querer <b>anular su adhesión</b> como miembro?",
"LOGIN_UNUSED_WALLET_TITLE": "¿Error de introducción de datos?",
"LOGIN_UNUSED_WALLET": "Está usted conectado a une cuenta que parece <b>inactiva</b>.<br/><br/>Si esta cuenta no corresponde a la suya, se trata probablemente de un <b>error al introducir los datos</b> de sus identificadores de conexión.<br/></br/><b>¿Quiere usted sin embargo continuar con esta cuenta?</b>",
"FIX_IDENTITY": "El seudónimo <b>{{uid}}</b> va a ser publicado de nuevo, en reemplazo del antiguo que caducó.<br/></br/><b>¿Está usted seguro</b> de querer continuar?",
"FIX_MEMBERSHIP": "Su solicitud de adhesión como miembro va a ser enviada de nuevo.<br/></br/><b>¿Está usted seguro</b>de querer continuar?",
"MEMBERSHIP": "Se enviará su solicitud de membresía como miembro.<br/></br/><b>¿Está usted seguro</b>de querer continuar?",
"RENEW_MEMBERSHIP": "Su adhesión como miembro va a estar renovada.<br/></br/><b>¿Está usted seguro</b>de querer continuar?",
"REVOKE_IDENTITY": "Va a <b>revocar definitivamente esta identidad</b>.<br/><br/>La llave pública y el seudónimo asociados <b>jamás podrán ser utilizados</b> (para una cuenta miembro). <br/></br/><b>¿Está usted seguro</b> de querer revocar definitivamente esta cuenta?",
"REVOKE_IDENTITY_2": "¡Esta operación es <b>irreversible</b>!<br/><br/>¿Está usted seguro de querer <b>revocar definitivamente</b> esta cuenta?",
......
......@@ -390,6 +390,7 @@
"SCRYPT_FORM_HELP": "Veuillez saisir vos identifiants.<br>Pensez à vérifier que la clé publique est celle de votre compte.",
"PUBKEY_FORM_HELP": "Veuillez saisir une clé publique de compte :",
"FILE_FORM_HELP": "Choisissez le fichier de trousseau à utiliser :",
"SCAN_FORM_HELP": "Scanner le QR code d'un portefeuille.",
"SALT": "Identifiant secret",
"SALT_HELP": "Identifiant secret",
"SHOW_SALT": "Afficher l'identifiant secret ?",
......@@ -442,7 +443,8 @@
"BTN_AUTH": "S'authentifier",
"GENERAL_HELP": "Veuillez vous authentifier :",
"EXPECTED_UID_HELP": "Veuillez vous authentifier sur le compte <i class=\"ion-person\"></i> {{uid}} :",
"EXPECTED_PUBKEY_HELP": "Veuillez vous authentifier sur le portefeuille <i class=\"ion-key\"></i> {{pubkey|formatPubkey}} :"
"EXPECTED_PUBKEY_HELP": "Veuillez vous authentifier sur le portefeuille <i class=\"ion-key\"></i> {{pubkey|formatPubkey}} :",
"SCAN_FORM_HELP": "Scanner le QR code de la <b>clef privée</b> du portefeuille."
},
"ACCOUNT": {
"TITLE": "Mon compte",
......@@ -537,7 +539,7 @@
"BTN_RENAME": "Renommer le portefeuille",
"EDIT_POPOVER": {
"TITLE": "Renommer le portefeuille",
"HELP": "Rensignez le nouveau nom",
"HELP": "Renseignez le nouveau nom",
"NAME_HELP": "Nom du portefeuille"
}
},
......
......@@ -381,6 +381,7 @@
"SCRYPT_FORM_HELP": "Accedi con tuoi dati <br> Ricordati di verificare che stai utilizzando la chiave del tuo conto.",
"PUBKEY_FORM_HELP": "Scrivi qui la tua chiave privata:",
"FILE_FORM_HELP": "Scegliere un portachiavi da utilizzare:",
"SCAN_FORM_HELP": "Scansiona il codice QR di un portafoglio.",
"SALT": "Identificativo segreto",
"SALT_HELP": "Identificativo segreto",
"SHOW_SALT": "Mostrare identificativo segreto?",
......@@ -406,7 +407,8 @@
"SCRYPT_DEFAULT": "Salatura standard (imp. predefinita)",
"SCRYPT_ADVANCED": "Salatura avanzata",
"FILE": "File del portachiavi",
"PUBKEY": "Chiave pubblica soltanto"
"PUBKEY": "Chiave pubblica soltanto",
"SCAN": "Scansiona un codice QR"
},
"SCRYPT": {
"SIMPLE": "Salatura leggera",
......@@ -430,7 +432,10 @@
"AUTH": {
"TITLE": "<i class=\"icon ion-locked\"></i> Autenticazione",
"BTN_AUTH": "Autenticarsi",
"GENERAL_HELP": "Autenticati :"
"GENERAL_HELP": "Autenticati :",
"EXPECTED_UID_HELP": "Effettua il login nell'account <i class=\"ion-person\"></i> {{uid}}:",
"EXPECTED_PUBKEY_HELP": "Si prega di autenticarsi sul portafoglio <i class=\"ion-key\"></i> {{pubkey|formatPubkey}}:",
"SCAN_FORM_HELP": "Scansiona il codice QR della <b>chiave privata</b> del portafoglio."
},
"ACCOUNT": {
"TITLE": "Mio conto",
......@@ -442,6 +447,7 @@
"SHOW_ALL_TX": "Mostrare tutte",
"TX_FROM_DATE": "(limite attuale del {{fromTime|formatFromNowShort}})",
"PENDING_TX": "Transazioni pendenti",
"VALIDATING_TX": "Transazioni in corso di convalida",
"ERROR_TX": "Transaction non eseguite",
"ERROR_TX_SENT": "Transazioni inviate",
"PENDING_TX_RECEIVED": "Transazioni in attesa di recezione",
......@@ -457,12 +463,10 @@
"SIG_STOCK": "Stock di certificazioni da inviare",
"BTN_RECEIVE_MONEY": "Ricevere",
"BTN_SELECT_ALTERNATIVES_IDENTITIES": "Usare un'altra identità..",
"BTN_MEMBERSHIP_IN_DOTS": "Registrati come membro..",
"BTN_FIX_MEMBERSHIP": "Invia nuovamente di adesione...",
"BTN_MEMBERSHIP_RENEW": "Rinnovare adesione",
"BTN_MEMBERSHIP_RENEW_DOTS": "Rinnovare adesione ...",
"BTN_MEMBERSHIP_OUT_DOTS": "Revocare adesione...",
"BTN_SEND_IDENTITY_DOTS": "Pubblicare identità...",
"BTN_SECURITY_DOTS": "Login e securità...",
"BTN_SHOW_DETAILS": "Visualizzare dati tecnici",
"LOCKED_OUTPUTS_POPOVER": {
......@@ -515,6 +519,21 @@
"TITLE": "Selezionare una identità",
"HELP": "Più <b>identità diverse</b> sono state inviate per la chiave pubblica <span class=\"gray\"><i class=\"ion-key\"></i> {{pubkey|formatPubkey}}</span>.<br/>Seleziona un dossier da usare :"
},
"SELECT_WALLET_MODAL": {
"TITLE": "Selezione del portafoglio"
},
"WALLET_LIST": {
"TITLE": "Portafoglio secondario",
"BTN_NEW": "Aggiungi un portfolio",
"NO_WALLET": "Nessun portafoglio secondario",
"BTN_DELETE": "Rimuovi un portafoglio secondario ...",
"BTN_RENAME": "Rinominare il portafoglio",
"EDIT_POPOVER": {
"TITLE": "Rinominare il portafoglio",
"HELP": "Compila il nuovo nome",
"NAME_HELP": "Nome del portafoglio"
}
},
"SECURITY":{
"ADD_QUESTION" : "Aggiungere domanda personalizzata",
"BTN_CLEAN" : "Svuotare",
......
......@@ -89,40 +89,6 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
// (code removed when NO device)
////////////////////////////////////////
$scope.parseWIF = function(data, options) {
options = options || {};
options.withSecret = angular.isDefined(options.withSecret) && options.withSecret || true;
options.password = function() {
UIUtils.loading.hide();
return Modals.showPassword({
title: 'ACCOUNT.SECURITY.KEYFILE.PASSWORD_POPUP.TITLE',
subTitle: 'ACCOUNT.SECURITY.KEYFILE.PASSWORD_POPUP.HELP',
error: options.error,
scope: $scope
})
.then(function(password) {
// Timeout is need to force popup to be hide
return $timeout(function() {
if (password) UIUtils.loading.show();
return password;
}, 150);
});
};
UIUtils.loading.show();
return csCrypto.keyfile.parseWIF_or_EWIF(data, options)
.catch(function(err) {
if (err && err == 'CANCELLED') return;
if (err && err.ucode == csCrypto.errorCodes.BAD_PASSWORD) {
// recursive call
return $scope.parseWIF(data, {withSecret: options.withSecret, error: 'ACCOUNT.SECURITY.KEYFILE.ERROR.BAD_PASSWORD'});
}
console.error("[app] Unable to parse as WIF or EWIF format: " + (err && err.message || err));
throw err; // rethrow
});
};
$scope.scanQrCodeAndGo = function() {
if (!Device.barcode.enable) return;
......@@ -148,18 +114,19 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
console.debug("[app] Scan data is not an URI (get error: " + (err && err.message || err) + "). Trying to decode as a WIF or EWIF format...");
// Try to read as WIF format
return $scope.parseWIF(data)
return csCrypto.keyfile.parseData(data)
.then(function(keypair) {
if (!keypair || !keypair.signPk || !keypair.signSk) throw err; // rethrow the first error (e.g. Bad URI)
var pubkey = CryptoUtils.base58.encode(keypair.signPk);
console.debug("[app] Detected WIF/EWIF format. Will login to wallet {" + pubkey.substring(0, 8) + "}");
// Create the wallet (if need) or use default
// Create a new wallet (if default wallet is already used)
var wallet = !csWallet.isLogin() ? csWallet : csWallet.children.create({store: false});
// Login using keypair
return wallet.login({
silent: true,
forceAuth: true,
minData: false,
authData: {
......@@ -168,7 +135,11 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
}
})
.then(function () {
// Open transfer all wallet
$ionicHistory.nextViewOptions({
historyRoot: true
});
return $state.go('app.new_transfer', {
all: true, // transfer all sources
wallet: !wallet.isDefault() ? wallet.id : undefined
......@@ -498,7 +469,7 @@ function HomeController($scope, $state, $timeout, $ionicHistory, csPlatform, csC
$scope.loading = true;
$scope.enter = function(e, state) {
if (state && state.stateParams && state.stateParams.error) { // Query parameter
if (state && state.stateParams && state.stateParams.error) { // Error query parameter
$scope.error = state.stateParams.error;
$scope.node = csCurrency.data.node;
$scope.loading = false;
......
......@@ -23,13 +23,21 @@ angular.module('cesium.join.controllers', ['cesium.services'])
.controller('JoinModalCtrl', JoinModalController)
;
function JoinController($timeout, Modals) {
function JoinController($scope, $timeout, $controller, Modals, csWallet) {
'ngInject';
// Open join modal
$timeout(function() {
Modals.showJoin();
}, 100);
// Initialize the super class and extend it.
angular.extend(this, $controller('HomeCtrl', {$scope: $scope}));
$scope.showJoinModal = function() {
if ($scope.loading) return $timeout($scope.showJoinModal, 500); // recursive call
if (!csWallet.isLogin() && !$scope.error) {
return $timeout(Modals.showJoin, 300);
}
};
$scope.$on('$ionicView.enter', $scope.showJoinModal);
}
function JoinChooseAccountTypeModalController($scope, $state, Modals, UIUtils, csCurrency) {
......
angular.module('cesium.login.controllers', ['cesium.services'])
.config(function($stateProvider) {
'ngInject';
$stateProvider
.state('app.login', {
url: "/login",
views: {
'menuContent': {
templateUrl: "templates/home/home.html",
controller: 'LoginCtrl'
}
}
})
;
})
.controller('LoginCtrl', LoginController)
.controller('LoginModalCtrl', LoginModalController)
.controller('AuthCtrl', AuthController)
;
function LoginController($scope, $timeout, $controller, csWallet) {
'ngInject';
// Initialize the super class and extend it.
angular.extend(this, $controller('HomeCtrl', {$scope: $scope}));
$scope.showLoginModal = function() {
if ($scope.loading) return $timeout($scope.showLoginModal, 500); // recursive call
if (!csWallet.isLogin() && !$scope.error) {
return $timeout(csWallet.login, 300);
}
};
$scope.$on('$ionicView.enter', $scope.showLoginModal);
}
function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, csCrypto,
UIUtils, BMA, Modals, csSettings, Device, parameters) {
'ngInject';
......@@ -75,14 +111,15 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils,
$scope.$on('modal.hide', $scope.leave);
// Login form submit
$scope.doLogin = function() {
if(!$scope.form.$valid) return;
$scope.doLogin = function(skipForm) {
var method = $scope.formData.method;
if(!$scope.form.$valid && method !== 'SCAN') return;
// removeIf(no-device)
Device.keyboard.close();
// endRemoveIf(no-device)
var method = $scope.formData.method;
var keepAuthIdle = $scope.formData.keepAuthIdle;
var promise;
......@@ -192,49 +229,17 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils,
}
// Scan QR code
else if (method === 'SCAN' && Device.barcode.enable) {
// Run scan cordova plugin, on device
promise = Device.barcode.scan()
.then(function(data) {
if (!data) return;
// Try to parse as an URI
return BMA.uri.parse(data)
.then(function(res){
if (!res || !res.pubkey) throw {message: 'ERROR.SCAN_UNKNOWN_FORMAT'};
// If simple pubkey
promise = UIUtils.loading.show()
.then(function() {
return {
pubkey: pubkey
};
});
})
// Not an URI: try WIF or EWIF format
.catch(function(err) {
console.debug("[login] Scan data is not an URI (get error: " + (err && err.message || err) + "). Trying to decode as a WIF or EWIF format...");
// Try to read as WIF format
return $scope.parseWIF(data)
.then(function(keypair) {
if (!keypair || !keypair.signPk || !keypair.signSk) throw err; // rethrow the first error (e.g. Bad URI)
var pubkey = CryptoUtils.base58.encode(keypair.signPk);
console.debug("[login] Detected WIF/EWIF format. Will login to wallet {" + pubkey.substring(0, 8) + "}");
// Login using keypair
return {
pubkey: pubkey,
keypair: keypair
};
})
// Unknown format (nor URI, nor WIF/EWIF)
.catch(UIUtils.onError('ERROR.SCAN_UNKNOWN_FORMAT'));
});
})
.catch(UIUtils.onError('ERROR.SCAN_FAILED'));
else if (method === 'SCAN') {
var valid = $scope.formData.pubkey && (!$scope.isAuth || !!$scope.formData.keypair);
if (!valid) return;
promise = UIUtils.loading.show()
.then(function() {
return {
pubkey: $scope.formData.pubkey,
keypair: $scope.formData.keypair
};
});
}
if (!promise) {
......@@ -339,9 +344,74 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils,
return Modals.showHelp(parameters);
};
$scope.doScan = function() {
if ($scope.computing) return;
$scope.computing = true;
$scope.formData.pubkey = null;
$scope.formData.keypair = null;
// Run scan cordova plugin, on device
return Device.barcode.scan()
.then(function(data) {
if (!data) return;
// Skip simple parsing, if auth if need
if ($scope.isAuth) return $q.when(data);
// Try to parse as an URI
return BMA.uri.parse(data)
.then(function (res) {
if (!res || !res.pubkey) throw {message: 'ERROR.SCAN_UNKNOWN_FORMAT'};
// If simple pubkey
return res;
})
.catch(function(err) {
console.debug('[login] Error while parsing as URI: ' + (err && err.message || err));
return data;
});
})
.then(function(data) {
// Parse success: continue
if (data && data.pubkey) return data;
// Try to read as WIF format
return csCrypto.keyfile.parseData(data, {silent: true})
.then(function(keypair) {
if (!keypair || !keypair.signPk || !keypair.signSk) throw {message: 'ERROR.SCAN_UNKNOWN_FORMAT'}; // rethrow an error
var pubkey = CryptoUtils.base58.encode(keypair.signPk);
// Login using keypair
return {
pubkey: pubkey,
keypair: keypair
};
})
// Unknown format (nor URI, nor WIF/EWIF)
.catch(UIUtils.onError('ERROR.SCAN_UNKNOWN_FORMAT'));
})
.then(function(res) {
if (!res || !res.pubkey) return; // no data
$scope.pubkeyError = $scope.expectedPubkey && $scope.expectedPubkey != res.pubkey;
$scope.formData.pubkey = res.pubkey;
$scope.formData.keypair = res.keypair;
})
.then(function() {
$scope.computing = false;
UIUtils.loading.hide(10);
})
.catch(function(err) {
$scope.computing = false;
UIUtils.onError('ERROR.SCAN_FAILED')(err);
});
};
$scope.changeMethod = function(method, params){
$scope.hideMethodsPopover();
if (method == $scope.formData.method) return; // same method
if (!method || method == $scope.formData.method) return; // same method
console.debug("[login] method is: " + method);
$scope.formData.method = method;
......@@ -351,12 +421,10 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils,
delete $scope.form.$submitted;
}
if (method == 'SCAN') {
return $scope.doLogin();
}
// Scrypt (advanced or not)
if (method == 'SCRYPT_DEFAULT' || method == 'SCRYPT_ADVANCED') {
$scope.pubkey = null;
// Search scrypt object
var scrypt;
if (params) {
......@@ -375,11 +443,15 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils,
$scope.autoComputePubkey = $scope.autoComputePubkey && (method == 'SCRYPT_DEFAULT');
}
else if (method == 'SCAN') {
return $scope.doScan();
}
else {
$scope.formData.username = null;
$scope.formData.password = null;
$scope.formData.pubkey = null;
$scope.formData.computing = false;
$scope.pubkey = null;
$scope.computing = false;
}
};
......@@ -413,6 +485,9 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils,
return csCrypto.keyfile.read($scope.formData.file, options)
.catch(function(err) {
$scope.formData.file.password = undefined;
if (err === 'CANCELLED') {
UIUtils.loading.hide(10);
}
if (err && err.ucode == csCrypto.errorCodes.BAD_PASSWORD) {
// Recursive call
return $scope.readKeyFile($scope.formData.file, {withSecret: options.withSecret, error: 'ACCOUNT.SECURITY.KEYFILE.ERROR.BAD_PASSWORD'});
......
......@@ -1451,7 +1451,10 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate, pa
})
.catch(function(err){
if (err && err == 'CANCELLED') return;
if (err && err === 'CANCELLED') {
UIUtils.loading.hide();
return;
}
UIUtils.onError('ERROR.DOWNLOAD_KEYFILE_FAILED')(err);
})
;
......
......@@ -717,6 +717,7 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
exports.uri.parse = function(uri) {
return $q(function(resolve, reject) {
var pubkey;
// If pubkey: not need to parse
if (exact(regexp.PUBKEY).test(uri)) {
resolve({
......@@ -785,6 +786,7 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
});
})
.catch(function(err) {
console.error(err);
reject({message: 'Could not get node parameter. Currency could not be retrieve'});
});
}
......@@ -813,25 +815,30 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.
host: host,
currency: currency
});
})
.catch(function(err) {
console.error(err);
reject({message: 'Could not get node parameter. Currency could not be retrieve'});
});
}
}
else {
console.debug("[BMA.parse] Could not parse URI: " + uri);
reject( {message: 'ERROR.UNKNOWN_URI_FORMAT'});
reject({message: 'ERROR.UNKNOWN_URI_FORMAT'});
}
})
// Check values against regex
.then(function(result) {
if (!result) return;
if (result.pubkey && !(exact(regexp.PUBKEY).test(result.pubkey))) {
reject({message: "Invalid pubkey format [" + result.pubkey + "]"}); return;
throw {message: "Invalid pubkey format [" + result.pubkey + "]"};
}
if (result.uid && !(exact(regexp.USER_ID).test(result.uid))) {
reject({message: "Invalid uid format [" + result.uid + "]"}); return;
throw {message: "Invalid uid format [" + result.uid + "]"};
}
if (result.currency && !(exact(regexp.CURRENCY).test(result.currency))) {
reject({message: "Invalid currency format ["+result.currency+"]"}); return;
throw {message: "Invalid currency format ["+result.currency+"]"};
}
return result;
});
......
......@@ -829,7 +829,7 @@ angular.module('cesium.crypto.services', ['cesium.utils.services'])
Crypto advanced service for Cesium
*/