@lightsparkdev/lightspark-sdk 0.4.10 → 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.
Files changed (125) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -1
  3. package/dist/{chunk-NXUFC5J7.js → chunk-LZC5C5NI.js} +2908 -635
  4. package/dist/{index-3ffe9e7b.d.ts → index-09d4ac20.d.ts} +373 -62
  5. package/dist/index.cjs +3395 -842
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +390 -94
  8. package/dist/objects/index.cjs +2735 -553
  9. package/dist/objects/index.d.ts +1 -1
  10. package/dist/objects/index.js +17 -5
  11. package/package.json +12 -9
  12. package/src/NodeKeyLoaderCache.ts +87 -0
  13. package/src/SigningKeyLoader.ts +177 -0
  14. package/src/auth/AccountTokenAuthProvider.ts +4 -4
  15. package/src/client.ts +209 -118
  16. package/src/graphql/CreateInvoice.ts +3 -2
  17. package/src/graphql/CreateLnurlInvoice.ts +2 -0
  18. package/src/graphql/CreateUmaInvoice.ts +23 -0
  19. package/src/graphql/MultiNodeDashboard.ts +0 -3
  20. package/src/graphql/PayUmaInvoice.ts +29 -0
  21. package/src/graphql/RecoverNodeSigningKey.ts +1 -1
  22. package/src/graphql/SingleNodeDashboard.ts +0 -1
  23. package/src/lightspark_crypto/lightspark_crypto.d.ts +157 -0
  24. package/src/lightspark_crypto/lightspark_crypto.js +1010 -0
  25. package/src/lightspark_crypto/lightspark_crypto_bg.wasm +0 -0
  26. package/src/lightspark_crypto/lightspark_crypto_bg.wasm.d.ts +120 -0
  27. package/src/lightspark_crypto/package.json +11 -0
  28. package/src/objects/Account.ts +437 -120
  29. package/src/objects/AccountToApiTokensConnection.ts +3 -3
  30. package/src/objects/AccountToChannelsConnection.ts +4 -4
  31. package/src/objects/AccountToNodesConnection.ts +2 -15
  32. package/src/objects/AccountToPaymentRequestsConnection.ts +3 -3
  33. package/src/objects/AccountToTransactionsConnection.ts +6 -6
  34. package/src/objects/AccountToWalletsConnection.ts +2 -2
  35. package/src/objects/Balances.ts +2 -2
  36. package/src/objects/Channel.ts +4 -4
  37. package/src/objects/ChannelClosingTransaction.ts +2 -2
  38. package/src/objects/ChannelOpeningTransaction.ts +2 -2
  39. package/src/objects/ChannelToTransactionsConnection.ts +4 -4
  40. package/src/objects/{CryptoSanctionsScreeningProvider.ts → ComplianceProvider.ts} +3 -3
  41. package/src/objects/Connection.ts +25 -31
  42. package/src/objects/CreateApiTokenInput.ts +1 -1
  43. package/src/objects/CreateApiTokenOutput.ts +1 -1
  44. package/src/objects/CreateInvoiceInput.ts +0 -6
  45. package/src/objects/CreateLnurlInvoiceInput.ts +1 -7
  46. package/src/objects/CreateNodeWalletAddressInput.ts +1 -1
  47. package/src/objects/CreateNodeWalletAddressOutput.ts +1 -1
  48. package/src/objects/CreateTestModeInvoiceInput.ts +1 -1
  49. package/src/objects/CreateTestModeInvoiceOutput.ts +1 -1
  50. package/src/objects/CreateTestModePaymentInput.ts +1 -1
  51. package/src/objects/CreateTestModePaymentoutput.ts +14 -2
  52. package/src/objects/CreateUmaInvoiceInput.ts +24 -0
  53. package/src/objects/DeclineToSignMessagesInput.ts +16 -0
  54. package/src/objects/DeclineToSignMessagesOutput.ts +28 -0
  55. package/src/objects/DeleteApiTokenOutput.ts +1 -1
  56. package/src/objects/Entity.ts +401 -66
  57. package/src/objects/GraphNode.ts +3 -3
  58. package/src/objects/IdAndSignature.ts +16 -0
  59. package/src/objects/IncomingPayment.ts +21 -8
  60. package/src/objects/IncomingPaymentAttempt.ts +2 -2
  61. package/src/objects/IncomingPaymentToAttemptsConnection.ts +3 -3
  62. package/src/objects/Invoice.ts +118 -21
  63. package/src/objects/InvoiceData.ts +118 -21
  64. package/src/objects/LightningFeeEstimateForInvoiceInput.ts +1 -1
  65. package/src/objects/LightningFeeEstimateForNodeInput.ts +1 -1
  66. package/src/objects/LightningFeeEstimateOutput.ts +2 -2
  67. package/src/objects/LightningTransaction.ts +155 -31
  68. package/src/objects/LightsparkNode.ts +272 -112
  69. package/src/objects/LightsparkNodeOwner.ts +8 -4
  70. package/src/objects/LightsparkNodeToChannelsConnection.ts +3 -3
  71. package/src/objects/LightsparkNodeWithOSK.ts +389 -0
  72. package/src/objects/LightsparkNodeWithRemoteSigning.ts +384 -0
  73. package/src/objects/Node.ts +213 -60
  74. package/src/objects/NodeToAddressesConnection.ts +2 -2
  75. package/src/objects/OnChainTransaction.ts +2 -2
  76. package/src/objects/OutgoingPayment.ts +139 -24
  77. package/src/objects/OutgoingPaymentAttempt.ts +5 -5
  78. package/src/objects/OutgoingPaymentAttemptToHopsConnection.ts +3 -3
  79. package/src/objects/OutgoingPaymentToAttemptsConnection.ts +3 -3
  80. package/src/objects/OutgoingPaymentsForInvoiceQueryInput.ts +25 -0
  81. package/src/objects/OutgoingPaymentsForInvoiceQueryOutput.ts +28 -0
  82. package/src/objects/PayUmaInvoiceInput.ts +25 -0
  83. package/src/objects/{LightsparkNodePurpose.ts → PaymentDirection.ts} +5 -7
  84. package/src/objects/PaymentRequest.ts +119 -22
  85. package/src/objects/PaymentRequestData.ts +119 -22
  86. package/src/objects/PostTransactionData.ts +39 -0
  87. package/src/objects/RegisterPaymentInput.ts +31 -0
  88. package/src/objects/RegisterPaymentOutput.ts +23 -0
  89. package/src/objects/ReleaseChannelPerCommitmentSecretInput.ts +23 -0
  90. package/src/objects/ReleaseChannelPerCommitmentSecretOutput.ts +23 -0
  91. package/src/objects/ReleasePaymentPreimageInput.ts +20 -0
  92. package/src/objects/ReleasePaymentPreimageOutput.ts +23 -0
  93. package/src/objects/RemoteSigningSubEventType.ts +26 -0
  94. package/src/objects/RequestWithdrawalInput.ts +1 -1
  95. package/src/objects/RequestWithdrawalOutput.ts +1 -1
  96. package/src/objects/RoutingTransaction.ts +1 -1
  97. package/src/objects/ScreenNodeInput.ts +20 -0
  98. package/src/objects/ScreenNodeOutput.ts +22 -0
  99. package/src/objects/SetInvoicePaymentHashInput.ts +24 -0
  100. package/src/objects/SetInvoicePaymentHashOutput.ts +23 -0
  101. package/src/objects/SignInvoiceInput.ts +19 -0
  102. package/src/objects/SignInvoiceOutput.ts +21 -0
  103. package/src/objects/SignMessagesInput.ts +18 -0
  104. package/src/objects/SignMessagesOutput.ts +26 -0
  105. package/src/objects/Signable.ts +58 -0
  106. package/src/objects/SignablePayload.ts +93 -0
  107. package/src/objects/SignablePayloadStatus.ts +17 -0
  108. package/src/objects/SingleNodeDashboard.ts +0 -2
  109. package/src/objects/Transaction.ts +153 -29
  110. package/src/objects/TransactionFailures.ts +1 -1
  111. package/src/objects/UpdateChannelPerCommitmentPointInput.ts +25 -0
  112. package/src/objects/UpdateChannelPerCommitmentPointOutput.ts +23 -0
  113. package/src/objects/UpdateNodeSharedSecretInput.ts +18 -0
  114. package/src/objects/UpdateNodeSharedSecretOutput.ts +23 -0
  115. package/src/objects/Wallet.ts +271 -51
  116. package/src/objects/WalletToPaymentRequestsConnection.ts +3 -3
  117. package/src/objects/WalletToTransactionsConnection.ts +3 -3
  118. package/src/objects/WithdrawalRequest.ts +6 -6
  119. package/src/objects/WithdrawalRequestToChannelClosingTransactionsConnection.ts +2 -2
  120. package/src/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.ts +2 -2
  121. package/src/objects/index.ts +37 -4
  122. package/src/{__tests__ → tests}/webhooks.test.ts +1 -1
  123. package/src/webhooks.ts +1 -1
  124. package/src/objects/ScreenBitcoinAddressesInput.ts +0 -23
  125. package/src/objects/ScreenBitcoinAddressesOutput.ts +0 -25
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  BitcoinNetwork_default,
6
6
  ChannelStatus_default,
