@lightsparkdev/lightspark-sdk 1.0.5 → 1.0.7
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 +16 -0
- package/dist/index.cjs +40 -10
- package/dist/index.d.ts +13 -3
- package/dist/index.js +39 -9
- package/package.json +5 -4
- package/src/client.ts +5 -3
- package/src/webhooks.ts +45 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @lightsparkdev/lightspark-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e156e3e: Remote signing webhooks handler and generate latest wasm
|
|
8
|
+
- Updated dependencies [e156e3e]
|
|
9
|
+
- @lightsparkdev/crypto-wasm@0.1.2
|
|
10
|
+
|
|
11
|
+
## 1.0.6
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- ca58c08: Update createSha256Hash with option to return as hex string and accept string data
|
|
16
|
+
- Updated dependencies [ca58c08]
|
|
17
|
+
- @lightsparkdev/core@1.0.5
|
|
18
|
+
|
|
3
19
|
## 1.0.5
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1865,6 +1865,7 @@ __export(src_exports, {
|
|
|
1865
1865
|
PaymentRequestStatus: () => PaymentRequestStatus_default,
|
|
1866
1866
|
Permission: () => Permission_default,
|
|
1867
1867
|
RemoteSigningSubEventType: () => RemoteSigningSubEventType_default,
|
|
1868
|
+
RemoteSigningWebhookHandler: () => RemoteSigningWebhookHandler,
|
|
1868
1869
|
RiskRating: () => RiskRating_default,
|
|
1869
1870
|
RoutingTransactionFailureReason: () => RoutingTransactionFailureReason_default,
|
|
1870
1871
|
SignablePayloadStatus: () => SignablePayloadStatus_default,
|
|
@@ -1933,12 +1934,11 @@ var AccountTokenAuthProvider_default = AccountTokenAuthProvider;
|
|
|
1933
1934
|
// src/client.ts
|
|
1934
1935
|
var import_auto_bind15 = __toESM(require("auto-bind"), 1);
|
|
1935
1936
|
var import_core9 = require("@lightsparkdev/core");
|
|
1936
|
-
var import_crypto = require("crypto");
|
|
1937
1937
|
|
|
1938
1938
|
// package.json
|
|
1939
1939
|
var package_default = {
|
|
1940
1940
|
name: "@lightsparkdev/lightspark-sdk",
|
|
1941
|
-
version: "1.0.
|
|
1941
|
+
version: "1.0.7",
|
|
1942
1942
|
description: "Lightspark JS SDK",
|
|
1943
1943
|
author: "Lightspark Inc.",
|
|
1944
1944
|
keywords: [
|
|
@@ -2018,14 +2018,14 @@ var package_default = {
|
|
|
2018
2018
|
"lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
|
|
2019
2019
|
lint: "eslint .",
|
|
2020
2020
|
postversion: "yarn build",
|
|
2021
|
-
test: "jest --no-cache --runInBand --bail",
|
|
2021
|
+
test: "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail",
|
|
2022
2022
|
"types:watch": "tsc-absolute --watch",
|
|
2023
2023
|
types: "tsc"
|
|
2024
2024
|
},
|
|
2025
2025
|
license: "Apache-2.0",
|
|
2026
2026
|
dependencies: {
|
|
2027
|
-
"@lightsparkdev/core": "1.0.
|
|
2028
|
-
"@lightsparkdev/crypto-wasm": "0.1.
|
|
2027
|
+
"@lightsparkdev/core": "1.0.5",
|
|
2028
|
+
"@lightsparkdev/crypto-wasm": "0.1.2",
|
|
2029
2029
|
"auto-bind": "^5.0.1",
|
|
2030
2030
|
crypto: "^1.0.1",
|
|
2031
2031
|
"crypto-browserify": "^3.12.0",
|
|
@@ -2041,6 +2041,7 @@ var package_default = {
|
|
|
2041
2041
|
"@lightsparkdev/tsconfig": "0.0.0",
|
|
2042
2042
|
"@types/crypto-js": "^4.1.1",
|
|
2043
2043
|
"@types/jest": "^29.5.3",
|
|
2044
|
+
"@types/node": "^20.2.5",
|
|
2044
2045
|
"@types/ws": "^8.5.4",
|
|
2045
2046
|
eslint: "^8.3.0",
|
|
2046
2047
|
"eslint-watch": "^8.0.0",
|
|
@@ -10762,10 +10763,11 @@ var LightsparkClient = class {
|
|
|
10762
10763
|
* @returns An Invoice object representing the generated invoice.
|
|
10763
10764
|
*/
|
|
10764
10765
|
async createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
|
|
10766
|
+
const metadataHash = await (0, import_core9.createSha256Hash)(metadata, true);
|
|
10765
10767
|
const variables = {
|
|
10766
10768
|
node_id: nodeId,
|
|
10767
10769
|
amount_msats: amountMsats,
|
|
10768
|
-
metadata_hash:
|
|
10770
|
+
metadata_hash: metadataHash
|
|
10769
10771
|
};
|
|
10770
10772
|
if (expirySecs !== void 0) {
|
|
10771
10773
|
variables["expiry_secs"] = expirySecs;
|
|
@@ -10795,10 +10797,11 @@ var LightsparkClient = class {
|
|
|
10795
10797
|
* @returns An Invoice object representing the generated invoice.
|
|
10796
10798
|
*/
|
|
10797
10799
|
async createUmaInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
|
|
10800
|
+
const metadataHash = await (0, import_core9.createSha256Hash)(metadata, true);
|
|
10798
10801
|
const variables = {
|
|
10799
10802
|
node_id: nodeId,
|
|
10800
10803
|
amount_msats: amountMsats,
|
|
10801
|
-
metadata_hash:
|
|
10804
|
+
metadata_hash: metadataHash,
|
|
10802
10805
|
expiry_secs: expirySecs !== void 0 ? expirySecs : 3600
|
|
10803
10806
|
};
|
|
10804
10807
|
const response = await this.requester.makeRawRequest(
|
|
@@ -12352,10 +12355,11 @@ ${FRAGMENT33}
|
|
|
12352
12355
|
};
|
|
12353
12356
|
|
|
12354
12357
|
// src/webhooks.ts
|
|
12355
|
-
var
|
|
12358
|
+
var import_crypto_wasm = require("@lightsparkdev/crypto-wasm");
|
|
12356
12359
|
var WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
|
|
12357
|
-
var verifyAndParseWebhook = (data, hexdigest, webhook_secret) => {
|
|
12358
|
-
const
|
|
12360
|
+
var verifyAndParseWebhook = async (data, hexdigest, webhook_secret) => {
|
|
12361
|
+
const { createHmac } = await import("crypto");
|
|
12362
|
+
const sig = createHmac("sha256", webhook_secret).update(data).digest("hex");
|
|
12359
12363
|
if (sig.toLowerCase() !== hexdigest.toLowerCase()) {
|
|
12360
12364
|
throw new Error("Webhook message hash does not match signature");
|
|
12361
12365
|
}
|
|
@@ -12377,6 +12381,31 @@ var parseWebhook = async (data) => {
|
|
|
12377
12381
|
wallet_id: event.wallet_id
|
|
12378
12382
|
};
|
|
12379
12383
|
};
|
|
12384
|
+
var RemoteSigningWebhookHandler = class {
|
|
12385
|
+
client;
|
|
12386
|
+
#masterSeed;
|
|
12387
|
+
validator;
|
|
12388
|
+
constructor(client, masterSeed, validator) {
|
|
12389
|
+
this.client = client;
|
|
12390
|
+
this.#masterSeed = masterSeed;
|
|
12391
|
+
this.validator = validator;
|
|
12392
|
+
}
|
|
12393
|
+
handleWebhookRequest(data, webhookSignature, webhookSecret) {
|
|
12394
|
+
const response = (0, import_crypto_wasm.wasm_handle_remote_signing_webhook_event)(
|
|
12395
|
+
data,
|
|
12396
|
+
webhookSignature,
|
|
12397
|
+
webhookSecret,
|
|
12398
|
+
this.#masterSeed,
|
|
12399
|
+
this.validator
|
|
12400
|
+
);
|
|
12401
|
+
const variables = JSON.parse(response.variables);
|
|
12402
|
+
this.client.executeRawQuery({
|
|
12403
|
+
queryPayload: response.query,
|
|
12404
|
+
variables,
|
|
12405
|
+
constructObject: (rawData) => rawData
|
|
12406
|
+
});
|
|
12407
|
+
}
|
|
12408
|
+
};
|
|
12380
12409
|
// Annotate the CommonJS export names for ESM import in node:
|
|
12381
12410
|
0 && (module.exports = {
|
|
12382
12411
|
Account,
|
|
@@ -12407,6 +12436,7 @@ var parseWebhook = async (data) => {
|
|
|
12407
12436
|
PaymentRequestStatus,
|
|
12408
12437
|
Permission,
|
|
12409
12438
|
RemoteSigningSubEventType,
|
|
12439
|
+
RemoteSigningWebhookHandler,
|
|
12410
12440
|
RiskRating,
|
|
12411
12441
|
RoutingTransactionFailureReason,
|
|
12412
12442
|
SignablePayloadStatus,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthProvider } from '@lightsparkdev/core';
|
|
2
|
-
import { W as WebhookEventType } from './index-dbf06298.js';
|
|
3
|
-
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BlockchainBalance, C as Channel, j as ChannelClosingTransaction, l as ChannelFees, m as ChannelOpeningTransaction, o as ChannelStatus, p as ChannelToTransactionsConnection, q as ComplianceProvider, r as Connection, s as CreateApiTokenInput, t as CreateApiTokenOutput, u as CreateInvoiceInput, v as CreateInvoiceOutput, w as CreateLnurlInvoiceInput, x as CreateNodeWalletAddressInput, y as CreateNodeWalletAddressOutput, z as CreateTestModeInvoiceInput, D as CreateTestModeInvoiceOutput, E as CreateTestModePaymentInput, F as CreateTestModePaymentoutput, G as CreateUmaInvoiceInput, H as CurrencyAmount, I as CurrencyUnit, J as DeclineToSignMessagesInput, K as DeclineToSignMessagesOutput, M as DeleteApiTokenInput, N as DeleteApiTokenOutput, O as Deposit, Q as Entity, R as FeeEstimate, S as FundNodeInput, T as FundNodeOutput, U as GraphNode, V as Hop, Y as HtlcAttemptFailureCode, Z as IdAndSignature, _ as IncomingPayment, $ as IncomingPaymentAttempt, a1 as IncomingPaymentAttemptStatus, a2 as IncomingPaymentToAttemptsConnection, a3 as Invoice, a5 as InvoiceData, a6 as InvoiceType, a7 as LightningFeeEstimateForInvoiceInput, a8 as LightningFeeEstimateForNodeInput, a9 as LightningFeeEstimateOutput, aa as LightningTransaction,
|
|
2
|
+
import { W as WebhookEventType, L as LightsparkClient } from './index-dbf06298.js';
|
|
3
|
+
export { A as Account, a as AccountToApiTokensConnection, b as AccountToChannelsConnection, c as AccountToNodesConnection, d as AccountToPaymentRequestsConnection, e as AccountToTransactionsConnection, f as AccountToWalletsConnection, g as ApiToken, B as Balances, i as BlockchainBalance, C as Channel, j as ChannelClosingTransaction, l as ChannelFees, m as ChannelOpeningTransaction, o as ChannelStatus, p as ChannelToTransactionsConnection, q as ComplianceProvider, r as Connection, s as CreateApiTokenInput, t as CreateApiTokenOutput, u as CreateInvoiceInput, v as CreateInvoiceOutput, w as CreateLnurlInvoiceInput, x as CreateNodeWalletAddressInput, y as CreateNodeWalletAddressOutput, z as CreateTestModeInvoiceInput, D as CreateTestModeInvoiceOutput, E as CreateTestModePaymentInput, F as CreateTestModePaymentoutput, G as CreateUmaInvoiceInput, H as CurrencyAmount, I as CurrencyUnit, J as DeclineToSignMessagesInput, K as DeclineToSignMessagesOutput, M as DeleteApiTokenInput, N as DeleteApiTokenOutput, O as Deposit, Q as Entity, R as FeeEstimate, S as FundNodeInput, T as FundNodeOutput, U as GraphNode, V as Hop, Y as HtlcAttemptFailureCode, Z as IdAndSignature, _ as IncomingPayment, $ as IncomingPaymentAttempt, a1 as IncomingPaymentAttemptStatus, a2 as IncomingPaymentToAttemptsConnection, a3 as Invoice, a5 as InvoiceData, a6 as InvoiceType, a7 as LightningFeeEstimateForInvoiceInput, a8 as LightningFeeEstimateForNodeInput, a9 as LightningFeeEstimateOutput, aa as LightningTransaction, ac as LightsparkNode, ad as LightsparkNodeOwner, af as LightsparkNodeStatus, ag as LightsparkNodeToChannelsConnection, ah as LightsparkNodeWithOSK, ai as LightsparkNodeWithRemoteSigning, aj as Node, ak as NodeAddress, al as NodeAddressType, am as NodeToAddressesConnection, an as OnChainTransaction, ap as OutgoingPayment, aq as OutgoingPaymentAttempt, ar as OutgoingPaymentAttemptStatus, as as OutgoingPaymentAttemptToHopsConnection, av as OutgoingPaymentToAttemptsConnection, at as OutgoingPaymentsForInvoiceQueryInput, au as OutgoingPaymentsForInvoiceQueryOutput, aw as PageInfo, ax as PayInvoiceInput, ay as PayInvoiceOutput, aF as PayUmaInvoiceInput, az as PaymentDirection, aA as PaymentFailureReason, aB as PaymentRequest, aD as PaymentRequestData, aE as PaymentRequestStatus, aG as Permission, aH as PostTransactionData, aI as RegisterPaymentInput, aJ as RegisterPaymentOutput, aK as ReleaseChannelPerCommitmentSecretInput, aL as ReleaseChannelPerCommitmentSecretOutput, aM as ReleasePaymentPreimageInput, aN as ReleasePaymentPreimageOutput, aO as RemoteSigningSubEventType, aP as RequestWithdrawalInput, aQ as RequestWithdrawalOutput, aR as RichText, aS as RiskRating, aT as RoutingTransaction, aV as RoutingTransactionFailureReason, aW as ScreenNodeInput, aX as ScreenNodeOutput, aY as Secret, aZ as SendPaymentInput, a_ as SendPaymentOutput, a$ as SetInvoicePaymentHashInput, b0 as SetInvoicePaymentHashOutput, b6 as SignInvoiceInput, b7 as SignInvoiceOutput, b8 as SignMessagesInput, b9 as SignMessagesOutput, b1 as Signable, b3 as SignablePayload, b5 as SignablePayloadStatus, ba as SingleNodeDashboard, bb as Transaction, bd as TransactionFailures, be as TransactionStatus, bf as TransactionType, bg as TransactionUpdate, bh as UpdateChannelPerCommitmentPointInput, bi as UpdateChannelPerCommitmentPointOutput, bj as UpdateNodeSharedSecretInput, bk as UpdateNodeSharedSecretOutput, bl as Wallet, bm as WalletStatus, bn as WalletToPaymentRequestsConnection, bo as WalletToTransactionsConnection, bp as Withdrawal, br as WithdrawalMode, bs as WithdrawalRequest, bt as WithdrawalRequestStatus, bu as WithdrawalRequestToChannelClosingTransactionsConnection, bv as WithdrawalRequestToChannelOpeningTransactionsConnection, h as getApiTokenQuery, k as getChannelClosingTransactionQuery, n as getChannelOpeningTransactionQuery, P as getDepositQuery, X as getHopQuery, a0 as getIncomingPaymentAttemptQuery, a4 as getInvoiceQuery, ab as getLightningTransactionQuery, ae as getLightsparkNodeOwnerQuery, ao as getOnChainTransactionQuery, aC as getPaymentRequestQuery, aU as getRoutingTransactionQuery, b4 as getSignablePayloadQuery, b2 as getSignableQuery, bc as getTransactionQuery, bq as getWithdrawalQuery } from './index-dbf06298.js';
|
|
4
4
|
import { B as BitcoinNetwork } from './BitcoinNetwork-a816c0be.js';
|
|
5
5
|
import 'zen-observable';
|
|
6
6
|
|
|
@@ -27,5 +27,15 @@ interface WebhookEvent {
|
|
|
27
27
|
wallet_id?: string;
|
|
28
28
|
}
|
|
29
29
|
declare const verifyAndParseWebhook: (data: Uint8Array, hexdigest: string, webhook_secret: string) => Promise<WebhookEvent>;
|
|
30
|
+
type Validator = {
|
|
31
|
+
should_sign: (event: WebhookEvent) => boolean;
|
|
32
|
+
};
|
|
33
|
+
declare class RemoteSigningWebhookHandler {
|
|
34
|
+
#private;
|
|
35
|
+
client: LightsparkClient;
|
|
36
|
+
validator: Validator;
|
|
37
|
+
constructor(client: LightsparkClient, masterSeed: Uint8Array, validator: Validator);
|
|
38
|
+
handleWebhookRequest(data: Uint8Array, webhookSignature: string, webhookSecret: string): void;
|
|
39
|
+
}
|
|
30
40
|
|
|
31
|
-
export { AccountTokenAuthProvider, BitcoinNetwork, WEBHOOKS_SIGNATURE_HEADER, WebhookEvent, WebhookEventType, assertValidBitcoinNetwork, getBitcoinNetworkOrThrow, isBitcoinNetwork, verifyAndParseWebhook };
|
|
41
|
+
export { AccountTokenAuthProvider, BitcoinNetwork, LightsparkClient, RemoteSigningWebhookHandler, WEBHOOKS_SIGNATURE_HEADER, WebhookEvent, WebhookEventType, assertValidBitcoinNetwork, getBitcoinNetworkOrThrow, isBitcoinNetwork, verifyAndParseWebhook };
|
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.
|
|
132
|
+
version: "1.0.7",
|
|
133
133
|
description: "Lightspark JS SDK",
|
|
134
134
|
author: "Lightspark Inc.",
|
|
135
135
|
keywords: [
|
|
@@ -209,14 +209,14 @@ var package_default = {
|
|
|
209
209
|
"lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
|
|
210
210
|
lint: "eslint .",
|
|
211
211
|
postversion: "yarn build",
|
|
212
|
-
test: "jest --no-cache --runInBand --bail",
|
|
212
|
+
test: "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail",
|
|
213
213
|
"types:watch": "tsc-absolute --watch",
|
|
214
214
|
types: "tsc"
|
|
215
215
|
},
|
|
216
216
|
license: "Apache-2.0",
|
|
217
217
|
dependencies: {
|
|
218
|
-
"@lightsparkdev/core": "1.0.
|
|
219
|
-
"@lightsparkdev/crypto-wasm": "0.1.
|
|
218
|
+
"@lightsparkdev/core": "1.0.5",
|
|
219
|
+
"@lightsparkdev/crypto-wasm": "0.1.2",
|
|
220
220
|
"auto-bind": "^5.0.1",
|
|
221
221
|
crypto: "^1.0.1",
|
|
222
222
|
"crypto-browserify": "^3.12.0",
|
|
@@ -232,6 +232,7 @@ var package_default = {
|
|
|
232
232
|
"@lightsparkdev/tsconfig": "0.0.0",
|
|
233
233
|
"@types/crypto-js": "^4.1.1",
|
|
234
234
|
"@types/jest": "^29.5.3",
|
|
235
|
+
"@types/node": "^20.2.5",
|
|
235
236
|
"@types/ws": "^8.5.4",
|
|
236
237
|
eslint: "^8.3.0",
|
|
237
238
|
"eslint-watch": "^8.0.0",
|
|
@@ -1312,10 +1313,11 @@ var LightsparkClient = class {
|
|
|
1312
1313
|
* @returns An Invoice object representing the generated invoice.
|
|
1313
1314
|
*/
|
|
1314
1315
|
async createLnurlInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
|
|
1316
|
+
const metadataHash = await createSha256Hash(metadata, true);
|
|
1315
1317
|
const variables = {
|
|
1316
1318
|
node_id: nodeId,
|
|
1317
1319
|
amount_msats: amountMsats,
|
|
1318
|
-
metadata_hash:
|
|
1320
|
+
metadata_hash: metadataHash
|
|
1319
1321
|
};
|
|
1320
1322
|
if (expirySecs !== void 0) {
|
|
1321
1323
|
variables["expiry_secs"] = expirySecs;
|
|
@@ -1345,10 +1347,11 @@ var LightsparkClient = class {
|
|
|
1345
1347
|
* @returns An Invoice object representing the generated invoice.
|
|
1346
1348
|
*/
|
|
1347
1349
|
async createUmaInvoice(nodeId, amountMsats, metadata, expirySecs = void 0) {
|
|
1350
|
+
const metadataHash = await createSha256Hash(metadata, true);
|
|
1348
1351
|
const variables = {
|
|
1349
1352
|
node_id: nodeId,
|
|
1350
1353
|
amount_msats: amountMsats,
|
|
1351
|
-
metadata_hash:
|
|
1354
|
+
metadata_hash: metadataHash,
|
|
1352
1355
|
expiry_secs: expirySecs !== void 0 ? expirySecs : 3600
|
|
1353
1356
|
};
|
|
1354
1357
|
const response = await this.requester.makeRawRequest(
|
|
@@ -1725,9 +1728,10 @@ var LightsparkClient = class {
|
|
|
1725
1728
|
var client_default = LightsparkClient;
|
|
1726
1729
|
|
|
1727
1730
|
// src/webhooks.ts
|
|
1728
|
-
import {
|
|
1731
|
+
import { wasm_handle_remote_signing_webhook_event } from "@lightsparkdev/crypto-wasm";
|
|
1729
1732
|
var WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
|
|
1730
|
-
var verifyAndParseWebhook = (data, hexdigest, webhook_secret) => {
|
|
1733
|
+
var verifyAndParseWebhook = async (data, hexdigest, webhook_secret) => {
|
|
1734
|
+
const { createHmac } = await import("crypto");
|
|
1731
1735
|
const sig = createHmac("sha256", webhook_secret).update(data).digest("hex");
|
|
1732
1736
|
if (sig.toLowerCase() !== hexdigest.toLowerCase()) {
|
|
1733
1737
|
throw new Error("Webhook message hash does not match signature");
|
|
@@ -1750,6 +1754,31 @@ var parseWebhook = async (data) => {
|
|
|
1750
1754
|
wallet_id: event.wallet_id
|
|
1751
1755
|
};
|
|
1752
1756
|
};
|
|
1757
|
+
var RemoteSigningWebhookHandler = class {
|
|
1758
|
+
client;
|
|
1759
|
+
#masterSeed;
|
|
1760
|
+
validator;
|
|
1761
|
+
constructor(client, masterSeed, validator) {
|
|
1762
|
+
this.client = client;
|
|
1763
|
+
this.#masterSeed = masterSeed;
|
|
1764
|
+
this.validator = validator;
|
|
1765
|
+
}
|
|
1766
|
+
handleWebhookRequest(data, webhookSignature, webhookSecret) {
|
|
1767
|
+
const response = wasm_handle_remote_signing_webhook_event(
|
|
1768
|
+
data,
|
|
1769
|
+
webhookSignature,
|
|
1770
|
+
webhookSecret,
|
|
1771
|
+
this.#masterSeed,
|
|
1772
|
+
this.validator
|
|
1773
|
+
);
|
|
1774
|
+
const variables = JSON.parse(response.variables);
|
|
1775
|
+
this.client.executeRawQuery({
|
|
1776
|
+
queryPayload: response.query,
|
|
1777
|
+
variables,
|
|
1778
|
+
constructObject: (rawData) => rawData
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1753
1782
|
export {
|
|
1754
1783
|
Account_default as Account,
|
|
1755
1784
|
AccountToChannelsConnection_default as AccountToChannelsConnection,
|
|
@@ -1779,6 +1808,7 @@ export {
|
|
|
1779
1808
|
PaymentRequestStatus_default as PaymentRequestStatus,
|
|
1780
1809
|
Permission_default as Permission,
|
|
1781
1810
|
RemoteSigningSubEventType_default as RemoteSigningSubEventType,
|
|
1811
|
+
RemoteSigningWebhookHandler,
|
|
1782
1812
|
RiskRating_default as RiskRating,
|
|
1783
1813
|
RoutingTransactionFailureReason_default as RoutingTransactionFailureReason,
|
|
1784
1814
|
SignablePayloadStatus_default as SignablePayloadStatus,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsparkdev/lightspark-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Lightspark JS SDK",
|
|
5
5
|
"author": "Lightspark Inc.",
|
|
6
6
|
"keywords": [
|
|
@@ -80,14 +80,14 @@
|
|
|
80
80
|
"lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
|
|
81
81
|
"lint": "eslint .",
|
|
82
82
|
"postversion": "yarn build",
|
|
83
|
-
"test": "jest --no-cache --runInBand --bail",
|
|
83
|
+
"test": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail",
|
|
84
84
|
"types:watch": "tsc-absolute --watch",
|
|
85
85
|
"types": "tsc"
|
|
86
86
|
},
|
|
87
87
|
"license": "Apache-2.0",
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@lightsparkdev/core": "1.0.
|
|
90
|
-
"@lightsparkdev/crypto-wasm": "0.1.
|
|
89
|
+
"@lightsparkdev/core": "1.0.5",
|
|
90
|
+
"@lightsparkdev/crypto-wasm": "0.1.2",
|
|
91
91
|
"auto-bind": "^5.0.1",
|
|
92
92
|
"crypto": "^1.0.1",
|
|
93
93
|
"crypto-browserify": "^3.12.0",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"@lightsparkdev/tsconfig": "0.0.0",
|
|
104
104
|
"@types/crypto-js": "^4.1.1",
|
|
105
105
|
"@types/jest": "^29.5.3",
|
|
106
|
+
"@types/node": "^20.2.5",
|
|
106
107
|
"@types/ws": "^8.5.4",
|
|
107
108
|
"eslint": "^8.3.0",
|
|
108
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:
|
|
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:
|
|
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,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { wasm_handle_remote_signing_webhook_event } from "@lightsparkdev/crypto-wasm";
|
|
2
|
+
import type LightsparkClient from "./client.js";
|
|
2
3
|
import { WebhookEventType } from "./objects/WebhookEventType.js";
|
|
3
4
|
|
|
4
5
|
export const WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
|
|
@@ -11,11 +12,13 @@ export interface WebhookEvent {
|
|
|
11
12
|
wallet_id?: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export const verifyAndParseWebhook = (
|
|
15
|
+
export const verifyAndParseWebhook = async (
|
|
15
16
|
data: Uint8Array,
|
|
16
17
|
hexdigest: string,
|
|
17
18
|
webhook_secret: string,
|
|
18
19
|
): Promise<WebhookEvent> => {
|
|
20
|
+
/* dynamic import to avoid bundling crypto in browser */
|
|
21
|
+
const { createHmac } = await import("crypto");
|
|
19
22
|
const sig = createHmac("sha256", webhook_secret).update(data).digest("hex");
|
|
20
23
|
|
|
21
24
|
if (sig.toLowerCase() !== hexdigest.toLowerCase()) {
|
|
@@ -42,3 +45,43 @@ const parseWebhook = async (data: Uint8Array): Promise<WebhookEvent> => {
|
|
|
42
45
|
wallet_id: event.wallet_id,
|
|
43
46
|
};
|
|
44
47
|
};
|
|
48
|
+
|
|
49
|
+
type Validator = {
|
|
50
|
+
should_sign: (event: WebhookEvent) => boolean;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export class RemoteSigningWebhookHandler {
|
|
54
|
+
client: LightsparkClient;
|
|
55
|
+
#masterSeed: Uint8Array;
|
|
56
|
+
validator: Validator;
|
|
57
|
+
|
|
58
|
+
constructor(
|
|
59
|
+
client: LightsparkClient,
|
|
60
|
+
masterSeed: Uint8Array,
|
|
61
|
+
validator: Validator,
|
|
62
|
+
) {
|
|
63
|
+
this.client = client;
|
|
64
|
+
this.#masterSeed = masterSeed;
|
|
65
|
+
this.validator = validator;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
handleWebhookRequest(
|
|
69
|
+
data: Uint8Array,
|
|
70
|
+
webhookSignature: string,
|
|
71
|
+
webhookSecret: string,
|
|
72
|
+
) {
|
|
73
|
+
const response = wasm_handle_remote_signing_webhook_event(
|
|
74
|
+
data,
|
|
75
|
+
webhookSignature,
|
|
76
|
+
webhookSecret,
|
|
77
|
+
this.#masterSeed,
|
|
78
|
+
this.validator,
|
|
79
|
+
);
|
|
80
|
+
const variables = JSON.parse(response.variables);
|
|
81
|
+
this.client.executeRawQuery({
|
|
82
|
+
queryPayload: response.query,
|
|
83
|
+
variables,
|
|
84
|
+
constructObject: (rawData: unknown) => rawData,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|