aboutsummaryrefslogtreecommitdiff
path: root/src/account/public.rs
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2022-05-03 07:59:24 +0200
committerNicholas Rodrigues Lordello <[email protected]>2022-05-03 07:59:24 +0200
commit2cf5f650b8fdbd1992f3d65ad6e102087e74f896 (patch)
tree7c501fcd82b33a6203cb6b55c4820d698c1d83e5 /src/account/public.rs
parent1c13a451bc2e56ce8531d5da683a3c7aa6d4d887 (diff)
Use Rust Secp256k1 implementation from RustCrypto project (#92)
This PR ports `hdwallet` to use the `k256` crate - a native Rust implementation of secp256k1 elliptic curve and ECDSA signing. The motivation for this change is that we can just use the `wasm32-wasi` Rust target without requiring a WASI C toolchain! Notice that the CI no longer requires installing the WASI SDK in order to build the WASI target.
Diffstat (limited to 'src/account/public.rs')
-rw-r--r--src/account/public.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/account/public.rs b/src/account/public.rs
new file mode 100644
index 0000000..c5d0aec
--- /dev/null
+++ b/src/account/public.rs
@@ -0,0 +1,17 @@
+//! Module implementing public key operations.
+
+use k256::elliptic_curve::sec1::ToEncodedPoint as _;
+
+/// A public key.
+pub struct PublicKey(pub k256::PublicKey);
+
+impl PublicKey {
+ /// Returns an uncompressed encoded bytes for the public key.
+ pub fn encode_uncompressed(&self) -> [u8; 65] {
+ self.0
+ .to_encoded_point(false)
+ .as_bytes()
+ .try_into()
+ .expect("unexpected uncompressed private key length")
+ }
+}