diff --git a/api/rates.php b/api/rates.php
new file mode 100644
index 0000000..b2e73a4
--- /dev/null
+++ b/api/rates.php
@@ -0,0 +1,22 @@
+ true,
+ CURLOPT_TIMEOUT => 10,
+ CURLOPT_HTTPHEADER => ['Accept: application/json'],
+]);
+$response = curl_exec($ch);
+$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+curl_close($ch);
+
+if ($response !== false && $httpCode === 200) {
+ echo $response;
+} else {
+ http_response_code(502);
+ echo json_encode(['error' => 'Failed to fetch rates']);
+}
diff --git a/app.js b/app.js
index 4f57f62..40b7ec5 100644
--- a/app.js
+++ b/app.js
@@ -2,7 +2,7 @@
'use strict';
// --- Config ---
- const COINGECKO_API = 'https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=eur,usd,chf';
+ const COINGECKO_API = '/api/rates.php';
// Standard address (4..., 95 chars), Subaddress (8..., 95 chars), Integrated address (4..., 106 chars)
const XMR_STANDARD_REGEX = /^[48][1-9A-HJ-NP-Za-km-z]{94}$/;
const XMR_INTEGRATED_REGEX = /^4[1-9A-HJ-NP-Za-km-z]{105}$/;
diff --git a/app.min.js b/app.min.js
index 59be42a..34c3452 100644
--- a/app.min.js
+++ b/app.min.js
@@ -1 +1 @@
-(function(){"use strict";const St="https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=eur,usd,chf",It=/^[48][1-9A-HJ-NP-Za-km-z]{94}$/,_t=/^4[1-9A-HJ-NP-Za-km-z]{105}$/;let y=null,lt=0,I=null,z=!1,_=null;const i=e=>document.querySelector(e),u=i("#addr"),C=i("#amount"),L=i("#currency"),q=i("#desc"),T=i("#timerCustom"),D=i("#deadlineBadges");let f=0;const tt=i("#generate"),B=i("#result"),v=i("#qr"),et=i("#uri"),dt=i("#openWallet"),Tt=i("#copyAddr"),w=i("#countdown"),h=i("#fiatHint"),nt=i("#toast"),H=i("#shareLink"),Ft=i("#copyShareLink"),Et=i("#newRequest"),Rt=i("#homeLink"),bt=i("#proofToggle"),M=i("#proofPanel"),F=i("#txHash"),U=i("#txKey"),E=i("#verifyProof"),p=i("#proofResult"),R=i("#paymentStatus"),ut=i("#paymentSummary"),Pt=i("#downloadPdf");let ft=!1,kt=!1,at=null;xt(),Mt()||Bt(),Ut(),I18n.onChange(function(){var e=v.querySelector(".qr-hint");e&&(e.textContent=I18n.t("qr_hint"));var t=v.querySelector(".paid-stamp");if(t&&(t.textContent=I18n.t("status_paid")),at&&it(at),B.classList.contains("visible")){var n=rt(),a=q.value.trim();mt(n,a,f),ht(n,a)}}),u.addEventListener("input",ot),C.addEventListener("input",O),L.addEventListener("change",O),tt.addEventListener("click",pt),Tt.addEventListener("click",()=>gt(u.value.trim())),Ft.addEventListener("click",()=>gt(H.value)),v.addEventListener("click",At),Et.addEventListener("click",vt),Rt.addEventListener("click",function(e){e.preventDefault(),vt()}),D.querySelectorAll(".badge").forEach(function(e){e.addEventListener("click",function(){const t=parseInt(e.getAttribute("data-days"));e.classList.contains("active")?(e.classList.remove("active"),f=0,T.value=""):(D.querySelectorAll(".badge").forEach(function(n){n.classList.remove("active")}),e.classList.add("active"),f=t,T.value="")})}),T.addEventListener("input",function(){D.querySelectorAll(".badge").forEach(function(e){e.classList.remove("active")}),f=parseInt(T.value)||0}),Pt.addEventListener("click",Wt),bt.addEventListener("click",Gt),F.addEventListener("input",Ct),U.addEventListener("input",Ct),E.addEventListener("click",Yt);function vt(){u.value="",C.value="",L.value="EUR",q.value="",f=0,T.value="",D.querySelectorAll(".badge").forEach(function(e){e.classList.remove("active")}),h.textContent="",h.classList.remove("error"),u.classList.remove("valid","invalid"),tt.disabled=!0,B.classList.remove("visible"),I&&clearInterval(I),v.innerHTML="",et.textContent="",H.value="",_=null,M.classList.remove("open"),F.value="",U.value="",E.disabled=!0,p.innerHTML="",p.className="proof-result",R.innerHTML="",R.className="payment-status",ut.innerHTML="",document.title="xmrpay.link \u2014 Monero Invoice Generator",history.replaceState(null,"",location.pathname),window.scrollTo({top:0,behavior:"smooth"}),u.focus()}function N(e){return It.test(e)||_t.test(e)}function ot(){const e=u.value.trim();u.classList.remove("valid","invalid"),e.length!==0&&(N(e)?u.classList.add("valid"):e.length>=10&&u.classList.add("invalid"),Xt())}function Xt(){const e=u.value.trim();tt.disabled=!N(e)}function O(){const e=parseFloat(C.value),t=L.value;if(!e||e<=0){h.textContent="",h.classList.remove("error");return}if(t!=="XMR"&&!y){h.textContent=z?I18n.t("rates_offline"):"",h.classList.toggle("error",z);return}if(h.classList.remove("error"),t==="XMR")if(y){const n=(e*y.eur).toFixed(2);h.textContent="\u2248 "+n+" EUR"}else h.textContent="";else{const n=y[t.toLowerCase()];if(n&&n>0){const a=(e/n).toFixed(8);h.textContent="\u2248 "+a+" XMR"}}}function rt(){const e=parseFloat(C.value),t=L.value;if(!e||e<=0)return null;if(t==="XMR")return e;if(y){const n=y[t.toLowerCase()];if(n&&n>0)return e/n}return null}function qt(e,t,n){let a="monero:"+e;const o=[];return t&&o.push("tx_amount="+t.toFixed(12)),n&&o.push("tx_description="+encodeURIComponent(n)),o.length&&(a+="?"+o.join("&")),a}function Dt(e,t,n,a){const o=new URLSearchParams;return o.set("a",e),t&&o.set("x",t.toFixed(12)),n&&o.set("d",n),a&&o.set("t",a),o.toString()}async function Ht(e){try{const t=await fetch("/api/shorten.php",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({hash:e})});if(!t.ok)throw new Error("HTTP "+t.status);const n=await t.json();return _||(_=n.code),location.origin+"/s/"+n.code}catch(t){return console.warn("Short URL failed:",t),null}}function pt(){const e=u.value.trim();if(!N(e))return;const t=rt(),n=q.value.trim(),a=f,o=qt(e,t,n);B.classList.add("visible"),et.textContent=o,dt.onclick=function(){window.location.href=o},mt(t,n,a),ht(t,n);const c=Dt(e,t,n,a);H.value=location.origin+"/#"+c,Ht(c).then(function(l){l&&(H.value=l)}),v.innerHTML="",new QRCode(v,{text:o,width:256,height:256,colorDark:"#000000",colorLight:"#ffffff",correctLevel:QRCode.CorrectLevel.M});const d=document.createElement("div");d.className="qr-hint",d.textContent=I18n.t("qr_hint"),v.appendChild(d),Nt(),zt(e),B.scrollIntoView({behavior:"smooth",block:"start"})}function Mt(){const e=location.hash.substring(1);if(!e)return!1;const t=new URLSearchParams(e),n=t.get("a");if(!n||!N(n))return!1;u.value=n,ot();const a=t.get("x");a&&(C.value=parseFloat(a),L.value="XMR");const o=t.get("d");o&&(q.value=o);const c=t.get("t");if(c&&parseInt(c)>0){f=parseInt(c);const l=D.querySelector('.badge[data-days="'+f+'"]');l?l.classList.add("active"):T.value=f}const d=t.get("c");return d&&(_=d,setTimeout(function(){Jt(d)},200)),setTimeout(pt,100),!0}function mt(e,t,n){var a="";if(e){a+='
'+t.replace(/"),ut.innerHTML=a}function ht(e,t){var n=[];e&&n.push(e.toFixed(4)+" XMR"),t&&n.push(t),n.length&&(document.title=n.join(" \u2014 ")+" | xmrpay.link")}function Nt(){if(I&&clearInterval(I),w.textContent="",w.className="countdown",!f||f<=0)return;const e=Date.now()+f*864e5;w.classList.add("active");function t(){const n=e-Date.now();if(n<=0){clearInterval(I),w.textContent=I18n.t("countdown_expired"),w.className="countdown expired";return}const a=Math.floor(n/864e5),o=Math.floor(n%864e5/36e5),c=Math.floor(n%36e5/6e4);a>0?w.textContent=I18n.t("countdown_remaining_days").replace("{d}",a).replace("{h}",o):w.textContent=I18n.t("countdown_remaining_hours").replace("{h}",yt(o)).replace("{m}",yt(c))}t(),I=setInterval(t,6e4)}function yt(e){return e<10?"0"+e:""+e}function At(){const e=v.querySelector("canvas");if(!e)return;const t=document.createElement("a");t.download="xmrpay-qr.png",t.href=e.toDataURL("image/png"),t.click()}function gt(e){navigator.clipboard.writeText(e).then(()=>{jt(I18n.t("toast_copied"))})}function jt(e){nt.textContent=e,nt.classList.add("show"),setTimeout(()=>nt.classList.remove("show"),2e3)}function zt(e){try{localStorage.setItem("xmrpay_addr",e)}catch{}}function Bt(){try{const e=localStorage.getItem("xmrpay_addr");e&&(u.value=e,ot())}catch{}}async function xt(){if(!(y&&Date.now()-lt<6e4))try{const e=await fetch(St);if(!e.ok)throw new Error("HTTP "+e.status);y=(await e.json()).monero,lt=Date.now(),z=!1,O()}catch(e){console.warn("Kurse konnten nicht geladen werden:",e),z=!0,O(),setTimeout(xt,1e4)}}function Ut(){"serviceWorker"in navigator&&navigator.serviceWorker.register("sw.js").catch(function(){})}function Ot(){return new Promise(function(e,t){if(window.jspdf){e();return}var n=document.createElement("script");n.src="lib/jspdf.min.js",n.onload=function(){kt=!0,e()},n.onerror=function(){t(new Error("Failed to load jsPDF"))},document.head.appendChild(n)})}async function Wt(){await Ot();var e=window.jspdf.jsPDF,t=new e({orientation:"portrait",unit:"mm",format:"a4"}),n=u.value.trim(),a=rt(),o=q.value.trim(),c=parseFloat(C.value),d=L.value,l=t.internal.pageSize.getWidth(),s=20,g=l-s*2,r=s;t.setFillColor(242,104,33),t.rect(0,0,l,8,"F"),r=22,t.setFont("helvetica","bold"),t.setFontSize(22),t.setTextColor(242,104,33),t.text(I18n.t("pdf_title"),s,r),t.setFont("helvetica","normal"),t.setFontSize(10),t.setTextColor(120,120,120);var st=new Date().toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"});t.text(I18n.t("pdf_date")+": "+st,l-s,r,{align:"right"}),r+=6,t.setDrawColor(220,220,220),t.setLineWidth(.3),t.line(s,r,l-s,r);var G=v.querySelector("canvas"),x=50,b=l-s-x,A=r+6;if(G){var K=G.toDataURL("image/png");t.addImage(K,"PNG",b,A,x,x),t.setFontSize(7),t.setTextColor(150,150,150),t.text(I18n.t("pdf_scan_qr"),b+x/2,A+x+4,{align:"center"})}var P=s,Y=b-s-10;r+=14;function k(j,Lt){t.setFont("helvetica","normal"),t.setFontSize(9),t.setTextColor(150,150,150),t.text(j,P,r),r+=5,t.setFont("helvetica","bold"),t.setFontSize(11),t.setTextColor(40,40,40);var wt=t.splitTextToSize(Lt,Y);t.text(wt,P,r),r+=wt.length*5+4}if(a){var m=a.toFixed(8)+" XMR";d!=="XMR"&&c&&(m+=" (\u2248 "+c.toFixed(2)+" "+d+")"),k(I18n.t("pdf_amount"),m)}if(o&&k(I18n.t("pdf_desc"),o),f>0){var S=new Date(Date.now()+f*864e5),J=S.toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"});k(I18n.t("pdf_deadline"),J+" ("+I18n.t("pdf_deadline_days").replace("{d}",f)+")")}r=Math.max(r,A+x+12),t.setFont("helvetica","normal"),t.setFontSize(9),t.setTextColor(150,150,150),t.text(I18n.t("pdf_address"),s,r),r+=5,t.setFillColor(245,245,245),t.roundedRect(s,r-3.5,g,10,2,2,"F"),t.setFont("courier","normal"),t.setFontSize(8),t.setTextColor(60,60,60),t.text(n,s+3,r+2.5),r+=14;var V=et.textContent;if(V){t.setFillColor(245,245,245),t.roundedRect(s,r-3.5,g,10,2,2,"F"),t.setFont("courier","normal"),t.setFontSize(6.5),t.setTextColor(100,100,100);var $=t.splitTextToSize(V,g-6);t.text($,s+3,r+2),r+=$.length*3+10}if(R.classList.contains("paid")){r+=4,t.setFillColor(76,175,80),t.roundedRect(s,r-4,g,16,2,2,"F"),t.setFont("helvetica","bold"),t.setFontSize(12),t.setTextColor(255,255,255),t.text(I18n.t("status_paid").toUpperCase(),s+g/2,r+2,{align:"center"});var Q=R.querySelector(".paid-detail");Q&&(t.setFont("helvetica","normal"),t.setFontSize(8),t.text(Q.textContent,s+g/2,r+8,{align:"center"})),r+=22}t.setDrawColor(220,220,220),t.setLineWidth(.3);var X=t.internal.pageSize.getHeight()-15;t.line(s,X,l-s,X),t.setFont("helvetica","normal"),t.setFontSize(7),t.setTextColor(180,180,180),t.text(I18n.t("pdf_footer"),l/2,X+5,{align:"center"});var Z=H.value;Z&&t.text(Z,l/2,X+9,{align:"center"});var ct="xmrpay-"+(o?o.replace(/[^a-zA-Z0-9]/g,"-").substring(0,30):"invoice")+".pdf";t.save(ct)}function Gt(){if(M.classList.contains("open")){M.classList.remove("open");return}if(!ft&&!window.XmrCrypto){Kt().then(function(){ft=!0,M.classList.add("open"),F.focus()});return}M.classList.add("open"),F.focus()}function Kt(){return new Promise(function(e,t){if(window.XmrCrypto){e();return}const n=document.createElement("script");n.src="lib/xmr-crypto.bundle.js",n.onload=e,n.onerror=function(){t(new Error("Failed to load crypto module"))},document.head.appendChild(n)})}function W(e){return/^[0-9a-fA-F]{64}$/.test(e)}function Ct(){const e=F.value.trim(),t=U.value.trim();E.disabled=!(W(e)&&W(t))}async function Yt(){const e=F.value.trim(),t=U.value.trim(),n=u.value.trim();if(!(!W(e)||!W(t)||!N(n))){E.disabled=!0,p.className="proof-result active",p.textContent=I18n.t("proof_verifying");try{var a=await fetch("/api/node.php",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:"gettransactions",params:{txs_hashes:[e],decode_as_json:!0}})}),o=await a.json(),c=o.txs||[];if(c.length===0){p.className="proof-result active error",p.textContent=I18n.t("proof_tx_not_found"),E.disabled=!1;return}for(var d=c[0],l=JSON.parse(d.as_json),s=XmrCrypto.getKeysFromAddress(n),g=s.publicViewKey,r=s.publicSpendKey,st=XmrCrypto.bytesToScalar(XmrCrypto.hexToBytes(t)),G=XmrCrypto.Point.fromHex(g),x=G.multiply(st).multiply(8n),b=x.toBytes(),A=XmrCrypto.Point.fromHex(r),K=l.vout||[],P=l.rct_signatures&&l.rct_signatures.ecdhInfo||[],Y=0n,k=!1,m=0;m
document.querySelector(e),u=i("#addr"),C=i("#amount"),L=i("#currency"),q=i("#desc"),T=i("#timerCustom"),D=i("#deadlineBadges");let f=0;const tt=i("#generate"),B=i("#result"),v=i("#qr"),et=i("#uri"),dt=i("#openWallet"),Tt=i("#copyAddr"),w=i("#countdown"),h=i("#fiatHint"),nt=i("#toast"),H=i("#shareLink"),Ft=i("#copyShareLink"),Et=i("#newRequest"),Rt=i("#homeLink"),bt=i("#proofToggle"),M=i("#proofPanel"),F=i("#txHash"),U=i("#txKey"),E=i("#verifyProof"),p=i("#proofResult"),R=i("#paymentStatus"),ut=i("#paymentSummary"),Pt=i("#downloadPdf");let ft=!1,kt=!1,at=null;xt(),Mt()||Bt(),Ut(),I18n.onChange(function(){var e=v.querySelector(".qr-hint");e&&(e.textContent=I18n.t("qr_hint"));var t=v.querySelector(".paid-stamp");if(t&&(t.textContent=I18n.t("status_paid")),at&&it(at),B.classList.contains("visible")){var n=rt(),a=q.value.trim();mt(n,a,f),ht(n,a)}}),u.addEventListener("input",ot),C.addEventListener("input",O),L.addEventListener("change",O),tt.addEventListener("click",pt),Tt.addEventListener("click",()=>gt(u.value.trim())),Ft.addEventListener("click",()=>gt(H.value)),v.addEventListener("click",At),Et.addEventListener("click",vt),Rt.addEventListener("click",function(e){e.preventDefault(),vt()}),D.querySelectorAll(".badge").forEach(function(e){e.addEventListener("click",function(){const t=parseInt(e.getAttribute("data-days"));e.classList.contains("active")?(e.classList.remove("active"),f=0,T.value=""):(D.querySelectorAll(".badge").forEach(function(n){n.classList.remove("active")}),e.classList.add("active"),f=t,T.value="")})}),T.addEventListener("input",function(){D.querySelectorAll(".badge").forEach(function(e){e.classList.remove("active")}),f=parseInt(T.value)||0}),Pt.addEventListener("click",Wt),bt.addEventListener("click",Gt),F.addEventListener("input",Ct),U.addEventListener("input",Ct),E.addEventListener("click",Yt);function vt(){u.value="",C.value="",L.value="EUR",q.value="",f=0,T.value="",D.querySelectorAll(".badge").forEach(function(e){e.classList.remove("active")}),h.textContent="",h.classList.remove("error"),u.classList.remove("valid","invalid"),tt.disabled=!0,B.classList.remove("visible"),I&&clearInterval(I),v.innerHTML="",et.textContent="",H.value="",_=null,M.classList.remove("open"),F.value="",U.value="",E.disabled=!0,p.innerHTML="",p.className="proof-result",R.innerHTML="",R.className="payment-status",ut.innerHTML="",document.title="xmrpay.link \u2014 Monero Invoice Generator",history.replaceState(null,"",location.pathname),window.scrollTo({top:0,behavior:"smooth"}),u.focus()}function N(e){return It.test(e)||_t.test(e)}function ot(){const e=u.value.trim();u.classList.remove("valid","invalid"),e.length!==0&&(N(e)?u.classList.add("valid"):e.length>=10&&u.classList.add("invalid"),Xt())}function Xt(){const e=u.value.trim();tt.disabled=!N(e)}function O(){const e=parseFloat(C.value),t=L.value;if(!e||e<=0){h.textContent="",h.classList.remove("error");return}if(t!=="XMR"&&!y){h.textContent=z?I18n.t("rates_offline"):"",h.classList.toggle("error",z);return}if(h.classList.remove("error"),t==="XMR")if(y){const n=(e*y.eur).toFixed(2);h.textContent="\u2248 "+n+" EUR"}else h.textContent="";else{const n=y[t.toLowerCase()];if(n&&n>0){const a=(e/n).toFixed(8);h.textContent="\u2248 "+a+" XMR"}}}function rt(){const e=parseFloat(C.value),t=L.value;if(!e||e<=0)return null;if(t==="XMR")return e;if(y){const n=y[t.toLowerCase()];if(n&&n>0)return e/n}return null}function qt(e,t,n){let a="monero:"+e;const o=[];return t&&o.push("tx_amount="+t.toFixed(12)),n&&o.push("tx_description="+encodeURIComponent(n)),o.length&&(a+="?"+o.join("&")),a}function Dt(e,t,n,a){const o=new URLSearchParams;return o.set("a",e),t&&o.set("x",t.toFixed(12)),n&&o.set("d",n),a&&o.set("t",a),o.toString()}async function Ht(e){try{const t=await fetch("/api/shorten.php",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({hash:e})});if(!t.ok)throw new Error("HTTP "+t.status);const n=await t.json();return _||(_=n.code),location.origin+"/s/"+n.code}catch(t){return console.warn("Short URL failed:",t),null}}function pt(){const e=u.value.trim();if(!N(e))return;const t=rt(),n=q.value.trim(),a=f,o=qt(e,t,n);B.classList.add("visible"),et.textContent=o,dt.onclick=function(){window.location.href=o},mt(t,n,a),ht(t,n);const c=Dt(e,t,n,a);H.value=location.origin+"/#"+c,Ht(c).then(function(l){l&&(H.value=l)}),v.innerHTML="",new QRCode(v,{text:o,width:256,height:256,colorDark:"#000000",colorLight:"#ffffff",correctLevel:QRCode.CorrectLevel.M});const d=document.createElement("div");d.className="qr-hint",d.textContent=I18n.t("qr_hint"),v.appendChild(d),Nt(),zt(e),B.scrollIntoView({behavior:"smooth",block:"start"})}function Mt(){const e=location.hash.substring(1);if(!e)return!1;const t=new URLSearchParams(e),n=t.get("a");if(!n||!N(n))return!1;u.value=n,ot();const a=t.get("x");a&&(C.value=parseFloat(a),L.value="XMR");const o=t.get("d");o&&(q.value=o);const c=t.get("t");if(c&&parseInt(c)>0){f=parseInt(c);const l=D.querySelector('.badge[data-days="'+f+'"]');l?l.classList.add("active"):T.value=f}const d=t.get("c");return d&&(_=d,setTimeout(function(){Jt(d)},200)),setTimeout(pt,100),!0}function mt(e,t,n){var a="";if(e){a+=''+e.toFixed(8)+" XMR
";var o=parseFloat(C.value),c=L.value;c!=="XMR"&&o&&(a+='\u2248 '+o.toFixed(2)+" "+c+"
")}t&&(a+=''+t.replace(/"),ut.innerHTML=a}function ht(e,t){var n=[];e&&n.push(e.toFixed(4)+" XMR"),t&&n.push(t),n.length&&(document.title=n.join(" \u2014 ")+" | xmrpay.link")}function Nt(){if(I&&clearInterval(I),w.textContent="",w.className="countdown",!f||f<=0)return;const e=Date.now()+f*864e5;w.classList.add("active");function t(){const n=e-Date.now();if(n<=0){clearInterval(I),w.textContent=I18n.t("countdown_expired"),w.className="countdown expired";return}const a=Math.floor(n/864e5),o=Math.floor(n%864e5/36e5),c=Math.floor(n%36e5/6e4);a>0?w.textContent=I18n.t("countdown_remaining_days").replace("{d}",a).replace("{h}",o):w.textContent=I18n.t("countdown_remaining_hours").replace("{h}",yt(o)).replace("{m}",yt(c))}t(),I=setInterval(t,6e4)}function yt(e){return e<10?"0"+e:""+e}function At(){const e=v.querySelector("canvas");if(!e)return;const t=document.createElement("a");t.download="xmrpay-qr.png",t.href=e.toDataURL("image/png"),t.click()}function gt(e){navigator.clipboard.writeText(e).then(()=>{jt(I18n.t("toast_copied"))})}function jt(e){nt.textContent=e,nt.classList.add("show"),setTimeout(()=>nt.classList.remove("show"),2e3)}function zt(e){try{localStorage.setItem("xmrpay_addr",e)}catch{}}function Bt(){try{const e=localStorage.getItem("xmrpay_addr");e&&(u.value=e,ot())}catch{}}async function xt(){if(!(y&&Date.now()-lt<6e4))try{const e=await fetch(St);if(!e.ok)throw new Error("HTTP "+e.status);y=(await e.json()).monero,lt=Date.now(),z=!1,O()}catch(e){console.warn("Kurse konnten nicht geladen werden:",e),z=!0,O(),setTimeout(xt,1e4)}}function Ut(){"serviceWorker"in navigator&&navigator.serviceWorker.register("sw.js").catch(function(){})}function Ot(){return new Promise(function(e,t){if(window.jspdf){e();return}var n=document.createElement("script");n.src="lib/jspdf.min.js",n.onload=function(){kt=!0,e()},n.onerror=function(){t(new Error("Failed to load jsPDF"))},document.head.appendChild(n)})}async function Wt(){await Ot();var e=window.jspdf.jsPDF,t=new e({orientation:"portrait",unit:"mm",format:"a4"}),n=u.value.trim(),a=rt(),o=q.value.trim(),c=parseFloat(C.value),d=L.value,l=t.internal.pageSize.getWidth(),s=20,g=l-s*2,r=s;t.setFillColor(242,104,33),t.rect(0,0,l,8,"F"),r=22,t.setFont("helvetica","bold"),t.setFontSize(22),t.setTextColor(242,104,33),t.text(I18n.t("pdf_title"),s,r),t.setFont("helvetica","normal"),t.setFontSize(10),t.setTextColor(120,120,120);var st=new Date().toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"});t.text(I18n.t("pdf_date")+": "+st,l-s,r,{align:"right"}),r+=6,t.setDrawColor(220,220,220),t.setLineWidth(.3),t.line(s,r,l-s,r);var G=v.querySelector("canvas"),x=50,b=l-s-x,A=r+6;if(G){var K=G.toDataURL("image/png");t.addImage(K,"PNG",b,A,x,x),t.setFontSize(7),t.setTextColor(150,150,150),t.text(I18n.t("pdf_scan_qr"),b+x/2,A+x+4,{align:"center"})}var P=s,Y=b-s-10;r+=14;function k(j,Lt){t.setFont("helvetica","normal"),t.setFontSize(9),t.setTextColor(150,150,150),t.text(j,P,r),r+=5,t.setFont("helvetica","bold"),t.setFontSize(11),t.setTextColor(40,40,40);var wt=t.splitTextToSize(Lt,Y);t.text(wt,P,r),r+=wt.length*5+4}if(a){var m=a.toFixed(8)+" XMR";d!=="XMR"&&c&&(m+=" (\u2248 "+c.toFixed(2)+" "+d+")"),k(I18n.t("pdf_amount"),m)}if(o&&k(I18n.t("pdf_desc"),o),f>0){var S=new Date(Date.now()+f*864e5),J=S.toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"});k(I18n.t("pdf_deadline"),J+" ("+I18n.t("pdf_deadline_days").replace("{d}",f)+")")}r=Math.max(r,A+x+12),t.setFont("helvetica","normal"),t.setFontSize(9),t.setTextColor(150,150,150),t.text(I18n.t("pdf_address"),s,r),r+=5,t.setFillColor(245,245,245),t.roundedRect(s,r-3.5,g,10,2,2,"F"),t.setFont("courier","normal"),t.setFontSize(8),t.setTextColor(60,60,60),t.text(n,s+3,r+2.5),r+=14;var V=et.textContent;if(V){t.setFillColor(245,245,245),t.roundedRect(s,r-3.5,g,10,2,2,"F"),t.setFont("courier","normal"),t.setFontSize(6.5),t.setTextColor(100,100,100);var $=t.splitTextToSize(V,g-6);t.text($,s+3,r+2),r+=$.length*3+10}if(R.classList.contains("paid")){r+=4,t.setFillColor(76,175,80),t.roundedRect(s,r-4,g,16,2,2,"F"),t.setFont("helvetica","bold"),t.setFontSize(12),t.setTextColor(255,255,255),t.text(I18n.t("status_paid").toUpperCase(),s+g/2,r+2,{align:"center"});var Q=R.querySelector(".paid-detail");Q&&(t.setFont("helvetica","normal"),t.setFontSize(8),t.text(Q.textContent,s+g/2,r+8,{align:"center"})),r+=22}t.setDrawColor(220,220,220),t.setLineWidth(.3);var X=t.internal.pageSize.getHeight()-15;t.line(s,X,l-s,X),t.setFont("helvetica","normal"),t.setFontSize(7),t.setTextColor(180,180,180),t.text(I18n.t("pdf_footer"),l/2,X+5,{align:"center"});var Z=H.value;Z&&t.text(Z,l/2,X+9,{align:"center"});var ct="xmrpay-"+(o?o.replace(/[^a-zA-Z0-9]/g,"-").substring(0,30):"invoice")+".pdf";t.save(ct)}function Gt(){if(M.classList.contains("open")){M.classList.remove("open");return}if(!ft&&!window.XmrCrypto){Kt().then(function(){ft=!0,M.classList.add("open"),F.focus()});return}M.classList.add("open"),F.focus()}function Kt(){return new Promise(function(e,t){if(window.XmrCrypto){e();return}const n=document.createElement("script");n.src="lib/xmr-crypto.bundle.js",n.onload=e,n.onerror=function(){t(new Error("Failed to load crypto module"))},document.head.appendChild(n)})}function W(e){return/^[0-9a-fA-F]{64}$/.test(e)}function Ct(){const e=F.value.trim(),t=U.value.trim();E.disabled=!(W(e)&&W(t))}async function Yt(){const e=F.value.trim(),t=U.value.trim(),n=u.value.trim();if(!(!W(e)||!W(t)||!N(n))){E.disabled=!0,p.className="proof-result active",p.textContent=I18n.t("proof_verifying");try{var a=await fetch("/api/node.php",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:"gettransactions",params:{txs_hashes:[e],decode_as_json:!0}})}),o=await a.json(),c=o.txs||[];if(c.length===0){p.className="proof-result active error",p.textContent=I18n.t("proof_tx_not_found"),E.disabled=!1;return}for(var d=c[0],l=JSON.parse(d.as_json),s=XmrCrypto.getKeysFromAddress(n),g=s.publicViewKey,r=s.publicSpendKey,st=XmrCrypto.bytesToScalar(XmrCrypto.hexToBytes(t)),G=XmrCrypto.Point.fromHex(g),x=G.multiply(st).multiply(8n),b=x.toBytes(),A=XmrCrypto.Point.fromHex(r),K=l.vout||[],P=l.rct_signatures&&l.rct_signatures.ecdhInfo||[],Y=0n,k=!1,m=0;m