settings.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Component } from "@angular/core";
  2. import { NavController, ToastController } from "ionic-angular";
  3. import { Storage } from "@ionic/storage";
  4. import { CryptoProvider } from "../../providers/crypto/crypto";
  5. @Component({
  6. selector: "page-settings",
  7. templateUrl: "settings.html"
  8. })
  9. export class SettingsPage {
  10. keywords: string;
  11. privateKey: string;
  12. publicKey: string;
  13. constructor(
  14. public navCtrl: NavController,
  15. public toastCtrl: ToastController,
  16. private cryptoUtils: CryptoProvider,
  17. private storage: Storage
  18. ) {
  19. this.loadValuesFromStorage();
  20. }
  21. async loadValuesFromStorage() {
  22. this.privateKey = await this.storage.get("privateKey");
  23. this.publicKey = await this.storage.get("publicKey");
  24. this.keywords = await this.storage.get("keywords");
  25. }
  26. async generateKeys() {
  27. const keys = await this.cryptoUtils.generateRsaKeys();
  28. this.publicKey = await this.cryptoUtils.extractPublicKey(keys);
  29. this.privateKey = await this.cryptoUtils.extractPrivateKey(keys);
  30. }
  31. save() {
  32. this.storage.set("publicKey", this.publicKey);
  33. this.storage.set("privateKey", this.privateKey);
  34. this.storage.set("keywords", this.keywords);
  35. const toast = this.toastCtrl.create({
  36. message: "Successfully saved!",
  37. position: "bottom",
  38. duration: 3000
  39. });
  40. toast.present();
  41. }
  42. publishPublicKey() {
  43. this.cryptoUtils.publishPublicKey(this.publicKey);
  44. }
  45. }