From 8e0210af97dab473231c8350cb1b311829b58f76 Mon Sep 17 00:00:00 2001 From: 0xfnzero <0xfnzero@users.noreply.github.com> Date: Sat, 9 May 2026 15:02:25 +0800 Subject: [PATCH] fix(swqos): replace non-portable try_from_base58_string with bs58 decode + TryFrom The patched solana-keypair in the main workspace adds try_from_base58_string, but sol-safekey and other consumers use the standard crates.io version which only provides from_base58_string (panics) and TryFrom<&[u8]> (fallible). Use bs58::decode + Keypair::try_from to keep proper error handling while remaining compatible with the standard solana-keypair crate. --- src/swqos/soyas.rs | 11 +++++------ src/swqos/speedlanding.rs | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/swqos/soyas.rs b/src/swqos/soyas.rs index b46e71e..c334ded 100644 --- a/src/swqos/soyas.rs +++ b/src/swqos/soyas.rs @@ -103,12 +103,11 @@ pub struct SoyasClient { impl SoyasClient { pub async fn new(rpc_url: String, endpoint_string: String, api_key: String) -> Result { let rpc_client = SolanaRpcClient::new(rpc_url); - let keypair = Keypair::try_from_base58_string(api_key.trim()).map_err(|e| { - anyhow::anyhow!( - "Soyas api_token 无法解析为 Solana keypair base58(QUIC mTLS 用): {}", - e - ) - })?; + let keypair_bytes = bs58::decode(api_key.trim()) + .into_vec() + .map_err(|e| anyhow::anyhow!("Soyas api_token base58 解码失败(QUIC mTLS 用): {}", e))?; + let keypair = Keypair::try_from(keypair_bytes.as_slice()) + .map_err(|e| anyhow::anyhow!("Soyas api_token 无法解析为 Solana keypair(QUIC mTLS 用): {}", e))?; let (cert, key) = generate_client_tls_credentials(&keypair)?; let mut crypto = rustls::ClientConfig::builder() .dangerous() diff --git a/src/swqos/speedlanding.rs b/src/swqos/speedlanding.rs index c936093..67a003e 100644 --- a/src/swqos/speedlanding.rs +++ b/src/swqos/speedlanding.rs @@ -48,12 +48,11 @@ impl SpeedlandingClient { pub async fn new(rpc_url: String, endpoint_string: String, api_key: String) -> Result { let rpc_client = SolanaRpcClient::new(rpc_url); // Speedlanding QUIC:与官方一致使用 `solana_tls_utils::new_dummy_x509_certificate`(Ed25519 dummy cert)+ SNI `speed-landing`。 - let keypair = Keypair::try_from_base58_string(api_key.trim()).map_err(|e| { - anyhow::anyhow!( - "Speedlanding api_token 无法解析为 Solana keypair base58(用于 mTLS);请确认粘贴的是机器人提供的密钥而非其它字符串: {}", - e - ) - })?; + let keypair_bytes = bs58::decode(api_key.trim()) + .into_vec() + .map_err(|e| anyhow::anyhow!("Speedlanding api_token base58 解码失败(mTLS 用): {}", e))?; + let keypair = Keypair::try_from(keypair_bytes.as_slice()) + .map_err(|e| anyhow::anyhow!("Speedlanding api_token 无法解析为 Solana keypair(mTLS 用): {}", e))?; let (cert, key) = new_dummy_x509_certificate(&keypair); let mut crypto = rustls::ClientConfig::builder() .dangerous()