mirror of
https://github.com/luxfi/netrunner.git
synced 2026-07-27 00:04:23 +00:00
Renames LUX_-prefixed env vars to canonical, non-noisy forms across genesis_config, blockchain, network, examples, tests, genkeys, server: - LUX_MNEMONIC -> MNEMONIC - LUX_PRIVATE_KEY -> PRIVATE_KEY - LUX_KEYS_DIR -> KEYS_DIR - LUX_BINARY_PATH -> BINARY_PATH - LUX_NETWORK_TYPE -> NETWORK_TYPE (doc only) - LUX_GPU_EVM -> GPU_EVM (doc only) - LUX_GPU_WORKER_PID-> GPU_WORKER_PID Also fixes an obvious infinite-recursion bug in local/genesis_config.go::getMnemonic() that the previous LUX_MNEMONIC fallback line had become — the helper now reads MNEMONIC then LIGHT_MNEMONIC and returns. Without this fix, callers reaching the fallback would have hung the process. BREAKING: external callers (CI, dev scripts, operators) must update env var names. Per CLAUDE.md no-backwards-compatibility rule, the old forms are removed.
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
package local
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
luxcrypto "github.com/luxfi/crypto/secp256k1"
|
|
"github.com/luxfi/go-bip39"
|
|
"golang.org/x/crypto/sha3"
|
|
)
|
|
|
|
func TestMnemonicDerivation(t *testing.T) {
|
|
mnemonic := os.Getenv("MNEMONIC")
|
|
if mnemonic == "" {
|
|
t.Skip("MNEMONIC not set")
|
|
}
|
|
|
|
fmt.Printf("Mnemonic: %s...\n", mnemonic[:20])
|
|
|
|
if !bip39.IsMnemonicValid(mnemonic) {
|
|
t.Fatal("Invalid mnemonic")
|
|
}
|
|
|
|
seed := bip39.NewSeed(mnemonic, "")
|
|
|
|
// Derive using BIP44 m/44'/60'/0'/0/0
|
|
masterKey, _ := hdkeychain.NewMaster(seed, &chaincfg.MainNetParams)
|
|
purpose, _ := masterKey.Derive(hdkeychain.HardenedKeyStart + 44)
|
|
coinType, _ := purpose.Derive(hdkeychain.HardenedKeyStart + 60)
|
|
account, _ := coinType.Derive(hdkeychain.HardenedKeyStart + 0)
|
|
change, _ := account.Derive(0)
|
|
addressKey, _ := change.Derive(0)
|
|
|
|
ecPrivKey, _ := addressKey.ECPrivKey()
|
|
privKeyBytes := ecPrivKey.Serialize()
|
|
|
|
privKey, err := luxcrypto.ToPrivateKey(privKeyBytes)
|
|
if err != nil {
|
|
t.Fatalf("Error: %v", err)
|
|
}
|
|
pubKey := privKey.PublicKey()
|
|
shortID := pubKey.Address()
|
|
|
|
// Get Ethereum address
|
|
pubKeyBytes := pubKey.Bytes()
|
|
hash := sha3.NewLegacyKeccak256()
|
|
hash.Write(pubKeyBytes[1:]) // skip the 0x04 prefix
|
|
ethAddr := hash.Sum(nil)[12:]
|
|
|
|
fmt.Printf("\n=== Key Derivation Results (m/44'/60'/0'/0/0) ===\n")
|
|
fmt.Printf("Lux Short ID: %s\n", shortID.String())
|
|
fmt.Printf("Ethereum Address: 0x%x\n", ethAddr)
|
|
fmt.Printf("Expected Treasury: 0x9011E888251AB053B7bD1cdB598Db4f9DEd94714\n")
|
|
|
|
// Also derive using coin type 9000 for comparison
|
|
coinType9000, _ := purpose.Derive(hdkeychain.HardenedKeyStart + 9000)
|
|
account9000, _ := coinType9000.Derive(hdkeychain.HardenedKeyStart + 0)
|
|
change9000, _ := account9000.Derive(0)
|
|
addressKey9000, _ := change9000.Derive(0)
|
|
ecPrivKey9000, _ := addressKey9000.ECPrivKey()
|
|
privKey9000, _ := luxcrypto.ToPrivateKey(ecPrivKey9000.Serialize())
|
|
shortID9000 := privKey9000.PublicKey().Address()
|
|
|
|
fmt.Printf("\n=== Comparison: Coin Type 9000 (m/44'/9000'/0'/0/0) ===\n")
|
|
fmt.Printf("Lux Short ID (9000): %s\n", shortID9000.String())
|
|
|
|
fmt.Printf("\n=== Genesis Treasury P-chain Address ===\n")
|
|
fmt.Printf("Expected: P-lux1jqg73zp9r2c98daarnd4nrd5l80dj3c5eha5fl\n")
|
|
}
|