altcha 0.1.0 → 0.1.1
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/LICENSE.txt +21 -0
- package/README.md +19 -15
- package/dist/altcha.iife.js +1 -0
- package/dist/altcha.js +69 -69
- package/dist/altcha.umd.cjs +1 -1
- package/package.json +15 -1
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Daniel Regeci
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
ALTCHA uses a proof-of-work mechanism to protect your website, APIs, and online services from spam and abuse. Unlike other solutions, ALTCHA is self-hosted, does not use cookies nor fingerprinting, does not track users, and is fully compliant with GDPR.
|
|
4
4
|
|
|
5
|
+
https://altcha.org
|
|
6
|
+
|
|
5
7
|
## Benefits
|
|
6
8
|
|
|
7
9
|
- __Friction-less__ - Using PoW instead of visual puzzles.
|
|
@@ -18,47 +20,49 @@ ALTCHA widget is distributed as a "Web Component" and [supports all modern brows
|
|
|
18
20
|
<script async defer src="/altcha.js" type="module"></script>
|
|
19
21
|
```
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
CDN: https://cdn.jsdelivr.net/gh/altcha-org/altcha@main/dist/altcha.min.js
|
|
24
|
+
|
|
25
|
+
### 2. Use `<altcha-widget>` tag in your forms
|
|
22
26
|
|
|
23
27
|
```html
|
|
24
28
|
<form>
|
|
25
|
-
<altcha-
|
|
29
|
+
<altcha-widget
|
|
26
30
|
challengeurl="https://..."
|
|
27
|
-
></altcha-
|
|
31
|
+
></altcha-widget>
|
|
28
32
|
</form>
|
|
29
33
|
```
|
|
30
34
|
|
|
31
35
|
See the [configuration](#configuration) below or visit the [website integration documentation](https://altcha.org/docs/website-integration).
|
|
32
36
|
|
|
33
|
-
### 3. Integrate
|
|
37
|
+
### 3. Integrate ALTCHA with your server
|
|
34
38
|
|
|
35
39
|
See [server documentation](https://altcha.org/docs/server-integration) for more details.
|
|
36
40
|
|
|
37
41
|
## Configuration
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
Required options (at least one is required):
|
|
40
44
|
|
|
41
|
-
- __challengeurl__ -
|
|
42
|
-
- __challengejson__ -
|
|
45
|
+
- __challengeurl__ - URL of your server to fetch the challenge from. Refer to [server integration](/docs/server-integration).
|
|
46
|
+
- __challengejson__ - JSON-encoded challenge data. If avoiding an HTTP request to `challengeurl`, provide the data here.
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
Additional options:
|
|
45
49
|
|
|
46
50
|
- __hidefooter__ - Hide the footer (ALTCHA link).
|
|
47
51
|
- __hidelogo__ - Hide the ALTCHA logo.
|
|
48
|
-
- __maxnumber__ -
|
|
49
|
-
- __name__ - The name of the hidden field containing payload (defaults to "altcha").
|
|
50
|
-
- __strings__ - JSON-encoded translation strings.
|
|
52
|
+
- __maxnumber__ - The max. number to iterate to (defaults to 10,000,000).
|
|
53
|
+
- __name__ - The name of the hidden field containing the payload (defaults to "altcha").
|
|
54
|
+
- __strings__ - JSON-encoded translation strings. Refer to [customization](/docs/widget-customization).
|
|
51
55
|
|
|
52
56
|
Development / testing options:
|
|
53
57
|
|
|
54
|
-
- __debug__ - Print log messages
|
|
58
|
+
- __debug__ - Print log messages in the console.
|
|
55
59
|
- __mockerror__ - Causes the verification to always fail with a "mock" error.
|
|
56
|
-
- __test__ -
|
|
60
|
+
- __test__ - Generates a "mock" challenge within the widget, bypassing the request to `challengeurl`.
|
|
57
61
|
|
|
58
62
|
Events:
|
|
59
63
|
|
|
60
|
-
- __statechange__ -
|
|
61
|
-
- __verified__ -
|
|
64
|
+
- __statechange__ - Triggers whenever an internal `state` changes.
|
|
65
|
+
- __verified__ - Triggers when the challenge is verified.
|
|
62
66
|
|
|
63
67
|
Using events:
|
|
64
68
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var altcha=function(O){"use strict";var ft=Object.defineProperty;var ht=(O,y,H)=>y in O?ft(O,y,{enumerable:!0,configurable:!0,writable:!0,value:H}):O[y]=H;var x=(O,y,H)=>(ht(O,typeof y!="symbol"?y+"":y,H),H);function y(){}function H(t){return t()}function le(){return Object.create(null)}function U(t){t.forEach(H)}function ie(t){return typeof t=="function"}function ve(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function we(t){return Object.keys(t).length===0}function d(t,e){t.appendChild(e)}function je(t,e,n){const l=pe(t);if(!l.getElementById(e)){const i=$("style");i.id=e,i.textContent=n,ye(l,i)}}function pe(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function ye(t,e){return d(t.head||t,e),e.sheet}function V(t,e,n){t.insertBefore(e,n||null)}function R(t){t.parentNode&&t.parentNode.removeChild(t)}function $(t){return document.createElement(t)}function S(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function ke(t){return document.createTextNode(t)}function T(){return ke(" ")}function J(t,e,n,l){return t.addEventListener(e,n,l),()=>t.removeEventListener(e,n,l)}function o(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ee(t){return Array.from(t.childNodes)}function se(t,e,n){t.classList.toggle(e,!!n)}function Ce(t,e,{bubbles:n=!1,cancelable:l=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:l})}function Le(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let K;function P(t){K=t}function Q(){if(!K)throw new Error("Function called outside component initialization");return K}function xe(t){Q().$$.on_mount.push(t)}function Re(t){Q().$$.on_destroy.push(t)}function Ie(){const t=Q();return(e,n,{cancelable:l=!1}={})=>{const i=t.$$.callbacks[e];if(i){const r=Ce(e,n,{cancelable:l});return i.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const B=[],q=[];let Y=[];const oe=[],Ne=Promise.resolve();let ee=!1;function Ae(){ee||(ee=!0,Ne.then(I))}function te(t){Y.push(t)}const ne=new Set;let Z=0;function I(){if(Z!==0)return;const t=K;do{try{for(;Z<B.length;){const e=B[Z];Z++,P(e),Me(e.$$)}}catch(e){throw B.length=0,Z=0,e}for(P(null),B.length=0,Z=0;q.length;)q.pop()();for(let e=0;e<Y.length;e+=1){const n=Y[e];ne.has(n)||(ne.add(n),n())}Y.length=0}while(B.length);for(;oe.length;)oe.pop()();ee=!1,ne.clear(),P(t)}function Me(t){if(t.fragment!==null){t.update(),U(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(te)}}function Ve(t){const e=[],n=[];Y.forEach(l=>t.indexOf(l)===-1?e.push(l):n.push(l)),n.forEach(l=>l()),Y=e}const Oe=new Set;function Se(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Fe(t,e,n){const{fragment:l,after_update:i}=t.$$;l&&l.m(e,n),te(()=>{const r=t.$$.on_mount.map(H).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):U(r),t.$$.on_mount=[]}),i.forEach(te)}function He(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),U(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Ge(t,e){t.$$.dirty[0]===-1&&(B.push(t),Ae(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Te(t,e,n,l,i,r,c=null,a=[-1]){const u=K;P(t);const f=t.$$={fragment:null,ctx:[],props:r,update:y,not_equal:i,bound:le(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(u?u.$$.context:[])),callbacks:le(),dirty:a,skip_bound:!1,root:e.target||u.$$.root};c&&c(f.root);let N=!1;if(f.ctx=n?n(t,e.props||{},(g,_,...E)=>{const k=E.length?E[0]:_;return f.ctx&&i(f.ctx[g],f.ctx[g]=k)&&(!f.skip_bound&&f.bound[g]&&f.bound[g](k),N&&Ge(t,g)),_}):[],f.update(),N=!0,U(f.before_update),f.fragment=l?l(f.ctx):!1,e.target){if(e.hydrate){const g=Ee(e.target);f.fragment&&f.fragment.l(g),g.forEach(R)}else f.fragment&&f.fragment.c();e.intro&&Se(t.$$.fragment),Fe(t,e.target,e.anchor),I()}P(u)}let ce;typeof HTMLElement=="function"&&(ce=class extends HTMLElement{constructor(e,n,l){super();x(this,"$$ctor");x(this,"$$s");x(this,"$$c");x(this,"$$cn",!1);x(this,"$$d",{});x(this,"$$r",!1);x(this,"$$p_d",{});x(this,"$$l",{});x(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,l&&this.attachShadow({mode:"open"})}addEventListener(e,n,l){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const i=this.$$c.$on(e,n);this.$$l_u.set(n,i)}super.addEventListener(e,n,l)}removeEventListener(e,n,l){if(super.removeEventListener(e,n,l),this.$$c){const i=this.$$l_u.get(n);i&&(i(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=$("slot"),r!=="default"&&o(c,"name",r)},m:function(f,N){V(f,c,N)},d:function(f){f&&R(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},l=Le(this);for(const r of this.$$s)r in l&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=D(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const i=()=>{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=D(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(i),i();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,l){var i;this.$$r||(e=this.$$g_p(e),this.$$d[e]=D(e,l,this.$$p_d,"toProp"),(i=this.$$c)==null||i.$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 D(t,e,n,l){var r;const i=(r=n[t])==null?void 0:r.type;if(e=i==="Boolean"&&typeof e!="boolean"?e!=null:e,!l||!n[t])return e;if(l==="toAttribute")switch(i){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(i){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function We(t,e,n,l,i,r){let c=class extends ce{constructor(){super(t,n,i),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=D(a,u,e),this.$$d[a]=u,(f=this.$$c)==null||f.$set({[a]:u})}})}),l.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(){x(this,"$$");x(this,"$$set")}$destroy(){He(this,1),this.$destroy=y}$on(e,n){if(!ie(n))return y;const l=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return l.push(n),()=>{const i=l.indexOf(n);i!==-1&&l.splice(i,1)}}$set(e){this.$$set&&!we(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Ye="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ye);const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLHIuZW5jb2RlKGUrbikpKX1hc3luYyBmdW5jdGlvbiBpKGUsbixhPSJTSEEtMjU2IixvPTFlNyl7Y29uc3Qgcz1EYXRlLm5vdygpO2ZvcihsZXQgdD0wO3Q8PW87dCsrKWlmKGF3YWl0IGwobix0LGEpPT09ZSlyZXR1cm57bnVtYmVyOnQsdG9vazpEYXRlLm5vdygpLXN9O3JldHVybiBudWxsfW9ubWVzc2FnZT1hc3luYyBlPT57Y29uc3R7YWxnOm4sY2hhbGxlbmdlOmEsbWF4Om8sc2FsdDpzfT1lLmRhdGF8fHt9O2lmKGEmJnMpe2NvbnN0IHQ9YXdhaXQgaShhLHMsbixvKTtzZWxmLnBvc3RNZXNzYWdlKHQmJnsuLi50LHdvcmtlcjohMH0pfWVsc2Ugc2VsZi5wb3N0TWVzc2FnZShudWxsKX19KSgpOwo=",ue=typeof window<"u"&&window.Blob&&new Blob([atob(ae)],{type:"text/javascript;charset=utf-8"});function Ze(){let t;try{if(t=ue&&(window.URL||window.webkitURL).createObjectURL(ue),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+ae)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Ue=1e7,Ke=new TextEncoder;function Pe(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Xe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),l=Math.round(Math.random()*t),i=await fe(n,l,e);return{algorithm:e,challenge:i,salt:n,signature:""}}async function fe(t,e,n){return Pe(await crypto.subtle.digest(n,Ke.encode(t+e)))}async function De(t,e,n="SHA-256",l=Ue){const i=Date.now();for(let r=0;r<=l;r++)if(await fe(e,r,n)===t)return{number:r,took:Date.now()-i};return null}var p=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverfied",t))(p||{});function ze(t){je(t,"svelte-mjm2j6",".altcha.svelte-mjm2j6.svelte-mjm2j6{background:var(--altcha-color-base, #ffffff);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}.altcha.svelte-mjm2j6.svelte-mjm2j6:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-mjm2j6.svelte-mjm2j6{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-mjm2j6.svelte-mjm2j6{flex-grow:1}.altcha-label.svelte-mjm2j6 label.svelte-mjm2j6{cursor:pointer}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6{color:currentColor;opacity:0.3}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6:hover{opacity:1}.altcha-error.svelte-mjm2j6.svelte-mjm2j6{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-mjm2j6.svelte-mjm2j6{align-items:center;background-color:var(--altcha-color-footer-bg, #f4f4f4);display:flex;font-size:0.75rem;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-mjm2j6>.svelte-mjm2j6:first-child{flex-grow:1}.altcha-footer.svelte-mjm2j6 a{color:currentColor}.altcha-checkbox.svelte-mjm2j6.svelte-mjm2j6{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-mjm2j6 input.svelte-mjm2j6{width:18px;height:18px;margin:0}.altcha-hidden.svelte-mjm2j6.svelte-mjm2j6{display:none}.altcha-spinner.svelte-mjm2j6.svelte-mjm2j6{animation:svelte-mjm2j6-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-mjm2j6-altcha-spinner{100%{transform:rotate(360deg)}}")}function he(t){let e,n,l;return{c(){e=S("svg"),n=S("path"),l=S("path"),o(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"),o(n,"fill","currentColor"),o(n,"opacity",".25"),o(l,"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"),o(l,"fill","currentColor"),o(l,"class","altcha-spinner svelte-mjm2j6"),o(e,"width","24"),o(e,"height","24"),o(e,"viewBox","0 0 24 24"),o(e,"xmlns","http://www.w3.org/2000/svg")},m(i,r){V(i,e,r),d(e,n),d(e,l)},d(i){i&&R(e)}}}function Je(t){let e,n=t[7].label+"",l;return{c(){e=$("label"),o(e,"for",l=t[1]+"_checkbox"),o(e,"class","svelte-mjm2j6")},m(i,r){V(i,e,r),e.innerHTML=n},p(i,r){r[0]&128&&n!==(n=i[7].label+"")&&(e.innerHTML=n),r[0]&2&&l!==(l=i[1]+"_checkbox")&&o(e,"for",l)},d(i){i&&R(e)}}}function Qe(t){let e,n=t[7].verifying+"";return{c(){e=$("span")},m(l,i){V(l,e,i),e.innerHTML=n},p(l,i){i[0]&128&&n!==(n=l[7].verifying+"")&&(e.innerHTML=n)},d(l){l&&R(e)}}}function qe(t){let e,n=t[7].verified+"",l,i;return{c(){e=$("span"),l=T(),i=$("input"),o(i,"type","hidden"),o(i,"name",t[1]),i.value=t[2]},m(r,c){V(r,e,c),e.innerHTML=n,V(r,l,c),V(r,i,c)},p(r,c){c[0]&128&&n!==(n=r[7].verified+"")&&(e.innerHTML=n),c[0]&2&&o(i,"name",r[1]),c[0]&4&&(i.value=r[2])},d(r){r&&(R(e),R(l),R(i))}}}function de(t){let e,n,l,i,r,c=t[7].error+"";return{c(){e=$("div"),n=S("svg"),l=S("path"),i=T(),r=$("div"),o(l,"stroke-linecap","round"),o(l,"stroke-linejoin","round"),o(l,"d","M6 18L18 6M6 6l12 12"),o(n,"width","14"),o(n,"height","14"),o(n,"xmlns","http://www.w3.org/2000/svg"),o(n,"fill","none"),o(n,"viewBox","0 0 24 24"),o(n,"stroke-width","1.5"),o(n,"stroke","currentColor"),o(r,"title",t[6]),o(e,"class","altcha-error svelte-mjm2j6")},m(a,u){V(a,e,u),d(e,n),d(n,l),d(e,i),d(e,r),r.innerHTML=c},p(a,u){u[0]&128&&c!==(c=a[7].error+"")&&(r.innerHTML=c),u[0]&64&&o(r,"title",a[6])},d(a){a&&R(e)}}}function me(t){let e,n,l=t[7].footer+"";return{c(){e=$("div"),n=$("div"),o(n,"class","svelte-mjm2j6"),o(e,"class","altcha-footer svelte-mjm2j6")},m(i,r){V(i,e,r),d(e,n),n.innerHTML=l},p(i,r){r[0]&128&&l!==(l=i[7].footer+"")&&(n.innerHTML=l)},d(i){i&&R(e)}}}function et(t){let e,n,l,i,r,c,a,u,f,N,g,_,E,k,W,X,A,G,M,v=t[3]===p.VERIFYING&&he();function F(h,L){return h[3]===p.VERIFIED?qe:h[3]===p.VERIFYING?Qe:Je}let C=F(t),m=C(t),w=t[6]&&de(t),j=t[7].footer&&t[0]!==!0&&me(t);return{c(){e=$("div"),n=$("div"),v&&v.c(),l=T(),i=$("div"),r=$("input"),a=T(),u=$("div"),m.c(),f=T(),N=$("div"),g=$("a"),_=S("svg"),E=S("path"),k=S("path"),W=S("path"),X=T(),w&&w.c(),A=T(),j&&j.c(),o(r,"type","checkbox"),o(r,"id",c=t[1]+"_checkbox"),r.required=!0,o(r,"class","svelte-mjm2j6"),o(i,"class","altcha-checkbox svelte-mjm2j6"),se(i,"altcha-hidden",t[3]===p.VERIFYING),o(u,"class","altcha-label svelte-mjm2j6"),o(E,"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"),o(E,"fill","currentColor"),o(k,"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"),o(k,"fill","currentColor"),o(W,"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"),o(W,"fill","currentColor"),o(_,"width","22"),o(_,"height","22"),o(_,"viewBox","0 0 20 20"),o(_,"fill","none"),o(_,"xmlns","http://www.w3.org/2000/svg"),o(g,"href",ge),o(g,"target","_blank"),o(g,"class","altcha-logo svelte-mjm2j6"),o(n,"class","altcha-main svelte-mjm2j6"),o(e,"class","altcha svelte-mjm2j6"),o(e,"data-state",t[3])},m(h,L){V(h,e,L),d(e,n),v&&v.m(n,null),d(n,l),d(n,i),d(i,r),r.checked=t[4],d(n,a),d(n,u),m.m(u,null),d(n,f),d(n,N),d(N,g),d(g,_),d(_,E),d(_,k),d(_,W),d(e,X),w&&w.m(e,null),d(e,A),j&&j.m(e,null),t[20](e),G||(M=[J(r,"change",t[19]),J(r,"change",t[8]),J(r,"invalid",t[9])],G=!0)},p(h,L){h[3]===p.VERIFYING?v||(v=he(),v.c(),v.m(n,l)):v&&(v.d(1),v=null),L[0]&2&&c!==(c=h[1]+"_checkbox")&&o(r,"id",c),L[0]&16&&(r.checked=h[4]),L[0]&8&&se(i,"altcha-hidden",h[3]===p.VERIFYING),C===(C=F(h))&&m?m.p(h,L):(m.d(1),m=C(h),m&&(m.c(),m.m(u,null))),h[6]?w?w.p(h,L):(w=de(h),w.c(),w.m(e,A)):w&&(w.d(1),w=null),h[7].footer&&h[0]!==!0?j?j.p(h,L):(j=me(h),j.c(),j.m(e,null)):j&&(j.d(1),j=null),L[0]&8&&o(e,"data-state",h[3])},i:y,o:y,d(h){h&&R(e),v&&v.d(),m.d(),w&&w.d(),j&&j.d(),t[20](null),G=!1,U(M)}}}const ge="https://altcha.org/";function be(t){return JSON.parse(t)}function tt(t,e,n){let l,i,r,{challengeurl:c=void 0}=e,{challengejson:a=void 0}=e,{debug:u=!1}=e,{hidefooter:f=!1}=e,{name:N="altcha"}=e,{maxnumber:g=void 0}=e,{mockerror:_=!1}=e,{strings:E=void 0}=e,{test:k=!1}=e;const W=Ie(),X=["SHA-256","SHA-384","SHA-512"];let A=!1,G,M=null,v=null,F=null,C=p.UNVERIFIED;Re(()=>{M&&(M.removeEventListener("submit",w),M.removeEventListener("reset",j),M=null)}),xe(()=>{m("mounted"),k&&m("using test mode"),M=G.closest("form"),M&&(M.addEventListener("submit",w),M.addEventListener("reset",j))});function m(...s){(u||s.some(b=>b instanceof Error))&&console[s[0]instanceof Error?"error":"log"]("ALTCHA",...s)}function w(){z()}function j(){z()}function h(s,b){return btoa(JSON.stringify({algorithm:s.algorithm,challenge:s.challenge,number:b.number,salt:s.salt,signature:s.signature,test:k?!0:void 0,took:b.took}))}function L(s){if(!s.algorithm||!X.includes(s.algorithm))throw new Error(`Unknown algorithm value. Allowed values: ${X.join(", ")}`);if(!s.challenge||s.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!s.salt||s.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.");if(s.signature===void 0)throw new Error("Signature is missing.")}async function nt(){if(_)throw m("mocking error"),new Error("Mocked error.");if(l)return m("using provided json data"),l;if(k)return m("generating test challenge"),Xe();{if(!c)throw new Error("Attribute challengeurl not set.");m("fetching challenge from",c);const s=await fetch(c);if(s.status!==200)throw new Error(`Server responded with ${s.status}.`);return s.json()}}async function rt(s){let b=null;if("Worker"in window){try{b=await lt(s.challenge,s.salt,s.algorithm)}catch(re){m(re)}if((b==null?void 0:b.number)!==void 0)return{data:s,solution:b}}return{data:s,solution:await De(s.challenge,s.salt,s.algorithm,g)}}async function lt(s,b,re){const _e=new Ze;return new Promise(at=>{_e.addEventListener("message",ut=>{at(ut.data)}),_e.postMessage({alg:re,challenge:s,max:g,salt:b})})}function it(){[p.UNVERIFIED,p.ERROR].includes(C)?(z(p.VERIFYING),nt().then(s=>(L(s),m("challenge",s),rt(s))).then(({data:s,solution:b})=>{if(m("solution",b),(b==null?void 0:b.number)!==void 0)m("verified"),n(3,C=p.VERIFIED),n(4,A=!0),n(2,F=h(s,b)),W("verified",{payload:F}),m("payload",F);else throw new Error("Unexpected result returned.")}).catch(s=>{m(s),n(3,C=p.ERROR),n(4,A=!1),n(6,v=s)})):n(4,A=!0)}function st(){C===p.VERIFYING&&alert(r.waitAlert)}function z(s=p.UNVERIFIED){n(4,A=!1),n(6,v=null),n(2,F=null),n(3,C=s)}function ot(){A=this.checked,n(4,A)}function ct(s){q[s?"unshift":"push"](()=>{G=s,n(5,G)})}return t.$$set=s=>{"challengeurl"in s&&n(10,c=s.challengeurl),"challengejson"in s&&n(11,a=s.challengejson),"debug"in s&&n(12,u=s.debug),"hidefooter"in s&&n(0,f=s.hidefooter),"name"in s&&n(1,N=s.name),"maxnumber"in s&&n(13,g=s.maxnumber),"mockerror"in s&&n(14,_=s.mockerror),"strings"in s&&n(15,E=s.strings),"test"in s&&n(16,k=s.test)},t.$$.update=()=>{t.$$.dirty[0]&2048&&(l=a?be(a):void 0),t.$$.dirty[0]&32768&&n(18,i=E?be(E):{}),t.$$.dirty[0]&262144&&n(7,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ge}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...i}),t.$$.dirty[0]&12&&W("statechange",{payload:F,state:C})},[f,N,F,C,A,G,v,r,it,st,c,a,u,g,_,E,k,z,i,ot,ct]}class $e extends Be{constructor(e){super(),Te(this,e,tt,et,ve,{challengeurl:10,challengejson:11,debug:12,hidefooter:0,name:1,maxnumber:13,mockerror:14,strings:15,test:16,reset:17},ze,[-1,-1])}get challengeurl(){return this.$$.ctx[10]}set challengeurl(e){this.$$set({challengeurl:e}),I()}get challengejson(){return this.$$.ctx[11]}set challengejson(e){this.$$set({challengejson:e}),I()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),I()}get hidefooter(){return this.$$.ctx[0]}set hidefooter(e){this.$$set({hidefooter:e}),I()}get name(){return this.$$.ctx[1]}set name(e){this.$$set({name:e}),I()}get maxnumber(){return this.$$.ctx[13]}set maxnumber(e){this.$$set({maxnumber:e}),I()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),I()}get strings(){return this.$$.ctx[15]}set strings(e){this.$$set({strings:e}),I()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),I()}get reset(){return this.$$.ctx[17]}}return customElements.define("altcha-widget",We($e,{challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset"],!1)),O.Altcha=$e,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"}),O}({});
|
package/dist/altcha.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var Ce = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
2
|
+
var Le = (t, e, n) => e in t ? Ce(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var L = (t, e, n) => (Le(t, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
4
|
function Z() {
|
|
5
5
|
}
|
|
6
6
|
function fe(t) {
|
|
@@ -15,7 +15,7 @@ function K(t) {
|
|
|
15
15
|
function he(t) {
|
|
16
16
|
return typeof t == "function";
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function xe(t, e) {
|
|
19
19
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
20
20
|
}
|
|
21
21
|
function Re(t) {
|
|
@@ -57,7 +57,7 @@ function A(t) {
|
|
|
57
57
|
function p(t) {
|
|
58
58
|
return document.createElement(t);
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function O(t) {
|
|
61
61
|
return document.createElementNS("http://www.w3.org/2000/svg", t);
|
|
62
62
|
}
|
|
63
63
|
function Me(t) {
|
|
@@ -214,11 +214,11 @@ function De(t, e, n, l, i, r, c = null, a = [-1]) {
|
|
|
214
214
|
root: e.target || u.$$.root
|
|
215
215
|
};
|
|
216
216
|
c && c(f.root);
|
|
217
|
-
let
|
|
217
|
+
let x = !1;
|
|
218
218
|
if (f.ctx = n ? n(t, e.props || {}, (g, $, ...k) => {
|
|
219
219
|
const y = k.length ? k[0] : $;
|
|
220
|
-
return f.ctx && i(f.ctx[g], f.ctx[g] = y) && (!f.skip_bound && f.bound[g] && f.bound[g](y),
|
|
221
|
-
}) : [], f.update(),
|
|
220
|
+
return f.ctx && i(f.ctx[g], f.ctx[g] = y) && (!f.skip_bound && f.bound[g] && f.bound[g](y), x && Xe(t, g)), $;
|
|
221
|
+
}) : [], f.update(), x = !0, K(f.before_update), f.fragment = l ? l(f.ctx) : !1, e.target) {
|
|
222
222
|
if (e.hydrate) {
|
|
223
223
|
const g = Ve(e.target);
|
|
224
224
|
f.fragment && f.fragment.l(g), g.forEach(A);
|
|
@@ -233,23 +233,23 @@ typeof HTMLElement == "function" && (de = class extends HTMLElement {
|
|
|
233
233
|
constructor(e, n, l) {
|
|
234
234
|
super();
|
|
235
235
|
/** The Svelte component constructor */
|
|
236
|
-
|
|
236
|
+
L(this, "$$ctor");
|
|
237
237
|
/** Slots */
|
|
238
|
-
|
|
238
|
+
L(this, "$$s");
|
|
239
239
|
/** The Svelte component instance */
|
|
240
|
-
|
|
240
|
+
L(this, "$$c");
|
|
241
241
|
/** Whether or not the custom element is connected */
|
|
242
|
-
|
|
242
|
+
L(this, "$$cn", !1);
|
|
243
243
|
/** Component props data */
|
|
244
|
-
|
|
244
|
+
L(this, "$$d", {});
|
|
245
245
|
/** `true` if currently in the process of reflecting component props back to attributes */
|
|
246
|
-
|
|
246
|
+
L(this, "$$r", !1);
|
|
247
247
|
/** @type {Record<string, CustomElementPropDefinition>} Props definition (name, reflected, type etc) */
|
|
248
|
-
|
|
248
|
+
L(this, "$$p_d", {});
|
|
249
249
|
/** @type {Record<string, Function[]>} Event listeners */
|
|
250
|
-
|
|
250
|
+
L(this, "$$l", {});
|
|
251
251
|
/** @type {Map<Function, Function>} Event listener unsubscribe functions */
|
|
252
|
-
|
|
252
|
+
L(this, "$$l_u", /* @__PURE__ */ new Map());
|
|
253
253
|
this.$$ctor = e, this.$$s = n, l && this.attachShadow({ mode: "open" });
|
|
254
254
|
}
|
|
255
255
|
addEventListener(e, n, l) {
|
|
@@ -278,8 +278,8 @@ typeof HTMLElement == "function" && (de = class extends HTMLElement {
|
|
|
278
278
|
* @param {HTMLElement} target
|
|
279
279
|
* @param {HTMLElement} [anchor]
|
|
280
280
|
*/
|
|
281
|
-
m: function(f,
|
|
282
|
-
M(f, c,
|
|
281
|
+
m: function(f, x) {
|
|
282
|
+
M(f, c, x);
|
|
283
283
|
},
|
|
284
284
|
d: function(f) {
|
|
285
285
|
f && A(c);
|
|
@@ -416,7 +416,7 @@ class Je {
|
|
|
416
416
|
*
|
|
417
417
|
* @type {any}
|
|
418
418
|
*/
|
|
419
|
-
|
|
419
|
+
L(this, "$$");
|
|
420
420
|
/**
|
|
421
421
|
* ### PRIVATE API
|
|
422
422
|
*
|
|
@@ -424,7 +424,7 @@ class Je {
|
|
|
424
424
|
*
|
|
425
425
|
* @type {any}
|
|
426
426
|
*/
|
|
427
|
-
|
|
427
|
+
L(this, "$$set");
|
|
428
428
|
}
|
|
429
429
|
/** @returns {void} */
|
|
430
430
|
$destroy() {
|
|
@@ -473,10 +473,10 @@ function nt(t) {
|
|
|
473
473
|
return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
474
474
|
}
|
|
475
475
|
async function rt(t = 1e5, e = "SHA-256") {
|
|
476
|
-
const n = Date.now().toString(16), l =
|
|
476
|
+
const n = Date.now().toString(16), l = Math.round(Math.random() * t), i = await ge(n, l, e);
|
|
477
477
|
return {
|
|
478
478
|
algorithm: e,
|
|
479
|
-
challenge:
|
|
479
|
+
challenge: i,
|
|
480
480
|
salt: n,
|
|
481
481
|
signature: ""
|
|
482
482
|
};
|
|
@@ -502,7 +502,7 @@ function oe(t) {
|
|
|
502
502
|
let e, n, l;
|
|
503
503
|
return {
|
|
504
504
|
c() {
|
|
505
|
-
e =
|
|
505
|
+
e = O("svg"), n = O("path"), l = O("path"), o(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"), o(n, "fill", "currentColor"), o(n, "opacity", ".25"), o(l, "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"), o(l, "fill", "currentColor"), o(l, "class", "altcha-spinner svelte-mjm2j6"), o(e, "width", "24"), o(e, "height", "24"), o(e, "viewBox", "0 0 24 24"), o(e, "xmlns", "http://www.w3.org/2000/svg");
|
|
506
506
|
},
|
|
507
507
|
m(i, r) {
|
|
508
508
|
M(i, e, r), m(e, n), m(e, l);
|
|
@@ -572,7 +572,7 @@ function ct(t) {
|
|
|
572
572
|
/*name*/
|
|
573
573
|
t[1]
|
|
574
574
|
), i.value = /*payload*/
|
|
575
|
-
t[
|
|
575
|
+
t[2];
|
|
576
576
|
},
|
|
577
577
|
m(r, c) {
|
|
578
578
|
M(r, e, c), e.innerHTML = n, M(r, l, c), M(r, i, c);
|
|
@@ -587,8 +587,8 @@ function ct(t) {
|
|
|
587
587
|
/*name*/
|
|
588
588
|
r[1]
|
|
589
589
|
), c[0] & /*payload*/
|
|
590
|
-
|
|
591
|
-
r[
|
|
590
|
+
4 && (i.value = /*payload*/
|
|
591
|
+
r[2]);
|
|
592
592
|
},
|
|
593
593
|
d(r) {
|
|
594
594
|
r && (A(e), A(l), A(i));
|
|
@@ -602,11 +602,11 @@ function ce(t) {
|
|
|
602
602
|
);
|
|
603
603
|
return {
|
|
604
604
|
c() {
|
|
605
|
-
e = p("div"), n =
|
|
605
|
+
e = p("div"), n = O("svg"), l = O("path"), i = S(), r = p("div"), o(l, "stroke-linecap", "round"), o(l, "stroke-linejoin", "round"), o(l, "d", "M6 18L18 6M6 6l12 12"), o(n, "width", "14"), o(n, "height", "14"), o(n, "xmlns", "http://www.w3.org/2000/svg"), o(n, "fill", "none"), o(n, "viewBox", "0 0 24 24"), o(n, "stroke-width", "1.5"), o(n, "stroke", "currentColor"), o(
|
|
606
606
|
r,
|
|
607
607
|
"title",
|
|
608
608
|
/*error*/
|
|
609
|
-
t[
|
|
609
|
+
t[6]
|
|
610
610
|
), o(e, "class", "altcha-error svelte-mjm2j6");
|
|
611
611
|
},
|
|
612
612
|
m(a, u) {
|
|
@@ -616,11 +616,11 @@ function ce(t) {
|
|
|
616
616
|
u[0] & /*_strings*/
|
|
617
617
|
128 && c !== (c = /*_strings*/
|
|
618
618
|
a[7].error + "") && (r.innerHTML = c), u[0] & /*error*/
|
|
619
|
-
|
|
619
|
+
64 && o(
|
|
620
620
|
r,
|
|
621
621
|
"title",
|
|
622
622
|
/*error*/
|
|
623
|
-
a[
|
|
623
|
+
a[6]
|
|
624
624
|
);
|
|
625
625
|
},
|
|
626
626
|
d(a) {
|
|
@@ -651,22 +651,22 @@ function ae(t) {
|
|
|
651
651
|
};
|
|
652
652
|
}
|
|
653
653
|
function at(t) {
|
|
654
|
-
let e, n, l, i, r, c, a, u, f,
|
|
654
|
+
let e, n, l, i, r, c, a, u, f, x, g, $, k, y, H, B, R, F, I, _ = (
|
|
655
655
|
/*state*/
|
|
656
|
-
t[
|
|
656
|
+
t[3] === j.VERIFYING && oe()
|
|
657
657
|
);
|
|
658
|
-
function
|
|
658
|
+
function V(h, C) {
|
|
659
659
|
return (
|
|
660
660
|
/*state*/
|
|
661
|
-
h[
|
|
661
|
+
h[3] === j.VERIFIED ? ct : (
|
|
662
662
|
/*state*/
|
|
663
|
-
h[
|
|
663
|
+
h[3] === j.VERIFYING ? ot : st
|
|
664
664
|
)
|
|
665
665
|
);
|
|
666
666
|
}
|
|
667
|
-
let E =
|
|
667
|
+
let E = V(t), d = E(t), v = (
|
|
668
668
|
/*error*/
|
|
669
|
-
t[
|
|
669
|
+
t[6] && ce(t)
|
|
670
670
|
), w = (
|
|
671
671
|
/*_strings*/
|
|
672
672
|
t[7].footer && /*hidefooter*/
|
|
@@ -674,22 +674,22 @@ function at(t) {
|
|
|
674
674
|
);
|
|
675
675
|
return {
|
|
676
676
|
c() {
|
|
677
|
-
e = p("div"), n = p("div"), _ && _.c(), l = S(), i = p("div"), r = p("input"), a = S(), u = p("div"), d.c(), f = S(),
|
|
677
|
+
e = p("div"), n = p("div"), _ && _.c(), l = S(), i = p("div"), r = p("input"), a = S(), u = p("div"), d.c(), f = S(), x = p("div"), g = p("a"), $ = O("svg"), k = O("path"), y = O("path"), H = O("path"), B = S(), v && v.c(), R = S(), w && w.c(), o(r, "type", "checkbox"), o(r, "id", c = /*name*/
|
|
678
678
|
t[1] + "_checkbox"), r.required = !0, o(r, "class", "svelte-mjm2j6"), o(i, "class", "altcha-checkbox svelte-mjm2j6"), le(
|
|
679
679
|
i,
|
|
680
680
|
"altcha-hidden",
|
|
681
681
|
/*state*/
|
|
682
|
-
t[
|
|
682
|
+
t[3] === j.VERIFYING
|
|
683
683
|
), o(u, "class", "altcha-label svelte-mjm2j6"), o(k, "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"), o(k, "fill", "currentColor"), o(y, "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"), o(y, "fill", "currentColor"), o(H, "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"), o(H, "fill", "currentColor"), o($, "width", "22"), o($, "height", "22"), o($, "viewBox", "0 0 20 20"), o($, "fill", "none"), o($, "xmlns", "http://www.w3.org/2000/svg"), o(g, "href", be), o(g, "target", "_blank"), o(g, "class", "altcha-logo svelte-mjm2j6"), o(n, "class", "altcha-main svelte-mjm2j6"), o(e, "class", "altcha svelte-mjm2j6"), o(
|
|
684
684
|
e,
|
|
685
685
|
"data-state",
|
|
686
686
|
/*state*/
|
|
687
|
-
t[
|
|
687
|
+
t[3]
|
|
688
688
|
);
|
|
689
689
|
},
|
|
690
690
|
m(h, C) {
|
|
691
691
|
M(h, e, C), m(e, n), _ && _.m(n, null), m(n, l), m(n, i), m(i, r), r.checked = /*checked*/
|
|
692
|
-
t[
|
|
692
|
+
t[4], m(n, a), m(n, u), d.m(u, null), m(n, f), m(n, x), m(x, g), m(g, $), m($, k), m($, y), m($, H), m(e, B), v && v.m(e, null), m(e, R), w && w.m(e, null), t[20](e), F || (I = [
|
|
693
693
|
z(
|
|
694
694
|
r,
|
|
695
695
|
"change",
|
|
@@ -708,35 +708,35 @@ function at(t) {
|
|
|
708
708
|
/*onInvalid*/
|
|
709
709
|
t[9]
|
|
710
710
|
)
|
|
711
|
-
],
|
|
711
|
+
], F = !0);
|
|
712
712
|
},
|
|
713
713
|
p(h, C) {
|
|
714
714
|
/*state*/
|
|
715
|
-
h[
|
|
715
|
+
h[3] === j.VERIFYING ? _ || (_ = oe(), _.c(), _.m(n, l)) : _ && (_.d(1), _ = null), C[0] & /*name*/
|
|
716
716
|
2 && c !== (c = /*name*/
|
|
717
717
|
h[1] + "_checkbox") && o(r, "id", c), C[0] & /*checked*/
|
|
718
|
-
|
|
719
|
-
h[
|
|
720
|
-
|
|
718
|
+
16 && (r.checked = /*checked*/
|
|
719
|
+
h[4]), C[0] & /*state*/
|
|
720
|
+
8 && le(
|
|
721
721
|
i,
|
|
722
722
|
"altcha-hidden",
|
|
723
723
|
/*state*/
|
|
724
|
-
h[
|
|
725
|
-
), E === (E =
|
|
726
|
-
h[
|
|
724
|
+
h[3] === j.VERIFYING
|
|
725
|
+
), E === (E = V(h)) && d ? d.p(h, C) : (d.d(1), d = E(h), d && (d.c(), d.m(u, null))), /*error*/
|
|
726
|
+
h[6] ? v ? v.p(h, C) : (v = ce(h), v.c(), v.m(e, R)) : v && (v.d(1), v = null), /*_strings*/
|
|
727
727
|
h[7].footer && /*hidefooter*/
|
|
728
728
|
h[0] !== !0 ? w ? w.p(h, C) : (w = ae(h), w.c(), w.m(e, null)) : w && (w.d(1), w = null), C[0] & /*state*/
|
|
729
|
-
|
|
729
|
+
8 && o(
|
|
730
730
|
e,
|
|
731
731
|
"data-state",
|
|
732
732
|
/*state*/
|
|
733
|
-
h[
|
|
733
|
+
h[3]
|
|
734
734
|
);
|
|
735
735
|
},
|
|
736
736
|
i: Z,
|
|
737
737
|
o: Z,
|
|
738
738
|
d(h) {
|
|
739
|
-
h && A(e), _ && _.d(), d.d(), v && v.d(), w && w.d(), t[20](null),
|
|
739
|
+
h && A(e), _ && _.d(), d.d(), v && v.d(), w && w.d(), t[20](null), F = !1, K(I);
|
|
740
740
|
}
|
|
741
741
|
};
|
|
742
742
|
}
|
|
@@ -745,13 +745,13 @@ function ue(t) {
|
|
|
745
745
|
return JSON.parse(t);
|
|
746
746
|
}
|
|
747
747
|
function ut(t, e, n) {
|
|
748
|
-
let l, i, r, { challengeurl: c = void 0 } = e, { challengejson: a = void 0 } = e, { debug: u = !1 } = e, { hidefooter: f = !1 } = e, { name:
|
|
748
|
+
let l, i, r, { challengeurl: c = void 0 } = e, { challengejson: a = void 0 } = e, { debug: u = !1 } = e, { hidefooter: f = !1 } = e, { name: x = "altcha" } = e, { maxnumber: g = void 0 } = e, { mockerror: $ = !1 } = e, { strings: k = void 0 } = e, { test: y = !1 } = e;
|
|
749
749
|
const H = Ge(), B = ["SHA-256", "SHA-384", "SHA-512"];
|
|
750
|
-
let R = !1,
|
|
750
|
+
let R = !1, F, I = null, _ = null, V = null, E = j.UNVERIFIED;
|
|
751
751
|
Se(() => {
|
|
752
752
|
I && (I.removeEventListener("submit", v), I.removeEventListener("reset", w), I = null);
|
|
753
753
|
}), He(() => {
|
|
754
|
-
d("mounted"), y && d("using test mode"), I =
|
|
754
|
+
d("mounted"), y && d("using test mode"), I = F.closest("form"), I && (I.addEventListener("submit", v), I.addEventListener("reset", w));
|
|
755
755
|
});
|
|
756
756
|
function d(...s) {
|
|
757
757
|
(u || s.some((b) => b instanceof Error)) && console[s[0] instanceof Error ? "error" : "log"]("ALTCHA", ...s);
|
|
@@ -827,29 +827,29 @@ function ut(t, e, n) {
|
|
|
827
827
|
function we() {
|
|
828
828
|
[j.UNVERIFIED, j.ERROR].includes(E) ? (P(j.VERIFYING), $e().then((s) => (C(s), d("challenge", s), _e(s))).then(({ data: s, solution: b }) => {
|
|
829
829
|
if (d("solution", b), (b == null ? void 0 : b.number) !== void 0)
|
|
830
|
-
d("verified"), n(
|
|
830
|
+
d("verified"), n(3, E = j.VERIFIED), n(4, R = !0), n(2, V = h(s, b)), H("verified", { payload: V }), d("payload", V);
|
|
831
831
|
else
|
|
832
832
|
throw new Error("Unexpected result returned.");
|
|
833
833
|
}).catch((s) => {
|
|
834
|
-
d(s), n(
|
|
835
|
-
})) : n(
|
|
834
|
+
d(s), n(3, E = j.ERROR), n(4, R = !1), n(6, _ = s);
|
|
835
|
+
})) : n(4, R = !0);
|
|
836
836
|
}
|
|
837
837
|
function pe() {
|
|
838
838
|
E === j.VERIFYING && alert(r.waitAlert);
|
|
839
839
|
}
|
|
840
840
|
function P(s = j.UNVERIFIED) {
|
|
841
|
-
n(
|
|
841
|
+
n(4, R = !1), n(6, _ = null), n(2, V = null), n(3, E = s);
|
|
842
842
|
}
|
|
843
843
|
function je() {
|
|
844
|
-
R = this.checked, n(
|
|
844
|
+
R = this.checked, n(4, R);
|
|
845
845
|
}
|
|
846
846
|
function ye(s) {
|
|
847
847
|
Q[s ? "unshift" : "push"](() => {
|
|
848
|
-
|
|
848
|
+
F = s, n(5, F);
|
|
849
849
|
});
|
|
850
850
|
}
|
|
851
851
|
return t.$$set = (s) => {
|
|
852
|
-
"challengeurl" in s && n(10, c = s.challengeurl), "challengejson" in s && n(11, a = s.challengejson), "debug" in s && n(12, u = s.debug), "hidefooter" in s && n(0, f = s.hidefooter), "name" in s && n(1,
|
|
852
|
+
"challengeurl" in s && n(10, c = s.challengeurl), "challengejson" in s && n(11, a = s.challengejson), "debug" in s && n(12, u = s.debug), "hidefooter" in s && n(0, f = s.hidefooter), "name" in s && n(1, x = s.name), "maxnumber" in s && n(13, g = s.maxnumber), "mockerror" in s && n(14, $ = s.mockerror), "strings" in s && n(15, k = s.strings), "test" in s && n(16, y = s.test);
|
|
853
853
|
}, t.$$.update = () => {
|
|
854
854
|
t.$$.dirty[0] & /*challengejson*/
|
|
855
855
|
2048 && (l = a ? ue(a) : void 0), t.$$.dirty[0] & /*strings*/
|
|
@@ -862,16 +862,16 @@ function ut(t, e, n) {
|
|
|
862
862
|
verifying: "Verifying...",
|
|
863
863
|
waitAlert: "Verifying... please wait.",
|
|
864
864
|
...i
|
|
865
|
-
}), t.$$.dirty[0] & /*state*/
|
|
866
|
-
|
|
865
|
+
}), t.$$.dirty[0] & /*payload, state*/
|
|
866
|
+
12 && H("statechange", { payload: V, state: E });
|
|
867
867
|
}, [
|
|
868
868
|
f,
|
|
869
|
-
|
|
869
|
+
x,
|
|
870
|
+
V,
|
|
870
871
|
E,
|
|
871
872
|
R,
|
|
872
|
-
O,
|
|
873
|
-
_,
|
|
874
873
|
F,
|
|
874
|
+
_,
|
|
875
875
|
r,
|
|
876
876
|
we,
|
|
877
877
|
pe,
|
|
@@ -895,7 +895,7 @@ class ft extends Je {
|
|
|
895
895
|
e,
|
|
896
896
|
ut,
|
|
897
897
|
at,
|
|
898
|
-
|
|
898
|
+
xe,
|
|
899
899
|
{
|
|
900
900
|
challengeurl: 10,
|
|
901
901
|
challengejson: 11,
|
|
@@ -970,7 +970,7 @@ class ft extends Je {
|
|
|
970
970
|
return this.$$.ctx[17];
|
|
971
971
|
}
|
|
972
972
|
}
|
|
973
|
-
customElements.define("altcha-
|
|
973
|
+
customElements.define("altcha-widget", ze(ft, { challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, hidefooter: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" } }, [], ["reset"], !1));
|
|
974
974
|
export {
|
|
975
975
|
ft as Altcha
|
|
976
976
|
};
|
package/dist/altcha.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(E,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(E=typeof globalThis<"u"?globalThis:E||self,$(E["<<name>>"]={}))})(this,function(E){"use strict";var ft=Object.defineProperty;var ht=(E,$,F)=>$ in E?ft(E,$,{enumerable:!0,configurable:!0,writable:!0,value:F}):E[$]=F;var R=(E,$,F)=>(ht(E,typeof $!="symbol"?$+"":$,F),F);function $(){}function F(t){return t()}function le(){return Object.create(null)}function U(t){t.forEach(F)}function ie(t){return typeof t=="function"}function ve(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function pe(t){return Object.keys(t).length===0}function d(t,e){t.appendChild(e)}function we(t,e,n){const l=je(t);if(!l.getElementById(e)){const i=_("style");i.id=e,i.textContent=n,ye(l,i)}}function je(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function ye(t,e){return d(t.head||t,e),e.sheet}function O(t,e,n){t.insertBefore(e,n||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function S(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function ke(t){return document.createTextNode(t)}function G(){return ke(" ")}function J(t,e,n,l){return t.addEventListener(e,n,l),()=>t.removeEventListener(e,n,l)}function o(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ee(t){return Array.from(t.childNodes)}function se(t,e,n){t.classList.toggle(e,!!n)}function Ce(t,e,{bubbles:n=!1,cancelable:l=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:l})}function xe(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let K;function P(t){K=t}function Q(){if(!K)throw new Error("Function called outside component initialization");return K}function Le(t){Q().$$.on_mount.push(t)}function Re(t){Q().$$.on_destroy.push(t)}function Ie(){const t=Q();return(e,n,{cancelable:l=!1}={})=>{const i=t.$$.callbacks[e];if(i){const r=Ce(e,n,{cancelable:l});return i.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const B=[],q=[];let Y=[];const oe=[],Ne=Promise.resolve();let ee=!1;function Ae(){ee||(ee=!0,Ne.then(N))}function te(t){Y.push(t)}const ne=new Set;let Z=0;function N(){if(Z!==0)return;const t=K;do{try{for(;Z<B.length;){const e=B[Z];Z++,P(e),Me(e.$$)}}catch(e){throw B.length=0,Z=0,e}for(P(null),B.length=0,Z=0;q.length;)q.pop()();for(let e=0;e<Y.length;e+=1){const n=Y[e];ne.has(n)||(ne.add(n),n())}Y.length=0}while(B.length);for(;oe.length;)oe.pop()();ee=!1,ne.clear(),P(t)}function Me(t){if(t.fragment!==null){t.update(),U(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(te)}}function Ve(t){const e=[],n=[];Y.forEach(l=>t.indexOf(l)===-1?e.push(l):n.push(l)),n.forEach(l=>l()),Y=e}const Oe=new Set;function Se(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Fe(t,e,n){const{fragment:l,after_update:i}=t.$$;l&&l.m(e,n),te(()=>{const r=t.$$.on_mount.map(F).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):U(r),t.$$.on_mount=[]}),i.forEach(te)}function He(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),U(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Te(t,e){t.$$.dirty[0]===-1&&(B.push(t),Ae(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Ge(t,e,n,l,i,r,c=null,a=[-1]){const u=K;P(t);const f=t.$$={fragment:null,ctx:[],props:r,update:$,not_equal:i,bound:le(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(u?u.$$.context:[])),callbacks:le(),dirty:a,skip_bound:!1,root:e.target||u.$$.root};c&&c(f.root);let A=!1;if(f.ctx=n?n(t,e.props||{},(g,v,...C)=>{const k=C.length?C[0]:v;return f.ctx&&i(f.ctx[g],f.ctx[g]=k)&&(!f.skip_bound&&f.bound[g]&&f.bound[g](k),A&&Te(t,g)),v}):[],f.update(),A=!0,U(f.before_update),f.fragment=l?l(f.ctx):!1,e.target){if(e.hydrate){const g=Ee(e.target);f.fragment&&f.fragment.l(g),g.forEach(I)}else f.fragment&&f.fragment.c();e.intro&&Se(t.$$.fragment),Fe(t,e.target,e.anchor),N()}P(u)}let ce;typeof HTMLElement=="function"&&(ce=class extends HTMLElement{constructor(e,n,l){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,l&&this.attachShadow({mode:"open"})}addEventListener(e,n,l){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const i=this.$$c.$on(e,n);this.$$l_u.set(n,i)}super.addEventListener(e,n,l)}removeEventListener(e,n,l){if(super.removeEventListener(e,n,l),this.$$c){const i=this.$$l_u.get(n);i&&(i(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=_("slot"),r!=="default"&&o(c,"name",r)},m:function(f,A){O(f,c,A)},d:function(f){f&&I(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},l=xe(this);for(const r of this.$$s)r in l&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=D(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const i=()=>{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=D(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(i),i();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,l){var i;this.$$r||(e=this.$$g_p(e),this.$$d[e]=D(e,l,this.$$p_d,"toProp"),(i=this.$$c)==null||i.$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 D(t,e,n,l){var r;const i=(r=n[t])==null?void 0:r.type;if(e=i==="Boolean"&&typeof e!="boolean"?e!=null:e,!l||!n[t])return e;if(l==="toAttribute")switch(i){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(i){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function We(t,e,n,l,i,r){let c=class extends ce{constructor(){super(t,n,i),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=D(a,u,e),this.$$d[a]=u,(f=this.$$c)==null||f.$set({[a]:u})}})}),l.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(){He(this,1),this.$destroy=$}$on(e,n){if(!ie(n))return $;const l=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return l.push(n),()=>{const i=l.indexOf(n);i!==-1&&l.splice(i,1)}}$set(e){this.$$set&&!pe(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Ye="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ye);const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLHIuZW5jb2RlKGUrbikpKX1hc3luYyBmdW5jdGlvbiBpKGUsbixhPSJTSEEtMjU2IixvPTFlNyl7Y29uc3Qgcz1EYXRlLm5vdygpO2ZvcihsZXQgdD0wO3Q8PW87dCsrKWlmKGF3YWl0IGwobix0LGEpPT09ZSlyZXR1cm57bnVtYmVyOnQsdG9vazpEYXRlLm5vdygpLXN9O3JldHVybiBudWxsfW9ubWVzc2FnZT1hc3luYyBlPT57Y29uc3R7YWxnOm4sY2hhbGxlbmdlOmEsbWF4Om8sc2FsdDpzfT1lLmRhdGF8fHt9O2lmKGEmJnMpe2NvbnN0IHQ9YXdhaXQgaShhLHMsbixvKTtzZWxmLnBvc3RNZXNzYWdlKHQmJnsuLi50LHdvcmtlcjohMH0pfWVsc2Ugc2VsZi5wb3N0TWVzc2FnZShudWxsKX19KSgpOwo=",ue=typeof window<"u"&&window.Blob&&new Blob([atob(ae)],{type:"text/javascript;charset=utf-8"});function Ze(){let t;try{if(t=ue&&(window.URL||window.webkitURL).createObjectURL(ue),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+ae)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Ue=1e7,Ke=new TextEncoder;function Pe(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Xe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),l=await fe(n,Math.round(Math.random()*t),e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function fe(t,e,n){return Pe(await crypto.subtle.digest(n,Ke.encode(t+e)))}async function De(t,e,n="SHA-256",l=Ue){const i=Date.now();for(let r=0;r<=l;r++)if(await fe(e,r,n)===t)return{number:r,took:Date.now()-i};return null}var y=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverfied",t))(y||{});function ze(t){we(t,"svelte-mjm2j6",".altcha.svelte-mjm2j6.svelte-mjm2j6{background:var(--altcha-color-base, #ffffff);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}.altcha.svelte-mjm2j6.svelte-mjm2j6:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-mjm2j6.svelte-mjm2j6{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-mjm2j6.svelte-mjm2j6{flex-grow:1}.altcha-label.svelte-mjm2j6 label.svelte-mjm2j6{cursor:pointer}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6{color:currentColor;opacity:0.3}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6:hover{opacity:1}.altcha-error.svelte-mjm2j6.svelte-mjm2j6{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-mjm2j6.svelte-mjm2j6{align-items:center;background-color:var(--altcha-color-footer-bg, #f4f4f4);display:flex;font-size:0.75rem;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-mjm2j6>.svelte-mjm2j6:first-child{flex-grow:1}.altcha-footer.svelte-mjm2j6 a{color:currentColor}.altcha-checkbox.svelte-mjm2j6.svelte-mjm2j6{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-mjm2j6 input.svelte-mjm2j6{width:18px;height:18px;margin:0}.altcha-hidden.svelte-mjm2j6.svelte-mjm2j6{display:none}.altcha-spinner.svelte-mjm2j6.svelte-mjm2j6{animation:svelte-mjm2j6-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-mjm2j6-altcha-spinner{100%{transform:rotate(360deg)}}")}function he(t){let e,n,l;return{c(){e=S("svg"),n=S("path"),l=S("path"),o(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"),o(n,"fill","currentColor"),o(n,"opacity",".25"),o(l,"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"),o(l,"fill","currentColor"),o(l,"class","altcha-spinner svelte-mjm2j6"),o(e,"width","24"),o(e,"height","24"),o(e,"viewBox","0 0 24 24"),o(e,"xmlns","http://www.w3.org/2000/svg")},m(i,r){O(i,e,r),d(e,n),d(e,l)},d(i){i&&I(e)}}}function Je(t){let e,n=t[7].label+"",l;return{c(){e=_("label"),o(e,"for",l=t[1]+"_checkbox"),o(e,"class","svelte-mjm2j6")},m(i,r){O(i,e,r),e.innerHTML=n},p(i,r){r[0]&128&&n!==(n=i[7].label+"")&&(e.innerHTML=n),r[0]&2&&l!==(l=i[1]+"_checkbox")&&o(e,"for",l)},d(i){i&&I(e)}}}function Qe(t){let e,n=t[7].verifying+"";return{c(){e=_("span")},m(l,i){O(l,e,i),e.innerHTML=n},p(l,i){i[0]&128&&n!==(n=l[7].verifying+"")&&(e.innerHTML=n)},d(l){l&&I(e)}}}function qe(t){let e,n=t[7].verified+"",l,i;return{c(){e=_("span"),l=G(),i=_("input"),o(i,"type","hidden"),o(i,"name",t[1]),i.value=t[6]},m(r,c){O(r,e,c),e.innerHTML=n,O(r,l,c),O(r,i,c)},p(r,c){c[0]&128&&n!==(n=r[7].verified+"")&&(e.innerHTML=n),c[0]&2&&o(i,"name",r[1]),c[0]&64&&(i.value=r[6])},d(r){r&&(I(e),I(l),I(i))}}}function de(t){let e,n,l,i,r,c=t[7].error+"";return{c(){e=_("div"),n=S("svg"),l=S("path"),i=G(),r=_("div"),o(l,"stroke-linecap","round"),o(l,"stroke-linejoin","round"),o(l,"d","M6 18L18 6M6 6l12 12"),o(n,"width","14"),o(n,"height","14"),o(n,"xmlns","http://www.w3.org/2000/svg"),o(n,"fill","none"),o(n,"viewBox","0 0 24 24"),o(n,"stroke-width","1.5"),o(n,"stroke","currentColor"),o(r,"title",t[5]),o(e,"class","altcha-error svelte-mjm2j6")},m(a,u){O(a,e,u),d(e,n),d(n,l),d(e,i),d(e,r),r.innerHTML=c},p(a,u){u[0]&128&&c!==(c=a[7].error+"")&&(r.innerHTML=c),u[0]&32&&o(r,"title",a[5])},d(a){a&&I(e)}}}function me(t){let e,n,l=t[7].footer+"";return{c(){e=_("div"),n=_("div"),o(n,"class","svelte-mjm2j6"),o(e,"class","altcha-footer svelte-mjm2j6")},m(i,r){O(i,e,r),d(e,n),n.innerHTML=l},p(i,r){r[0]&128&&l!==(l=i[7].footer+"")&&(n.innerHTML=l)},d(i){i&&I(e)}}}function et(t){let e,n,l,i,r,c,a,u,f,A,g,v,C,k,W,X,M,H,V,p=t[2]===y.VERIFYING&&he();function T(h,L){return h[2]===y.VERIFIED?qe:h[2]===y.VERIFYING?Qe:Je}let x=T(t),m=x(t),w=t[5]&&de(t),j=t[7].footer&&t[0]!==!0&&me(t);return{c(){e=_("div"),n=_("div"),p&&p.c(),l=G(),i=_("div"),r=_("input"),a=G(),u=_("div"),m.c(),f=G(),A=_("div"),g=_("a"),v=S("svg"),C=S("path"),k=S("path"),W=S("path"),X=G(),w&&w.c(),M=G(),j&&j.c(),o(r,"type","checkbox"),o(r,"id",c=t[1]+"_checkbox"),r.required=!0,o(r,"class","svelte-mjm2j6"),o(i,"class","altcha-checkbox svelte-mjm2j6"),se(i,"altcha-hidden",t[2]===y.VERIFYING),o(u,"class","altcha-label svelte-mjm2j6"),o(C,"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"),o(C,"fill","currentColor"),o(k,"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"),o(k,"fill","currentColor"),o(W,"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"),o(W,"fill","currentColor"),o(v,"width","22"),o(v,"height","22"),o(v,"viewBox","0 0 20 20"),o(v,"fill","none"),o(v,"xmlns","http://www.w3.org/2000/svg"),o(g,"href",ge),o(g,"target","_blank"),o(g,"class","altcha-logo svelte-mjm2j6"),o(n,"class","altcha-main svelte-mjm2j6"),o(e,"class","altcha svelte-mjm2j6"),o(e,"data-state",t[2])},m(h,L){O(h,e,L),d(e,n),p&&p.m(n,null),d(n,l),d(n,i),d(i,r),r.checked=t[3],d(n,a),d(n,u),m.m(u,null),d(n,f),d(n,A),d(A,g),d(g,v),d(v,C),d(v,k),d(v,W),d(e,X),w&&w.m(e,null),d(e,M),j&&j.m(e,null),t[20](e),H||(V=[J(r,"change",t[19]),J(r,"change",t[8]),J(r,"invalid",t[9])],H=!0)},p(h,L){h[2]===y.VERIFYING?p||(p=he(),p.c(),p.m(n,l)):p&&(p.d(1),p=null),L[0]&2&&c!==(c=h[1]+"_checkbox")&&o(r,"id",c),L[0]&8&&(r.checked=h[3]),L[0]&4&&se(i,"altcha-hidden",h[2]===y.VERIFYING),x===(x=T(h))&&m?m.p(h,L):(m.d(1),m=x(h),m&&(m.c(),m.m(u,null))),h[5]?w?w.p(h,L):(w=de(h),w.c(),w.m(e,M)):w&&(w.d(1),w=null),h[7].footer&&h[0]!==!0?j?j.p(h,L):(j=me(h),j.c(),j.m(e,null)):j&&(j.d(1),j=null),L[0]&4&&o(e,"data-state",h[2])},i:$,o:$,d(h){h&&I(e),p&&p.d(),m.d(),w&&w.d(),j&&j.d(),t[20](null),H=!1,U(V)}}}const ge="https://altcha.org/";function be(t){return JSON.parse(t)}function tt(t,e,n){let l,i,r,{challengeurl:c=void 0}=e,{challengejson:a=void 0}=e,{debug:u=!1}=e,{hidefooter:f=!1}=e,{name:A="altcha"}=e,{maxnumber:g=void 0}=e,{mockerror:v=!1}=e,{strings:C=void 0}=e,{test:k=!1}=e;const W=Ie(),X=["SHA-256","SHA-384","SHA-512"];let M=!1,H,V=null,p=null,T=null,x=y.UNVERIFIED;Re(()=>{V&&(V.removeEventListener("submit",w),V.removeEventListener("reset",j),V=null)}),Le(()=>{m("mounted"),k&&m("using test mode"),V=H.closest("form"),V&&(V.addEventListener("submit",w),V.addEventListener("reset",j))});function m(...s){(u||s.some(b=>b instanceof Error))&&console[s[0]instanceof Error?"error":"log"]("ALTCHA",...s)}function w(){z()}function j(){z()}function h(s,b){return btoa(JSON.stringify({algorithm:s.algorithm,challenge:s.challenge,number:b.number,salt:s.salt,signature:s.signature,test:k?!0:void 0,took:b.took}))}function L(s){if(!s.algorithm||!X.includes(s.algorithm))throw new Error(`Unknown algorithm value. Allowed values: ${X.join(", ")}`);if(!s.challenge||s.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!s.salt||s.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.");if(s.signature===void 0)throw new Error("Signature is missing.")}async function nt(){if(v)throw m("mocking error"),new Error("Mocked error.");if(l)return m("using provided json data"),l;if(k)return m("generating test challenge"),Xe();{if(!c)throw new Error("Attribute challengeurl not set.");m("fetching challenge from",c);const s=await fetch(c);if(s.status!==200)throw new Error(`Server responded with ${s.status}.`);return s.json()}}async function rt(s){let b=null;if("Worker"in window){try{b=await lt(s.challenge,s.salt,s.algorithm)}catch(re){m(re)}if((b==null?void 0:b.number)!==void 0)return{data:s,solution:b}}return{data:s,solution:await De(s.challenge,s.salt,s.algorithm,g)}}async function lt(s,b,re){const _e=new Ze;return new Promise(at=>{_e.addEventListener("message",ut=>{at(ut.data)}),_e.postMessage({alg:re,challenge:s,max:g,salt:b})})}function it(){[y.UNVERIFIED,y.ERROR].includes(x)?(z(y.VERIFYING),nt().then(s=>(L(s),m("challenge",s),rt(s))).then(({data:s,solution:b})=>{if(m("solution",b),(b==null?void 0:b.number)!==void 0)m("verified"),n(2,x=y.VERIFIED),n(3,M=!0),n(6,T=h(s,b)),W("verified",{payload:T}),m("payload",T);else throw new Error("Unexpected result returned.")}).catch(s=>{m(s),n(2,x=y.ERROR),n(3,M=!1),n(5,p=s)})):n(3,M=!0)}function st(){x===y.VERIFYING&&alert(r.waitAlert)}function z(s=y.UNVERIFIED){n(3,M=!1),n(5,p=null),n(6,T=null),n(2,x=s)}function ot(){M=this.checked,n(3,M)}function ct(s){q[s?"unshift":"push"](()=>{H=s,n(4,H)})}return t.$$set=s=>{"challengeurl"in s&&n(10,c=s.challengeurl),"challengejson"in s&&n(11,a=s.challengejson),"debug"in s&&n(12,u=s.debug),"hidefooter"in s&&n(0,f=s.hidefooter),"name"in s&&n(1,A=s.name),"maxnumber"in s&&n(13,g=s.maxnumber),"mockerror"in s&&n(14,v=s.mockerror),"strings"in s&&n(15,C=s.strings),"test"in s&&n(16,k=s.test)},t.$$.update=()=>{t.$$.dirty[0]&2048&&(l=a?be(a):void 0),t.$$.dirty[0]&32768&&n(18,i=C?be(C):{}),t.$$.dirty[0]&262144&&n(7,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ge}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...i}),t.$$.dirty[0]&4&&W("statechange",{state:x})},[f,A,x,M,H,p,T,r,it,st,c,a,u,g,v,C,k,z,i,ot,ct]}class $e extends Be{constructor(e){super(),Ge(this,e,tt,et,ve,{challengeurl:10,challengejson:11,debug:12,hidefooter:0,name:1,maxnumber:13,mockerror:14,strings:15,test:16,reset:17},ze,[-1,-1])}get challengeurl(){return this.$$.ctx[10]}set challengeurl(e){this.$$set({challengeurl:e}),N()}get challengejson(){return this.$$.ctx[11]}set challengejson(e){this.$$set({challengejson:e}),N()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),N()}get hidefooter(){return this.$$.ctx[0]}set hidefooter(e){this.$$set({hidefooter:e}),N()}get name(){return this.$$.ctx[1]}set name(e){this.$$set({name:e}),N()}get maxnumber(){return this.$$.ctx[13]}set maxnumber(e){this.$$set({maxnumber:e}),N()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),N()}get strings(){return this.$$.ctx[15]}set strings(e){this.$$set({strings:e}),N()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),N()}get reset(){return this.$$.ctx[17]}}customElements.define("altcha-box",We($e,{challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset"],!1)),E.Altcha=$e,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(E,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(E=typeof globalThis<"u"?globalThis:E||self,$(E.altcha={}))})(this,function(E){"use strict";var ft=Object.defineProperty;var ht=(E,$,H)=>$ in E?ft(E,$,{enumerable:!0,configurable:!0,writable:!0,value:H}):E[$]=H;var R=(E,$,H)=>(ht(E,typeof $!="symbol"?$+"":$,H),H);function $(){}function H(t){return t()}function le(){return Object.create(null)}function U(t){t.forEach(H)}function ie(t){return typeof t=="function"}function ve(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function pe(t){return Object.keys(t).length===0}function d(t,e){t.appendChild(e)}function we(t,e,n){const l=je(t);if(!l.getElementById(e)){const i=_("style");i.id=e,i.textContent=n,ye(l,i)}}function je(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function ye(t,e){return d(t.head||t,e),e.sheet}function O(t,e,n){t.insertBefore(e,n||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function S(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function ke(t){return document.createTextNode(t)}function G(){return ke(" ")}function J(t,e,n,l){return t.addEventListener(e,n,l),()=>t.removeEventListener(e,n,l)}function o(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ee(t){return Array.from(t.childNodes)}function se(t,e,n){t.classList.toggle(e,!!n)}function Ce(t,e,{bubbles:n=!1,cancelable:l=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:l})}function xe(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let K;function P(t){K=t}function Q(){if(!K)throw new Error("Function called outside component initialization");return K}function Le(t){Q().$$.on_mount.push(t)}function Re(t){Q().$$.on_destroy.push(t)}function Ie(){const t=Q();return(e,n,{cancelable:l=!1}={})=>{const i=t.$$.callbacks[e];if(i){const r=Ce(e,n,{cancelable:l});return i.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const B=[],q=[];let Y=[];const oe=[],Ne=Promise.resolve();let ee=!1;function Ae(){ee||(ee=!0,Ne.then(N))}function te(t){Y.push(t)}const ne=new Set;let Z=0;function N(){if(Z!==0)return;const t=K;do{try{for(;Z<B.length;){const e=B[Z];Z++,P(e),Me(e.$$)}}catch(e){throw B.length=0,Z=0,e}for(P(null),B.length=0,Z=0;q.length;)q.pop()();for(let e=0;e<Y.length;e+=1){const n=Y[e];ne.has(n)||(ne.add(n),n())}Y.length=0}while(B.length);for(;oe.length;)oe.pop()();ee=!1,ne.clear(),P(t)}function Me(t){if(t.fragment!==null){t.update(),U(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(te)}}function Ve(t){const e=[],n=[];Y.forEach(l=>t.indexOf(l)===-1?e.push(l):n.push(l)),n.forEach(l=>l()),Y=e}const Oe=new Set;function Se(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Fe(t,e,n){const{fragment:l,after_update:i}=t.$$;l&&l.m(e,n),te(()=>{const r=t.$$.on_mount.map(H).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):U(r),t.$$.on_mount=[]}),i.forEach(te)}function He(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),U(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Te(t,e){t.$$.dirty[0]===-1&&(B.push(t),Ae(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Ge(t,e,n,l,i,r,c=null,a=[-1]){const u=K;P(t);const f=t.$$={fragment:null,ctx:[],props:r,update:$,not_equal:i,bound:le(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(u?u.$$.context:[])),callbacks:le(),dirty:a,skip_bound:!1,root:e.target||u.$$.root};c&&c(f.root);let A=!1;if(f.ctx=n?n(t,e.props||{},(g,v,...C)=>{const k=C.length?C[0]:v;return f.ctx&&i(f.ctx[g],f.ctx[g]=k)&&(!f.skip_bound&&f.bound[g]&&f.bound[g](k),A&&Te(t,g)),v}):[],f.update(),A=!0,U(f.before_update),f.fragment=l?l(f.ctx):!1,e.target){if(e.hydrate){const g=Ee(e.target);f.fragment&&f.fragment.l(g),g.forEach(I)}else f.fragment&&f.fragment.c();e.intro&&Se(t.$$.fragment),Fe(t,e.target,e.anchor),N()}P(u)}let ce;typeof HTMLElement=="function"&&(ce=class extends HTMLElement{constructor(e,n,l){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,l&&this.attachShadow({mode:"open"})}addEventListener(e,n,l){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const i=this.$$c.$on(e,n);this.$$l_u.set(n,i)}super.addEventListener(e,n,l)}removeEventListener(e,n,l){if(super.removeEventListener(e,n,l),this.$$c){const i=this.$$l_u.get(n);i&&(i(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=_("slot"),r!=="default"&&o(c,"name",r)},m:function(f,A){O(f,c,A)},d:function(f){f&&I(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},l=xe(this);for(const r of this.$$s)r in l&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=D(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const i=()=>{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=D(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(i),i();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,l){var i;this.$$r||(e=this.$$g_p(e),this.$$d[e]=D(e,l,this.$$p_d,"toProp"),(i=this.$$c)==null||i.$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 D(t,e,n,l){var r;const i=(r=n[t])==null?void 0:r.type;if(e=i==="Boolean"&&typeof e!="boolean"?e!=null:e,!l||!n[t])return e;if(l==="toAttribute")switch(i){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(i){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function We(t,e,n,l,i,r){let c=class extends ce{constructor(){super(t,n,i),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=D(a,u,e),this.$$d[a]=u,(f=this.$$c)==null||f.$set({[a]:u})}})}),l.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(){He(this,1),this.$destroy=$}$on(e,n){if(!ie(n))return $;const l=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return l.push(n),()=>{const i=l.indexOf(n);i!==-1&&l.splice(i,1)}}$set(e){this.$$set&&!pe(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Ye="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ye);const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLHIuZW5jb2RlKGUrbikpKX1hc3luYyBmdW5jdGlvbiBpKGUsbixhPSJTSEEtMjU2IixvPTFlNyl7Y29uc3Qgcz1EYXRlLm5vdygpO2ZvcihsZXQgdD0wO3Q8PW87dCsrKWlmKGF3YWl0IGwobix0LGEpPT09ZSlyZXR1cm57bnVtYmVyOnQsdG9vazpEYXRlLm5vdygpLXN9O3JldHVybiBudWxsfW9ubWVzc2FnZT1hc3luYyBlPT57Y29uc3R7YWxnOm4sY2hhbGxlbmdlOmEsbWF4Om8sc2FsdDpzfT1lLmRhdGF8fHt9O2lmKGEmJnMpe2NvbnN0IHQ9YXdhaXQgaShhLHMsbixvKTtzZWxmLnBvc3RNZXNzYWdlKHQmJnsuLi50LHdvcmtlcjohMH0pfWVsc2Ugc2VsZi5wb3N0TWVzc2FnZShudWxsKX19KSgpOwo=",ue=typeof window<"u"&&window.Blob&&new Blob([atob(ae)],{type:"text/javascript;charset=utf-8"});function Ze(){let t;try{if(t=ue&&(window.URL||window.webkitURL).createObjectURL(ue),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+ae)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Ue=1e7,Ke=new TextEncoder;function Pe(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Xe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),l=Math.round(Math.random()*t),i=await fe(n,l,e);return{algorithm:e,challenge:i,salt:n,signature:""}}async function fe(t,e,n){return Pe(await crypto.subtle.digest(n,Ke.encode(t+e)))}async function De(t,e,n="SHA-256",l=Ue){const i=Date.now();for(let r=0;r<=l;r++)if(await fe(e,r,n)===t)return{number:r,took:Date.now()-i};return null}var y=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverfied",t))(y||{});function ze(t){we(t,"svelte-mjm2j6",".altcha.svelte-mjm2j6.svelte-mjm2j6{background:var(--altcha-color-base, #ffffff);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}.altcha.svelte-mjm2j6.svelte-mjm2j6:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-mjm2j6.svelte-mjm2j6{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-mjm2j6.svelte-mjm2j6{flex-grow:1}.altcha-label.svelte-mjm2j6 label.svelte-mjm2j6{cursor:pointer}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6{color:currentColor;opacity:0.3}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6:hover{opacity:1}.altcha-error.svelte-mjm2j6.svelte-mjm2j6{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-mjm2j6.svelte-mjm2j6{align-items:center;background-color:var(--altcha-color-footer-bg, #f4f4f4);display:flex;font-size:0.75rem;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-mjm2j6>.svelte-mjm2j6:first-child{flex-grow:1}.altcha-footer.svelte-mjm2j6 a{color:currentColor}.altcha-checkbox.svelte-mjm2j6.svelte-mjm2j6{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-mjm2j6 input.svelte-mjm2j6{width:18px;height:18px;margin:0}.altcha-hidden.svelte-mjm2j6.svelte-mjm2j6{display:none}.altcha-spinner.svelte-mjm2j6.svelte-mjm2j6{animation:svelte-mjm2j6-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-mjm2j6-altcha-spinner{100%{transform:rotate(360deg)}}")}function he(t){let e,n,l;return{c(){e=S("svg"),n=S("path"),l=S("path"),o(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"),o(n,"fill","currentColor"),o(n,"opacity",".25"),o(l,"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"),o(l,"fill","currentColor"),o(l,"class","altcha-spinner svelte-mjm2j6"),o(e,"width","24"),o(e,"height","24"),o(e,"viewBox","0 0 24 24"),o(e,"xmlns","http://www.w3.org/2000/svg")},m(i,r){O(i,e,r),d(e,n),d(e,l)},d(i){i&&I(e)}}}function Je(t){let e,n=t[7].label+"",l;return{c(){e=_("label"),o(e,"for",l=t[1]+"_checkbox"),o(e,"class","svelte-mjm2j6")},m(i,r){O(i,e,r),e.innerHTML=n},p(i,r){r[0]&128&&n!==(n=i[7].label+"")&&(e.innerHTML=n),r[0]&2&&l!==(l=i[1]+"_checkbox")&&o(e,"for",l)},d(i){i&&I(e)}}}function Qe(t){let e,n=t[7].verifying+"";return{c(){e=_("span")},m(l,i){O(l,e,i),e.innerHTML=n},p(l,i){i[0]&128&&n!==(n=l[7].verifying+"")&&(e.innerHTML=n)},d(l){l&&I(e)}}}function qe(t){let e,n=t[7].verified+"",l,i;return{c(){e=_("span"),l=G(),i=_("input"),o(i,"type","hidden"),o(i,"name",t[1]),i.value=t[2]},m(r,c){O(r,e,c),e.innerHTML=n,O(r,l,c),O(r,i,c)},p(r,c){c[0]&128&&n!==(n=r[7].verified+"")&&(e.innerHTML=n),c[0]&2&&o(i,"name",r[1]),c[0]&4&&(i.value=r[2])},d(r){r&&(I(e),I(l),I(i))}}}function de(t){let e,n,l,i,r,c=t[7].error+"";return{c(){e=_("div"),n=S("svg"),l=S("path"),i=G(),r=_("div"),o(l,"stroke-linecap","round"),o(l,"stroke-linejoin","round"),o(l,"d","M6 18L18 6M6 6l12 12"),o(n,"width","14"),o(n,"height","14"),o(n,"xmlns","http://www.w3.org/2000/svg"),o(n,"fill","none"),o(n,"viewBox","0 0 24 24"),o(n,"stroke-width","1.5"),o(n,"stroke","currentColor"),o(r,"title",t[6]),o(e,"class","altcha-error svelte-mjm2j6")},m(a,u){O(a,e,u),d(e,n),d(n,l),d(e,i),d(e,r),r.innerHTML=c},p(a,u){u[0]&128&&c!==(c=a[7].error+"")&&(r.innerHTML=c),u[0]&64&&o(r,"title",a[6])},d(a){a&&I(e)}}}function me(t){let e,n,l=t[7].footer+"";return{c(){e=_("div"),n=_("div"),o(n,"class","svelte-mjm2j6"),o(e,"class","altcha-footer svelte-mjm2j6")},m(i,r){O(i,e,r),d(e,n),n.innerHTML=l},p(i,r){r[0]&128&&l!==(l=i[7].footer+"")&&(n.innerHTML=l)},d(i){i&&I(e)}}}function et(t){let e,n,l,i,r,c,a,u,f,A,g,v,C,k,W,X,M,T,V,p=t[3]===y.VERIFYING&&he();function F(h,L){return h[3]===y.VERIFIED?qe:h[3]===y.VERIFYING?Qe:Je}let x=F(t),m=x(t),w=t[6]&&de(t),j=t[7].footer&&t[0]!==!0&&me(t);return{c(){e=_("div"),n=_("div"),p&&p.c(),l=G(),i=_("div"),r=_("input"),a=G(),u=_("div"),m.c(),f=G(),A=_("div"),g=_("a"),v=S("svg"),C=S("path"),k=S("path"),W=S("path"),X=G(),w&&w.c(),M=G(),j&&j.c(),o(r,"type","checkbox"),o(r,"id",c=t[1]+"_checkbox"),r.required=!0,o(r,"class","svelte-mjm2j6"),o(i,"class","altcha-checkbox svelte-mjm2j6"),se(i,"altcha-hidden",t[3]===y.VERIFYING),o(u,"class","altcha-label svelte-mjm2j6"),o(C,"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"),o(C,"fill","currentColor"),o(k,"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"),o(k,"fill","currentColor"),o(W,"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"),o(W,"fill","currentColor"),o(v,"width","22"),o(v,"height","22"),o(v,"viewBox","0 0 20 20"),o(v,"fill","none"),o(v,"xmlns","http://www.w3.org/2000/svg"),o(g,"href",ge),o(g,"target","_blank"),o(g,"class","altcha-logo svelte-mjm2j6"),o(n,"class","altcha-main svelte-mjm2j6"),o(e,"class","altcha svelte-mjm2j6"),o(e,"data-state",t[3])},m(h,L){O(h,e,L),d(e,n),p&&p.m(n,null),d(n,l),d(n,i),d(i,r),r.checked=t[4],d(n,a),d(n,u),m.m(u,null),d(n,f),d(n,A),d(A,g),d(g,v),d(v,C),d(v,k),d(v,W),d(e,X),w&&w.m(e,null),d(e,M),j&&j.m(e,null),t[20](e),T||(V=[J(r,"change",t[19]),J(r,"change",t[8]),J(r,"invalid",t[9])],T=!0)},p(h,L){h[3]===y.VERIFYING?p||(p=he(),p.c(),p.m(n,l)):p&&(p.d(1),p=null),L[0]&2&&c!==(c=h[1]+"_checkbox")&&o(r,"id",c),L[0]&16&&(r.checked=h[4]),L[0]&8&&se(i,"altcha-hidden",h[3]===y.VERIFYING),x===(x=F(h))&&m?m.p(h,L):(m.d(1),m=x(h),m&&(m.c(),m.m(u,null))),h[6]?w?w.p(h,L):(w=de(h),w.c(),w.m(e,M)):w&&(w.d(1),w=null),h[7].footer&&h[0]!==!0?j?j.p(h,L):(j=me(h),j.c(),j.m(e,null)):j&&(j.d(1),j=null),L[0]&8&&o(e,"data-state",h[3])},i:$,o:$,d(h){h&&I(e),p&&p.d(),m.d(),w&&w.d(),j&&j.d(),t[20](null),T=!1,U(V)}}}const ge="https://altcha.org/";function be(t){return JSON.parse(t)}function tt(t,e,n){let l,i,r,{challengeurl:c=void 0}=e,{challengejson:a=void 0}=e,{debug:u=!1}=e,{hidefooter:f=!1}=e,{name:A="altcha"}=e,{maxnumber:g=void 0}=e,{mockerror:v=!1}=e,{strings:C=void 0}=e,{test:k=!1}=e;const W=Ie(),X=["SHA-256","SHA-384","SHA-512"];let M=!1,T,V=null,p=null,F=null,x=y.UNVERIFIED;Re(()=>{V&&(V.removeEventListener("submit",w),V.removeEventListener("reset",j),V=null)}),Le(()=>{m("mounted"),k&&m("using test mode"),V=T.closest("form"),V&&(V.addEventListener("submit",w),V.addEventListener("reset",j))});function m(...s){(u||s.some(b=>b instanceof Error))&&console[s[0]instanceof Error?"error":"log"]("ALTCHA",...s)}function w(){z()}function j(){z()}function h(s,b){return btoa(JSON.stringify({algorithm:s.algorithm,challenge:s.challenge,number:b.number,salt:s.salt,signature:s.signature,test:k?!0:void 0,took:b.took}))}function L(s){if(!s.algorithm||!X.includes(s.algorithm))throw new Error(`Unknown algorithm value. Allowed values: ${X.join(", ")}`);if(!s.challenge||s.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!s.salt||s.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.");if(s.signature===void 0)throw new Error("Signature is missing.")}async function nt(){if(v)throw m("mocking error"),new Error("Mocked error.");if(l)return m("using provided json data"),l;if(k)return m("generating test challenge"),Xe();{if(!c)throw new Error("Attribute challengeurl not set.");m("fetching challenge from",c);const s=await fetch(c);if(s.status!==200)throw new Error(`Server responded with ${s.status}.`);return s.json()}}async function rt(s){let b=null;if("Worker"in window){try{b=await lt(s.challenge,s.salt,s.algorithm)}catch(re){m(re)}if((b==null?void 0:b.number)!==void 0)return{data:s,solution:b}}return{data:s,solution:await De(s.challenge,s.salt,s.algorithm,g)}}async function lt(s,b,re){const _e=new Ze;return new Promise(at=>{_e.addEventListener("message",ut=>{at(ut.data)}),_e.postMessage({alg:re,challenge:s,max:g,salt:b})})}function it(){[y.UNVERIFIED,y.ERROR].includes(x)?(z(y.VERIFYING),nt().then(s=>(L(s),m("challenge",s),rt(s))).then(({data:s,solution:b})=>{if(m("solution",b),(b==null?void 0:b.number)!==void 0)m("verified"),n(3,x=y.VERIFIED),n(4,M=!0),n(2,F=h(s,b)),W("verified",{payload:F}),m("payload",F);else throw new Error("Unexpected result returned.")}).catch(s=>{m(s),n(3,x=y.ERROR),n(4,M=!1),n(6,p=s)})):n(4,M=!0)}function st(){x===y.VERIFYING&&alert(r.waitAlert)}function z(s=y.UNVERIFIED){n(4,M=!1),n(6,p=null),n(2,F=null),n(3,x=s)}function ot(){M=this.checked,n(4,M)}function ct(s){q[s?"unshift":"push"](()=>{T=s,n(5,T)})}return t.$$set=s=>{"challengeurl"in s&&n(10,c=s.challengeurl),"challengejson"in s&&n(11,a=s.challengejson),"debug"in s&&n(12,u=s.debug),"hidefooter"in s&&n(0,f=s.hidefooter),"name"in s&&n(1,A=s.name),"maxnumber"in s&&n(13,g=s.maxnumber),"mockerror"in s&&n(14,v=s.mockerror),"strings"in s&&n(15,C=s.strings),"test"in s&&n(16,k=s.test)},t.$$.update=()=>{t.$$.dirty[0]&2048&&(l=a?be(a):void 0),t.$$.dirty[0]&32768&&n(18,i=C?be(C):{}),t.$$.dirty[0]&262144&&n(7,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ge}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...i}),t.$$.dirty[0]&12&&W("statechange",{payload:F,state:x})},[f,A,F,x,M,T,p,r,it,st,c,a,u,g,v,C,k,z,i,ot,ct]}class $e extends Be{constructor(e){super(),Ge(this,e,tt,et,ve,{challengeurl:10,challengejson:11,debug:12,hidefooter:0,name:1,maxnumber:13,mockerror:14,strings:15,test:16,reset:17},ze,[-1,-1])}get challengeurl(){return this.$$.ctx[10]}set challengeurl(e){this.$$set({challengeurl:e}),N()}get challengejson(){return this.$$.ctx[11]}set challengejson(e){this.$$set({challengejson:e}),N()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),N()}get hidefooter(){return this.$$.ctx[0]}set hidefooter(e){this.$$set({hidefooter:e}),N()}get name(){return this.$$.ctx[1]}set name(e){this.$$set({name:e}),N()}get maxnumber(){return this.$$.ctx[13]}set maxnumber(e){this.$$set({maxnumber:e}),N()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),N()}get strings(){return this.$$.ctx[15]}set strings(e){this.$$set({strings:e}),N()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),N()}get reset(){return this.$$.ctx[17]}}customElements.define("altcha-widget",We($e,{challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset"],!1)),E.Altcha=$e,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "altcha",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Daniel Regeci"
|
|
7
|
+
},
|
|
5
8
|
"homepage": "https://github.com/altcha-org/altchajs",
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "https://github.com/altcha-org/altchajs"
|
|
9
12
|
},
|
|
10
13
|
"type": "module",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"altcha",
|
|
16
|
+
"altcaptcha",
|
|
17
|
+
"captcha",
|
|
18
|
+
"recaptcha",
|
|
19
|
+
"hcaptcha",
|
|
20
|
+
"antispam",
|
|
21
|
+
"spam",
|
|
22
|
+
"protection",
|
|
23
|
+
"svelte"
|
|
24
|
+
],
|
|
11
25
|
"files": [
|
|
12
26
|
"dist"
|
|
13
27
|
],
|