kevinheavey / solders

A high-performance Python toolkit for Solana, written in Rust
https://kevinheavey.github.io/solders/
Apache License 2.0
205 stars 23 forks source link

bytes(solders.keypair.Keypair()) conversion is not obvious #88

Closed MJBlack9000 closed 5 months ago

MJBlack9000 commented 6 months ago

Issue As of now it is difficult to figure out how to treat the 32-bit Keypair().secret() field. My first assumption was that it is a private key, but it is only a portion of the private key. bytes(Keypair()) is the private key. Type-casting Keypair to bytes is far from being obvious, in my opinion.

Suggested solution add a private_key() or privkey() or to_bytes() method to solders.keypair.Keypair

Background Myself, someone without any prior Solana background, it took me nearly 3 hours of research to finally arrive at this repo, and out of desperation - to try and learn something from the auto-tests. Keypair docs do a good job of showing how to create an account with a private key. But do nothing to explain how to export a private key for later use. Stack overflow and various media outlets are full of outdated information(or are written for JS libraries), most of it either referring to solana Keypair which featured .generate() and .private_key, among others, or are simply dead links to the docs. Not to mention that all of the info is on Solana SO, where I for example don't even have an account and can't comment and therefore can't ask for clarification or further pointers. Long story short - I imagine most people new to Solana would also find themselves in a similar situation. I have found a solution, but it was costly. Therefore I request that you bring back some form of a .private_key field, or even at least expose the ability to type-cast to bytes through some obvious field/method.

kevinheavey commented 6 months ago

Let's start with adding a bit here about how you can call bytes(keypair) https://kevinheavey.github.io/solders/tutorials/keypairs.html