@lightsparkdev/lightspark-sdk 1.0.4 → 1.0.6

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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @lightsparkdev/lightspark-sdk
2
2
 
3
+ ## 1.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - ca58c08: Update createSha256Hash with option to return as hex string and accept string data
8
+ - Updated dependencies [ca58c08]
9
+ - @lightsparkdev/core@1.0.5
10
+
11
+ ## 1.0.5
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [545fe1f]
16
+ - Updated dependencies [545fe1f]
17
+ - @lightsparkdev/core@1.0.4
18
+
3
19
  ## 1.0.4
4
20
 
5
21
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1933,12 +1933,11 @@ var AccountTokenAuthProvider_default = AccountTokenAuthProvider;
1933
1933
  // src/client.ts
1934
1934
  var import_auto_bind15 = __toESM(require("auto-bind"), 1);
1935
1935
  var import_core9 = require("@lightsparkdev/core");
1936
- var import_crypto = require("crypto");
1937
1936
 
1938
1937
  // package.json
1939
1938
  var package_default = {
1940
1939
  name: "@lightsparkdev/lightspark-sdk",
1941
- version: "1.0.4",
1940
+ version: "1.0.6",
1942
1941
  description: "Lightspark JS SDK",
1943
1942
  author: "Lightspark Inc.",
1944
1943
  keywords: [
@@ -2007,6 +2006,7 @@ var package_default = {
2007
2006
  ],
2008
2007
  scripts: {
2009
2008
  build: "yarn tsc && tsup",
2009
+ "build:watch": "yarn build --watch",
2010
2010
  clean: "rm -rf .turbo && rm -rf dist",
2011
2011
  dev: "yarn build -- --watch",
2012
2012
  docs: "typedoc src",
@@ -2017,13 +2017,13 @@ var package_default = {
2017
2017
  "lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
2018
2018
  lint: "eslint .",
2019
2019
  postversion: "yarn build",
2020
- test: "jest --no-cache --runInBand --bail",
2020
+ test: "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail",
2021
2021
  "types:watch": "tsc-absolute --watch",
2022
2022
  types: "tsc"
2023
2023
  },
2024
2024
  license: "Apache-2.0",
2025
2025
  dependencies: {
2026
- "@lightsparkdev/core": "1.0.3",
2026
+ "@lightsparkdev/core": "1.0.5",
2027
2027
  "@lightsparkdev/crypto-wasm": "0.1.1",
2028
2028
  "auto-bind": "^5.0.1",
2029
2029
  crypto: "^1.0.1",
@@ -2040,6 +2040,7 @@ var package_default = {
2040
2040
  "@lightsparkdev/tsconfig": "0.0.0",
2041
2041
  "@types/crypto-js": "^4.1.1",
2042
2042
  "@types/jest": "^29.5.3",
2043
+ "@types/node": "^20.2.5",
2043
2044
  "@types/ws": "^8.5.4",
2044
2045
  eslint: "^8.3.0",
2045
2046
  "eslint-watch": "^8.0.0",
@@ -10761,10 +10762,11 @@ var LightsparkClient = class {
10761
10762
  * @returns An Invoice object representing the generated invoice.
10762
10763
  */
10763
10764
  async createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
10765
+ const metadataHash = await (0, import_core9.createSha256Hash)(metadata, true);
10764
10766
  const variables = {
10765
10767
  node_id: nodeId,
10766
10768
  amount_msats: amountMsats,
10767
- metadata_hash: (0, import_crypto.createHash)("sha256").update(metadata).digest("hex")
10769
+ metadata_hash: metadataHash
10768
10770
  };
10769
10771
  if (expirySecs !== void 0) {
10770
10772
  variables["expiry_secs"] = expirySecs;
@@ -10794,10 +10796,11 @@ var LightsparkClient = class {
10794
10796
  * @returns An Invoice object representing the generated invoice.
10795
10797
  */
10796
10798
  async createUmaInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
10799
+ const metadataHash = await (0, import_core9.createSha256Hash)(metadata, true);
10797
10800
  const variables = {
10798
10801
  node_id: nodeId,
10799
10802
  amount_msats: amountMsats,
10800
- metadata_hash: (0, import_crypto.createHash)("sha256").update(metadata).digest("hex"),
10803
+ metadata_hash: metadataHash,
10801
10804
  expiry_secs: expirySecs !== void 0 ? expirySecs : 3600
10802
10805
  };
10803
10806
  const response = await this.requester.makeRawRequest(
@@ -12351,10 +12354,10 @@ ${FRAGMENT33}
12351
12354
  };
12352
12355
 
12353
12356
  // src/webhooks.ts
12354
- var import_crypto2 = require("crypto");
12355
12357
  var WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
12356
- var verifyAndParseWebhook = (data, hexdigest, webhook_secret) => {
12357
- const sig = (0, import_crypto2.createHmac)("sha256", webhook_secret).update(data).digest("hex");
12358
+ var verifyAndParseWebhook = async (data, hexdigest, webhook_secret) => {
12359
+ const { createHmac } = await import("crypto");
12360
+ const sig = createHmac("sha256", webhook_secret).update(data).digest("hex");
12358
12361
  if (sig.toLowerCase() !== hexdigest.toLowerCase()) {
12359
12362
  throw new Error("Webhook message hash does not match signature");
12360
12363
  }
package/dist/index.js CHANGED
@@ -115,6 +115,7 @@ var AccountTokenAuthProvider_default = AccountTokenAuthProvider;
115
115
  // src/client.ts
116
116
  import autoBind2 from "auto-bind";
117
117
  import {
118
+ createSha256Hash,
118
119
  DefaultCrypto as DefaultCrypto2,
119
120
  LightsparkAuthException,
120
121
  LightsparkException,
@@ -124,12 +125,11 @@ import {
124
125
  SigningKeyType as SigningKeyType2,
125
126
  StubAuthProvider
126
127
  } from "@lightsparkdev/core";
127
- import { createHash } from "crypto";
128
128
 
129
129
  // package.json
130
130
  var package_default = {
131
131
  name: "@lightsparkdev/lightspark-sdk",
132
- version: "1.0.4",
132
+ version: "1.0.6",
133
133
  description: "Lightspark JS SDK",
134
134
  author: "Lightspark Inc.",
135
135
  keywords: [
@@ -198,6 +198,7 @@ var package_default = {
198
198
  ],
199
199
  scripts: {
200
200
  build: "yarn tsc && tsup",
201
+ "build:watch": "yarn build --watch",
201
202
  clean: "rm -rf .turbo && rm -rf dist",
202
203
  dev: "yarn build -- --watch",
203
204
  docs: "typedoc src",
@@ -208,13 +209,13 @@ var package_default = {
208
209
  "lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
209
210
  lint: "eslint .",
210
211
  postversion: "yarn build",
211
- test: "jest --no-cache --runInBand --bail",
212
+ test: "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail",
212
213
  "types:watch": "tsc-absolute --watch",
213
214
  types: "tsc"
214
215
  },
215
216
  license: "Apache-2.0",
216
217
  dependencies: {
217
- "@lightsparkdev/core": "1.0.3",
218
+ "@lightsparkdev/core": "1.0.5",
218
219
  "@lightsparkdev/crypto-wasm": "0.1.1",
219
220
  "auto-bind": "^5.0.1",
220
221
  crypto: "^1.0.1",
@@ -231,6 +232,7 @@ var package_default = {
231
232
  "@lightsparkdev/tsconfig": "0.0.0",
232
233
  "@types/crypto-js": "^4.1.1",
233
234
  "@types/jest": "^29.5.3",
235
+ "@types/node": "^20.2.5",
234
236
  "@types/ws": "^8.5.4",
235
237
  eslint: "^8.3.0",
236
238
  "eslint-watch": "^8.0.0",
@@ -1311,10 +1313,11 @@ var LightsparkClient = class {
1311
1313
  * @returns An Invoice object representing the generated invoice.
1312
1314
  */
1313
1315
  async createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
1316
+ const metadataHash = await createSha256Hash(metadata, true);
1314
1317
  const variables = {
1315
1318
  node_id: nodeId,
1316
1319
  amount_msats: amountMsats,
1317
- metadata_hash: createHash("sha256").update(metadata).digest("hex")
1320
+ metadata_hash: metadataHash
1318
1321
  };
1319
1322
  if (expirySecs !== void 0) {
1320
1323
  variables["expiry_secs"] = expirySecs;
@@ -1344,10 +1347,11 @@ var LightsparkClient = class {
1344
1347
  * @returns An Invoice object representing the generated invoice.
1345
1348
  */
1346
1349
  async createUmaInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
1350
+ const metadataHash = await createSha256Hash(metadata, true);
1347
1351
  const variables = {
1348
1352
  node_id: nodeId,
1349
1353
  amount_msats: amountMsats,
1350
- metadata_hash: createHash("sha256").update(metadata).digest("hex"),
1354
+ metadata_hash: metadataHash,
1351
1355
  expiry_secs: expirySecs !== void 0 ? expirySecs : 3600
1352
1356
  };
1353
1357
  const response = await this.requester.makeRawRequest(
@@ -1724,9 +1728,9 @@ var LightsparkClient = class {
1724
1728
  var client_default = LightsparkClient;
1725
1729
 
1726
1730
  // src/webhooks.ts
1727
- import { createHmac } from "crypto";
1728
1731
  var WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
1729
- var verifyAndParseWebhook = (data, hexdigest, webhook_secret) => {
1732
+ var verifyAndParseWebhook = async (data, hexdigest, webhook_secret) => {
1733
+ const { createHmac } = await import("crypto");
1730
1734
  const sig = createHmac("sha256", webhook_secret).update(data).digest("hex");
1731
1735
  if (sig.toLowerCase() !== hexdigest.toLowerCase()) {
1732
1736
  throw new Error("Webhook message hash does not match signature");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/lightspark-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -69,6 +69,7 @@
69
69
  ],
70
70
  "scripts": {
71
71
  "build": "yarn tsc && tsup",
72
+ "build:watch": "yarn build --watch",
72
73
  "clean": "rm -rf .turbo && rm -rf dist",
73
74
  "dev": "yarn build -- --watch",
74
75
  "docs": "typedoc src",
@@ -79,13 +80,13 @@
79
80
  "lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
80
81
  "lint": "eslint .",
81
82
  "postversion": "yarn build",
82
- "test": "jest --no-cache --runInBand --bail",
83
+ "test": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail",
83
84
  "types:watch": "tsc-absolute --watch",
84
85
  "types": "tsc"
85
86
  },
86
87
  "license": "Apache-2.0",
87
88
  "dependencies": {
88
- "@lightsparkdev/core": "1.0.3",
89
+ "@lightsparkdev/core": "1.0.5",
89
90
  "@lightsparkdev/crypto-wasm": "0.1.1",
90
91
  "auto-bind": "^5.0.1",
91
92
  "crypto": "^1.0.1",
@@ -102,6 +103,7 @@
102
103
  "@lightsparkdev/tsconfig": "0.0.0",
103
104
  "@types/crypto-js": "^4.1.1",
104
105
  "@types/jest": "^29.5.3",
106
+ "@types/node": "^20.2.5",
105
107
  "@types/ws": "^8.5.4",
106
108
  "eslint": "^8.3.0",
107
109
  "eslint-watch": "^8.0.0",
package/src/client.ts CHANGED
@@ -12,6 +12,7 @@ import type {
12
12
  SigningKey,
13
13
  } from "@lightsparkdev/core";
14
14
  import {
15
+ createSha256Hash,
15
16
  DefaultCrypto,
16
17
  LightsparkAuthException,
17
18
  LightsparkException,
@@ -21,7 +22,6 @@ import {
21
22
  SigningKeyType,
22
23
  StubAuthProvider,
23
24
  } from "@lightsparkdev/core";
24
- import { createHash } from "crypto";
25
25
  import packageJson from "../package.json";
26
26
  import { BitcoinFeeEstimate as BitcoinFeeEstimateQuery } from "./graphql/BitcoinFeeEstimate.js";
27
27
  import { CreateApiToken } from "./graphql/CreateApiToken.js";
@@ -479,10 +479,11 @@ class LightsparkClient {
479
479
  metadata: string,
480
480
  expirySecs: number | undefined = undefined,
481
481
  ): Promise<Invoice | undefined> {
482
+ const metadataHash = await createSha256Hash(metadata, true);
482
483
  const variables = {
483
484
  node_id: nodeId,
484
485
  amount_msats: amountMsats,
485
- metadata_hash: createHash("sha256").update(metadata).digest("hex"),
486
+ metadata_hash: metadataHash,
486
487
  };
487
488
  if (expirySecs !== undefined) {
488
489
  variables["expiry_secs"] = expirySecs;
@@ -518,10 +519,11 @@ class LightsparkClient {
518
519
  metadata: string,
519
520
  expirySecs: number | undefined = undefined,
520
521
  ): Promise<Invoice | undefined> {
522
+ const metadataHash = await createSha256Hash(metadata, true);
521
523
  const variables = {
522
524
  node_id: nodeId,
523
525
  amount_msats: amountMsats,
524
- metadata_hash: createHash("sha256").update(metadata).digest("hex"),
526
+ metadata_hash: metadataHash,
525
527
  expiry_secs: expirySecs !== undefined ? expirySecs : 3600,
526
528
  };
527
529
  const response = await this.requester.makeRawRequest(
package/src/webhooks.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { createHmac } from "crypto";
2
1
  import { WebhookEventType } from "./objects/WebhookEventType.js";
3
2
 
4
3
  export const WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
@@ -11,11 +10,13 @@ export interface WebhookEvent {
11
10
  wallet_id?: string;
12
11
  }
13
12
 
14
- export const verifyAndParseWebhook = (
13
+ export const verifyAndParseWebhook = async (
15
14
  data: Uint8Array,
16
15
  hexdigest: string,
17
16
  webhook_secret: string,
18
17
  ): Promise<WebhookEvent> => {
18
+ /* dynamic import to avoid bundling crypto in browser */
19
+ const { createHmac } = await import("crypto");
19
20
  const sig = createHmac("sha256", webhook_secret).update(data).digest("hex");
20
21
 
21
22
  if (sig.toLowerCase() !== hexdigest.toLowerCase()) {