From ed1b9908c88bb8d86efa9b20db063e2da7502a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 27 Sep 2017 14:51:36 -0300 Subject: [PATCH] Feat: fingerprint provider added --- config.xml | 169 +++++++++++++++--------------- package.json | 12 ++- src/app/app.module.ts | 6 ++ src/providers/popup/popup.spec.ts | 0 src/providers/popup/popup.ts | 3 +- src/providers/touchid/touchid.ts | 99 +++++++++++++++++ 6 files changed, 198 insertions(+), 91 deletions(-) delete mode 100644 src/providers/popup/popup.spec.ts create mode 100644 src/providers/touchid/touchid.ts diff --git a/config.xml b/config.xml index 9ecb3b36b..077493996 100644 --- a/config.xml +++ b/config.xml @@ -1,95 +1,92 @@ - + Copay Copay Bitcoin Wallet BitPay - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + diff --git a/package.json b/package.json index 1e348fc98..fc979de74 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@angular/platform-browser-dynamic": "4.1.3", "@angular/tsc-wrapped": "4.1.3", "@biesbjerg/ngx-translate-po-http-loader": "1.0.1", + "@ionic-native/android-fingerprint-auth": "4.2.1", "@ionic-native/clipboard": "4.1.0", "@ionic-native/core": "3.12.1", "@ionic-native/file": "4.1.0", @@ -35,6 +36,7 @@ "@ionic-native/splash-screen": "3.12.1", "@ionic-native/status-bar": "3.12.1", "@ionic-native/toast": "4.1.0", + "@ionic-native/touch-id": "4.2.1", "@ionic/storage": "2.0.1", "@ngx-translate/core": "6.0.1", "@nsalaun/ng-logger": "2.0.1", @@ -47,11 +49,13 @@ "cordova-android": "6.2.3", "cordova-clipboard": "1.0.0", "cordova-ios": "4.4.0", + "cordova-plugin-android-fingerprint-auth": "1.4.0", "cordova-plugin-console": "1.0.5", "cordova-plugin-device": "1.1.4", "cordova-plugin-qrscanner": "2.5.0", "cordova-plugin-splashscreen": "4.0.3", "cordova-plugin-statusbar": "2.2.2", + "cordova-plugin-touch-id": "3.2.0", "cordova-plugin-whitelist": "1.3.1", "cordova-plugin-wkwebview-engine": "git+https://github.com/ionic-team/cordova-plugin-wkwebview-engine.git", "cordova-plugin-x-socialsharing": "5.1.8", @@ -78,7 +82,7 @@ "angular2-template-loader": "0.6.2", "codecov": "2.2.0", "html-loader": "0.4.5", - "ionic": "3.9.2", + "ionic": "3.12.0", "jasmine-core": "2.6.4", "jasmine-spec-reporter": "4.1.1", "karma": "1.7.0", @@ -111,11 +115,13 @@ "cordova-plugin-x-toast": {}, "cordova-plugin-x-socialsharing": {}, "cordova-plugin-qrscanner": {}, - "cordova-plugin-wkwebview-engine": {} + "cordova-plugin-wkwebview-engine": {}, + "cordova-plugin-touch-id": {}, + "cordova-plugin-android-fingerprint-auth": {} }, "platforms": [ "android", "ios" ] } -} +} \ No newline at end of file diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5dd93610b..d5f2d8b0b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,12 +4,14 @@ import { HttpModule, Http } from '@angular/http'; import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; /* Native modules */ +import { AndroidFingerprintAuth } from '@ionic-native/android-fingerprint-auth'; import { Clipboard } from '@ionic-native/clipboard'; import { QRScanner } from '@ionic-native/qr-scanner'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; import { SocialSharing } from '@ionic-native/social-sharing'; import { Toast } from '@ionic-native/toast'; +import { TouchID } from '@ionic-native/touch-id'; /* Modules */ import { MomentModule } from 'angular2-moment'; @@ -61,6 +63,7 @@ import { PopupProvider } from '../providers/popup/popup'; import { ProfileProvider } from '../providers/profile/profile'; import { RateProvider } from '../providers/rate/rate'; import { ScanProvider } from '../providers/scan/scan'; +import { TouchIdProvider } from '../providers/touchid/touchid'; import { TxFormatProvider } from '../providers/tx-format/tx-format'; import { WalletProvider } from '../providers/wallet/wallet'; @@ -91,6 +94,7 @@ let pages: any = [ ]; let providers: any = [ + AndroidFingerprintAuth, AppProvider, BwcProvider, ConfigProvider, @@ -107,6 +111,8 @@ let providers: any = [ ScanProvider, SocialSharing, Toast, + TouchID, + TouchIdProvider, TxFormatProvider, WalletProvider, { diff --git a/src/providers/popup/popup.spec.ts b/src/providers/popup/popup.spec.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/providers/popup/popup.ts b/src/providers/popup/popup.ts index 3c7afeb32..2cab34bfd 100644 --- a/src/providers/popup/popup.ts +++ b/src/providers/popup/popup.ts @@ -1,10 +1,9 @@ import { Injectable } from '@angular/core'; -import { Platform } from 'ionic-angular'; import { AlertController } from 'ionic-angular'; @Injectable() export class PopupProvider { - constructor(private platform: Platform, public alertCtrl: AlertController) { + constructor(public alertCtrl: AlertController) { } ionicAlert(title, subTitle, okText): void { diff --git a/src/providers/touchid/touchid.ts b/src/providers/touchid/touchid.ts new file mode 100644 index 000000000..e0f31a851 --- /dev/null +++ b/src/providers/touchid/touchid.ts @@ -0,0 +1,99 @@ +import { Injectable } from '@angular/core'; +import { PlatformProvider } from '../platform/platform'; + +import { TouchID } from '@ionic-native/touch-id'; +import { AndroidFingerprintAuth } from '@ionic-native/android-fingerprint-auth'; + +@Injectable() +export class TouchIdProvider { + + private _isAvailable: any = false; + + constructor(private touchId: TouchID, private androidFingerprintAuth: AndroidFingerprintAuth, private platform: PlatformProvider) { + this.checkDeviceFingerprint(); + } + + checkDeviceFingerprint() { + if (this.platform.isAndroid) this.checkAndroid(); + if (this.platform.isIOS) this.checkIOS(); + } + + checkIOS() { + this.touchId.isAvailable() + .then( + res => this._isAvailable = 'IOS', + err => console.log("Fingerprint is not available") + ); + } + + checkAndroid() { + this.androidFingerprintAuth.isAvailable() + .then( + res => { + if (res.isAvailable) this._isAvailable = 'ANDROID' + else console.log("Fingerprint is not available") + }); + } + + verifyIOSFingerprint(): Promise { + return new Promise((resolve, reject) => { + this.touchId.verifyFingerprint('Scan your fingerprint please') + .then( + res => resolve(true), + err => reject(false) + ); + }); + } + + verifyAndroidFingerprint(): Promise { + return new Promise((resolve, reject) => { + this.androidFingerprintAuth.encrypt({ clientId: 'Copay' }) + .then(result => { + if (result.withFingerprint) { + console.log('Successfully authenticated with fingerprint.'); + resolve(true); + } else if (result.withBackup) { + console.log('Successfully authenticated with backup password!'); + resolve(true); + } else console.log('Didn\'t authenticate!'); + }) + .catch(error => { + if (error === this.androidFingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) { + console.log('Fingerprint authentication cancelled'); + reject(false); + } else { + console.error(error); + resolve(false); + } + }); + }); + } + + isAvailable() { + return this._isAvailable; + } + + check(): Promise { + return new Promise((resolve, reject) => { + if (!this.isAvailable()) reject(); + if (this.isAvailable() == 'IOS') { + this.verifyIOSFingerprint() + .then((success) => { + resolve(success); + }) + .catch(err => { + reject(err); + }); + } + if (this.isAvailable() == 'ANDROID') { + this.verifyAndroidFingerprint() + .then((success) => { + resolve(success); + }) + .catch(err => { + reject(err); + }); + } + }); + } +}