altcha 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/altcha.iife.js +1 -1
- package/dist/altcha.js +140 -137
- package/dist/altcha.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/altcha.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var altcha=function(M){"use strict";var dt=Object.defineProperty;var gt=(M,C,U)=>C in M?dt(M,C,{enumerable:!0,configurable:!0,writable:!0,value:U}):M[C]=U;var N=(M,C,U)=>(gt(M,typeof C!="symbol"?C+"":C,U),U);function C(){}function U(t){return t()}function oe(){return Object.create(null)}function P(t){t.forEach(U)}function se(t){return typeof t=="function"}function pe(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function ye(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function ke(t,e,n){const i=Ee(t);if(!i.getElementById(e)){const l=w("style");l.id=e,l.textContent=n,Ce(i,l)}}function Ee(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ce(t,e){return g(t.head||t,e),e.sheet}function A(t,e,n){t.insertBefore(e,n||null)}function R(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 xe(t){return document.createTextNode(t)}function Y(){return xe(" ")}function Q(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function s(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ie(t){return Array.from(t.childNodes)}function ce(t,e,n){t.classList.toggle(e,!!n)}function Le(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function qe(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let T;function X(t){T=t}function ee(){if(!T)throw new Error("Function called outside component initialization");return T}function Ne(t){ee().$$.on_mount.push(t)}function Re(t){ee().$$.on_destroy.push(t)}function je(){const t=ee();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Le(e,n,{cancelable:i});return l.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const H=[],te=[];let B=[];const ae=[],Ae=Promise.resolve();let ne=!1;function Ge(){ne||(ne=!0,Ae.then(L))}function re(t){B.push(t)}const ie=new Set;let W=0;function L(){if(W!==0)return;const t=T;do{try{for(;W<H.length;){const e=H[W];W++,X(e),Se(e.$$)}}catch(e){throw H.length=0,W=0,e}for(X(null),H.length=0,W=0;te.length;)te.pop()();for(let e=0;e<B.length;e+=1){const n=B[e];ie.has(n)||(ie.add(n),n())}B.length=0}while(H.length);for(;ae.length;)ae.pop()();ne=!1,ie.clear(),X(t)}function Se(t){if(t.fragment!==null){t.update(),P(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(re)}}function Me(t){const e=[],n=[];B.forEach(i=>t.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Ve=new Set;function Fe(t,e){t&&t.i&&(Ve.delete(t),t.i(e))}function Ue(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),re(()=>{const r=t.$$.on_mount.map(U).filter(se);t.$$.on_destroy?t.$$.on_destroy.push(...r):P(r),t.$$.on_mount=[]}),l.forEach(re)}function Oe(t,e){const n=t.$$;n.fragment!==null&&(Me(n.after_update),P(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Ye(t,e){t.$$.dirty[0]===-1&&(H.push(t),Ge(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Ze(t,e,n,i,l,r,c=null,a=[-1]){const f=T;X(t);const u=t.$$={fragment:null,ctx:[],props:r,update:C,not_equal:l,bound:oe(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(f?f.$$.context:[])),callbacks:oe(),dirty:a,skip_bound:!1,root:e.target||f.$$.root};c&&c(u.root);let G=!1;if(u.ctx=n?n(t,e.props||{},(y,E,...b)=>{const q=b.length?b[0]:E;return u.ctx&&l(u.ctx[y],u.ctx[y]=q)&&(!u.skip_bound&&u.bound[y]&&u.bound[y](q),G&&Ye(t,y)),E}):[],u.update(),G=!0,P(u.before_update),u.fragment=i?i(u.ctx):!1,e.target){if(e.hydrate){const y=Ie(e.target);u.fragment&&u.fragment.l(y),y.forEach(R)}else u.fragment&&u.fragment.c();e.intro&&Fe(t.$$.fragment),Ue(t,e.target,e.anchor),L()}X(f)}let ue;typeof HTMLElement=="function"&&(ue=class extends HTMLElement{constructor(e,n,i){super();N(this,"$$ctor");N(this,"$$s");N(this,"$$c");N(this,"$$cn",!1);N(this,"$$d",{});N(this,"$$r",!1);N(this,"$$p_d",{});N(this,"$$l",{});N(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=w("slot"),r!=="default"&&s(c,"name",r)},m:function(u,G){A(u,c,G)},d:function(u){u&&R(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},i=qe(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=K(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const c=K(r,this.$$d[r],this.$$p_d,"toAttribute");c==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,c)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const c of this.$$l[r]){const a=this.$$c.$on(r,c);this.$$l_u.set(c,a)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=K(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}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 K(t,e,n,i){var r;const l=(r=n[t])==null?void 0:r.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function He(t,e,n,i,l,r){let c=class extends ue{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(c.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(f){var u;f=K(a,f,e),this.$$d[a]=f,(u=this.$$c)==null||u.$set({[a]:f})}})}),i.forEach(a=>{Object.defineProperty(c.prototype,a,{get(){var f;return(f=this.$$c)==null?void 0:f[a]}})}),r&&(c=r(c)),t.element=c,c}class Be{constructor(){N(this,"$$");N(this,"$$set")}$destroy(){Oe(this,1),this.$destroy=C}$on(e,n){if(!se(n))return C;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const l=i.indexOf(n);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!ye(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const We="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(We);const fe="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",he=typeof window<"u"&&window.Blob&&new Blob([atob(fe)],{type:"text/javascript;charset=utf-8"});function Pe(){let t;try{if(t=he&&(window.URL||window.webkitURL).createObjectURL(he),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+fe)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Te=1e7,Xe=new TextEncoder;function De(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Ke(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await de(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function de(t,e,n){return De(await crypto.subtle.digest(n.toUpperCase(),Xe.encode(t+e)))}async function ze(t,e,n="SHA-256",i=Te){const l=Date.now();for(let r=0;r<=i;r++)if(await de(e,r,n)===t)return{number:r,took:Date.now()-l};return null}var p=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(p||{});function Je(t){ke(t,"svelte-fqcw55",".altcha.svelte-fqcw55.svelte-fqcw55{background:var(--altcha-color-base, transparent);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative;text-align:left}.altcha.svelte-fqcw55.svelte-fqcw55:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-fqcw55.svelte-fqcw55{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-fqcw55.svelte-fqcw55{flex-grow:1}.altcha-label.svelte-fqcw55 label.svelte-fqcw55{cursor:pointer}.altcha-logo.svelte-fqcw55.svelte-fqcw55{color:currentColor;opacity:0.3}.altcha-logo.svelte-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-error.svelte-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-footer.svelte-fqcw55>.svelte-fqcw55:first-child{flex-grow:1}.altcha-footer.svelte-fqcw55 a{color:currentColor}.altcha-checkbox.svelte-fqcw55.svelte-fqcw55{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-fqcw55 input.svelte-fqcw55{width:18px;height:18px;margin:0}.altcha-hidden.svelte-fqcw55.svelte-fqcw55{display:none}.altcha-spinner.svelte-fqcw55.svelte-fqcw55{animation:svelte-fqcw55-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-fqcw55-altcha-spinner{100%{transform:rotate(360deg)}}")}function ge(t){let e,n,i;return{c(){e=V("svg"),n=V("path"),i=V("path"),s(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"),s(n,"fill","currentColor"),s(n,"opacity",".25"),s(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),s(i,"fill","currentColor"),s(i,"class","altcha-spinner svelte-fqcw55"),s(e,"width","24"),s(e,"height","24"),s(e,"viewBox","0 0 24 24"),s(e,"xmlns","http://www.w3.org/2000/svg")},m(l,r){A(l,e,r),g(e,n),g(e,i)},d(l){l&&R(e)}}}function Qe(t){let e,n=t[8].label+"",i;return{c(){e=w("label"),s(e,"for",i=t[2]+"_checkbox"),s(e,"class","svelte-fqcw55")},m(l,r){A(l,e,r),e.innerHTML=n},p(l,r){r[0]&256&&n!==(n=l[8].label+"")&&(e.innerHTML=n),r[0]&4&&i!==(i=l[2]+"_checkbox")&&s(e,"for",i)},d(l){l&&R(e)}}}function et(t){let e,n=t[8].verifying+"";return{c(){e=w("span")},m(i,l){A(i,e,l),e.innerHTML=n},p(i,l){l[0]&256&&n!==(n=i[8].verifying+"")&&(e.innerHTML=n)},d(i){i&&R(e)}}}function tt(t){let e,n=t[8].verified+"",i,l;return{c(){e=w("span"),i=Y(),l=w("input"),s(l,"type","hidden"),s(l,"name",t[2]),l.value=t[3]},m(r,c){A(r,e,c),e.innerHTML=n,A(r,i,c),A(r,l,c)},p(r,c){c[0]&256&&n!==(n=r[8].verified+"")&&(e.innerHTML=n),c[0]&4&&s(l,"name",r[2]),c[0]&8&&(l.value=r[3])},d(r){r&&(R(e),R(i),R(l))}}}function me(t){let e,n,i,l,r,c=t[8].error+"";return{c(){e=w("div"),n=V("svg"),i=V("path"),l=Y(),r=w("div"),s(i,"stroke-linecap","round"),s(i,"stroke-linejoin","round"),s(i,"d","M6 18L18 6M6 6l12 12"),s(n,"width","14"),s(n,"height","14"),s(n,"xmlns","http://www.w3.org/2000/svg"),s(n,"fill","none"),s(n,"viewBox","0 0 24 24"),s(n,"stroke-width","1.5"),s(n,"stroke","currentColor"),s(r,"title",t[7]),s(e,"class","altcha-error svelte-fqcw55")},m(a,f){A(a,e,f),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=c},p(a,f){f[0]&256&&c!==(c=a[8].error+"")&&(r.innerHTML=c),f[0]&128&&s(r,"title",a[7])},d(a){a&&R(e)}}}function we(t){let e,n,i=t[8].footer+"";return{c(){e=w("div"),n=w("div"),s(n,"class","svelte-fqcw55"),s(e,"class","altcha-footer svelte-fqcw55")},m(l,r){A(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&256&&i!==(i=l[8].footer+"")&&(n.innerHTML=i)},d(l){l&&R(e)}}}function nt(t){let e,n,i,l,r,c,a,f,u,G,y,E,b,q,S,Z,D,j,O,k,$=t[4]===p.VERIFYING&&ge();function F(h,I){return h[4]===p.VERIFIED?tt:h[4]===p.VERIFYING?et:Qe}let x=F(t),d=x(t),v=t[7]&&me(t),_=t[8].footer&&t[1]!==!0&&we(t);return{c(){e=w("div"),n=w("div"),$&&$.c(),i=Y(),l=w("div"),r=w("input"),f=Y(),u=w("div"),d.c(),G=Y(),y=w("div"),E=w("a"),b=V("svg"),q=V("path"),S=V("path"),Z=V("path"),D=Y(),v&&v.c(),j=Y(),_&&_.c(),s(r,"type","checkbox"),s(r,"id",c=t[2]+"_checkbox"),r.required=a=t[0]!=="onsubmit",s(r,"class","svelte-fqcw55"),s(l,"class","altcha-checkbox svelte-fqcw55"),ce(l,"altcha-hidden",t[4]===p.VERIFYING),s(u,"class","altcha-label svelte-fqcw55"),s(q,"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"),s(q,"fill","currentColor"),s(S,"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"),s(S,"fill","currentColor"),s(Z,"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"),s(Z,"fill","currentColor"),s(b,"width","22"),s(b,"height","22"),s(b,"viewBox","0 0 20 20"),s(b,"fill","none"),s(b,"xmlns","http://www.w3.org/2000/svg"),s(E,"href",be),s(E,"target","_blank"),s(E,"class","altcha-logo svelte-fqcw55"),s(n,"class","altcha-main svelte-fqcw55"),s(e,"class","altcha svelte-fqcw55"),s(e,"data-state",t[4])},m(h,I){A(h,e,I),g(e,n),$&&$.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[5],g(n,f),g(n,u),d.m(u,null),g(n,G),g(n,y),g(y,E),g(E,b),g(b,q),g(b,S),g(b,Z),g(e,D),v&&v.m(e,null),g(e,j),_&&_.m(e,null),t[22](e),O||(k=[Q(r,"change",t[21]),Q(r,"change",t[9]),Q(r,"invalid",t[10])],O=!0)},p(h,I){h[4]===p.VERIFYING?$||($=ge(),$.c(),$.m(n,i)):$&&($.d(1),$=null),I[0]&4&&c!==(c=h[2]+"_checkbox")&&s(r,"id",c),I[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),I[0]&32&&(r.checked=h[5]),I[0]&16&&ce(l,"altcha-hidden",h[4]===p.VERIFYING),x===(x=F(h))&&d?d.p(h,I):(d.d(1),d=x(h),d&&(d.c(),d.m(u,null))),h[7]?v?v.p(h,I):(v=me(h),v.c(),v.m(e,j)):v&&(v.d(1),v=null),h[8].footer&&h[1]!==!0?_?_.p(h,I):(_=we(h),_.c(),_.m(e,null)):_&&(_.d(1),_=null),I[0]&16&&s(e,"data-state",h[4])},i:C,o:C,d(h){h&&R(e),$&&$.d(),d.d(),v&&v.d(),_&&_.d(),t[22](null),O=!1,P(k)}}}const be="https://altcha.org/";function $e(t){return JSON.parse(t)}function rt(t,e,n){let i,l,r,{auto:c=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:f=void 0}=e,{debug:u=!1}=e,{hidefooter:G=!1}=e,{name:y="altcha"}=e,{maxnumber:E=void 0}=e,{mockerror:b=!1}=e,{strings:q=void 0}=e,{test:S=!1}=e;const Z=je(),D=["SHA-256","SHA-384","SHA-512"];let j=!1,O,k=null,$=null,F=null,x=p.UNVERIFIED;Re(()=>{k&&(k.removeEventListener("submit",v),k.removeEventListener("reset",_),k=null)}),Ne(()=>{d("mounted","0.1.4"),S&&d("using test mode"),c!==void 0&&d("auto",c),k=O.closest("form"),k&&(k.addEventListener("submit",v),k.addEventListener("reset",_)),c==="onload"&&J()});function d(...o){(u||o.some(m=>m instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function v(o){k&&c==="onsubmit"&&x===p.UNVERIFIED?(o.preventDefault(),o.stopPropagation(),J().then(()=>{k==null||k.submit()})):requestAnimationFrame(()=>{z()})}function _(){z()}function h(o,m){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:m.number,salt:o.salt,signature:o.signature,test:S?!0:void 0,took:m.took}))}function I(o){if(!o.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(o.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!D.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${D.join(", ")}`);if(!o.challenge||o.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!o.salt||o.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function it(){if(b)throw d("mocking error"),new Error("Mocked error.");if(i)return d("using provided json data"),i;if(S)return d("generating test challenge"),Ke();{if(!a)throw new Error("Attribute challengeurl not set.");d("fetching challenge from",a);const o=await fetch(a);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);return o.json()}}async function lt(o){let m=null;if("Worker"in window){try{m=await ot(o.challenge,o.salt,o.algorithm)}catch(le){d(le)}if((m==null?void 0:m.number)!==void 0)return{data:o,solution:m}}return{data:o,solution:await ze(o.challenge,o.salt,o.algorithm,E)}}async function ot(o,m,le){const _e=new Pe;return new Promise(ft=>{_e.addEventListener("message",ht=>{ft(ht.data)}),_e.postMessage({alg:le,challenge:o,max:E,salt:m})})}function st(){[p.UNVERIFIED,p.ERROR].includes(x)?J():n(5,j=!0)}function ct(){x===p.VERIFYING&&alert(r.waitAlert)}function z(o=p.UNVERIFIED){n(5,j=!1),n(7,$=null),n(3,F=null),n(4,x=o)}async function J(){return z(p.VERIFYING),it().then(o=>(I(o),d("challenge",o),lt(o))).then(({data:o,solution:m})=>{if(d("solution",m),(m==null?void 0:m.number)!==void 0)d("verified"),n(4,x=p.VERIFIED),n(5,j=!0),n(3,F=h(o,m)),Z("verified",{payload:F}),d("payload",F);else throw new Error("Unexpected result returned.")}).catch(o=>{d(o),n(4,x=p.ERROR),n(5,j=!1),n(7,$=o)})}function at(){j=this.checked,n(5,j)}function ut(o){te[o?"unshift":"push"](()=>{O=o,n(6,O)})}return t.$$set=o=>{"auto"in o&&n(0,c=o.auto),"challengeurl"in o&&n(11,a=o.challengeurl),"challengejson"in o&&n(12,f=o.challengejson),"debug"in o&&n(13,u=o.debug),"hidefooter"in o&&n(1,G=o.hidefooter),"name"in o&&n(2,y=o.name),"maxnumber"in o&&n(14,E=o.maxnumber),"mockerror"in o&&n(15,b=o.mockerror),"strings"in o&&n(16,q=o.strings),"test"in o&&n(17,S=o.test)},t.$$.update=()=>{t.$$.dirty[0]&4096&&(i=f?$e(f):void 0),t.$$.dirty[0]&65536&&n(20,l=q?$e(q):{}),t.$$.dirty[0]&1048576&&n(8,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${be}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&24&&Z("statechange",{payload:F,state:x})},[c,G,y,F,x,j,O,$,r,st,ct,a,f,u,E,b,q,S,z,J,l,at,ut]}class ve extends Be{constructor(e){super(),Ze(this,e,rt,nt,pe,{auto:0,challengeurl:11,challengejson:12,debug:13,hidefooter:1,name:2,maxnumber:14,mockerror:15,strings:16,test:17,reset:18,verify:19},Je,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),L()}get challengeurl(){return this.$$.ctx[11]}set challengeurl(e){this.$$set({challengeurl:e}),L()}get challengejson(){return this.$$.ctx[12]}set challengejson(e){this.$$set({challengejson:e}),L()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),L()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),L()}get name(){return this.$$.ctx[2]}set name(e){this.$$set({name:e}),L()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),L()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),L()}get strings(){return this.$$.ctx[16]}set strings(e){this.$$set({strings:e}),L()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),L()}get reset(){return this.$$.ctx[18]}get verify(){return this.$$.ctx[19]}}return customElements.define("altcha-widget",He(ve,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset","verify"],!1)),M.Altcha=ve,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),M}({});
|
|
1
|
+
var altcha=function(M){"use strict";var gt=Object.defineProperty;var mt=(M,C,F)=>C in M?gt(M,C,{enumerable:!0,configurable:!0,writable:!0,value:F}):M[C]=F;var N=(M,C,F)=>(mt(M,typeof C!="symbol"?C+"":C,F),F);function C(){}function F(t){return t()}function oe(){return Object.create(null)}function P(t){t.forEach(F)}function se(t){return typeof t=="function"}function ke(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ee(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function Ce(t,e,n){const i=xe(t);if(!i.getElementById(e)){const l=w("style");l.id=e,l.textContent=n,Ie(i,l)}}function xe(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ie(t,e){return g(t.head||t,e),e.sheet}function A(t,e,n){t.insertBefore(e,n||null)}function R(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 Le(t){return document.createTextNode(t)}function Y(){return Le(" ")}function J(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function s(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function qe(t){return Array.from(t.childNodes)}function ce(t,e,n){t.classList.toggle(e,!!n)}function Ne(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function Re(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let T;function X(t){T=t}function Q(){if(!T)throw new Error("Function called outside component initialization");return T}function je(t){Q().$$.on_mount.push(t)}function Ae(t){Q().$$.on_destroy.push(t)}function Ge(){const t=Q();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Ne(e,n,{cancelable:i});return l.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const H=[],ee=[];let B=[];const ae=[],ue=Promise.resolve();let te=!1;function fe(){te||(te=!0,ue.then(L))}function Se(){return fe(),ue}function ne(t){B.push(t)}const re=new Set;let W=0;function L(){if(W!==0)return;const t=T;do{try{for(;W<H.length;){const e=H[W];W++,X(e),Me(e.$$)}}catch(e){throw H.length=0,W=0,e}for(X(null),H.length=0,W=0;ee.length;)ee.pop()();for(let e=0;e<B.length;e+=1){const n=B[e];re.has(n)||(re.add(n),n())}B.length=0}while(H.length);for(;ae.length;)ae.pop()();te=!1,re.clear(),X(t)}function Me(t){if(t.fragment!==null){t.update(),P(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(ne)}}function Ve(t){const e=[],n=[];B.forEach(i=>t.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Ue=new Set;function Fe(t,e){t&&t.i&&(Ue.delete(t),t.i(e))}function Oe(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),ne(()=>{const r=t.$$.on_mount.map(F).filter(se);t.$$.on_destroy?t.$$.on_destroy.push(...r):P(r),t.$$.on_mount=[]}),l.forEach(ne)}function Ye(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),P(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Ze(t,e){t.$$.dirty[0]===-1&&(H.push(t),fe(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function He(t,e,n,i,l,r,c=null,a=[-1]){const f=T;X(t);const u=t.$$={fragment:null,ctx:[],props:r,update:C,not_equal:l,bound:oe(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(f?f.$$.context:[])),callbacks:oe(),dirty:a,skip_bound:!1,root:e.target||f.$$.root};c&&c(u.root);let G=!1;if(u.ctx=n?n(t,e.props||{},(y,E,...b)=>{const q=b.length?b[0]:E;return u.ctx&&l(u.ctx[y],u.ctx[y]=q)&&(!u.skip_bound&&u.bound[y]&&u.bound[y](q),G&&Ze(t,y)),E}):[],u.update(),G=!0,P(u.before_update),u.fragment=i?i(u.ctx):!1,e.target){if(e.hydrate){const y=qe(e.target);u.fragment&&u.fragment.l(y),y.forEach(R)}else u.fragment&&u.fragment.c();e.intro&&Fe(t.$$.fragment),Oe(t,e.target,e.anchor),L()}X(f)}let he;typeof HTMLElement=="function"&&(he=class extends HTMLElement{constructor(e,n,i){super();N(this,"$$ctor");N(this,"$$s");N(this,"$$c");N(this,"$$cn",!1);N(this,"$$d",{});N(this,"$$r",!1);N(this,"$$p_d",{});N(this,"$$l",{});N(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=w("slot"),r!=="default"&&s(c,"name",r)},m:function(u,G){A(u,c,G)},d:function(u){u&&R(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},i=Re(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=K(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const c=K(r,this.$$d[r],this.$$p_d,"toAttribute");c==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,c)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const c of this.$$l[r]){const a=this.$$c.$on(r,c);this.$$l_u.set(c,a)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=K(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}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 K(t,e,n,i){var r;const l=(r=n[t])==null?void 0:r.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Be(t,e,n,i,l,r){let c=class extends he{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(c.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(f){var u;f=K(a,f,e),this.$$d[a]=f,(u=this.$$c)==null||u.$set({[a]:f})}})}),i.forEach(a=>{Object.defineProperty(c.prototype,a,{get(){var f;return(f=this.$$c)==null?void 0:f[a]}})}),r&&(c=r(c)),t.element=c,c}class We{constructor(){N(this,"$$");N(this,"$$set")}$destroy(){Ye(this,1),this.$destroy=C}$on(e,n){if(!se(n))return C;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const l=i.indexOf(n);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Ee(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Pe="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Pe);const de="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",ge=typeof window<"u"&&window.Blob&&new Blob([atob(de)],{type:"text/javascript;charset=utf-8"});function Te(){let t;try{if(t=ge&&(window.URL||window.webkitURL).createObjectURL(ge),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+de)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Xe=1e7,De=new TextEncoder;function Ke(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ze(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await me(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function me(t,e,n){return Ke(await crypto.subtle.digest(n.toUpperCase(),De.encode(t+e)))}async function Je(t,e,n="SHA-256",i=Xe){const l=Date.now();for(let r=0;r<=i;r++)if(await me(e,r,n)===t)return{number:r,took:Date.now()-l};return null}var p=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(p||{});function Qe(t){Ce(t,"svelte-fqcw55",".altcha.svelte-fqcw55.svelte-fqcw55{background:var(--altcha-color-base, transparent);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative;text-align:left}.altcha.svelte-fqcw55.svelte-fqcw55:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-fqcw55.svelte-fqcw55{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-fqcw55.svelte-fqcw55{flex-grow:1}.altcha-label.svelte-fqcw55 label.svelte-fqcw55{cursor:pointer}.altcha-logo.svelte-fqcw55.svelte-fqcw55{color:currentColor;opacity:0.3}.altcha-logo.svelte-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-error.svelte-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-footer.svelte-fqcw55>.svelte-fqcw55:first-child{flex-grow:1}.altcha-footer.svelte-fqcw55 a{color:currentColor}.altcha-checkbox.svelte-fqcw55.svelte-fqcw55{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-fqcw55 input.svelte-fqcw55{width:18px;height:18px;margin:0}.altcha-hidden.svelte-fqcw55.svelte-fqcw55{display:none}.altcha-spinner.svelte-fqcw55.svelte-fqcw55{animation:svelte-fqcw55-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-fqcw55-altcha-spinner{100%{transform:rotate(360deg)}}")}function we(t){let e,n,i;return{c(){e=V("svg"),n=V("path"),i=V("path"),s(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"),s(n,"fill","currentColor"),s(n,"opacity",".25"),s(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),s(i,"fill","currentColor"),s(i,"class","altcha-spinner svelte-fqcw55"),s(e,"width","24"),s(e,"height","24"),s(e,"viewBox","0 0 24 24"),s(e,"xmlns","http://www.w3.org/2000/svg")},m(l,r){A(l,e,r),g(e,n),g(e,i)},d(l){l&&R(e)}}}function et(t){let e,n=t[8].label+"",i;return{c(){e=w("label"),s(e,"for",i=t[2]+"_checkbox"),s(e,"class","svelte-fqcw55")},m(l,r){A(l,e,r),e.innerHTML=n},p(l,r){r[0]&256&&n!==(n=l[8].label+"")&&(e.innerHTML=n),r[0]&4&&i!==(i=l[2]+"_checkbox")&&s(e,"for",i)},d(l){l&&R(e)}}}function tt(t){let e,n=t[8].verifying+"";return{c(){e=w("span")},m(i,l){A(i,e,l),e.innerHTML=n},p(i,l){l[0]&256&&n!==(n=i[8].verifying+"")&&(e.innerHTML=n)},d(i){i&&R(e)}}}function nt(t){let e,n=t[8].verified+"",i,l;return{c(){e=w("span"),i=Y(),l=w("input"),s(l,"type","hidden"),s(l,"name",t[2]),l.value=t[3]},m(r,c){A(r,e,c),e.innerHTML=n,A(r,i,c),A(r,l,c)},p(r,c){c[0]&256&&n!==(n=r[8].verified+"")&&(e.innerHTML=n),c[0]&4&&s(l,"name",r[2]),c[0]&8&&(l.value=r[3])},d(r){r&&(R(e),R(i),R(l))}}}function be(t){let e,n,i,l,r,c=t[8].error+"";return{c(){e=w("div"),n=V("svg"),i=V("path"),l=Y(),r=w("div"),s(i,"stroke-linecap","round"),s(i,"stroke-linejoin","round"),s(i,"d","M6 18L18 6M6 6l12 12"),s(n,"width","14"),s(n,"height","14"),s(n,"xmlns","http://www.w3.org/2000/svg"),s(n,"fill","none"),s(n,"viewBox","0 0 24 24"),s(n,"stroke-width","1.5"),s(n,"stroke","currentColor"),s(r,"title",t[7]),s(e,"class","altcha-error svelte-fqcw55")},m(a,f){A(a,e,f),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=c},p(a,f){f[0]&256&&c!==(c=a[8].error+"")&&(r.innerHTML=c),f[0]&128&&s(r,"title",a[7])},d(a){a&&R(e)}}}function $e(t){let e,n,i=t[8].footer+"";return{c(){e=w("div"),n=w("div"),s(n,"class","svelte-fqcw55"),s(e,"class","altcha-footer svelte-fqcw55")},m(l,r){A(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&256&&i!==(i=l[8].footer+"")&&(n.innerHTML=i)},d(l){l&&R(e)}}}function rt(t){let e,n,i,l,r,c,a,f,u,G,y,E,b,q,S,Z,D,j,O,k,$=t[4]===p.VERIFYING&&we();function U(h,I){return h[4]===p.VERIFIED?nt:h[4]===p.VERIFYING?tt:et}let x=U(t),d=x(t),v=t[7]&&be(t),_=t[8].footer&&t[1]!==!0&&$e(t);return{c(){e=w("div"),n=w("div"),$&&$.c(),i=Y(),l=w("div"),r=w("input"),f=Y(),u=w("div"),d.c(),G=Y(),y=w("div"),E=w("a"),b=V("svg"),q=V("path"),S=V("path"),Z=V("path"),D=Y(),v&&v.c(),j=Y(),_&&_.c(),s(r,"type","checkbox"),s(r,"id",c=t[2]+"_checkbox"),r.required=a=t[0]!=="onsubmit",s(r,"class","svelte-fqcw55"),s(l,"class","altcha-checkbox svelte-fqcw55"),ce(l,"altcha-hidden",t[4]===p.VERIFYING),s(u,"class","altcha-label svelte-fqcw55"),s(q,"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"),s(q,"fill","currentColor"),s(S,"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"),s(S,"fill","currentColor"),s(Z,"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"),s(Z,"fill","currentColor"),s(b,"width","22"),s(b,"height","22"),s(b,"viewBox","0 0 20 20"),s(b,"fill","none"),s(b,"xmlns","http://www.w3.org/2000/svg"),s(E,"href",ve),s(E,"target","_blank"),s(E,"class","altcha-logo svelte-fqcw55"),s(n,"class","altcha-main svelte-fqcw55"),s(e,"class","altcha svelte-fqcw55"),s(e,"data-state",t[4])},m(h,I){A(h,e,I),g(e,n),$&&$.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[5],g(n,f),g(n,u),d.m(u,null),g(n,G),g(n,y),g(y,E),g(E,b),g(b,q),g(b,S),g(b,Z),g(e,D),v&&v.m(e,null),g(e,j),_&&_.m(e,null),t[22](e),O||(k=[J(r,"change",t[21]),J(r,"change",t[9]),J(r,"invalid",t[10])],O=!0)},p(h,I){h[4]===p.VERIFYING?$||($=we(),$.c(),$.m(n,i)):$&&($.d(1),$=null),I[0]&4&&c!==(c=h[2]+"_checkbox")&&s(r,"id",c),I[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),I[0]&32&&(r.checked=h[5]),I[0]&16&&ce(l,"altcha-hidden",h[4]===p.VERIFYING),x===(x=U(h))&&d?d.p(h,I):(d.d(1),d=x(h),d&&(d.c(),d.m(u,null))),h[7]?v?v.p(h,I):(v=be(h),v.c(),v.m(e,j)):v&&(v.d(1),v=null),h[8].footer&&h[1]!==!0?_?_.p(h,I):(_=$e(h),_.c(),_.m(e,null)):_&&(_.d(1),_=null),I[0]&16&&s(e,"data-state",h[4])},i:C,o:C,d(h){h&&R(e),$&&$.d(),d.d(),v&&v.d(),_&&_.d(),t[22](null),O=!1,P(k)}}}const ve="https://altcha.org/";function _e(t){return JSON.parse(t)}function it(t,e,n){let i,l,r,{auto:c=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:f=void 0}=e,{debug:u=!1}=e,{hidefooter:G=!1}=e,{name:y="altcha"}=e,{maxnumber:E=void 0}=e,{mockerror:b=!1}=e,{strings:q=void 0}=e,{test:S=!1}=e;const Z=Ge(),D=["SHA-256","SHA-384","SHA-512"];let j=!1,O,k=null,$=null,U=null,x=p.UNVERIFIED;Ae(()=>{k&&(k.removeEventListener("submit",v),k.removeEventListener("reset",_),k=null)}),je(()=>{d("mounted","0.1.5"),S&&d("using test mode"),c!==void 0&&d("auto",c),k=O.closest("form"),k&&(k.addEventListener("submit",v),k.addEventListener("reset",_)),c==="onload"&&z()});function d(...o){(u||o.some(m=>m instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function v(o){k&&c==="onsubmit"&&x===p.UNVERIFIED&&(o.preventDefault(),o.stopPropagation(),z().then(()=>{k==null||k.requestSubmit()}))}function _(){ie()}function h(o,m){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:m.number,salt:o.salt,signature:o.signature,test:S?!0:void 0,took:m.took}))}function I(o){if(!o.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(o.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!D.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${D.join(", ")}`);if(!o.challenge||o.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!o.salt||o.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function lt(){if(b)throw d("mocking error"),new Error("Mocked error.");if(i)return d("using provided json data"),i;if(S)return d("generating test challenge"),ze();{if(!a)throw new Error("Attribute challengeurl not set.");d("fetching challenge from",a);const o=await fetch(a);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);return o.json()}}async function ot(o){let m=null;if("Worker"in window){try{m=await st(o.challenge,o.salt,o.algorithm)}catch(le){d(le)}if((m==null?void 0:m.number)!==void 0)return{data:o,solution:m}}return{data:o,solution:await Je(o.challenge,o.salt,o.algorithm,E)}}async function st(o,m,le){const ye=new Te;return new Promise(ht=>{ye.addEventListener("message",dt=>{ht(dt.data)}),ye.postMessage({alg:le,challenge:o,max:E,salt:m})})}function ct(){[p.UNVERIFIED,p.ERROR].includes(x)?z():n(5,j=!0)}function at(){x===p.VERIFYING&&alert(r.waitAlert)}function ie(o=p.UNVERIFIED){n(5,j=!1),n(7,$=null),n(3,U=null),n(4,x=o)}async function z(){return ie(p.VERIFYING),lt().then(o=>(I(o),d("challenge",o),ot(o))).then(({data:o,solution:m})=>{if(d("solution",m),(m==null?void 0:m.number)!==void 0)d("verified"),n(4,x=p.VERIFIED),n(5,j=!0),n(3,U=h(o,m)),d("payload",U),Se().then(()=>{Z("verified",{payload:U})});else throw new Error("Unexpected result returned.")}).catch(o=>{d(o),n(4,x=p.ERROR),n(5,j=!1),n(7,$=o)})}function ut(){j=this.checked,n(5,j)}function ft(o){ee[o?"unshift":"push"](()=>{O=o,n(6,O)})}return t.$$set=o=>{"auto"in o&&n(0,c=o.auto),"challengeurl"in o&&n(11,a=o.challengeurl),"challengejson"in o&&n(12,f=o.challengejson),"debug"in o&&n(13,u=o.debug),"hidefooter"in o&&n(1,G=o.hidefooter),"name"in o&&n(2,y=o.name),"maxnumber"in o&&n(14,E=o.maxnumber),"mockerror"in o&&n(15,b=o.mockerror),"strings"in o&&n(16,q=o.strings),"test"in o&&n(17,S=o.test)},t.$$.update=()=>{t.$$.dirty[0]&4096&&(i=f?_e(f):void 0),t.$$.dirty[0]&65536&&n(20,l=q?_e(q):{}),t.$$.dirty[0]&1048576&&n(8,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ve}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&24&&Z("statechange",{payload:U,state:x})},[c,G,y,U,x,j,O,$,r,ct,at,a,f,u,E,b,q,S,ie,z,l,ut,ft]}class pe extends We{constructor(e){super(),He(this,e,it,rt,ke,{auto:0,challengeurl:11,challengejson:12,debug:13,hidefooter:1,name:2,maxnumber:14,mockerror:15,strings:16,test:17,reset:18,verify:19},Qe,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),L()}get challengeurl(){return this.$$.ctx[11]}set challengeurl(e){this.$$set({challengeurl:e}),L()}get challengejson(){return this.$$.ctx[12]}set challengejson(e){this.$$set({challengejson:e}),L()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),L()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),L()}get name(){return this.$$.ctx[2]}set name(e){this.$$set({name:e}),L()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),L()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),L()}get strings(){return this.$$.ctx[16]}set strings(e){this.$$set({strings:e}),L()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),L()}get reset(){return this.$$.ctx[18]}get verify(){return this.$$.ctx[19]}}return customElements.define("altcha-widget",Be(pe,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset","verify"],!1)),M.Altcha=pe,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),M}({});
|
package/dist/altcha.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var L = (t, e, n) => (
|
|
1
|
+
var Ne = Object.defineProperty;
|
|
2
|
+
var Re = (t, e, n) => e in t ? Ne(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var L = (t, e, n) => (Re(t, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
4
|
function W() {
|
|
5
5
|
}
|
|
6
6
|
function de(t) {
|
|
@@ -15,23 +15,23 @@ function T(t) {
|
|
|
15
15
|
function ge(t) {
|
|
16
16
|
return typeof t == "function";
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function je(t, e) {
|
|
19
19
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function Ge(t) {
|
|
22
22
|
return Object.keys(t).length === 0;
|
|
23
23
|
}
|
|
24
24
|
function g(t, e) {
|
|
25
25
|
t.appendChild(e);
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const i =
|
|
27
|
+
function Ae(t, e, n) {
|
|
28
|
+
const i = Se(t);
|
|
29
29
|
if (!i.getElementById(e)) {
|
|
30
30
|
const l = v("style");
|
|
31
|
-
l.id = e, l.textContent = n,
|
|
31
|
+
l.id = e, l.textContent = n, Ve(i, l);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function Se(t) {
|
|
35
35
|
if (!t)
|
|
36
36
|
return document;
|
|
37
37
|
const e = t.getRootNode ? t.getRootNode() : t.ownerDocument;
|
|
@@ -41,14 +41,14 @@ function Ae(t) {
|
|
|
41
41
|
e
|
|
42
42
|
) : t.ownerDocument;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function Ve(t, e) {
|
|
45
45
|
return g(
|
|
46
46
|
/** @type {Document} */
|
|
47
47
|
t.head || t,
|
|
48
48
|
e
|
|
49
49
|
), e.sheet;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function A(t, e, n) {
|
|
52
52
|
t.insertBefore(e, n || null);
|
|
53
53
|
}
|
|
54
54
|
function R(t) {
|
|
@@ -60,11 +60,11 @@ function v(t) {
|
|
|
60
60
|
function V(t) {
|
|
61
61
|
return document.createElementNS("http://www.w3.org/2000/svg", t);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function Me(t) {
|
|
64
64
|
return document.createTextNode(t);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
return
|
|
66
|
+
function F() {
|
|
67
|
+
return Me(" ");
|
|
68
68
|
}
|
|
69
69
|
function J(t, e, n, i) {
|
|
70
70
|
return t.addEventListener(e, n, i), () => t.removeEventListener(e, n, i);
|
|
@@ -72,16 +72,16 @@ function J(t, e, n, i) {
|
|
|
72
72
|
function s(t, e, n) {
|
|
73
73
|
n == null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n);
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function Ue(t) {
|
|
76
76
|
return Array.from(t.childNodes);
|
|
77
77
|
}
|
|
78
78
|
function oe(t, e, n) {
|
|
79
79
|
t.classList.toggle(e, !!n);
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function Fe(t, e, { bubbles: n = !1, cancelable: i = !1 } = {}) {
|
|
82
82
|
return new CustomEvent(t, { detail: e, bubbles: n, cancelable: i });
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function Ye(t) {
|
|
85
85
|
const e = {};
|
|
86
86
|
return t.childNodes.forEach(
|
|
87
87
|
/** @param {Element} node */
|
|
@@ -99,18 +99,18 @@ function re() {
|
|
|
99
99
|
throw new Error("Function called outside component initialization");
|
|
100
100
|
return P;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function Ze(t) {
|
|
103
103
|
re().$$.on_mount.push(t);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function Oe(t) {
|
|
106
106
|
re().$$.on_destroy.push(t);
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function He() {
|
|
109
109
|
const t = re();
|
|
110
110
|
return (e, n, { cancelable: i = !1 } = {}) => {
|
|
111
111
|
const l = t.$$.callbacks[e];
|
|
112
112
|
if (l) {
|
|
113
|
-
const r =
|
|
113
|
+
const r = Fe(
|
|
114
114
|
/** @type {string} */
|
|
115
115
|
e,
|
|
116
116
|
n,
|
|
@@ -125,10 +125,13 @@ function Ze() {
|
|
|
125
125
|
}
|
|
126
126
|
const Z = [], ee = [];
|
|
127
127
|
let O = [];
|
|
128
|
-
const se = [],
|
|
128
|
+
const se = [], me = /* @__PURE__ */ Promise.resolve();
|
|
129
129
|
let te = !1;
|
|
130
|
-
function
|
|
131
|
-
te || (te = !0,
|
|
130
|
+
function we() {
|
|
131
|
+
te || (te = !0, me.then(q));
|
|
132
|
+
}
|
|
133
|
+
function Be() {
|
|
134
|
+
return we(), me;
|
|
132
135
|
}
|
|
133
136
|
function ne(t) {
|
|
134
137
|
O.push(t);
|
|
@@ -143,7 +146,7 @@ function q() {
|
|
|
143
146
|
try {
|
|
144
147
|
for (; Y < Z.length; ) {
|
|
145
148
|
const e = Z[Y];
|
|
146
|
-
Y++, B(e),
|
|
149
|
+
Y++, B(e), We(e.$$);
|
|
147
150
|
}
|
|
148
151
|
} catch (e) {
|
|
149
152
|
throw Z.length = 0, Y = 0, e;
|
|
@@ -160,36 +163,36 @@ function q() {
|
|
|
160
163
|
se.pop()();
|
|
161
164
|
te = !1, Q.clear(), B(t);
|
|
162
165
|
}
|
|
163
|
-
function
|
|
166
|
+
function We(t) {
|
|
164
167
|
if (t.fragment !== null) {
|
|
165
168
|
t.update(), T(t.before_update);
|
|
166
169
|
const e = t.dirty;
|
|
167
170
|
t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(ne);
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
|
-
function
|
|
173
|
+
function Pe(t) {
|
|
171
174
|
const e = [], n = [];
|
|
172
175
|
O.forEach((i) => t.indexOf(i) === -1 ? e.push(i) : n.push(i)), n.forEach((i) => i()), O = e;
|
|
173
176
|
}
|
|
174
|
-
const
|
|
175
|
-
function
|
|
176
|
-
t && t.i && (
|
|
177
|
+
const Te = /* @__PURE__ */ new Set();
|
|
178
|
+
function Xe(t, e) {
|
|
179
|
+
t && t.i && (Te.delete(t), t.i(e));
|
|
177
180
|
}
|
|
178
|
-
function
|
|
181
|
+
function De(t, e, n) {
|
|
179
182
|
const { fragment: i, after_update: l } = t.$$;
|
|
180
183
|
i && i.m(e, n), ne(() => {
|
|
181
184
|
const r = t.$$.on_mount.map(de).filter(ge);
|
|
182
185
|
t.$$.on_destroy ? t.$$.on_destroy.push(...r) : T(r), t.$$.on_mount = [];
|
|
183
186
|
}), l.forEach(ne);
|
|
184
187
|
}
|
|
185
|
-
function
|
|
188
|
+
function Ke(t, e) {
|
|
186
189
|
const n = t.$$;
|
|
187
|
-
n.fragment !== null && (
|
|
190
|
+
n.fragment !== null && (Pe(n.after_update), T(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []);
|
|
188
191
|
}
|
|
189
|
-
function
|
|
190
|
-
t.$$.dirty[0] === -1 && (Z.push(t),
|
|
192
|
+
function ze(t, e) {
|
|
193
|
+
t.$$.dirty[0] === -1 && (Z.push(t), we(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31;
|
|
191
194
|
}
|
|
192
|
-
function
|
|
195
|
+
function Je(t, e, n, i, l, r, c = null, a = [-1]) {
|
|
193
196
|
const u = P;
|
|
194
197
|
B(t);
|
|
195
198
|
const f = t.$$ = {
|
|
@@ -217,19 +220,19 @@ function ze(t, e, n, i, l, r, c = null, a = [-1]) {
|
|
|
217
220
|
let j = !1;
|
|
218
221
|
if (f.ctx = n ? n(t, e.props || {}, (y, E, ...w) => {
|
|
219
222
|
const I = w.length ? w[0] : E;
|
|
220
|
-
return f.ctx && l(f.ctx[y], f.ctx[y] = I) && (!f.skip_bound && f.bound[y] && f.bound[y](I), j &&
|
|
223
|
+
return f.ctx && l(f.ctx[y], f.ctx[y] = I) && (!f.skip_bound && f.bound[y] && f.bound[y](I), j && ze(t, y)), E;
|
|
221
224
|
}) : [], f.update(), j = !0, T(f.before_update), f.fragment = i ? i(f.ctx) : !1, e.target) {
|
|
222
225
|
if (e.hydrate) {
|
|
223
|
-
const y =
|
|
226
|
+
const y = Ue(e.target);
|
|
224
227
|
f.fragment && f.fragment.l(y), y.forEach(R);
|
|
225
228
|
} else
|
|
226
229
|
f.fragment && f.fragment.c();
|
|
227
|
-
e.intro &&
|
|
230
|
+
e.intro && Xe(t.$$.fragment), De(t, e.target, e.anchor), q();
|
|
228
231
|
}
|
|
229
232
|
B(u);
|
|
230
233
|
}
|
|
231
|
-
let
|
|
232
|
-
typeof HTMLElement == "function" && (
|
|
234
|
+
let be;
|
|
235
|
+
typeof HTMLElement == "function" && (be = class extends HTMLElement {
|
|
233
236
|
constructor(e, n, i) {
|
|
234
237
|
super();
|
|
235
238
|
/** The Svelte component constructor */
|
|
@@ -279,7 +282,7 @@ typeof HTMLElement == "function" && (me = class extends HTMLElement {
|
|
|
279
282
|
* @param {HTMLElement} [anchor]
|
|
280
283
|
*/
|
|
281
284
|
m: function(f, j) {
|
|
282
|
-
|
|
285
|
+
A(f, c, j);
|
|
283
286
|
},
|
|
284
287
|
d: function(f) {
|
|
285
288
|
f && R(c);
|
|
@@ -289,12 +292,12 @@ typeof HTMLElement == "function" && (me = class extends HTMLElement {
|
|
|
289
292
|
};
|
|
290
293
|
if (await Promise.resolve(), !this.$$cn)
|
|
291
294
|
return;
|
|
292
|
-
const n = {}, i =
|
|
295
|
+
const n = {}, i = Ye(this);
|
|
293
296
|
for (const r of this.$$s)
|
|
294
297
|
r in i && (n[r] = [e(r)]);
|
|
295
298
|
for (const r of this.attributes) {
|
|
296
299
|
const c = this.$$g_p(r.name);
|
|
297
|
-
c in this.$$d || (this.$$d[c] =
|
|
300
|
+
c in this.$$d || (this.$$d[c] = D(c, r.value, this.$$p_d, "toProp"));
|
|
298
301
|
}
|
|
299
302
|
this.$$c = new this.$$ctor({
|
|
300
303
|
target: this.shadowRoot || this,
|
|
@@ -310,7 +313,7 @@ typeof HTMLElement == "function" && (me = class extends HTMLElement {
|
|
|
310
313
|
this.$$r = !0;
|
|
311
314
|
for (const r in this.$$p_d)
|
|
312
315
|
if (this.$$d[r] = this.$$c.$$.ctx[this.$$c.$$.props[r]], this.$$p_d[r].reflect) {
|
|
313
|
-
const c =
|
|
316
|
+
const c = D(
|
|
314
317
|
r,
|
|
315
318
|
this.$$d[r],
|
|
316
319
|
this.$$p_d,
|
|
@@ -333,7 +336,7 @@ typeof HTMLElement == "function" && (me = class extends HTMLElement {
|
|
|
333
336
|
// and setting attributes through setAttribute etc, this is helpful
|
|
334
337
|
attributeChangedCallback(e, n, i) {
|
|
335
338
|
var l;
|
|
336
|
-
this.$$r || (e = this.$$g_p(e), this.$$d[e] =
|
|
339
|
+
this.$$r || (e = this.$$g_p(e), this.$$d[e] = D(e, i, this.$$p_d, "toProp"), (l = this.$$c) == null || l.$set({ [e]: this.$$d[e] }));
|
|
337
340
|
}
|
|
338
341
|
disconnectedCallback() {
|
|
339
342
|
this.$$cn = !1, Promise.resolve().then(() => {
|
|
@@ -346,7 +349,7 @@ typeof HTMLElement == "function" && (me = class extends HTMLElement {
|
|
|
346
349
|
) || e;
|
|
347
350
|
}
|
|
348
351
|
});
|
|
349
|
-
function
|
|
352
|
+
function D(t, e, n, i) {
|
|
350
353
|
var r;
|
|
351
354
|
const l = (r = n[t]) == null ? void 0 : r.type;
|
|
352
355
|
if (e = l === "Boolean" && typeof e != "boolean" ? e != null : e, !i || !n[t])
|
|
@@ -376,8 +379,8 @@ function K(t, e, n, i) {
|
|
|
376
379
|
return e;
|
|
377
380
|
}
|
|
378
381
|
}
|
|
379
|
-
function
|
|
380
|
-
let c = class extends
|
|
382
|
+
function Qe(t, e, n, i, l, r) {
|
|
383
|
+
let c = class extends be {
|
|
381
384
|
constructor() {
|
|
382
385
|
super(t, n, l), this.$$p_d = e;
|
|
383
386
|
}
|
|
@@ -394,7 +397,7 @@ function Je(t, e, n, i, l, r) {
|
|
|
394
397
|
},
|
|
395
398
|
set(u) {
|
|
396
399
|
var f;
|
|
397
|
-
u =
|
|
400
|
+
u = D(a, u, e), this.$$d[a] = u, (f = this.$$c) == null || f.$set({ [a]: u });
|
|
398
401
|
}
|
|
399
402
|
});
|
|
400
403
|
}), i.forEach((a) => {
|
|
@@ -407,7 +410,7 @@ function Je(t, e, n, i, l, r) {
|
|
|
407
410
|
}), r && (c = r(c)), t.element = /** @type {any} */
|
|
408
411
|
c, c;
|
|
409
412
|
}
|
|
410
|
-
class
|
|
413
|
+
class et {
|
|
411
414
|
constructor() {
|
|
412
415
|
/**
|
|
413
416
|
* ### PRIVATE API
|
|
@@ -428,7 +431,7 @@ class Qe {
|
|
|
428
431
|
}
|
|
429
432
|
/** @returns {void} */
|
|
430
433
|
$destroy() {
|
|
431
|
-
|
|
434
|
+
Ke(this, 1), this.$destroy = W;
|
|
432
435
|
}
|
|
433
436
|
/**
|
|
434
437
|
* @template {Extract<keyof Events, string>} K
|
|
@@ -450,30 +453,30 @@ class Qe {
|
|
|
450
453
|
* @returns {void}
|
|
451
454
|
*/
|
|
452
455
|
$set(e) {
|
|
453
|
-
this.$$set && !
|
|
456
|
+
this.$$set && !Ge(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1);
|
|
454
457
|
}
|
|
455
458
|
}
|
|
456
|
-
const
|
|
457
|
-
typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(
|
|
458
|
-
const
|
|
459
|
-
function
|
|
459
|
+
const tt = "4";
|
|
460
|
+
typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(tt);
|
|
461
|
+
const $e = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==", ce = typeof window < "u" && window.Blob && new Blob([atob($e)], { type: "text/javascript;charset=utf-8" });
|
|
462
|
+
function nt() {
|
|
460
463
|
let t;
|
|
461
464
|
try {
|
|
462
465
|
if (t = ce && (window.URL || window.webkitURL).createObjectURL(ce), !t)
|
|
463
466
|
throw "";
|
|
464
467
|
return new Worker(t);
|
|
465
468
|
} catch {
|
|
466
|
-
return new Worker("data:application/javascript;base64," +
|
|
469
|
+
return new Worker("data:application/javascript;base64," + $e);
|
|
467
470
|
} finally {
|
|
468
471
|
t && (window.URL || window.webkitURL).revokeObjectURL(t);
|
|
469
472
|
}
|
|
470
473
|
}
|
|
471
|
-
const
|
|
472
|
-
function
|
|
474
|
+
const rt = 1e7, it = new TextEncoder();
|
|
475
|
+
function lt(t) {
|
|
473
476
|
return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
474
477
|
}
|
|
475
|
-
async function
|
|
476
|
-
const n = Date.now().toString(16), i = Math.round(Math.random() * t), l = await
|
|
478
|
+
async function ot(t = 1e5, e = "SHA-256") {
|
|
479
|
+
const n = Date.now().toString(16), i = Math.round(Math.random() * t), l = await _e(n, i, e);
|
|
477
480
|
return {
|
|
478
481
|
algorithm: e,
|
|
479
482
|
challenge: l,
|
|
@@ -481,13 +484,13 @@ async function lt(t = 1e5, e = "SHA-256") {
|
|
|
481
484
|
signature: ""
|
|
482
485
|
};
|
|
483
486
|
}
|
|
484
|
-
async function
|
|
485
|
-
return
|
|
487
|
+
async function _e(t, e, n) {
|
|
488
|
+
return lt(await crypto.subtle.digest(n.toUpperCase(), it.encode(t + e)));
|
|
486
489
|
}
|
|
487
|
-
async function
|
|
490
|
+
async function st(t, e, n = "SHA-256", i = rt) {
|
|
488
491
|
const l = Date.now();
|
|
489
492
|
for (let r = 0; r <= i; r++)
|
|
490
|
-
if (await
|
|
493
|
+
if (await _e(e, r, n) === t)
|
|
491
494
|
return {
|
|
492
495
|
number: r,
|
|
493
496
|
took: Date.now() - l
|
|
@@ -495,8 +498,8 @@ async function ot(t, e, n = "SHA-256", i = nt) {
|
|
|
495
498
|
return null;
|
|
496
499
|
}
|
|
497
500
|
var p = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverified", t))(p || {});
|
|
498
|
-
function
|
|
499
|
-
|
|
501
|
+
function ct(t) {
|
|
502
|
+
Ae(t, "svelte-fqcw55", ".altcha.svelte-fqcw55.svelte-fqcw55{background:var(--altcha-color-base, transparent);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative;text-align:left}.altcha.svelte-fqcw55.svelte-fqcw55:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-fqcw55.svelte-fqcw55{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-fqcw55.svelte-fqcw55{flex-grow:1}.altcha-label.svelte-fqcw55 label.svelte-fqcw55{cursor:pointer}.altcha-logo.svelte-fqcw55.svelte-fqcw55{color:currentColor;opacity:0.3}.altcha-logo.svelte-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-error.svelte-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-footer.svelte-fqcw55>.svelte-fqcw55:first-child{flex-grow:1}.altcha-footer.svelte-fqcw55 a{color:currentColor}.altcha-checkbox.svelte-fqcw55.svelte-fqcw55{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-fqcw55 input.svelte-fqcw55{width:18px;height:18px;margin:0}.altcha-hidden.svelte-fqcw55.svelte-fqcw55{display:none}.altcha-spinner.svelte-fqcw55.svelte-fqcw55{animation:svelte-fqcw55-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-fqcw55-altcha-spinner{100%{transform:rotate(360deg)}}");
|
|
500
503
|
}
|
|
501
504
|
function ae(t) {
|
|
502
505
|
let e, n, i;
|
|
@@ -505,14 +508,14 @@ function ae(t) {
|
|
|
505
508
|
e = V("svg"), n = V("path"), i = V("path"), s(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"), s(n, "fill", "currentColor"), s(n, "opacity", ".25"), s(i, "d", "M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"), s(i, "fill", "currentColor"), s(i, "class", "altcha-spinner svelte-fqcw55"), s(e, "width", "24"), s(e, "height", "24"), s(e, "viewBox", "0 0 24 24"), s(e, "xmlns", "http://www.w3.org/2000/svg");
|
|
506
509
|
},
|
|
507
510
|
m(l, r) {
|
|
508
|
-
|
|
511
|
+
A(l, e, r), g(e, n), g(e, i);
|
|
509
512
|
},
|
|
510
513
|
d(l) {
|
|
511
514
|
l && R(e);
|
|
512
515
|
}
|
|
513
516
|
};
|
|
514
517
|
}
|
|
515
|
-
function
|
|
518
|
+
function at(t) {
|
|
516
519
|
let e, n = (
|
|
517
520
|
/*_strings*/
|
|
518
521
|
t[8].label + ""
|
|
@@ -523,7 +526,7 @@ function ct(t) {
|
|
|
523
526
|
t[2] + "_checkbox"), s(e, "class", "svelte-fqcw55");
|
|
524
527
|
},
|
|
525
528
|
m(l, r) {
|
|
526
|
-
|
|
529
|
+
A(l, e, r), e.innerHTML = n;
|
|
527
530
|
},
|
|
528
531
|
p(l, r) {
|
|
529
532
|
r[0] & /*_strings*/
|
|
@@ -537,7 +540,7 @@ function ct(t) {
|
|
|
537
540
|
}
|
|
538
541
|
};
|
|
539
542
|
}
|
|
540
|
-
function
|
|
543
|
+
function ft(t) {
|
|
541
544
|
let e, n = (
|
|
542
545
|
/*_strings*/
|
|
543
546
|
t[8].verifying + ""
|
|
@@ -547,7 +550,7 @@ function at(t) {
|
|
|
547
550
|
e = v("span");
|
|
548
551
|
},
|
|
549
552
|
m(i, l) {
|
|
550
|
-
|
|
553
|
+
A(i, e, l), e.innerHTML = n;
|
|
551
554
|
},
|
|
552
555
|
p(i, l) {
|
|
553
556
|
l[0] & /*_strings*/
|
|
@@ -559,14 +562,14 @@ function at(t) {
|
|
|
559
562
|
}
|
|
560
563
|
};
|
|
561
564
|
}
|
|
562
|
-
function
|
|
565
|
+
function ut(t) {
|
|
563
566
|
let e, n = (
|
|
564
567
|
/*_strings*/
|
|
565
568
|
t[8].verified + ""
|
|
566
569
|
), i, l;
|
|
567
570
|
return {
|
|
568
571
|
c() {
|
|
569
|
-
e = v("span"), i =
|
|
572
|
+
e = v("span"), i = F(), l = v("input"), s(l, "type", "hidden"), s(
|
|
570
573
|
l,
|
|
571
574
|
"name",
|
|
572
575
|
/*name*/
|
|
@@ -575,7 +578,7 @@ function ft(t) {
|
|
|
575
578
|
t[3];
|
|
576
579
|
},
|
|
577
580
|
m(r, c) {
|
|
578
|
-
|
|
581
|
+
A(r, e, c), e.innerHTML = n, A(r, i, c), A(r, l, c);
|
|
579
582
|
},
|
|
580
583
|
p(r, c) {
|
|
581
584
|
c[0] & /*_strings*/
|
|
@@ -602,7 +605,7 @@ function fe(t) {
|
|
|
602
605
|
);
|
|
603
606
|
return {
|
|
604
607
|
c() {
|
|
605
|
-
e = v("div"), n = V("svg"), i = V("path"), l =
|
|
608
|
+
e = v("div"), n = V("svg"), i = V("path"), l = F(), r = v("div"), s(i, "stroke-linecap", "round"), s(i, "stroke-linejoin", "round"), s(i, "d", "M6 18L18 6M6 6l12 12"), s(n, "width", "14"), s(n, "height", "14"), s(n, "xmlns", "http://www.w3.org/2000/svg"), s(n, "fill", "none"), s(n, "viewBox", "0 0 24 24"), s(n, "stroke-width", "1.5"), s(n, "stroke", "currentColor"), s(
|
|
606
609
|
r,
|
|
607
610
|
"title",
|
|
608
611
|
/*error*/
|
|
@@ -610,7 +613,7 @@ function fe(t) {
|
|
|
610
613
|
), s(e, "class", "altcha-error svelte-fqcw55");
|
|
611
614
|
},
|
|
612
615
|
m(a, u) {
|
|
613
|
-
|
|
616
|
+
A(a, e, u), g(e, n), g(n, i), g(e, l), g(e, r), r.innerHTML = c;
|
|
614
617
|
},
|
|
615
618
|
p(a, u) {
|
|
616
619
|
u[0] & /*_strings*/
|
|
@@ -638,7 +641,7 @@ function ue(t) {
|
|
|
638
641
|
e = v("div"), n = v("div"), s(n, "class", "svelte-fqcw55"), s(e, "class", "altcha-footer svelte-fqcw55");
|
|
639
642
|
},
|
|
640
643
|
m(l, r) {
|
|
641
|
-
|
|
644
|
+
A(l, e, r), g(e, n), n.innerHTML = i;
|
|
642
645
|
},
|
|
643
646
|
p(l, r) {
|
|
644
647
|
r[0] & /*_strings*/
|
|
@@ -650,17 +653,17 @@ function ue(t) {
|
|
|
650
653
|
}
|
|
651
654
|
};
|
|
652
655
|
}
|
|
653
|
-
function
|
|
654
|
-
let e, n, i, l, r, c, a, u, f, j, y, E, w, I,
|
|
656
|
+
function ht(t) {
|
|
657
|
+
let e, n, i, l, r, c, a, u, f, j, y, E, w, I, G, U, H, N, M, k, b = (
|
|
655
658
|
/*state*/
|
|
656
659
|
t[4] === p.VERIFYING && ae()
|
|
657
660
|
);
|
|
658
661
|
function S(h, x) {
|
|
659
662
|
return (
|
|
660
663
|
/*state*/
|
|
661
|
-
h[4] === p.VERIFIED ?
|
|
664
|
+
h[4] === p.VERIFIED ? ut : (
|
|
662
665
|
/*state*/
|
|
663
|
-
h[4] === p.VERIFYING ?
|
|
666
|
+
h[4] === p.VERIFYING ? ft : at
|
|
664
667
|
)
|
|
665
668
|
);
|
|
666
669
|
}
|
|
@@ -674,14 +677,14 @@ function ut(t) {
|
|
|
674
677
|
);
|
|
675
678
|
return {
|
|
676
679
|
c() {
|
|
677
|
-
e = v("div"), n = v("div"), b && b.c(), i =
|
|
680
|
+
e = v("div"), n = v("div"), b && b.c(), i = F(), l = v("div"), r = v("input"), u = F(), f = v("div"), d.c(), j = F(), y = v("div"), E = v("a"), w = V("svg"), I = V("path"), G = V("path"), U = V("path"), H = F(), $ && $.c(), N = F(), _ && _.c(), s(r, "type", "checkbox"), s(r, "id", c = /*name*/
|
|
678
681
|
t[2] + "_checkbox"), r.required = a = /*auto*/
|
|
679
682
|
t[0] !== "onsubmit", s(r, "class", "svelte-fqcw55"), s(l, "class", "altcha-checkbox svelte-fqcw55"), oe(
|
|
680
683
|
l,
|
|
681
684
|
"altcha-hidden",
|
|
682
685
|
/*state*/
|
|
683
686
|
t[4] === p.VERIFYING
|
|
684
|
-
), s(f, "class", "altcha-label svelte-fqcw55"), s(I, "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"), s(I, "fill", "currentColor"), s(
|
|
687
|
+
), s(f, "class", "altcha-label svelte-fqcw55"), s(I, "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"), s(I, "fill", "currentColor"), s(G, "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"), s(G, "fill", "currentColor"), s(U, "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"), s(U, "fill", "currentColor"), s(w, "width", "22"), s(w, "height", "22"), s(w, "viewBox", "0 0 20 20"), s(w, "fill", "none"), s(w, "xmlns", "http://www.w3.org/2000/svg"), s(E, "href", ve), s(E, "target", "_blank"), s(E, "class", "altcha-logo svelte-fqcw55"), s(n, "class", "altcha-main svelte-fqcw55"), s(e, "class", "altcha svelte-fqcw55"), s(
|
|
685
688
|
e,
|
|
686
689
|
"data-state",
|
|
687
690
|
/*state*/
|
|
@@ -689,8 +692,8 @@ function ut(t) {
|
|
|
689
692
|
);
|
|
690
693
|
},
|
|
691
694
|
m(h, x) {
|
|
692
|
-
|
|
693
|
-
t[5], g(n, u), g(n, f), d.m(f, null), g(n, j), g(n, y), g(y, E), g(E, w), g(w, I), g(w,
|
|
695
|
+
A(h, e, x), g(e, n), b && b.m(n, null), g(n, i), g(n, l), g(l, r), r.checked = /*checked*/
|
|
696
|
+
t[5], g(n, u), g(n, f), d.m(f, null), g(n, j), g(n, y), g(y, E), g(E, w), g(w, I), g(w, G), g(w, U), g(e, H), $ && $.m(e, null), g(e, N), _ && _.m(e, null), t[22](e), M || (k = [
|
|
694
697
|
J(
|
|
695
698
|
r,
|
|
696
699
|
"change",
|
|
@@ -743,31 +746,29 @@ function ut(t) {
|
|
|
743
746
|
}
|
|
744
747
|
};
|
|
745
748
|
}
|
|
746
|
-
const
|
|
749
|
+
const ve = "https://altcha.org/";
|
|
747
750
|
function he(t) {
|
|
748
751
|
return JSON.parse(t);
|
|
749
752
|
}
|
|
750
|
-
function
|
|
751
|
-
let i, l, r, { auto: c = void 0 } = e, { challengeurl: a = void 0 } = e, { challengejson: u = void 0 } = e, { debug: f = !1 } = e, { hidefooter: j = !1 } = e, { name: y = "altcha" } = e, { maxnumber: E = void 0 } = e, { mockerror: w = !1 } = e, { strings: I = void 0 } = e, { test:
|
|
752
|
-
const
|
|
753
|
+
function dt(t, e, n) {
|
|
754
|
+
let i, l, r, { auto: c = void 0 } = e, { challengeurl: a = void 0 } = e, { challengejson: u = void 0 } = e, { debug: f = !1 } = e, { hidefooter: j = !1 } = e, { name: y = "altcha" } = e, { maxnumber: E = void 0 } = e, { mockerror: w = !1 } = e, { strings: I = void 0 } = e, { test: G = !1 } = e;
|
|
755
|
+
const U = He(), H = ["SHA-256", "SHA-384", "SHA-512"];
|
|
753
756
|
let N = !1, M, k = null, b = null, S = null, C = p.UNVERIFIED;
|
|
754
|
-
|
|
757
|
+
Oe(() => {
|
|
755
758
|
k && (k.removeEventListener("submit", $), k.removeEventListener("reset", _), k = null);
|
|
756
|
-
}),
|
|
757
|
-
d("mounted", "0.1.
|
|
759
|
+
}), Ze(() => {
|
|
760
|
+
d("mounted", "0.1.5"), G && d("using test mode"), c !== void 0 && d("auto", c), k = M.closest("form"), k && (k.addEventListener("submit", $), k.addEventListener("reset", _)), c === "onload" && X();
|
|
758
761
|
});
|
|
759
762
|
function d(...o) {
|
|
760
763
|
(f || o.some((m) => m instanceof Error)) && console[o[0] instanceof Error ? "error" : "log"]("ALTCHA", ...o);
|
|
761
764
|
}
|
|
762
765
|
function $(o) {
|
|
763
|
-
k && c === "onsubmit" && C === p.UNVERIFIED
|
|
764
|
-
k == null || k.
|
|
765
|
-
}))
|
|
766
|
-
X();
|
|
767
|
-
});
|
|
766
|
+
k && c === "onsubmit" && C === p.UNVERIFIED && (o.preventDefault(), o.stopPropagation(), X().then(() => {
|
|
767
|
+
k == null || k.requestSubmit();
|
|
768
|
+
}));
|
|
768
769
|
}
|
|
769
770
|
function _() {
|
|
770
|
-
|
|
771
|
+
K();
|
|
771
772
|
}
|
|
772
773
|
function h(o, m) {
|
|
773
774
|
return btoa(JSON.stringify({
|
|
@@ -776,7 +777,7 @@ function ht(t, e, n) {
|
|
|
776
777
|
number: m.number,
|
|
777
778
|
salt: o.salt,
|
|
778
779
|
signature: o.signature,
|
|
779
|
-
test:
|
|
780
|
+
test: G ? !0 : void 0,
|
|
780
781
|
took: m.took
|
|
781
782
|
}));
|
|
782
783
|
}
|
|
@@ -792,13 +793,13 @@ function ht(t, e, n) {
|
|
|
792
793
|
if (!o.salt || o.salt.length < 10)
|
|
793
794
|
throw new Error("Salt is too short. Min. 10 chars.");
|
|
794
795
|
}
|
|
795
|
-
async function
|
|
796
|
+
async function pe() {
|
|
796
797
|
if (w)
|
|
797
798
|
throw d("mocking error"), new Error("Mocked error.");
|
|
798
799
|
if (i)
|
|
799
800
|
return d("using provided json data"), i;
|
|
800
|
-
if (
|
|
801
|
-
return d("generating test challenge"),
|
|
801
|
+
if (G)
|
|
802
|
+
return d("generating test challenge"), ot();
|
|
802
803
|
{
|
|
803
804
|
if (!a)
|
|
804
805
|
throw new Error("Attribute challengeurl not set.");
|
|
@@ -809,11 +810,11 @@ function ht(t, e, n) {
|
|
|
809
810
|
return o.json();
|
|
810
811
|
}
|
|
811
812
|
}
|
|
812
|
-
async function
|
|
813
|
+
async function ye(o) {
|
|
813
814
|
let m = null;
|
|
814
815
|
if ("Worker" in window) {
|
|
815
816
|
try {
|
|
816
|
-
m = await
|
|
817
|
+
m = await ke(o.challenge, o.salt, o.algorithm);
|
|
817
818
|
} catch (z) {
|
|
818
819
|
d(z);
|
|
819
820
|
}
|
|
@@ -822,60 +823,62 @@ function ht(t, e, n) {
|
|
|
822
823
|
}
|
|
823
824
|
return {
|
|
824
825
|
data: o,
|
|
825
|
-
solution: await
|
|
826
|
+
solution: await st(o.challenge, o.salt, o.algorithm, E)
|
|
826
827
|
};
|
|
827
828
|
}
|
|
828
|
-
async function
|
|
829
|
-
const ie = new
|
|
830
|
-
return new Promise((
|
|
831
|
-
ie.addEventListener("message", (
|
|
832
|
-
|
|
829
|
+
async function ke(o, m, z) {
|
|
830
|
+
const ie = new nt();
|
|
831
|
+
return new Promise((Le) => {
|
|
832
|
+
ie.addEventListener("message", (qe) => {
|
|
833
|
+
Le(qe.data);
|
|
833
834
|
}), ie.postMessage({ alg: z, challenge: o, max: E, salt: m });
|
|
834
835
|
});
|
|
835
836
|
}
|
|
836
|
-
function
|
|
837
|
-
[p.UNVERIFIED, p.ERROR].includes(C) ?
|
|
837
|
+
function Ee() {
|
|
838
|
+
[p.UNVERIFIED, p.ERROR].includes(C) ? X() : n(5, N = !0);
|
|
838
839
|
}
|
|
839
|
-
function
|
|
840
|
+
function Ce() {
|
|
840
841
|
C === p.VERIFYING && alert(r.waitAlert);
|
|
841
842
|
}
|
|
842
|
-
function
|
|
843
|
+
function K(o = p.UNVERIFIED) {
|
|
843
844
|
n(5, N = !1), n(7, b = null), n(3, S = null), n(4, C = o);
|
|
844
845
|
}
|
|
845
|
-
async function
|
|
846
|
-
return
|
|
846
|
+
async function X() {
|
|
847
|
+
return K(p.VERIFYING), pe().then((o) => (x(o), d("challenge", o), ye(o))).then(({ data: o, solution: m }) => {
|
|
847
848
|
if (d("solution", m), (m == null ? void 0 : m.number) !== void 0)
|
|
848
|
-
d("verified"), n(4, C = p.VERIFIED), n(5, N = !0), n(3, S = h(o, m)),
|
|
849
|
+
d("verified"), n(4, C = p.VERIFIED), n(5, N = !0), n(3, S = h(o, m)), d("payload", S), Be().then(() => {
|
|
850
|
+
U("verified", { payload: S });
|
|
851
|
+
});
|
|
849
852
|
else
|
|
850
853
|
throw new Error("Unexpected result returned.");
|
|
851
854
|
}).catch((o) => {
|
|
852
855
|
d(o), n(4, C = p.ERROR), n(5, N = !1), n(7, b = o);
|
|
853
856
|
});
|
|
854
857
|
}
|
|
855
|
-
function
|
|
858
|
+
function xe() {
|
|
856
859
|
N = this.checked, n(5, N);
|
|
857
860
|
}
|
|
858
|
-
function
|
|
861
|
+
function Ie(o) {
|
|
859
862
|
ee[o ? "unshift" : "push"](() => {
|
|
860
863
|
M = o, n(6, M);
|
|
861
864
|
});
|
|
862
865
|
}
|
|
863
866
|
return t.$$set = (o) => {
|
|
864
|
-
"auto" in o && n(0, c = o.auto), "challengeurl" in o && n(11, a = o.challengeurl), "challengejson" in o && n(12, u = o.challengejson), "debug" in o && n(13, f = o.debug), "hidefooter" in o && n(1, j = o.hidefooter), "name" in o && n(2, y = o.name), "maxnumber" in o && n(14, E = o.maxnumber), "mockerror" in o && n(15, w = o.mockerror), "strings" in o && n(16, I = o.strings), "test" in o && n(17,
|
|
867
|
+
"auto" in o && n(0, c = o.auto), "challengeurl" in o && n(11, a = o.challengeurl), "challengejson" in o && n(12, u = o.challengejson), "debug" in o && n(13, f = o.debug), "hidefooter" in o && n(1, j = o.hidefooter), "name" in o && n(2, y = o.name), "maxnumber" in o && n(14, E = o.maxnumber), "mockerror" in o && n(15, w = o.mockerror), "strings" in o && n(16, I = o.strings), "test" in o && n(17, G = o.test);
|
|
865
868
|
}, t.$$.update = () => {
|
|
866
869
|
t.$$.dirty[0] & /*challengejson*/
|
|
867
870
|
4096 && (i = u ? he(u) : void 0), t.$$.dirty[0] & /*strings*/
|
|
868
871
|
65536 && n(20, l = I ? he(I) : {}), t.$$.dirty[0] & /*parsedStrings*/
|
|
869
872
|
1048576 && n(8, r = {
|
|
870
873
|
error: "Verification failed. Try again later.",
|
|
871
|
-
footer: `Protected by <a href="${
|
|
874
|
+
footer: `Protected by <a href="${ve}" target="_blank">ALTCHA</a>`,
|
|
872
875
|
label: "I'm not a robot",
|
|
873
876
|
verified: "Verified",
|
|
874
877
|
verifying: "Verifying...",
|
|
875
878
|
waitAlert: "Verifying... please wait.",
|
|
876
879
|
...l
|
|
877
880
|
}), t.$$.dirty[0] & /*payload, state*/
|
|
878
|
-
24 &&
|
|
881
|
+
24 && U("statechange", { payload: S, state: C });
|
|
879
882
|
}, [
|
|
880
883
|
c,
|
|
881
884
|
j,
|
|
@@ -886,30 +889,30 @@ function ht(t, e, n) {
|
|
|
886
889
|
M,
|
|
887
890
|
b,
|
|
888
891
|
r,
|
|
889
|
-
|
|
890
|
-
|
|
892
|
+
Ee,
|
|
893
|
+
Ce,
|
|
891
894
|
a,
|
|
892
895
|
u,
|
|
893
896
|
f,
|
|
894
897
|
E,
|
|
895
898
|
w,
|
|
896
899
|
I,
|
|
897
|
-
|
|
900
|
+
G,
|
|
901
|
+
K,
|
|
898
902
|
X,
|
|
899
|
-
D,
|
|
900
903
|
l,
|
|
901
|
-
|
|
902
|
-
|
|
904
|
+
xe,
|
|
905
|
+
Ie
|
|
903
906
|
];
|
|
904
907
|
}
|
|
905
|
-
class
|
|
908
|
+
class gt extends et {
|
|
906
909
|
constructor(e) {
|
|
907
|
-
super(),
|
|
910
|
+
super(), Je(
|
|
908
911
|
this,
|
|
909
912
|
e,
|
|
913
|
+
dt,
|
|
910
914
|
ht,
|
|
911
|
-
|
|
912
|
-
Ne,
|
|
915
|
+
je,
|
|
913
916
|
{
|
|
914
917
|
auto: 0,
|
|
915
918
|
challengeurl: 11,
|
|
@@ -924,7 +927,7 @@ class dt extends Qe {
|
|
|
924
927
|
reset: 18,
|
|
925
928
|
verify: 19
|
|
926
929
|
},
|
|
927
|
-
|
|
930
|
+
ct,
|
|
928
931
|
[-1, -1]
|
|
929
932
|
);
|
|
930
933
|
}
|
|
@@ -995,7 +998,7 @@ class dt extends Qe {
|
|
|
995
998
|
return this.$$.ctx[19];
|
|
996
999
|
}
|
|
997
1000
|
}
|
|
998
|
-
customElements.define("altcha-widget",
|
|
1001
|
+
customElements.define("altcha-widget", Qe(gt, { auto: {}, challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, hidefooter: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" } }, [], ["reset", "verify"], !1));
|
|
999
1002
|
export {
|
|
1000
|
-
|
|
1003
|
+
gt as Altcha
|
|
1001
1004
|
};
|
package/dist/altcha.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(L,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(L=typeof globalThis<"u"?globalThis:L||self,w(L.altcha={}))})(this,function(L){"use strict";var dt=Object.defineProperty;var gt=(L,w,U)=>w in L?dt(L,w,{enumerable:!0,configurable:!0,writable:!0,value:U}):L[w]=U;var R=(L,w,U)=>(gt(L,typeof w!="symbol"?w+"":w,U),U);function w(){}function U(t){return t()}function oe(){return Object.create(null)}function T(t){t.forEach(U)}function se(t){return typeof t=="function"}function pe(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function ye(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function ke(t,e,n){const i=Ee(t);if(!i.getElementById(e)){const l=b("style");l.id=e,l.textContent=n,Ce(i,l)}}function Ee(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ce(t,e){return g(t.head||t,e),e.sheet}function G(t,e,n){t.insertBefore(e,n||null)}function j(t){t.parentNode&&t.parentNode.removeChild(t)}function b(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function xe(t){return document.createTextNode(t)}function Y(){return xe(" ")}function Q(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function s(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ie(t){return Array.from(t.childNodes)}function ce(t,e,n){t.classList.toggle(e,!!n)}function Le(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function qe(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let P;function X(t){P=t}function ee(){if(!P)throw new Error("Function called outside component initialization");return P}function Ne(t){ee().$$.on_mount.push(t)}function Re(t){ee().$$.on_destroy.push(t)}function je(){const t=ee();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Le(e,n,{cancelable:i});return l.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const H=[],te=[];let B=[];const ae=[],Ae=Promise.resolve();let ne=!1;function Ge(){ne||(ne=!0,Ae.then(q))}function re(t){B.push(t)}const ie=new Set;let W=0;function q(){if(W!==0)return;const t=P;do{try{for(;W<H.length;){const e=H[W];W++,X(e),Se(e.$$)}}catch(e){throw H.length=0,W=0,e}for(X(null),H.length=0,W=0;te.length;)te.pop()();for(let e=0;e<B.length;e+=1){const n=B[e];ie.has(n)||(ie.add(n),n())}B.length=0}while(H.length);for(;ae.length;)ae.pop()();ne=!1,ie.clear(),X(t)}function Se(t){if(t.fragment!==null){t.update(),T(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(re)}}function Me(t){const e=[],n=[];B.forEach(i=>t.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Ve=new Set;function Fe(t,e){t&&t.i&&(Ve.delete(t),t.i(e))}function Ue(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),re(()=>{const r=t.$$.on_mount.map(U).filter(se);t.$$.on_destroy?t.$$.on_destroy.push(...r):T(r),t.$$.on_mount=[]}),l.forEach(re)}function Oe(t,e){const n=t.$$;n.fragment!==null&&(Me(n.after_update),T(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Ye(t,e){t.$$.dirty[0]===-1&&(H.push(t),Ge(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Ze(t,e,n,i,l,r,c=null,a=[-1]){const u=P;X(t);const f=t.$$={fragment:null,ctx:[],props:r,update:w,not_equal:l,bound:oe(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(u?u.$$.context:[])),callbacks:oe(),dirty:a,skip_bound:!1,root:e.target||u.$$.root};c&&c(f.root);let S=!1;if(f.ctx=n?n(t,e.props||{},(k,C,...$)=>{const N=$.length?$[0]:C;return f.ctx&&l(f.ctx[k],f.ctx[k]=N)&&(!f.skip_bound&&f.bound[k]&&f.bound[k](N),S&&Ye(t,k)),C}):[],f.update(),S=!0,T(f.before_update),f.fragment=i?i(f.ctx):!1,e.target){if(e.hydrate){const k=Ie(e.target);f.fragment&&f.fragment.l(k),k.forEach(j)}else f.fragment&&f.fragment.c();e.intro&&Fe(t.$$.fragment),Ue(t,e.target,e.anchor),q()}X(u)}let fe;typeof HTMLElement=="function"&&(fe=class extends HTMLElement{constructor(e,n,i){super();R(this,"$$ctor");R(this,"$$s");R(this,"$$c");R(this,"$$cn",!1);R(this,"$$d",{});R(this,"$$r",!1);R(this,"$$p_d",{});R(this,"$$l",{});R(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=b("slot"),r!=="default"&&s(c,"name",r)},m:function(f,S){G(f,c,S)},d:function(f){f&&j(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},i=qe(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=K(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const c=K(r,this.$$d[r],this.$$p_d,"toAttribute");c==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,c)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const c of this.$$l[r]){const a=this.$$c.$on(r,c);this.$$l_u.set(c,a)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=K(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}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 K(t,e,n,i){var r;const l=(r=n[t])==null?void 0:r.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function He(t,e,n,i,l,r){let c=class extends fe{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(c.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(u){var f;u=K(a,u,e),this.$$d[a]=u,(f=this.$$c)==null||f.$set({[a]:u})}})}),i.forEach(a=>{Object.defineProperty(c.prototype,a,{get(){var u;return(u=this.$$c)==null?void 0:u[a]}})}),r&&(c=r(c)),t.element=c,c}class Be{constructor(){R(this,"$$");R(this,"$$set")}$destroy(){Oe(this,1),this.$destroy=w}$on(e,n){if(!se(n))return w;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const l=i.indexOf(n);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!ye(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const We="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(We);const ue="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",he=typeof window<"u"&&window.Blob&&new Blob([atob(ue)],{type:"text/javascript;charset=utf-8"});function Te(){let t;try{if(t=he&&(window.URL||window.webkitURL).createObjectURL(he),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+ue)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Pe=1e7,Xe=new TextEncoder;function De(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Ke(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await de(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function de(t,e,n){return De(await crypto.subtle.digest(n.toUpperCase(),Xe.encode(t+e)))}async function ze(t,e,n="SHA-256",i=Pe){const l=Date.now();for(let r=0;r<=i;r++)if(await de(e,r,n)===t)return{number:r,took:Date.now()-l};return null}var y=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(y||{});function Je(t){ke(t,"svelte-fqcw55",".altcha.svelte-fqcw55.svelte-fqcw55{background:var(--altcha-color-base, transparent);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative;text-align:left}.altcha.svelte-fqcw55.svelte-fqcw55:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-fqcw55.svelte-fqcw55{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-fqcw55.svelte-fqcw55{flex-grow:1}.altcha-label.svelte-fqcw55 label.svelte-fqcw55{cursor:pointer}.altcha-logo.svelte-fqcw55.svelte-fqcw55{color:currentColor;opacity:0.3}.altcha-logo.svelte-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-error.svelte-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-footer.svelte-fqcw55>.svelte-fqcw55:first-child{flex-grow:1}.altcha-footer.svelte-fqcw55 a{color:currentColor}.altcha-checkbox.svelte-fqcw55.svelte-fqcw55{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-fqcw55 input.svelte-fqcw55{width:18px;height:18px;margin:0}.altcha-hidden.svelte-fqcw55.svelte-fqcw55{display:none}.altcha-spinner.svelte-fqcw55.svelte-fqcw55{animation:svelte-fqcw55-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-fqcw55-altcha-spinner{100%{transform:rotate(360deg)}}")}function ge(t){let e,n,i;return{c(){e=V("svg"),n=V("path"),i=V("path"),s(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"),s(n,"fill","currentColor"),s(n,"opacity",".25"),s(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),s(i,"fill","currentColor"),s(i,"class","altcha-spinner svelte-fqcw55"),s(e,"width","24"),s(e,"height","24"),s(e,"viewBox","0 0 24 24"),s(e,"xmlns","http://www.w3.org/2000/svg")},m(l,r){G(l,e,r),g(e,n),g(e,i)},d(l){l&&j(e)}}}function Qe(t){let e,n=t[8].label+"",i;return{c(){e=b("label"),s(e,"for",i=t[2]+"_checkbox"),s(e,"class","svelte-fqcw55")},m(l,r){G(l,e,r),e.innerHTML=n},p(l,r){r[0]&256&&n!==(n=l[8].label+"")&&(e.innerHTML=n),r[0]&4&&i!==(i=l[2]+"_checkbox")&&s(e,"for",i)},d(l){l&&j(e)}}}function et(t){let e,n=t[8].verifying+"";return{c(){e=b("span")},m(i,l){G(i,e,l),e.innerHTML=n},p(i,l){l[0]&256&&n!==(n=i[8].verifying+"")&&(e.innerHTML=n)},d(i){i&&j(e)}}}function tt(t){let e,n=t[8].verified+"",i,l;return{c(){e=b("span"),i=Y(),l=b("input"),s(l,"type","hidden"),s(l,"name",t[2]),l.value=t[3]},m(r,c){G(r,e,c),e.innerHTML=n,G(r,i,c),G(r,l,c)},p(r,c){c[0]&256&&n!==(n=r[8].verified+"")&&(e.innerHTML=n),c[0]&4&&s(l,"name",r[2]),c[0]&8&&(l.value=r[3])},d(r){r&&(j(e),j(i),j(l))}}}function me(t){let e,n,i,l,r,c=t[8].error+"";return{c(){e=b("div"),n=V("svg"),i=V("path"),l=Y(),r=b("div"),s(i,"stroke-linecap","round"),s(i,"stroke-linejoin","round"),s(i,"d","M6 18L18 6M6 6l12 12"),s(n,"width","14"),s(n,"height","14"),s(n,"xmlns","http://www.w3.org/2000/svg"),s(n,"fill","none"),s(n,"viewBox","0 0 24 24"),s(n,"stroke-width","1.5"),s(n,"stroke","currentColor"),s(r,"title",t[7]),s(e,"class","altcha-error svelte-fqcw55")},m(a,u){G(a,e,u),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=c},p(a,u){u[0]&256&&c!==(c=a[8].error+"")&&(r.innerHTML=c),u[0]&128&&s(r,"title",a[7])},d(a){a&&j(e)}}}function we(t){let e,n,i=t[8].footer+"";return{c(){e=b("div"),n=b("div"),s(n,"class","svelte-fqcw55"),s(e,"class","altcha-footer svelte-fqcw55")},m(l,r){G(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&256&&i!==(i=l[8].footer+"")&&(n.innerHTML=i)},d(l){l&&j(e)}}}function nt(t){let e,n,i,l,r,c,a,u,f,S,k,C,$,N,M,Z,D,A,O,E,v=t[4]===y.VERIFYING&&ge();function F(h,I){return h[4]===y.VERIFIED?tt:h[4]===y.VERIFYING?et:Qe}let x=F(t),d=x(t),_=t[7]&&me(t),p=t[8].footer&&t[1]!==!0&&we(t);return{c(){e=b("div"),n=b("div"),v&&v.c(),i=Y(),l=b("div"),r=b("input"),u=Y(),f=b("div"),d.c(),S=Y(),k=b("div"),C=b("a"),$=V("svg"),N=V("path"),M=V("path"),Z=V("path"),D=Y(),_&&_.c(),A=Y(),p&&p.c(),s(r,"type","checkbox"),s(r,"id",c=t[2]+"_checkbox"),r.required=a=t[0]!=="onsubmit",s(r,"class","svelte-fqcw55"),s(l,"class","altcha-checkbox svelte-fqcw55"),ce(l,"altcha-hidden",t[4]===y.VERIFYING),s(f,"class","altcha-label svelte-fqcw55"),s(N,"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"),s(N,"fill","currentColor"),s(M,"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"),s(M,"fill","currentColor"),s(Z,"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"),s(Z,"fill","currentColor"),s($,"width","22"),s($,"height","22"),s($,"viewBox","0 0 20 20"),s($,"fill","none"),s($,"xmlns","http://www.w3.org/2000/svg"),s(C,"href",be),s(C,"target","_blank"),s(C,"class","altcha-logo svelte-fqcw55"),s(n,"class","altcha-main svelte-fqcw55"),s(e,"class","altcha svelte-fqcw55"),s(e,"data-state",t[4])},m(h,I){G(h,e,I),g(e,n),v&&v.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[5],g(n,u),g(n,f),d.m(f,null),g(n,S),g(n,k),g(k,C),g(C,$),g($,N),g($,M),g($,Z),g(e,D),_&&_.m(e,null),g(e,A),p&&p.m(e,null),t[22](e),O||(E=[Q(r,"change",t[21]),Q(r,"change",t[9]),Q(r,"invalid",t[10])],O=!0)},p(h,I){h[4]===y.VERIFYING?v||(v=ge(),v.c(),v.m(n,i)):v&&(v.d(1),v=null),I[0]&4&&c!==(c=h[2]+"_checkbox")&&s(r,"id",c),I[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),I[0]&32&&(r.checked=h[5]),I[0]&16&&ce(l,"altcha-hidden",h[4]===y.VERIFYING),x===(x=F(h))&&d?d.p(h,I):(d.d(1),d=x(h),d&&(d.c(),d.m(f,null))),h[7]?_?_.p(h,I):(_=me(h),_.c(),_.m(e,A)):_&&(_.d(1),_=null),h[8].footer&&h[1]!==!0?p?p.p(h,I):(p=we(h),p.c(),p.m(e,null)):p&&(p.d(1),p=null),I[0]&16&&s(e,"data-state",h[4])},i:w,o:w,d(h){h&&j(e),v&&v.d(),d.d(),_&&_.d(),p&&p.d(),t[22](null),O=!1,T(E)}}}const be="https://altcha.org/";function $e(t){return JSON.parse(t)}function rt(t,e,n){let i,l,r,{auto:c=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:u=void 0}=e,{debug:f=!1}=e,{hidefooter:S=!1}=e,{name:k="altcha"}=e,{maxnumber:C=void 0}=e,{mockerror:$=!1}=e,{strings:N=void 0}=e,{test:M=!1}=e;const Z=je(),D=["SHA-256","SHA-384","SHA-512"];let A=!1,O,E=null,v=null,F=null,x=y.UNVERIFIED;Re(()=>{E&&(E.removeEventListener("submit",_),E.removeEventListener("reset",p),E=null)}),Ne(()=>{d("mounted","0.1.4"),M&&d("using test mode"),c!==void 0&&d("auto",c),E=O.closest("form"),E&&(E.addEventListener("submit",_),E.addEventListener("reset",p)),c==="onload"&&J()});function d(...o){(f||o.some(m=>m instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function _(o){E&&c==="onsubmit"&&x===y.UNVERIFIED?(o.preventDefault(),o.stopPropagation(),J().then(()=>{E==null||E.submit()})):requestAnimationFrame(()=>{z()})}function p(){z()}function h(o,m){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:m.number,salt:o.salt,signature:o.signature,test:M?!0:void 0,took:m.took}))}function I(o){if(!o.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(o.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!D.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${D.join(", ")}`);if(!o.challenge||o.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!o.salt||o.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function it(){if($)throw d("mocking error"),new Error("Mocked error.");if(i)return d("using provided json data"),i;if(M)return d("generating test challenge"),Ke();{if(!a)throw new Error("Attribute challengeurl not set.");d("fetching challenge from",a);const o=await fetch(a);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);return o.json()}}async function lt(o){let m=null;if("Worker"in window){try{m=await ot(o.challenge,o.salt,o.algorithm)}catch(le){d(le)}if((m==null?void 0:m.number)!==void 0)return{data:o,solution:m}}return{data:o,solution:await ze(o.challenge,o.salt,o.algorithm,C)}}async function ot(o,m,le){const _e=new Te;return new Promise(ut=>{_e.addEventListener("message",ht=>{ut(ht.data)}),_e.postMessage({alg:le,challenge:o,max:C,salt:m})})}function st(){[y.UNVERIFIED,y.ERROR].includes(x)?J():n(5,A=!0)}function ct(){x===y.VERIFYING&&alert(r.waitAlert)}function z(o=y.UNVERIFIED){n(5,A=!1),n(7,v=null),n(3,F=null),n(4,x=o)}async function J(){return z(y.VERIFYING),it().then(o=>(I(o),d("challenge",o),lt(o))).then(({data:o,solution:m})=>{if(d("solution",m),(m==null?void 0:m.number)!==void 0)d("verified"),n(4,x=y.VERIFIED),n(5,A=!0),n(3,F=h(o,m)),Z("verified",{payload:F}),d("payload",F);else throw new Error("Unexpected result returned.")}).catch(o=>{d(o),n(4,x=y.ERROR),n(5,A=!1),n(7,v=o)})}function at(){A=this.checked,n(5,A)}function ft(o){te[o?"unshift":"push"](()=>{O=o,n(6,O)})}return t.$$set=o=>{"auto"in o&&n(0,c=o.auto),"challengeurl"in o&&n(11,a=o.challengeurl),"challengejson"in o&&n(12,u=o.challengejson),"debug"in o&&n(13,f=o.debug),"hidefooter"in o&&n(1,S=o.hidefooter),"name"in o&&n(2,k=o.name),"maxnumber"in o&&n(14,C=o.maxnumber),"mockerror"in o&&n(15,$=o.mockerror),"strings"in o&&n(16,N=o.strings),"test"in o&&n(17,M=o.test)},t.$$.update=()=>{t.$$.dirty[0]&4096&&(i=u?$e(u):void 0),t.$$.dirty[0]&65536&&n(20,l=N?$e(N):{}),t.$$.dirty[0]&1048576&&n(8,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${be}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&24&&Z("statechange",{payload:F,state:x})},[c,S,k,F,x,A,O,v,r,st,ct,a,u,f,C,$,N,M,z,J,l,at,ft]}class ve extends Be{constructor(e){super(),Ze(this,e,rt,nt,pe,{auto:0,challengeurl:11,challengejson:12,debug:13,hidefooter:1,name:2,maxnumber:14,mockerror:15,strings:16,test:17,reset:18,verify:19},Je,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),q()}get challengeurl(){return this.$$.ctx[11]}set challengeurl(e){this.$$set({challengeurl:e}),q()}get challengejson(){return this.$$.ctx[12]}set challengejson(e){this.$$set({challengejson:e}),q()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),q()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),q()}get name(){return this.$$.ctx[2]}set name(e){this.$$set({name:e}),q()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),q()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),q()}get strings(){return this.$$.ctx[16]}set strings(e){this.$$set({strings:e}),q()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),q()}get reset(){return this.$$.ctx[18]}get verify(){return this.$$.ctx[19]}}customElements.define("altcha-widget",He(ve,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset","verify"],!1)),L.Altcha=ve,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(L,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(L=typeof globalThis<"u"?globalThis:L||self,w(L.altcha={}))})(this,function(L){"use strict";var gt=Object.defineProperty;var mt=(L,w,F)=>w in L?gt(L,w,{enumerable:!0,configurable:!0,writable:!0,value:F}):L[w]=F;var R=(L,w,F)=>(mt(L,typeof w!="symbol"?w+"":w,F),F);function w(){}function F(t){return t()}function oe(){return Object.create(null)}function T(t){t.forEach(F)}function se(t){return typeof t=="function"}function ke(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Ee(t){return Object.keys(t).length===0}function g(t,e){t.appendChild(e)}function Ce(t,e,n){const i=xe(t);if(!i.getElementById(e)){const l=b("style");l.id=e,l.textContent=n,Ie(i,l)}}function xe(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function Ie(t,e){return g(t.head||t,e),e.sheet}function G(t,e,n){t.insertBefore(e,n||null)}function j(t){t.parentNode&&t.parentNode.removeChild(t)}function b(t){return document.createElement(t)}function V(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function Le(t){return document.createTextNode(t)}function Y(){return Le(" ")}function J(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function s(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function qe(t){return Array.from(t.childNodes)}function ce(t,e,n){t.classList.toggle(e,!!n)}function Ne(t,e,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:i})}function Re(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let P;function X(t){P=t}function Q(){if(!P)throw new Error("Function called outside component initialization");return P}function je(t){Q().$$.on_mount.push(t)}function Ae(t){Q().$$.on_destroy.push(t)}function Ge(){const t=Q();return(e,n,{cancelable:i=!1}={})=>{const l=t.$$.callbacks[e];if(l){const r=Ne(e,n,{cancelable:i});return l.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const H=[],ee=[];let B=[];const ae=[],fe=Promise.resolve();let te=!1;function ue(){te||(te=!0,fe.then(q))}function Se(){return ue(),fe}function ne(t){B.push(t)}const re=new Set;let W=0;function q(){if(W!==0)return;const t=P;do{try{for(;W<H.length;){const e=H[W];W++,X(e),Me(e.$$)}}catch(e){throw H.length=0,W=0,e}for(X(null),H.length=0,W=0;ee.length;)ee.pop()();for(let e=0;e<B.length;e+=1){const n=B[e];re.has(n)||(re.add(n),n())}B.length=0}while(H.length);for(;ae.length;)ae.pop()();te=!1,re.clear(),X(t)}function Me(t){if(t.fragment!==null){t.update(),T(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(ne)}}function Ve(t){const e=[],n=[];B.forEach(i=>t.indexOf(i)===-1?e.push(i):n.push(i)),n.forEach(i=>i()),B=e}const Ue=new Set;function Fe(t,e){t&&t.i&&(Ue.delete(t),t.i(e))}function Oe(t,e,n){const{fragment:i,after_update:l}=t.$$;i&&i.m(e,n),ne(()=>{const r=t.$$.on_mount.map(F).filter(se);t.$$.on_destroy?t.$$.on_destroy.push(...r):T(r),t.$$.on_mount=[]}),l.forEach(ne)}function Ye(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),T(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Ze(t,e){t.$$.dirty[0]===-1&&(H.push(t),ue(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function He(t,e,n,i,l,r,c=null,a=[-1]){const u=P;X(t);const f=t.$$={fragment:null,ctx:[],props:r,update:w,not_equal:l,bound:oe(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(u?u.$$.context:[])),callbacks:oe(),dirty:a,skip_bound:!1,root:e.target||u.$$.root};c&&c(f.root);let S=!1;if(f.ctx=n?n(t,e.props||{},(k,C,...$)=>{const N=$.length?$[0]:C;return f.ctx&&l(f.ctx[k],f.ctx[k]=N)&&(!f.skip_bound&&f.bound[k]&&f.bound[k](N),S&&Ze(t,k)),C}):[],f.update(),S=!0,T(f.before_update),f.fragment=i?i(f.ctx):!1,e.target){if(e.hydrate){const k=qe(e.target);f.fragment&&f.fragment.l(k),k.forEach(j)}else f.fragment&&f.fragment.c();e.intro&&Fe(t.$$.fragment),Oe(t,e.target,e.anchor),q()}X(u)}let he;typeof HTMLElement=="function"&&(he=class extends HTMLElement{constructor(e,n,i){super();R(this,"$$ctor");R(this,"$$s");R(this,"$$c");R(this,"$$cn",!1);R(this,"$$d",{});R(this,"$$r",!1);R(this,"$$p_d",{});R(this,"$$l",{});R(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,i&&this.attachShadow({mode:"open"})}addEventListener(e,n,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const l=this.$$c.$on(e,n);this.$$l_u.set(n,l)}super.addEventListener(e,n,i)}removeEventListener(e,n,i){if(super.removeEventListener(e,n,i),this.$$c){const l=this.$$l_u.get(n);l&&(l(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=b("slot"),r!=="default"&&s(c,"name",r)},m:function(f,S){G(f,c,S)},d:function(f){f&&j(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},i=Re(this);for(const r of this.$$s)r in i&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=K(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const l=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const c=K(r,this.$$d[r],this.$$p_d,"toAttribute");c==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,c)}this.$$r=!1};this.$$c.$$.after_update.push(l),l();for(const r in this.$$l)for(const c of this.$$l[r]){const a=this.$$c.$on(r,c);this.$$l_u.set(c,a)}this.$$l={}}}attributeChangedCallback(e,n,i){var l;this.$$r||(e=this.$$g_p(e),this.$$d[e]=K(e,i,this.$$p_d,"toProp"),(l=this.$$c)==null||l.$set({[e]:this.$$d[e]}))}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 K(t,e,n,i){var r;const l=(r=n[t])==null?void 0:r.type;if(e=l==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!n[t])return e;if(i==="toAttribute")switch(l){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(l){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function Be(t,e,n,i,l,r){let c=class extends he{constructor(){super(t,n,l),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(c.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(u){var f;u=K(a,u,e),this.$$d[a]=u,(f=this.$$c)==null||f.$set({[a]:u})}})}),i.forEach(a=>{Object.defineProperty(c.prototype,a,{get(){var u;return(u=this.$$c)==null?void 0:u[a]}})}),r&&(c=r(c)),t.element=c,c}class We{constructor(){R(this,"$$");R(this,"$$set")}$destroy(){Ye(this,1),this.$destroy=w}$on(e,n){if(!se(n))return w;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const l=i.indexOf(n);l!==-1&&i.splice(l,1)}}$set(e){this.$$set&&!Ee(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Te="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Te);const de="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLnRvVXBwZXJDYXNlKCksci5lbmNvZGUoZStuKSkpfWFzeW5jIGZ1bmN0aW9uIGkoZSxuLGE9IlNIQS0yNTYiLG89MWU3KXtjb25zdCBzPURhdGUubm93KCk7Zm9yKGxldCB0PTA7dDw9bzt0KyspaWYoYXdhaXQgbChuLHQsYSk9PT1lKXJldHVybntudW1iZXI6dCx0b29rOkRhdGUubm93KCktc307cmV0dXJuIG51bGx9b25tZXNzYWdlPWFzeW5jIGU9Pntjb25zdHthbGc6bixjaGFsbGVuZ2U6YSxtYXg6byxzYWx0OnN9PWUuZGF0YXx8e307aWYoYSYmcyl7Y29uc3QgdD1hd2FpdCBpKGEscyxuLG8pO3NlbGYucG9zdE1lc3NhZ2UodCYmey4uLnQsd29ya2VyOiEwfSl9ZWxzZSBzZWxmLnBvc3RNZXNzYWdlKG51bGwpfX0pKCk7Cg==",ge=typeof window<"u"&&window.Blob&&new Blob([atob(de)],{type:"text/javascript;charset=utf-8"});function Pe(){let t;try{if(t=ge&&(window.URL||window.webkitURL).createObjectURL(ge),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+de)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Xe=1e7,De=new TextEncoder;function Ke(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function ze(t=1e5,e="SHA-256"){const n=Date.now().toString(16),i=Math.round(Math.random()*t),l=await me(n,i,e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function me(t,e,n){return Ke(await crypto.subtle.digest(n.toUpperCase(),De.encode(t+e)))}async function Je(t,e,n="SHA-256",i=Xe){const l=Date.now();for(let r=0;r<=i;r++)if(await me(e,r,n)===t)return{number:r,took:Date.now()-l};return null}var y=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverified",t))(y||{});function Qe(t){Ce(t,"svelte-fqcw55",".altcha.svelte-fqcw55.svelte-fqcw55{background:var(--altcha-color-base, transparent);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative;text-align:left}.altcha.svelte-fqcw55.svelte-fqcw55:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-fqcw55.svelte-fqcw55{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-fqcw55.svelte-fqcw55{flex-grow:1}.altcha-label.svelte-fqcw55 label.svelte-fqcw55{cursor:pointer}.altcha-logo.svelte-fqcw55.svelte-fqcw55{color:currentColor;opacity:0.3}.altcha-logo.svelte-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-error.svelte-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55{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-fqcw55.svelte-fqcw55:hover{opacity:1}.altcha-footer.svelte-fqcw55>.svelte-fqcw55:first-child{flex-grow:1}.altcha-footer.svelte-fqcw55 a{color:currentColor}.altcha-checkbox.svelte-fqcw55.svelte-fqcw55{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-fqcw55 input.svelte-fqcw55{width:18px;height:18px;margin:0}.altcha-hidden.svelte-fqcw55.svelte-fqcw55{display:none}.altcha-spinner.svelte-fqcw55.svelte-fqcw55{animation:svelte-fqcw55-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-fqcw55-altcha-spinner{100%{transform:rotate(360deg)}}")}function we(t){let e,n,i;return{c(){e=V("svg"),n=V("path"),i=V("path"),s(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"),s(n,"fill","currentColor"),s(n,"opacity",".25"),s(i,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),s(i,"fill","currentColor"),s(i,"class","altcha-spinner svelte-fqcw55"),s(e,"width","24"),s(e,"height","24"),s(e,"viewBox","0 0 24 24"),s(e,"xmlns","http://www.w3.org/2000/svg")},m(l,r){G(l,e,r),g(e,n),g(e,i)},d(l){l&&j(e)}}}function et(t){let e,n=t[8].label+"",i;return{c(){e=b("label"),s(e,"for",i=t[2]+"_checkbox"),s(e,"class","svelte-fqcw55")},m(l,r){G(l,e,r),e.innerHTML=n},p(l,r){r[0]&256&&n!==(n=l[8].label+"")&&(e.innerHTML=n),r[0]&4&&i!==(i=l[2]+"_checkbox")&&s(e,"for",i)},d(l){l&&j(e)}}}function tt(t){let e,n=t[8].verifying+"";return{c(){e=b("span")},m(i,l){G(i,e,l),e.innerHTML=n},p(i,l){l[0]&256&&n!==(n=i[8].verifying+"")&&(e.innerHTML=n)},d(i){i&&j(e)}}}function nt(t){let e,n=t[8].verified+"",i,l;return{c(){e=b("span"),i=Y(),l=b("input"),s(l,"type","hidden"),s(l,"name",t[2]),l.value=t[3]},m(r,c){G(r,e,c),e.innerHTML=n,G(r,i,c),G(r,l,c)},p(r,c){c[0]&256&&n!==(n=r[8].verified+"")&&(e.innerHTML=n),c[0]&4&&s(l,"name",r[2]),c[0]&8&&(l.value=r[3])},d(r){r&&(j(e),j(i),j(l))}}}function be(t){let e,n,i,l,r,c=t[8].error+"";return{c(){e=b("div"),n=V("svg"),i=V("path"),l=Y(),r=b("div"),s(i,"stroke-linecap","round"),s(i,"stroke-linejoin","round"),s(i,"d","M6 18L18 6M6 6l12 12"),s(n,"width","14"),s(n,"height","14"),s(n,"xmlns","http://www.w3.org/2000/svg"),s(n,"fill","none"),s(n,"viewBox","0 0 24 24"),s(n,"stroke-width","1.5"),s(n,"stroke","currentColor"),s(r,"title",t[7]),s(e,"class","altcha-error svelte-fqcw55")},m(a,u){G(a,e,u),g(e,n),g(n,i),g(e,l),g(e,r),r.innerHTML=c},p(a,u){u[0]&256&&c!==(c=a[8].error+"")&&(r.innerHTML=c),u[0]&128&&s(r,"title",a[7])},d(a){a&&j(e)}}}function $e(t){let e,n,i=t[8].footer+"";return{c(){e=b("div"),n=b("div"),s(n,"class","svelte-fqcw55"),s(e,"class","altcha-footer svelte-fqcw55")},m(l,r){G(l,e,r),g(e,n),n.innerHTML=i},p(l,r){r[0]&256&&i!==(i=l[8].footer+"")&&(n.innerHTML=i)},d(l){l&&j(e)}}}function rt(t){let e,n,i,l,r,c,a,u,f,S,k,C,$,N,M,Z,D,A,O,E,v=t[4]===y.VERIFYING&&we();function U(h,I){return h[4]===y.VERIFIED?nt:h[4]===y.VERIFYING?tt:et}let x=U(t),d=x(t),_=t[7]&&be(t),p=t[8].footer&&t[1]!==!0&&$e(t);return{c(){e=b("div"),n=b("div"),v&&v.c(),i=Y(),l=b("div"),r=b("input"),u=Y(),f=b("div"),d.c(),S=Y(),k=b("div"),C=b("a"),$=V("svg"),N=V("path"),M=V("path"),Z=V("path"),D=Y(),_&&_.c(),A=Y(),p&&p.c(),s(r,"type","checkbox"),s(r,"id",c=t[2]+"_checkbox"),r.required=a=t[0]!=="onsubmit",s(r,"class","svelte-fqcw55"),s(l,"class","altcha-checkbox svelte-fqcw55"),ce(l,"altcha-hidden",t[4]===y.VERIFYING),s(f,"class","altcha-label svelte-fqcw55"),s(N,"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"),s(N,"fill","currentColor"),s(M,"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"),s(M,"fill","currentColor"),s(Z,"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"),s(Z,"fill","currentColor"),s($,"width","22"),s($,"height","22"),s($,"viewBox","0 0 20 20"),s($,"fill","none"),s($,"xmlns","http://www.w3.org/2000/svg"),s(C,"href",ve),s(C,"target","_blank"),s(C,"class","altcha-logo svelte-fqcw55"),s(n,"class","altcha-main svelte-fqcw55"),s(e,"class","altcha svelte-fqcw55"),s(e,"data-state",t[4])},m(h,I){G(h,e,I),g(e,n),v&&v.m(n,null),g(n,i),g(n,l),g(l,r),r.checked=t[5],g(n,u),g(n,f),d.m(f,null),g(n,S),g(n,k),g(k,C),g(C,$),g($,N),g($,M),g($,Z),g(e,D),_&&_.m(e,null),g(e,A),p&&p.m(e,null),t[22](e),O||(E=[J(r,"change",t[21]),J(r,"change",t[9]),J(r,"invalid",t[10])],O=!0)},p(h,I){h[4]===y.VERIFYING?v||(v=we(),v.c(),v.m(n,i)):v&&(v.d(1),v=null),I[0]&4&&c!==(c=h[2]+"_checkbox")&&s(r,"id",c),I[0]&1&&a!==(a=h[0]!=="onsubmit")&&(r.required=a),I[0]&32&&(r.checked=h[5]),I[0]&16&&ce(l,"altcha-hidden",h[4]===y.VERIFYING),x===(x=U(h))&&d?d.p(h,I):(d.d(1),d=x(h),d&&(d.c(),d.m(f,null))),h[7]?_?_.p(h,I):(_=be(h),_.c(),_.m(e,A)):_&&(_.d(1),_=null),h[8].footer&&h[1]!==!0?p?p.p(h,I):(p=$e(h),p.c(),p.m(e,null)):p&&(p.d(1),p=null),I[0]&16&&s(e,"data-state",h[4])},i:w,o:w,d(h){h&&j(e),v&&v.d(),d.d(),_&&_.d(),p&&p.d(),t[22](null),O=!1,T(E)}}}const ve="https://altcha.org/";function _e(t){return JSON.parse(t)}function it(t,e,n){let i,l,r,{auto:c=void 0}=e,{challengeurl:a=void 0}=e,{challengejson:u=void 0}=e,{debug:f=!1}=e,{hidefooter:S=!1}=e,{name:k="altcha"}=e,{maxnumber:C=void 0}=e,{mockerror:$=!1}=e,{strings:N=void 0}=e,{test:M=!1}=e;const Z=Ge(),D=["SHA-256","SHA-384","SHA-512"];let A=!1,O,E=null,v=null,U=null,x=y.UNVERIFIED;Ae(()=>{E&&(E.removeEventListener("submit",_),E.removeEventListener("reset",p),E=null)}),je(()=>{d("mounted","0.1.5"),M&&d("using test mode"),c!==void 0&&d("auto",c),E=O.closest("form"),E&&(E.addEventListener("submit",_),E.addEventListener("reset",p)),c==="onload"&&z()});function d(...o){(f||o.some(m=>m instanceof Error))&&console[o[0]instanceof Error?"error":"log"]("ALTCHA",...o)}function _(o){E&&c==="onsubmit"&&x===y.UNVERIFIED&&(o.preventDefault(),o.stopPropagation(),z().then(()=>{E==null||E.requestSubmit()}))}function p(){ie()}function h(o,m){return btoa(JSON.stringify({algorithm:o.algorithm,challenge:o.challenge,number:m.number,salt:o.salt,signature:o.signature,test:M?!0:void 0,took:m.took}))}function I(o){if(!o.algorithm)throw new Error("Invalid challenge. Property algorithm is missing.");if(o.signature===void 0)throw new Error("Invalid challenge. Property signature is missing.");if(!D.includes(o.algorithm.toUpperCase()))throw new Error(`Unknown algorithm value. Allowed values: ${D.join(", ")}`);if(!o.challenge||o.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!o.salt||o.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.")}async function lt(){if($)throw d("mocking error"),new Error("Mocked error.");if(i)return d("using provided json data"),i;if(M)return d("generating test challenge"),ze();{if(!a)throw new Error("Attribute challengeurl not set.");d("fetching challenge from",a);const o=await fetch(a);if(o.status!==200)throw new Error(`Server responded with ${o.status}.`);return o.json()}}async function ot(o){let m=null;if("Worker"in window){try{m=await st(o.challenge,o.salt,o.algorithm)}catch(le){d(le)}if((m==null?void 0:m.number)!==void 0)return{data:o,solution:m}}return{data:o,solution:await Je(o.challenge,o.salt,o.algorithm,C)}}async function st(o,m,le){const ye=new Pe;return new Promise(ht=>{ye.addEventListener("message",dt=>{ht(dt.data)}),ye.postMessage({alg:le,challenge:o,max:C,salt:m})})}function ct(){[y.UNVERIFIED,y.ERROR].includes(x)?z():n(5,A=!0)}function at(){x===y.VERIFYING&&alert(r.waitAlert)}function ie(o=y.UNVERIFIED){n(5,A=!1),n(7,v=null),n(3,U=null),n(4,x=o)}async function z(){return ie(y.VERIFYING),lt().then(o=>(I(o),d("challenge",o),ot(o))).then(({data:o,solution:m})=>{if(d("solution",m),(m==null?void 0:m.number)!==void 0)d("verified"),n(4,x=y.VERIFIED),n(5,A=!0),n(3,U=h(o,m)),d("payload",U),Se().then(()=>{Z("verified",{payload:U})});else throw new Error("Unexpected result returned.")}).catch(o=>{d(o),n(4,x=y.ERROR),n(5,A=!1),n(7,v=o)})}function ft(){A=this.checked,n(5,A)}function ut(o){ee[o?"unshift":"push"](()=>{O=o,n(6,O)})}return t.$$set=o=>{"auto"in o&&n(0,c=o.auto),"challengeurl"in o&&n(11,a=o.challengeurl),"challengejson"in o&&n(12,u=o.challengejson),"debug"in o&&n(13,f=o.debug),"hidefooter"in o&&n(1,S=o.hidefooter),"name"in o&&n(2,k=o.name),"maxnumber"in o&&n(14,C=o.maxnumber),"mockerror"in o&&n(15,$=o.mockerror),"strings"in o&&n(16,N=o.strings),"test"in o&&n(17,M=o.test)},t.$$.update=()=>{t.$$.dirty[0]&4096&&(i=u?_e(u):void 0),t.$$.dirty[0]&65536&&n(20,l=N?_e(N):{}),t.$$.dirty[0]&1048576&&n(8,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ve}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...l}),t.$$.dirty[0]&24&&Z("statechange",{payload:U,state:x})},[c,S,k,U,x,A,O,v,r,ct,at,a,u,f,C,$,N,M,ie,z,l,ft,ut]}class pe extends We{constructor(e){super(),He(this,e,it,rt,ke,{auto:0,challengeurl:11,challengejson:12,debug:13,hidefooter:1,name:2,maxnumber:14,mockerror:15,strings:16,test:17,reset:18,verify:19},Qe,[-1,-1])}get auto(){return this.$$.ctx[0]}set auto(e){this.$$set({auto:e}),q()}get challengeurl(){return this.$$.ctx[11]}set challengeurl(e){this.$$set({challengeurl:e}),q()}get challengejson(){return this.$$.ctx[12]}set challengejson(e){this.$$set({challengejson:e}),q()}get debug(){return this.$$.ctx[13]}set debug(e){this.$$set({debug:e}),q()}get hidefooter(){return this.$$.ctx[1]}set hidefooter(e){this.$$set({hidefooter:e}),q()}get name(){return this.$$.ctx[2]}set name(e){this.$$set({name:e}),q()}get maxnumber(){return this.$$.ctx[14]}set maxnumber(e){this.$$set({maxnumber:e}),q()}get mockerror(){return this.$$.ctx[15]}set mockerror(e){this.$$set({mockerror:e}),q()}get strings(){return this.$$.ctx[16]}set strings(e){this.$$set({strings:e}),q()}get test(){return this.$$.ctx[17]}set test(e){this.$$set({test:e}),q()}get reset(){return this.$$.ctx[18]}get verify(){return this.$$.ctx[19]}}customElements.define("altcha-widget",Be(pe,{auto:{},challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset","verify"],!1)),L.Altcha=pe,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|