Skip to content

Commit

Permalink
Merge pull request #319 from 0xcregis/318-fix-add-alphabet-check-for-…
Browse files Browse the repository at this point in the history
…rippleaddress

fix: add alphabet check for ripple address
  • Loading branch information
loki-cmu authored Jan 21, 2025
2 parents 9ee8348 + 4bb5e13 commit b873d82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/anychain-ripple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "anychain-ripple"
description = "A Rust library for interacting with the Ripple blockchain. It provides core functionalities such as transaction signing and serialization, address generation, and network communication."
version = "0.1.10"
version = "0.1.11"
keywords = ["ripple", "blockchain", "wallet", "transactions"]
categories = ["cryptography::cryptocurrencies"]

Expand Down
9 changes: 9 additions & 0 deletions crates/anychain-ripple/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use anychain_core::{
// map_gen(ripple_alphabet, bitcoin_alphabet);
// }

const RIPPLE_ALPHABET: &str = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";

/// Utility for mapping the bitcoin base58 alphabet to ripple base58 alphabet
static BTC_2_XRP_BS58_MAP: [i8; 128] = [
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Expand Down Expand Up @@ -100,6 +102,13 @@ impl Address for RippleAddress {
impl FromStr for RippleAddress {
type Err = AddressError;
fn from_str(addr: &str) -> Result<Self, Self::Err> {
for c in addr.chars() {
if !RIPPLE_ALPHABET.contains(c) {
return Err(AddressError::InvalidAddress(
"illegal ripple address".to_string(),
));
}
}
let s = to_btc_bs58(addr)?;
let data = s.from_base58()?;
if data.len() != 25 {
Expand Down

0 comments on commit b873d82

Please sign in to comment.