feat: Add support for NIP-55 #18
@@ -13,12 +13,6 @@ class ExternalSignerLauncher {
|
||||
this.launcher = launcher
|
||||
}
|
||||
|
||||
fun unregister() {
|
||||
launcher = null
|
||||
pendingResult?.cancel()
|
||||
pendingResult = null
|
||||
}
|
||||
|
||||
suspend fun launch(intent: Intent): ActivityResult {
|
||||
val deferred = CompletableDeferred<ActivityResult>()
|
||||
pendingResult = deferred
|
||||
|
||||
@@ -17,7 +17,9 @@ import su.reya.coop.coop.storage.SecretStore
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
private val externalSignerLauncher = ExternalSignerLauncher()
|
||||
companion object {
|
||||
val externalSignerLauncher = ExternalSignerLauncher()
|
||||
}
|
||||
|
||||
private val viewModel: NostrViewModel by viewModels {
|
||||
object : ViewModelProvider.Factory {
|
||||
@@ -81,9 +83,4 @@ class MainActivity : ComponentActivity() {
|
||||
super.onNewIntent(intent)
|
||||
setIntent(intent)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
externalSignerLauncher.unregister()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,10 +160,9 @@ fun OnboardingScreen() {
|
||||
if (viewModel.isExternalSignerAvailable()) {
|
||||
try {
|
||||
viewModel.connectExternalSigner()
|
||||
navigator.navigate(Screen.Home)
|
||||
} catch (e: Exception) {
|
||||
e.message?.let { snackbarHostState.showSnackbar(it) }
|
||||
} finally {
|
||||
navigator.navigate(Screen.Home)
|
||||
}
|
||||
} else {
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
|
||||
@@ -413,10 +413,10 @@ class NostrViewModel(
|
||||
val newMetadata = nostr.updateProfile(name, bio, avatarUrl)
|
||||
// Update the metadata state after successfully published
|
||||
updateMetadata(nostr.signer.currentUser!!, newMetadata)
|
||||
// Update local state
|
||||
_isBusy.value = false
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
} finally {
|
||||
_isBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,12 +435,13 @@ class NostrViewModel(
|
||||
val avatarUrl = picture?.let { blossomUpload(it, contentType ?: "image/jpeg") }
|
||||
// Create identity
|
||||
nostr.createIdentity(keys = keys, name = name, bio, picture = avatarUrl)
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
} finally {
|
||||
// Persist the secret in the secret storage
|
||||
secretStore.set("user_signer", secret)
|
||||
// Update local states
|
||||
_isBusy.value = false
|
||||
_signerRequired.value = false
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,13 +490,15 @@ class NostrViewModel(
|
||||
_isBusy.value = true
|
||||
try {
|
||||
val signer = createSigner(secret)
|
||||
// Update signer
|
||||
nostr.setSigner(signer)
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
} finally {
|
||||
// Persist the secret in the secret storage
|
||||
secretStore.set("user_signer", secret)
|
||||
// Update local states
|
||||
_signerRequired.value = false
|
||||
_isBusy.value = false
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,19 +515,19 @@ class NostrViewModel(
|
||||
SignerPermissions.nip44Decrypt(),
|
||||
)
|
||||
)
|
||||
|
||||
val result = handler.getPublicKey(permissions) ?: throw Exception("Rejected")
|
||||
val signer = ExternalSignerProxy(handler, result.pubkey)
|
||||
|
||||
// Update signer
|
||||
nostr.setSigner(signer)
|
||||
|
||||
// Store the signer in the secret storage
|
||||
secretStore.set("user_signer", "nip55://${result.packageName}/${result.pubkey.toHex()}")
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
} finally {
|
||||
// Update local states
|
||||
_signerRequired.value = false
|
||||
_isBusy.value = false
|
||||
} catch (e: Exception) {
|
||||
throw Exception("Notice: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user