Skip to content

Commit

Permalink
Merge pull request #14 from Web3Auth/feat/update-manifest.xml
Browse files Browse the repository at this point in the history
Sdk Updates after testing by devrel team.
  • Loading branch information
chaitanyapotti authored Dec 4, 2024
2 parents 180add8 + fb31653 commit e81c0e1
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 58 deletions.
13 changes: 5 additions & 8 deletions app/src/main/java/com/web3auth/sfaexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,25 @@ class MainActivity : AppCompatActivity() {
tv = findViewById(R.id.tv)

btnTorusKey.setOnClickListener {
getSFAKey()
getSessionData()
}
val idToken = JwtUtils.generateIdToken(TORUS_TEST_EMAIL)
val web3AuthOptions =
Web3AuthOptions("YOUR_CLIENT_ID", Web3AuthNetwork.SAPPHIRE_MAINNET, 86400)
singleFactorAuth = SingleFactorAuth(web3AuthOptions, this)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)

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

}

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
2 changes: 1 addition & 1 deletion singlefactorauth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'

implementation 'org.web3j:crypto:4.8.8-android'
implementation 'org.torusresearch:torus-utils-java:4.0.3'
api 'org.torusresearch:torus-utils-java:4.0.3'
api 'org.torusresearch:fetch-node-details-java:5.0.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'org.slf4j:slf4j-simple:2.0.3'
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SingleFactorAuth(
sessionManager = SessionManager(ctx, web3AuthOptions.getSessionTime(), ctx.packageName)
}

fun initialize(ctx: Context): CompletableFuture<SessionData?> {
fun initialize(ctx: Context): CompletableFuture<Nothing?> {
return CompletableFuture.supplyAsync {
val savedSessionId = SessionManager.getSessionIdFromStorage()
sessionManager.setSessionId(savedSessionId)
Expand Down Expand Up @@ -85,8 +85,8 @@ class SingleFactorAuth(
userInfo = finalUserInfo
)
state
}.thenApplyAsync({ sessionData ->
sessionData
}.thenApplyAsync({ _ ->
null
}, { Handler(Looper.getMainLooper()).post(it) }).exceptionally { ex ->
throw Exception("Initialization failed", ex)
}
Expand Down Expand Up @@ -214,12 +214,17 @@ class SingleFactorAuth(
}
}

fun logout(context: Context) {
sessionManager.invalidateSession(context).whenComplete { res, _ ->
fun logout(context: Context): CompletableFuture<Void> {
val logoutCF = CompletableFuture<Void>()
sessionManager.invalidateSession(context).whenComplete { res, err ->
if (res) {
SessionManager.deleteSessionIdFromStorage()
this.state = null
logoutCF.complete(null)
} else {
logoutCF.completeExceptionally(err)
}
}
return logoutCF
}
}

0 comments on commit e81c0e1

Please sign in to comment.