Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
30bed5e
Merge pull request #147 from lightsparkdev/release/lightspark-sdk-v0.…
github-actions[bot] Jan 29, 2024
37cac03
lnurlp fallback
shreyav Feb 6, 2024
2b23e5e
annotation and tests
shreyav Feb 7, 2024
1fcc69a
Merge pull request #150 from lightsparkdev/fix/overloads
shreyav Feb 7, 2024
f93008d
Merge pull request #149 from lightsparkdev/feat/lnurlp-fallback
shreyav Feb 7, 2024
570790e
fallback sender side
shreyav Feb 6, 2024
3fdd4b7
fix serialization
shreyav Feb 8, 2024
18f9ff5
unused import
shreyav Feb 8, 2024
3acf947
comments
shreyav Feb 8, 2024
9dd1184
Merge pull request #151 from lightsparkdev/feat/fallback-lnurlp-sender
shreyav Feb 8, 2024
b7b8501
fixes
shreyav Feb 9, 2024
ebea915
Merge pull request #152 from lightsparkdev/fix/lnurl-sender
shreyav Feb 9, 2024
ba616af
Try to fix docs publish job my running on main
jklein24 Feb 13, 2024
561bbda
Merge pull request #153 from lightsparkdev/fix/docspublish
jklein24 Feb 13, 2024
d650245
[gha] Use environment for doc-publish
mgorven Feb 13, 2024
b3ab9b1
[gha] Use environment for doc-publish
mgorven Feb 13, 2024
3410b5e
Fix sender vasp utxo callback
shreyav Feb 15, 2024
d44c831
Merge pull request #155 from lightsparkdev/fix/sender-vasp
shreyav Feb 15, 2024
e88f6fe
Switch to a full 64bit nonce
jklein24 Feb 21, 2024
99d182f
Merge pull request #156 from lightsparkdev/fix/64bitnonce
jklein24 Feb 21, 2024
63b654b
Use json for parsing in demo vasp (#163)
shreyav Mar 19, 2024
9aef4ff
Update the demo VASP's SDK version to 0.8.0
jklein24 Mar 21, 2024
b6066e8
Merge pull request #165 from lightsparkdev/feat/updatevaspsdk
jklein24 Mar 21, 2024
f10605e
Update the demo VASP's SDK version to 0.8.1
jklein24 Mar 21, 2024
dee939d
Merge pull request #166 from lightsparkdev/feat/updatevaspsdk2
jklein24 Mar 23, 2024
7d9733e
Accept gzip responses, compress request with deflate (#172)
mgorven May 13, 2024
9a954d4
Regenerate SDK (#173)
shreyav Jun 22, 2024
b411657
Update macos environment version (#175)
shreyav Jun 25, 2024
59d4a35
Uma data visibility (#174)
shreyav Jun 25, 2024
3003ada
fix typo (#176)
shreyav Jun 26, 2024
ba09e4c
encode hex (#177)
shreyav Jun 28, 2024
4a254c3
Bump lightspark-sdk to version 0.14.0
Jul 9, 2024
ea71c6d
Merge pull request #178 from lightsparkdev/release/lightspark-sdk-v0.…
github-actions[bot] Jul 9, 2024
ba193a7
Merge branch 'main' into merge/main
jklein24 Jul 9, 2024
9904b3e
Load signing key
jklein24 Jul 9, 2024
dc7a477
Merge pull request #180 from lightsparkdev/merge/main
jklein24 Jul 9, 2024
fd7723e
Revert "Merge release/lightspark-sdk-v0.14.0 into develop" (#181)
shreyav Jul 9, 2024
65d0d91
Bump lightspark-sdk to version 0.14.0
Jul 9, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/core-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:

jobs:
build:
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/core-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
publish-core-sdk:
if: ${{ startsWith(github.event.release.tag_name, 'core-') }}
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/crypto-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build:
# No point in running this build on a core cut because it will fail until the deploy is done.
if: github.event.base_ref == null || !startsWith(github.event.base_ref, 'release/core-')
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/crypto-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
publish-crypto-sdk:
if: ${{ startsWith(github.event.release.tag_name, 'crypto-') }}
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/docs-publish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Publish SDK Docs

on:
workflow_dispatch: {}
workflow_run:
workflows:
[
Expand All @@ -15,13 +16,16 @@ on:
jobs:
publish-docs:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: macos-11
runs-on: macos-12
environment: "docs"
permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v3
with:
ref: "main"
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lightspark-sdk-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
build:
# No point in running this build on a core cut because it will fail until the deploy is done.
if: github.event.base_ref == null || !startsWith(github.event.base_ref, 'release/core-')
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lightspark-sdk-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
publish-lightspark-sdk:
if: ${{ startsWith(github.event.release.tag_name, 'lightspark-sdk-') }}
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-branch-cut.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
bump-versions:
runs-on: macos-11
runs-on: macos-12
permissions:
contents: write
pull-requests: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wallet-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
build:
# No point in running this build on a core cut because it will fail until the deploy is done.
if: github.event.base_ref == null || !startsWith(github.event.base_ref, 'release/core-')
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wallet-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
publish-wallet-sdk:
if: ${{ startsWith(github.event.release.tag_name, 'wallet-sdk-') }}
runs-on: macos-11
runs-on: macos-12

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ kotlin {
api(libs.kotlinx.datetime)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.encoding)
// implementation(project(":crypto"))
implementation(libs.lightspark.crypto)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.lightspark.sdk.core.crypto

import java.security.SecureRandom

internal actual fun nextInt(): Int {
return SecureRandom().nextInt()
internal actual fun nextLong(): Long {
return SecureRandom().nextLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package com.lightspark.sdk.core.crypto

internal expect fun nextInt(): Int
internal expect fun nextLong(): Long
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import com.lightspark.sdk.core.LightsparkException
import com.lightspark.sdk.core.auth.AuthProvider
import com.lightspark.sdk.core.crypto.MissingKeyException
import com.lightspark.sdk.core.crypto.NodeKeyCache
import com.lightspark.sdk.core.crypto.nextInt
import com.lightspark.sdk.core.crypto.nextLong
import com.lightspark.sdk.core.util.getPlatform
import io.ktor.client.HttpClient
import io.ktor.client.plugins.compression.ContentEncoding
import io.ktor.client.plugins.websocket.WebSockets
import io.ktor.client.request.headers
import io.ktor.client.request.post
Expand All @@ -21,6 +22,7 @@ import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
import kotlin.coroutines.cancellation.CancellationException
import kotlin.math.absoluteValue
import kotlin.time.Duration.Companion.hours
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
Expand All @@ -34,6 +36,7 @@ import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import java.util.zip.Deflater

private const val DEFAULT_BASE_URL = "api.lightspark.com"

Expand All @@ -45,6 +48,9 @@ class Requester constructor(
private val baseUrl: String = DEFAULT_BASE_URL,
) {
private val httpClient = HttpClient {
install(ContentEncoding) {
gzip() // Switch to deflate() when https://youtrack.jetbrains.com/issue/KTOR-6999 is fixed
}
install(WebSockets)
}
private val userAgent =
Expand Down Expand Up @@ -87,15 +93,15 @@ class Requester constructor(
)
}
val operation = operationMatch.groupValues[2]
var bodyData = buildJsonObject {
var payload = buildJsonObject {
put("query", JsonPrimitive(queryPayload))
variables?.let { put("variables", it) }
put("operationName", JsonPrimitive(operation))
}
var headers = defaultHeaders + authProvider.getCredentialHeaders()
var headers = defaultHeaders + authProvider.getCredentialHeaders() + mapOf("X-GraphQL-Operation" to operation)
val signedBodyAndHeaders = try {
addSigningDataIfNeeded(
bodyData,
payload,
headers,
signingNodeId,
)
Expand All @@ -106,11 +112,25 @@ class Requester constructor(
e,
)
}
bodyData = signedBodyAndHeaders.first
var body = signedBodyAndHeaders.first
headers = signedBodyAndHeaders.second

if (body.size > 1024) {
val output = ByteArray(body.size)
val deflater = Deflater(Deflater.BEST_SPEED)
deflater.setInput(body)
deflater.finish()
val length = deflater.deflate(output)
deflater.end()
body = output.copyOfRange(0, length)

headers = headers.toMutableMap().apply {
this["Content-Encoding"] = "deflate"
}
}

val response = httpClient.post("https://$baseUrl/$schemaEndpoint") {
setBody(bodyData.toString())
setBody(body)
headers {
headers.forEach { (key, value) ->
append(key, value)
Expand Down Expand Up @@ -193,27 +213,27 @@ class Requester constructor(
bodyData: JsonObject,
headers: Map<String, String>,
signingNodeId: String?,
): Pair<JsonObject, Map<String, String>> {
): Pair<ByteArray, Map<String, String>> {
if (signingNodeId == null) {
return bodyData to headers
return bodyData.toString().encodeToByteArray() to headers
}
if (!nodeKeyCache.contains(signingNodeId)) {
throw MissingKeyException(signingNodeId)
}

val newBodyData = bodyData.toMutableMap().apply {
// Note: The nonce is a 64-bit unsigned integer, but the Kotlin random number generator wants to
// spit out a signed int, which the backend can't decode.
put("nonce", JsonPrimitive(nextInt().toUInt().toLong()))
// spit out a signed int, which the backend can't decode, so we take the absolute value.
put("nonce", JsonPrimitive(nextLong().absoluteValue))
put("expires_at", JsonPrimitive(anHourFromNowISOString()))
}.let { JsonObject(it) }
val newBodyString = Json.encodeToString(newBodyData)
val signature = nodeKeyCache[signingNodeId].sign(newBodyString.encodeToByteArray())
val newBodyString = newBodyData.toString().encodeToByteArray()
val signature = nodeKeyCache[signingNodeId].sign(newBodyString)
val newHeaders = headers.toMutableMap().apply {
this["X-LIGHTSPARK-SIGNING"] =
"{\"v\":1,\"signature\":\"${signature.base64Encoded}\"}"
}
return newBodyData to newHeaders
return newBodyString to newHeaders
}

private fun anHourFromNowISOString() = Clock.System.now().plus(1.hours).toString()
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ ktor-client-serialization = { module = "io.ktor:ktor-client-serialization", vers
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
ktor-client-encoding = { module = "io.ktor:ktor-client-encoding", version.ref = "ktor" }

kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }

Expand Down Expand Up @@ -140,4 +141,4 @@ ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
gradleS3 = { id = "com.mgd.core.gradle.s3", version.ref = "gradleS3" }
downloadFile = { id = "de.undercouch.download", version.ref = "downloadFile" }
downloadFile = { id = "de.undercouch.download", version.ref = "downloadFile" }
Loading