mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
Merge pull request #460 from greenart7c3/claude/youthful-dirac-HZaMp
Add LOGOUT support for NIP-46 bunker protocol
This commit is contained in:
@@ -15,4 +15,5 @@ enum class SignerType {
|
|||||||
INVALID,
|
INVALID,
|
||||||
SWITCH_RELAYS,
|
SWITCH_RELAYS,
|
||||||
SIGN_PSBT,
|
SIGN_PSBT,
|
||||||
|
LOGOUT,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,6 +235,7 @@ object BunkerRequestUtils {
|
|||||||
"ping" -> SignerType.PING
|
"ping" -> SignerType.PING
|
||||||
"switch_relays" -> SignerType.SWITCH_RELAYS
|
"switch_relays" -> SignerType.SWITCH_RELAYS
|
||||||
"sign_psbt" -> SignerType.SIGN_PSBT
|
"sign_psbt" -> SignerType.SIGN_PSBT
|
||||||
|
"logout" -> SignerType.LOGOUT
|
||||||
else -> SignerType.INVALID
|
else -> SignerType.INVALID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,6 +252,7 @@ object BunkerRequestUtils {
|
|||||||
"nip44v3_encrypt", "nip44v3_decrypt" -> bunkerRequest.params.getOrElse(3) { "" }
|
"nip44v3_encrypt", "nip44v3_decrypt" -> bunkerRequest.params.getOrElse(3) { "" }
|
||||||
"ping" -> "pong"
|
"ping" -> "pong"
|
||||||
"sign_psbt" -> bunkerRequest.params.first()
|
"sign_psbt" -> bunkerRequest.params.first()
|
||||||
|
"logout" -> "ack"
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,29 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == SignerType.LOGOUT) {
|
||||||
|
permission?.let {
|
||||||
|
BunkerRequestUtils.sendBunkerResponse(
|
||||||
|
context = applicationContext,
|
||||||
|
account = acc,
|
||||||
|
bunkerRequest = request,
|
||||||
|
bunkerResponse = BunkerResponse(bunkerRequest.id, "ack", null),
|
||||||
|
relays = relays,
|
||||||
|
onLoading = { },
|
||||||
|
onDone = { success ->
|
||||||
|
if (success) {
|
||||||
|
Amber.instance.applicationIOScope.launch {
|
||||||
|
dao.delete(permission.application.key)
|
||||||
|
historyDao.deleteHistory(permission.application.key)
|
||||||
|
Amber.instance.notificationSubscription.updateFilter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (type == SignerType.GET_PUBLIC_KEY) {
|
if (type == SignerType.GET_PUBLIC_KEY) {
|
||||||
val gpkPermission = dao.getPermission(event.pubKey, "GET_PUBLIC_KEY")
|
val gpkPermission = dao.getPermission(event.pubKey, "GET_PUBLIC_KEY")
|
||||||
val signPolicy = dao.getSignPolicy(event.pubKey)
|
val signPolicy = dao.getSignPolicy(event.pubKey)
|
||||||
|
|||||||
@@ -125,6 +125,11 @@ class BunkerRequestUtilsTest {
|
|||||||
assertEquals(SignerType.SIGN_PSBT, BunkerRequestUtils.getTypeFromBunker(mockBunkerRequest("sign_psbt")))
|
assertEquals(SignerType.SIGN_PSBT, BunkerRequestUtils.getTypeFromBunker(mockBunkerRequest("sign_psbt")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getTypeFromBunker returns LOGOUT for logout`() {
|
||||||
|
assertEquals(SignerType.LOGOUT, BunkerRequestUtils.getTypeFromBunker(mockBunkerRequest("logout")))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `getTypeFromBunker returns INVALID for unknown method`() {
|
fun `getTypeFromBunker returns INVALID for unknown method`() {
|
||||||
assertEquals(SignerType.INVALID, BunkerRequestUtils.getTypeFromBunker(mockBunkerRequest("unknown_method")))
|
assertEquals(SignerType.INVALID, BunkerRequestUtils.getTypeFromBunker(mockBunkerRequest("unknown_method")))
|
||||||
@@ -235,6 +240,11 @@ class BunkerRequestUtilsTest {
|
|||||||
assertEquals("", BunkerRequestUtils.getDataFromBunker(mockBunkerRequest("switch_relays")))
|
assertEquals("", BunkerRequestUtils.getDataFromBunker(mockBunkerRequest("switch_relays")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `getDataFromBunker returns ack for logout`() {
|
||||||
|
assertEquals("ack", BunkerRequestUtils.getDataFromBunker(mockBunkerRequest("logout")))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `getDataFromBunker returns empty string for unknown method`() {
|
fun `getDataFromBunker returns empty string for unknown method`() {
|
||||||
assertEquals("", BunkerRequestUtils.getDataFromBunker(mockBunkerRequest("unknown_method")))
|
assertEquals("", BunkerRequestUtils.getDataFromBunker(mockBunkerRequest("unknown_method")))
|
||||||
|
|||||||
Reference in New Issue
Block a user