Skip to content
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ See also:
### References

- For LNURL dev testing see [bitkit-docker](https://github.com/ovitrif/bitkit-docker)
- Bitkit Core Android bindings README: [synonymdev/bitkit-core — bindings/android/README.md](https://github.com/synonymdev/bitkit-core/blob/master/bindings/android/README.md)

### Linting

Expand All @@ -63,12 +62,14 @@ See repo: https://github.com/synonymdev/bitkit-transifex-sync
## Build

### Bitcoin Networks

The build config supports building 3 different apps for the 3 bitcoin networks (mainnet, testnet, regtest) via the 3 build flavors:
- `dev` flavour = regtest
- `mainnet` flavour = mainnet
- `tnet` flavour = testnet

### Build for E2E Testing

Simply pass `E2E=true` as environment variable and build any flavor.

```sh
Expand Down
26 changes: 22 additions & 4 deletions app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package to.bitkit.data.backup
import com.synonym.vssclient.VssItem
import com.synonym.vssclient.vssGet
import com.synonym.vssclient.vssNewClient
import com.synonym.vssclient.vssNewClientWithLnurlAuth
import com.synonym.vssclient.vssStore
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import to.bitkit.data.keychain.Keychain
import to.bitkit.di.BgDispatcher
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 All @@ -19,17 +22,32 @@ import kotlin.time.Duration.Companion.seconds
class VssBackupClient @Inject constructor(
@BgDispatcher private val bgDispatcher: CoroutineDispatcher,
private val vssStoreIdProvider: VssStoreIdProvider,
private val keychain: Keychain,
) {
private val isSetup = CompletableDeferred<Unit>()

suspend fun setup() = withContext(bgDispatcher) {
try {
withTimeout(30.seconds) {
Logger.verbose("VSS client setting up…", context = TAG)
vssNewClient(
baseUrl = Env.vssServerUrl,
storeId = vssStoreIdProvider.getVssStoreId(),
)
if (Env.lnurlAuthSeverUrl.isNotEmpty()) {
val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name)
?: throw ServiceError.MnemonicNotFound
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)

vssNewClientWithLnurlAuth(
baseUrl = Env.vssServerUrl,
storeId = vssStoreIdProvider.getVssStoreId(),
mnemonic = mnemonic,
passphrase = passphrase,
lnurlAuthServerUrl = Env.lnurlAuthSeverUrl,
)
} else {
vssNewClient(
baseUrl = Env.vssServerUrl,
storeId = vssStoreIdProvider.getVssStoreId(),
)
}
isSetup.complete(Unit)
Logger.info("VSS client setup ok", context = TAG)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/to/bitkit/env/Env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal object Env {
get() = when (network) {
Network.BITCOIN -> TODO("VSS not implemented for mainnet")
// Network.REGTEST -> "http://localhost:5050/vss"
// Network.REGTEST -> "https://bitkit.stag0.blocktank.to/vss_rs_auth"
else -> "https://bitkit.stag0.blocktank.to/vss_rs/"
}

Expand Down
12 changes: 1 addition & 11 deletions app/src/main/java/to/bitkit/repositories/BackupRepo.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package to.bitkit.repositories

import android.content.Context
import com.synonym.vssclient.VssItem
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -218,7 +217,7 @@ class BackupRepo @Inject constructor(
it.copy(running = true, required = System.currentTimeMillis())
}

encryptAndUpload(category)
vssBackupClient.putObject(key = category.name, data = getBackupDataBytes(category))
.onSuccess {
cacheStore.updateBackupStatus(category) {
it.copy(
Expand All @@ -236,15 +235,6 @@ class BackupRepo @Inject constructor(
}
}

private suspend fun encryptAndUpload(category: BackupCategory): Result<VssItem> = runCatching {
val dataBytes = getBackupDataBytes(category)

// TODO encrypt data before upload
val encrypted = dataBytes

return vssBackupClient.putObject(category.name, encrypted)
}

private suspend fun getBackupDataBytes(category: BackupCategory): ByteArray = when (category) {
BackupCategory.SETTINGS -> {
val data = settingsStore.data.first().resetPin()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/to/bitkit/services/LightningService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class LightningService @Inject constructor(

ServiceQueue.LDK.background {
node = try {
if (Env.lnurlAuthSeverUrl.isNotBlank()) {
if (Env.lnurlAuthSeverUrl.isNotEmpty()) {
builder.buildWithVssStore(
vssUrl = Env.vssServerUrl,
storeId = vssStoreId,
Expand Down
Loading