Skip to content

Commit

Permalink
avoid changing behaviour of Keypair::from_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Oct 15, 2024
1 parent 96ecb7d commit c0decd0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sdk/signer/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ impl Keypair {

/// Recovers a `Keypair` from a byte array
pub fn from_bytes(slice: &[u8]) -> Result<Self, ed25519_dalek::SignatureError> {
let Ok(bytes): Result<[u8; 64], _> = slice.try_into() else {
return Err(ed25519_dalek::SignatureError::from_source(String::from(
"candidate keypair byte array is too short",
)));
};
Ok(Self(ed25519_dalek::SigningKey::from_keypair_bytes(&bytes)?))
let arr: [u8; ed25519_dalek::KEYPAIR_LENGTH] = slice
.get(0..ed25519_dalek::KEYPAIR_LENGTH)
.ok_or_else(|| {
ed25519_dalek::SignatureError::from_source(String::from(
"candidate keypair byte array is too short",
))
})?
.try_into()
.unwrap();
Ok(Self(ed25519_dalek::SigningKey::from_keypair_bytes(&arr)?))
}

/// Returns this `Keypair` as a byte array
Expand Down

0 comments on commit c0decd0

Please sign in to comment.