JSON wallets are a standardized way of storing wallets securely. They follow a specific schema and are encrypted using a password. This makes it easier to manage multiple wallets and securely store them on disk. This guide will take you through the process of encrypting and decrypting JSON wallets using the Typescript SDK.
We will be calling
encrypt
from the
WalletUnlocked
instance which will take a password as the argument. It will encrypt the private key using a cipher and returns the JSON keystore wallet. You can then securely store this JSON wallet.
Please note that
encrypt
must be called within an instance of
WalletUnlocked
. This instance can only be achieved through passing a private key or mnemonic phrase to a locked wallet.
To decrypt the JSON wallet and retrieve your private key, you can call
fromEncryptedJson
on a
Wallet instance. It takes the encrypted JSON wallet and the password as its arguments, and returns the decrypted wallet.
In this example,
decryptedWallet
is an instance of
WalletUnlocked
class, now available for use.
Remember to securely store your encrypted JSON wallet and password. If you lose them, there will be no way to recover your wallet. For security reasons, avoid sharing your private key, encrypted JSON wallet or password with anyone.