Skip to content

Commit

Permalink
Merge pull request #129 from lightsparkdev/release/lightspark-sdk-v0.…
Browse files Browse the repository at this point in the history
…12.0

Merge release/lightspark-sdk-v0.12.0 into main
  • Loading branch information
jklein24 authored Jan 2, 2024
2 parents a64259f + 8247176 commit 2f93ced
Show file tree
Hide file tree
Showing 33 changed files with 656 additions and 18 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/core-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ on:
branches:
- 'main'
- 'develop'
pull_request:
branches:
- 'develop'
paths:
- 'core/**'
- 'build.gradle.kts'
- '.github/workflows/core-build.yaml'

jobs:
build:
Expand All @@ -25,5 +32,7 @@ jobs:
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
- name: Build and lint
uses: gradle/gradle-build-action@v2.4.2
env:
CI: true
with:
arguments: core:assemble
1 change: 1 addition & 0 deletions .github/workflows/core-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
with:
arguments: core:publish
env:
CI: true
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY_IN_MEMORY }}
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/crypto-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ on:
branches:
- 'main'
- 'develop'
pull_request:
branches:
- 'develop'
paths:
- 'crypto/**'
- 'build.gradle.kts'
- '.github/workflows/crypto-build.yaml'

jobs:
build:
Expand All @@ -27,5 +34,7 @@ jobs:
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
- name: Build and lint
uses: gradle/gradle-build-action@v2.4.2
env:
CI: true
with:
arguments: crypto:assemble
1 change: 1 addition & 0 deletions .github/workflows/crypto-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
with:
arguments: crypto:publish
env:
CI: true
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY_IN_MEMORY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
- name: Build dokka
uses: gradle/gradle-build-action@v2.4.2
env:
CI: true
with:
arguments: dokkaHtmlMultiModule
- name: "Upload to S3"
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/lightspark-sdk-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ on:
branches:
- 'main'
- 'develop'
pull_request:
branches:
- 'develop'
paths:
- 'lightspark-sdk/**'
- 'core/**'
- 'build.gradle.kts'
- '.github/workflows/lightspark-sdk-build.yaml'

jobs:
build:
Expand All @@ -28,5 +36,7 @@ jobs:
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
- name: Build and lint
uses: gradle/gradle-build-action@v2.4.2
env:
CI: true
with:
arguments: lightspark-sdk:assemble
1 change: 1 addition & 0 deletions .github/workflows/lightspark-sdk-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
with:
arguments: lightspark-sdk:publish
env:
CI: true
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY_IN_MEMORY }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release-branch-cut.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ jobs:
fi
- name: Bump Version
uses: gradle/gradle-build-action@v2.4.2
env:
CI: true
with:
arguments: "${{ env.sdk_name }}:bumpVersion -PnewVersion=${{ env.rel_version }}"
- name: Build
uses: gradle/gradle-build-action@v2.4.2
env:
CI: true
with:
arguments: "${{ env.sdk_name }}:assemble"
- name: Merge version updates
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/wallet-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ on:
branches:
- 'main'
- 'develop'
pull_request:
branches:
- 'develop'
paths:
- 'wallet-sdk/**'
- 'core/**'
- 'build.gradle.kts'
- '.github/workflows/wallet-build.yaml'

jobs:
build:
Expand All @@ -28,5 +36,7 @@ jobs:
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
- name: Build and lint
uses: gradle/gradle-build-action@v2.4.2
env:
CI: true
with:
arguments: wallet-sdk:assemble
1 change: 1 addition & 0 deletions .github/workflows/wallet-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
with:
arguments: wallet-sdk:publish
env:
CI: true
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY_IN_MEMORY }}
Expand Down
7 changes: 6 additions & 1 deletion androidwalletdemo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ various examples:
- [Generating keys and initializing a wallet - WalletRepository::initializeWallet](./src/main/java/com/lightspark/androidwalletdemo/wallet/WalletRepository.kt)
- [Unlocking a wallet to make payments - WalletRepository::attemptKeyStoreUnlock](./src/main/java/com/lightspark/androidwalletdemo/wallet/WalletRepository.kt)
- [Creating, Decoding, and Paying Invoices - PaymentRepository.kt](./src/main/java/com/lightspark/androidwalletdemo/wallet/PaymentRepository.kt)
- [Scanning an invoice QR code - InvoiceQrScanner.kt](./src/main/java/com/lightspark/androidwalletdemo/sendpayment/InvoiceQrScanner.kt)
- [Scanning an invoice QR code - InvoiceQrScanner.kt](./src/main/java/com/lightspark/androidwalletdemo/sendpayment/InvoiceQrScanner.kt)

