confirmation

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package confirmation owns short-lived, single-use proofs for high-risk device operations. Proofs are opaque to adapters and are consumed only by the hardware execution service at the final send boundary.

Index

Constants

View Source
const (
	DefaultTTL = 2 * time.Minute
)

Variables

View Source
var (
	ErrInvalidConfiguration = errors.New("invalid confirmation configuration")
	ErrPrincipalRequired    = errors.New("authenticated principal is required")
	ErrProofRequired        = errors.New("confirmation proof is required")
	ErrProofInvalid         = errors.New("confirmation proof is invalid")
	ErrProofExpired         = errors.New("confirmation proof has expired")
	ErrProofMismatch        = errors.New("confirmation proof does not match the operation")
	ErrProofReplayed        = errors.New("confirmation proof was already consumed")
)

Functions

func DigestArguments

func DigestArguments(canonical []byte) [sha256.Size]byte

DigestArguments derives the unkeyed identity of canonical arguments. The HMAC-sealed proof prevents callers from substituting this digest.

func WithPrincipal

func WithPrincipal(ctx context.Context, principal Principal) context.Context

WithPrincipal attaches the identity established by stdio process ownership or HTTP authentication. Device-facing request arguments must never choose it.

func WithProof

func WithProof(ctx context.Context, proof Proof) context.Context

WithProof attaches a proof issued after a trusted confirmation interaction.

Types

type Authority

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

Authority mints and verifies proofs. Key material is supplied by the composition root and is never generated or persisted by this package.

func NewAuthority

func NewAuthority(config Config) (*Authority, error)

func (*Authority) Mint

func (a *Authority) Mint(ctx context.Context, binding Binding) (Proof, error)

Mint creates a short-lived proof for the principal already authenticated in ctx. Minting is reserved for trusted adapters after user confirmation.

func (*Authority) VerifyAndConsume

func (a *Authority) VerifyAndConsume(ctx context.Context, expected Binding) error

VerifyAndConsume validates every bound field and atomically consumes the nonce. Callers must invoke it immediately before crossing the send boundary.

type Binding

type Binding struct {
	DeviceID        domain.DeviceID
	Generation      uint64
	Effect          domain.EffectClass
	Action          string
	ArgumentsDigest [sha256.Size]byte
	PolicyRevision  string
}

Binding is the complete authority identity for one high-risk operation. ArgumentsDigest must cover deterministic, versioned canonical arguments.

type Config

type Config struct {
	Key    []byte
	TTL    time.Duration
	Nonces NonceStore
	Now    func() time.Time
}

type MemoryNonceStore

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

MemoryNonceStore is suitable for the single-process stdio and loopback HTTP deployment supported by the first release.

func NewMemoryNonceStore

func NewMemoryNonceStore() *MemoryNonceStore

func (*MemoryNonceStore) Consume

func (s *MemoryNonceStore) Consume(_ context.Context, nonce uuid.UUID, expiresAt time.Time) error

type NonceStore

type NonceStore interface {
	Consume(context.Context, uuid.UUID, time.Time) error
}

NonceStore is the atomic single-use authority. Implementations used by multi-process servers must place this state in their shared durable store.

type Principal

type Principal struct {
	ID        string
	Transport string
}

Principal is the authenticated caller identity established by a trusted transport adapter. ID must be stable within the adapter's trust domain.

func LocalProcessPrincipal

func LocalProcessPrincipal() Principal

LocalProcessPrincipal is the identity used by the local stdio adapter.

func PrincipalFromContext

func PrincipalFromContext(ctx context.Context) (Principal, bool)

PrincipalFromContext returns the transport-authenticated caller identity.

type Proof

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

Proof is intentionally opaque. Only an Issuer can create a valid value.

Jump to

Keyboard shortcuts

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