Skip to content

Commit 4c430a9

Browse files
committed
feat: get store id from vss client lib
1 parent dbbe138 commit 4c430a9

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package to.bitkit.data.backup
22

3-
import org.lightningdevkit.ldknode.Network
3+
import com.synonym.vssclient.vssDeriveStoreId
44
import to.bitkit.data.keychain.Keychain
55
import to.bitkit.env.Env
6-
import to.bitkit.ext.toHex
7-
import to.bitkit.ext.toSha256
86
import to.bitkit.utils.Logger
97
import to.bitkit.utils.ServiceError
108
import javax.inject.Inject
@@ -14,21 +12,31 @@ import javax.inject.Singleton
1412
class VssStoreIdProvider @Inject constructor(
1513
private val keychain: Keychain,
1614
) {
15+
@Volatile
16+
private var cachedStoreId: String? = null
17+
1718
fun getVssStoreId(): String {
18-
// TODO Temp fix as we don't have VSS auth yet
19-
if (Env.network == Network.BITCOIN) {
20-
error(
21-
"Do not run this on mainnet until VSS auth is implemented. Below hack is a temporary fix and not safe for mainnet."
22-
)
23-
}
19+
cachedStoreId?.let { return it }
20+
21+
return synchronized(this) {
22+
cachedStoreId?.let { return it }
2423

25-
val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name) ?: throw ServiceError.MnemonicNotFound
26-
val mnemonicData = mnemonic.encodeToByteArray()
27-
val hashedMnemonic = mnemonicData.toSha256()
24+
val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name) ?: throw ServiceError.MnemonicNotFound
25+
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)
2826

29-
val storeIdHack = Env.vssStoreId + hashedMnemonic.toHex()
30-
Logger.info("storeIdHack: $storeIdHack")
27+
val storeId = vssDeriveStoreId(
28+
prefix = Env.vssStoreIdPrefix,
29+
mnemonic = mnemonic,
30+
passphrase = passphrase,
31+
)
32+
33+
Logger.info("VSS store id: '$storeId'", context = TAG)
34+
cachedStoreId = storeId
35+
storeId
36+
}
37+
}
3138

32-
return storeIdHack
39+
companion object {
40+
private const val TAG = "VssStoreIdProvider"
3341
}
3442
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ internal object Env {
5050
else -> "" // TODO implement LNURL-auth Server for other networks
5151
}
5252

53-
val vssStoreId
54-
get() = when (network) {
55-
Network.REGTEST -> "bitkit_regtest"
56-
Network.TESTNET -> "bitkit_testnet"
57-
else -> TODO("${network.name} network not implemented")
58-
}
53+
val vssStoreIdPrefix get() = "bitkit_v1_${network.name.lowercase()}"
5954

6055
val esploraServerUrl
6156
get() = when (network) {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ test-junit-ext = { module = "androidx.test.ext:junit", version.ref = "junitExt"
109109
test-mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "mockitoKotlin" }
110110
test-robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
111111
test-turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
112-
vss = { module = "com.synonym:vss-client-android", version = "0.2.0" }
112+
vss = { module = "com.synonym:vss-client-android", version = "0.3.0" }
113113
work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "workRuntimeKtx" }
114114
zxing = { module = "com.google.zxing:core", version.ref = "zxing" }
115115
lottie = { module = "com.airbnb.android:lottie-compose", version.ref = "lottieVersion" }

0 commit comments

Comments
 (0)