@getalby/lightning-tools 8.0.0 → 8.1.1

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