@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.
Files changed (84) hide show
  1. package/CHANGELOG.md +22 -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 +3393 -841
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +388 -93
  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 +10 -8
  12. package/src/NodeKeyLoaderCache.ts +87 -0
  13. package/src/SigningKeyLoader.ts +177 -0
  14. package/src/client.ts +160 -71
  15. package/src/graphql/CreateInvoice.ts +3 -2
  16. package/src/graphql/CreateLnurlInvoice.ts +2 -0
  17. package/src/graphql/CreateUmaInvoice.ts +23 -0
  18. package/src/graphql/MultiNodeDashboard.ts +0 -3
  19. package/src/graphql/PayUmaInvoice.ts +29 -0
  20. package/src/graphql/RecoverNodeSigningKey.ts +1 -1
  21. package/src/graphql/SingleNodeDashboard.ts +0 -1
  22. package/src/lightspark_crypto/lightspark_crypto.d.ts +157 -0
  23. package/src/lightspark_crypto/lightspark_crypto.js +1010 -0
  24. package/src/lightspark_crypto/lightspark_crypto_bg.wasm +0 -0
  25. package/src/lightspark_crypto/lightspark_crypto_bg.wasm.d.ts +120 -0
  26. package/src/lightspark_crypto/package.json +11 -0
  27. package/src/objects/Account.ts +424 -107
  28. package/src/objects/AccountToNodesConnection.ts +0 -13
  29. package/src/objects/{CryptoSanctionsScreeningProvider.ts → ComplianceProvider.ts} +3 -3
  30. package/src/objects/Connection.ts +0 -6
  31. package/src/objects/CreateInvoiceInput.ts +0 -6
  32. package/src/objects/CreateLnurlInvoiceInput.ts +0 -6
  33. package/src/objects/CreateTestModePaymentoutput.ts +13 -1
  34. package/src/objects/CreateUmaInvoiceInput.ts +24 -0
  35. package/src/objects/DeclineToSignMessagesInput.ts +16 -0
  36. package/src/objects/DeclineToSignMessagesOutput.ts +28 -0
  37. package/src/objects/Entity.ts +401 -66
  38. package/src/objects/IdAndSignature.ts +16 -0
  39. package/src/objects/IncomingPayment.ts +18 -5
  40. package/src/objects/Invoice.ts +118 -21
  41. package/src/objects/InvoiceData.ts +118 -21
  42. package/src/objects/LightningTransaction.ts +149 -25
  43. package/src/objects/LightsparkNode.ts +270 -110
  44. package/src/objects/LightsparkNodeOwner.ts +4 -0
  45. package/src/objects/LightsparkNodeWithOSK.ts +389 -0
  46. package/src/objects/LightsparkNodeWithRemoteSigning.ts +384 -0
  47. package/src/objects/Node.ts +209 -56
  48. package/src/objects/OutgoingPayment.ts +136 -21
  49. package/src/objects/OutgoingPaymentsForInvoiceQueryInput.ts +25 -0
  50. package/src/objects/OutgoingPaymentsForInvoiceQueryOutput.ts +28 -0
  51. package/src/objects/PayUmaInvoiceInput.ts +25 -0
  52. package/src/objects/{LightsparkNodePurpose.ts → PaymentDirection.ts} +5 -7
  53. package/src/objects/PaymentRequest.ts +118 -21
  54. package/src/objects/PaymentRequestData.ts +118 -21
  55. package/src/objects/PostTransactionData.ts +39 -0
  56. package/src/objects/RegisterPaymentInput.ts +31 -0
  57. package/src/objects/RegisterPaymentOutput.ts +23 -0
  58. package/src/objects/ReleaseChannelPerCommitmentSecretInput.ts +23 -0
  59. package/src/objects/ReleaseChannelPerCommitmentSecretOutput.ts +23 -0
  60. package/src/objects/ReleasePaymentPreimageInput.ts +20 -0
  61. package/src/objects/ReleasePaymentPreimageOutput.ts +23 -0
  62. package/src/objects/RemoteSigningSubEventType.ts +26 -0
  63. package/src/objects/ScreenNodeInput.ts +20 -0
  64. package/src/objects/ScreenNodeOutput.ts +22 -0
  65. package/src/objects/SetInvoicePaymentHashInput.ts +24 -0
  66. package/src/objects/SetInvoicePaymentHashOutput.ts +23 -0
  67. package/src/objects/SignInvoiceInput.ts +19 -0
  68. package/src/objects/SignInvoiceOutput.ts +21 -0
  69. package/src/objects/SignMessagesInput.ts +18 -0
  70. package/src/objects/SignMessagesOutput.ts +26 -0
  71. package/src/objects/Signable.ts +58 -0
  72. package/src/objects/SignablePayload.ts +93 -0
  73. package/src/objects/SignablePayloadStatus.ts +17 -0
  74. package/src/objects/SingleNodeDashboard.ts +0 -2
  75. package/src/objects/Transaction.ts +149 -25
  76. package/src/objects/UpdateChannelPerCommitmentPointInput.ts +25 -0
  77. package/src/objects/UpdateChannelPerCommitmentPointOutput.ts +23 -0
  78. package/src/objects/UpdateNodeSharedSecretInput.ts +18 -0
  79. package/src/objects/UpdateNodeSharedSecretOutput.ts +23 -0
  80. package/src/objects/Wallet.ts +265 -45
  81. package/src/objects/index.ts +37 -4
  82. package/src/objects/ScreenBitcoinAddressesInput.ts +0 -23
  83. package/src/objects/ScreenBitcoinAddressesOutput.ts +0 -25
  84. /package/src/{__tests__ → tests}/webhooks.test.ts +0 -0
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.11",
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,7 +180,7 @@ 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",
@@ -190,7 +197,7 @@ var package_default = {
190
197
  },
191
198
  license: "Apache-2.0",
192
199
  dependencies: {
193
- "@lightsparkdev/core": "0.3.11",
200
+ "@lightsparkdev/core": "1.0.0",
194
201
  "auto-bind": "^5.0.1",
195
202
  crypto: "^1.0.1",
196
203
  "crypto-browserify": "^3.12.0",
@@ -204,14 +211,14 @@ var package_default = {
204
211
  "@lightsparkdev/eslint-config": "*",
205
212
  "@lightsparkdev/tsconfig": "0.0.0",
206
213
  "@types/crypto-js": "^4.1.1",
207
- "@types/jest": "^29.5.2",
214
+ "@types/jest": "^29.5.3",
208
215
  "@types/ws": "^8.5.4",
209
216
  eslint: "^8.3.0",
210
217
  "eslint-watch": "^8.0.0",
211
- jest: "^29.4.1",
218
+ jest: "^29.6.2",
212
219
  prettier: "3.0.2",
213
220
  "prettier-plugin-organize-imports": "^3.2.2",
214
- "ts-jest": "^29.0.5",
221
+ "ts-jest": "^29.1.1",
215
222
  "ts-node": "^10.9.1",
216
223
  "tsc-absolute": "^1.0.1",
217
224
  tsup: "^6.7.0",
@@ -258,8 +265,9 @@ var CreateInvoice = `
258
265
  $amount_msats: Long!
259
266
  $memo: String
260
267
  $type: InvoiceType = null
261
- ) {
262
- 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 }) {
263
271
  invoice {
264
272
  data {
265
273
  encoded_payment_request
@@ -275,11 +283,13 @@ mutation CreateLnurlInvoice(
275
283
  $node_id: ID!
276
284
  $amount_msats: Long!
277
285
  $metadata_hash: String!
286
+ $expiry_secs: Int = null
278
287
  ) {
279
288
  create_lnurl_invoice(input: {
280
289
  node_id: $node_id
281
290
  amount_msats: $amount_msats
282
291
  metadata_hash: $metadata_hash
292
+ expiry_secs: $expiry_secs
283
293
  }) {
284
294
  invoice {
285
295
  ...InvoiceFragment
@@ -342,6 +352,28 @@ mutation CreateTestModePayment(
342
352
  ${FRAGMENT6}
343
353
  `;
344
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
+
345
377
  // src/graphql/DecodeInvoice.ts
346
378
  var DecodeInvoice = `
347
379
  query DecodeInvoice($encoded_payment_request: String!) {
@@ -440,7 +472,6 @@ var MultiNodeDashboard = `
440
472
  entities {
441
473
  color
442
474
  display_name
443
- purpose
444
475
  id
445
476
  addresses(first: 1) {
446
477
  entities {
@@ -526,19 +557,31 @@ var PayInvoice = `
526
557
  ${FRAGMENT6}
527
558
  `;
528
559
 
529
- // src/graphql/RecoverNodeSigningKey.ts
530
- var RecoverNodeSigningKey = `
531
- query RecoverNodeSigningKey($nodeId: ID!) {
532
- entity(id: $nodeId) {
533
- __typename
534
- ... on LightsparkNode {
535
- encrypted_signing_private_key {
536
- encrypted_value
537
- cipher
538
- }
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
539
580
  }
540
581
  }
541
582
  }
583
+
584
+ ${FRAGMENT6}
542
585
  `;
543
586
 
544
587
  // src/graphql/RequestWithdrawal.ts
@@ -613,7 +656,6 @@ query SingleNodeDashboard(
613
656
  entities {
614
657
  color
615
658
  display_name
616
- purpose
617
659
  id
618
660
  addresses(first: 1) {
619
661
  entities {
@@ -757,6 +799,183 @@ subscription TransactionSubscription(
757
799
  ${FRAGMENT10}
758
800
  `;
759
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
+
760
979
  // src/client.ts
761
980
  var sdkVersion = package_default.version;
762
981
  var LightsparkClient = class {
@@ -769,14 +988,18 @@ var LightsparkClient = class {
769
988
  * @param cryptoImpl The crypto implementation to use. Defaults to web and node compatible crypto.
770
989
  * For React Native, you should use the `ReactNativeCrypto` implementation from `@lightsparkdev/react-native`.
771
990
  */
772
- constructor(authProvider = new StubAuthProvider(), serverUrl = "api.lightspark.com", cryptoImpl = DefaultCrypto) {
991
+ constructor(authProvider = new StubAuthProvider(), serverUrl = "api.lightspark.com", cryptoImpl = DefaultCrypto2) {
773
992
  this.authProvider = authProvider;
774
993
  this.serverUrl = serverUrl;
775
994
  this.cryptoImpl = cryptoImpl;
776
995
  this.nodeKeyCache = new NodeKeyCache(this.cryptoImpl);
996
+ this.nodeKeyLoaderCache = new NodeKeyLoaderCache(
997
+ this.nodeKeyCache,
998
+ this.cryptoImpl
999
+ );
777
1000
  this.requester = new Requester(
778
1001
  this.nodeKeyCache,
779
- LIGHTSPARK_SDK_ENDPOINT,
1002
+ this.LIGHTSPARK_SDK_ENDPOINT,
780
1003
  `js-lightspark-sdk/${sdkVersion}`,
781
1004
  authProvider,
782
1005
  serverUrl,
@@ -786,6 +1009,30 @@ var LightsparkClient = class {
786
1009
  }
787
1010
  requester;
788
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
+ }
789
1036
  /**
790
1037
  * Sets the auth provider for the client. This is useful for switching between auth providers if you are using
791
1038
  * multiple accounts or waiting for the user to log in.
@@ -795,7 +1042,7 @@ var LightsparkClient = class {
795
1042
  async setAuthProvider(authProvider) {
796
1043
  this.requester = new Requester(
797
1044
  this.nodeKeyCache,
798
- LIGHTSPARK_SDK_ENDPOINT,
1045
+ this.LIGHTSPARK_SDK_ENDPOINT,
799
1046
  `js-lightspark-sdk/${sdkVersion}`,
800
1047
  authProvider,
801
1048
  this.serverUrl,
@@ -889,7 +1136,6 @@ var LightsparkClient = class {
889
1136
  return {
890
1137
  color: node.color,
891
1138
  displayName: node.display_name,
892
- purpose: node.purpose,
893
1139
  id: node.id,
894
1140
  publicKey: node.public_key,
895
1141
  status: node.status,
@@ -966,7 +1212,6 @@ var LightsparkClient = class {
966
1212
  return {
967
1213
  color: node.color,
968
1214
  displayName: account.name,
969
- purpose: node.purpose,
970
1215
  id: node.id,
971
1216
  publicKey: node.public_key,
972
1217
  status: node.status,
@@ -1005,15 +1250,23 @@ var LightsparkClient = class {
1005
1250
  * @param type The type of invoice to create. Defaults to a normal payment invoice, but you can pass InvoiceType.AMP
1006
1251
  * to create an [AMP invoice](https://docs.lightning.engineering/lightning-network-tools/lnd/amp), which can be
1007
1252
  * paid multiple times.
1253
+ * @param expirySecs The number of seconds until the invoice expires. Defaults to 86400 (1 day).
1008
1254
  * @returns An encoded payment request for the invoice, or undefined if the invoice could not be created.
1009
1255
  */
1010
- async createInvoice(nodeId, amountMsats, memo, type = void 0) {
1011
- const response = await this.requester.makeRawRequest(CreateInvoice, {
1256
+ async createInvoice(nodeId, amountMsats, memo, type = void 0, expirySecs = void 0) {
1257
+ const variables = {
1012
1258
  node_id: nodeId,
1013
1259
  amount_msats: amountMsats,
1014
1260
  memo,
1015
1261
  type
1016
- });
1262
+ };
1263
+ if (expirySecs !== void 0) {
1264
+ variables["expiry_secs"] = expirySecs;
1265
+ }
1266
+ const response = await this.requester.makeRawRequest(
1267
+ CreateInvoice,
1268
+ variables
1269
+ );
1017
1270
  return response.create_invoice?.invoice.data?.encoded_payment_request;
1018
1271
  }
1019
1272
  /**
@@ -1028,20 +1281,59 @@ var LightsparkClient = class {
1028
1281
  * @param metadata The LNURL metadata payload field in the initial payreq response. This wil be hashed and present in the
1029
1282
  * h-tag (SHA256 purpose of payment) of the resulting Bolt 11 invoice. See
1030
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).
1031
1285
  * @returns An Invoice object representing the generated invoice.
1032
1286
  */
1033
- async createLnurlInvoice(nodeId, amountMsats, metadata) {
1034
- const response = await this.requester.makeRawRequest(CreateLnurlInvoice, {
1287
+ async createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
1288
+ const variables = {
1035
1289
  node_id: nodeId,
1036
1290
  amount_msats: amountMsats,
1037
1291
  metadata_hash: createHash("sha256").update(metadata).digest("hex")
1038
- });
1292
+ };
1293
+ if (expirySecs !== void 0) {
1294
+ variables["expiry_secs"] = expirySecs;
1295
+ }
1296
+ const response = await this.requester.makeRawRequest(
1297
+ CreateLnurlInvoice,
1298
+ variables
1299
+ );
1039
1300
  const invoiceJson = response.create_lnurl_invoice?.invoice;
1040
1301
  if (!invoiceJson) {
1041
1302
  return void 0;
1042
1303
  }
1043
1304
  return InvoiceFromJson(invoiceJson);
1044
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
+ }
1045
1337
  /**
1046
1338
  * Decodes an encoded lightning invoice string.
1047
1339
  *
@@ -1112,53 +1404,6 @@ var LightsparkClient = class {
1112
1404
  response.lightning_fee_estimate_for_node.lightning_fee_estimate_output_fee_estimate
1113
1405
  );
1114
1406
  }
1115
- /**
1116
- * Unlock the given node for sensitive operations like sending payments.
1117
- *
1118
- * @param nodeId The ID of the node to unlock.
1119
- * @param password The node password assigned at node creation.
1120
- * @returns True if the node was unlocked successfully, false otherwise.
1121
- */
1122
- async unlockNode(nodeId, password) {
1123
- const encryptedKey = await this.recoverNodeSigningKey(nodeId);
1124
- if (!encryptedKey) {
1125
- console.warn("No encrypted key found for node " + nodeId);
1126
- return false;
1127
- }
1128
- const signingPrivateKey = await this.cryptoImpl.decryptSecretWithNodePassword(
1129
- encryptedKey.cipher,
1130
- encryptedKey.encrypted_value,
1131
- password
1132
- );
1133
- if (!signingPrivateKey) {
1134
- throw new LightsparkSigningException(
1135
- "Unable to decrypt signing key with provided password. Please try again."
1136
- );
1137
- }
1138
- let signingPrivateKeyPEM = "";
1139
- if (new Uint8Array(signingPrivateKey)[0] === 48) {
1140
- signingPrivateKeyPEM = b64encode2(signingPrivateKey);
1141
- } else {
1142
- const dec = new TextDecoder();
1143
- signingPrivateKeyPEM = dec.decode(signingPrivateKey);
1144
- }
1145
- await this.nodeKeyCache.loadKey(
1146
- nodeId,
1147
- KeyOrAlias.key(signingPrivateKeyPEM)
1148
- );
1149
- return true;
1150
- }
1151
- async recoverNodeSigningKey(nodeId) {
1152
- const response = await this.requester.makeRawRequest(
1153
- RecoverNodeSigningKey,
1154
- { nodeId }
1155
- );
1156
- const nodeEntity = response.entity;
1157
- if (nodeEntity?.__typename === "LightsparkNode") {
1158
- return nodeEntity.encrypted_signing_private_key;
1159
- }
1160
- return null;
1161
- }
1162
1407
  /**
1163
1408
  * Directly unlocks a node with a signing private key or alias.
1164
1409
  *
@@ -1166,7 +1411,11 @@ var LightsparkClient = class {
1166
1411
  * @param signingPrivateKeyPEM The PEM-encoded signing private key.
1167
1412
  */
1168
1413
  async loadNodeKey(nodeId, signingPrivateKeyOrAlias) {
1169
- await this.nodeKeyCache.loadKey(nodeId, signingPrivateKeyOrAlias);
1414
+ await this.nodeKeyCache.loadKey(
1415
+ nodeId,
1416
+ signingPrivateKeyOrAlias,
1417
+ SigningKeyType2.RSASigningKey
1418
+ );
1170
1419
  }
1171
1420
  /**
1172
1421
  * Sends a lightning payment for a given invoice.
@@ -1186,7 +1435,7 @@ var LightsparkClient = class {
1186
1435
  */
1187
1436
  async payInvoice(payerNodeId, encodedInvoice, maximumFeesMsats, timeoutSecs = 60, amountMsats = void 0) {
1188
1437
  if (!this.nodeKeyCache.hasKey(payerNodeId)) {
1189
- throw new LightsparkSigningException("Paying node is not unlocked");
1438
+ throw new LightsparkSigningException3("Paying node is not unlocked");
1190
1439
  }
1191
1440
  const variables = {
1192
1441
  node_id: payerNodeId,
@@ -1210,6 +1459,47 @@ var LightsparkClient = class {
1210
1459
  }
1211
1460
  return response.pay_invoice && OutgoingPaymentFromJson(response.pay_invoice.payment);
1212
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
+ }
1213
1503
  /**
1214
1504
  * Sends a payment directly to a node on the Lightning Network through the public key of the node without an invoice.
1215
1505
  *
@@ -1224,7 +1514,7 @@ var LightsparkClient = class {
1224
1514
  */
1225
1515
  async sendPayment(payerNodeId, destinationPublicKey, timeoutSecs = 60, amountMsats, maximumFeesMsats) {
1226
1516
  if (!this.nodeKeyCache.hasKey(payerNodeId)) {
1227
- throw new LightsparkSigningException("Paying node is not unlocked");
1517
+ throw new LightsparkSigningException3("Paying node is not unlocked");
1228
1518
  }
1229
1519
  const response = await this.requester.makeRawRequest(
1230
1520
  SendPayment,
@@ -1405,7 +1695,6 @@ var LightsparkClient = class {
1405
1695
  return this.requester.executeQuery(query);
1406
1696
  }
1407
1697
  };
1408
- var LIGHTSPARK_SDK_ENDPOINT = "graphql/server/2023-04-04";
1409
1698
  var client_default = LightsparkClient;
1410
1699
 
1411
1700
  // src/webhooks.ts
@@ -1441,7 +1730,7 @@ export {
1441
1730
  BitcoinNetwork_default as BitcoinNetwork,
1442
1731
  Channel_default as Channel,
1443
1732
  ChannelStatus_default as ChannelStatus,
1444
- CryptoSanctionsScreeningProvider_default as CryptoSanctionsScreeningProvider,
1733
+ ComplianceProvider_default as ComplianceProvider,
1445
1734
  CurrencyUnit_default as CurrencyUnit,
1446
1735
  GraphNode_default as GraphNode,
1447
1736
  HtlcAttemptFailureCode_default as HtlcAttemptFailureCode,
@@ -1450,18 +1739,22 @@ export {
1450
1739
  InvoiceType_default as InvoiceType,
1451
1740
  client_default as LightsparkClient,
1452
1741
  LightsparkNode_default as LightsparkNode,
1453
- LightsparkNodePurpose_default as LightsparkNodePurpose,
1454
1742
  LightsparkNodeStatus_default as LightsparkNodeStatus,
1743
+ LightsparkNodeWithOSK_default as LightsparkNodeWithOSK,
1744
+ LightsparkNodeWithRemoteSigning_default as LightsparkNodeWithRemoteSigning,
1455
1745
  Node_default as Node,
1456
1746
  NodeAddressType_default as NodeAddressType,
1457
1747
  OutgoingPayment_default as OutgoingPayment,
1458
1748
  OutgoingPaymentAttempt_default as OutgoingPaymentAttempt,
1459
1749
  OutgoingPaymentAttemptStatus_default as OutgoingPaymentAttemptStatus,
1750
+ PaymentDirection_default as PaymentDirection,
1460
1751
  PaymentFailureReason_default as PaymentFailureReason,
1461
1752
  PaymentRequestStatus_default as PaymentRequestStatus,
1462
1753
  Permission_default as Permission,
1754
+ RemoteSigningSubEventType_default as RemoteSigningSubEventType,
1463
1755
  RiskRating_default as RiskRating,
1464
1756
  RoutingTransactionFailureReason_default as RoutingTransactionFailureReason,
1757
+ SignablePayloadStatus_default as SignablePayloadStatus,
1465
1758
  TransactionStatus_default as TransactionStatus,
1466
1759
  TransactionType_default as TransactionType,
1467
1760
  WEBHOOKS_SIGNATURE_HEADER,
@@ -1483,6 +1776,8 @@ export {
1483
1776
  getOnChainTransactionQuery,
1484
1777
  getPaymentRequestQuery,
1485
1778
  getRoutingTransactionQuery,
1779
+ getSignablePayloadQuery,
1780
+ getSignableQuery,
1486
1781
  getTransactionQuery,
1487
1782
  getWithdrawalQuery,
1488
1783
  verifyAndParseWebhook