Minimizes the dependency on the Account further by moving Tor settings to a tor Privacy State

This commit is contained in:
Vitor Pamplona
2025-07-21 19:09:06 -04:00
parent 95c6dcce5e
commit 8e6d71e422
29 changed files with 305 additions and 342 deletions
@@ -92,7 +92,7 @@ class PrivateZapTests {
val privateZapRequest =
runBlocking {
LnZapRequestEvent.create(
originalNote = poll,
zappedEvent = poll,
relays = setOf("wss://relay.damus.io/"),
signer = loggedIn,
pollOption = 0,
@@ -152,7 +152,7 @@ class PrivateZapTests {
val privateZapRequest =
runBlocking {
LnZapRequestEvent.create(
originalNote = textNote,
zappedEvent = textNote,
relays = setOf("wss://relay.damus.io/", "wss://relay.damus2.io/", "wss://relay.damus3.io/"),
signer = loggedIn,
pollOption = null,
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.nip03Timestamp
interface OtsResolverBuilder {
fun build(): OtsResolver
}
@@ -29,15 +29,15 @@ class VerificationStateCache {
fun verify(
event: OtsEvent,
resolverBuilder: () -> OtsResolver,
resolverBuilder: OtsResolverBuilder,
): VerificationState {
cache.put(event.id, VerificationState.Verifying)
return event.verifyState(resolverBuilder()).also { cache.put(event.id, it) }
return event.verifyState(resolverBuilder.build()).also { cache.put(event.id, it) }
}
fun cacheVerify(
event: OtsEvent,
resolverBuilder: () -> OtsResolver,
resolverBuilder: OtsResolverBuilder,
): VerificationState =
when (val verif = cache[event.id]) {
is VerificationState.Verifying -> verif
@@ -45,7 +45,7 @@ class VerificationStateCache {
is VerificationState.NetworkError -> {
// try again in 5 mins
if (verif.time < TimeUtils.fiveMinutesAgo()) {
event.verifyState(resolverBuilder()).also { cache.put(event.id, it) }
event.verifyState(resolverBuilder.build()).also { cache.put(event.id, it) }
} else {
verify(event, resolverBuilder)
}
@@ -87,8 +87,8 @@ class LnZapRequestEvent(
const val ALT = "Zap request"
suspend fun create(
originalNote: Event,
relays: Set<String>,
zappedEvent: Event,
relays: Set<NormalizedRelayUrl>,
signer: NostrSigner,
pollOption: Int?,
message: String,
@@ -98,13 +98,13 @@ class LnZapRequestEvent(
): LnZapRequestEvent {
var tags =
listOf(
arrayOf("e", originalNote.id),
arrayOf("p", toUserPubHex ?: originalNote.pubKey),
arrayOf("relays") + relays,
arrayOf("e", zappedEvent.id),
arrayOf("p", toUserPubHex ?: zappedEvent.pubKey),
arrayOf("relays") + relays.map { it.url },
AltTag.assemble(ALT),
)
if (originalNote is AddressableEvent) {
tags = tags + listOf(arrayOf("a", originalNote.aTag().toTag()))
if (zappedEvent is AddressableEvent) {
tags = tags + listOf(arrayOf("a", zappedEvent.aTag().toTag()))
}
if (pollOption != null && pollOption >= 0) {
tags = tags + listOf(arrayOf(PollOptionTag.TAG_NAME, pollOption.toString()))