Skip to content

Commit 9eb1694

Browse files
committed
encryp wallet with name api.
1 parent 834a848 commit 9eb1694

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/fuels-accounts/src/wallet.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ impl WalletUnlocked {
171171
.map_err(|e| error!(Other, "{e}"))
172172
}
173173

174+
/// Encrypts the wallet's private key with the given password and saves it
175+
/// to the given path named with given name.
176+
pub fn encrypt_with_name<P, S>(&self, dir: P, password: S, name: &str) -> Result<String>
177+
where
178+
P: AsRef<Path>,
179+
S: AsRef<[u8]>,
180+
{
181+
let mut rng = rand::thread_rng();
182+
183+
eth_keystore::encrypt_key(dir, &mut rng, *self.private_key, password, name)
184+
.map_err(|e| error!(Other, "{e}"))
185+
}
186+
187+
174188
/// Recreates a wallet from an encrypted JSON wallet given the provided path and password.
175189
pub fn load_keystore<P, S>(keypath: P, password: S, provider: Option<Provider>) -> Result<Self>
176190
where

0 commit comments

Comments
 (0)