Skip to content

Commit fb2a4fa

Browse files
Merge pull request #50 from Web3Auth/feature/PD-2003-add-corekit-flag
Adding coreKitKey and coreKitEd25519PrivKey in Web3AuthResponse.kt
2 parents d5750de + b72801e commit fb2a4fa

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

app/src/main/java/com/web3auth/app/MainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
5555
loginCompletableFuture.whenComplete { loginResponse, error ->
5656
if (error == null) {
5757
reRender(loginResponse)
58+
println("PrivKey: " + web3Auth.getPrivkey())
59+
println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
5860
} else {
5961
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
6062
}
@@ -133,6 +135,8 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
133135
sessionResponse.whenComplete { loginResponse, error ->
134136
if (error == null) {
135137
reRender(loginResponse)
138+
println("PrivKey: " + web3Auth.getPrivkey())
139+
println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
136140
} else {
137141
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
138142
}

core/src/main/java/com/web3auth/core/Web3Auth.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,21 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
3333
TESTNET,
3434

3535
@SerializedName("cyan")
36-
CYAN
36+
CYAN,
37+
38+
@SerializedName("aqua")
39+
AQUA,
40+
41+
@SerializedName("celeste")
42+
CELESTE
43+
}
44+
45+
enum class ChainNamespace {
46+
@SerializedName("eip155")
47+
EIP155,
48+
49+
@SerializedName("solana")
50+
SOLANA
3751
}
3852

3953
private val gson = GsonBuilder().disableHtmlEscaping().create()
@@ -136,6 +150,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
136150
decodeBase64URLString(hash).toString(Charsets.UTF_8),
137151
Web3AuthResponse::class.java
138152
)
153+
139154
if (web3AuthResponse.error?.isNotBlank() == true) {
140155
loginCompletableFuture.completeExceptionally(
141156
UnKnownException(
@@ -318,6 +333,24 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
318333
}
319334
}
320335

336+
fun getPrivkey(): String {
337+
val privKey: String = if (web3AuthOption.useCoreKitKey == true) {
338+
web3AuthResponse.coreKitKey.toString()
339+
} else {
340+
web3AuthResponse.privKey.toString()
341+
}
342+
return privKey
343+
}
344+
345+
fun getEd25519PrivKey(): String {
346+
val ed25519Key: String = if (web3AuthOption.useCoreKitKey == true) {
347+
web3AuthResponse.coreKitEd25519PrivKey.toString()
348+
} else {
349+
web3AuthResponse.ed25519PrivKey.toString()
350+
}
351+
return ed25519Key
352+
}
353+
321354
fun logout(
322355
redirectUrl: Uri? = null,
323356
appState: String? = null

core/src/main/java/com/web3auth/core/keystore/KeyStoreManagerUtils.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ object KeyStoreManagerUtils {
3636
private lateinit var sharedPreferences: EncryptedSharedPreferences
3737

3838
fun initializePreferences(context: Context) {
39-
sharedPreferences = EncryptedSharedPreferences.create(
40-
"Web3Auth",
41-
masterKeyAlias,
42-
context,
43-
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
44-
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
45-
) as EncryptedSharedPreferences
39+
try {
40+
sharedPreferences = EncryptedSharedPreferences.create(
41+
"Web3Auth",
42+
masterKeyAlias,
43+
context,
44+
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
45+
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
46+
) as EncryptedSharedPreferences
47+
} catch (ex: Exception) {
48+
ex.printStackTrace()
49+
}
4650
}
4751

4852
/**

core/src/main/java/com/web3auth/core/types/Web3AuthOptions.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ import android.content.Context
44
import android.net.Uri
55
import com.web3auth.core.Web3Auth
66

7-
data class Web3AuthOptions (
7+
data class Web3AuthOptions(
88
var context: Context,
99
val clientId: String,
1010
val network: Web3Auth.Network,
1111
@Transient var redirectUrl: Uri? = null,
12-
var sdkUrl: String = "https://sdk.openlogin.com",
12+
var sdkUrl: String = getSdkUrl(network),
1313
val whiteLabel: WhiteLabelData? = null,
1414
val loginConfig: HashMap<String, LoginConfigItem>? = null,
15-
)
15+
val useCoreKitKey: Boolean? = false,
16+
val chainNamespace: Web3Auth.ChainNamespace? = Web3Auth.ChainNamespace.EIP155
17+
)
18+
19+
fun getSdkUrl(network: Web3Auth.Network): String {
20+
var sdkUrl = ""
21+
sdkUrl = if (network == Web3Auth.Network.TESTNET) {
22+
"https://dev-sdk.openlogin.com"
23+
} else {
24+
"https://sdk.openlogin.com"
25+
}
26+
return sdkUrl
27+
}

core/src/main/java/com/web3auth/core/types/Web3AuthResponse.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import androidx.annotation.Keep
44

55
@Keep
66
data class Web3AuthResponse(
7-
val privKey: String? = null,
8-
val ed25519PrivKey: String? = null,
7+
var privKey: String? = null,
8+
var ed25519PrivKey: String? = null,
99
val userInfo: UserInfo? = null,
1010
val error: String? = null,
11-
val sessionId: String? = null
11+
val sessionId: String? = null,
12+
val coreKitKey: String? = null,
13+
val coreKitEd25519PrivKey: String? = null
1214
)

0 commit comments

Comments
 (0)