From 10c58d84a9b151b3d71b629aa13a4afeebe2c898 Mon Sep 17 00:00:00 2001 From: Sean Wu Date: Thu, 5 Nov 2020 00:50:53 +0800 Subject: [PATCH] Rebuild proof details with angular-material. - Rename default-information-provider to capacitor-provider. - Rename default-signature-provider to web-crypto-api-provider. - Only display the information from capacitor and the signature from web-crypto-api. Resolve #152, #153. --- src/app/app-routing.module.ts | 4 - src/app/app.component.ts | 6 +- src/app/pages/profile/profile.page.scss | 5 - src/app/pages/profile/profile.page.ts | 6 +- .../information/information-routing.module.ts | 0 .../proof}/information/information.module.ts | 0 .../proof}/information/information.page.html | 2 +- .../proof}/information/information.page.scss | 0 .../information/information.page.spec.ts | 0 .../proof}/information/information.page.ts | 0 .../storage/proof/proof-routing.module.ts | 5 + src/app/pages/storage/proof/proof.module.ts | 4 +- src/app/pages/storage/proof/proof.page.html | 102 ++++++------------ src/app/pages/storage/proof/proof.page.scss | 9 ++ .../pages/storage/proof/proof.page.spec.ts | 4 +- src/app/pages/storage/proof/proof.page.ts | 76 ++++--------- .../capacitor-provider/capacitor-provider.ts | 39 +++---- .../information/information-provider.ts | 2 +- .../collector/signature/signature-provider.ts | 2 +- .../web-crypto-api-provider.spec.ts} | 0 .../web-crypto-api-provider.ts} | 13 +-- .../utils/preferences/preference-manager.ts | 8 +- src/global.scss | 5 + 23 files changed, 117 insertions(+), 175 deletions(-) rename src/app/pages/{ => storage/proof}/information/information-routing.module.ts (100%) rename src/app/pages/{ => storage/proof}/information/information.module.ts (100%) rename src/app/pages/{ => storage/proof}/information/information.page.html (95%) rename src/app/pages/{ => storage/proof}/information/information.page.scss (100%) rename src/app/pages/{ => storage/proof}/information/information.page.spec.ts (100%) rename src/app/pages/{ => storage/proof}/information/information.page.ts (100%) rename src/app/services/collector/signature/{default-provider/default-provider.spec.ts => web-crypto-api-provider/web-crypto-api-provider.spec.ts} (100%) rename src/app/services/collector/signature/{default-provider/default-provider.ts => web-crypto-api-provider/web-crypto-api-provider.ts} (80%) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 5375e56a5..b0f917d4b 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -33,10 +33,6 @@ const routes: Routes = [{ path: 'about', loadChildren: () => import('./pages/about/about.module').then(m => m.AboutPageModule), canActivate: [AuthGuardService], -}, { - path: 'information', - loadChildren: () => import('./pages/information/information.module').then(m => m.InformationPageModule), - canActivate: [AuthGuardService], }, { path: 'publishers', redirectTo: 'settings', diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1afd4a1fe..fd4f5ec6f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -7,7 +7,7 @@ import { map } from 'rxjs/operators'; import { CameraService } from './services/camera/camera.service'; import { CollectorService } from './services/collector/collector.service'; import { CapacitorProvider } from './services/collector/information/capacitor-provider/capacitor-provider'; -import { DefaultSignatureProvider } from './services/collector/signature/default-provider/default-provider'; +import { WebCryptoApiProvider } from './services/collector/signature/web-crypto-api-provider/web-crypto-api-provider'; import { CaptionRepository } from './services/data/caption/caption-repository.service'; import { InformationRepository } from './services/data/information/information-repository.service'; import { ProofRepository } from './services/data/proof/proof-repository.service'; @@ -68,12 +68,12 @@ export class AppComponent { } initializeCollector() { - DefaultSignatureProvider.initialize$().pipe(untilDestroyed(this)).subscribe(); + WebCryptoApiProvider.initialize$().pipe(untilDestroyed(this)).subscribe(); this.collectorService.addInformationProvider( new CapacitorProvider(this.informationRepository, this.translocoService) ); this.collectorService.addSignatureProvider( - new DefaultSignatureProvider(this.signatureRepository, this.serializationService) + new WebCryptoApiProvider(this.signatureRepository, this.serializationService) ); } diff --git a/src/app/pages/profile/profile.page.scss b/src/app/pages/profile/profile.page.scss index d6953916e..51e5470f5 100644 --- a/src/app/pages/profile/profile.page.scss +++ b/src/app/pages/profile/profile.page.scss @@ -7,8 +7,3 @@ mat-toolbar { width: 50%; margin: 10vw auto; } - -.expand { - width: calc(100vw - 16px); - margin: 0 8px; -} diff --git a/src/app/pages/profile/profile.page.ts b/src/app/pages/profile/profile.page.ts index 3ea5d90b1..b51b43672 100644 --- a/src/app/pages/profile/profile.page.ts +++ b/src/app/pages/profile/profile.page.ts @@ -8,7 +8,7 @@ import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { defer } from 'rxjs'; import { catchError, concatMapTo } from 'rxjs/operators'; import { BlockingActionService } from '../../services/blocking-action/blocking-action.service'; -import { DefaultSignatureProvider } from '../../services/collector/signature/default-provider/default-provider'; +import { WebCryptoApiProvider } from '../../services/collector/signature/web-crypto-api-provider/web-crypto-api-provider'; import { NumbersStorageApi } from '../../services/publisher/numbers-storage/numbers-storage-api.service'; const { Clipboard } = Plugins; @@ -23,8 +23,8 @@ export class ProfilePage { readonly userName$ = this.numbersStorageApi.getUserName$(); readonly email$ = this.numbersStorageApi.getEmail$(); - readonly publicKey$ = DefaultSignatureProvider.getPublicKey$(); - readonly privateKey$ = DefaultSignatureProvider.getPrivateKey$(); + readonly publicKey$ = WebCryptoApiProvider.getPublicKey$(); + readonly privateKey$ = WebCryptoApiProvider.getPrivateKey$(); constructor( private readonly router: Router, diff --git a/src/app/pages/information/information-routing.module.ts b/src/app/pages/storage/proof/information/information-routing.module.ts similarity index 100% rename from src/app/pages/information/information-routing.module.ts rename to src/app/pages/storage/proof/information/information-routing.module.ts diff --git a/src/app/pages/information/information.module.ts b/src/app/pages/storage/proof/information/information.module.ts similarity index 100% rename from src/app/pages/information/information.module.ts rename to src/app/pages/storage/proof/information/information.module.ts diff --git a/src/app/pages/information/information.page.html b/src/app/pages/storage/proof/information/information.page.html similarity index 95% rename from src/app/pages/information/information.page.html rename to src/app/pages/storage/proof/information/information.page.html index 8ddba8475..080a07360 100644 --- a/src/app/pages/information/information.page.html +++ b/src/app/pages/storage/proof/information/information.page.html @@ -1,7 +1,7 @@ - + diff --git a/src/app/pages/information/information.page.scss b/src/app/pages/storage/proof/information/information.page.scss similarity index 100% rename from src/app/pages/information/information.page.scss rename to src/app/pages/storage/proof/information/information.page.scss diff --git a/src/app/pages/information/information.page.spec.ts b/src/app/pages/storage/proof/information/information.page.spec.ts similarity index 100% rename from src/app/pages/information/information.page.spec.ts rename to src/app/pages/storage/proof/information/information.page.spec.ts diff --git a/src/app/pages/information/information.page.ts b/src/app/pages/storage/proof/information/information.page.ts similarity index 100% rename from src/app/pages/information/information.page.ts rename to src/app/pages/storage/proof/information/information.page.ts diff --git a/src/app/pages/storage/proof/proof-routing.module.ts b/src/app/pages/storage/proof/proof-routing.module.ts index 81d70a329..812a1f7c3 100644 --- a/src/app/pages/storage/proof/proof-routing.module.ts +++ b/src/app/pages/storage/proof/proof-routing.module.ts @@ -1,10 +1,15 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { AuthGuardService } from 'src/app/services/auth/auth-guard.service'; import { ProofPage } from './proof.page'; const routes: Routes = [{ path: '', component: ProofPage +}, { + path: 'information', + loadChildren: () => import('./information/information.module').then(m => m.InformationPageModule), + canActivate: [AuthGuardService], }]; @NgModule({ diff --git a/src/app/pages/storage/proof/proof.module.ts b/src/app/pages/storage/proof/proof.module.ts index ad56136c8..af3e1e033 100644 --- a/src/app/pages/storage/proof/proof.module.ts +++ b/src/app/pages/storage/proof/proof.module.ts @@ -3,6 +3,7 @@ import { NgModule } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatListModule } from '@angular/material/list'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatToolbarModule } from '@angular/material/toolbar'; import { IonicModule } from '@ionic/angular'; import { TranslocoModule } from '@ngneat/transloco'; @@ -18,7 +19,8 @@ import { ProofPage } from './proof.page'; MatToolbarModule, MatButtonModule, MatIconModule, - MatListModule + MatListModule, + MatSnackBarModule ], declarations: [ProofPage] }) diff --git a/src/app/pages/storage/proof/proof.page.html b/src/app/pages/storage/proof/proof.page.html index 7e2bcc58d..453f75a6c 100644 --- a/src/app/pages/storage/proof/proof.page.html +++ b/src/app/pages/storage/proof/proof.page.html @@ -4,6 +4,9 @@ {{ t('proofDetails') }} + @@ -15,6 +18,7 @@
+
{{ t('information') }}
sticky_note_2
{{ t('caption') }}
@@ -24,6 +28,9 @@ code
{{ t('hash') }}
{{ hash$ | async }}
+
access_time @@ -38,77 +45,28 @@ place
{{ t('location') }}
-
{{ 'location' }}
+
{{ location$ | async }}
-
{{ t('information') }}
-
- - \ No newline at end of file + + +
{{ t('signature') }}
+ + policy +
{{ t('signature') }}
+
{{ (signature$ | async)?.signature }}
+ +
+ + lock +
{{ t('publicKey') }}
+
{{ (signature$ | async)?.publicKey }}
+ +
+
+ \ No newline at end of file diff --git a/src/app/pages/storage/proof/proof.page.scss b/src/app/pages/storage/proof/proof.page.scss index 0e57c1cf3..b943bd541 100644 --- a/src/app/pages/storage/proof/proof.page.scss +++ b/src/app/pages/storage/proof/proof.page.scss @@ -5,3 +5,12 @@ mat-toolbar { .toolbar-spacer { flex: 1 1 auto; } + +.page-content { + padding-bottom: 16px; +} + +button.center { + display: block; + margin: 0 auto; +} diff --git a/src/app/pages/storage/proof/proof.page.spec.ts b/src/app/pages/storage/proof/proof.page.spec.ts index 8d09b0628..14a01608f 100644 --- a/src/app/pages/storage/proof/proof.page.spec.ts +++ b/src/app/pages/storage/proof/proof.page.spec.ts @@ -2,6 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatListModule } from '@angular/material/list'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatToolbarModule } from '@angular/material/toolbar'; import { RouterTestingModule } from '@angular/router/testing'; import { IonicModule } from '@ionic/angular'; @@ -22,7 +23,8 @@ describe('ProofPage', () => { MatToolbarModule, MatButtonModule, MatIconModule, - MatListModule + MatListModule, + MatSnackBarModule ] }).compileComponents(); diff --git a/src/app/pages/storage/proof/proof.page.ts b/src/app/pages/storage/proof/proof.page.ts index 2b77afc4b..e9088f73d 100644 --- a/src/app/pages/storage/proof/proof.page.ts +++ b/src/app/pages/storage/proof/proof.page.ts @@ -1,20 +1,24 @@ import { Component } from '@angular/core'; +import { MatSnackBar } from '@angular/material/snack-bar'; import { ActivatedRoute, Router } from '@angular/router'; -import { AlertController } from '@ionic/angular'; +import { Plugins } from '@capacitor/core'; import { TranslocoService } from '@ngneat/transloco'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { defer } from 'rxjs'; import { first, map, pluck, switchMap, switchMapTo } from 'rxjs/operators'; import { BlockingActionService } from 'src/app/services/blocking-action/blocking-action.service'; +import { CapacitorProvider } from 'src/app/services/collector/information/capacitor-provider/capacitor-provider'; +import { WebCryptoApiProvider } from 'src/app/services/collector/signature/web-crypto-api-provider/web-crypto-api-provider'; import { ConfirmAlert } from 'src/app/services/confirm-alert/confirm-alert.service'; import { CaptionRepository } from 'src/app/services/data/caption/caption-repository.service'; -import { Importance } from 'src/app/services/data/information/information'; import { InformationRepository } from 'src/app/services/data/information/information-repository.service'; import { ProofRepository } from 'src/app/services/data/proof/proof-repository.service'; import { SignatureRepository } from 'src/app/services/data/signature/signature-repository.service'; import { PublishersAlert } from 'src/app/services/publisher/publishers-alert/publishers-alert.service'; import { isNonNullable } from 'src/app/utils/rx-operators'; +const { Clipboard } = Plugins; + @UntilDestroy({ checkProperties: true }) @Component({ selector: 'app-proof', @@ -34,9 +38,6 @@ export class ProofPage { switchMap(proof => this.proofRepository.getRawFile$(proof)), map(rawBase64 => `data:image/png;base64,${rawBase64}`) ); - readonly hash$ = this.proof$.pipe(pluck('hash')); - readonly mimeType$ = this.proof$.pipe(pluck('mimeType')); - readonly timestamp$ = this.proof$.pipe(pluck('timestamp')); readonly caption$ = this.proof$.pipe( switchMap(proof => this.captionRepository.getByProof$(proof)), map(caption => { @@ -44,36 +45,33 @@ export class ProofPage { return ''; }) ); - - readonly providersWithImportantInformation$ = this.proof$.pipe( + readonly hash$ = this.proof$.pipe(pluck('hash')); + readonly timestamp$ = this.proof$.pipe(pluck('timestamp')); + readonly mimeType$ = this.proof$.pipe(pluck('mimeType')); + readonly location$ = this.proof$.pipe( switchMap(proof => this.informationRepository.getByProof$(proof)), - map(informationList => { - const providers = new Set(informationList.map(information => information.provider)); - return [...providers].map(provider => ({ - provider, - informationList: informationList.filter( - information => information.provider === provider && information.importance === Importance.High - ) - })); - }) + map(informationList => informationList.find(information => information.provider === CapacitorProvider.ID && information.name === 'Location')), + isNonNullable(), + pluck('value') ); - - readonly signatures$ = this.proof$.pipe( - switchMap(proof => this.signatureRepository.getByProof$(proof)) + readonly signature$ = this.proof$.pipe( + switchMap(proof => this.signatureRepository.getByProof$(proof)), + map(signatures => signatures.find(signature => signature.provider === WebCryptoApiProvider.ID)), + isNonNullable() ); constructor( private readonly router: Router, private readonly route: ActivatedRoute, private readonly translocoService: TranslocoService, - private readonly alertController: AlertController, private readonly confirmAlert: ConfirmAlert, private readonly publishersAlert: PublishersAlert, private readonly proofRepository: ProofRepository, private readonly captionRepository: CaptionRepository, private readonly informationRepository: InformationRepository, private readonly signatureRepository: SignatureRepository, - private readonly blockingActionService: BlockingActionService + private readonly blockingActionService: BlockingActionService, + private readonly snackBar: MatSnackBar ) { } publish() { @@ -96,38 +94,8 @@ export class ProofPage { return this.confirmAlert.present$(onConfirm).pipe(untilDestroyed(this)).subscribe(); } - editCaption() { - const captionInputName = 'captionInputName'; - this.caption$.pipe( - first(), - switchMap(caption => this.alertController.create({ - header: this.translocoService.translate('editCaption'), - inputs: [{ - name: captionInputName, - type: 'text', - value: caption, - placeholder: this.translocoService.translate('nothingHere') - }], - buttons: [{ - text: this.translocoService.translate('cancel'), - role: 'cancel' - }, { - text: this.translocoService.translate('ok'), - handler: (inputs) => this.saveCaption(inputs[captionInputName]) - }] - })), - switchMap(alertElement => alertElement.present()), - untilDestroyed(this) - ).subscribe(); - } - - private saveCaption(text: string) { - this.proof$.pipe( - switchMap(proof => this.captionRepository.addOrEdit$({ - proofHash: proof.hash, - text - })), - untilDestroyed(this) - ).subscribe(); + copyToClipboard(value: string) { + Clipboard.write({ string: value }); + this.snackBar.open(this.translocoService.translate('message.copiedToClipboard')); } } diff --git a/src/app/services/collector/information/capacitor-provider/capacitor-provider.ts b/src/app/services/collector/information/capacitor-provider/capacitor-provider.ts index 2005d8726..6b219869a 100644 --- a/src/app/services/collector/information/capacitor-provider/capacitor-provider.ts +++ b/src/app/services/collector/information/capacitor-provider/capacitor-provider.ts @@ -10,7 +10,7 @@ import { InformationProvider } from '../information-provider'; const { Device, Geolocation } = Plugins; -const preferences = PreferenceManager.DEFAULT_INFORMATION_PROVIDER_PREF; +const preferences = PreferenceManager.CAPACITOR_PROVIDER_PREF; const enum PrefKeys { CollectDeviceInfo = 'collectDeviceInfo', CollectLocationInfo = 'collectLocationInfo' @@ -18,7 +18,8 @@ const enum PrefKeys { export class CapacitorProvider extends InformationProvider { - readonly name = 'Capacitor'; + static readonly ID = 'capacitor'; + readonly id = CapacitorProvider.ID; constructor( informationRepository: InformationRepository, @@ -63,91 +64,91 @@ export class CapacitorProvider extends InformationProvider { if (deviceInfo !== undefined) { informationList.push({ proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('uuid'), value: String(deviceInfo.uuid), importance: Importance.High, type: InformationType.Other }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('deviceName'), value: String(deviceInfo.name), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('deviceModel'), value: String(deviceInfo.model), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('devicePlatform'), value: String(deviceInfo.platform), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('appVersion'), value: String(deviceInfo.appVersion), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('appVersionCode'), value: String(deviceInfo.appBuild), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('operatingSystem'), value: String(deviceInfo.operatingSystem), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('osVersion'), value: String(deviceInfo.osVersion), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('deviceManufacturer'), value: String(deviceInfo.manufacturer), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('runningOnVm'), value: String(deviceInfo.isVirtual), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('usedMemory'), value: String(deviceInfo.memUsed), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('freeDiskSpace'), value: String(deviceInfo.diskFree), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('totalDiskSpace'), value: String(deviceInfo.diskTotal), importance: Importance.Low, @@ -157,14 +158,14 @@ export class CapacitorProvider extends InformationProvider { if (batteryInfo !== undefined) { informationList.push({ proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('batteryLevel'), value: String(batteryInfo.batteryLevel), importance: Importance.Low, type: InformationType.Device }, { proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('batteryCharging'), value: String(batteryInfo.isCharging), importance: Importance.Low, @@ -174,7 +175,7 @@ export class CapacitorProvider extends InformationProvider { if (languageCode !== undefined) { informationList.push({ proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('deviceLanguageCode'), value: String(languageCode.value), importance: Importance.Low, @@ -184,7 +185,7 @@ export class CapacitorProvider extends InformationProvider { if (geolocationPosition !== undefined) { informationList.push({ proofHash: proof.hash, - provider: this.name, + provider: this.id, name: this.translocoService.translate('location'), value: `(${geolocationPosition.coords.latitude}, ${geolocationPosition.coords.longitude})`, importance: Importance.High, diff --git a/src/app/services/collector/information/information-provider.ts b/src/app/services/collector/information/information-provider.ts index 5ddfbaade..46d9162b5 100644 --- a/src/app/services/collector/information/information-provider.ts +++ b/src/app/services/collector/information/information-provider.ts @@ -6,7 +6,7 @@ import { Proof } from '../../data/proof/proof'; export abstract class InformationProvider { - abstract readonly name: string; + abstract readonly id: string; constructor( private readonly informationRepository: InformationRepository diff --git a/src/app/services/collector/signature/signature-provider.ts b/src/app/services/collector/signature/signature-provider.ts index dad87d54d..00f858b9e 100644 --- a/src/app/services/collector/signature/signature-provider.ts +++ b/src/app/services/collector/signature/signature-provider.ts @@ -7,7 +7,7 @@ import { SerializationService } from '../../serialization/serialization.service' export abstract class SignatureProvider { - abstract readonly name: string; + abstract readonly id: string; constructor( private readonly signatureRepository: SignatureRepository, diff --git a/src/app/services/collector/signature/default-provider/default-provider.spec.ts b/src/app/services/collector/signature/web-crypto-api-provider/web-crypto-api-provider.spec.ts similarity index 100% rename from src/app/services/collector/signature/default-provider/default-provider.spec.ts rename to src/app/services/collector/signature/web-crypto-api-provider/web-crypto-api-provider.spec.ts diff --git a/src/app/services/collector/signature/default-provider/default-provider.ts b/src/app/services/collector/signature/web-crypto-api-provider/web-crypto-api-provider.ts similarity index 80% rename from src/app/services/collector/signature/default-provider/default-provider.ts rename to src/app/services/collector/signature/web-crypto-api-provider/web-crypto-api-provider.ts index 066184839..3c905de5d 100644 --- a/src/app/services/collector/signature/default-provider/default-provider.ts +++ b/src/app/services/collector/signature/web-crypto-api-provider/web-crypto-api-provider.ts @@ -6,15 +6,16 @@ import { createEcKeyPair$, signWithSha256AndEcdsa$ } from 'src/app/utils/crypto/ import { PreferenceManager } from 'src/app/utils/preferences/preference-manager'; import { SignatureProvider } from '../signature-provider'; -const preferences = PreferenceManager.DEFAULT_SIGNATURE_PROVIDER_PREF; +const preferences = PreferenceManager.WEB_CRYPTO_API_PROVIDER_PREF; const enum PrefKeys { PublicKey = 'publicKey', PrivateKey = 'privateKey' } -export class DefaultSignatureProvider extends SignatureProvider { +export class WebCryptoApiProvider extends SignatureProvider { - readonly name = 'Web Crypto API'; + static readonly ID = 'web-crypto-api'; + readonly id = WebCryptoApiProvider.ID; static initialize$() { return zip( @@ -40,14 +41,14 @@ export class DefaultSignatureProvider extends SignatureProvider { } protected provide$(proof: Proof, serialized: string): Observable { - return DefaultSignatureProvider.getPrivateKey$().pipe( + return WebCryptoApiProvider.getPrivateKey$().pipe( first(), switchMap(privateKeyHex => signWithSha256AndEcdsa$(serialized, privateKeyHex)), - switchMap(signatureHex => zip(of(signatureHex), DefaultSignatureProvider.getPublicKey$())), + switchMap(signatureHex => zip(of(signatureHex), WebCryptoApiProvider.getPublicKey$())), first(), map(([signatureHex, publicKeyHex]) => ({ proofHash: proof.hash, - provider: this.name, + provider: this.id, signature: signatureHex, publicKey: publicKeyHex })) diff --git a/src/app/utils/preferences/preference-manager.ts b/src/app/utils/preferences/preference-manager.ts index bffc7b4de..6ff899417 100644 --- a/src/app/utils/preferences/preference-manager.ts +++ b/src/app/utils/preferences/preference-manager.ts @@ -2,15 +2,15 @@ import { Preferences } from './preferences'; const enum RepositoryName { Language = 'language', - DefaultInformationProvider = 'defaultInformationProvider', - DefaultSignatureProvider = 'defaultSignatureProvider', + CapacitorProvider = 'capacitorProvider', + WebCryptoApiProvider = 'webCryptoApiProvider', NumbersStoragePublisher = 'numbersStoragePublisher' } export class PreferenceManager { static readonly LANGUAGE_PREF = new Preferences(RepositoryName.Language); - static readonly DEFAULT_INFORMATION_PROVIDER_PREF = new Preferences(RepositoryName.DefaultInformationProvider); - static readonly DEFAULT_SIGNATURE_PROVIDER_PREF = new Preferences(RepositoryName.DefaultSignatureProvider); + static readonly CAPACITOR_PROVIDER_PREF = new Preferences(RepositoryName.CapacitorProvider); + static readonly WEB_CRYPTO_API_PROVIDER_PREF = new Preferences(RepositoryName.WebCryptoApiProvider); static readonly NUMBERS_STORAGE_PUBLISHER_PREF = new Preferences(RepositoryName.NumbersStoragePublisher); } diff --git a/src/global.scss b/src/global.scss index 4b883e4be..8fabbe675 100644 --- a/src/global.scss +++ b/src/global.scss @@ -37,3 +37,8 @@ mat-toolbar { min-height: 56px; } + +button.expand { + width: calc(100vw - 16px); + margin: 0 8px; +}