Documentation
¶
Overview ¶
Package keystore provides key management for Cardano stake pool operators. It wraps pool credentials (VRF, KES, OpCert) and handles KES key evolution as the blockchain progresses through KES periods.
Index ¶
- Constants
- Variables
- func DefaultKESPeriodDuration() time.Duration
- func DefaultOpCertLifetimeDuration() time.Duration
- func DefaultOpCertLifetimeSlots() uint64
- func KESPeriodDuration(slotsPerPeriod uint64, slotDuration time.Duration) time.Duration
- func KESPeriodEndSlot(period, slotsPerPeriod uint64) uint64
- func KESPeriodStartSlot(period, slotsPerPeriod uint64) uint64
- func OpCertLifetimeDuration(slotsPerPeriod, maxEvolutions uint64, slotDuration time.Duration) time.Duration
- func OpCertLifetimeSlots(slotsPerPeriod, maxEvolutions uint64) uint64
- func SlotToKESPeriod(slot, slotsPerPeriod uint64) uint64
- type ExpiryWarningThresholds
- type KESSigner
- type KeyStore
- func (ks *KeyStore) CurrentKESPeriod() uint64
- func (ks *KeyStore) EvolveKESTo(targetPeriod uint64) error
- func (ks *KeyStore) IsLoaded() bool
- func (ks *KeyStore) KESSigner() KESSigner
- func (ks *KeyStore) LoadFromFiles() error
- func (ks *KeyStore) OpCert() *OpCert
- func (ks *KeyStore) OpCertExpiryPeriod() uint64
- func (ks *KeyStore) PeriodsRemaining(currentPeriod uint64) uint64
- func (ks *KeyStore) PoolID() *lcommon.PoolId
- func (ks *KeyStore) Start(ctx context.Context, slotClock SlotClock) error
- func (ks *KeyStore) Stop() error
- func (ks *KeyStore) VRFSigner() VRFSigner
- func (ks *KeyStore) ValidateOpCert() error
- type KeyStoreConfig
- type OpCert
- type SlotClock
- type SlotTick
- type VRFSigner
Constants ¶
const ( // DefaultSlotsPerKESPeriod is the number of slots in a KES period on preview. // After this many slots, the KES key must be evolved to the next period. // Preview value: 129600 slots = 1.5 days (at 1 second per slot) DefaultSlotsPerKESPeriod = 129600 // DefaultMaxKESEvolutions is the maximum number of times a KES key can evolve. // For Cardano's KES depth of 6, this is 2^6 - 2 = 62 evolutions. // After this many evolutions, a new operational certificate must be issued. DefaultMaxKESEvolutions = 62 // DefaultSlotDuration is the default slot duration on preview (1 second). DefaultSlotDuration = time.Second )
KES (Key Evolving Signature) constants for Cardano. These values are defined in the Shelley genesis configuration and determine how often KES keys must be evolved. Default values are for the preview network (Dingo's default network).
Variables ¶
var ( ErrKeysNotLoaded = errors.New("keys not loaded") ErrVRFKeyNotLoaded = errors.New("VRF key not loaded") ErrKESKeyNotLoaded = errors.New("KES key not loaded") ErrOpCertNotLoaded = errors.New("operational certificate not loaded") ErrAlreadyRunning = errors.New("keystore already running") ErrNotRunning = errors.New("keystore not running") ErrInsecureFileMode = errors.New("insecure file mode") )
Common errors returned by KeyStore operations.
Functions ¶
func DefaultKESPeriodDuration ¶
DefaultKESPeriodDuration returns the KES period duration using preview defaults. This is approximately 1.5 days.
func DefaultOpCertLifetimeDuration ¶
DefaultOpCertLifetimeDuration returns the OpCert lifetime using preview defaults.
func DefaultOpCertLifetimeSlots ¶
func DefaultOpCertLifetimeSlots() uint64
DefaultOpCertLifetimeSlots returns the OpCert lifetime using preview defaults. This is approximately 93 days (62 periods * 1.5 days per period).
func KESPeriodDuration ¶
KESPeriodDuration returns the approximate wall-clock duration of a KES period. This is useful for calculating when the next evolution will occur.
func KESPeriodEndSlot ¶
KESPeriodEndSlot returns the last slot of the given KES period. Returns 0 if slotsPerPeriod is 0 to avoid underflow.
func KESPeriodStartSlot ¶
KESPeriodStartSlot returns the first slot of the given KES period.
func OpCertLifetimeDuration ¶
func OpCertLifetimeDuration( slotsPerPeriod, maxEvolutions uint64, slotDuration time.Duration, ) time.Duration
OpCertLifetimeDuration returns the approximate wall-clock duration an OpCert is valid.
func OpCertLifetimeSlots ¶
OpCertLifetimeSlots returns the total number of slots an OpCert is valid for.
func SlotToKESPeriod ¶
SlotToKESPeriod converts a slot number to a KES period. Returns 0 if slotsPerPeriod is 0 to avoid division by zero.
Types ¶
type ExpiryWarningThresholds ¶
type ExpiryWarningThresholds struct {
// Critical: OpCert is about to expire, cannot produce blocks soon
Critical uint64
// Warning: OpCert should be renewed soon
Warning uint64
// Info: OpCert expiry is approaching
Info uint64
}
ExpiryWarningThresholds defines warning thresholds for OpCert expiry. These are the number of KES periods remaining before expiry.
func DefaultExpiryWarningThresholds ¶
func DefaultExpiryWarningThresholds() ExpiryWarningThresholds
DefaultExpiryWarningThresholds returns the default warning thresholds.
type KESSigner ¶
type KESSigner interface {
// Sign signs a message at the specified KES period.
Sign(period uint64, message []byte) ([]byte, error)
// VKey returns the KES verification key.
VKey() []byte
// CurrentPeriod returns the current KES period the key is evolved to.
CurrentPeriod() uint64
}
KESSigner provides KES signing capabilities for block production.
type KeyStore ¶
type KeyStore struct {
// contains filtered or unexported fields
}
KeyStore manages pool credentials and KES key evolution.
func NewKeyStore ¶
func NewKeyStore(config KeyStoreConfig) *KeyStore
NewKeyStore creates a new KeyStore with the given configuration.
func (*KeyStore) CurrentKESPeriod ¶
CurrentKESPeriod returns the current KES period the key is evolved to.
func (*KeyStore) EvolveKESTo ¶
EvolveKESTo evolves the KES key to the specified period.
func (*KeyStore) KESSigner ¶
KESSigner returns a KES signer for block signing. Returns nil if KES key is not loaded.
func (*KeyStore) LoadFromFiles ¶
LoadFromFiles loads all pool credentials from the configured file paths. Parses cardano-cli format key files.
func (*KeyStore) OpCert ¶
OpCert returns a copy of the operational certificate. Returns nil if not loaded.
func (*KeyStore) OpCertExpiryPeriod ¶
OpCertExpiryPeriod returns the KES period at which the OpCert expires.
func (*KeyStore) PeriodsRemaining ¶
PeriodsRemaining returns how many KES periods remain before expiry.
func (*KeyStore) PoolID ¶
PoolID returns the pool ID (Blake2b-224 of cold vkey). Returns nil if not loaded.
func (*KeyStore) Start ¶
Start begins KES evolution monitoring using the provided slot clock. The keystore will automatically evolve the KES key when the period advances.
func (*KeyStore) Stop ¶
Stop halts KES evolution monitoring, zeros secret key material from memory, and cleans up resources.
func (*KeyStore) VRFSigner ¶
VRFSigner returns a VRF signer for leader election. Returns nil if VRF key is not loaded.
func (*KeyStore) ValidateOpCert ¶
ValidateOpCert validates that the operational certificate matches the KES key.
type KeyStoreConfig ¶
type KeyStoreConfig struct {
// VRFSKeyPath is the path to the VRF signing key file.
VRFSKeyPath string
// KESSKeyPath is the path to the KES signing key file.
KESSKeyPath string
// OpCertPath is the path to the operational certificate file.
OpCertPath string
// SlotsPerKESPeriod is the number of slots in a KES period.
// Default: 129600 (preview network value)
SlotsPerKESPeriod uint64
// MaxKESEvolutions is the maximum number of KES evolutions.
// Default: 62 (for KES depth 6)
MaxKESEvolutions uint64
// Logger for keystore events.
Logger *slog.Logger
}
KeyStoreConfig holds configuration for the KeyStore.
func DefaultKeyStoreConfig ¶
func DefaultKeyStoreConfig() KeyStoreConfig
DefaultKeyStoreConfig returns the default configuration.
type OpCert ¶
type OpCert struct {
KESVKey []byte // KES verification key (32 bytes)
IssueNumber uint64 // Certificate sequence number
KESPeriod uint64 // KES period when certificate was created
Signature []byte // Cold key signature (64 bytes)
ColdVKey []byte // Cold verification key (32 bytes)
}
OpCert represents an operational certificate that binds a KES key to a pool.
type SlotClock ¶
type SlotClock interface {
// CurrentSlot returns the current slot number.
CurrentSlot() (uint64, error)
// Subscribe returns a channel that receives slot tick notifications.
Subscribe() <-chan SlotTick
// Unsubscribe removes a subscriber channel.
Unsubscribe(ch <-chan SlotTick)
}
SlotClock provides slot information for KES evolution monitoring.