sdk: add is_interactive() method Signer trait (#18407)

(cherry picked from commit 2af5ec4f57)

Co-authored-by: Trent Nelson <trent@solana.com>
This commit is contained in:
mergify[bot]
2021-07-03 09:09:39 +00:00
committed by GitHub
parent eefca613ad
commit 30fa9cbee7
7 changed files with 33 additions and 0 deletions

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]