diff options
Diffstat (limited to 'internal/notify/vapid.go')
| -rw-r--r-- | internal/notify/vapid.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/notify/vapid.go b/internal/notify/vapid.go new file mode 100644 index 0000000..684bf4d --- /dev/null +++ b/internal/notify/vapid.go @@ -0,0 +1,25 @@ +package notify + +import ( + "encoding/base64" + + webpush "github.com/SherClockHolmes/webpush-go" +) + +// GenerateVAPIDKeys generates a VAPID key pair for web push notifications. +// Returns the base64url-encoded public and private keys. +// Note: webpush.GenerateVAPIDKeys returns (privateKey, publicKey) — we swap here. +func GenerateVAPIDKeys() (publicKey, privateKey string, err error) { + privateKey, publicKey, err = webpush.GenerateVAPIDKeys() + return +} + +// ValidateVAPIDPublicKey reports whether key is a valid VAPID public key: +// a base64url-encoded 65-byte uncompressed P-256 point (starts with 0x04). +func ValidateVAPIDPublicKey(key string) bool { + b, err := base64.RawURLEncoding.DecodeString(key) + if err != nil { + return false + } + return len(b) == 65 && b[0] == 0x04 +} |
