From 438f833b06886f874c1da7cf9d86ec9b1d92fc8a Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Fri, 13 Dec 2024 14:27:37 +0530 Subject: [PATCH 1/3] feat: add sessionNamespace param in constructor and namespace param in createSession and authorizeSession request params Signed-off-by: Gaurav Goel --- .../session_manager_android/SessionManagerTest.kt | 2 +- .../session_manager_android/SessionManager.kt | 12 +++++++++--- .../models/AuthorizeSessionRequest.kt | 3 ++- .../models/SessionRequestBody.kt | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt index 0586f1e..00f9368 100644 --- a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt +++ b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt @@ -41,7 +41,7 @@ class SessionManagerTest { fun test_authorizeSession() { val context = InstrumentationRegistry.getInstrumentation().context val sessionId = SessionManager.generateRandomSessionKey() - sessionManager = SessionManager(context, 86400, context.packageName, sessionId) + sessionManager = SessionManager(context, 86400, context.packageName, sessionId, "sfa") val json = JSONObject() json.put( "privateKey", diff --git a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt index 4be27c7..6c43a33 100644 --- a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt +++ b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt @@ -27,13 +27,15 @@ class SessionManager( context: Context, sessionTime: Int = 86400, allowedOrigin: String = "*", - sessionId: String? = null + sessionId: String? = null, + sessionNamespace: String? = "*" ) { private val gson = GsonBuilder().disableHtmlEscaping().create() private val web3AuthApi = ApiHelper.getInstance().create(Web3AuthApi::class.java) private var sessionTime: Int private var allowedOrigin: String + private lateinit var sessionNamespace: String private lateinit var sessionId: String companion object { @@ -64,6 +66,9 @@ class SessionManager( } this.sessionTime = sessionTime this.allowedOrigin = allowedOrigin + if (sessionNamespace != null) { + this.sessionNamespace = sessionNamespace + } } fun setSessionId(sessionId: String) { @@ -120,7 +125,7 @@ class SessionManager( withContext(Dispatchers.IO) { web3AuthApi.authorizeSession( origin = origin, - AuthorizeSessionRequest(key = pubKey) + AuthorizeSessionRequest(key = pubKey, namespace = sessionNamespace) ) } } @@ -313,7 +318,8 @@ class SessionManager( BigInteger(newSessionKey, 16), gsonData ), timeout = min(sessionTime, 7 * 86400), - allowedOrigin = allowedOrigin + allowedOrigin = allowedOrigin, + namespace = sessionNamespace ) ) } diff --git a/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/AuthorizeSessionRequest.kt b/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/AuthorizeSessionRequest.kt index 73587b2..641503f 100644 --- a/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/AuthorizeSessionRequest.kt +++ b/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/AuthorizeSessionRequest.kt @@ -4,5 +4,6 @@ import androidx.annotation.Keep @Keep data class AuthorizeSessionRequest( - val key: String + val key: String, + val namespace: String ) \ No newline at end of file diff --git a/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/SessionRequestBody.kt b/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/SessionRequestBody.kt index 8e26842..e0c8241 100644 --- a/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/SessionRequestBody.kt +++ b/session-manager-android/src/main/java/com/web3auth/session_manager_android/models/SessionRequestBody.kt @@ -8,5 +8,6 @@ data class SessionRequestBody( val data: String, val signature: String, val timeout: Int = 0, - val allowedOrigin: String? = null + val allowedOrigin: String? = null, + val namespace: String? = null ) \ No newline at end of file From c0f6367089df765ce9b55753d255097cb675e516 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Mon, 16 Dec 2024 09:44:13 +0530 Subject: [PATCH 2/3] feat: PR comments addressed Signed-off-by: Gaurav Goel --- .../web3auth/session_manager_android/SessionManagerTest.kt | 4 ++-- .../com/web3auth/session_manager_android/SessionManager.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt index 00f9368..52dcff8 100644 --- a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt +++ b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt @@ -22,7 +22,7 @@ class SessionManagerTest { fun test_createSession() { val context = InstrumentationRegistry.getInstrumentation().context val sessionId = SessionManager.generateRandomSessionKey() - sessionManager = SessionManager(context, 86400, context.packageName, sessionId) + sessionManager = SessionManager(context, 86400, context.packageName, sessionId, "*") val json = JSONObject() json.put( "privateKey", @@ -68,7 +68,7 @@ class SessionManagerTest { fun test_invalidateSession() { val context = InstrumentationRegistry.getInstrumentation().context val sessionId = SessionManager.generateRandomSessionKey() - sessionManager = SessionManager(context, 86400, context.packageName, sessionId) + sessionManager = SessionManager(context, 86400, context.packageName, sessionId, "sfa") val json = JSONObject() json.put( "privateKey", diff --git a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt index 6c43a33..4657ba0 100644 --- a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt +++ b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt @@ -28,7 +28,7 @@ class SessionManager( sessionTime: Int = 86400, allowedOrigin: String = "*", sessionId: String? = null, - sessionNamespace: String? = "*" + sessionNamespace: String? = null ) { private val gson = GsonBuilder().disableHtmlEscaping().create() From 02dbd2336421b01e54044bebf9c5420f2273ab49 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Tue, 17 Dec 2024 09:26:14 +0530 Subject: [PATCH 3/3] feat: PR comments addressed Signed-off-by: Gaurav Goel --- .../web3auth/session_manager_android/SessionManagerTest.kt | 4 ++-- .../com/web3auth/session_manager_android/SessionManager.kt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt index 52dcff8..00f9368 100644 --- a/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt +++ b/session-manager-android/src/androidTest/java/com/web3auth/session_manager_android/SessionManagerTest.kt @@ -22,7 +22,7 @@ class SessionManagerTest { fun test_createSession() { val context = InstrumentationRegistry.getInstrumentation().context val sessionId = SessionManager.generateRandomSessionKey() - sessionManager = SessionManager(context, 86400, context.packageName, sessionId, "*") + sessionManager = SessionManager(context, 86400, context.packageName, sessionId) val json = JSONObject() json.put( "privateKey", @@ -68,7 +68,7 @@ class SessionManagerTest { fun test_invalidateSession() { val context = InstrumentationRegistry.getInstrumentation().context val sessionId = SessionManager.generateRandomSessionKey() - sessionManager = SessionManager(context, 86400, context.packageName, sessionId, "sfa") + sessionManager = SessionManager(context, 86400, context.packageName, sessionId) val json = JSONObject() json.put( "privateKey", diff --git a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt index 4657ba0..a033623 100644 --- a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt +++ b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt @@ -35,7 +35,7 @@ class SessionManager( private val web3AuthApi = ApiHelper.getInstance().create(Web3AuthApi::class.java) private var sessionTime: Int private var allowedOrigin: String - private lateinit var sessionNamespace: String + private var sessionNamespace: String = "" private lateinit var sessionId: String companion object { @@ -61,12 +61,12 @@ class SessionManager( init { KeyStoreManager.initializePreferences(context.applicationContext) initiateKeyStoreManager() - if (sessionId != null && sessionId.isNotEmpty()) { + if (!sessionId.isNullOrEmpty()) { this.sessionId = sessionId } this.sessionTime = sessionTime this.allowedOrigin = allowedOrigin - if (sessionNamespace != null) { + if (!sessionNamespace.isNullOrEmpty()) { this.sessionNamespace = sessionNamespace } }