const l = (e) => typeof btoa < "u" ? btoa(e) : Buffer.from(e, "utf-8").toString("base64"), d = (e) => typeof atob < "u" ? atob(e) : Buffer.from(e, "base64").toString("utf-8"), g = (e) => l(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""), h = (e) => {
  let t = e;
  for (; t.length % 4; )
    t += "=";
  return d(
    t.replace(/-/g, "+").replace(/_/g, "/")
  );
}, y = (e) => {
  if (typeof crypto < "u" && crypto.getRandomValues)
    return crypto.getRandomValues(new Uint8Array(e));
  const t = new Uint8Array(e);
  for (let r = 0; r < e; r++)
    t[r] = Math.floor(Math.random() * 256);
  return t;
}, s = (e, t) => {
  const n = t || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", o = y(e);
  let a = "";
  for (let c = 0; c < e; c++)
    a += n[o[c] % n.length];
  return a;
}, S = () => {
  const e = Date.now().toString(36), t = s(8);
  return `${e}${t}`;
}, v = () => s(32), x = () => s(32), C = () => s(128, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"), A = async (e) => {
  if (typeof crypto < "u" && crypto.subtle) {
    const r = new TextEncoder().encode(e), n = await crypto.subtle.digest("SHA-256", r), o = new Uint8Array(n);
    return g(String.fromCharCode(...o));
  }
  return console.warn("WebCrypto API not available, using plain code verifier"), e;
}, D = async () => {
  const e = C();
  if (typeof crypto < "u" && crypto.subtle) {
    const t = await A(e);
    return {
      codeVerifier: e,
      codeChallenge: t,
      codeChallengeMethod: "S256"
    };
  }
  return {
    codeVerifier: e,
    codeChallenge: e,
    codeChallengeMethod: "plain"
  };
}, p = async (e) => {
  if (typeof crypto < "u" && crypto.subtle) {
    const n = new TextEncoder().encode(e), o = await crypto.subtle.digest("SHA-256", n), a = new Uint8Array(o);
    return Array.from(a).map((c) => c.toString(16).padStart(2, "0")).join("");
  }
  let t = 0;
  for (let r = 0; r < e.length; r++) {
    const n = e.charCodeAt(r);
    t = (t << 5) - t + n, t = t & t;
  }
  return Math.abs(t).toString(16);
}, T = (e) => {
  let t = 0;
  for (let r = 0; r < e.length; r++) {
    const n = e.charCodeAt(r);
    t = (t << 5) - t + n, t = t & t;
  }
  return Math.abs(t).toString(16);
}, B = (e, t) => {
  let r = "";
  for (let n = 0; n < e.length; n++) {
    const o = e.charCodeAt(n), a = t.charCodeAt(n % t.length);
    r += String.fromCharCode(o ^ a);
  }
  return l(r);
}, E = (e, t) => {
  try {
    const r = d(e);
    let n = "";
    for (let o = 0; o < r.length; o++) {
      const a = r.charCodeAt(o), c = t.charCodeAt(o % t.length);
      n += String.fromCharCode(a ^ c);
    }
    return n;
  } catch {
    return "";
  }
}, f = (e) => {
  try {
    const t = e.split(".");
    if (t.length !== 3) return null;
    const r = JSON.parse(h(t[0])), n = JSON.parse(h(t[1])), o = t[2];
    return { header: r, payload: n, signature: o };
  } catch {
    return null;
  }
}, U = (e) => {
  const t = f(e);
  if (!t || !t.payload.exp) return !0;
  const r = Math.floor(Date.now() / 1e3);
  return t.payload.exp < r;
}, O = (e) => {
  const t = f(e);
  return !t || !t.payload.exp ? null : new Date(t.payload.exp * 1e3);
}, i = (e) => {
  const t = new Uint8Array(e);
  let r = "";
  for (let n = 0; n < t.byteLength; n++)
    r += String.fromCharCode(t[n]);
  return l(r);
}, u = (e) => {
  const t = d(e), r = new ArrayBuffer(t.length), n = new Uint8Array(r);
  for (let o = 0; o < t.length; o++)
    n[o] = t.charCodeAt(o);
  return r;
}, M = (e) => i(e.buffer), R = (e) => new Uint8Array(u(e)), P = (e) => ({
  id: e.id,
  rawId: i(e.rawId),
  type: e.type,
  response: {
    clientDataJSON: i(e.response.clientDataJSON),
    attestationObject: e.response instanceof AuthenticatorAttestationResponse ? i(e.response.attestationObject) : void 0,
    authenticatorData: e.response instanceof AuthenticatorAssertionResponse ? i(e.response.authenticatorData) : void 0,
    signature: e.response instanceof AuthenticatorAssertionResponse ? i(e.response.signature) : void 0,
    userHandle: e.response instanceof AuthenticatorAssertionResponse && e.response.userHandle ? i(e.response.userHandle) : void 0
  }
}), J = (e) => ({
  ...e,
  challenge: u(e.challenge),
  user: {
    ...e.user,
    id: u(e.user.id)
  },
  excludeCredentials: e.excludeCredentials?.map((t) => ({
    ...t,
    id: u(t.id)
  }))
}), k = (e) => ({
  ...e,
  challenge: u(e.challenge),
  allowCredentials: e.allowCredentials?.map((t) => ({
    ...t,
    id: u(t.id)
  }))
}), _ = async (e, t) => {
  const r = e + t;
  return await p(r);
}, $ = () => s(16), q = async () => {
  const e = [
    navigator.userAgent,
    navigator.language,
    screen.width + "x" + screen.height,
    screen.colorDepth,
    (/* @__PURE__ */ new Date()).getTimezoneOffset(),
    navigator.hardwareConcurrency || 0,
    navigator.deviceMemory || 0,
    navigator.cookieEnabled
  ];
  try {
    const r = document.createElement("canvas"), n = r.getContext("2d");
    n && (n.textBaseline = "top", n.font = "14px Arial", n.fillText("Frank Auth fingerprint", 2, 2), e.push(r.toDataURL()));
  } catch {
  }
  const t = e.join("|");
  return await p(t);
}, j = () => {
  const e = document.createElement("canvas");
  e.getContext("2d")?.fillText("fingerprint", 0, 0);
  const r = [
    navigator.userAgent,
    navigator.language,
    screen.width + "x" + screen.height,
    (/* @__PURE__ */ new Date()).getTimezoneOffset(),
    e.toDataURL(),
    navigator.hardwareConcurrency,
    navigator.deviceMemory
  ].join("|");
  let n = 0;
  for (let o = 0; o < r.length; o++) {
    const a = r.charCodeAt(o);
    n = (n << 5) - n + a, n = n & n;
  }
  return Math.abs(n).toString(36);
}, F = (e = 32) => s(e, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), G = () => {
  const e = "pk_", t = "test_", r = s(32);
  return `${e}${t}${r}`;
}, H = (e) => {
  try {
    return l(d(e)) === e;
  } catch {
    return !1;
  }
}, K = (e) => f(e) !== null, N = () => s(32, "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), V = (e = 10) => {
  const t = [];
  for (let r = 0; r < e; r++)
    t.push(s(8, "0123456789ABCDEF"));
  return t;
}, W = (e) => g(e), I = (e) => h(e), m = (e) => {
  let t = 0;
  for (let r = 0; r < e.length; r++)
    t += e.charCodeAt(r);
  return t.toString(16);
}, L = (e, t) => m(e) === t, z = async (e, t, r = 1e3) => {
  if (typeof crypto < "u" && crypto.subtle) {
    const o = new TextEncoder(), a = await crypto.subtle.importKey(
      "raw",
      o.encode(e),
      { name: "PBKDF2" },
      !1,
      ["deriveBits"]
    ), c = await crypto.subtle.deriveBits(
      {
        name: "PBKDF2",
        salt: o.encode(t),
        iterations: r,
        hash: "SHA-256"
      },
      a,
      256
    ), w = new Uint8Array(c);
    return Array.from(w).map((b) => b.toString(16).padStart(2, "0")).join("");
  }
  let n = e + t;
  for (let o = 0; o < r; o++)
    n = await p(n);
  return n;
}, Q = {
  // Encoding
  base64Encode: l,
  base64Decode: d,
  base64UrlEncode: g,
  base64UrlDecode: h,
  urlSafeEncode: W,
  urlSafeDecode: I,
  // Random generation
  generateRandomBytes: y,
  generateRandomString: s,
  generateSecureId: S,
  generateNonce: v,
  generateState: x,
  generateSecureToken: F,
  // Hashing
  sha256: p,
  md5: T,
  calculateChecksum: m,
  verifyChecksum: L,
  // JWT
  parseJWT: f,
  isJWTExpired: U,
  getJWTExpiration: O,
  isValidJWT: K,
  // WebAuthn
  arrayBufferToBase64: i,
  base64ToArrayBuffer: u,
  uint8ArrayToBase64: M,
  base64ToUint8Array: R,
  credentialToJSON: P,
  jsonToCredentialCreationOptions: J,
  jsonToCredentialRequestOptions: k,
  // PKCE
  generateCodeVerifier: C,
  generateCodeChallenge: A,
  generatePKCEPair: D,
  // Device fingerprinting
  generateDeviceFingerprint: j,
  // Authentication codes
  generateTOTPSecret: N,
  generateBackupCodes: V,
  // Key derivation
  deriveKey: z,
  // Simple encryption (for obfuscation only)
  simpleEncrypt: B,
  simpleDecrypt: E,
  // Validation
  isValidBase64: H
};
export {
  Q as CryptoUtils,
  i as arrayBufferToBase64,
  d as base64Decode,
  l as base64Encode,
  u as base64ToArrayBuffer,
  R as base64ToUint8Array,
  h as base64UrlDecode,
  g as base64UrlEncode,
  m as calculateChecksum,
  P as credentialToJSON,
  z as deriveKey,
  G as generateApiKey,
  V as generateBackupCodes,
  A as generateCodeChallenge,
  C as generateCodeVerifier,
  j as generateDeviceFingerprint,
  q as generateDeviceFingerprintPromise,
  v as generateNonce,
  D as generatePKCEPair,
  y as generateRandomBytes,
  s as generateRandomString,
  $ as generateSalt,
  S as generateSecureId,
  F as generateSecureToken,
  x as generateState,
  N as generateTOTPSecret,
  O as getJWTExpiration,
  _ as hashPassword,
  U as isJWTExpired,
  H as isValidBase64,
  K as isValidJWT,
  J as jsonToCredentialCreationOptions,
  k as jsonToCredentialRequestOptions,
  T as md5,
  f as parseJWT,
  p as sha256,
  E as simpleDecrypt,
  B as simpleEncrypt,
  M as uint8ArrayToBase64,
  I as urlSafeDecode,
  W as urlSafeEncode,
  L as verifyChecksum
};
//# sourceMappingURL=crypto.js.map
