Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Security/RecoveryView.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 QyvoraWallet43import QyvoraUI4445/// Quantum Recovery: state of the two backups (written phrase, encrypted file) and the entries to reveal, verify,46/// export, back up and transfer.47struct RecoveryView: View {48 @Environment(WalletStore.self) private var store4950 var body: some View {51 SecurityScroll {52 if let snapshot = store.snapshot {53 if !snapshot.hasWallet {54 EmptyStateView(systemImage: "arrow.counterclockwise.circle", title: "No wallet on this device",55 message: "Create or restore a wallet first. Restoring from an encrypted backup or from another iPhone is offered when the app starts without a wallet.")56 } else if snapshot.profile.kind == .watchOnly {57 EmptyStateView(systemImage: "eye", title: "Watch-only wallet",58 message: "This device holds public keys only. The recovery phrase and its backups live on the device that holds the keys.")59 } else {60 status(snapshot.profile).id("state")61 phrase.id("phrase")62 backup.id("backup")63 transfer.id("transfer")64 }65 } else {66 SecSkeletonSection(title: "State", rows: 2)67 SecSkeletonSection(title: "Recovery phrase", rows: 3)68 }69 }70 .debugScroll()71 .navigationTitle("Quantum Recovery")72 .navigationBarTitleDisplayMode(.inline)73 }7475 private func status(_ profile: WalletProfile) -> some View {76 QListSection("State", footnote: "The recovery phrase restores the keys of every chain of this wallet in any compatible wallet: the recovery sheet lists the path of each one. The encrypted backup also restores the identity and the vault records, in QYVORA only.") {77 statusRow("Written recovery phrase", profile.recoveryPhraseVerified ? .positive : .warning, profile.recoveryPhraseVerified ? "Verified" : "Not verified")78 if profile.usesPassphrase {79 SecFactRow(label: "BIP-39 passphrase", value: "In use")80 }81 if let date = profile.lastBackupDate {82 SecFactRow(label: "Last encrypted backup", value: SecurityFormat.date(date))83 SecFactRow(label: "Signed by the identity", value: profile.lastBackupSigned.map { $0 ? "Yes" : "No" } ?? "Not recorded")84 } else {85 statusRow("Last encrypted backup", .neutral, "None made on this device")86 }87 }88 }8990 private func statusRow(_ label: String, _ tone: QTone, _ value: String) -> some View {91 ViewThatFits(in: .horizontal) {92 HStack(spacing: QSpace.m) {93 Text(label).font(QFont.callout).foregroundStyle(QColor.textSecondary)94 Spacer(minLength: QSpace.s)95 StatusDot(tone, label: value)96 }97 VStack(alignment: .leading, spacing: 3) {98 Text(label).font(QFont.callout).foregroundStyle(QColor.textSecondary)99 StatusDot(tone, label: value)100 }101 }102 .padding(.vertical, QSpace.m)103 .accessibilityElement(children: .combine)104 }105106 private var phrase: some View {107 QListSection("Recovery phrase") {108 SecLinkRow(title: "Reveal recovery phrase", subtitle: "After authentication", systemImage: "eye", value: SecurityRoute.revealPhrase)109 SecLinkRow(title: "Verify your written copy", subtitle: "Type the phrase back", systemImage: "checkmark.circle", value: SecurityRoute.verifyPhrase)110 SecLinkRow(title: "Recovery sheet", subtitle: "Every chain: paths, public keys, descriptors, addresses", systemImage: "doc.text", value: SecurityRoute.recoverySheet)111 }112 }113114 private var backup: some View {115 QListSection("Encrypted backup", footnote: "Restoring a backup is offered on a device without wallet, before a wallet is created.") {116 SecLinkRow(title: "Create encrypted backup", subtitle: "A file protected by its own password", systemImage: "externaldrive.badge.plus", value: SecurityRoute.backupCreate)117 SecLinkRow(title: "Inspect a backup file", subtitle: "Date, records and signer, without the password", systemImage: "doc.viewfinder", value: SecurityRoute.backupInspect)118 }119 }120121 private var transfer: some View {122 QListSection("Device-to-device transfer", footnote: "The new iPhone starts the transfer before any wallet is created on it, and shows a code to scan here.") {123 SecLinkRow(title: "Transfer to a new iPhone", subtitle: "Encrypted for the new device, by QR codes", systemImage: "iphone.and.arrow.forward",124 value: SecurityRoute.transferSend(receiver: nil))125 }126 }127}128