!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).scryptPbkdf={})}(this,(function(e){"use strict";const r=function(e){function r(e,r){return e<>>32-r}const t=e.slice(0);for(let e=8;e>0;e-=2)t[4]^=r(t[0]+t[12],7),t[8]^=r(t[4]+t[0],9),t[12]^=r(t[8]+t[4],13),t[0]^=r(t[12]+t[8],18),t[9]^=r(t[5]+t[1],7),t[13]^=r(t[9]+t[5],9),t[1]^=r(t[13]+t[9],13),t[5]^=r(t[1]+t[13],18),t[14]^=r(t[10]+t[6],7),t[2]^=r(t[14]+t[10],9),t[6]^=r(t[2]+t[14],13),t[10]^=r(t[6]+t[2],18),t[3]^=r(t[15]+t[11],7),t[7]^=r(t[3]+t[15],9),t[11]^=r(t[7]+t[3],13),t[15]^=r(t[11]+t[7],18),t[1]^=r(t[0]+t[3],7),t[2]^=r(t[1]+t[0],9),t[3]^=r(t[2]+t[1],13),t[0]^=r(t[3]+t[2],18),t[6]^=r(t[5]+t[4],7),t[7]^=r(t[6]+t[5],9),t[4]^=r(t[7]+t[6],13),t[5]^=r(t[4]+t[7],18),t[11]^=r(t[10]+t[9],7),t[8]^=r(t[11]+t[10],9),t[9]^=r(t[8]+t[11],13),t[10]^=r(t[9]+t[8],18),t[12]^=r(t[15]+t[14],7),t[13]^=r(t[12]+t[15],9),t[14]^=r(t[13]+t[12],13),t[15]^=r(t[14]+t[13],18);for(let r=0;r<16;r++)e[r]=t[r]+e[r]},t=function(e,r){for(let t=0;t>1);if(s)for(let r=0;r<16;r++)e[u+r]=i[r];else for(let e=0;e<16;e++)a[u+e]=i[e];s=!s}const f=16*n;for(let r=0;r{o in i||u(new RangeError(`Valid hash algorithm values are any of ${Object.keys(i).toString()}`)),"string"==typeof e?e=(new TextEncoder).encode(e):e instanceof ArrayBuffer?e=new Uint8Array(e):ArrayBuffer.isView(e)||u(RangeError("P should be string, ArrayBuffer, TypedArray, DataView")),"string"==typeof r?r=(new TextEncoder).encode(r):r instanceof ArrayBuffer?r=new Uint8Array(r):ArrayBuffer.isView(r)?r=new Uint8Array(r.buffer,r.byteOffset,r.byteLength):u(RangeError("S should be string, ArrayBuffer, TypedArray, DataView")),crypto.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]).then((c=>{const l={name:"PBKDF2",hash:o,salt:r,iterations:t};crypto.subtle.deriveBits(l,c,8*n).then((e=>a(e)),(c=>{(async function(e,r,t,n,o){if(!(o in i))throw new RangeError(`Valid hash algorithm values are any of ${Object.keys(i).toString()}`);if(!Number.isInteger(t)||t<=0)throw new RangeError("c must be a positive integer");const a=i[o].outputLength;if(!Number.isInteger(n)||n<=0||n>=(2**32-1)*a)throw new RangeError("dkLen must be a positive integer < (2 ** 32 - 1) * hLen");const u=Math.ceil(n/a),c=n-(u-1)*a,l=new Array(u);0===e.byteLength&&(e=new Uint8Array(i[o].blockSize));const y=await crypto.subtle.importKey("raw",e,{name:"HMAC",hash:{name:o}},!0,["sign"]),g=async function(e,r){const t=await crypto.subtle.sign("HMAC",e,r);return new Uint8Array(t)};for(let e=0;ea(e)),(e=>u(e)))}))}),(e=>u(e)))}))}function s(...e){const r=e.reduce(((e,r)=>e+r.length),0);if(0===e.length)throw new RangeError("Cannot concat no arrays");const t=new Uint8Array(r);let n=0;for(const r of e)t.set(r,n),n+=r.length;return t}function f(e,r){for(let t=0;t= 0");return 0===e?new ArrayBuffer(0):crypto.getRandomValues(new Uint8Array(e)).buffer},e.scrypt=async function(e,r,t,n){if("string"==typeof e)e=(new TextEncoder).encode(e);else if(e instanceof ArrayBuffer)e=new Uint8Array(e);else if(!ArrayBuffer.isView(e))throw RangeError("P should be string, ArrayBuffer, TypedArray, DataView");if("string"==typeof r)r=(new TextEncoder).encode(r);else if(r instanceof ArrayBuffer)r=new Uint8Array(r);else if(!ArrayBuffer.isView(r))throw RangeError("S should be string, ArrayBuffer, TypedArray, DataView");if(!Number.isInteger(t)||t<=0||t>137438953440)throw RangeError("dkLen is the intended output length in octets of the derived key; a positive integer less than or equal to (2^32 - 1) * hLen where hLen is 32");const i=void 0!==n&&void 0!==n.N?n.N:131072,s=void 0!==n&&void 0!==n.r?n.r:8,f=void 0!==n&&void 0!==n.p?n.p:1;if(!Number.isInteger(i)||i<=0||0!=(i&i-1))throw RangeError("N must be a power of 2");if(!Number.isInteger(s)||s<=0||!Number.isInteger(f)||f<=0||f*s>1073741823.75)throw RangeError("Parallelization parameter p and blocksize parameter r must be positive integers satisfying p ≤ (2^32− 1) * hLen / MFLen where hLen is 32 and MFlen is 128 * r.");const u=await a(e,r,1,128*f*s),c=new Uint32Array(u);for(let e=0;e