7
7
  Channel_default,
8
- CryptoSanctionsScreeningProvider_default,
8
+ ComplianceProvider_default,
9
9
  CurrencyAmountFromJson,
10
10
  CurrencyUnit_default,
11
11
  FRAGMENT,
@@ -26,8 +26,9 @@ import {
26
26
  InvoiceDataFromJson,
27
27
  InvoiceFromJson,
28
28
  InvoiceType_default,
29
- LightsparkNodePurpose_default,
30
29
  LightsparkNodeStatus_default,
30
+ LightsparkNodeWithOSK_default,
31
+ LightsparkNodeWithRemoteSigning_default,
31
32
  LightsparkNode_default,
32
33
  NodeAddressType_default,
33
34
  Node_default,
@@ -35,11 +36,14 @@ import {
35
36
  OutgoingPaymentAttempt_default,
36
37
  OutgoingPaymentFromJson,
37
38
  OutgoingPayment_default,
39
+ PaymentDirection_default,
38
40
  PaymentFailureReason_default,
39
41
  PaymentRequestStatus_default,
40
42
  Permission_default,
43
+ RemoteSigningSubEventType_default,
41
44
  RiskRating_default,
42
45
  RoutingTransactionFailureReason_default,
46
+ SignablePayloadStatus_default,
43
47
  TransactionFromJson,
44
48
  TransactionStatus_default,
45
49
  TransactionType_default,
@@ -64,9 +68,11 @@ import {
64
68
  getOnChainTransactionQuery,
65
69
  getPaymentRequestQuery,
66
70
  getRoutingTransactionQuery,
71
+ getSignablePayloadQuery,
72
+ getSignableQuery,
67
73
  getTransactionQuery,
68
74
  getWithdrawalQuery
69
- } from "./chunk-NXUFC5J7.js";
75
+ } from "./chunk-LZC5C5NI.js";
70
76
  import "./chunk-NIMBE7W3.js";
71
77
 
72
78
  // src/auth/AccountTokenAuthProvider.ts
@@ -102,14 +108,13 @@ var AccountTokenAuthProvider_default = AccountTokenAuthProvider;
102
108
  // src/client.ts
103
109
  import autoBind2 from "auto-bind";
104
110
  import {
105
- b64encode as b64encode2,
106
- DefaultCrypto,
107
- KeyOrAlias,
111
+ DefaultCrypto as DefaultCrypto2,
108
112
  LightsparkAuthException,
109
113
  LightsparkException,
110
- LightsparkSigningException,
114
+ LightsparkSigningException as LightsparkSigningException3,
111
115
  NodeKeyCache,
112
116
  Requester,
117
+ SigningKeyType as SigningKeyType2,
113
118
  StubAuthProvider
114
119
  } from "@lightsparkdev/core";
115
120
  import { createHash } from "crypto";
@@ -117,7 +122,7 @@ import { createHash } from "crypto";
117
122
  // package.json
118
123
  var package_default = {
119
124
  name: "@lightsparkdev/lightspark-sdk",
120
- version: "0.4.10",
125
+ version: "1.0.0",
121
126
  description: "Lightspark JS SDK",
122
127
  author: "Lightspark Inc.",
123
128
  keywords: [
@@ -136,7 +141,7 @@ var package_default = {
136
141
  url: "https://github.com/lightsparkdev/js-sdk/issues"
137
142
  },
138
143
  engines: {
139
- node: ">=14.16"
144
+ node: ">=18.17.0"
140
145
  },
141
146
  exports: {
142
147
  ".": {
@@ -165,7 +170,9 @@ var package_default = {
165
170
  main: "./dist/index.js",
166
171
  module: "./dist/index.js",
167
172
  browser: {
168
- crypto: false
173
+ crypto: false,
174
+ fs: false,
175
+ path: false
169
176
  },
170
177
  files: [
171
178
  "src/*",
@@ -173,13 +180,14 @@ var package_default = {
173
180
  "CHANGELOG.md"
174
181
  ],
175
182
  scripts: {
176
- build: "tsup --entry src/index.ts --entry src/objects/index.ts --format cjs,esm --dts",
183
+ build: "tsup",
177
184
  clean: "rm -rf .turbo && rm -rf dist",
178
185
  dev: "yarn build -- --watch",
179
186
  docs: "typedoc src",
180
187
  "format:fix": "prettier src --write",
181
188
  format: "prettier src --check",
182
189
  "lint:fix": "eslint --fix .",
190
+ "lint:fix:continue": "eslint --fix . || exit 0",
183
191
  "lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
184
192
  lint: "eslint .",
185
193
  postversion: "yarn build",
@@ -189,7 +197,7 @@ var package_default = {
189
197
  },
190
198
  license: "Apache-2.0",
191
199
  dependencies: {
192
- "@lightsparkdev/core": "0.3.10",
200
+ "@lightsparkdev/core": "1.0.0",
193
201
  "auto-bind": "^5.0.1",
194
202
  crypto: "^1.0.1",
195
203
  "crypto-browserify": "^3.12.0",
@@ -203,14 +211,14 @@ var package_default = {
203
211
  "@lightsparkdev/eslint-config": "*",
204
212
  "@lightsparkdev/tsconfig": "0.0.0",
205
213
  "@types/crypto-js": "^4.1.1",
206
- "@types/jest": "^29.5.2",
214
+ "@types/jest": "^29.5.3",
207
215
  "@types/ws": "^8.5.4",
208
216
  eslint: "^8.3.0",
209
217
  "eslint-watch": "^8.0.0",
210
- jest: "^29.4.1",
211
- prettier: "2.8.7",
218
+ jest: "^29.6.2",
219
+ prettier: "3.0.2",
212
220
  "prettier-plugin-organize-imports": "^3.2.2",
213
- "ts-jest": "^29.0.5",
221
+ "ts-jest": "^29.1.1",
214
222
  "ts-node": "^10.9.1",
215
223
  "tsc-absolute": "^1.0.1",
216
224
  tsup: "^6.7.0",
@@ -257,8 +265,9 @@ var CreateInvoice = `
257
265
  $amount_msats: Long!
258
266
  $memo: String
259
267
  $type: InvoiceType = null
260
- ) {
261
- create_invoice(input: { node_id: $node_id, amount_msats: $amount_msats, memo: $memo, invoice_type: $type }) {
268
+ $expiry_secs: Int = null
269
+ ) {
270
+ create_invoice(input: { node_id: $node_id, amount_msats: $amount_msats, memo: $memo, invoice_type: $type, expiry_secs: $expiry_secs }) {
262
271
  invoice {
263
272
  data {
264
273
  encoded_payment_request
@@ -274,11 +283,13 @@ mutation CreateLnurlInvoice(
274
283
  $node_id: ID!
275
284
  $amount_msats: Long!
276
285
  $metadata_hash: String!
286
+ $expiry_secs: Int = null
277
287
  ) {
278
288
  create_lnurl_invoice(input: {
279
289
  node_id: $node_id
280
290
  amount_msats: $amount_msats
281
291
  metadata_hash: $metadata_hash
292
+ expiry_secs: $expiry_secs
282
293
  }) {
283
294
  invoice {
284
295
  ...InvoiceFragment
@@ -341,6 +352,28 @@ mutation CreateTestModePayment(
341
352
  ${FRAGMENT6}
342
353
  `;
343
354
 
355
+ // src/graphql/CreateUmaInvoice.ts
356
+ var CreateUmaInvoice = `
357
+ mutation CreateUmaInvoice(
358
+ $node_id: ID!
359
+ $amount_msats: Long!
360
+ $metadata_hash: String!
361
+ $expiry_secs: Int = null
362
+ ) {
363
+ create_uma_invoice(input: {
364
+ node_id: $node_id
365
+ amount_msats: $amount_msats
366
+ metadata_hash: $metadata_hash
367
+ expiry_secs: $expiry_secs
368
+ }) {
369
+ invoice {
370
+ ...InvoiceFragment
371
+ }
372
+ }
373
+ }
374
+ ${FRAGMENT5}
375
+ `;
376
+
344
377
  // src/graphql/DecodeInvoice.ts
345
378
  var DecodeInvoice = `
346
379
  query DecodeInvoice($encoded_payment_request: String!) {
@@ -439,7 +472,6 @@ var MultiNodeDashboard = `
439
472
  entities {
440
473
  color
441
474
  display_name
442
- purpose
443
475
  id
444
476
  addresses(first: 1) {
445
477
  entities {
@@ -525,19 +557,31 @@ var PayInvoice = `
525
557
  ${FRAGMENT6}
526
558
  `;
527
559
 
528
- // src/graphql/RecoverNodeSigningKey.ts
529
- var RecoverNodeSigningKey = `
530
- query RecoverNodeSigningKey($nodeId: ID!) {
531
- entity(id: $nodeId) {
532
- __typename
533
- ... on LightsparkNode {
534
- encrypted_signing_private_key {
535
- encrypted_value
536
- cipher
537
- }
560
+ // src/graphql/PayUmaInvoice.ts
561
+ var PayUmaInvoice = `
562
+ mutation PayUmaInvoice(
563
+ $node_id: ID!
564
+ $encoded_invoice: String!
565
+ $timeout_secs: Int!
566
+ $maximum_fees_msats: Long!
567
+ $amount_msats: Long
568
+ ) {
569
+ pay_uma_invoice(
570
+ input: {
571
+ node_id: $node_id
572
+ encoded_invoice: $encoded_invoice
573
+ timeout_secs: $timeout_secs
574
+ maximum_fees_msats: $maximum_fees_msats
575
+ amount_msats: $amount_msats
576
+ }
577
+ ) {
578
+ payment {
579
+ ...OutgoingPaymentFragment
538
580
  }
539
581
  }
540
582
  }
583
+
584
+ ${FRAGMENT6}
541
585
  `;
542
586
 
543
587
  // src/graphql/RequestWithdrawal.ts
@@ -612,7 +656,6 @@ query SingleNodeDashboard(
612
656
  entities {
613
657
  color
614
658
  display_name
615
- purpose
616
659
  id
617
660
  addresses(first: 1) {
618
661
  entities {
@@ -756,6 +799,183 @@ subscription TransactionSubscription(
756
799
  ${FRAGMENT10}
757
800
  `;
758
801
 
802
+ // src/NodeKeyLoaderCache.ts
803
+ import {
804
+ LightsparkSigningException as LightsparkSigningException2
805
+ } from "@lightsparkdev/core";
806
+
807
+ // src/SigningKeyLoader.ts
808
+ import {
809
+ b64encode as b64encode2,
810
+ LightsparkSigningException,
811
+ SigningKeyType
812
+ } from "@lightsparkdev/core";
813
+
814
+ // src/graphql/RecoverNodeSigningKey.ts
815
+ var RecoverNodeSigningKey = `
816
+ query RecoverNodeSigningKey($nodeId: ID!) {
817
+ entity(id: $nodeId) {
818
+ __typename
819
+ ... on LightsparkNodeWithOSK {
820
+ encrypted_signing_private_key {
821
+ encrypted_value
822
+ cipher
823
+ }
824
+ }
825
+ }
826
+ }
827
+ `;
828
+
829
+ // src/SigningKeyLoader.ts
830
+ import {
831
+ LightsparkSigner,
832
+ Network
833
+ } from "../src/lightspark_crypto/lightspark_crypto.js";
834
+ var SIGNING_KEY_PATH = "m/5";
835
+ var getCryptoLibNetwork = (bitcoinNetwork) => {
836
+ switch (bitcoinNetwork) {
837
+ case BitcoinNetwork_default.MAINNET:
838
+ return Network.Bitcoin;
839
+ case BitcoinNetwork_default.TESTNET:
840
+ return Network.Testnet;
841
+ case BitcoinNetwork_default.REGTEST:
842
+ return Network.Regtest;
843
+ default:
844
+ throw new Error(
845
+ `Unsupported lightspark_crypto network ${bitcoinNetwork}.`
846
+ );
847
+ }
848
+ };
849
+ function isNodeIdAndPasswordSigningKeyLoaderArgs(args) {
850
+ return args.password !== void 0;
851
+ }
852
+ function isMasterSeedSigningKeyLoaderArgs(args) {
853
+ return args.masterSeed !== void 0;
854
+ }
855
+ var NodeIdAndPasswordSigningKeyLoader = class {
856
+ nodeId;
857
+ password;
858
+ requester;
859
+ cryptoImpl;
860
+ constructor(args, requester, cryptoImpl) {
861
+ this.nodeId = args.nodeId;
862
+ this.password = args.password;
863
+ this.requester = requester;
864
+ this.cryptoImpl = cryptoImpl;
865
+ }
866
+ async loadSigningKey() {
867
+ const encryptedKey = await this.recoverNodeSigningKey();
868
+ if (!encryptedKey) {
869
+ console.warn("No encrypted key found for node " + this.nodeId);
870
+ return;
871
+ }
872
+ const signingPrivateKey = await this.cryptoImpl.decryptSecretWithNodePassword(
873
+ encryptedKey.cipher,
874
+ encryptedKey.encrypted_value,
875
+ this.password
876
+ );
877
+ if (!signingPrivateKey) {
878
+ throw new LightsparkSigningException(
879
+ "Unable to decrypt signing key with provided password. Please try again."
880
+ );
881
+ }
882
+ let signingPrivateKeyPEM = "";
883
+ if (new Uint8Array(signingPrivateKey)[0] === 48) {
884
+ signingPrivateKeyPEM = b64encode2(signingPrivateKey);
885
+ } else {
886
+ const dec = new TextDecoder();
887
+ signingPrivateKeyPEM = dec.decode(signingPrivateKey);
888
+ }
889
+ return { key: signingPrivateKeyPEM, type: SigningKeyType.RSASigningKey };
890
+ }
891
+ async recoverNodeSigningKey() {
892
+ const response = await this.requester.makeRawRequest(
893
+ RecoverNodeSigningKey,
894
+ { nodeId: this.nodeId }
895
+ );
896
+ const nodeEntity = response.entity;
897
+ if (nodeEntity?.__typename === "LightsparkNodeWithOSK") {
898
+ return nodeEntity.encrypted_signing_private_key;
899
+ }
900
+ return null;
901
+ }
902
+ };
903
+ var MasterSeedSigningKeyLoader = class {
904
+ masterSeed;
905
+ network;
906
+ constructor(args) {
907
+ this.masterSeed = args.masterSeed;
908
+ this.network = args.network;
909
+ }
910
+ async loadSigningKey() {
911
+ const lightsparkSigner = LightsparkSigner.from_bytes(
912
+ this.masterSeed,
913
+ getCryptoLibNetwork(this.network)
914
+ );
915
+ const privateKey = lightsparkSigner.derive_private_key(SIGNING_KEY_PATH);
916
+ return { key: privateKey, type: SigningKeyType.Secp256k1SigningKey };
917
+ }
918
+ };
919
+
920
+ // src/NodeKeyLoaderCache.ts
921
+ var NodeKeyLoaderCache = class {
922
+ constructor(nodeKeyCache, cryptoImpl = DefaultCrypto) {
923
+ this.nodeKeyCache = nodeKeyCache;
924
+ this.cryptoImpl = cryptoImpl;
925
+ this.idToLoader = /* @__PURE__ */ new Map();
926
+ }
927
+ idToLoader;
928
+ /**
929
+ * Sets the signing key loader for a node.
930
+ * Instantiates a signing key loader based on the type of args passed in by the user.
931
+ *
932
+ * @param nodeId The ID of the node to get the key for
933
+ * @param loaderArgs Loader arguments for loading the key
934
+ * @param requester Requester used for loading the key
935
+ */
936
+ setLoader(nodeId, loaderArgs, requester) {
937
+ let loader;
938
+ if (isNodeIdAndPasswordSigningKeyLoaderArgs(loaderArgs)) {
939
+ loader = new NodeIdAndPasswordSigningKeyLoader(
940
+ { nodeId, ...loaderArgs },
941
+ requester,
942
+ this.cryptoImpl
943
+ );
944
+ } else if (isMasterSeedSigningKeyLoaderArgs(loaderArgs)) {
945
+ loader = new MasterSeedSigningKeyLoader({ ...loaderArgs });
946
+ } else {
947
+ throw new LightsparkSigningException2("Invalid signing key loader args");
948
+ }
949
+ this.idToLoader.set(nodeId, loader);
950
+ }
951
+ /**
952
+ * Gets the key for a node using the loader set by [setLoader]
953
+ *
954
+ * @param id The ID of the node to get the key for
955
+ * @returns The loaded key
956
+ */
957
+ async getKeyWithLoader(id) {
958
+ if (this.nodeKeyCache.hasKey(id)) {
959
+ return this.nodeKeyCache.getKey(id);
960
+ }
961
+ const loader = this.idToLoader.get(id);
962
+ if (!loader) {
963
+ throw new LightsparkSigningException2(
964
+ "No signing key loader found for node " + id
965
+ );
966
+ }
967
+ const loaderResult = await loader.loadSigningKey();
968
+ if (!loaderResult) {
969
+ return;
970
+ }
971
+ return this.nodeKeyCache.loadKey(
972
+ id,
973
+ { key: loaderResult.key },
974
+ loaderResult.type
975
+ );
976
+ }
977
+ };
978
+
759
979
  // src/client.ts
760
980
  var sdkVersion = package_default.version;
761
981
  var LightsparkClient = class {
@@ -768,14 +988,18 @@ var LightsparkClient = class {
768
988
  * @param cryptoImpl The crypto implementation to use. Defaults to web and node compatible crypto.
769
989
  * For React Native, you should use the `ReactNativeCrypto` implementation from `@lightsparkdev/react-native`.
770
990
  */
771
- constructor(authProvider = new StubAuthProvider(), serverUrl = "api.lightspark.com", cryptoImpl = DefaultCrypto) {
991
+ constructor(authProvider = new StubAuthProvider(), serverUrl = "api.lightspark.com", cryptoImpl = DefaultCrypto2) {
772
992
  this.authProvider = authProvider;
773
993
  this.serverUrl = serverUrl;
774
994
  this.cryptoImpl = cryptoImpl;
775
995
  this.nodeKeyCache = new NodeKeyCache(this.cryptoImpl);
996
+ this.nodeKeyLoaderCache = new NodeKeyLoaderCache(
997
+ this.nodeKeyCache,
998
+ this.cryptoImpl
999
+ );
776
1000
  this.requester = new Requester(
777
1001
  this.nodeKeyCache,
778
- LIGHTSPARK_SDK_ENDPOINT,
1002
+ this.LIGHTSPARK_SDK_ENDPOINT,
779
1003
  `js-lightspark-sdk/${sdkVersion}`,
780
1004
  authProvider,
781
1005
  serverUrl,
@@ -785,6 +1009,30 @@ var LightsparkClient = class {
785
1009
  }
786
1010
  requester;
787
1011
  nodeKeyCache;
1012
+ nodeKeyLoaderCache;
1013
+ LIGHTSPARK_SDK_ENDPOINT = process.env.LIGHTSPARK_SDK_ENDPOINT || "graphql/server/2023-09-13";
1014
+ /**
1015
+ * Sets the key loader for a node. This unlocks client operations that require a private key.
1016
+ * Passing in [NodeIdAndPasswordSigningKeyLoaderArgs] loads the RSA key for an OSK node.
1017
+ * Passing in [MasterSeedSigningKeyLoaderArgs] loads the Secp256k1 key for a remote signing node.
1018
+ *
1019
+ * @param nodeId The ID of the node the key is for
1020
+ * @param loader The loader for the key
1021
+ */
1022
+ async loadNodeSigningKey(nodeId, loaderArgs) {
1023
+ this.nodeKeyLoaderCache.setLoader(nodeId, loaderArgs, this.requester);
1024
+ const key = await this.getNodeSigningKey(nodeId);
1025
+ return !!key;
1026
+ }
1027
+ /**
1028
+ * Gets the signing key for a node. Must have previously called [loadNodeSigningKey].
1029
+ *
1030
+ * @param nodeId The ID of the node the key is for
1031
+ * @returns The signing key for the node
1032
+ */
1033
+ async getNodeSigningKey(nodeId) {
1034
+ return await this.nodeKeyLoaderCache.getKeyWithLoader(nodeId);
1035
+ }
788
1036
  /**
789
1037
  * Sets the auth provider for the client. This is useful for switching between auth providers if you are using
790
1038
  * multiple accounts or waiting for the user to log in.
@@ -794,7 +1042,7 @@ var LightsparkClient = class {
794
1042
  async setAuthProvider(authProvider) {
795
1043
  this.requester = new Requester(
796
1044
  this.nodeKeyCache,
797
- LIGHTSPARK_SDK_ENDPOINT,
1045
+ this.LIGHTSPARK_SDK_ENDPOINT,
798
1046
  `js-lightspark-sdk/${sdkVersion}`,
799
1047
  authProvider,
800
1048
  this.serverUrl,
@@ -888,7 +1136,6 @@ var LightsparkClient = class {
888
1136
  return {
889
1137
  color: node.color,
890
1138
  displayName: node.display_name,
891
- purpose: node.purpose,
892
1139
  id: node.id,
893
1140
  publicKey: node.public_key,
894
1141
  status: node.status,
@@ -965,7 +1212,6 @@ var LightsparkClient = class {
965
1212
  return {
966
1213
  color: node.color,
967
1214
  displayName: account.name,
968
- purpose: node.purpose,
969
1215
  id: node.id,
970
1216
  publicKey: node.public_key,
971
1217
  status: node.status,
@@ -1004,15 +1250,23 @@ var LightsparkClient = class {
1004
1250
  * @param type The type of invoice to create. Defaults to a normal payment invoice, but you can pass InvoiceType.AMP
1005
1251
  * to create an [AMP invoice](https://docs.lightning.engineering/lightning-network-tools/lnd/amp), which can be
1006
1252
  * paid multiple times.
1253
+ * @param expirySecs The number of seconds until the invoice expires. Defaults to 86400 (1 day).
1007
1254
  * @returns An encoded payment request for the invoice, or undefined if the invoice could not be created.
1008
1255
  */
1009
- async createInvoice(nodeId, amountMsats, memo, type = void 0) {
1010
- const response = await this.requester.makeRawRequest(CreateInvoice, {
1256
+ async createInvoice(nodeId, amountMsats, memo, type = void 0, expirySecs = void 0) {
1257
+ const variables = {
1011
1258
  node_id: nodeId,
1012
1259
  amount_msats: amountMsats,
1013
1260
  memo,
1014
1261
  type
1015
- });
1262
+ };
1263
+ if (expirySecs !== void 0) {
1264
+ variables["expiry_secs"] = expirySecs;
1265
+ }
1266
+ const response = await this.requester.makeRawRequest(
1267
+ CreateInvoice,
1268
+ variables
1269
+ );
1016
1270
  return response.create_invoice?.invoice.data?.encoded_payment_request;
1017
1271
  }
1018
1272
  /**
@@ -1027,20 +1281,59 @@ var LightsparkClient = class {
1027
1281
  * @param metadata The LNURL metadata payload field in the initial payreq response. This wil be hashed and present in the
1028
1282
  * h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice. See
1029
1283
  * [this spec](https://github.com/lnurl/luds/blob/luds/06.md#pay-to-static-qrnfclink) for details.
1284
+ * @param expirySecs The number of seconds until the invoice expires. Defaults to 86400 (1 day).
1030
1285
  * @returns An Invoice object representing the generated invoice.
1031
1286
  */
1032
- async createLnurlInvoice(nodeId, amountMsats, metadata) {
1033
- const response = await this.requester.makeRawRequest(CreateLnurlInvoice, {
1287
+ async createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
1288
+ const variables = {
1034
1289
  node_id: nodeId,
1035
1290
  amount_msats: amountMsats,
1036
1291
  metadata_hash: createHash("sha256").update(metadata).digest("hex")
1037
- });
1292
+ };
1293
+ if (expirySecs !== void 0) {
1294
+ variables["expiry_secs"] = expirySecs;
1295
+ }
1296
+ const response = await this.requester.makeRawRequest(
1297
+ CreateLnurlInvoice,
1298
+ variables
1299
+ );
1038
1300
  const invoiceJson = response.create_lnurl_invoice?.invoice;
1039
1301
  if (!invoiceJson) {
1040
1302
  return void 0;
1041
1303
  }
1042
1304
  return InvoiceFromJson(invoiceJson);
1043
1305
  }
1306
+ /**
1307
+ * Creates a new invoice for the UMA protocol. The metadata is hashed and included in the invoice.
1308
+ * This API generates a Lightning Invoice (follows the Bolt 11 specification) to request a payment
1309
+ * from another Lightning Node. This should only be used for generating invoices for UMA, with `createInvoice`
1310
+ * preferred in the general case.
1311
+ *
1312
+ * @param nodeId The node ID for which to create an invoice.
1313
+ * @param amountMsats The amount of the invoice in msats. You can create a zero-amount invoice to accept any payment amount.
1314
+ * @param metadata The LNURL metadata payload field in the initial payreq response. This wil be hashed and present in the
1315
+ * h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice. See
1316
+ * [this spec](https://github.com/lnurl/luds/blob/luds/06.md#pay-to-static-qrnfclink) for details.
1317
+ * @param expirySecs The number of seconds until the invoice expires. Defaults to 3600 (1 hour).
1318
+ * @returns An Invoice object representing the generated invoice.
1319
+ */
1320
+ async createUmaInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
1321
+ const variables = {
1322
+ node_id: nodeId,
1323
+ amount_msats: amountMsats,
1324
+ metadata_hash: createHash("sha256").update(metadata).digest("hex"),
1325
+ expiry_secs: expirySecs !== void 0 ? expirySecs : 3600
1326
+ };
1327
+ const response = await this.requester.makeRawRequest(
1328
+ CreateUmaInvoice,
1329
+ variables
1330
+ );
1331
+ const invoiceJson = response.create_uma_invoice?.invoice;
1332
+ if (!invoiceJson) {
1333
+ return void 0;
1334
+ }
1335
+ return InvoiceFromJson(invoiceJson);
1336
+ }
1044
1337
  /**
1045
1338
  * Decodes an encoded lightning invoice string.
1046
1339
  *
@@ -1111,53 +1404,6 @@ var LightsparkClient = class {
1111
1404
  response.lightning_fee_estimate_for_node.lightning_fee_estimate_output_fee_estimate
1112
1405
  );
1113
1406
  }
1114
- /**
1115
- * Unlock the given node for sensitive operations like sending payments.
1116
- *
1117
- * @param nodeId The ID of the node to unlock.
1118
- * @param password The node password assigned at node creation.
1119
- * @returns True if the node was unlocked successfully, false otherwise.
1120
- */
1121
- async unlockNode(nodeId, password) {
1122
- const encryptedKey = await this.recoverNodeSigningKey(nodeId);
1123
- if (!encryptedKey) {
1124
- console.warn("No encrypted key found for node " + nodeId);
1125
- return false;
1126
- }
1127
- const signingPrivateKey = await this.cryptoImpl.decryptSecretWithNodePassword(
1128
- encryptedKey.cipher,
1129
- encryptedKey.encrypted_value,
1130
- password
1131
- );
1132
- if (!signingPrivateKey) {
1133
- throw new LightsparkSigningException(
1134
- "Unable to decrypt signing key with provided password. Please try again."
1135
- );
1136
- }
1137
- let signingPrivateKeyPEM = "";
1138
- if (new Uint8Array(signingPrivateKey)[0] === 48) {
1139
- signingPrivateKeyPEM = b64encode2(signingPrivateKey);
1140
- } else {
1141
- const dec = new TextDecoder();
1142
- signingPrivateKeyPEM = dec.decode(signingPrivateKey);
1143
- }
1144
- await this.nodeKeyCache.loadKey(
1145
- nodeId,
1146
- KeyOrAlias.key(signingPrivateKeyPEM)
1147
- );
1148
- return true;
1149
- }
1150
- async recoverNodeSigningKey(nodeId) {
1151
- const response = await this.requester.makeRawRequest(
1152
- RecoverNodeSigningKey,
1153
- { nodeId }
1154
- );
1155
- const nodeEntity = response.entity;
1156
- if (nodeEntity?.__typename === "LightsparkNode") {
1157
- return nodeEntity.encrypted_signing_private_key;
1158
- }
1159
- return null;
1160
- }
1161
1407
  /**
1162
1408
  * Directly unlocks a node with a signing private key or alias.
1163
1409
  *
@@ -1165,7 +1411,11 @@ var LightsparkClient = class {
1165
1411
  * @param signingPrivateKeyPEM The PEM-encoded signing private key.
1166
1412
  */
1167
1413
  async loadNodeKey(nodeId, signingPrivateKeyOrAlias) {
1168
- await this.nodeKeyCache.loadKey(nodeId, signingPrivateKeyOrAlias);
1414
+ await this.nodeKeyCache.loadKey(
1415
+ nodeId,
1416
+ signingPrivateKeyOrAlias,
1417
+ SigningKeyType2.RSASigningKey
1418
+ );
1169
1419
  }
1170
1420
  /**
1171
1421
  * Sends a lightning payment for a given invoice.
@@ -1185,7 +1435,7 @@ var LightsparkClient = class {
1185
1435
  */
1186
1436
  async payInvoice(payerNodeId, encodedInvoice, maximumFeesMsats, timeoutSecs = 60, amountMsats = void 0) {
1187
1437
  if (!this.nodeKeyCache.hasKey(payerNodeId)) {
1188
- throw new LightsparkSigningException("Paying node is not unlocked");
1438
+ throw new LightsparkSigningException3("Paying node is not unlocked");
1189
1439
  }
1190
1440
  const variables = {
1191
1441
  node_id: payerNodeId,
@@ -1209,6 +1459,47 @@ var LightsparkClient = class {
1209
1459
  }
1210
1460
  return response.pay_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
1211
1461
  }
1462
+ /**
1463
+ * sends an UMA payment to a node on the Lightning Network, based on the invoice
1464
+ * (as defined by the BOLT11 specification) that you provide.
1465
+ * This should only be used for paying UMA invoices, with `payInvoice` preferred in the general case.
1466
+ *
1467
+ * @param payerNodeId The ID of the node that will pay the invoice.
1468
+ * @param encodedInvoice The encoded invoice to pay.
1469
+ * @param maximumFeesMsats Maximum fees (in msats) to pay for the payment. This parameter is required.
1470
+ * As guidance, a maximum fee of 16 basis points should make almost all transactions succeed. For example,
1471
+ * for a transaction between 10k sats and 100k sats, this would mean a fee limit of 16 to 160 sats.
1472
+ * @param timeoutSecs A timeout for the payment in seconds. Defaults to 60 seconds.
1473
+ * @param amountMsats The amount to pay in msats for a zero-amount invoice. Defaults to the full amount of the
1474
+ * invoice. NOTE: This parameter can only be passed for a zero-amount invoice. Otherwise, the call will fail.
1475
+ * @returns An `OutgoingPayment` object if the payment was successful, or undefined if the payment failed.
1476
+ */
1477
+ async payUmaInvoice(payerNodeId, encodedInvoice, maximumFeesMsats, timeoutSecs = 60, amountMsats = void 0) {
1478
+ if (!this.nodeKeyCache.hasKey(payerNodeId)) {
1479
+ throw new LightsparkSigningException3("Paying node is not unlocked");
1480
+ }
1481
+ const variables = {
1482
+ node_id: payerNodeId,
1483
+ encoded_invoice: encodedInvoice,
1484
+ timeout_secs: timeoutSecs,
1485
+ maximum_fees_msats: maximumFeesMsats
1486
+ };
1487
+ if (amountMsats !== void 0) {
1488
+ variables.amount_msats = amountMsats;
1489
+ }
1490
+ const response = await this.requester.makeRawRequest(
1491
+ PayUmaInvoice,
1492
+ variables,
1493
+ payerNodeId
1494
+ );
1495
+ if (response.pay_invoice?.payment.outgoing_payment_failure_message) {
1496
+ throw new LightsparkException(
1497
+ "PaymentError",
1498
+ response.pay_invoice?.payment.outgoing_payment_failure_message.rich_text_text
1499
+ );
1500
+ }
1501
+ return response.pay_uma_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
1502
+ }
1212
1503
  /**
1213
1504
  * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
1214
1505
  *
@@ -1223,7 +1514,7 @@ var LightsparkClient = class {
1223
1514
  */
1224
1515
  async sendPayment(payerNodeId, destinationPublicKey, timeoutSecs = 60, amountMsats, maximumFeesMsats) {
1225
1516
  if (!this.nodeKeyCache.hasKey(payerNodeId)) {
1226
- throw new LightsparkSigningException("Paying node is not unlocked");
1517
+ throw new LightsparkSigningException3("Paying node is not unlocked");
1227
1518
  }
1228
1519
  const response = await this.requester.makeRawRequest(
1229
1520
  SendPayment,
@@ -1404,7 +1695,6 @@ var LightsparkClient = class {
1404
1695
  return this.requester.executeQuery(query);
1405
1696
  }
1406
1697
  };
1407
- var LIGHTSPARK_SDK_ENDPOINT = "graphql/server/2023-04-04";
1408
1698
  var client_default = LightsparkClient;
1409
1699
 
1410
1700
  // src/webhooks.ts
@@ -1440,7 +1730,7 @@ export {
1440
1730
  BitcoinNetwork_default as BitcoinNetwork,
1441
1731
  Channel_default as Channel,
1442
1732
  ChannelStatus_default as ChannelStatus,
1443
- CryptoSanctionsScreeningProvider_default as CryptoSanctionsScreeningProvider,
1733
+ ComplianceProvider_default as ComplianceProvider,
1444
1734
  CurrencyUnit_default as CurrencyUnit,
1445
1735
  GraphNode_default as GraphNode,
1446
1736
  HtlcAttemptFailureCode_default as HtlcAttemptFailureCode,
@@ -1449,18 +1739,22 @@ export {
1449
1739
  InvoiceType_default as InvoiceType,
1450
1740
  client_default as LightsparkClient,
1451
1741
  LightsparkNode_default as LightsparkNode,
1452
- LightsparkNodePurpose_default as LightsparkNodePurpose,
1453
1742
  LightsparkNodeStatus_default as LightsparkNodeStatus,
1743
+ LightsparkNodeWithOSK_default as LightsparkNodeWithOSK,
1744
+ LightsparkNodeWithRemoteSigning_default as LightsparkNodeWithRemoteSigning,
1454
1745
  Node_default as Node,
1455
1746
  NodeAddressType_default as NodeAddressType,
1456
1747
  OutgoingPayment_default as OutgoingPayment,
1457
1748
  OutgoingPaymentAttempt_default as OutgoingPaymentAttempt,
1458
1749
  OutgoingPaymentAttemptStatus_default as OutgoingPaymentAttemptStatus,
1750
+ PaymentDirection_default as PaymentDirection,
1459
1751
  PaymentFailureReason_default as PaymentFailureReason,
1460
1752
  PaymentRequestStatus_default as PaymentRequestStatus,
1461
1753
  Permission_default as Permission,
1754
+ RemoteSigningSubEventType_default as RemoteSigningSubEventType,
1462
1755
  RiskRating_default as RiskRating,
1463
1756
  RoutingTransactionFailureReason_default as RoutingTransactionFailureReason,
1757
+ SignablePayloadStatus_default as SignablePayloadStatus,
1464
1758
  TransactionStatus_default as TransactionStatus,
1465
1759
  TransactionType_default as TransactionType,
1466
1760
  WEBHOOKS_SIGNATURE_HEADER,
@@ -1482,6 +1776,8 @@ export {
1482
1776
  getOnChainTransactionQuery,
1483
1777
  getPaymentRequestQuery,
1484
1778
  getRoutingTransactionQuery,
1779
+ getSignablePayloadQuery,
1780
+ getSignableQuery,
1485
1781
  getTransactionQuery,
1486
1782
  getWithdrawalQuery,
1487
1783
  verifyAndParseWebhook