Documentation
¶
Index ¶
- Variables
- func ChangePassword(keystorePath string, currentPassword, newPassword []byte) error
- func CreateKeystore(dir string, password []byte) (string, string, error)
- func GetKeystoreAddress(keystorePath string) (string, error)
- func ImportPrivateKey(dir string, privateKeyHex []byte, password []byte) (string, string, error)
- func IsTerminal() bool
- func ReadPasswordWithConfirm(prompt string) ([]byte, error)
- func ReadSecret() ([]byte, error)
- func SecureZeroize(data []byte)
- func VerifyPassword(keystorePath string, password []byte) error
- type KeystoreInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotTerminal is returned when stdin is not a terminal ErrNotTerminal = errors.New("stdin is not a terminal, cannot read password securely") // ErrPasswordMismatch is returned when password confirmation does not match ErrPasswordMismatch = errors.New("passwords do not match") // ErrEmptyPassword is returned when password is empty ErrEmptyPassword = errors.New("password cannot be empty") )
Functions ¶
func ChangePassword ¶
ChangePassword changes the password of an existing keystore file.
Parameters:
- keystorePath: Path to the keystore file
- currentPassword: Current password
- newPassword: New password
Returns:
- error: Any error that occurred
func CreateKeystore ¶
CreateKeystore creates a new keystore with a randomly generated key.
Parameters:
- dir: Directory to store the keystore file (will be created if not exists)
- password: Password to encrypt the keystore
Returns:
- address: The Ethereum address of the new key (0x prefixed)
- path: Full path to the created keystore file
- error: Any error that occurred
func GetKeystoreAddress ¶
GetKeystoreAddress reads a keystore file and returns the address without decrypting.
Parameters:
- keystorePath: Path to the keystore file
Returns:
- address: The Ethereum address (0x prefixed, checksummed)
- error: Any error that occurred
func ImportPrivateKey ¶
ImportPrivateKey imports a hex-encoded private key into a new keystore.
Parameters:
- dir: Directory to store the keystore file (will be created if not exists)
- privateKeyHex: Hex-encoded private key (with or without 0x prefix)
- password: Password to encrypt the keystore
Returns:
- address: The Ethereum address derived from the private key (0x prefixed)
- path: Full path to the created keystore file
- error: Any error that occurred
func ReadPasswordWithConfirm ¶
ReadPasswordWithConfirm reads a password twice for confirmation. Returns error if passwords don't match or if stdin is not a terminal.
func ReadSecret ¶
ReadSecret reads a secret from stdin without echoing. Returns error if stdin is not a terminal to prevent insecure piping.
func SecureZeroize ¶
func SecureZeroize(data []byte)
SecureZeroize securely erases sensitive data from memory. This function should be called with defer after reading a password.
func VerifyPassword ¶
VerifyPassword verifies that the password can decrypt the keystore.
Parameters:
- keystorePath: Path to the keystore file
- password: Password to verify
Returns:
- error: nil if password is correct, error otherwise
Types ¶
type KeystoreInfo ¶
KeystoreInfo contains information about a keystore file.
func ListKeystores ¶
func ListKeystores(dir string) ([]KeystoreInfo, error)
ListKeystores lists all keystore files in a directory.
Parameters:
- dir: Directory to scan for keystore files
Returns:
- []KeystoreInfo: List of keystores found
- error: Any error that occurred