Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Binance Rust API Ed25519Dalek not working with futures API
Hi, i am developing a Rust Binance API and i have implemented the Ed25519Dalek data structure to sign the payload for Binance API endpoints request using the ed25519-dalek library.
I have also implemented the HmacSha256 where i encoding the signature with hex::encode, that works fine over all the unit tests.
But regarding the Ed25519Dalek data structure hex::encode does not work, here i use base64::engine::general_purpose::STANDARD.encode. It works just fine with Spot Api for the unit test in case of Spot, but for futures side it pass rarely for the unit test in case of Futures.
Did I miss something in signing the parameters and convert them to base64?
pub struct Ed25519Dalek {
api_key: String,
signing_key: SigningKey,
}
impl Ed25519Dalek {
pub fn new(api_key: String, signing_key: &str) -> Result<Ed25519Dalek, BinanceError> {
Ok(Ed25519Dalek {
api_key,
signing_key: SigningKey::from_pkcs8_pem(signing_key).map_err(|_| {
BinanceError::Unknown("Invalid private key pem for ed25519!".to_string())
})?,
})
}
}
Signing the code and building the url:
fn sign(
&self,
host: &str,
path: &str,
params: &str,
) -> Result<String, binance_common::error::BinanceError> {
let params = self.add_timestamp(params);
let signature = self.signing_key.sign(params.as_bytes());
let endpoint = format!(
"{}&signature={}",
params,
base64::engine::general_purpose::STANDARD.encode(signature.to_bytes())
);
Ok(format!("{}{}{}", host, path, endpoint))
}
Here is the full repository code:
binance-rs
1 post - 1 participant
🏷️ Rust_feed