Struct ethers_signers::Wallet
source · pub struct Wallet<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> { /* private fields */ }
Expand description
An Ethereum private-public key pair which can be used for signing messages.
Examples
Signing and Verifying a message
The wallet can be used to produce ECDSA Signature
objects, which can be
then verified. Note that this uses hash_message
under the hood which will
prefix the message being hashed with the Ethereum Signed Message
domain separator.
use ethers_core::rand::thread_rng;
use ethers_signers::{LocalWallet, Signer};
let wallet = LocalWallet::new(&mut thread_rng());
// Optionally, the wallet's chain id can be set, in order to use EIP-155
// replay protection with different chains
let wallet = wallet.with_chain_id(1337u64);
// The wallet can be used to sign messages
let message = b"hello";
let signature = wallet.sign_message(message).await?;
assert_eq!(signature.recover(&message[..]).unwrap(), wallet.address());
// LocalWallet is clonable:
let wallet_clone = wallet.clone();
let signature2 = wallet_clone.sign_message(message).await?;
assert_eq!(signature, signature2);
Implementations§
source§impl Wallet<SigningKey>
impl Wallet<SigningKey>
sourcepub fn new_keystore<P, R, S>(
dir: P,
rng: &mut R,
password: S,
name: Option<&str>
) -> Result<(Self, String), WalletError>where
P: AsRef<Path>,
R: Rng + CryptoRng + CryptoRng,
S: AsRef<[u8]>,
pub fn new_keystore<P, R, S>(
dir: P,
rng: &mut R,
password: S,
name: Option<&str>
) -> Result<(Self, String), WalletError>where
P: AsRef<Path>,
R: Rng + CryptoRng + CryptoRng,
S: AsRef<[u8]>,
Creates a new random encrypted JSON with the provided password and stores it in the
provided directory. Returns a tuple (Wallet, String) of the wallet instance for the
keystore with its random UUID. Accepts an optional name for the keystore file. If None
,
the keystore is stored as the stringified UUID.
sourcepub fn decrypt_keystore<P, S>(
keypath: P,
password: S
) -> Result<Self, WalletError>where
P: AsRef<Path>,
S: AsRef<[u8]>,
pub fn decrypt_keystore<P, S>(
keypath: P,
password: S
) -> Result<Self, WalletError>where
P: AsRef<Path>,
S: AsRef<[u8]>,
Decrypts an encrypted JSON from the provided path to construct a Wallet instance
source§impl Wallet<YubiSigner<Secp256k1>>
impl Wallet<YubiSigner<Secp256k1>>
sourcepub fn connect(connector: Connector, credentials: Credentials, id: Id) -> Self
pub fn connect(connector: Connector, credentials: Credentials, id: Id) -> Self
Connects to a yubi key’s ECDSA account at the provided id
source§impl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Wallet<D>
impl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Wallet<D>
sourcepub fn new_with_signer(signer: D, address: Address, chain_id: u64) -> Self
pub fn new_with_signer(signer: D, address: Address, chain_id: u64) -> Self
Construct a new wallet with an external Signer
source§impl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Wallet<D>
impl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Wallet<D>
sourcepub fn sign_transaction_sync(&self, tx: &TypedTransaction) -> Signature
pub fn sign_transaction_sync(&self, tx: &TypedTransaction) -> Signature
Synchronously signs the provided transaction, normalizing the signature v
value with
EIP-155 using the transaction’s chain_id
, or the signer’s chain_id
if the transaction
does not specify one.
Trait Implementations§
source§impl From<Signer<Secp256k1>> for Wallet<YubiSigner<Secp256k1>>
impl From<Signer<Secp256k1>> for Wallet<YubiSigner<Secp256k1>>
source§fn from(signer: YubiSigner<Secp256k1>) -> Self
fn from(signer: YubiSigner<Secp256k1>) -> Self
source§impl PartialEq<Wallet<SigningKey>> for Wallet<SigningKey>
impl PartialEq<Wallet<SigningKey>> for Wallet<SigningKey>
source§impl<D: Sync + Send + DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Signer for Wallet<D>
impl<D: Sync + Send + DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Signer for Wallet<D>
source§fn with_chain_id<T: Into<u64>>(self, chain_id: T) -> Self
fn with_chain_id<T: Into<u64>>(self, chain_id: T) -> Self
Sets the wallet’s chain_id, used in conjunction with EIP-155 signing