Help us shape the future of Go! Take the 2026 Go Developer Survey

sign

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sign implements HTTP Message Signatures (RFC 9421) with Ed25519, as used by the Web Bot Auth proposal for cryptographically identifying automated clients.

Index

Constants

View Source
const WebBotAuthTag = "web-bot-auth"

WebBotAuthTag is the signature tag Web Bot Auth verifiers look for.

Variables

This section is empty.

Functions

func Base

func Base(req *http.Request, components []string, p Params) (string, error)

Base builds the signature base for req (RFC 9421 §2.5).

func Directory

func Directory(pubs ...ed25519.PublicKey) ([]byte, error)

Directory returns the JSON key directory a signing agent publishes at /.well-known/http-message-signatures-directory.

func EncodePrivateKey

func EncodePrivateKey(key ed25519.PrivateKey) ([]byte, error)

EncodePrivateKey returns key as a PKCS #8 PEM block.

func GenerateKey

func GenerateKey() (ed25519.PrivateKey, error)

GenerateKey returns a new Ed25519 private key.

func LoadPrivateKey

func LoadPrivateKey(path string) (ed25519.PrivateKey, error)

LoadPrivateKey reads a PEM private key file.

func ParsePrivateKey

func ParsePrivateKey(data []byte) (ed25519.PrivateKey, error)

ParsePrivateKey parses a PKCS #8 PEM Ed25519 private key.

func Sign

func Sign(req *http.Request, key ed25519.PrivateKey, label string, components []string, p Params) error

Sign signs req and sets the Signature-Input and Signature headers under label (for example "sig1").

func Thumbprint

func Thumbprint(pub ed25519.PublicKey) string

Thumbprint returns the RFC 7638 JWK SHA-256 thumbprint of pub, base64url-encoded. Web Bot Auth uses it as the signature keyid.

func Verify

func Verify(req *http.Request, pub ed25519.PublicKey, label string, components []string, p Params) error

Verify checks the signature under label on req against pub. It is used by tests and by `acurl serve` to show what a server would see.

Types

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Crv string `json:"crv"`
	X   string `json:"x"`
	Kid string `json:"kid,omitempty"`
}

JWK is an Ed25519 public key in JSON Web Key form (RFC 8037).

func PublicJWK

func PublicJWK(pub ed25519.PublicKey) JWK

PublicJWK returns the JWK for pub with its thumbprint as kid.

type Params

type Params struct {
	Created time.Time
	Expires time.Time // zero means none
	KeyID   string
	Alg     string // e.g. "ed25519"; empty omits the parameter
	Nonce   string
	Tag     string
}

Params are the signature parameters of RFC 9421 §2.3.

type Signer

type Signer struct {
	Key ed25519.PrivateKey
	// Agent is the Signature-Agent URL where the key directory is published,
	// e.g. "https://bot.example". Empty omits the header.
	Agent string
	// Validity is how long a signature is valid. Default one minute.
	Validity time.Duration
	// contains filtered or unexported fields
}

Signer signs requests the way Web Bot Auth agents do: an Ed25519 signature over @authority and Signature-Agent, with a short validity window, a nonce and the web-bot-auth tag.

func (*Signer) Headers

func (s *Signer) Headers(method, rawURL string) (map[string]string, error)

Headers returns the Signature-Agent, Signature-Input and Signature headers for a request.

func (*Signer) KeyID

func (s *Signer) KeyID() string

KeyID returns the JWK thumbprint used as keyid.

Jump to

Keyboard shortcuts

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