Commit 64380fe6 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] QR Code can hold G1 Link (june:// or web+june://)

parent 6a44b2a6
Pipeline #9510 failed
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Cesium" type="JavascriptDebugType" uri="http://localhost:8100/">
<mapping url="http://localhost:8100" local-file="$PROJECT_DIR$/www" />
<method v="2" />
</configuration>
</component>
\ No newline at end of file
Subproject commit 2737fb8bc928e634cd86748567467ecee96791f5
Subproject commit 366b85e16a589746f53ad260a02abdaa346a1212
......@@ -8,7 +8,6 @@ const gulp = require('gulp'),
rename = require('gulp-rename'),
ngConstant = require('gulp-ng-constant'),
fs = require("fs"),
es = require('event-stream'),
header = require('gulp-header'),
footer = require('gulp-footer'),
removeCode = require('gulp-remove-code'),
......@@ -149,7 +148,7 @@ function appConfig() {
const env = argv.env || 'default';
const config = allConfig[env];
if(!config) {
if (!config) {
throw new Error(colors.red("=> Could not load `" + env + "` environment!"));
}
......@@ -197,7 +196,7 @@ function appNgTemplate() {
.pipe(sort())
.pipe(templateCache({
standalone: true,
module:"cesium.templates",
module: "cesium.templates",
root: "templates/"
}))
.pipe(gulp.dest('./www/dist/dist_js/app'));
......@@ -258,8 +257,8 @@ function pluginNgTemplate() {
return gulp.src(paths.templatecache_plugin)
.pipe(sort())
.pipe(templateCache({
standalone:true,
module:"cesium.plugins.templates",
standalone: true,
module: "cesium.plugins.templates",
root: "plugins/"
}))
.pipe(gulp.dest('./www/dist/dist_js/plugins'));
......@@ -273,8 +272,7 @@ function pluginNgAnnotate(event) {
path = path.substring(0, path.lastIndexOf('/'));
return gulp.src(event.path)
.pipe(ngAnnotate({single_quotes: true}))
.pipe(gulp.dest('./www/dist/dist_js/app' + path))
;
.pipe(gulp.dest('./www/dist/dist_js/app' + path));
}
log(colors.green('Building Plugins JS file...'));
......@@ -295,7 +293,7 @@ function pluginNgTranslate() {
}
function pluginLeafletImages(dest) {
dest = dest || './www/img/';
dest = dest || './www/img/';
// Leaflet images
return gulp.src(['scss/leaflet/images/*.*',
'www/lib/leaflet/dist/images/*.*',
......@@ -358,13 +356,7 @@ function webCopyFiles() {
log(colors.green('Preparing dist/web files...'));
let htmlminOptions = {removeComments: true, collapseWhitespace: true};
const debugOptions = {
title: 'Copying',
minimal: true,
showFiles: argv.debug || false,
showCount: argv.debug || false,
logger: m => log(colors.grey(m))
};
const debugOptions = { ...debugBaseOptions, title: 'Copying' };
var targetPath = './dist/web/www';
return merge(
......@@ -453,8 +445,8 @@ function webNgTemplate() {
return gulp.src(targetPath + '/templates/**/*.html')
.pipe(sort())
.pipe(templateCache({
standalone:true,
module:"cesium.templates",
standalone: true,
module: "cesium.templates",
root: "templates/"
}))
.pipe(gulp.dest(targetPath + '/dist/dist_js/app'));
......@@ -585,13 +577,8 @@ function webIntegrity() {
.pipe(sriHash())
.pipe(rename({ extname: '.integrity.html' }))
.pipe(gulp.dest(targetPath)),
gulp.src(targetPath + '/index.html', {base: targetPath})
.pipe(rename({ extname: '.test.html' }))
.pipe(gulp.dest(targetPath));
.pipe(gulp.dest(targetPath));
}
else {
return Promise.resolve();
}
......@@ -662,12 +649,9 @@ function webCleanUnusedFiles(done) {
const targetPath = './dist/web/www';
const enableUglify = argv.release || argv.uglify || false;
const cleanSources = enableUglify;
const debugOptions = {
const debugOptions = {...debugBaseOptions,
title: 'Deleting',
minimal: true,
showFiles: argv.debug || false,
showCount: !argv.debug,
logger: m => log(colors.grey(m))
showCount: !argv.debug
};
if (cleanSources) {
......@@ -677,6 +661,11 @@ function webCleanUnusedFiles(done) {
.pipe(debug(debugOptions))
.pipe(clean()),
// Clean core CSS
gulp.src(targetPath + '/css/**/*.css', {read: false})
.pipe(debug(debugOptions))
.pipe(clean()),
// Clean plugins JS + CSS
gulp.src(targetPath + '/plugins/**/*.js', {read: false})
.pipe(debug(debugOptions))
......@@ -700,12 +689,9 @@ function webCleanUnusedFiles(done) {
function webCleanUnusedDirectories() {
log(colors.green('Clean unused directories...'));
const enableUglify = argv.release || argv.uglify || false;
const debugOptions = {
const debugOptions = { ...debugBaseOptions,
title: 'Deleting',
minimal: true,
showFiles: argv.debug || false,
showCount: !argv.debug,
logger: m => log(colors.grey(m))
showCount: !argv.debug
};
// Clean dir
......@@ -913,18 +899,7 @@ function cdvNgAnnotate() {
// Ng annotate app JS file
gulp.src(wwwPath + '/plugins/**/*.js')
.pipe(ngAnnotate({single_quotes: true}))
.pipe(gulp.dest(wwwPath + '/dist/dist_js/plugins')),
/*
// Copy plugin CSS
gulp.src(wwwPath + '/plugins/!*!/css/!**!/!*.css')
.pipe(gulp.dest(wwwPath + '/dist/dist_css/plugins')),
// Copy Leaflet images
pluginLeafletImages(wwwPath + '/img'),
// Copy Leaflet CSS
gulp.src('./www/css/!**!/leaflet.*')
.pipe(gulp.dest(wwwPath + '/css'))*/
.pipe(gulp.dest(wwwPath + '/dist/dist_js/plugins'))
);
}
......@@ -948,12 +923,8 @@ function cdvRemoveCode() {
removeCodeOptions[platform] = true; // = {<platform>: true}
const htmlminOptions = {removeComments: true, collapseWhitespace: true};
const debugOptions = {
title: 'Processing',
minimal: true,
showFiles: argv.debug || false,
showCount: false,
logger: m => log(colors.grey(m))
const debugOptions = {...debugBaseOptions,
showCount: false
};
// Do not remove desktop code for iOS and macOS (support for tablets and desktop macs)
......@@ -1239,7 +1210,6 @@ function cdvCleanUnusedDirectories() {
function cdvCopyBuildFiles() {
log(colors.green('Copy build files... '));
const projectRoot = argv.root || '.';
......@@ -1247,12 +1217,9 @@ function cdvCopyBuildFiles() {
const srcPath = path.join(projectRoot, 'resources', platform, 'build');
const targetPath = path.join(projectRoot, 'platforms', platform);
const debugOptions = {
title: 'Copying',
minimal: true,
const debugOptions = { ...debugBaseOptions, title: 'Copying',
showFiles: argv.debug || false,
showCount: !argv.debug,
logger: m => log(colors.grey(m))
showCount: !argv.debug
};
if (fs.existsSync(srcPath)) {
......@@ -1424,7 +1391,7 @@ exports.webExtClean = webExtClean;
exports.webExtCompile = webExtCompile;
exports.webExtBuild = webExtBuild;
exports.webExtCopyFiles = webExtCopyFiles;
exports['build:webExt'] = exports.webBuild; // Alias
exports['build:webExt'] = exports.webExtBuild; // Alias
// Cordova (hooks)
const cdvAfterPrepare = gulp.series(
......
......@@ -10,7 +10,7 @@
"url": "git@git.duniter.org:clients/cesium/cesium.git"
},
"scripts": {
"clean": "trash www/dist/** dist/web/* dist/desktop/**/*.deb platforms/android/**/*.apk",
"clean": "clean webClean webExtClean && trash dist/desktop/**/*.deb platforms/android/**/*.apk",
"postinstall": "node scripts/node/postinstall.js",
"lint": "gulp lint",
"install-platforms": "ionic cordova prepare",
......@@ -19,6 +19,7 @@
"start:android": "ionic cordova run android --color",
"docker:build": "sudo docker build . -t cesium/release",
"docker:run": "sudo docker run -ti --rm -p 8100:8100 -p 35729:35729 -v .:/cesium:rw cesium/release",
"build": "gulp build",
"build:web": "gulp config --env default && gulp webBuild --release",
"build:webExt": "gulp config --env default && gulp webExtBuild --release",
"build:android": "ionic cordova build android --color --release",
......
......@@ -41,9 +41,7 @@ fi
echo "Executing jarsigner..."
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ${KEYSTORE_FILE} ${APK_UNSIGNED_FILE} Cesium
if [[ $? -ne 0 ]]; then
exit 1
fi
[[ $? -ne 0 ]] && exit 1
echo "Executing jarsigner [OK]"
BUILD_TOOLS_DIR="${ANDROID_SDK_ROOT}/build-tools/28.*/"
......@@ -51,16 +49,12 @@ cd ${BUILD_TOOLS_DIR}
echo "Executing zipalign..."
./zipalign -v 4 ${APK_UNSIGNED_FILE} ${APK_SIGNED_FILE}
if [[ $? -ne 0 ]]; then
exit 1
fi
[[ $? -ne 0 ]] && exit 1
echo "Executing zipalign [OK]"
echo "Verify APK signature..."
./apksigner verify ${APK_SIGNED_FILE}
if [[ $? -ne 0 ]]; then
exit 1
fi
[[ $? -ne 0 ]] && exit 1
echo "Verify APK signature [OK]"
echo "Successfully generated signed APK at: ${APK_SIGNED_FILE}"
......@@ -26,6 +26,6 @@ if [[ "$1" == "--release" ]]; then
native-run android --app ${ANDROID_OUTPUT_APK_RELEASE}/app-release-unsigned.apk
fi
else
native-run android --app ${ls }/app-debug.apk
native-run android --app ${ANDROID_OUTPUT_APK_DEBUG}/app-debug.apk
fi
......@@ -393,12 +393,13 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
/**
* Parse an external URI (see g1lien), and open the expected state
* @param uri
* @param reject optional function, to avoid error to be displayed
* @returns {*}
*/
$scope.handleUri = function(uri) {
$scope.handleUri = function(uri, reject) {
if (!uri) return $q.when(); // Skip
console.info('[app] Parsing external uri: ', uri);
console.info('[app] Trying to parse as uri: ', uri);
var fromHomeState = $state.current && $state.current.name === 'app.home';
// Parse the URI
......@@ -448,21 +449,76 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
})
.catch(function(err) {
if (reject) {
reject(err);
return;
}
console.error("[home] Error while handle uri {" + uri + "': ", err);
return UIUtils.onError(uri)(err);
});
};
/**
* Try to parse as auth data (e.g. WIF/EWIF format)
* @param data
* @param reject optional function, to avoid error to be displayed
* @returns {*}
*/
$scope.handleAuthData = function(data, reject) {
console.debug("[app] Trying to parse as a auth data (WIF, EWIF)...");
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 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: {
pubkey: pubkey,
keypair: keypair
}
})
.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
});
});
})
.catch(function(err) {
if (reject) {
reject(err);
return;
}
console.error("[home] Error while handle auth data", err);
return UIUtils.onError('ERROR.AUTH_INVALID_FILE')(err);
});
}
$scope.registerProtocolHandlers = function() {
var protocols = ['web+june', /*'june' - NOT yet accepted by web browser */];
_.each(protocols, function(protocol) {
console.debug("[app] Registering protocol '%s'...".format(protocol));
console.debug("[app] Registering protocol '{0}'...".format(protocol));
try {
navigator.registerProtocolHandler(protocol, "#/app/home?uri=%s", "Cesium");
}
catch(err) {
console.error("[app] Error while registering protocol '%s'".format(protocol), err);
console.error("[app] Error while registering protocol '{0}'".format(protocol), err);
}
});
};
......@@ -522,59 +578,30 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
.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 pubkey: open the identity
return $state.go('app.wot_identity', {
pubkey: res.pubkey,
node: res.host ? res.host: null}
);
var throwIfError = function (err) {
if (err) throw err;
};
// First, try to handle as an URI
var firstError;
return $scope.handleUri(data, throwIfError)
// If failed
.catch(function(e) {
firstError = e;
console.error("[app] Failed to parse as URI: " + (e && e.message || e));
// Try as an auth data
return $scope.handleAuthData(data, throwIfError)
})
// Not an URI: try WIF or EWIF format
.catch(function(err) {
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 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 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: {
pubkey: pubkey,
keypair: keypair
}
})
.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
});
});
})
// Unknown format (nor URI, nor WIF/EWIF)
.catch(UIUtils.onError('ERROR.SCAN_UNKNOWN_FORMAT'));
// Both failed
.catch(function(e) {
// Log second error, then display the first error
console.error("[app] Failed to parse as Auth data: " + (e && e.message || e));
return UIUtils.onError('ERROR.SCAN_UNKNOWN_FORMAT')(firstError);
});
})
.catch(UIUtils.onError('ERROR.SCAN_FAILED'));
});
};
/**
......
......@@ -14,9 +14,7 @@ angular.module('cesium.home.controllers', ['cesium.platform', 'cesium.services']
controller: 'HomeCtrl'
}
}
})
;
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/home');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment