Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
5 changes: 4 additions & 1 deletion primitives/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ pub trait Ss58Codec: Sized + AsMut<[u8]> + AsRef<[u8]> + Default {
// Invalid length.
return Err(PublicError::BadLength);
}
let ver = d[0].try_into().map_err(|_: ()| PublicError::UnknownVersion)?;
let ver = d[0]
.try_into()
.or_else(|_| d[0].to_string().as_str().try_into())
Comment thread
atenjin marked this conversation as resolved.
Outdated
.map_err(|_: ()| PublicError::UnknownVersion)?;

if d[len + 1..len + 3] != ss58hash(&d[0..len + 1]).as_bytes()[0..2] {
// Invalid checksum.
Expand Down
19 changes: 18 additions & 1 deletion primitives/core/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ impl CryptoType for Pair {
mod test {
use super::*;
use hex_literal::hex;
use crate::crypto::DEV_PHRASE;
use crate::crypto::{DEV_PHRASE, set_default_ss58_version};
use serde_json;

#[test]
Expand Down Expand Up @@ -648,6 +648,23 @@ mod test {
assert_eq!(cmp, public);
}

#[test]
fn ss58check_custom_format_works() {
use crate::crypto::Ss58AddressFormat;
// temp save default format version
let default_format = Ss58AddressFormat::default();
// set current ss58 version is custom "200" `Ss58AddressFormat::Custom(200)`
set_default_ss58_version(Ss58AddressFormat::try_from("200")
.expect("parse str to u8 must success"));
// custom addr encoded by version 200
let addr = "2X64kMNEWAW5KLZMSKcGKEc96MyuaRsRUku7vomuYxKgqjVCRj";
assert!(Public::from_ss58check(&addr).is_ok());
Comment thread
bkchr marked this conversation as resolved.
Outdated
set_default_ss58_version(default_format);
// set current ss58 version to default version
let addr = "KWAfgC2aRG5UVD6CpbPQXCx4YZZUhvWqqAJE6qcYc9Rtr6g5C";
assert!(Public::from_ss58check(&addr).is_ok());
Comment thread
bkchr marked this conversation as resolved.
Outdated
}

#[test]
fn signature_serialization_works() {
let pair = Pair::from_seed(b"12345678901234567890123456789012");
Expand Down