Skip to main content
2 of 2
added 24 characters in body
Jimii
  • 7.7k
  • 1
  • 8
  • 22

how to decode privatekey into bs58 acceptable by wallets?

I'm trying to encode a privatekey into bs58 and login into wallets but it says its not in the correct format. However i'm encoding into bs58 and even decoding to make sure i'm getting the same original bytes, wich according to the logs are correctly decoding and encoding, here is my snippet

use solana_sdk::signature::{Keypair, Signer};
use bs58;

fn main() {
    println!("Hello, world!");

    let keypair = Keypair::new();
    let public_key = keypair.pubkey();
    let secret_key = keypair.secret().to_bytes();
    let bs58_encode = bs58::encode(secret_key).into_string();
    let bs58_decode = bs58::decode(bs58_encode.clone()).into_vec();

    println!("Chave Pública: {}", public_key);
    println!("Chave Privada: {:?}", secret_key);
    println!("bs58: {:?}", bs58_encode);
    println!("bs58 decode: {:?}", bs58_decode);
}
    Chave Pública: 5cBhgaZ6Tjq8AhGWjPeGavdqv6nh6mQnab9g23LUgmKV
    Chave Privada: [190, 254, 81, 191, 188, 251, 2, 110, 124, 255, 154, 228, 12, 147, 48, 115, 138, 224, 49, 33, 213, 236, 238, 139, 148, 114, 85, 177, 208, 82, 32, 60]
    bs58: "DrZPGNoMRaP9snVhjLRZEgLKcQHvzNJ2JBZCiK9UJeS7"
    bs58 decode: Ok([190, 254, 81, 191, 188, 251, 2, 110, 124, 255, 154, 228, 12, 147, 48, 115, 138, 224, 49, 33, 213, 236, 238, 139, 148, 114, 85, 177, 208, 82, 32, 60])

as you can see I'm able to get the original bytes sequence from the encoded string, so I have no idea of what's going wrong