#![cfg_attr(doc_cfg, feature(doc_cfg))]
use sui_sdk_types::types::PersonalMessage;
use sui_sdk_types::types::Transaction;
use sui_sdk_types::types::UserSignature;
pub use signature::Error as SignatureError;
pub use signature::Signer;
pub use signature::Verifier;
#[cfg(feature = "ed25519")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "ed25519")))]
pub mod ed25519;
#[allow(unused)]
mod bls12381;
#[cfg(feature = "secp256k1")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "secp256k1")))]
pub mod secp256k1;
#[cfg(feature = "secp256r1")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "secp256r1")))]
pub mod secp256r1;
#[cfg(feature = "zklogin")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "zklogin")))]
pub mod zklogin;
#[cfg(any(
feature = "ed25519",
feature = "secp256r1",
feature = "secp256k1",
feature = "zklogin"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(
feature = "ed25519",
feature = "secp256r1",
feature = "secp256k1",
feature = "zklogin"
)))
)]
pub mod simple;
#[cfg(any(
feature = "ed25519",
feature = "secp256r1",
feature = "secp256k1",
feature = "zklogin"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(
feature = "ed25519",
feature = "secp256r1",
feature = "secp256k1",
feature = "zklogin"
)))
)]
pub mod multisig;
#[cfg(any(
feature = "ed25519",
feature = "secp256r1",
feature = "secp256k1",
feature = "zklogin"
))]
#[cfg_attr(
doc_cfg,
doc(cfg(any(
feature = "ed25519",
feature = "secp256r1",
feature = "secp256k1",
feature = "zklogin"
)))
)]
#[doc(inline)]
pub use multisig::UserSignatureVerifier;
pub trait SuiSigner {
fn sign_transaction(&self, transaction: &Transaction) -> Result<UserSignature, SignatureError>;
fn sign_personal_message(
&self,
message: &PersonalMessage<'_>,
) -> Result<UserSignature, SignatureError>;
}
impl<T: Signer<UserSignature>> SuiSigner for T {
fn sign_transaction(&self, transaction: &Transaction) -> Result<UserSignature, SignatureError> {
let msg = transaction.signing_digest();
self.try_sign(&msg)
}
fn sign_personal_message(
&self,
message: &PersonalMessage<'_>,
) -> Result<UserSignature, SignatureError> {
let msg = message.signing_digest();
self.try_sign(&msg)
}
}
pub trait SuiVerifier {
fn verify_transaction(
&self,
transaction: &Transaction,
signature: &UserSignature,
) -> Result<(), SignatureError>;
fn verify_personal_message(
&self,
message: &PersonalMessage<'_>,
signature: &UserSignature,
) -> Result<(), SignatureError>;
}
impl<T: Verifier<UserSignature>> SuiVerifier for T {
fn verify_transaction(
&self,
transaction: &Transaction,
signature: &UserSignature,
) -> Result<(), SignatureError> {
let message = transaction.signing_digest();
self.verify(&message, signature)
}
fn verify_personal_message(
&self,
message: &PersonalMessage<'_>,
signature: &UserSignature,
) -> Result<(), SignatureError> {
let message = message.signing_digest();
self.verify(&message, signature)
}
}