import { cu as L, cR as T, cS as g, c5 as k, cT as I, bx as F, c3 as R, cy as S } from "./address-CrYNZ_Nj.mjs";
function P(n, t, e, c) {
  T(n);
  const i = g({ dkLen: 32, asyncTick: 10 }, c), { c: u, dkLen: s, asyncTick: o } = i;
  if (k(u), k(s), k(o), u < 1)
    throw new Error("iterations (c) should be >= 1");
  const d = I(t), a = I(e), f = new Uint8Array(s), l = F.create(n, d), r = l._cloneInto().update(a);
  return { c: u, dkLen: s, asyncTick: o, DK: f, PRF: l, PRFSalt: r };
}
function v(n, t, e, c, i) {
  return n.destroy(), t.destroy(), c && c.destroy(), R(i), e;
}
function A(n, t, e, c) {
  const { c: i, dkLen: u, DK: s, PRF: o, PRFSalt: d } = P(n, t, e, c);
  let a;
  const f = new Uint8Array(4), l = L(f), r = new Uint8Array(o.outputLen);
  for (let w = 1, p = 0; p < u; w++, p += o.outputLen) {
    const y = s.subarray(p, p + o.outputLen);
    l.setInt32(0, w, !1), (a = d._cloneInto(a)).update(f).digestInto(r), y.set(r.subarray(0, y.length));
    for (let h = 1; h < i; h++) {
      o._cloneInto(a).update(r).digestInto(r);
      for (let m = 0; m < y.length; m++)
        y[m] ^= r[m];
    }
  }
  return v(o, d, s, a, r);
}
/*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */
function b(n) {
  if (typeof n != "string")
    throw new TypeError("invalid mnemonic type: " + typeof n);
  return n.normalize("NFKD");
}
function D(n) {
  const t = b(n), e = t.split(" ");
  if (![12, 15, 18, 21, 24].includes(e.length))
    throw new Error("Invalid mnemonic");
  return { nfkd: t, words: e };
}
const E = (n) => b("mnemonic" + n);
function U(n, t = "") {
  return A(S, D(n).nfkd, E(t), { c: 2048, dkLen: 64 });
}
export {
  U as m
};
