1
- pub use ed25519_dalek:: { Keypair , PublicKey , Signature , SignatureError , Signer , Verifier } ;
1
+ pub use ed25519_dalek:: {
2
+ Keypair , PublicKey , Signature , SignatureError , Signer , Verifier ,
3
+ } ;
2
4
use plain_types:: blake3;
3
- use plain_types:: { Address , AuthorizedTransaction , Body , GetAddress , Transaction , Verify } ;
5
+ use plain_types:: {
6
+ Address , AuthorizedTransaction , Body , GetAddress , Transaction , Verify ,
7
+ } ;
4
8
use rayon:: prelude:: * ;
5
9
use serde:: { Deserialize , Serialize } ;
6
10
@@ -16,9 +20,13 @@ impl GetAddress for Authorization {
16
20
}
17
21
}
18
22
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
+ {
20
26
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 >
22
30
where
23
31
Self : Sized ,
24
32
{
@@ -56,16 +64,17 @@ pub fn verify_authorized_transaction<C: Clone + Serialize + Sync>(
56
64
let messages: Vec < _ > = std:: iter:: repeat ( serialized_transaction. as_slice ( ) )
57
65
. take ( transaction. authorizations . len ( ) )
58
66
. 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 ( ) ;
69
78
ed25519_dalek:: verify_batch ( & messages, & signatures, & public_keys) ?;
70
79
Ok ( ( ) )
71
80
}
@@ -82,7 +91,8 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
82
91
. par_iter ( )
83
92
. map ( bincode:: serialize)
84
93
. 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) ;
86
96
let messages = input_numbers. zip ( serialized_transactions) . flat_map (
87
97
|( input_number, serialized_transaction) | {
88
98
std:: iter:: repeat ( serialized_transaction) . take ( input_number)
@@ -101,7 +111,9 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
101
111
signatures : Vec :: with_capacity ( package_size) ,
102
112
public_keys : Vec :: with_capacity ( package_size) ,
103
113
} ;
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
+ {
105
117
package. messages . push ( * message) ;
106
118
package. signatures . push ( authorization. signature ) ;
107
119
package. public_keys . push ( authorization. public_key ) ;
@@ -128,7 +140,9 @@ pub fn verify_authorizations<C: Clone + Serialize + Sync>(
128
140
messages,
129
141
signatures,
130
142
public_keys,
131
- } | ed25519_dalek:: verify_batch ( messages, signatures, public_keys) ,
143
+ } | {
144
+ ed25519_dalek:: verify_batch ( messages, signatures, public_keys)
145
+ } ,
132
146
)
133
147
. collect :: < Result < ( ) , SignatureError > > ( ) ?;
134
148
Ok ( ( ) )
@@ -146,7 +160,8 @@ pub fn authorize<C: Clone + Serialize>(
146
160
addresses_keypairs : & [ ( Address , & Keypair ) ] ,
147
161
transaction : Transaction < C > ,
148
162
) -> 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 ( ) ) ;
150
165
let message = bincode:: serialize ( & transaction) ?;
151
166
for ( address, keypair) in addresses_keypairs {
152
167
let hash_public_key = get_address ( & keypair. public ) ;
0 commit comments