SPB Git

Repository Public

AlgorithmDetailView.swift 8.7 KB 181 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/AlgorithmDetailView.swift8// Module           : Sources9// 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 QyvoraCrypto43import QyvoraWallet44import QyvoraUI4546/// Everything the catalogue knows about one algorithm.47struct AlgorithmDetailView: View {48    let name: String4950    var algorithm: QyvoraEngine.Algorithm? { QyvoraEngine.algorithms.first { $0.name == name } }5152    /// The chains of the registry whose transactions are signed with this algorithm.53    var chains: [ChainDescriptor] { ChainRegistry.mainChains.filter { $0.signatureScheme == name } }5455    var body: some View {56        Group {57            if let algorithm {58                content(algorithm)59            } else {60                UnavailableDataView(reason: "The engine catalogue has no algorithm named \(name).", title: "Unknown algorithm")61                    .frame(maxWidth: .infinity, maxHeight: .infinity)62            }63        }64        .qScreen()65        .navigationTitle(name)66        .navigationBarTitleDisplayMode(.inline)67    }6869    func content(_ a: QyvoraEngine.Algorithm) -> some View {70        ScrollView {71            VStack(alignment: .leading, spacing: QSpace.xl) {72                VStack(alignment: .leading, spacing: QSpace.s) {73                    Label(a.kind.rawValue, systemImage: a.kind.systemImage)74                        .font(QFont.eyebrow)75                        .textCase(.uppercase)76                        .kerning(1.1)77                        .foregroundStyle(QColor.textSecondary)78                    Text(a.name)79                        .font(Font.system(.title, design: .monospaced).weight(.semibold))80                        .foregroundStyle(QColor.textPrimary)81                        .fixedSize(horizontal: false, vertical: true)82                        .accessibilityAddTraits(.isHeader)83                    Text(a.standard).font(QFont.callout).foregroundStyle(QColor.textSecondary)84                }8586                QListSection("Role in QYVORA", separatorInset: QMetric.padding) {87                    SecTextRow(text: a.isInUse ? a.use : (a.use == "Available" ? "Implemented and tested in the engine. No feature of this version uses it." : a.use),88                               systemImage: a.isInUse ? "checkmark" : "circle.dashed", tone: a.isInUse ? .info : .neutral)89                    if !a.isFromScratch {90                        SecTextRow(text: "System implementation (CryptoKit): not written from scratch in this engine, and not covered by its test vectors or its self-test.",91                                   systemImage: "info.circle")92                    }93                    if !chains.isEmpty {94                        VStack(alignment: .leading, spacing: QSpace.s) {95                            QEyebrow("Chains that validate it")96                            FlowLayout(spacing: 6) {97                                ForEach(chains) { chain in98                                    HStack(spacing: 5) {99                                        ChainGlyph(chain.qNetwork, size: .mini)100                                        Text(chain.displayName).font(QFont.caption).foregroundStyle(QColor.textSecondary)101                                    }102                                }103                            }104                        }105                        .padding(.vertical, QSpace.m)106                        .accessibilityElement(children: .ignore)107                        .accessibilityLabel("Chains that validate it: \(chains.map(\.displayName).joined(separator: ", "))")108                    }109                }110111                if a.publicKeySize != nil || a.privateKeySize != nil || a.outputSize != nil {112                    QListSection("Sizes", separatorInset: QMetric.padding) {113                        if let size = a.publicKeySize { sizeRow("Public key", size) }114                        if let size = a.privateKeySize { sizeRow(a.privateKeyLabel, size) }115                        if let size = a.outputSize { sizeRow(a.outputLabel, size) }116                    }117                }118119                QListSection("Security", separatorInset: QMetric.padding) {120                    if let category = a.category {121                        SecFactRow(label: "NIST security category", value: "\(category) of 5")122                        SecTextRow(text: Self.categoryMeaning(category))123                    }124                    quantumNote(a)125                }126127                WarningBanner(.info, title: "Implementation", message: QyvoraEngine.auditStatus)128            }129            .padding(.horizontal, QMetric.screenPadding)130            .padding(.top, QSpace.m)131            .padding(.bottom, QSpace.xxl)132            .frame(maxWidth: 640, alignment: .leading)133            .frame(maxWidth: .infinity)134        }135        .debugScroll()136    }137138    func sizeRow(_ label: String, _ bytes: Int) -> some View {139        SecFactRow(label: label, value: "\(bytes.formatted(.number.grouping(.automatic))) bytes")140    }141142    @ViewBuilder func quantumNote(_ a: QyvoraEngine.Algorithm) -> some View {143        if a.kind == .curve {144            note("xmark.shield", QColor.negative, "Not quantum-resistant",145                 "Elliptic-curve signatures are broken by Shor's algorithm on a sufficiently large fault-tolerant quantum computer. The networks that validate this curve require it; no wallet can change that.")146        } else if a.isPostQuantumStandard {147            note("checkmark.shield", QColor.positive, "Post-quantum standard",148                 "Standardised by NIST to resist attacks by quantum computers. The claim rests on the hardness assumption of the scheme and on a correct implementation.")149        } else {150            note("shield", QColor.textSecondary, "Symmetric primitive",151                 "No public-key structure for Shor's algorithm to attack. Grover's algorithm gives at most a quadratic speed-up to exhaustive search, which long keys and digests absorb.")152        }153    }154155    func note(_ systemImage: String, _ tint: Color, _ title: String, _ text: String) -> some View {156        HStack(alignment: .firstTextBaseline, spacing: QSpace.m) {157            Image(systemName: systemImage).foregroundStyle(tint).accessibilityHidden(true)158            VStack(alignment: .leading, spacing: 4) {159                Text(title).font(QFont.headline).foregroundStyle(QColor.textPrimary)160                Text(text).font(QFont.callout).foregroundStyle(QColor.textSecondary)161            }162            .fixedSize(horizontal: false, vertical: true)163        }164        .frame(maxWidth: .infinity, alignment: .leading)165        .padding(.vertical, QSpace.m)166        .accessibilityElement(children: .combine)167    }168169    /// NIST post-quantum security categories (call for proposals, section 4.A.5).170    static func categoryMeaning(_ category: Int) -> String {171        switch category {172        case 1: return "At least as hard to break as finding an AES-128 key by exhaustive search."173        case 2: return "At least as hard to break as finding a SHA-256 collision."174        case 3: return "At least as hard to break as finding an AES-192 key by exhaustive search."175        case 4: return "At least as hard to break as finding a SHA-384 collision."176        case 5: return "At least as hard to break as finding an AES-256 key by exhaustive search."177        default: return "Category defined by the standard."178        }179    }180}181
Files main
Menu

Theme