mirror of
https://github.com/luxfi/netrunner.git
synced 2026-07-27 00:04:23 +00:00
fix(keys): route genkeys/testkeys through luxfi/kms mnemonic.Load (5-arg, cycle-free)
Co-authored-by: Hanzo Dev <dev@hanzo.ai>
This commit is contained in:
+15
-10
@@ -1,12 +1,12 @@
|
|||||||
// genkeys generates mainnet validator keys from a BIP-39 mnemonic.
|
// genkeys generates mainnet validator keys from a BIP-39 mnemonic.
|
||||||
//
|
//
|
||||||
// Mnemonic source (priority order, handled inside the shared luxfi/kms
|
// Mnemonic source (priority order, handled inside the shared
|
||||||
// keys.LoadMnemonic loader so every Lux-derived tool resolves keys
|
// luxfi/kms mnemonic.Load loader so every Lux-derived tool resolves
|
||||||
// the same way):
|
// keys the same way):
|
||||||
//
|
//
|
||||||
// 1. MNEMONIC env var — local dev + CI test seam
|
// 1. MNEMONIC env var — local dev + CI test seam
|
||||||
// 2. KMS_ADDR + KMS_ENV + — native ZAP from Liquid KMS
|
// 2. KMS_ADDR + KMS_ENV + — native ZAP from Liquid KMS
|
||||||
// KMS_MNEMONIC_PATH
|
// KMS_MNEMONIC_PATH
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/luxfi/keys"
|
"github.com/luxfi/keys"
|
||||||
|
"github.com/luxfi/kms/pkg/mnemonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ValidatorBackup struct {
|
type ValidatorBackup struct {
|
||||||
@@ -35,10 +36,15 @@ type ValidatorBackup struct {
|
|||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
mnemonic, err := keys.LoadMnemonic(ctx,
|
// Bootstrap loader: identity is nil. genkeys derives the root validator
|
||||||
|
// set FROM this mnemonic, so no service identity exists yet to sign the
|
||||||
|
// KMS envelope (the mnemonic is the root every later identity derives
|
||||||
|
// from). With MNEMONIC set the KMS dial is never reached.
|
||||||
|
phrase, err := mnemonic.Load(ctx,
|
||||||
os.Getenv("KMS_ADDR"),
|
os.Getenv("KMS_ADDR"),
|
||||||
os.Getenv("KMS_ENV"),
|
os.Getenv("KMS_ENV"),
|
||||||
envOr("KMS_MNEMONIC_PATH", "/mnemonic"))
|
envOr("KMS_MNEMONIC_PATH", "/mnemonic"),
|
||||||
|
nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: load mnemonic: %v\n", err)
|
fmt.Printf("ERROR: load mnemonic: %v\n", err)
|
||||||
fmt.Println("Set MNEMONIC env var, or KMS_ADDR + KMS_ENV + KMS_MNEMONIC_PATH for native ZAP.")
|
fmt.Println("Set MNEMONIC env var, or KMS_ADDR + KMS_ENV + KMS_MNEMONIC_PATH for native ZAP.")
|
||||||
@@ -58,7 +64,7 @@ func main() {
|
|||||||
ks := keys.NewKeyStore(keysDir)
|
ks := keys.NewKeyStore(keysDir)
|
||||||
|
|
||||||
// Generate 5 validators
|
// Generate 5 validators
|
||||||
validators, err := keys.DeriveValidatorsFromMnemonic(mnemonic, 5)
|
validators, err := keys.DeriveValidatorsFromMnemonic(phrase, 5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: Failed to derive validators: %v\n", err)
|
fmt.Printf("ERROR: Failed to derive validators: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -151,4 +157,3 @@ func envOr(name, def string) string {
|
|||||||
}
|
}
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,20 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/luxfi/keys"
|
"github.com/luxfi/keys"
|
||||||
|
"github.com/luxfi/kms/pkg/mnemonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
mnemonic, err := keys.LoadMnemonic(ctx,
|
// Bootstrap loader: identity is nil (the mnemonic is the root; no service
|
||||||
|
// identity exists yet to sign the KMS envelope). With MNEMONIC set the KMS
|
||||||
|
// dial is never reached.
|
||||||
|
phrase, err := mnemonic.Load(ctx,
|
||||||
os.Getenv("KMS_ADDR"),
|
os.Getenv("KMS_ADDR"),
|
||||||
os.Getenv("KMS_ENV"),
|
os.Getenv("KMS_ENV"),
|
||||||
envOr("KMS_MNEMONIC_PATH", "/mnemonic"))
|
envOr("KMS_MNEMONIC_PATH", "/mnemonic"),
|
||||||
|
nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR: load mnemonic: %v\n", err)
|
fmt.Printf("ERROR: load mnemonic: %v\n", err)
|
||||||
fmt.Println("Set MNEMONIC env var, or KMS_ADDR + KMS_ENV + KMS_MNEMONIC_PATH for native ZAP.")
|
fmt.Println("Set MNEMONIC env var, or KMS_ADDR + KMS_ENV + KMS_MNEMONIC_PATH for native ZAP.")
|
||||||
@@ -51,7 +56,7 @@ func main() {
|
|||||||
|
|
||||||
// Keys don't exist - derive from mnemonic and persist (first run only)
|
// Keys don't exist - derive from mnemonic and persist (first run only)
|
||||||
fmt.Println("=== Deriving 5 validators from mnemonic (first run) ===")
|
fmt.Println("=== Deriving 5 validators from mnemonic (first run) ===")
|
||||||
validators, err := keys.DeriveValidatorsFromMnemonic(mnemonic, 5)
|
validators, err := keys.DeriveValidatorsFromMnemonic(phrase, 5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error deriving: %v\n", err)
|
fmt.Printf("Error deriving: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -91,4 +96,3 @@ func envOr(name, def string) string {
|
|||||||
}
|
}
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ require (
|
|||||||
github.com/luxfi/go-bip39 v1.1.2
|
github.com/luxfi/go-bip39 v1.1.2
|
||||||
github.com/luxfi/ids v1.2.15
|
github.com/luxfi/ids v1.2.15
|
||||||
github.com/luxfi/keys v1.2.0
|
github.com/luxfi/keys v1.2.0
|
||||||
|
github.com/luxfi/kms v1.12.0
|
||||||
github.com/luxfi/log v1.4.3
|
github.com/luxfi/log v1.4.3
|
||||||
github.com/luxfi/math v1.4.1
|
github.com/luxfi/math v1.4.1
|
||||||
github.com/luxfi/metric v1.5.8
|
github.com/luxfi/metric v1.5.8
|
||||||
@@ -90,7 +91,6 @@ require (
|
|||||||
github.com/luxfi/crypto/ipa v1.2.4 // indirect
|
github.com/luxfi/crypto/ipa v1.2.4 // indirect
|
||||||
github.com/luxfi/filesystem v0.0.1 // indirect
|
github.com/luxfi/filesystem v0.0.1 // indirect
|
||||||
github.com/luxfi/formatting v1.0.1 // indirect
|
github.com/luxfi/formatting v1.0.1 // indirect
|
||||||
github.com/luxfi/kms v1.11.7 // indirect
|
|
||||||
github.com/luxfi/mdns v0.1.1 // indirect
|
github.com/luxfi/mdns v0.1.1 // indirect
|
||||||
github.com/luxfi/net v0.0.5 // indirect
|
github.com/luxfi/net v0.0.5 // indirect
|
||||||
github.com/luxfi/pq v1.0.3 // indirect
|
github.com/luxfi/pq v1.0.3 // indirect
|
||||||
|
|||||||
@@ -300,6 +300,8 @@ github.com/luxfi/keys v1.2.0 h1:+AriQNM7FOylAEls1XvFdlSOXDfoyc6X3ZfJRWQ2I9g=
|
|||||||
github.com/luxfi/keys v1.2.0/go.mod h1:SjsAaxo6sGmSp9OaHXUiVCqsknO8iPspN6jMOoEAMb8=
|
github.com/luxfi/keys v1.2.0/go.mod h1:SjsAaxo6sGmSp9OaHXUiVCqsknO8iPspN6jMOoEAMb8=
|
||||||
github.com/luxfi/kms v1.11.7 h1:E25z8SCNTGOVvzzg5tj6pwJQ2K3FrE/nuy0KAfF+0zs=
|
github.com/luxfi/kms v1.11.7 h1:E25z8SCNTGOVvzzg5tj6pwJQ2K3FrE/nuy0KAfF+0zs=
|
||||||
github.com/luxfi/kms v1.11.7/go.mod h1:XhLUVqN4RBv6j4Bj3MNgTZmHCnm74jH7RqqK0b9xbzw=
|
github.com/luxfi/kms v1.11.7/go.mod h1:XhLUVqN4RBv6j4Bj3MNgTZmHCnm74jH7RqqK0b9xbzw=
|
||||||
|
github.com/luxfi/kms v1.12.0 h1:Ij77JRqb1aFBPAJscc8iBRU06cbfB8hGnNXImh11BLI=
|
||||||
|
github.com/luxfi/kms v1.12.0/go.mod h1:JcfnH5eNsUWf0U/8aHJoiX3e/IQvlNDZiOAVf330zss=
|
||||||
github.com/luxfi/lattice/v7 v7.1.4 h1:hQR02M6cHTAV5+joOPi9gb9Gm+z/hKJnhJF4IlciIJs=
|
github.com/luxfi/lattice/v7 v7.1.4 h1:hQR02M6cHTAV5+joOPi9gb9Gm+z/hKJnhJF4IlciIJs=
|
||||||
github.com/luxfi/lattice/v7 v7.1.4/go.mod h1:DmIQFi3mJiehVsR235l1NKYEU0JhU649OX5p7gMEW2c=
|
github.com/luxfi/lattice/v7 v7.1.4/go.mod h1:DmIQFi3mJiehVsR235l1NKYEU0JhU649OX5p7gMEW2c=
|
||||||
github.com/luxfi/log v1.4.3 h1:xkUKRWvQ4ZwvlUC2e0/RTtHYZOYSMvSQ9W9lbjwBmiI=
|
github.com/luxfi/log v1.4.3 h1:xkUKRWvQ4ZwvlUC2e0/RTtHYZOYSMvSQ9W9lbjwBmiI=
|
||||||
|
|||||||
Reference in New Issue
Block a user