diff --git a/ethers-providers/src/transports/common.rs b/ethers-providers/src/transports/common.rs index 747e1405..a23b68d5 100644 --- a/ethers-providers/src/transports/common.rs +++ b/ethers-providers/src/transports/common.rs @@ -1,5 +1,6 @@ // Code adapted from: https://github.com/althea-net/guac_rs/tree/master/web3/src/jsonrpc +use base64::{engine::general_purpose, Engine}; use ethers_core::types::U256; use serde::{ de::{self, MapAccess, Unexpected, Visitor}, @@ -190,8 +191,10 @@ pub enum Authorization { } impl Authorization { - pub fn basic(username: impl Into, password: impl Into) -> Self { - let auth_secret = base64::encode(username.into() + ":" + &password.into()); + pub fn basic(username: impl AsRef, password: impl AsRef) -> Self { + let username = username.as_ref(); + let password = password.as_ref(); + let auth_secret = general_purpose::STANDARD.encode(format!("{username}:{password}")); Self::Basic(auth_secret) }