Skip to content

Commit 54d19dd

Browse files
authored
Merge pull request #964 from subspace/fix-ss58-parsing
Fix ss58 parsing in farmer
2 parents 20a9d71 + 0570625 commit 54d19dd

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/subspace-farmer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ include = [
1515
anyhow = "1.0.66"
1616
async-trait = "0.1.58"
1717
base58 = "0.2.0"
18+
blake2 = "0.10.5"
1819
bytesize = "1.1.0"
1920
clap = { version = "4.0.26", features = ["color", "derive"] }
2021
derive_more = "0.99.17"

crates/subspace-farmer/src/bin/subspace-farmer/ss58.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
//! `sp-core` into farmer application
1919
2020
use base58::FromBase58;
21+
use blake2::digest::typenum::U64;
22+
use blake2::digest::FixedOutput;
23+
use blake2::{Blake2b, Digest};
2124
use ss58_registry::Ss58AddressFormat;
22-
use subspace_core_primitives::crypto::blake2b_256_hash_list;
23-
use subspace_core_primitives::{Blake2b256Hash, PublicKey, PUBLIC_KEY_LENGTH};
25+
use subspace_core_primitives::{PublicKey, PUBLIC_KEY_LENGTH};
2426
use thiserror::Error;
2527

2628
const PREFIX: &[u8] = b"SS58PRE";
@@ -90,6 +92,20 @@ pub(crate) fn parse_ss58_reward_address(s: &str) -> Result<PublicKey, Ss58Parsin
9092
Ok(PublicKey::from(bytes))
9193
}
9294

93-
fn ss58hash(data: &[u8]) -> Blake2b256Hash {
94-
blake2b_256_hash_list(&[PREFIX, data])
95+
fn ss58hash(data: &[u8]) -> [u8; 64] {
96+
let mut state = Blake2b::<U64>::new();
97+
state.update(PREFIX);
98+
state.update(data);
99+
state.finalize_fixed().into()
100+
}
101+
102+
#[cfg(test)]
103+
mod tests {
104+
use super::parse_ss58_reward_address;
105+
106+
#[test]
107+
fn basic() {
108+
// Alice
109+
parse_ss58_reward_address("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY").unwrap();
110+
}
95111
}

0 commit comments

Comments
 (0)