We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 41c663a commit 362b02aCopy full SHA for 362b02a
keypair/src/lib.rs
@@ -68,10 +68,15 @@ impl Keypair {
68
}
69
70
/// Recovers a `Keypair` from a base58-encoded string
71
- pub fn from_base58_string(s: &str) -> Self {
+ pub fn try_from_base58_string(s: &str) -> Result<Self, Box<dyn error::Error>> {
72
let mut buf = [0u8; ed25519_dalek::KEYPAIR_LENGTH];
73
- bs58::decode(s).onto(&mut buf).unwrap();
74
- Self::from_bytes(&buf).unwrap()
+ let written = bs58::decode(s).onto(&mut buf)?;
+ Ok(Self::from_bytes(&buf[..written])?)
75
+ }
76
+
77
+ /// Recovers a `Keypair` from a base58-encoded string. Panic on errors.
78
+ pub fn from_base58_string(s: &str) -> Self {
79
+ Self::try_from_base58_string(s).unwrap()
80
81
82
/// Returns this `Keypair` as a base58-encoded string
0 commit comments