diff --git a/dist/altcha.iife.js b/dist/altcha.iife.js index d5d1a60..0b7eb62 100644 --- a/dist/altcha.iife.js +++ b/dist/altcha.iife.js @@ -1 +1 @@ -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}({}); +var altcha=function(G){"use strict";var jt=Object.defineProperty;var At=(G,x,H)=>x in G?jt(G,x,{enumerable:!0,configurable:!0,writable:!0,value:H}):G[x]=H;var j=(G,x,H)=>(At(G,typeof x!="symbol"?x+"":x,H),H);function x(){}function H(t){return t()}function ae(){return Object.create(null)}function B(t){t.forEach(H)}function fe(t){return typeof t=="function"}function Te(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ge(t){return Object.keys(t).length===0}function v(t,e){t.appendChild(e)}function Ve(t,e,n){const r=Ze(t);if(!r.getElementById(e)){const l=_("style");l.id=e,l.textContent=n,He(r,l)}}function Ze(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function He(t,e){return v(t.head||t,e),e.sheet}function I(t,e,n){t.insertBefore(e,n||null)}function C(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 Oe(t){return document.createTextNode(t)}function O(){return Oe(" ")}function ee(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 Fe(t){return Array.from(t.childNodes)}function he(t,e,n){t.classList.toggle(e,!!n)}function Pe(t,e,{bubbles:n=!1,cancelable:r=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:r})}function Ue(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let W;function J(t){W=t}function te(){if(!W)throw new Error("Function called outside component initialization");return W}function De(t){te().$$.on_mount.push(t)}function Xe(t){te().$$.on_destroy.push(t)}function Ye(){const t=te();return(e,n,{cancelable:r=!1}={})=>{const l=t.$$.callbacks[e];if(l){const o=Pe(e,n,{cancelable:r});return l.slice().forEach(s=>{s.call(t,o)}),!o.defaultPrevented}return!0}}const P=[],ne=[];let U=[];const de=[],ge=Promise.resolve();let re=!1;function be(){re||(re=!0,ge.then(E))}function Ke(){return be(),ge}function ie(t){U.push(t)}const le=new Set;let D=0;function E(){if(D!==0)return;const t=W;do{try{for(;Dt.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),U=e}const Je=new Set;function Qe(t,e){t&&t.i&&(Je.delete(t),t.i(e))}function ze(t,e,n){const{fragment:r,after_update:l}=t.$$;r&&r.m(e,n),ie(()=>{const o=t.$$.on_mount.map(H).filter(fe);t.$$.on_destroy?t.$$.on_destroy.push(...o):B(o),t.$$.on_mount=[]}),l.forEach(ie)}function qe(t,e){const n=t.$$;n.fragment!==null&&(We(n.after_update),B(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function et(t,e){t.$$.dirty[0]===-1&&(P.push(t),be(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const A=S.length?S[0]:N;return a.ctx&&l(a.ctx[w],a.ctx[w]=A)&&(!a.skip_bound&&a.bound[w]&&a.bound[w](A),k&&et(t,w)),N}):[],a.update(),k=!0,B(a.before_update),a.fragment=r?r(a.ctx):!1,e.target){if(e.hydrate){const w=Fe(e.target);a.fragment&&a.fragment.l(w),w.forEach(C)}else a.fragment&&a.fragment.c();e.intro&&Qe(t.$$.fragment),ze(t,e.target,e.anchor),E()}J(f)}let me;typeof HTMLElement=="function"&&(me=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=_("slot"),o!=="default"&&c(s,"name",o)},m:function(a,k){I(a,s,k)},d:function(a){a&&C(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},r=Ue(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]=Q(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=Q(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]=Q(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 Q(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 nt(t,e,n,r,l,o){let s=class extends me{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(f){var a;f=Q(u,f,e),this.$$d[u]=f,(a=this.$$c)==null||a.$set({[u]:f})}})}),r.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var f;return(f=this.$$c)==null?void 0:f[u]}})}),o&&(s=o(s)),t.element=s,s}class rt{constructor(){j(this,"$$");j(this,"$$set")}$destroy(){qe(this,1),this.$destroy=x}$on(e,n){if(!fe(n))return x;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&&!Ge(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const it="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(it);const ve="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+PWk/cyhudWxsKTpoKGUsbCxvKS50aGVuKHc9Pnt3PT09dD9zKHtudW1iZXI6bCx0b29rOkRhdGUubm93KCktcn0pOmQobCsxKX0pLmNhdGNoKGMpfTtkKHApfSksY29udHJvbGxlcjphfX1sZXQgbjtvbm1lc3NhZ2U9YXN5bmMgdD0+e2NvbnN0e3R5cGU6ZSxwYXlsb2FkOm99PXQuZGF0YTtpZihlPT09ImFib3J0IiluPT1udWxsfHxuLmFib3J0KCksbj12b2lkIDA7ZWxzZSBpZihlPT09IndvcmsiKXtjb25zdHthbGc6aSxjaGFsbGVuZ2U6cCxtYXg6YSxzYWx0OnUsc3RhcnQ6c309b3x8e30sYz1tKHAsdSxpLGEscyk7bj1jLmNvbnRyb2xsZXIsYy5wcm9taXNlLnRoZW4ocj0+e3NlbGYucG9zdE1lc3NhZ2UociYmey4uLnIsd29ya2VyOiEwfSl9KX19fSkoKTsK",lt=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),we=typeof window<"u"&&window.Blob&&new Blob([lt(ve)],{type:"text/javascript;charset=utf-8"});function ot(t){let e;try{if(e=we&&(window.URL||window.webkitURL).createObjectURL(we),!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,"+ve,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const st=new TextEncoder;function ct(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ut(t=1e5,e="SHA-256"){const n=Date.now().toString(16),r=Math.round(Math.random()*t),l=await _e(n,r,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function _e(t,e,n){return ct(await crypto.subtle.digest(n.toUpperCase(),st.encode(t+e)))}function at(t,e,n="SHA-256",r=1e6,l=0){const o=new AbortController;return{promise:new Promise((u,f)=>{const a=Date.now(),k=w=>{o.signal.aborted||w>=r?u(null):_e(e,w,n).then(N=>{N===t?u({number:w,took:Date.now()-a}):k(w+1)}).catch(f)};k(l)}),controller:o}}var b=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(b||{});function ft(t){Ve(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 pe(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){I(l,e,o),v(e,n),v(e,r)},d(l){l&&C(e)}}}function ht(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){I(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&&C(e)}}}function dt(t){let e,n=t[9].verifying+"";return{c(){e=_("span")},m(r,l){I(r,e,l),e.innerHTML=n},p(r,l){l[0]&512&&n!==(n=r[9].verifying+"")&&(e.innerHTML=n)},d(r){r&&C(e)}}}function gt(t){let e,n=t[9].verified+"",r,l;return{c(){e=_("span"),r=O(),l=_("input"),c(l,"type","hidden"),c(l,"name",t[3]),l.value=t[4]},m(o,s){I(o,e,s),e.innerHTML=n,I(o,r,s),I(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&&(C(e),C(r),C(l))}}}function $e(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",Ee),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(u,f){I(u,e,f),v(e,n),v(n,r),v(r,l),v(r,o),v(r,s)},p:x,d(u){u&&C(e)}}}function ye(t){let e,n,r,l;function o(f,a){return f[5]===b.EXPIRED?mt:bt}let s=o(t),u=s(t);return{c(){e=_("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(f,a){I(f,e,a),v(e,n),v(n,r),v(e,l),u.m(e,null)},p(f,a){s===(s=o(f))&&u?u.p(f,a):(u.d(1),u=s(f),u&&(u.c(),u.m(e,null)))},d(f){f&&C(e),u.d()}}}function bt(t){let e,n=t[9].error+"";return{c(){e=_("div"),c(e,"title",t[8])},m(r,l){I(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&&C(e)}}}function mt(t){let e,n=t[9].expired+"";return{c(){e=_("div"),c(e,"title",t[8])},m(r,l){I(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&&C(e)}}}function ke(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){I(l,e,o),v(e,n),n.innerHTML=r},p(l,o){o[0]&512&&r!==(r=l[9].footer+"")&&(n.innerHTML=r)},d(l){l&&C(e)}}}function vt(t){let e,n,r,l,o,s,u,f,a,k,w,N,S,A,p=t[5]===b.VERIFYING&&pe();function F(h,d){return h[5]===b.VERIFIED?gt:h[5]===b.VERIFYING?dt:ht}let M=F(t),L=M(t),$=t[2]!==!0&&$e(),y=(t[8]||t[5]===b.EXPIRED)&&ye(t),m=t[9].footer&&t[1]!==!0&&ke(t);return{c(){e=_("div"),n=_("div"),p&&p.c(),r=O(),l=_("div"),o=_("input"),f=O(),a=_("div"),L.c(),k=O(),$&&$.c(),w=O(),y&&y.c(),N=O(),m&&m.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"),he(l,"altcha-hidden",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",t[5])},m(h,d){I(h,e,d),v(e,n),p&&p.m(n,null),v(n,r),v(n,l),v(l,o),o.checked=t[6],v(n,f),v(n,a),L.m(a,null),v(n,k),$&&$.m(n,null),v(e,w),y&&y.m(e,null),v(e,N),m&&m.m(e,null),t[26](e),S||(A=[ee(o,"change",t[25]),ee(o,"change",t[10]),ee(o,"invalid",t[11])],S=!0)},p(h,d){h[5]===b.VERIFYING?p||(p=pe(),p.c(),p.m(n,r)):p&&(p.d(1),p=null),d[0]&8&&s!==(s=h[3]+"_checkbox")&&c(o,"id",s),d[0]&1&&u!==(u=h[0]!=="onsubmit")&&(o.required=u),d[0]&64&&(o.checked=h[6]),d[0]&32&&he(l,"altcha-hidden",h[5]===b.VERIFYING),M===(M=F(h))&&L?L.p(h,d):(L.d(1),L=M(h),L&&(L.c(),L.m(a,null))),h[2]!==!0?$?$.p(h,d):($=$e(),$.c(),$.m(n,null)):$&&($.d(1),$=null),h[8]||h[5]===b.EXPIRED?y?y.p(h,d):(y=ye(h),y.c(),y.m(e,N)):y&&(y.d(1),y=null),h[9].footer&&h[1]!==!0?m?m.p(h,d):(m=ke(h),m.c(),m.m(e,null)):m&&(m.d(1),m=null),d[0]&32&&c(e,"data-state",h[5])},i:x,o:x,d(h){h&&C(e),p&&p.d(),L.d(),$&&$.d(),y&&y.d(),m&&m.d(),t[26](null),S=!1,B(A)}}}const Ee="https://altcha.org/";function xe(t){return JSON.parse(t)}function wt(t,e,n){let r,l,o,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:f=void 0}=e,{debug:a=!1}=e,{expire:k=void 0}=e,{hidefooter:w=!1}=e,{hidelogo:N=!1}=e,{name:S="altcha"}=e,{maxnumber:A=1e6}=e,{mockerror:p=!1}=e,{strings:F=void 0}=e,{test:M=!1}=e,{workers:L=8}=e;const $=Ye(),y=["SHA-256","SHA-384","SHA-512"];let m=!1,h,d=null,oe=null,X=null,Z=b.UNVERIFIED,se;Xe(()=>{d&&(d.removeEventListener("submit",Le),d.removeEventListener("reset",Ie),d=null)}),De(()=>{R("mounted","0.1.9"),M&&R("using test mode"),k&&ce(k),s!==void 0&&R("auto",s),d=h.closest("form"),d&&(d.addEventListener("submit",Le),d.addEventListener("reset",Ie)),s==="onload"&&Y()});function R(...i){(a||i.some(g=>g instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Le(i){d&&s==="onsubmit"&&Z===b.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),Y().then(()=>{d==null||d.requestSubmit()}))}function Ie(){z()}function _t(i,g){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:g.number,salt:i.salt,signature:i.signature,test:M?!0:void 0,took:g.took}))}function Re(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(!y.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${y.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 pt(){if(p)throw R("mocking error"),new Error("Mocked error.");if(r)return R("using provided json data"),r;if(M)return R("generating test challenge"),ut();{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 g=i.headers.get("Expires");if(g!=null&&g.length){const K=Date.parse(g);isNaN(K)||ce(K-Date.now())}return i.json()}}function Ne(){u&&Z===b.VERIFIED?Y():z(b.EXPIRED,o.expired)}async function $t(i){let g=null;if("Worker"in window){try{g=await yt(i.challenge,i.salt,i.algorithm)}catch(K){R(K)}if((g==null?void 0:g.number)!==void 0)return{data:i,solution:g}}return{data:i,solution:await at(i.challenge,i.salt,i.algorithm,A).promise}}async function yt(i,g,K,ue=Math.ceil(L)){const q=[];if(ue<1)throw new Error("Wrong number of workers configured.");for(let T=0;T{const Ae=Rt*je;return new Promise(Nt=>{T.addEventListener("message",Me=>{if(Me.data)for(const Se of q)Se!==T&&Se.postMessage({type:"abort"});Nt(Me.data)}),T.postMessage({payload:{alg:K,challenge:i,max:Ae+je,salt:g,start:Ae},type:"work"})})}));for(const T of q)T.terminate();return It.find(T=>!!T)||null}function kt(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(Z)?Y():n(6,m=!0)}function Et(){Z===b.VERIFYING&&alert(o.waitAlert)}function ce(i){clearTimeout(se),i<1?Ne():se=setTimeout(Ne,i)}function xt(i){i.auto!==void 0&&(n(0,s=i.auto),s==="onload"&&Y()),i.expire!==void 0&&(ce(i.expire),n(13,k=i.expire)),i.challenge&&(Re(i.challenge),r=i.challenge),i.debug!==void 0&&n(12,a=!!i.debug),i.hidefooter!==void 0&&n(1,w=!!i.hidefooter),i.hidelogo!==void 0&&n(2,N=!!i.hidelogo),i.maxnumber!==void 0&&n(14,A=+i.maxnumber),i.mockerror!==void 0&&n(15,p=!!i.mockerror),i.name!==void 0&&n(3,S=i.name),i.test!==void 0&&n(16,M=!!i.test),i.strings&&n(24,l=i.strings)}function z(i=b.UNVERIFIED,g=null){clearTimeout(se),n(6,m=!1),n(8,oe=g),n(4,X=null),n(5,Z=i)}async function Y(){return z(b.VERIFYING),pt().then(i=>(Re(i),R("challenge",i),$t(i))).then(({data:i,solution:g})=>{if(R("solution",g),(g==null?void 0:g.number)!==void 0)R("verified"),n(5,Z=b.VERIFIED),n(6,m=!0),n(4,X=_t(i,g)),R("payload",X),Ke().then(()=>{$("verified",{payload:X})});else throw new Error("Unexpected result returned.")}).catch(i=>{R(i),n(5,Z=b.ERROR),n(6,m=!1),n(8,oe=i.message)})}function Ct(){m=this.checked,n(6,m)}function Lt(i){ne[i?"unshift":"push"](()=>{h=i,n(7,h)})}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,f=i.challengejson),"debug"in i&&n(12,a=i.debug),"expire"in i&&n(13,k=i.expire),"hidefooter"in i&&n(1,w=i.hidefooter),"hidelogo"in i&&n(2,N=i.hidelogo),"name"in i&&n(3,S=i.name),"maxnumber"in i&&n(14,A=i.maxnumber),"mockerror"in i&&n(15,p=i.mockerror),"strings"in i&&n(19,F=i.strings),"test"in i&&n(16,M=i.test),"workers"in i&&n(20,L=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&262144&&(r=f?xe(f):void 0),t.$$.dirty[0]&524288&&n(24,l=F?xe(F):{}),t.$$.dirty[0]&16777216&&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&&$("statechange",{payload:X,state:Z})},[s,w,N,S,X,Z,m,h,oe,o,kt,Et,a,k,A,p,M,u,f,F,L,xt,z,Y,l,Ct,Lt]}class Ce extends rt{constructor(e){super(),tt(this,e,wt,vt,Te,{auto:0,challengeurl:17,challengejson:18,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:19,test:16,workers:20,configure:21,reset:22,verify:23},ft,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),E()}get challengeurl(){return this.$$.ctx[17]}set challengeurl(e){this.$$set({challengeurl:e}),E()}get challengejson(){return this.$$.ctx[18]}set challengejson(e){this.$$set({challengejson:e}),E()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),E()}get expire(){return this.$$.ctx[13]}set expire(e){this.$$set({expire: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[14]}set maxnumber(e){this.$$set({maxnumber:e}),E()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),E()}get strings(){return this.$$.ctx[19]}set strings(e){this.$$set({strings:e}),E()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),E()}get workers(){return this.$$.ctx[20]}set workers(e){this.$$set({workers:e}),E()}get configure(){return this.$$.ctx[21]}get reset(){return this.$$.ctx[22]}get verify(){return this.$$.ctx[23]}}return customElements.define("altcha-widget",nt(Ce,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),G.Altcha=Ce,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"}),G}({}); diff --git a/dist/altcha.js b/dist/altcha.js index a266900..85447fa 100644 --- a/dist/altcha.js +++ b/dist/altcha.js @@ -1,37 +1,37 @@ -var Ue = Object.defineProperty; -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() { +var Xe = Object.defineProperty; +var Ye = (t, e, n) => e in t ? Xe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; +var N = (t, e, n) => (Ye(t, typeof e != "symbol" ? e + "" : e, n), n); +function X() { } -function _e(t) { +function xe(t) { return t(); } -function ue() { +function me() { return /* @__PURE__ */ Object.create(null); } -function X(t) { - t.forEach(_e); +function B(t) { + t.forEach(xe); } -function we(t) { +function Ce(t) { return typeof t == "function"; } -function Oe(t, e) { +function Ke(t, e) { return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function"; } -function Ye(t) { +function Be(t) { return Object.keys(t).length === 0; } -function m(t, e) { +function v(t, e) { t.appendChild(e); } -function Ze(t, e, n) { - const r = Be(t); +function We(t, e, n) { + const r = Je(t); if (!r.getElementById(e)) { - const l = w("style"); - l.id = e, l.textContent = n, He(r, l); + const l = p("style"); + l.id = e, l.textContent = n, Qe(r, l); } } -function Be(t) { +function Je(t) { if (!t) return document; const e = t.getRootNode ? t.getRootNode() : t.ownerDocument; @@ -41,47 +41,47 @@ function Be(t) { e ) : t.ownerDocument; } -function He(t, e) { - return m( +function Qe(t, e) { + return v( /** @type {Document} */ t.head || t, e ), e.sheet; } -function L(t, e, n) { +function I(t, e, n) { t.insertBefore(e, n || null); } -function E(t) { +function C(t) { t.parentNode && t.parentNode.removeChild(t); } -function w(t) { +function p(t) { return document.createElement(t); } -function M(t) { +function S(t) { return document.createElementNS("http://www.w3.org/2000/svg", t); } -function Te(t) { +function ze(t) { return document.createTextNode(t); } -function U() { - return Te(" "); +function Z() { + return ze(" "); } -function Q(t, e, n, r) { +function ne(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 De(t) { +function qe(t) { return Array.from(t.childNodes); } -function ae(t, e, n) { +function ve(t, e, n) { t.classList.toggle(e, !!n); } -function Pe(t, e, { bubbles: n = !1, cancelable: r = !1 } = {}) { +function et(t, e, { bubbles: n = !1, cancelable: r = !1 } = {}) { return new CustomEvent(t, { detail: e, bubbles: n, cancelable: r }); } -function Xe(t) { +function tt(t) { const e = {}; return t.childNodes.forEach( /** @param {Element} node */ @@ -90,27 +90,27 @@ function Xe(t) { } ), e; } -let P; -function D(t) { - P = t; +let K; +function Y(t) { + K = t; } -function re() { - if (!P) +function se() { + if (!K) throw new Error("Function called outside component initialization"); - return P; + return K; } -function We(t) { - re().$$.on_mount.push(t); +function nt(t) { + se().$$.on_mount.push(t); } -function Ke(t) { - re().$$.on_destroy.push(t); +function rt(t) { + se().$$.on_destroy.push(t); } -function ze() { - const t = re(); +function it() { + const t = se(); return (e, n, { cancelable: r = !1 } = {}) => { const l = t.$$.callbacks[e]; if (l) { - const o = Pe( + const o = et( /** @type {string} */ e, n, @@ -123,136 +123,136 @@ function ze() { return !0; }; } -const Z = [], ee = []; -let B = []; -const fe = [], $e = /* @__PURE__ */ Promise.resolve(); -let te = !1; -function pe() { - te || (te = !0, $e.then(k)); +const D = [], ie = []; +let P = []; +const we = [], Le = /* @__PURE__ */ Promise.resolve(); +let le = !1; +function Ie() { + le || (le = !0, Le.then(E)); } -function Je() { - return pe(), $e; +function lt() { + return Ie(), Le; } -function ne(t) { - B.push(t); +function oe(t) { + P.push(t); } -const q = /* @__PURE__ */ new Set(); -let Y = 0; -function k() { - if (Y !== 0) +const re = /* @__PURE__ */ new Set(); +let U = 0; +function E() { + if (U !== 0) return; - const t = P; + const t = K; do { try { - for (; Y < Z.length; ) { - const e = Z[Y]; - Y++, D(e), Qe(e.$$); + for (; U < D.length; ) { + const e = D[U]; + U++, Y(e), ot(e.$$); } } catch (e) { - throw Z.length = 0, Y = 0, e; + throw D.length = 0, U = 0, e; } - 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]; - q.has(n) || (q.add(n), n()); + for (Y(null), D.length = 0, U = 0; ie.length; ) + ie.pop()(); + for (let e = 0; e < P.length; e += 1) { + const n = P[e]; + re.has(n) || (re.add(n), n()); } - B.length = 0; - } while (Z.length); - for (; fe.length; ) - fe.pop()(); - te = !1, q.clear(), D(t); + P.length = 0; + } while (D.length); + for (; we.length; ) + we.pop()(); + le = !1, re.clear(), Y(t); } -function Qe(t) { +function ot(t) { if (t.fragment !== null) { - t.update(), X(t.before_update); + t.update(), B(t.before_update); const e = t.dirty; - t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(ne); + t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(oe); } } -function qe(t) { +function st(t) { const e = [], n = []; - B.forEach((r) => t.indexOf(r) === -1 ? e.push(r) : n.push(r)), n.forEach((r) => r()), B = e; + P.forEach((r) => t.indexOf(r) === -1 ? e.push(r) : n.push(r)), n.forEach((r) => r()), P = e; } -const et = /* @__PURE__ */ new Set(); -function tt(t, e) { - t && t.i && (et.delete(t), t.i(e)); +const ct = /* @__PURE__ */ new Set(); +function ut(t, e) { + t && t.i && (ct.delete(t), t.i(e)); } -function nt(t, e, n) { +function at(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); + r && r.m(e, n), oe(() => { + const o = t.$$.on_mount.map(xe).filter(Ce); + t.$$.on_destroy ? t.$$.on_destroy.push(...o) : B(o), t.$$.on_mount = []; + }), l.forEach(oe); } -function rt(t, e) { +function ft(t, e) { const n = t.$$; - 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 = []); + n.fragment !== null && (st(n.after_update), B(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []); } -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 ht(t, e) { + t.$$.dirty[0] === -1 && (D.push(t), Ie(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31; } -function lt(t, e, n, r, l, o, s = null, u = [-1]) { - const h = P; - D(t); +function dt(t, e, n, r, l, o, s = null, u = [-1]) { + const f = K; + Y(t); const a = t.$$ = { fragment: null, ctx: [], // state props: o, - update: H, + update: X, not_equal: l, - bound: ue(), + bound: me(), // lifecycle on_mount: [], on_destroy: [], on_disconnect: [], before_update: [], after_update: [], - context: new Map(e.context || (h ? h.$$.context : [])), + context: new Map(e.context || (f ? f.$$.context : [])), // everything else - callbacks: ue(), + callbacks: me(), dirty: u, skip_bound: !1, - root: e.target || h.$$.root + root: e.target || f.$$.root }; 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) { + let k = !1; + if (a.ctx = n ? n(t, e.props || {}, (w, R, ...M) => { + const j = M.length ? M[0] : R; + return a.ctx && l(a.ctx[w], a.ctx[w] = j) && (!a.skip_bound && a.bound[w] && a.bound[w](j), k && ht(t, w)), R; + }) : [], a.update(), k = !0, B(a.before_update), a.fragment = r ? r(a.ctx) : !1, e.target) { if (e.hydrate) { - const y = De(e.target); - a.fragment && a.fragment.l(y), y.forEach(E); + const w = qe(e.target); + a.fragment && a.fragment.l(w), w.forEach(C); } else a.fragment && a.fragment.c(); - e.intro && tt(t.$$.fragment), nt(t, e.target, e.anchor), k(); + e.intro && ut(t.$$.fragment), at(t, e.target, e.anchor), E(); } - D(h); + Y(f); } -let ye; -typeof HTMLElement == "function" && (ye = class extends HTMLElement { +let Re; +typeof HTMLElement == "function" && (Re = class extends HTMLElement { constructor(e, n, r) { super(); /** The Svelte component constructor */ - R(this, "$$ctor"); + N(this, "$$ctor"); /** Slots */ - R(this, "$$s"); + N(this, "$$s"); /** The Svelte component instance */ - R(this, "$$c"); + N(this, "$$c"); /** Whether or not the custom element is connected */ - R(this, "$$cn", !1); + N(this, "$$cn", !1); /** Component props data */ - R(this, "$$d", {}); + N(this, "$$d", {}); /** `true` if currently in the process of reflecting component props back to attributes */ - R(this, "$$r", !1); + N(this, "$$r", !1); /** @type {Record} Props definition (name, reflected, type etc) */ - R(this, "$$p_d", {}); + N(this, "$$p_d", {}); /** @type {Record} Event listeners */ - R(this, "$$l", {}); + N(this, "$$l", {}); /** @type {Map} Event listener unsubscribe functions */ - R(this, "$$l_u", /* @__PURE__ */ new Map()); + N(this, "$$l_u", /* @__PURE__ */ new Map()); this.$$ctor = e, this.$$s = n, r && this.attachShadow({ mode: "open" }); } addEventListener(e, n, r) { @@ -275,29 +275,29 @@ typeof HTMLElement == "function" && (ye = class extends HTMLElement { let s; return { c: function() { - s = w("slot"), o !== "default" && c(s, "name", o); + s = p("slot"), o !== "default" && c(s, "name", o); }, /** * @param {HTMLElement} target * @param {HTMLElement} [anchor] */ - m: function(a, x) { - L(a, s, x); + m: function(a, k) { + I(a, s, k); }, d: function(a) { - a && E(s); + a && C(s); } }; }; }; if (await Promise.resolve(), !this.$$cn || this.$$c) return; - const n = {}, r = Xe(this); + const n = {}, r = tt(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")); + s in this.$$d || (this.$$d[s] = Q(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]); @@ -315,7 +315,7 @@ typeof HTMLElement == "function" && (ye = class extends HTMLElement { 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 = K( + const s = Q( o, this.$$d[o], this.$$p_d, @@ -338,7 +338,7 @@ typeof HTMLElement == "function" && (ye = class extends HTMLElement { // and setting attributes through setAttribute etc, this is helpful attributeChangedCallback(e, n, r) { var l; - 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] })); + this.$$r || (e = this.$$g_p(e), this.$$d[e] = Q(e, r, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] })); } disconnectedCallback() { this.$$cn = !1, Promise.resolve().then(() => { @@ -351,7 +351,7 @@ typeof HTMLElement == "function" && (ye = class extends HTMLElement { ) || e; } }); -function K(t, e, n, r) { +function Q(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]) @@ -381,8 +381,8 @@ function K(t, e, n, r) { return e; } } -function ot(t, e, n, r, l, o) { - let s = class extends ye { +function gt(t, e, n, r, l, o) { + let s = class extends Re { constructor() { super(t, n, l), this.$$p_d = e; } @@ -397,22 +397,22 @@ function ot(t, e, n, r, l, o) { get() { return this.$$c && u in this.$$c ? this.$$c[u] : this.$$d[u]; }, - set(h) { + set(f) { var a; - h = K(u, h, e), this.$$d[u] = h, (a = this.$$c) == null || a.$set({ [u]: h }); + f = Q(u, f, e), this.$$d[u] = f, (a = this.$$c) == null || a.$set({ [u]: f }); } }); }), r.forEach((u) => { Object.defineProperty(s.prototype, u, { get() { - var h; - return (h = this.$$c) == null ? void 0 : h[u]; + var f; + return (f = this.$$c) == null ? void 0 : f[u]; } }); }), o && (s = o(s)), t.element = /** @type {any} */ s, s; } -class st { +class bt { constructor() { /** * ### PRIVATE API @@ -421,7 +421,7 @@ class st { * * @type {any} */ - R(this, "$$"); + N(this, "$$"); /** * ### PRIVATE API * @@ -429,11 +429,11 @@ class st { * * @type {any} */ - R(this, "$$set"); + N(this, "$$set"); } /** @returns {void} */ $destroy() { - rt(this, 1), this.$destroy = H; + ft(this, 1), this.$destroy = X; } /** * @template {Extract} K @@ -442,8 +442,8 @@ class st { * @returns {() => void} */ $on(e, n) { - if (!we(n)) - return H; + if (!Ce(n)) + return X; const r = this.$$.callbacks[e] || (this.$$.callbacks[e] = []); return r.push(n), () => { const l = r.indexOf(n); @@ -455,16 +455,16 @@ class st { * @returns {void} */ $set(e) { - this.$$set && !Ye(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1); + this.$$set && !Be(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1); } } -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) { +const mt = "4"; +typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(mt); +const Ne = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+PWk/cyhudWxsKTpoKGUsbCxvKS50aGVuKHc9Pnt3PT09dD9zKHtudW1iZXI6bCx0b29rOkRhdGUubm93KCktcn0pOmQobCsxKX0pLmNhdGNoKGMpfTtkKHApfSksY29udHJvbGxlcjphfX1sZXQgbjtvbm1lc3NhZ2U9YXN5bmMgdD0+e2NvbnN0e3R5cGU6ZSxwYXlsb2FkOm99PXQuZGF0YTtpZihlPT09ImFib3J0IiluPT1udWxsfHxuLmFib3J0KCksbj12b2lkIDA7ZWxzZSBpZihlPT09IndvcmsiKXtjb25zdHthbGc6aSxjaGFsbGVuZ2U6cCxtYXg6YSxzYWx0OnUsc3RhcnQ6c309b3x8e30sYz1tKHAsdSxpLGEscyk7bj1jLmNvbnRyb2xsZXIsYy5wcm9taXNlLnRoZW4ocj0+e3NlbGYucG9zdE1lc3NhZ2UociYmey4uLnIsd29ya2VyOiEwfSl9KX19fSkoKTsK", vt = (t) => Uint8Array.from(atob(t), (e) => e.charCodeAt(0)), _e = typeof window < "u" && window.Blob && new Blob([vt(Ne)], { type: "text/javascript;charset=utf-8" }); +function wt(t) { let e; try { - if (e = he && (window.URL || window.webkitURL).createObjectURL(he), !e) + if (e = _e && (window.URL || window.webkitURL).createObjectURL(_e), !e) throw ""; const n = new Worker(e, { name: t == null ? void 0 : t.name @@ -474,7 +474,7 @@ function at(t) { }), n; } catch { return new Worker( - "data:text/javascript;base64," + ke, + "data:text/javascript;base64," + Ne, { name: t == null ? void 0 : t.name } @@ -483,12 +483,12 @@ function at(t) { e && (window.URL || window.webkitURL).revokeObjectURL(e); } } -const ft = 1e7, ht = new TextEncoder(); -function dt(t) { +const _t = new TextEncoder(); +function pt(t) { return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join(""); } -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); +async function $t(t = 1e5, e = "SHA-256") { + const n = Date.now().toString(16), r = Math.round(Math.random() * t), l = await je(n, r, e); return { algorithm: e, challenge: l, @@ -496,49 +496,56 @@ async function gt(t = 1e5, e = "SHA-256") { signature: "" }; } -async function Ee(t, e, n) { - return dt(await crypto.subtle.digest(n.toUpperCase(), ht.encode(t + e))); +async function je(t, e, n) { + return pt(await crypto.subtle.digest(n.toUpperCase(), _t.encode(t + e))); } -async function bt(t, e, n = "SHA-256", r = ft) { - const l = Date.now(); - for (let o = 0; o <= r; o++) - if (await Ee(e, o, n) === t) - return { - number: o, - took: Date.now() - l +function yt(t, e, n = "SHA-256", r = 1e6, l = 0) { + const o = new AbortController(); + return { + promise: new Promise((u, f) => { + const a = Date.now(), k = (w) => { + o.signal.aborted || w >= r ? u(null) : je(e, w, n).then((R) => { + R === t ? u({ + number: w, + took: Date.now() - a + }) : k(w + 1); + }).catch(f); }; - return null; + k(l); + }), + controller: o + }; } -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)}}"); +var m = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t.EXPIRED = "expired", t))(m || {}); +function kt(t) { + We(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 de(t) { +function pe(t) { let e, n, r; return { c() { - 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"); + e = S("svg"), n = S("path"), r = S("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) { - L(l, e, o), m(e, n), m(e, r); + I(l, e, o), v(e, n), v(e, r); }, d(l) { - l && E(e); + l && C(e); } }; } -function vt(t) { +function Et(t) { let e, n = ( /*_strings*/ t[9].label + "" ), r; return { c() { - e = w("label"), c(e, "for", r = /*name*/ + e = p("label"), c(e, "for", r = /*name*/ t[3] + "_checkbox"), c(e, "class", "svelte-vuofbg"); }, m(l, o) { - L(l, e, o), e.innerHTML = n; + I(l, e, o), e.innerHTML = n; }, p(l, o) { o[0] & /*_strings*/ @@ -548,21 +555,21 @@ function vt(t) { l[3] + "_checkbox") && c(e, "for", r); }, d(l) { - l && E(e); + l && C(e); } }; } -function _t(t) { +function xt(t) { let e, n = ( /*_strings*/ t[9].verifying + "" ); return { c() { - e = w("span"); + e = p("span"); }, m(r, l) { - L(r, e, l), e.innerHTML = n; + I(r, e, l), e.innerHTML = n; }, p(r, l) { l[0] & /*_strings*/ @@ -570,18 +577,18 @@ function _t(t) { r[9].verifying + "") && (e.innerHTML = n); }, d(r) { - r && E(e); + r && C(e); } }; } -function wt(t) { +function Ct(t) { let e, n = ( /*_strings*/ t[9].verified + "" ), r, l; return { c() { - e = w("span"), r = U(), l = w("input"), c(l, "type", "hidden"), c( + e = p("span"), r = Z(), l = p("input"), c(l, "type", "hidden"), c( l, "name", /*name*/ @@ -590,7 +597,7 @@ function wt(t) { t[4]; }, m(o, s) { - L(o, e, s), e.innerHTML = n, L(o, r, s), L(o, l, s); + I(o, e, s), e.innerHTML = n, I(o, r, s), I(o, l, s); }, p(o, s) { s[0] & /*_strings*/ @@ -606,57 +613,57 @@ function wt(t) { o[4]); }, d(o) { - o && (E(e), E(r), E(l)); + o && (C(e), C(r), C(l)); } }; } -function ge(t) { +function $e(t) { let e, n, r, l, o, s; return { c() { - 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"); + e = p("div"), n = p("a"), r = S("svg"), l = S("path"), o = S("path"), s = S("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", Ae), c(n, "target", "_blank"), c(n, "class", "altcha-logo svelte-vuofbg"); }, - m(u, h) { - L(u, e, h), m(e, n), m(n, r), m(r, l), m(r, o), m(r, s); + m(u, f) { + I(u, e, f), v(e, n), v(n, r), v(r, l), v(r, o), v(r, s); }, - p: H, + p: X, d(u) { - u && E(e); + u && C(e); } }; } -function be(t) { +function ye(t) { let e, n, r, l; - function o(h, a) { + function o(f, a) { return ( /*state*/ - h[5] === b.EXPIRED ? pt : $t + f[5] === m.EXPIRED ? It : Lt ); } let s = o(t), u = s(t); return { c() { - 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"); + e = p("div"), n = S("svg"), r = S("path"), l = Z(), 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) { - L(h, e, a), m(e, n), m(n, r), m(e, l), u.m(e, null); + m(f, a) { + I(f, e, a), v(e, n), v(n, r), v(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))); + p(f, a) { + s === (s = o(f)) && u ? u.p(f, a) : (u.d(1), u = s(f), u && (u.c(), u.m(e, null))); }, - d(h) { - h && E(e), u.d(); + d(f) { + f && C(e), u.d(); } }; } -function $t(t) { +function Lt(t) { let e, n = ( /*_strings*/ t[9].error + "" ); return { c() { - e = w("div"), c( + e = p("div"), c( e, "title", /*error*/ @@ -664,7 +671,7 @@ function $t(t) { ); }, m(r, l) { - L(r, e, l), e.innerHTML = n; + I(r, e, l), e.innerHTML = n; }, p(r, l) { l[0] & /*_strings*/ @@ -678,18 +685,18 @@ function $t(t) { ); }, d(r) { - r && E(e); + r && C(e); } }; } -function pt(t) { +function It(t) { let e, n = ( /*_strings*/ t[9].expired + "" ); return { c() { - e = w("div"), c( + e = p("div"), c( e, "title", /*error*/ @@ -697,7 +704,7 @@ function pt(t) { ); }, m(r, l) { - L(r, e, l), e.innerHTML = n; + I(r, e, l), e.innerHTML = n; }, p(r, l) { l[0] & /*_strings*/ @@ -711,21 +718,21 @@ function pt(t) { ); }, d(r) { - r && E(e); + r && C(e); } }; } -function me(t) { +function ke(t) { let e, n, r = ( /*_strings*/ t[9].footer + "" ); return { c() { - e = w("div"), n = w("div"), c(n, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); + e = p("div"), n = p("div"), c(n, "class", "svelte-vuofbg"), c(e, "class", "altcha-footer svelte-vuofbg"); }, m(l, o) { - L(l, e, o), m(e, n), n.innerHTML = r; + I(l, e, o), v(e, n), n.innerHTML = r; }, p(l, o) { o[0] & /*_strings*/ @@ -733,45 +740,45 @@ function me(t) { l[9].footer + "") && (n.innerHTML = r); }, d(l) { - l && E(e); + l && C(e); } }; } -function yt(t) { - let e, n, r, l, o, s, u, h, a, x, y, A, G, N, _ = ( +function Rt(t) { + let e, n, r, l, o, s, u, f, a, k, w, R, M, j, _ = ( /*state*/ - t[5] === b.VERIFYING && de() + t[5] === m.VERIFYING && pe() ); - function S(f, p) { + function V(h, d) { return ( /*state*/ - f[5] === b.VERIFIED ? wt : ( + h[5] === m.VERIFIED ? Ct : ( /*state*/ - f[5] === b.VERIFYING ? _t : vt + h[5] === m.VERIFYING ? xt : Et ) ); } - let j = S(t), C = j(t), $ = ( + let A = V(t), x = A(t), $ = ( /*hidelogo*/ - t[2] !== !0 && ge() - ), g = ( + t[2] !== !0 && $e() + ), y = ( /*error*/ (t[8] || /*state*/ - t[5] === b.EXPIRED) && be(t) - ), v = ( + t[5] === m.EXPIRED) && ye(t) + ), b = ( /*_strings*/ t[9].footer && /*hidefooter*/ - t[1] !== !0 && me(t) + t[1] !== !0 && ke(t) ); return { c() { - 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*/ + e = p("div"), n = p("div"), _ && _.c(), r = Z(), l = p("div"), o = p("input"), f = Z(), a = p("div"), x.c(), k = Z(), $ && $.c(), w = Z(), y && y.c(), R = Z(), b && b.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( + t[0] !== "onsubmit", c(o, "class", "svelte-vuofbg"), c(l, "class", "altcha-checkbox svelte-vuofbg"), ve( l, "altcha-hidden", /*state*/ - t[5] === b.VERIFYING + 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", @@ -779,248 +786,271 @@ function yt(t) { t[5] ); }, - 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( + m(h, d) { + I(h, e, d), v(e, n), _ && _.m(n, null), v(n, r), v(n, l), v(l, o), o.checked = /*checked*/ + t[6], v(n, f), v(n, a), x.m(a, null), v(n, k), $ && $.m(n, null), v(e, w), y && y.m(e, null), v(e, R), b && b.m(e, null), t[26](e), M || (j = [ + ne( o, "change", /*input_change_handler*/ - t[24] + t[25] ), - Q( + ne( o, "change", /*onCheckedChange*/ t[10] ), - Q( + ne( o, "invalid", /*onInvalid*/ t[11] ) - ], G = !0); + ], M = !0); }, - p(f, p) { + p(h, d) { /*state*/ - f[5] === b.VERIFYING ? _ || (_ = de(), _.c(), _.m(n, r)) : _ && (_.d(1), _ = null), p[0] & /*name*/ + h[5] === m.VERIFYING ? _ || (_ = pe(), _.c(), _.m(n, r)) : _ && (_.d(1), _ = null), d[0] & /*name*/ 8 && s !== (s = /*name*/ - f[3] + "_checkbox") && c(o, "id", s), p[0] & /*auto*/ + h[3] + "_checkbox") && c(o, "id", s), d[0] & /*auto*/ 1 && u !== (u = /*auto*/ - f[0] !== "onsubmit") && (o.required = u), p[0] & /*checked*/ + h[0] !== "onsubmit") && (o.required = u), d[0] & /*checked*/ 64 && (o.checked = /*checked*/ - f[6]), p[0] & /*state*/ - 32 && ae( + h[6]), d[0] & /*state*/ + 32 && ve( l, "altcha-hidden", /*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*/ + h[5] === m.VERIFYING + ), A === (A = V(h)) && x ? x.p(h, d) : (x.d(1), x = A(h), x && (x.c(), x.m(a, null))), /*hidelogo*/ + h[2] !== !0 ? $ ? $.p(h, d) : ($ = $e(), $.c(), $.m(n, null)) : $ && ($.d(1), $ = null), /*error*/ + h[8] || /*state*/ + h[5] === m.EXPIRED ? y ? y.p(h, d) : (y = ye(h), y.c(), y.m(e, R)) : y && (y.d(1), y = null), /*_strings*/ + h[9].footer && /*hidefooter*/ + h[1] !== !0 ? b ? b.p(h, d) : (b = ke(h), b.c(), b.m(e, null)) : b && (b.d(1), b = null), d[0] & /*state*/ 32 && c( e, "data-state", /*state*/ - f[5] + h[5] ); }, - i: H, - o: H, - d(f) { - f && E(e), _ && _.d(), C.d(), $ && $.d(), g && g.d(), v && v.d(), t[25](null), G = !1, X(N); + i: X, + o: X, + d(h) { + h && C(e), _ && _.d(), x.d(), $ && $.d(), y && y.d(), b && b.d(), t[26](null), M = !1, B(j); } }; } -const xe = "https://altcha.org/"; -function ve(t) { +const Ae = "https://altcha.org/"; +function Ee(t) { return JSON.parse(t); } -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 Nt(t, e, n) { + let r, l, o, { auto: s = void 0 } = e, { challengeurl: u = void 0 } = e, { challengejson: f = void 0 } = e, { debug: a = !1 } = e, { expire: k = void 0 } = e, { hidefooter: w = !1 } = e, { hidelogo: R = !1 } = e, { name: M = "altcha" } = e, { maxnumber: j = 1e6 } = e, { mockerror: _ = !1 } = e, { strings: V = void 0 } = e, { test: A = !1 } = e, { workers: x = 8 } = e; + const $ = it(), y = ["SHA-256", "SHA-384", "SHA-512"]; + let b = !1, h, d = null, z = null, H = null, T = m.UNVERIFIED, q; + rt(() => { + d && (d.removeEventListener("submit", ce), d.removeEventListener("reset", ue), d = null); + }), nt(() => { + L("mounted", "0.1.9"), A && L("using test mode"), k && ee(k), s !== void 0 && L("auto", s), d = h.closest("form"), d && (d.addEventListener("submit", ce), d.addEventListener("reset", ue)), s === "onload" && F(); }); - function I(...i) { - (a || i.some((d) => d instanceof Error)) && console[i[0] instanceof Error ? "error" : "log"]("ALTCHA", ...i); + function L(...i) { + (a || i.some((g) => g instanceof Error)) && console[i[0] instanceof Error ? "error" : "log"]("ALTCHA", ...i); } - function ie(i) { - f && s === "onsubmit" && V === b.UNVERIFIED && (i.preventDefault(), i.stopPropagation(), T().then(() => { - f == null || f.requestSubmit(); + function ce(i) { + d && s === "onsubmit" && T === m.UNVERIFIED && (i.preventDefault(), i.stopPropagation(), F().then(() => { + d == null || d.requestSubmit(); })); } - function le() { + function ue() { W(); } - function Ce(i, d) { + function Me(i, g) { return btoa(JSON.stringify({ algorithm: i.algorithm, challenge: i.challenge, - number: d.number, + number: g.number, salt: i.salt, signature: i.signature, - test: j ? !0 : void 0, - took: d.took + test: A ? !0 : void 0, + took: g.took })); } - function oe(i) { + function ae(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 (!y.includes(i.algorithm.toUpperCase())) + throw new Error(`Unknown algorithm value. Allowed values: ${y.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 Ie() { + async function Ge() { if (_) - throw I("mocking error"), new Error("Mocked error."); + throw L("mocking error"), new Error("Mocked error."); if (r) - return I("using provided json data"), r; - if (j) - return I("generating test challenge"), gt(); + return L("using provided json data"), r; + if (A) + return L("generating test challenge"), $t(); { if (!u) throw new Error("Attribute challengeurl not set."); - I("fetching challenge from", u); + L("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()); + const g = i.headers.get("Expires"); + if (g != null && g.length) { + const O = Date.parse(g); + isNaN(O) || ee(O - Date.now()); } return i.json(); } } - function se() { - W(b.EXPIRED, o.expired); + function fe() { + u && T === m.VERIFIED ? F() : W(m.EXPIRED, o.expired); } - async function Le(i) { - let d = null; + async function Te(i) { + let g = null; if ("Worker" in window) { try { - d = await Re(i.challenge, i.salt, i.algorithm); + g = await Se(i.challenge, i.salt, i.algorithm); } catch (O) { - I(O); + L(O); } - if ((d == null ? void 0 : d.number) !== void 0) - return { data: i, solution: d }; + if ((g == null ? void 0 : g.number) !== void 0) + return { data: i, solution: g }; } return { data: i, - solution: await bt(i.challenge, i.salt, i.algorithm, N) + solution: await yt(i.challenge, i.salt, i.algorithm, j).promise }; } - async function Re(i, d, O) { - const ce = new at(); - return new Promise((Ve) => { - ce.addEventListener("message", (Se) => { - Ve(Se.data); - }), ce.postMessage({ alg: O, challenge: i, max: N, salt: d }); - }); + async function Se(i, g, O, te = Math.ceil(x)) { + const J = []; + if (te < 1) + throw new Error("Wrong number of workers configured."); + for (let G = 0; G < te; G++) + J.push(new wt()); + const he = Math.ceil(j / te), Ue = await Promise.all(J.map((G, De) => { + const de = De * he; + return new Promise((Pe) => { + G.addEventListener("message", (ge) => { + if (ge.data) + for (const be of J) + be !== G && be.postMessage({ type: "abort" }); + Pe(ge.data); + }), G.postMessage({ + payload: { + alg: O, + challenge: i, + max: de + he, + salt: g, + start: de + }, + type: "work" + }); + }); + })); + for (const G of J) + G.terminate(); + return Ue.find((G) => !!G) || null; } - function Ne() { - [b.UNVERIFIED, b.ERROR, b.EXPIRED].includes(V) ? T() : n(6, g = !0); + function Ve() { + [m.UNVERIFIED, m.ERROR, m.EXPIRED].includes(T) ? F() : n(6, b = !0); } - function je() { - V === b.VERIFYING && alert(o.waitAlert); + function Ze() { + T === m.VERIFYING && alert(o.waitAlert); } - function J(i) { - clearTimeout(z), i < 1 ? se() : z = setTimeout(se, i); + function ee(i) { + clearTimeout(q), i < 1 ? fe() : q = setTimeout(fe, i); } - 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 He(i) { + i.auto !== void 0 && (n(0, s = i.auto), s === "onload" && F()), i.expire !== void 0 && (ee(i.expire), n(13, k = i.expire)), i.challenge && (ae(i.challenge), r = i.challenge), i.debug !== void 0 && n(12, a = !!i.debug), i.hidefooter !== void 0 && n(1, w = !!i.hidefooter), i.hidelogo !== void 0 && n(2, R = !!i.hidelogo), i.maxnumber !== void 0 && n(14, j = +i.maxnumber), i.mockerror !== void 0 && n(15, _ = !!i.mockerror), i.name !== void 0 && n(3, M = i.name), i.test !== void 0 && n(16, A = !!i.test), i.strings && n(24, 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); + function W(i = m.UNVERIFIED, g = null) { + clearTimeout(q), n(6, b = !1), n(8, z = g), n(4, H = null), n(5, T = 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 }); + async function F() { + return W(m.VERIFYING), Ge().then((i) => (ae(i), L("challenge", i), Te(i))).then(({ data: i, solution: g }) => { + if (L("solution", g), (g == null ? void 0 : g.number) !== void 0) + L("verified"), n(5, T = m.VERIFIED), n(6, b = !0), n(4, H = Me(i, g)), L("payload", H), lt().then(() => { + $("verified", { payload: H }); }); else throw new Error("Unexpected result returned."); }).catch((i) => { - I(i), n(5, V = b.ERROR), n(6, g = !1), n(8, p = i.message); + L(i), n(5, T = m.ERROR), n(6, b = !1), n(8, z = i.message); }); } - function Ge() { - g = this.checked, n(6, g); + function Fe() { + b = this.checked, n(6, b); } - function Me(i) { - ee[i ? "unshift" : "push"](() => { - v = i, n(7, v); + function Oe(i) { + ie[i ? "unshift" : "push"](() => { + h = i, n(7, h); }); } 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); + "auto" in i && n(0, s = i.auto), "challengeurl" in i && n(17, u = i.challengeurl), "challengejson" in i && n(18, f = i.challengejson), "debug" in i && n(12, a = i.debug), "expire" in i && n(13, k = i.expire), "hidefooter" in i && n(1, w = i.hidefooter), "hidelogo" in i && n(2, R = i.hidelogo), "name" in i && n(3, M = i.name), "maxnumber" in i && n(14, j = i.maxnumber), "mockerror" in i && n(15, _ = i.mockerror), "strings" in i && n(19, V = i.strings), "test" in i && n(16, A = i.test), "workers" in i && n(20, x = i.workers); }, t.$$.update = () => { t.$$.dirty[0] & /*challengejson*/ - 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 = { + 262144 && (r = f ? Ee(f) : void 0), t.$$.dirty[0] & /*strings*/ + 524288 && n(24, l = V ? Ee(V) : {}), t.$$.dirty[0] & /*parsedStrings*/ + 16777216 && 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 && C("statechange", { payload: F, state: V }); + 48 && $("statechange", { payload: H, state: T }); }, [ s, - y, - A, - G, - F, - V, - g, - v, - p, + w, + R, + M, + H, + T, + b, + h, + z, o, - Ne, - je, + Ve, + Ze, a, - x, - N, - _, + k, j, + _, + A, u, - h, - S, - Ae, + f, + V, + x, + He, W, - T, + F, l, - Ge, - Me + Fe, + Oe ]; } -class Et extends st { +class jt extends bt { constructor(e) { - super(), lt( + super(), dt( this, e, - kt, - yt, - Oe, + Nt, + Rt, + Ke, { auto: 0, challengeurl: 17, @@ -1034,11 +1064,12 @@ class Et extends st { mockerror: 15, strings: 19, test: 16, - configure: 20, - reset: 21, - verify: 22 + workers: 20, + configure: 21, + reset: 22, + verify: 23 }, - mt, + kt, [-1, -1] ); } @@ -1046,85 +1077,91 @@ class Et extends st { return this.$$.ctx[0]; } set auto(e) { - this.$$set({ auto: e }), k(); + this.$$set({ auto: e }), E(); } get challengeurl() { return this.$$.ctx[17]; } set challengeurl(e) { - this.$$set({ challengeurl: e }), k(); + this.$$set({ challengeurl: e }), E(); } get challengejson() { return this.$$.ctx[18]; } set challengejson(e) { - this.$$set({ challengejson: e }), k(); + this.$$set({ challengejson: e }), E(); } get debug() { return this.$$.ctx[12]; } set debug(e) { - this.$$set({ debug: e }), k(); + this.$$set({ debug: e }), E(); } get expire() { return this.$$.ctx[13]; } set expire(e) { - this.$$set({ expire: e }), k(); + this.$$set({ expire: e }), E(); } get hidefooter() { return this.$$.ctx[1]; } set hidefooter(e) { - this.$$set({ hidefooter: e }), k(); + this.$$set({ hidefooter: e }), E(); } get hidelogo() { return this.$$.ctx[2]; } set hidelogo(e) { - this.$$set({ hidelogo: e }), k(); + this.$$set({ hidelogo: e }), E(); } get name() { return this.$$.ctx[3]; } set name(e) { - this.$$set({ name: e }), k(); + this.$$set({ name: e }), E(); } get maxnumber() { return this.$$.ctx[14]; } set maxnumber(e) { - this.$$set({ maxnumber: e }), k(); + this.$$set({ maxnumber: e }), E(); } get mockerror() { return this.$$.ctx[15]; } set mockerror(e) { - this.$$set({ mockerror: e }), k(); + this.$$set({ mockerror: e }), E(); } get strings() { return this.$$.ctx[19]; } set strings(e) { - this.$$set({ strings: e }), k(); + this.$$set({ strings: e }), E(); } get test() { return this.$$.ctx[16]; } set test(e) { - this.$$set({ test: e }), k(); + this.$$set({ test: e }), E(); } - get configure() { + get workers() { return this.$$.ctx[20]; } - get reset() { + set workers(e) { + this.$$set({ workers: e }), E(); + } + get configure() { return this.$$.ctx[21]; } - get verify() { + get reset() { return this.$$.ctx[22]; } + get verify() { + return this.$$.ctx[23]; + } } -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)); +customElements.define("altcha-widget", gt(jt, { auto: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, expire: {}, hidefooter: { type: "Boolean" }, hidelogo: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" }, workers: {} }, [], ["configure", "reset", "verify"], !1)); export { - Et as Altcha + jt as Altcha }; diff --git a/dist/altcha.umd.cjs b/dist/altcha.umd.cjs index 9d5c6ff..07b57e5 100644 --- a/dist/altcha.umd.cjs +++ b/dist/altcha.umd.cjs @@ -1 +1 @@ -(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"})}); +(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 jt=Object.defineProperty;var At=(N,_,H)=>_ in N?jt(N,_,{enumerable:!0,configurable:!0,writable:!0,value:H}):N[_]=H;var A=(N,_,H)=>(At(N,typeof _!="symbol"?_+"":_,H),H);function _(){}function H(t){return t()}function fe(){return Object.create(null)}function B(t){t.forEach(H)}function ae(t){return typeof t=="function"}function Se(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ge(t){return Object.keys(t).length===0}function v(t,e){t.appendChild(e)}function Ve(t,e,n){const r=Ze(t);if(!r.getElementById(e)){const o=p("style");o.id=e,o.textContent=n,He(r,o)}}function Ze(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function He(t,e){return v(t.head||t,e),e.sheet}function I(t,e,n){t.insertBefore(e,n||null)}function C(t){t.parentNode&&t.parentNode.removeChild(t)}function p(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Oe(t){return document.createTextNode(t)}function O(){return Oe(" ")}function ee(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 Fe(t){return Array.from(t.childNodes)}function he(t,e,n){t.classList.toggle(e,!!n)}function Pe(t,e,{bubbles:n=!1,cancelable:r=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:r})}function Ue(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let W;function J(t){W=t}function te(){if(!W)throw new Error("Function called outside component initialization");return W}function De(t){te().$$.on_mount.push(t)}function Xe(t){te().$$.on_destroy.push(t)}function Ye(){const t=te();return(e,n,{cancelable:r=!1}={})=>{const o=t.$$.callbacks[e];if(o){const l=Pe(e,n,{cancelable:r});return o.slice().forEach(s=>{s.call(t,l)}),!l.defaultPrevented}return!0}}const P=[],ne=[];let U=[];const de=[],ge=Promise.resolve();let re=!1;function be(){re||(re=!0,ge.then(x))}function Ke(){return be(),ge}function ie(t){U.push(t)}const oe=new Set;let D=0;function x(){if(D!==0)return;const t=W;do{try{for(;Dt.indexOf(r)===-1?e.push(r):n.push(r)),n.forEach(r=>r()),U=e}const Je=new Set;function Qe(t,e){t&&t.i&&(Je.delete(t),t.i(e))}function ze(t,e,n){const{fragment:r,after_update:o}=t.$$;r&&r.m(e,n),ie(()=>{const l=t.$$.on_mount.map(H).filter(ae);t.$$.on_destroy?t.$$.on_destroy.push(...l):B(l),t.$$.on_mount=[]}),o.forEach(ie)}function qe(t,e){const n=t.$$;n.fragment!==null&&(We(n.after_update),B(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function et(t,e){t.$$.dirty[0]===-1&&(P.push(t),be(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<{const M=S.length?S[0]:j;return f.ctx&&o(f.ctx[w],f.ctx[w]=M)&&(!f.skip_bound&&f.bound[w]&&f.bound[w](M),E&&et(t,w)),j}):[],f.update(),E=!0,B(f.before_update),f.fragment=r?r(f.ctx):!1,e.target){if(e.hydrate){const w=Fe(e.target);f.fragment&&f.fragment.l(w),w.forEach(C)}else f.fragment&&f.fragment.c();e.intro&&Qe(t.$$.fragment),ze(t,e.target,e.anchor),x()}J(a)}let me;typeof HTMLElement=="function"&&(me=class extends HTMLElement{constructor(e,n,r){super();A(this,"$$ctor");A(this,"$$s");A(this,"$$c");A(this,"$$cn",!1);A(this,"$$d",{});A(this,"$$r",!1);A(this,"$$p_d",{});A(this,"$$l",{});A(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 o=this.$$c.$on(e,n);this.$$l_u.set(n,o)}super.addEventListener(e,n,r)}removeEventListener(e,n,r){if(super.removeEventListener(e,n,r),this.$$c){const o=this.$$l_u.get(n);o&&(o(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(l){return()=>{let s;return{c:function(){s=p("slot"),l!=="default"&&c(s,"name",l)},m:function(f,E){I(f,s,E)},d:function(f){f&&C(s)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;const n={},r=Ue(this);for(const l of this.$$s)l in r&&(n[l]=[e(l)]);for(const l of this.attributes){const s=this.$$g_p(l.name);s in this.$$d||(this.$$d[s]=Q(s,l.value,this.$$p_d,"toProp"))}for(const l in this.$$p_d)!(l in this.$$d)&&this[l]!==void 0&&(this.$$d[l]=this[l],delete this[l]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const l in this.$$p_d)if(this.$$d[l]=this.$$c.$$.ctx[this.$$c.$$.props[l]],this.$$p_d[l].reflect){const s=Q(l,this.$$d[l],this.$$p_d,"toAttribute");s==null?this.removeAttribute(this.$$p_d[l].attribute||l):this.setAttribute(this.$$p_d[l].attribute||l,s)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const l in this.$$l)for(const s of this.$$l[l]){const u=this.$$c.$on(l,s);this.$$l_u.set(s,u)}this.$$l={}}}attributeChangedCallback(e,n,r){var o;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Q(e,r,this.$$p_d,"toProp"),(o=this.$$c)==null||o.$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 Q(t,e,n,r){var l;const o=(l=n[t])==null?void 0:l.type;if(e=o==="Boolean"&&typeof e!="boolean"?e!=null:e,!r||!n[t])return e;if(r==="toAttribute")switch(o){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(o){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function nt(t,e,n,r,o,l){let s=class extends me{constructor(){super(t,n,o),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(a){var f;a=Q(u,a,e),this.$$d[u]=a,(f=this.$$c)==null||f.$set({[u]:a})}})}),r.forEach(u=>{Object.defineProperty(s.prototype,u,{get(){var a;return(a=this.$$c)==null?void 0:a[u]}})}),l&&(s=l(s)),t.element=s,s}class rt{constructor(){A(this,"$$");A(this,"$$set")}$destroy(){qe(this,1),this.$destroy=_}$on(e,n){if(!ae(n))return _;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o!==-1&&r.splice(o,1)}}$set(e){this.$$set&&!Ge(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const it="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(it);const ve="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IGY9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGcodCl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KHQpXS5tYXAoZT0+ZS50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBoKHQsZSxvKXtyZXR1cm4gZyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChvLnRvVXBwZXJDYXNlKCksZi5lbmNvZGUodCtlKSkpfWZ1bmN0aW9uIG0odCxlLG89IlNIQS0yNTYiLGk9MWU2LHA9MCl7Y29uc3QgYT1uZXcgQWJvcnRDb250cm9sbGVyO3JldHVybntwcm9taXNlOm5ldyBQcm9taXNlKChzLGMpPT57Y29uc3Qgcj1EYXRlLm5vdygpLGQ9bD0+e2Euc2lnbmFsLmFib3J0ZWR8fGw+PWk/cyhudWxsKTpoKGUsbCxvKS50aGVuKHc9Pnt3PT09dD9zKHtudW1iZXI6bCx0b29rOkRhdGUubm93KCktcn0pOmQobCsxKX0pLmNhdGNoKGMpfTtkKHApfSksY29udHJvbGxlcjphfX1sZXQgbjtvbm1lc3NhZ2U9YXN5bmMgdD0+e2NvbnN0e3R5cGU6ZSxwYXlsb2FkOm99PXQuZGF0YTtpZihlPT09ImFib3J0IiluPT1udWxsfHxuLmFib3J0KCksbj12b2lkIDA7ZWxzZSBpZihlPT09IndvcmsiKXtjb25zdHthbGc6aSxjaGFsbGVuZ2U6cCxtYXg6YSxzYWx0OnUsc3RhcnQ6c309b3x8e30sYz1tKHAsdSxpLGEscyk7bj1jLmNvbnRyb2xsZXIsYy5wcm9taXNlLnRoZW4ocj0+e3NlbGYucG9zdE1lc3NhZ2UociYmey4uLnIsd29ya2VyOiEwfSl9KX19fSkoKTsK",ot=t=>Uint8Array.from(atob(t),e=>e.charCodeAt(0)),we=typeof window<"u"&&window.Blob&&new Blob([ot(ve)],{type:"text/javascript;charset=utf-8"});function lt(t){let e;try{if(e=we&&(window.URL||window.webkitURL).createObjectURL(we),!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,"+ve,{name:t==null?void 0:t.name})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const st=new TextEncoder;function ct(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ut(t=1e5,e="SHA-256"){const n=Date.now().toString(16),r=Math.round(Math.random()*t),o=await _e(n,r,e);return{algorithm:e,challenge:o,salt:n,signature:""}}async function _e(t,e,n){return ct(await crypto.subtle.digest(n.toUpperCase(),st.encode(t+e)))}function ft(t,e,n="SHA-256",r=1e6,o=0){const l=new AbortController;return{promise:new Promise((u,a)=>{const f=Date.now(),E=w=>{l.signal.aborted||w>=r?u(null):_e(e,w,n).then(j=>{j===t?u({number:w,took:Date.now()-f}):E(w+1)}).catch(a)};E(o)}),controller:l}}var b=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t.EXPIRED="expired",t))(b||{});function at(t){Ve(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 pe(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(o,l){I(o,e,l),v(e,n),v(e,r)},d(o){o&&C(e)}}}function ht(t){let e,n=t[9].label+"",r;return{c(){e=p("label"),c(e,"for",r=t[3]+"_checkbox"),c(e,"class","svelte-vuofbg")},m(o,l){I(o,e,l),e.innerHTML=n},p(o,l){l[0]&512&&n!==(n=o[9].label+"")&&(e.innerHTML=n),l[0]&8&&r!==(r=o[3]+"_checkbox")&&c(e,"for",r)},d(o){o&&C(e)}}}function dt(t){let e,n=t[9].verifying+"";return{c(){e=p("span")},m(r,o){I(r,e,o),e.innerHTML=n},p(r,o){o[0]&512&&n!==(n=r[9].verifying+"")&&(e.innerHTML=n)},d(r){r&&C(e)}}}function gt(t){let e,n=t[9].verified+"",r,o;return{c(){e=p("span"),r=O(),o=p("input"),c(o,"type","hidden"),c(o,"name",t[3]),o.value=t[4]},m(l,s){I(l,e,s),e.innerHTML=n,I(l,r,s),I(l,o,s)},p(l,s){s[0]&512&&n!==(n=l[9].verified+"")&&(e.innerHTML=n),s[0]&8&&c(o,"name",l[3]),s[0]&16&&(o.value=l[4])},d(l){l&&(C(e),C(r),C(o))}}}function ye(t){let e,n,r,o,l,s;return{c(){e=p("div"),n=p("a"),r=V("svg"),o=V("path"),l=V("path"),s=V("path"),c(o,"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(o,"fill","currentColor"),c(l,"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(l,"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",Ee),c(n,"target","_blank"),c(n,"class","altcha-logo svelte-vuofbg")},m(u,a){I(u,e,a),v(e,n),v(n,r),v(r,o),v(r,l),v(r,s)},p:_,d(u){u&&C(e)}}}function $e(t){let e,n,r,o;function l(a,f){return a[5]===b.EXPIRED?mt:bt}let s=l(t),u=s(t);return{c(){e=p("div"),n=V("svg"),r=V("path"),o=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(a,f){I(a,e,f),v(e,n),v(n,r),v(e,o),u.m(e,null)},p(a,f){s===(s=l(a))&&u?u.p(a,f):(u.d(1),u=s(a),u&&(u.c(),u.m(e,null)))},d(a){a&&C(e),u.d()}}}function bt(t){let e,n=t[9].error+"";return{c(){e=p("div"),c(e,"title",t[8])},m(r,o){I(r,e,o),e.innerHTML=n},p(r,o){o[0]&512&&n!==(n=r[9].error+"")&&(e.innerHTML=n),o[0]&256&&c(e,"title",r[8])},d(r){r&&C(e)}}}function mt(t){let e,n=t[9].expired+"";return{c(){e=p("div"),c(e,"title",t[8])},m(r,o){I(r,e,o),e.innerHTML=n},p(r,o){o[0]&512&&n!==(n=r[9].expired+"")&&(e.innerHTML=n),o[0]&256&&c(e,"title",r[8])},d(r){r&&C(e)}}}function ke(t){let e,n,r=t[9].footer+"";return{c(){e=p("div"),n=p("div"),c(n,"class","svelte-vuofbg"),c(e,"class","altcha-footer svelte-vuofbg")},m(o,l){I(o,e,l),v(e,n),n.innerHTML=r},p(o,l){l[0]&512&&r!==(r=o[9].footer+"")&&(n.innerHTML=r)},d(o){o&&C(e)}}}function vt(t){let e,n,r,o,l,s,u,a,f,E,w,j,S,M,y=t[5]===b.VERIFYING&&pe();function F(h,d){return h[5]===b.VERIFIED?gt:h[5]===b.VERIFYING?dt:ht}let T=F(t),L=T(t),$=t[2]!==!0&&ye(),k=(t[8]||t[5]===b.EXPIRED)&&$e(t),m=t[9].footer&&t[1]!==!0&&ke(t);return{c(){e=p("div"),n=p("div"),y&&y.c(),r=O(),o=p("div"),l=p("input"),a=O(),f=p("div"),L.c(),E=O(),$&&$.c(),w=O(),k&&k.c(),j=O(),m&&m.c(),c(l,"type","checkbox"),c(l,"id",s=t[3]+"_checkbox"),l.required=u=t[0]!=="onsubmit",c(l,"class","svelte-vuofbg"),c(o,"class","altcha-checkbox svelte-vuofbg"),he(o,"altcha-hidden",t[5]===b.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(h,d){I(h,e,d),v(e,n),y&&y.m(n,null),v(n,r),v(n,o),v(o,l),l.checked=t[6],v(n,a),v(n,f),L.m(f,null),v(n,E),$&&$.m(n,null),v(e,w),k&&k.m(e,null),v(e,j),m&&m.m(e,null),t[26](e),S||(M=[ee(l,"change",t[25]),ee(l,"change",t[10]),ee(l,"invalid",t[11])],S=!0)},p(h,d){h[5]===b.VERIFYING?y||(y=pe(),y.c(),y.m(n,r)):y&&(y.d(1),y=null),d[0]&8&&s!==(s=h[3]+"_checkbox")&&c(l,"id",s),d[0]&1&&u!==(u=h[0]!=="onsubmit")&&(l.required=u),d[0]&64&&(l.checked=h[6]),d[0]&32&&he(o,"altcha-hidden",h[5]===b.VERIFYING),T===(T=F(h))&&L?L.p(h,d):(L.d(1),L=T(h),L&&(L.c(),L.m(f,null))),h[2]!==!0?$?$.p(h,d):($=ye(),$.c(),$.m(n,null)):$&&($.d(1),$=null),h[8]||h[5]===b.EXPIRED?k?k.p(h,d):(k=$e(h),k.c(),k.m(e,j)):k&&(k.d(1),k=null),h[9].footer&&h[1]!==!0?m?m.p(h,d):(m=ke(h),m.c(),m.m(e,null)):m&&(m.d(1),m=null),d[0]&32&&c(e,"data-state",h[5])},i:_,o:_,d(h){h&&C(e),y&&y.d(),L.d(),$&&$.d(),k&&k.d(),m&&m.d(),t[26](null),S=!1,B(M)}}}const Ee="https://altcha.org/";function xe(t){return JSON.parse(t)}function wt(t,e,n){let r,o,l,{auto:s=void 0}=e,{challengeurl:u=void 0}=e,{challengejson:a=void 0}=e,{debug:f=!1}=e,{expire:E=void 0}=e,{hidefooter:w=!1}=e,{hidelogo:j=!1}=e,{name:S="altcha"}=e,{maxnumber:M=1e6}=e,{mockerror:y=!1}=e,{strings:F=void 0}=e,{test:T=!1}=e,{workers:L=8}=e;const $=Ye(),k=["SHA-256","SHA-384","SHA-512"];let m=!1,h,d=null,le=null,X=null,Z=b.UNVERIFIED,se;Xe(()=>{d&&(d.removeEventListener("submit",Le),d.removeEventListener("reset",Ie),d=null)}),De(()=>{R("mounted","0.1.9"),T&&R("using test mode"),E&&ce(E),s!==void 0&&R("auto",s),d=h.closest("form"),d&&(d.addEventListener("submit",Le),d.addEventListener("reset",Ie)),s==="onload"&&Y()});function R(...i){(f||i.some(g=>g instanceof Error))&&console[i[0]instanceof Error?"error":"log"]("ALTCHA",...i)}function Le(i){d&&s==="onsubmit"&&Z===b.UNVERIFIED&&(i.preventDefault(),i.stopPropagation(),Y().then(()=>{d==null||d.requestSubmit()}))}function Ie(){z()}function _t(i,g){return btoa(JSON.stringify({algorithm:i.algorithm,challenge:i.challenge,number:g.number,salt:i.salt,signature:i.signature,test:T?!0:void 0,took:g.took}))}function Re(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(!k.includes(i.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${k.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 pt(){if(y)throw R("mocking error"),new Error("Mocked error.");if(r)return R("using provided json data"),r;if(T)return R("generating test challenge"),ut();{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 g=i.headers.get("Expires");if(g!=null&&g.length){const K=Date.parse(g);isNaN(K)||ce(K-Date.now())}return i.json()}}function Ne(){u&&Z===b.VERIFIED?Y():z(b.EXPIRED,l.expired)}async function yt(i){let g=null;if("Worker"in window){try{g=await $t(i.challenge,i.salt,i.algorithm)}catch(K){R(K)}if((g==null?void 0:g.number)!==void 0)return{data:i,solution:g}}return{data:i,solution:await ft(i.challenge,i.salt,i.algorithm,M).promise}}async function $t(i,g,K,ue=Math.ceil(L)){const q=[];if(ue<1)throw new Error("Wrong number of workers configured.");for(let G=0;G{const Ae=Rt*je;return new Promise(Nt=>{G.addEventListener("message",Me=>{if(Me.data)for(const Te of q)Te!==G&&Te.postMessage({type:"abort"});Nt(Me.data)}),G.postMessage({payload:{alg:K,challenge:i,max:Ae+je,salt:g,start:Ae},type:"work"})})}));for(const G of q)G.terminate();return It.find(G=>!!G)||null}function kt(){[b.UNVERIFIED,b.ERROR,b.EXPIRED].includes(Z)?Y():n(6,m=!0)}function Et(){Z===b.VERIFYING&&alert(l.waitAlert)}function ce(i){clearTimeout(se),i<1?Ne():se=setTimeout(Ne,i)}function xt(i){i.auto!==void 0&&(n(0,s=i.auto),s==="onload"&&Y()),i.expire!==void 0&&(ce(i.expire),n(13,E=i.expire)),i.challenge&&(Re(i.challenge),r=i.challenge),i.debug!==void 0&&n(12,f=!!i.debug),i.hidefooter!==void 0&&n(1,w=!!i.hidefooter),i.hidelogo!==void 0&&n(2,j=!!i.hidelogo),i.maxnumber!==void 0&&n(14,M=+i.maxnumber),i.mockerror!==void 0&&n(15,y=!!i.mockerror),i.name!==void 0&&n(3,S=i.name),i.test!==void 0&&n(16,T=!!i.test),i.strings&&n(24,o=i.strings)}function z(i=b.UNVERIFIED,g=null){clearTimeout(se),n(6,m=!1),n(8,le=g),n(4,X=null),n(5,Z=i)}async function Y(){return z(b.VERIFYING),pt().then(i=>(Re(i),R("challenge",i),yt(i))).then(({data:i,solution:g})=>{if(R("solution",g),(g==null?void 0:g.number)!==void 0)R("verified"),n(5,Z=b.VERIFIED),n(6,m=!0),n(4,X=_t(i,g)),R("payload",X),Ke().then(()=>{$("verified",{payload:X})});else throw new Error("Unexpected result returned.")}).catch(i=>{R(i),n(5,Z=b.ERROR),n(6,m=!1),n(8,le=i.message)})}function Ct(){m=this.checked,n(6,m)}function Lt(i){ne[i?"unshift":"push"](()=>{h=i,n(7,h)})}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,a=i.challengejson),"debug"in i&&n(12,f=i.debug),"expire"in i&&n(13,E=i.expire),"hidefooter"in i&&n(1,w=i.hidefooter),"hidelogo"in i&&n(2,j=i.hidelogo),"name"in i&&n(3,S=i.name),"maxnumber"in i&&n(14,M=i.maxnumber),"mockerror"in i&&n(15,y=i.mockerror),"strings"in i&&n(19,F=i.strings),"test"in i&&n(16,T=i.test),"workers"in i&&n(20,L=i.workers)},t.$$.update=()=>{t.$$.dirty[0]&262144&&(r=a?xe(a):void 0),t.$$.dirty[0]&524288&&n(24,o=F?xe(F):{}),t.$$.dirty[0]&16777216&&n(9,l={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.",...o}),t.$$.dirty[0]&48&&$("statechange",{payload:X,state:Z})},[s,w,j,S,X,Z,m,h,le,l,kt,Et,f,E,M,y,T,u,a,F,L,xt,z,Y,o,Ct,Lt]}class Ce extends rt{constructor(e){super(),tt(this,e,wt,vt,Se,{auto:0,challengeurl:17,challengejson:18,debug:12,expire:13,hidefooter:1,hidelogo:2,name:3,maxnumber:14,mockerror:15,strings:19,test:16,workers:20,configure:21,reset:22,verify:23},at,[-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 workers(){return this.$$.ctx[20]}set workers(e){this.$$set({workers:e}),x()}get configure(){return this.$$.ctx[21]}get reset(){return this.$$.ctx[22]}get verify(){return this.$$.ctx[23]}}customElements.define("altcha-widget",nt(Ce,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},expire:{},hidefooter:{type:"Boolean"},hidelogo:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"},workers:{}},[],["configure","reset","verify"],!1)),N.Altcha=Ce,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}); diff --git a/src/Altcha.svelte b/src/Altcha.svelte index 1ed6e80..fec92ad 100644 --- a/src/Altcha.svelte +++ b/src/Altcha.svelte @@ -18,10 +18,11 @@ export let hidefooter: boolean = false; export let hidelogo: boolean = false; export let name: string = 'altcha'; - export let maxnumber: number | undefined = undefined; + export let maxnumber: number = 1e6; export let mockerror: boolean = false; export let strings: string | undefined = undefined; export let test: boolean = false; + export let workers: number = 8; const dispatch = createEventDispatcher(); const allowedAlgs = ['SHA-256', 'SHA-384', 'SHA-512']; @@ -166,7 +167,7 @@ } function expireChallenge() { - if (false && challengeurl && state === State.VERIFIED) { + if (challengeurl && state === State.VERIFIED) { // re-fetch challenge and verify again verify(); @@ -192,23 +193,51 @@ } return { data, - solution: await solveChallenge(data.challenge, data.salt, data.algorithm, maxnumber), - } - } - - async function runWorker(challenge: string, salt: string, alg?: string): Promise { - const worker = new InlineWorker(); - return new Promise((resolve) => { - worker.addEventListener('message', (message: MessageEvent) => { - resolve(message.data); - }); - worker.postMessage({ - alg, - challenge, - max: maxnumber, - salt, - }); - }); + solution: await solveChallenge(data.challenge, data.salt, data.algorithm, maxnumber).promise, + } + } + + async function runWorker(challenge: string, salt: string, alg?: string, concurrency: number = Math.ceil(workers)): Promise { + const workers: Worker[] = []; + if (concurrency < 1) { + throw new Error('Wrong number of workers configured.'); + } + if (concurrency > 16) { + throw new Error('Too many workers. Max. 16 allowed workers.'); + } + for (let i = 0; i < concurrency; i ++) { + workers.push(new InlineWorker()); + } + const step = Math.ceil(maxnumber / concurrency); + const solutions = await Promise.all(workers.map((worker, i) => { + const start = i * step; + return new Promise((resolve) => { + worker.addEventListener('message', (message: MessageEvent) => { + if (message.data) { + for (const w of workers) { + if (w !== worker) { + w.postMessage({ type: 'abort' }); + } + } + } + resolve(message.data); + }); + worker.postMessage({ + payload: { + alg, + challenge, + max: start + step, + salt, + start, + }, + type: 'work', + }); + }) as Promise; + })); + for (const worker of workers) { + worker.terminate(); + } + return solutions.find((solution) => !!solution) || null; } function onCheckedChange() { diff --git a/src/helpers.ts b/src/helpers.ts index 4d4d9f7..a302c47 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,7 +1,5 @@ import type { Solution } from './types'; -const MAX = 1e7; - const encoder = new TextEncoder(); export function ab2hex(ab: ArrayBuffer) { @@ -24,16 +22,30 @@ export async function hashChallenge(salt: string, num: number, algorithm: string return ab2hex(await crypto.subtle.digest(algorithm.toUpperCase(), encoder.encode(salt + num))); } -export async function solveChallenge(challenge: string, salt: string, algorithm: string = 'SHA-256', max: number = MAX): Promise { - const start = Date.now(); - for (let i = 0; i <= max; i ++) { - const t = await hashChallenge(salt, i, algorithm); - if (t === challenge) { - return { - number: i, - took: Date.now() - start, - }; - } - } - return null; +export function solveChallenge(challenge: string, salt: string, algorithm: string = 'SHA-256', max: number = 1e6, start: number = 0): { promise: Promise; controller: AbortController } { + const controller = new AbortController(); + const promise = new Promise((resolve, reject) => { + const startTime = Date.now(); + const next = (n: number) => { + if (controller.signal.aborted || n >= max) { + resolve(null); + } else { + hashChallenge(salt, n, algorithm).then((t) => { + if (t === challenge) { + resolve({ + number: n, + took: Date.now() - startTime, + }); + } else { + next(n + 1); + } + }).catch(reject); + } + }; + next(start); + }) as Promise; + return { + promise, + controller, + }; } diff --git a/src/worker.ts b/src/worker.ts index 5040aca..7664414 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,12 +1,19 @@ import { solveChallenge } from './helpers'; +let controller: AbortController | undefined = undefined; + onmessage = async (message) => { - const { alg, challenge, max, salt } = message.data || {}; - if (challenge && salt) { - const solution = await solveChallenge(challenge, salt, alg, max); - self.postMessage(solution ? { ...solution, worker: true } : solution); - } else { - self.postMessage(null); + const { type, payload } = message.data + if (type === 'abort') { + controller?.abort(); + controller = undefined; + } else if (type === 'work') { + const { alg, challenge, max, salt, start } = payload || {}; + const result = solveChallenge(challenge, salt, alg, max, start); + controller = result.controller; + result.promise.then((solution) => { + self.postMessage(solution ? { ...solution, worker: true } : solution); + }); } }; diff --git a/tests/helpers.test.ts b/tests/helpers.test.ts index c73c45b..48b4f29 100644 --- a/tests/helpers.test.ts +++ b/tests/helpers.test.ts @@ -31,7 +31,7 @@ describe('createTestChallenge', () => { describe('solveChallenge', () => { test('should solve challenge and return number', async () => { const data = await createTestChallenge(10, alg); - const solution = await solveChallenge(data.challenge, data.salt, data.algorithm); + const solution = await solveChallenge(data.challenge, data.salt, data.algorithm).promise; expect(solution?.number).toBeDefined(); expect(solution?.took).toBeDefined(); const challenge = await hashChallenge(data.salt, solution!.number, alg);