mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 22:41:06 +00:00
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:
@@ -33,7 +33,6 @@ parking_lot = { version = "0.10.0", optional = true }
|
|||||||
sp-debug-derive = { version = "2.0.0-alpha.2", path = "../debug-derive" }
|
sp-debug-derive = { version = "2.0.0-alpha.2", path = "../debug-derive" }
|
||||||
sp-externalities = { version = "0.8.0-alpha.2", optional = true, path = "../externalities" }
|
sp-externalities = { version = "0.8.0-alpha.2", optional = true, path = "../externalities" }
|
||||||
sp-storage = { version = "2.0.0-alpha.2", default-features = false, path = "../storage" }
|
sp-storage = { version = "2.0.0-alpha.2", default-features = false, path = "../storage" }
|
||||||
libsecp256k1 = { version = "0.3.2", default-features = false, features = ["hmac"] }
|
|
||||||
parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] }
|
parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] }
|
||||||
|
|
||||||
# full crypto
|
# full crypto
|
||||||
@@ -44,6 +43,7 @@ schnorrkel = { version = "0.8.5", features = ["preaudit_deprecated", "u64_backen
|
|||||||
sha2 = { version = "0.8.0", default-features = false, optional = true }
|
sha2 = { version = "0.8.0", default-features = false, optional = true }
|
||||||
hex = { version = "0.4", default-features = false, optional = true }
|
hex = { version = "0.4", default-features = false, optional = true }
|
||||||
twox-hash = { version = "1.5.0", default-features = false, optional = true }
|
twox-hash = { version = "1.5.0", default-features = false, optional = true }
|
||||||
|
libsecp256k1 = { version = "0.3.2", default-features = false, features = ["hmac"], optional = true }
|
||||||
|
|
||||||
sp-runtime-interface = { version = "2.0.0-alpha.2", default-features = false, path = "../runtime-interface" }
|
sp-runtime-interface = { version = "2.0.0-alpha.2", default-features = false, path = "../runtime-interface" }
|
||||||
|
|
||||||
@@ -116,5 +116,6 @@ full_crypto = [
|
|||||||
"hex",
|
"hex",
|
||||||
"sha2",
|
"sha2",
|
||||||
"twox-hash",
|
"twox-hash",
|
||||||
|
"libsecp256k1",
|
||||||
"sp-runtime-interface/disable_target_static_assertions",
|
"sp-runtime-interface/disable_target_static_assertions",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -92,6 +92,17 @@ impl Public {
|
|||||||
pub fn from_raw(data: [u8; 33]) -> Self {
|
pub fn from_raw(data: [u8; 33]) -> Self {
|
||||||
Self(data)
|
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 {
|
impl TraitPublic for Public {
|
||||||
@@ -133,10 +144,8 @@ impl sp_std::convert::TryFrom<&[u8]> for Public {
|
|||||||
if data.len() == 33 {
|
if data.len() == 33 {
|
||||||
Ok(Self::from_slice(data))
|
Ok(Self::from_slice(data))
|
||||||
} else {
|
} else {
|
||||||
secp256k1::PublicKey::parse_slice(data, None)
|
|
||||||
.map(|k| k.serialize_compressed())
|
Err(())
|
||||||
.map(Self)
|
|
||||||
.map_err(|_| ())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,7 +553,7 @@ mod test {
|
|||||||
let public = pair.public();
|
let public = pair.public();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
public,
|
public,
|
||||||
Public::try_from(
|
Public::from_full(
|
||||||
&hex!("8db55b05db86c0b1786ca49f095d76344c9e6056b2f02701a7e7f3c20aabfd913ebbe148dd17c56551a52952371071a6c604b3f3abe8f2c8fa742158ea6dd7d4")[..],
|
&hex!("8db55b05db86c0b1786ca49f095d76344c9e6056b2f02701a7e7f3c20aabfd913ebbe148dd17c56551a52952371071a6c604b3f3abe8f2c8fa742158ea6dd7d4")[..],
|
||||||
).unwrap(),
|
).unwrap(),
|
||||||
);
|
);
|
||||||
@@ -564,7 +573,7 @@ mod test {
|
|||||||
let public = pair.public();
|
let public = pair.public();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
public,
|
public,
|
||||||
Public::try_from(
|
Public::from_full(
|
||||||
&hex!("8db55b05db86c0b1786ca49f095d76344c9e6056b2f02701a7e7f3c20aabfd913ebbe148dd17c56551a52952371071a6c604b3f3abe8f2c8fa742158ea6dd7d4")[..],
|
&hex!("8db55b05db86c0b1786ca49f095d76344c9e6056b2f02701a7e7f3c20aabfd913ebbe148dd17c56551a52952371071a6c604b3f3abe8f2c8fa742158ea6dd7d4")[..],
|
||||||
).unwrap(),
|
).unwrap(),
|
||||||
);
|
);
|
||||||
@@ -591,7 +600,7 @@ mod test {
|
|||||||
let public = pair.public();
|
let public = pair.public();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
public,
|
public,
|
||||||
Public::try_from(
|
Public::from_full(
|
||||||
&hex!("5676109c54b9a16d271abeb4954316a40a32bcce023ac14c8e26e958aa68fba995840f3de562156558efbfdac3f16af0065e5f66795f4dd8262a228ef8c6d813")[..],
|
&hex!("5676109c54b9a16d271abeb4954316a40a32bcce023ac14c8e26e958aa68fba995840f3de562156558efbfdac3f16af0065e5f66795f4dd8262a228ef8c6d813")[..],
|
||||||
).unwrap(),
|
).unwrap(),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user