@lightsparkdev/lightspark-sdk 0.4.11 → 1.0.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 +22 -0
- package/README.md +1 -1
- package/dist/{chunk-NXUFC5J7.js → chunk-LZC5C5NI.js} +2908 -635
- package/dist/{index-3ffe9e7b.d.ts → index-09d4ac20.d.ts} +373 -62
- package/dist/index.cjs +3393 -841
- package/dist/index.d.ts +2 -2
- package/dist/index.js +388 -93
- package/dist/objects/index.cjs +2735 -553
- package/dist/objects/index.d.ts +1 -1
- package/dist/objects/index.js +17 -5
- package/package.json +10 -8
- package/src/NodeKeyLoaderCache.ts +87 -0
- package/src/SigningKeyLoader.ts +177 -0
- package/src/client.ts +160 -71
- package/src/graphql/CreateInvoice.ts +3 -2
- package/src/graphql/CreateLnurlInvoice.ts +2 -0
- package/src/graphql/CreateUmaInvoice.ts +23 -0
- package/src/graphql/MultiNodeDashboard.ts +0 -3
- package/src/graphql/PayUmaInvoice.ts +29 -0
- package/src/graphql/RecoverNodeSigningKey.ts +1 -1
- package/src/graphql/SingleNodeDashboard.ts +0 -1
- package/src/lightspark_crypto/lightspark_crypto.d.ts +157 -0
- package/src/lightspark_crypto/lightspark_crypto.js +1010 -0
- package/src/lightspark_crypto/lightspark_crypto_bg.wasm +0 -0
- package/src/lightspark_crypto/lightspark_crypto_bg.wasm.d.ts +120 -0
- package/src/lightspark_crypto/package.json +11 -0
- package/src/objects/Account.ts +424 -107
- package/src/objects/AccountToNodesConnection.ts +0 -13
- package/src/objects/{CryptoSanctionsScreeningProvider.ts → ComplianceProvider.ts} +3 -3
- package/src/objects/Connection.ts +0 -6
- package/src/objects/CreateInvoiceInput.ts +0 -6
- package/src/objects/CreateLnurlInvoiceInput.ts +0 -6
- package/src/objects/CreateTestModePaymentoutput.ts +13 -1
- package/src/objects/CreateUmaInvoiceInput.ts +24 -0
- package/src/objects/DeclineToSignMessagesInput.ts +16 -0
- package/src/objects/DeclineToSignMessagesOutput.ts +28 -0
- package/src/objects/Entity.ts +401 -66
- package/src/objects/IdAndSignature.ts +16 -0
- package/src/objects/IncomingPayment.ts +18 -5
- package/src/objects/Invoice.ts +118 -21
- package/src/objects/InvoiceData.ts +118 -21
- package/src/objects/LightningTransaction.ts +149 -25
- package/src/objects/LightsparkNode.ts +270 -110
- package/src/objects/LightsparkNodeOwner.ts +4 -0
- package/src/objects/LightsparkNodeWithOSK.ts +389 -0
- package/src/objects/LightsparkNodeWithRemoteSigning.ts +384 -0
- package/src/objects/Node.ts +209 -56
- package/src/objects/OutgoingPayment.ts +136 -21
- package/src/objects/OutgoingPaymentsForInvoiceQueryInput.ts +25 -0
- package/src/objects/OutgoingPaymentsForInvoiceQueryOutput.ts +28 -0
- package/src/objects/PayUmaInvoiceInput.ts +25 -0
- package/src/objects/{LightsparkNodePurpose.ts → PaymentDirection.ts} +5 -7
- package/src/objects/PaymentRequest.ts +118 -21
- package/src/objects/PaymentRequestData.ts +118 -21
- package/src/objects/PostTransactionData.ts +39 -0
- package/src/objects/RegisterPaymentInput.ts +31 -0
- package/src/objects/RegisterPaymentOutput.ts +23 -0
- package/src/objects/ReleaseChannelPerCommitmentSecretInput.ts +23 -0
- package/src/objects/ReleaseChannelPerCommitmentSecretOutput.ts +23 -0
- package/src/objects/ReleasePaymentPreimageInput.ts +20 -0
- package/src/objects/ReleasePaymentPreimageOutput.ts +23 -0
- package/src/objects/RemoteSigningSubEventType.ts +26 -0
- package/src/objects/ScreenNodeInput.ts +20 -0
- package/src/objects/ScreenNodeOutput.ts +22 -0
- package/src/objects/SetInvoicePaymentHashInput.ts +24 -0
- package/src/objects/SetInvoicePaymentHashOutput.ts +23 -0
- package/src/objects/SignInvoiceInput.ts +19 -0
- package/src/objects/SignInvoiceOutput.ts +21 -0
- package/src/objects/SignMessagesInput.ts +18 -0
- package/src/objects/SignMessagesOutput.ts +26 -0
- package/src/objects/Signable.ts +58 -0
- package/src/objects/SignablePayload.ts +93 -0
- package/src/objects/SignablePayloadStatus.ts +17 -0
- package/src/objects/SingleNodeDashboard.ts +0 -2
- package/src/objects/Transaction.ts +149 -25
- package/src/objects/UpdateChannelPerCommitmentPointInput.ts +25 -0
- package/src/objects/UpdateChannelPerCommitmentPointOutput.ts +23 -0
- package/src/objects/UpdateNodeSharedSecretInput.ts +18 -0
- package/src/objects/UpdateNodeSharedSecretOutput.ts +23 -0
- package/src/objects/Wallet.ts +265 -45
- package/src/objects/index.ts +37 -4
- package/src/objects/ScreenBitcoinAddressesInput.ts +0 -23
- package/src/objects/ScreenBitcoinAddressesOutput.ts +0 -25
- /package/src/{__tests__ → tests}/webhooks.test.ts +0 -0
package/src/client.ts
CHANGED
|
@@ -9,16 +9,16 @@ import type {
|
|
|
9
9
|
KeyOrAliasType,
|
|
10
10
|
Maybe,
|
|
11
11
|
Query,
|
|
12
|
+
SigningKey,
|
|
12
13
|
} from "@lightsparkdev/core";
|
|
13
14
|
import {
|
|
14
|
-
b64encode,
|
|
15
15
|
DefaultCrypto,
|
|
16
|
-
KeyOrAlias,
|
|
17
16
|
LightsparkAuthException,
|
|
18
17
|
LightsparkException,
|
|
19
18
|
LightsparkSigningException,
|
|
20
19
|
NodeKeyCache,
|
|
21
20
|
Requester,
|
|
21
|
+
SigningKeyType,
|
|
22
22
|
StubAuthProvider,
|
|
23
23
|
} from "@lightsparkdev/core";
|
|
24
24
|
import { createHash } from "crypto";
|
|
@@ -30,6 +30,7 @@ import { CreateLnurlInvoice } from "./graphql/CreateLnurlInvoice.js";
|
|
|
30
30
|
import { CreateNodeWalletAddress } from "./graphql/CreateNodeWalletAddress.js";
|
|
31
31
|
import { CreateTestModeInvoice } from "./graphql/CreateTestModeInvoice.js";
|
|
32
32
|
import { CreateTestModePayment } from "./graphql/CreateTestModePayment.js";
|
|
33
|
+
import { CreateUmaInvoice } from "./graphql/CreateUmaInvoice.js";
|
|
33
34
|
import { DecodeInvoice } from "./graphql/DecodeInvoice.js";
|
|
34
35
|
import { DeleteApiToken } from "./graphql/DeleteApiToken.js";
|
|
35
36
|
import { FundNode } from "./graphql/FundNode.js";
|
|
@@ -38,12 +39,13 @@ import { LightningFeeEstimateForNode } from "./graphql/LightningFeeEstimateForNo
|
|
|
38
39
|
import type { AccountDashboard } from "./graphql/MultiNodeDashboard.js";
|
|
39
40
|
import { MultiNodeDashboard } from "./graphql/MultiNodeDashboard.js";
|
|
40
41
|
import { PayInvoice } from "./graphql/PayInvoice.js";
|
|
41
|
-
import {
|
|
42
|
+
import { PayUmaInvoice } from "./graphql/PayUmaInvoice.js";
|
|
42
43
|
import { RequestWithdrawal } from "./graphql/RequestWithdrawal.js";
|
|
43
44
|
import { SendPayment } from "./graphql/SendPayment.js";
|
|
44
45
|
import { SingleNodeDashboard as SingleNodeDashboardQuery } from "./graphql/SingleNodeDashboard.js";
|
|
45
46
|
import { TransactionsForNode } from "./graphql/TransactionsForNode.js";
|
|
46
47
|
import { TransactionSubscription } from "./graphql/TransactionSubscription.js";
|
|
48
|
+
import NodeKeyLoaderCache from "./NodeKeyLoaderCache.js";
|
|
47
49
|
import Account from "./objects/Account.js";
|
|
48
50
|
import { ApiTokenFromJson } from "./objects/ApiToken.js";
|
|
49
51
|
import BitcoinNetwork from "./objects/BitcoinNetwork.js";
|
|
@@ -68,6 +70,7 @@ import { TransactionUpdateFromJson } from "./objects/TransactionUpdate.js";
|
|
|
68
70
|
import type WithdrawalMode from "./objects/WithdrawalMode.js";
|
|
69
71
|
import type WithdrawalRequest from "./objects/WithdrawalRequest.js";
|
|
70
72
|
import { WithdrawalRequestFromJson } from "./objects/WithdrawalRequest.js";
|
|
73
|
+
import { type SigningKeyLoaderArgs } from "./SigningKeyLoader.js";
|
|
71
74
|
|
|
72
75
|
const sdkVersion = packageJson.version;
|
|
73
76
|
|
|
@@ -97,6 +100,9 @@ const sdkVersion = packageJson.version;
|
|
|
97
100
|
class LightsparkClient {
|
|
98
101
|
private requester: Requester;
|
|
99
102
|
private readonly nodeKeyCache: NodeKeyCache;
|
|
103
|
+
private readonly nodeKeyLoaderCache: NodeKeyLoaderCache;
|
|
104
|
+
private readonly LIGHTSPARK_SDK_ENDPOINT =
|
|
105
|
+
process.env.LIGHTSPARK_SDK_ENDPOINT || "graphql/server/2023-09-13";
|
|
100
106
|
|
|
101
107
|
/**
|
|
102
108
|
* Constructs a new LightsparkClient.
|
|
@@ -113,9 +119,13 @@ class LightsparkClient {
|
|
|
113
119
|
private readonly cryptoImpl: CryptoInterface = DefaultCrypto,
|
|
114
120
|
) {
|
|
115
121
|
this.nodeKeyCache = new NodeKeyCache(this.cryptoImpl);
|
|
122
|
+
this.nodeKeyLoaderCache = new NodeKeyLoaderCache(
|
|
123
|
+
this.nodeKeyCache,
|
|
124
|
+
this.cryptoImpl,
|
|
125
|
+
);
|
|
116
126
|
this.requester = new Requester(
|
|
117
127
|
this.nodeKeyCache,
|
|
118
|
-
LIGHTSPARK_SDK_ENDPOINT,
|
|
128
|
+
this.LIGHTSPARK_SDK_ENDPOINT,
|
|
119
129
|
`js-lightspark-sdk/${sdkVersion}`,
|
|
120
130
|
authProvider,
|
|
121
131
|
serverUrl,
|
|
@@ -125,6 +135,35 @@ class LightsparkClient {
|
|
|
125
135
|
autoBind(this);
|
|
126
136
|
}
|
|
127
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Sets the key loader for a node. This unlocks client operations that require a private key.
|
|
140
|
+
* Passing in [NodeIdAndPasswordSigningKeyLoaderArgs] loads the RSA key for an OSK node.
|
|
141
|
+
* Passing in [MasterSeedSigningKeyLoaderArgs] loads the Secp256k1 key for a remote signing node.
|
|
142
|
+
*
|
|
143
|
+
* @param nodeId The ID of the node the key is for
|
|
144
|
+
* @param loader The loader for the key
|
|
145
|
+
*/
|
|
146
|
+
public async loadNodeSigningKey(
|
|
147
|
+
nodeId: string,
|
|
148
|
+
loaderArgs: SigningKeyLoaderArgs,
|
|
149
|
+
) {
|
|
150
|
+
this.nodeKeyLoaderCache.setLoader(nodeId, loaderArgs, this.requester);
|
|
151
|
+
const key = await this.getNodeSigningKey(nodeId);
|
|
152
|
+
return !!key;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Gets the signing key for a node. Must have previously called [loadNodeSigningKey].
|
|
157
|
+
*
|
|
158
|
+
* @param nodeId The ID of the node the key is for
|
|
159
|
+
* @returns The signing key for the node
|
|
160
|
+
*/
|
|
161
|
+
public async getNodeSigningKey(
|
|
162
|
+
nodeId: string,
|
|
163
|
+
): Promise<SigningKey | undefined> {
|
|
164
|
+
return await this.nodeKeyLoaderCache.getKeyWithLoader(nodeId);
|
|
165
|
+
}
|
|
166
|
+
|
|
128
167
|
/**
|
|
129
168
|
* Sets the auth provider for the client. This is useful for switching between auth providers if you are using
|
|
130
169
|
* multiple accounts or waiting for the user to log in.
|
|
@@ -134,7 +173,7 @@ class LightsparkClient {
|
|
|
134
173
|
public async setAuthProvider(authProvider: AuthProvider) {
|
|
135
174
|
this.requester = new Requester(
|
|
136
175
|
this.nodeKeyCache,
|
|
137
|
-
LIGHTSPARK_SDK_ENDPOINT,
|
|
176
|
+
this.LIGHTSPARK_SDK_ENDPOINT,
|
|
138
177
|
`js-lightspark-sdk/${sdkVersion}`,
|
|
139
178
|
authProvider,
|
|
140
179
|
this.serverUrl,
|
|
@@ -251,7 +290,6 @@ class LightsparkClient {
|
|
|
251
290
|
return {
|
|
252
291
|
color: node.color,
|
|
253
292
|
displayName: node.display_name,
|
|
254
|
-
purpose: node.purpose,
|
|
255
293
|
id: node.id,
|
|
256
294
|
publicKey: node.public_key,
|
|
257
295
|
status: node.status,
|
|
@@ -354,7 +392,6 @@ class LightsparkClient {
|
|
|
354
392
|
return {
|
|
355
393
|
color: node.color,
|
|
356
394
|
displayName: account.name,
|
|
357
|
-
purpose: node.purpose,
|
|
358
395
|
id: node.id,
|
|
359
396
|
publicKey: node.public_key,
|
|
360
397
|
status: node.status,
|
|
@@ -395,6 +432,7 @@ class LightsparkClient {
|
|
|
395
432
|
* @param type The type of invoice to create. Defaults to a normal payment invoice, but you can pass InvoiceType.AMP
|
|
396
433
|
* to create an [AMP invoice](https://docs.lightning.engineering/lightning-network-tools/lnd/amp), which can be
|
|
397
434
|
* paid multiple times.
|
|
435
|
+
* @param expirySecs The number of seconds until the invoice expires. Defaults to 86400 (1 day).
|
|
398
436
|
* @returns An encoded payment request for the invoice, or undefined if the invoice could not be created.
|
|
399
437
|
*/
|
|
400
438
|
public async createInvoice(
|
|
@@ -402,13 +440,21 @@ class LightsparkClient {
|
|
|
402
440
|
amountMsats: number,
|
|
403
441
|
memo: string,
|
|
404
442
|
type: InvoiceType | undefined = undefined,
|
|
443
|
+
expirySecs: number | undefined = undefined,
|
|
405
444
|
): Promise<string | undefined> {
|
|
406
|
-
const
|
|
445
|
+
const variables = {
|
|
407
446
|
node_id: nodeId,
|
|
408
447
|
amount_msats: amountMsats,
|
|
409
448
|
memo,
|
|
410
449
|
type,
|
|
411
|
-
}
|
|
450
|
+
};
|
|
451
|
+
if (expirySecs !== undefined) {
|
|
452
|
+
variables["expiry_secs"] = expirySecs;
|
|
453
|
+
}
|
|
454
|
+
const response = await this.requester.makeRawRequest(
|
|
455
|
+
CreateInvoice,
|
|
456
|
+
variables,
|
|
457
|
+
);
|
|
412
458
|
return response.create_invoice?.invoice.data?.encoded_payment_request;
|
|
413
459
|
}
|
|
414
460
|
|
|
@@ -424,18 +470,27 @@ class LightsparkClient {
|
|
|
424
470
|
* @param metadata The LNURL metadata payload field in the initial payreq response. This wil be hashed and present in the
|
|
425
471
|
* h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice. See
|
|
426
472
|
* [this spec](https://github.com/lnurl/luds/blob/luds/06.md#pay-to-static-qrnfclink) for details.
|
|
473
|
+
* @param expirySecs The number of seconds until the invoice expires. Defaults to 86400 (1 day).
|
|
427
474
|
* @returns An Invoice object representing the generated invoice.
|
|
428
475
|
*/
|
|
429
476
|
public async createLnurlInvoice(
|
|
430
477
|
nodeId: string,
|
|
431
478
|
amountMsats: number,
|
|
432
479
|
metadata: string,
|
|
480
|
+
expirySecs: number | undefined = undefined,
|
|
433
481
|
): Promise<Invoice | undefined> {
|
|
434
|
-
const
|
|
482
|
+
const variables = {
|
|
435
483
|
node_id: nodeId,
|
|
436
484
|
amount_msats: amountMsats,
|
|
437
485
|
metadata_hash: createHash("sha256").update(metadata).digest("hex"),
|
|
438
|
-
}
|
|
486
|
+
};
|
|
487
|
+
if (expirySecs !== undefined) {
|
|
488
|
+
variables["expiry_secs"] = expirySecs;
|
|
489
|
+
}
|
|
490
|
+
const response = await this.requester.makeRawRequest(
|
|
491
|
+
CreateLnurlInvoice,
|
|
492
|
+
variables,
|
|
493
|
+
);
|
|
439
494
|
const invoiceJson = response.create_lnurl_invoice?.invoice;
|
|
440
495
|
if (!invoiceJson) {
|
|
441
496
|
return undefined;
|
|
@@ -443,6 +498,43 @@ class LightsparkClient {
|
|
|
443
498
|
return InvoiceFromJson(invoiceJson);
|
|
444
499
|
}
|
|
445
500
|
|
|
501
|
+
/**
|
|
502
|
+
* Creates a new invoice for the UMA protocol. The metadata is hashed and included in the invoice.
|
|
503
|
+
* This API generates a Lightning Invoice (follows the Bolt 11 specification) to request a payment
|
|
504
|
+
* from another Lightning Node. This should only be used for generating invoices for UMA, with `createInvoice`
|
|
505
|
+
* preferred in the general case.
|
|
506
|
+
*
|
|
507
|
+
* @param nodeId The node ID for which to create an invoice.
|
|
508
|
+
* @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
|
|
509
|
+
* @param metadata The LNURL metadata payload field in the initial payreq response. This wil be hashed and present in the
|
|
510
|
+
* h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice. See
|
|
511
|
+
* [this spec](https://github.com/lnurl/luds/blob/luds/06.md#pay-to-static-qrnfclink) for details.
|
|
512
|
+
* @param expirySecs The number of seconds until the invoice expires. Defaults to 3600 (1 hour).
|
|
513
|
+
* @returns An Invoice object representing the generated invoice.
|
|
514
|
+
*/
|
|
515
|
+
public async createUmaInvoice(
|
|
516
|
+
nodeId: string,
|
|
517
|
+
amountMsats: number,
|
|
518
|
+
metadata: string,
|
|
519
|
+
expirySecs: number | undefined = undefined,
|
|
520
|
+
): Promise<Invoice | undefined> {
|
|
521
|
+
const variables = {
|
|
522
|
+
node_id: nodeId,
|
|
523
|
+
amount_msats: amountMsats,
|
|
524
|
+
metadata_hash: createHash("sha256").update(metadata).digest("hex"),
|
|
525
|
+
expiry_secs: expirySecs !== undefined ? expirySecs : 3600,
|
|
526
|
+
};
|
|
527
|
+
const response = await this.requester.makeRawRequest(
|
|
528
|
+
CreateUmaInvoice,
|
|
529
|
+
variables,
|
|
530
|
+
);
|
|
531
|
+
const invoiceJson = response.create_uma_invoice?.invoice;
|
|
532
|
+
if (!invoiceJson) {
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
535
|
+
return InvoiceFromJson(invoiceJson);
|
|
536
|
+
}
|
|
537
|
+
|
|
446
538
|
/**
|
|
447
539
|
* Decodes an encoded lightning invoice string.
|
|
448
540
|
*
|
|
@@ -529,63 +621,6 @@ class LightsparkClient {
|
|
|
529
621
|
);
|
|
530
622
|
}
|
|
531
623
|
|
|
532
|
-
/**
|
|
533
|
-
* Unlock the given node for sensitive operations like sending payments.
|
|
534
|
-
*
|
|
535
|
-
* @param nodeId The ID of the node to unlock.
|
|
536
|
-
* @param password The node password assigned at node creation.
|
|
537
|
-
* @returns True if the node was unlocked successfully, false otherwise.
|
|
538
|
-
*/
|
|
539
|
-
public async unlockNode(nodeId: string, password: string): Promise<boolean> {
|
|
540
|
-
const encryptedKey = await this.recoverNodeSigningKey(nodeId);
|
|
541
|
-
if (!encryptedKey) {
|
|
542
|
-
console.warn("No encrypted key found for node " + nodeId);
|
|
543
|
-
return false;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const signingPrivateKey =
|
|
547
|
-
await this.cryptoImpl.decryptSecretWithNodePassword(
|
|
548
|
-
encryptedKey.cipher,
|
|
549
|
-
encryptedKey.encrypted_value,
|
|
550
|
-
password,
|
|
551
|
-
);
|
|
552
|
-
|
|
553
|
-
if (!signingPrivateKey) {
|
|
554
|
-
throw new LightsparkSigningException(
|
|
555
|
-
"Unable to decrypt signing key with provided password. Please try again.",
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
let signingPrivateKeyPEM = "";
|
|
560
|
-
if (new Uint8Array(signingPrivateKey)[0] === 48) {
|
|
561
|
-
// Support DER format - https://github.com/lightsparkdev/webdev/pull/1982
|
|
562
|
-
signingPrivateKeyPEM = b64encode(signingPrivateKey);
|
|
563
|
-
} else {
|
|
564
|
-
const dec = new TextDecoder();
|
|
565
|
-
signingPrivateKeyPEM = dec.decode(signingPrivateKey);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
await this.nodeKeyCache.loadKey(
|
|
569
|
-
nodeId,
|
|
570
|
-
KeyOrAlias.key(signingPrivateKeyPEM),
|
|
571
|
-
);
|
|
572
|
-
return true;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
private async recoverNodeSigningKey(
|
|
576
|
-
nodeId: string,
|
|
577
|
-
): Promise<Maybe<{ encrypted_value: string; cipher: string }>> {
|
|
578
|
-
const response = await this.requester.makeRawRequest(
|
|
579
|
-
RecoverNodeSigningKey,
|
|
580
|
-
{ nodeId },
|
|
581
|
-
);
|
|
582
|
-
const nodeEntity = response.entity;
|
|
583
|
-
if (nodeEntity?.__typename === "LightsparkNode") {
|
|
584
|
-
return nodeEntity.encrypted_signing_private_key;
|
|
585
|
-
}
|
|
586
|
-
return null;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
624
|
/**
|
|
590
625
|
* Directly unlocks a node with a signing private key or alias.
|
|
591
626
|
*
|
|
@@ -596,7 +631,11 @@ class LightsparkClient {
|
|
|
596
631
|
nodeId: string,
|
|
597
632
|
signingPrivateKeyOrAlias: KeyOrAliasType,
|
|
598
633
|
) {
|
|
599
|
-
await this.nodeKeyCache.loadKey(
|
|
634
|
+
await this.nodeKeyCache.loadKey(
|
|
635
|
+
nodeId,
|
|
636
|
+
signingPrivateKeyOrAlias,
|
|
637
|
+
SigningKeyType.RSASigningKey,
|
|
638
|
+
);
|
|
600
639
|
}
|
|
601
640
|
|
|
602
641
|
/**
|
|
@@ -652,6 +691,58 @@ class LightsparkClient {
|
|
|
652
691
|
);
|
|
653
692
|
}
|
|
654
693
|
|
|
694
|
+
/**
|
|
695
|
+
* sends an UMA payment to a node on the Lightning Network, based on the invoice
|
|
696
|
+
* (as defined by the BOLT11 specification) that you provide.
|
|
697
|
+
* This should only be used for paying UMA invoices, with `payInvoice` preferred in the general case.
|
|
698
|
+
*
|
|
699
|
+
* @param payerNodeId The ID of the node that will pay the invoice.
|
|
700
|
+
* @param encodedInvoice The encoded invoice to pay.
|
|
701
|
+
* @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
|
|
702
|
+
* As guidance, a maximum fee of 16 basis points should make almost all transactions succeed. For example,
|
|
703
|
+
* for a transaction between 10k sats and 100k sats, this would mean a fee limit of 16 to 160 sats.
|
|
704
|
+
* @param timeoutSecs A timeout for the payment in seconds. Defaults to 60 seconds.
|
|
705
|
+
* @param amountMsats The amount to pay in msats for a zero-amount invoice. Defaults to the full amount of the
|
|
706
|
+
* invoice. NOTE: This parameter can only be passed for a zero-amount invoice. Otherwise, the call will fail.
|
|
707
|
+
* @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
|
|
708
|
+
*/
|
|
709
|
+
public async payUmaInvoice(
|
|
710
|
+
payerNodeId: string,
|
|
711
|
+
encodedInvoice: string,
|
|
712
|
+
maximumFeesMsats: number,
|
|
713
|
+
timeoutSecs: number = 60,
|
|
714
|
+
amountMsats: number | undefined = undefined,
|
|
715
|
+
): Promise<OutgoingPayment | undefined> {
|
|
716
|
+
if (!this.nodeKeyCache.hasKey(payerNodeId)) {
|
|
717
|
+
throw new LightsparkSigningException("Paying node is not unlocked");
|
|
718
|
+
}
|
|
719
|
+
const variables: Record<string, string | number> = {
|
|
720
|
+
node_id: payerNodeId,
|
|
721
|
+
encoded_invoice: encodedInvoice,
|
|
722
|
+
timeout_secs: timeoutSecs,
|
|
723
|
+
maximum_fees_msats: maximumFeesMsats,
|
|
724
|
+
};
|
|
725
|
+
if (amountMsats !== undefined) {
|
|
726
|
+
variables.amount_msats = amountMsats;
|
|
727
|
+
}
|
|
728
|
+
const response = await this.requester.makeRawRequest(
|
|
729
|
+
PayUmaInvoice,
|
|
730
|
+
variables,
|
|
731
|
+
payerNodeId,
|
|
732
|
+
);
|
|
733
|
+
if (response.pay_invoice?.payment.outgoing_payment_failure_message) {
|
|
734
|
+
throw new LightsparkException(
|
|
735
|
+
"PaymentError",
|
|
736
|
+
response.pay_invoice?.payment.outgoing_payment_failure_message
|
|
737
|
+
.rich_text_text,
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
return (
|
|
741
|
+
response.pay_uma_invoice &&
|
|
742
|
+
OutgoingPaymentFromJson(response.pay_invoice.payment)
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
|
|
655
746
|
/**
|
|
656
747
|
* Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
|
|
657
748
|
*
|
|
@@ -897,6 +988,4 @@ class LightsparkClient {
|
|
|
897
988
|
}
|
|
898
989
|
}
|
|
899
990
|
|
|
900
|
-
const LIGHTSPARK_SDK_ENDPOINT = "graphql/server/2023-04-04";
|
|
901
|
-
|
|
902
991
|
export default LightsparkClient;
|
|
@@ -6,8 +6,9 @@ export const CreateInvoice = `
|
|
|
6
6
|
$amount_msats: Long!
|
|
7
7
|
$memo: String
|
|
8
8
|
$type: InvoiceType = null
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
$expiry_secs: Int = null
|
|
10
|
+
) {
|
|
11
|
+
create_invoice(input: { node_id: $node_id, amount_msats: $amount_msats, memo: $memo, invoice_type: $type, expiry_secs: $expiry_secs }) {
|
|
11
12
|
invoice {
|
|
12
13
|
data {
|
|
13
14
|
encoded_payment_request
|
|
@@ -6,11 +6,13 @@ mutation CreateLnurlInvoice(
|
|
|
6
6
|
$node_id: ID!
|
|
7
7
|
$amount_msats: Long!
|
|
8
8
|
$metadata_hash: String!
|
|
9
|
+
$expiry_secs: Int = null
|
|
9
10
|
) {
|
|
10
11
|
create_lnurl_invoice(input: {
|
|
11
12
|
node_id: $node_id
|
|
12
13
|
amount_msats: $amount_msats
|
|
13
14
|
metadata_hash: $metadata_hash
|
|
15
|
+
expiry_secs: $expiry_secs
|
|
14
16
|
}) {
|
|
15
17
|
invoice {
|
|
16
18
|
...InvoiceFragment
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
import { FRAGMENT as InvoiceFragment } from "../objects/Invoice.js";
|
|
3
|
+
|
|
4
|
+
export const CreateUmaInvoice = `
|
|
5
|
+
mutation CreateUmaInvoice(
|
|
6
|
+
$node_id: ID!
|
|
7
|
+
$amount_msats: Long!
|
|
8
|
+
$metadata_hash: String!
|
|
9
|
+
$expiry_secs: Int = null
|
|
10
|
+
) {
|
|
11
|
+
create_uma_invoice(input: {
|
|
12
|
+
node_id: $node_id
|
|
13
|
+
amount_msats: $amount_msats
|
|
14
|
+
metadata_hash: $metadata_hash
|
|
15
|
+
expiry_secs: $expiry_secs
|
|
16
|
+
}) {
|
|
17
|
+
invoice {
|
|
18
|
+
...InvoiceFragment
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
${InvoiceFragment}
|
|
23
|
+
`;
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import type { Maybe } from "@lightsparkdev/core";
|
|
4
4
|
import type CurrencyAmount from "../objects/CurrencyAmount.js";
|
|
5
5
|
import { FRAGMENT as CurrencyAmountFragment } from "../objects/CurrencyAmount.js";
|
|
6
|
-
import type LightsparkNodePurpose from "../objects/LightsparkNodePurpose.js";
|
|
7
6
|
import type LightsparkNodeStatus from "../objects/LightsparkNodeStatus.js";
|
|
8
7
|
import type NodeAddressType from "../objects/NodeAddressType.js";
|
|
9
8
|
|
|
@@ -14,7 +13,6 @@ export type AccountDashboard = {
|
|
|
14
13
|
id: string;
|
|
15
14
|
color: Maybe<string>;
|
|
16
15
|
displayName: string;
|
|
17
|
-
purpose: Maybe<LightsparkNodePurpose>;
|
|
18
16
|
publicKey: Maybe<string>;
|
|
19
17
|
status: Maybe<LightsparkNodeStatus>;
|
|
20
18
|
addresses: {
|
|
@@ -57,7 +55,6 @@ export const MultiNodeDashboard = `
|
|
|
57
55
|
entities {
|
|
58
56
|
color
|
|
59
57
|
display_name
|
|
60
|
-
purpose
|
|
61
58
|
id
|
|
62
59
|
addresses(first: 1) {
|
|
63
60
|
entities {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
|
+
|
|
3
|
+
import { FRAGMENT as OutgoingPaymentFragment } from "../objects/OutgoingPayment.js";
|
|
4
|
+
|
|
5
|
+
export const PayUmaInvoice = `
|
|
6
|
+
mutation PayUmaInvoice(
|
|
7
|
+
$node_id: ID!
|
|
8
|
+
$encoded_invoice: String!
|
|
9
|
+
$timeout_secs: Int!
|
|
10
|
+
$maximum_fees_msats: Long!
|
|
11
|
+
$amount_msats: Long
|
|
12
|
+
) {
|
|
13
|
+
pay_uma_invoice(
|
|
14
|
+
input: {
|
|
15
|
+
node_id: $node_id
|
|
16
|
+
encoded_invoice: $encoded_invoice
|
|
17
|
+
timeout_secs: $timeout_secs
|
|
18
|
+
maximum_fees_msats: $maximum_fees_msats
|
|
19
|
+
amount_msats: $amount_msats
|
|
20
|
+
}
|
|
21
|
+
) {
|
|
22
|
+
payment {
|
|
23
|
+
...OutgoingPaymentFragment
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
${OutgoingPaymentFragment}
|
|
29
|
+
`;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
*/
|
|
5
|
+
export enum Network {
|
|
6
|
+
Bitcoin = 0,
|
|
7
|
+
Testnet = 1,
|
|
8
|
+
Regtest = 2,
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
*/
|
|
12
|
+
export class InvoiceSignature {
|
|
13
|
+
free(): void;
|
|
14
|
+
/**
|
|
15
|
+
* @returns {Uint8Array}
|
|
16
|
+
*/
|
|
17
|
+
get_signature(): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
get_recovery_id(): number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*/
|
|
25
|
+
export class LightsparkSigner {
|
|
26
|
+
free(): void;
|
|
27
|
+
/**
|
|
28
|
+
* @param {Seed} seed
|
|
29
|
+
* @param {number} network
|
|
30
|
+
* @returns {LightsparkSigner}
|
|
31
|
+
*/
|
|
32
|
+
static new(seed: Seed, network: number): LightsparkSigner;
|
|
33
|
+
/**
|
|
34
|
+
* @param {Uint8Array} seed
|
|
35
|
+
* @param {number} network
|
|
36
|
+
* @returns {LightsparkSigner}
|
|
37
|
+
*/
|
|
38
|
+
static from_bytes(seed: Uint8Array, network: number): LightsparkSigner;
|
|
39
|
+
/**
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
get_master_public_key(): string;
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} derivation_path
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
derive_public_key(derivation_path: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* @param {Uint8Array} message
|
|
50
|
+
* @param {string} derivation_path
|
|
51
|
+
* @param {boolean} is_raw
|
|
52
|
+
* @param {Uint8Array | undefined} add_tweak
|
|
53
|
+
* @param {Uint8Array | undefined} mul_tweak
|
|
54
|
+
* @returns {Uint8Array}
|
|
55
|
+
*/
|
|
56
|
+
derive_key_and_sign(
|
|
57
|
+
message: Uint8Array,
|
|
58
|
+
derivation_path: string,
|
|
59
|
+
is_raw: boolean,
|
|
60
|
+
add_tweak?: Uint8Array,
|
|
61
|
+
mul_tweak?: Uint8Array,
|
|
62
|
+
): Uint8Array;
|
|
63
|
+
/**
|
|
64
|
+
* @param {Uint8Array} public_key
|
|
65
|
+
* @returns {Uint8Array}
|
|
66
|
+
*/
|
|
67
|
+
ecdh(public_key: Uint8Array): Uint8Array;
|
|
68
|
+
/**
|
|
69
|
+
* @param {string} derivation_path
|
|
70
|
+
* @param {bigint} per_commitment_point_idx
|
|
71
|
+
* @returns {Uint8Array}
|
|
72
|
+
*/
|
|
73
|
+
get_per_commitment_point(
|
|
74
|
+
derivation_path: string,
|
|
75
|
+
per_commitment_point_idx: bigint,
|
|
76
|
+
): Uint8Array;
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} derivation_path
|
|
79
|
+
* @param {bigint} per_commitment_point_idx
|
|
80
|
+
* @returns {Uint8Array}
|
|
81
|
+
*/
|
|
82
|
+
release_per_commitment_secret(
|
|
83
|
+
derivation_path: string,
|
|
84
|
+
per_commitment_point_idx: bigint,
|
|
85
|
+
): Uint8Array;
|
|
86
|
+
/**
|
|
87
|
+
* @returns {Uint8Array}
|
|
88
|
+
*/
|
|
89
|
+
generate_preimage_nonce(): Uint8Array;
|
|
90
|
+
/**
|
|
91
|
+
* @param {Uint8Array} nonce
|
|
92
|
+
* @returns {Uint8Array}
|
|
93
|
+
*/
|
|
94
|
+
generate_preimage(nonce: Uint8Array): Uint8Array;
|
|
95
|
+
/**
|
|
96
|
+
* @param {Uint8Array} nonce
|
|
97
|
+
* @returns {Uint8Array}
|
|
98
|
+
*/
|
|
99
|
+
generate_preimage_hash(nonce: Uint8Array): Uint8Array;
|
|
100
|
+
/**
|
|
101
|
+
* @param {string} derivation_path
|
|
102
|
+
* @returns {string}
|
|
103
|
+
*/
|
|
104
|
+
derive_private_key(derivation_path: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* @param {string} unsigned_invoice
|
|
107
|
+
* @returns {InvoiceSignature}
|
|
108
|
+
*/
|
|
109
|
+
sign_invoice_wasm(unsigned_invoice: string): InvoiceSignature;
|
|
110
|
+
/**
|
|
111
|
+
* @param {Uint8Array} invoice_hash
|
|
112
|
+
* @returns {InvoiceSignature}
|
|
113
|
+
*/
|
|
114
|
+
sign_invoice_hash_wasm(invoice_hash: Uint8Array): InvoiceSignature;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
*/
|
|
118
|
+
export class Mnemonic {
|
|
119
|
+
free(): void;
|
|
120
|
+
/**
|
|
121
|
+
* @returns {Mnemonic}
|
|
122
|
+
*/
|
|
123
|
+
static random(): Mnemonic;
|
|
124
|
+
/**
|
|
125
|
+
* @param {Uint8Array} entropy
|
|
126
|
+
* @returns {Mnemonic}
|
|
127
|
+
*/
|
|
128
|
+
static from_entropy(entropy: Uint8Array): Mnemonic;
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} phrase
|
|
131
|
+
* @returns {Mnemonic}
|
|
132
|
+
*/
|
|
133
|
+
static from_phrase(phrase: string): Mnemonic;
|
|
134
|
+
/**
|
|
135
|
+
* @returns {string}
|
|
136
|
+
*/
|
|
137
|
+
as_string(): string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
*/
|
|
141
|
+
export class Seed {
|
|
142
|
+
free(): void;
|
|
143
|
+
/**
|
|
144
|
+
* @param {Mnemonic} mnemonic
|
|
145
|
+
* @returns {Seed}
|
|
146
|
+
*/
|
|
147
|
+
static from_mnemonic(mnemonic: Mnemonic): Seed;
|
|
148
|
+
/**
|
|
149
|
+
* @param {Uint8Array} seed
|
|
150
|
+
* @returns {Seed}
|
|
151
|
+
*/
|
|
152
|
+
static new(seed: Uint8Array): Seed;
|
|
153
|
+
/**
|
|
154
|
+
* @returns {Uint8Array}
|
|
155
|
+
*/
|
|
156
|
+
as_bytes(): Uint8Array;
|
|
157
|
+
}
|