Skip to content

Commit

Permalink
feat: Update all unit-tests and example.
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 Nov 13, 2024
1 parent 3fd8be3 commit fb31653
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 46 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/web3auth/sfaexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MainActivity : AppCompatActivity() {
tv = findViewById(R.id.tv)

btnTorusKey.setOnClickListener {
getSFAKey()
getSessionData()
}
val idToken = JwtUtils.generateIdToken(TORUS_TEST_EMAIL)
val web3AuthOptions =
Expand All @@ -44,7 +44,7 @@ class MainActivity : AppCompatActivity() {

}

private fun getSFAKey() {
private fun getSessionData() {
val idToken = JwtUtils.generateIdToken(TORUS_TEST_EMAIL)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val sfakey =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,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 sfaKey = singleFactorAuth.connect(loginParams, context)
val sessionData = singleFactorAuth.connect(loginParams, context)
singleFactorAuth.initialize(context)
val requiredPrivateKey =
BigInteger("d8204e9f8c270647294c54acd8d49ee208789f981a7503158e122527d38626d8", 16)
if (sfaKey != null) {
assert(requiredPrivateKey.toString(16) == sfaKey.privateKey)
assert("0x8b32926cD9224fec3B296aA7250B049029434807" == sfaKey.publicAddress)
if (sessionData != null) {
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
assert("0x8b32926cD9224fec3B296aA7250B049029434807" == sessionData.publicAddress)
} else {
fail()
}
Expand Down Expand Up @@ -88,13 +88,13 @@ class AquaTest {
)
)
)
val sfaKey = singleFactorAuth.connect(loginParams, context)
val sessionData = singleFactorAuth.connect(loginParams, context)
singleFactorAuth.initialize(context)
val requiredPrivateKey =
BigInteger("6f8b884f19975fb0d138ed21b22a6a7e1b79e37f611d0a29f1442b34efc6bacd", 16)
if (sfaKey != null) {
assert(requiredPrivateKey.toString(16) == sfaKey.privateKey)
assert("0x62BaCa60f48C2b2b7e3074f7B7b4795EeF2afD2e" == sfaKey.publicAddress)
if (sessionData != null) {
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
assert("0x62BaCa60f48C2b2b7e3074f7B7b4795EeF2afD2e" == sessionData.publicAddress)
} 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 sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x6b902fBCEb0E0374e5eB9eDFe68cD4B888c32150" == sfakey.publicAddress)
val sessionData = singleFactorAuth.connect(loginParams, context)
if (sessionData != null) {
assert("0x6b902fBCEb0E0374e5eB9eDFe68cD4B888c32150" == sessionData.publicAddress)
val requiredPrivateKey =
BigInteger("223d982054fa1ad27d1497560521e4cce5b8c6438c38533c7bad27ff21ce0546", 16)
assert(requiredPrivateKey.toString(16) == sfakey.privateKey)
BigInteger("223d982054fa1ad27d1497560521e4cce5b8c6438c38533c7bad27ff21ce0546", 16)
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
} else {
fail()
}
Expand Down Expand Up @@ -83,12 +83,12 @@ class CyanTest {
)
)
)
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
val sessionData = singleFactorAuth.connect(loginParams, context)
if (sessionData != null) {
val requiredPrivateKey =
BigInteger("66af498ea82c95d52fdb8c8dedd44cf2f758424a0eecab7ac3dd8721527ea2d4", 16)
assert(requiredPrivateKey.toString(16) == sfakey.privateKey)
assert("0xFF4c4A0Aa5D633302B5711C3047D7D5967884521" == sfakey.publicAddress)
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
assert("0xFF4c4A0Aa5D633302B5711C3047D7D5967884521" == sessionData.publicAddress)
} else {
fail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,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 sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x462A8BF111A55C9354425F875F89B22678c0Bc44" == sfakey.publicAddress)
val sessionData = singleFactorAuth.connect(loginParams, context)
if (sessionData != null) {
assert("0x462A8BF111A55C9354425F875F89B22678c0Bc44" == sessionData.publicAddress)
val requiredPrivateKey =
BigInteger("230dad9f42039569e891e6b066ff5258b14e9764ef5176d74aeb594d1a744203", 16)
assert(requiredPrivateKey.toString(16) == sfakey.privateKey)
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
} else {
fail()
}
Expand Down Expand Up @@ -85,12 +85,12 @@ class SapphireDevnetTest {
)
)
)
val sfakey = singleFactorAuth.connect(loginParams, context)
val sessionData = singleFactorAuth.connect(loginParams, context)
val requiredPrivateKey =
BigInteger("edef171853fdf23ed3cfc702d32cf46f181b475a449d2f7b636924cabecd81d4", 16)
if (sfakey != null) {
assert(requiredPrivateKey.toString(16) == sfakey.privateKey)
assert("0xfC58EB0475F1E3fa05877eE2e1350f6A619E2d78" == sfakey.publicAddress)
if (sessionData != null) {
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
assert("0xfC58EB0475F1E3fa05877eE2e1350f6A619E2d78" == sessionData.publicAddress)
} else {
fail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class SapphireMainnetTest {
) as ECPublicKey
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER,TORUS_TEST_EMAIL, idToken)
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x0934d844a0a6db37CF75aF0269436ae1b2Ae5D36" == sfakey.publicAddress)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val sessionData = singleFactorAuth.connect(loginParams, context)
if (sessionData != null) {
assert("0x0934d844a0a6db37CF75aF0269436ae1b2Ae5D36" == sessionData.publicAddress)
val requiredPrivateKey =
BigInteger("2c4b346a91ecd11fe8a02d111d00bd921bf9b543f0a1e811face91b5f28947d6", 16)
assert(requiredPrivateKey.toString(16) == sfakey.privateKey)
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
} else {
fail()
}
Expand Down Expand Up @@ -89,15 +89,15 @@ class SapphireMainnetTest {
)
)
)
val sfakey = singleFactorAuth.connect(loginParams, context)
val sessionData = singleFactorAuth.connect(loginParams, context)
val requiredPrivateKey =
BigInteger("0c724bb285560dc41e585b91aa2ded94fdd703c2e7133dcc64b1361b0d1fd105", 16)

