text: /*! noble-hashes - MIT License (c) 2021 Paul Miller (paulmillr.com) */
  // The import here is via the package name. This is to ensure
  // that exports mapping/resolution does fall into place.
  import { crypto } from '@noble/hashes/lib/crypto';
  // Cast array to different type
  export const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
  export const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
  // Cast array to view
  export const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
  // The rotate right (circular right shift) operation for uint32
  export const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
  export const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
  // There is almost no big endian hardware, but js typed arrays uses platform specific endianess.
  // So, just to be sure not to corrupt anything.
  if (!isLE)
      throw new Error('Non little-endian hardware is not supported');
  const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
  export function bytesToHex(uint8a) {
      // pre-caching chars could speed this up 6x.
      let hex = '';
      for (let i = 0; i < uint8a.length; i++) {
          hex += hexes[uint8a[i]];
      }
      return hex;
  }
  // Currently avoid insertion of polyfills with packers (browserify/webpack/etc)
  // But setTimeout is pretty slow, maybe worth to investigate howto do minimal polyfill here
  export const nextTick = (() => {
      const nodeRequire = typeof module !== 'undefined' &&
          typeof module.require === 'function' &&
          module.require.bind(module);
      try {
          if (nodeRequire) {
              const { setImmediate } = nodeRequire('timers');
              return () => new Promise((resolve) => setImmediate(resolve));
          }
      }
      catch (e) { }
      return () => new Promise((resolve) => setTimeout(resolve, 0));
  })();
  // Returns control to thread each 'tick' ms to avoid blocking
  export async function asyncLoop(iters, tick, cb) {
      let ts = Date.now();
      for (let i = 0; i < iters; i++) {
          cb(i);
          // Date.now() is not monotonic, so in case if clock goes backwards we return return control too
          const diff = Date.now() - ts;
          if (diff >= 0 && diff < tick)
              continue;
          await nextTick();
          ts += diff;
      }
  }
  export function toBytes(data) {
      if (typeof data === 'string')
          data = new TextEncoder().encode(data);
      if (!(data instanceof Uint8Array))
          throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
      return data;
  }
  export function assertNumber(n) {
      if (!Number.isSafeInteger(n))
          throw new Error(`Wrong integer: ${n}`);
  }
  export function assertBool(b) {
      if (typeof b !== 'boolean') {
          throw new Error(`Expected boolean, not ${b}`);
      }
  }
  export function assertHash(hash) {
      if (typeof hash !== 'function' || typeof hash.init !== 'function')
          throw new Error('Hash should be wrapped by utils.wrapConstructor');
      assertNumber(hash.outputLen);
      assertNumber(hash.blockLen);
  }
  // For runtime check if class implements interface
  export class Hash {
      // Safe version that clones internal state
      clone() {
          return this._cloneInto();
      }
  }
  // Check if object doens't have custom constructor (like Uint8Array/Array)
  const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
  export function checkOpts(def, _opts) {
      if (_opts !== undefined && (typeof _opts !== 'object' || !isPlainObject(_opts)))
          throw new TypeError('Options should be object or undefined');
      const opts = Object.assign(def, _opts);
      return opts;
  }
  export function wrapConstructor(hashConstructor) {
      const hashC = (message) => hashConstructor().update(toBytes(message)).digest();
      const tmp = hashConstructor();
      hashC.outputLen = tmp.outputLen;
      hashC.blockLen = tmp.blockLen;
      hashC.create = () => hashConstructor();
      hashC.init = hashC.create;
      return hashC;
  }
  export function wrapConstructorWithOpts(hashCons) {
      const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
      const tmp = hashCons({});
      hashC.outputLen = tmp.outputLen;
      hashC.blockLen = tmp.blockLen;
      hashC.create = (opts) => hashCons(opts);
      hashC.init = hashC.create;
      return hashC;
  }
  export function randomBytes(bytesLength = 32) {
      if (crypto.web) {
          return crypto.web.getRandomValues(new Uint8Array(bytesLength));
      }
      else if (crypto.node) {
          return new Uint8Array(crypto.node.randomBytes(bytesLength).buffer);
      }
      else {
          throw new Error("The environment doesn't have randomBytes function");
      }
  }
  