Browse Source

Export private key

Carsten Porth 5 years ago
parent
commit
7efac06356

+ 3 - 0
app/config.xml

@@ -97,5 +97,8 @@
     <allow-navigation href="http://192.168.56.1:8100" />
     <allow-navigation href="http://192.168.10.1:8100" />
     <allow-navigation href="http://192.168.2.23:8100" />
+    <plugin name="cordova-plugin-x-socialsharing" spec="5.4.3">
+        <variable name="ANDROID_SUPPORT_V4_VERSION" value="24.1.1+" />
+    </plugin>
     <engine name="android" spec="^7.1.4" />
 </widget>

+ 26 - 30
app/package-lock.json

@@ -302,6 +302,11 @@
       "resolved": "https://registry.npmjs.org/@ionic-native/secure-storage/-/secure-storage-4.18.0.tgz",
       "integrity": "sha512-ykqfcxAsMFkUOiY/i587ut07C2jHfBNWbQPQDPzvcd5+QtLeAcX41QzmCIvi7UT/6rYliD+2uQFONP6wxgxa3g=="
     },
+    "@ionic-native/social-sharing": {
+      "version": "4.18.0",
+      "resolved": "https://registry.npmjs.org/@ionic-native/social-sharing/-/social-sharing-4.18.0.tgz",
+      "integrity": "sha512-Yfq2SA7UWTdXmSLDIgyD3ZrMTK0zp6hyw+GSRkVzuilcKkImUaDmU60IyHfSQ8CkfvNX98+pqR53L6fAboLteQ=="
+    },
     "@ionic-native/splash-screen": {
       "version": "4.8.0",
       "resolved": "https://registry.npmjs.org/@ionic-native/splash-screen/-/splash-screen-4.8.0.tgz",
@@ -1589,6 +1594,11 @@
       "resolved": "https://registry.npmjs.org/cordova-plugin-whitelist/-/cordova-plugin-whitelist-1.3.3.tgz",
       "integrity": "sha1-tehezbv+Wu3tQKG/TuI3LmfZb7Q="
     },
+    "cordova-plugin-x-socialsharing": {
+      "version": "5.4.3",
+      "resolved": "https://registry.npmjs.org/cordova-plugin-x-socialsharing/-/cordova-plugin-x-socialsharing-5.4.3.tgz",
+      "integrity": "sha512-4HjeMtil1nWYGul7+/YIKqhPLensUG1cjar0FQQ7kSsic1v8y6dhDdsPzOJR+R4pXmjOqW1OrIGMtpKufjwymA=="
+    },
     "cordova-support-android-plugin": {
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/cordova-support-android-plugin/-/cordova-support-android-plugin-1.0.1.tgz",
@@ -2033,6 +2043,11 @@
         "event-emitter": "~0.3.5"
       }
     },
