SPB Git

Repository Public

WatchOnlyExportView.swift 7.1 KB 132 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/Security/WatchOnlyExportView.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/// Shows the watch-only package of this wallet (`exportWatchOnlyPackage`, format version 2) for the online companion46/// device: the Bitcoin descriptors with key origin, the account keys of the other UTXO coins, the EVM, Solana and TRON47/// addresses and the list of enabled chains, as QR frames and as text. Public data only.48struct WatchOnlyExportView: View {49    @Environment(WalletStore.self) private var store50    @State private var export: QRExport?51    @State private var package: WatchOnlyPackage?52    /// The code and the first addresses of the package shown, computed from its own text (QYV-APP-080).53    @State private var preview: WatchOnlyPreview?54    @State private var error: String?5556    var body: some View {57        SecurityScroll {58            WarningBanner(.info, title: "Public data only",59                          message: "The package lets the online device see every address and balance of this wallet and prepare transactions. It holds no private key and cannot sign.")60            if let export {61                QRExportCard(frames: export.frames, text: export.text, label: "Watch-only package")62                    .id("qr")63                if let preview {64                    WatchOnlyFingerprintCard(preview: preview).id("code")65                    WarningBanner(.warning, title: "Compare this code on the other device",66                                  message: "The package is public data and nothing signs it: a package replaced on its way would make the other device show someone else's addresses as yours, and what is received on them would be lost. The other device shows the code of what it scanned and asks for the last group: read it from this screen. If the first four groups differ there, do not import.")67                }68                QListSection("On the online device") {69                    SecFactRow(label: "1", value: "Install QYVORA and set it up as a watch-only wallet.")70                    SecFactRow(label: "2", value: "Scan this code.")71                    SecFactRow(label: "3", value: "Compare the package code and type its last group as shown here.")72                    SecFactRow(label: "4", value: "Compare the first address of each network below with the ones it lists.")73                }74                .id("steps")75                if let preview {76                    WatchOnlyAccountsSection(preview: preview, title: "First address of each account",77                                             footnote: "Derived from the package itself. The other device lists the same addresses before it imports; they are also the first receive addresses of this wallet.")78                        .id("addresses")79                }80                if let package { contents(package).id("contents") }81                Explanation("The Bitcoin part is a standard output descriptor and can be imported in other descriptor wallets. Anyone who obtains the package can follow the wallet's balances on every chain it names: share it only with your own device.")82            } else if let error {83                UnavailableDataView(reason: error, title: "Package unavailable") { Task { await load() } }84            } else {85                QCard {86                    VStack(spacing: QSpace.m) {87                        QSkeletonBlock(width: 220, height: 220)88                        QSkeletonBlock(width: 140, height: 12)89                    }90                    .frame(maxWidth: .infinity)91                }92                .accessibilityElement(children: .ignore)93                .accessibilityLabel("Building the package")94            }95        }96        .navigationTitle("Watch-only package")97        .navigationBarTitleDisplayMode(.inline)98        .task { await load() }99    }100101    /// What the package really holds, read back from its own text.102    private func contents(_ package: WatchOnlyPackage) -> some View {103        let coins = (package.accounts ?? [:]).keys.sorted()104        let chains = (package.enabledChains ?? []).compactMap { ChainRegistry.descriptor(ChainID($0))?.displayName }105        return QListSection("In this package", footnote: "Format version \(package.version). A device running QYVORA 1.0 reads the Bitcoin and Ethereum parts only.") {106            SecFactRow(label: "Bitcoin", value: package.bitcoin.map { "Descriptor, \($0.network.displayName)" + ($0.masterFingerprint == nil ? "" : ", with key origin") } ?? "Not included")107            if !coins.isEmpty {108                SecFactRow(label: "Other UTXO coins", value: "Account keys: " + coins.joined(separator: ", "))109            }110            SecFactRow(label: "EVM account", value: package.ethereumAddress == nil ? "Not included" : "One address for every EVM network")111            SecFactRow(label: "Solana", value: package.solanaAddress == nil ? "Not included" : "Address")112            SecFactRow(label: "TRON", value: package.tronAddress == nil ? "Not included" : "Address")113            if !chains.isEmpty {114                SecFactRow(label: "Enabled chains", value: chains.joined(separator: ", "))115            }116        }117    }118119    private func load() async {120        guard export == nil else { return }121        do {122            let made = try await store.run { try await $0.exportWatchOnlyPackage() }123            package = try? JSONDecoder().decode(WatchOnlyPackage.self, from: Data(made.text.utf8))124            preview = try? WalletService.watchOnlyPreview(package: [made.text])125            export = made126            error = nil127        } catch {128            self.error = SecurityError.text(error)129        }130    }131}132
Files main
Menu

Theme