Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.synonym.vssclient.VssItem
import com.synonym.vssclient.vssDelete
import com.synonym.vssclient.vssGet
import com.synonym.vssclient.vssListKeys
import com.synonym.vssclient.vssNewClient
import com.synonym.vssclient.vssNewClientWithLnurlAuth
import com.synonym.vssclient.vssStore
import kotlinx.coroutines.CompletableDeferred
Expand All @@ -19,6 +18,7 @@ import to.bitkit.data.keychain.Keychain
import to.bitkit.di.IoDispatcher
import to.bitkit.env.Env
import to.bitkit.utils.Logger
import to.bitkit.utils.ServiceError
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -51,22 +51,18 @@ class VssBackupClient @Inject constructor(
val vssStoreId = vssStoreIdProvider.getVssStoreId(walletIndex)
Logger.verbose("Building VSS client with vssUrl: '$vssUrl'", context = TAG)
Logger.verbose("Building VSS client with lnurlAuthServerUrl: '$lnurlAuthServerUrl'", context = TAG)
if (lnurlAuthServerUrl.isNotEmpty()) {
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)

vssNewClientWithLnurlAuth(
baseUrl = vssUrl,
storeId = vssStoreId,
mnemonic = mnemonic,
passphrase = passphrase,
lnurlAuthServerUrl = lnurlAuthServerUrl,
)
} else {
vssNewClient(
baseUrl = vssUrl,
storeId = vssStoreId,
)
if (lnurlAuthServerUrl.isBlank()) {
throw ServiceError.VssAuthRequired()
}
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)

vssNewClientWithLnurlAuth(
baseUrl = vssUrl,
storeId = vssStoreId,
mnemonic = mnemonic,
passphrase = passphrase,
lnurlAuthServerUrl = lnurlAuthServerUrl,
)
isSetup.complete(Unit)
Logger.info("VSS client setup with server: '$vssUrl'", context = TAG)
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/to/bitkit/data/backup/VssBackupClientLdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import to.bitkit.data.keychain.Keychain
import to.bitkit.di.IoDispatcher
import to.bitkit.env.Env
import to.bitkit.utils.Logger
import to.bitkit.utils.ServiceError
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -52,6 +53,9 @@ class VssBackupClientLdk @Inject constructor(
?: throw MnemonicNotAvailableException()

withTimeout(30.seconds) {
if (Env.lnurlAuthServerUrl.isBlank()) {
throw ServiceError.VssAuthRequired()
}
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)
vssNewLdkClientWithLnurlAuth(
baseUrl = Env.vssServerUrl,
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/to/bitkit/services/LightningService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ class LightningService @Inject constructor(
context = TAG,
)

if (lnurlAuthServerUrl.isNotEmpty()) {
builder.buildWithVssStore(vssUrl, vssStoreId, lnurlAuthServerUrl, fixedHeaders)
} else {
builder.buildWithVssStoreAndFixedHeaders(vssUrl, vssStoreId, fixedHeaders)
if (lnurlAuthServerUrl.isBlank()) {
throw ServiceError.VssAuthRequired()
}

builder.buildWithVssStore(vssUrl, vssStoreId, lnurlAuthServerUrl, fixedHeaders)
} catch (e: BuildException) {
throw LdkError(e)
} finally {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/to/bitkit/utils/Errors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sealed class ServiceError(message: String) : AppError(message) {
class NodeNotSetup : ServiceError("Node is not setup")
class NodeNotStarted : ServiceError("Node is not started")
class MnemonicNotFound : ServiceError("Mnemonic not found")
class VssAuthRequired : ServiceError("VSS requires LNURL-auth")
class NodeStillRunning : ServiceError("Node is still running")
class NodeReleaseTimeout : ServiceError("Previous node release did not finish in time")
class InvalidNodeSigningMessage : ServiceError("Invalid node signing message")
Expand Down
1 change: 1 addition & 0 deletions changelog.d/next/1156.security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wallet backups no longer fall back to unauthenticated VSS when LNURL-auth is missing.
Loading