-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwallet.rs
32 lines (28 loc) · 1.04 KB
/
wallet.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use super::sled_to_wallet_error;
use super::SledStorage;
use crate::error::WalletError;
use crate::KeyStorage;
use bitcoin::secp256k1::SecretKey;
impl KeyStorage for SledStorage {
fn get_secret_key(&self, key_id: [u8; 32]) -> Result<SecretKey, WalletError> {
let key = hex::encode(key_id);
let info = self
.signer_tree()
.map_err(sled_to_wallet_error)?
.get(key)
.map_err(sled_to_wallet_error)?
.unwrap();
Ok(serde_json::from_slice::<SecretKey>(&info)?)
}
/// Store the secret and public with the givem key id
fn store_secret_key(&self, key_id: [u8; 32], secret_key: SecretKey) -> Result<(), WalletError> {
let serialized_signer_info = serde_json::to_vec(&secret_key)?;
// Store the key id string instead of bytes.
let key_id = hex::encode(key_id);
self.signer_tree()
.map_err(sled_to_wallet_error)?
.insert(key_id, serialized_signer_info)
.map_err(sled_to_wallet_error)?;
Ok(())
}
}