Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Security/RevealPhraseView.swift8// Module : Security9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import UIKit43import QyvoraWallet44import QyvoraUI4546/// Shows the recovery phrase after a fresh authentication. The words live in this view's state only: they are47/// cleared when the screen is left, when the app leaves the foreground, or when the user hides them. They cannot be48/// selected or copied.49struct RevealPhraseView: View {50 @Environment(WalletStore.self) private var store51 @Environment(\.scenePhase) private var scenePhase52 @State private var words: [String] = []53 @State private var error: String?54 @State private var busy = false55 @State private var reauthenticate = false56 @State private var screenshotTaken = false5758 var usesPassphrase: Bool { store.snapshot?.profile.usesPassphrase == true }5960 var body: some View {61 SecurityScroll {62 if words.isEmpty {63 CompromisedDeviceNotice()64 WarningBanner(.critical, title: "Anyone who reads these words controls the funds",65 message: "Make sure nobody and no camera can see the screen. QYVORA will never ask for the phrase; neither will its publisher.")66 QListSection("Before you reveal", footnote: "The same words restore every chain of this wallet: Bitcoin and the other coins, the EVM account, Solana and TRON.") {67 SecTextRow(text: "Write the words on paper, in order, with their numbers.", systemImage: "pencil.line")68 SecTextRow(text: "Do not take a screenshot: screenshots are stored in Photos and may be synchronized to a cloud account.", systemImage: "camera.metering.none")69 SecTextRow(text: "Do not type the words into a notes app, an e-mail or a website.", systemImage: "keyboard.badge.ellipsis")70 SecTextRow(text: "The words are hidden again when you leave this screen or the app.", systemImage: "eye.slash")71 }72 SecInlineError(error)73 LoadingButton("Reveal recovery phrase", loadingTitle: "Reading the vault", systemImage: "eye", state: busy ? .loading : .idle) {74 reauthenticate = true75 }76 } else {77 if screenshotTaken {78 WarningBanner(.critical, title: ScreenshotWarning.title, message: ScreenshotWarning.message)79 }80 SeedPhraseGrid(words: words, masked: false, protected: true)81 if usesPassphrase {82 WarningBanner(.warning, title: "This wallet also uses a BIP-39 passphrase",83 message: "The passphrase is not shown here. Without it these words open a different, empty wallet.")84 }85 Explanation("\(words.count) words. Check each one against your written copy, then verify the copy from the Recovery screen.")86 Button { hide() } label: { Label("Hide", systemImage: "eye.slash") }87 .buttonStyle(.qSecondary)88 }89 }90 .navigationTitle("Recovery phrase")91 .navigationBarTitleDisplayMode(.inline)92 .privacySensitive()93 .requiresReauthentication(isPresented: $reauthenticate, reason: "Reveal the recovery phrase") { reveal() }94 .onDisappear { hide() }95 #if DEBUG96 .task { if SecurityDebug.action == "go" { reauthenticate = true } }97 #endif98 .onChange(of: scenePhase) { _, phase in99 if phase != .active { hide() }100 }101 .warnsAboutScreenshots(of: !words.isEmpty, taken: $screenshotTaken)102 }103104 func hide() {105 words = []106 }107108 func reveal() {109 guard !busy else { return }110 busy = true111 error = nil112 screenshotTaken = false113 Task {114 do {115 words = try await store.run { try await $0.revealRecoveryPhrase() }116 } catch {117 self.error = SecurityError.text(error)118 }119 busy = false120 }121 }122}123