blob: 684bf4d78938d20554e716cba802fd2a5f86898e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
}
|