Documentation
¶
Overview ¶
Package kchainvm implements the K-Chain Virtual Machine for distributed key management using ML-KEM post-quantum cryptography and threshold sharing.
Index ¶
- Constants
- Variables
- type AlgorithmInfo
- type Block
- func (b *Block) Accept(ctx context.Context) error
- func (b *Block) Bytes() []byte
- func (b *Block) Height() uint64
- func (b *Block) ID() ids.ID
- func (b *Block) ParentID() ids.ID
- func (b *Block) Reject(ctx context.Context) error
- func (b *Block) SetStatus(status string)
- func (b *Block) Status() string
- func (b *Block) Timestamp() int64
- func (b *Block) Verify(ctx context.Context) error
- type CreateKeyArgs
- type CreateKeyPayload
- type CreateKeyReply
- type DeleteKeyArgs
- type DeleteKeyPayload
- type DeleteKeyReply
- type DistributeKeyPayload
- type EncryptArgs
- type EncryptReply
- type Factory
- type GetKeyByIDArgs
- type GetKeyByIDReply
- type GetKeyByNameArgs
- type GetKeyByNameReply
- type HealthArgs
- type HealthReply
- type KeyMetadata
- type KeyMetadataReply
- type KeyShare
- type ListAlgorithmsArgs
- type ListAlgorithmsReply
- type ListKeysArgs
- type ListKeysReply
- type ReshareKeyPayload
- type RevokeKeyPayload
- type Service
- func (s *Service) CreateKey(r *http.Request, args *CreateKeyArgs, reply *CreateKeyReply) error
- func (s *Service) DeleteKey(r *http.Request, args *DeleteKeyArgs, reply *DeleteKeyReply) error
- func (s *Service) Encrypt(r *http.Request, args *EncryptArgs, reply *EncryptReply) error
- func (s *Service) GetKeyByID(r *http.Request, args *GetKeyByIDArgs, reply *GetKeyByIDReply) error
- func (s *Service) GetKeyByName(r *http.Request, args *GetKeyByNameArgs, reply *GetKeyByNameReply) error
- func (s *Service) Health(r *http.Request, args *HealthArgs, reply *HealthReply) error
- func (s *Service) ListAlgorithms(r *http.Request, args *ListAlgorithmsArgs, reply *ListAlgorithmsReply) error
- func (s *Service) ListKeys(r *http.Request, args *ListKeysArgs, reply *ListKeysReply) error
- type Transaction
- func (tx *Transaction) Bytes() []byte
- func (tx *Transaction) Execute(ctx context.Context, vm *VM) error
- func (tx *Transaction) ID() ids.ID
- func (tx *Transaction) KeyID() ids.ID
- func (tx *Transaction) Payload() []byte
- func (tx *Transaction) Timestamp() time.Time
- func (tx *Transaction) Type() uint8
- func (tx *Transaction) Verify(ctx context.Context) error
- type UpdateKeyMetaPayload
- type VM
- func (vm *VM) BuildBlock(ctx context.Context) (consensuscore.Block, error)
- func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error
- func (vm *VM) CreateHandlers(ctx context.Context) (map[string]http.Handler, error)
- func (vm *VM) CreateKey(ctx context.Context, name, algorithm string, threshold, totalShares int) (*KeyMetadata, error)
- func (vm *VM) CreateStaticHandlers(ctx context.Context) (map[string]http.Handler, error)
- func (vm *VM) DeleteKey(ctx context.Context, keyID ids.ID) error
- func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error
- func (vm *VM) Encrypt(ctx context.Context, keyID ids.ID, plaintext []byte) ([]byte, []byte, error)
- func (vm *VM) GetBlock(ctx context.Context, blockID ids.ID) (consensuscore.Block, error)
- func (vm *VM) GetKey(ctx context.Context, keyID ids.ID) (*KeyMetadata, error)
- func (vm *VM) GetKeyByName(ctx context.Context, name string) (*KeyMetadata, error)
- func (vm *VM) HealthCheck(ctx context.Context) (interface{}, error)
- func (vm *VM) Initialize(ctx context.Context, chainCtx interface{}, db database.Database, ...) error
- func (vm *VM) ListKeys(ctx context.Context) ([]*KeyMetadata, error)
- func (vm *VM) ParseBlock(ctx context.Context, blockBytes []byte) (consensuscore.Block, error)
- func (vm *VM) SetState(ctx context.Context, state consensusinterfaces.State) error
- func (vm *VM) Shutdown(ctx context.Context) error
- func (vm *VM) Version(ctx context.Context) (string, error)
Constants ¶
const ( TxTypeCreateKey = 1 TxTypeDeleteKey = 2 TxTypeDistributeKey = 3 TxTypeUpdateKeyMeta = 5 TxTypeRevokeKey = 6 )
Transaction types
const ( // Version of the K-Chain VM Version = "1.0.0" // VMID is the unique identifier for K-Chain VM VMID = "kchainvm" // MaxParallelOperations is the maximum number of concurrent crypto operations MaxParallelOperations = 100 SharePrefix = "share:" // KeyPrefix is the database prefix for key metadata KeyPrefix = "key:" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AlgorithmInfo ¶
type AlgorithmInfo struct {
Name string `json:"name"`
Type string `json:"type"`
SecurityLevel int `json:"securityLevel"`
KeySize int `json:"keySize"`
SignatureSize int `json:"signatureSize"`
PostQuantum bool `json:"postQuantum"`
ThresholdSupport bool `json:"thresholdSupport"`
Description string `json:"description"`
Standards []string `json:"standards"`
}
AlgorithmInfo describes a supported algorithm.
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block represents a K-Chain block containing key management transactions.
type CreateKeyArgs ¶
type CreateKeyArgs struct {
Name string `json:"name"`
Algorithm string `json:"algorithm"`
Threshold int `json:"threshold"`
Tags []string `json:"tags"`
}
CreateKeyArgs contains arguments for CreateKey.
type CreateKeyPayload ¶
CreateKeyPayload represents the payload for a CreateKey transaction.
type CreateKeyReply ¶
type CreateKeyReply struct {
Key KeyMetadataReply `json:"key"`
PublicKey string `json:"publicKey"`
}
CreateKeyReply contains the response for CreateKey.
type DeleteKeyArgs ¶
DeleteKeyArgs contains arguments for DeleteKey.
type DeleteKeyPayload ¶
type DeleteKeyPayload struct {
Force bool
}
DeleteKeyPayload represents the payload for a DeleteKey transaction.
type DeleteKeyReply ¶
type DeleteKeyReply struct {
Success bool `json:"success"`
}
DeleteKeyReply contains the response for DeleteKey.
type DistributeKeyPayload ¶
DistributeKeyPayload represents the payload for a DistributeKey transaction.
type EncryptArgs ¶
type EncryptArgs struct {
KeyID string `json:"keyId"`
Plaintext string `json:"plaintext"` // Base64-encoded
}
EncryptArgs contains arguments for Encrypt.
type EncryptReply ¶
type EncryptReply struct {
Ciphertext string `json:"ciphertext"` // Base64-encoded
Nonce string `json:"nonce"`
Tag string `json:"tag"`
}
EncryptReply contains the response for Encrypt.
type Factory ¶
Factory implements vms.Factory interface for creating K-Chain VM instances.
func NewDefaultFactory ¶
func NewDefaultFactory() *Factory
NewDefaultFactory creates a new K-Chain VM factory with default configuration.
func NewFactory ¶
NewFactory creates a new K-Chain VM factory with the given configuration.
type GetKeyByIDArgs ¶
type GetKeyByIDArgs struct {
ID string `json:"id"`
}
GetKeyByIDArgs contains arguments for GetKeyByID.
type GetKeyByIDReply ¶
type GetKeyByIDReply struct {
KeyMetadataReply
}
GetKeyByIDReply contains the response for GetKeyByID.
type GetKeyByNameArgs ¶
type GetKeyByNameArgs struct {
Name string `json:"name"`
}
GetKeyByNameArgs contains arguments for GetKeyByName.
type GetKeyByNameReply ¶
type GetKeyByNameReply struct {
KeyMetadataReply
}
GetKeyByNameReply contains the response for GetKeyByName.
type HealthReply ¶
type HealthReply struct {
Healthy bool `json:"healthy"`
Version string `json:"version"`
Validators map[string]bool `json:"validators"`
Latency map[string]int64 `json:"latency"`
}
HealthReply contains the response for Health.
type KeyMetadata ¶
type KeyMetadata struct {
ID ids.ID `json:"id"`
Name string `json:"name"`
Algorithm string `json:"algorithm"`
KeyType string `json:"keyType"`
PublicKey []byte `json:"publicKey"`
Threshold int `json:"threshold"`
Validators []string `json:"validators"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Status string `json:"status"`
Tags []string `json:"tags"`
Metadata map[string]string `json:"metadata"`
}
KeyMetadata stores information about a distributed key.
type KeyMetadataReply ¶
type KeyMetadataReply struct {
ID string `json:"id"`
Name string `json:"name"`
Algorithm string `json:"algorithm"`
KeyType string `json:"keyType"`
PublicKey string `json:"publicKey"`
Threshold int `json:"threshold"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
Status string `json:"status"`
Tags []string `json:"tags"`
}
KeyMetadataReply is the JSON representation of KeyMetadata.
type ListAlgorithmsArgs ¶
type ListAlgorithmsArgs struct{}
ListAlgorithmsArgs contains arguments for ListAlgorithms.
type ListAlgorithmsReply ¶
type ListAlgorithmsReply struct {
Algorithms []AlgorithmInfo `json:"algorithms"`
}
ListAlgorithmsReply contains the response for ListAlgorithms.
type ListKeysArgs ¶
type ListKeysArgs struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
Algorithm string `json:"algorithm"`
Status string `json:"status"`
}
ListKeysArgs contains arguments for ListKeys.
type ListKeysReply ¶
type ListKeysReply struct {
Keys []KeyMetadataReply `json:"keys"`
Total int `json:"total"`
}
ListKeysReply contains the response for ListKeys.
type ReshareKeyPayload ¶
type ReshareKeyPayload struct {
}
ReshareKeyPayload represents the payload for a ReshareKey transaction.
type RevokeKeyPayload ¶
type RevokeKeyPayload struct {
Reason string
}
RevokeKeyPayload represents the payload for a RevokeKey transaction.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides JSON-RPC endpoints for the K-Chain VM.
func (*Service) CreateKey ¶
func (s *Service) CreateKey(r *http.Request, args *CreateKeyArgs, reply *CreateKeyReply) error
CreateKey creates a new distributed key.
func (*Service) DeleteKey ¶
func (s *Service) DeleteKey(r *http.Request, args *DeleteKeyArgs, reply *DeleteKeyReply) error
DeleteKey deletes a key.
func (*Service) Encrypt ¶
func (s *Service) Encrypt(r *http.Request, args *EncryptArgs, reply *EncryptReply) error
Encrypt encrypts data.
func (*Service) GetKeyByID ¶
func (s *Service) GetKeyByID(r *http.Request, args *GetKeyByIDArgs, reply *GetKeyByIDReply) error
GetKeyByID retrieves a key by ID.
func (*Service) GetKeyByName ¶
func (s *Service) GetKeyByName(r *http.Request, args *GetKeyByNameArgs, reply *GetKeyByNameReply) error
GetKeyByName retrieves a key by name.
func (*Service) Health ¶
func (s *Service) Health(r *http.Request, args *HealthArgs, reply *HealthReply) error
Health checks service health.
func (*Service) ListAlgorithms ¶
func (s *Service) ListAlgorithms(r *http.Request, args *ListAlgorithmsArgs, reply *ListAlgorithmsReply) error
ListAlgorithms lists supported algorithms.
func (*Service) ListKeys ¶
func (s *Service) ListKeys(r *http.Request, args *ListKeysArgs, reply *ListKeysReply) error
ListKeys lists all keys.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction represents a K-Chain transaction.
func NewTransaction ¶
NewTransaction creates a new transaction.
func ParseTransaction ¶
func ParseTransaction(data []byte) (*Transaction, error)
ParseTransaction deserializes a transaction from bytes.
func (*Transaction) Bytes ¶
func (tx *Transaction) Bytes() []byte
Bytes serializes the transaction to bytes.
func (*Transaction) Execute ¶
func (tx *Transaction) Execute(ctx context.Context, vm *VM) error
Execute executes the transaction against the VM state.
func (*Transaction) ID ¶
func (tx *Transaction) ID() ids.ID
ID returns the transaction's unique identifier.
func (*Transaction) KeyID ¶
func (tx *Transaction) KeyID() ids.ID
KeyID returns the key ID this transaction operates on.
func (*Transaction) Payload ¶
func (tx *Transaction) Payload() []byte
Payload returns the transaction payload.
func (*Transaction) Timestamp ¶
func (tx *Transaction) Timestamp() time.Time
Timestamp returns the transaction timestamp.
type UpdateKeyMetaPayload ¶
UpdateKeyMetaPayload represents the payload for an UpdateKeyMeta transaction.
type VM ¶
VM implements the K-Chain Virtual Machine.
func (*VM) BuildBlock ¶
BuildBlock builds a new block from pending transactions.
func (*VM) Connected ¶
func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, nodeVersion *version.Application) error
Connected handles node connection events.
func (*VM) CreateHandlers ¶
CreateHandlers returns HTTP handlers for the VM.
func (*VM) CreateKey ¶
func (vm *VM) CreateKey(ctx context.Context, name, algorithm string, threshold, totalShares int) (*KeyMetadata, error)
CreateKey creates a new distributed key.
func (*VM) CreateStaticHandlers ¶
CreateStaticHandlers returns static HTTP handlers.
func (*VM) Disconnected ¶
Disconnected handles node disconnection events.
func (*VM) GetKeyByName ¶
GetKeyByName retrieves key metadata by name.
func (*VM) HealthCheck ¶
HealthCheck returns VM health status.
func (*VM) Initialize ¶
func (vm *VM) Initialize( ctx context.Context, chainCtx interface{}, db database.Database, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, toEngine chan<- consensuscore.Message, fxs []*consensuscore.Fx, appSender warp.Sender, ) error
Initialize initializes the K-Chain VM.
func (*VM) ListKeys ¶
func (vm *VM) ListKeys(ctx context.Context) ([]*KeyMetadata, error)
ListKeys lists all keys.
func (*VM) ParseBlock ¶
ParseBlock parses a block from bytes.