-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented basic functions * implemented and tested the deployAccount function * implemented and tested the deployAccount function * implemented and tested the balance function * implemented and tested the TransferFunds function * removed unused imports * updated return parameters and other fixes
- Loading branch information
Showing
8 changed files
with
414 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
wallet-sdk/app/src/main/java/com/snphone/snwalletsdk/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.snphone.snwalletsdk | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.lifecycleScope | ||
import com.snphone.snwalletsdk.utils.StarknetClient | ||
import com.swmansion.starknet.account.StandardAccount | ||
import com.swmansion.starknet.data.types.Felt | ||
import com.swmansion.starknet.data.types.StarknetChainId | ||
import com.swmansion.starknet.extensions.toFelt | ||
import com.swmansion.starknet.provider.rpc.JsonRpcProvider | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
init { | ||
instance = this | ||
} | ||
|
||
companion object { | ||
private var instance: MainActivity? = null | ||
|
||
fun applicationContext() : Context { | ||
return instance!!.applicationContext | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enableEdgeToEdge() | ||
instance = this | ||
setContentView(R.layout.activity_main) | ||
|
||
val starknetClient = StarknetClient(BuildConfig.RPC_URL) | ||
lifecycleScope.launch(Dispatchers.IO) { | ||
|
||
//Deploy account | ||
//val (privateKey, accountAddress) = deployAccount() | ||
|
||
//GetBalance | ||
//val balance = getBalance(accountAddress) | ||
val addressUser = BuildConfig.publicAddress.toFelt | ||
val privateKey = BuildConfig.privateKey.toFelt | ||
|
||
val account = StandardAccount( | ||
address = addressUser, | ||
privateKey = privateKey, | ||
provider = JsonRpcProvider(BuildConfig.RPC_URL), | ||
chainId = StarknetChainId.SEPOLIA, | ||
) | ||
val recipientAddress = Felt.fromHex(BuildConfig.recepientAddress) | ||
try { | ||
val amount = StarknetClient.toUint256Amount(1.toString()) | ||
val address = starknetClient.transferFunds(account,recipientAddress,amount) | ||
Log.d("MainActivity", "transaction id: $address") | ||
|
||
}catch (e: Exception){ | ||
Log.d("MainActivity", "Error in amount: $e") | ||
|
||
} | ||
} | ||
} | ||
} |
30 changes: 29 additions & 1 deletion
30
wallet-sdk/app/src/main/java/com/snphone/snwalletsdk/SNWalletSDK.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
package com.snphone.snwalletsdk | ||
|
||
class SNWalletSDK { | ||
import android.content.Context | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.lifecycle.lifecycleScope | ||
import com.snphone.snwalletsdk.utils.StarknetClient | ||
import kotlinx.coroutines.launch | ||
|
||
class SNWalletSDK : ComponentActivity() { | ||
init { | ||
instance = this | ||
} | ||
|
||
companion object { | ||
private var instance: SNWalletSDK? = null | ||
|
||
fun applicationContext() : Context { | ||
return instance!!.applicationContext | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
instance = this | ||
|
||
val starknetClient = StarknetClient(BuildConfig.RPC_URL) | ||
lifecycleScope.launch { | ||
starknetClient.deployAccount() | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
wallet-sdk/app/src/main/java/com/snphone/snwalletsdk/utils/Keystore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.snphone.snwalletsdk.utils | ||
|
||
import android.util.Log | ||
import androidx.security.crypto.EncryptedSharedPreferences | ||
import androidx.security.crypto.MasterKey | ||
import com.snphone.snwalletsdk.MainActivity | ||
import com.snphone.snwalletsdk.SNWalletSDK | ||
import java.io.IOException | ||
import java.security.GeneralSecurityException | ||
|
||
class Keystore() { | ||
|
||
private val tag = "Keystore" | ||
private val context = MainActivity.applicationContext() | ||
fun storeData(message: String) { | ||
try { | ||
val masterKey = MasterKey.Builder(context) | ||
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM) | ||
.build() | ||
|
||
val sharedPreferences = EncryptedSharedPreferences.create( | ||
context, | ||
"my_encrypted_prefs", | ||
masterKey, | ||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | ||
) | ||
|
||
val editor = sharedPreferences.edit() | ||
editor.putString("key", message) | ||
editor.apply() | ||
|
||
} catch (e: GeneralSecurityException) { | ||
Log.e(tag, "Security exception while storing data: ${e.message}", e) | ||
} catch (e: IOException) { | ||
Log.e(tag, "I/O exception while storing data: ${e.message}", e) | ||
} | ||
} | ||
|
||
fun retrieveData(): String { | ||
try { | ||
val masterKey = MasterKey.Builder(context) | ||
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM) | ||
.build() | ||
|
||
val sharedPreferences = EncryptedSharedPreferences.create( | ||
context, | ||
"my_encrypted_prefs", | ||
masterKey, | ||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | ||
) | ||
|
||
return sharedPreferences.getString("key", "") ?: "" | ||
|
||
} catch (e: GeneralSecurityException) { | ||
Log.e(tag, "Security exception while retrieving data: ${e.message}", e) | ||
return "" | ||
} catch (e: IOException) { | ||
Log.e(tag, "I/O exception while retrieving data: ${e.message}", e) | ||
return "" | ||
} | ||
} | ||
} |
Oops, something went wrong.