functionnumber(n){if(!Number.isSafeInteger(n)||n<0)thrownewError(`Wrong positive integer: ${n}`)}functionbytes(b,...lengths){if(!(binstanceofUint8Array))thrownewError("Expected Uint8Array");if(lengths.length>0&&!lengths.includes(b.length))thrownewError(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`)}functionexists(instance,checkFinished=true){if(instance.destroyed)thrownewError("Hash instance has been destroyed");if(checkFinished&&instance.finished)thrownewError("Hash#digest() has already been called")}functionoutput(out,instance){bytes(out);constmin=instance.outputLen;if(out.length<min){thrownewError(`digestInto() expects output buffer of length at least ${min}`)}}constu8a=a=>ainstanceofUint8Array;constu32=arr=>newUint32Array(arr.buffer,arr.byteOffset,Math.floor(arr.byteLength/4));constisLE=newUint8Array(newUint32Array([287454020]).buffer)[0]===68;if(!isLE)thrownewError("Non little-endian hardware is not supported");functionutf8ToBytes(str){if(typeofstr!=="string")thrownewError(`utf8ToBytes expected string, got ${typeofstr}`);returnnewUint8Array((newTextEncoder).encode(str))}functiontoBytes(data){if(typeofdata==="string")data=utf8ToBytes(data);if(!u8a(data))thrownewError(`expected Uint8Array, got ${typeofdata}`);returndata}classHash{clone(){returnthis._cloneInto()}}functionwrapConstructor(hashCons){consthashC=msg=>hashCons().update(toBytes(msg)).digest();consttmp=hashCons();hashC.outputLen=tmp.outputLen;hashC.blockLen=tmp.blockLen;hashC.create=()=>hashCons();returnhashC}constU32_MASK64=BigInt(2**32-1);const_32n=BigInt(32);functionfromBig(n,le=false){if(le)return{h:Number(n&U32_MASK64),l:Number(n>>_32n&U32_MASK64)};return{h:Number(n>>_32n&U32_MASK64)|0,l:Number(n&U32_MASK64)|0}}functionsplit(lst,le=false){letAh=newUint32Array(lst.length);letAl=newUint32Array(lst.length);for(leti=0;i<lst.length;i++){const{h,l}=fromBig(lst[i],le);[Ah[i],Al[i]]=[h,l]}return[Ah,Al]}constrotlSH=(h,l,s)=>h<<s|l>>>32-s;constrotlSL=(h,l,s)=>l<<s|h>>>32-s;constrotlBH=(h,l,s)=>l<<s-32|h>>>64-s;constrotlBL=(h,l,s)=>h<<s-32|l>>>64-s;constversion="6.11.1";functioncheckType(value,type,name){consttypes=type.split("|").map(t=>t.trim());for(leti=0;i<types.length;i++){switch(type){case"any":return;case"bigint":case"boolean":case"number":case"string":if(typeofvalue===type){return}}}consterror=newError(`invalid value for type ${type}`);error.code="INVALID_ARGUMENT";error.argument=`value.${name}`;error.value=value;throwerror}functiondefineProperties(target,values,types){for(letkeyinvalues){letvalue=values[key];consttype=types?types[key]:null;if(type){checkType(value,type,key)}Object.defineProperty(target,key,{enumerable:true,value:value,writable:false})}}functionstringify(value){if(value==null){return"null"}if(Array.isArray(value)){return"[ "+value.map(stringify).join(", ")+" ]"}if(valueinstanceofUint8Array){constHEX="0123456789abcdef";letresult="0x";for(leti=0;i<value.length;i++){result+=HEX[value[i]>>4];result+=HEX[value[i]&15]}returnresult}if(typeofvalue==="object"&&typeofvalue.toJSON==="function"){returnstringify(value.toJSON())}switch(typeofvalue){case"boolean":case"symbol":returnvalue.toString();case"bigint":returnBigInt(value).toString();case"number":returnvalue.toString();case"string":returnJSON.stringify(value);case"object":{constkeys=Object.keys(value);keys.sort();return"{ "+keys.map(k=>`${stringify(k)}: ${stringify(value[k])}`).join(", ")+" }"}}return`[ COULD NOT SERIALIZE ]`}functionmakeError(message,code,info){letshortMessage=message;{constdetails=[];if(info){if("message"ininfo||"code"ininfo||"name"ininfo){thrownewError(`value will overwrite populated values: ${stringify(info)}`)}for(constkeyininfo){if(key==="shortMessage"){continue}constvalue=info[key];details.push(key+"="+stringify(value))}}details.push(`code=${code}`);details.push(`version=${version}`);if(details.length){message+=" ("+details.join(", ")+")"}}leterror;switch(code){case"INVALID_ARGUMENT":error=newTypeError(message);break;case"NUMERIC_FAULT":case"BUFF