Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Security/SecurityDebug+Cold.swift8// Module : Security9// 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// =============================================================================4041#if DEBUG42import Foundation43import QyvoraMath44import QyvoraCore45import QyvoraSolana46import QyvoraTron47import QyvoraWallet4849/// DEBUG-only inputs of the unified cold-signing screen (`-QYSecScreen cold-sign`). Not compiled in Release.50///51/// -QYSecPayload <text> the unsigned transaction to review. Besides a literal payload:52/// sample-psbt a PSBT for the test-vector wallet (`SecurityDebug.samplePSBT`)53/// sample-transfer an unsigned Sepolia transfer of 0.001 ETH (`sampleEthereumPayload`)54/// sample-unknown an unsigned Sepolia call that cannot be decoded (blind-signing review)55/// sample-solana an unsigned transfer of 0.01 SOL from this wallet's Solana account on its56/// active Solana network, built with the engine57/// sample-tron an unsigned transfer of 1 TRX from this wallet's TRON account on its58/// active TRON network, built with the engine59/// psbt-file the PSBT written by `-QYSecPrep psbt` (tmp/qy-security-debug-psbt.txt)60/// -QYSecAction sign each advance notification confirms the extra confirmations and opens the authentication61///62/// The Solana sample carries a constant in place of a recent blockhash and the TRON sample refers to a block that does63/// not exist: both can be reviewed and signed, and neither can ever be broadcast.64extension SecurityDebug {65 /// Resolves `-QYSecPayload` for the unified screen. nil when the argument is absent or the sample cannot be built66 /// (no account of that chain, chain not enabled).67 static func coldPayload(snapshot: WalletSnapshot?) -> String? {68 switch payload {69 case nil: return nil70 case "sample-psbt": return samplePSBT()71 case "sample-transfer": return sampleEthereumPayload(unknownCall: false)72 case "sample-unknown": return sampleEthereumPayload(unknownCall: true)73 case "sample-solana": return snapshot.flatMap(sampleSolanaEnvelope)74 case "sample-tron": return snapshot.flatMap(sampleTronEnvelope)75 case "psbt-file":76 return try? String(contentsOf: FileManager.default.temporaryDirectory.appendingPathComponent(psbtName), encoding: .utf8)77 default: return payload78 }79 }8081 /// "qyvtx1|u|<chain id>|<base64>": a system transfer of 10 000 000 lamports paid and signed by the wallet's account.82 static func sampleSolanaEnvelope(_ snapshot: WalletSnapshot) -> String? {83 guard let chain = snapshot.chains.first(where: { $0.chain.family == .solana })?.chain,84 let text = snapshot.profile.solanaAddress, let owner = SolanaPublicKey(base58: text),85 let recipient = SolanaPublicKey(base58: solanaDevnetAddress) else { return nil }86 // a syntactically valid constant, not a blockhash of any cluster87 let blockhash = (1...32).map { UInt8($0) }88 guard let message = try? SolanaMessage(feePayer: owner, instructions: [SolanaSystemProgram.transfer(from: owner, to: recipient, lamports: 10_000_000)],89 recentBlockhash: blockhash),90 let payload = try? SolanaTransaction(message: message).base64() else {91 lastFailure = "sample Solana transaction failed"92 return nil93 }94 return "qyvtx1|u|\(chain.id.rawValue)|\(payload)"95 }9697 /// "qyvtx1|u|<chain id>|<hex>": a transfer of 1 TRX from the wallet's account, valid for thirty minutes from now.98 static func sampleTronEnvelope(_ snapshot: WalletSnapshot) -> String? {99 guard let chain = snapshot.chains.first(where: { $0.chain.family == .tron })?.chain,100 let text = snapshot.profile.tronAddress, let owner = TronAddress(text), let recipient = TronAddress(tronNileAddress) else { return nil }101 let now = UInt64(Date().timeIntervalSince1970 * 1000)102 // block number 1 with an identifier that belongs to no network103 let id: Bytes = [0, 0, 0, 0, 0, 0, 0, 1] + (9...32).map { UInt8($0) }104 guard let reference = TronBlockReference(number: 1, id: id, timestamp: now),105 let transaction = try? TronTransaction.transfer(from: owner, to: recipient, amountSun: 1_000_000, reference: reference, timestamp: now,106 expiration: now + 30 * 60 * 1000) else {107 lastFailure = "sample TRON transaction failed"108 return nil109 }110 return "qyvtx1|u|\(chain.id.rawValue)|\(Hex.encode(transaction.rawData))"111 }112}113#endif114