Skip to content

Commit

Permalink
feat: isSessionIdExists method removed
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Goel <[email protected]>
  • Loading branch information
grvgoel81 authored and Gaurav Goel committed Sep 24, 2024
1 parent 63fc54f commit 2766801
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 129 deletions.
22 changes: 8 additions & 14 deletions app/src/main/java/com/web3auth/sfaexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@ class MainActivity : AppCompatActivity() {
singleFactorAuth = SingleFactorAuth(sfaParams, this)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)

val res = singleFactorAuth.isSessionIdExists(this)
res.whenComplete { res, err ->
if (res) {
val sfakey = singleFactorAuth.initialize(this.applicationContext)
sfakey.whenComplete { response, error ->
if (error == null) {
val text =
"Public Address: ${response.getPublicAddress()} , Private Key: ${response.getPrivateKey()}"
tv.text = text
} else {
tv.text = error.message
}
}
val sfakey = singleFactorAuth.initialize(this.applicationContext)
sfakey.whenComplete { response, error ->
if (error == null) {
val text =
"Public Address: ${response.getPublicAddress()} , Private Key: ${response.getPrivateKey()}"
tv.text = text
} else {
tv.text = err.message
tv.text = error.message
}
}

}

private fun getSFAKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.web3auth.singlefactorauth.types.TorusSubVerifierInfo
import com.web3auth.singlefactorauth.utils.JwtUtils.generateIdToken
import com.web3auth.singlefactorauth.utils.PemUtils.readPrivateKeyFromReader
import com.web3auth.singlefactorauth.utils.WellKnownSecret
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.fail
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -100,39 +99,4 @@ class AquaTest {
fail()
}
}

@Test
@Throws(ExecutionException::class, InterruptedException::class)
fun testisSessionIdExistsWithLogoutApiCalled() {
val context = getInstrumentation().context
sfaParams = SFAParams(Web3AuthNetwork.AQUA, "YOUR_CLIENT_ID", 86400, null, 0)
singleFactorAuth = SingleFactorAuth(sfaParams, context)
val privateKey = readPrivateKeyFromReader(
WellKnownSecret.pem(),
"EC"
) as ECPrivateKey
val publicKey = KeyFactory.getInstance("EC").generatePublic(
ECPublicKeySpec(
privateKey.params.generator,
privateKey.params
)
) as ECPublicKey
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
singleFactorAuth.connect(loginParams, context)
val logoutCF = singleFactorAuth.logout(context).get()
if (logoutCF == true) {
val res = singleFactorAuth.isSessionIdExists(context)
res.whenComplete { res, err ->
if (err != null) {
fail()
} else {
assertEquals(res, false)
}
}
} else {
fail()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.web3auth.singlefactorauth.types.TorusSubVerifierInfo
import com.web3auth.singlefactorauth.utils.JwtUtils.generateIdToken
import com.web3auth.singlefactorauth.utils.PemUtils.readPrivateKeyFromReader
import com.web3auth.singlefactorauth.utils.WellKnownSecret
import junit.framework.TestCase
import junit.framework.TestCase.fail
import org.junit.Test
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork
Expand Down Expand Up @@ -105,69 +104,4 @@ class SapphireMainnetTest {
fail()
}
}

@Test
@Throws(ExecutionException::class, InterruptedException::class)
fun testisSessionIdExistsWithLogoutApiCalled() {
val context = InstrumentationRegistry.getInstrumentation().context
sfaParams = SFAParams(Web3AuthNetwork.SAPPHIRE_MAINNET, "YOUR_CLIENT_ID", 86400, null, 0)
singleFactorAuth = SingleFactorAuth(sfaParams, context)
val privateKey = readPrivateKeyFromReader(
WellKnownSecret.pem(),
"EC"
) as ECPrivateKey
val publicKey = KeyFactory.getInstance("EC").generatePublic(
ECPublicKeySpec(
privateKey.params.generator,
privateKey.params
)
) as ECPublicKey
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
singleFactorAuth.connect(loginParams, context)
val logoutCF = singleFactorAuth.logout(context).get()
if (logoutCF == true) {
val res = singleFactorAuth.isSessionIdExists(context)
res.whenComplete { res, err ->
if (err != null) {
fail()
} else {
TestCase.assertEquals(res, false)
}
}
} else {
fail()
}
}

@Test
@Throws(ExecutionException::class, InterruptedException::class)
fun testisSessionIdExistsWithLogoutApiNotCalled() {
val context = InstrumentationRegistry.getInstrumentation().context
sfaParams = SFAParams(Web3AuthNetwork.SAPPHIRE_MAINNET, "YOUR_CLIENT_ID", 86400, null, 0)
singleFactorAuth = SingleFactorAuth(sfaParams, context)
val privateKey = readPrivateKeyFromReader(
WellKnownSecret.pem(),
"EC"
) as ECPrivateKey
val publicKey = KeyFactory.getInstance("EC").generatePublic(
ECPublicKeySpec(
privateKey.params.generator,
privateKey.params
)
) as ECPublicKey
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
singleFactorAuth.connect(loginParams, context)
val res = singleFactorAuth.isSessionIdExists(context)
res.whenComplete { res, err ->
if (err != null) {
fail()
} else {
TestCase.assertEquals(res, true)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ class SingleFactorAuth(
return nodeDetails.torusNodeEndpoints
}

fun isSessionIdExists(ctx: Context): CompletableFuture<Boolean> {
val authorizeCF = CompletableFuture<Boolean>()
val data = sessionManager.authorizeSession(ctx.packageName, ctx)
data.whenComplete { res, error ->
if (res.startsWith("Error")) {
authorizeCF.complete(false)
} else {
authorizeCF.complete(true)
}
}
return authorizeCF
}

fun getTorusKey(
loginParams: LoginParams
): TorusKey? {
Expand Down

0 comments on commit 2766801

Please sign in to comment.