implement the functions of nip46
This commit is contained in:
+114
-40
@@ -39,6 +39,7 @@ import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestNip44Encrypt
|
|||||||
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestPing
|
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestPing
|
||||||
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestSign
|
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerRequestSign
|
||||||
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerResponse
|
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerResponse
|
||||||
|
import com.vitorpamplona.quartz.nip46RemoteSigner.BunkerResponseEvent
|
||||||
import com.vitorpamplona.quartz.nip46RemoteSigner.NostrConnectEvent
|
import com.vitorpamplona.quartz.nip46RemoteSigner.NostrConnectEvent
|
||||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
|
import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
|
||||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
|
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
|
||||||
@@ -110,95 +111,156 @@ class NostrSignerRemote(
|
|||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
|
|
||||||
client.send(event, relayList = relays)
|
val result =
|
||||||
|
tryAndWait(timeout) { continuation ->
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
awaitingRequests.remove(request.id)
|
||||||
|
}
|
||||||
|
|
||||||
TODO("Not yet implemented")
|
awaitingRequests.put(request.id, continuation)
|
||||||
|
|
||||||
|
client.send(event, relayList = relays)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (result as BunkerResponseEvent).event as T
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun nip04Encrypt(
|
override suspend fun nip04Encrypt(
|
||||||
plaintext: String,
|
plaintext: String,
|
||||||
toPublicKey: HexKey,
|
toPublicKey: HexKey,
|
||||||
): String {
|
): String {
|
||||||
|
val request =
|
||||||
|
BunkerRequestNip04Encrypt(
|
||||||
|
message = plaintext,
|
||||||
|
pubKey = toPublicKey,
|
||||||
|
)
|
||||||
val event =
|
val event =
|
||||||
NostrConnectEvent.create(
|
NostrConnectEvent.create(
|
||||||
message =
|
message = request,
|
||||||
BunkerRequestNip04Encrypt(
|
|
||||||
message = plaintext,
|
|
||||||
pubKey = toPublicKey,
|
|
||||||
),
|
|
||||||
remoteKey = remotePubkey,
|
remoteKey = remotePubkey,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
client.send(event, relayList = relays)
|
val result =
|
||||||
TODO("Not yet implemented")
|
tryAndWait(timeout) { continuation ->
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
awaitingRequests.remove(request.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitingRequests.put(request.id, continuation)
|
||||||
|
|
||||||
|
client.send(event, relayList = relays)
|
||||||
|
}
|
||||||
|
return result?.result ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun nip04Decrypt(
|
override suspend fun nip04Decrypt(
|
||||||
ciphertext: String,
|
ciphertext: String,
|
||||||
fromPublicKey: HexKey,
|
fromPublicKey: HexKey,
|
||||||
): String {
|
): String {
|
||||||
|
val request =
|
||||||
|
BunkerRequestNip04Decrypt(
|
||||||
|
ciphertext = ciphertext,
|
||||||
|
pubKey = fromPublicKey,
|
||||||
|
)
|
||||||
val event =
|
val event =
|
||||||
NostrConnectEvent.create(
|
NostrConnectEvent.create(
|
||||||
message =
|
message = request,
|
||||||
BunkerRequestNip04Decrypt(
|
|
||||||
ciphertext = ciphertext,
|
|
||||||
pubKey = fromPublicKey,
|
|
||||||
),
|
|
||||||
remoteKey = remotePubkey,
|
remoteKey = remotePubkey,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
client.send(event, relayList = relays)
|
val result =
|
||||||
TODO("Not yet implemented")
|
tryAndWait(timeout) { continuation ->
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
awaitingRequests.remove(request.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitingRequests.put(request.id, continuation)
|
||||||
|
|
||||||
|
client.send(event, relayList = relays)
|
||||||
|
}
|
||||||
|
return result?.result ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun nip44Encrypt(
|
override suspend fun nip44Encrypt(
|
||||||
plaintext: String,
|
plaintext: String,
|
||||||
toPublicKey: HexKey,
|
toPublicKey: HexKey,
|
||||||
): String {
|
): String {
|
||||||
|
val request =
|
||||||
|
BunkerRequestNip44Encrypt(
|
||||||
|
message = plaintext,
|
||||||
|
pubKey = toPublicKey,
|
||||||
|
)
|
||||||
val event =
|
val event =
|
||||||
NostrConnectEvent.create(
|
NostrConnectEvent.create(
|
||||||
message =
|
message = request,
|
||||||
BunkerRequestNip44Encrypt(
|
|
||||||
message = plaintext,
|
|
||||||
pubKey = toPublicKey,
|
|
||||||
),
|
|
||||||
remoteKey = remotePubkey,
|
remoteKey = remotePubkey,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
client.send(event, relayList = relays)
|
val result =
|
||||||
TODO("Not yet implemented")
|
tryAndWait(timeout) { continuation ->
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
awaitingRequests.remove(request.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitingRequests.put(request.id, continuation)
|
||||||
|
|
||||||
|
client.send(event, relayList = relays)
|
||||||
|
}
|
||||||
|
return result?.result ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun nip44Decrypt(
|
override suspend fun nip44Decrypt(
|
||||||
ciphertext: String,
|
ciphertext: String,
|
||||||
fromPublicKey: HexKey,
|
fromPublicKey: HexKey,
|
||||||
): String {
|
): String {
|
||||||
|
val request =
|
||||||
|
BunkerRequestNip44Decrypt(
|
||||||
|
ciphertext = ciphertext,
|
||||||
|
pubKey = fromPublicKey,
|
||||||
|
)
|
||||||
val event =
|
val event =
|
||||||
NostrConnectEvent.create(
|
NostrConnectEvent.create(
|
||||||
message =
|
message = request,
|
||||||
BunkerRequestNip44Decrypt(
|
|
||||||
ciphertext = ciphertext,
|
|
||||||
pubKey = fromPublicKey,
|
|
||||||
),
|
|
||||||
remoteKey = remotePubkey,
|
remoteKey = remotePubkey,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
client.send(event, relayList = relays)
|
val result =
|
||||||
TODO("Not yet implemented")
|
tryAndWait(timeout) { continuation ->
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
awaitingRequests.remove(request.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitingRequests.put(request.id, continuation)
|
||||||
|
|
||||||
|
client.send(event, relayList = relays)
|
||||||
|
}
|
||||||
|
return result?.result ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun ping(): String {
|
suspend fun ping(): String? {
|
||||||
|
val request = BunkerRequestPing()
|
||||||
val event =
|
val event =
|
||||||
NostrConnectEvent.create(
|
NostrConnectEvent.create(
|
||||||
message = BunkerRequestPing(),
|
message = request,
|
||||||
remoteKey = remotePubkey,
|
remoteKey = remotePubkey,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
client.send(event, relayList = relays)
|
|
||||||
TODO("Not yet implemented")
|
val result =
|
||||||
|
tryAndWait(timeout) { continuation ->
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
awaitingRequests.remove(request.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitingRequests.put(request.id, continuation)
|
||||||
|
|
||||||
|
client.send(event, relayList = relays)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result?.result
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun connect(): BunkerResponse? {
|
suspend fun connect(): HexKey? {
|
||||||
val request =
|
val request =
|
||||||
BunkerRequestConnect(
|
BunkerRequestConnect(
|
||||||
remoteKey = remotePubkey,
|
remoteKey = remotePubkey,
|
||||||
@@ -223,18 +285,30 @@ class NostrSignerRemote(
|
|||||||
client.send(event, relayList = relays)
|
client.send(event, relayList = relays)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result?.result
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getPublicKey(): String {
|
suspend fun getPublicKey(): HexKey? {
|
||||||
|
val request = BunkerRequestGetPublicKey()
|
||||||
val event =
|
val event =
|
||||||
NostrConnectEvent.create(
|
NostrConnectEvent.create(
|
||||||
message = BunkerRequestGetPublicKey(),
|
message = request,
|
||||||
remoteKey = remotePubkey,
|
remoteKey = remotePubkey,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
client.send(event, relayList = relays)
|
|
||||||
TODO("Not yet implemented")
|
val result =
|
||||||
|
tryAndWait(timeout) { continuation ->
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
awaitingRequests.remove(request.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
awaitingRequests.put(request.id, continuation)
|
||||||
|
|
||||||
|
client.send(event, relayList = relays)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result?.result
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun decryptZapEvent(event: LnZapRequestEvent): LnZapPrivateEvent {
|
override suspend fun decryptZapEvent(event: LnZapRequestEvent): LnZapPrivateEvent {
|
||||||
|
|||||||
Reference in New Issue
Block a user