@atomiqlabs/lp-lib 17.0.4 → 17.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.
@@ -50,6 +50,13 @@ export declare class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAb
50
50
  * @param invoice
51
51
  */
52
52
  private htlcReceived;
53
+ /**
54
+ * Checks invoice description
55
+ *
56
+ * @param description
57
+ * @throws {DefinedRuntimeError} will throw an error if the description is invalid
58
+ */
59
+ private checkDescription;
53
60
  /**
54
61
  * Checks invoice description hash
55
62
  *
@@ -314,6 +314,20 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
314
314
  return;
315
315
  }
316
316
  }
317
+ /**
318
+ * Checks invoice description
319
+ *
320
+ * @param description
321
+ * @throws {DefinedRuntimeError} will throw an error if the description is invalid
322
+ */
323
+ checkDescription(description) {
324
+ if (description != null && Buffer.byteLength(description, "utf8") > 500) {
325
+ throw {
326
+ code: 20100,
327
+ msg: "Invalid request body (description)"
328
+ };
329
+ }
330
+ }
317
331
  /**
318
332
  * Checks invoice description hash
319
333
  *
@@ -430,22 +444,6 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
430
444
  code: 10001,
431
445
  msg: "Invoice expired/canceled"
432
446
  };
433
- const arr = invoice.description.split("-");
434
- if (arr.length < 2)
435
- throw {
436
- _httpStatus: 200,
437
- code: 10001,
438
- msg: "Invoice expired/canceled"
439
- };
440
- const chainIdentifier = arr[0];
441
- const address = arr[1];
442
- const { chainInterface } = this.getChain(chainIdentifier);
443
- if (!chainInterface.isValidAddress(address, true))
444
- throw {
445
- _httpStatus: 200,
446
- code: 10001,
447
- msg: "Invoice expired/canceled"
448
- };
449
447
  switch (invoice.status) {
450
448
  case "canceled":
451
449
  throw {
@@ -484,6 +482,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
484
482
  * amount: string amount (in sats) of the invoice
485
483
  * token: string Desired token to swap
486
484
  * exactOut: boolean Whether the swap should be an exact out instead of exact in swap
485
+ * description: string Description of the invoice (max 500 bytes)
487
486
  * descriptionHash: string Description hash of the invoice
488
487
  *
489
488
  *Sent later:
@@ -510,6 +509,10 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
510
509
  msg: "Invalid request body"
511
510
  };
512
511
  metadata.request = parsedBody;
512
+ const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
513
+ description: SchemaVerifier_1.FieldTypeEnum.StringOptional
514
+ });
515
+ const description = descriptionBodyPart?.description;
513
516
  const requestedAmount = { input: !parsedBody.exactOut, amount: parsedBody.amount, token: parsedBody.token };
514
517
  const request = {
515
518
  chainIdentifier,
@@ -520,6 +523,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
520
523
  const useToken = parsedBody.token;
521
524
  //Check request params
522
525
  this.checkTooManyInflightSwaps();
526
+ this.checkDescription(description);
523
527
  this.checkDescriptionHash(parsedBody.descriptionHash);
524
528
  const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount);
525
529
  metadata.times.requestChecked = Date.now();
@@ -550,7 +554,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
550
554
  metadata.times.balanceChecked = Date.now();
551
555
  //Create swap
552
556
  const hodlInvoiceObj = {
553
- description: chainIdentifier + "-" + parsedBody.address,
557
+ description: description ?? (chainIdentifier + "-" + parsedBody.address),
554
558
  cltvDelta: Number(this.config.minCltv) + 5,
555
559
  expiresAt: Date.now() + (this.config.invoiceTimeoutSeconds * 1000),
556
560
  id: parsedBody.paymentHash,
@@ -63,6 +63,13 @@ export declare class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoS
63
63
  */
64
64
  private htlcReceived;
65
65
  private offerHtlc;
