altcha 2.2.2 → 2.2.4
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/README.md +3 -2
- package/dist/altcha.d.ts +39 -19
- package/dist/altcha.i18n.d.ts +39 -19
- package/dist/altcha.i18n.js +1688 -1729
- package/dist/altcha.i18n.umd.js +4 -4
- package/dist/altcha.js +1625 -1666
- package/dist/altcha.umd.cjs +4 -4
- package/dist_external/altcha.css +1 -1
- package/dist_external/altcha.d.ts +39 -19
- package/dist_external/altcha.js +1685 -1724
- package/dist_external/altcha.umd.cjs +3 -3
- package/dist_external/worker.js +1 -1
- package/dist_plugins/analytics.js +68 -82
- package/dist_plugins/analytics.umd.cjs +1 -1
- package/dist_plugins/obfuscation.js +70 -79
- package/dist_plugins/obfuscation.umd.cjs +1 -1
- package/dist_plugins/upload.js +360 -332
- package/dist_plugins/upload.umd.cjs +4 -4
- package/package.json +7 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`,
|
|
3
|
-
`+
|
|
4
|
-
`+
|
|
1
|
+
(function(p,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(p=typeof globalThis<"u"?globalThis:p||self,l(p["[name]"]={}))})(this,function(p){"use strict";const l={generateKey:F,exportKey:K,importKey:v,decrypt:x,encrypt:S};async function F(n=256){return crypto.subtle.generateKey({name:"AES-GCM",length:n},!0,["encrypt","decrypt"])}async function K(n){return new Uint8Array(await crypto.subtle.exportKey("raw",n))}async function v(n){return crypto.subtle.importKey("raw",n,{name:"AES-GCM"},!0,["encrypt","decrypt"])}async function S(n,e,t=16){const r=crypto.getRandomValues(new Uint8Array(t));return{encrypted:new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:r},n,e)),iv:r}}async function x(n,e,t){return new Uint8Array(await crypto.subtle.decrypt({name:"AES-GCM",iv:t},n,e))}function L(n,e=!1){return e&&(n=n.replace(/_/g,"/").replace(/-/g,"+")+"=".repeat(3-(3+n.length)%4)),Uint8Array.from(atob(n),t=>t.charCodeAt(0))}function h(n,e=!1){const t=btoa(String.fromCharCode(...n));return e?t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""):t}function f(n,e=80){let t="";for(;n.length>0;)t+=n.slice(0,e)+`
|
|
2
|
+
`,n=n.slice(e);return t}function m(n){return L(n.split(/\r?\n/).filter(e=>!e.startsWith("-----")).join(""))}const u="RSA-OAEP",d="SHA-256",C=2048,I=new Uint8Array([1,0,1]),T={generateKeyPair:N,encrypt:z,decrypt:j,exportPrivateKey:g,exportPrivateKeyPem:R,exportPublicKey:y,exportPublicKeyPem:_,exportPublicKeyFromPrivateKey:H,importPrivateKey:E,importPrivateKeyPem:k,importPublicKey:w,importPublicKeyPem:b};async function N(){return crypto.subtle.generateKey({name:u,modulusLength:C,publicExponent:I,hash:d},!0,["encrypt","decrypt"])}async function z(n,e){return new Uint8Array(await crypto.subtle.encrypt({name:u},n,e))}async function j(n,e){return new Uint8Array(await crypto.subtle.decrypt({name:u},n,e))}async function y(n){return new Uint8Array(await crypto.subtle.exportKey("spki",n))}async function g(n){return new Uint8Array(await crypto.subtle.exportKey("pkcs8",n))}async function _(n){return`-----BEGIN PUBLIC KEY-----
|
|
3
|
+
`+f(h(await y(n)),64)+"-----END PUBLIC KEY-----"}async function R(n){return`-----BEGIN PRIVATE KEY-----
|
|
4
|
+
`+f(h(await g(n)),64)+"-----END PRIVATE KEY-----"}async function w(n){return crypto.subtle.importKey("spki",n,{name:u,hash:d},!0,["encrypt"])}async function b(n){return w(m(n))}async function E(n){return crypto.subtle.importKey("pkcs8",n,{name:u,hash:d},!0,["decrypt"])}async function k(n){return E(m(n))}async function H(n){const e=await crypto.subtle.exportKey("jwk",n);delete e.d,delete e.dp,delete e.dq,delete e.q,delete e.qi,e.key_ops=["encrypt"];const t=await crypto.subtle.importKey("jwk",e,{name:u,hash:d},!0,["encrypt"]);return y(t)}const O=new Uint8Array([1,0,1]),q=256,M=16;async function $(n,e,t={}){const{aesIVLength:r=M,aesKeyLength:i=q}=t,s=await l.generateKey(i),{encrypted:o,iv:a}=await l.encrypt(s,e,r),c=await T.encrypt(n,await l.exportKey(s));return new Uint8Array([...O,...new Uint8Array([c.length]),...new Uint8Array([a.length]),...c,...a,...o])}class P{constructor(e){this.context=e}static pluginName;static register(e){typeof globalThis.altchaPlugins!="object"&&(globalThis.altchaPlugins=[]),globalThis.altchaPlugins.includes(e)||globalThis.altchaPlugins.push(e)}destroy(){}onErrorChange(e){}onStateChange(e){}}class U extends P{static pluginName="upload";pendingFiles=[];uploadHandles=[];elForm;#e=this.#c.bind(this);#t=this.#l.bind(this);constructor(e){super(e),this.elForm=this.context.el.closest("form"),this.elForm&&(this.elForm.addEventListener("change",this.#e),this.elForm.addEventListener("submit",this.#t,{capture:!0}))}addFile(e,t){this.pendingFiles.find(([r,i])=>r===e&&i===t)||this.pendingFiles.push([e,t])}destroy(){this.elForm&&(this.elForm.removeEventListener("change",this.#e),this.elForm.removeEventListener("submit",this.#t))}async uploadPendingFiles(){const e=async()=>{const t=this.pendingFiles[0];if(t&&await this.#r(this.#s(t)),this.pendingFiles.length)return e()};try{await e()}catch(t){return this.context.log("upload failed",t),this.context.dispatch("uploaderror",{error:t}),!1}this.pendingFiles.length===0&&(this.#i(),this.elForm?.requestSubmit())}#i(){const e=this.uploadHandles.reduce((t,r)=>(t[r.fieldName]||(t[r.fieldName]=[]),r.fileId&&t[r.fieldName].push(r.fileId),t),{});for(const t in e){const r=document.createElement("input");r.name=t,r.type="hidden",r.value=e[t].join(","),this.elForm?.querySelector(`[name="${t}"]`)?.setAttribute("disabled","disabled"),this.elForm?.appendChild(r)}}#s(e){const t=this.pendingFiles.findIndex(([i,s])=>i===e[0]&&s===e[1]);if(t<0)throw new Error("Cannot create upload handle.");const r=new B(e[0],e[1]);return this.uploadHandles.push(r),this.pendingFiles.splice(t,1),this.#o(r),this.#n(),r}#o(e){this.context.dispatch("upload",{handle:e})}#n(){const e=this.pendingFiles.reduce((r,[i,s])=>r+s.size,0)+this.uploadHandles.reduce((r,{uploadSize:i})=>r+i,0),t=this.uploadHandles.reduce((r,{loaded:i})=>r+i,0);this.context.dispatch("uploadprogress",{bytesLoaded:t,bytesTotal:e,pendingFiles:this.pendingFiles,uploadHandles:this.uploadHandles})}#a(){if(this.elForm){const e=this.elForm.getAttribute("action"),t=this.elForm.getAttribute("data-upload-url");if(t)return t;const r=new URL(e||location.origin);return r.pathname=r.pathname+"/file",r.toString()}return null}#c(e){const t=e.target;if(t&&t.type==="file"){const r=t.files;if(r?.length)for(const i of r)this.addFile(t.name,i)}}#l(e){e.target?.hasAttribute("data-code-challenge-form")||this.pendingFiles.length&&(e.preventDefault(),e.stopPropagation(),this.uploadPendingFiles())}async#r(e,t){const r=this.#a();if(!r)throw new Error("Upload url not specified.");const i={"content-type":"application/json"};t&&(i.authorization="Altcha payload="+t);const s=await fetch(r,{body:JSON.stringify({name:e.file.name||"file",size:e.file.size,type:e.file.type||"application/octet-stream"}),credentials:"include",headers:i,method:"POST"});if(s.status===401)return this.#p(s,e);if(s.status!==200)throw new Error(`Unexpected server response ${s.status}.`);const o=await s.json();let a=e.file;if(o.encrypted&&o.encryptionPublicKey){const c=await b(o.encryptionPublicKey),G=await new Response(new ReadableStream({async start(A){const Y=e.file.stream().getReader();for(;;){const{done:D,value:V}=await Y.read();if(D)break;A.enqueue(V)}A.close()}})).arrayBuffer();a=await $(c,new Uint8Array(G))}return e.uploadSize=a instanceof Uint8Array?a.byteLength:e.file.size,await this.#d(o.uploadUrl,e,a,{"content-type":e.file.type||"application/octet-stream"}),o.finalizeUrl&&await this.#u(o.finalizeUrl,e.uploadSize),e.fileId=o.fileId,e.resolve({encrypted:o.encrypted,fileId:o.fileId}),e.promise}async#p(e,t){try{const i=e.headers.get("www-authenticate")?.match(/challenge=(.*),/)?.[1];if(!i)throw new Error("Unable to retrieve altcha challenge from www-authenticate header.");const s=JSON.parse(i);if(s&&"challenge"in s){const{solution:o}=await this.context.solve(s);if(o&&"number"in o)return this.#r(t,btoa(JSON.stringify({...s,number:o.number})));throw new Error("Invalid challenge solution.")}}catch(r){throw this.context.log(r),new Error("Unable to solve altcha challenge for upload.")}}async#u(e,t){const r=await fetch(e,{body:JSON.stringify({uploadedBytes:t}),headers:{"content-type":"application/json"},method:"POST"});if(r.status>204)throw new Error(`Unexpected server response ${r.status}.`);return!0}async#d(e,t,r,i={}){return e=new URL(e,this.elForm?.getAttribute("action")||location.origin).toString(),new Promise((s,o)=>{const a=new XMLHttpRequest;t.controller.signal.addEventListener("abort",()=>{a.abort()}),a.upload.addEventListener("progress",c=>{t.setProgress(c.loaded),this.#n()}),a.addEventListener("error",c=>{o(new Error("Upload failed."))}),a.addEventListener("load",()=>{a.status>=400?o(new Error(`Server responded with ${a.status}`)):s(void 0)}),a.open("PUT",e);for(const c in i)a.setRequestHeader(c,i[c]);a.send(r)})}}class B{constructor(e,t){this.fieldName=e,this.file=t,this.uploadSize=this.file.size,this.promise=new Promise((r,i)=>{this.resolve=r,this.reject=i})}controller=new AbortController;promise;fileId;loaded=0;progress=0;uploadSize=0;resolve;reject;abort(){this.controller.abort()}setProgress(e){this.loaded=e,this.progress=this.file.size&&e?Math.min(1,e/this.file.size):0}}P.register(U),p.PluginUpload=U,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "altcha",
|
|
3
3
|
"description": "Privacy-first CAPTCHA widget, compliant with global regulations (GDPR/HIPAA/CCPA/LGDP/DPDPA/PIPL) and WCAG accessible. No tracking, self-verifying.",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Daniel Regeci",
|
|
@@ -96,11 +96,11 @@
|
|
|
96
96
|
"prepare": "husky"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
99
|
+
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
100
100
|
"@tsconfig/svelte": "^5.0.4",
|
|
101
101
|
"@types/csso": "^5.0.4",
|
|
102
102
|
"@types/node": "^20.16.3",
|
|
103
|
-
"@types/react": "^19.
|
|
103
|
+
"@types/react": "^19.1.14",
|
|
104
104
|
"csso": "^5.0.5",
|
|
105
105
|
"husky": "^9.1.5",
|
|
106
106
|
"prettier": "3.2.5",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"testcafe": "^3.7.2",
|
|
113
113
|
"tslib": "^2.7.0",
|
|
114
114
|
"typescript": "^5.5.4",
|
|
115
|
-
"vite": "^
|
|
115
|
+
"vite": "^7.1.7",
|
|
116
116
|
"vite-plugin-string": "^1.2.3",
|
|
117
117
|
"vitest": "^3.0.8"
|
|
118
118
|
},
|
|
@@ -121,5 +121,8 @@
|
|
|
121
121
|
},
|
|
122
122
|
"optionalDependencies": {
|
|
123
123
|
"@rollup/rollup-linux-x64-gnu": "4.18.0"
|
|
124
|
+
},
|
|
125
|
+
"overrides": {
|
|
126
|
+
"tmp": "0.2.5"
|
|
124
127
|
}
|
|
125
128
|
}
|