Skip to content

Commit 934e765

Browse files
Merge branch 'develop' into aaryaman/lpt-263-create-releasepaymentpreimage-function
2 parents 01cf641 + 242a9ba commit 934e765

File tree

6 files changed

+93
-4
lines changed

6 files changed

+93
-4
lines changed

lightspark-sdk/src/commonJvmAndroidMain/kotlin/com/lightspark/sdk/LightsparkFuturesClient.kt

+27-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class LightsparkFuturesClient(config: ClientConfig) {
144144
* @param memo Optional memo to include in the invoice.
145145
* @param type The type of invoice to create. Defaults to [InvoiceType.STANDARD].
146146
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
147+
* @param paymentHash Optional payment hash to include in the invoice.
148+
* @param preimageNonce Optional preimage nonce to include in the invoice.
147149
*/
148150
@JvmOverloads
149151
fun createInvoice(
@@ -152,8 +154,20 @@ class LightsparkFuturesClient(config: ClientConfig) {
152154
memo: String? = null,
153155
type: InvoiceType = InvoiceType.STANDARD,
154156
expirySecs: Int? = null,
157+
paymentHash: String? = null,
158+
preimageNonce: String? = null,
155159
): CompletableFuture<Invoice> =
156-
coroutineScope.future { coroutinesClient.createInvoice(nodeId, amountMsats, memo, type, expirySecs) }
160+
coroutineScope.future {
161+
coroutinesClient.createInvoice(
162+
nodeId,
163+
amountMsats,
164+
memo,
165+
type,
166+
expirySecs,
167+
paymentHash,
168+
preimageNonce,
169+
)
170+
}
157171

158172
/**
159173
* Creates a Lightning invoice for the given node. This should only be used for generating invoices for LNURLs, with
@@ -164,20 +178,26 @@ class LightsparkFuturesClient(config: ClientConfig) {
164178
* @param metadata The LNURL metadata payload field from the initial payreq response. This will be hashed and
165179
* present in the h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice.
166180
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
181+
* @param paymentHash Optional payment hash to include in the invoice.
182+
* @param preimageNonce Optional preimage nonce to include in the invoice.
167183
*/
168184
@JvmOverloads
169185
fun createLnurlInvoice(
170186
nodeId: String,
171187
amountMsats: Long,
172188
metadata: String,
173189
expirySecs: Int? = null,
190+
paymentHash: String? = null,
191+
preimageNonce: String? = null,
174192
): CompletableFuture<Invoice> =
175193
coroutineScope.future {
176194
coroutinesClient.createLnurlInvoice(
177195
nodeId,
178196
amountMsats,
179197
metadata,
180198
expirySecs,
199+
paymentHash,
200+
preimageNonce,
181201
)
182202
}
183203

@@ -193,6 +213,8 @@ class LightsparkFuturesClient(config: ClientConfig) {
193213
* @param signingPrivateKey The receiver's signing private key. Used to hash the receiver identifier.
194214
* @param receiverIdentifier Optional identifier of the receiver. If provided, this will be hashed using a
195215
* monthly-rotated seed and used for anonymized analysis.
216+
* @param paymentHash Optional payment hash to include in the invoice.
217+
* @param preimageNonce Optional preimage nonce to include in the invoice.
196218
*/
197219
@JvmOverloads
198220
@Throws(IllegalArgumentException::class)
@@ -203,6 +225,8 @@ class LightsparkFuturesClient(config: ClientConfig) {
203225
expirySecs: Int? = null,
204226
signingPrivateKey: ByteArray? = null,
205227
receiverIdentifier: String? = null,
228+
paymentHash: String? = null,
229+
preimageNonce: String? = null,
206230
): CompletableFuture<Invoice> =
207231
coroutineScope.future {
208232
coroutinesClient.createUmaInvoice(
@@ -212,6 +236,8 @@ class LightsparkFuturesClient(config: ClientConfig) {
212236
expirySecs,
213237
signingPrivateKey,
214238
receiverIdentifier,
239+
paymentHash,
240+
preimageNonce,
215241
)
216242
}
217243

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkCoroutinesClient.kt

+18
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,17 @@ class LightsparkCoroutinesClient private constructor(
206206
* @param memo Optional memo to include in the invoice.
207207
* @param type The type of invoice to create. Defaults to [InvoiceType.STANDARD].
208208
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
209+
* @param paymentHash Optional payment hash to include in the invoice.
210+
* @param preimageNonce Optional preimage nonce to include in the invoice.
209211
*/
210212
suspend fun createInvoice(
211213
nodeId: String,
212214
amountMsats: Long,
213215
memo: String? = null,
214216
type: InvoiceType = InvoiceType.STANDARD,
215217
expirySecs: Int? = null,
218+
paymentHash: String? = null,
219+
preimageNonce: String? = null,
216220
): Invoice {
217221
requireValidAuth()
218222
return executeQuery(
@@ -224,6 +228,8 @@ class LightsparkCoroutinesClient private constructor(
224228
memo?.let { add("memo", memo) }
225229
add("type", serializerFormat.encodeToJsonElement(type))
226230
expirySecs?.let { add("expirySecs", expirySecs) }
231+
paymentHash?.let { add("paymentHash", paymentHash) }
232+
preimageNonce?.let { add("preimageNonce", preimageNonce) }
227233
},
228234
) {
229235
val invoiceJson =
@@ -244,12 +250,16 @@ class LightsparkCoroutinesClient private constructor(
244250
* @param metadata The LNURL metadata payload field from the initial payreq response. This will be hashed and
245251
* present in the h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice.
246252
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
253+
* @param paymentHash Optional payment hash to include in the invoice.
254+
* @param preimageNonce Optional preimage nonce to include in the invoice.
247255
*/
248256
suspend fun createLnurlInvoice(
249257
nodeId: String,
250258
amountMsats: Long,
251259
metadata: String,
252260
expirySecs: Int? = null,
261+
paymentHash: String? = null,
262+
preimageNonce: String? = null,
253263
): Invoice {
254264
requireValidAuth()
255265

@@ -265,6 +275,8 @@ class LightsparkCoroutinesClient private constructor(
265275
add("amountMsats", amountMsats)
266276
add("metadataHash", metadataHash)
267277
expirySecs?.let { add("expirySecs", expirySecs) }
278+
paymentHash?.let { add("paymentHash", paymentHash) }
279+
preimageNonce?.let { add("preimageNonce", preimageNonce) }
268280
},
269281
) {
270282
val invoiceJson =
@@ -288,6 +300,8 @@ class LightsparkCoroutinesClient private constructor(
288300
* @param signingPrivateKey The receiver's signing private key. Used to hash the receiver identifier.
289301
* @param receiverIdentifier Optional identifier of the receiver. If provided, this will be hashed using a
290302
* monthly-rotated seed and used for anonymized analysis.
303+
* @param paymentHash Optional payment hash to include in the invoice.
304+
* @param preimageNonce Optional preimage nonce to include in the invoice.
291305
*/
292306
@Throws(IllegalArgumentException::class)
293307
suspend fun createUmaInvoice(
@@ -297,6 +311,8 @@ class LightsparkCoroutinesClient private constructor(
297311
expirySecs: Int? = null,
298312
signingPrivateKey: ByteArray? = null,
299313
receiverIdentifier: String? = null,
314+
paymentHash: String? = null,
315+
preimageNonce: String? = null,
300316
): Invoice {
301317
requireValidAuth()
302318

@@ -320,6 +336,8 @@ class LightsparkCoroutinesClient private constructor(
320336
add("metadataHash", metadataHash)
321337
expirySecs?.let { add("expirySecs", expirySecs) }
322338
receiverHash?.let { add("receiverHash", receiverHash) }
339+
paymentHash?.let { add("paymentHash", paymentHash) }
340+
preimageNonce?.let { add("preimageNonce", preimageNonce) }
323341
},
324342
) {
325343
val invoiceJson =

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/LightsparkSyncClient.kt

+27-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
124124
* @param memo Optional memo to include in the invoice.
125125
* @param type The type of invoice to create. Defaults to [InvoiceType.STANDARD].
126126
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
127+
* @param paymentHash Optional payment hash to include in the invoice.
128+
* @param preimageNonce Optional preimage nonce to include in the invoice.
127129
*/
128130
@JvmOverloads
129131
fun createInvoice(
@@ -132,7 +134,19 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
132134
memo: String? = null,
133135
type: InvoiceType = InvoiceType.STANDARD,
134136
expirySecs: Int? = null,
135-
): Invoice = runBlocking { asyncClient.createInvoice(nodeId, amountMsats, memo, type, expirySecs) }
137+
paymentHash: String? = null,
138+
preimageNonce: String? = null,
139+
): Invoice = runBlocking {
140+
asyncClient.createInvoice(
141+
nodeId,
142+
amountMsats,
143+
memo,
144+
type,
145+
expirySecs,
146+
paymentHash,
147+
preimageNonce,
148+
)
149+
}
136150

137151
/**
138152
* Creates a Lightning invoice for the given node. This should only be used for generating invoices for LNURLs, with
@@ -143,19 +157,25 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
143157
* @param metadata The LNURL metadata payload field from the initial payreq response. This will be hashed and
144158
* present in the h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice.
145159
* @param expirySecs The number of seconds until the invoice expires. Defaults to 1 day.
160+
* @param paymentHash Optional payment hash to include in the invoice.
161+
* @param preimageNonce Optional preimage nonce to include in the invoice.
146162
*/
147163
@JvmOverloads
148164
fun createLnurlInvoice(
149165
nodeId: String,
150166
amountMsats: Long,
151167
metadata: String,
152168
expirySecs: Int? = null,
169+
paymentHash: String? = null,
170+
preimageNonce: String? = null,
153171
): Invoice = runBlocking {
154172
asyncClient.createLnurlInvoice(
155173
nodeId,
156174
amountMsats,
157175
metadata,
158176
expirySecs,
177+
paymentHash,
178+
preimageNonce,
159179
)
160180
}
161181

@@ -171,6 +191,8 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
171191
* @param signingPrivateKey The receiver's signing private key. Used to hash the receiver identifier.
172192
* @param receiverIdentifier Optional identifier of the receiver. If provided, this will be hashed using a
173193
* monthly-rotated seed and used for anonymized analysis.
194+
* @param paymentHash Optional payment hash to include in the invoice.
195+
* @param preimageNonce Optional preimage nonce to include in the invoice.
174196
*/
175197
@JvmOverloads
176198
@Throws(IllegalArgumentException::class)
@@ -181,6 +203,8 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
181203
expirySecs: Int? = null,
182204
signingPrivateKey: ByteArray? = null,
183205
receiverIdentifier: String? = null,
206+
paymentHash: String? = null,
207+
preimageNonce: String? = null,
184208
): Invoice = runBlocking {
185209
asyncClient.createUmaInvoice(
186210
nodeId,
@@ -189,6 +213,8 @@ class LightsparkSyncClient constructor(config: ClientConfig) {
189213
expirySecs,
190214
signingPrivateKey,
191215
receiverIdentifier,
216+
paymentHash,
217+
preimageNonce,
192218
)
193219
}
194220

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/graphql/CreateInvoice.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@ const val CreateInvoiceMutation = """
99
${'$'}memo: String
1010
${'$'}type: InvoiceType = null
1111
${'$'}expirySecs: Int = null
12+
${'$'}paymentHash: Hash32 = null
13+
${'$'}preimageNonce: Hash32 = null
1214
) {
13-
create_invoice(input: { node_id: ${'$'}nodeId, amount_msats: ${'$'}amountMsats, memo: ${'$'}memo, invoice_type: ${'$'}type, expiry_secs: ${'$'}expirySecs }) {
15+
create_invoice(
16+
input: {
17+
node_id: ${'$'}nodeId
18+
amount_msats: ${'$'}amountMsats
19+
memo: ${'$'}memo
20+
invoice_type: ${'$'}type
21+
expiry_secs: ${'$'}expirySecs
22+
payment_hash: ${'$'}paymentHash
23+
preimage_nonce: ${'$'}preimageNonce
24+
}) {
1425
invoice {
1526
...InvoiceFragment
1627
}

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/graphql/CreateLnurlInvoice.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const val CreateLnurlInvoiceMutation = """
99
${'$'}metadataHash: String!
1010
${'$'}expirySecs: Int = null
1111
${'$'}receiverHash: String = null
12+
${'$'}paymentHash: Hash32 = null
13+
${'$'}preimageNonce: Hash32 = null
1214
) {
1315
create_lnurl_invoice(
1416
input: {
@@ -17,7 +19,9 @@ const val CreateLnurlInvoiceMutation = """
1719
metadata_hash: ${'$'}metadataHash
1820
expiry_secs: ${'$'}expirySecs
1921
receiver_hash: ${'$'}receiverHash
20-
}
22+
payment_hash: ${'$'}paymentHash
23+
preimage_nonce: ${'$'}preimageNonce
24+
}
2125
) {
2226
invoice {
2327
...InvoiceFragment

lightspark-sdk/src/commonMain/kotlin/com/lightspark/sdk/graphql/CreateUmaInvoice.kt

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const val CreateUmaInvoiceMutation = """
99
${'$'}metadataHash: String!
1010
${'$'}expirySecs: Int = null
1111
${'$'}receiverHash: String = null
12+
${'$'}paymentHash: Hash32 = null
13+
${'$'}preimageNonce: Hash32 = null
1214
) {
1315
create_uma_invoice(
1416
input: {
@@ -17,6 +19,8 @@ const val CreateUmaInvoiceMutation = """
1719
metadata_hash: ${'$'}metadataHash
1820
expiry_secs: ${'$'}expirySecs
1921
receiver_hash: ${'$'}receiverHash
22+
payment_hash: ${'$'}paymentHash
23+
preimage_nonce: ${'$'}preimageNonce
2024
}
2125
) {
2226
invoice {

0 commit comments

Comments
 (0)