pub struct Keypair { /* private fields */ }Expand description
An Ed25519 keypair for signing transactions.
This is a lightweight wrapper around ed25519_dalek::SigningKey that provides convenient methods for creating keypairs and signing messages.
§Security Note
This stores the private key in memory. For production use with significant funds, consider using a hardware wallet or external signing service.
Implementations§
Source§impl Keypair
impl Keypair
Sourcepub fn from_bytes(secret_key: [u8; 32]) -> Self
pub fn from_bytes(secret_key: [u8; 32]) -> Self
Create a keypair from a 32-byte secret key.
Sourcepub fn from_hex(hex: &str) -> SDKResult<Self>
pub fn from_hex(hex: &str) -> SDKResult<Self>
Create a keypair from a hex-encoded secret key.
Accepts keys with or without “0x” prefix.
Sourcepub fn sign(&self, message: &[u8]) -> Vec<u8> ⓘ
pub fn sign(&self, message: &[u8]) -> Vec<u8> ⓘ
Sign a message and return the 64-byte signature.
Sourcepub fn public_key(&self) -> Vec<u8> ⓘ
pub fn public_key(&self) -> Vec<u8> ⓘ
Get the 32-byte public key.
Sourcepub fn address(&self) -> String
pub fn address(&self) -> String
The on-chain address (base58-encoded public key).
This is the canonical address format used by the Bullet exchange.
For the hex-encoded raw public key, see address_hex.
Sourcepub fn address_hex(&self) -> String
pub fn address_hex(&self) -> String
The public key as a hex string (32 bytes → 64 hex chars).
Sourcepub fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()>
pub fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()>
Write to a Solana-compatible JSON keystore file.
Format: a JSON array of 64 integers — the 32-byte secret key followed
by the 32-byte public key. Compatible with solana-keygen and Phantom.
Sourcepub fn read_from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn read_from_file(path: impl AsRef<Path>) -> Result<Self>
Read a Solana-compatible JSON keystore file.
Accepts either a 64-byte array (secret + public) or a 32-byte array (secret only). Returns an error if the file is missing or malformed.