identity

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package identity manages the behalf state directory and the two local Ed25519 keys that live in it:

  • the device key — the human principal's root key. Its RFC 7638 JWK thumbprint is the OIDC nonce at `behalf login` (D5), which makes it the verified identity root. Generated fresh at login.
  • the emitter key — the capture surface's own key (receipt-schema-v1.md §5, Q19). It signs receipt DSSE envelopes and is distinct from any human device key.

The state directory defaults to ~/.behalf, overridable via the BEHALF_HOME environment variable or an explicit --dir flag. Private key files are written with mode 0600 and the directory with 0700.

Index

Constants

View Source
const (
	DeviceKeyFile  = "device_key.jwk"
	EmitterKeyFile = "emitter_key.jwk"
	CounterFile    = "emitter.counter"
	BlobsDirName   = "blobs"
)

File names inside the state directory.

View Source
const DefaultDirName = ".behalf"

DefaultDirName is the state directory created under $HOME by default.

View Source
const EnvHome = "BEHALF_HOME"

EnvHome is the environment variable that overrides the default state dir.

Variables

This section is empty.

Functions

func BlobsDir

func BlobsDir(dir string) string

BlobsDir returns the content-addressed store directory under dir.

func DeviceKeyPath

func DeviceKeyPath(dir string) string

DeviceKeyPath returns the device key file path under dir.

func EmitterKeyPath

func EmitterKeyPath(dir string) string

EmitterKeyPath returns the emitter key file path under dir.

func EnsureDir

func EnsureDir(dir string) error

EnsureDir creates the state directory (and its blobs/ subdirectory) with owner-only permissions if it does not exist.

func NextEmitterCounter

func NextEmitterCounter(dir string) (int, error)

NextEmitterCounter returns the next per-emitter monotonic counter value and persists the advance (receipt-schema-v1.md §5, Q48). The first call returns 0. Single-process use only, which is the CLI's situation; the log service owns cross-process sequencing.

func ResolveDir

func ResolveDir(explicit string) (string, error)

ResolveDir returns the state directory: explicit (from a --dir flag) if non-empty, else $BEHALF_HOME if set, else ~/.behalf.

func SaveDevice

func SaveDevice(dir string, k *Key) error

SaveDevice persists the device key under dir with mode 0600.

func SaveKey

func SaveKey(k *Key, path string) error

SaveKey writes k's private JWK to path with mode 0600. The write is atomic: a temp file in the same directory is renamed into place.

Types

type Key

type Key struct {
	Private ed25519.PrivateKey
	Public  ed25519.PublicKey
	JWK     dsse.JWK
	JKT     string
}

Key is a local Ed25519 keypair with its JWK form and RFC 7638 thumbprint.

func Generate

func Generate() (*Key, error)

Generate creates a fresh Ed25519 keypair.

func LoadDevice

func LoadDevice(dir string) (*Key, error)

LoadDevice loads the device key from dir. os.IsNotExist on the returned error distinguishes "never logged in" from corruption.

func LoadKey

func LoadKey(path string) (*Key, error)

LoadKey reads a private JWK written by SaveKey.

func LoadOrGenerateEmitter

func LoadOrGenerateEmitter(dir string) (*Key, error)

LoadOrGenerateEmitter returns the emitter key from dir, generating and persisting one on first use. The emitter key is the capture surface's own key, distinct from any device key (Q19).

Jump to

Keyboard shortcuts

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