@getalby/lightning-tools 8.0.0 → 8.1.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.
package/dist/esm/lnurl.js CHANGED
@@ -1345,6 +1345,19 @@ const decodeInvoice = (paymentRequest) => {
1345
1345
  return null;
1346
1346
  }
1347
1347
  };
1348
+ function validatePreimage(preimage, paymentHash) {
1349
+ try {
1350
+ if (!/^[0-9a-fA-F]{64}$/.test(preimage))
1351
+ return false;
1352
+ if (!/^[0-9a-fA-F]{64}$/.test(paymentHash))
1353
+ return false;
1354
+ const preimageHash = bytesToHex(sha256(fromHexString(preimage)));
1355
+ return paymentHash === preimageHash;
1356
+ }
1357
+ catch {
1358
+ return false;
1359
+ }
1360
+ }
1348
1361
 
1349
1362
  class Invoice {
1350
1363
  constructor(args) {
@@ -1384,13 +1397,7 @@ class Invoice {
1384
1397
  validatePreimage(preimage) {
1385
1398
  if (!preimage || !this.paymentHash)
1386
1399
  return false;
1387
- try {
1388
- const preimageHash = bytesToHex(sha256(fromHexString(preimage)));
1389
- return this.paymentHash === preimageHash;
1390
- }
1391
- catch {
1392
- return false;
1393
- }
1400
+ return validatePreimage(preimage, this.paymentHash);
1394
1401
  }
1395
1402
  async verifyPayment() {
1396
1403
  try {