@@ -18,7 +18,6 @@ import KeyStore from "./session/KeyStore";
1818class Web3Auth {
1919 initParams : SdkInitParams ;
2020 webBrowser : IWebBrowser ;
21- sessionResponse : EventEmitter ;
2221 keyStore : KeyStore ;
2322
2423 constructor ( webBrowser : IWebBrowser , storage : SecureStore | EncryptedStorage , initParams : SdkInitParams ) {
@@ -27,10 +26,11 @@ class Web3Auth {
2726 this . initParams . sdkUrl = "https://sdk.openlogin.com" ;
2827 }
2928 this . webBrowser = webBrowser ;
30- this . sessionResponse = new EventEmitter ( ) ;
3129 this . keyStore = new KeyStore ( storage ) ;
30+ }
3231
33- this . authorizeSession ( ) ;
32+ async init ( ) : Promise < State > {
33+ return this . authorizeSession ( ) ;
3434 }
3535
3636 async login ( options : SdkLoginParams ) : Promise < State > {
@@ -107,7 +107,7 @@ class Web3Auth {
107107 return this . webBrowser . openAuthSessionAsync ( url . href , redirectUrl ) ;
108108 }
109109
110- async authorizeSession ( ) {
110+ async authorizeSession ( ) : Promise < State > {
111111 const sessionId = await this . keyStore . get ( "sessionId" ) ;
112112 if ( sessionId && sessionId . length > 0 ) {
113113 var pubKey = getPublic ( Buffer . from ( sessionId , "hex" ) ) . toString ( "hex" ) ;
@@ -128,10 +128,10 @@ class Web3Auth {
128128 if ( ! web3AuthResponse . error ) {
129129 web3AuthResponse = web3AuthResponse as State ;
130130 if ( web3AuthResponse . privKey && web3AuthResponse . privKey . trim ( '0' ) . length > 0 ) {
131- this . sessionResponse . emit ( "login" , web3AuthResponse ) ;
131+ return Promise . resolve ( web3AuthResponse ) ;
132132 }
133133 } else {
134- throw new Error ( `session recovery failed with error ${ web3AuthResponse . error } ` ) ;
134+ return Promise . reject ( `session recovery failed with error ${ web3AuthResponse . error } ` ) ;
135135 }
136136 }
137137 }
@@ -166,7 +166,7 @@ class Web3Auth {
166166 this . keyStore . remove ( "ephemPublicKey" ) ;
167167 this . keyStore . remove ( "ivKey" ) ;
168168 this . keyStore . remove ( "mac" ) ;
169-
169+
170170 if ( this . initParams . loginConfig ) {
171171 var loginConfigItem = Object . values ( this . initParams . loginConfig ) [ 0 ] ;
172172 if ( loginConfigItem ) {
0 commit comments