@lightsparkdev/core 1.0.20 → 1.0.22

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,7 +50,6 @@ __export(utils_exports, {
50
50
  getLocalStorageConfigItem: () => getLocalStorageConfigItem,
51
51
  hexToBytes: () => hexToBytes,
52
52
  isBrowser: () => isBrowser,
53
- isCurrencyAmount: () => isCurrencyAmount,
54
53
  isCurrencyAmountObj: () => isCurrencyAmountObj,
55
54
  isCurrencyMap: () => isCurrencyMap,
56
55
  isError: () => isError,
@@ -58,6 +57,7 @@ __export(utils_exports, {
58
57
  isErrorWithMessage: () => isErrorWithMessage,
59
58
  isNode: () => isNode,
60
59
  isNumber: () => isNumber,
60
+ isSDKCurrencyAmount: () => isSDKCurrencyAmount,
61
61
  isTest: () => isTest,
62
62
  isType: () => isType,
63
63
  isUint8Array: () => isUint8Array,
@@ -66,6 +66,7 @@ __export(utils_exports, {
66
66
  localeToCurrencySymbol: () => localeToCurrencySymbol,
67
67
  lsidToUUID: () => lsidToUUID,
68
68
  mapCurrencyAmount: () => mapCurrencyAmount,
69
+ notNullUndefined: () => notNullUndefined,
69
70
  pollUntil: () => pollUntil,
70
71
  round: () => round,
71
72
  separateCurrencyStrParts: () => separateCurrencyStrParts,
@@ -469,102 +470,108 @@ function isNumber(value) {
469
470
 
470
471
  // src/utils/currency.ts
471
472
  var defaultCurrencyCode = "USD";
472
- var CurrencyUnit = /* @__PURE__ */ ((CurrencyUnit2) => {
473
- CurrencyUnit2["FUTURE_VALUE"] = "FUTURE_VALUE";
474
- CurrencyUnit2["BITCOIN"] = "BITCOIN";
475
- CurrencyUnit2["SATOSHI"] = "SATOSHI";
476
- CurrencyUnit2["MILLISATOSHI"] = "MILLISATOSHI";
477
- CurrencyUnit2["USD"] = "USD";
478
- CurrencyUnit2["NANOBITCOIN"] = "NANOBITCOIN";
479
- CurrencyUnit2["MICROBITCOIN"] = "MICROBITCOIN";
480
- CurrencyUnit2["MILLIBITCOIN"] = "MILLIBITCOIN";
481
- return CurrencyUnit2;
482
- })(CurrencyUnit || {});
473
+ var CurrencyUnit = {
474
+ FUTURE_VALUE: "FUTURE_VALUE",
475
+ BITCOIN: "BITCOIN",
476
+ SATOSHI: "SATOSHI",
477
+ MILLISATOSHI: "MILLISATOSHI",
478
+ USD: "USD",
479
+ NANOBITCOIN: "NANOBITCOIN",
480
+ MICROBITCOIN: "MICROBITCOIN",
481
+ MILLIBITCOIN: "MILLIBITCOIN",
482
+ Bitcoin: "BITCOIN",
483
+ Microbitcoin: "MICROBITCOIN",
484
+ Millibitcoin: "MILLIBITCOIN",
485
+ Millisatoshi: "MILLISATOSHI",
486
+ Nanobitcoin: "NANOBITCOIN",
487
+ Satoshi: "SATOSHI",
488
+ Usd: "USD"
489
+ };
483
490
  var CONVERSION_MAP = {
484
- ["BITCOIN" /* BITCOIN */]: {
485
- ["BITCOIN" /* BITCOIN */]: (v) => v,
486
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e6,
487
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v * 1e3,
488
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e11,
489
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e9,
490
- ["SATOSHI" /* SATOSHI */]: (v) => v * 1e8,
491
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
491
+ [CurrencyUnit.BITCOIN]: {
492
+ [CurrencyUnit.BITCOIN]: (v) => v,
493
+ [CurrencyUnit.MICROBITCOIN]: (v) => v * 1e6,
494
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v * 1e3,
495
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
496
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
497
+ [CurrencyUnit.SATOSHI]: (v) => v * 1e8,
498
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
492
499
  /* Round without decimals since we're returning cents: */
493
500
  round(v * centsPerBtc, 2)
494
501
  )
495
502
  },
496
- ["MICROBITCOIN" /* MICROBITCOIN */]: {
497
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e6,
498
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v,
499
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e3,
500
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e5,
501
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e3,
502
- ["SATOSHI" /* SATOSHI */]: (v) => v * 100,
503
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
503
+ [CurrencyUnit.MICROBITCOIN]: {
504
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
505
+ [CurrencyUnit.MICROBITCOIN]: (v) => v,
506
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e3,
507
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
508
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
509
+ [CurrencyUnit.SATOSHI]: (v) => v * 100,
510
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
504
511
  /* Round without decimals since we're returning cents: */
505
512
  round(v / 1e6 * centsPerBtc)
506
513
  )
507
514
  },
508
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: {
509
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e3,
510
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e3,
511
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v,
512
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e8,
513
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e6,
514
- ["SATOSHI" /* SATOSHI */]: (v) => v * 1e5,
515
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
515
+ [CurrencyUnit.MILLIBITCOIN]: {
516
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
517
+ [CurrencyUnit.MICROBITCOIN]: (v) => v * 1e3,
518
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v,
519
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
520
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
521
+ [CurrencyUnit.SATOSHI]: (v) => v * 1e5,
522
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
516
523
  /* Round without decimals since we're returning cents: */
517
524
  round(v / 1e3 * centsPerBtc)
518
525
  )
519
526
  },
520
- ["MILLISATOSHI" /* MILLISATOSHI */]: {
521
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e11,
522
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 1e5,
523
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e8,
524
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v,
525
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v / 100,
526
- ["SATOSHI" /* SATOSHI */]: (v) => v / 1e3,
527
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
527
+ [CurrencyUnit.MILLISATOSHI]: {
528
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
529
+ [CurrencyUnit.MICROBITCOIN]: (v) => v / 1e5,
530
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e8,
531
+ [CurrencyUnit.MILLISATOSHI]: (v) => v,
532
+ [CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
533
+ [CurrencyUnit.SATOSHI]: (v) => v / 1e3,
534
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
528
535
  /* Round without decimals since we're returning cents: */
529
536
  round(v / 1e11 * centsPerBtc)
530
537
  )
531
538
  },
532
- ["NANOBITCOIN" /* NANOBITCOIN */]: {
533
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e9,
534
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 1e3,
535
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e6,
536
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 100,
537
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v,
538
- ["SATOSHI" /* SATOSHI */]: (v) => v / 10,
539
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
539
+ [CurrencyUnit.NANOBITCOIN]: {
540
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
541
+ [CurrencyUnit.MICROBITCOIN]: (v) => v / 1e3,
542
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e6,
543
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
544
+ [CurrencyUnit.NANOBITCOIN]: (v) => v,
545
+ [CurrencyUnit.SATOSHI]: (v) => v / 10,
546
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
540
547
  /* Round without decimals since we're returning cents: */
541
548
  round(v / 1e9 * centsPerBtc)
542
549
  )
543
550
  },
544
- ["SATOSHI" /* SATOSHI */]: {
545
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e8,
546
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 100,
547
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e5,
548
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e3,
549
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 10,
550
- ["SATOSHI" /* SATOSHI */]: (v) => v,
551
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
551
+ [CurrencyUnit.SATOSHI]: {
552
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
553
+ [CurrencyUnit.MICROBITCOIN]: (v) => v / 100,
554
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e5,
555
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
556
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
557
+ [CurrencyUnit.SATOSHI]: (v) => v,
558
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
552
559
  /* Round without decimals since we're returning cents: */
553
560
  round(v / 1e8 * centsPerBtc)
554
561
  )
555
562
  },
556
- ["USD" /* USD */]: {
557
- ["BITCOIN" /* BITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc,
558
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
559
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
560
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
561
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
562
- ["SATOSHI" /* SATOSHI */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
563
- ["USD" /* USD */]: (v) => v
563
+ [CurrencyUnit.USD]: {
564
+ [CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
565
+ [CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
566
+ [CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
567
+ [CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
568
+ [CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
569
+ [CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
570
+ [CurrencyUnit.USD]: (v) => v
564
571
  }
565
572
  };
566
573
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
567
- if (fromUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || toUnit === "FUTURE_VALUE" /* FUTURE_VALUE */) {
574
+ if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
568
575
  throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
569
576
  }
570
577
  if (fromUnit === toUnit) {
@@ -595,8 +602,9 @@ var convertCurrencyAmount = (from, toUnit) => {
595
602
  function isCurrencyAmountObj(arg) {
596
603
  return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
597
604
  }
598
- function isCurrencyAmount(arg) {
599
- return typeof arg === "object" && arg !== null && "originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
605
+ function isSDKCurrencyAmount(arg) {
606
+ return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
607
+ "originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
600
608
  }
601
609
  function asNumber(value) {
602
610
  if (typeof value === "string") {
@@ -607,67 +615,67 @@ function asNumber(value) {
607
615
  function getCurrencyAmount(currencyAmountArg) {
608
616
  let value = 0;
609
617
  let unit = void 0;
610
- if (isCurrencyAmountObj(currencyAmountArg)) {
611
- value = asNumber(currencyAmountArg.value);
612
- unit = currencyAmountArg.unit;
613
- } else if (isCurrencyAmount(currencyAmountArg)) {
618
+ if (isSDKCurrencyAmount(currencyAmountArg)) {
614
619
  value = currencyAmountArg.originalValue;
615
620
  unit = currencyAmountArg.originalUnit;
621
+ } else if (isCurrencyAmountObj(currencyAmountArg)) {
622
+ value = asNumber(currencyAmountArg.value);
623
+ unit = currencyAmountArg.unit;
616
624
  }
617
625
  return {
618
626
  value: asNumber(value),
619
- unit: unit || "SATOSHI" /* SATOSHI */
627
+ unit: unit || CurrencyUnit.SATOSHI
620
628
  };
621
629
  }
622
630
  function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
623
631
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
624
632
  const convert = convertCurrencyAmountValue;
625
- const sats = convert(unit, "SATOSHI" /* SATOSHI */, value, centsPerBtc);
626
- const btc = convert(unit, "BITCOIN" /* BITCOIN */, value, centsPerBtc);
627
- const msats = convert(unit, "MILLISATOSHI" /* MILLISATOSHI */, value, centsPerBtc);
628
- const usd = convert(unit, "USD" /* USD */, value, centsPerBtc);
629
- const mibtc = convert(unit, "MICROBITCOIN" /* MICROBITCOIN */, value, centsPerBtc);
630
- const mlbtc = convert(unit, "MILLIBITCOIN" /* MILLIBITCOIN */, value, centsPerBtc);
631
- const nbtc = convert(unit, "NANOBITCOIN" /* NANOBITCOIN */, value, centsPerBtc);
633
+ const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
634
+ const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
635
+ const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
636
+ const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
637
+ const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
638
+ const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
639
+ const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
632
640
  const mapWithCurrencyUnits = {
633
- ["BITCOIN" /* BITCOIN */]: btc,
634
- ["SATOSHI" /* SATOSHI */]: sats,
635
- ["MILLISATOSHI" /* MILLISATOSHI */]: msats,
636
- ["USD" /* USD */]: usd,
637
- ["MICROBITCOIN" /* MICROBITCOIN */]: mibtc,
638
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: mlbtc,
639
- ["NANOBITCOIN" /* NANOBITCOIN */]: nbtc,
640
- ["FUTURE_VALUE" /* FUTURE_VALUE */]: NaN,
641
+ [CurrencyUnit.BITCOIN]: btc,
642
+ [CurrencyUnit.SATOSHI]: sats,
643
+ [CurrencyUnit.MILLISATOSHI]: msats,
644
+ [CurrencyUnit.USD]: usd,
645
+ [CurrencyUnit.MICROBITCOIN]: mibtc,
646
+ [CurrencyUnit.MILLIBITCOIN]: mlbtc,
647
+ [CurrencyUnit.NANOBITCOIN]: nbtc,
648
+ [CurrencyUnit.FUTURE_VALUE]: NaN,
641
649
  formatted: {
642
- ["BITCOIN" /* BITCOIN */]: formatCurrencyStr({
650
+ [CurrencyUnit.BITCOIN]: formatCurrencyStr({
643
651
  value: btc,
644
- unit: "BITCOIN" /* BITCOIN */
652
+ unit: CurrencyUnit.BITCOIN
645
653
  }),
646
- ["SATOSHI" /* SATOSHI */]: formatCurrencyStr({
654
+ [CurrencyUnit.SATOSHI]: formatCurrencyStr({
647
655
  value: sats,
648
- unit: "SATOSHI" /* SATOSHI */
656
+ unit: CurrencyUnit.SATOSHI
649
657
  }),
650
- ["MILLISATOSHI" /* MILLISATOSHI */]: formatCurrencyStr({
658
+ [CurrencyUnit.MILLISATOSHI]: formatCurrencyStr({
651
659
  value: msats,
652
- unit: "MILLISATOSHI" /* MILLISATOSHI */
660
+ unit: CurrencyUnit.MILLISATOSHI
653
661
  }),
654
- ["MICROBITCOIN" /* MICROBITCOIN */]: formatCurrencyStr({
662
+ [CurrencyUnit.MICROBITCOIN]: formatCurrencyStr({
655
663
  value: mibtc,
656
- unit: "MICROBITCOIN" /* MICROBITCOIN */
664
+ unit: CurrencyUnit.MICROBITCOIN
657
665
  }),
658
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: formatCurrencyStr({
666
+ [CurrencyUnit.MILLIBITCOIN]: formatCurrencyStr({
659
667
  value: mlbtc,
660
- unit: "MILLIBITCOIN" /* MILLIBITCOIN */
668
+ unit: CurrencyUnit.MILLIBITCOIN
661
669
  }),
662
- ["NANOBITCOIN" /* NANOBITCOIN */]: formatCurrencyStr({
670
+ [CurrencyUnit.NANOBITCOIN]: formatCurrencyStr({
663
671
  value: nbtc,
664
- unit: "NANOBITCOIN" /* NANOBITCOIN */
672
+ unit: CurrencyUnit.NANOBITCOIN
665
673
  }),
666
- ["USD" /* USD */]: formatCurrencyStr({
674
+ [CurrencyUnit.USD]: formatCurrencyStr({
667
675
  value: usd,
668
- unit: "USD" /* USD */
676
+ unit: CurrencyUnit.USD
669
677
  }),
670
- ["FUTURE_VALUE" /* FUTURE_VALUE */]: "-"
678
+ [CurrencyUnit.FUTURE_VALUE]: "-"
671
679
  }
672
680
  };
673
681
  return {
@@ -705,9 +713,9 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
705
713
  },
706
714
  formatted: {
707
715
  ...mapWithCurrencyUnits.formatted,
708
- btc: mapWithCurrencyUnits.formatted["BITCOIN" /* BITCOIN */],
709
- sats: mapWithCurrencyUnits.formatted["SATOSHI" /* SATOSHI */],
710
- msats: mapWithCurrencyUnits.formatted["MILLISATOSHI" /* MILLISATOSHI */]
716
+ btc: mapWithCurrencyUnits.formatted[CurrencyUnit.BITCOIN],
717
+ sats: mapWithCurrencyUnits.formatted[CurrencyUnit.SATOSHI],
718
+ msats: mapWithCurrencyUnits.formatted[CurrencyUnit.MILLISATOSHI]
711
719
  },
712
720
  type: "CurrencyMap"
713
721
  };
@@ -715,13 +723,13 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
715
723
  var isCurrencyMap = (currencyMap) => typeof currencyMap === "object" && currencyMap !== null && "type" in currencyMap && typeof currencyMap.type === "string" && currencyMap.type === "CurrencyMap";
716
724
  var abbrCurrencyUnit = (unit) => {
717
725
  switch (unit) {
718
- case "BITCOIN" /* BITCOIN */:
726
+ case CurrencyUnit.BITCOIN:
719
727
  return "BTC";
720
- case "SATOSHI" /* SATOSHI */:
728
+ case CurrencyUnit.SATOSHI:
721
729
  return "SAT";
722
- case "MILLISATOSHI" /* MILLISATOSHI */:
730
+ case CurrencyUnit.MILLISATOSHI:
723
731
  return "MSAT";
724
- case "USD" /* USD */:
732
+ case CurrencyUnit.USD:
725
733
  return "USD";
726
734
  }
727
735
  return "Unsupported CurrencyUnit";
@@ -730,33 +738,33 @@ function formatCurrencyStr(amount, maxFractionDigits, compact, showBtcSymbol = f
730
738
  const currencyAmount = getCurrencyAmount(amount);
731
739
  let { value: num } = currencyAmount;
732
740
  const { unit } = currencyAmount;
733
- if (unit === "USD" /* USD */) {
741
+ if (unit === CurrencyUnit.USD) {
734
742
  num = num / 100;
735
743
  }
736
744
  function getDefaultMaxFractionDigits(defaultDigits) {
737
745
  return typeof maxFractionDigits === "undefined" ? compact ? 1 : defaultDigits : maxFractionDigits;
738
746
  }
739
- const symbol = !showBtcSymbol ? "" : unit === "BITCOIN" /* BITCOIN */ ? "\uE903" : unit === "SATOSHI" /* SATOSHI */ ? "\uE902" : "";
747
+ const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
740
748
  const currentLocale = getCurrentLocale();
741
749
  switch (unit) {
742
- case "BITCOIN" /* BITCOIN */:
750
+ case CurrencyUnit.BITCOIN:
743
751
  return `${symbol}${num.toLocaleString(currentLocale, {
744
752
  notation: compact ? "compact" : void 0,
745
753
  maximumFractionDigits: getDefaultMaxFractionDigits(4),
746
754
  ...options
747
755
  })}`;
748
- case "MILLISATOSHI" /* MILLISATOSHI */:
749
- case "SATOSHI" /* SATOSHI */:
750
- case "MICROBITCOIN" /* MICROBITCOIN */:
751
- case "MILLIBITCOIN" /* MILLIBITCOIN */:
752
- case "NANOBITCOIN" /* NANOBITCOIN */:
756
+ case CurrencyUnit.MILLISATOSHI:
757
+ case CurrencyUnit.SATOSHI:
758
+ case CurrencyUnit.MICROBITCOIN:
759
+ case CurrencyUnit.MILLIBITCOIN:
760
+ case CurrencyUnit.NANOBITCOIN:
753
761
  default:
754
762
  return `${symbol}${num.toLocaleString(currentLocale, {
755
763
  notation: compact ? "compact" : void 0,
756
764
  maximumFractionDigits: getDefaultMaxFractionDigits(0),
757
765
  ...options
758
766
  })}`;
759
- case "USD" /* USD */:
767
+ case CurrencyUnit.USD:
760
768
  return num.toLocaleString(currentLocale, {
761
769
  style: "currency",
762
770
  currency: defaultCurrencyCode,
@@ -980,6 +988,9 @@ function isUint8Array(variable) {
980
988
  var isType = (typename) => (node) => {
981
989
  return node?.__typename === typename;
982
990
  };
991
+ function notNullUndefined(value) {
992
+ return value !== null && value !== void 0;
993
+ }
983
994
  // Annotate the CommonJS export names for ESM import in node:
984
995
  0 && (module.exports = {
985
996
  CurrencyUnit,
@@ -1002,7 +1013,6 @@ var isType = (typename) => (node) => {
1002
1013
  getLocalStorageConfigItem,
1003
1014
  hexToBytes,
1004
1015
  isBrowser,
1005
- isCurrencyAmount,
1006
1016
  isCurrencyAmountObj,
1007
1017
  isCurrencyMap,
1008
1018
  isError,
@@ -1010,6 +1020,7 @@ var isType = (typename) => (node) => {
1010
1020
  isErrorWithMessage,
1011
1021
  isNode,
1012
1022
  isNumber,
1023
+ isSDKCurrencyAmount,
1013
1024
  isTest,
1014
1025
  isType,
1015
1026
  isUint8Array,
@@ -1018,6 +1029,7 @@ var isType = (typename) => (node) => {
1018
1029
  localeToCurrencySymbol,
1019
1030
  lsidToUUID,
1020
1031
  mapCurrencyAmount,
1032
+ notNullUndefined,
1021
1033
  pollUntil,
1022
1034
  round,
1023
1035
  separateCurrencyStrParts,
@@ -1 +1 @@
1
- export { Y as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, $ as DeepPartial, X as ExpandRecursively, a0 as JSONLiteral, a2 as JSONObject, a1 as JSONType, W as Maybe, a3 as NN, Z as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, _ as isType, V as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, U as lsidToUUID, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-324f8ba4.js';
1
+ export { Z as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, f as CurrencyUnitType, a0 as DeepPartial, Y as ExpandRecursively, a1 as JSONLiteral, a3 as JSONObject, a2 as JSONType, X as Maybe, a4 as NN, _ as OmitTypename, S as SDKCurrencyAmountType, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, m as isSDKCurrencyAmount, w as isTest, $ as isType, W as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, V as lsidToUUID, n as mapCurrencyAmount, a5 as notNullUndefined, T as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, U as sleep, u as urlsafe_b64decode } from '../index-9ecb1570.js';
@@ -1 +1 @@
1
- export { Y as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, $ as DeepPartial, X as ExpandRecursively, a0 as JSONLiteral, a2 as JSONObject, a1 as JSONType, W as Maybe, a3 as NN, Z as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, _ as isType, V as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, U as lsidToUUID, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-324f8ba4.js';
1
+ export { Z as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, f as CurrencyUnitType, a0 as DeepPartial, Y as ExpandRecursively, a1 as JSONLiteral, a3 as JSONObject, a2 as JSONType, X as Maybe, a4 as NN, _ as OmitTypename, S as SDKCurrencyAmountType, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, m as isSDKCurrencyAmount, w as isTest, $ as isType, W as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, V as lsidToUUID, n as mapCurrencyAmount, a5 as notNullUndefined, T as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, U as sleep, u as urlsafe_b64decode } from '../index-9ecb1570.js';
@@ -19,7 +19,6 @@ import {
19
19
  getLocalStorageConfigItem,
20
20
  hexToBytes,
21
21
  isBrowser,
22
- isCurrencyAmount,
23
22
  isCurrencyAmountObj,
24
23
  isCurrencyMap,
25
24
  isError,
@@ -27,6 +26,7 @@ import {
27
26
  isErrorWithMessage,
28
27
  isNode,
29
28
  isNumber,
29
+ isSDKCurrencyAmount,
30
30
  isTest,
31
31
  isType,
32
32
  isUint8Array,
@@ -35,13 +35,14 @@ import {
35
35
  localeToCurrencySymbol,
36
36
  lsidToUUID,
37
37
  mapCurrencyAmount,
38
+ notNullUndefined,
38
39
  pollUntil,
39
40
  round,
40
41
  separateCurrencyStrParts,
41
42
  setLocalStorageBoolean,
42
43
  sleep,
43
44
  urlsafe_b64decode
44
- } from "../chunk-ZPGGNCAE.js";
45
+ } from "../chunk-RC2KOZKZ.js";
45
46
  export {
46
47
  CurrencyUnit,
47
48
  abbrCurrencyUnit,
@@ -63,7 +64,6 @@ export {
63
64
  getLocalStorageConfigItem,
64
65
  hexToBytes,
65
66
  isBrowser,
66
- isCurrencyAmount,
67
67
  isCurrencyAmountObj,
68
68
  isCurrencyMap,
69
69
  isError,
@@ -71,6 +71,7 @@ export {
71
71
  isErrorWithMessage,
72
72
  isNode,
73
73
  isNumber,
74
+ isSDKCurrencyAmount,
74
75
  isTest,
75
76
  isType,
76
77
  isUint8Array,
@@ -79,6 +80,7 @@ export {
79
80
  localeToCurrencySymbol,
80
81
  lsidToUUID,
81
82
  mapCurrencyAmount,
83
+ notNullUndefined,
82
84
  pollUntil,
83
85
  round,
84
86
  separateCurrencyStrParts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -226,8 +226,12 @@ const serializeSigningKey = async (
226
226
  };
227
227
 
228
228
  const getNonce = async () => {
229
- const nonceSt = await getRandomValues32(new Uint32Array(1));
230
- return Number(nonceSt);
229
+ const nonceSt = await getRandomValues32(new Uint32Array(2));
230
+ const [upper, lower] = nonceSt;
231
+ const nonce = (BigInt(upper) << 32n) | BigInt(lower);
232
+ // Note: We lose some precision here going from bigint to number
233
+ // because js numbers are floats, but it's ok.
234
+ return Number(nonce);
231
235
  };
232
236
 
233
237
  const sign = async (
@@ -18,4 +18,9 @@ describe("Crypto tests", () => {
18
18
  expect(serializedKeypair.privateKey).not.toBeNull();
19
19
  expect(serializedKeypair.publicKey).not.toBeNull();
20
20
  }, 60_000);
21
+
22
+ test("should generate a valid nonce", async () => {
23
+ const nonce = await DefaultCrypto.getNonce();
24
+ expect(nonce).toBeGreaterThan(0);
25
+ }, 10_000);
21
26
  });