mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
Log decrypted plaintext for NIP-44 v3 history
V3 wire payloads are Base64-encoded bytes, so history entries recorded the opaque Base64 string instead of the readable content. Decode it when storing history across all three paths (ContentProvider, bunker approval, intent), falling back to the original string when the bytes aren't valid UTF-8 (e.g. binary data).
This commit is contained in:
@@ -411,6 +411,12 @@ class SignerProvider : ContentProvider() {
|
||||
"Could not decrypt the message"
|
||||
}
|
||||
|
||||
// For v3 the wire payload is Base64; store the readable plaintext.
|
||||
val historyContent = if (isV3) {
|
||||
AmberUtils.decodeNip44v3LogContent(if (!isEncrypt) finalResult else content)
|
||||
} else {
|
||||
if (!isEncrypt) finalResult else content
|
||||
}
|
||||
scope.launch {
|
||||
historyDatabase.dao().addHistory(
|
||||
listOf(
|
||||
@@ -421,7 +427,7 @@ class SignerProvider : ContentProvider() {
|
||||
v3Kind,
|
||||
TimeUtils.now(),
|
||||
true,
|
||||
content = if (!isEncrypt) finalResult else content,
|
||||
content = historyContent,
|
||||
),
|
||||
),
|
||||
account.npub,
|
||||
|
||||
@@ -70,6 +70,18 @@ object AmberUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NIP-44 v3 wire payloads are Base64-encoded plaintext bytes. History logs
|
||||
* should record the readable plaintext, so decode it here; if the bytes
|
||||
* aren't valid base64/UTF-8 (e.g. binary data) keep the original string.
|
||||
*/
|
||||
@OptIn(kotlin.io.encoding.ExperimentalEncodingApi::class)
|
||||
fun decodeNip44v3LogContent(content: String): String = try {
|
||||
kotlin.io.encoding.Base64.decode(content).decodeToString(throwOnInvalidSequence = true)
|
||||
} catch (_: Exception) {
|
||||
content
|
||||
}
|
||||
|
||||
suspend fun sendBunkerError(
|
||||
account: Account,
|
||||
bunkerRequest: AmberBunkerRequest,
|
||||
|
||||
@@ -432,6 +432,9 @@ object BunkerRequestUtils {
|
||||
SignerType.NIP44_DECRYPT,
|
||||
SignerType.DECRYPT_ZAP_EVENT,
|
||||
-> response
|
||||
// v3 payloads are Base64; log the readable plaintext.
|
||||
SignerType.NIP44_V3_DECRYPT -> AmberUtils.decodeNip44v3LogContent(response)
|
||||
SignerType.NIP44_V3_ENCRYPT -> AmberUtils.decodeNip44v3LogContent(getDataFromBunker(bunkerRequest.request))
|
||||
else -> getDataFromBunker(bunkerRequest.request)
|
||||
},
|
||||
),
|
||||
|
||||
@@ -857,6 +857,10 @@ object IntentUtils {
|
||||
SignerType.DECRYPT_ZAP_EVENT,
|
||||
-> value
|
||||
|
||||
// v3 payloads are Base64; log the readable plaintext.
|
||||
SignerType.NIP44_V3_DECRYPT -> AmberUtils.decodeNip44v3LogContent(value)
|
||||
SignerType.NIP44_V3_ENCRYPT -> AmberUtils.decodeNip44v3LogContent(intentData.data)
|
||||
|
||||
else -> intentData.data
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user