/* esm.sh - @noble/hashes@1.8.0/utils */
import{crypto as c}from"./crypto.mjs";function m(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function x(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function u(t,...e){if(!m(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function T(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");x(t.outputLen),x(t.blockLen)}function S(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function I(t,e){u(t);let n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function V(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function _(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function j(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function D(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function F(t,e){return t<<32-e|t>>>e}function R(t,e){return t<<e|t>>>32-e>>>0}var w=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function d(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}var A=w?t=>t:t=>d(t),C=A;function L(t){for(let e=0;e<t.length;e++)t[e]=d(t[e]);return t}var W=w?t=>t:L,g=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",E=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function X(t){if(u(t),g)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=E[t[n]];return e}var f={_0:48,_9:57,A:65,F:70,a:97,f:102};function l(t){if(t>=f._0&&t<=f._9)return t-f._0;if(t>=f.A&&t<=f.F)return t-(f.A-10);if(t>=f.a&&t<=f.f)return t-(f.a-10)}function v(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(g)return Uint8Array.fromHex(t);let e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let r=new Uint8Array(n);for(let o=0,i=0;o<n;o++,i+=2){let s=l(t.charCodeAt(i)),a=l(t.charCodeAt(i+1));if(s===void 0||a===void 0){let b=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+b+'" at index '+i)}r[o]=s*16+a}return r}var U=async()=>{};async function M(t,e,n){let r=Date.now();for(let o=0;o<t;o++){n(o);let i=Date.now()-r;i>=0&&i<e||(await U(),r+=i)}}function h(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function N(t){return new TextDecoder().decode(t)}function p(t){return typeof t=="string"&&(t=h(t)),u(t),t}function q(t){return typeof t=="string"&&(t=h(t)),u(t),t}function z(...t){let e=0;for(let r=0;r<t.length;r++){let o=t[r];u(o),e+=o.length}let n=new Uint8Array(e);for(let r=0,o=0;r<t.length;r++){let i=t[r];n.set(i,o),o+=i.length}return n}function G(t,e){if(e!==void 0&&{}.toString.call(e)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(t,e)}var y=class{};function B(t){let e=r=>t().update(p(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function H(t){let e=(r,o)=>t(o).update(p(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function O(t){let e=(r,o)=>t(o).update(p(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}var J=B,K=H,P=O;function Q(t=32){if(c&&typeof c.getRandomValues=="function")return c.getRandomValues(new Uint8Array(t));if(c&&typeof c.randomBytes=="function")return Uint8Array.from(c.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}export{y as Hash,u as abytes,S as aexists,T as ahash,x as anumber,I as aoutput,M as asyncLoop,d as byteSwap,L as byteSwap32,C as byteSwapIfBE,X as bytesToHex,N as bytesToUtf8,G as checkOpts,j as clean,z as concatBytes,B as createHasher,H as createOptHasher,D as createView,O as createXOFer,v as hexToBytes,m as isBytes,w as isLE,q as kdfInputToBytes,U as nextTick,Q as randomBytes,R as rotl,F as rotr,W as swap32IfBE,A as swap8IfBE,p as toBytes,_ as u32,V as u8,h as utf8ToBytes,J as wrapConstructor,K as wrapConstructorWithOpts,P as wrapXOFConstructorWithOpts};
/*! Bundled license information:

@noble/hashes/esm/utils.js:
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
*/
//# sourceMappingURL=utils.mjs.map