nodekey

package
v0.1.74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrivKeyName = "comet/PrivKeySecp256k1Uncompressed"
	PubKeyName  = "comet/PubKeySecp256k1Uncompressed"

	KeyType     = "secp256k1"
	PrivKeySize = 32
	// PubKeySize (uncompressed) is composed of 65 bytes for two field elements (x and y)
	// and a prefix byte (0x04) to indicate that it is uncompressed.
	PubKeySize = 65
	// SigSize is the size of the ECDSA signature.
	SigSize = 65
)
View Source
const RSAKeypairBits = 2048

Variables

View Source
var NodekeyCmd = &cobra.Command{
	Use:   "nodekey",
	Short: "Generate node keys for different blockchain clients and protocols.",
	Long:  usage,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		inputNodeKeyPrivateKey = flag_loader.GetRpcUrlFlagValue(cmd)
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		var nko nodeKeyOut
		var withSeed bool
		switch *inputNodeKeyProtocol {
		case "devp2p":
			switch *inputNodeKeyType {
			case "ed25519":
				var err error
				nko, err = generateDevp2pNodeKey()
				if err != nil {
					return err
				}
			case "secp256k1":
				secret := []byte(strings.TrimPrefix(*inputNodeKeyPrivateKey, "0x"))
				secp256k1PrivateKey := generateSecp256k1PrivateKey(secret)
				if err := displayHeimdallV2PrivValidatorKey(secp256k1PrivateKey); err != nil {
					return err
				}
				return nil
			}

		case "seed-libp2p":
			withSeed = true
			fallthrough
		case "libp2p":
			keyType, err := keyTypeToInt(*inputNodeKeyType)
			if err != nil {
				return err
			}
			nko, err = generateLibp2pNodeKey(keyType, withSeed)
			if err != nil {
				return err
			}
		default:
			return fmt.Errorf("%s is not implemented yet", *inputNodeKeyProtocol)
		}

		out, err := json.Marshal(nko)
		if err != nil {
			return fmt.Errorf("could not json marshal the key data %w", err)
		}
		fmt.Println(string(out))

		return nil
	},
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) != 0 {
			return fmt.Errorf("this command expects no arguments")
		}

		validProtocols := []string{"devp2p", "libp2p", "seed-libp2p"}
		ok := slices.Contains(validProtocols, *inputNodeKeyProtocol)
		if !ok {
			return fmt.Errorf("the protocol %s is not implemented", *inputNodeKeyProtocol)
		}

		if *inputNodeKeyProtocol == "devp2p" {
			invalidFlags := []string{"seed", "marshal-protobuf"}
			err := validateNodeKeyFlags(cmd, invalidFlags)
			if err != nil {
				return err
			}
		}
		if *inputNodeKeyProtocol == "libp2p" {
			invalidFlags := []string{"file", "ip", "tcp", "udp", "sign", "seed"}
			err := validateNodeKeyFlags(cmd, invalidFlags)
			if err != nil {
				return err
			}
		}
		if *inputNodeKeyProtocol == "seed-libp2p" {
			invalidFlags := []string{"file", "ip", "tcp", "udp", "sign"}
			err := validateNodeKeyFlags(cmd, invalidFlags)
			if err != nil {
				return err
			}
			if *inputNodeKeyType == "rsa" {
				return fmt.Errorf("the RSA key type doesn't support manual key seeding")
			}
			if *inputNodeKeyType == "secp256k1" {
				return fmt.Errorf("the secp256k1 key type doesn't support manual key seeding")
			}
		}
		return nil
	},
}

NodekeyCmd represents the nodekey command

Functions

This section is empty.

Types

type PrivKey added in v0.1.69

type PrivKey []byte

func (PrivKey) Bytes added in v0.1.69

func (privKey PrivKey) Bytes() []byte

Bytes marshals the private key using amino encoding.

func (PrivKey) Equals added in v0.1.69

func (privKey PrivKey) Equals(other crypto.PrivKey) bool

Equals - you probably don't need to use this. Runs in constant time based on length of the keys.

func (PrivKey) PubKey added in v0.1.69

func (privKey PrivKey) PubKey() crypto.PubKey

PubKey performs the point-scalar multiplication from the privKey on the generator point to get the pubkey.

func (PrivKey) Sign added in v0.1.69

func (privKey PrivKey) Sign(msg []byte) ([]byte, error)

Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg. The returned signature will be of the form R || S || V (in lower-S form).

func (PrivKey) Type added in v0.1.69

func (privKey PrivKey) Type() string

type PubKey added in v0.1.69

type PubKey []byte

func (PubKey) Address added in v0.1.69

func (pubKey PubKey) Address() crypto.Address

Address returns a Ethereym style addresses: Last_20_Bytes(KECCAK256(pubkey))

func (PubKey) Bytes added in v0.1.69

func (pubKey PubKey) Bytes() []byte

Bytes returns the pubkey marshaled with amino encoding.

func (PubKey) Equals added in v0.1.69

func (pubKey PubKey) Equals(other crypto.PubKey) bool

func (PubKey) Type added in v0.1.69

func (pubKey PubKey) Type() string

func (PubKey) VerifySignature added in v0.1.69

func (pubKey PubKey) VerifySignature(msg []byte, sigStr []byte) bool

VerifySignature verifies a signature of the form R || S || V. It rejects signatures which are not in lower-S form.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL