alloy-signer
Ethereum signer abstraction.
You can implement the Signer
trait to extend functionality to other signers
such as Hardware Security Modules, KMS etc. See its documentation for more.
Signer implementations in Alloy:
Examples
Sign an Ethereum prefixed message (EIP-712):
use ;
use PrivateKeySigner;
// Instantiate a signer.
let signer = random;
// Sign a message.
let message = "Some data";
let signature = signer.sign_message_sync?;
// Recover the signer from the message.
let recovered = signature.recover_address_from_msg?;
assert_eq!;
# Ok::
Sign a transaction:
use TxLegacy;
use ;
use ;
use PrivateKeySigner;
use ;
// Instantiate a signer.
let signer = "dcf2cbdd171a21c480aa7f53d77f31bb102282b3ff099c78e3118b37348c72f7"
.?;
// Create a transaction.
let mut tx = TxLegacy ;
// Sign it.
let signature = signer.sign_transaction_sync?;
# Ok::