Documentation
¶
Overview ¶
Package slhdsafx provides SLH-DSA (FIPS 205) hash-based post-quantum credentials for high-assurance UTXO spending on X-Chain.
SLH-DSA is a stateless hash-based signature scheme that provides security against both classical and quantum computer attacks. Hash-based signatures have the strongest security assumptions of any PQ scheme.
This package supports six parameter sets across three security levels:
- SHA2-128f / SHAKE-128f: 128-bit security, fast signing
- SHA2-192f / SHAKE-192f: 192-bit security, balanced (default)
- SHA2-256f / SHAKE-256f: 256-bit security, highest security
"f" (fast) variants are used over "s" (small) because UTXO spending prioritizes signing latency over signature size.
Index ¶
- Constants
- Variables
- type Credential
- type Factory
- type Fx
- func (fx *Fx) Bootstrapped() error
- func (*Fx) Bootstrapping() error
- func (*Fx) CreateOutput(amount uint64, ownerIntf interface{}) (interface{}, error)
- func (fx *Fx) Initialize(vmIntf interface{}) error
- func (fx *Fx) InitializeVM(vmIntf interface{}) error
- func (fx *Fx) VerifyCredentials(utx UnsignedTx, in *Input, cred *Credential, out *OutputOwners) error
- func (fx *Fx) VerifyOperation(txIntf, opIntf, credIntf interface{}, utxosIntf []interface{}) error
- func (fx *Fx) VerifyPermission(txIntf, inIntf, credIntf, ownerIntf interface{}) error
- func (fx *Fx) VerifySpend(utx UnsignedTx, in *TransferInput, cred *Credential, utxo *TransferOutput) error
- func (fx *Fx) VerifyTransfer(txIntf, inIntf, credIntf, utxoIntf interface{}) error
- type Input
- type Keychain
- func (kc *Keychain) Add(key *slhdsa.PrivateKey)
- func (kc Keychain) Addresses() set.Set[ids.ShortID]
- func (kc Keychain) Get(id ids.ShortID) (keychain.Signer, bool)
- func (kc *Keychain) Match(owners *OutputOwners, time uint64) ([]uint32, []*slhdsa.PrivateKey, bool)
- func (kc *Keychain) New() (*slhdsa.PrivateKey, error)
- func (kc *Keychain) Spend(out verify.Verifiable, time uint64) (verify.Verifiable, []*slhdsa.PrivateKey, error)
- type MintOperation
- type MintOutput
- type OutputOwners
- type SecurityLevel
- type TestTx
- type TestVM
- type TransferInput
- type TransferOutput
- type UnsignedTx
- type VM
Constants ¶
const ( // SHA2-128f (NIST Level 1, fast) SLH128fPubKeyLen = 32 SLH128fSigLen = 17088 // SHA2-192f (NIST Level 3, fast) - DEFAULT SLH192fPubKeyLen = 48 SLH192fSigLen = 35664 // SHA2-256f (NIST Level 5, fast) SLH256fPubKeyLen = 64 SLH256fSigLen = 49856 )
Signature and public key sizes from FIPS 205 specification.
const ( // CostPerSignature is the compute cost per SLH-DSA signature verification. // Benchmarked at ~862us vs secp256k1 ~40us (21.5x ratio). // secp256k1 CostPerSignature = 1000, so SLH-DSA = 22000. CostPerSignature uint64 = 22000 )
const Name = "slhdsafx"
Variables ¶
var ( ErrNilCredential = errors.New("nil SLH-DSA credential") ErrEmptyCredential = errors.New("empty SLH-DSA credential") ErrInvalidSignature = errors.New("invalid SLH-DSA signature") ErrInvalidSecLevel = errors.New("invalid SLH-DSA security level") ErrSignatureTooShort = errors.New("SLH-DSA signature too short") ErrMismatchedSecLevel = errors.New("signature length doesn't match security level") )
var ( ErrWrongVMType = errors.New("wrong vm type") ErrWrongTxType = errors.New("wrong tx type") ErrWrongOpType = errors.New("wrong operation type") ErrWrongUTXOType = errors.New("wrong utxo type") ErrWrongInputType = errors.New("wrong input type") ErrWrongCredentialType = errors.New("wrong credential type") ErrWrongOwnerType = errors.New("wrong owner type") ErrMismatchedAmounts = errors.New("utxo amount and input amount are not equal") ErrWrongNumberOfUTXOs = errors.New("wrong number of utxos for the operation") ErrWrongMintCreated = errors.New("wrong mint output created from the operation") ErrTimelocked = errors.New("output is time locked") ErrTooManySigners = errors.New("input has more signers than expected") ErrTooFewSigners = errors.New("input has less signers than expected") ErrInputOutputIndexOutOfBounds = errors.New("input referenced a nonexistent address in the output") ErrInputCredentialSignersMismatch = errors.New("input expected a different number of signers than provided in the credential") ErrWrongSig = errors.New("wrong signature") )
var ( ErrNilInput = errors.New("nil input") ErrInputIndicesNotSortedUnique = errors.New("address indices not sorted and unique") )
var ( ErrNilOutputOwners = errors.New("nil SLH-DSA output owners") ErrNilPublicKey = errors.New("nil SLH-DSA public key") ErrThresholdExceeded = errors.New("threshold exceeds number of addresses") ErrOutputUnoptimized = errors.New("output representation should be optimized") ErrOutputNotSpendable = errors.New("output not yet spendable") ErrInvalidPubKeyLength = errors.New("invalid SLH-DSA public key length") )
var ErrNoValueInput = errors.New("input has no value")
var (
ErrNoValueOutput = errors.New("output has no value")
)
var ( // ID that this Fx uses when labeled ID = ids.ID{'s', 'l', 'h', 'd', 's', 'a', 'f', 'x'} )
Functions ¶
This section is empty.
Types ¶
type Credential ¶
type Credential struct {
// Level indicates the SLH-DSA parameter set
Level SecurityLevel `serialize:"true" json:"securityLevel"`
// Sigs contains the SLH-DSA signatures (variable length based on Level)
Sigs [][]byte `serialize:"true" json:"signatures"`
}
Credential contains SLH-DSA signatures for spending UTXOs.
func NewCredential ¶
func NewCredential(level SecurityLevel, sigs [][]byte) (*Credential, error)
NewCredential creates a new SLH-DSA credential at the specified security level
func NewCredential192f ¶
func NewCredential192f(sigs [][]byte) (*Credential, error)
NewCredential192f creates a credential using the recommended SLH-DSA-SHA2-192f level
func (*Credential) MarshalJSON ¶
func (cr *Credential) MarshalJSON() ([]byte, error)
MarshalJSON marshals the credential to JSON with hex-encoded signatures
func (*Credential) UnmarshalJSON ¶
func (cr *Credential) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals JSON into the credential
func (*Credential) Verify ¶
func (cr *Credential) Verify() error
Verify validates the credential structure (not cryptographic validity).
type Fx ¶
type Fx struct {
VM VM
// contains filtered or unexported fields
}
Fx describes the SLH-DSA feature extension for post-quantum secure UTXO spending
func (*Fx) Bootstrapped ¶
func (*Fx) Bootstrapping ¶
func (*Fx) CreateOutput ¶
CreateOutput creates a new output with the provided control group worth the specified amount
func (*Fx) Initialize ¶
func (*Fx) InitializeVM ¶
func (*Fx) VerifyCredentials ¶
func (fx *Fx) VerifyCredentials(utx UnsignedTx, in *Input, cred *Credential, out *OutputOwners) error
VerifyCredentials ensures that the output can be spent by the input with the credential. SLH-DSA signatures are verified directly against the public key stored in OutputOwners.Addrs.
func (*Fx) VerifyOperation ¶
func (*Fx) VerifyPermission ¶
VerifyPermission returns nil iff [credIntf] proves that [ownerIntf] assents to [txIntf]
func (*Fx) VerifySpend ¶
func (fx *Fx) VerifySpend(utx UnsignedTx, in *TransferInput, cred *Credential, utxo *TransferOutput) error
VerifySpend ensures that the utxo can be sent to any address
func (*Fx) VerifyTransfer ¶
type Input ¶
type Input struct {
SigIndices []uint32 `serialize:"true" json:"signatureIndices"`
}
Input references signature indices into the credential for spending.
type Keychain ¶
type Keychain struct {
Addrs set.Set[ids.ShortID]
Keys []*slhdsa.PrivateKey
// contains filtered or unexported fields
}
Keychain is a collection of SLH-DSA keys that can be used to spend outputs
func NewKeychain ¶
func NewKeychain(keys ...*slhdsa.PrivateKey) *Keychain
NewKeychain returns a new keychain containing [keys]
func (*Keychain) Add ¶
func (kc *Keychain) Add(key *slhdsa.PrivateKey)
Add a new key to the key chain
func (*Keychain) Match ¶
func (kc *Keychain) Match(owners *OutputOwners, time uint64) ([]uint32, []*slhdsa.PrivateKey, bool)
Match attempts to match a list of addresses up to the provided threshold
func (*Keychain) New ¶
func (kc *Keychain) New() (*slhdsa.PrivateKey, error)
New generates a new SLH-DSA-SHA2-192f key pair and adds it to the keychain
func (*Keychain) Spend ¶
func (kc *Keychain) Spend(out verify.Verifiable, time uint64) (verify.Verifiable, []*slhdsa.PrivateKey, error)
Spend attempts to create an input for the given output
type MintOperation ¶
type MintOperation struct {
MintInput Input `serialize:"true" json:"mintInput"`
MintOutput MintOutput `serialize:"true" json:"mintOutput"`
TransferOutput TransferOutput `serialize:"true" json:"transferOutput"`
}
func (*MintOperation) Cost ¶
func (op *MintOperation) Cost() (uint64, error)
func (*MintOperation) Outs ¶
func (op *MintOperation) Outs() []verify.State
func (*MintOperation) Verify ¶
func (op *MintOperation) Verify() error
type MintOutput ¶
type MintOutput struct {
verify.IsState `serialize:"-" json:"-"`
OutputOwners `serialize:"true"`
}
func (*MintOutput) Verify ¶
func (out *MintOutput) Verify() error
type OutputOwners ¶
type OutputOwners struct {
// Level indicates the SLH-DSA parameter set for all addresses
Level SecurityLevel `serialize:"true" json:"securityLevel"`
// Locktime is the Unix timestamp after which this output can be spent
Locktime uint64 `serialize:"true" json:"locktime"`
// Threshold is the number of signatures required to spend
Threshold uint32 `serialize:"true" json:"threshold"`
// Addrs are the SLH-DSA public keys that can sign to spend
Addrs [][]byte `serialize:"true" json:"addresses"`
}
OutputOwners describes who can spend an output locked with SLH-DSA keys.
func (*OutputOwners) Addresses ¶
func (out *OutputOwners) Addresses() []ids.ShortID
Addresses returns short IDs derived from the SLH-DSA public keys. Public keys are hashed via SHA256+RIPEMD160 to produce 20-byte addresses.
func (*OutputOwners) Equals ¶
func (out *OutputOwners) Equals(other *OutputOwners) bool
Equals returns true if the provided owners create the same condition
func (*OutputOwners) MarshalJSON ¶
func (out *OutputOwners) MarshalJSON() ([]byte, error)
MarshalJSON marshals the output owners to JSON
func (*OutputOwners) Verify ¶
func (out *OutputOwners) Verify() error
Verify validates the output owners structure
type SecurityLevel ¶
type SecurityLevel uint8
SecurityLevel indicates the SLH-DSA parameter set
const ( // SecLevelSLH128f is 128-bit security with fast signing SecLevelSLH128f SecurityLevel = iota // SecLevelSLH192f is 192-bit security with fast signing (recommended default) SecLevelSLH192f // SecLevelSLH256f is 256-bit security with fast signing SecLevelSLH256f )
func (SecurityLevel) PubKeyLen ¶
func (s SecurityLevel) PubKeyLen() int
PubKeyLen returns the public key length for this security level
func (SecurityLevel) SignatureLen ¶
func (s SecurityLevel) SignatureLen() int
SignatureLen returns the signature length for this security level
func (SecurityLevel) String ¶
func (s SecurityLevel) String() string
String returns the human-readable name
type TransferInput ¶
func (*TransferInput) Amount ¶
func (in *TransferInput) Amount() uint64
Amount returns the quantity of the asset this input produces
func (*TransferInput) InitRuntime ¶
func (*TransferInput) InitRuntime(*runtime.Runtime)
func (*TransferInput) Verify ¶
func (in *TransferInput) Verify() error
Verify this input is syntactically valid
type TransferOutput ¶
type TransferOutput struct {
verify.IsState `serialize:"-" json:"-"`
Amt uint64 `serialize:"true" json:"amount"`
OutputOwners `serialize:"true"`
}
func (*TransferOutput) Amount ¶
func (out *TransferOutput) Amount() uint64
Amount returns the quantity of the asset this output consumes
func (*TransferOutput) Owners ¶
func (out *TransferOutput) Owners() interface{}
func (*TransferOutput) Verify ¶
func (out *TransferOutput) Verify() error
type UnsignedTx ¶
type UnsignedTx interface {
Bytes() []byte
}
UnsignedTx that this Fx is supporting