if (sfakey != null) {
assert(requiredPrivateKey.toString(16).padStart(64, '0') == sfakey.privateKey)
if (sessionData != null) {
assert(requiredPrivateKey.toString(16).padStart(64, '0') == sessionData.privateKey)
assert(
"0xA92E2C756B5b2abABc127907b02D4707dc085612" ==
sfakey.publicAddress
sessionData.publicAddress
)
} else {
fail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ class SingleFactorAuthTest {
algorithmRs = Algorithm.ECDSA256(publicKey, privateKey)
val idToken: String = generateIdToken(TORUS_TEST_EMAIL, algorithmRs)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)
val sfakey = singleFactorAuth.connect(loginParams, context)
if (sfakey != null) {
assert("0x90A926b698047b4A87265ba1E9D8b512E8489067" == sfakey.publicAddress)
val sessionData = singleFactorAuth.connect(loginParams, context)
if (sessionData != null) {
assert("0x90A926b698047b4A87265ba1E9D8b512E8489067" == sessionData.publicAddress)
val requiredPrivateKey =
BigInteger("0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44", 16).toString(16).padStart(64,'0')
assert(requiredPrivateKey == sfakey.privateKey)
BigInteger(
"0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44",
16
).toString(16).padStart(64, '0')
assert(requiredPrivateKey == sessionData.privateKey)
} else {
fail()
}
Expand Down Expand Up @@ -85,13 +88,13 @@ class SingleFactorAuthTest {
)
)
)
val sfakey = singleFactorAuth.connect(loginParams, context)
val sessionData = singleFactorAuth.connect(loginParams, context)
val requiredPrivateKey =
BigInteger("68390578bbdab74e9883de58d3919c176662852bdd42a783bc3a08f1a1024e0c", 16)
if (sfakey != null) {
assert(requiredPrivateKey.toString(16) == sfakey.privateKey)
assert("0x86129bC541b03B6B42A76E9e002eE88F81E0aadD" == sfakey.publicAddress)
} else {
if (sessionData != null) {
assert(requiredPrivateKey.toString(16) == sessionData.privateKey)
assert("0x86129bC541b03B6B42A76E9e002eE88F81E0aadD" == sessionData.publicAddress)
} else {
fail()
}
}
Expand Down

0 comments on commit fb31653

Please sign in to comment.