UNPKG

aegis-auth

Version:

A credentials-based auth solution for Next.js (and other Node projects) with IP rate-limiting, account lockouts, and sessions in DB.

36 lines 1.25 kB
// function from: https://github.com/better-auth/utils const hexadecimal = "0123456789abcdef"; export const hex = { encode: (data) => { const inputData = typeof data === "string" ? new TextEncoder().encode(data) : data; if (inputData.byteLength === 0) { return ""; } const buffer = new Uint8Array(inputData); let result = ""; for (const byte of buffer) { result += byte.toString(16).padStart(2, "0"); } return result; }, decode: (data) => { if (!data) { return ""; } if (typeof data === "string") { if (data.length % 2 !== 0) { throw new Error("Invalid hexadecimal string"); } if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) { throw new Error("Invalid hexadecimal string"); } const result = new Uint8Array(data.length / 2); for (let i = 0; i < data.length; i += 2) { result[i / 2] = Number.parseInt(data.slice(i, i + 2), 16); } return new TextDecoder().decode(result); } return new TextDecoder().decode(data); }, }; //# sourceMappingURL=hex.js.map