11use crate :: types:: blake3;
2- use crate :: types:: { Address , AuthorizedTransaction , Body , GetAddress , Transaction , Verify } ;
3- pub use ed25519_dalek:: { Keypair , PublicKey , Signature , SignatureError , Signer , Verifier } ;
2+ use crate :: types:: {
3+ Address , AuthorizedTransaction , Body , GetAddress , Transaction , Verify ,
4+ } ;
5+ pub use ed25519_dalek:: {
6+ Keypair , PublicKey , Signature , SignatureError , Signer , Verifier ,
7+ } ;
48use rayon:: prelude:: * ;
59use serde:: { Deserialize , Serialize } ;
610
@@ -16,9 +20,13 @@ impl GetAddress for Authorization {
1620 }
1721}
1822
19- impl < C : Clone + Serialize + for < ' de > Deserialize < ' de > + Send + Sync > Verify < C > for Authorization {
23+ impl < C : Clone + Serialize + for < ' de > Deserialize < ' de > + Send + Sync > Verify < C >
24+ for Authorization
25+ {
2026 type Error = Error ;
21- fn verify_transaction ( transaction : & AuthorizedTransaction < Self , C > ) -> Result < ( ) , Self :: Error >
27+ fn verify_transaction (
28+ transaction : & AuthorizedTransaction < Self , C > ,
29+ ) -> Result < ( ) , Self :: Error >
2230 where
2331 Self : Sized ,
2432 {
@@ -56,16 +64,17 @@ pub fn verify_authorized_transaction<C: Clone + Serialize + Sync>(
5664 let messages: Vec < _ > = std:: iter:: repeat ( serialized_transaction. as_slice ( ) )
5765 . take ( transaction. authorizations . len ( ) )
5866 . collect ( ) ;
59- let ( public_keys, signatures) : ( Vec < PublicKey > , Vec < Signature > ) = transaction
60- . authorizations
61- . iter ( )
62- . map (
63- |Authorization {
64- public_key,
65- signature,
66- } | ( public_key, signature) ,
67- )
68- . unzip ( ) ;
67+ let ( public_keys, signatures) : ( Vec < PublicKey > , Vec < Signature > ) =
68+ transaction
69+ . authorizations
70+ . iter ( )
71+ . map (
72+ |Authorization {
73+ public_key,
74+ signature,
75+ } | ( public_key, signature) ,
76+ )
77+ . unzip ( ) ;
6978 ed25519_dalek:: verify_batch ( & messages, & signatures, & public_keys) ?;
7079 Ok ( ( ) )
7180}
@@ -82,7 +91,8 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
8291 . par_iter ( )
8392 . map ( bincode:: serialize)
8493 . collect :: < Result < _ , _ > > ( ) ?;
85- let serialized_transactions = serialized_transactions. iter ( ) . map ( Vec :: as_slice) ;
94+ let serialized_transactions =
95+ serialized_transactions. iter ( ) . map ( Vec :: as_slice) ;
8696 let messages = input_numbers. zip ( serialized_transactions) . flat_map (
8797 |( input_number, serialized_transaction) | {
8898 std:: iter:: repeat ( serialized_transaction) . take ( input_number)
@@ -101,7 +111,9 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
101111 signatures : Vec :: with_capacity ( package_size) ,
102112 public_keys : Vec :: with_capacity ( package_size) ,
103113 } ;
104- for ( authorization, message) in & pairs[ i * package_size..( i + 1 ) * package_size] {
114+ for ( authorization, message) in
115+ & pairs[ i * package_size..( i + 1 ) * package_size]
116+ {
105117 package. messages . push ( * message) ;
106118 package. signatures . push ( authorization. signature ) ;
107119 package. public_keys . push ( authorization. public_key ) ;
@@ -128,7 +140,9 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
128140 messages,
129141 signatures,
130142 public_keys,
131- } | ed25519_dalek:: verify_batch ( messages, signatures, public_keys) ,
143+ } | {
144+ ed25519_dalek:: verify_batch ( messages, signatures, public_keys)
145+ } ,
132146 )
133147 . collect :: < Result < ( ) , SignatureError > > ( ) ?;
134148 Ok ( ( ) )
@@ -146,7 +160,8 @@ pub fn authorize<C: Clone + Serialize>(
146160 addresses_keypairs : & [ ( Address , & Keypair ) ] ,
147161 transaction : Transaction < C > ,
148162) -> Result < AuthorizedTransaction < Authorization , C > , Error > {
149- let mut authorizations: Vec < Authorization > = Vec :: with_capacity ( addresses_keypairs. len ( ) ) ;
163+ let mut authorizations: Vec < Authorization > =
164+ Vec :: with_capacity ( addresses_keypairs. len ( ) ) ;
150165 let message = bincode:: serialize ( & transaction) ?;
151166 for ( address, keypair) in addresses_keypairs {
152167 let hash_public_key = get_address ( & keypair. public ) ;
0 commit comments