@@ -31,11 +31,12 @@ use substrate_bip39::mini_secret_from_entropy;
31
31
use bip39:: { Mnemonic , Language , MnemonicType } ;
32
32
#[ cfg( feature = "std" ) ]
33
33
use crate :: crypto:: {
34
- Pair as TraitPair , DeriveJunction , Infallible , SecretStringError , Ss58Codec
34
+ Pair as TraitPair , DeriveJunction , Infallible , SecretStringError , Ss58Codec , PublicError
35
35
} ;
36
36
use crate :: { crypto:: { Public as TraitPublic , UncheckedFrom , CryptoType , Derive } } ;
37
37
use crate :: hash:: { H256 , H512 } ;
38
38
use codec:: { Encode , Decode } ;
39
+ use core:: { str:: FromStr , ops:: Deref } ;
39
40
40
41
#[ cfg( feature = "std" ) ]
41
42
use serde:: { de, Deserialize , Deserializer , Serialize , Serializer } ;
@@ -48,7 +49,7 @@ const SIGNING_CTX: &[u8] = b"substrate";
48
49
49
50
/// An Schnorrkel/Ristretto x25519 ("sr25519") public key.
50
51
#[ cfg_attr( feature = "std" , derive( Hash ) ) ]
51
- #[ derive( PartialEq , Eq , PartialOrd , Ord , Clone , Encode , Decode , Default ) ]
52
+ #[ derive( PartialEq , Eq , PartialOrd , Ord , Clone , Copy , Encode , Decode , Default ) ]
52
53
pub struct Public ( pub [ u8 ; 32 ] ) ;
53
54
54
55
impl AsRef < [ u8 ; 32 ] > for Public {
@@ -69,6 +70,14 @@ impl AsMut<[u8]> for Public {
69
70
}
70
71
}
71
72
73
+ impl Deref for Public {
74
+ type Target = [ u8 ] ;
75
+
76
+ fn deref ( & self ) -> & Self :: Target {
77
+ & self . 0
78
+ }
79
+ }
80
+
72
81
impl From < Public > for [ u8 ; 32 ] {
73
82
fn from ( x : Public ) -> [ u8 ; 32 ] {
74
83
x. 0
@@ -81,6 +90,15 @@ impl From<Public> for H256 {
81
90
}
82
91
}
83
92
93
+ #[ cfg( feature = "std" ) ]
94
+ impl FromStr for Public {
95
+ type Err = PublicError ;
96
+
97
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
98
+ Self :: from_ss58check ( s)
99
+ }
100
+ }
101
+
84
102
impl rstd:: convert:: TryFrom < & [ u8 ] > for Public {
85
103
type Error = ( ) ;
86
104
0 commit comments