Skip to content

Commit 8ecd9b9

Browse files
committed
Add Lightning
1 parent eeb84b1 commit 8ecd9b9

File tree

227 files changed

+8304
-2052
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+8304
-2052
lines changed

base/build.gradle

Lines changed: 0 additions & 65 deletions
This file was deleted.

base/src/main/java/com/blockstream/base/Constants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ object Urls {
2121
const val HELP_MNEMONIC_BACKUP = "https://help.blockstream.com/hc/en-us/articles/900001392563-What-is-a-mnemonic-backup-"
2222
const val HELP_NLOCKTIMES = "https://help.blockstream.com/hc/en-us/articles/900004249546-The-upgrade-from-nLockTime-to-CheckSequenceVerify"
2323
const val HELP_FEES = "https://help.blockstream.com/hc/en-us/articles/4412578550809"
24+
const val HELP_RECEIVE_FEES = "https://help.blockstream.com/hc/en-us/articles/18788578831897"
25+
const val HELP_RECEIVE_CAPACITY = "https://help.blockstream.com/hc/en-us/articles/18788499177753"
2426
const val HELP_GET_LIQUID = "https://help.blockstream.com/hc/en-us/articles/900000630846-How-do-I-get-Liquid-Bitcoin-L-BTC-"
2527
const val HELP_JADE_USB_UPGRADE = "https://help.blockstream.com/hc/en-us/articles/4408030503577"
2628
const val HELP_WHATS_COLLECTED = "https://help.blockstream.com/hc/en-us/articles/5988514431897"

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ allprojects {
2525
google()
2626
mavenCentral()
2727
maven ("https://jitpack.io")
28+
maven("https://mvn.breez.technology/releases")
2829
}
2930
}
3031

