1// Import delle dipendenze necessarie 2import { EthereumClient, w3mConnectors, w3mProvider, WagmiCore, WagmiCoreChains } from "https://unpkg.com/@web3modal/[email protected]"; 3import { Web3Modal } from "https://unpkg.com/@web3modal/[email protected]"; 4 5// Configurazione delle chain supportate 6const { mainnet, polygon, avalanche, arbitrum } = WagmiCoreChains; 7const { configureChains, createConfig, watchAccount, signMessage, disconnect } = WagmiCore; 8 9// Project ID per l'applicazione 10const projectId = IDDigitaleProjectID; 11 12// Definizione delle chain e del provider pubblico 13const chains = [mainnet, polygon, avalanche, arbitrum]; 14const { publicClient } = configureChains(chains, [w3mProvider({ projectId })]); 15 16let nonce; 17 18// Configurazione di Wagmi 19const wagmiConfig = createConfig({ 20 autoConnect: true, 21 connectors: [ 22 ...w3mConnectors({ appName: "web3Modal", chains, version: 2, projectId }) 23 ], 24 publicClient 25}); 26 27// Creazione dell'istanza di EthereumClient 28const ethereumClient = new EthereumClient(wagmiConfig, chains); 29 30// Funzione Vue per Web3Modal 31var optionApp = { 32 data() { 33 return { 34 web3Modal: null, 35 }; 36 }, 37 mounted: function () { 38 // Inizializzazione di Web3Modal 39 this.web3Modal = new Web3Modal( 40 { 41 projectId 42 }, 43 ethereumClient 44 ); 45 }, 46 methods: { 47 // Apertura del modal per la connessione con ID digitale 48 async entraConID() { 49 this.web3Modal.openModal(); 50 51 // Watch per l'account selezionato 52 const unwatch = await watchAccount((account) => this.checkAccount(account)); 53 }, 54 55 // Verifica dell'account selezionato e firma del messaggio 56 async checkAccount(account) { 57 try { 58 if (account.address) { 59 var selectedAccount = account.address; 60 await this.verificaAddress(selectedAccount); 61 const signature = await signMessage({ 62 message: nonce 63 }); 64 var obj = { publicAddress: selectedAccount, signature: signature }; 65 this.LoginIDDigitale(obj); 66 await disconnect(); 67 } 68 } catch (err) { 69 console.error(err); 70 await disconnect(); 71 } 72 }, 73 74 // Verifica dell'indirizzo selezionato per ottenere il nonce 75 async verificaAddress(address) { 76 try { 77 var configVerificaAddress = { 78 headers: { 79 Authorization: IDDigitaleToken, 80 ContentType: 'application/json; charset=utf-8', 81 dataType: 'json' 82 } 83 }; 84 await axios.get(BaseUrlWebAPIIDDigitale + "/soggetto/SetNonce/" + address, configVerificaAddress) 85 .then(response => { 86 nonce = response.data; 87 console.log(nonce); 88 }) 89 .catch(e => { 90 console.error("Errore: Impossibile recuperare il valore del Nonce.", e.message); 91 Swal.fire({ 92 title: "Attenzione!", 93 text: "Login Fallita", 94 icon: "error", 95 }); 96 }); 97 } catch (error) { 98 console.error("Errore durante la verifica dell'indirizzo", error); 99 Swal.fire({ 100 title: "Attenzione!", 101 text: "Login Fallita", 102 icon: "error", 103 }); 104 } 105 }, 106 107 // Login con ID digitale utilizzando il signature 108 LoginIDDigitale(signature) { 109 try { 110 var configLoginIDDigitale = { 111 headers: { 112 Authorization: IDDigitaleToken, 113 ContentType: 'application/json; charset=utf-8' 114 } 115 }; 116 117 axios.post(BaseUrlWebAPIIDDigitale + "/soggetto/login/", signature, configLoginIDDigitale) 118 .then(response => { 119 if (!response.headers.authorization) { 120 throw new Error("Token non presente nella risposta"); 121 } 122 123 var token = response.headers.authorization.replace("Bearer ", ""); 124 125 // Memorizza il token in modo sicuro (opzionale) 126 localStorage.setItem("authToken", token); 127 128 // Esegui il redirect alla route predefinita 129 document.getElementsByName("idToken")[0].value = token; 130 document.getElementsByName("redirectUrl")[0].value = "/"; // window.location.pathname; 131 document.getElementById("formLoginIDDigitale").submit(); 132/* window.location.href = BaseUrlWebAPIIDDigitale;*/ 133 }) 134 .catch(e => { 135 console.error("Errore: Login fallita. Dettagli:", e.response || e.message); 136 Swal.fire({ 137 title: "Attenzione!", 138 text: "Login Fallita", 139 icon: "error", 140 }); 141 }); 142 } catch (error) { 143 console.error("Errore durante il login con ID digitale", error); 144 Swal.fire({ 145 title: "Attenzione!", 146 text: "Login Fallita", 147 icon: "error", 148 }); 149 } 150 } 151 152 } 153}; 154 155const loginWithID = Vue.createApp(optionApp); 156 157loginWithID.mount('#loginWithID');
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.