webpush

package
v0.0.0-...-2cef8ba Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2018 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package webpush implements the message encryption required by the Web Push protocol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSigningKey

func GenerateSigningKey() (*ecdsa.PrivateKey, error)

func New

func New(sub *Subscription, message []byte, opts *Options) (*http.Request, error)

New encrypts the message and creates a HTTP request that will submit it to the push endpoint

Types

type KeyPair

type KeyPair struct {
	Pub  *PublicKey
	Priv []byte
}

type Options

type Options struct {
	SigningKey *ecdsa.PrivateKey
	Urgency    Urgency
	TTL        time.Duration
	Topic      string
}

type PublicKey

type PublicKey struct {
	X, Y *big.Int
}

PublicKey is a point (X, Y) on the P-256 curve

func (*PublicKey) MarshalBinary

func (p *PublicKey) MarshalBinary() ([]byte, error)

func (*PublicKey) UnmarshalBinary

func (p *PublicKey) UnmarshalBinary(data []byte) error

type Subscription

type Subscription struct {
	// The push endpoint URL, unique to the given push subscription
	Endpoint string
	// 16 random bytes generated by the user agent, called auth_secret in the
	// RFC 8291 encryption summary
	Auth []byte
	// The P-256 public key generated by the User Agent
	P256DH *PublicKey
}

Subscription is a User Agent's push message subscription

func UnmarshalSubscription

func UnmarshalSubscription(data []byte) (*Subscription, error)

type Urgency

type Urgency string

Urgency allows battery powered devices to avoid expending power on less important messages by only fetching messages of a certain urgency

var (
	// UrgencyVeryLow sends notifications to devices that are both connected
	// to power and on Wi-Fi
	UrgencyVeryLow Urgency = "very-low"
	// UrgencyLow includes devices that are on either power or Wi-Fi
	UrgencyLow Urgency = "low"
	// UrgencyNormal includes devices that are not connected to power nor Wi-Fi
	// with acceptable remaining battery life
	UrgencyNormal Urgency = "normal"
	// UrgencyHigh includes devices with low battery power
	UrgencyHigh Urgency = "high"
)

Jump to

Keyboard shortcuts

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