Skip to content

Commit

Permalink
use private key instead of seed in registrar client
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Feb 26, 2025
1 parent c27651f commit f343f79
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 29 deletions.
23 changes: 1 addition & 22 deletions registrar-cli/cmd/create_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var createAccountCmd = &cobra.Command{

log.Info().Msgf("public key (Hex): %s", hex.EncodeToString(publicKey))

cli, err := client.NewRegistrarClient(u, seedBytes)
cli, err := client.NewRegistrarClient(u, privateKey)
if err != nil {
return err
}
Expand Down Expand Up @@ -94,24 +94,3 @@ func generateRandomSeed() (string, error) {
seed := hex.EncodeToString(s)
return seed, nil
}

func createAccount(c client.RegistrarClient, relays []string, rmbEncKey string) (client.Account, error) {
account, err := c.CreateAccount(relays, rmbEncKey)
if err != nil {
log.Fatal().Err(err).Msg("failed to create new account on registrar")
}

return account, err
}

func parseSeed(seed string) (ed25519.PublicKey, ed25519.PrivateKey, []byte, error) {
privateKeyBytes, err := hex.DecodeString(seed)
if err != nil {
return nil, nil, nil, err
}

privateKey := ed25519.NewKeyFromSeed(privateKeyBytes)
publicKey := privateKey.Public().(ed25519.PublicKey)

return publicKey, privateKey, privateKeyBytes, nil
}
4 changes: 3 additions & 1 deletion registrar-cli/cmd/create_farm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"crypto/ed25519"
"encoding/hex"
"fmt"

Expand Down Expand Up @@ -49,7 +50,8 @@ var createFarmCmd = &cobra.Command{
return err
}

cli, err := client.NewRegistrarClient(u, seedBytes)
privateKey := ed25519.NewKeyFromSeed(seedBytes)
cli, err := client.NewRegistrarClient(u, privateKey)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion registrar-cli/cmd/get_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"crypto/ed25519"
"encoding/hex"
"fmt"

Expand Down Expand Up @@ -50,7 +51,8 @@ var getAccountCmd = &cobra.Command{
return err
}

cli, err := client.NewRegistrarClient(u, seedBytes)
privateKey := ed25519.NewKeyFromSeed(seedBytes)
cli, err := client.NewRegistrarClient(u, privateKey)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion registrar-cli/cmd/get_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"crypto/ed25519"
"encoding/hex"
"fmt"

Expand Down Expand Up @@ -45,7 +46,8 @@ var getNodeCmd = &cobra.Command{
return err
}

cli, err := client.NewRegistrarClient(u, seedBytes)
privateKey := ed25519.NewKeyFromSeed(seedBytes)
cli, err := client.NewRegistrarClient(u, privateKey)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion registrar-cli/cmd/get_zos_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"crypto/ed25519"
"encoding/hex"
"fmt"

Expand Down Expand Up @@ -35,7 +36,8 @@ var getZosVersionCmd = &cobra.Command{
return err
}

cli, err := client.NewRegistrarClient(u, seedBytes)
privateKey := ed25519.NewKeyFromSeed(seedBytes)
cli, err := client.NewRegistrarClient(u, privateKey)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion registrar-cli/cmd/update_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"crypto/ed25519"
"encoding/hex"
"fmt"

Expand Down Expand Up @@ -49,7 +50,8 @@ var UpdateAccountCmd = &cobra.Command{
return err
}

cli, err := client.NewRegistrarClient(u, seedBytes)
privateKey := ed25519.NewKeyFromSeed(seedBytes)
cli, err := client.NewRegistrarClient(u, privateKey)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion registrar-cli/cmd/update_farm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"crypto/ed25519"
"encoding/hex"
"fmt"

Expand Down Expand Up @@ -54,7 +55,8 @@ var UpdateFarmCmd = &cobra.Command{
return err
}

cli, err := client.NewRegistrarClient(u, seedBytes)
privateKey := ed25519.NewKeyFromSeed(seedBytes)
cli, err := client.NewRegistrarClient(u, privateKey)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion registrar-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.0
require (
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.9.1
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250226140024-dc119126c93f
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250226194238-c27651fbdd6e
)

require (
Expand Down
2 changes: 2 additions & 0 deletions registrar-cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250226140024-dc119126c93f h1:IJ0BULHQuYWT6UFFiZEhEB0QyFSSbyCPgcKaAVII4a4=
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250226140024-dc119126c93f/go.mod h1:x6Sluj6YKfelWzcNwsD2oqGO8dpRlH7fbmeIqEsK8hI=
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250226194238-c27651fbdd6e h1:n/hq2t7txZNuQ53EMR+ikwvu3bSvZIerm1d6JiXbmro=
github.com/threefoldtech/tfgrid4-sdk-go/node-registrar v0.0.0-20250226194238-c27651fbdd6e/go.mod h1:x6Sluj6YKfelWzcNwsD2oqGO8dpRlH7fbmeIqEsK8hI=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit f343f79

Please sign in to comment.