NAME
Blockchain::Ethereum::Keystore::File - Ethereum keystore file abstraction
VERSION
version 0.021
SYNOPSIS
use Blockchain::Ethereum::Keystore::File;
use Blockchain::Ethereum::Key;
# Create a new keystore from a private key
my $private_key = Blockchain::Ethereum::Key->new(
private_key => $key_bytes
);
my $keystore = Blockchain::Ethereum::Keystore::File->new(
private_key => $private_key,
password => 'my_secure_password'
);
# Save to file
$keystore->write_to_file('/path/to/keystore.json');
# Load from existing keystore file
my $loaded = Blockchain::Ethereum::Keystore::File->from_file(
'/path/to/keystore.json',
'my_secure_password'
);
# Change password and save
$loaded->write_to_file('/path/to/new_keystore.json', 'new_password');
# Access keystore properties
my $private_key = $loaded->private_key;
my $address = $private_key->address;
OVERVIEW
This module provides a way to create, read, and write Ethereum keystore files (version 3). Ethereum keystores are encrypted JSON files that securely store private keys using password-based encryption with scrypt key derivation and AES-128-CTR cipher.
The module supports:
Creating new keystores from private keys
Loading existing keystore files
Password verification and changing
Proper MAC validation for security
METHODS
from_key
Load a keystore from an existing private key.
my $key = Blockchain::Ethereum::Key->new(
private_key => $key_bytes
);
my $keystore = Blockchain::Ethereum::Keystore::File->from_key($key);
key- A Blockchain::Ethereum::Key instance (required)
Returns a keystore object with the loaded private key and parameters.
from_file
Load a keystore from an existing file.
my $keystore = Blockchain::Ethereum::Keystore::File->from_file(
'/path/to/keystore.json',
'password'
);
file_path- Path to the keystore JSON file (required)password- Password to decrypt the keystore (required)
Returns a keystore object with the loaded private key and parameters.
write_to_file
Write the keystore to a file, optionally with a new password.
# Write with current password
$keystore->write_to_file('/path/to/output.json');
# Write with new password
$keystore->write_to_file('/path/to/output.json', 'new_password');
file_path- Path where to save the keystore file (required)password- New password to encrypt with (optional)
If a new password is provided, the keystore will be re-encrypted with the new password while keeping the same private key.
Returns true on success, throws an exception on failure.
AUTHOR
REFECO <refeco@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2022 by REFECO.
This is free software, licensed under:
The MIT (X11) License