@lightsparkdev/lightspark-sdk 0.2.2 → 0.2.4

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/src/client.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
- import { Query } from "@lightsparkdev/core";
3
+ import { LightsparkSigningException, Query } from "@lightsparkdev/core";
4
4
  import autoBind from "auto-bind";
5
5
  import Observable from "zen-observable";
6
6
 
7
7
  import {
8
8
  AuthProvider,
9
9
  b64encode,
10
- decryptSecretWithNodePassword,
10
+ CryptoInterface,
11
+ DefaultCrypto,
11
12
  LightsparkAuthException,
12
13
  LightsparkException,
13
- LightsparkSigningException,
14
14
  Maybe,
15
15
  NodeKeyCache,
16
16
  Requester,
@@ -33,7 +33,7 @@ import { PayInvoice } from "./graphql/PayInvoice.js";
33
33
  import { RecoverNodeSigningKey } from "./graphql/RecoverNodeSigningKey.js";
34
34
  import { RequestWithdrawal } from "./graphql/RequestWithdrawal.js";
35
35
  import { SendPayment } from "./graphql/SendPayment.js";
36
- import { SingleNodeDashboard } from "./graphql/SingleNodeDashboard.js";
36
+ import { SingleNodeDashboard as SingleNodeDashboardQuery } from "./graphql/SingleNodeDashboard.js";
37
37
  import { TransactionsForNode } from "./graphql/TransactionsForNode.js";
38
38
  import { TransactionSubscription } from "./graphql/TransactionSubscription.js";
39
39
  import Account from "./objects/Account.js";
@@ -50,11 +50,11 @@ import OutgoingPayment, {
50
50
  OutgoingPaymentFromJson,
51
51
  } from "./objects/OutgoingPayment.js";
52
52
  import Permission from "./objects/Permission.js";
53
+ import SingleNodeDashboard from "./objects/SingleNodeDashboard.js";
53
54
  import Transaction, { TransactionFromJson } from "./objects/Transaction.js";
54
55
  import TransactionUpdate, {
55
56
  TransactionUpdateFromJson,
56
57
  } from "./objects/TransactionUpdate.js";
57
- import WalletDashboard from "./objects/WalletDashboard.js";
58
58
  import WithdrawalMode from "./objects/WithdrawalMode.js";
59
59
  import WithdrawalRequest, {
60
60
  WithdrawalRequestFromJson,
@@ -85,6 +85,7 @@ import WithdrawalRequest, {
85
85
  */
86
86
  class LightsparkClient {
87
87
  private requester: Requester;
88
+ private readonly nodeKeyCache: NodeKeyCache;
88
89
 
89
90
  /**
90
91
  * Constructs a new LightsparkClient.
@@ -98,15 +99,17 @@ class LightsparkClient {
98
99
  constructor(
99
100
  private authProvider: AuthProvider = new StubAuthProvider(),
100
101
  private readonly serverUrl: string = "api.lightspark.com",
101
- private readonly nodeKeyCache: NodeKeyCache = new NodeKeyCache()
102
+ private readonly cryptoImpl: CryptoInterface = DefaultCrypto
102
103
  ) {
103
104
  const sdkVersion = require("../package.json").version;
105
+ this.nodeKeyCache = new NodeKeyCache(this.cryptoImpl);
104
106
  this.requester = new Requester(
105
107
  this.nodeKeyCache,
106
108
  LIGHTSPARK_SDK_ENDPOINT,
107
109
  `js-lightspark-sdk/${sdkVersion}`,
108
110
  authProvider,
109
- serverUrl
111
+ serverUrl,
112
+ this.cryptoImpl
110
113
  );
111
114
 
112
115
  autoBind(this);
@@ -125,7 +128,8 @@ class LightsparkClient {
125
128
  LIGHTSPARK_SDK_ENDPOINT,
126
129
  `js-lightspark-sdk/${sdkVersion}`,
127
130
  authProvider,
128
- this.serverUrl
131
+ this.serverUrl,
132
+ this.cryptoImpl
129
133
  );
130
134
  this.authProvider = authProvider;
131
135
  }
@@ -288,7 +292,7 @@ class LightsparkClient {
288
292
  }
289
293
 
290
294
  /**
291
- * Gets a basic dashboard for a single node, including recent transactions. See `WalletDashboard` for which info is
295
+ * Gets a basic dashboard for a single node, including recent transactions. See `SingleNodeDashboard` for which info is
292
296
  * included.
293
297
  *
294
298
  * @param nodeId The node ID for which to get a dashboard.
@@ -301,13 +305,16 @@ class LightsparkClient {
301
305
  nodeId: string,
302
306
  bitcoinNetwork: BitcoinNetwork = BitcoinNetwork.MAINNET,
303
307
  transactionsAfterDate: Maybe<string> = undefined
304
- ): Promise<WalletDashboard> {
305
- const response = await this.requester.makeRawRequest(SingleNodeDashboard, {
306
- nodeId: nodeId,
307
- network: bitcoinNetwork,
308
- numTransactions: 20,
309
- transactionsAfterDate,
310
- });
308
+ ): Promise<SingleNodeDashboard> {
309
+ const response = await this.requester.makeRawRequest(
310
+ SingleNodeDashboardQuery,
311
+ {
312
+ nodeId: nodeId,
313
+ network: bitcoinNetwork,
314
+ numTransactions: 20,
315
+ transactionsAfterDate,
316
+ }
317
+ );
311
318
  if (!response.current_account) {
312
319
  throw new LightsparkAuthException("No current account");
313
320
  }
@@ -489,11 +496,12 @@ class LightsparkClient {
489
496
  return false;
490
497
  }
491
498
 
492
- const signingPrivateKey = await decryptSecretWithNodePassword(
493
- encryptedKey.cipher,
494
- encryptedKey.encrypted_value,
495
- password
496
- );
499
+ const signingPrivateKey =
500
+ await this.cryptoImpl.decryptSecretWithNodePassword(
501
+ encryptedKey.cipher,
502
+ encryptedKey.encrypted_value,
503
+ password
504
+ );
497
505
 
498
506
  if (!signingPrivateKey) {
499
507
  throw new LightsparkSigningException(
@@ -5,7 +5,7 @@ import LightsparkNodeStatus from "./LightsparkNodeStatus.js";
5
5
  import NodeAddressType from "./NodeAddressType.js";
6
6
  import Transaction from "./Transaction.js";
7
7
 
8
- type WalletDashboard = {
8
+ type SingleNodeDashboard = {
9
9
  id: string;
10
10
  displayName: string;
11
11
  purpose: Maybe<LightsparkNodePurpose>;
@@ -29,4 +29,4 @@ type WalletDashboard = {
29
29
  recentTransactions: Transaction[];
30
30
  };
31
31
 
32
- export default WalletDashboard;
32
+ export default SingleNodeDashboard;
@@ -95,13 +95,13 @@ export { default as RoutingTransactionFailureReason } from "./RoutingTransaction
95
95
  export { default as Secret } from "./Secret.js";
96
96
  export { default as SendPaymentInput } from "./SendPaymentInput.js";
97
97
  export { default as SendPaymentOutput } from "./SendPaymentOutput.js";
98
+ export { default as SingleNodeDashboard } from "./SingleNodeDashboard.js";
98
99
  export { default as Transaction, getTransactionQuery } from "./Transaction.js";
99
100
  export { default as TransactionFailures } from "./TransactionFailures.js";
100
101
  export { default as TransactionStatus } from "./TransactionStatus.js";
101
102
  export { default as TransactionType } from "./TransactionType.js";
102
103
  export { default as TransactionUpdate } from "./TransactionUpdate.js";
103
104
  export { default as Wallet } from "./Wallet.js";
104
- export { default as WalletDashboard } from "./WalletDashboard.js";
105
105
  export { default as WebhookEventType } from "./WebhookEventType.js";
106
106
  export { default as Withdrawal, getWithdrawalQuery } from "./Withdrawal.js";
107
107
  export { default as WithdrawalMode } from "./WithdrawalMode.js";