push

package
v1.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package push provides push notification drivers.

Index

Constants

View Source
const (
	// HeaderKey carries the server's Ed25519 public key, standard base64.
	HeaderKey = "X-Herald-Key"
	// HeaderTimestamp carries the Unix seconds the request was signed at.
	HeaderTimestamp = "X-Herald-Timestamp"
	// HeaderSignature carries the standard base64 Ed25519 signature of SignatureBase.
	HeaderSignature = "X-Herald-Signature"
)

Headers the sealed driver sets on a gateway request. The gateway reads the same names, so both sides import them from here.

View Source
const MaxEnvelopeBytes = 2560

MaxEnvelopeBytes is the largest envelope JSON, in bytes, accepted before sealing.

View Source
const SealInfo = "herald push v1"

SealInfo is the HPKE info string every sealed push envelope is bound to.

View Source
const SealOverhead = 48

SealOverhead is what sealing adds to a plaintext: a 32-byte enc and a 16-byte tag.

Variables

View Source
var (
	// ErrPayloadTooLarge reports an envelope over MaxEnvelopeBytes.
	ErrPayloadTooLarge = errors.New("herald: push payload too large")
	// ErrMissingCollapseID reports a withdraw with no collapse ID: a withdraw
	// names the notification to remove by that ID.
	ErrMissingCollapseID = errors.New("herald: push withdraw needs a collapse id")
	// ErrMissingPublicKey reports a device without a usable X25519 public key.
	ErrMissingPublicKey = errors.New("herald: push device has no public key")
)

Functions

func KeyID

func KeyID(publicKey []byte) string

KeyID returns the lowercase hex of the first 8 bytes of the SHA-256 of publicKey.

func MarshalEnvelope

func MarshalEnvelope(e Envelope) ([]byte, error)

MarshalEnvelope encodes e as JSON with V forced to 1.

func Open

func Open(privateKey, sealed []byte) ([]byte, error)

Open decrypts sealed with a raw 32-byte X25519 private key.

func Seal

func Seal(publicKey, plaintext []byte) ([]byte, error)

Seal encrypts plaintext to a raw 32-byte X25519 public key with HPKE base mode. The result is the 32-byte enc followed by the ciphertext.

func SignatureBase

func SignatureBase(timestamp string, body []byte) []byte

SignatureBase returns the bytes a request signature covers: the timestamp, a dot, then the raw body.

Types

type Envelope

type Envelope struct {
	V        int               `json:"v"`
	Title    string            `json:"title"`
	Body     string            `json:"body"`
	Category string            `json:"category,omitempty"`
	Thread   string            `json:"thread,omitempty"`
	Data     map[string]string `json:"data,omitempty"`
}

Envelope is the plaintext a device opens after unsealing a push.

type FCMDriver

type FCMDriver struct {
	// contains filtered or unexported fields
}

FCMDriver delivers push notifications via Firebase Cloud Messaging HTTP v1 API.

The zero value is ready to use. It caches minted access tokens per service account key, so share one instance rather than creating one per send.

func (*FCMDriver) Channel

func (d *FCMDriver) Channel() string

func (*FCMDriver) Fields

func (d *FCMDriver) Fields() []driver.Field

Fields describes what the FCM driver reads. It needs one of service_account, access_token or server_key; the schema can't express "one of", so neither is required here and Validate enforces it.

func (*FCMDriver) Name

func (d *FCMDriver) Name() string

func (*FCMDriver) Send

func (*FCMDriver) Validate

func (d *FCMDriver) Validate(credentials, _ map[string]string) error

type SealedDriver

type SealedDriver struct {
	// Now supplies the signing time. Nil means time.Now.
	Now func() time.Time
}

SealedDriver delivers a push through a gateway without letting it read the content. It seals the notification to the device's public key, then asks the gateway to relay the sealed bytes, signing the request with an Ed25519 key.

The zero value is ready to use.

func (*SealedDriver) Channel

func (d *SealedDriver) Channel() string

Channel returns the channel the driver serves.

func (*SealedDriver) Fields

func (d *SealedDriver) Fields() []driver.Field

Fields describes what the sealed gateway driver reads.

func (*SealedDriver) Name

func (d *SealedDriver) Name() string

Name returns the driver name.

func (*SealedDriver) Send

Send seals msg to the device key and posts it to the gateway.

func (*SealedDriver) Validate

func (d *SealedDriver) Validate(credentials, settings map[string]string) error

Validate checks the signing key and gateway URL.

type SendBody

type SendBody struct {
	Handle     string `json:"handle"`
	Sealed     string `json:"sealed,omitempty"`
	KeyID      string `json:"key_id"`
	Urgency    string `json:"urgency"`
	Kind       string `json:"kind"`
	CollapseID string `json:"collapse_id,omitempty"`
	TTLSeconds int64  `json:"ttl_seconds,omitempty"`
}

SendBody is the JSON body of POST /v1/send on a push gateway.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL