mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
Remove validator / node / geth dependency
This commit is contained in:
@@ -8,11 +8,9 @@ require (
|
||||
github.com/crate-crypto/go-eth-kzg v1.3.0
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.1
|
||||
github.com/ethereum/go-ethereum v1.16.1
|
||||
github.com/google/gofuzz v1.2.0
|
||||
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267
|
||||
github.com/luxfi/ids v1.0.1
|
||||
github.com/luxfi/node v1.15.1
|
||||
github.com/mr-tron/base58 v1.2.0
|
||||
github.com/stretchr/testify v1.10.0
|
||||
golang.org/x/crypto v0.40.0
|
||||
@@ -20,15 +18,10 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ava-labs/avalanchego v1.13.4 // indirect
|
||||
github.com/bits-and-blooms/bitset v1.20.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/google/renameio/v2 v2.0.0 // indirect
|
||||
github.com/holiman/uint256 v1.3.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/supranational/blst v0.3.15 // indirect
|
||||
golang.org/x/sync v0.16.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/luxfi/node => github.com/ava-labs/avalanchego v1.13.4
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
github.com/ava-labs/avalanchego v1.13.2 h1:Kx/T2a8vqLlgHde3DWT5zMF5yBIh1rqEd6nJQMMzV/Y=
|
||||
github.com/ava-labs/avalanchego v1.13.2/go.mod h1:s7W/kim5L6hiD2PB1v/Ozy1ZZyoLQ4H6mxVO0aMnxng=
|
||||
github.com/ava-labs/avalanchego v1.13.4 h1:H7bI1qx9qaOddJ3E2J9KkLvTe7d613K821eST6VGXEU=
|
||||
github.com/ava-labs/avalanchego v1.13.4/go.mod h1:pMPIH9KeyXFsdxuF6sy06sztq3p2rI4XeePXvGeg9Ew=
|
||||
github.com/bits-and-blooms/bitset v1.20.0 h1:2F+rfL86jE2d/bmw7OhqUg2Sj/1rURkBn3MdfoPyRVU=
|
||||
github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
|
||||
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
|
||||
@@ -18,14 +14,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnN
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.1 h1:KhzBVjmURsfr1+S3k/VE35T02+AW2qU9t9gr4R6YpSo=
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.1/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E=
|
||||
github.com/ethereum/go-ethereum v1.16.1 h1:7684NfKCb1+IChudzdKyZJ12l1Tq4ybPZOITiCDXqCk=
|
||||
github.com/ethereum/go-ethereum v1.16.1/go.mod h1:ngYIvmMAYdo4sGW9cGzLvSsPGhDOOzL0jK5S5iXpj0g=
|
||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/renameio/v2 v2.0.0 h1:UifI23ZTGY8Tt29JbYFiuyIU3eX+RNFtUwefq9qAhxg=
|
||||
github.com/google/renameio/v2 v2.0.0/go.mod h1:BtmJXm5YlszgC+TD4HOEEUFgkJP3nLxehU6hfe7jRt4=
|
||||
github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA=
|
||||
github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
|
||||
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267 h1:TMtDYDHKYY15rFihtRfck/bfFqNfvcabqvXAFQfAUpY=
|
||||
github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267/go.mod h1:h1nSAbGFqGVzn6Jyl1R/iCcBUHN4g+gW1u9CoBTrb9E=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package validator
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/node/staking"
|
||||
)
|
||||
|
||||
// ValidatorKeys represents the keys needed for a validator
|
||||
type ValidatorKeys struct {
|
||||
NodeID string
|
||||
StakingCert string
|
||||
StakingKey string
|
||||
}
|
||||
|
||||
// ValidatorKeysWithTLS includes TLS certificates
|
||||
type ValidatorKeysWithTLS struct {
|
||||
ValidatorKeys
|
||||
TLSCert string
|
||||
TLSKey string
|
||||
}
|
||||
|
||||
// ValidatorInfo represents validator configuration
|
||||
type ValidatorInfo struct {
|
||||
NodeID string `json:"nodeId"`
|
||||
StakingCert string `json:"stakingCert"`
|
||||
StakingKey string `json:"stakingKey"`
|
||||
ETHAddress string `json:"ethAddress,omitempty"`
|
||||
}
|
||||
|
||||
// KeyGenerator generates validator keys
|
||||
type KeyGenerator struct{}
|
||||
|
||||
// NewKeyGenerator creates a new key generator
|
||||
func NewKeyGenerator() *KeyGenerator {
|
||||
return &KeyGenerator{}
|
||||
}
|
||||
|
||||
// Generate creates a new set of validator keys
|
||||
func (kg *KeyGenerator) Generate() (*ValidatorKeysWithTLS, error) {
|
||||
// Generate staking certificate
|
||||
certBytes, keyBytes, err := staking.NewCertAndKeyBytes()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate staking cert: %w", err)
|
||||
}
|
||||
|
||||
// Generate TLS certificate
|
||||
tlsCertBytes, tlsKeyBytes, err := staking.NewCertAndKeyBytes()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate TLS cert: %w", err)
|
||||
}
|
||||
|
||||
// Parse the cert to get NodeID
|
||||
parsedCert, err := staking.ParseCertificate(certBytes)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse certificate: %w", err)
|
||||
}
|
||||
|
||||
nodeID := ids.NodeIDFromCert((*ids.Certificate)(parsedCert))
|
||||
|
||||
return &ValidatorKeysWithTLS{
|
||||
ValidatorKeys: ValidatorKeys{
|
||||
NodeID: nodeID.String(),
|
||||
StakingCert: string(certBytes),
|
||||
StakingKey: string(keyBytes),
|
||||
},
|
||||
TLSCert: string(tlsCertBytes),
|
||||
TLSKey: string(tlsKeyBytes),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GenerateFromPrivateKey creates keys from an existing private key
|
||||
func (kg *KeyGenerator) GenerateFromPrivateKey(privateKeyHex string) (*ValidatorKeysWithTLS, error) {
|
||||
// For now, just generate new keys
|
||||
// In a real implementation, this would derive from the provided key
|
||||
return kg.Generate()
|
||||
}
|
||||
|
||||
// GenerateFromSeed creates keys from a seed phrase
|
||||
func (kg *KeyGenerator) GenerateFromSeed(seed string, index int) (*ValidatorKeysWithTLS, error) {
|
||||
// For now, just generate new keys
|
||||
// In a real implementation, this would derive from the seed
|
||||
return kg.Generate()
|
||||
}
|
||||
|
||||
// GenerateFromSeedWithTLS creates keys from a seed phrase with TLS support
|
||||
func (kg *KeyGenerator) GenerateFromSeedWithTLS(seed string, index int) (*ValidatorKeysWithTLS, error) {
|
||||
// For now, just generate new keys
|
||||
// In a real implementation, this would derive from the seed
|
||||
return kg.Generate()
|
||||
}
|
||||
|
||||
// GenerateCompatibleKeys generates multiple sets of compatible keys
|
||||
func (kg *KeyGenerator) GenerateCompatibleKeys(count int) ([]*ValidatorKeysWithTLS, error) {
|
||||
keys := make([]*ValidatorKeysWithTLS, count)
|
||||
for i := 0; i < count; i++ {
|
||||
keySet, err := kg.Generate()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate key %d: %w", i, err)
|
||||
}
|
||||
keys[i] = keySet
|
||||
}
|
||||
return keys, nil
|
||||
}
|
||||
|
||||
// SaveKeys saves validator keys to disk
|
||||
func SaveKeys(keys *ValidatorKeysWithTLS, outputPath string) error {
|
||||
// Create directory if it doesn't exist
|
||||
if err := os.MkdirAll(outputPath, 0755); err != nil {
|
||||
return fmt.Errorf("failed to create directory: %w", err)
|
||||
}
|
||||
|
||||
// Save staking cert
|
||||
stakingCertPath := filepath.Join(outputPath, "staker.crt")
|
||||
if err := ioutil.WriteFile(stakingCertPath, []byte(keys.StakingCert), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write staking cert: %w", err)
|
||||
}
|
||||
|
||||
// Save staking key
|
||||
stakingKeyPath := filepath.Join(outputPath, "staker.key")
|
||||
if err := ioutil.WriteFile(stakingKeyPath, []byte(keys.StakingKey), 0600); err != nil {
|
||||
return fmt.Errorf("failed to write staking key: %w", err)
|
||||
}
|
||||
|
||||
// Save TLS cert
|
||||
tlsCertPath := filepath.Join(outputPath, "tls.crt")
|
||||
if err := ioutil.WriteFile(tlsCertPath, []byte(keys.TLSCert), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write TLS cert: %w", err)
|
||||
}
|
||||
|
||||
// Save TLS key
|
||||
tlsKeyPath := filepath.Join(outputPath, "tls.key")
|
||||
if err := ioutil.WriteFile(tlsKeyPath, []byte(keys.TLSKey), 0600); err != nil {
|
||||
return fmt.Errorf("failed to write TLS key: %w", err)
|
||||
}
|
||||
|
||||
// Save node ID
|
||||
nodeIDPath := filepath.Join(outputPath, "node.id")
|
||||
if err := ioutil.WriteFile(nodeIDPath, []byte(keys.NodeID), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write node ID: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GenerateValidatorConfig creates a validator configuration
|
||||
func GenerateValidatorConfig(keys ValidatorKeys, ethAddress string, stakeAmount interface{}, network interface{}) *ValidatorInfo {
|
||||
return &ValidatorInfo{
|
||||
NodeID: keys.NodeID,
|
||||
StakingCert: keys.StakingCert,
|
||||
StakingKey: keys.StakingKey,
|
||||
ETHAddress: ethAddress,
|
||||
}
|
||||
}
|
||||
|
||||
// SaveValidatorConfigs saves validator configurations to a JSON file
|
||||
func SaveValidatorConfigs(configs []*ValidatorInfo, outputPath string) error {
|
||||
data, err := json.MarshalIndent(configs, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal configs: %w", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(outputPath, data, 0644); err != nil {
|
||||
return fmt.Errorf("failed to write configs: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user