material

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package material is the sealed payload for an item.

Token is the API key / password. TOTP is the base32 *seed*, never a 6-digit code. Codes are minted at inject time with pquerna/otp (https://pkg.go.dev/github.com/pquerna/otp/totp — GenerateCode).

Index

Constants

View Source
const (
	Version    = 1
	HeaderTOTP = "X-TOTP"
	MaxFile    = 8 << 20
)

Variables

This section is empty.

Functions

func AccessToken

func AccessToken(ctx context.Context, env Envelope, client *http.Client) (string, error)

AccessToken follows Authsome's "log in once" pattern. Refresh stays here. golang.org/x/oauth2 performs the refresh. The access token is for inject only.

func AccessTokenWithMetadata

func AccessTokenWithMetadata(ctx context.Context, env Envelope, client *http.Client) (access, nextRefresh, extraScrub string, err error)

AccessTokenWithMetadata is AccessTokenWithRefresh plus any intermediate secret material (such as a minted WIF assertion JWT) that the caller must include in response scrubbing.

func AccessTokenWithRefresh

func AccessTokenWithRefresh(ctx context.Context, env Envelope, client *http.Client) (access, nextRefresh string, err error)

AccessTokenWithRefresh performs the OAuth refresh (or RFC 7523 jwt-bearer WIF exchange when FederationRuleID is set) and also returns any rotated refresh token issued by the provider so the broker can persist it.

func Apply

func Apply(h http.Header, env Envelope, now time.Time) (code string, err error)

func AuthorizationValue

func AuthorizationValue(token string) string

AuthorizationValue is the Authorization header for an injected token. Stripe/GitHub/OpenAI want Bearer. Linear API keys (lin_api_) reject it.

func FileBytes

func FileBytes(env Envelope) ([]byte, error)

func Mint

func Mint(seed string, now time.Time) (string, error)

func Pack

func Pack(token, totpSeed []byte) ([]byte, error)

func PackCard

func PackCard(number, expMonth, expYear, cvv, name string) ([]byte, error)

func PackFile

func PackFile(name, mime string, body []byte) ([]byte, error)

func PackIdentity

func PackIdentity(given, family, address, city, region, postal, country, phone, email string) ([]byte, error)

func PackOAuth

func PackOAuth(refresh, tokenURL, clientID, clientSecret []byte) ([]byte, error)

func PackPasskey

func PackPasskey(pem, credID, rpID, userHandle string) ([]byte, error)

func PackWIF

func PackWIF(opts WIFOpts) ([]byte, error)

func ScrubList

func ScrubList(env Envelope, extra ...[]byte) [][]byte

func WithLogin

func WithLogin(raw []byte, login string) ([]byte, error)

WithLogin puts the fill username in the sealed blob. Empty login leaves raw unchanged. Item list and MCP never see this field.

func WithRefresh

func WithRefresh(raw []byte, refresh string) ([]byte, error)

WithRefresh seals a rotated OAuth refresh token into an existing envelope, preserving all other fields.

func WithRotatedToken

func WithRotatedToken(raw, token []byte, keyID, pendingKeyID string) ([]byte, error)

WithRotatedToken seals a rotated token and the dual-phase provider key IDs in one envelope. Item list and MCP never see these fields.

func WithRotatedTokenMeta

func WithRotatedTokenMeta(raw, token []byte, keyID, pendingKeyID, mgmtItemID, interval string, nextRotateAt int64) ([]byte, error)

WithRotatedTokenMeta seals a rotated token, dual-phase key IDs, and optional management-credential / rotation-schedule metadata inside the envelope.

func WithToken

func WithToken(raw, token []byte) ([]byte, error)

WithToken rotates the sealed secret — a changed password keeps its TOTP seed, login, and passkey. A raw pre-envelope token upgrades to v1. Blank tokens refuse: a rotate must never seal nothing.

Types

type Envelope

type Envelope struct {
	V                  int    `json:"v"`
	Token              string `json:"token,omitempty"`
	Login              string `json:"login,omitempty"`
	TOTP               string `json:"totp,omitempty"`
	Refresh            string `json:"refresh,omitempty"`
	TokenURL           string `json:"token_url,omitempty"`
	ClientID           string `json:"client_id,omitempty"`
	ClientSec          string `json:"client_secret,omitempty"`
	FileName           string `json:"file_name,omitempty"`
	MIME               string `json:"mime,omitempty"`
	FileB64            string `json:"file_b64,omitempty"`
	PasskeyPEM         string `json:"passkey_pem,omitempty"`
	CredID             string `json:"cred_id,omitempty"`
	RpID               string `json:"rp_id,omitempty"`
	UserHandle         string `json:"user_handle,omitempty"`
	Number             string `json:"number,omitempty"`
	ExpMonth           string `json:"exp_month,omitempty"`
	ExpYear            string `json:"exp_year,omitempty"`
	CVV                string `json:"cvv,omitempty"`
	GivenName          string `json:"given_name,omitempty"`
	FamilyName         string `json:"family_name,omitempty"`
	Address            string `json:"address,omitempty"`
	City               string `json:"city,omitempty"`
	Region             string `json:"region,omitempty"`
	Postal             string `json:"postal,omitempty"`
	Country            string `json:"country,omitempty"`
	Phone              string `json:"phone,omitempty"`
	Email              string `json:"email,omitempty"`
	KeyID              string `json:"key_id,omitempty"`
	PendingKeyID       string `json:"pending_key_id,omitempty"`
	ManagementItemID   string `json:"management_item_id,omitempty"`
	RotateInterval     string `json:"rotate_interval,omitempty"`
	NextRotateAt       int64  `json:"next_rotate_at,omitempty"`
	AssertionTokenURL  string `json:"assertion_token_url,omitempty"`
	AssertionClientID  string `json:"assertion_client_id,omitempty"`
	AssertionClientSec string `json:"assertion_client_secret,omitempty"`
	AssertionAudience  string `json:"assertion_audience,omitempty"`
	FederationRuleID   string `json:"federation_rule_id,omitempty"`
	FederationOrgID    string `json:"federation_org_id,omitempty"`
	ServiceAccountID   string `json:"service_account_id,omitempty"`
	WorkspaceID        string `json:"workspace_id,omitempty"`
}

func Unpack

func Unpack(raw []byte) Envelope

type TokenCache

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

TokenCache caches short-lived access tokens minted from OAuth refresh or RFC 7523 WIF exchanges until expiresAt - 60s headroom, keyed by a SHA-256 digest of the envelope's token-minting inputs. Rotating or editing the item's secret changes the digest and invalidates the entry automatically.

func NewTokenCache

func NewTokenCache() *TokenCache

type WIFOpts

type WIFOpts struct {
	TokenURL          string
	AssertionTokenURL string
	AssertionClientID string
	AssertionSecret   string
	AssertionAudience string
	FederationRuleID  string
	OrganizationID    string
	ServiceAccountID  string
	WorkspaceID       string
}

WIFOpts configures an outbound RFC 7523 jwt-bearer Workload Identity Federation item (such as Anthropic's POST /v1/oauth/token) so Veil mints a short-lived upstream access token per use without storing a static API key.

Jump to

Keyboard shortcuts

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