Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Sources/QyvoraWallet/ChainRegistry+Keys.swift8// Module : Qyvora Wallet9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0512// Last Modified : 2026-12-0513//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 Foundation42import QyvoraCore43import QyvoraRecovery44import QyvoraSolana45import QyvoraTron4647// What the interface needs to go from a registry descriptor to the module value behind it and back, without48// comparing display names: the network of each family, the key of the endpoint tables, and the limits of a main49// network as the service words them, before they apply.5051public extension ChainDescriptor {52 /// The UTXO network behind the descriptor; nil for another family.53 var utxoNetwork: BitcoinNetwork? {54 if case .utxo(let network) = kind { return network }55 return nil56 }5758 /// The EVM network behind the descriptor; nil for another family.59 var evmNetwork: EthereumNetwork? {60 if case .evm(let network) = kind { return network }61 return nil62 }6364 /// The Solana cluster behind the descriptor; nil for another family.65 var solanaNetwork: SolanaNetwork? {66 if case .solana(let network) = kind { return network }67 return nil68 }6970 /// The TRON network behind the descriptor; nil for another family.71 var tronNetwork: TronNetwork? {72 if case .tron(let network) = kind { return network }73 return nil74 }7576 /// The key under which the endpoint tables (`Endpoints`, `SolanaEndpoints`, `TronEndpoints`) store this network:77 /// the raw value of the module's own network type ("signet", "baseSepolia", "devnet", "nile").78 var endpointKey: String {79 switch kind {80 case .utxo(let network): return network.rawValue81 case .evm(let network): return network.rawValue82 case .solana(let network): return network.rawValue83 case .tron(let network): return network.rawValue84 }85 }86}8788public extension RecoverySheet.ChainAccount {89 /// The registry descriptor of the account's network; nil for a sheet that carries no identifier (written before90 /// the field existed) or an identifier this version does not know.91 var chainDescriptor: ChainDescriptor? { chainID.flatMap { ChainRegistry.descriptor(ChainID($0)) } }92}9394public extension ChainRegistry {95 /// The descriptor of a UTXO network; nil for a network the wallet service does not drive.96 static func descriptor(of network: BitcoinNetwork) -> ChainDescriptor? {97 utxoNetworks.first { $0.1 == network }.flatMap { descriptor($0.0) }98 }99100 /// The descriptor of an EVM network.101 static func descriptor(of network: EthereumNetwork) -> ChainDescriptor? {102 evmNetworks.first { $0.1 == network }.flatMap { descriptor($0.0) }103 }104105 /// The descriptor of a Solana cluster.106 static func descriptor(of network: SolanaNetwork) -> ChainDescriptor? {107 solanaNetworks.first { $0.1 == network }.flatMap { descriptor($0.0) }108 }109110 /// The descriptor of a TRON network.111 static func descriptor(of network: TronNetwork) -> ChainDescriptor? {112 tronNetworks.first { $0.1 == network }.flatMap { descriptor($0.0) }113 }114115 /// The per-transaction ceilings an unaudited build applies on the main network of a chain, as the sentences116 /// `ChainSnapshot.limits` shows once main networks are on. Available before the opt-in, so that the warning the117 /// user reads first states the same limits, in the same words. A test network gives the limits of its main network.118 static func previewLimits(for chain: ChainDescriptor) -> ChainLimits {119 let main = descriptor(chain.mainCounterpart) ?? chain120 if let limits = WalletService.limitSentences(main.kind) { return limits }121 // no ceiling is defined for this network: say so rather than show nothing (no chain of the registry is in122 // this case; `WalletService.limitSentences` covers every main network)123 return ChainLimits(native: "No per-transaction limit is defined for \(main.displayName) in this build.", tokens: nil,124 fee: "No fee limit is defined for \(main.displayName) in this build.")125 }126}127