signature uses fd_bs58

This commit is contained in:
Lou-Kamades 2024-04-04 19:40:36 +02:00
parent d594a4133e
commit 971ccb756f
No known key found for this signature in database
GPG Key ID: 87A166E4D7C01F30
7 changed files with 17 additions and 19 deletions

2
Cargo.lock generated
View File

@ -6939,7 +6939,6 @@ dependencies = [
"bincode",
"bitflags 2.3.3",
"borsh 0.10.3",
"bs58",
"bytemuck",
"byteorder",
"chrono",
@ -6948,6 +6947,7 @@ dependencies = [
"digest 0.10.7",
"ed25519-dalek",
"ed25519-dalek-bip32",
"fd_bs58",
"generic-array 0.14.7",
"hex",
"hmac 0.12.1",

View File

@ -193,6 +193,7 @@ enum-iterator = "1.4.1"
env_logger = "0.9.3"
etcd-client = "0.11.1"
fast-math = "0.1"
fd_bs58 = "0.1.0"
fd-lock = "3.0.13"
flate2 = "1.0.27"
fnv = "1.0.7"

View File

@ -43,7 +43,6 @@ base64 = { workspace = true }
bincode = { workspace = true }
bitflags = { workspace = true }
borsh = { workspace = true }
bs58 = { workspace = true }
bytemuck = { workspace = true, features = ["derive"] }
byteorder = { workspace = true, optional = true }
chrono = { workspace = true, features = ["alloc"], optional = true }
@ -52,6 +51,7 @@ derivation-path = { workspace = true }
digest = { workspace = true, optional = true }
ed25519-dalek = { workspace = true, optional = true }
ed25519-dalek-bip32 = { workspace = true, optional = true }
fd_bs58 = { workspace = true }
generic-array = { workspace = true, features = ["serde", "more_lengths"], optional = true }
hmac = { workspace = true }
itertools = { workspace = true }

View File

@ -16,9 +16,9 @@ bincode = { workspace = true }
blake3 = { workspace = true, features = ["digest", "traits-preview"] }
borsh = { workspace = true }
borsh0-9 = { package = "borsh", version = "0.9.3" }
fd_bs58 = "0.1.0"
bv = { workspace = true, features = ["serde"] }
bytemuck = { workspace = true, features = ["derive"] }
fd_bs58 = { workspace = true }
itertools = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true }

View File

@ -168,7 +168,7 @@ macro_rules! saturating_add_assign {
#[macro_use]
extern crate serde_derive;
pub extern crate bs58;
pub extern crate fd_bs58;
extern crate log as logger;
#[macro_use]

View File

@ -80,13 +80,13 @@ impl AsRef<[u8]> for Signature {
impl fmt::Debug for Signature {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
write!(f, "{}", fd_bs58::encode_64(self.0))
}
}
impl fmt::Display for Signature {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
write!(f, "{}", fd_bs58::encode_64(self.0))
}
}
@ -136,9 +136,7 @@ impl FromStr for Signature {
if s.len() > MAX_BASE58_SIGNATURE_LEN {
return Err(ParseSignatureError::WrongSize);
}
let bytes = bs58::decode(s)
.into_vec()
.map_err(|_| ParseSignatureError::Invalid)?;
let bytes = fd_bs58::decode_64(s).map_err(|_| ParseSignatureError::Invalid)?;
Signature::try_from(bytes).map_err(|_| ParseSignatureError::WrongSize)
}
}
@ -150,11 +148,11 @@ mod tests {
fn test_signature_fromstr() {
let signature = Keypair::new().sign_message(&[0u8]);
let mut signature_base58_str = bs58::encode(signature).into_string();
let mut signature_base58_str = fd_bs58::encode_64(signature);
assert_eq!(signature_base58_str.parse::<Signature>(), Ok(signature));
signature_base58_str.push_str(&bs58::encode(signature.0).into_string());
signature_base58_str.push_str(&fd_bs58::encode_64(signature.0));
assert_eq!(
signature_base58_str.parse::<Signature>(),
Err(ParseSignatureError::WrongSize)
@ -166,10 +164,10 @@ mod tests {
signature_base58_str.truncate(signature_base58_str.len() / 2);
assert_eq!(
signature_base58_str.parse::<Signature>(),
Err(ParseSignatureError::WrongSize)
Err(ParseSignatureError::Invalid)
);
let mut signature_base58_str = bs58::encode(signature.0).into_string();
let mut signature_base58_str = fd_bs58::encode_64(signature.0);
assert_eq!(signature_base58_str.parse::<Signature>(), Ok(signature));
// throw some non-base58 stuff in there
@ -181,7 +179,7 @@ mod tests {
// too long input string
// longest valid encoding
let mut too_long = bs58::encode(&[255u8; SIGNATURE_BYTES]).into_string();
let mut too_long = fd_bs58::encode_64(&[255u8; SIGNATURE_BYTES]);
// and one to grow on
too_long.push('1');
assert_eq!(
@ -193,9 +191,8 @@ mod tests {
#[test]
fn test_off_curve_pubkey_verify_fails() {
// Golden point off the ed25519 curve
let off_curve_bytes = bs58::decode("9z5nJyQar1FUxVJxpBXzon6kHehbomeYiDaLi9WAMhCq")
.into_vec()
.unwrap();
let off_curve_bytes =
fd_bs58::decode_32("9z5nJyQar1FUxVJxpBXzon6kHehbomeYiDaLi9WAMhCq").unwrap();
// Confirm golden's off-curvedness
let mut off_curve_bits = [0u8; 32];

View File

@ -68,12 +68,12 @@ impl Keypair {
/// Recovers a `Keypair` from a base58-encoded string
pub fn from_base58_string(s: &str) -> Self {
Self::from_bytes(&bs58::decode(s).into_vec().unwrap()).unwrap()
Self::from_bytes(&fd_bs58::decode_64(s).unwrap()).unwrap()
}
/// Returns this `Keypair` as a base58-encoded string
pub fn to_base58_string(&self) -> String {
bs58::encode(&self.0.to_bytes()).into_string()
fd_bs58::encode_64(&self.0.to_bytes())
}
/// Gets this `Keypair`'s SecretKey