@lightsparkdev/core 1.0.21 → 1.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/index.cjs CHANGED
@@ -67,7 +67,6 @@ __export(src_exports, {
67
67
  getLocalStorageConfigItem: () => getLocalStorageConfigItem,
68
68
  hexToBytes: () => hexToBytes,
69
69
  isBrowser: () => isBrowser,
70
- isCurrencyAmount: () => isCurrencyAmount,
71
70
  isCurrencyAmountObj: () => isCurrencyAmountObj,
72
71
  isCurrencyMap: () => isCurrencyMap,
73
72
  isError: () => isError,
@@ -75,6 +74,7 @@ __export(src_exports, {
75
74
  isErrorWithMessage: () => isErrorWithMessage,
76
75
  isNode: () => isNode,
77
76
  isNumber: () => isNumber,
77
+ isSDKCurrencyAmount: () => isSDKCurrencyAmount,
78
78
  isTest: () => isTest,
79
79
  isType: () => isType,
80
80
  isUint8Array: () => isUint8Array,
@@ -836,102 +836,108 @@ function isNumber(value) {
836
836
 
837
837
  // src/utils/currency.ts
838
838
  var defaultCurrencyCode = "USD";
839
- var CurrencyUnit = /* @__PURE__ */ ((CurrencyUnit2) => {
840
- CurrencyUnit2["FUTURE_VALUE"] = "FUTURE_VALUE";
841
- CurrencyUnit2["BITCOIN"] = "BITCOIN";
842
- CurrencyUnit2["SATOSHI"] = "SATOSHI";
843
- CurrencyUnit2["MILLISATOSHI"] = "MILLISATOSHI";
844
- CurrencyUnit2["USD"] = "USD";
845
- CurrencyUnit2["NANOBITCOIN"] = "NANOBITCOIN";
846
- CurrencyUnit2["MICROBITCOIN"] = "MICROBITCOIN";
847
- CurrencyUnit2["MILLIBITCOIN"] = "MILLIBITCOIN";
848
- return CurrencyUnit2;
849
- })(CurrencyUnit || {});
839
+ var CurrencyUnit = {
840
+ FUTURE_VALUE: "FUTURE_VALUE",
841
+ BITCOIN: "BITCOIN",
842
+ SATOSHI: "SATOSHI",
843
+ MILLISATOSHI: "MILLISATOSHI",
844
+ USD: "USD",
845
+ NANOBITCOIN: "NANOBITCOIN",
846
+ MICROBITCOIN: "MICROBITCOIN",
847
+ MILLIBITCOIN: "MILLIBITCOIN",
848
+ Bitcoin: "BITCOIN",
849
+ Microbitcoin: "MICROBITCOIN",
850
+ Millibitcoin: "MILLIBITCOIN",
851
+ Millisatoshi: "MILLISATOSHI",
852
+ Nanobitcoin: "NANOBITCOIN",
853
+ Satoshi: "SATOSHI",
854
+ Usd: "USD"
855
+ };
850
856
  var CONVERSION_MAP = {
851
- ["BITCOIN" /* BITCOIN */]: {
852
- ["BITCOIN" /* BITCOIN */]: (v) => v,
853
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e6,
854
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v * 1e3,
855
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e11,
856
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e9,
857
- ["SATOSHI" /* SATOSHI */]: (v) => v * 1e8,
858
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
857
+ [CurrencyUnit.BITCOIN]: {
858
+ [CurrencyUnit.BITCOIN]: (v) => v,
859
+ [CurrencyUnit.MICROBITCOIN]: (v) => v * 1e6,
860
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v * 1e3,
861
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
862
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
863
+ [CurrencyUnit.SATOSHI]: (v) => v * 1e8,
864
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
859
865
  /* Round without decimals since we're returning cents: */
860
866
  round(v * centsPerBtc, 2)
861
867
  )
862
868
  },
863
- ["MICROBITCOIN" /* MICROBITCOIN */]: {
864
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e6,
865
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v,
866
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e3,
867
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e5,
868
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e3,
869
- ["SATOSHI" /* SATOSHI */]: (v) => v * 100,
870
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
869
+ [CurrencyUnit.MICROBITCOIN]: {
870
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
871
+ [CurrencyUnit.MICROBITCOIN]: (v) => v,
872
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e3,
873
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
874
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
875
+ [CurrencyUnit.SATOSHI]: (v) => v * 100,
876
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
871
877
  /* Round without decimals since we're returning cents: */
872
878
  round(v / 1e6 * centsPerBtc)
873
879
  )
874
880
  },
875
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: {
876
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e3,
877
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e3,
878
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v,
879
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e8,
880
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e6,
881
- ["SATOSHI" /* SATOSHI */]: (v) => v * 1e5,
882
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
881
+ [CurrencyUnit.MILLIBITCOIN]: {
882
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
883
+ [CurrencyUnit.MICROBITCOIN]: (v) => v * 1e3,
884
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v,
885
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
886
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
887
+ [CurrencyUnit.SATOSHI]: (v) => v * 1e5,
888
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
883
889
  /* Round without decimals since we're returning cents: */
884
890
  round(v / 1e3 * centsPerBtc)
885
891
  )
886
892
  },
887
- ["MILLISATOSHI" /* MILLISATOSHI */]: {
888
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e11,
889
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 1e5,
890
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e8,
891
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v,
892
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v / 100,
893
- ["SATOSHI" /* SATOSHI */]: (v) => v / 1e3,
894
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
893
+ [CurrencyUnit.MILLISATOSHI]: {
894
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
895
+ [CurrencyUnit.MICROBITCOIN]: (v) => v / 1e5,
896
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e8,
897
+ [CurrencyUnit.MILLISATOSHI]: (v) => v,
898
+ [CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
899
+ [CurrencyUnit.SATOSHI]: (v) => v / 1e3,
900
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
895
901
  /* Round without decimals since we're returning cents: */
896
902
  round(v / 1e11 * centsPerBtc)
897
903
  )
898
904
  },
899
- ["NANOBITCOIN" /* NANOBITCOIN */]: {
900
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e9,
901
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 1e3,
902
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e6,
903
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 100,
904
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v,
905
- ["SATOSHI" /* SATOSHI */]: (v) => v / 10,
906
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
905
+ [CurrencyUnit.NANOBITCOIN]: {
906
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
907
+ [CurrencyUnit.MICROBITCOIN]: (v) => v / 1e3,
908
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e6,
909
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
910
+ [CurrencyUnit.NANOBITCOIN]: (v) => v,
911
+ [CurrencyUnit.SATOSHI]: (v) => v / 10,
912
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
907
913
  /* Round without decimals since we're returning cents: */
908
914
  round(v / 1e9 * centsPerBtc)
909
915
  )
910
916
  },
911
- ["SATOSHI" /* SATOSHI */]: {
912
- ["BITCOIN" /* BITCOIN */]: (v) => v / 1e8,
913
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v / 100,
914
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v / 1e5,
915
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e3,
916
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 10,
917
- ["SATOSHI" /* SATOSHI */]: (v) => v,
918
- ["USD" /* USD */]: (v, centsPerBtc = 1) => (
917
+ [CurrencyUnit.SATOSHI]: {
918
+ [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
919
+ [CurrencyUnit.MICROBITCOIN]: (v) => v / 100,
920
+ [CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e5,
921
+ [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
922
+ [CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
923
+ [CurrencyUnit.SATOSHI]: (v) => v,
924
+ [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
919
925
  /* Round without decimals since we're returning cents: */
920
926
  round(v / 1e8 * centsPerBtc)
921
927
  )
922
928
  },
923
- ["USD" /* USD */]: {
924
- ["BITCOIN" /* BITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc,
925
- ["MICROBITCOIN" /* MICROBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
926
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
927
- ["MILLISATOSHI" /* MILLISATOSHI */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
928
- ["NANOBITCOIN" /* NANOBITCOIN */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
929
- ["SATOSHI" /* SATOSHI */]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
930
- ["USD" /* USD */]: (v) => v
929
+ [CurrencyUnit.USD]: {
930
+ [CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
931
+ [CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
932
+ [CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
933
+ [CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
934
+ [CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
935
+ [CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
936
+ [CurrencyUnit.USD]: (v) => v
931
937
  }
932
938
  };
933
939
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
934
- if (fromUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || toUnit === "FUTURE_VALUE" /* FUTURE_VALUE */) {
940
+ if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
935
941
  throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
936
942
  }
937
943
  if (fromUnit === toUnit) {
@@ -962,8 +968,9 @@ var convertCurrencyAmount = (from, toUnit) => {
962
968
  function isCurrencyAmountObj(arg) {
963
969
  return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
964
970
  }
965
- function isCurrencyAmount(arg) {
966
- return typeof arg === "object" && arg !== null && "originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
971
+ function isSDKCurrencyAmount(arg) {
972
+ return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
973
+ "originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
967
974
  }
968
975
  function asNumber(value) {
969
976
  if (typeof value === "string") {
@@ -974,67 +981,67 @@ function asNumber(value) {
974
981
  function getCurrencyAmount(currencyAmountArg) {
975
982
  let value = 0;
976
983
  let unit = void 0;
977
- if (isCurrencyAmountObj(currencyAmountArg)) {
978
- value = asNumber(currencyAmountArg.value);
979
- unit = currencyAmountArg.unit;
980
- } else if (isCurrencyAmount(currencyAmountArg)) {
984
+ if (isSDKCurrencyAmount(currencyAmountArg)) {
981
985
  value = currencyAmountArg.originalValue;
982
986
  unit = currencyAmountArg.originalUnit;
987
+ } else if (isCurrencyAmountObj(currencyAmountArg)) {
988
+ value = asNumber(currencyAmountArg.value);
989
+ unit = currencyAmountArg.unit;
983
990
  }
984
991
  return {
985
992
  value: asNumber(value),
986
- unit: unit || "SATOSHI" /* SATOSHI */
993
+ unit: unit || CurrencyUnit.SATOSHI
987
994
  };
988
995
  }
989
996
  function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
990
997
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
991
998
  const convert = convertCurrencyAmountValue;
992
- const sats = convert(unit, "SATOSHI" /* SATOSHI */, value, centsPerBtc);
993
- const btc = convert(unit, "BITCOIN" /* BITCOIN */, value, centsPerBtc);
994
- const msats = convert(unit, "MILLISATOSHI" /* MILLISATOSHI */, value, centsPerBtc);
995
- const usd = convert(unit, "USD" /* USD */, value, centsPerBtc);
996
- const mibtc = convert(unit, "MICROBITCOIN" /* MICROBITCOIN */, value, centsPerBtc);
997
- const mlbtc = convert(unit, "MILLIBITCOIN" /* MILLIBITCOIN */, value, centsPerBtc);
998
- const nbtc = convert(unit, "NANOBITCOIN" /* NANOBITCOIN */, value, centsPerBtc);
999
+ const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
1000
+ const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
1001
+ const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
1002
+ const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
1003
+ const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
1004
+ const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
1005
+ const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
999
1006
  const mapWithCurrencyUnits = {
1000
- ["BITCOIN" /* BITCOIN */]: btc,
1001
- ["SATOSHI" /* SATOSHI */]: sats,
1002
- ["MILLISATOSHI" /* MILLISATOSHI */]: msats,
1003
- ["USD" /* USD */]: usd,
1004
- ["MICROBITCOIN" /* MICROBITCOIN */]: mibtc,
1005
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: mlbtc,
1006
- ["NANOBITCOIN" /* NANOBITCOIN */]: nbtc,
1007
- ["FUTURE_VALUE" /* FUTURE_VALUE */]: NaN,
1007
+ [CurrencyUnit.BITCOIN]: btc,
1008
+ [CurrencyUnit.SATOSHI]: sats,
1009
+ [CurrencyUnit.MILLISATOSHI]: msats,
1010
+ [CurrencyUnit.USD]: usd,
1011
+ [CurrencyUnit.MICROBITCOIN]: mibtc,
1012
+ [CurrencyUnit.MILLIBITCOIN]: mlbtc,
1013
+ [CurrencyUnit.NANOBITCOIN]: nbtc,
1014
+ [CurrencyUnit.FUTURE_VALUE]: NaN,
1008
1015
  formatted: {
1009
- ["BITCOIN" /* BITCOIN */]: formatCurrencyStr({
1016
+ [CurrencyUnit.BITCOIN]: formatCurrencyStr({
1010
1017
  value: btc,
1011
- unit: "BITCOIN" /* BITCOIN */
1018
+ unit: CurrencyUnit.BITCOIN
1012
1019
  }),
1013
- ["SATOSHI" /* SATOSHI */]: formatCurrencyStr({
1020
+ [CurrencyUnit.SATOSHI]: formatCurrencyStr({
1014
1021
  value: sats,
1015
- unit: "SATOSHI" /* SATOSHI */
1022
+ unit: CurrencyUnit.SATOSHI
1016
1023
  }),
1017
- ["MILLISATOSHI" /* MILLISATOSHI */]: formatCurrencyStr({
1024
+ [CurrencyUnit.MILLISATOSHI]: formatCurrencyStr({
1018
1025
  value: msats,
1019
- unit: "MILLISATOSHI" /* MILLISATOSHI */
1026
+ unit: CurrencyUnit.MILLISATOSHI
1020
1027
  }),
1021
- ["MICROBITCOIN" /* MICROBITCOIN */]: formatCurrencyStr({
1028
+ [CurrencyUnit.MICROBITCOIN]: formatCurrencyStr({
1022
1029
  value: mibtc,
1023
- unit: "MICROBITCOIN" /* MICROBITCOIN */
1030
+ unit: CurrencyUnit.MICROBITCOIN
1024
1031
  }),
1025
- ["MILLIBITCOIN" /* MILLIBITCOIN */]: formatCurrencyStr({
1032
+ [CurrencyUnit.MILLIBITCOIN]: formatCurrencyStr({
1026
1033
  value: mlbtc,
1027
- unit: "MILLIBITCOIN" /* MILLIBITCOIN */
1034
+ unit: CurrencyUnit.MILLIBITCOIN
1028
1035
  }),
1029
- ["NANOBITCOIN" /* NANOBITCOIN */]: formatCurrencyStr({
1036
+ [CurrencyUnit.NANOBITCOIN]: formatCurrencyStr({
1030
1037
  value: nbtc,
1031
- unit: "NANOBITCOIN" /* NANOBITCOIN */
1038
+ unit: CurrencyUnit.NANOBITCOIN
1032
1039
  }),
1033
- ["USD" /* USD */]: formatCurrencyStr({
1040
+ [CurrencyUnit.USD]: formatCurrencyStr({
1034
1041
  value: usd,
1035
- unit: "USD" /* USD */
1042
+ unit: CurrencyUnit.USD
1036
1043
  }),
1037
- ["FUTURE_VALUE" /* FUTURE_VALUE */]: "-"
1044
+ [CurrencyUnit.FUTURE_VALUE]: "-"
1038
1045
  }
1039
1046
  };
1040
1047
  return {
@@ -1072,9 +1079,9 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
1072
1079
  },
1073
1080
  formatted: {
1074
1081
  ...mapWithCurrencyUnits.formatted,
1075
- btc: mapWithCurrencyUnits.formatted["BITCOIN" /* BITCOIN */],
1076
- sats: mapWithCurrencyUnits.formatted["SATOSHI" /* SATOSHI */],
1077
- msats: mapWithCurrencyUnits.formatted["MILLISATOSHI" /* MILLISATOSHI */]
1082
+ btc: mapWithCurrencyUnits.formatted[CurrencyUnit.BITCOIN],
1083
+ sats: mapWithCurrencyUnits.formatted[CurrencyUnit.SATOSHI],
1084
+ msats: mapWithCurrencyUnits.formatted[CurrencyUnit.MILLISATOSHI]
1078
1085
  },
1079
1086
  type: "CurrencyMap"
1080
1087
  };
@@ -1082,54 +1089,73 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
1082
1089
  var isCurrencyMap = (currencyMap) => typeof currencyMap === "object" && currencyMap !== null && "type" in currencyMap && typeof currencyMap.type === "string" && currencyMap.type === "CurrencyMap";
1083
1090
  var abbrCurrencyUnit = (unit) => {
1084
1091
  switch (unit) {
1085
- case "BITCOIN" /* BITCOIN */:
1092
+ case CurrencyUnit.BITCOIN:
1086
1093
  return "BTC";
1087
- case "SATOSHI" /* SATOSHI */:
1094
+ case CurrencyUnit.SATOSHI:
1088
1095
  return "SAT";
1089
- case "MILLISATOSHI" /* MILLISATOSHI */:
1096
+ case CurrencyUnit.MILLISATOSHI:
1090
1097
  return "MSAT";
1091
- case "USD" /* USD */:
1098
+ case CurrencyUnit.USD:
1092
1099
  return "USD";
1093
1100
  }
1094
1101
  return "Unsupported CurrencyUnit";
1095
1102
  };
1096
- function formatCurrencyStr(amount, maxFractionDigits, compact, showBtcSymbol = false, options = {}) {
1103
+ var defaultOptions = {
1104
+ /* undefined indicates to use default precision for unit defined below */
1105
+ precision: void 0,
1106
+ compact: false,
1107
+ showBtcSymbol: false
1108
+ };
1109
+ function formatCurrencyStr(amount, options) {
1110
+ const { precision, compact, showBtcSymbol } = {
1111
+ ...defaultOptions,
1112
+ ...options
1113
+ };
1097
1114
  const currencyAmount = getCurrencyAmount(amount);
1098
1115
  let { value: num } = currencyAmount;
1099
1116
  const { unit } = currencyAmount;
1100
- if (unit === "USD" /* USD */) {
1117
+ if (unit === CurrencyUnit.USD) {
1101
1118
  num = num / 100;
1102
1119
  }
1103
- function getDefaultMaxFractionDigits(defaultDigits) {
1104
- return typeof maxFractionDigits === "undefined" ? compact ? 1 : defaultDigits : maxFractionDigits;
1120
+ function getDefaultMaxFractionDigits(defaultDigits, fullPrecisionDigits) {
1121
+ let digits = defaultDigits;
1122
+ if (precision === "full") {
1123
+ digits = fullPrecisionDigits;
1124
+ } else if (typeof precision === "number") {
1125
+ digits = precision;
1126
+ } else if (compact) {
1127
+ digits = 1;
1128
+ }
1129
+ return digits;
1105
1130
  }
1106
- const symbol = !showBtcSymbol ? "" : unit === "BITCOIN" /* BITCOIN */ ? "\uE903" : unit === "SATOSHI" /* SATOSHI */ ? "\uE902" : "";
1131
+ const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
1107
1132
  const currentLocale = getCurrentLocale();
1108
1133
  switch (unit) {
1109
- case "BITCOIN" /* BITCOIN */:
1134
+ case CurrencyUnit.BITCOIN:
1135
+ return `${symbol}${num.toLocaleString(currentLocale, {
1136
+ notation: compact ? "compact" : void 0,
1137
+ maximumFractionDigits: getDefaultMaxFractionDigits(4, 8)
1138
+ })}`;
1139
+ case CurrencyUnit.SATOSHI:
1110
1140
  return `${symbol}${num.toLocaleString(currentLocale, {
1111
1141
  notation: compact ? "compact" : void 0,
1112
- maximumFractionDigits: getDefaultMaxFractionDigits(4),
1113
- ...options
1142
+ maximumFractionDigits: getDefaultMaxFractionDigits(0, 3)
1114
1143
  })}`;
1115
- case "MILLISATOSHI" /* MILLISATOSHI */:
1116
- case "SATOSHI" /* SATOSHI */:
1117
- case "MICROBITCOIN" /* MICROBITCOIN */:
1118
- case "MILLIBITCOIN" /* MILLIBITCOIN */:
1119
- case "NANOBITCOIN" /* NANOBITCOIN */:
1144
+ case CurrencyUnit.MILLISATOSHI:
1145
+ case CurrencyUnit.MICROBITCOIN:
1146
+ case CurrencyUnit.MILLIBITCOIN:
1147
+ case CurrencyUnit.NANOBITCOIN:
1120
1148
  default:
1121
1149
  return `${symbol}${num.toLocaleString(currentLocale, {
1122
1150
  notation: compact ? "compact" : void 0,
1123
- maximumFractionDigits: getDefaultMaxFractionDigits(0),
1124
- ...options
1151
+ maximumFractionDigits: getDefaultMaxFractionDigits(0, 0)
1125
1152
  })}`;
1126
- case "USD" /* USD */:
1153
+ case CurrencyUnit.USD:
1127
1154
  return num.toLocaleString(currentLocale, {
1128
1155
  style: "currency",
1129
1156
  currency: defaultCurrencyCode,
1130
1157
  notation: compact ? "compact" : void 0,
1131
- maximumFractionDigits: getDefaultMaxFractionDigits(2),
1132
- ...options
1158
+ maximumFractionDigits: getDefaultMaxFractionDigits(2, 2)
1133
1159
  });
1134
1160
  }
1135
1161
  }
@@ -1541,7 +1567,7 @@ var Requester = class {
1541
1567
  }
1542
1568
  }
1543
1569
  const operation = operationMatch[2];
1544
- let bodyData = {
1570
+ const payload = {
1545
1571
  query: queryPayload,
1546
1572
  variables,
1547
1573
  operationName: operation
@@ -1551,14 +1577,19 @@ var Requester = class {
1551
1577
  const baseHeaders = {
1552
1578
  "Content-Type": "application/json",
1553
1579
  "X-Lightspark-SDK": sdkUserAgent,
1554
- "User-Agent": browserUserAgent || sdkUserAgent
1580
+ "User-Agent": browserUserAgent || sdkUserAgent,
1581
+ "X-GraphQL-Operation": operation
1555
1582
  };
1556
1583
  const headers = skipAuth ? baseHeaders : await this.authProvider.addAuthHeaders(baseHeaders);
1557
- bodyData = await this.addSigningDataIfNeeded(
1558
- bodyData,
1584
+ let bodyData = await this.addSigningDataIfNeeded(
1585
+ payload,
1559
1586
  headers,
1560
1587
  signingNodeId
1561
1588
  );
1589
+ if (bodyData.length > 1024 && typeof CompressionStream != "undefined") {
1590
+ bodyData = await compress(bodyData);
1591
+ headers["Content-Encoding"] = "deflate";
1592
+ }
1562
1593
  let urlWithProtocol = this.baseUrl;
1563
1594
  if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
1564
1595
  urlWithProtocol = `https://${urlWithProtocol}`;
@@ -1572,7 +1603,7 @@ var Requester = class {
1572
1603
  const response = await fetch(url, {
1573
1604
  method: "POST",
1574
1605
  headers,
1575
- body: JSON.stringify(bodyData)
1606
+ body: bodyData
1576
1607
  });
1577
1608
  if (!response.ok) {
1578
1609
  throw new LightsparkException_default(
@@ -1599,8 +1630,14 @@ var Requester = class {
1599
1630
  return url.replace(/.*?:\/\//g, "");
1600
1631
  }
1601
1632
  async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
1633
+ let TextEncoderImpl;
1634
+ if (typeof TextEncoder === "undefined") {
1635
+ TextEncoderImpl = (await import("text-encoding")).TextEncoder;
1636
+ } else {
1637
+ TextEncoderImpl = TextEncoder;
1638
+ }
1602
1639
  if (!signingNodeId) {
1603
- return queryPayload;
1640
+ return new TextEncoderImpl().encode(JSON.stringify(queryPayload));
1604
1641
  }
1605
1642
  const query = queryPayload.query;
1606
1643
  const variables = queryPayload.variables;
@@ -1620,12 +1657,6 @@ var Requester = class {
1620
1657
  "Missing node of encrypted_signing_private_key"
1621
1658
  );
1622
1659
  }
1623
- let TextEncoderImpl;
1624
- if (typeof TextEncoder === "undefined") {
1625
- TextEncoderImpl = (await import("text-encoding")).TextEncoder;
1626
- } else {
1627
- TextEncoderImpl = TextEncoder;
1628
- }
1629
1660
  const encodedPayload = new TextEncoderImpl().encode(
1630
1661
  JSON.stringify(payload)
1631
1662
  );
@@ -1635,9 +1666,22 @@ var Requester = class {
1635
1666
  v: "1",
1636
1667
  signature: encodedSignedPayload
1637
1668
  });
1638
- return payload;
1669
+ return encodedPayload;
1639
1670
  }
1640
1671
  };
1672
+ async function compress(data) {
1673
+ const stream = new Blob([data]).stream();
1674
+ const compressedStream = stream.pipeThrough(new CompressionStream("deflate"));
1675
+ const reader = compressedStream.getReader();
1676
+ const chunks = [];
1677
+ let done, value;
1678
+ while (!done) {
1679
+ ({ done, value } = await reader.read());
1680
+ chunks.push(value);
1681
+ }
1682
+ const blob = new Blob(chunks);
1683
+ return new Uint8Array(await blob.arrayBuffer());
1684
+ }
1641
1685
  var Requester_default = Requester;
1642
1686
  // Annotate the CommonJS export names for ESM import in node:
1643
1687
  0 && (module.exports = {
@@ -1678,7 +1722,6 @@ var Requester_default = Requester;
1678
1722
  getLocalStorageConfigItem,
1679
1723
  hexToBytes,
1680
1724
  isBrowser,
1681
- isCurrencyAmount,
1682
1725
  isCurrencyAmountObj,
1683
1726
  isCurrencyMap,
1684
1727
  isError,
@@ -1686,6 +1729,7 @@ var Requester_default = Requester;
1686
1729
  isErrorWithMessage,
1687
1730
  isNode,
1688
1731
  isNumber,
1732
+ isSDKCurrencyAmount,
1689
1733
  isTest,
1690
1734
  isType,
1691
1735
  isUint8Array,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { Y as ById, C as ConfigKeys, 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, a4 as notNullUndefined, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-9e41ffe5.js';
1
+ export { Z as ById, a7 as Complete, C as ConfigKeys, 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, a6 as PartialBy, 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-4698c2db.js';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  declare class LightsparkException extends Error {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { Y as ById, C as ConfigKeys, 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, a4 as notNullUndefined, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-9e41ffe5.js';
1
+ export { Z as ById, a7 as Complete, C as ConfigKeys, 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, a6 as PartialBy, 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-4698c2db.js';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  declare class LightsparkException extends Error {