sdk: add is_interactive() method Signer trait

(cherry picked from commit 2af5ec4f57)
This commit is contained in:
Trent Nelson
2021-07-02 23:08:10 -06:00
committed by Michael Vines
parent 57b69b5804
commit 6859516126
7 changed files with 33 additions and 0 deletions

View File

@@ -2446,6 +2446,10 @@ mod tests {
fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
Ok(Signature::new(&[1u8; 64]))
}
fn is_interactive(&self) -> bool {
false
}
}
let present: Box<dyn Signer> = Box::new(keypair_from_seed(&[2u8; 32]).unwrap());

View File

@@ -53,6 +53,10 @@ impl Signer for RemoteKeypair {
.map_err(|e| e.into()),
}
}
fn is_interactive(&self) -> bool {
true
}
}
pub fn generate_remote_keypair(

View File

@@ -80,6 +80,10 @@ impl Signer for Keypair {
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError> {
Ok(self.sign_message(message))
}
fn is_interactive(&self) -> bool {
false
}
}
impl<T> PartialEq<T> for Keypair

View File

@@ -68,6 +68,8 @@ pub trait Signer {
}
/// Fallibly produces an Ed25519 signature over the provided `message` bytes.
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>;
/// Whether the impelmentation requires user interaction to sign
fn is_interactive(&self) -> bool;
}
impl<T> From<T> for Box<dyn Signer>

View File

@@ -28,6 +28,10 @@ impl Signer for NullSigner {
fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
Ok(Signature::default())
}
fn is_interactive(&self) -> bool {
false
}
}
impl<T> PartialEq<T> for NullSigner

View File

@@ -46,6 +46,10 @@ impl Signer for Presigner {
Err(PresignerError::VerificationFailure.into())
}
}
fn is_interactive(&self) -> bool {
false
}
}
impl<T> PartialEq<T> for Presigner

View File

@@ -10,6 +10,7 @@ pub trait Signers {
fn try_pubkeys(&self) -> Result<Vec<Pubkey>, SignerError>;
fn sign_message(&self, message: &[u8]) -> Vec<Signature>;
fn try_sign_message(&self, message: &[u8]) -> Result<Vec<Signature>, SignerError>;
fn is_interactive(&self) -> bool;
}
macro_rules! default_keypairs_impl {
@@ -39,6 +40,10 @@ macro_rules! default_keypairs_impl {
}
Ok(signatures)
}
fn is_interactive(&self) -> bool {
self.iter().any(|s| s.is_interactive())
}
};
}
@@ -118,6 +123,9 @@ mod tests {
fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
Ok(Signature::default())
}
fn is_interactive(&self) -> bool {
false
}
}
struct Bar;
@@ -128,6 +136,9 @@ mod tests {
fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
Ok(Signature::default())
}
fn is_interactive(&self) -> bool {
false
}
}
#[test]