GenerateKeys (webpush/vapid.go)

clickclack · apps/api/internal/webpush/vapid.go · go · MIT
auth, Auth / Identity

Go utilities for generating, validating, and signing VAPID keys for web push.

// Source: https://github.com/openclaw/clickclack | License: MIT | Copyright 2026 openclaw
// Provided via justclaw.it.com; keep this notice with the code.
package webpush

import (
	"bytes"
	"crypto/ecdh"
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"errors"
	"fmt"
	"net/url"
	"strings"
	"time"

	"github.com/golang-jwt/jwt/v5"
)

// vapidTokenLifetime is how long a push service will accept one signed token.
// RFC 8292 caps it at 24 hours; half a day leaves room for clock skew.
const vapidTokenLifetime = 12 * time.Hour

// GenerateKeys returns a fresh base64url VAPID key pair, public key first. The
// public key is the uncompressed P-256 point the browser passes to
// pushManager.subscribe; the private key is the raw scalar.
func G

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key