mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
Support for hex keys
This commit is contained in:
@@ -9,6 +9,7 @@ import com.greenart7c3.nostrsigner.database.HistoryEntity
|
||||
import com.greenart7c3.nostrsigner.models.SignerType
|
||||
import com.greenart7c3.nostrsigner.models.TimeUtils
|
||||
import com.greenart7c3.nostrsigner.service.AmberUtils
|
||||
import com.greenart7c3.nostrsigner.service.IntentUtils
|
||||
import com.vitorpamplona.quartz.crypto.CryptoUtils
|
||||
import com.vitorpamplona.quartz.encoders.toHexKey
|
||||
import com.vitorpamplona.quartz.encoders.toNpub
|
||||
@@ -51,8 +52,9 @@ class SignerProvider : ContentProvider() {
|
||||
"content://$appId.SIGN_MESSAGE" -> {
|
||||
val packageName = callingPackage ?: return null
|
||||
val message = projection?.first() ?: return null
|
||||
if (!LocalPreferences.containsAccount(context!!, projection[2])) return null
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context!!, projection[2]) ?: return null
|
||||
val npub = IntentUtils.parsePubKey(projection[2]) ?: return null
|
||||
if (!LocalPreferences.containsAccount(context!!, npub)) return null
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context!!, npub) ?: return null
|
||||
val currentSelection = selection ?: "0"
|
||||
val database = NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub())
|
||||
val permission =
|
||||
@@ -119,8 +121,9 @@ class SignerProvider : ContentProvider() {
|
||||
"content://$appId.SIGN_EVENT" -> {
|
||||
val packageName = callingPackage ?: return null
|
||||
val json = projection?.first() ?: return null
|
||||
if (!LocalPreferences.containsAccount(context!!, projection[2])) return null
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context!!, projection[2]) ?: return null
|
||||
val npub = IntentUtils.parsePubKey(projection[2]) ?: return null
|
||||
if (!LocalPreferences.containsAccount(context!!, npub)) return null
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context!!, npub) ?: return null
|
||||
val event = Event.fromJson(json)
|
||||
val currentSelection = selection ?: "0"
|
||||
val database = NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub())
|
||||
@@ -214,10 +217,11 @@ class SignerProvider : ContentProvider() {
|
||||
-> {
|
||||
val packageName = callingPackage ?: return null
|
||||
val content = projection?.first() ?: return null
|
||||
if (!LocalPreferences.containsAccount(context!!, projection[2])) return null
|
||||
val npub = IntentUtils.parsePubKey(projection[2]) ?: return null
|
||||
if (!LocalPreferences.containsAccount(context!!, npub)) return null
|
||||
val stringType = uri.toString().replace("content://$appId.", "")
|
||||
val pubkey = projection[1]
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context!!, projection[2]) ?: return null
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context!!, npub) ?: return null
|
||||
val currentSelection = selection ?: "0"
|
||||
val database = NostrSigner.getInstance().getDatabase(account.keyPair.pubKey.toNpub())
|
||||
val permission =
|
||||
|
||||
@@ -550,7 +550,7 @@ object IntentUtils {
|
||||
|
||||
val callbackUrl = intent.extras?.getString("callbackUrl") ?: ""
|
||||
val name = if (callbackUrl.isNotBlank()) Uri.parse(callbackUrl).host ?: "" else ""
|
||||
val pubKey = intent.extras?.getString("pubKey") ?: ""
|
||||
val pubKey = intent.extras?.getString("pubKey") ?: intent.extras?.getString("pubkey") ?: ""
|
||||
val id = intent.extras?.getString("id") ?: ""
|
||||
|
||||
val compressionType = if (intent.extras?.getString("compression") == "gzip") CompressionType.GZIP else CompressionType.NONE
|
||||
@@ -577,6 +577,11 @@ object IntentUtils {
|
||||
unsignedEvent.tags,
|
||||
unsignedEvent.content,
|
||||
) {
|
||||
var npub = intent.getStringExtra("current_user")
|
||||
if (npub != null) {
|
||||
npub = parsePubKey(npub!!)
|
||||
}
|
||||
|
||||
onReady(
|
||||
IntentData(
|
||||
data,
|
||||
@@ -588,7 +593,7 @@ object IntentUtils {
|
||||
compressionType,
|
||||
returnType,
|
||||
permissions,
|
||||
intent.extras?.getString("current_user") ?: Hex.decode(it.pubKey).toNpub(),
|
||||
npub ?: Hex.decode(it.pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
null,
|
||||
@@ -612,6 +617,11 @@ object IntentUtils {
|
||||
"Could not decrypt the message"
|
||||
}
|
||||
|
||||
var npub = intent.getStringExtra("current_user")
|
||||
if (npub != null) {
|
||||
npub = parsePubKey(npub!!)
|
||||
}
|
||||
|
||||
onReady(
|
||||
IntentData(
|
||||
data,
|
||||
@@ -623,7 +633,7 @@ object IntentUtils {
|
||||
compressionType,
|
||||
returnType,
|
||||
permissions,
|
||||
intent.extras?.getString("current_user") ?: Hex.decode(pubKey).toNpub(),
|
||||
npub ?: Hex.decode(pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
null,
|
||||
@@ -634,6 +644,11 @@ object IntentUtils {
|
||||
)
|
||||
}
|
||||
SignerType.GET_PUBLIC_KEY -> {
|
||||
var npub = intent.getStringExtra("current_user")
|
||||
if (npub != null) {
|
||||
npub = parsePubKey(npub!!)
|
||||
}
|
||||
|
||||
onReady(
|
||||
IntentData(
|
||||
data,
|
||||
@@ -645,7 +660,7 @@ object IntentUtils {
|
||||
compressionType,
|
||||
returnType,
|
||||
permissions,
|
||||
intent.extras?.getString("current_user") ?: Hex.decode(pubKey).toNpub(),
|
||||
npub ?: Hex.decode(pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
null,
|
||||
@@ -656,6 +671,11 @@ object IntentUtils {
|
||||
)
|
||||
}
|
||||
SignerType.SIGN_MESSAGE -> {
|
||||
var npub = intent.getStringExtra("current_user")
|
||||
if (npub != null) {
|
||||
npub = parsePubKey(npub!!)
|
||||
}
|
||||
|
||||
onReady(
|
||||
IntentData(
|
||||
data,
|
||||
@@ -667,7 +687,7 @@ object IntentUtils {
|
||||
compressionType,
|
||||
returnType,
|
||||
permissions,
|
||||
intent.extras?.getString("current_user") ?: Hex.decode(pubKey).toNpub(),
|
||||
npub ?: Hex.decode(pubKey).toNpub(),
|
||||
mutableStateOf(true),
|
||||
mutableStateOf(false),
|
||||
null,
|
||||
@@ -681,6 +701,17 @@ object IntentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
fun parsePubKey(key: String): String? {
|
||||
if (key.startsWith("npub1")) {
|
||||
return key
|
||||
}
|
||||
return try {
|
||||
Hex.decode(key).toNpub()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun metaDataFromJson(json: String): BunkerMetadata {
|
||||
return BunkerMetadata.mapper.readValue(json, BunkerMetadata::class.java)
|
||||
}
|
||||
@@ -780,7 +811,11 @@ object IntentUtils {
|
||||
localAccount = it
|
||||
}
|
||||
} else if (intent.getStringExtra("current_user") != null) {
|
||||
LocalPreferences.loadFromEncryptedStorage(context, intent.getStringExtra("current_user"))?.let {
|
||||
var npub = intent.getStringExtra("current_user")
|
||||
if (npub != null) {
|
||||
npub = parsePubKey(npub)
|
||||
}
|
||||
LocalPreferences.loadFromEncryptedStorage(context, npub)?.let {
|
||||
localAccount = it
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user