66
+ /**
67
+ * Checks invoice description
68
+ *
69
+ * @param description
70
+ * @throws {DefinedRuntimeError} will throw an error if the description is invalid
71
+ */
72
+ private checkDescription;
66
73
  /**
67
74
  * Checks invoice description hash
68
75
  *
@@ -360,6 +360,20 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
360
360
  }
361
361
  return true;
362
362
  }
363
+ /**
364
+ * Checks invoice description
365
+ *
366
+ * @param description
367
+ * @throws {DefinedRuntimeError} will throw an error if the description is invalid
368
+ */
369
+ checkDescription(description) {
370
+ if (description != null && Buffer.byteLength(description, "utf8") > 500) {
371
+ throw {
372
+ code: 20100,
373
+ msg: "Invalid request body (description)"
374
+ };
375
+ }
376
+ }
363
377
  /**
364
378
  * Checks invoice description hash
365
379
  *
@@ -454,22 +468,6 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
454
468
  code: 10001,
455
469
  msg: "Invoice expired/canceled"
456
470
  };
457
- const arr = invoice.description.split("-");
458
- if (arr.length < 2)
459
- throw {
460
- _httpStatus: 200,
461
- code: 10001,
462
- msg: "Invoice expired/canceled"
463
- };
464
- const chainIdentifier = arr[0];
465
- const address = arr[1];
466
- const { chainInterface } = this.getChain(chainIdentifier);
467
- if (!chainInterface.isValidAddress(address, true))
468
- throw {
469
- _httpStatus: 200,
470
- code: 10001,
471
- msg: "Invoice expired/canceled"
472
- };
473
471
  switch (invoice.status) {
474
472
  case "canceled":
475
473
  throw {
@@ -511,6 +509,7 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
511
509
  * amount: string amount (in sats) of the invoice
512
510
  * token: string Desired token to swap
513
511
  * exactOut: boolean Whether the swap should be an exact out instead of exact in swap
512
+ * description: string Description of the invoice (max 500 bytes)
514
513
  * descriptionHash: string Description hash of the invoice
515
514
  * gasAmount: string Desired amount in gas token to also get
516
515
  * gasToken: string
@@ -541,6 +540,10 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
541
540
  code: 20100,
542
541
  msg: "Invalid request body"
543
542
  };
543
+ const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
544
+ description: SchemaVerifier_1.FieldTypeEnum.StringOptional
545
+ });
546
+ const description = descriptionBodyPart?.description;
544
547
  if (parsedBody.gasToken !== chainInterface.getNativeCurrencyAddress())
545
548
  throw {
546
549
  code: 20290,
@@ -572,6 +575,7 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
572
575
  const useToken = parsedBody.token;
573
576
  const gasToken = parsedBody.gasToken;
574
577
  //Check request params
578
+ this.checkDescription(description);
575
579
  this.checkDescriptionHash(parsedBody.descriptionHash);
576
580
  this.checkTooManyInflightSwaps();
577
581
  const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount, gasTokenAmount);
@@ -606,7 +610,7 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
606
610
  metadata.times.balanceChecked = Date.now();
607
611
  //Create swap
608
612
  const hodlInvoiceObj = {
609
- description: chainIdentifier + "-" + parsedBody.address,
613
+ description: description ?? (chainIdentifier + "-" + parsedBody.address),
610
614
  cltvDelta: Number(this.config.minCltv) + 5,
611
615
  expiresAt: Date.now() + (this.config.invoiceTimeoutSeconds * 1000),
612
616
  id: parsedBody.paymentHash,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "17.0.4",
3
+ "version": "17.1.1",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -27,7 +27,6 @@ import {
27
27
  LightningNetworkInvoice
28
28
  } from "../../../wallets/ILightningWallet";
29
29
  import {LightningAssertions} from "../../assertions/LightningAssertions";
30
- import {FromBtcLnAutoSwapState} from "../frombtcln_autoinit/FromBtcLnAutoSwap";
31
30
 
32
31
  export type FromBtcLnConfig = FromBtcBaseConfig & {
33
32
  invoiceTimeoutSeconds?: number,
@@ -399,6 +398,21 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
399
398
  }
400
399
  }
401
400
 
401
+ /**
402
+ * Checks invoice description
403
+ *
404
+ * @param description
405
+ * @throws {DefinedRuntimeError} will throw an error if the description is invalid
406
+ */
407
+ private checkDescription(description: string) {
408
+ if(description!=null && Buffer.byteLength(description, "utf8") > 500) {
409
+ throw {
410
+ code: 20100,
411
+ msg: "Invalid request body (description)"
412
+ };
413
+ }
414
+ }
415
+
402
416
  /**
403
417
  * Checks invoice description hash
404
418
  *
@@ -535,22 +549,6 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
535
549
  msg: "Invoice expired/canceled"
536
550
  };
537
551
 
538
- const arr = invoice.description.split("-");
539
- if(arr.length<2) throw {
540
- _httpStatus: 200,
541
- code: 10001,
542
- msg: "Invoice expired/canceled"
543
- };
544
- const chainIdentifier = arr[0];
545
- const address = arr[1];
546
-
547
- const {chainInterface} = this.getChain(chainIdentifier);
548
- if(!chainInterface.isValidAddress(address, true)) throw {
549
- _httpStatus: 200,
550
- code: 10001,
551
- msg: "Invoice expired/canceled"
552
- };
553
-
554
552
  switch(invoice.status) {
555
553
  case "canceled":
556
554
  throw {
@@ -600,6 +598,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
600
598
  * amount: string amount (in sats) of the invoice
601
599
  * token: string Desired token to swap
602
600
  * exactOut: boolean Whether the swap should be an exact out instead of exact in swap
601
+ * description: string Description of the invoice (max 500 bytes)
603
602
  * descriptionHash: string Description hash of the invoice
604
603
  *
605
604
  *Sent later:
@@ -626,6 +625,11 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
626
625
  };
627
626
  metadata.request = parsedBody;
628
627
 
628
+ const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
629
+ description: FieldTypeEnum.StringOptional
630
+ });
631
+ const description = descriptionBodyPart?.description;
632
+
629
633
  const requestedAmount = {input: !parsedBody.exactOut, amount: parsedBody.amount, token: parsedBody.token};
630
634
  const request = {
631
635
  chainIdentifier,
@@ -637,6 +641,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
637
641
 
638
642
  //Check request params
639
643
  this.checkTooManyInflightSwaps();
644
+ this.checkDescription(description);
640
645
  this.checkDescriptionHash(parsedBody.descriptionHash);
641
646
  const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount);
642
647
  metadata.times.requestChecked = Date.now();
@@ -689,7 +694,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
689
694
 
690
695
  //Create swap
691
696
  const hodlInvoiceObj: HodlInvoiceInit = {
692
- description: chainIdentifier+"-"+parsedBody.address,
697
+ description: description ?? (chainIdentifier+"-"+parsedBody.address),
693
698
  cltvDelta: Number(this.config.minCltv) + 5,
694
699
  expiresAt: Date.now()+(this.config.invoiceTimeoutSeconds*1000),
695
700
  id: parsedBody.paymentHash,
@@ -439,6 +439,21 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
439
439
  return true;
440
440
  }
441
441
 
442
+ /**
443
+ * Checks invoice description
444
+ *
445
+ * @param description
446
+ * @throws {DefinedRuntimeError} will throw an error if the description is invalid
447
+ */
448
+ private checkDescription(description: string) {
449
+ if(description!=null && Buffer.byteLength(description, "utf8") > 500) {
450
+ throw {
451
+ code: 20100,
452
+ msg: "Invalid request body (description)"
453
+ };
454
+ }
455
+ }
456
+
442
457
  /**
443
458
  * Checks invoice description hash
444
459
  *
@@ -539,22 +554,6 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
539
554
  msg: "Invoice expired/canceled"
540
555
  };
541
556
 
542
- const arr = invoice.description.split("-");
543
- if(arr.length<2) throw {
544
- _httpStatus: 200,
545
- code: 10001,
546
- msg: "Invoice expired/canceled"
547
- };
548
- const chainIdentifier = arr[0];
549
- const address = arr[1];
550
-
551
- const {chainInterface} = this.getChain(chainIdentifier);
552
- if(!chainInterface.isValidAddress(address, true)) throw {
553
- _httpStatus: 200,
554
- code: 10001,
555
- msg: "Invoice expired/canceled"
556
- };
557
-
558
557
  switch(invoice.status) {
559
558
  case "canceled":
560
559
  throw {
@@ -605,6 +604,7 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
605
604
  * amount: string amount (in sats) of the invoice
606
605
  * token: string Desired token to swap
607
606
  * exactOut: boolean Whether the swap should be an exact out instead of exact in swap
607
+ * description: string Description of the invoice (max 500 bytes)
608
608
  * descriptionHash: string Description hash of the invoice
609
609
  * gasAmount: string Desired amount in gas token to also get
610
610
  * gasToken: string
@@ -635,6 +635,11 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
635
635
  msg: "Invalid request body"
636
636
  };
637
637
 
638
+ const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
639
+ description: FieldTypeEnum.StringOptional
640
+ });
641
+ const description = descriptionBodyPart?.description;
642
+
638
643
  if(parsedBody.gasToken!==chainInterface.getNativeCurrencyAddress()) throw {
639
644
  code: 20290,
640
645
  msg: "Unsupported gas token"
@@ -666,6 +671,7 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
666
671
  const gasToken = parsedBody.gasToken;
667
672
 
668
673
  //Check request params
674
+ this.checkDescription(description);
669
675
  this.checkDescriptionHash(parsedBody.descriptionHash);
670
676
  this.checkTooManyInflightSwaps();
671
677
  const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount, gasTokenAmount);
@@ -724,7 +730,7 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
724
730
 
725
731
  //Create swap
726
732
  const hodlInvoiceObj: HodlInvoiceInit = {
727
- description: chainIdentifier+"-"+parsedBody.address,
733
+ description: description ?? (chainIdentifier+"-"+parsedBody.address),
728
734
  cltvDelta: Number(this.config.minCltv) + 5,
729
735
  expiresAt: Date.now()+(this.config.invoiceTimeoutSeconds*1000),
730
736
  id: parsedBody.paymentHash,