friendly-challenge
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -1,1 +0,1433 @@ | ||
!function(){class t{constructor(t){this.b=new Uint8Array(128),this.h=new Uint32Array(16),this.t=0,this.c=0,this.v=new Uint32Array(32),this.m=new Uint32Array(32),this.outlen=t}}function e(t,e,n){const r=t[e],s=t[e+1],o=t[n],i=t[n+1],a=r+o>>>0,f=(r&o|(r|o)&~a)>>>31;t[e]=a,t[e+1]=s+i+f>>>0}function n(t,e,n,r){const s=t[e],o=t[e+1],i=s+n>>>0,a=(s&n|(s|n)&~i)>>>31;t[e]=i,t[e+1]=o+r+a>>>0}function r(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function s(t,r,s,o,i,a,f,c){const l=r[f],u=r[f+1],y=r[c],h=r[c+1];e(t,s,o),n(t,s,l,u);let w=t[a]^t[s],_=t[a+1]^t[s+1];t[a]=_,t[a+1]=w,e(t,i,a),w=t[o]^t[i],_=t[o+1]^t[i+1],t[o]=w>>>24^_<<8,t[o+1]=_>>>24^w<<8,e(t,s,o),n(t,s,y,h),w=t[a]^t[s],_=t[a+1]^t[s+1],t[a]=w>>>16^_<<16,t[a+1]=_>>>16^w<<16,e(t,i,a),w=t[o]^t[i],_=t[o+1]^t[i+1],t[o]=_>>>31^w<<1,t[o+1]=w>>>31^_<<1}const o=new Uint32Array(16).map((t,e)=>[4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225][e]),i=[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,28,20,8,16,18,30,26,12,2,24,0,4,22,14,10,6,22,16,24,0,10,4,30,26,20,28,6,12,14,2,18,8,14,18,6,2,26,24,22,28,4,12,10,20,8,0,30,16,18,0,10,14,4,8,20,30,28,2,22,24,12,16,6,26,4,24,12,20,0,22,16,6,8,26,14,10,30,28,2,18,24,10,2,30,28,26,8,20,0,14,12,6,18,4,16,22,26,22,14,28,24,2,6,18,10,0,30,8,16,12,4,20,12,30,28,18,22,6,0,16,24,4,26,14,2,8,20,10,20,4,16,8,14,12,2,10,30,22,18,28,6,24,26,0,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,28,20,8,16,18,30,26,12,2,24,0,4,22,14,10,6];function a(t,e){const n=t.v,a=t.m;for(let e=0;e<16;e++)n[e]=t.h[e],n[e+16]=o[e];n[24]=n[24]^t.t,n[25]=n[25]^t.t/4294967296,e&&(n[28]=~n[28],n[29]=~n[29]);for(let e=0;e<32;e++)a[e]=r(t.b,4*e);for(let t=0;t<12;t++)s(n,a,0,8,16,24,i[16*t+0],i[16*t+1]),s(n,a,2,10,18,26,i[16*t+2],i[16*t+3]),s(n,a,4,12,20,28,i[16*t+4],i[16*t+5]),s(n,a,6,14,22,30,i[16*t+6],i[16*t+7]),s(n,a,0,10,20,30,i[16*t+8],i[16*t+9]),s(n,a,2,12,22,24,i[16*t+10],i[16*t+11]),s(n,a,4,14,16,26,i[16*t+12],i[16*t+13]),s(n,a,6,8,18,28,i[16*t+14],i[16*t+15]);for(let e=0;e<16;e++)t.h[e]=t.h[e]^n[e]^n[e+16]}function f(t,e){for(let e=0;e<16;e++)t.h[e]=o[e];t.b.set(e),t.h[0]^=16842752^t.outlen}function c(t,e){const n=new Uint8Array(3),r=new DataView(n.buffer);return r.setUint8(0,t),r.setUint16(1,e),n}let l,u;self.ASC_TARGET=0;let y=new Promise(t=>u=t),h=!1;self.onerror=t=>{self.postMessage({type:"error",error:JSON.stringify(t)})},self.onmessage=e=>{const n=e.data,r=n.type;if("module"===r)(async function(t){const e=await async function(t){const e={env:{abort(){throw Error("Wasm aborted")}}},n=await WebAssembly.instantiate(t,e),r=function(t){const e={},n=t.exports,r=n.memory,s=n.__alloc,o=n.__retain,i=n.__rtti_base||-1;return e.__allocArray=(t,e)=>{const n=function(t){return new Uint32Array(r.buffer)[(i+4>>>2)+2*t]}(t),a=31-Math.clz32(n>>>6&31),f=e.length,c=s(f<<a,0),l=s(12,t),u=new Uint32Array(r.buffer);u[l+0>>>2]=o(c),u[l+4>>>2]=c,u[l+8>>>2]=f<<a;const y=r.buffer,h=new Uint8Array(y);if(16384&n)for(let t=0;t<f;++t)h[(c>>>a)+t]=o(e[t]);else h.set(e,c>>>a);return l},e.__getUint8Array=t=>{const e=new Uint32Array(r.buffer),n=e[t+4>>>2];return new Uint8Array(r.buffer,n,e[n-4>>>2]>>>0)},function(t,e={}){const n=t.__argumentsLength?e=>{t.__argumentsLength.value=e}:t.__setArgumentsLength||t.__setargc||(()=>({}));for(const r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;const s=t[r],o=r.split(".")[0];"function"==typeof s&&s!==n?(e[o]=(...t)=>(n(t.length),s(...t))).original=s:e[o]=s}return e}(n,e)}(n);return{...n,exports:r}}(t),n=e.exports.__retain(e.exports.__allocArray(e.exports.Uint8Array_ID,new Uint8Array(128)));let r=e.exports.__getUint8Array(n);return(t,s,o=4294967295)=>{r.set(t);const i=e.exports.solveBlake2b(n,s,o);r=e.exports.__getUint8Array(n);const a=e.exports.__getUint8Array(i);return e.exports.__release(i),[r,a]}})(n.module).then(t=>{self.postMessage({type:"ready",solver:1}),l=1,u(t)});else if("js"===r)(async function(){return(e,n,r=4294967295)=>[e,function(e,n,r){if(128!=e.length)throw Error("Invalid input");const s=e.buffer,o=new DataView(s),i=new t(32);i.t=128;const c=o.getUint32(124,!0),l=c+r;for(let t=c;t<l;t++)if(o.setUint32(124,t,!0),f(i,e),a(i,!0),i.h[0]<n)return 0==ASC_TARGET?new Uint8Array(i.h.buffer):Uint8Array.wrap(i.h.buffer);return new Uint8Array(0)}(e,n,r)]})().then(t=>{self.postMessage({type:"ready",solver:2}),l=2,u(t)});else if("start"===r){if(h)return;h=!0,y.then(t=>{setTimeout(()=>{self.postMessage({type:"started"});let e=Date.now(),r=0;const s=function(t,e){const n=[];for(let r=0;r<e;r++){const e=new Uint8Array(128);e.set(t),e[120]=r,n.push(e)}return n}(n.buffer,n.n),o=new Uint8Array(8*n.n);for(var i=0;i<s.length;i++){const e=Date.now();let f;for(var a=0;a<256;a++){s[i][123]=a;const[e,r]=t(s[i],n.threshold);if(0!==e.length){f=e;break}console.error("FC: Internal error or no solution found")}const c=new DataView(f.slice(-4).buffer).getUint32(0,!0),l=(Date.now()-e)/1e3;r+=c,o.set(f.slice(-8),8*i),self.postMessage({type:"progress",n:n.n,h:c,t:l,i:i})}const f=(Date.now()-e)/1e3,u={type:"done",solution:o,h:r,t:f,diagnostics:c(l,f)};self.postMessage(u),self.close()})})}}}(); | ||
// FriendlyCaptcha worker | ||
(function () { | ||
'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
// This is not an enum to save some bytes in the output bundle. | ||
var SOLVER_TYPE_JS = 1; | ||
var SOLVER_TYPE_WASM = 2; | ||
var CHALLENGE_SIZE_BYTES = 128; | ||
function getPuzzleSolverInputs(puzzleBuffer, numPuzzles) { | ||
var startingPoints = []; | ||
for (var i = 0; i < numPuzzles; i++) { | ||
var input = new Uint8Array(CHALLENGE_SIZE_BYTES); | ||
input.set(puzzleBuffer); | ||
input[120] = i; | ||
startingPoints.push(input); | ||
} | ||
return startingPoints; | ||
} | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
// This is a hand-pruned version of the assemblyscript loader, removing | ||
// a lot of functionality we don't need, saving in bundle size. | ||
function addUtilityExports(instance) { | ||
var extendedExports = {}; | ||
var exports = instance.exports; | ||
var memory = exports.memory; | ||
var alloc = exports["__alloc"]; | ||
var retain = exports["__retain"]; | ||
var rttiBase = exports["__rtti_base"] || ~0; // oob if not present | ||
/** Gets the runtime type info for the given id. */ | ||
function getInfo(id) { | ||
var U32 = new Uint32Array(memory.buffer); // const count = U32[rttiBase >>> 2]; | ||
// if ((id >>>= 0) >= count) throw Error("invalid id: " + id); | ||
return U32[(rttiBase + 4 >>> 2) + id * 2]; | ||
} | ||
/** Allocates a new array in the module's memory and returns its retained pointer. */ | ||
extendedExports.__allocArray = function (id, values) { | ||
var info = getInfo(id); | ||
var align = 31 - Math.clz32(info >>> 6 & 31); | ||
var length = values.length; | ||
var buf = alloc(length << align, 0); | ||
var arr = alloc(12, id); | ||
var U32 = new Uint32Array(memory.buffer); | ||
U32[arr + 0 >>> 2] = retain(buf); | ||
U32[arr + 4 >>> 2] = buf; | ||
U32[arr + 8 >>> 2] = length << align; | ||
var buffer = memory.buffer; | ||
var view = new Uint8Array(buffer); | ||
if (info & 1 << 14) { | ||
for (var i = 0; i < length; ++i) { | ||
view[(buf >>> align) + i] = retain(values[i]); | ||
} | ||
} else { | ||
view.set(values, buf >>> align); | ||
} | ||
return arr; | ||
}; | ||
extendedExports.__getUint8Array = function (ptr) { | ||
var U32 = new Uint32Array(memory.buffer); | ||
var bufPtr = U32[ptr + 4 >>> 2]; | ||
return new Uint8Array(memory.buffer, bufPtr, U32[bufPtr - 4 >>> 2] >>> 0); | ||
}; | ||
return demangle(exports, extendedExports); | ||
} | ||
/** Demangles an AssemblyScript module's exports to a friendly object structure. */ | ||
function demangle(exports) { | ||
var extendedExports = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// extendedExports = Object.create(extendedExports); | ||
var setArgumentsLength = exports["__argumentsLength"] ? function (length) { | ||
exports["__argumentsLength"].value = length; | ||
} : exports["__setArgumentsLength"] || exports["__setargc"] || function () { | ||
return {}; | ||
}; | ||
var _loop = function _loop(internalName) { | ||
if (!Object.prototype.hasOwnProperty.call(exports, internalName)) return "continue"; | ||
var elem = exports[internalName]; // Only necessary if nested exports are present | ||
// let parts = internalName.split("."); | ||
// let curr = extendedExports; | ||
// while (parts.length > 1) { | ||
// let part = parts.shift(); | ||
// if (!Object.prototype.hasOwnProperty.call(curr, part as any)) curr[part as any] = {}; | ||
// curr = curr[part as any]; | ||
// } | ||
var name = internalName.split(".")[0]; | ||
if (typeof elem === "function" && elem !== setArgumentsLength) { | ||
(extendedExports[name] = function () { | ||
setArgumentsLength(arguments.length); | ||
return elem.apply(void 0, arguments); | ||
}).original = elem; | ||
} else { | ||
extendedExports[name] = elem; | ||
} | ||
}; | ||
for (var internalName in exports) { | ||
var _ret = _loop(internalName); | ||
if (_ret === "continue") continue; | ||
} | ||
return extendedExports; | ||
} | ||
function instantiateWasmSolver(_x) { | ||
return _instantiateWasmSolver.apply(this, arguments); | ||
} | ||
function _instantiateWasmSolver() { | ||
_instantiateWasmSolver = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(module) { | ||
var imports, result, exports; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
imports = { | ||
env: { | ||
abort: function abort() { | ||
throw Error("Wasm aborted"); | ||
} | ||
} | ||
}; | ||
_context.next = 3; | ||
return WebAssembly.instantiate(module, imports); | ||
case 3: | ||
result = _context.sent; | ||
exports = addUtilityExports(result); | ||
return _context.abrupt("return", _objectSpread2(_objectSpread2({}, result), {}, { | ||
exports: exports | ||
})); | ||
case 6: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _instantiateWasmSolver.apply(this, arguments); | ||
} | ||
function getWasmSolver(_x) { | ||
return _getWasmSolver.apply(this, arguments); | ||
} | ||
function _getWasmSolver() { | ||
_getWasmSolver = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(module) { | ||
var w, arrPtr, solution; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return instantiateWasmSolver(module); | ||
case 2: | ||
w = _context.sent; | ||
arrPtr = w.exports.__retain(w.exports.__allocArray(w.exports.Uint8Array_ID, new Uint8Array(128))); | ||
solution = w.exports.__getUint8Array(arrPtr); | ||
return _context.abrupt("return", function (puzzleBuffer, threshold) { | ||
var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4294967295; | ||
solution.set(puzzleBuffer); | ||
var hashPtr = w.exports.solveBlake2b(arrPtr, threshold, n); | ||
solution = w.exports.__getUint8Array(arrPtr); | ||
var hash = w.exports.__getUint8Array(hashPtr); | ||
w.exports.__release(hashPtr); | ||
return [solution, hash]; | ||
}); | ||
case 6: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _getWasmSolver.apply(this, arguments); | ||
} | ||
// Blake2B made assemblyscript compatible, adapted from (CC0 licensed): | ||
// Blake2B in pure Javascript | ||
// Adapted from the reference implementation in RFC7693 | ||
// Ported to Javascript by DC - https://github.com/dcposch | ||
var Context = function Context(outlen) { | ||
_classCallCheck(this, Context); | ||
this.b = new Uint8Array(128); | ||
this.h = new Uint32Array(16); | ||
this.t = 0; // input count | ||
this.c = 0; // pointer within buffer | ||
this.v = new Uint32Array(32); | ||
this.m = new Uint32Array(32); | ||
this.outlen = outlen; | ||
}; // 64-bit unsigned addition | ||
// Sets v[a,a+1] += v[b,b+1] | ||
// v should be a Uint32Array | ||
function ADD64AA(v, a, b) { | ||
// Faster in Chrome.. | ||
var a0 = v[a]; | ||
var a1 = v[a + 1]; | ||
var b0 = v[b]; | ||
var b1 = v[b + 1]; | ||
var c0 = a0 + b0 >>> 0; | ||
var c = (a0 & b0 | (a0 | b0) & ~c0) >>> 31; | ||
v[a] = c0; | ||
v[a + 1] = a1 + b1 + c >>> 0; // Alternative, faster in Firefox.. | ||
// const o0: u64 = (v[a] as u64) + (v[b] as u64); | ||
// let o1: u64 = (v[a + 1] as u64) + (v[b + 1] as u64); | ||
// if (o0 >= 0x100000000) { | ||
// o1++; | ||
// } | ||
// v[a] = o0 as u32; | ||
// v[a + 1] = o1 as u32; | ||
} // 64-bit unsigned addition | ||
// Sets v[a,a+1] += b | ||
// b0 is the low 32 bits of b, b1 represents the high 32 bits | ||
function ADD64AC(v, a, b0, b1) { | ||
// Faster in Chrome.. | ||
var a0 = v[a]; | ||
var a1 = v[a + 1]; | ||
var c0 = a0 + b0 >>> 0; | ||
var c = (a0 & b0 | (a0 | b0) & ~c0) >>> 31; | ||
v[a] = c0; | ||
v[a + 1] = a1 + b1 + c >>> 0; // Alternative, faster in Firefox.. | ||
// let o0: i64 = (v[a] as i64) + b0; | ||
// if (b0 < 0) { | ||
// o0 += 0x100000000; | ||
// } | ||
// let o1: i64 = v[a + 1] + b1; | ||
// if (o0 >= 0x100000000) { | ||
// o1++; | ||
// } | ||
// v[a] = o0 as u32; | ||
// v[a + 1] = o1 as u32; | ||
} // Little-endian byte access | ||
function B2B_GET32(arr, i) { | ||
return arr[i] ^ arr[i + 1] << 8 ^ arr[i + 2] << 16 ^ arr[i + 3] << 24; | ||
} // G Mixing function | ||
// The ROTRs are inlined for speed | ||
function B2B_G(v, m, a, b, c, d, ix, iy) { | ||
var x0 = m[ix]; | ||
var x1 = m[ix + 1]; | ||
var y0 = m[iy]; | ||
var y1 = m[iy + 1]; | ||
ADD64AA(v, a, b); // v[a,a+1] += v[b,b+1] ... in JS we must store a uint64 as two uint32s | ||
ADD64AC(v, a, x0, x1); // v[a, a+1] += x ... x0 is the low 32 bits of x, x1 is the high 32 bits | ||
// v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated to the right by 32 bits | ||
var xor0 = v[d] ^ v[a]; | ||
var xor1 = v[d + 1] ^ v[a + 1]; | ||
v[d] = xor1; | ||
v[d + 1] = xor0; | ||
ADD64AA(v, c, d); // v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 24 bits | ||
xor0 = v[b] ^ v[c]; | ||
xor1 = v[b + 1] ^ v[c + 1]; | ||
v[b] = xor0 >>> 24 ^ xor1 << 8; | ||
v[b + 1] = xor1 >>> 24 ^ xor0 << 8; | ||
ADD64AA(v, a, b); | ||
ADD64AC(v, a, y0, y1); // v[d,d+1] = (v[d,d+1] xor v[a,a+1]) rotated right by 16 bits | ||
xor0 = v[d] ^ v[a]; | ||
xor1 = v[d + 1] ^ v[a + 1]; | ||
v[d] = xor0 >>> 16 ^ xor1 << 16; | ||
v[d + 1] = xor1 >>> 16 ^ xor0 << 16; | ||
ADD64AA(v, c, d); // v[b,b+1] = (v[b,b+1] xor v[c,c+1]) rotated right by 63 bits | ||
xor0 = v[b] ^ v[c]; | ||
xor1 = v[b + 1] ^ v[c + 1]; | ||
v[b] = xor1 >>> 31 ^ xor0 << 1; | ||
v[b + 1] = xor0 >>> 31 ^ xor1 << 1; | ||
} // Initialization Vector | ||
var BLAKE2B_IV32 = new Uint32Array(16).map(function (v, i) { | ||
return [0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85, 0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A, 0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C, 0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19][i]; | ||
}); // TODO format more nicely | ||
// Note these offsets have all been multiplied by two to make them offsets into | ||
// a uint32 buffer. | ||
var SIGMA82 = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12, 2, 24, 0, 4, 22, 14, 10, 6, 22, 16, 24, 0, 10, 4, 30, 26, 20, 28, 6, 12, 14, 2, 18, 8, 14, 18, 6, 2, 26, 24, 22, 28, 4, 12, 10, 20, 8, 0, 30, 16, 18, 0, 10, 14, 4, 8, 20, 30, 28, 2, 22, 24, 12, 16, 6, 26, 4, 24, 12, 20, 0, 22, 16, 6, 8, 26, 14, 10, 30, 28, 2, 18, 24, 10, 2, 30, 28, 26, 8, 20, 0, 14, 12, 6, 18, 4, 16, 22, 26, 22, 14, 28, 24, 2, 6, 18, 10, 0, 30, 8, 16, 12, 4, 20, 12, 30, 28, 18, 22, 6, 0, 16, 24, 4, 26, 14, 2, 8, 20, 10, 20, 4, 16, 8, 14, 12, 2, 10, 30, 22, 18, 28, 6, 24, 26, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12, 2, 24, 0, 4, 22, 14, 10, 6]; // Compression function. 'last' flag indicates last block. | ||
function blake2bCompress(ctx, last) { | ||
var v = ctx.v; | ||
var m = ctx.m; // init work variables | ||
for (var i = 0; i < 16; i++) { | ||
v[i] = ctx.h[i]; | ||
v[i + 16] = BLAKE2B_IV32[i]; | ||
} // low 64 bits of offset | ||
v[24] = v[24] ^ ctx.t; | ||
v[25] = v[25] ^ ctx.t / 0x100000000; // high 64 bits not supported, offset may not be higher than 2**53-1 | ||
// last block flag set ? | ||
if (last) { | ||
v[28] = ~v[28]; | ||
v[29] = ~v[29]; | ||
} // get little-endian words | ||
for (var _i = 0; _i < 32; _i++) { | ||
m[_i] = B2B_GET32(ctx.b, 4 * _i); | ||
} // twelve rounds of mixing | ||
for (var _i2 = 0; _i2 < 12; _i2++) { | ||
B2B_G(v, m, 0, 8, 16, 24, SIGMA82[_i2 * 16 + 0], SIGMA82[_i2 * 16 + 1]); | ||
B2B_G(v, m, 2, 10, 18, 26, SIGMA82[_i2 * 16 + 2], SIGMA82[_i2 * 16 + 3]); | ||
B2B_G(v, m, 4, 12, 20, 28, SIGMA82[_i2 * 16 + 4], SIGMA82[_i2 * 16 + 5]); | ||
B2B_G(v, m, 6, 14, 22, 30, SIGMA82[_i2 * 16 + 6], SIGMA82[_i2 * 16 + 7]); | ||
B2B_G(v, m, 0, 10, 20, 30, SIGMA82[_i2 * 16 + 8], SIGMA82[_i2 * 16 + 9]); | ||
B2B_G(v, m, 2, 12, 22, 24, SIGMA82[_i2 * 16 + 10], SIGMA82[_i2 * 16 + 11]); | ||
B2B_G(v, m, 4, 14, 16, 26, SIGMA82[_i2 * 16 + 12], SIGMA82[_i2 * 16 + 13]); | ||
B2B_G(v, m, 6, 8, 18, 28, SIGMA82[_i2 * 16 + 14], SIGMA82[_i2 * 16 + 15]); | ||
} | ||
for (var _i3 = 0; _i3 < 16; _i3++) { | ||
ctx.h[_i3] = ctx.h[_i3] ^ v[_i3] ^ v[_i3 + 16]; | ||
} | ||
} // Creates a BLAKE2b hashing context | ||
/** | ||
* FRIENDLYCAPTCHA optimization only, does not reset ctx.t (global byte counter) | ||
* Assumes no key | ||
*/ | ||
function blake2bResetForShortMessage(ctx, input) { | ||
// Initialize State vector h with IV | ||
for (var i = 0; i < 16; i++) { | ||
ctx.h[i] = BLAKE2B_IV32[i]; | ||
} // Danger: These operations and resetting are really only possible because our input is exactly 128 bytes | ||
ctx.b.set(input); // ctx.m.fill(0); | ||
// ctx.v.fill(0); | ||
ctx.h[0] ^= 0x01010000 ^ ctx.outlen; | ||
} | ||
var HASH_SIZE_BYTES = 32; | ||
/** | ||
* Solve the blake2b hashing problem, re-using the memory between different attempts (which solves up to 50% faster). | ||
* | ||
* This only changes the last 4 bytes of the input array to find a solution. To find multiple solutions | ||
* one could call this function multiple times with the 4 bytes in front of those last 4 bytes varying. | ||
* | ||
* | ||
* The goal is to find a nonce that, hashed together with the rest of the input header, has a value of its | ||
* most significant 32bits that is below some threshold. | ||
* Approximately this means: the hash value of it starts with K zeroes (little endian), which is expected to be | ||
* increasingly difficult as K increases. | ||
* | ||
* In practice you should ask the client to solve multiple (easier) puzzles which should reduce variance and also allows us | ||
* to show a progress bar. | ||
* @param input challenge bytes | ||
* @param threshold u32 value under which the solution's hash should be below. | ||
*/ | ||
function solveBlake2bEfficient(input, threshold, n) { | ||
if (input.length != CHALLENGE_SIZE_BYTES) { | ||
throw Error("Invalid input"); | ||
} | ||
var buf = input.buffer; | ||
var view = new DataView(buf); | ||
var ctx = new Context(HASH_SIZE_BYTES); | ||
ctx.t = CHALLENGE_SIZE_BYTES; | ||
var start = view.getUint32(124, true); | ||
var end = start + n; | ||
for (var i = start; i < end; i++) { | ||
view.setUint32(124, i, true); | ||
blake2bResetForShortMessage(ctx, input); | ||
blake2bCompress(ctx, true); | ||
if (ctx.h[0] < threshold) { | ||
if (ASC_TARGET == 0) { | ||
// JS | ||
return new Uint8Array(ctx.h.buffer); | ||
} //@ts-ignore | ||
return Uint8Array.wrap(ctx.h.buffer); | ||
} | ||
} | ||
return new Uint8Array(0); | ||
} | ||
function getJSSolver() { | ||
return _getJSSolver.apply(this, arguments); | ||
} | ||
function _getJSSolver() { | ||
_getJSSolver = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", function (puzzleBuffer, threshold) { | ||
var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4294967295; | ||
var hash = solveBlake2bEfficient(puzzleBuffer, threshold, n); | ||
return [puzzleBuffer, hash]; | ||
}); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _getJSSolver.apply(this, arguments); | ||
} | ||
function createDiagnosticsBuffer(solverID, timeToSolved) { | ||
var arr = new Uint8Array(3); | ||
var view = new DataView(arr.buffer); | ||
view.setUint8(0, solverID); | ||
view.setUint16(1, timeToSolved); | ||
return arr; | ||
} | ||
function createCommonjsModule(fn, basedir, module) { | ||
return module = { | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(); | ||
} | ||
}, fn(module, module.exports), module.exports; | ||
} | ||
function commonjsRequire () { | ||
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); | ||
} | ||
var runtime_1 = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var runtime = function (exports) { | ||
var Op = Object.prototype; | ||
var hasOwn = Op.hasOwnProperty; | ||
var undefined$1; // More compressible than void 0. | ||
var $Symbol = typeof Symbol === "function" ? Symbol : {}; | ||
var iteratorSymbol = $Symbol.iterator || "@@iterator"; | ||
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; | ||
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; | ||
var generator = Object.create(protoGenerator.prototype); | ||
var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next, | ||
// .throw, and .return methods. | ||
generator._invoke = makeInvokeMethod(innerFn, self, context); | ||
return generator; | ||
} | ||
exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion | ||
// record like context.tryEntries[i].completion. This interface could | ||
// have been (and was previously) designed to take a closure to be | ||
// invoked without arguments, but in all the cases we care about we | ||
// already have an existing method we want to call, so there's no need | ||
// to create a new function object. We can even get away with assuming | ||
// the method takes exactly one argument, since that happens to be true | ||
// in every case, so we don't have to touch the arguments object. The | ||
// only additional allocation required is the completion record, which | ||
// has a stable shape and so hopefully should be cheap to allocate. | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
} | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
var GenStateSuspendedYield = "suspendedYield"; | ||
var GenStateExecuting = "executing"; | ||
var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as | ||
// breaking out of the dispatch switch statement. | ||
var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and | ||
// .constructor.prototype properties for functions that return Generator | ||
// objects. For full spec compliance, you may wish to configure your | ||
// minifier not to mangle the names of these two functions. | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that | ||
// don't natively support it. | ||
var IteratorPrototype = {}; | ||
IteratorPrototype[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
var getProto = Object.getPrototypeOf; | ||
var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { | ||
// This environment has a native %IteratorPrototype%; use it instead | ||
// of the polyfill. | ||
IteratorPrototype = NativeIteratorPrototype; | ||
} | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; | ||
GeneratorFunctionPrototype.constructor = GeneratorFunction; | ||
GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction"; // Helper for defining the .next, .throw, and .return methods of the | ||
// Iterator interface in terms of a single ._invoke method. | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
prototype[method] = function (arg) { | ||
return this._invoke(method, arg); | ||
}; | ||
}); | ||
} | ||
exports.isGeneratorFunction = function (genFun) { | ||
var ctor = typeof genFun === "function" && genFun.constructor; | ||
return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can | ||
// do is to check its .name property. | ||
(ctor.displayName || ctor.name) === "GeneratorFunction" : false; | ||
}; | ||
exports.mark = function (genFun) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); | ||
} else { | ||
genFun.__proto__ = GeneratorFunctionPrototype; | ||
if (!(toStringTagSymbol in genFun)) { | ||
genFun[toStringTagSymbol] = "GeneratorFunction"; | ||
} | ||
} | ||
genFun.prototype = Object.create(Gp); | ||
return genFun; | ||
}; // Within the body of any async function, `await x` is transformed to | ||
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test | ||
// `hasOwn.call(value, "__await")` to determine if the yielded value is | ||
// meant to be awaited. | ||
exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}; | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type === "throw") { | ||
reject(record.arg); | ||
} else { | ||
var result = record.arg; | ||
var value = result.value; | ||
if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) { | ||
return PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}); | ||
} | ||
return PromiseImpl.resolve(value).then(function (unwrapped) { | ||
// When a yielded Promise is resolved, its final value becomes | ||
// the .value of the Promise<{value,done}> result for the | ||
// current iteration. | ||
result.value = unwrapped; | ||
resolve(result); | ||
}, function (error) { | ||
// If a rejected Promise was yielded, throw the rejection back | ||
// into the async generator function so it can be handled there. | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
} | ||
var previousPromise; | ||
function enqueue(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = // If enqueue has been called before, then we want to wait until | ||
// all previous Promises have been resolved before calling invoke, | ||
// so that results are always delivered in the correct order. If | ||
// enqueue has not been called before, then it is important to | ||
// call invoke immediately, without waiting on a callback to fire, | ||
// so that the async generator function has the opportunity to do | ||
// any necessary setup in a predictable way. This predictability | ||
// is why the Promise constructor synchronously invokes its | ||
// executor callback, and why async functions synchronously | ||
// execute code before the first await. Since we implement simple | ||
// async functions in terms of async generators, it is especially | ||
// important to get this right, even though it requires care. | ||
previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later | ||
// invocations of the iterator. | ||
callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} // Define the unified helper method that is used to implement .next, | ||
// .throw, and .return (see defineIteratorMethods). | ||
this._invoke = enqueue; | ||
} | ||
defineIteratorMethods(AsyncIterator.prototype); | ||
AsyncIterator.prototype[asyncIteratorSymbol] = function () { | ||
return this; | ||
}; | ||
exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of | ||
// AsyncIterator objects; they just return a Promise for the value of | ||
// the final result produced by the iterator. | ||
exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
if (PromiseImpl === void 0) PromiseImpl = Promise; | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator. | ||
: iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}; | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = GenStateSuspendedStart; | ||
return function invoke(method, arg) { | ||
if (state === GenStateExecuting) { | ||
throw new Error("Generator is already running"); | ||
} | ||
if (state === GenStateCompleted) { | ||
if (method === "throw") { | ||
throw arg; | ||
} // Be forgiving, per 25.3.3.3.3 of the spec: | ||
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume | ||
return doneResult(); | ||
} | ||
context.method = method; | ||
context.arg = arg; | ||
while (true) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if (context.method === "next") { | ||
// Setting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
context.sent = context._sent = context.arg; | ||
} else if (context.method === "throw") { | ||
if (state === GenStateSuspendedStart) { | ||
state = GenStateCompleted; | ||
throw context.arg; | ||
} | ||
context.dispatchException(context.arg); | ||
} else if (context.method === "return") { | ||
context.abrupt("return", context.arg); | ||
} | ||
state = GenStateExecuting; | ||
var record = tryCatch(innerFn, self, context); | ||
if (record.type === "normal") { | ||
// If an exception is thrown from innerFn, we leave state === | ||
// GenStateExecuting and loop back for another invocation. | ||
state = context.done ? GenStateCompleted : GenStateSuspendedYield; | ||
if (record.arg === ContinueSentinel) { | ||
continue; | ||
} | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} else if (record.type === "throw") { | ||
state = GenStateCompleted; // Dispatch the exception by looping back around to the | ||
// context.dispatchException(context.arg) call above. | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
} | ||
} | ||
}; | ||
} // Call delegate.iterator[context.method](context.arg) and handle the | ||
// result, either by returning a { value, done } result from the | ||
// delegate iterator, or by modifying context.method and context.arg, | ||
// setting context.delegate to null, and returning the ContinueSentinel. | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === undefined$1) { | ||
// A .throw or .return when the delegate iterator has no .throw | ||
// method always terminates the yield* loop. | ||
context.delegate = null; | ||
if (context.method === "throw") { | ||
// Note: ["return"] must be used for ES3 parsing compatibility. | ||
if (delegate.iterator["return"]) { | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
context.method = "return"; | ||
context.arg = undefined$1; | ||
maybeInvokeDelegate(delegate, context); | ||
if (context.method === "throw") { | ||
// If maybeInvokeDelegate(context) changed context.method from | ||
// "return" to "throw", let that override the TypeError below. | ||
return ContinueSentinel; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = new TypeError("The iterator does not provide a 'throw' method"); | ||
} | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
var info = record.arg; | ||
if (!info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if (info.done) { | ||
// Assign the result of the finished delegate to the temporary | ||
// variable specified by delegate.resultName (see delegateYield). | ||
context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield). | ||
context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the | ||
// exception, let the outer generator proceed normally. If | ||
// context.method was "next", forget context.arg since it has been | ||
// "consumed" by the delegate iterator. If context.method was | ||
// "return", allow the original .return call to continue in the | ||
// outer generator. | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
} else { | ||
// Re-yield the result returned by the delegate method. | ||
return info; | ||
} // The delegate iterator is finished, so forget it and continue with | ||
// the outer generator. | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} // Define Generator.prototype.{next,throw,return} in terms of the | ||
// unified ._invoke helper method. | ||
defineIteratorMethods(Gp); | ||
Gp[toStringTagSymbol] = "Generator"; // A Generator should always return itself as the iterator object when the | ||
// @@iterator function is called on it. Some browsers' implementations of the | ||
// iterator prototype chain incorrectly implement this, causing the Generator | ||
// object to not be returned from this call. This ensures that doesn't happen. | ||
// See https://github.com/facebook/regenerator/issues/274 for more details. | ||
Gp[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
Gp.toString = function () { | ||
return "[object Generator]"; | ||
}; | ||
function pushTryEntry(locs) { | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
if (1 in locs) { | ||
entry.catchLoc = locs[1]; | ||
} | ||
if (2 in locs) { | ||
entry.finallyLoc = locs[2]; | ||
entry.afterLoc = locs[3]; | ||
} | ||
this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal"; | ||
delete record.arg; | ||
entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
// The root entry object (effectively a try statement without a catch | ||
// or a finally block) gives us a place to store values thrown from | ||
// locations where there is no enclosing try statement. | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}]; | ||
tryLocsList.forEach(pushTryEntry, this); | ||
this.reset(true); | ||
} | ||
exports.keys = function (object) { | ||
var keys = []; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
keys.reverse(); // Rather than returning an object with a next method, we keep | ||
// things simple and return the next function itself. | ||
return function next() { | ||
while (keys.length) { | ||
var key = keys.pop(); | ||
if (key in object) { | ||
next.value = key; | ||
next.done = false; | ||
return next; | ||
} | ||
} // To avoid creating an additional object, we just hang the .value | ||
// and .done properties off the next function object itself. This | ||
// also ensures that the minifier will not anonymize the function. | ||
next.done = true; | ||
return next; | ||
}; | ||
}; | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) { | ||
return iteratorMethod.call(iterable); | ||
} | ||
if (typeof iterable.next === "function") { | ||
return iterable; | ||
} | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
while (++i < iterable.length) { | ||
if (hasOwn.call(iterable, i)) { | ||
next.value = iterable[i]; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
next.value = undefined$1; | ||
next.done = true; | ||
return next; | ||
}; | ||
return next.next = next; | ||
} | ||
} // Return an iterator with no values. | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
exports.values = values; | ||
function doneResult() { | ||
return { | ||
value: undefined$1, | ||
done: true | ||
}; | ||
} | ||
Context.prototype = { | ||
constructor: Context, | ||
reset: function reset(skipTempReset) { | ||
this.prev = 0; | ||
this.next = 0; // Resetting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
this.sent = this._sent = undefined$1; | ||
this.done = false; | ||
this.delegate = null; | ||
this.method = "next"; | ||
this.arg = undefined$1; | ||
this.tryEntries.forEach(resetTryEntry); | ||
if (!skipTempReset) { | ||
for (var name in this) { | ||
// Not sure about the optimal order of these conditions: | ||
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) { | ||
this[name] = undefined$1; | ||
} | ||
} | ||
} | ||
}, | ||
stop: function stop() { | ||
this.done = true; | ||
var rootEntry = this.tryEntries[0]; | ||
var rootRecord = rootEntry.completion; | ||
if (rootRecord.type === "throw") { | ||
throw rootRecord.arg; | ||
} | ||
return this.rval; | ||
}, | ||
dispatchException: function dispatchException(exception) { | ||
if (this.done) { | ||
throw exception; | ||
} | ||
var context = this; | ||
function handle(loc, caught) { | ||
record.type = "throw"; | ||
record.arg = exception; | ||
context.next = loc; | ||
if (caught) { | ||
// If the dispatched exception was caught by a catch block, | ||
// then let that catch block handle the exception normally. | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
return !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (entry.tryLoc === "root") { | ||
// Exception thrown outside of any try block that could handle | ||
// it, so set the completion value of the entire function to | ||
// throw the exception. | ||
return handle("end"); | ||
} | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"); | ||
var hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} else if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} | ||
} else if (hasFinally) { | ||
if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else { | ||
throw new Error("try statement without catch or finally"); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function abrupt(type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) { | ||
// Ignore the finally entry if control is not jumping to a | ||
// location outside the try/catch block. | ||
finallyEntry = null; | ||
} | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
record.type = type; | ||
record.arg = arg; | ||
if (finallyEntry) { | ||
this.method = "next"; | ||
this.next = finallyEntry.finallyLoc; | ||
return ContinueSentinel; | ||
} | ||
return this.complete(record); | ||
}, | ||
complete: function complete(record, afterLoc) { | ||
if (record.type === "throw") { | ||
throw record.arg; | ||
} | ||
if (record.type === "break" || record.type === "continue") { | ||
this.next = record.arg; | ||
} else if (record.type === "return") { | ||
this.rval = this.arg = record.arg; | ||
this.method = "return"; | ||
this.next = "end"; | ||
} else if (record.type === "normal" && afterLoc) { | ||
this.next = afterLoc; | ||
} | ||
return ContinueSentinel; | ||
}, | ||
finish: function finish(finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) { | ||
this.complete(entry.completion, entry.afterLoc); | ||
resetTryEntry(entry); | ||
return ContinueSentinel; | ||
} | ||
} | ||
}, | ||
"catch": function _catch(tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if (record.type === "throw") { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
return thrown; | ||
} | ||
} // The context.catch method must only be called with a location | ||
// argument that corresponds to a known catch block. | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function delegateYield(iterable, resultName, nextLoc) { | ||
this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}; | ||
if (this.method === "next") { | ||
// Deliberately forget the last sent value so that we don't | ||
// accidentally pass it on to the delegate. | ||
this.arg = undefined$1; | ||
} | ||
return ContinueSentinel; | ||
} | ||
}; // Regardless of whether this script is executing as a CommonJS module | ||
// or not, return the runtime object so that we can declare the variable | ||
// regeneratorRuntime in the outer scope, which allows this module to be | ||
// injected easily by `bin/regenerator --include-runtime script.js`. | ||
return exports; | ||
}( // If this script is executing as a CommonJS module, use module.exports | ||
// as the regeneratorRuntime namespace. Otherwise create a new empty | ||
// object. Either way, the resulting object will be used to initialize | ||
// the regeneratorRuntime variable at the top of this file. | ||
module.exports ); | ||
try { | ||
regeneratorRuntime = runtime; | ||
} catch (accidentalStrictMode) { | ||
// This module should not be running in strict mode, so the above | ||
// assignment should always work unless something is misconfigured. Just | ||
// in case runtime.js accidentally runs in strict mode, we can escape | ||
// strict mode using a global Function call. This could conceivably fail | ||
// if a Content Security Policy forbids using Function, but in that case | ||
// the proper solution is to fix the accidental strict mode problem. If | ||
// you've misconfigured your bundler to force strict mode and applied a | ||
// CSP to forbid Function, and you're not willing to fix either of those | ||
// problems, please detail your unique predicament in a GitHub issue. | ||
Function("r", "regeneratorRuntime = r")(runtime); | ||
} | ||
}); | ||
self.ASC_TARGET = 0; | ||
// 1 for JS, 2 for WASM | ||
var solverType; | ||
// Puzzle consisting of zeroes | ||
var setSolver; | ||
var solver = new Promise(function (resolve) { return setSolver = resolve; }); | ||
var hasStarted = false; | ||
self.onerror = function (evt) { | ||
self.postMessage({ | ||
type: "error", | ||
error: JSON.stringify(evt), | ||
}); | ||
}; | ||
self.onmessage = function (evt) { | ||
var data = evt.data; | ||
var type = data.type; | ||
if (type === "module") { | ||
getWasmSolver(data.module).then(function (s) { | ||
self.postMessage({ | ||
type: "ready", | ||
solver: SOLVER_TYPE_JS, | ||
}); | ||
solverType = SOLVER_TYPE_JS; | ||
setSolver(s); | ||
}); | ||
} | ||
else if (type === "js") { | ||
getJSSolver().then(function (s) { | ||
self.postMessage({ | ||
type: "ready", | ||
solver: SOLVER_TYPE_WASM, | ||
}); | ||
solverType = SOLVER_TYPE_WASM; | ||
setSolver(s); | ||
}); | ||
} | ||
else if (type === "start") { | ||
if (hasStarted) { | ||
return; | ||
} | ||
hasStarted = true; | ||
solver.then(function (solve) { | ||
setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var solverStartTime, totalH, starts, solutionBuffer, i, startTime, solution, b, _a, s, hash, view, h, t, totalTime, doneMessage; | ||
return __generator(this, function (_b) { | ||
self.postMessage({ | ||
type: "started", | ||
}); | ||
solverStartTime = Date.now(); | ||
totalH = 0; | ||
starts = getPuzzleSolverInputs(data.buffer, data.n); | ||
solutionBuffer = new Uint8Array(8 * data.n); | ||
// Note: var instead of const for IE11 compat | ||
for (i = 0; i < starts.length; i++) { | ||
startTime = Date.now(); | ||
solution = void 0; | ||
for (b = 0; b < 256; b++) { // In the very unlikely case no solution is found we should try again | ||
starts[i][123] = b; | ||
_a = solve(starts[i], data.threshold), s = _a[0], hash = _a[1]; | ||
if (hash.length === 0) { | ||
// This should be very small in probability unless you set the difficulty much too high. | ||
// Also this means 2^32 puzzles were evaluated, which takes a while in a browser! | ||
// As we try 256 times, this is not fatal | ||
console.warn("FC: Internal error or no solution found"); | ||
continue; | ||
} | ||
solution = s; | ||
break; | ||
} | ||
view = new DataView(solution.slice(-4).buffer); | ||
h = view.getUint32(0, true); | ||
t = (Date.now() - startTime) / 1000; | ||
totalH += h; | ||
solutionBuffer.set(solution.slice(-8), i * 8); // The last 8 bytes are the solution nonce | ||
self.postMessage({ | ||
type: "progress", | ||
n: data.n, | ||
h: h, | ||
t: t, | ||
i: i | ||
}); | ||
// For the synchronous worker, so that the UI can update | ||
} | ||
totalTime = (Date.now() - solverStartTime) / 1000; | ||
doneMessage = { | ||
type: "done", | ||
solution: solutionBuffer, | ||
h: totalH, | ||
t: totalTime, | ||
diagnostics: createDiagnosticsBuffer(solverType, totalTime), | ||
}; | ||
self.postMessage(doneMessage); | ||
// @ts-ignore | ||
self.close(); | ||
return [2 /*return*/]; | ||
}); | ||
}); }, 0); | ||
}); | ||
} | ||
}; | ||
}()); |
{ | ||
"name": "friendly-challenge", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "The client code used for FriendlyCaptcha (widget html, styling and webworker solver)", | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"lint": "eslint src/**/*.ts test/**/*.ts", | ||
"prebuild": "rimraf dist", | ||
"build": "rollup -c rollup.config.ts && cp src/html/index.html dist/index.html", | ||
"start": "rollup -c rollup.config.ts -w", | ||
"format": "prettier --write '**/*.{ts,js,css,json,md}'", | ||
"test:prod": "npm run lint && npm run test -- --no-cache && jest --config=jest-browser.config.js --no-cache" | ||
"test": "nightwatch", | ||
"test:prod": "npm run lint && npm run test" | ||
}, | ||
@@ -18,11 +19,23 @@ "files": [ | ||
"devDependencies": { | ||
"@babel/cli": "^7.10.4", | ||
"@babel/core": "^7.10.4", | ||
"@babel/plugin-transform-runtime": "^7.10.4", | ||
"@babel/plugin-transform-template-literals": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@rollup/plugin-babel": "^5.0.4", | ||
"@rollup/plugin-commonjs": "^13.0.0", | ||
"@rollup/plugin-node-resolve": "^8.0.0", | ||
"@rollup/plugin-wasm": "^5.0.0", | ||
"@types/jest": "^25.2.3", | ||
"@types/nightwatch": "^1.1.6", | ||
"@types/node": "^14.0.9", | ||
"@typescript-eslint/eslint-plugin": "^2.21.0", | ||
"@typescript-eslint/parser": "^2.21.0", | ||
"babel-plugin-transform-modules-iife": "^1.0.0", | ||
"chromedriver": "^83.0.0", | ||
"clean-css": "^4.2.3", | ||
"eslint": "^6.8.0", | ||
"geckodriver": "^1.19.1", | ||
"jest": "^26.0.1", | ||
"nightwatch": "^1.3.6", | ||
"prettier": "^1.18.2", | ||
@@ -35,8 +48,12 @@ "rimraf": "^3.0.2", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"selenium-webdriver": "^4.0.0-alpha.7", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^3.5.3" | ||
"typescript": "^3.5.3", | ||
"webpack-cli": "^3.3.12" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime-corejs3": "^7.10.4", | ||
"core-js": "^3.6.5", | ||
"friendly-pow": "0.0.2" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142855
1795
3
32
5
2
+ Addedcore-js@^3.6.5
+ Added@babel/runtime-corejs3@7.26.0(transitive)
+ Addedcore-js@3.39.0(transitive)
+ Addedcore-js-pure@3.39.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)