Skip to content

Commit

Permalink
Signing added to Android LocationShare example app
Browse files Browse the repository at this point in the history
  • Loading branch information
SanttuRantanen committed Oct 21, 2024
1 parent 462e366 commit 5b861ca
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 70 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ Java_com_example_locationshare_ProxyClientJNI_proxyClientDisconnect(JNIEnv *env,
}
*/
JNIEXPORT void JNICALL
Java_com_example_locationshare_ProxyClientJNI_proxyClientPublish(JNIEnv *env, jclass, jlong clientHandle, jstring jContent) {
Java_com_example_locationshare_ProxyClientJNI_proxyClientPublish(JNIEnv *env, jclass, jlong clientHandle, jstring jContent, jstring jEthereumPrivateKey) {

const char* content = env->GetStringUTFChars(jContent, 0);
uint64_t contentLength = strlen(content);
const char* ethereumPrivateKey = env->GetStringUTFChars(jEthereumPrivateKey, 0);
LOGI("proxyClientPublish clientHandle: %d", clientHandle);

LOGI("proxyClientPublish string: %s", content);
LOGI("proxyClientPublish content: %s", content);
LOGI("proxyClientPublish ethereumPrivateKey: %s", ethereumPrivateKey);

Error* errors = nullptr;
uint64_t numErrors = 0;

proxyClientPublish(&errors, &numErrors, static_cast<uint64_t>(clientHandle), content, contentLength);
proxyClientPublish(&errors, &numErrors, static_cast<uint64_t>(clientHandle), content, contentLength, ethereumPrivateKey);

env->ReleaseStringUTFChars(jContent, content);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ProxyClientJNI {
external fun proxyClientDisconnect(clientHandle: Long)
*/
@Throws(StreamrProxyException::class)
external fun proxyClientPublish(clientHandle: Long, content: String)
external fun proxyClientPublish(clientHandle: Long, content: String, ethereumPrivateKey: String)

data class Proxy(
val websocketUrl: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class StreamrProxyClient(val state: StateFlow<LocationState>) {
private val job = SupervisorJob()
private val scope = CoroutineScope(Dispatchers.Default + job)
private var publishingJob: Job? = null
private val validEthereumAddress = "0x1234567890123456789012345678901234567890";
private val validEthereumAddress = "0xa5374e3c19f15e1847881979dd0c6c9ffe846bd5";
private val validStreamPartId = "0xd7278f1e4a946fa7838b5d1e0fe50c5725fb23de/nativesdktest#01";
val proxyClientHandle = ProxyClientJNI.proxyClientNew(validEthereumAddress, validStreamPartId)
companion object {
Expand All @@ -25,12 +25,15 @@ class StreamrProxyClient(val state: StateFlow<LocationState>) {
var status: Status by mutableStateOf(Status.stopped)
private set

var proxyAddress by mutableStateOf("0xfccf49c5a714cab640e329464c6f81d72df6e307")
var proxyAddress by mutableStateOf("0x2ee615edd5d13310f83d8125ff4f0960a7475e33")
private set

var proxyId by mutableStateOf("ws://10.0.2.2:44211")
private set

var ethereumPrivateKey by mutableStateOf("23bead9b499af21c4c16e4511b3b6b08c3e22e76e0591f5ab5ba8d4c3a5b1820")
private set

var intervalSeconds by mutableStateOf(defaultPublishingIntervalInSeconds)
private set

Expand All @@ -42,6 +45,10 @@ class StreamrProxyClient(val state: StateFlow<LocationState>) {
this.proxyId = proxyId
}

fun updateEthereumPrivateKey(ethereumPrivateKey: String){
this.ethereumPrivateKey = ethereumPrivateKey
}

fun updateIntervalSeconds(intervalSeconds: String){
this.intervalSeconds = intervalSeconds
}
Expand All @@ -55,7 +62,7 @@ class StreamrProxyClient(val state: StateFlow<LocationState>) {
withContext(Dispatchers.IO) {
println("proxyClientHandle: ${proxyClientHandle}")
println("Publish: $data")
ProxyClientJNI.proxyClientPublish(proxyClientHandle, data)
ProxyClientJNI.proxyClientPublish(proxyClientHandle, data, ethereumPrivateKey)
println("Publish End")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ fun LocationShareScreen(
ProxyFieldsLayout(
proxyAddress = locationShareViewModel.streamrProxyClient.proxyAddress,
proxyId = locationShareViewModel.streamrProxyClient.proxyId,
ethereumPrivateKey = locationShareViewModel.streamrProxyClient.ethereumPrivateKey,
status = locationShareViewModel.streamrProxyClient.status,
onProxyAddressChanged = {
locationShareViewModel.streamrProxyClient.updateProxyAddress(
it
)
},
onProxyIdChanged = { locationShareViewModel.streamrProxyClient.updateProxyId(it) },
onEthereumPrivateKeyChanged = { locationShareViewModel.streamrProxyClient.updateEthereumPrivateKey(it) },
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
Expand Down Expand Up @@ -139,9 +141,11 @@ fun LocationShareScreen(
fun ProxyFieldsLayout(
proxyAddress: String,
proxyId: String,
ethereumPrivateKey: String,
status: Status,
onProxyAddressChanged: (String) -> Unit,
onProxyIdChanged: (String) -> Unit,
onEthereumPrivateKeyChanged: (String) -> Unit,
modifier: Modifier = Modifier
) {
val mediumPadding = dimensionResource(R.dimen.padding_medium)
Expand Down Expand Up @@ -187,6 +191,22 @@ fun ProxyFieldsLayout(
disabledContainerColor = colorScheme.surface,
)
)

OutlinedTextField(
value = ethereumPrivateKey,
onValueChange = onEthereumPrivateKeyChanged,
label = {
Text("Ethereum Private Key")
},
singleLine = true,
shape = shapes.large,
modifier = Modifier.fillMaxWidth(),
colors = TextFieldDefaults.colors(
focusedContainerColor = colorScheme.surface,
unfocusedContainerColor = colorScheme.surface,
disabledContainerColor = colorScheme.surface,
)
)
Text(text = "Status: ${status}")
}
}
Expand Down

0 comments on commit 5b861ca

Please sign in to comment.