+    "es6-promise-plugin": {
+      "version": "4.2.2",
+      "resolved": "https://registry.npmjs.org/es6-promise-plugin/-/es6-promise-plugin-4.2.2.tgz",
+      "integrity": "sha512-uoA4aVplXI9oqUYJFBAVRwAqIN9/n9JgrTAUGX3qPbnSZVE5yY1+6/MsoN5f4xsaPO62WjPHOdtts6okMN6tNA=="
+    },
     "es6-set": {
       "version": "0.1.5",
       "resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz",
@@ -2457,8 +2472,7 @@
         },
         "ansi-regex": {
           "version": "2.1.1",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "aproba": {
           "version": "1.2.0",
@@ -2476,13 +2490,11 @@
         },
         "balanced-match": {
           "version": "1.0.0",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "brace-expansion": {
           "version": "1.1.11",
           "bundled": true,
-          "optional": true,
           "requires": {
             "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
@@ -2495,18 +2507,15 @@
         },
         "code-point-at": {
           "version": "1.1.0",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "concat-map": {
           "version": "0.0.1",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "console-control-strings": {
           "version": "1.1.0",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "core-util-is": {
           "version": "1.0.2",
@@ -2609,8 +2618,7 @@
         },
         "inherits": {
           "version": "2.0.3",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "ini": {
           "version": "1.3.5",
@@ -2620,7 +2628,6 @@
         "is-fullwidth-code-point": {
           "version": "1.0.0",
           "bundled": true,
-          "optional": true,
           "requires": {
             "number-is-nan": "^1.0.0"
           }
@@ -2633,20 +2640,17 @@
         "minimatch": {
           "version": "3.0.4",
           "bundled": true,
-          "optional": true,
           "requires": {
             "brace-expansion": "^1.1.7"
           }
         },
         "minimist": {
           "version": "0.0.8",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "minipass": {
           "version": "2.2.4",
           "bundled": true,
-          "optional": true,
           "requires": {
             "safe-buffer": "^5.1.1",
             "yallist": "^3.0.0"
@@ -2663,7 +2667,6 @@
         "mkdirp": {
           "version": "0.5.1",
           "bundled": true,
-          "optional": true,
           "requires": {
             "minimist": "0.0.8"
           }
@@ -2736,8 +2739,7 @@
         },
         "number-is-nan": {
           "version": "1.0.1",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "object-assign": {
           "version": "4.1.1",
@@ -2747,7 +2749,6 @@
         "once": {
           "version": "1.4.0",
           "bundled": true,
-          "optional": true,
           "requires": {
             "wrappy": "1"
           }
@@ -2823,8 +2824,7 @@
         },
         "safe-buffer": {
           "version": "5.1.1",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "safer-buffer": {
           "version": "2.1.2",
@@ -2854,7 +2854,6 @@
         "string-width": {
           "version": "1.0.2",
           "bundled": true,
-          "optional": true,
           "requires": {
             "code-point-at": "^1.0.0",
             "is-fullwidth-code-point": "^1.0.0",
@@ -2872,7 +2871,6 @@
         "strip-ansi": {
           "version": "3.0.1",
           "bundled": true,
-          "optional": true,
           "requires": {
             "ansi-regex": "^2.0.0"
           }
@@ -2911,13 +2909,11 @@
         },
         "wrappy": {
           "version": "1.0.2",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "yallist": {
           "version": "3.0.2",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         }
       }
     },

+ 7 - 1
app/package.json

@@ -23,6 +23,7 @@
     "@angular/platform-browser-dynamic": "5.2.11",
     "@ionic-native/core": "4.8.0",
     "@ionic-native/secure-storage": "^4.18.0",
+    "@ionic-native/social-sharing": "^4.18.0",
     "@ionic-native/splash-screen": "4.8.0",
     "@ionic-native/status-bar": "4.8.0",
     "@ionic/storage": "2.1.3",
@@ -38,9 +39,11 @@
     "cordova-plugin-secure-storage": "^2.6.8",
     "cordova-plugin-splashscreen": "^5.0.2",
     "cordova-plugin-whitelist": "^1.3.3",
+    "cordova-plugin-x-socialsharing": "5.4.3",
     "cordova-support-android-plugin": "^1.0.1",
     "cordova-support-google-services": "^1.2.1",
     "cordova-universal-links-plugin": "git+https://github.com/walteram/cordova-universal-links-plugin.git",
+    "es6-promise-plugin": "4.2.2",
     "firebase": "^5.7.1",
     "gun": "^0.9.999995",
     "ionic-angular": "3.9.2",
@@ -68,7 +71,10 @@
       "cordova-plugin-buildinfo": {},
       "cordova-plugin-browsertab": {},
       "cordova-plugin-inappbrowser": {},
-      "cordova-universal-links-plugin": {}
+      "cordova-universal-links-plugin": {},
+      "cordova-plugin-x-socialsharing": {
+        "ANDROID_SUPPORT_V4_VERSION": "24.1.1+"
+      }
     },
     "platforms": [
       "android"

+ 3 - 1
app/src/app/app.module.ts

@@ -5,6 +5,7 @@ import { SplashScreen } from "@ionic-native/splash-screen";
 import { StatusBar } from "@ionic-native/status-bar";
 import { HttpClient, HttpClientModule } from "@angular/common/http";
 import { IonicStorageModule } from "@ionic/storage";
+import { SocialSharing } from "@ionic-native/social-sharing";
 
 import { AuthProvider } from "../providers/auth/auth";
 
@@ -34,7 +35,7 @@ import { SearchResultsTweetsPopularPage } from "../pages/search-results-tweets-p
 import { SearchResultsTweetsRecentPage } from "../pages/search-results-tweets-recent/search-results-tweets-recent";
 import { SearchResultsTweetsTabsPage } from "../pages/search-results-tweets-tabs/search-results-tweets-tabs";
 import { AboutPage } from "../pages/about/about";
-import { CryptoProvider } from '../providers/crypto/crypto';
+import { CryptoProvider } from "../providers/crypto/crypto";
 
 @NgModule({
   declarations: [
@@ -86,6 +87,7 @@ import { CryptoProvider } from '../providers/crypto/crypto';
     StatusBar,
     SplashScreen,
     HttpClient,
+    SocialSharing,
     { provide: ErrorHandler, useClass: IonicErrorHandler },
     AuthProvider,
     TwitterApiProvider,

+ 3 - 2
app/src/pages/settings/settings.html

@@ -24,12 +24,13 @@
         generate
         a pair of keys. If you run the app on multiple devices, please enter everywhere the same pair of keys.</p>
       <button ion-button block (click)="generateKeys()">Generate keys</button>
-      <ion-label color="primary" stacked>Public Key:</ion-label>
-      <ion-textarea [(ngModel)]="privateKey"></ion-textarea>
       <ion-label color="primary" stacked>Private Key:</ion-label>
+      <ion-textarea [(ngModel)]="privateKey"></ion-textarea>
+      <ion-label color="primary" stacked>Public Key:</ion-label>
       <ion-textarea [(ngModel)]="publicKey"></ion-textarea>
       <p>Under no circumstances share your private key with any other person!</p>
       <button ion-button block (click)="publishPublicKey()">Publish public key</button>
+      <button ion-button block (click)="exportPrivateKey()">Export private key</button>
     </ion-card-content>
   </ion-card>
 

+ 18 - 1
app/src/pages/settings/settings.ts

@@ -6,6 +6,7 @@ import {
 } from "ionic-angular";
 import { Storage } from "@ionic/storage";
 import { CryptoProvider } from "../../providers/crypto/crypto";
+import { SocialSharing } from "@ionic-native/social-sharing";
 
 @Component({
   selector: "page-settings",
@@ -21,7 +22,8 @@ export class SettingsPage {
     public toastCtrl: ToastController,
     private cryptoUtils: CryptoProvider,
     private storage: Storage,
-    private loadingCtrl: LoadingController
+    private loadingCtrl: LoadingController,
+    private sharing: SocialSharing
   ) {
     this.loadValuesFromStorage();
   }
@@ -59,6 +61,21 @@ export class SettingsPage {
     }
   }
 
+  exportPrivateKey() {
+    if (this.privateKey.length) {
+      this.sharing
+        .share(this.privateKey, null, null, null)
+        .then(() => console.log("Private key was exported"))
+        .catch(() =>
+          this.showToast(
+            "Sorry! Something went wrong trying to export the private key :("
+          )
+        );
+    } else {
+      this.showToast("There is nothing to share.");
+    }
+  }
+
   private showToast(message: string) {
     const toast = this.toastCtrl.create({
       message: message,