function base64urlEncode(bytes) {
    let binary = "";
    for (const byte of bytes) {
        binary += String.fromCharCode(byte);
    }
    return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
}
export async function generatePKCE() {
    const verifierBytes = new Uint8Array(32);
    crypto.getRandomValues(verifierBytes);
    const verifier = base64urlEncode(verifierBytes);
    const data = new TextEncoder().encode(verifier);
    const hashBuffer = await crypto.subtle.digest("SHA-256", data);
    const challenge = base64urlEncode(new Uint8Array(hashBuffer));
    return { verifier, challenge };
}
//# sourceMappingURL=pkce.js.map