@@ -48,6 +48,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
4848
4949 private lateinit var loginCompletableFuture: CompletableFuture <Web3AuthResponse >
5050 private lateinit var enableMfaCompletableFuture: CompletableFuture <Boolean >
51+ private lateinit var manageMfaCompletableFuture: CompletableFuture <Boolean >
5152 private lateinit var signMsgCF: CompletableFuture <SignResponse >
5253
5354 private var web3AuthResponse: Web3AuthResponse ? = null
@@ -117,7 +118,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
117118 )
118119 paramMap.put(" actionType" , actionType)
119120
120- if (actionType == " enable_mfa" ) {
121+ if (actionType == " enable_mfa" || actionType == " manage_mfa " ) {
121122 val userInfo = web3AuthResponse?.userInfo
122123 initParams.put(" loginProvider" , userInfo?.typeOfLogin)
123124 var extraOptionsString = " "
@@ -205,17 +206,25 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
205206 val hashUri = Uri .parse(uri?.host + " ?" + uri?.fragment)
206207 val error = uri?.getQueryParameter(" error" )
207208 if (error != null ) {
208- loginCompletableFuture.completeExceptionally(UnKnownException (error))
209+ if (::loginCompletableFuture.isInitialized) loginCompletableFuture.completeExceptionally(
210+ UnKnownException (error)
211+ )
212+
209213 if (::enableMfaCompletableFuture.isInitialized) enableMfaCompletableFuture.completeExceptionally(
210214 UnKnownException (error)
211215 )
216+
217+ if (::manageMfaCompletableFuture.isInitialized) manageMfaCompletableFuture.completeExceptionally(
218+ UnKnownException (error)
219+ )
212220 return
213221 }
214222
215223 val b64Params = hashUri.getQueryParameter(" b64Params" )
216224 if (b64Params.isNullOrBlank()) {
217225 throwLoginError(ErrorCode .INVALID_LOGIN )
218226 throwEnableMFAError(ErrorCode .INVALID_LOGIN )
227+ throwManageMFAError(ErrorCode .INVALID_LOGIN )
219228 return
220229 }
221230 val b64ParamString = decodeBase64URLString(b64Params).toString(Charsets .UTF_8 )
@@ -235,9 +244,11 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
235244 if (web3AuthResponse?.error?.isNotBlank() == true ) {
236245 throwLoginError(ErrorCode .SOMETHING_WENT_WRONG )
237246 throwEnableMFAError(ErrorCode .SOMETHING_WENT_WRONG )
247+ throwManageMFAError(ErrorCode .SOMETHING_WENT_WRONG )
238248 } else if (web3AuthResponse?.privKey.isNullOrBlank() && web3AuthResponse?.factorKey.isNullOrBlank()) {
239249 throwLoginError(ErrorCode .SOMETHING_WENT_WRONG )
240250 throwEnableMFAError(ErrorCode .SOMETHING_WENT_WRONG )
251+ throwManageMFAError(ErrorCode .SOMETHING_WENT_WRONG )
241252 } else {
242253 web3AuthResponse?.sessionId?.let {
243254 SessionManager .saveSessionIdToStorage(it)
@@ -251,9 +262,14 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
251262 web3AuthResponse?.userInfo?.dappShare!! ,
252263 )
253264 }
254- loginCompletableFuture.complete(web3AuthResponse)
265+ if (::loginCompletableFuture.isInitialized)
266+ loginCompletableFuture.complete(web3AuthResponse)
267+
255268 if (::enableMfaCompletableFuture.isInitialized)
256269 enableMfaCompletableFuture.complete(true )
270+
271+ if (::manageMfaCompletableFuture.isInitialized)
272+ manageMfaCompletableFuture.complete(true )
257273 }
258274 } else {
259275 print (error)
@@ -263,6 +279,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
263279 } else {
264280 throwLoginError(ErrorCode .SOMETHING_WENT_WRONG )
265281 throwEnableMFAError(ErrorCode .SOMETHING_WENT_WRONG )
282+ throwManageMFAError(ErrorCode .SOMETHING_WENT_WRONG )
266283 }
267284 }
268285
@@ -334,6 +351,22 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
334351 return enableMfaCompletableFuture
335352 }
336353
354+
355+ fun manageMFA (loginParams : LoginParams ? = null): CompletableFuture <Boolean > {
356+ manageMfaCompletableFuture = CompletableFuture ()
357+ if (web3AuthResponse?.userInfo?.isMfaEnabled == false ) {
358+ throwManageMFAError(ErrorCode .MFA_NOT_ENABLED )
359+ return manageMfaCompletableFuture
360+ }
361+ val sessionId = sessionManager.getSessionId()
362+ if (sessionId.isBlank()) {
363+ throwManageMFAError(ErrorCode .NOUSERFOUND )
364+ return manageMfaCompletableFuture
365+ }
366+ processRequest(" manage_mfa" , loginParams)
367+ return manageMfaCompletableFuture
368+ }
369+
337370 /* *
338371 * Authorize User session in order to avoid re-login
339372 */
@@ -590,6 +623,17 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
590623 )
591624 }
592625
626+ private fun throwManageMFAError (error : ErrorCode ) {
627+ if (::manageMfaCompletableFuture.isInitialized)
628+ manageMfaCompletableFuture.completeExceptionally(
629+ Exception (
630+ Web3AuthError .getError(
631+ error
632+ )
633+ )
634+ )
635+ }
636+
593637 private fun throwLoginError (error : ErrorCode ) {
594638 if (::loginCompletableFuture.isInitialized) {
595639 loginCompletableFuture.completeExceptionally(
0 commit comments