From f7e59d708f735c18cd06032d1864cc1875a8c2e6 Mon Sep 17 00:00:00 2001 From: Daniel Regeci <536331+ovx@users.noreply.github.com> Date: Thu, 7 Mar 2024 07:35:53 +0100 Subject: [PATCH] expire - improvements --- dist/altcha.iife.js | 2 +- dist/altcha.js | 939 ++++++++++++++++++++++++-------------------- dist/altcha.umd.cjs | 2 +- src/Altcha.svelte | 56 ++- src/types.ts | 1 + 5 files changed, 554 insertions(+), 446 deletions(-) diff --git a/dist/altcha.iife.js b/dist/altcha.iife.js index 32e53ba..d5d1a60 100644 --- a/dist/altcha.iife.js +++ b/dist/altcha.iife.js @@ -1 +1 @@ -var altcha=function(S){"use strict";var yt=Object.defineProperty;var pt=(S,k,U)=>k in S?yt(S,k,{enumerable:!0,configurable:!0,writable:!0,value:U}):S[k]=U;var R=(S,k,U)=>(pt(S,typeof k!="symbol"?k+"":k,U),U);function k(){}function U(t){return t()}function ie(){return Object.create(null)}function T(t){t.forEach(U)}function oe(t){return typeof t=="function"}function Ie(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Le(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function Re(t,e,n){const i=Ne(t);if(!i.getElementById(e)){const l=$("style");l.id=e,l.textContent=n,je(i,l)}}function Ne(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function je(t,e){return g(t.head||t,e),e.sheet}function N(t,e,n){t.insertBefore(e,n||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function $(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Ae(t){return document.createTextNode(t)}function F(){return Ae(" ")}function Q(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ge(t){return Array.from(t.childNodes)}function le(t,e,n){t.classList.toggle(e,!!n)}function Se(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function Ve(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let D;function X(t){D=t}function q(){if(!D)throw new Error("Function called outside component initialization");return D}function Me(t){q().$$.on_mount.push(t)}function Ue(t){q().$$.on_destroy.push(t)}function Oe(){const t=q();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Se(e,n,{cancelable:i});return l.slice().forEach(s=>{s.call(t,r)}),!r.defaultPrevented}return!0}}const Z=[],ee=[];let B=[];const se=[],ce=Promise.resolve();let te=!1;function ue(){te||(te=!0,ce.then(E))}function Fe(){return ue(),ce}function ne(t){B.push(t)}const re=new Set;let H=0;function E(){if(H!==0)return;const t=D;do{try{for(;Ht.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Be=new Set;function He(t,e){t&&t.i&&(Be.delete(t),t.i(e))}function We(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),ne(()=>{const r=t.$$.on_mount.map(U).filter(oe);t.$$.on_destroy?t.$$.on_destroy.push(...r):T(r),t.$$.on_mount=[]}),l.forEach(ne)}function Pe(t,e){const n=t.$$;n.fragment!==null&&(Ze(n.after_update),T(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Te(t,e){t.$$.dirty[0]===-1&&(Z.push(t),ue(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const G=L.length?L[0]:A;return f.ctx&&l(f.ctx[p],f.ctx[p]=G)&&(!f.skip_bound&&f.bound[p]&&f.bound[p](G),j&&Te(t,p)),A}):[],f.update(),j=!0,T(f.before_update),f.fragment=i?i(f.ctx):!1,e.target){if(e.hydrate){const p=Ge(e.target);f.fragment&&f.fragment.l(p),p.forEach(I)}else f.fragment&&f.fragment.c();e.intro&&He(t.$$.fragment),We(t,e.target,e.anchor),E()}X(h)}let ae;typeof HTMLElement=="function"&&(ae=class extends HTMLElement{constructor(e,n,i){super();R(this,"$$ctor");R(this,"$$s");R(this,"$$c");R(this,"$$cn",!1);R(this,"$$d",{});R(this,"$$r",!1);R(this,"$$p_d",{});R(this,"$$l",{});R(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let s;return{c:function(){s=$("slot"),r!=="default"&&c(s,"name",r)},m:function(f,j){N(f,s,j)},d:function(f){f&&I(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},i=Ve(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const s=this.$$g_p(r.name);s in this.$$d||(this.$$d[s]=z(s,r.value,this.$$p_d,"toProp"))}for(const r in this.$$p_d)!(r in this.$$d)&&this[r]!==void 0&&(this.$$d[r]=this[r],delete this[r]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const s=z(r,this.$$d[r],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const s of this.$$l[r]){const a=this.$$c.$on(r,s);this.$$l_u.set(s,a)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=z(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function z(t,e,n,i){var r;const l=(r=n[t])==null?void 0:r.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Xe(t,e,n,i,l,r){let s=class extends ae{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(s.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(h){var f;h=z(a,h,e),this.$$d[a]=h,(f=this.$$c)==null||f.$set({[a]:h})}})}),i.forEach(a=>{Object.defineProperty(s.prototype,a,{get(){var h;return(h=this.$$c)==null?void 0:h[a]}})}),r&&(s=r(s)),t.element=s,s}class Ke{constructor(){R(this,"$$");R(this,"$$set")}$destroy(){Pe(this,1),this.$destroy=k}$on(e,n){if(!oe(n))return k;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const l=i.indexOf(n);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Le(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ze="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ze);const fe="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",Je=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),he=typeof window<"u"&&window.Blob&&new Blob([Je(fe)],{type:"text/javascript;charset=utf-8"});function Qe(t){let e;try{if(e=he&&(window.URL||window.webkitURL).createObjectURL(he),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+fe,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const qe=1e7,et=new TextEncoder;function tt(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function nt(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await de(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function de(t,e,n){return tt(await crypto.subtle.digest(n.toUpperCase(),et.encode(t+e)))}async function rt(t,e,n="SHA-256",i=qe){const l=Date.now();for(let r=0;r<=i;r++)if(await de(e,r,n)===t)return{number:r,took:Date.now()-l};return null}var v=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(v||{});function it(t){Re(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ge(t){let e,n,i;return{c(){e=V("svg"),n=V("path"),i=V("path"),c(n,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(n,"fill","currentColor"),c(n,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,r){N(l,e,r),g(e,n),g(e,i)},d(l){l&&I(e)}}}function ot(t){let e,n=t[9].label+"",i;return{c(){e=$("label"),c(e,"for",i=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(l,r){N(l,e,r),e.innerHTML=n},p(l,r){r[0]&512&&n!==(n=l[9].label+"")&&(e.innerHTML=n),r[0]&8&&i!==(i=l[3]+"_checkbox")&&c(e,"for",i)},d(l){l&&I(e)}}}function lt(t){let e,n=t[9].verifying+"";return{c(){e=$("span")},m(i,l){N(i,e,l),e.innerHTML=n},p(i,l){l[0]&512&&n!==(n=i[9].verifying+"")&&(e.innerHTML=n)},d(i){i&&I(e)}}}function st(t){let e,n=t[9].verified+"",i,l;return{c(){e=$("span"),i=F(),l=$("input"),c(l,"type","hidden"),c(l,"name",t[3]),l.value=t[4]},m(r,s){N(r,e,s),e.innerHTML=n,N(r,i,s),N(r,l,s)},p(r,s){s[0]&512&&n!==(n=r[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(l,"name",r[3]),s[0]&16&&(l.value=r[4])},d(r){r&&(I(e),I(i),I(l))}}}function be(t){let e,n,i,l,r,s;return{c(){e=$("div"),n=$("a"),i=V("svg"),l=V("path"),r=V("path"),s=V("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(r,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(r,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",_e),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(a,h){N(a,e,h),g(e,n),g(n,i),g(i,l),g(i,r),g(i,s)},p:k,d(a){a&&I(e)}}}function me(t){let e,n,i,l,r;return{c(){e=$("div"),n=V("svg"),i=V("path"),l=F(),r=$("div"),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(s,a){N(s,e,a),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=t[8]},p(s,a){a[0]&256&&(r.innerHTML=s[8])},d(s){s&&I(e)}}}function ve(t){let e,n,i=t[9].footer+"";return{c(){e=$("div"),n=$("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(l,r){N(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&512&&i!==(i=l[9].footer+"")&&(n.innerHTML=i)},d(l){l&&I(e)}}}function ct(t){let e,n,i,l,r,s,a,h,f,j,p,A,L,G,_=t[5]===v.VERIFYING&&ge();function M(u,y){return u[5]===v.VERIFIED?st:u[5]===v.VERIFYING?lt:ot}let Y=M(t),C=Y(t),w=t[2]!==!0&&be(),b=t[8]&&me(t),m=t[9].footer&&t[1]!==!0&&ve(t);return{c(){e=$("div"),n=$("div"),_&&_.c(),i=F(),l=$("div"),r=$("input"),h=F(),f=$("div"),C.c(),j=F(),w&&w.c(),p=F(),b&&b.c(),A=F(),m&&m.c(),c(r,"type","checkbox"),c(r,"id",s=t[3]+"_checkbox"),r.required=a=t[0]!=="onsubmit",c(r,"class","svelte-vuofbg"),c(l,"class","altcha-checkbox svelte-vuofbg"),le(l,"altcha-hidden",t[5]===v.VERIFYING),c(f,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(u,y){N(u,e,y),g(e,n),_&&_.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[6],g(n,h),g(n,f),C.m(f,null),g(n,j),w&&w.m(n,null),g(e,p),b&&b.m(e,null),g(e,A),m&&m.m(e,null),t[24](e),L||(G=[Q(r,"change",t[23]),Q(r,"change",t[10]),Q(r,"invalid",t[11])],L=!0)},p(u,y){u[5]===v.VERIFYING?_||(_=ge(),_.c(),_.m(n,i)):_&&(_.d(1),_=null),y[0]&8&&s!==(s=u[3]+"_checkbox")&&c(r,"id",s),y[0]&1&&a!==(a=u[0]!=="onsubmit")&&(r.required=a),y[0]&64&&(r.checked=u[6]),y[0]&32&&le(l,"altcha-hidden",u[5]===v.VERIFYING),Y===(Y=M(u))&&C?C.p(u,y):(C.d(1),C=Y(u),C&&(C.c(),C.m(f,null))),u[2]!==!0?w?w.p(u,y):(w=be(),w.c(),w.m(n,null)):w&&(w.d(1),w=null),u[8]?b?b.p(u,y):(b=me(u),b.c(),b.m(e,A)):b&&(b.d(1),b=null),u[9].footer&&u[1]!==!0?m?m.p(u,y):(m=ve(u),m.c(),m.m(e,null)):m&&(m.d(1),m=null),y[0]&32&&c(e,"data-state",u[5])},i:k,o:k,d(u){u&&I(e),_&&_.d(),C.d(),w&&w.d(),b&&b.d(),m&&m.d(),t[24](null),L=!1,T(G)}}}const _e="https://altcha.org/";function we(t){return JSON.parse(t)}function ut(t,e,n){let i,l,r,{auto:s=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:h=void 0}=e,{debug:f=!1}=e,{hidefooter:j=!1}=e,{hidelogo:p=!1}=e,{name:A="altcha"}=e,{maxnumber:L=void 0}=e,{mockerror:G=!1}=e,{strings:_=void 0}=e,{test:M=!1}=e;const Y=Oe(),C=["SHA-256","SHA-384","SHA-512"],w=[];let b=!1,m,u=null,y=null,W=null,O=v.UNVERIFIED,ye;Ue(()=>{u&&(u.removeEventListener("submit",pe),u.removeEventListener("reset",ke),u=null)}),Me(()=>{x("mounted","0.1.9"),M&&x("using test mode"),s!==void 0&&x("auto",s),u=m.closest("form"),u&&(u.addEventListener("submit",pe),u.addEventListener("reset",ke)),s==="onload"&&K()});function x(...o){(f||o.some(d=>d instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function pe(o){u&&s==="onsubmit"&&O===v.UNVERIFIED&&(o.preventDefault(),o.stopPropagation(),K().then(()=>{u==null||u.requestSubmit()}))}function ke(){J()}function at(o,d){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:d.number,salt:o.salt,signature:o.signature,test:M?!0:void 0,took:d.took}))}function Ee(o){if(!o.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(o.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!C.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${C.join(", ")}`);if(!o.challenge||o.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!o.salt||o.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function ft(){if(G)throw x("mocking error"),new Error("Mocked error.");if(i)return x("using provided json data"),i;if(M)return x("generating test challenge"),nt();{if(!a)throw new Error("Attribute challengeurl not set.");x("fetching challenge from",a);const o=await fetch(a);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);const d=o.headers.get("Expires");if(d.length){const P=Date.parse(d)-Date.now();P<1?Ce():ye=setTimeout(Ce,P)}return o.json()}}function Ce(){J(v.EXPIRED,r.expired)}async function ht(o){let d=null;if("Worker"in window){try{d=await dt(o.challenge,o.salt,o.algorithm)}catch(P){x(P)}if((d==null?void 0:d.number)!==void 0)return{data:o,solution:d}}return{data:o,solution:await rt(o.challenge,o.salt,o.algorithm,L)}}async function dt(o,d,P){const xe=w.push(new Qe);return new Promise(wt=>{w[xe-1].addEventListener("message",$t=>{wt($t.data)}),w[xe-1].postMessage({alg:P,challenge:o,max:L,salt:d})})}function gt(){[v.UNVERIFIED,v.ERROR,v.EXPIRED].includes(O)?K():n(6,b=!0)}function bt(){O===v.VERIFYING&&alert(r.waitAlert)}function mt(o){o.auto!==void 0&&(n(0,s=o.auto),s==="onload"&&K()),o.challenge&&(Ee(o.challenge),i=o.challenge),o.debug!==void 0&&n(12,f=!!o.debug),o.hidefooter!==void 0&&n(1,j=!!o.hidefooter),o.hidelogo!==void 0&&n(2,p=!!o.hidelogo),o.maxnumber!==void 0&&n(13,L=+o.maxnumber),o.mockerror!==void 0&&n(14,G=!!o.mockerror),o.name!==void 0&&n(3,A=o.name),o.test!==void 0&&n(15,M=!!o.test),o.strings&&n(22,l=o.strings)}function J(o=v.UNVERIFIED,d=null){clearTimeout(ye),n(6,b=!1),n(8,y=d),n(4,W=null),n(5,O=o)}async function K(){return J(v.VERIFYING),ft().then(o=>(Ee(o),x("challenge",o),ht(o))).then(({data:o,solution:d})=>{if(x("solution",d),(d==null?void 0:d.number)!==void 0)x("verified"),n(5,O=v.VERIFIED),n(6,b=!0),n(4,W=at(o,d)),x("payload",W),Fe().then(()=>{Y("verified",{payload:W})});else throw new Error("Unexpected result returned.")}).catch(o=>{x(o),n(5,O=v.ERROR),n(6,b=!1),n(8,y=o.message)})}function vt(){b=this.checked,n(6,b)}function _t(o){ee[o?"unshift":"push"](()=>{m=o,n(7,m)})}return t.$$set=o=>{"auto"in o&&n(0,s=o.auto),"challengeurl"in o&&n(16,a=o.challengeurl),"challengejson"in o&&n(17,h=o.challengejson),"debug"in o&&n(12,f=o.debug),"hidefooter"in o&&n(1,j=o.hidefooter),"hidelogo"in o&&n(2,p=o.hidelogo),"name"in o&&n(3,A=o.name),"maxnumber"in o&&n(13,L=o.maxnumber),"mockerror"in o&&n(14,G=o.mockerror),"strings"in o&&n(18,_=o.strings),"test"in o&&n(15,M=o.test)},t.$$.update=()=>{t.$$.dirty[0]&131072&&(i=h?we(h):void 0),t.$$.dirty[0]&262144&&n(22,l=_?we(_):{}),t.$$.dirty[0]&4194304&&n(9,r={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&48&&Y("statechange",{payload:W,state:O})},[s,j,p,A,W,O,b,m,y,r,gt,bt,f,L,G,M,a,h,_,mt,J,K,l,vt,_t]}class $e extends Ke{constructor(e){super(),De(this,e,ut,ct,Ie,{auto:0,challengeurl:16,challengejson:17,debug:12,hidefooter:1,hidelogo:2,name:3,maxnumber:13,mockerror:14,strings:18,test:15,configure:19,reset:20,verify:21},it,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[16]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[17]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),E()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),E()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),E()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),E()}get maxnumber(){return this.$$.ctx[13]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),E()}get strings(){return this.$$.ctx[18]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[15]}set test(e){this.$$set({test:e}),E()}get configure(){return this.$$.ctx[19]}get reset(){return this.$$.ctx[20]}get verify(){return this.$$.ctx[21]}}return customElements.define("altcha-widget",Xe($e,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["configure","reset","verify"],!1)),S.Altcha=$e,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"}),S}({}); +var altcha=function(S){"use strict";var Et=Object.defineProperty;var Ct=(S,k,U)=>k in S?Et(S,k,{enumerable:!0,configurable:!0,writable:!0,value:U}):S[k]=U;var N=(S,k,U)=>(Ct(S,typeof k!="symbol"?k+"":k,U),U);function k(){}function U(t){return t()}function oe(){return Object.create(null)}function D(t){t.forEach(U)}function se(t){return typeof t=="function"}function Le(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Re(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function Ne(t,e,n){const r=je(t);if(!r.getElementById(e)){const l=_("style");l.id=e,l.textContent=n,Ae(r,l)}}function je(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ae(t,e){return b(t.head||t,e),e.sheet}function x(t,e,n){t.insertBefore(e,n||null)}function E(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Ge(t){return document.createTextNode(t)}function F(){return Ge(" ")}function Q(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Me(t){return Array.from(t.childNodes)}function ce(t,e,n){t.classList.toggle(e,!!n)}function Se(t,e,{bubbles:n=!1,cancelable:r=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:r})}function Ve(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let X;function W(t){X=t}function q(){if(!X)throw new Error("Function called outside component initialization");return X}function Ue(t){q().$$.on_mount.push(t)}function Oe(t){q().$$.on_destroy.push(t)}function Fe(){const t=q();return(e,n,{cancelable:r=!1}={})=>{const l=t.$$.callbacks[e];if(l){const o=Se(e,n,{cancelable:r});return l.slice().forEach(s=>{s.call(t,o)}),!o.defaultPrevented}return!0}}const Y=[],ee=[];let Z=[];const ue=[],ae=Promise.resolve();let te=!1;function fe(){te||(te=!0,ae.then(C))}function Te(){return fe(),ae}function ne(t){Z.push(t)}const re=new Set;let B=0;function C(){if(B!==0)return;const t=X;do{try{for(;Bt.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Z=e}const Be=new Set;function He(t,e){t&&t.i&&(Be.delete(t),t.i(e))}function Pe(t,e,n){const{fragment:r,after_update:l}=t.$$;r&&r.m(e,n),ne(()=>{const o=t.$$.on_mount.map(U).filter(se);t.$$.on_destroy?t.$$.on_destroy.push(...o):D(o),t.$$.on_mount=[]}),l.forEach(ne)}function De(t,e){const n=t.$$;n.fragment!==null&&(Ze(n.after_update),D(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Xe(t,e){t.$$.dirty[0]===-1&&(Y.push(t),fe(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const j=M.length?M[0]:G;return a.ctx&&l(a.ctx[p],a.ctx[p]=j)&&(!a.skip_bound&&a.bound[p]&&a.bound[p](j),I&&Xe(t,p)),G}):[],a.update(),I=!0,D(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const p=Me(e.target);a.fragment&&a.fragment.l(p),p.forEach(E)}else a.fragment&&a.fragment.c();e.intro&&He(t.$$.fragment),Pe(t,e.target,e.anchor),C()}W(h)}let he;typeof HTMLElement=="function"&&(he=class extends HTMLElement{constructor(e,n,r){super();N(this,"$$ctor");N(this,"$$s");N(this,"$$c");N(this,"$$cn",!1);N(this,"$$d",{});N(this,"$$r",!1);N(this,"$$p_d",{});N(this,"$$l",{});N(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,r&&this.attachShadow({mode:"open"})}addEventListener(e,n,r){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,r)}removeEventListener(e,n,r){if(super.removeEventListener(e,n,r),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(o){return()=>{let s;return{c:function(){s=_("slot"),o!=="default"&&c(s,"name",o)},m:function(a,I){x(a,s,I)},d:function(a){a&&E(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},r=Ve(this);for(const o of this.$$s)o in r&&(n[o]=[e(o)]);for(const o of this.attributes){const s=this.$$g_p(o.name);s in this.$$d||(this.$$d[s]=z(s,o.value,this.$$p_d,"toProp"))}for(const o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){const s=z(o,this.$$d[o],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const o in this.$$l)for(const s of this.$$l[o]){const u=this.$$c.$on(o,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,n,r){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=z(e,r,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function z(t,e,n,r){var o;const l=(o=n[t])==null?void 0:o.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Ke(t,e,n,r,l,o){let s=class extends he{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(h){var a;h=z(u,h,e),this.$$d[u]=h,(a=this.$$c)==null||a.$set({[u]:h})}})}),r.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var h;return(h=this.$$c)==null?void 0:h[u]}})}),o&&(s=o(s)),t.element=s,s}class ze{constructor(){N(this,"$$");N(this,"$$set")}$destroy(){De(this,1),this.$destroy=k}$on(e,n){if(!se(n))return k;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{const l=r.indexOf(n);l!==-1&&r.splice(l,1)}}$set(e){this.$$set&&!Re(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Je="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Je);const de="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",Qe=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),ge=typeof window<"u"&&window.Blob&&new Blob([Qe(de)],{type:"text/javascript;charset=utf-8"});function qe(t){let e;try{if(e=ge&&(window.URL||window.webkitURL).createObjectURL(ge),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+de,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const et=1e7,tt=new TextEncoder;function nt(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function rt(t=1e5,e="SHA-256"){const n=Date.now().toString(16),r=Math.round(Math.random()*t),l=await be(n,r,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function be(t,e,n){return nt(await crypto.subtle.digest(n.toUpperCase(),tt.encode(t+e)))}async function it(t,e,n="SHA-256",r=et){const l=Date.now();for(let o=0;o<=r;o++)if(await be(e,o,n)===t)return{number:o,took:Date.now()-l};return null}var m=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(m||{});function lt(t){Ne(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function me(t){let e,n,r;return{c(){e=V("svg"),n=V("path"),r=V("path"),c(n,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(n,"fill","currentColor"),c(n,"opacity",".25"),c(r,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(r,"fill","currentColor"),c(r,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,o){x(l,e,o),b(e,n),b(e,r)},d(l){l&&E(e)}}}function ot(t){let e,n=t[9].label+"",r;return{c(){e=_("label"),c(e,"for",r=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(l,o){x(l,e,o),e.innerHTML=n},p(l,o){o[0]&512&&n!==(n=l[9].label+"")&&(e.innerHTML=n),o[0]&8&&r!==(r=l[3]+"_checkbox")&&c(e,"for",r)},d(l){l&&E(e)}}}function st(t){let e,n=t[9].verifying+"";return{c(){e=_("span")},m(r,l){x(r,e,l),e.innerHTML=n},p(r,l){l[0]&512&&n!==(n=r[9].verifying+"")&&(e.innerHTML=n)},d(r){r&&E(e)}}}function ct(t){let e,n=t[9].verified+"",r,l;return{c(){e=_("span"),r=F(),l=_("input"),c(l,"type","hidden"),c(l,"name",t[3]),l.value=t[4]},m(o,s){x(o,e,s),e.innerHTML=n,x(o,r,s),x(o,l,s)},p(o,s){s[0]&512&&n!==(n=o[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(l,"name",o[3]),s[0]&16&&(l.value=o[4])},d(o){o&&(E(e),E(r),E(l))}}}function ve(t){let e,n,r,l,o,s;return{c(){e=_("div"),n=_("a"),r=V("svg"),l=V("path"),o=V("path"),s=V("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(o,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(o,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(r,"width","22"),c(r,"height","22"),c(r,"viewBox","0 0 20 20"),c(r,"fill","none"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",$e),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(u,h){x(u,e,h),b(e,n),b(n,r),b(r,l),b(r,o),b(r,s)},p:k,d(u){u&&E(e)}}}function _e(t){let e,n,r,l;function o(h,a){return h[5]===m.EXPIRED?at:ut}let s=o(t),u=s(t);return{c(){e=_("div"),n=V("svg"),r=V("path"),l=F(),u.c(),c(r,"stroke-linecap","round"),c(r,"stroke-linejoin","round"),c(r,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(h,a){x(h,e,a),b(e,n),b(n,r),b(e,l),u.m(e,null)},p(h,a){s===(s=o(h))&&u?u.p(h,a):(u.d(1),u=s(h),u&&(u.c(),u.m(e,null)))},d(h){h&&E(e),u.d()}}}function ut(t){let e,n=t[9].error+"";return{c(){e=_("div"),c(e,"title",t[8])},m(r,l){x(r,e,l),e.innerHTML=n},p(r,l){l[0]&512&&n!==(n=r[9].error+"")&&(e.innerHTML=n),l[0]&256&&c(e,"title",r[8])},d(r){r&&E(e)}}}function at(t){let e,n=t[9].expired+"";return{c(){e=_("div"),c(e,"title",t[8])},m(r,l){x(r,e,l),e.innerHTML=n},p(r,l){l[0]&512&&n!==(n=r[9].expired+"")&&(e.innerHTML=n),l[0]&256&&c(e,"title",r[8])},d(r){r&&E(e)}}}function we(t){let e,n,r=t[9].footer+"";return{c(){e=_("div"),n=_("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(l,o){x(l,e,o),b(e,n),n.innerHTML=r},p(l,o){o[0]&512&&r!==(r=l[9].footer+"")&&(n.innerHTML=r)},d(l){l&&E(e)}}}function ft(t){let e,n,r,l,o,s,u,h,a,I,p,G,M,j,w=t[5]===m.VERIFYING&&me();function T(f,y){return f[5]===m.VERIFIED?ct:f[5]===m.VERIFYING?st:ot}let A=T(t),L=A(t),$=t[2]!==!0&&ve(),g=(t[8]||t[5]===m.EXPIRED)&&_e(t),v=t[9].footer&&t[1]!==!0&&we(t);return{c(){e=_("div"),n=_("div"),w&&w.c(),r=F(),l=_("div"),o=_("input"),h=F(),a=_("div"),L.c(),I=F(),$&&$.c(),p=F(),g&&g.c(),G=F(),v&&v.c(),c(o,"type","checkbox"),c(o,"id",s=t[3]+"_checkbox"),o.required=u=t[0]!=="onsubmit",c(o,"class","svelte-vuofbg"),c(l,"class","altcha-checkbox svelte-vuofbg"),ce(l,"altcha-hidden",t[5]===m.VERIFYING),c(a,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(f,y){x(f,e,y),b(e,n),w&&w.m(n,null),b(n,r),b(n,l),b(l,o),o.checked=t[6],b(n,h),b(n,a),L.m(a,null),b(n,I),$&&$.m(n,null),b(e,p),g&&g.m(e,null),b(e,G),v&&v.m(e,null),t[25](e),M||(j=[Q(o,"change",t[24]),Q(o,"change",t[10]),Q(o,"invalid",t[11])],M=!0)},p(f,y){f[5]===m.VERIFYING?w||(w=me(),w.c(),w.m(n,r)):w&&(w.d(1),w=null),y[0]&8&&s!==(s=f[3]+"_checkbox")&&c(o,"id",s),y[0]&1&&u!==(u=f[0]!=="onsubmit")&&(o.required=u),y[0]&64&&(o.checked=f[6]),y[0]&32&&ce(l,"altcha-hidden",f[5]===m.VERIFYING),A===(A=T(f))&&L?L.p(f,y):(L.d(1),L=A(f),L&&(L.c(),L.m(a,null))),f[2]!==!0?$?$.p(f,y):($=ve(),$.c(),$.m(n,null)):$&&($.d(1),$=null),f[8]||f[5]===m.EXPIRED?g?g.p(f,y):(g=_e(f),g.c(),g.m(e,G)):g&&(g.d(1),g=null),f[9].footer&&f[1]!==!0?v?v.p(f,y):(v=we(f),v.c(),v.m(e,null)):v&&(v.d(1),v=null),y[0]&32&&c(e,"data-state",f[5])},i:k,o:k,d(f){f&&E(e),w&&w.d(),L.d(),$&&$.d(),g&&g.d(),v&&v.d(),t[25](null),M=!1,D(j)}}}const $e="https://altcha.org/";function ye(t){return JSON.parse(t)}function ht(t,e,n){let r,l,o,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:h=void 0}=e,{debug:a=!1}=e,{expire:I=void 0}=e,{hidefooter:p=!1}=e,{hidelogo:G=!1}=e,{name:M="altcha"}=e,{maxnumber:j=void 0}=e,{mockerror:w=!1}=e,{strings:T=void 0}=e,{test:A=!1}=e;const L=Fe(),$=["SHA-256","SHA-384","SHA-512"];let g=!1,v,f=null,y=null,H=null,O=m.UNVERIFIED,ie;Oe(()=>{f&&(f.removeEventListener("submit",ke),f.removeEventListener("reset",Ee),f=null)}),Ue(()=>{R("mounted","0.1.9"),A&&R("using test mode"),I&&le(I),s!==void 0&&R("auto",s),f=v.closest("form"),f&&(f.addEventListener("submit",ke),f.addEventListener("reset",Ee)),s==="onload"&&K()});function R(...i){(a||i.some(d=>d instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function ke(i){f&&s==="onsubmit"&&O===m.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),K().then(()=>{f==null||f.requestSubmit()}))}function Ee(){J()}function dt(i,d){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:d.number,salt:i.salt,signature:i.signature,test:A?!0:void 0,took:d.took}))}function Ce(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!$.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${$.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function gt(){if(w)throw R("mocking error"),new Error("Mocked error.");if(r)return R("using provided json data"),r;if(A)return R("generating test challenge"),rt();{if(!u)throw new Error("Attribute challengeurl not set.");R("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const d=i.headers.get("Expires");if(d!=null&&d.length){const P=Date.parse(d);isNaN(P)||le(P-Date.now())}return i.json()}}function xe(){J(m.EXPIRED,o.expired)}async function bt(i){let d=null;if("Worker"in window){try{d=await mt(i.challenge,i.salt,i.algorithm)}catch(P){R(P)}if((d==null?void 0:d.number)!==void 0)return{data:i,solution:d}}return{data:i,solution:await it(i.challenge,i.salt,i.algorithm,j)}}async function mt(i,d,P){const Ie=new qe;return new Promise(pt=>{Ie.addEventListener("message",kt=>{pt(kt.data)}),Ie.postMessage({alg:P,challenge:i,max:j,salt:d})})}function vt(){[m.UNVERIFIED,m.ERROR,m.EXPIRED].includes(O)?K():n(6,g=!0)}function _t(){O===m.VERIFYING&&alert(o.waitAlert)}function le(i){clearTimeout(ie),i<1?xe():ie=setTimeout(xe,i)}function wt(i){i.auto!==void 0&&(n(0,s=i.auto),s==="onload"&&K()),i.expire!==void 0&&(le(i.expire),n(13,I=i.expire)),i.challenge&&(Ce(i.challenge),r=i.challenge),i.debug!==void 0&&n(12,a=!!i.debug),i.hidefooter!==void 0&&n(1,p=!!i.hidefooter),i.hidelogo!==void 0&&n(2,G=!!i.hidelogo),i.maxnumber!==void 0&&n(14,j=+i.maxnumber),i.mockerror!==void 0&&n(15,w=!!i.mockerror),i.name!==void 0&&n(3,M=i.name),i.test!==void 0&&n(16,A=!!i.test),i.strings&&n(23,l=i.strings)}function J(i=m.UNVERIFIED,d=null){clearTimeout(ie),n(6,g=!1),n(8,y=d),n(4,H=null),n(5,O=i)}async function K(){return J(m.VERIFYING),gt().then(i=>(Ce(i),R("challenge",i),bt(i))).then(({data:i,solution:d})=>{if(R("solution",d),(d==null?void 0:d.number)!==void 0)R("verified"),n(5,O=m.VERIFIED),n(6,g=!0),n(4,H=dt(i,d)),R("payload",H),Te().then(()=>{L("verified",{payload:H})});else throw new Error("Unexpected result returned.")}).catch(i=>{R(i),n(5,O=m.ERROR),n(6,g=!1),n(8,y=i.message)})}function $t(){g=this.checked,n(6,g)}function yt(i){ee[i?"unshift":"push"](()=>{v=i,n(7,v)})}return t.$$set=i=>{"auto"in i&&n(0,s=i.auto),"challengeurl"in i&&n(17,u=i.challengeurl),"challengejson"in i&&n(18,h=i.challengejson),"debug"in i&&n(12,a=i.debug),"expire"in i&&n(13,I=i.expire),"hidefooter"in i&&n(1,p=i.hidefooter),"hidelogo"in i&&n(2,G=i.hidelogo),"name"in i&&n(3,M=i.name),"maxnumber"in i&&n(14,j=i.maxnumber),"mockerror"in i&&n(15,w=i.mockerror),"strings"in i&&n(19,T=i.strings),"test"in i&&n(16,A=i.test)},t.$$.update=()=>{t.$$.dirty[0]&262144&&(r=h?ye(h):void 0),t.$$.dirty[0]&524288&&n(23,l=T?ye(T):{}),t.$$.dirty[0]&8388608&&n(9,o={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&48&&L("statechange",{payload:H,state:O})},[s,p,G,M,H,O,g,v,y,o,vt,_t,a,I,j,w,A,u,h,T,wt,J,K,l,$t,yt]}class pe extends ze{constructor(e){super(),We(this,e,ht,ft,Le,{auto:0,challengeurl:17,challengejson:18,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:19,test:16,configure:20,reset:21,verify:22},lt,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),C()}get challengeurl(){return this.$$.ctx[17]}set challengeurl(e){this.$$set({challengeurl:e}),C()}get challengejson(){return this.$$.ctx[18]}set challengejson(e){this.$$set({challengejson:e}),C()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),C()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),C()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),C()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),C()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),C()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),C()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),C()}get strings(){return this.$$.ctx[19]}set strings(e){this.$$set({strings:e}),C()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),C()}get configure(){return this.$$.ctx[20]}get reset(){return this.$$.ctx[21]}get verify(){return this.$$.ctx[22]}}return customElements.define("altcha-widget",Ke(pe,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["configure","reset","verify"],!1)),S.Altcha=pe,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"}),S}({}); diff --git a/dist/altcha.js b/dist/altcha.js index b686224..a266900 100644 --- a/dist/altcha.js +++ b/dist/altcha.js @@ -1,37 +1,37 @@ var Ue = Object.defineProperty; -var Me = (t, e, n) => e in t ? Ue(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; -var I = (t, e, n) => (Me(t, typeof e != "symbol" ? e + "" : e, n), n); +var Fe = (t, e, n) => e in t ? Ue(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; +var R = (t, e, n) => (Fe(t, typeof e != "symbol" ? e + "" : e, n), n); function H() { } -function ve(t) { +function _e(t) { return t(); } -function ce() { +function ue() { return /* @__PURE__ */ Object.create(null); } -function T(t) { - t.forEach(ve); +function X(t) { + t.forEach(_e); } -function _e(t) { +function we(t) { return typeof t == "function"; } -function Fe(t, e) { +function Oe(t, e) { return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function"; } -function Oe(t) { +function Ye(t) { return Object.keys(t).length === 0; } -function b(t, e) { +function m(t, e) { t.appendChild(e); } -function Ye(t, e, n) { - const i = Ze(t); - if (!i.getElementById(e)) { - const l = $("style"); - l.id = e, l.textContent = n, Be(i, l); +function Ze(t, e, n) { + const r = Be(t); + if (!r.getElementById(e)) { + const l = w("style"); + l.id = e, l.textContent = n, He(r, l); } } -function Ze(t) { +function Be(t) { if (!t) return document; const e = t.getRootNode ? t.getRootNode() : t.ownerDocument; @@ -41,47 +41,47 @@ function Ze(t) { e ) : t.ownerDocument; } -function Be(t, e) { - return b( +function He(t, e) { + return m( /** @type {Document} */ t.head || t, e ), e.sheet; } -function N(t, e, n) { +function L(t, e, n) { t.insertBefore(e, n || null); } -function L(t) { +function E(t) { t.parentNode && t.parentNode.removeChild(t); } -function $(t) { +function w(t) { return document.createElement(t); } -function V(t) { +function M(t) { return document.createElementNS("http://www.w3.org/2000/svg", t); } -function He(t) { +function Te(t) { return document.createTextNode(t); } -function M() { - return He(" "); +function U() { + return Te(" "); } -function z(t, e, n, i) { - return t.addEventListener(e, n, i), () => t.removeEventListener(e, n, i); +function Q(t, e, n, r) { + return t.addEventListener(e, n, r), () => t.removeEventListener(e, n, r); } function c(t, e, n) { n == null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n); } -function We(t) { +function De(t) { return Array.from(t.childNodes); } -function ue(t, e, n) { +function ae(t, e, n) { t.classList.toggle(e, !!n); } -function De(t, e, { bubbles: n = !1, cancelable: i = !1 } = {}) { - return new CustomEvent(t, { detail: e, bubbles: n, cancelable: i }); +function Pe(t, e, { bubbles: n = !1, cancelable: r = !1 } = {}) { + return new CustomEvent(t, { detail: e, bubbles: n, cancelable: r }); } -function Pe(t) { +function Xe(t) { const e = {}; return t.childNodes.forEach( /** @param {Element} node */ @@ -94,51 +94,51 @@ let P; function D(t) { P = t; } -function te() { +function re() { if (!P) throw new Error("Function called outside component initialization"); return P; } -function Te(t) { - te().$$.on_mount.push(t); +function We(t) { + re().$$.on_mount.push(t); } -function Xe(t) { - te().$$.on_destroy.push(t); +function Ke(t) { + re().$$.on_destroy.push(t); } -function Ke() { - const t = te(); - return (e, n, { cancelable: i = !1 } = {}) => { +function ze() { + const t = re(); + return (e, n, { cancelable: r = !1 } = {}) => { const l = t.$$.callbacks[e]; if (l) { - const r = De( + const o = Pe( /** @type {string} */ e, n, - { cancelable: i } + { cancelable: r } ); return l.slice().forEach((s) => { - s.call(t, r); - }), !r.defaultPrevented; + s.call(t, o); + }), !o.defaultPrevented; } return !0; }; } -const Z = [], Q = []; +const Z = [], ee = []; let B = []; -const ae = [], we = /* @__PURE__ */ Promise.resolve(); -let q = !1; -function $e() { - q || (q = !0, we.then(x)); +const fe = [], $e = /* @__PURE__ */ Promise.resolve(); +let te = !1; +function pe() { + te || (te = !0, $e.then(k)); } -function ze() { - return $e(), we; +function Je() { + return pe(), $e; } -function ee(t) { +function ne(t) { B.push(t); } -const J = /* @__PURE__ */ new Set(); +const q = /* @__PURE__ */ new Set(); let Y = 0; -function x() { +function k() { if (Y !== 0) return; const t = P; @@ -146,63 +146,63 @@ function x() { try { for (; Y < Z.length; ) { const e = Z[Y]; - Y++, D(e), Je(e.$$); + Y++, D(e), Qe(e.$$); } } catch (e) { throw Z.length = 0, Y = 0, e; } - for (D(null), Z.length = 0, Y = 0; Q.length; ) - Q.pop()(); + for (D(null), Z.length = 0, Y = 0; ee.length; ) + ee.pop()(); for (let e = 0; e < B.length; e += 1) { const n = B[e]; - J.has(n) || (J.add(n), n()); + q.has(n) || (q.add(n), n()); } B.length = 0; } while (Z.length); - for (; ae.length; ) - ae.pop()(); - q = !1, J.clear(), D(t); + for (; fe.length; ) + fe.pop()(); + te = !1, q.clear(), D(t); } -function Je(t) { +function Qe(t) { if (t.fragment !== null) { - t.update(), T(t.before_update); + t.update(), X(t.before_update); const e = t.dirty; - t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(ee); + t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(ne); } } -function Qe(t) { +function qe(t) { const e = [], n = []; - B.forEach((i) => t.indexOf(i) === -1 ? e.push(i) : n.push(i)), n.forEach((i) => i()), B = e; + B.forEach((r) => t.indexOf(r) === -1 ? e.push(r) : n.push(r)), n.forEach((r) => r()), B = e; } -const qe = /* @__PURE__ */ new Set(); -function et(t, e) { - t && t.i && (qe.delete(t), t.i(e)); +const et = /* @__PURE__ */ new Set(); +function tt(t, e) { + t && t.i && (et.delete(t), t.i(e)); } -function tt(t, e, n) { - const { fragment: i, after_update: l } = t.$$; - i && i.m(e, n), ee(() => { - const r = t.$$.on_mount.map(ve).filter(_e); - t.$$.on_destroy ? t.$$.on_destroy.push(...r) : T(r), t.$$.on_mount = []; - }), l.forEach(ee); +function nt(t, e, n) { + const { fragment: r, after_update: l } = t.$$; + r && r.m(e, n), ne(() => { + const o = t.$$.on_mount.map(_e).filter(we); + t.$$.on_destroy ? t.$$.on_destroy.push(...o) : X(o), t.$$.on_mount = []; + }), l.forEach(ne); } -function nt(t, e) { +function rt(t, e) { const n = t.$$; - n.fragment !== null && (Qe(n.after_update), T(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []); + n.fragment !== null && (qe(n.after_update), X(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []); } -function rt(t, e) { - t.$$.dirty[0] === -1 && (Z.push(t), $e(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31; +function it(t, e) { + t.$$.dirty[0] === -1 && (Z.push(t), pe(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31; } -function it(t, e, n, i, l, r, s = null, a = [-1]) { +function lt(t, e, n, r, l, o, s = null, u = [-1]) { const h = P; D(t); - const f = t.$$ = { + const a = t.$$ = { fragment: null, ctx: [], // state - props: r, + props: o, update: H, not_equal: l, - bound: ce(), + bound: ue(), // lifecycle on_mount: [], on_destroy: [], @@ -211,96 +211,96 @@ function it(t, e, n, i, l, r, s = null, a = [-1]) { after_update: [], context: new Map(e.context || (h ? h.$$.context : [])), // everything else - callbacks: ce(), - dirty: a, + callbacks: ue(), + dirty: u, skip_bound: !1, root: e.target || h.$$.root }; - s && s(f.root); - let R = !1; - if (f.ctx = n ? n(t, e.props || {}, (p, j, ...C) => { - const A = C.length ? C[0] : j; - return f.ctx && l(f.ctx[p], f.ctx[p] = A) && (!f.skip_bound && f.bound[p] && f.bound[p](A), R && rt(t, p)), j; - }) : [], f.update(), R = !0, T(f.before_update), f.fragment = i ? i(f.ctx) : !1, e.target) { + s && s(a.root); + let x = !1; + if (a.ctx = n ? n(t, e.props || {}, (y, A, ...G) => { + const N = G.length ? G[0] : A; + return a.ctx && l(a.ctx[y], a.ctx[y] = N) && (!a.skip_bound && a.bound[y] && a.bound[y](N), x && it(t, y)), A; + }) : [], a.update(), x = !0, X(a.before_update), a.fragment = r ? r(a.ctx) : !1, e.target) { if (e.hydrate) { - const p = We(e.target); - f.fragment && f.fragment.l(p), p.forEach(L); + const y = De(e.target); + a.fragment && a.fragment.l(y), y.forEach(E); } else - f.fragment && f.fragment.c(); - e.intro && et(t.$$.fragment), tt(t, e.target, e.anchor), x(); + a.fragment && a.fragment.c(); + e.intro && tt(t.$$.fragment), nt(t, e.target, e.anchor), k(); } D(h); } let ye; typeof HTMLElement == "function" && (ye = class extends HTMLElement { - constructor(e, n, i) { + constructor(e, n, r) { super(); /** The Svelte component constructor */ - I(this, "$$ctor"); + R(this, "$$ctor"); /** Slots */ - I(this, "$$s"); + R(this, "$$s"); /** The Svelte component instance */ - I(this, "$$c"); + R(this, "$$c"); /** Whether or not the custom element is connected */ - I(this, "$$cn", !1); + R(this, "$$cn", !1); /** Component props data */ - I(this, "$$d", {}); + R(this, "$$d", {}); /** `true` if currently in the process of reflecting component props back to attributes */ - I(this, "$$r", !1); + R(this, "$$r", !1); /** @type {Record} Props definition (name, reflected, type etc) */ - I(this, "$$p_d", {}); + R(this, "$$p_d", {}); /** @type {Record} Event listeners */ - I(this, "$$l", {}); + R(this, "$$l", {}); /** @type {Map} Event listener unsubscribe functions */ - I(this, "$$l_u", /* @__PURE__ */ new Map()); - this.$$ctor = e, this.$$s = n, i && this.attachShadow({ mode: "open" }); + R(this, "$$l_u", /* @__PURE__ */ new Map()); + this.$$ctor = e, this.$$s = n, r && this.attachShadow({ mode: "open" }); } - addEventListener(e, n, i) { + addEventListener(e, n, r) { if (this.$$l[e] = this.$$l[e] || [], this.$$l[e].push(n), this.$$c) { const l = this.$$c.$on(e, n); this.$$l_u.set(n, l); } - super.addEventListener(e, n, i); + super.addEventListener(e, n, r); } - removeEventListener(e, n, i) { - if (super.removeEventListener(e, n, i), this.$$c) { + removeEventListener(e, n, r) { + if (super.removeEventListener(e, n, r), this.$$c) { const l = this.$$l_u.get(n); l && (l(), this.$$l_u.delete(n)); } } async connectedCallback() { if (this.$$cn = !0, !this.$$c) { - let e = function(r) { + let e = function(o) { return () => { let s; return { c: function() { - s = $("slot"), r !== "default" && c(s, "name", r); + s = w("slot"), o !== "default" && c(s, "name", o); }, /** * @param {HTMLElement} target * @param {HTMLElement} [anchor] */ - m: function(f, R) { - N(f, s, R); + m: function(a, x) { + L(a, s, x); }, - d: function(f) { - f && L(s); + d: function(a) { + a && E(s); } }; }; }; if (await Promise.resolve(), !this.$$cn || this.$$c) return; - const n = {}, i = Pe(this); - for (const r of this.$$s) - r in i && (n[r] = [e(r)]); - for (const r of this.attributes) { - const s = this.$$g_p(r.name); - s in this.$$d || (this.$$d[s] = K(s, r.value, this.$$p_d, "toProp")); + const n = {}, r = Xe(this); + for (const o of this.$$s) + o in r && (n[o] = [e(o)]); + for (const o of this.attributes) { + const s = this.$$g_p(o.name); + s in this.$$d || (this.$$d[s] = K(s, o.value, this.$$p_d, "toProp")); } - for (const r in this.$$p_d) - !(r in this.$$d) && this[r] !== void 0 && (this.$$d[r] = this[r], delete this[r]); + for (const o in this.$$p_d) + !(o in this.$$d) && this[o] !== void 0 && (this.$$d[o] = this[o], delete this[o]); this.$$c = new this.$$ctor({ target: this.shadowRoot || this, props: { @@ -313,32 +313,32 @@ typeof HTMLElement == "function" && (ye = class extends HTMLElement { }); const l = () => { this.$$r = !0; - for (const r in this.$$p_d) - if (this.$$d[r] = this.$$c.$$.ctx[this.$$c.$$.props[r]], this.$$p_d[r].reflect) { + for (const o in this.$$p_d) + if (this.$$d[o] = this.$$c.$$.ctx[this.$$c.$$.props[o]], this.$$p_d[o].reflect) { const s = K( - r, - this.$$d[r], + o, + this.$$d[o], this.$$p_d, "toAttribute" ); - s == null ? this.removeAttribute(this.$$p_d[r].attribute || r) : this.setAttribute(this.$$p_d[r].attribute || r, s); + s == null ? this.removeAttribute(this.$$p_d[o].attribute || o) : this.setAttribute(this.$$p_d[o].attribute || o, s); } this.$$r = !1; }; this.$$c.$$.after_update.push(l), l(); - for (const r in this.$$l) - for (const s of this.$$l[r]) { - const a = this.$$c.$on(r, s); - this.$$l_u.set(s, a); + for (const o in this.$$l) + for (const s of this.$$l[o]) { + const u = this.$$c.$on(o, s); + this.$$l_u.set(s, u); } this.$$l = {}; } } // We don't need this when working within Svelte code, but for compatibility of people using this outside of Svelte // and setting attributes through setAttribute etc, this is helpful - attributeChangedCallback(e, n, i) { + attributeChangedCallback(e, n, r) { var l; - this.$$r || (e = this.$$g_p(e), this.$$d[e] = K(e, i, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] })); + this.$$r || (e = this.$$g_p(e), this.$$d[e] = K(e, r, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] })); } disconnectedCallback() { this.$$cn = !1, Promise.resolve().then(() => { @@ -351,12 +351,12 @@ typeof HTMLElement == "function" && (ye = class extends HTMLElement { ) || e; } }); -function K(t, e, n, i) { - var r; - const l = (r = n[t]) == null ? void 0 : r.type; - if (e = l === "Boolean" && typeof e != "boolean" ? e != null : e, !i || !n[t]) +function K(t, e, n, r) { + var o; + const l = (o = n[t]) == null ? void 0 : o.type; + if (e = l === "Boolean" && typeof e != "boolean" ? e != null : e, !r || !n[t]) return e; - if (i === "toAttribute") + if (r === "toAttribute") switch (l) { case "Object": case "Array": @@ -381,38 +381,38 @@ function K(t, e, n, i) { return e; } } -function ot(t, e, n, i, l, r) { +function ot(t, e, n, r, l, o) { let s = class extends ye { constructor() { super(t, n, l), this.$$p_d = e; } static get observedAttributes() { return Object.keys(e).map( - (a) => (e[a].attribute || a).toLowerCase() + (u) => (e[u].attribute || u).toLowerCase() ); } }; - return Object.keys(e).forEach((a) => { - Object.defineProperty(s.prototype, a, { + return Object.keys(e).forEach((u) => { + Object.defineProperty(s.prototype, u, { get() { - return this.$$c && a in this.$$c ? this.$$c[a] : this.$$d[a]; + return this.$$c && u in this.$$c ? this.$$c[u] : this.$$d[u]; }, set(h) { - var f; - h = K(a, h, e), this.$$d[a] = h, (f = this.$$c) == null || f.$set({ [a]: h }); + var a; + h = K(u, h, e), this.$$d[u] = h, (a = this.$$c) == null || a.$set({ [u]: h }); } }); - }), i.forEach((a) => { - Object.defineProperty(s.prototype, a, { + }), r.forEach((u) => { + Object.defineProperty(s.prototype, u, { get() { var h; - return (h = this.$$c) == null ? void 0 : h[a]; + return (h = this.$$c) == null ? void 0 : h[u]; } }); - }), r && (s = r(s)), t.element = /** @type {any} */ + }), o && (s = o(s)), t.element = /** @type {any} */ s, s; } -class lt { +class st { constructor() { /** * ### PRIVATE API @@ -421,7 +421,7 @@ class lt { * * @type {any} */ - I(this, "$$"); + R(this, "$$"); /** * ### PRIVATE API * @@ -429,11 +429,11 @@ class lt { * * @type {any} */ - I(this, "$$set"); + R(this, "$$set"); } /** @returns {void} */ $destroy() { - nt(this, 1), this.$destroy = H; + rt(this, 1), this.$destroy = H; } /** * @template {Extract} K @@ -442,12 +442,12 @@ class lt { * @returns {() => void} */ $on(e, n) { - if (!_e(n)) + if (!we(n)) return H; - const i = this.$$.callbacks[e] || (this.$$.callbacks[e] = []); - return i.push(n), () => { - const l = i.indexOf(n); - l !== -1 && i.splice(l, 1); + const r = this.$$.callbacks[e] || (this.$$.callbacks[e] = []); + return r.push(n), () => { + const l = r.indexOf(n); + l !== -1 && r.splice(l, 1); }; } /** @@ -455,16 +455,16 @@ class lt { * @returns {void} */ $set(e) { - this.$$set && !Oe(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1); + this.$$set && !Ye(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1); } } -const st = "4"; -typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(st); -const pe = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==", ct = (t) => Uint8Array.from(atob(t), (e) => e.charCodeAt(0)), fe = typeof window < "u" && window.Blob && new Blob([ct(pe)], { type: "text/javascript;charset=utf-8" }); -function ut(t) { +const ct = "4"; +typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(ct); +const ke = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==", ut = (t) => Uint8Array.from(atob(t), (e) => e.charCodeAt(0)), he = typeof window < "u" && window.Blob && new Blob([ut(ke)], { type: "text/javascript;charset=utf-8" }); +function at(t) { let e; try { - if (e = fe && (window.URL || window.webkitURL).createObjectURL(fe), !e) + if (e = he && (window.URL || window.webkitURL).createObjectURL(he), !e) throw ""; const n = new Worker(e, { name: t == null ? void 0 : t.name @@ -474,7 +474,7 @@ function ut(t) { }), n; } catch { return new Worker( - "data:text/javascript;base64," + pe, + "data:text/javascript;base64," + ke, { name: t == null ? void 0 : t.name } @@ -483,12 +483,12 @@ function ut(t) { e && (window.URL || window.webkitURL).revokeObjectURL(e); } } -const at = 1e7, ft = new TextEncoder(); -function ht(t) { +const ft = 1e7, ht = new TextEncoder(); +function dt(t) { return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join(""); } -async function dt(t = 1e5, e = "SHA-256") { - const n = Date.now().toString(16), i = Math.round(Math.random() * t), l = await ke(n, i, e); +async function gt(t = 1e5, e = "SHA-256") { + const n = Date.now().toString(16), r = Math.round(Math.random() * t), l = await Ee(n, r, e); return { algorithm: e, challenge: l, @@ -496,92 +496,92 @@ async function dt(t = 1e5, e = "SHA-256") { signature: "" }; } -async function ke(t, e, n) { - return ht(await crypto.subtle.digest(n.toUpperCase(), ft.encode(t + e))); +async function Ee(t, e, n) { + return dt(await crypto.subtle.digest(n.toUpperCase(), ht.encode(t + e))); } -async function gt(t, e, n = "SHA-256", i = at) { +async function bt(t, e, n = "SHA-256", r = ft) { const l = Date.now(); - for (let r = 0; r <= i; r++) - if (await ke(e, r, n) === t) + for (let o = 0; o <= r; o++) + if (await Ee(e, o, n) === t) return { - number: r, + number: o, took: Date.now() - l }; return null; } -var w = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t.EXPIRED = "expired", t))(w || {}); -function bt(t) { - Ye(t, "svelte-vuofbg", ".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}"); +var b = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t.EXPIRED = "expired", t))(b || {}); +function mt(t) { + Ze(t, "svelte-vuofbg", ".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}"); } -function he(t) { - let e, n, i; +function de(t) { + let e, n, r; return { c() { - e = V("svg"), n = V("path"), i = V("path"), c(n, "d", "M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"), c(n, "fill", "currentColor"), c(n, "opacity", ".25"), c(i, "d", "M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"), c(i, "fill", "currentColor"), c(i, "class", "altcha-spinner svelte-vuofbg"), c(e, "width", "24"), c(e, "height", "24"), c(e, "viewBox", "0 0 24 24"), c(e, "xmlns", "http://www.w3.org/2000/svg"); + e = M("svg"), n = M("path"), r = M("path"), c(n, "d", "M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"), c(n, "fill", "currentColor"), c(n, "opacity", ".25"), c(r, "d", "M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"), c(r, "fill", "currentColor"), c(r, "class", "altcha-spinner svelte-vuofbg"), c(e, "width", "24"), c(e, "height", "24"), c(e, "viewBox", "0 0 24 24"), c(e, "xmlns", "http://www.w3.org/2000/svg"); }, - m(l, r) { - N(l, e, r), b(e, n), b(e, i); + m(l, o) { + L(l, e, o), m(e, n), m(e, r); }, d(l) { - l && L(e); + l && E(e); } }; } -function mt(t) { +function vt(t) { let e, n = ( /*_strings*/ t[9].label + "" - ), i; + ), r; return { c() { - e = $("label"), c(e, "for", i = /*name*/ + e = w("label"), c(e, "for", r = /*name*/ t[3] + "_checkbox"), c(e, "class", "svelte-vuofbg"); }, - m(l, r) { - N(l, e, r), e.innerHTML = n; + m(l, o) { + L(l, e, o), e.innerHTML = n; }, - p(l, r) { - r[0] & /*_strings*/ + p(l, o) { + o[0] & /*_strings*/ 512 && n !== (n = /*_strings*/ - l[9].label + "") && (e.innerHTML = n), r[0] & /*name*/ - 8 && i !== (i = /*name*/ - l[3] + "_checkbox") && c(e, "for", i); + l[9].label + "") && (e.innerHTML = n), o[0] & /*name*/ + 8 && r !== (r = /*name*/ + l[3] + "_checkbox") && c(e, "for", r); }, d(l) { - l && L(e); + l && E(e); } }; } -function vt(t) { +function _t(t) { let e, n = ( /*_strings*/ t[9].verifying + "" ); return { c() { - e = $("span"); + e = w("span"); }, - m(i, l) { - N(i, e, l), e.innerHTML = n; + m(r, l) { + L(r, e, l), e.innerHTML = n; }, - p(i, l) { + p(r, l) { l[0] & /*_strings*/ 512 && n !== (n = /*_strings*/ - i[9].verifying + "") && (e.innerHTML = n); + r[9].verifying + "") && (e.innerHTML = n); }, - d(i) { - i && L(e); + d(r) { + r && E(e); } }; } -function _t(t) { +function wt(t) { let e, n = ( /*_strings*/ t[9].verified + "" - ), i, l; + ), r, l; return { c() { - e = $("span"), i = M(), l = $("input"), c(l, "type", "hidden"), c( + e = w("span"), r = U(), l = w("input"), c(l, "type", "hidden"), c( l, "name", /*name*/ @@ -589,379 +589,456 @@ function _t(t) { ), l.value = /*payload*/ t[4]; }, - m(r, s) { - N(r, e, s), e.innerHTML = n, N(r, i, s), N(r, l, s); + m(o, s) { + L(o, e, s), e.innerHTML = n, L(o, r, s), L(o, l, s); }, - p(r, s) { + p(o, s) { s[0] & /*_strings*/ 512 && n !== (n = /*_strings*/ - r[9].verified + "") && (e.innerHTML = n), s[0] & /*name*/ + o[9].verified + "") && (e.innerHTML = n), s[0] & /*name*/ 8 && c( l, "name", /*name*/ - r[3] + o[3] ), s[0] & /*payload*/ 16 && (l.value = /*payload*/ - r[4]); + o[4]); }, - d(r) { - r && (L(e), L(i), L(l)); + d(o) { + o && (E(e), E(r), E(l)); } }; } -function de(t) { - let e, n, i, l, r, s; +function ge(t) { + let e, n, r, l, o, s; return { c() { - e = $("div"), n = $("a"), i = V("svg"), l = V("path"), r = V("path"), s = V("path"), c(l, "d", "M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"), c(l, "fill", "currentColor"), c(r, "d", "M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"), c(r, "fill", "currentColor"), c(s, "d", "M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"), c(s, "fill", "currentColor"), c(i, "width", "22"), c(i, "height", "22"), c(i, "viewBox", "0 0 20 20"), c(i, "fill", "none"), c(i, "xmlns", "http://www.w3.org/2000/svg"), c(n, "href", Ee), c(n, "target", "_blank"), c(n, "class", "altcha-logo svelte-vuofbg"); + e = w("div"), n = w("a"), r = M("svg"), l = M("path"), o = M("path"), s = M("path"), c(l, "d", "M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"), c(l, "fill", "currentColor"), c(o, "d", "M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"), c(o, "fill", "currentColor"), c(s, "d", "M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"), c(s, "fill", "currentColor"), c(r, "width", "22"), c(r, "height", "22"), c(r, "viewBox", "0 0 20 20"), c(r, "fill", "none"), c(r, "xmlns", "http://www.w3.org/2000/svg"), c(n, "href", xe), c(n, "target", "_blank"), c(n, "class", "altcha-logo svelte-vuofbg"); }, - m(a, h) { - N(a, e, h), b(e, n), b(n, i), b(i, l), b(i, r), b(i, s); + m(u, h) { + L(u, e, h), m(e, n), m(n, r), m(r, l), m(r, o), m(r, s); }, p: H, - d(a) { - a && L(e); + d(u) { + u && E(e); } }; } -function ge(t) { - let e, n, i, l, r; +function be(t) { + let e, n, r, l; + function o(h, a) { + return ( + /*state*/ + h[5] === b.EXPIRED ? pt : $t + ); + } + let s = o(t), u = s(t); return { c() { - e = $("div"), n = V("svg"), i = V("path"), l = M(), r = $("div"), c(i, "stroke-linecap", "round"), c(i, "stroke-linejoin", "round"), c(i, "d", "M6 18L18 6M6 6l12 12"), c(n, "width", "14"), c(n, "height", "14"), c(n, "xmlns", "http://www.w3.org/2000/svg"), c(n, "fill", "none"), c(n, "viewBox", "0 0 24 24"), c(n, "stroke-width", "1.5"), c(n, "stroke", "currentColor"), c(e, "class", "altcha-error svelte-vuofbg"); + e = w("div"), n = M("svg"), r = M("path"), l = U(), u.c(), c(r, "stroke-linecap", "round"), c(r, "stroke-linejoin", "round"), c(r, "d", "M6 18L18 6M6 6l12 12"), c(n, "width", "14"), c(n, "height", "14"), c(n, "xmlns", "http://www.w3.org/2000/svg"), c(n, "fill", "none"), c(n, "viewBox", "0 0 24 24"), c(n, "stroke-width", "1.5"), c(n, "stroke", "currentColor"), c(e, "class", "altcha-error svelte-vuofbg"); }, - m(s, a) { - N(s, e, a), b(e, n), b(n, i), b(e, l), b(e, r), r.innerHTML = /*error*/ - t[8]; + m(h, a) { + L(h, e, a), m(e, n), m(n, r), m(e, l), u.m(e, null); }, - p(s, a) { - a[0] & /*error*/ - 256 && (r.innerHTML = /*error*/ - s[8]); + p(h, a) { + s === (s = o(h)) && u ? u.p(h, a) : (u.d(1), u = s(h), u && (u.c(), u.m(e, null))); }, - d(s) { - s && L(e); + d(h) { + h && E(e), u.d(); } }; } -function be(t) { - let e, n, i = ( +function $t(t) { + let e, n = ( + /*_strings*/ + t[9].error + "" + ); + return { + c() { + e = w("div"), c( + e, + "title", + /*error*/ + t[8] + ); + }, + m(r, l) { + L(r, e, l), e.innerHTML = n; + }, + p(r, l) { + l[0] & /*_strings*/ + 512 && n !== (n = /*_strings*/ + r[9].error + "") && (e.innerHTML = n), l[0] & /*error*/ + 256 && c( + e, + "title", + /*error*/ + r[8] + ); + }, + d(r) { + r && E(e); + } + }; +} +function pt(t) { + let e, n = ( + /*_strings*/ + t[9].expired + "" + ); + return { + c() { + e = w("div"), c( + e, + "title", + /*error*/ + t[8] + ); + }, + m(r, l) { + L(r, e, l), e.innerHTML = n; + }, + p(r, l) { + l[0] & /*_strings*/ + 512 && n !== (n = /*_strings*/ + r[9].expired + "") && (e.innerHTML = n), l[0] & /*error*/ + 256 && c( + e, + "title", + /*error*/ + r[8] + ); + }, + d(r) { + r && E(e); + } + }; +} +function me(t) { + let e, n, r = ( /*_strings*/ t[9].footer + "" ); return { c() { - e = $("div"), n = $("div"), c(n, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); + e = w("div"), n = w("div"), c(n, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); }, - m(l, r) { - N(l, e, r), b(e, n), n.innerHTML = i; + m(l, o) { + L(l, e, o), m(e, n), n.innerHTML = r; }, - p(l, r) { - r[0] & /*_strings*/ - 512 && i !== (i = /*_strings*/ - l[9].footer + "") && (n.innerHTML = i); + p(l, o) { + o[0] & /*_strings*/ + 512 && r !== (r = /*_strings*/ + l[9].footer + "") && (n.innerHTML = r); }, d(l) { - l && L(e); + l && E(e); } }; } -function wt(t) { - let e, n, i, l, r, s, a, h, f, R, p, j, C, A, v = ( +function yt(t) { + let e, n, r, l, o, s, u, h, a, x, y, A, G, N, _ = ( /*state*/ - t[5] === w.VERIFYING && he() + t[5] === b.VERIFYING && de() ); - function G(u, y) { + function S(f, p) { return ( /*state*/ - u[5] === w.VERIFIED ? _t : ( + f[5] === b.VERIFIED ? wt : ( /*state*/ - u[5] === w.VERIFYING ? vt : mt + f[5] === b.VERIFYING ? _t : vt ) ); } - let U = G(t), k = U(t), _ = ( + let j = S(t), C = j(t), $ = ( /*hidelogo*/ - t[2] !== !0 && de() + t[2] !== !0 && ge() ), g = ( /*error*/ - t[8] && ge(t) - ), m = ( + (t[8] || /*state*/ + t[5] === b.EXPIRED) && be(t) + ), v = ( /*_strings*/ t[9].footer && /*hidefooter*/ - t[1] !== !0 && be(t) + t[1] !== !0 && me(t) ); return { c() { - e = $("div"), n = $("div"), v && v.c(), i = M(), l = $("div"), r = $("input"), h = M(), f = $("div"), k.c(), R = M(), _ && _.c(), p = M(), g && g.c(), j = M(), m && m.c(), c(r, "type", "checkbox"), c(r, "id", s = /*name*/ - t[3] + "_checkbox"), r.required = a = /*auto*/ - t[0] !== "onsubmit", c(r, "class", "svelte-vuofbg"), c(l, "class", "altcha-checkbox svelte-vuofbg"), ue( + e = w("div"), n = w("div"), _ && _.c(), r = U(), l = w("div"), o = w("input"), h = U(), a = w("div"), C.c(), x = U(), $ && $.c(), y = U(), g && g.c(), A = U(), v && v.c(), c(o, "type", "checkbox"), c(o, "id", s = /*name*/ + t[3] + "_checkbox"), o.required = u = /*auto*/ + t[0] !== "onsubmit", c(o, "class", "svelte-vuofbg"), c(l, "class", "altcha-checkbox svelte-vuofbg"), ae( l, "altcha-hidden", /*state*/ - t[5] === w.VERIFYING - ), c(f, "class", "altcha-label svelte-vuofbg"), c(n, "class", "altcha-main svelte-vuofbg"), c(e, "class", "altcha svelte-vuofbg"), c( + t[5] === b.VERIFYING + ), c(a, "class", "altcha-label svelte-vuofbg"), c(n, "class", "altcha-main svelte-vuofbg"), c(e, "class", "altcha svelte-vuofbg"), c( e, "data-state", /*state*/ t[5] ); }, - m(u, y) { - N(u, e, y), b(e, n), v && v.m(n, null), b(n, i), b(n, l), b(l, r), r.checked = /*checked*/ - t[6], b(n, h), b(n, f), k.m(f, null), b(n, R), _ && _.m(n, null), b(e, p), g && g.m(e, null), b(e, j), m && m.m(e, null), t[24](e), C || (A = [ - z( - r, + m(f, p) { + L(f, e, p), m(e, n), _ && _.m(n, null), m(n, r), m(n, l), m(l, o), o.checked = /*checked*/ + t[6], m(n, h), m(n, a), C.m(a, null), m(n, x), $ && $.m(n, null), m(e, y), g && g.m(e, null), m(e, A), v && v.m(e, null), t[25](e), G || (N = [ + Q( + o, "change", /*input_change_handler*/ - t[23] + t[24] ), - z( - r, + Q( + o, "change", /*onCheckedChange*/ t[10] ), - z( - r, + Q( + o, "invalid", /*onInvalid*/ t[11] ) - ], C = !0); + ], G = !0); }, - p(u, y) { + p(f, p) { /*state*/ - u[5] === w.VERIFYING ? v || (v = he(), v.c(), v.m(n, i)) : v && (v.d(1), v = null), y[0] & /*name*/ + f[5] === b.VERIFYING ? _ || (_ = de(), _.c(), _.m(n, r)) : _ && (_.d(1), _ = null), p[0] & /*name*/ 8 && s !== (s = /*name*/ - u[3] + "_checkbox") && c(r, "id", s), y[0] & /*auto*/ - 1 && a !== (a = /*auto*/ - u[0] !== "onsubmit") && (r.required = a), y[0] & /*checked*/ - 64 && (r.checked = /*checked*/ - u[6]), y[0] & /*state*/ - 32 && ue( + f[3] + "_checkbox") && c(o, "id", s), p[0] & /*auto*/ + 1 && u !== (u = /*auto*/ + f[0] !== "onsubmit") && (o.required = u), p[0] & /*checked*/ + 64 && (o.checked = /*checked*/ + f[6]), p[0] & /*state*/ + 32 && ae( l, "altcha-hidden", /*state*/ - u[5] === w.VERIFYING - ), U === (U = G(u)) && k ? k.p(u, y) : (k.d(1), k = U(u), k && (k.c(), k.m(f, null))), /*hidelogo*/ - u[2] !== !0 ? _ ? _.p(u, y) : (_ = de(), _.c(), _.m(n, null)) : _ && (_.d(1), _ = null), /*error*/ - u[8] ? g ? g.p(u, y) : (g = ge(u), g.c(), g.m(e, j)) : g && (g.d(1), g = null), /*_strings*/ - u[9].footer && /*hidefooter*/ - u[1] !== !0 ? m ? m.p(u, y) : (m = be(u), m.c(), m.m(e, null)) : m && (m.d(1), m = null), y[0] & /*state*/ + f[5] === b.VERIFYING + ), j === (j = S(f)) && C ? C.p(f, p) : (C.d(1), C = j(f), C && (C.c(), C.m(a, null))), /*hidelogo*/ + f[2] !== !0 ? $ ? $.p(f, p) : ($ = ge(), $.c(), $.m(n, null)) : $ && ($.d(1), $ = null), /*error*/ + f[8] || /*state*/ + f[5] === b.EXPIRED ? g ? g.p(f, p) : (g = be(f), g.c(), g.m(e, A)) : g && (g.d(1), g = null), /*_strings*/ + f[9].footer && /*hidefooter*/ + f[1] !== !0 ? v ? v.p(f, p) : (v = me(f), v.c(), v.m(e, null)) : v && (v.d(1), v = null), p[0] & /*state*/ 32 && c( e, "data-state", /*state*/ - u[5] + f[5] ); }, i: H, o: H, - d(u) { - u && L(e), v && v.d(), k.d(), _ && _.d(), g && g.d(), m && m.d(), t[24](null), C = !1, T(A); + d(f) { + f && E(e), _ && _.d(), C.d(), $ && $.d(), g && g.d(), v && v.d(), t[25](null), G = !1, X(N); } }; } -const Ee = "https://altcha.org/"; -function me(t) { +const xe = "https://altcha.org/"; +function ve(t) { return JSON.parse(t); } -function $t(t, e, n) { - let i, l, r, { auto: s = void 0 } = e, { challengeurl: a = void 0 } = e, { challengejson: h = void 0 } = e, { debug: f = !1 } = e, { hidefooter: R = !1 } = e, { hidelogo: p = !1 } = e, { name: j = "altcha" } = e, { maxnumber: C = void 0 } = e, { mockerror: A = !1 } = e, { strings: v = void 0 } = e, { test: G = !1 } = e; - const U = Ke(), k = ["SHA-256", "SHA-384", "SHA-512"], _ = []; - let g = !1, m, u = null, y = null, F = null, S = w.UNVERIFIED, ne; - Xe(() => { - u && (u.removeEventListener("submit", re), u.removeEventListener("reset", ie), u = null); - }), Te(() => { - E("mounted", "0.1.9"), G && E("using test mode"), s !== void 0 && E("auto", s), u = m.closest("form"), u && (u.addEventListener("submit", re), u.addEventListener("reset", ie)), s === "onload" && W(); +function kt(t, e, n) { + let r, l, o, { auto: s = void 0 } = e, { challengeurl: u = void 0 } = e, { challengejson: h = void 0 } = e, { debug: a = !1 } = e, { expire: x = void 0 } = e, { hidefooter: y = !1 } = e, { hidelogo: A = !1 } = e, { name: G = "altcha" } = e, { maxnumber: N = void 0 } = e, { mockerror: _ = !1 } = e, { strings: S = void 0 } = e, { test: j = !1 } = e; + const C = ze(), $ = ["SHA-256", "SHA-384", "SHA-512"]; + let g = !1, v, f = null, p = null, F = null, V = b.UNVERIFIED, z; + Ke(() => { + f && (f.removeEventListener("submit", ie), f.removeEventListener("reset", le), f = null); + }), We(() => { + I("mounted", "0.1.9"), j && I("using test mode"), x && J(x), s !== void 0 && I("auto", s), f = v.closest("form"), f && (f.addEventListener("submit", ie), f.addEventListener("reset", le)), s === "onload" && T(); }); - function E(...o) { - (f || o.some((d) => d instanceof Error)) && console[o[0] instanceof Error ? "error" : "log"]("ALTCHA", ...o); + function I(...i) { + (a || i.some((d) => d instanceof Error)) && console[i[0] instanceof Error ? "error" : "log"]("ALTCHA", ...i); } - function re(o) { - u && s === "onsubmit" && S === w.UNVERIFIED && (o.preventDefault(), o.stopPropagation(), W().then(() => { - u == null || u.requestSubmit(); + function ie(i) { + f && s === "onsubmit" && V === b.UNVERIFIED && (i.preventDefault(), i.stopPropagation(), T().then(() => { + f == null || f.requestSubmit(); })); } - function ie() { - X(); + function le() { + W(); } - function xe(o, d) { + function Ce(i, d) { return btoa(JSON.stringify({ - algorithm: o.algorithm, - challenge: o.challenge, + algorithm: i.algorithm, + challenge: i.challenge, number: d.number, - salt: o.salt, - signature: o.signature, - test: G ? !0 : void 0, + salt: i.salt, + signature: i.signature, + test: j ? !0 : void 0, took: d.took })); } - function oe(o) { - if (!o.algorithm) + function oe(i) { + if (!i.algorithm) throw new Error("Invalid challenge. Property algorithm is missing."); - if (o.signature === void 0) + if (i.signature === void 0) throw new Error("Invalid challenge. Property signature is missing."); - if (!k.includes(o.algorithm.toUpperCase())) - throw new Error(`Unknown algorithm value. Allowed values: ${k.join(", ")}`); - if (!o.challenge || o.challenge.length < 40) + if (!$.includes(i.algorithm.toUpperCase())) + throw new Error(`Unknown algorithm value. Allowed values: ${$.join(", ")}`); + if (!i.challenge || i.challenge.length < 40) throw new Error("Challenge is too short. Min. 40 chars."); - if (!o.salt || o.salt.length < 10) + if (!i.salt || i.salt.length < 10) throw new Error("Salt is too short. Min. 10 chars."); } - async function Ce() { - if (A) - throw E("mocking error"), new Error("Mocked error."); - if (i) - return E("using provided json data"), i; - if (G) - return E("generating test challenge"), dt(); + async function Ie() { + if (_) + throw I("mocking error"), new Error("Mocked error."); + if (r) + return I("using provided json data"), r; + if (j) + return I("generating test challenge"), gt(); { - if (!a) + if (!u) throw new Error("Attribute challengeurl not set."); - E("fetching challenge from", a); - const o = await fetch(a); - if (o.status !== 200) - throw new Error(`Server responded with ${o.status}.`); - const d = o.headers.get("Expires"); - if (d.length) { - const O = Date.parse(d) - Date.now(); - O < 1 ? le() : ne = setTimeout(le, O); + I("fetching challenge from", u); + const i = await fetch(u); + if (i.status !== 200) + throw new Error(`Server responded with ${i.status}.`); + const d = i.headers.get("Expires"); + if (d != null && d.length) { + const O = Date.parse(d); + isNaN(O) || J(O - Date.now()); } - return o.json(); + return i.json(); } } - function le() { - X(w.EXPIRED, r.expired); + function se() { + W(b.EXPIRED, o.expired); } - async function Ie(o) { + async function Le(i) { let d = null; if ("Worker" in window) { try { - d = await Le(o.challenge, o.salt, o.algorithm); + d = await Re(i.challenge, i.salt, i.algorithm); } catch (O) { - E(O); + I(O); } if ((d == null ? void 0 : d.number) !== void 0) - return { data: o, solution: d }; + return { data: i, solution: d }; } return { - data: o, - solution: await gt(o.challenge, o.salt, o.algorithm, C) + data: i, + solution: await bt(i.challenge, i.salt, i.algorithm, N) }; } - async function Le(o, d, O) { - const se = _.push(new ut()); + async function Re(i, d, O) { + const ce = new at(); return new Promise((Ve) => { - _[se - 1].addEventListener("message", (Se) => { + ce.addEventListener("message", (Se) => { Ve(Se.data); - }), _[se - 1].postMessage({ alg: O, challenge: o, max: C, salt: d }); + }), ce.postMessage({ alg: O, challenge: i, max: N, salt: d }); }); } - function Re() { - [w.UNVERIFIED, w.ERROR, w.EXPIRED].includes(S) ? W() : n(6, g = !0); - } function Ne() { - S === w.VERIFYING && alert(r.waitAlert); + [b.UNVERIFIED, b.ERROR, b.EXPIRED].includes(V) ? T() : n(6, g = !0); } - function je(o) { - o.auto !== void 0 && (n(0, s = o.auto), s === "onload" && W()), o.challenge && (oe(o.challenge), i = o.challenge), o.debug !== void 0 && n(12, f = !!o.debug), o.hidefooter !== void 0 && n(1, R = !!o.hidefooter), o.hidelogo !== void 0 && n(2, p = !!o.hidelogo), o.maxnumber !== void 0 && n(13, C = +o.maxnumber), o.mockerror !== void 0 && n(14, A = !!o.mockerror), o.name !== void 0 && n(3, j = o.name), o.test !== void 0 && n(15, G = !!o.test), o.strings && n(22, l = o.strings); + function je() { + V === b.VERIFYING && alert(o.waitAlert); } - function X(o = w.UNVERIFIED, d = null) { - clearTimeout(ne), n(6, g = !1), n(8, y = d), n(4, F = null), n(5, S = o); + function J(i) { + clearTimeout(z), i < 1 ? se() : z = setTimeout(se, i); } - async function W() { - return X(w.VERIFYING), Ce().then((o) => (oe(o), E("challenge", o), Ie(o))).then(({ data: o, solution: d }) => { - if (E("solution", d), (d == null ? void 0 : d.number) !== void 0) - E("verified"), n(5, S = w.VERIFIED), n(6, g = !0), n(4, F = xe(o, d)), E("payload", F), ze().then(() => { - U("verified", { payload: F }); + function Ae(i) { + i.auto !== void 0 && (n(0, s = i.auto), s === "onload" && T()), i.expire !== void 0 && (J(i.expire), n(13, x = i.expire)), i.challenge && (oe(i.challenge), r = i.challenge), i.debug !== void 0 && n(12, a = !!i.debug), i.hidefooter !== void 0 && n(1, y = !!i.hidefooter), i.hidelogo !== void 0 && n(2, A = !!i.hidelogo), i.maxnumber !== void 0 && n(14, N = +i.maxnumber), i.mockerror !== void 0 && n(15, _ = !!i.mockerror), i.name !== void 0 && n(3, G = i.name), i.test !== void 0 && n(16, j = !!i.test), i.strings && n(23, l = i.strings); + } + function W(i = b.UNVERIFIED, d = null) { + clearTimeout(z), n(6, g = !1), n(8, p = d), n(4, F = null), n(5, V = i); + } + async function T() { + return W(b.VERIFYING), Ie().then((i) => (oe(i), I("challenge", i), Le(i))).then(({ data: i, solution: d }) => { + if (I("solution", d), (d == null ? void 0 : d.number) !== void 0) + I("verified"), n(5, V = b.VERIFIED), n(6, g = !0), n(4, F = Ce(i, d)), I("payload", F), Je().then(() => { + C("verified", { payload: F }); }); else throw new Error("Unexpected result returned."); - }).catch((o) => { - E(o), n(5, S = w.ERROR), n(6, g = !1), n(8, y = o.message); + }).catch((i) => { + I(i), n(5, V = b.ERROR), n(6, g = !1), n(8, p = i.message); }); } - function Ae() { + function Ge() { g = this.checked, n(6, g); } - function Ge(o) { - Q[o ? "unshift" : "push"](() => { - m = o, n(7, m); + function Me(i) { + ee[i ? "unshift" : "push"](() => { + v = i, n(7, v); }); } - return t.$$set = (o) => { - "auto" in o && n(0, s = o.auto), "challengeurl" in o && n(16, a = o.challengeurl), "challengejson" in o && n(17, h = o.challengejson), "debug" in o && n(12, f = o.debug), "hidefooter" in o && n(1, R = o.hidefooter), "hidelogo" in o && n(2, p = o.hidelogo), "name" in o && n(3, j = o.name), "maxnumber" in o && n(13, C = o.maxnumber), "mockerror" in o && n(14, A = o.mockerror), "strings" in o && n(18, v = o.strings), "test" in o && n(15, G = o.test); + return t.$$set = (i) => { + "auto" in i && n(0, s = i.auto), "challengeurl" in i && n(17, u = i.challengeurl), "challengejson" in i && n(18, h = i.challengejson), "debug" in i && n(12, a = i.debug), "expire" in i && n(13, x = i.expire), "hidefooter" in i && n(1, y = i.hidefooter), "hidelogo" in i && n(2, A = i.hidelogo), "name" in i && n(3, G = i.name), "maxnumber" in i && n(14, N = i.maxnumber), "mockerror" in i && n(15, _ = i.mockerror), "strings" in i && n(19, S = i.strings), "test" in i && n(16, j = i.test); }, t.$$.update = () => { t.$$.dirty[0] & /*challengejson*/ - 131072 && (i = h ? me(h) : void 0), t.$$.dirty[0] & /*strings*/ - 262144 && n(22, l = v ? me(v) : {}), t.$$.dirty[0] & /*parsedStrings*/ - 4194304 && n(9, r = { + 262144 && (r = h ? ve(h) : void 0), t.$$.dirty[0] & /*strings*/ + 524288 && n(23, l = S ? ve(S) : {}), t.$$.dirty[0] & /*parsedStrings*/ + 8388608 && n(9, o = { error: "Verification failed. Try again later.", expired: "Verification expired. Try again.", - footer: `Protected by ALTCHA`, + footer: `Protected by ALTCHA`, label: "I'm not a robot", verified: "Verified", verifying: "Verifying...", waitAlert: "Verifying... please wait.", ...l }), t.$$.dirty[0] & /*payload, state*/ - 48 && U("statechange", { payload: F, state: S }); + 48 && C("statechange", { payload: F, state: V }); }, [ s, - R, - p, - j, - F, - S, - g, - m, y, - r, - Re, - Ne, - f, - C, A, G, - a, - h, + F, + V, + g, v, + p, + o, + Ne, je, - X, + a, + x, + N, + _, + j, + u, + h, + S, + Ae, W, + T, l, - Ae, - Ge + Ge, + Me ]; } -class yt extends lt { +class Et extends st { constructor(e) { - super(), it( + super(), lt( this, e, - $t, - wt, - Fe, + kt, + yt, + Oe, { auto: 0, - challengeurl: 16, - challengejson: 17, + challengeurl: 17, + challengejson: 18, debug: 12, + expire: 13, hidefooter: 1, hidelogo: 2, name: 3, - maxnumber: 13, - mockerror: 14, - strings: 18, - test: 15, - configure: 19, - reset: 20, - verify: 21 + maxnumber: 14, + mockerror: 15, + strings: 19, + test: 16, + configure: 20, + reset: 21, + verify: 22 }, - bt, + mt, [-1, -1] ); } @@ -969,79 +1046,85 @@ class yt extends lt { return this.$$.ctx[0]; } set auto(e) { - this.$$set({ auto: e }), x(); + this.$$set({ auto: e }), k(); } get challengeurl() { - return this.$$.ctx[16]; + return this.$$.ctx[17]; } set challengeurl(e) { - this.$$set({ challengeurl: e }), x(); + this.$$set({ challengeurl: e }), k(); } get challengejson() { - return this.$$.ctx[17]; + return this.$$.ctx[18]; } set challengejson(e) { - this.$$set({ challengejson: e }), x(); + this.$$set({ challengejson: e }), k(); } get debug() { return this.$$.ctx[12]; } set debug(e) { - this.$$set({ debug: e }), x(); + this.$$set({ debug: e }), k(); + } + get expire() { + return this.$$.ctx[13]; + } + set expire(e) { + this.$$set({ expire: e }), k(); } get hidefooter() { return this.$$.ctx[1]; } set hidefooter(e) { - this.$$set({ hidefooter: e }), x(); + this.$$set({ hidefooter: e }), k(); } get hidelogo() { return this.$$.ctx[2]; } set hidelogo(e) { - this.$$set({ hidelogo: e }), x(); + this.$$set({ hidelogo: e }), k(); } get name() { return this.$$.ctx[3]; } set name(e) { - this.$$set({ name: e }), x(); + this.$$set({ name: e }), k(); } get maxnumber() { - return this.$$.ctx[13]; + return this.$$.ctx[14]; } set maxnumber(e) { - this.$$set({ maxnumber: e }), x(); + this.$$set({ maxnumber: e }), k(); } get mockerror() { - return this.$$.ctx[14]; + return this.$$.ctx[15]; } set mockerror(e) { - this.$$set({ mockerror: e }), x(); + this.$$set({ mockerror: e }), k(); } get strings() { - return this.$$.ctx[18]; + return this.$$.ctx[19]; } set strings(e) { - this.$$set({ strings: e }), x(); + this.$$set({ strings: e }), k(); } get test() { - return this.$$.ctx[15]; + return this.$$.ctx[16]; } set test(e) { - this.$$set({ test: e }), x(); + this.$$set({ test: e }), k(); } get configure() { - return this.$$.ctx[19]; + return this.$$.ctx[20]; } get reset() { - return this.$$.ctx[20]; + return this.$$.ctx[21]; } get verify() { - return this.$$.ctx[21]; + return this.$$.ctx[22]; } } -customElements.define("altcha-widget", ot(yt, { auto: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, hidefooter: { type: "Boolean" }, hidelogo: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" } }, [], ["configure", "reset", "verify"], !1)); +customElements.define("altcha-widget", ot(Et, { auto: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, expire: {}, hidefooter: { type: "Boolean" }, hidelogo: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" } }, [], ["configure", "reset", "verify"], !1)); export { - yt as Altcha + Et as Altcha }; diff --git a/dist/altcha.umd.cjs b/dist/altcha.umd.cjs index 346f94f..9d5c6ff 100644 --- a/dist/altcha.umd.cjs +++ b/dist/altcha.umd.cjs @@ -1 +1 @@ -(function(I,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(I=typeof globalThis<"u"?globalThis:I||self,v(I.altcha={}))})(this,function(I){"use strict";var yt=Object.defineProperty;var pt=(I,v,U)=>v in I?yt(I,v,{enumerable:!0,configurable:!0,writable:!0,value:U}):I[v]=U;var N=(I,v,U)=>(pt(I,typeof v!="symbol"?v+"":v,U),U);function v(){}function U(t){return t()}function ie(){return Object.create(null)}function P(t){t.forEach(U)}function oe(t){return typeof t=="function"}function Ie(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Le(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function Re(t,e,n){const i=Ne(t);if(!i.getElementById(e)){const l=y("style");l.id=e,l.textContent=n,je(i,l)}}function Ne(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function je(t,e){return g(t.head||t,e),e.sheet}function j(t,e,n){t.insertBefore(e,n||null)}function L(t){t.parentNode&&t.parentNode.removeChild(t)}function y(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Ae(t){return document.createTextNode(t)}function F(){return Ae(" ")}function Q(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ge(t){return Array.from(t.childNodes)}function le(t,e,n){t.classList.toggle(e,!!n)}function Se(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function Ve(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let D;function X(t){D=t}function q(){if(!D)throw new Error("Function called outside component initialization");return D}function Me(t){q().$$.on_mount.push(t)}function Ue(t){q().$$.on_destroy.push(t)}function Oe(){const t=q();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Se(e,n,{cancelable:i});return l.slice().forEach(s=>{s.call(t,r)}),!r.defaultPrevented}return!0}}const Z=[],ee=[];let B=[];const se=[],ce=Promise.resolve();let te=!1;function ue(){te||(te=!0,ce.then(E))}function Fe(){return ue(),ce}function ne(t){B.push(t)}const re=new Set;let H=0;function E(){if(H!==0)return;const t=D;do{try{for(;Ht.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Be=new Set;function He(t,e){t&&t.i&&(Be.delete(t),t.i(e))}function Te(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),ne(()=>{const r=t.$$.on_mount.map(U).filter(oe);t.$$.on_destroy?t.$$.on_destroy.push(...r):P(r),t.$$.on_mount=[]}),l.forEach(ne)}function We(t,e){const n=t.$$;n.fragment!==null&&(Ze(n.after_update),P(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Pe(t,e){t.$$.dirty[0]===-1&&(Z.push(t),ue(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const S=R.length?R[0]:G;return f.ctx&&l(f.ctx[k],f.ctx[k]=S)&&(!f.skip_bound&&f.bound[k]&&f.bound[k](S),A&&Pe(t,k)),G}):[],f.update(),A=!0,P(f.before_update),f.fragment=i?i(f.ctx):!1,e.target){if(e.hydrate){const k=Ge(e.target);f.fragment&&f.fragment.l(k),k.forEach(L)}else f.fragment&&f.fragment.c();e.intro&&He(t.$$.fragment),Te(t,e.target,e.anchor),E()}X(h)}let ae;typeof HTMLElement=="function"&&(ae=class extends HTMLElement{constructor(e,n,i){super();N(this,"$$ctor");N(this,"$$s");N(this,"$$c");N(this,"$$cn",!1);N(this,"$$d",{});N(this,"$$r",!1);N(this,"$$p_d",{});N(this,"$$l",{});N(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let s;return{c:function(){s=y("slot"),r!=="default"&&c(s,"name",r)},m:function(f,A){j(f,s,A)},d:function(f){f&&L(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},i=Ve(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const s=this.$$g_p(r.name);s in this.$$d||(this.$$d[s]=z(s,r.value,this.$$p_d,"toProp"))}for(const r in this.$$p_d)!(r in this.$$d)&&this[r]!==void 0&&(this.$$d[r]=this[r],delete this[r]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const s=z(r,this.$$d[r],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const s of this.$$l[r]){const a=this.$$c.$on(r,s);this.$$l_u.set(s,a)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=z(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function z(t,e,n,i){var r;const l=(r=n[t])==null?void 0:r.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Xe(t,e,n,i,l,r){let s=class extends ae{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(s.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(h){var f;h=z(a,h,e),this.$$d[a]=h,(f=this.$$c)==null||f.$set({[a]:h})}})}),i.forEach(a=>{Object.defineProperty(s.prototype,a,{get(){var h;return(h=this.$$c)==null?void 0:h[a]}})}),r&&(s=r(s)),t.element=s,s}class Ke{constructor(){N(this,"$$");N(this,"$$set")}$destroy(){We(this,1),this.$destroy=v}$on(e,n){if(!oe(n))return v;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const l=i.indexOf(n);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Le(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ze="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ze);const fe="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",Je=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),he=typeof window<"u"&&window.Blob&&new Blob([Je(fe)],{type:"text/javascript;charset=utf-8"});function Qe(t){let e;try{if(e=he&&(window.URL||window.webkitURL).createObjectURL(he),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+fe,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const qe=1e7,et=new TextEncoder;function tt(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function nt(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await de(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function de(t,e,n){return tt(await crypto.subtle.digest(n.toUpperCase(),et.encode(t+e)))}async function rt(t,e,n="SHA-256",i=qe){const l=Date.now();for(let r=0;r<=i;r++)if(await de(e,r,n)===t)return{number:r,took:Date.now()-l};return null}var _=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(_||{});function it(t){Re(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function ge(t){let e,n,i;return{c(){e=V("svg"),n=V("path"),i=V("path"),c(n,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(n,"fill","currentColor"),c(n,"opacity",".25"),c(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(i,"fill","currentColor"),c(i,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,r){j(l,e,r),g(e,n),g(e,i)},d(l){l&&L(e)}}}function ot(t){let e,n=t[9].label+"",i;return{c(){e=y("label"),c(e,"for",i=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(l,r){j(l,e,r),e.innerHTML=n},p(l,r){r[0]&512&&n!==(n=l[9].label+"")&&(e.innerHTML=n),r[0]&8&&i!==(i=l[3]+"_checkbox")&&c(e,"for",i)},d(l){l&&L(e)}}}function lt(t){let e,n=t[9].verifying+"";return{c(){e=y("span")},m(i,l){j(i,e,l),e.innerHTML=n},p(i,l){l[0]&512&&n!==(n=i[9].verifying+"")&&(e.innerHTML=n)},d(i){i&&L(e)}}}function st(t){let e,n=t[9].verified+"",i,l;return{c(){e=y("span"),i=F(),l=y("input"),c(l,"type","hidden"),c(l,"name",t[3]),l.value=t[4]},m(r,s){j(r,e,s),e.innerHTML=n,j(r,i,s),j(r,l,s)},p(r,s){s[0]&512&&n!==(n=r[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(l,"name",r[3]),s[0]&16&&(l.value=r[4])},d(r){r&&(L(e),L(i),L(l))}}}function be(t){let e,n,i,l,r,s;return{c(){e=y("div"),n=y("a"),i=V("svg"),l=V("path"),r=V("path"),s=V("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(r,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(r,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(i,"width","22"),c(i,"height","22"),c(i,"viewBox","0 0 20 20"),c(i,"fill","none"),c(i,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",_e),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(a,h){j(a,e,h),g(e,n),g(n,i),g(i,l),g(i,r),g(i,s)},p:v,d(a){a&&L(e)}}}function me(t){let e,n,i,l,r;return{c(){e=y("div"),n=V("svg"),i=V("path"),l=F(),r=y("div"),c(i,"stroke-linecap","round"),c(i,"stroke-linejoin","round"),c(i,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(s,a){j(s,e,a),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=t[8]},p(s,a){a[0]&256&&(r.innerHTML=s[8])},d(s){s&&L(e)}}}function ve(t){let e,n,i=t[9].footer+"";return{c(){e=y("div"),n=y("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(l,r){j(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&512&&i!==(i=l[9].footer+"")&&(n.innerHTML=i)},d(l){l&&L(e)}}}function ct(t){let e,n,i,l,r,s,a,h,f,A,k,G,R,S,w=t[5]===_.VERIFYING&&ge();function M(u,p){return u[5]===_.VERIFIED?st:u[5]===_.VERIFYING?lt:ot}let Y=M(t),x=Y(t),$=t[2]!==!0&&be(),b=t[8]&&me(t),m=t[9].footer&&t[1]!==!0&&ve(t);return{c(){e=y("div"),n=y("div"),w&&w.c(),i=F(),l=y("div"),r=y("input"),h=F(),f=y("div"),x.c(),A=F(),$&&$.c(),k=F(),b&&b.c(),G=F(),m&&m.c(),c(r,"type","checkbox"),c(r,"id",s=t[3]+"_checkbox"),r.required=a=t[0]!=="onsubmit",c(r,"class","svelte-vuofbg"),c(l,"class","altcha-checkbox svelte-vuofbg"),le(l,"altcha-hidden",t[5]===_.VERIFYING),c(f,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(u,p){j(u,e,p),g(e,n),w&&w.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[6],g(n,h),g(n,f),x.m(f,null),g(n,A),$&&$.m(n,null),g(e,k),b&&b.m(e,null),g(e,G),m&&m.m(e,null),t[24](e),R||(S=[Q(r,"change",t[23]),Q(r,"change",t[10]),Q(r,"invalid",t[11])],R=!0)},p(u,p){u[5]===_.VERIFYING?w||(w=ge(),w.c(),w.m(n,i)):w&&(w.d(1),w=null),p[0]&8&&s!==(s=u[3]+"_checkbox")&&c(r,"id",s),p[0]&1&&a!==(a=u[0]!=="onsubmit")&&(r.required=a),p[0]&64&&(r.checked=u[6]),p[0]&32&&le(l,"altcha-hidden",u[5]===_.VERIFYING),Y===(Y=M(u))&&x?x.p(u,p):(x.d(1),x=Y(u),x&&(x.c(),x.m(f,null))),u[2]!==!0?$?$.p(u,p):($=be(),$.c(),$.m(n,null)):$&&($.d(1),$=null),u[8]?b?b.p(u,p):(b=me(u),b.c(),b.m(e,G)):b&&(b.d(1),b=null),u[9].footer&&u[1]!==!0?m?m.p(u,p):(m=ve(u),m.c(),m.m(e,null)):m&&(m.d(1),m=null),p[0]&32&&c(e,"data-state",u[5])},i:v,o:v,d(u){u&&L(e),w&&w.d(),x.d(),$&&$.d(),b&&b.d(),m&&m.d(),t[24](null),R=!1,P(S)}}}const _e="https://altcha.org/";function we(t){return JSON.parse(t)}function ut(t,e,n){let i,l,r,{auto:s=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:h=void 0}=e,{debug:f=!1}=e,{hidefooter:A=!1}=e,{hidelogo:k=!1}=e,{name:G="altcha"}=e,{maxnumber:R=void 0}=e,{mockerror:S=!1}=e,{strings:w=void 0}=e,{test:M=!1}=e;const Y=Oe(),x=["SHA-256","SHA-384","SHA-512"],$=[];let b=!1,m,u=null,p=null,T=null,O=_.UNVERIFIED,ye;Ue(()=>{u&&(u.removeEventListener("submit",pe),u.removeEventListener("reset",ke),u=null)}),Me(()=>{C("mounted","0.1.9"),M&&C("using test mode"),s!==void 0&&C("auto",s),u=m.closest("form"),u&&(u.addEventListener("submit",pe),u.addEventListener("reset",ke)),s==="onload"&&K()});function C(...o){(f||o.some(d=>d instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function pe(o){u&&s==="onsubmit"&&O===_.UNVERIFIED&&(o.preventDefault(),o.stopPropagation(),K().then(()=>{u==null||u.requestSubmit()}))}function ke(){J()}function at(o,d){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:d.number,salt:o.salt,signature:o.signature,test:M?!0:void 0,took:d.took}))}function Ee(o){if(!o.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(o.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!x.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${x.join(", ")}`);if(!o.challenge||o.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!o.salt||o.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function ft(){if(S)throw C("mocking error"),new Error("Mocked error.");if(i)return C("using provided json data"),i;if(M)return C("generating test challenge"),nt();{if(!a)throw new Error("Attribute challengeurl not set.");C("fetching challenge from",a);const o=await fetch(a);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);const d=o.headers.get("Expires");if(d.length){const W=Date.parse(d)-Date.now();W<1?xe():ye=setTimeout(xe,W)}return o.json()}}function xe(){J(_.EXPIRED,r.expired)}async function ht(o){let d=null;if("Worker"in window){try{d=await dt(o.challenge,o.salt,o.algorithm)}catch(W){C(W)}if((d==null?void 0:d.number)!==void 0)return{data:o,solution:d}}return{data:o,solution:await rt(o.challenge,o.salt,o.algorithm,R)}}async function dt(o,d,W){const Ce=$.push(new Qe);return new Promise(wt=>{$[Ce-1].addEventListener("message",$t=>{wt($t.data)}),$[Ce-1].postMessage({alg:W,challenge:o,max:R,salt:d})})}function gt(){[_.UNVERIFIED,_.ERROR,_.EXPIRED].includes(O)?K():n(6,b=!0)}function bt(){O===_.VERIFYING&&alert(r.waitAlert)}function mt(o){o.auto!==void 0&&(n(0,s=o.auto),s==="onload"&&K()),o.challenge&&(Ee(o.challenge),i=o.challenge),o.debug!==void 0&&n(12,f=!!o.debug),o.hidefooter!==void 0&&n(1,A=!!o.hidefooter),o.hidelogo!==void 0&&n(2,k=!!o.hidelogo),o.maxnumber!==void 0&&n(13,R=+o.maxnumber),o.mockerror!==void 0&&n(14,S=!!o.mockerror),o.name!==void 0&&n(3,G=o.name),o.test!==void 0&&n(15,M=!!o.test),o.strings&&n(22,l=o.strings)}function J(o=_.UNVERIFIED,d=null){clearTimeout(ye),n(6,b=!1),n(8,p=d),n(4,T=null),n(5,O=o)}async function K(){return J(_.VERIFYING),ft().then(o=>(Ee(o),C("challenge",o),ht(o))).then(({data:o,solution:d})=>{if(C("solution",d),(d==null?void 0:d.number)!==void 0)C("verified"),n(5,O=_.VERIFIED),n(6,b=!0),n(4,T=at(o,d)),C("payload",T),Fe().then(()=>{Y("verified",{payload:T})});else throw new Error("Unexpected result returned.")}).catch(o=>{C(o),n(5,O=_.ERROR),n(6,b=!1),n(8,p=o.message)})}function vt(){b=this.checked,n(6,b)}function _t(o){ee[o?"unshift":"push"](()=>{m=o,n(7,m)})}return t.$$set=o=>{"auto"in o&&n(0,s=o.auto),"challengeurl"in o&&n(16,a=o.challengeurl),"challengejson"in o&&n(17,h=o.challengejson),"debug"in o&&n(12,f=o.debug),"hidefooter"in o&&n(1,A=o.hidefooter),"hidelogo"in o&&n(2,k=o.hidelogo),"name"in o&&n(3,G=o.name),"maxnumber"in o&&n(13,R=o.maxnumber),"mockerror"in o&&n(14,S=o.mockerror),"strings"in o&&n(18,w=o.strings),"test"in o&&n(15,M=o.test)},t.$$.update=()=>{t.$$.dirty[0]&131072&&(i=h?we(h):void 0),t.$$.dirty[0]&262144&&n(22,l=w?we(w):{}),t.$$.dirty[0]&4194304&&n(9,r={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&48&&Y("statechange",{payload:T,state:O})},[s,A,k,G,T,O,b,m,p,r,gt,bt,f,R,S,M,a,h,w,mt,J,K,l,vt,_t]}class $e extends Ke{constructor(e){super(),De(this,e,ut,ct,Ie,{auto:0,challengeurl:16,challengejson:17,debug:12,hidefooter:1,hidelogo:2,name:3,maxnumber:13,mockerror:14,strings:18,test:15,configure:19,reset:20,verify:21},it,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[16]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[17]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),E()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),E()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),E()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),E()}get maxnumber(){return this.$$.ctx[13]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),E()}get strings(){return this.$$.ctx[18]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[15]}set test(e){this.$$set({test:e}),E()}get configure(){return this.$$.ctx[19]}get reset(){return this.$$.ctx[20]}get verify(){return this.$$.ctx[21]}}customElements.define("altcha-widget",Xe($e,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["configure","reset","verify"],!1)),I.Altcha=$e,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}); +(function(N,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(N=typeof globalThis<"u"?globalThis:N||self,_(N.altcha={}))})(this,function(N){"use strict";var Et=Object.defineProperty;var xt=(N,_,U)=>_ in N?Et(N,_,{enumerable:!0,configurable:!0,writable:!0,value:U}):N[_]=U;var j=(N,_,U)=>(xt(N,typeof _!="symbol"?_+"":_,U),U);function _(){}function U(t){return t()}function oe(){return Object.create(null)}function D(t){t.forEach(U)}function se(t){return typeof t=="function"}function Le(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Re(t){return Object.keys(t).length===0}function b(t,e){t.appendChild(e)}function Ne(t,e,n){const r=je(t);if(!r.getElementById(e)){const l=w("style");l.id=e,l.textContent=n,Ae(r,l)}}function je(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ae(t,e){return b(t.head||t,e),e.sheet}function C(t,e,n){t.insertBefore(e,n||null)}function E(t){t.parentNode&&t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Ge(t){return document.createTextNode(t)}function O(){return Ge(" ")}function Q(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}function c(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Me(t){return Array.from(t.childNodes)}function ce(t,e,n){t.classList.toggle(e,!!n)}function Se(t,e,{bubbles:n=!1,cancelable:r=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:r})}function Ve(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let X;function W(t){X=t}function q(){if(!X)throw new Error("Function called outside component initialization");return X}function Ue(t){q().$$.on_mount.push(t)}function Te(t){q().$$.on_destroy.push(t)}function Oe(){const t=q();return(e,n,{cancelable:r=!1}={})=>{const l=t.$$.callbacks[e];if(l){const o=Se(e,n,{cancelable:r});return l.slice().forEach(s=>{s.call(t,o)}),!o.defaultPrevented}return!0}}const Y=[],ee=[];let Z=[];const ue=[],ae=Promise.resolve();let te=!1;function fe(){te||(te=!0,ae.then(x))}function Fe(){return fe(),ae}function ne(t){Z.push(t)}const re=new Set;let B=0;function x(){if(B!==0)return;const t=X;do{try{for(;Bt.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),Z=e}const Be=new Set;function He(t,e){t&&t.i&&(Be.delete(t),t.i(e))}function Pe(t,e,n){const{fragment:r,after_update:l}=t.$$;r&&r.m(e,n),ne(()=>{const o=t.$$.on_mount.map(U).filter(se);t.$$.on_destroy?t.$$.on_destroy.push(...o):D(o),t.$$.on_mount=[]}),l.forEach(ne)}function De(t,e){const n=t.$$;n.fragment!==null&&(Ze(n.after_update),D(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Xe(t,e){t.$$.dirty[0]===-1&&(Y.push(t),fe(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const A=S.length?S[0]:M;return a.ctx&&l(a.ctx[k],a.ctx[k]=A)&&(!a.skip_bound&&a.bound[k]&&a.bound[k](A),I&&Xe(t,k)),M}):[],a.update(),I=!0,D(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const k=Me(e.target);a.fragment&&a.fragment.l(k),k.forEach(E)}else a.fragment&&a.fragment.c();e.intro&&He(t.$$.fragment),Pe(t,e.target,e.anchor),x()}W(h)}let he;typeof HTMLElement=="function"&&(he=class extends HTMLElement{constructor(e,n,r){super();j(this,"$$ctor");j(this,"$$s");j(this,"$$c");j(this,"$$cn",!1);j(this,"$$d",{});j(this,"$$r",!1);j(this,"$$p_d",{});j(this,"$$l",{});j(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,r&&this.attachShadow({mode:"open"})}addEventListener(e,n,r){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,r)}removeEventListener(e,n,r){if(super.removeEventListener(e,n,r),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(o){return()=>{let s;return{c:function(){s=w("slot"),o!=="default"&&c(s,"name",o)},m:function(a,I){C(a,s,I)},d:function(a){a&&E(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},r=Ve(this);for(const o of this.$$s)o in r&&(n[o]=[e(o)]);for(const o of this.attributes){const s=this.$$g_p(o.name);s in this.$$d||(this.$$d[s]=z(s,o.value,this.$$p_d,"toProp"))}for(const o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){const s=z(o,this.$$d[o],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,s)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const o in this.$$l)for(const s of this.$$l[o]){const u=this.$$c.$on(o,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,n,r){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=z(e,r,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function z(t,e,n,r){var o;const l=(o=n[t])==null?void 0:o.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Ke(t,e,n,r,l,o){let s=class extends he{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(u=>(e[u].attribute||u).toLowerCase())}};return Object.keys(e).forEach(u=>{Object.defineProperty(s.prototype,u,{get(){return this.$$c&&u in this.$$c?this.$$c[u]:this.$$d[u]},set(h){var a;h=z(u,h,e),this.$$d[u]=h,(a=this.$$c)==null||a.$set({[u]:h})}})}),r.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var h;return(h=this.$$c)==null?void 0:h[u]}})}),o&&(s=o(s)),t.element=s,s}class ze{constructor(){j(this,"$$");j(this,"$$set")}$destroy(){De(this,1),this.$destroy=_}$on(e,n){if(!se(n))return _;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{const l=r.indexOf(n);l!==-1&&r.splice(l,1)}}$set(e){this.$$set&&!Re(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Je="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Je);const de="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",Qe=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),ge=typeof window<"u"&&window.Blob&&new Blob([Qe(de)],{type:"text/javascript;charset=utf-8"});function qe(t){let e;try{if(e=ge&&(window.URL||window.webkitURL).createObjectURL(ge),!e)throw"";const n=new Worker(e,{name:t==null?void 0:t.name});return n.addEventListener("error",()=>{(window.URL||window.webkitURL).revokeObjectURL(e)}),n}catch{return new Worker("data:text/javascript;base64,"+de,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const et=1e7,tt=new TextEncoder;function nt(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function rt(t=1e5,e="SHA-256"){const n=Date.now().toString(16),r=Math.round(Math.random()*t),l=await be(n,r,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function be(t,e,n){return nt(await crypto.subtle.digest(n.toUpperCase(),tt.encode(t+e)))}async function it(t,e,n="SHA-256",r=et){const l=Date.now();for(let o=0;o<=r;o++)if(await be(e,o,n)===t)return{number:o,took:Date.now()-l};return null}var m=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(m||{});function lt(t){Ne(t,"svelte-vuofbg",".altcha.svelte-vuofbg.svelte-vuofbg{background:var(--altcha-color-base, transparent);border:var(--altcha-border-width, 1px) solid var(--altcha-color-border, #a0a0a0);border-radius:var(--altcha-border-radius, 3px);color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:var(--altcha-max-width, 260px);overflow:hidden;position:relative;text-align:left}.altcha.svelte-vuofbg.svelte-vuofbg:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-vuofbg.svelte-vuofbg{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-vuofbg.svelte-vuofbg{flex-grow:1}.altcha-label.svelte-vuofbg label.svelte-vuofbg{cursor:pointer}.altcha-logo.svelte-vuofbg.svelte-vuofbg{color:currentColor;opacity:0.3}.altcha-logo.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-error.svelte-vuofbg.svelte-vuofbg{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-vuofbg.svelte-vuofbg{align-items:center;background-color:var(--altcha-color-footer-bg, transparent);display:flex;font-size:0.75rem;opacity:0.4;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-vuofbg.svelte-vuofbg:hover{opacity:1}.altcha-footer.svelte-vuofbg>.svelte-vuofbg:first-child{flex-grow:1}.altcha-footer.svelte-vuofbg a{color:currentColor}.altcha-checkbox.svelte-vuofbg.svelte-vuofbg{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-vuofbg input.svelte-vuofbg{width:18px;height:18px;margin:0}.altcha-hidden.svelte-vuofbg.svelte-vuofbg{display:none}.altcha-spinner.svelte-vuofbg.svelte-vuofbg{animation:svelte-vuofbg-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-vuofbg-altcha-spinner{100%{transform:rotate(360deg)}}")}function me(t){let e,n,r;return{c(){e=V("svg"),n=V("path"),r=V("path"),c(n,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),c(n,"fill","currentColor"),c(n,"opacity",".25"),c(r,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),c(r,"fill","currentColor"),c(r,"class","altcha-spinner svelte-vuofbg"),c(e,"width","24"),c(e,"height","24"),c(e,"viewBox","0 0 24 24"),c(e,"xmlns","http://www.w3.org/2000/svg")},m(l,o){C(l,e,o),b(e,n),b(e,r)},d(l){l&&E(e)}}}function ot(t){let e,n=t[9].label+"",r;return{c(){e=w("label"),c(e,"for",r=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(l,o){C(l,e,o),e.innerHTML=n},p(l,o){o[0]&512&&n!==(n=l[9].label+"")&&(e.innerHTML=n),o[0]&8&&r!==(r=l[3]+"_checkbox")&&c(e,"for",r)},d(l){l&&E(e)}}}function st(t){let e,n=t[9].verifying+"";return{c(){e=w("span")},m(r,l){C(r,e,l),e.innerHTML=n},p(r,l){l[0]&512&&n!==(n=r[9].verifying+"")&&(e.innerHTML=n)},d(r){r&&E(e)}}}function ct(t){let e,n=t[9].verified+"",r,l;return{c(){e=w("span"),r=O(),l=w("input"),c(l,"type","hidden"),c(l,"name",t[3]),l.value=t[4]},m(o,s){C(o,e,s),e.innerHTML=n,C(o,r,s),C(o,l,s)},p(o,s){s[0]&512&&n!==(n=o[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(l,"name",o[3]),s[0]&16&&(l.value=o[4])},d(o){o&&(E(e),E(r),E(l))}}}function ve(t){let e,n,r,l,o,s;return{c(){e=w("div"),n=w("a"),r=V("svg"),l=V("path"),o=V("path"),s=V("path"),c(l,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),c(l,"fill","currentColor"),c(o,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),c(o,"fill","currentColor"),c(s,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),c(s,"fill","currentColor"),c(r,"width","22"),c(r,"height","22"),c(r,"viewBox","0 0 20 20"),c(r,"fill","none"),c(r,"xmlns","http://www.w3.org/2000/svg"),c(n,"href",$e),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(u,h){C(u,e,h),b(e,n),b(n,r),b(r,l),b(r,o),b(r,s)},p:_,d(u){u&&E(e)}}}function _e(t){let e,n,r,l;function o(h,a){return h[5]===m.EXPIRED?at:ut}let s=o(t),u=s(t);return{c(){e=w("div"),n=V("svg"),r=V("path"),l=O(),u.c(),c(r,"stroke-linecap","round"),c(r,"stroke-linejoin","round"),c(r,"d","M6 18L18 6M6 6l12 12"),c(n,"width","14"),c(n,"height","14"),c(n,"xmlns","http://www.w3.org/2000/svg"),c(n,"fill","none"),c(n,"viewBox","0 0 24 24"),c(n,"stroke-width","1.5"),c(n,"stroke","currentColor"),c(e,"class","altcha-error svelte-vuofbg")},m(h,a){C(h,e,a),b(e,n),b(n,r),b(e,l),u.m(e,null)},p(h,a){s===(s=o(h))&&u?u.p(h,a):(u.d(1),u=s(h),u&&(u.c(),u.m(e,null)))},d(h){h&&E(e),u.d()}}}function ut(t){let e,n=t[9].error+"";return{c(){e=w("div"),c(e,"title",t[8])},m(r,l){C(r,e,l),e.innerHTML=n},p(r,l){l[0]&512&&n!==(n=r[9].error+"")&&(e.innerHTML=n),l[0]&256&&c(e,"title",r[8])},d(r){r&&E(e)}}}function at(t){let e,n=t[9].expired+"";return{c(){e=w("div"),c(e,"title",t[8])},m(r,l){C(r,e,l),e.innerHTML=n},p(r,l){l[0]&512&&n!==(n=r[9].expired+"")&&(e.innerHTML=n),l[0]&256&&c(e,"title",r[8])},d(r){r&&E(e)}}}function we(t){let e,n,r=t[9].footer+"";return{c(){e=w("div"),n=w("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(l,o){C(l,e,o),b(e,n),n.innerHTML=r},p(l,o){o[0]&512&&r!==(r=l[9].footer+"")&&(n.innerHTML=r)},d(l){l&&E(e)}}}function ft(t){let e,n,r,l,o,s,u,h,a,I,k,M,S,A,$=t[5]===m.VERIFYING&&me();function F(f,y){return f[5]===m.VERIFIED?ct:f[5]===m.VERIFYING?st:ot}let G=F(t),L=G(t),p=t[2]!==!0&&ve(),g=(t[8]||t[5]===m.EXPIRED)&&_e(t),v=t[9].footer&&t[1]!==!0&&we(t);return{c(){e=w("div"),n=w("div"),$&&$.c(),r=O(),l=w("div"),o=w("input"),h=O(),a=w("div"),L.c(),I=O(),p&&p.c(),k=O(),g&&g.c(),M=O(),v&&v.c(),c(o,"type","checkbox"),c(o,"id",s=t[3]+"_checkbox"),o.required=u=t[0]!=="onsubmit",c(o,"class","svelte-vuofbg"),c(l,"class","altcha-checkbox svelte-vuofbg"),ce(l,"altcha-hidden",t[5]===m.VERIFYING),c(a,"class","altcha-label svelte-vuofbg"),c(n,"class","altcha-main svelte-vuofbg"),c(e,"class","altcha svelte-vuofbg"),c(e,"data-state",t[5])},m(f,y){C(f,e,y),b(e,n),$&&$.m(n,null),b(n,r),b(n,l),b(l,o),o.checked=t[6],b(n,h),b(n,a),L.m(a,null),b(n,I),p&&p.m(n,null),b(e,k),g&&g.m(e,null),b(e,M),v&&v.m(e,null),t[25](e),S||(A=[Q(o,"change",t[24]),Q(o,"change",t[10]),Q(o,"invalid",t[11])],S=!0)},p(f,y){f[5]===m.VERIFYING?$||($=me(),$.c(),$.m(n,r)):$&&($.d(1),$=null),y[0]&8&&s!==(s=f[3]+"_checkbox")&&c(o,"id",s),y[0]&1&&u!==(u=f[0]!=="onsubmit")&&(o.required=u),y[0]&64&&(o.checked=f[6]),y[0]&32&&ce(l,"altcha-hidden",f[5]===m.VERIFYING),G===(G=F(f))&&L?L.p(f,y):(L.d(1),L=G(f),L&&(L.c(),L.m(a,null))),f[2]!==!0?p?p.p(f,y):(p=ve(),p.c(),p.m(n,null)):p&&(p.d(1),p=null),f[8]||f[5]===m.EXPIRED?g?g.p(f,y):(g=_e(f),g.c(),g.m(e,M)):g&&(g.d(1),g=null),f[9].footer&&f[1]!==!0?v?v.p(f,y):(v=we(f),v.c(),v.m(e,null)):v&&(v.d(1),v=null),y[0]&32&&c(e,"data-state",f[5])},i:_,o:_,d(f){f&&E(e),$&&$.d(),L.d(),p&&p.d(),g&&g.d(),v&&v.d(),t[25](null),S=!1,D(A)}}}const $e="https://altcha.org/";function pe(t){return JSON.parse(t)}function ht(t,e,n){let r,l,o,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:h=void 0}=e,{debug:a=!1}=e,{expire:I=void 0}=e,{hidefooter:k=!1}=e,{hidelogo:M=!1}=e,{name:S="altcha"}=e,{maxnumber:A=void 0}=e,{mockerror:$=!1}=e,{strings:F=void 0}=e,{test:G=!1}=e;const L=Oe(),p=["SHA-256","SHA-384","SHA-512"];let g=!1,v,f=null,y=null,H=null,T=m.UNVERIFIED,ie;Te(()=>{f&&(f.removeEventListener("submit",ke),f.removeEventListener("reset",Ee),f=null)}),Ue(()=>{R("mounted","0.1.9"),G&&R("using test mode"),I&&le(I),s!==void 0&&R("auto",s),f=v.closest("form"),f&&(f.addEventListener("submit",ke),f.addEventListener("reset",Ee)),s==="onload"&&K()});function R(...i){(a||i.some(d=>d instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function ke(i){f&&s==="onsubmit"&&T===m.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),K().then(()=>{f==null||f.requestSubmit()}))}function Ee(){J()}function dt(i,d){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:d.number,salt:i.salt,signature:i.signature,test:G?!0:void 0,took:d.took}))}function xe(i){if(!i.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(i.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!p.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${p.join(", ")}`);if(!i.challenge||i.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!i.salt||i.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function gt(){if($)throw R("mocking error"),new Error("Mocked error.");if(r)return R("using provided json data"),r;if(G)return R("generating test challenge"),rt();{if(!u)throw new Error("Attribute challengeurl not set.");R("fetching challenge from",u);const i=await fetch(u);if(i.status!==200)throw new Error(`Server responded with ${i.status}.`);const d=i.headers.get("Expires");if(d!=null&&d.length){const P=Date.parse(d);isNaN(P)||le(P-Date.now())}return i.json()}}function Ce(){J(m.EXPIRED,o.expired)}async function bt(i){let d=null;if("Worker"in window){try{d=await mt(i.challenge,i.salt,i.algorithm)}catch(P){R(P)}if((d==null?void 0:d.number)!==void 0)return{data:i,solution:d}}return{data:i,solution:await it(i.challenge,i.salt,i.algorithm,A)}}async function mt(i,d,P){const Ie=new qe;return new Promise(yt=>{Ie.addEventListener("message",kt=>{yt(kt.data)}),Ie.postMessage({alg:P,challenge:i,max:A,salt:d})})}function vt(){[m.UNVERIFIED,m.ERROR,m.EXPIRED].includes(T)?K():n(6,g=!0)}function _t(){T===m.VERIFYING&&alert(o.waitAlert)}function le(i){clearTimeout(ie),i<1?Ce():ie=setTimeout(Ce,i)}function wt(i){i.auto!==void 0&&(n(0,s=i.auto),s==="onload"&&K()),i.expire!==void 0&&(le(i.expire),n(13,I=i.expire)),i.challenge&&(xe(i.challenge),r=i.challenge),i.debug!==void 0&&n(12,a=!!i.debug),i.hidefooter!==void 0&&n(1,k=!!i.hidefooter),i.hidelogo!==void 0&&n(2,M=!!i.hidelogo),i.maxnumber!==void 0&&n(14,A=+i.maxnumber),i.mockerror!==void 0&&n(15,$=!!i.mockerror),i.name!==void 0&&n(3,S=i.name),i.test!==void 0&&n(16,G=!!i.test),i.strings&&n(23,l=i.strings)}function J(i=m.UNVERIFIED,d=null){clearTimeout(ie),n(6,g=!1),n(8,y=d),n(4,H=null),n(5,T=i)}async function K(){return J(m.VERIFYING),gt().then(i=>(xe(i),R("challenge",i),bt(i))).then(({data:i,solution:d})=>{if(R("solution",d),(d==null?void 0:d.number)!==void 0)R("verified"),n(5,T=m.VERIFIED),n(6,g=!0),n(4,H=dt(i,d)),R("payload",H),Fe().then(()=>{L("verified",{payload:H})});else throw new Error("Unexpected result returned.")}).catch(i=>{R(i),n(5,T=m.ERROR),n(6,g=!1),n(8,y=i.message)})}function $t(){g=this.checked,n(6,g)}function pt(i){ee[i?"unshift":"push"](()=>{v=i,n(7,v)})}return t.$$set=i=>{"auto"in i&&n(0,s=i.auto),"challengeurl"in i&&n(17,u=i.challengeurl),"challengejson"in i&&n(18,h=i.challengejson),"debug"in i&&n(12,a=i.debug),"expire"in i&&n(13,I=i.expire),"hidefooter"in i&&n(1,k=i.hidefooter),"hidelogo"in i&&n(2,M=i.hidelogo),"name"in i&&n(3,S=i.name),"maxnumber"in i&&n(14,A=i.maxnumber),"mockerror"in i&&n(15,$=i.mockerror),"strings"in i&&n(19,F=i.strings),"test"in i&&n(16,G=i.test)},t.$$.update=()=>{t.$$.dirty[0]&262144&&(r=h?pe(h):void 0),t.$$.dirty[0]&524288&&n(23,l=F?pe(F):{}),t.$$.dirty[0]&8388608&&n(9,o={error:"Verification failed. Try again later.",expired:"Verification expired. Try again.",footer:`Protected by ALTCHA`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&48&&L("statechange",{payload:H,state:T})},[s,k,M,S,H,T,g,v,y,o,vt,_t,a,I,A,$,G,u,h,F,wt,J,K,l,$t,pt]}class ye extends ze{constructor(e){super(),We(this,e,ht,ft,Le,{auto:0,challengeurl:17,challengejson:18,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:19,test:16,configure:20,reset:21,verify:22},lt,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),x()}get challengeurl(){return this.$$.ctx[17]}set challengeurl(e){this.$$set({challengeurl:e}),x()}get challengejson(){return this.$$.ctx[18]}set challengejson(e){this.$$set({challengejson:e}),x()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),x()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire:e}),x()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),x()}get hidelogo(){return this.$$.ctx[2]}set hidelogo(e){this.$$set({hidelogo:e}),x()}get name(){return this.$$.ctx[3]}set name(e){this.$$set({name:e}),x()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),x()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),x()}get strings(){return this.$$.ctx[19]}set strings(e){this.$$set({strings:e}),x()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),x()}get configure(){return this.$$.ctx[20]}get reset(){return this.$$.ctx[21]}get verify(){return this.$$.ctx[22]}}customElements.define("altcha-widget",Ke(ye,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["configure","reset","verify"],!1)),N.Altcha=ye,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}); diff --git a/src/Altcha.svelte b/src/Altcha.svelte index 3e9c706..1ed6e80 100644 --- a/src/Altcha.svelte +++ b/src/Altcha.svelte @@ -14,6 +14,7 @@ export let challengeurl: string | undefined = undefined; export let challengejson: string | undefined = undefined; export let debug: boolean = false; + export let expire: number | undefined = undefined; export let hidefooter: boolean = false; export let hidelogo: boolean = false; export let name: string = 'altcha'; @@ -25,7 +26,6 @@ const dispatch = createEventDispatcher(); const allowedAlgs = ['SHA-256', 'SHA-384', 'SHA-512']; const website = 'https://altcha.org/'; - const workers = []; let checked: boolean = false; let el: HTMLElement; @@ -33,7 +33,7 @@ let error: string | null = null; let payload: string | null = null; let state: State = State.UNVERIFIED; - let expiry: ReturnType; + let expireTimeout: ReturnType; $: parsedChallenge = challengejson ? parseJsonAttribute(challengejson) : undefined; $: parsedStrings = strings ? parseJsonAttribute(strings) : {}; @@ -62,6 +62,9 @@ if (test) { log('using test mode'); } + if (expire) { + setExpire(expire); + } if (auto !== undefined) { log('auto', auto); } @@ -152,20 +155,24 @@ throw new Error(`Server responded with ${resp.status}.`); } const expHeader = resp.headers.get('Expires'); - if(expHeader.length) { - const diff = Date.parse(expHeader) - Date.now(); - if(diff < 1) { - expire() - } else { - expiry = setTimeout(expire, diff); + if(expHeader?.length) { + const parsed = Date.parse(expHeader); + if (!isNaN(parsed)) { + setExpire(parsed - Date.now()); } } return resp.json(); } } - function expire() { - reset(State.EXPIRED, _strings.expired) + function expireChallenge() { + if (false && challengeurl && state === State.VERIFIED) { + // re-fetch challenge and verify again + verify(); + + } else { + reset(State.EXPIRED, _strings.expired); + } } async function run(data: Challenge): Promise<{ data: Challenge, solution: Solution | null }> { @@ -190,12 +197,12 @@ } async function runWorker(challenge: string, salt: string, alg?: string): Promise { - const totalWorkers = workers.push(new InlineWorker()); + const worker = new InlineWorker(); return new Promise((resolve) => { - workers[totalWorkers - 1].addEventListener('message', (message: MessageEvent) => { + worker.addEventListener('message', (message: MessageEvent) => { resolve(message.data); }); - workers[totalWorkers - 1].postMessage({ + worker.postMessage({ alg, challenge, max: maxnumber, @@ -217,6 +224,15 @@ alert(_strings.waitAlert); } } + + function setExpire(duration: number) { + clearTimeout(expireTimeout); + if(duration < 1) { + expireChallenge(); + } else { + expireTimeout = setTimeout(expireChallenge, duration); + } + } export function configure(options: Configure) { if (options.auto !== void 0) { @@ -225,6 +241,10 @@ verify(); } } + if (options.expire !== void 0) { + setExpire(options.expire); + expire = options.expire; + } if (options.challenge) { validateChallenge(options.challenge); parsedChallenge = options.challenge; @@ -256,7 +276,7 @@ } export function reset(newState: State = State.UNVERIFIED, err: string | null = null) { - clearTimeout(expiry); + clearTimeout(expireTimeout); checked = false; error = err; payload = null; @@ -350,12 +370,16 @@ {/if} - {#if error} + {#if error || state === State.EXPIRED}
-
{@html error}
+ {#if state === State.EXPIRED} +
{@html _strings.expired}
+ {:else} +
{@html _strings.error}
+ {/if}
{/if} diff --git a/src/types.ts b/src/types.ts index 393b08a..39afdcb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,6 +12,7 @@ export interface Configure { auto?: 'onload' | 'onsubmit'; challenge?: Challenge; debug?: boolean; + expire?: number; hidefooter?: boolean; hidelogo?: boolean; maxnumber?: number;