Initialise Clef
The first time Clef is used it needs to be initialised with a master seed that unlocks Clef’s secure vault and a path where the vault should be located. Clef will use the vault to store passwords for keystores, javascript auto-signing rules and hashes of rule files. To initialise Clef, pass a vault path toclef init
, for example to store it in a new directory inside /home/user/parallax
:
Connecting the Parallax client and Clef
Clef and the Parallax client should be started separately but with complementary configurations so that they can communicate. This requires Clef to know thechain_id
of the network the Parallax client will connect to so that this information can be included in any signatures. Clef also needs to know the location of the keystore where accounts are (or will be) stored. This is usually in a subdirectory inside the Parallax client’s data directory. Clef is also given a data directory which is also often placed conveniently inside Parallax client’s data directory. To enable communication with Clef using Curl, --http
can be passed which will start an HTTP server on localhost:8550
by default. To start Clef configured for a Parallax node connecting to the testnet:
--configdir
flag - in this case we set it to ~/parallax/testnet/clef
:
Interacting with Clef
There are two modes of interaction with Clef. One is direct interaction, which is achieved by passing requests by HTTP or IPC with JSON-RPC data as defined in Clef’s external API. This is the way to do things in Clef that don’t require the Parallax client, such as creating and listing accounts, or signing data offline. The other way is via Parallax client. With the Parallax client started with Clef as an external signer, requests made to the Parallax client that touch account data will route via Clef for approval. By default, the user approves or denies interactions manually by typingy
or n
into the Clef console when prompted, but custom rules can also be created to automate common tasks.
Creating accounts
New accounts can be created using Clef’saccount new
method. This generates a new key pair and adds them to the given keystore
directory:
parallax/testnet
. A JSON response is returned to the terminal the request originated from, containing the new account address in the result field.
<datadir>/keystore/
. The file naming format is UTC--<date>--<address>
where date
is the date and time of key creation formatted according to UTC 8601 with zero time offset and seconds precise to eight decimal places; address
is the 40 hexadecimal characters that make up the account address without a leading 0x
, for example:
UTC--2022-05-19T12-34-36.47413510Z--0b85e5a13e118466159b1e1b6a4234e5f9f784bb
An account can also be created by importing a raw private key (hex string) using clef importraw as follows:
Listing accounts
The accounts in the keystore can be listed to the terminal using a simple CLI command as follows:account_list
in a POST request as follows:
result
field.
keystore
directory or individual key files between Parallax nodes. This is important because when accounts are added from other nodes the order of accounts in the keystore may change. It is therefore important not to rely on account indexes in scripts or code snippets.
Accounts can also be listed in the Javascript console using eth.accounts
, which will defer to Clef for approval.
As well as individual accounts, any wallets managed by Clef can be listed (which will also print the wallet status and the address and URl of any accounts they contain. This uses the list-wallets
CLI command.
Import a keyfile
It is also possible to create an account by importing an existing private key. For example, a user might already have some Laxes at an address they created using a browser wallet and now wish to use a new Parallax node to interact with their funds. In this case, the private key can be exported from the browser wallet and imported into the Parallax client. It is possible to do this using Clef, but currently the method is not externally exposed and requires implementing a UI. There is a Python UI on the Parallax GitHub that could be used as an example or it can be done using the default console UI. However, for now, the most straightforward way to import an account from a private key is to use Parallax client’saccount import
.
The Parallax client requires the private key to be stored as a file which contains the private key as unencrypted canonical elliptic curve bytes encoded into hex (i.e. plain text key without leading 0x). The new account is then saved in encrypted format, protected by a passphrase the user provides on request. As always, this passphrase must be securely and safely backed up - there is no way to retrieve or reset it if it is forgotten!
.txt
file and passing its path with the --password
flag on startup.
Updating accounts
Clef can be used to set and remove passwords for an existing keystore file. To set a new password, pass the account address to setpw:account update
subcommand can also be used to update the account password:
--password
flag:
prlx account update
replaces the original file with a new one - this means the original file is no longer available after it has been updated. This can be used to update a key file to the latest format.