crypto/build.gradle.kts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
2+
13
plugins {
24
id("com.android.library")
35
id("org.jetbrains.kotlin.android")
@@ -11,6 +13,15 @@ android {
1113

1214
defaultConfig {
1315
minSdk = 23
16+
17+
val breezApiKey = System.getenv("BREEZ_API_KEY") ?: gradleLocalProperties(rootDir).getProperty("breez.apikey", "")
18+
val greenlightCertificate = System.getenv("GREENLIGHT_DEVICE_CERT") ?: gradleLocalProperties(rootDir).getProperty("greenlight.cert", "")
19+
val greenlightKey = System.getenv("GREENLIGHT_DEVICE_KEY") ?: gradleLocalProperties(rootDir).getProperty("greenlight.key", "")
20+
21+
buildConfigField("String", "BREEZ_API_KEY", "\"${breezApiKey}\"")
22+
buildConfigField("String", "GREENLIGHT_DEVICE_CERT", "\"${greenlightCertificate}\"")
23+
buildConfigField("String", "GREENLIGHT_DEVICE_KEY", "\"${greenlightKey}\"")
24+
1425
consumerProguardFiles("consumer-rules.pro")
1526
}
1627
compileOptions {
@@ -50,10 +61,13 @@ afterEvaluate {
5061
}
5162

5263
dependencies {
64+
/** --- Modules ---------------------------------------------------------------------------- */
65+
api(project(":lightning"))
66+
/** ----------------------------------------------------------------------------------------- */
5367

5468
/** --- Kotlin & KotlinX ------------------------------------------------------------------- */
55-
implementation libs.kotlinx.serialization.core
56-
implementation libs.kotlinx.serialization.json
69+
implementation(libs.kotlinx.serialization.core)
70+
implementation(libs.kotlinx.serialization.json)
5771
implementation(libs.kotlinx.datetime)
5872
/** ----------------------------------------------------------------------------------------- */
5973

crypto/fetch_gdk_binaries.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ rm ${TARBALL}
104104

105105
# Move the libraries and Java wrapper where we need them
106106
mv ${NAME}/lib/ ${CRYPTO_MODULE_ROOT}/src/main/jniLibs/
107+
rm -rf ${CRYPTO_MODULE_ROOT}/src/main/jniLibs/*/gdk # remove unnecessary files
107108
mv ${NAME}/share/java/com/blockstream/libgreenaddress/GDK.java ${GDK_JAVA_DIR}/libgreenaddress/GDK.java
108109
mv ${NAME}/share/java/com/blockstream/libwally/Wally.java ${GDK_JAVA_DIR}/libwally/Wally.java
109110

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.blockstream.gdk
2+
3+
const val BTC_UNIT = "BTC"
4+
const val MBTC_UNIT = "mBTC"
5+
const val UBTC_UNIT = "\u00B5BTC"
6+
const val BITS_UNIT = "bits"
7+
const val SATOSHI_UNIT = "sats"

crypto/src/main/java/com/blockstream/gdk/GdkBridge.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.blockstream.gdk.params.SubAccountParams
3232
import com.blockstream.gdk.params.SubAccountsParams
3333
import com.blockstream.gdk.params.TransactionParams
3434
import com.blockstream.gdk.params.UpdateSubAccountParams
35+
import com.blockstream.gdk.params.ValidateAddresseesParams
3536
import com.blockstream.libgreenaddress.GAAuthHandler
3637
import com.blockstream.libgreenaddress.GASession
3738
import com.blockstream.libgreenaddress.GDK
@@ -60,9 +61,6 @@ class GdkBridge constructor(
6061
isDevelopment: Boolean,
6162
extraLogger: Logger? = null
6263
) {
63-
64-
private val bip39WordList by lazy { wally.bip39Wordlist(BIP39_WORD_LIST_LANG) }
65-
6664
val networks by lazy {
6765
val jsonElement = gdk.getNetworks() as JsonElement
6866
Networks.fromJsonElement(JsonDeserializer, jsonElement)
@@ -91,6 +89,8 @@ class GdkBridge constructor(
9189
}
9290
}
9391

92+
val breezSdkWorkingDir by lazy { File(dataDir, "breezSdk") }
93+
9494
private fun randomBytes(len: Int): ByteArray {
9595
return ByteArray(len).also {
9696
SecureRandom().nextBytes(it)
@@ -174,6 +174,11 @@ class GdkBridge constructor(
174174
params: JsonElement
175175
) = gdk.validate(session, params)
176176

177+
fun validate(
178+
session: GASession,
179+
params: ValidateAddresseesParams
180+
) = gdk.validate(session, params)
181+
177182
fun encryptWithPin(
178183
session: GASession,
179184
encryptWithPinParams: EncryptWithPinParams
@@ -321,16 +326,15 @@ class GdkBridge constructor(
321326

322327
fun getMnemonicWordList(): List<String> {
323328
val wordList = mutableListOf<String>()
324-
val enWords = bip39WordList
325329
for (i in 0 until wally.BIP39_WORDLIST_LEN) {
326-
wordList += wally.bip39Word(enWords, i)
330+
wordList += wally.bip39Word(i)
327331
}
328332

329333
return wordList
330334
}
331335

332336
fun isMnemonicValid(mnemonic: String): Boolean {
333-
return wally.bip39MnemonicValidate(bip39WordList, mnemonic)
337+
return wally.bip39MnemonicValidate(mnemonic)
334338
}
335339

336340
fun isXpubValid(xpub: String): Boolean {
@@ -352,6 +356,10 @@ class GdkBridge constructor(
352356
}
353357
}
354358

359+
fun bip85FromMnemonic(mnemonic: String, passphrase: String?, index: Long = 0, isTestnet: Boolean = false): String {
360+
return wally.bip85FromMnemonic(mnemonic = mnemonic, passphrase = passphrase, isTestnet = isTestnet, index = index)
361+
}
362+
355363
fun hasGdkCache(loginData: LoginData): Boolean {
356364
return File(dataDir, "state/${loginData.networkHashId}").exists()
357365
}
@@ -373,8 +381,6 @@ class GdkBridge constructor(
373381
isLenient = true
374382
}
375383

376-
const val BIP39_WORD_LIST_LANG = "en"
377-
378384
const val KEY_CUSTOM_NETWORK = "custom_network"
379385

380386
// val FeeBlockTarget = listOf(3, 12, 24) // Old calculations

crypto/src/main/java/com/blockstream/gdk/NetworkAssetManager.kt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class NetworkAssetManager constructor(
3434
val coroutineScope: CoroutineScope,
3535
val qaTester: AssetQATester,
3636
) {
37-
private var metadata = mutableMapOf<String, Asset?>()
38-
private var icons = mutableMapOf<String, Bitmap?>()
37+
private val metadata = mutableMapOf<String, Asset?>()
38+
private val icons = mutableMapOf<String, Bitmap?>()
3939

4040
private val _statusStateFlow = MutableStateFlow(AssetStatus())
4141
private val _status get() = _statusStateFlow.value
@@ -103,16 +103,16 @@ class NetworkAssetManager constructor(
103103
?: context.getDrawable(R.drawable.ic_unknown)!!
104104
}
105105

106-
fun updateAssetsIfNeeded(provider: AssetsProvider, forceUpdate: Boolean = false) {
107-
if (_status.cacheStatus != CacheStatus.Latest || forceUpdate) {
106+
fun updateAssetsIfNeeded(provider: AssetsProvider) {
107+
if (_status.cacheStatus != CacheStatus.Latest) {
108108

109109
coroutineScope.launch(context = Dispatchers.IO) {
110110

111111
try {
112112
_statusStateFlow.value = _status.apply { onProgress = true }
113113

114114
// Allow forceUpdate to override QATester settings
115-
if (!qaTester.isAssetFetchDisabled() || forceUpdate) {
115+
if (!qaTester.isAssetFetchDisabled()) {
116116
// Try to update the registry
117117
provider.refreshAssets(
118118
AssetsParams(
@@ -122,9 +122,6 @@ class NetworkAssetManager constructor(
122122
)
123123
)
124124

125-
// Clear our local cache
126-
metadata.clear()
127-
128125
_status.cacheStatus = CacheStatus.Latest
129126
}
130127

@@ -138,9 +135,5 @@ class NetworkAssetManager constructor(
138135
}
139136
}
140137

141-
142-
companion object : KLogging(){
143-
const val REMOTE_CONFIG_ASSETS_MAINNET = "liquid_assets"
144-
const val REMOTE_CONFIG_ASSETS_TESTNET = "liquid_assets_testnet"
145-
}
138+
companion object: KLogging()
146139
}

crypto/src/main/java/com/blockstream/gdk/data/Account.kt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ data class Account constructor(
2424
@SerialName("bip44_discovered") val bip44Discovered: Boolean? = null,
2525
@SerialName("core_descriptors") val coreDescriptors: List<String>? = null,
2626
@SerialName("slip132_extended_pubkey") val extendedPubkey: String? = null,
27-
@SerialName("user_path") val derivationPath: List<Long>? = null,
28-
) : Parcelable {
27+
@SerialName("user_path") val derivationPath: List<Long>? = null
28+
) : Parcelable, Comparable<Account> {
2929

3030
@IgnoredOnParcel
3131
val network
@@ -44,6 +44,9 @@ data class Account constructor(
4444
val isMultisig
4545
get() = network.isMultisig
4646

47+
val isLightning
48+
get() = type == AccountType.LIGHTNING
49+
4750
val networkId
4851
get() = network.id
4952

@@ -71,6 +74,18 @@ data class Account constructor(
7174
val outputDescriptors: String?
7275
get() = coreDescriptors?.joinToString("\n")
7376

77+
@IgnoredOnParcel
78+
private val weight by lazy {
79+
when{
80+
isBitcoin && isSinglesig -> 0
81+
isBitcoin && isMultisig -> 1
82+
isLightning -> 2
83+
isLiquid && isSinglesig -> 3
84+
isLiquid && isMultisig && !isAmp -> 4
85+
isLiquid && isMultisig && isAmp -> 5
86+
else -> 6
87+
}
88+
}
7489

7590
@IgnoredOnParcel
7691
val name: String by lazy {
@@ -152,4 +167,12 @@ data class Account constructor(
152167
fun getRecoveryPubKeyAsBytes(): ByteArray? {
153168
return Wally.hex_to_bytes(recoveryPubKey)
154169
}
170+
171+
override fun compareTo(other: Account): Int {
172+
return if (weight == other.weight) {
173+
pointer.compareTo(other.pointer)
174+
} else {
175+
weight.compareTo(other.weight)
176+
}
177+
}
155178
}

crypto/src/main/java/com/blockstream/gdk/data/AccountType.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ enum class AccountType(val gdkType: String) {
1919

2020
override fun toString(): String = when(this){
2121
BIP44_LEGACY -> "Legacy"
22-
BIP49_SEGWIT_WRAPPED -> "Legacy"
23-
BIP84_SEGWIT -> "SegWit"
22+
BIP49_SEGWIT_WRAPPED -> "Standard"
23+
BIP84_SEGWIT -> "Native SegWit"
2424
BIP86_TAPROOT -> "Taproot"
2525
LIGHTNING -> "Lightning"
26+
27+
STANDARD -> "2FA Protected"
28+
AMP_ACCOUNT -> "AMP"
29+
TWO_OF_THREE -> "2of3 with 2FA"
2630
else -> gdkType
2731
}
2832

@@ -31,7 +35,9 @@ enum class AccountType(val gdkType: String) {
3135
else -> false
3236
}
3337

34-
fun isMutlisig() = !isSinglesig()
38+
fun isLightning() = this == LIGHTNING
39+
40+
fun isMutlisig() = !isSinglesig() && !isLightning()
3541

3642
companion object {
3743
fun byGDKType(name: String) = when(name){

0 commit comments

Comments
 (0)