linktoken

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package linktoken signs the tokens embedded in emails: open pixel, click redirect, one-click unsubscribe (RFC 8058), preference center, view online and double opt-in confirmation links. Tokens are compact, unforgeable (HMAC-SHA256 truncated to 128 bits) and carry no personal data in clear.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("linktoken: invalid token")

ErrInvalid is returned for malformed or forged tokens.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Kind        Kind
	WorkspaceID uuid.UUID
	MessageID   uuid.UUID // uuid.Nil when not tied to a message
	ContactID   uuid.UUID
	// Link is the index of the link in campaign_links for Click tokens.
	Link uint32
}

Claims identify the message (or contact, for links outside a message).

type Kind

type Kind byte

Kind is what a token is for; a token for one purpose never works for another.

const (
	Open        Kind = 1
	Click       Kind = 2
	Unsubscribe Kind = 3
	Preferences Kind = 4
	ViewOnline  Kind = 5
	Confirm     Kind = 6
)

Token kinds.

type Signer

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

Signer signs and verifies tokens with a key derived from the instance key.

func NewSigner

func NewSigner(master []byte) (*Signer, error)

NewSigner derives the signing key from the instance master key with HKDF.

func (*Signer) Sign

func (s *Signer) Sign(c Claims) string

Sign returns a URL-safe token.

func (*Signer) Verify

func (s *Signer) Verify(token string, want Kind) (Claims, error)

Verify checks a token and returns its claims; want limits the accepted kind.

Jump to

Keyboard shortcuts

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