Skip to content

Commit

Permalink
Merge pull request #17 from Web3Auth/feat/namespace_addition_in_API
Browse files Browse the repository at this point in the history
feat: add sessionNamespace param in constructor and namespace param added
  • Loading branch information
chaitanyapotti authored Dec 17, 2024
2 parents 0c485fc + 02dbd23 commit 3714be8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ class SessionManager(
context: Context,
sessionTime: Int = 86400,
allowedOrigin: String = "*",
sessionId: String? = null
sessionId: String? = null,
sessionNamespace: String? = null
) {

private val gson = GsonBuilder().disableHtmlEscaping().create()
private val web3AuthApi = ApiHelper.getInstance().create(Web3AuthApi::class.java)
private var sessionTime: Int
private var allowedOrigin: String
private var sessionNamespace: String = ""
private lateinit var sessionId: String

companion object {
Expand All @@ -59,11 +61,14 @@ 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.isNullOrEmpty()) {
this.sessionNamespace = sessionNamespace
}
}

fun setSessionId(sessionId: String) {
Expand Down Expand Up @@ -120,7 +125,7 @@ class SessionManager(
withContext(Dispatchers.IO) {
web3AuthApi.authorizeSession(
origin = origin,
AuthorizeSessionRequest(key = pubKey)
AuthorizeSessionRequest(key = pubKey, namespace = sessionNamespace)
)
}
}
Expand Down Expand Up @@ -313,7 +318,8 @@ class SessionManager(
BigInteger(newSessionKey, 16), gsonData
),
timeout = min(sessionTime, 7 * 86400),
allowedOrigin = allowedOrigin
allowedOrigin = allowedOrigin,
namespace = sessionNamespace
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import androidx.annotation.Keep

@Keep
data class AuthorizeSessionRequest(
val key: String
val key: String,
val namespace: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 3714be8

Please sign in to comment.