Skip to content

Commit

Permalink
refactor: Add prefix to determine account's ecosystem (#147)
Browse files Browse the repository at this point in the history
Determining which blockchain the address belongs to might be frustrating when dealing with multiple platforms. Defining a custom prefix for each blockchain might be a useful and easy to implement solution
  • Loading branch information
aminbenmansour authored May 8, 2023
2 parents 9ba197f + cd5a080 commit e70fd08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object AuthController {
}
}
ctx.json(UserInfo(userInfo.id).apply {
if (id.contains("##")){ id = userInfo.id.split("##")[1]}
token = JWTService.toJWT(userInfo)
})
}
Expand Down
21 changes: 14 additions & 7 deletions src/main/kotlin/id/walt/webwallet/backend/auth/UserInfo.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package id.walt.webwallet.backend.auth

import kotlinx.serialization.Serializable

@Serializable
class UserInfo(
val id: String
) {
class UserInfo(var id: String ) {
var email: String? = null
var password: String? = null
var token: String? = null
var ethAccount: String? = null
var did: String? = null
var tezosAccount: String? = null
var polkadotAccount: String? = null
var polkadotEvmAccount: String? = null
var flowAccount: String? = null

init {
when {
id.contains("@") -> email = id
id.lowercase().contains("0x") -> ethAccount = id
id.lowercase().startsWith("did:") -> did = id
id.startsWith("did") -> {
did = id
}
id.split("##")[0].lowercase().startsWith("eth") -> {ethAccount = id.split("##")[1] }
id.split("##")[0].lowercase().startsWith("pol") -> {polkadotAccount = id.split("##")[1]}
id.split("##")[0].lowercase().startsWith("polevm") -> {polkadotEvmAccount = id.split("##")[1]}
id.split("##")[0].lowercase().startsWith("flow") -> {flowAccount = id.split("##")[1]}
id.lowercase().startsWith("tz") -> tezosAccount = id

}

}
}
}

0 comments on commit e70fd08

Please sign in to comment.