defmodule Mix.Tasks.WebPush.Gen.Vapid do @moduledoc """ Generates a VAPID (P-256) keypair for Web Push. mix web_push.gen.vapid Prints the keys ready to paste into config or to export as environment variables. The public key (65-byte uncompressed point, URL-safe base64 without padding) is also the value the browser passes to `pushManager.subscribe({ applicationServerKey })`. """ use Mix.Task @shortdoc "Generates a VAPID P-256 keypair for Web Push" @impl Mix.Task def run(_args) do %{public_key: public_b64, private_key: private_b64} = WebPush.Vapid.generate_keypair() IO.puts(""" # VAPID keypair ## config (runtime.exs recommended) config :web_push, :vapid, public_key: "#{public_b64}", private_key: "#{private_b64}", subject: "mailto:you@example.com" ## env vars (production) export VAPID_PUBLIC_KEY="#{public_b64}" export VAPID_PRIVATE_KEY="#{private_b64}" export VAPID_SUBJECT="mailto:you@example.com" """) end end