Skip to content

Commit

Permalink
feat: Rename function getKey to connect everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Goel <[email protected]>
  • Loading branch information
Gaurav Goel committed Sep 2, 2024
1 parent f8d8695 commit 38e3f45
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
12 changes: 6 additions & 6 deletions app/src/main/java/com/web3auth/sfaexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ class MainActivity : AppCompatActivity() {
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)

if (singleFactorAuth.isSessionIdExists()) {
val torusSFAKey = singleFactorAuth.initialize(this.applicationContext)
val text = "Private Key: ${torusSFAKey.getPrivateKey()}"
val sfakey = singleFactorAuth.initialize(this.applicationContext)
val text = "Private Key: ${sfakey.getPrivateKey()}"
tv.text = text
}
}

private fun getTorusKey() {
val idToken = JwtUtils.generateIdToken(TORUS_TEST_EMAIL)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val torusSFAKey =
singleFactorAuth.getKey(loginParams, this.applicationContext)
if (torusSFAKey != null) {
val text = "Private Key: ${torusSFAKey.getPrivateKey()}"
val sfakey =
singleFactorAuth.connect(loginParams, this.applicationContext)
if (sfakey != null) {
val text = "Private Key: ${sfakey.getPrivateKey()}"
tv.text = text
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import java.security.interfaces.ECPublicKey
import java.security.spec.ECPublicKeySpec
import java.util.concurrent.ExecutionException


@RunWith(AndroidJUnit4::class)
class AquaTest {

Expand Down Expand Up @@ -52,13 +51,13 @@ class AquaTest {
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val torusSFAKey = singleFactorAuth.getKey(loginParams,context)
val sfaKey = singleFactorAuth.connect(loginParams, context)
singleFactorAuth.initialize(context)
val requiredPrivateKey =
BigInteger("d8204e9f8c270647294c54acd8d49ee208789f981a7503158e122527d38626d8", 16)
if (torusSFAKey != null) {
assert(requiredPrivateKey.toString(16) == torusSFAKey.getPrivateKey())
assert("0x8b32926cD9224fec3B296aA7250B049029434807" == torusSFAKey.getPublicAddress())
if (sfaKey != null) {
assert(requiredPrivateKey.toString(16) == sfaKey.getPrivateKey())
assert("0x8b32926cD9224fec3B296aA7250B049029434807" == sfaKey.getPublicAddress())
} else {
fail()
}
Expand Down Expand Up @@ -89,13 +88,13 @@ class AquaTest {
)
)
)
val torusSFAKey = singleFactorAuth.getKey(loginParams,context)
val sfaKey = singleFactorAuth.connect(loginParams, context)
singleFactorAuth.initialize(context)
val requiredPrivateKey =
BigInteger("6f8b884f19975fb0d138ed21b22a6a7e1b79e37f611d0a29f1442b34efc6bacd", 16)
if (torusSFAKey != null) {
assert(requiredPrivateKey.toString(16) == torusSFAKey.getPrivateKey())
assert("0x62BaCa60f48C2b2b7e3074f7B7b4795EeF2afD2e" == torusSFAKey.getPublicAddress())
if (sfaKey != null) {
assert(requiredPrivateKey.toString(16) == sfaKey.getPrivateKey())
assert("0x62BaCa60f48C2b2b7e3074f7B7b4795EeF2afD2e" == sfaKey.getPublicAddress())
} else {
fail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class CyanTest {
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
if (TorusSFAKey != null) {
assert("0x6b902fBCEb0E0374e5eB9eDFe68cD4B888c32150" == TorusSFAKey.getPublicAddress())
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x6b902fBCEb0E0374e5eB9eDFe68cD4B888c32150" == sfakey.getPublicAddress())
val requiredPrivateKey =
BigInteger("223d982054fa1ad27d1497560521e4cce5b8c6438c38533c7bad27ff21ce0546", 16)
assert(requiredPrivateKey.toString(16) == TorusSFAKey.getPrivateKey())
assert(requiredPrivateKey.toString(16) == sfakey.getPrivateKey())
} else {
fail()
}
Expand Down Expand Up @@ -83,12 +83,12 @@ class CyanTest {
)
)
)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
if (TorusSFAKey != null) {
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
val requiredPrivateKey =
BigInteger("66af498ea82c95d52fdb8c8dedd44cf2f758424a0eecab7ac3dd8721527ea2d4", 16)
assert(requiredPrivateKey.toString(16) == TorusSFAKey.getPrivateKey())
assert("0xFF4c4A0Aa5D633302B5711C3047D7D5967884521" == TorusSFAKey.getPublicAddress())
assert(requiredPrivateKey.toString(16) == sfakey.getPrivateKey())
assert("0xFF4c4A0Aa5D633302B5711C3047D7D5967884521" == sfakey.getPublicAddress())
} else {
fail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class SapphireDevnetTest {
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
if (TorusSFAKey != null) {
assert("0x462A8BF111A55C9354425F875F89B22678c0Bc44" == TorusSFAKey.getPublicAddress())
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x462A8BF111A55C9354425F875F89B22678c0Bc44" == sfakey.getPublicAddress())
val requiredPrivateKey =
BigInteger("230dad9f42039569e891e6b066ff5258b14e9764ef5176d74aeb594d1a744203", 16)
assert(requiredPrivateKey.toString(16) == TorusSFAKey.getPrivateKey())
assert(requiredPrivateKey.toString(16) == sfakey.getPrivateKey())
} else {
fail()
}
Expand Down Expand Up @@ -89,12 +89,12 @@ class SapphireDevnetTest {
)
)
)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
val sfakey = singleFactorAuth.connect(loginParams, context)
val requiredPrivateKey =
BigInteger("edef171853fdf23ed3cfc702d32cf46f181b475a449d2f7b636924cabecd81d4", 16)
if (TorusSFAKey != null) {
assert(requiredPrivateKey.toString(16) == TorusSFAKey.getPrivateKey())
assert("0xfC58EB0475F1E3fa05877eE2e1350f6A619E2d78" == TorusSFAKey.getPublicAddress())
if (sfakey != null) {
assert(requiredPrivateKey.toString(16) == sfakey.getPrivateKey())
assert("0xfC58EB0475F1E3fa05877eE2e1350f6A619E2d78" == sfakey.getPublicAddress())
} else {
fail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class SapphireMainnetTest {
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER,TORUS_TEST_EMAIL, idToken)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
if (TorusSFAKey != null) {
assert("0x0934d844a0a6db37CF75aF0269436ae1b2Ae5D36" == TorusSFAKey.getPublicAddress())
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x0934d844a0a6db37CF75aF0269436ae1b2Ae5D36" == sfakey.getPublicAddress())
val requiredPrivateKey =
BigInteger("2c4b346a91ecd11fe8a02d111d00bd921bf9b543f0a1e811face91b5f28947d6", 16)
assert(requiredPrivateKey.toString(16) == TorusSFAKey.getPrivateKey())
assert(requiredPrivateKey.toString(16) == sfakey.getPrivateKey())
} else {
fail()
}
Expand Down Expand Up @@ -90,15 +90,15 @@ class SapphireMainnetTest {
)
)
)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
val sfakey = singleFactorAuth.connect(loginParams, context)
val requiredPrivateKey =
BigInteger("0c724bb285560dc41e585b91aa2ded94fdd703c2e7133dcc64b1361b0d1fd105", 16)

if (TorusSFAKey != null) {
assert(requiredPrivateKey.toString(16).padStart(64,'0') == TorusSFAKey.getPrivateKey())
if (sfakey != null) {
assert(requiredPrivateKey.toString(16).padStart(64, '0') == sfakey.getPrivateKey())
assert(
"0xA92E2C756B5b2abABc127907b02D4707dc085612" ==
TorusSFAKey.getPublicAddress()
sfakey.getPublicAddress()
)
} else {
fail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class SingleFactorAuthTest {
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
if (TorusSFAKey != null) {
assert("0x90A926b698047b4A87265ba1E9D8b512E8489067" == TorusSFAKey.getPublicAddress())
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x90A926b698047b4A87265ba1E9D8b512E8489067" == sfakey.getPublicAddress())
val requiredPrivateKey =
BigInteger("0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44", 16).toString(16).padStart(64,'0')
assert(requiredPrivateKey == TorusSFAKey.getPrivateKey())
assert(requiredPrivateKey == sfakey.getPrivateKey())
} else {
fail()
}
Expand Down Expand Up @@ -83,12 +83,12 @@ class SingleFactorAuthTest {
)
)
)
val TorusSFAKey = singleFactorAuth.getKey(loginParams,context)
val sfakey = singleFactorAuth.connect(loginParams, context)
val requiredPrivateKey =
BigInteger("68390578bbdab74e9883de58d3919c176662852bdd42a783bc3a08f1a1024e0c", 16)
if (TorusSFAKey != null) {
assert(requiredPrivateKey.toString(16) == TorusSFAKey.getPrivateKey())
assert("0x86129bC541b03B6B42A76E9e002eE88F81E0aadD" == TorusSFAKey.getPublicAddress())
if (sfakey != null) {
assert(requiredPrivateKey.toString(16) == sfakey.getPrivateKey())
assert("0x86129bC541b03B6B42A76E9e002eE88F81E0aadD" == sfakey.getPublicAddress())
} else {
fail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SingleFactorAuth(sfaParams: SFAParams, ctx: Context) {
}
}

fun getKey(
fun connect(
loginParams: LoginParams,
ctx: Context
): TorusSFAKey? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class SFAParams(
this.networkUrl = networkUrl
this.serverTimeOffset = serverTimeOffset
}
fun getClientId(): String? {

fun getClientId(): String {
return clientid
}
fun getNetwork(): Web3AuthNetwork {
Expand Down

0 comments on commit 38e3f45

Please sign in to comment.