Skip to content

Commit

Permalink
feat: add sessionNamespace param in constructor and namespace param i…
Browse files Browse the repository at this point in the history
…n createSession and authorizeSession request params

Signed-off-by: Gaurav Goel <[email protected]>
  • Loading branch information
grvgoel81 authored and Gaurav Goel committed Dec 13, 2024
1 parent 0c485fc commit 438f833
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 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? = "*"
) {

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 {
Expand Down Expand Up @@ -64,6 +66,9 @@ class SessionManager(
}
this.sessionTime = sessionTime
this.allowedOrigin = allowedOrigin
if (sessionNamespace != null) {
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 438f833

Please sign in to comment.