@@ -34,8 +34,10 @@ pub struct EthereumAdapter {
3434 keystore_json : String ,
3535 keystore_pwd : Password ,
3636 config : Config ,
37- tokens_verified : RefCell < HashMap < String , Session > > ,
38- tokens_for_auth : RefCell < HashMap < String , String > > ,
37+ // Auth tokens that we have verified (tokenId => session)
38+ session_tokens : RefCell < HashMap < String , Session > > ,
39+ // Auth tokens that we've generated to authenticate with someone (address => token)
40+ authorization_tokens : RefCell < HashMap < String , String > > ,
3941 wallet : RefCell < Option < SafeAccount > > ,
4042}
4143
@@ -59,8 +61,8 @@ impl Adapter for EthereumAdapter {
5961 Ok ( Self {
6062 keystore_json,
6163 keystore_pwd : keystore_pwd. into ( ) ,
62- tokens_verified : RefCell :: new ( HashMap :: new ( ) ) ,
63- tokens_for_auth : RefCell :: new ( HashMap :: new ( ) ) ,
64+ session_tokens : RefCell :: new ( HashMap :: new ( ) ) ,
65+ authorization_tokens : RefCell :: new ( HashMap :: new ( ) ) ,
6466 wallet : RefCell :: new ( None ) ,
6567 config : config. to_owned ( ) ,
6668 } )
@@ -87,10 +89,10 @@ impl Adapter for EthereumAdapter {
8789 fn whoami ( & self ) -> AdapterResult < String > {
8890 match self . wallet . borrow ( ) . clone ( ) {
8991 Some ( wallet) => {
90- let public = & wallet
92+ let public = wallet
9193 . public ( & self . keystore_pwd )
9294 . map_err ( |_| map_error ( "Failed to get public key" ) ) ?;
93- let address = format ! ( "{:?}" , public_to_address( public) ) ;
95+ let address = format ! ( "{:?}" , public_to_address( & public) ) ;
9496 let checksum_address = eth_checksum:: checksum ( & address) ;
9597 Ok ( checksum_address)
9698 }
@@ -173,7 +175,7 @@ impl Adapter for EthereumAdapter {
173175 let is_channel_valid = EthereumAdapter :: is_channel_valid ( & self . config , channel) ;
174176 if is_channel_valid. is_err ( ) {
175177 return Err ( AdapterError :: InvalidChannel (
176- is_channel_valid. err ( ) . unwrap ( ) . to_string ( ) ,
178+ is_channel_valid. err ( ) . expect ( "failed to get channel error" ) . to_string ( ) ,
177179 ) ) ;
178180 }
179181
@@ -194,9 +196,9 @@ impl Adapter for EthereumAdapter {
194196
195197 fn session_from_token ( & self , token : & str ) -> AdapterResult < Session > {
196198 let token_id = token. to_owned ( ) [ ..16 ] . to_string ( ) ;
197- let result = self . tokens_verified . borrow_mut ( ) ;
199+ let result = self . session_tokens . borrow_mut ( ) ;
198200 if result. get ( & token_id) . is_some ( ) {
199- return Ok ( result. get ( & token_id) . unwrap ( ) . to_owned ( ) ) ;
201+ return Ok ( result. get ( & token_id) . expect ( "failed to get session" ) . to_owned ( ) ) ;
200202 }
201203
202204 let verified = match ewt_verify ( & token) {
@@ -246,17 +248,17 @@ impl Adapter for EthereumAdapter {
246248 } ,
247249 } ;
248250
249- self . tokens_verified
251+ self . session_tokens
250252 . borrow_mut ( )
251253 . insert ( token_id, sess. clone ( ) ) ;
252254 Ok ( sess)
253255 }
254256
255257 fn get_auth ( & self , validator : & ValidatorDesc ) -> AdapterResult < String > {
256- let tokens_for_auth = self . tokens_for_auth . borrow ( ) ;
258+ let authorization_tokens = self . authorization_tokens . borrow ( ) ;
257259 match (
258260 self . wallet . borrow ( ) . clone ( ) ,
259- tokens_for_auth . get ( & validator. id ) ,
261+ authorization_tokens . get ( & validator. id ) ,
260262 ) {
261263 ( Some ( _) , Some ( token) ) => Ok ( token. to_owned ( ) ) ,
262264 ( Some ( wallet) , None ) => {
@@ -269,7 +271,7 @@ impl Adapter for EthereumAdapter {
269271 let token = ewt_sign ( & wallet, & self . keystore_pwd , & payload)
270272 . map_err ( |_| map_error ( "Failed to sign token" ) ) ?;
271273
272- self . tokens_for_auth
274+ self . authorization_tokens
273275 . borrow_mut ( )
274276 . insert ( validator. id . clone ( ) , token. clone ( ) ) ;
275277
0 commit comments