diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2021-07-31 11:34:58 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2021-07-31 11:34:58 +0200 |
| commit | 177d24325a098e6e62ee9445a0a3cf59a119628c (patch) | |
| tree | 1fc041da39f22296042094605d1ab8d87f78cc58 /src/account.rs | |
| parent | ca26395c8305467985709bb873ee98e6e4fdea75 (diff) | |
add commpand for export public key
Diffstat (limited to 'src/account.rs')
| -rw-r--r-- | src/account.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/account.rs b/src/account.rs index 7d1eeb5..6233f6a 100644 --- a/src/account.rs +++ b/src/account.rs @@ -25,10 +25,15 @@ impl PrivateKey { Ok(PrivateKey(key)) } + /// Returns the public key for the private key. + pub fn public(&self) -> PublicKey { + let secp = Secp256k1::signing_only(); + PublicKey::from_secret_key(&secp, &self.0) + } + /// Returns the public address for the private key. pub fn address(&self) -> Address { - let secp = Secp256k1::signing_only(); - let public_key = PublicKey::from_secret_key(&secp, &self.0).serialize_uncompressed(); + let public_key = self.public().serialize_uncompressed(); // NOTE: An ethereum address is the last 20 bytes of the keccak hash of // the public key. Note that `libsecp256k1` public key is serialized |
