Skip to content

Commit 7301a2f

Browse files
authored
Merge pull request #307 from synonymdev/feat/vss-client-auth
feat: vss client auth
2 parents 951b715 + 26e8982 commit 7301a2f

File tree

7 files changed

+685
-659
lines changed

7 files changed

+685
-659
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ See also:
4040
### References
4141

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

4544
### Linting
4645

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

6564
### Bitcoin Networks
65+
6666
The build config supports building 3 different apps for the 3 bitcoin networks (mainnet, testnet, regtest) via the 3 build flavors:
6767
- `dev` flavour = regtest
6868
- `mainnet` flavour = mainnet
6969
- `tnet` flavour = testnet
7070

7171
### Build for E2E Testing
72+
7273
Simply pass `E2E=true` as environment variable and build any flavor.
7374

7475
```sh

app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ package to.bitkit.data.backup
33
import com.synonym.vssclient.VssItem
44
import com.synonym.vssclient.vssGet
55
import com.synonym.vssclient.vssNewClient
6+
import com.synonym.vssclient.vssNewClientWithLnurlAuth
67
import com.synonym.vssclient.vssStore
78
import kotlinx.coroutines.CompletableDeferred
89
import kotlinx.coroutines.CoroutineDispatcher
910
import kotlinx.coroutines.withContext
1011
import kotlinx.coroutines.withTimeout
12+
import to.bitkit.data.keychain.Keychain
1113
import to.bitkit.di.BgDispatcher
1214
import to.bitkit.env.Env
1315
import to.bitkit.utils.Logger
16+
import to.bitkit.utils.ServiceError
1417
import javax.inject.Inject
1518
import javax.inject.Singleton
1619
import kotlin.time.Duration.Companion.seconds
@@ -19,17 +22,32 @@ import kotlin.time.Duration.Companion.seconds
1922
class VssBackupClient @Inject constructor(
2023
@BgDispatcher private val bgDispatcher: CoroutineDispatcher,
2124
private val vssStoreIdProvider: VssStoreIdProvider,
25+
private val keychain: Keychain,
2226
) {
2327
private val isSetup = CompletableDeferred<Unit>()
2428

2529
suspend fun setup() = withContext(bgDispatcher) {
2630
try {
2731
withTimeout(30.seconds) {
2832
Logger.verbose("VSS client setting up…", context = TAG)
29-
vssNewClient(
30-
baseUrl = Env.vssServerUrl,
31-
storeId = vssStoreIdProvider.getVssStoreId(),
32-
)
33+
if (Env.lnurlAuthSeverUrl.isNotEmpty()) {
34+
val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name)
35+
?: throw ServiceError.MnemonicNotFound
36+
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)
37+
38+
vssNewClientWithLnurlAuth(
39+
baseUrl = Env.vssServerUrl,
40+
storeId = vssStoreIdProvider.getVssStoreId(),
41+
mnemonic = mnemonic,
42+
passphrase = passphrase,
43+
lnurlAuthServerUrl = Env.lnurlAuthSeverUrl,
44+
)
45+
} else {
46+
vssNewClient(
47+
baseUrl = Env.vssServerUrl,
48+
storeId = vssStoreIdProvider.getVssStoreId(),
49+
)
50+
}
3351
isSetup.complete(Unit)
3452
Logger.info("VSS client setup ok", context = TAG)
3553
}

app/src/main/java/to/bitkit/env/Env.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ internal object Env {
4141
get() = when (network) {
4242
Network.BITCOIN -> TODO("VSS not implemented for mainnet")
4343
// Network.REGTEST -> "http://localhost:5050/vss"
44+
// Network.REGTEST -> "https://bitkit.stag0.blocktank.to/vss_rs_auth"
4445
else -> "https://bitkit.stag0.blocktank.to/vss_rs/"
4546
}
4647

app/src/main/java/to/bitkit/repositories/BackupRepo.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package to.bitkit.repositories
22

33
import android.content.Context
4-
import com.synonym.vssclient.VssItem
54
import dagger.hilt.android.qualifiers.ApplicationContext
65
import kotlinx.coroutines.CoroutineDispatcher
76
import kotlinx.coroutines.CoroutineScope
@@ -218,7 +217,7 @@ class BackupRepo @Inject constructor(
218217
it.copy(running = true, required = System.currentTimeMillis())
219218
}
220219

221-
encryptAndUpload(category)
220+
vssBackupClient.putObject(key = category.name, data = getBackupDataBytes(category))
222221
.onSuccess {
223222
cacheStore.updateBackupStatus(category) {
224223
it.copy(
@@ -236,15 +235,6 @@ class BackupRepo @Inject constructor(
236235
}
237236
}
238237

239-
private suspend fun encryptAndUpload(category: BackupCategory): Result<VssItem> = runCatching {
240-
val dataBytes = getBackupDataBytes(category)
241-
242-
// TODO encrypt data before upload
243-
val encrypted = dataBytes
244-
245-
return vssBackupClient.putObject(category.name, encrypted)
246-
}
247-
248238
private suspend fun getBackupDataBytes(category: BackupCategory): ByteArray = when (category) {
249239
BackupCategory.SETTINGS -> {
250240
val data = settingsStore.data.first().resetPin()

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class LightningService @Inject constructor(
113113

114114
ServiceQueue.LDK.background {
115115
node = try {
116-
if (Env.lnurlAuthSeverUrl.isNotBlank()) {
116+
if (Env.lnurlAuthSeverUrl.isNotEmpty()) {
117117
builder.buildWithVssStore(
118118
vssUrl = Env.vssServerUrl,
119119
storeId = vssStoreId,

0 commit comments

Comments
 (0)