Enable remote-wallet signing in solana-keygen (#8267)
* Add fallible methods to KeypairUtil * Add RemoteKeypair struct and impl KeypairUtil * Implement RemoteKeypair in keygen; also add parse_keypair_path for cleanup
This commit is contained in:
@ -131,8 +131,14 @@ impl FromStr for Signature {
|
||||
}
|
||||
|
||||
pub trait KeypairUtil {
|
||||
fn pubkey(&self) -> Pubkey;
|
||||
fn sign_message(&self, message: &[u8]) -> Signature;
|
||||
fn pubkey(&self) -> Pubkey {
|
||||
self.try_pubkey().unwrap_or_default()
|
||||
}
|
||||
fn try_pubkey(&self) -> Result<Pubkey, Box<dyn error::Error>>;
|
||||
fn sign_message(&self, message: &[u8]) -> Signature {
|
||||
self.try_sign_message(message).unwrap_or_default()
|
||||
}
|
||||
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, Box<dyn error::Error>>;
|
||||
}
|
||||
|
||||
impl KeypairUtil for Keypair {
|
||||
@ -141,9 +147,17 @@ impl KeypairUtil for Keypair {
|
||||
Pubkey::new(self.0.public.as_ref())
|
||||
}
|
||||
|
||||
fn try_pubkey(&self) -> Result<Pubkey, Box<dyn error::Error>> {
|
||||
Ok(self.pubkey())
|
||||
}
|
||||
|
||||
fn sign_message(&self, message: &[u8]) -> Signature {
|
||||
Signature::new(&self.0.sign(message).to_bytes())
|
||||
}
|
||||
|
||||
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, Box<dyn error::Error>> {
|
||||
Ok(self.sign_message(message))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_keypair<R: Read>(reader: &mut R) -> Result<Keypair, Box<dyn error::Error>> {
|
||||
|
Reference in New Issue
Block a user