From 2af5ec4f57c933448696c676bf4b54ee7600b3e0 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Fri, 2 Jul 2021 23:08:10 -0600 Subject: [PATCH] sdk: add `is_interactive()` method `Signer` trait --- cli-output/src/cli_output.rs | 4 ++++ remote-wallet/src/remote_keypair.rs | 4 ++++ sdk/src/signer/keypair.rs | 4 ++++ sdk/src/signer/mod.rs | 2 ++ sdk/src/signer/null_signer.rs | 4 ++++ sdk/src/signer/presigner.rs | 4 ++++ sdk/src/signer/signers.rs | 11 +++++++++++ 7 files changed, 33 insertions(+) diff --git a/cli-output/src/cli_output.rs b/cli-output/src/cli_output.rs index 4ba5c2212..dd50572dc 100644 --- a/cli-output/src/cli_output.rs +++ b/cli-output/src/cli_output.rs @@ -2450,6 +2450,10 @@ mod tests { fn try_sign_message(&self, _message: &[u8]) -> Result { Ok(Signature::new(&[1u8; 64])) } + + fn is_interactive(&self) -> bool { + false + } } let present: Box = Box::new(keypair_from_seed(&[2u8; 32]).unwrap()); diff --git a/remote-wallet/src/remote_keypair.rs b/remote-wallet/src/remote_keypair.rs index 28ccbe83c..d37eefe24 100644 --- a/remote-wallet/src/remote_keypair.rs +++ b/remote-wallet/src/remote_keypair.rs @@ -53,6 +53,10 @@ impl Signer for RemoteKeypair { .map_err(|e| e.into()), } } + + fn is_interactive(&self) -> bool { + true + } } pub fn generate_remote_keypair( diff --git a/sdk/src/signer/keypair.rs b/sdk/src/signer/keypair.rs index aa6f46325..b32c348f9 100644 --- a/sdk/src/signer/keypair.rs +++ b/sdk/src/signer/keypair.rs @@ -80,6 +80,10 @@ impl Signer for Keypair { fn try_sign_message(&self, message: &[u8]) -> Result { Ok(self.sign_message(message)) } + + fn is_interactive(&self) -> bool { + false + } } impl PartialEq for Keypair diff --git a/sdk/src/signer/mod.rs b/sdk/src/signer/mod.rs index bf7dcc52e..27a4d0706 100644 --- a/sdk/src/signer/mod.rs +++ b/sdk/src/signer/mod.rs @@ -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; + /// Whether the impelmentation requires user interaction to sign + fn is_interactive(&self) -> bool; } impl From for Box diff --git a/sdk/src/signer/null_signer.rs b/sdk/src/signer/null_signer.rs index d5b5ccd38..2e9508511 100644 --- a/sdk/src/signer/null_signer.rs +++ b/sdk/src/signer/null_signer.rs @@ -28,6 +28,10 @@ impl Signer for NullSigner { fn try_sign_message(&self, _message: &[u8]) -> Result { Ok(Signature::default()) } + + fn is_interactive(&self) -> bool { + false + } } impl PartialEq for NullSigner diff --git a/sdk/src/signer/presigner.rs b/sdk/src/signer/presigner.rs index 4b9c12c11..a5f16fb6e 100644 --- a/sdk/src/signer/presigner.rs +++ b/sdk/src/signer/presigner.rs @@ -46,6 +46,10 @@ impl Signer for Presigner { Err(PresignerError::VerificationFailure.into()) } } + + fn is_interactive(&self) -> bool { + false + } } impl PartialEq for Presigner diff --git a/sdk/src/signer/signers.rs b/sdk/src/signer/signers.rs index abc077209..e4b07c8cd 100644 --- a/sdk/src/signer/signers.rs +++ b/sdk/src/signer/signers.rs @@ -10,6 +10,7 @@ pub trait Signers { fn try_pubkeys(&self) -> Result, SignerError>; fn sign_message(&self, message: &[u8]) -> Vec; fn try_sign_message(&self, message: &[u8]) -> Result, 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 { 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 { Ok(Signature::default()) } + fn is_interactive(&self) -> bool { + false + } } #[test]