@trustcomponent/trustcaptcha-frontend
Version:
TrustCaptcha – Privacy-first CAPTCHA solution. GDPR-compliant, bot protection made in Europe.
5 lines (4 loc) • 2.71 kB
JavaScript
export const powWorkerScript = `
var __awaiter=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{c(r.next(e))}catch(e){o(e)}}function u(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}c((r=r.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(i=0)),i;)try{if(n=1,r&&(a=2&u[0]?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;switch(r=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){i.label=u[1];break}if(6===u[0]&&i.label<a[1]){i.label=a[1],a=u;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(u);break}a[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],r=0}finally{n=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},_this=this;function base64ToArrayBuffer(e){for(var t=self.atob(e),n=t.length,r=new Uint8Array(n),a=0;a<n;a++)r[a]=t.charCodeAt(a);return r.buffer}function appendBuffer(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}function countLeadingZeroBits(e){var t=new Uint8Array(e),n=t.findIndex((function(e){return 0!==e}));return-1===n?8*t.length:8*n+(Math.clz32(t[n])-24)}function executePowTask(e,t){return __awaiter(this,void 0,void 0,(function(){var n,r,a,o;return __generator(this,(function(i){switch(i.label){case 0:n=base64ToArrayBuffer(e.input),r=0,i.label=1;case 1:return a="tcn".concat(r),o=appendBuffer(n,(new TextEncoder).encode(a).buffer),[4,crypto.subtle.digest("SHA-256",o)];case 2:return countLeadingZeroBits(i.sent())===t?[2,{number:e.number,nonce:a}]:(r++,[3,1]);case 3:return[2]}}))}))}self.addEventListener("message",(function(e){return __awaiter(_this,void 0,void 0,(function(){var t,n,r,a;return __generator(this,(function(o){switch(o.label){case 0:return t=e.data,n=t.task,r=t.difficulty,a=postMessage,[4,executePowTask(n,r)];case 1:return a.apply(void 0,[o.sent()]),[2]}}))}))}));
`;
//# sourceMappingURL=pow-worker-script.js.map