Skip to content

Commit

Permalink
fix private key from str
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrych committed Dec 8, 2023
1 parent cd7590f commit eafacc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub enum Error {
HexError(#[from] FromHexError),
#[error("unsupported operation: {0}")]
UnsupportedOperation(String),
#[error("failed to convert vector to array")]
PrivateKeyConversionError,
#[error("alias must be {min_length:?} to {max_length:?} length of {alphabet:?} and may have a prefix \"{max_length:?}{chain_id:?}:\"")]
InvalidAliasName {
min_length: u8,
Expand Down
5 changes: 4 additions & 1 deletion src/model/account/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ impl std::str::FromStr for PrivateKey {

fn from_str(base58string: &str) -> Result<PrivateKey> {
let bytes = Base58::decode(base58string)?;
let bytes_array: [u8; 32] = bytes.try_into()?;
let bytes_array: [u8; 32] = match bytes.try_into() {
Ok(v) => v,
Err(_) => return Err(Error::PrivateKeyConversionError),
};
PrivateKey::from_bytes(bytes_array)
}
}
Expand Down

0 comments on commit eafacc9

Please sign in to comment.