keys

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: LGPL-3.0 Imports: 13 Imported by: 12

Documentation

Overview

Package keys provides key management utilities for TRON accounts.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPrivateKey = errors.New("invalid private key: out of range for secp256k1")

ErrInvalidPrivateKey is returned when key material is zero or not below the secp256k1 curve order n, so it is not a valid private key.

Functions

func AddNewKey deprecated

func AddNewKey(password string)

AddNewKey creates a new account in the default keystore directory (~/.tronctl/keystore) and prints its address and file. On failure it prints the error to stderr and nothing else.

Deprecated: use account.CreateNewLocalAccount, or keystore.NewKeyStore and KeyStore.NewAccount, which return errors instead of printing them.

func FromMnemonicSeedAndPassphrase deprecated

func FromMnemonicSeedAndPassphrase(m, passphrase string, index int) (*btcec.PrivateKey, *btcec.PublicKey)

FromMnemonicSeedAndPassphrase derives a key pair at the TRON HD path index (44'/195'/0'/0/{index}). Like mnemonic.FromSeedAndPassphrase, it does NOT check the mnemonic's checksum, and it returns nil, nil on failure.

Deprecated: Use mnemonic.DeriveKey, which validates the mnemonic and returns an error, or mnemonic.Validate followed by mnemonic.FromSeedAndPassphrase.

func GenerateKey added in v0.24.1

func GenerateKey() (*btcec.PrivateKey, error)

GenerateKey generates a new random secp256k1 private key.

func GetPrivateKeyFromBytes added in v0.24.1

func GetPrivateKeyFromBytes(privateKeyBytes []byte) (*btcec.PrivateKey, error)

GetPrivateKeyFromBytes creates a private key from raw 32-byte key material. The value must be in [1, n-1] for the secp256k1 order n; zero or any value >= n returns ErrInvalidPrivateKey rather than being reduced mod n.

func GetPrivateKeyFromHex added in v0.24.1

func GetPrivateKeyFromHex(privateKeyHex string) (*btcec.PrivateKey, error)

GetPrivateKeyFromHex parses a hex-encoded private key string.

func ListKeys deprecated

func ListKeys(keystoreDir string)

ListKeys prints all accounts in keystoreDir to stdout. An empty keystoreDir means the default ~/.tronctl/keystore, which is created if missing.

Deprecated: use keystore.NewKeyStore(dir, ...).Accounts(), or the account and store packages, which return the accounts instead of printing them.

func ZeroECDSAKey added in v0.26.0

func ZeroECDSAKey(key *ecdsa.PrivateKey)

ZeroECDSAKey overwrites the backing memory of an ECDSA private key's D value. Unlike big.Int.SetInt64(0) which only changes the logical value, this zeros the actual backing array to prevent key material from lingering in memory.

func ZeroPrivateKey added in v0.26.0

func ZeroPrivateKey(key *btcec.PrivateKey)

ZeroPrivateKey overwrites the private key bytes with zeros.

Types

type Dump

type Dump struct {
	PrivateKey, PublicKeyCompressed, PublicKey string
}

Dump holds hex-encoded representations of a key pair.

func EncodeHex

func EncodeHex(sk *btcec.PrivateKey, pk *btcec.PublicKey) *Dump

EncodeHex serializes a private/public key pair into hex-encoded strings.

Directories

Path Synopsis
Package hd provides basic functionality Hierarchical Deterministic Wallets.
Package hd provides basic functionality Hierarchical Deterministic Wallets.

Jump to

Keyboard shortcuts

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