decomplect: drop evmcrypto/utxocrypto aliases — use crypto + secp256k1 by name

dropping aliases on github.com/luxfi/crypto and github.com/luxfi/crypto/secp256k1.
no name collisions with stdlib (validator_keys.go's crypto/rand is rand, not crypto).
also purges remaining ethAddr / luxAddr / luxKey local vars (renamed to addr /
utxoAddr / secpKey).
This commit is contained in:
Hanzo AI
2026-05-22 21:05:17 -07:00
parent c114107bac
commit 28e520ef7e
5 changed files with 47 additions and 47 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ import (
"strings"
"time"
luxcrypto "github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/go-bip32"
"github.com/luxfi/go-bip39"
"github.com/luxfi/ids"
@@ -71,7 +71,7 @@ func deriveAddrs(mnemonic, hrp string) []string {
if err != nil {
panic(err)
}
priv, err := luxcrypto.ToPrivateKey(child.Key)
priv, err := secp256k1.ToPrivateKey(child.Key)
if err != nil {
panic(err)
}
+4 -4
View File
@@ -65,7 +65,7 @@ func (a *ChainAllocations) PChain() ([]AllocationJSON, error) {
allocations := make([]AllocationJSON, len(a.keys))
for i, key := range a.keys {
luxAddr, err := FormatChainAddress("P", a.hrp, key.ShortID)
utxoAddr, err := FormatChainAddress("P", a.hrp, key.ShortID)
if err != nil {
return nil, fmt.Errorf("failed to format P-chain address for key %d: %w", i, err)
}
@@ -86,7 +86,7 @@ func (a *ChainAllocations) PChain() ([]AllocationJSON, error) {
allocations[i] = AllocationJSON{
EVMAddr: key.EVMAddr,
UTXOAddr: luxAddr,
UTXOAddr: utxoAddr,
InitialAmount: initialAmount,
UnlockSchedule: unlockSchedule,
}
@@ -134,7 +134,7 @@ func (a *ChainAllocations) PChainMap() ([]map[string]interface{}, error) {
allocations := make([]map[string]interface{}, len(a.keys))
for i, key := range a.keys {
luxAddr, err := FormatChainAddress("P", a.hrp, key.ShortID)
utxoAddr, err := FormatChainAddress("P", a.hrp, key.ShortID)
if err != nil {
return nil, fmt.Errorf("failed to format P-chain address for key %d: %w", i, err)
}
@@ -164,7 +164,7 @@ func (a *ChainAllocations) PChainMap() ([]map[string]interface{}, error) {
allocations[i] = map[string]interface{}{
"evmAddr": key.EVMAddr,
"utxoAddr": luxAddr,
"utxoAddr": utxoAddr,
"initialAmount": initialAmount,
"unlockSchedule": unlockSchedule,
}
+17 -17
View File
@@ -20,10 +20,10 @@ import (
// happens at the call site below (mldsaKeygenFromChildSeed) so the
// derivation is byte-for-byte reproducible against the prior CIRCL
// stop-gap.
ethcrypto "github.com/luxfi/crypto"
"github.com/luxfi/crypto"
"github.com/luxfi/crypto/bls"
"github.com/luxfi/crypto/pq/mldsa/mldsa65"
luxcrypto "github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/go-bip32"
"github.com/luxfi/go-bip39"
"github.com/luxfi/ids"
@@ -208,16 +208,16 @@ func loadNodeKey(nodeDir string) (*KeyInfo, error) {
privKeyBytes, err := hex.DecodeString(privKeyHex)
if err == nil {
// Get EVM address
evmPrivKey, err := ethcrypto.ToECDSA(privKeyBytes)
evmPrivKey, err := crypto.ToECDSA(privKeyBytes)
if err == nil {
evmAddr := ethcrypto.PubkeyToAddress(evmPrivKey.PublicKey)
evmAddr := crypto.PubkeyToAddress(evmPrivKey.PublicKey)
copy(keyInfo.EVMAddr[:], evmAddr[:])
}
// Get Lux ShortID (for X/P chain addresses)
luxPrivKey, err := luxcrypto.ToPrivateKey(privKeyBytes)
utxoPrivKey, err := secp256k1.ToPrivateKey(privKeyBytes)
if err == nil {
pubKey := luxPrivKey.PublicKey()
pubKey := utxoPrivKey.PublicKey()
shortID := ids.ShortID(pubKey.Address())
copy(keyInfo.StakingAddr[:], shortID[:])
}
@@ -280,7 +280,7 @@ func deriveFeeKey(keysDir string, validatorKey KeyInfo, index int) (*KeyInfo, er
feePrivBytes := keccak256(append([]byte("fee-reserve:"), privKeyBytes...))
// Derive proper P-chain address using secp256k1
feePrivKey, err := luxcrypto.ToPrivateKey(feePrivBytes)
feePrivKey, err := secp256k1.ToPrivateKey(feePrivBytes)
if err != nil {
return nil, fmt.Errorf("failed to create fee private key: %w", err)
}
@@ -288,11 +288,11 @@ func deriveFeeKey(keysDir string, validatorKey KeyInfo, index int) (*KeyInfo, er
feeAddr := ids.ShortID(feePubKey.Address())
// Derive EVM address
evmPrivKey, err := ethcrypto.ToECDSA(feePrivBytes)
evmPrivKey, err := crypto.ToECDSA(feePrivBytes)
if err != nil {
return nil, fmt.Errorf("failed to create fee ETH key: %w", err)
}
evmAddr := ethcrypto.PubkeyToAddress(evmPrivKey.PublicKey)
evmAddr := crypto.PubkeyToAddress(evmPrivKey.PublicKey)
var evmShortID ids.ShortID
copy(evmShortID[:], evmAddr[:])
@@ -569,11 +569,11 @@ func keyInfoFromPrivateKey(privKey []byte) (*KeyInfo, error) {
}
// Derive Lux P/X-Chain address (SHA256+RIPEMD160, like Bitcoin)
luxKey, err := luxcrypto.ToPrivateKey(privKey)
secpKey, err := secp256k1.ToPrivateKey(privKey)
if err != nil {
return nil, fmt.Errorf("failed to derive lux key: %w", err)
}
stakingAddr := luxKey.Address()
stakingAddr := secpKey.Address()
return &KeyInfo{
NodeID: nodeID,
@@ -585,11 +585,11 @@ func keyInfoFromPrivateKey(privKey []byte) (*KeyInfo, error) {
// privateKeyToEVMAddress derives an EVM address (H160 hex) from a private key
func privateKeyToEVMAddress(privKey []byte) (ids.ShortID, error) {
key, err := ethcrypto.ToECDSA(privKey)
key, err := crypto.ToECDSA(privKey)
if err != nil {
return ids.ShortID{}, fmt.Errorf("invalid secp256k1 private key: %w", err)
}
evmAddr := ethcrypto.PubkeyToAddress(key.PublicKey)
evmAddr := crypto.PubkeyToAddress(key.PublicKey)
var addr ids.ShortID
copy(addr[:], evmAddr[:])
return addr, nil
@@ -889,17 +889,17 @@ func BuildBIP44WalletAllocations(networkID uint32, numKeys int, amountPerKey uin
return nil, fmt.Errorf("failed to derive wallet key %d: %w", i, err)
}
luxPrivKey, err := luxcrypto.ToPrivateKey(childKey.Key)
utxoPrivKey, err := secp256k1.ToPrivateKey(childKey.Key)
if err != nil {
return nil, fmt.Errorf("failed to create secp256k1 key %d: %w", i, err)
}
stakingAddr := luxPrivKey.Address()
stakingAddr := utxoPrivKey.Address()
evmPrivKey, err := ethcrypto.ToECDSA(childKey.Key)
evmPrivKey, err := crypto.ToECDSA(childKey.Key)
if err != nil {
return nil, fmt.Errorf("failed to create ECDSA key %d: %w", i, err)
}
evmAddr := ethcrypto.PubkeyToAddress(evmPrivKey.PublicKey)
evmAddr := crypto.PubkeyToAddress(evmPrivKey.PublicKey)
var evmShortID ids.ShortID
copy(evmShortID[:], evmAddr[:])
+12 -12
View File
@@ -15,56 +15,56 @@ func TestChainPrefixFormat_KnownVectors(t *testing.T) {
// Known test addresses from mainnet genesis
testCases := []struct {
name string
ethAddrHex string
addrHex string
chainPrefix string
hrp string
expected string
}{
{
name: "node1_mainnet",
ethAddrHex: "9011E888251AB053B7bD1cdB598Db4f9DEd94714",
addrHex: "9011E888251AB053B7bD1cdB598Db4f9DEd94714",
chainPrefix: "P",
hrp: "lux",
expected: "P-lux1jqg73zp9r2c98daarnd4nrd5l80dj3c5eha5fl",
},
{
name: "node2_mainnet",
ethAddrHex: "EAbCC110fAcBfebabC66Ad6f9E7B67288e720B59",
addrHex: "EAbCC110fAcBfebabC66Ad6f9E7B67288e720B59",
chainPrefix: "P",
hrp: "lux",
expected: "P-lux1a27vzy86e0lt40rx44heu7m89z88yz6ey7av5e",
},
{
name: "node3_mainnet",
ethAddrHex: "8d5081153aE1cfb41f5c932fe0b6Beb7E159cF84",
addrHex: "8d5081153aE1cfb41f5c932fe0b6Beb7E159cF84",
chainPrefix: "P",
hrp: "lux",
expected: "P-lux134ggz9f6u88mg86ujvh7pd47kls4nnuy3hx4yp",
},
{
name: "node4_mainnet",
ethAddrHex: "f8f12D0592e6d1bFe92ee16CaBCC4a6F26dAAe23",
addrHex: "f8f12D0592e6d1bFe92ee16CaBCC4a6F26dAAe23",
chainPrefix: "P",
hrp: "lux",
expected: "P-lux1lrcj6pvjumgml6fwu9k2hnz2dund4t3rpsjuxu",
},
{
name: "node5_mainnet",
ethAddrHex: "Fb66808f708e1d4D7D43a8c75596e84f94e06806",
addrHex: "Fb66808f708e1d4D7D43a8c75596e84f94e06806",
chainPrefix: "P",
hrp: "lux",
expected: "P-lux1ldngprms3cw56l2r4rr4t9hgf72wq6qx057vd2",
},
{
name: "x_chain_testnet",
ethAddrHex: "9011E888251AB053B7bD1cdB598Db4f9DEd94714",
addrHex: "9011E888251AB053B7bD1cdB598Db4f9DEd94714",
chainPrefix: "X",
hrp: "test",
expected: "X-test1jqg73zp9r2c98daarnd4nrd5l80dj3c5644e09",
},
{
name: "local_dev",
ethAddrHex: "9011E888251AB053B7bD1cdB598Db4f9DEd94714",
addrHex: "9011E888251AB053B7bD1cdB598Db4f9DEd94714",
chainPrefix: "P",
hrp: "local",
expected: "P-local1jqg73zp9r2c98daarnd4nrd5l80dj3c56acgey",
@@ -73,7 +73,7 @@ func TestChainPrefixFormat_KnownVectors(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
addrBytes, err := hex.DecodeString(tc.ethAddrHex)
addrBytes, err := hex.DecodeString(tc.addrHex)
if err != nil {
t.Fatalf("failed to decode eth address: %v", err)
}
@@ -133,8 +133,8 @@ func TestBech32ChecksumConsistency(t *testing.T) {
"Fb66808f708e1d4D7D43a8c75596e84f94e06806",
}
for _, ethAddr := range testAddrs {
addrBytes, err := hex.DecodeString(ethAddr)
for _, addr := range testAddrs {
addrBytes, err := hex.DecodeString(addr)
if err != nil {
t.Fatalf("failed to decode eth address: %v", err)
}
@@ -155,7 +155,7 @@ func TestBech32ChecksumConsistency(t *testing.T) {
}
if ourAddr != nodeAddr {
t.Errorf("address mismatch for %s:\n ours: %s\n node: %s", ethAddr, ourAddr, nodeAddr)
t.Errorf("address mismatch for %s:\n ours: %s\n node: %s", addr, ourAddr, nodeAddr)
}
}
}
+12 -12
View File
@@ -12,8 +12,8 @@ import (
"strings"
"github.com/luxfi/address"
ethcrypto "github.com/luxfi/crypto"
luxcrypto "github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/crypto"
"github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/ids"
)
@@ -100,18 +100,18 @@ func ComputeValidatorKeyInfo(privKeyHex string) (ValidatorKeyInfo, error) {
}
// Get EVM address
evmPrivKey, err := ethcrypto.ToECDSA(privKeyBytes)
evmPrivKey, err := crypto.ToECDSA(privKeyBytes)
if err != nil {
return ValidatorKeyInfo{}, fmt.Errorf("invalid ECDSA key: %w", err)
}
evmAddr := ethcrypto.PubkeyToAddress(evmPrivKey.PublicKey)
evmAddr := crypto.PubkeyToAddress(evmPrivKey.PublicKey)
// Get Lux ShortID (for X/P chain addresses)
luxPrivKey, err := luxcrypto.ToPrivateKey(privKeyBytes)
utxoPrivKey, err := secp256k1.ToPrivateKey(privKeyBytes)
if err != nil {
return ValidatorKeyInfo{}, fmt.Errorf("invalid Lux key: %w", err)
}
pubKey := luxPrivKey.PublicKey()
pubKey := utxoPrivKey.PublicKey()
shortID := ids.ShortID(pubKey.Address())
return ValidatorKeyInfo{
@@ -144,7 +144,7 @@ func GeneratePChainAllocations(keys []ValidatorKeyInfo, hrp string, amountPerKey
allocations := make([]AllocationJSON, len(keys))
for i, key := range keys {
luxAddr, err := FormatChainAddress("P", hrp, key.ShortID)
utxoAddr, err := FormatChainAddress("P", hrp, key.ShortID)
if err != nil {
return nil, fmt.Errorf("failed to format address for key %d: %w", i, err)
}
@@ -159,7 +159,7 @@ func GeneratePChainAllocations(keys []ValidatorKeyInfo, hrp string, amountPerKey
allocations[i] = AllocationJSON{
EVMAddr: key.EVMAddr,
UTXOAddr: luxAddr,
UTXOAddr: utxoAddr,
InitialAmount: 0, // initialAmount is NOT immediately spendable
UnlockSchedule: unlockSchedule,
}
@@ -185,7 +185,7 @@ func GeneratePChainAllocationsWithVesting(keys []ValidatorKeyInfo, hrp string, a
allocations := make([]AllocationJSON, len(keys))
for i, key := range keys {
luxAddr, err := FormatChainAddress("P", hrp, key.ShortID)
utxoAddr, err := FormatChainAddress("P", hrp, key.ShortID)
if err != nil {
return nil, fmt.Errorf("failed to format address for key %d: %w", i, err)
}
@@ -195,7 +195,7 @@ func GeneratePChainAllocationsWithVesting(keys []ValidatorKeyInfo, hrp string, a
allocations[i] = AllocationJSON{
EVMAddr: key.EVMAddr,
UTXOAddr: luxAddr,
UTXOAddr: utxoAddr,
InitialAmount: amountPerKey, // X-chain initial amount
UnlockSchedule: unlockSchedule,
}
@@ -241,7 +241,7 @@ func GenerateAllocationsMapForNetrunner(keys []ValidatorKeyInfo, hrp string, amo
allocations := make([]map[string]interface{}, len(keys))
for i, key := range keys {
luxAddr, err := FormatChainAddress("P", hrp, key.ShortID)
utxoAddr, err := FormatChainAddress("P", hrp, key.ShortID)
if err != nil {
return nil, fmt.Errorf("failed to format address for key %d: %w", i, err)
}
@@ -256,7 +256,7 @@ func GenerateAllocationsMapForNetrunner(keys []ValidatorKeyInfo, hrp string, amo
allocations[i] = map[string]interface{}{
"evmAddr": key.EVMAddr,
"utxoAddr": luxAddr,
"utxoAddr": utxoAddr,
"initialAmount": uint64(0),
"unlockSchedule": unlockSchedule,
}