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.
This commit is contained in:
0xfnzero
2026-05-09 15:02:25 +08:00
parent e605485ecf
commit 8e0210af97
2 changed files with 10 additions and 12 deletions
+5 -6
View File
@@ -103,12 +103,11 @@ pub struct SoyasClient {
impl SoyasClient {
pub async fn new(rpc_url: String, endpoint_string: String, api_key: String) -> Result<Self> {
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 base58QUIC 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 keypairQUIC mTLS 用): {}", e))?;
let (cert, key) = generate_client_tls_credentials(&keypair)?;
let mut crypto = rustls::ClientConfig::builder()
.dangerous()
+5 -6
View File
@@ -48,12 +48,11 @@ impl SpeedlandingClient {
pub async fn new(rpc_url: String, endpoint_string: String, api_key: String) -> Result<Self> {
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 keypairmTLS 用): {}", e))?;
let (cert, key) = new_dummy_x509_certificate(&keypair);
let mut crypto = rustls::ClientConfig::builder()
.dangerous()