@@ -34,8 +34,10 @@ pub struct EthereumAdapter {
34
34
keystore_json : String ,
35
35
keystore_pwd : Password ,
36
36
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 > > ,
39
41
wallet : RefCell < Option < SafeAccount > > ,
40
42
}
41
43
@@ -59,8 +61,8 @@ impl Adapter for EthereumAdapter {
59
61
Ok ( Self {
60
62
keystore_json,
61
63
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 ( ) ) ,
64
66
wallet : RefCell :: new ( None ) ,
65
67
config : config. to_owned ( ) ,
66
68
} )
@@ -194,7 +196,7 @@ impl Adapter for EthereumAdapter {
194
196
195
197
fn session_from_token ( & self , token : & str ) -> AdapterResult < Session > {
196
198
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 ( ) ;
198
200
if result. get ( & token_id) . is_some ( ) {
199
201
return Ok ( result. get ( & token_id) . unwrap ( ) . to_owned ( ) ) ;
200
202
}
@@ -246,17 +248,17 @@ impl Adapter for EthereumAdapter {
246
248
} ,
247
249
} ;
248
250
249
- self . tokens_verified
251
+ self . session_tokens
250
252
. borrow_mut ( )
251
253
. insert ( token_id, sess. clone ( ) ) ;
252
254
Ok ( sess)
253
255
}
254
256
255
257
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 ( ) ;
257
259
match (
258
260
self . wallet . borrow ( ) . clone ( ) ,
259
- tokens_for_auth . get ( & validator. id ) ,
261
+ authorization_tokens . get ( & validator. id ) ,
260
262
) {
261
263
( Some ( _) , Some ( token) ) => Ok ( token. to_owned ( ) ) ,
262
264
( Some ( wallet) , None ) => {
@@ -269,7 +271,7 @@ impl Adapter for EthereumAdapter {
269
271
let token = ewt_sign ( & wallet, & self . keystore_pwd , & payload)
270
272
. map_err ( |_| map_error ( "Failed to sign token" ) ) ?;
271
273
272
- self . tokens_for_auth
274
+ self . authorization_tokens
273
275
. borrow_mut ( )
274
276
. insert ( validator. id . clone ( ) , token. clone ( ) ) ;
275
277
0 commit comments