### How to run

1. Set up the [demo JWT server](https://github.com/lightsparkdev/js-sdk/tree/main/apps/examples/jwt-server)
2. Edit `local.properties` generated by Android Studio and add the ngrok URL as `jwtServerUrl`.
7 changes: 7 additions & 0 deletions androidwalletdemo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import java.io.FileInputStream
import java.util.*

Expand All @@ -17,6 +18,11 @@ try {
throw RuntimeException("Unable to load version.properties", e)
}

val isCI: Boolean = System.getenv("CI") == "true"
val jwtServerUrl: String = if (isCI) "" else
gradleLocalProperties(rootDir).getProperty("jwtServerUrl")
?: throw Error("You must set the jwtServerUrl property in a local.properties file")

android {
namespace = "com.lightspark.androidwalletdemo"
compileSdk = 34
Expand All @@ -33,6 +39,7 @@ android {
useSupportLibrary = true
}
manifestPlaceholders["appAuthRedirectScheme"] = "com.lightspark.androidwalletdemo"
buildConfigField("String", "JWT_SERVER_URL", "\"${jwtServerUrl}\"")
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lightspark.androidwalletdemo.di

import com.lightspark.androidwalletdemo.BuildConfig
import com.lightspark.androidwalletdemo.auth.DemoAuthService
import dagger.Module
import dagger.Provides
Expand All @@ -15,7 +16,7 @@ class AuthModule {
@Provides
@Singleton
fun provideDemoAuthRetrofit(): Retrofit = Retrofit.Builder()
.baseUrl("https://us-central1-jwt-minter.cloudfunctions.net/")
.baseUrl(BuildConfig.JWT_SERVER_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import com.lightspark.sdk.core.LightsparkCoreConfig
import com.lightspark.sdk.core.LightsparkErrorCode
import com.lightspark.sdk.core.LightsparkException
import com.lightspark.sdk.core.auth.AuthProvider
import com.lightspark.sdk.core.auth.BETA_HEADER_KEY
import com.lightspark.sdk.core.auth.BETA_HEADER_VALUE
import com.lightspark.sdk.core.crypto.MissingKeyException
import com.lightspark.sdk.core.crypto.NodeKeyCache
import com.lightspark.sdk.core.util.getPlatform
Expand Down Expand Up @@ -53,7 +51,6 @@ class Requester constructor(
"lightspark-kotlin-sdk/${LightsparkCoreConfig.VERSION} ${getPlatform().platformName}/${getPlatform().version}"
private val defaultHeaders = mapOf(
"Content-Type" to "application/json",
BETA_HEADER_KEY to BETA_HEADER_VALUE,
"User-Agent" to userAgent,
"X-Lightspark-SDK" to userAgent,
)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ktlint = "11.3.1"
ktor = "2.2.3"
lightsparkCore = "0.5.0"
lightsparkCrypto = "0.5.0"
uma = "0.3.0"
uma = "0.6.0"
mavenPublish = "0.25.2"
mockitoCore = "5.5.0"
taskTree = "2.1.1"
Expand Down
4 changes: 2 additions & 2 deletions lightspark-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Start by installing the SDK from maven:
**build.gradle:**
```groovy
dependencies {
implementation "com.lightspark:lightspark-sdk:0.11.0"
implementation "com.lightspark:lightspark-sdk:0.12.0"
}
```

or with **build.gradle.kts:**
```kotlin
dependencies {
implementation("com.lightspark:lightspark-sdk:0.11.0")
implementation("com.lightspark:lightspark-sdk:0.12.0")
}
```

Expand Down
2 changes: 1 addition & 1 deletion lightspark-sdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GROUP=com.lightspark
POM_ARTIFACT_ID=lightspark-sdk
# Don't bump this manually. Run `scripts/versions.main.kt <new_version>` to bump the version instead.
VERSION_NAME=0.11.0
VERSION_NAME=0.12.0

POM_DESCRIPTION=The Lightspark API SDK for Kotlin and Java.
POM_INCEPTION_YEAR=2023
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ class LightsparkFuturesClient(config: ClientConfig) {
): CompletableFuture<Invoice> =
coroutineScope.future { coroutinesClient.createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs) }

/**
* Creates a Lightning invoice for the given node. This should only be used for generating invoices for UMA, with
* [LightsparkCoroutinesClient.createInvoice] preferred in the general case.
*
* @param nodeId The ID of the node for which to create the invoice.
* @param amountMsats The amount of the invoice in milli-satoshis.
* @param metadata The LNURL metadata payload field from the initial payreq response. This will be hashed and
* present in the h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice.
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
*/
@JvmOverloads
fun createUmaInvoice(
nodeId: String,
amountMsats: Long,
metadata: String,
expirySecs: Int? = null,
): CompletableFuture<Invoice> =
coroutineScope.future { coroutinesClient.createUmaInvoice(nodeId, amountMsats, metadata, expirySecs) }

/**
* Cancels an existing unpaid invoice and returns that invoice. Cancelled invoices cannot be paid.
*
Expand Down Expand Up @@ -201,6 +220,38 @@ class LightsparkFuturesClient(config: ClientConfig) {
)
}

/**
* [payUmaInvoice] sends an UMA payment to a node on the Lightning Network, based on the invoice (as defined by the
* BOLT11 specification) that you provide. This should only be used for paying UMA invoices, with [payInvoice]
* preferred in the general case.
*
* @param nodeId The ID of the node which will pay the invoice.
* @param encodedInvoice An encoded string representation of the invoice to pay.
* @param maxFeesMsats The maximum fees to pay in milli-satoshis. You must pass a value.
* As guidance, a maximum fee of 15 basis points should make almost all transactions succeed. For example,
* for a transaction between 10k sats and 100k sats, this would mean a fee limit of 15 to 150 sats.
* @param amountMsats The amount to pay in milli-satoshis. Defaults to the full amount of the invoice.
* @param timeoutSecs The number of seconds to wait for the payment to complete. Defaults to 60.
* @return The payment details.
*/
@JvmOverloads
fun payUmaInvoice(
nodeId: String,
encodedInvoice: String,
maxFeesMsats: Long,
amountMsats: Long? = null,
timeoutSecs: Int = 60,
): CompletableFuture<OutgoingPayment> =
coroutineScope.future {
coroutinesClient.payUmaInvoice(
nodeId,
encodedInvoice,
maxFeesMsats,
amountMsats,
timeoutSecs,
)
}

/**
* Decode a lightning invoice to get its details included payment amount, destination, etc.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
expirySecs: Int? = null,
): Invoice = runBlocking { asyncClient.createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs) }

/**
* Creates a Lightning invoice for the given node. This should only be used for generating invoices for UMA, with
* [LightsparkCoroutinesClient.createInvoice] preferred in the general case.
*
* @param nodeId The ID of the node for which to create the invoice.
* @param amountMsats The amount of the invoice in milli-satoshis.
* @param metadata The LNURL metadata payload field from the initial payreq response. This will be hashed and
* present in the h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice.
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
*/
@JvmOverloads
fun createUmaInvoice(
nodeId: String,
amountMsats: Long,
metadata: String,
expirySecs: Int? = null,
): Invoice = runBlocking { asyncClient.createUmaInvoice(nodeId, amountMsats, metadata, expirySecs) }

/**
* Cancels an existing unpaid invoice and returns that invoice. Cancelled invoices cannot be paid.
*
Expand Down Expand Up @@ -172,6 +190,30 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
): OutgoingPayment =
runBlocking { asyncClient.payInvoice(nodeId, encodedInvoice, maxFeesMsats, amountMsats, timeoutSecs) }

/**
* [payUmaInvoice] sends an UMA payment to a node on the Lightning Network, based on the invoice (as defined by the
* BOLT11 specification) that you provide. This should only be used for paying UMA invoices, with [payInvoice]
* preferred in the general case.
*
* @param nodeId The ID of the node which will pay the invoice.
* @param encodedInvoice An encoded string representation of the invoice to pay.
* @param maxFeesMsats The maximum fees to pay in milli-satoshis. You must pass a value.
* As guidance, a maximum fee of 15 basis points should make almost all transactions succeed. For example,
* for a transaction between 10k sats and 100k sats, this would mean a fee limit of 15 to 150 sats.
* @param amountMsats The amount to pay in milli-satoshis. Defaults to the full amount of the invoice.
* @param timeoutSecs The number of seconds to wait for the payment to complete. Defaults to 60.
* @return The payment details.
*/
@JvmOverloads
fun payUmaInvoice(
nodeId: String,
encodedInvoice: String,
maxFeesMsats: Long,
amountMsats: Long? = null,
timeoutSecs: Int = 60,
): OutgoingPayment =
runBlocking { asyncClient.payUmaInvoice(nodeId, encodedInvoice, maxFeesMsats, amountMsats, timeoutSecs) }

/**
* Decode a lightning invoice to get its details included payment amount, destination, etc.
*
Expand Down
Loading

0 comments on commit 2f93ced

Please sign in to comment.