This is separated from Ether Binder library addon, due to extension dependency.
This library requires PECL extension scrypt
. To install extension:
pecl install scrypt
Installing:
composer require m8b/ethbnd-keystore
To read the existing json keystore, get the json and password, and drop it to loadFromKeystore
function
$keystore = file_get_contents("path/to/key.json");
$wallet = \M8B\EtherBinder\Wallet\JSONKeystoreWallet::loadFromKeystore($keystore, "password");
To encrypt existing key
$key = \M8B\EtherBinder\Crypto\Key::fromHex("0x....");
$wallet = \M8B\EtherBinder\Wallet\JSONKeystoreWallet::wrap($key);
file_put_contents($wallet->export("password"));
To generate new key and immediately wrap it with json keystore
$wallet = \M8B\EtherBinder\Wallet\JSONKeystoreWallet::generate();
Mozilla public license 2.0