Skip to content
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

feat: expose Signature<T> #689

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,4 @@ arbitrary = [
"alloy-dyn-abi?/arbitrary",
]
k256 = ["alloy-primitives/k256"]
eip712 = ["alloy-sol-types?/eip712-serde", "alloy-dyn-abi?/eip712"]

unstable-doc = ["alloy-primitives/unstable-doc"]
eip712 = ["alloy-sol-types?/eip712-serde", "alloy-dyn-abi?/eip712"]
5 changes: 0 additions & 5 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ pub use alloy_primitives as primitives;
#[doc(no_inline)]
pub use primitives::{hex, uint};

#[cfg(feature = "unstable-doc")]
#[doc(hidden)]
#[allow(unused_imports)]
pub use primitives::PrivateSignature as _;

#[cfg(feature = "dyn-abi")]
#[doc(inline)]
pub use alloy_dyn_abi as dyn_abi;
Expand Down
2 changes: 0 additions & 2 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ allocative = ["dep:allocative"]
# Should not be needed most of the time.
hex-compat = ["hex/hex"]

unstable-doc = []

[[bench]]
name = "primitives"
path = "benches/primitives.rs"
Expand Down
18 changes: 5 additions & 13 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,13 @@ mod signed;
pub use signed::{BigIntConversionError, ParseSignedError, Sign, Signed};

mod signature;
pub use signature::{to_eip155_v, Parity, SignatureError};

/// Only available for documentation purposes.
// Without this visible (not `#[doc(hidden)]`) re-export, `rustdoc` will not generate documentation
// for the `Signature` type alias below.
#[cfg(feature = "unstable-doc")]
pub use signature::Signature as PrivateSignature;
pub use signature::{
to_eip155_v, BuildableSignature, Parity, RawSignature, Signature, SignatureError,
};

/// An ECDSA Signature, consisting of V, R, and S.
/// A memoized ECDSA Signature, consisting of V, R, and S.
#[cfg(feature = "k256")]
pub type Signature = signature::Signature<k256::ecdsa::Signature>;

/// An ECDSA Signature, consisting of V, R, and S.
#[cfg(not(feature = "k256"))]
pub type Signature = signature::Signature<()>;
pub type MemoizedSignature = signature::Signature<k256::ecdsa::Signature>;

pub mod utils;
pub use utils::{eip191_hash_message, keccak256, Keccak256};
Expand Down
22 changes: 22 additions & 0 deletions crates/primitives/src/signature/buildable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::{Parity, SignatureError, U256};

use super::RawSignature;

/// Trait used to uniformize signature creation.
pub trait BuildableSignature: Sized {
/// Instantiate from v, r, s.
fn from_rs_and_parity<P: TryInto<Parity, Error = E>, E: Into<SignatureError>>(
r: U256,
s: U256,
parity: P,
) -> Result<Self, SignatureError>;

/// Parses a signature from a byte slice, with a v value
fn from_bytes_and_parity<P: TryInto<Parity, Error = E>, E: Into<SignatureError>>(
bytes: &[u8],
parity: P,
) -> Result<Self, SignatureError>;

/// Converts the signature into a [`RawSignature`].
fn into_raw(self) -> RawSignature;
}
8 changes: 4 additions & 4 deletions crates/primitives/src/signature/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
mod buildable;
pub use buildable::BuildableSignature;

mod error;
pub use error::SignatureError;

mod parity;
pub use parity::Parity;

mod sig;
#[cfg(feature = "unstable-doc")]
pub use sig::Signature;
#[cfg(not(feature = "unstable-doc"))]
pub(crate) use sig::Signature;
pub use sig::{RawSignature, Signature};

mod utils;
pub use utils::to_eip155_v;
Loading