-
Notifications
You must be signed in to change notification settings - Fork 53
feat(dpp)!: convert Signer trait to async #3492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.1-dev
Are you sure you want to change the base?
Changes from 1 commit
91f68cc
e3cc4fc
ccabca7
9169382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,42 @@ | ||
| use crate::address_funds::AddressWitness; | ||
| use crate::ProtocolError; | ||
| use async_trait::async_trait; | ||
| use platform_value::BinaryData; | ||
| use std::fmt::Debug; | ||
| use std::sync::Arc; | ||
|
|
||
| pub trait Signer<K>: Sync + Debug { | ||
| #[async_trait] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure we still want to use |
||
| pub trait Signer<K>: Send + Sync + Debug { | ||
| /// the public key bytes are only used to look up the private key | ||
| fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError>; | ||
| async fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError>; | ||
|
|
||
| /// the public key bytes are only used to look up the private key | ||
| fn sign_create_witness(&self, key: &K, data: &[u8]) -> Result<AddressWitness, ProtocolError>; | ||
| async fn sign_create_witness( | ||
| &self, | ||
| key: &K, | ||
| data: &[u8], | ||
| ) -> Result<AddressWitness, ProtocolError>; | ||
|
|
||
| /// do we have this identity public key in the signer? | ||
| fn can_sign_with(&self, key: &K) -> bool; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl<K, S> Signer<K> for Arc<S> | ||
| where | ||
| S: Signer<K> + ?Sized + Send, | ||
| K: Send + Sync, | ||
| S: Signer<K> + ?Sized + Send + Sync, | ||
| { | ||
| fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError> { | ||
| (**self).sign(key, data) | ||
| async fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError> { | ||
| (**self).sign(key, data).await | ||
| } | ||
|
|
||
| fn sign_create_witness(&self, key: &K, data: &[u8]) -> Result<AddressWitness, ProtocolError> { | ||
| (**self).sign_create_witness(key, data) | ||
| async fn sign_create_witness( | ||
| &self, | ||
| key: &K, | ||
| data: &[u8], | ||
| ) -> Result<AddressWitness, ProtocolError> { | ||
| (**self).sign_create_witness(key, data).await | ||
| } | ||
|
|
||
| fn can_sign_with(&self, key: &K) -> bool { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| //#![deny(missing_docs)] | ||
| #![allow(dead_code)] | ||
| #![allow(clippy::result_large_err)] | ||
| #![allow(async_fn_in_trait)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use legacy |
||
|
|
||
| extern crate core; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can deadlock, workaround in #3490