INNER CODE UNIT · TypeScript

deriveSigningJwks

bex-co/beancount-io · backend-cluster/backend-v2/src/config/jwks/index.ts:93

export function deriveSigningJwks(secret: string | undefined): SigningJwks {
  if (!secret?.trim()) {
    throw new Error("AUTH_SECRET is required to derive the OAuth signing key");
  }
  // 48 bytes, then reduced, so the scalar is uniform in [1, N-1] rather than
  // biased by a 32-byte value that can exceed the group order.
  const material = Buffer.from(
    hkdfSync("sha256", secret, DERIVATION_SALT, DERIVATION_INFO, 48),
  );
  const scalar =
    (BigInt("0x" + material.toString("hex")) % (P256_ORDER - BigInt(1))) +
    BigInt(1);
  const d = Buffer.from(scalar.toString(16).padStart(64, "0"), "hex");

  const ecdh = createECDH("prime256v1");
  ecdh.setPrivateKey(d);
  const point = ecdh.getPublicKey(); // 0x04 || X || Y
  const x = point.subarray(1, 33);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…