INNER CODE UNIT · TypeScript

jwkThumbprintPreCompute

cloudflare/web-bot-auth · packages/jsonwebkey-thumbprint/src/index.ts:3

export const jwkThumbprintPreCompute = (jwk: JsonWebKey): Uint8Array => {
  const encoder = new TextEncoder();

  switch (jwk.kty) {
    // Defined in Section 3.2 of RFC 7638
    case "EC":
      return encoder.encode(
        `{"crv":"${jwk.crv}","kty":"EC","x":"${jwk.x}","y":"${jwk.y}"}`
      );
    // Defined in Appendix A.3 of RFC 8037
    case "OKP":
      return encoder.encode(`{"crv":"${jwk.crv}","kty":"OKP","x":"${jwk.x}"}`);
    // Defined in Section 3.2 of RFC 7638
    case "RSA":
      return encoder.encode(`{"e":"${jwk.e}","kty":"RSA","n":"${jwk.n}"}`);
    default:
      throw new Error("Unsupported key type");
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…