pub trait Key {
    fn sign(
        &self,
        message: &[u8],
        chain_id: Option<u64>
    ) -> Result<Signature, SigningError>; fn sign_message(&self, message: &[u8]) -> Result<Signature, SigningError>; fn address(&self) -> Address; }
Expand description

A trait representing ethereum-compatible key with signing capabilities.

The purpose of this trait is to prevent leaking secp256k1::SecretKey struct in stack or memory. To use secret keys securely, they should be wrapped in a struct that prevents leaving copies in memory (both when it’s moved or dropped). Please take a look at:

  • https://github.com/graphprotocol/solidity-bindgen/blob/master/solidity-bindgen/src/secrets.rs
  • or https://crates.io/crates/zeroize if you care enough about your secrets to be used securely.

If it’s enough to pass a reference to SecretKey (lifetimes) than you can use SecretKeyRef wrapper.

Required Methods

Sign given message and include chain-id replay protection.

When a chain ID is provided, the Signature’s V-value will have chain replay protection added (as per EIP-155). Otherwise, the V-value will be in ‘Electrum’ notation.

Sign given message without manipulating V-value; used for typed transactions (AccessList and EIP-1559)

Get public address that this key represents.

Implementors