rwadurian/tools/mnemonic-test/node_modules/hash-wasm/dist/crc32.umd.min.js

8 lines
7.4 KiB
JavaScript

/*!
* hash-wasm (https://www.npmjs.com/package/hash-wasm)
* (c) Dani Biro
* @license MIT
*/
!function(e,A){"object"==typeof exports&&"undefined"!=typeof module?A(exports):"function"==typeof define&&define.amd?define(["exports"],A):A((e="undefined"!=typeof globalThis?globalThis:e||self).hashwasm=e.hashwasm||{})}(this,(function(e){"use strict";var A,t={name:"crc32",data:"AGFzbQEAAAABEQRgAAF/YAF/AGAAAGACf38AAwgHAAEBAQIAAwUEAQECAgYOAn8BQZDJBQt/AEGACAsHcAgGbWVtb3J5AgAOSGFzaF9HZXRCdWZmZXIAAAlIYXNoX0luaXQAAgtIYXNoX1VwZGF0ZQADCkhhc2hfRmluYWwABA1IYXNoX0dldFN0YXRlAAUOSGFzaF9DYWxjdWxhdGUABgpTVEFURV9TSVpFAwEKkggHBQBBgAkLwwMBA39BgIkBIQFBACECA0AgAUEAQQBBAEEAQQBBAEEAQQAgAkEBcWsgAHEgAkEBdnMiA0EBcWsgAHEgA0EBdnMiA0EBcWsgAHEgA0EBdnMiA0EBcWsgAHEgA0EBdnMiA0EBcWsgAHEgA0EBdnMiA0EBcWsgAHEgA0EBdnMiA0EBcWsgAHEgA0EBdnMiA0EBcWsgAHEgA0EBdnM2AgAgAUEEaiEBIAJBAWoiAkGAAkcNAAtBACEAA0AgAEGEkQFqIABBhIkBaigCACICQf8BcUECdEGAiQFqKAIAIAJBCHZzIgI2AgAgAEGEmQFqIAJB/wFxQQJ0QYCJAWooAgAgAkEIdnMiAjYCACAAQYShAWogAkH/AXFBAnRBgIkBaigCACACQQh2cyICNgIAIABBhKkBaiACQf8BcUECdEGAiQFqKAIAIAJBCHZzIgI2AgAgAEGEsQFqIAJB/wFxQQJ0QYCJAWooAgAgAkEIdnMiAjYCACAAQYS5AWogAkH/AXFBAnRBgIkBaigCACACQQh2cyICNgIAIABBhMEBaiACQf8BcUECdEGAiQFqKAIAIAJBCHZzNgIAIABBBGoiAEH8B0cNAAsLJwACQEEAKAKAyQEgAEYNACAAEAFBACAANgKAyQELQQBBADYChMkBC4gDAQN/QQAoAoTJAUF/cyEBQYAJIQICQCAAQQhJDQBBgAkhAgNAIAJBBGooAgAiA0EOdkH8B3FBgJEBaigCACADQRZ2QfwHcUGAiQFqKAIAcyADQQZ2QfwHcUGAmQFqKAIAcyADQf8BcUECdEGAoQFqKAIAcyACKAIAIAFzIgFBFnZB/AdxQYCpAWooAgBzIAFBDnZB/AdxQYCxAWooAgBzIAFBBnZB/AdxQYC5AWooAgBzIAFB/wFxQQJ0QYDBAWooAgBzIQEgAkEIaiECIABBeGoiAEEHSw0ACwsCQCAARQ0AAkACQCAAQQFxDQAgACEDDAELIAFB/wFxIAItAABzQQJ0QYCJAWooAgAgAUEIdnMhASACQQFqIQIgAEF/aiEDCyAAQQFGDQADQCABQf8BcSACLQAAc0ECdEGAiQFqKAIAIAFBCHZzIgFB/wFxIAJBAWotAABzQQJ0QYCJAWooAgAgAUEIdnMhASACQQJqIQIgA0F+aiIDDQALC0EAIAFBf3M2AoTJAQsyAQF/QQBBACgChMkBIgBBGHQgAEGA/gNxQQh0ciAAQQh2QYD+A3EgAEEYdnJyNgKACQsGAEGEyQELWQACQEEAKAKAyQEgAUYNACABEAFBACABNgKAyQELQQBBADYChMkBIAAQA0EAQQAoAoTJASIBQRh0IAFBgP4DcUEIdHIgAUEIdkGA/gNxIAFBGHZycjYCgAkLCwsBAEGACAsEBAAAAA==",hash:"d2eba587"};function n(e,A,t,n){return new(t||(t=Promise))((function(r,o){function i(e){try{a(n.next(e))}catch(e){o(e)}}function s(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var A;e.done?r(e.value):(A=e.value,A instanceof t?A:new t((function(e){e(A)}))).then(i,s)}a((n=n.apply(e,A||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class r{constructor(){this.mutex=Promise.resolve()}lock(){let e=()=>{};return this.mutex=this.mutex.then((()=>new Promise(e))),new Promise((A=>{e=A}))}dispatch(e){return n(this,void 0,void 0,(function*(){const A=yield this.lock();try{return yield Promise.resolve(e())}finally{A()}}))}}const o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,i=null!==(A=o.Buffer)&&void 0!==A?A:null,s=o.TextEncoder?new o.TextEncoder:null;function a(e,A){return(15&e)+(e>>6|e>>3&8)<<4|(15&A)+(A>>6|A>>3&8)}const c="a".charCodeAt(0)-10,l="0".charCodeAt(0);function g(e,A,t){let n=0;for(let r=0;r<t;r++){let t=A[r]>>>4;e[n++]=t>9?t+c:t+l,t=15&A[r],e[n++]=t>9?t+c:t+l}return String.fromCharCode.apply(null,e)}const f=null!==i?e=>{if("string"==typeof e){const A=i.from(e,"utf8");return new Uint8Array(A.buffer,A.byteOffset,A.length)}if(i.isBuffer(e))return new Uint8Array(e.buffer,e.byteOffset,e.length);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")}:e=>{if("string"==typeof e)return s.encode(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Invalid data type!")},B="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=new Uint8Array(256);for(let e=0;e<B.length;e++)h[B.charCodeAt(e)]=e;function u(e){const A=function(e){let A=Math.floor(.75*e.length);const t=e.length;return"="===e[t-1]&&(A-=1,"="===e[t-2]&&(A-=1)),A}(e),t=e.length,n=new Uint8Array(A);let r=0;for(let A=0;A<t;A+=4){const t=h[e.charCodeAt(A)],o=h[e.charCodeAt(A+1)],i=h[e.charCodeAt(A+2)],s=h[e.charCodeAt(A+3)];n[r]=t<<2|o>>4,r+=1,n[r]=(15&o)<<4|i>>2,r+=1,n[r]=(3&i)<<6|63&s,r+=1}return n}const d=16384,E=new r,Q=new Map;function y(e,A){return n(this,void 0,void 0,(function*(){let t=null,r=null,o=!1;if("undefined"==typeof WebAssembly)throw new Error("WebAssembly is not supported in this environment!");const i=()=>new DataView(t.exports.memory.buffer).getUint32(t.exports.STATE_SIZE,!0),s=E.dispatch((()=>n(this,void 0,void 0,(function*(){if(!Q.has(e.name)){const A=u(e.data),t=WebAssembly.compile(A);Q.set(e.name,t)}const A=yield Q.get(e.name);t=yield WebAssembly.instantiate(A,{})})))),c=(e=null)=>{o=!0,t.exports.Hash_Init(e)},l=e=>{if(!o)throw new Error("update() called before init()");(e=>{let A=0;for(;A<e.length;){const n=e.subarray(A,A+d);A+=n.length,r.set(n),t.exports.Hash_Update(n.length)}})(f(e))},B=new Uint8Array(2*A),h=(e,n=null)=>{if(!o)throw new Error("digest() called before init()");return o=!1,t.exports.Hash_Final(n),"binary"===e?r.slice(0,A):g(B,r,A)},y=e=>"string"==typeof e?e.length<4096:e.byteLength<d;let C=y;switch(e.name){case"argon2":case"scrypt":C=()=>!0;break;case"blake2b":case"blake2s":C=(e,A)=>A<=512&&y(e);break;case"blake3":C=(e,A)=>0===A&&y(e);break;case"xxhash64":case"xxhash3":case"xxhash128":case"crc64":C=()=>!1}return yield(()=>n(this,void 0,void 0,(function*(){t||(yield s);const e=t.exports.Hash_GetBuffer(),A=t.exports.memory.buffer;r=new Uint8Array(A,e,d)})))(),{getMemory:()=>r,writeMemory:(e,A=0)=>{r.set(e,A)},getExports:()=>t.exports,setMemorySize:e=>{t.exports.Hash_SetMemorySize(e);const A=t.exports.Hash_GetBuffer(),n=t.exports.memory.buffer;r=new Uint8Array(n,A,e)},init:c,update:l,digest:h,save:()=>{if(!o)throw new Error("save() can only be called after init() and before digest()");const A=t.exports.Hash_GetState(),n=i(),r=t.exports.memory.buffer,s=new Uint8Array(r,A,n),c=new Uint8Array(4+n);return function(e,A){const t=A.length>>1;for(let n=0;n<t;n++){const t=n<<1;e[n]=a(A.charCodeAt(t),A.charCodeAt(t+1))}}(c,e.hash),c.set(s,4),c},load:A=>{if(!(A instanceof Uint8Array))throw new Error("load() expects an Uint8Array generated by save()");const n=t.exports.Hash_GetState(),r=i(),s=4+r,c=t.exports.memory.buffer;if(A.length!==s)throw new Error(`Bad state length (expected ${s} bytes, got ${A.length})`);if(!function(e,A){if(e.length!==2*A.length)return!1;for(let t=0;t<A.length;t++){const n=t<<1;if(A[t]!==a(e.charCodeAt(n),e.charCodeAt(n+1)))return!1}return!0}(e.hash,A.subarray(0,4)))throw new Error("This state was written by an incompatible hash implementation");const l=A.subarray(4);new Uint8Array(c,n,r).set(l),o=!0},calculate:(e,n=null,o=null)=>{if(!C(e,n))return c(n),l(e),h("hex",o);const i=f(e);return r.set(i),t.exports.Hash_Calculate(i.length,n,o),g(B,r,A)},hashLength:A}}))}const C=new r;let I=null;function w(e){return!Number.isInteger(e)||e<0||e>4294967295?new Error("Polynomial must be a valid 32-bit long unsigned integer"):null}e.crc32=function(e,A=3988292384){if(w(A))return Promise.reject(w(A));if(null===I)return function(e,A,t){return n(this,void 0,void 0,(function*(){const n=yield e.lock(),r=yield y(A,t);return n(),r}))}(C,t,4).then((t=>(I=t,I.calculate(e,A))));try{const t=I.calculate(e,A);return Promise.resolve(t)}catch(e){return Promise.reject(e)}},e.createCRC32=function(e=3988292384){return w(e)?Promise.reject(w(e)):y(t,4).then((A=>{A.init(e);const t={init:()=>(A.init(e),t),update:e=>(A.update(e),t),digest:e=>A.digest(e),save:()=>A.save(),load:e=>(A.load(e),t),blockSize:4,digestSize:4};return t}))}}));