Remove secp256k1 from WASM build (#5187)

* Remove `secp256k1` from WASM build

* Bring back full public key parse on native

* Add extra method to create from a full public key
This commit is contained in:
Bastian Köcher
2020-03-10 14:10:57 +01:00
committed by GitHub
parent d1cac6cd19
commit 57ecc10cf1
2 changed files with 18 additions and 8 deletions
+16 -7
View File
@@ -92,6 +92,17 @@ impl Public {
pub fn from_raw(data: [u8; 33]) -> Self {
Self(data)
}
/// Create a new instance from the given full public key.
///
/// This will convert the full public key into the compressed format.
#[cfg(feature = "std")]
pub fn from_full(full: &[u8]) -> Result<Self, ()> {
secp256k1::PublicKey::parse_slice(full, None)
.map(|k| k.serialize_compressed())
.map(Self)
.map_err(|_| ())
}
}
impl TraitPublic for Public {
@@ -133,10 +144,8 @@ impl sp_std::convert::TryFrom<&[u8]> for Public {
if data.len() == 33 {
Ok(Self::from_slice(data))
} else {
secp256k1::PublicKey::parse_slice(data, None)
.map(|k| k.serialize_compressed())
.map(Self)
.map_err(|_| ())
Err(())
}
}
}
@@ -544,7 +553,7 @@ mod test {
let public = pair.public();
assert_eq!(
public,
Public::try_from(
Public::from_full(
&hex!("8db55b05db86c0b1786ca49f095d76344c9e6056b2f02701a7e7f3c20aabfd913ebbe148dd17c56551a52952371071a6c604b3f3abe8f2c8fa742158ea6dd7d4")[..],
).unwrap(),
);
@@ -564,7 +573,7 @@ mod test {
let public = pair.public();
assert_eq!(
public,
Public::try_from(
Public::from_full(
&hex!("8db55b05db86c0b1786ca49f095d76344c9e6056b2f02701a7e7f3c20aabfd913ebbe148dd17c56551a52952371071a6c604b3f3abe8f2c8fa742158ea6dd7d4")[..],
).unwrap(),
);
@@ -591,7 +600,7 @@ mod test {
let public = pair.public();
assert_eq!(
public,
Public::try_from(
Public::from_full(
&hex!("5676109c54b9a16d271abeb4954316a40a32bcce023ac14c8e26e958aa68fba995840f3de562156558efbfdac3f16af0065e5f66795f4dd8262a228ef8c6d813")[..],
).unwrap(),
);