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());
Implementations
sourceimpl 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
sourceimpl 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
sourceimpl<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
sourceimpl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Debug for Wallet<D>
impl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Debug for Wallet<D>
sourceimpl From<Signer<Secp256k1>> for Wallet<YubiSigner<Secp256k1>>
impl From<Signer<Secp256k1>> for Wallet<YubiSigner<Secp256k1>>
sourcefn from(signer: YubiSigner<Secp256k1>) -> Self
fn from(signer: YubiSigner<Secp256k1>) -> Self
Converts to this type from the input type.
sourceimpl<D: Sync + Send + DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Signer for Wallet<D>
impl<D: Sync + Send + DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Signer for Wallet<D>
sourcefn 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
type Error = WalletError
sourcefn sign_message<'life0, 'async_trait, S>(
&'life0 self,
message: S
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>> where
S: 'async_trait + Send + Sync + AsRef<[u8]>,
'life0: 'async_trait,
Self: 'async_trait,
fn sign_message<'life0, 'async_trait, S>(
&'life0 self,
message: S
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>> where
S: 'async_trait + Send + Sync + AsRef<[u8]>,
'life0: 'async_trait,
Self: 'async_trait,
Signs the hash of the provided message after prefixing it
sourcefn sign_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 TypedTransaction
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn sign_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
tx: &'life1 TypedTransaction
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Signs the transaction
sourcefn sign_typed_data<'life0, 'life1, 'async_trait, T>(
&'life0 self,
payload: &'life1 T
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>> where
T: 'async_trait + Eip712 + Send + Sync,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn sign_typed_data<'life0, 'life1, 'async_trait, T>(
&'life0 self,
payload: &'life1 T
) -> Pin<Box<dyn Future<Output = Result<Signature, Self::Error>> + Send + 'async_trait>> where
T: 'async_trait + Eip712 + Send + Sync,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Encodes and signs the typed data according EIP-712. Payload must implement Eip712 trait. Read more
Auto Trait Implementations
impl<D> RefUnwindSafe for Wallet<D> where
D: RefUnwindSafe,
impl<D> Send for Wallet<D> where
D: Send,
impl<D> Sync for Wallet<D> where
D: Sync,
impl<D> Unpin for Wallet<D> where
D: Unpin,
impl<D> UnwindSafe for Wallet<D> where
D: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more