@lightsparkdev/lightspark-sdk 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/{Withdrawal-82dbbfd6.d.ts → Withdrawal-e4b8b697.d.ts} +31 -6
- package/dist/{chunk-2T6E6TXJ.js → chunk-7GDCZ2RB.js} +9 -9
- package/dist/index.cjs +871 -768
- package/dist/index.d.ts +1 -1
- package/dist/index.js +118 -15
- package/dist/objects/index.d.ts +1 -1
- package/dist/objects/index.js +1 -1
- package/package.json +2 -2
- package/src/client.ts +90 -8
- package/src/graphql/CreateTestModeInvoice.ts +19 -0
- package/src/graphql/CreateTestModePayment.ts +23 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthProvider } from '@lightsparkdev/core';
|
|
2
|
-
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BitcoinNetwork, j as BlockchainBalance, C as Channel, k as ChannelClosingTransaction, m as ChannelFees, n as ChannelOpeningTransaction, p as ChannelStatus, q as ChannelToTransactionsConnection, r as CreateApiTokenInput, s as CreateApiTokenOutput, t as CreateInvoiceInput, u as CreateInvoiceOutput, v as CreateNodeWalletAddressInput, w as CreateNodeWalletAddressOutput, x as CreateTestModeInvoiceInput, y as CreateTestModeInvoiceOutput, z as CreateTestModePaymentInput, D as CreateTestModePaymentoutput, E as CurrencyAmount, F as CurrencyUnit, G as DeleteApiTokenInput, H as DeleteApiTokenOutput, I as Deposit, K as Entity, M as FeeEstimate, N as FundNodeInput, O as FundNodeOutput, P as GraphNode, Q as Hop, S as HtlcAttemptFailureCode, T as IncomingPayment, U as IncomingPaymentAttempt, W as IncomingPaymentAttemptStatus, X as IncomingPaymentToAttemptsConnection, Y as Invoice, _ as InvoiceData, $ as InvoiceType, a0 as LightningFeeEstimateForInvoiceInput, a1 as LightningFeeEstimateForNodeInput, a2 as LightningFeeEstimateOutput, a3 as LightningTransaction, L as LightsparkClient, a5 as LightsparkNode, a6 as LightsparkNodePurpose, a7 as LightsparkNodeStatus, a8 as LightsparkNodeToChannelsConnection, a9 as Node, aa as NodeAddress, ab as NodeAddressType, ac as NodeToAddressesConnection, ad as OnChainTransaction, af as OutgoingPayment, ag as OutgoingPaymentAttempt, ah as OutgoingPaymentAttemptStatus, ai as OutgoingPaymentAttemptToHopsConnection, aj as OutgoingPaymentToAttemptsConnection, ak as PageInfo, al as PayInvoiceInput, am as PayInvoiceOutput, an as PaymentFailureReason, ao as PaymentRequest, aq as PaymentRequestData, ar as PaymentRequestStatus, as as Permission, at as RequestWithdrawalInput, au as RequestWithdrawalOutput, av as RichText, aw as RoutingTransaction, ay as RoutingTransactionFailureReason, az as Secret, aA as SendPaymentInput, aB as SendPaymentOutput, aC as SingleNodeDashboard, aD as Transaction, aF as TransactionFailures, aG as TransactionStatus, aH as TransactionType, aI as TransactionUpdate, aJ as Wallet, aK as WebhookEventType, aL as Withdrawal, aN as WithdrawalMode, aO as WithdrawalRequest, aP as WithdrawalRequestStatus, aQ as WithdrawalRequestToChannelClosingTransactionsConnection, aR as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, l as getChannelClosingTransactionQuery, o as getChannelOpeningTransactionQuery, J as getDepositQuery, R as getHopQuery, V as getIncomingPaymentAttemptQuery, Z as getInvoiceQuery, a4 as getLightningTransactionQuery, ae as getOnChainTransactionQuery, ap as getPaymentRequestQuery, ax as getRoutingTransactionQuery, aE as getTransactionQuery, aM as getWithdrawalQuery } from './Withdrawal-
|
|
2
|
+
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BitcoinNetwork, j as BlockchainBalance, C as Channel, k as ChannelClosingTransaction, m as ChannelFees, n as ChannelOpeningTransaction, p as ChannelStatus, q as ChannelToTransactionsConnection, r as CreateApiTokenInput, s as CreateApiTokenOutput, t as CreateInvoiceInput, u as CreateInvoiceOutput, v as CreateNodeWalletAddressInput, w as CreateNodeWalletAddressOutput, x as CreateTestModeInvoiceInput, y as CreateTestModeInvoiceOutput, z as CreateTestModePaymentInput, D as CreateTestModePaymentoutput, E as CurrencyAmount, F as CurrencyUnit, G as DeleteApiTokenInput, H as DeleteApiTokenOutput, I as Deposit, K as Entity, M as FeeEstimate, N as FundNodeInput, O as FundNodeOutput, P as GraphNode, Q as Hop, S as HtlcAttemptFailureCode, T as IncomingPayment, U as IncomingPaymentAttempt, W as IncomingPaymentAttemptStatus, X as IncomingPaymentToAttemptsConnection, Y as Invoice, _ as InvoiceData, $ as InvoiceType, a0 as LightningFeeEstimateForInvoiceInput, a1 as LightningFeeEstimateForNodeInput, a2 as LightningFeeEstimateOutput, a3 as LightningTransaction, L as LightsparkClient, a5 as LightsparkNode, a6 as LightsparkNodePurpose, a7 as LightsparkNodeStatus, a8 as LightsparkNodeToChannelsConnection, a9 as Node, aa as NodeAddress, ab as NodeAddressType, ac as NodeToAddressesConnection, ad as OnChainTransaction, af as OutgoingPayment, ag as OutgoingPaymentAttempt, ah as OutgoingPaymentAttemptStatus, ai as OutgoingPaymentAttemptToHopsConnection, aj as OutgoingPaymentToAttemptsConnection, ak as PageInfo, al as PayInvoiceInput, am as PayInvoiceOutput, an as PaymentFailureReason, ao as PaymentRequest, aq as PaymentRequestData, ar as PaymentRequestStatus, as as Permission, at as RequestWithdrawalInput, au as RequestWithdrawalOutput, av as RichText, aw as RoutingTransaction, ay as RoutingTransactionFailureReason, az as Secret, aA as SendPaymentInput, aB as SendPaymentOutput, aC as SingleNodeDashboard, aD as Transaction, aF as TransactionFailures, aG as TransactionStatus, aH as TransactionType, aI as TransactionUpdate, aJ as Wallet, aK as WebhookEventType, aL as Withdrawal, aN as WithdrawalMode, aO as WithdrawalRequest, aP as WithdrawalRequestStatus, aQ as WithdrawalRequestToChannelClosingTransactionsConnection, aR as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, l as getChannelClosingTransactionQuery, o as getChannelOpeningTransactionQuery, J as getDepositQuery, R as getHopQuery, V as getIncomingPaymentAttemptQuery, Z as getInvoiceQuery, a4 as getLightningTransactionQuery, ae as getOnChainTransactionQuery, ap as getPaymentRequestQuery, ax as getRoutingTransactionQuery, aE as getTransactionQuery, aM as getWithdrawalQuery } from './Withdrawal-e4b8b697.js';
|
|
3
3
|
import 'zen-observable';
|
|
4
4
|
|
|
5
5
|
declare class AccountTokenAuthProvider implements AuthProvider {
|
package/dist/index.js
CHANGED
|
@@ -60,14 +60,14 @@ import {
|
|
|
60
60
|
getRoutingTransactionQuery,
|
|
61
61
|
getTransactionQuery,
|
|
62
62
|
getWithdrawalQuery
|
|
63
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-7GDCZ2RB.js";
|
|
64
64
|
|
|
65
65
|
// package.json
|
|
66
66
|
var require_package = __commonJS({
|
|
67
67
|
"package.json"(exports, module) {
|
|
68
68
|
module.exports = {
|
|
69
69
|
name: "@lightsparkdev/lightspark-sdk",
|
|
70
|
-
version: "0.
|
|
70
|
+
version: "0.3.0",
|
|
71
71
|
description: "Lightspark JS SDK",
|
|
72
72
|
author: "Lightspark Inc.",
|
|
73
73
|
keywords: [
|
|
@@ -135,7 +135,7 @@ var require_package = __commonJS({
|
|
|
135
135
|
},
|
|
136
136
|
license: "Apache-2.0",
|
|
137
137
|
dependencies: {
|
|
138
|
-
"@lightsparkdev/core": "0.
|
|
138
|
+
"@lightsparkdev/core": "0.3.0",
|
|
139
139
|
"auto-bind": "^5.0.1",
|
|
140
140
|
crypto: "^1.0.1",
|
|
141
141
|
"crypto-browserify": "^3.12.0",
|
|
@@ -192,13 +192,14 @@ var AccountTokenAuthProvider = class {
|
|
|
192
192
|
var AccountTokenAuthProvider_default = AccountTokenAuthProvider;
|
|
193
193
|
|
|
194
194
|
// src/client.ts
|
|
195
|
-
import { LightsparkSigningException } from "@lightsparkdev/core";
|
|
196
195
|
import autoBind2 from "auto-bind";
|
|
197
196
|
import {
|
|
198
197
|
b64encode as b64encode2,
|
|
199
198
|
DefaultCrypto,
|
|
199
|
+
KeyOrAlias,
|
|
200
200
|
LightsparkAuthException,
|
|
201
201
|
LightsparkException,
|
|
202
|
+
LightsparkSigningException,
|
|
202
203
|
NodeKeyCache,
|
|
203
204
|
Requester,
|
|
204
205
|
StubAuthProvider
|
|
@@ -266,6 +267,46 @@ var CreateNodeWalletAddress = `
|
|
|
266
267
|
}
|
|
267
268
|
`;
|
|
268
269
|
|
|
270
|
+
// src/graphql/CreateTestModeInvoice.ts
|
|
271
|
+
var CreateTestModeInvoice = `
|
|
272
|
+
mutation CreateTestModeInvoice(
|
|
273
|
+
$local_node_id: ID!
|
|
274
|
+
$amount_msats: Long!
|
|
275
|
+
$memo: String
|
|
276
|
+
$invoice_type: InvoiceType
|
|
277
|
+
) {
|
|
278
|
+
create_test_mode_invoice(input: {
|
|
279
|
+
local_node_id: $local_node_id
|
|
280
|
+
amount_msats: $amount_msats
|
|
281
|
+
memo: $memo
|
|
282
|
+
invoice_type: $invoice_type
|
|
283
|
+
}) {
|
|
284
|
+
encoded_payment_request
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
`;
|
|
288
|
+
|
|
289
|
+
// src/graphql/CreateTestModePayment.ts
|
|
290
|
+
var CreateTestModePayment = `
|
|
291
|
+
mutation CreateTestModePayment(
|
|
292
|
+
$local_node_id: ID!
|
|
293
|
+
$encoded_invoice: String!
|
|
294
|
+
$amount_msats: Long
|
|
295
|
+
) {
|
|
296
|
+
create_test_mode_payment(input: {
|
|
297
|
+
local_node_id: $local_node_id
|
|
298
|
+
encoded_invoice: $encoded_invoice
|
|
299
|
+
amount_msats: $amount_msats
|
|
300
|
+
}) {
|
|
301
|
+
payment {
|
|
302
|
+
...OutgoingPaymentFragment
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
${FRAGMENT4}
|
|
308
|
+
`;
|
|
309
|
+
|
|
269
310
|
// src/graphql/DecodeInvoice.ts
|
|
270
311
|
var DecodeInvoice = `
|
|
271
312
|
query DecodeInvoice($encoded_payment_request: String!) {
|
|
@@ -277,7 +318,7 @@ var DecodeInvoice = `
|
|
|
277
318
|
}
|
|
278
319
|
}
|
|
279
320
|
|
|
280
|
-
${
|
|
321
|
+
${FRAGMENT5}
|
|
281
322
|
`;
|
|
282
323
|
|
|
283
324
|
// src/graphql/DeleteApiToken.ts
|
|
@@ -325,7 +366,7 @@ var LightningFeeEstimateForInvoice = `
|
|
|
325
366
|
}
|
|
326
367
|
}
|
|
327
368
|
|
|
328
|
-
${
|
|
369
|
+
${FRAGMENT6}
|
|
329
370
|
`;
|
|
330
371
|
|
|
331
372
|
// src/graphql/LightningFeeEstimateForNode.ts
|
|
@@ -344,7 +385,7 @@ var LightningFeeEstimateForNode = `
|
|
|
344
385
|
}
|
|
345
386
|
}
|
|
346
387
|
|
|
347
|
-
${
|
|
388
|
+
${FRAGMENT6}
|
|
348
389
|
`;
|
|
349
390
|
|
|
350
391
|
// src/graphql/MultiNodeDashboard.ts
|
|
@@ -447,7 +488,7 @@ var PayInvoice = `
|
|
|
447
488
|
}
|
|
448
489
|
}
|
|
449
490
|
|
|
450
|
-
${
|
|
491
|
+
${FRAGMENT4}
|
|
451
492
|
`;
|
|
452
493
|
|
|
453
494
|
// src/graphql/RecoverNodeSigningKey.ts
|
|
@@ -512,7 +553,7 @@ var SendPayment = `
|
|
|
512
553
|
}
|
|
513
554
|
}
|
|
514
555
|
|
|
515
|
-
${
|
|
556
|
+
${FRAGMENT4}
|
|
516
557
|
`;
|
|
517
558
|
|
|
518
559
|
// src/graphql/SingleNodeDashboard.ts
|
|
@@ -689,8 +730,8 @@ var LightsparkClient = class {
|
|
|
689
730
|
* @param authProvider The auth provider to use for authentication. Defaults to a stub auth provider. For server-side
|
|
690
731
|
* use, you should use the `AccountTokenAuthProvider`.
|
|
691
732
|
* @param serverUrl The base URL of the server to connect to. Defaults to lightspark production.
|
|
692
|
-
* @param
|
|
693
|
-
*
|
|
733
|
+
* @param cryptoImpl The crypto implementation to use. Defaults to web and node compatible crypto.
|
|
734
|
+
* For React Native, you should use the `ReactNativeCrypto` implementation from `@lightsparkdev/react-native`.
|
|
694
735
|
*/
|
|
695
736
|
constructor(authProvider = new StubAuthProvider(), serverUrl = "api.lightspark.com", cryptoImpl = DefaultCrypto) {
|
|
696
737
|
this.authProvider = authProvider;
|
|
@@ -919,6 +960,8 @@ var LightsparkClient = class {
|
|
|
919
960
|
/**
|
|
920
961
|
* Creates an invoice for the given node.
|
|
921
962
|
*
|
|
963
|
+
* Test mode note: You can simulate a payment of this invoice in test move using [createTestModePayment].
|
|
964
|
+
*
|
|
922
965
|
* @param nodeId The node ID for which to create an invoice.
|
|
923
966
|
* @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
|
|
924
967
|
* @param memo A string memo to include in the invoice as a description.
|
|
@@ -1036,7 +1079,10 @@ var LightsparkClient = class {
|
|
|
1036
1079
|
const dec = new TextDecoder();
|
|
1037
1080
|
signingPrivateKeyPEM = dec.decode(signingPrivateKey);
|
|
1038
1081
|
}
|
|
1039
|
-
await this.nodeKeyCache.loadKey(
|
|
1082
|
+
await this.nodeKeyCache.loadKey(
|
|
1083
|
+
nodeId,
|
|
1084
|
+
KeyOrAlias.key(signingPrivateKeyPEM)
|
|
1085
|
+
);
|
|
1040
1086
|
return true;
|
|
1041
1087
|
}
|
|
1042
1088
|
async recoverNodeSigningKey(nodeId) {
|
|
@@ -1051,17 +1097,20 @@ var LightsparkClient = class {
|
|
|
1051
1097
|
return null;
|
|
1052
1098
|
}
|
|
1053
1099
|
/**
|
|
1054
|
-
* Directly unlocks a node with a signing private key.
|
|
1100
|
+
* Directly unlocks a node with a signing private key or alias.
|
|
1055
1101
|
*
|
|
1056
1102
|
* @param nodeId The ID of the node to unlock.
|
|
1057
1103
|
* @param signingPrivateKeyPEM The PEM-encoded signing private key.
|
|
1058
1104
|
*/
|
|
1059
|
-
async loadNodeKey(nodeId,
|
|
1060
|
-
await this.nodeKeyCache.loadKey(nodeId,
|
|
1105
|
+
async loadNodeKey(nodeId, signingPrivateKeyOrAlias) {
|
|
1106
|
+
await this.nodeKeyCache.loadKey(nodeId, signingPrivateKeyOrAlias);
|
|
1061
1107
|
}
|
|
1062
1108
|
/**
|
|
1063
1109
|
* Sends a lightning payment for a given invoice.
|
|
1064
1110
|
*
|
|
1111
|
+
* Test mode note: For test mode, you can use the [createTestModeInvoice] function to create an invoice you can
|
|
1112
|
+
* pay in test mode.
|
|
1113
|
+
*
|
|
1065
1114
|
* @param payerNodeId The ID of the node that will pay the invoice.
|
|
1066
1115
|
* @param encodedInvoice The encoded invoice to pay.
|
|
1067
1116
|
* @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
|
|
@@ -1226,6 +1275,60 @@ var LightsparkClient = class {
|
|
|
1226
1275
|
async deleteApiToken(id) {
|
|
1227
1276
|
await this.requester.makeRawRequest(DeleteApiToken, { api_token_id: id });
|
|
1228
1277
|
}
|
|
1278
|
+
/**
|
|
1279
|
+
* In test mode, generates a Lightning Invoice which can be paid by a local node.
|
|
1280
|
+
* This call is only valid in test mode. You can then pay the invoice using [payInvoice].
|
|
1281
|
+
*
|
|
1282
|
+
* @param localNodeId The ID of the node that will pay the invoice.
|
|
1283
|
+
* @param amountMsats The amount to pay in milli-satoshis.
|
|
1284
|
+
* @param memo An optional memo to attach to the invoice.
|
|
1285
|
+
* @param invoiceType The type of invoice to create.
|
|
1286
|
+
*/
|
|
1287
|
+
async createTestModeInvoice(localNodeId, amountMsats, memo = void 0, invoiceType = InvoiceType_default.STANDARD) {
|
|
1288
|
+
return await this.executeRawQuery({
|
|
1289
|
+
queryPayload: CreateTestModeInvoice,
|
|
1290
|
+
variables: {
|
|
1291
|
+
local_node_id: localNodeId,
|
|
1292
|
+
amount_msats: amountMsats,
|
|
1293
|
+
memo,
|
|
1294
|
+
invoice_type: invoiceType
|
|
1295
|
+
},
|
|
1296
|
+
constructObject: (responseJson) => {
|
|
1297
|
+
const encodedPaymentRequest = responseJson.create_test_mode_invoice?.encoded_payment_request;
|
|
1298
|
+
if (!encodedPaymentRequest) {
|
|
1299
|
+
throw new LightsparkException(
|
|
1300
|
+
"CreateTestModeInvoiceError",
|
|
1301
|
+
"Unable to create test mode invoice"
|
|
1302
|
+
);
|
|
1303
|
+
}
|
|
1304
|
+
return encodedPaymentRequest;
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* In test mode, simulates a payment of a Lightning Invoice from another node.
|
|
1310
|
+
* This can only be used in test mode and should be used with invoices generated by [createInvoice].
|
|
1311
|
+
*
|
|
1312
|
+
* @param localNodeId The ID of the node that will receive the payment.
|
|
1313
|
+
* @param encodedInvoice The encoded invoice to pay.
|
|
1314
|
+
* @param amountMsats The amount to pay in milli-satoshis for 0-amount invoices. This should be null for non-zero
|
|
1315
|
+
* amount invoices.
|
|
1316
|
+
*/
|
|
1317
|
+
async createTestModePayment(localNodeId, encodedInvoice, amountMsats = void 0) {
|
|
1318
|
+
return await this.executeRawQuery({
|
|
1319
|
+
queryPayload: CreateTestModePayment,
|
|
1320
|
+
variables: {
|
|
1321
|
+
local_node_id: localNodeId,
|
|
1322
|
+
encoded_invoice: encodedInvoice,
|
|
1323
|
+
amount_msats: amountMsats
|
|
1324
|
+
},
|
|
1325
|
+
constructObject: (responseJson) => {
|
|
1326
|
+
return OutgoingPaymentFromJson(
|
|
1327
|
+
responseJson.create_test_mode_payment?.payment
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1229
1332
|
/**
|
|
1230
1333
|
* Executes a raw `Query` against the Lightspark API.
|
|
1231
1334
|
*
|
package/dist/objects/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BitcoinNetwork, j as BlockchainBalance, C as Channel, k as ChannelClosingTransaction, m as ChannelFees, n as ChannelOpeningTransaction, p as ChannelStatus, q as ChannelToTransactionsConnection, r as CreateApiTokenInput, s as CreateApiTokenOutput, t as CreateInvoiceInput, u as CreateInvoiceOutput, v as CreateNodeWalletAddressInput, w as CreateNodeWalletAddressOutput, x as CreateTestModeInvoiceInput, y as CreateTestModeInvoiceOutput, z as CreateTestModePaymentInput, D as CreateTestModePaymentoutput, E as CurrencyAmount, F as CurrencyUnit, G as DeleteApiTokenInput, H as DeleteApiTokenOutput, I as Deposit, K as Entity, M as FeeEstimate, N as FundNodeInput, O as FundNodeOutput, P as GraphNode, Q as Hop, S as HtlcAttemptFailureCode, T as IncomingPayment, U as IncomingPaymentAttempt, W as IncomingPaymentAttemptStatus, X as IncomingPaymentToAttemptsConnection, Y as Invoice, _ as InvoiceData, $ as InvoiceType, a0 as LightningFeeEstimateForInvoiceInput, a1 as LightningFeeEstimateForNodeInput, a2 as LightningFeeEstimateOutput, a3 as LightningTransaction, a5 as LightsparkNode, a6 as LightsparkNodePurpose, a7 as LightsparkNodeStatus, a8 as LightsparkNodeToChannelsConnection, a9 as Node, aa as NodeAddress, ab as NodeAddressType, ac as NodeToAddressesConnection, ad as OnChainTransaction, af as OutgoingPayment, ag as OutgoingPaymentAttempt, ah as OutgoingPaymentAttemptStatus, ai as OutgoingPaymentAttemptToHopsConnection, aj as OutgoingPaymentToAttemptsConnection, ak as PageInfo, al as PayInvoiceInput, am as PayInvoiceOutput, an as PaymentFailureReason, ao as PaymentRequest, aq as PaymentRequestData, ar as PaymentRequestStatus, as as Permission, at as RequestWithdrawalInput, au as RequestWithdrawalOutput, av as RichText, aw as RoutingTransaction, ay as RoutingTransactionFailureReason, az as Secret, aA as SendPaymentInput, aB as SendPaymentOutput, aC as SingleNodeDashboard, aD as Transaction, aF as TransactionFailures, aG as TransactionStatus, aH as TransactionType, aI as TransactionUpdate, aJ as Wallet, aK as WebhookEventType, aL as Withdrawal, aN as WithdrawalMode, aO as WithdrawalRequest, aP as WithdrawalRequestStatus, aQ as WithdrawalRequestToChannelClosingTransactionsConnection, aR as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, l as getChannelClosingTransactionQuery, o as getChannelOpeningTransactionQuery, J as getDepositQuery, R as getHopQuery, V as getIncomingPaymentAttemptQuery, Z as getInvoiceQuery, a4 as getLightningTransactionQuery, ae as getOnChainTransactionQuery, ap as getPaymentRequestQuery, ax as getRoutingTransactionQuery, aE as getTransactionQuery, aM as getWithdrawalQuery } from '../Withdrawal-
|
|
1
|
+
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BitcoinNetwork, j as BlockchainBalance, C as Channel, k as ChannelClosingTransaction, m as ChannelFees, n as ChannelOpeningTransaction, p as ChannelStatus, q as ChannelToTransactionsConnection, r as CreateApiTokenInput, s as CreateApiTokenOutput, t as CreateInvoiceInput, u as CreateInvoiceOutput, v as CreateNodeWalletAddressInput, w as CreateNodeWalletAddressOutput, x as CreateTestModeInvoiceInput, y as CreateTestModeInvoiceOutput, z as CreateTestModePaymentInput, D as CreateTestModePaymentoutput, E as CurrencyAmount, F as CurrencyUnit, G as DeleteApiTokenInput, H as DeleteApiTokenOutput, I as Deposit, K as Entity, M as FeeEstimate, N as FundNodeInput, O as FundNodeOutput, P as GraphNode, Q as Hop, S as HtlcAttemptFailureCode, T as IncomingPayment, U as IncomingPaymentAttempt, W as IncomingPaymentAttemptStatus, X as IncomingPaymentToAttemptsConnection, Y as Invoice, _ as InvoiceData, $ as InvoiceType, a0 as LightningFeeEstimateForInvoiceInput, a1 as LightningFeeEstimateForNodeInput, a2 as LightningFeeEstimateOutput, a3 as LightningTransaction, a5 as LightsparkNode, a6 as LightsparkNodePurpose, a7 as LightsparkNodeStatus, a8 as LightsparkNodeToChannelsConnection, a9 as Node, aa as NodeAddress, ab as NodeAddressType, ac as NodeToAddressesConnection, ad as OnChainTransaction, af as OutgoingPayment, ag as OutgoingPaymentAttempt, ah as OutgoingPaymentAttemptStatus, ai as OutgoingPaymentAttemptToHopsConnection, aj as OutgoingPaymentToAttemptsConnection, ak as PageInfo, al as PayInvoiceInput, am as PayInvoiceOutput, an as PaymentFailureReason, ao as PaymentRequest, aq as PaymentRequestData, ar as PaymentRequestStatus, as as Permission, at as RequestWithdrawalInput, au as RequestWithdrawalOutput, av as RichText, aw as RoutingTransaction, ay as RoutingTransactionFailureReason, az as Secret, aA as SendPaymentInput, aB as SendPaymentOutput, aC as SingleNodeDashboard, aD as Transaction, aF as TransactionFailures, aG as TransactionStatus, aH as TransactionType, aI as TransactionUpdate, aJ as Wallet, aK as WebhookEventType, aL as Withdrawal, aN as WithdrawalMode, aO as WithdrawalRequest, aP as WithdrawalRequestStatus, aQ as WithdrawalRequestToChannelClosingTransactionsConnection, aR as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, l as getChannelClosingTransactionQuery, o as getChannelOpeningTransactionQuery, J as getDepositQuery, R as getHopQuery, V as getIncomingPaymentAttemptQuery, Z as getInvoiceQuery, a4 as getLightningTransactionQuery, ae as getOnChainTransactionQuery, ap as getPaymentRequestQuery, ax as getRoutingTransactionQuery, aE as getTransactionQuery, aM as getWithdrawalQuery } from '../Withdrawal-e4b8b697.js';
|
|
2
2
|
import '@lightsparkdev/core';
|
|
3
3
|
import 'zen-observable';
|
package/dist/objects/index.js
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
getRoutingTransactionQuery,
|
|
43
43
|
getTransactionQuery,
|
|
44
44
|
getWithdrawalQuery
|
|
45
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-7GDCZ2RB.js";
|
|
46
46
|
export {
|
|
47
47
|
Account_default as Account,
|
|
48
48
|
AccountToChannelsConnection_default as AccountToChannelsConnection,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsparkdev/lightspark-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Lightspark JS SDK",
|
|
5
5
|
"author": "Lightspark Inc.",
|
|
6
6
|
"keywords": [
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
},
|
|
69
69
|
"license": "Apache-2.0",
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@lightsparkdev/core": "0.
|
|
71
|
+
"@lightsparkdev/core": "0.3.0",
|
|
72
72
|
"auto-bind": "^5.0.1",
|
|
73
73
|
"crypto": "^1.0.1",
|
|
74
74
|
"crypto-browserify": "^3.12.0",
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
2
|
|
|
3
|
-
import { LightsparkSigningException, Query } from "@lightsparkdev/core";
|
|
4
3
|
import autoBind from "auto-bind";
|
|
5
4
|
import Observable from "zen-observable";
|
|
6
5
|
|
|
@@ -9,10 +8,14 @@ import {
|
|
|
9
8
|
b64encode,
|
|
10
9
|
CryptoInterface,
|
|
11
10
|
DefaultCrypto,
|
|
11
|
+
KeyOrAlias,
|
|
12
|
+
KeyOrAliasType,
|
|
12
13
|
LightsparkAuthException,
|
|
13
14
|
LightsparkException,
|
|
15
|
+
LightsparkSigningException,
|
|
14
16
|
Maybe,
|
|
15
17
|
NodeKeyCache,
|
|
18
|
+
Query,
|
|
16
19
|
Requester,
|
|
17
20
|
StubAuthProvider,
|
|
18
21
|
} from "@lightsparkdev/core";
|
|
@@ -20,6 +23,8 @@ import { BitcoinFeeEstimate as BitcoinFeeEstimateQuery } from "./graphql/Bitcoin
|
|
|
20
23
|
import { CreateApiToken } from "./graphql/CreateApiToken.js";
|
|
21
24
|
import { CreateInvoice } from "./graphql/CreateInvoice.js";
|
|
22
25
|
import { CreateNodeWalletAddress } from "./graphql/CreateNodeWalletAddress.js";
|
|
26
|
+
import { CreateTestModeInvoice } from "./graphql/CreateTestModeInvoice.js";
|
|
27
|
+
import { CreateTestModePayment } from "./graphql/CreateTestModePayment.js";
|
|
23
28
|
import { DecodeInvoice } from "./graphql/DecodeInvoice.js";
|
|
24
29
|
import { DeleteApiToken } from "./graphql/DeleteApiToken.js";
|
|
25
30
|
import { FundNode } from "./graphql/FundNode.js";
|
|
@@ -77,7 +82,7 @@ import WithdrawalRequest, {
|
|
|
77
82
|
* const invoiceDetails = await lightsparkClient.decodeInvoice(encodedInvoice);
|
|
78
83
|
* console.log(invoiceDetails);
|
|
79
84
|
*
|
|
80
|
-
* const payment = await lightsparkClient.payInvoice(PAYING_NODE_ID, encodedInvoice,
|
|
85
|
+
* const payment = await lightsparkClient.payInvoice(PAYING_NODE_ID, encodedInvoice, 100000);
|
|
81
86
|
* console.log(payment);
|
|
82
87
|
* ```
|
|
83
88
|
*
|
|
@@ -93,8 +98,8 @@ class LightsparkClient {
|
|
|
93
98
|
* @param authProvider The auth provider to use for authentication. Defaults to a stub auth provider. For server-side
|
|
94
99
|
* use, you should use the `AccountTokenAuthProvider`.
|
|
95
100
|
* @param serverUrl The base URL of the server to connect to. Defaults to lightspark production.
|
|
96
|
-
* @param
|
|
97
|
-
*
|
|
101
|
+
* @param cryptoImpl The crypto implementation to use. Defaults to web and node compatible crypto.
|
|
102
|
+
* For React Native, you should use the `ReactNativeCrypto` implementation from `@lightsparkdev/react-native`.
|
|
98
103
|
*/
|
|
99
104
|
constructor(
|
|
100
105
|
private authProvider: AuthProvider = new StubAuthProvider(),
|
|
@@ -375,6 +380,8 @@ class LightsparkClient {
|
|
|
375
380
|
/**
|
|
376
381
|
* Creates an invoice for the given node.
|
|
377
382
|
*
|
|
383
|
+
* Test mode note: You can simulate a payment of this invoice in test move using [createTestModePayment].
|
|
384
|
+
*
|
|
378
385
|
* @param nodeId The node ID for which to create an invoice.
|
|
379
386
|
* @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
|
|
380
387
|
* @param memo A string memo to include in the invoice as a description.
|
|
@@ -518,7 +525,10 @@ class LightsparkClient {
|
|
|
518
525
|
signingPrivateKeyPEM = dec.decode(signingPrivateKey);
|
|
519
526
|
}
|
|
520
527
|
|
|
521
|
-
await this.nodeKeyCache.loadKey(
|
|
528
|
+
await this.nodeKeyCache.loadKey(
|
|
529
|
+
nodeId,
|
|
530
|
+
KeyOrAlias.key(signingPrivateKeyPEM)
|
|
531
|
+
);
|
|
522
532
|
return true;
|
|
523
533
|
}
|
|
524
534
|
|
|
@@ -537,18 +547,24 @@ class LightsparkClient {
|
|
|
537
547
|
}
|
|
538
548
|
|
|
539
549
|
/**
|
|
540
|
-
* Directly unlocks a node with a signing private key.
|
|
550
|
+
* Directly unlocks a node with a signing private key or alias.
|
|
541
551
|
*
|
|
542
552
|
* @param nodeId The ID of the node to unlock.
|
|
543
553
|
* @param signingPrivateKeyPEM The PEM-encoded signing private key.
|
|
544
554
|
*/
|
|
545
|
-
public async loadNodeKey(
|
|
546
|
-
|
|
555
|
+
public async loadNodeKey(
|
|
556
|
+
nodeId: string,
|
|
557
|
+
signingPrivateKeyOrAlias: KeyOrAliasType
|
|
558
|
+
) {
|
|
559
|
+
await this.nodeKeyCache.loadKey(nodeId, signingPrivateKeyOrAlias);
|
|
547
560
|
}
|
|
548
561
|
|
|
549
562
|
/**
|
|
550
563
|
* Sends a lightning payment for a given invoice.
|
|
551
564
|
*
|
|
565
|
+
* Test mode note: For test mode, you can use the [createTestModeInvoice] function to create an invoice you can
|
|
566
|
+
* pay in test mode.
|
|
567
|
+
*
|
|
552
568
|
* @param payerNodeId The ID of the node that will pay the invoice.
|
|
553
569
|
* @param encodedInvoice The encoded invoice to pay.
|
|
554
570
|
* @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
|
|
@@ -751,6 +767,72 @@ class LightsparkClient {
|
|
|
751
767
|
await this.requester.makeRawRequest(DeleteApiToken, { api_token_id: id });
|
|
752
768
|
}
|
|
753
769
|
|
|
770
|
+
/**
|
|
771
|
+
* In test mode, generates a Lightning Invoice which can be paid by a local node.
|
|
772
|
+
* This call is only valid in test mode. You can then pay the invoice using [payInvoice].
|
|
773
|
+
*
|
|
774
|
+
* @param localNodeId The ID of the node that will pay the invoice.
|
|
775
|
+
* @param amountMsats The amount to pay in milli-satoshis.
|
|
776
|
+
* @param memo An optional memo to attach to the invoice.
|
|
777
|
+
* @param invoiceType The type of invoice to create.
|
|
778
|
+
*/
|
|
779
|
+
public async createTestModeInvoice(
|
|
780
|
+
localNodeId: string,
|
|
781
|
+
amountMsats: number,
|
|
782
|
+
memo: string | undefined = undefined,
|
|
783
|
+
invoiceType: InvoiceType = InvoiceType.STANDARD
|
|
784
|
+
): Promise<string | null> {
|
|
785
|
+
return await this.executeRawQuery({
|
|
786
|
+
queryPayload: CreateTestModeInvoice,
|
|
787
|
+
variables: {
|
|
788
|
+
local_node_id: localNodeId,
|
|
789
|
+
amount_msats: amountMsats,
|
|
790
|
+
memo,
|
|
791
|
+
invoice_type: invoiceType,
|
|
792
|
+
},
|
|
793
|
+
constructObject: (responseJson: any) => {
|
|
794
|
+
const encodedPaymentRequest =
|
|
795
|
+
responseJson.create_test_mode_invoice?.encoded_payment_request;
|
|
796
|
+
if (!encodedPaymentRequest) {
|
|
797
|
+
throw new LightsparkException(
|
|
798
|
+
"CreateTestModeInvoiceError",
|
|
799
|
+
"Unable to create test mode invoice"
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
return encodedPaymentRequest as string;
|
|
803
|
+
},
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* In test mode, simulates a payment of a Lightning Invoice from another node.
|
|
809
|
+
* This can only be used in test mode and should be used with invoices generated by [createInvoice].
|
|
810
|
+
*
|
|
811
|
+
* @param localNodeId The ID of the node that will receive the payment.
|
|
812
|
+
* @param encodedInvoice The encoded invoice to pay.
|
|
813
|
+
* @param amountMsats The amount to pay in milli-satoshis for 0-amount invoices. This should be null for non-zero
|
|
814
|
+
* amount invoices.
|
|
815
|
+
*/
|
|
816
|
+
public async createTestModePayment(
|
|
817
|
+
localNodeId: string,
|
|
818
|
+
encodedInvoice: string,
|
|
819
|
+
amountMsats: number | undefined = undefined
|
|
820
|
+
): Promise<OutgoingPayment | null> {
|
|
821
|
+
return await this.executeRawQuery({
|
|
822
|
+
queryPayload: CreateTestModePayment,
|
|
823
|
+
variables: {
|
|
824
|
+
local_node_id: localNodeId,
|
|
825
|
+
encoded_invoice: encodedInvoice,
|
|
826
|
+
amount_msats: amountMsats,
|
|
827
|
+
},
|
|
828
|
+
constructObject: (responseJson: any) => {
|
|
829
|
+
return OutgoingPaymentFromJson(
|
|
830
|
+
responseJson.create_test_mode_payment?.payment
|
|
831
|
+
);
|
|
832
|
+
},
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
|
|
754
836
|
/**
|
|
755
837
|
* Executes a raw `Query` against the Lightspark API.
|
|
756
838
|
*
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
export const CreateTestModeInvoice = `
|
|
4
|
+
mutation CreateTestModeInvoice(
|
|
5
|
+
$local_node_id: ID!
|
|
6
|
+
$amount_msats: Long!
|
|
7
|
+
$memo: String
|
|
8
|
+
$invoice_type: InvoiceType
|
|
9
|
+
) {
|
|
10
|
+
create_test_mode_invoice(input: {
|
|
11
|
+
local_node_id: $local_node_id
|
|
12
|
+
amount_msats: $amount_msats
|
|
13
|
+
memo: $memo
|
|
14
|
+
invoice_type: $invoice_type
|
|
15
|
+
}) {
|
|
16
|
+
encoded_payment_request
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
import { FRAGMENT as OutgoingPaymentFragment } from "../objects/OutgoingPayment.js";
|
|
4
|
+
|
|
5
|
+
export const CreateTestModePayment = `
|
|
6
|
+
mutation CreateTestModePayment(
|
|
7
|
+
$local_node_id: ID!
|
|
8
|
+
$encoded_invoice: String!
|
|
9
|
+
$amount_msats: Long
|
|
10
|
+
) {
|
|
11
|
+
create_test_mode_payment(input: {
|
|
12
|
+
local_node_id: $local_node_id
|
|
13
|
+
encoded_invoice: $encoded_invoice
|
|
14
|
+
amount_msats: $amount_msats
|
|
15
|
+
}) {
|
|
16
|
+
payment {
|
|
17
|
+
...OutgoingPaymentFragment
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
${OutgoingPaymentFragment}
|
|
23
|
+
`;
|