pathfinder_common/
signature.rs1use fake::Dummy;
2
3use crate::{BlockCommitmentSignatureElem, BlockHash, PublicKey};
4
5#[derive(Default, Debug, Clone, PartialEq, Eq, Dummy)]
6pub struct BlockCommitmentSignature {
7 pub r: BlockCommitmentSignatureElem,
8 pub s: BlockCommitmentSignatureElem,
9}
10
11impl BlockCommitmentSignature {
12 pub fn verify(
13 &self,
14 public_key: PublicKey,
15 block_hash: BlockHash,
16 ) -> Result<(), pathfinder_crypto::signature::SignatureError> {
17 pathfinder_crypto::signature::ecdsa_verify_partial(
18 public_key.0,
19 block_hash.0,
20 self.r.0,
21 self.s.0,
22 )
23 }
24}
25
26#[cfg(test)]
27mod test {
28 use crate::macro_prelude::*;
29 use crate::BlockCommitmentSignature;
30
31 #[test]
32 fn _0_13_2_verification_method_for_the_last_0_13_1_1_block() {
33 let public_key =
35 public_key!("0x4e4856eb36dbd5f4a7dca29f7bb5232974ef1fb7eb5b597c58077174c294da1");
36 let block_hash =
38 block_hash!("0x77140bef51bbb4d1932f17cc5081825ff18465a1df4440ca0429a4fa80f1dc5");
39 let signature = BlockCommitmentSignature {
40 r: block_commitment_signature_elem!(
41 "0x44b4fef018bb755107ed0caab714f628c0804b2a8787664c5210e607aed3004"
42 ),
43 s: block_commitment_signature_elem!(
44 "0x2ea6ecf5d11f0eba14e867c8d771ab958b55e45ded7ce93a1fe78045593f22b"
45 ),
46 };
47
48 signature.verify(public_key, block_hash).unwrap();
52 }
53
54 #[test]
55 fn _0_13_2_verification_method_for_the_first_0_13_2_block() {
56 let public_key =
58 public_key!("0x4e4856eb36dbd5f4a7dca29f7bb5232974ef1fb7eb5b597c58077174c294da1");
59 let block_hash =
61 block_hash!("0x1ea2a9cfa3df5297d58c0a04d09d276bc68d40fe64701305bbe2ed8f417e869");
62 let signature = BlockCommitmentSignature {
63 r: block_commitment_signature_elem!(
64 "0x45161746eecbeae297f45a1f407ab702310f4e52c5e9350ed6f542fa8e98413"
65 ),
66 s: block_commitment_signature_elem!(
67 "0x3e67cfbc5b179ba55a3b687228d8fe40626233f6691b4aabe308fcd6d71dcdb"
68 ),
69 };
70
71 signature.verify(public_key, block_hash).unwrap();
75 }
76}