@@ -4,6 +4,7 @@ use alloy_primitives::{
4
4
} ;
5
5
use async_trait:: async_trait;
6
6
use auto_impl:: auto_impl;
7
+ pub use either:: Either ;
7
8
8
9
#[ cfg( feature = "eip712" ) ]
9
10
use alloy_dyn_abi:: eip712:: TypedData ;
@@ -134,6 +135,64 @@ pub trait SignerSync<Sig = Signature> {
134
135
fn chain_id_sync ( & self ) -> Option < ChainId > ;
135
136
}
136
137
138
+ #[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
139
+ #[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
140
+ #[ async_trait]
141
+ impl < A , B , Sig > Signer < Sig > for Either < A , B >
142
+ where
143
+ A : Signer < Sig > + Send + Sync ,
144
+ B : Signer < Sig > + Send + Sync ,
145
+ Sig : Send ,
146
+ {
147
+ async fn sign_hash ( & self , hash : & B256 ) -> Result < Sig > {
148
+ match self {
149
+ Self :: Left ( signer) => signer. sign_hash ( hash) . await ,
150
+ Self :: Right ( signer) => signer. sign_hash ( hash) . await ,
151
+ }
152
+ }
153
+
154
+ fn address ( & self ) -> Address {
155
+ match self {
156
+ Self :: Left ( signer) => signer. address ( ) ,
157
+ Self :: Right ( signer) => signer. address ( ) ,
158
+ }
159
+ }
160
+
161
+ fn chain_id ( & self ) -> Option < ChainId > {
162
+ match self {
163
+ Self :: Left ( signer) => signer. chain_id ( ) ,
164
+ Self :: Right ( signer) => signer. chain_id ( ) ,
165
+ }
166
+ }
167
+
168
+ fn set_chain_id ( & mut self , chain_id : Option < ChainId > ) {
169
+ match self {
170
+ Self :: Left ( signer) => signer. set_chain_id ( chain_id) ,
171
+ Self :: Right ( signer) => signer. set_chain_id ( chain_id) ,
172
+ }
173
+ }
174
+ }
175
+
176
+ impl < A , B , Sig > SignerSync < Sig > for Either < A , B >
177
+ where
178
+ A : SignerSync < Sig > ,
179
+ B : SignerSync < Sig > ,
180
+ {
181
+ fn sign_hash_sync ( & self , hash : & B256 ) -> Result < Sig > {
182
+ match self {
183
+ Self :: Left ( signer) => signer. sign_hash_sync ( hash) ,
184
+ Self :: Right ( signer) => signer. sign_hash_sync ( hash) ,
185
+ }
186
+ }
187
+
188
+ fn chain_id_sync ( & self ) -> Option < ChainId > {
189
+ match self {
190
+ Self :: Left ( signer) => signer. chain_id_sync ( ) ,
191
+ Self :: Right ( signer) => signer. chain_id_sync ( ) ,
192
+ }
193
+ }
194
+ }
195
+
137
196
#[ cfg( test) ]
138
197
mod tests {
139
198
use super :: * ;
0 commit comments