method added to construct keypair from raw bytes

This commit is contained in:
Bruce Leidl 2019-04-02 15:15:28 -04:00
parent e493e5180d
commit cf85d10055

View File

@ -50,8 +50,12 @@ impl KeyPair {
pub fn from_hex(hex: &str) -> Result<KeyPair> { pub fn from_hex(hex: &str) -> Result<KeyPair> {
let bytes = hex::decode(hex)?; let bytes = hex::decode(hex)?;
KeyPair::from_bytes(&bytes)
}
pub fn from_bytes(bytes: &[u8]) -> Result<KeyPair> {
if bytes.len() != SEEDBYTES { if bytes.len() != SEEDBYTES {
bail!("Hex encoded keypair has incorrect length"); bail!("Hex encoded keypair has incorrect length");
} }
let seed = sign::Seed::from_slice(&bytes).expect("Seed::from_slice() failed"); let seed = sign::Seed::from_slice(&bytes).expect("Seed::from_slice() failed");
Ok(KeyPair(seed)) Ok(KeyPair(seed))