feat: use alloy Signature type (#10758)

Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
This commit is contained in:
Aurélien
2024-09-23 15:29:48 +02:00
committed by GitHub
parent fba837468c
commit 15aee9b144
30 changed files with 537 additions and 709 deletions

View File

@ -4,6 +4,7 @@ mod genesis_account;
mod header;
mod log;
mod request;
mod signature;
mod transaction;
mod trie;
mod txkind;

View File

@ -0,0 +1,23 @@
use alloy_primitives::{Parity, Signature, U256};
use crate::Compact;
impl Compact for Signature {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
{
buf.put_slice(&self.r().as_le_bytes());
buf.put_slice(&self.s().as_le_bytes());
self.v().y_parity() as usize
}
fn from_compact(mut buf: &[u8], identifier: usize) -> (Self, &[u8]) {
use bytes::Buf;
assert!(buf.len() >= 64);
let r = U256::from_le_slice(&buf[0..32]);
let s = U256::from_le_slice(&buf[32..64]);
buf.advance(64);
(Self::new(r, s, Parity::Parity(identifier != 0)), buf)
}
}