mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: use alloy Signature type (#10758)
Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
use alloy_eips::{
|
||||
eip6110::DepositRequest, eip7002::WithdrawalRequest, eip7251::ConsolidationRequest,
|
||||
};
|
||||
use alloy_primitives::{Address, BlockNumber, Bytes, Sealable, TxKind, B256, U256};
|
||||
use alloy_primitives::{Address, BlockNumber, Bytes, Parity, Sealable, TxKind, B256, U256};
|
||||
pub use rand::Rng;
|
||||
use rand::{
|
||||
distributions::uniform::SampleRange, rngs::StdRng, seq::SliceRandom, thread_rng, SeedableRng,
|
||||
@ -138,8 +138,17 @@ pub fn sign_tx_with_random_key_pair<R: Rng>(rng: &mut R, tx: Transaction) -> Tra
|
||||
|
||||
/// Signs the [Transaction] with the given key pair.
|
||||
pub fn sign_tx_with_key_pair(key_pair: Keypair, tx: Transaction) -> TransactionSigned {
|
||||
let signature =
|
||||
let mut signature =
|
||||
sign_message(B256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap();
|
||||
|
||||
if matches!(tx, Transaction::Legacy(_)) {
|
||||
signature = if let Some(chain_id) = tx.chain_id() {
|
||||
signature.with_chain_id(chain_id)
|
||||
} else {
|
||||
signature.with_parity(Parity::NonEip155(signature.v().y_parity()))
|
||||
}
|
||||
}
|
||||
|
||||
TransactionSigned::from_transaction_and_signature(tx, signature)
|
||||
}
|
||||
|
||||
@ -475,6 +484,7 @@ pub fn random_request<R: Rng>(rng: &mut R) -> Request {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use alloy_primitives::Parity;
|
||||
use reth_primitives::{hex, public_key_to_address, AccessList, Signature, TxEip1559};
|
||||
use std::str::FromStr;
|
||||
|
||||
@ -539,17 +549,17 @@ mod tests {
|
||||
.unwrap();
|
||||
let signature = sign_message(secret, hash).unwrap();
|
||||
|
||||
let expected = Signature {
|
||||
r: U256::from_str(
|
||||
let expected = Signature::new(
|
||||
U256::from_str(
|
||||
"18515461264373351373200002665853028612451056578545711640558177340181847433846",
|
||||
)
|
||||
.unwrap(),
|
||||
s: U256::from_str(
|
||||
U256::from_str(
|
||||
"46948507304638947509940763649030358759909902576025900602547168820602576006531",
|
||||
)
|
||||
.unwrap(),
|
||||
odd_y_parity: false,
|
||||
};
|
||||
Parity::Parity(false),
|
||||
);
|
||||
assert_eq!(expected, signature);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user