Struct ethers_signers::Wallet[][src]

pub struct Wallet<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> { /* fields omitted */ }

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.set_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

impl Wallet<SigningKey>[src]

pub fn new_keystore<P, R, S>(
    dir: P,
    rng: &mut R,
    password: S
) -> Result<Self, WalletError> where
    P: AsRef<Path>,
    R: Rng + CryptoRng,
    S: AsRef<[u8]>, 
[src]

Creates a new random encrypted JSON with the provided password and stores it in the provided directory

pub fn decrypt_keystore<P, S>(
    keypath: P,
    password: S
) -> Result<Self, WalletError> where
    P: AsRef<Path>,
    S: AsRef<[u8]>, 
[src]

Decrypts an encrypted JSON from the provided path to construct a Wallet instance

pub fn new<R: Rng + CryptoRng>(rng: &mut R) -> Self[src]

Creates a new random keypair seeded with the provided RNG

impl Wallet<YubiSigner<Secp256k1>>[src]

pub fn connect(connector: Connector, credentials: Credentials, id: Id) -> Self[src]

Connects to a yubi key’s ECDSA account at the provided id

pub fn new(
    connector: Connector,
    credentials: Credentials,
    id: Id,
    label: Label,
    domain: Domain
) -> Self
[src]

Creates a new random ECDSA keypair on the yubi at the provided id

pub fn from_key(
    connector: Connector,
    credentials: Credentials,
    id: Id,
    label: Label,
    domain: Domain,
    key: impl Into<Vec<u8>>
) -> Self
[src]

Uploads the provided keypair on the yubi at the provided id

impl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Wallet<D>[src]

pub fn set_chain_id<T: Into<u64>>(self, chain_id: T) -> Self[src]

Sets the wallet’s chain_id, used in conjunction with EIP-155 signing

pub fn signer(&self) -> &D[src]

Gets the wallet’s signer

pub fn chain_id(&self) -> Option<u64>[src]

Gets the wallet’s chain id

pub fn address(&self) -> Address[src]

Returns the wallet’s address

Trait Implementations

impl Clone for Wallet<SigningKey>[src]

impl<D: DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Debug for Wallet<D>[src]

impl From<SecretKey<Secp256k1>> for Wallet<SigningKey>[src]

impl From<Signer<Secp256k1>> for Wallet<YubiSigner<Secp256k1>>[src]

impl From<SigningKey> for Wallet<SigningKey>[src]

impl FromStr for Wallet<SigningKey>[src]

type Err = K256Error

The associated error which can be returned from parsing.

impl PartialEq<Wallet<SigningKey>> for Wallet<SigningKey>[src]

impl<D: Sync + Send + DigestSigner<ProxyDigest<Sha256>, RecoverableSignature>> Signer for Wallet<D>[src]

type Error = Infallible

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,