@lightsparkdev/core 1.2.3 → 1.2.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.2.5
4
+
5
+ ### Patch Changes
6
+
7
+ - f148f37: - add RequiredKeys type utility
8
+
9
+ ## 1.2.4
10
+
11
+ ### Patch Changes
12
+
13
+ - 1a063b6: - Add MXN to currency conversion util
14
+ - 1a063b6: - Remove text-encoding dependency previously needed for React Native support
15
+
3
16
  ## 1.2.3
4
17
 
5
18
  ### Patch Changes
@@ -402,18 +402,37 @@ var CurrencyUnit = {
402
402
  BITCOIN: "BITCOIN",
403
403
  SATOSHI: "SATOSHI",
404
404
  MILLISATOSHI: "MILLISATOSHI",
405
- USD: "USD",
406
405
  NANOBITCOIN: "NANOBITCOIN",
407
406
  MICROBITCOIN: "MICROBITCOIN",
408
407
  MILLIBITCOIN: "MILLIBITCOIN",
408
+ USD: "USD",
409
+ MXN: "MXN",
409
410
  Bitcoin: "BITCOIN",
410
411
  Microbitcoin: "MICROBITCOIN",
411
412
  Millibitcoin: "MILLIBITCOIN",
412
413
  Millisatoshi: "MILLISATOSHI",
413
414
  Nanobitcoin: "NANOBITCOIN",
414
415
  Satoshi: "SATOSHI",
415
- Usd: "USD"
416
+ Usd: "USD",
417
+ Mxn: "MXN"
418
+ };
419
+ var standardUnitConversionObj = {
420
+ [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
421
+ [CurrencyUnit.MICROBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e6,
422
+ [CurrencyUnit.MILLIBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e3,
423
+ [CurrencyUnit.MILLISATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e11,
424
+ [CurrencyUnit.NANOBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e9,
425
+ [CurrencyUnit.SATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e8,
426
+ /* Converting between two different fiat types is not currently supported */
427
+ [CurrencyUnit.USD]: (v) => v,
428
+ [CurrencyUnit.MXN]: (v) => v
416
429
  };
430
+ var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
431
+ var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
432
+ var toMillibitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e3 * unitsPerBtc);
433
+ var toMillisatoshiConversion = (v, unitsPerBtc = 1) => round(v / 1e11 * unitsPerBtc);
434
+ var toNanobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e9 * unitsPerBtc);
435
+ var toSatoshiConversion = (v, unitsPerBtc = 1) => round(v / 1e8 * unitsPerBtc);
417
436
  var CONVERSION_MAP = {
418
437
  [CurrencyUnit.BITCOIN]: {
419
438
  [CurrencyUnit.BITCOIN]: (v) => v,
@@ -422,10 +441,8 @@ var CONVERSION_MAP = {
422
441
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
423
442
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
424
443
  [CurrencyUnit.SATOSHI]: (v) => v * 1e8,
425
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
426
- /* Round without decimals since we're returning cents: */
427
- round(v * centsPerBtc, 2)
428
- )
444
+ [CurrencyUnit.USD]: toBitcoinConversion,
445
+ [CurrencyUnit.MXN]: toBitcoinConversion
429
446
  },
430
447
  [CurrencyUnit.MICROBITCOIN]: {
431
448
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -434,10 +451,8 @@ var CONVERSION_MAP = {
434
451
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
435
452
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
436
453
  [CurrencyUnit.SATOSHI]: (v) => v * 100,
437
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
438
- /* Round without decimals since we're returning cents: */
439
- round(v / 1e6 * centsPerBtc)
440
- )
454
+ [CurrencyUnit.USD]: toMicrobitcoinConversion,
455
+ [CurrencyUnit.MXN]: toMicrobitcoinConversion
441
456
  },
442
457
  [CurrencyUnit.MILLIBITCOIN]: {
443
458
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -446,10 +461,8 @@ var CONVERSION_MAP = {
446
461
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
447
462
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
448
463
  [CurrencyUnit.SATOSHI]: (v) => v * 1e5,
449
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
450
- /* Round without decimals since we're returning cents: */
451
- round(v / 1e3 * centsPerBtc)
452
- )
464
+ [CurrencyUnit.USD]: toMillibitcoinConversion,
465
+ [CurrencyUnit.MXN]: toMillibitcoinConversion
453
466
  },
454
467
  [CurrencyUnit.MILLISATOSHI]: {
455
468
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -458,10 +471,8 @@ var CONVERSION_MAP = {
458
471
  [CurrencyUnit.MILLISATOSHI]: (v) => v,
459
472
  [CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
460
473
  [CurrencyUnit.SATOSHI]: (v) => v / 1e3,
461
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
462
- /* Round without decimals since we're returning cents: */
463
- round(v / 1e11 * centsPerBtc)
464
- )
474
+ [CurrencyUnit.USD]: toMillisatoshiConversion,
475
+ [CurrencyUnit.MXN]: toMillisatoshiConversion
465
476
  },
466
477
  [CurrencyUnit.NANOBITCOIN]: {
467
478
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -470,10 +481,8 @@ var CONVERSION_MAP = {
470
481
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
471
482
  [CurrencyUnit.NANOBITCOIN]: (v) => v,
472
483
  [CurrencyUnit.SATOSHI]: (v) => v / 10,
473
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
474
- /* Round without decimals since we're returning cents: */
475
- round(v / 1e9 * centsPerBtc)
476
- )
484
+ [CurrencyUnit.USD]: toNanobitcoinConversion,
485
+ [CurrencyUnit.MXN]: toNanobitcoinConversion
477
486
  },
478
487
  [CurrencyUnit.SATOSHI]: {
479
488
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -482,22 +491,13 @@ var CONVERSION_MAP = {
482
491
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
483
492
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
484
493
  [CurrencyUnit.SATOSHI]: (v) => v,
485
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
486
- /* Round without decimals since we're returning cents: */
487
- round(v / 1e8 * centsPerBtc)
488
- )
494
+ [CurrencyUnit.USD]: toSatoshiConversion,
495
+ [CurrencyUnit.MXN]: toSatoshiConversion
489
496
  },
490
- [CurrencyUnit.USD]: {
491
- [CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
492
- [CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
493
- [CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
494
- [CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
495
- [CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
496
- [CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
497
- [CurrencyUnit.USD]: (v) => v
498
- }
497
+ [CurrencyUnit.USD]: standardUnitConversionObj,
498
+ [CurrencyUnit.MXN]: standardUnitConversionObj
499
499
  };
500
- function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
500
+ function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
501
501
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
502
502
  throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
503
503
  }
@@ -511,7 +511,7 @@ function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
511
511
  `Cannot convert from ${fromUnit} to ${toUnit}`
512
512
  );
513
513
  }
514
- return conversionFn(amount, centsPerBtc);
514
+ return conversionFn(amount, unitsPerBtc);
515
515
  }
516
516
  var convertCurrencyAmount = (from, toUnit) => {
517
517
  const value = convertCurrencyAmountValue(
@@ -566,21 +566,23 @@ function getCurrencyAmount(currencyAmountArg) {
566
566
  unit: unit || CurrencyUnit.SATOSHI
567
567
  };
568
568
  }
569
- function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
569
+ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
570
570
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
571
571
  const convert = convertCurrencyAmountValue;
572
- const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
573
- const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
574
- const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
575
- const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
576
- const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
577
- const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
578
- const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
572
+ const sats = convert(unit, CurrencyUnit.SATOSHI, value, unitsPerBtc);
573
+ const btc = convert(unit, CurrencyUnit.BITCOIN, value, unitsPerBtc);
574
+ const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, unitsPerBtc);
575
+ const usd = convert(unit, CurrencyUnit.USD, value, unitsPerBtc);
576
+ const mxn = convert(unit, CurrencyUnit.MXN, value, unitsPerBtc);
577
+ const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, unitsPerBtc);
578
+ const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, unitsPerBtc);
579
+ const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, unitsPerBtc);
579
580
  const mapWithCurrencyUnits = {
580
581
  [CurrencyUnit.BITCOIN]: btc,
581
582
  [CurrencyUnit.SATOSHI]: sats,
582
583
  [CurrencyUnit.MILLISATOSHI]: msats,
583
584
  [CurrencyUnit.USD]: usd,
585
+ [CurrencyUnit.MXN]: mxn,
584
586
  [CurrencyUnit.MICROBITCOIN]: mibtc,
585
587
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
586
588
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -614,6 +616,10 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
614
616
  value: usd,
615
617
  unit: CurrencyUnit.USD
616
618
  }),
619
+ [CurrencyUnit.MXN]: formatCurrencyStr({
620
+ value: mxn,
621
+ unit: CurrencyUnit.MXN
622
+ }),
617
623
  [CurrencyUnit.FUTURE_VALUE]: "-"
618
624
  }
619
625
  };
@@ -20,10 +20,11 @@ declare const CurrencyUnit: {
20
20
  readonly BITCOIN: "BITCOIN";
21
21
  readonly SATOSHI: "SATOSHI";
22
22
  readonly MILLISATOSHI: "MILLISATOSHI";
23
- readonly USD: "USD";
24
23
  readonly NANOBITCOIN: "NANOBITCOIN";
25
24
  readonly MICROBITCOIN: "MICROBITCOIN";
26
25
  readonly MILLIBITCOIN: "MILLIBITCOIN";
26
+ readonly USD: "USD";
27
+ readonly MXN: "MXN";
27
28
  readonly Bitcoin: "BITCOIN";
28
29
  readonly Microbitcoin: "MICROBITCOIN";
29
30
  readonly Millibitcoin: "MILLIBITCOIN";
@@ -31,6 +32,7 @@ declare const CurrencyUnit: {
31
32
  readonly Nanobitcoin: "NANOBITCOIN";
32
33
  readonly Satoshi: "SATOSHI";
33
34
  readonly Usd: "USD";
35
+ readonly Mxn: "MXN";
34
36
  };
35
37
  type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
36
38
  type SDKCurrencyAmountType = {
@@ -40,7 +42,7 @@ type SDKCurrencyAmountType = {
40
42
  preferredCurrencyValueRounded: number;
41
43
  preferredCurrencyValueApprox: number;
42
44
  };
43
- declare function convertCurrencyAmountValue(fromUnit: CurrencyUnitType, toUnit: CurrencyUnitType, amount: number, centsPerBtc?: number): number;
45
+ declare function convertCurrencyAmountValue(fromUnit: CurrencyUnitType, toUnit: CurrencyUnitType, amount: number, unitsPerBtc?: number): number;
44
46
  declare const convertCurrencyAmount: (from: SDKCurrencyAmountType, toUnit: CurrencyUnitType) => SDKCurrencyAmountType;
45
47
  type CurrencyMap = {
46
48
  sats: number;
@@ -53,6 +55,7 @@ type CurrencyMap = {
53
55
  [CurrencyUnit.MILLIBITCOIN]: number;
54
56
  [CurrencyUnit.NANOBITCOIN]: number;
55
57
  [CurrencyUnit.USD]: number;
58
+ [CurrencyUnit.MXN]: number;
56
59
  [CurrencyUnit.FUTURE_VALUE]: number;
57
60
  formatted: {
58
61
  sats: string;
@@ -65,6 +68,7 @@ type CurrencyMap = {
65
68
  [CurrencyUnit.MICROBITCOIN]: string;
66
69
  [CurrencyUnit.NANOBITCOIN]: string;
67
70
  [CurrencyUnit.USD]: string;
71
+ [CurrencyUnit.MXN]: string;
68
72
  [CurrencyUnit.FUTURE_VALUE]: string;
69
73
  };
70
74
  isZero: boolean;
@@ -93,7 +97,7 @@ declare function isDeprecatedCurrencyAmountObj(arg: unknown): arg is DeprecatedC
93
97
  declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
94
98
  declare function isCurrencyAmountPreferenceObj(arg: unknown): arg is CurrencyAmountPreferenceObj;
95
99
  declare function isSDKCurrencyAmount(arg: unknown): arg is SDKCurrencyAmountType;
96
- declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
100
+ declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, unitsPerBtc?: number): CurrencyMap;
97
101
  declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
98
102
  declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
99
103
  type FormatCurrencyStrOptions = {
@@ -141,6 +145,15 @@ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
141
145
  type Complete<T> = {
142
146
  [P in keyof T]-?: NonNullable<T[P]>;
143
147
  };
148
+ /**
149
+ * RequiredKeys utility extracts all the keys of T that are required.
150
+ * For each key K in T, it checks if Pick<T, K> extends {} (an empty object). If it does, that
151
+ * means K is optional; otherwise, it's required.
152
+ * The resulting type is a union of all required keys in T.
153
+ */
154
+ type RequiredKeys<T> = {
155
+ [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
156
+ }[keyof T];
144
157
 
145
158
  declare const isError: (e: unknown) => e is Error;
146
159
  type ErrorWithMessage = {
@@ -253,4 +266,4 @@ declare function lsidToUUID(lsid: string): string;
253
266
  declare function isUint8Array(value: unknown): value is Uint8Array;
254
267
  declare function isObject(value: unknown): value is Record<string, unknown>;
255
268
 
256
- export { isUint8Array as $, isTest as A, isError as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, isErrorWithMessage as E, getErrorMsg as F, isErrorMsg as G, errorToJSON as H, bytesToHex as I, hexToBytes as J, getCurrentLocale as K, countryCodesToCurrencyCodes as L, type CurrencyLocales as M, type CurrencyCodes as N, localeToCurrencyCode as O, getLocalStorageConfigItem as P, getLocalStorageBoolean as Q, setLocalStorageBoolean as R, type SDKCurrencyAmountType as S, deleteLocalStorageItem as T, clamp as U, linearInterpolate as V, round as W, isNumber as X, pollUntil as Y, sleep as Z, lsidToUUID as _, b64encode as a, isObject as a0, type Maybe as a1, type ExpandRecursively as a2, type ById as a3, type OmitTypename as a4, isType as a5, type DeepPartial as a6, type JSONLiteral as a7, type JSONType as a8, type JSONObject as a9, type NN as aa, notNullUndefined as ab, type PartialBy as ac, type Complete as ad, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountObj as k, type CurrencyAmountPreferenceObj as l, type CurrencyAmountArg as m, isDeprecatedCurrencyAmountObj as n, isCurrencyAmountObj as o, isCurrencyAmountPreferenceObj as p, isSDKCurrencyAmount as q, mapCurrencyAmount as r, isCurrencyMap as s, abbrCurrencyUnit as t, urlsafe_b64decode as u, formatCurrencyStr as v, separateCurrencyStrParts as w, localeToCurrencySymbol as x, isBrowser as y, isNode as z };
269
+ export { isUint8Array as $, isTest as A, isError as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, isErrorWithMessage as E, getErrorMsg as F, isErrorMsg as G, errorToJSON as H, bytesToHex as I, hexToBytes as J, getCurrentLocale as K, countryCodesToCurrencyCodes as L, type CurrencyLocales as M, type CurrencyCodes as N, localeToCurrencyCode as O, getLocalStorageConfigItem as P, getLocalStorageBoolean as Q, setLocalStorageBoolean as R, type SDKCurrencyAmountType as S, deleteLocalStorageItem as T, clamp as U, linearInterpolate as V, round as W, isNumber as X, pollUntil as Y, sleep as Z, lsidToUUID as _, b64encode as a, isObject as a0, type Maybe as a1, type ExpandRecursively as a2, type ById as a3, type OmitTypename as a4, isType as a5, type DeepPartial as a6, type JSONLiteral as a7, type JSONType as a8, type JSONObject as a9, type NN as aa, notNullUndefined as ab, type PartialBy as ac, type Complete as ad, type RequiredKeys as ae, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountObj as k, type CurrencyAmountPreferenceObj as l, type CurrencyAmountArg as m, isDeprecatedCurrencyAmountObj as n, isCurrencyAmountObj as o, isCurrencyAmountPreferenceObj as p, isSDKCurrencyAmount as q, mapCurrencyAmount as r, isCurrencyMap as s, abbrCurrencyUnit as t, urlsafe_b64decode as u, formatCurrencyStr as v, separateCurrencyStrParts as w, localeToCurrencySymbol as x, isBrowser as y, isNode as z };
@@ -20,10 +20,11 @@ declare const CurrencyUnit: {
20
20
  readonly BITCOIN: "BITCOIN";
21
21
  readonly SATOSHI: "SATOSHI";
22
22
  readonly MILLISATOSHI: "MILLISATOSHI";
23
- readonly USD: "USD";
24
23
  readonly NANOBITCOIN: "NANOBITCOIN";
25
24
  readonly MICROBITCOIN: "MICROBITCOIN";
26
25
  readonly MILLIBITCOIN: "MILLIBITCOIN";
26
+ readonly USD: "USD";
27
+ readonly MXN: "MXN";
27
28
  readonly Bitcoin: "BITCOIN";
28
29
  readonly Microbitcoin: "MICROBITCOIN";
29
30
  readonly Millibitcoin: "MILLIBITCOIN";
@@ -31,6 +32,7 @@ declare const CurrencyUnit: {
31
32
  readonly Nanobitcoin: "NANOBITCOIN";
32
33
  readonly Satoshi: "SATOSHI";
33
34
  readonly Usd: "USD";
35
+ readonly Mxn: "MXN";
34
36
  };
35
37
  type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
36
38
  type SDKCurrencyAmountType = {
@@ -40,7 +42,7 @@ type SDKCurrencyAmountType = {
40
42
  preferredCurrencyValueRounded: number;
41
43
  preferredCurrencyValueApprox: number;
42
44
  };
43
- declare function convertCurrencyAmountValue(fromUnit: CurrencyUnitType, toUnit: CurrencyUnitType, amount: number, centsPerBtc?: number): number;
45
+ declare function convertCurrencyAmountValue(fromUnit: CurrencyUnitType, toUnit: CurrencyUnitType, amount: number, unitsPerBtc?: number): number;
44
46
  declare const convertCurrencyAmount: (from: SDKCurrencyAmountType, toUnit: CurrencyUnitType) => SDKCurrencyAmountType;
45
47
  type CurrencyMap = {
46
48
  sats: number;
@@ -53,6 +55,7 @@ type CurrencyMap = {
53
55
  [CurrencyUnit.MILLIBITCOIN]: number;
54
56
  [CurrencyUnit.NANOBITCOIN]: number;
55
57
  [CurrencyUnit.USD]: number;
58
+ [CurrencyUnit.MXN]: number;
56
59
  [CurrencyUnit.FUTURE_VALUE]: number;
57
60
  formatted: {
58
61
  sats: string;
@@ -65,6 +68,7 @@ type CurrencyMap = {
65
68
  [CurrencyUnit.MICROBITCOIN]: string;
66
69
  [CurrencyUnit.NANOBITCOIN]: string;
67
70
  [CurrencyUnit.USD]: string;
71
+ [CurrencyUnit.MXN]: string;
68
72
  [CurrencyUnit.FUTURE_VALUE]: string;
69
73
  };
70
74
  isZero: boolean;
@@ -93,7 +97,7 @@ declare function isDeprecatedCurrencyAmountObj(arg: unknown): arg is DeprecatedC
93
97
  declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
94
98
  declare function isCurrencyAmountPreferenceObj(arg: unknown): arg is CurrencyAmountPreferenceObj;
95
99
  declare function isSDKCurrencyAmount(arg: unknown): arg is SDKCurrencyAmountType;
96
- declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
100
+ declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, unitsPerBtc?: number): CurrencyMap;
97
101
  declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
98
102
  declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
99
103
  type FormatCurrencyStrOptions = {
@@ -141,6 +145,15 @@ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
141
145
  type Complete<T> = {
142
146
  [P in keyof T]-?: NonNullable<T[P]>;
143
147
  };
148
+ /**
149
+ * RequiredKeys utility extracts all the keys of T that are required.
150
+ * For each key K in T, it checks if Pick<T, K> extends {} (an empty object). If it does, that
151
+ * means K is optional; otherwise, it's required.
152
+ * The resulting type is a union of all required keys in T.
153
+ */
154
+ type RequiredKeys<T> = {
155
+ [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
156
+ }[keyof T];
144
157
 
145
158
  declare const isError: (e: unknown) => e is Error;
146
159
  type ErrorWithMessage = {
@@ -253,4 +266,4 @@ declare function lsidToUUID(lsid: string): string;
253
266
  declare function isUint8Array(value: unknown): value is Uint8Array;
254
267
  declare function isObject(value: unknown): value is Record<string, unknown>;
255
268
 
256
- export { isUint8Array as $, isTest as A, isError as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, isErrorWithMessage as E, getErrorMsg as F, isErrorMsg as G, errorToJSON as H, bytesToHex as I, hexToBytes as J, getCurrentLocale as K, countryCodesToCurrencyCodes as L, type CurrencyLocales as M, type CurrencyCodes as N, localeToCurrencyCode as O, getLocalStorageConfigItem as P, getLocalStorageBoolean as Q, setLocalStorageBoolean as R, type SDKCurrencyAmountType as S, deleteLocalStorageItem as T, clamp as U, linearInterpolate as V, round as W, isNumber as X, pollUntil as Y, sleep as Z, lsidToUUID as _, b64encode as a, isObject as a0, type Maybe as a1, type ExpandRecursively as a2, type ById as a3, type OmitTypename as a4, isType as a5, type DeepPartial as a6, type JSONLiteral as a7, type JSONType as a8, type JSONObject as a9, type NN as aa, notNullUndefined as ab, type PartialBy as ac, type Complete as ad, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountObj as k, type CurrencyAmountPreferenceObj as l, type CurrencyAmountArg as m, isDeprecatedCurrencyAmountObj as n, isCurrencyAmountObj as o, isCurrencyAmountPreferenceObj as p, isSDKCurrencyAmount as q, mapCurrencyAmount as r, isCurrencyMap as s, abbrCurrencyUnit as t, urlsafe_b64decode as u, formatCurrencyStr as v, separateCurrencyStrParts as w, localeToCurrencySymbol as x, isBrowser as y, isNode as z };
269
+ export { isUint8Array as $, isTest as A, isError as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, isErrorWithMessage as E, getErrorMsg as F, isErrorMsg as G, errorToJSON as H, bytesToHex as I, hexToBytes as J, getCurrentLocale as K, countryCodesToCurrencyCodes as L, type CurrencyLocales as M, type CurrencyCodes as N, localeToCurrencyCode as O, getLocalStorageConfigItem as P, getLocalStorageBoolean as Q, setLocalStorageBoolean as R, type SDKCurrencyAmountType as S, deleteLocalStorageItem as T, clamp as U, linearInterpolate as V, round as W, isNumber as X, pollUntil as Y, sleep as Z, lsidToUUID as _, b64encode as a, isObject as a0, type Maybe as a1, type ExpandRecursively as a2, type ById as a3, type OmitTypename as a4, isType as a5, type DeepPartial as a6, type JSONLiteral as a7, type JSONType as a8, type JSONObject as a9, type NN as aa, notNullUndefined as ab, type PartialBy as ac, type Complete as ad, type RequiredKeys as ae, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountObj as k, type CurrencyAmountPreferenceObj as l, type CurrencyAmountArg as m, isDeprecatedCurrencyAmountObj as n, isCurrencyAmountObj as o, isCurrencyAmountPreferenceObj as p, isSDKCurrencyAmount as q, mapCurrencyAmount as r, isCurrencyMap as s, abbrCurrencyUnit as t, urlsafe_b64decode as u, formatCurrencyStr as v, separateCurrencyStrParts as w, localeToCurrencySymbol as x, isBrowser as y, isNode as z };
package/dist/index.cjs CHANGED
@@ -789,18 +789,37 @@ var CurrencyUnit = {
789
789
  BITCOIN: "BITCOIN",
790
790
  SATOSHI: "SATOSHI",
791
791
  MILLISATOSHI: "MILLISATOSHI",
792
- USD: "USD",
793
792
  NANOBITCOIN: "NANOBITCOIN",
794
793
  MICROBITCOIN: "MICROBITCOIN",
795
794
  MILLIBITCOIN: "MILLIBITCOIN",
795
+ USD: "USD",
796
+ MXN: "MXN",
796
797
  Bitcoin: "BITCOIN",
797
798
  Microbitcoin: "MICROBITCOIN",
798
799
  Millibitcoin: "MILLIBITCOIN",
799
800
  Millisatoshi: "MILLISATOSHI",
800
801
  Nanobitcoin: "NANOBITCOIN",
801
802
  Satoshi: "SATOSHI",
802
- Usd: "USD"
803
+ Usd: "USD",
804
+ Mxn: "MXN"
803
805
  };
806
+ var standardUnitConversionObj = {
807
+ [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
808
+ [CurrencyUnit.MICROBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e6,
809
+ [CurrencyUnit.MILLIBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e3,
810
+ [CurrencyUnit.MILLISATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e11,
811
+ [CurrencyUnit.NANOBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e9,
812
+ [CurrencyUnit.SATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e8,
813
+ /* Converting between two different fiat types is not currently supported */
814
+ [CurrencyUnit.USD]: (v) => v,
815
+ [CurrencyUnit.MXN]: (v) => v
816
+ };
817
+ var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
818
+ var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
819
+ var toMillibitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e3 * unitsPerBtc);
820
+ var toMillisatoshiConversion = (v, unitsPerBtc = 1) => round(v / 1e11 * unitsPerBtc);
821
+ var toNanobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e9 * unitsPerBtc);
822
+ var toSatoshiConversion = (v, unitsPerBtc = 1) => round(v / 1e8 * unitsPerBtc);
804
823
  var CONVERSION_MAP = {
805
824
  [CurrencyUnit.BITCOIN]: {
806
825
  [CurrencyUnit.BITCOIN]: (v) => v,
@@ -809,10 +828,8 @@ var CONVERSION_MAP = {
809
828
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
810
829
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
811
830
  [CurrencyUnit.SATOSHI]: (v) => v * 1e8,
812
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
813
- /* Round without decimals since we're returning cents: */
814
- round(v * centsPerBtc, 2)
815
- )
831
+ [CurrencyUnit.USD]: toBitcoinConversion,
832
+ [CurrencyUnit.MXN]: toBitcoinConversion
816
833
  },
817
834
  [CurrencyUnit.MICROBITCOIN]: {
818
835
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -821,10 +838,8 @@ var CONVERSION_MAP = {
821
838
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
822
839
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
823
840
  [CurrencyUnit.SATOSHI]: (v) => v * 100,
824
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
825
- /* Round without decimals since we're returning cents: */
826
- round(v / 1e6 * centsPerBtc)
827
- )
841
+ [CurrencyUnit.USD]: toMicrobitcoinConversion,
842
+ [CurrencyUnit.MXN]: toMicrobitcoinConversion
828
843
  },
829
844
  [CurrencyUnit.MILLIBITCOIN]: {
830
845
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -833,10 +848,8 @@ var CONVERSION_MAP = {
833
848
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
834
849
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
835
850
  [CurrencyUnit.SATOSHI]: (v) => v * 1e5,
836
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
837
- /* Round without decimals since we're returning cents: */
838
- round(v / 1e3 * centsPerBtc)
839
- )
851
+ [CurrencyUnit.USD]: toMillibitcoinConversion,
852
+ [CurrencyUnit.MXN]: toMillibitcoinConversion
840
853
  },
841
854
  [CurrencyUnit.MILLISATOSHI]: {
842
855
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -845,10 +858,8 @@ var CONVERSION_MAP = {
845
858
  [CurrencyUnit.MILLISATOSHI]: (v) => v,
846
859
  [CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
847
860
  [CurrencyUnit.SATOSHI]: (v) => v / 1e3,
848
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
849
- /* Round without decimals since we're returning cents: */
850
- round(v / 1e11 * centsPerBtc)
851
- )
861
+ [CurrencyUnit.USD]: toMillisatoshiConversion,
862
+ [CurrencyUnit.MXN]: toMillisatoshiConversion
852
863
  },
853
864
  [CurrencyUnit.NANOBITCOIN]: {
854
865
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -857,10 +868,8 @@ var CONVERSION_MAP = {
857
868
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
858
869
  [CurrencyUnit.NANOBITCOIN]: (v) => v,
859
870
  [CurrencyUnit.SATOSHI]: (v) => v / 10,
860
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
861
- /* Round without decimals since we're returning cents: */
862
- round(v / 1e9 * centsPerBtc)
863
- )
871
+ [CurrencyUnit.USD]: toNanobitcoinConversion,
872
+ [CurrencyUnit.MXN]: toNanobitcoinConversion
864
873
  },
865
874
  [CurrencyUnit.SATOSHI]: {
866
875
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -869,22 +878,13 @@ var CONVERSION_MAP = {
869
878
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
870
879
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
871
880
  [CurrencyUnit.SATOSHI]: (v) => v,
872
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
873
- /* Round without decimals since we're returning cents: */
874
- round(v / 1e8 * centsPerBtc)
875
- )
881
+ [CurrencyUnit.USD]: toSatoshiConversion,
882
+ [CurrencyUnit.MXN]: toSatoshiConversion
876
883
  },
877
- [CurrencyUnit.USD]: {
878
- [CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
879
- [CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
880
- [CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
881
- [CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
882
- [CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
883
- [CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
884
- [CurrencyUnit.USD]: (v) => v
885
- }
884
+ [CurrencyUnit.USD]: standardUnitConversionObj,
885
+ [CurrencyUnit.MXN]: standardUnitConversionObj
886
886
  };
887
- function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
887
+ function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
888
888
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
889
889
  throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
890
890
  }
@@ -898,7 +898,7 @@ function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
898
898
  `Cannot convert from ${fromUnit} to ${toUnit}`
899
899
  );
900
900
  }
901
- return conversionFn(amount, centsPerBtc);
901
+ return conversionFn(amount, unitsPerBtc);
902
902
  }
903
903
  var convertCurrencyAmount = (from, toUnit) => {
904
904
  const value = convertCurrencyAmountValue(
@@ -953,21 +953,23 @@ function getCurrencyAmount(currencyAmountArg) {
953
953
  unit: unit || CurrencyUnit.SATOSHI
954
954
  };
955
955
  }
956
- function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
956
+ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
957
957
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
958
958
  const convert = convertCurrencyAmountValue;
959
- const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
960
- const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
961
- const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
962
- const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
963
- const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
964
- const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
965
- const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
959
+ const sats = convert(unit, CurrencyUnit.SATOSHI, value, unitsPerBtc);
960
+ const btc = convert(unit, CurrencyUnit.BITCOIN, value, unitsPerBtc);
961
+ const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, unitsPerBtc);
962
+ const usd = convert(unit, CurrencyUnit.USD, value, unitsPerBtc);
963
+ const mxn = convert(unit, CurrencyUnit.MXN, value, unitsPerBtc);
964
+ const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, unitsPerBtc);
965
+ const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, unitsPerBtc);
966
+ const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, unitsPerBtc);
966
967
  const mapWithCurrencyUnits = {
967
968
  [CurrencyUnit.BITCOIN]: btc,
968
969
  [CurrencyUnit.SATOSHI]: sats,
969
970
  [CurrencyUnit.MILLISATOSHI]: msats,
970
971
  [CurrencyUnit.USD]: usd,
972
+ [CurrencyUnit.MXN]: mxn,
971
973
  [CurrencyUnit.MICROBITCOIN]: mibtc,
972
974
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
973
975
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -1001,6 +1003,10 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
1001
1003
  value: usd,
1002
1004
  unit: CurrencyUnit.USD
1003
1005
  }),
1006
+ [CurrencyUnit.MXN]: formatCurrencyStr({
1007
+ value: mxn,
1008
+ unit: CurrencyUnit.MXN
1009
+ }),
1004
1010
  [CurrencyUnit.FUTURE_VALUE]: "-"
1005
1011
  }
1006
1012
  };
@@ -1652,14 +1658,8 @@ var Requester = class {
1652
1658
  return url.replace(/.*?:\/\//g, "");
1653
1659
  }
1654
1660
  async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
1655
- let TextEncoderImpl;
1656
- if (typeof TextEncoder === "undefined") {
1657
- TextEncoderImpl = (await import("text-encoding")).TextEncoder;
1658
- } else {
1659
- TextEncoderImpl = TextEncoder;
1660
- }
1661
1661
  if (!signingNodeId) {
1662
- return new TextEncoderImpl().encode(JSON.stringify(queryPayload));
1662
+ return new TextEncoder().encode(JSON.stringify(queryPayload));
1663
1663
  }
1664
1664
  const query = queryPayload.query;
1665
1665
  const variables = queryPayload.variables;
@@ -1679,9 +1679,7 @@ var Requester = class {
1679
1679
  "Missing node of encrypted_signing_private_key"
1680
1680
  );
1681
1681
  }
1682
- const encodedPayload = new TextEncoderImpl().encode(
1683
- JSON.stringify(payload)
1684
- );
1682
+ const encodedPayload = new TextEncoder().encode(JSON.stringify(payload));
1685
1683
  const signedPayload = await key.sign(encodedPayload);
1686
1684
  const encodedSignedPayload = b64encode(signedPayload);
1687
1685
  headers["X-Lightspark-Signing"] = JSON.stringify({
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { a3 as ById, ad as Complete, C as ConfigKeys, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from './index-DWJjMhfr.cjs';
1
+ export { a3 as ById, ad as Complete, C as ConfigKeys, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, ae as RequiredKeys, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from './index-COxEW2dD.cjs';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a3 as ById, ad as Complete, C as ConfigKeys, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from './index-DWJjMhfr.js';
1
+ export { a3 as ById, ad as Complete, C as ConfigKeys, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, ae as RequiredKeys, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from './index-COxEW2dD.js';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
package/dist/index.js CHANGED
@@ -47,7 +47,7 @@ import {
47
47
  setLocalStorageBoolean,
48
48
  sleep,
49
49
  urlsafe_b64decode
50
- } from "./chunk-ZU7NVHMW.js";
50
+ } from "./chunk-CKJUUY2Z.js";
51
51
 
52
52
  // src/auth/LightsparkAuthException.ts
53
53
  var LightsparkAuthException = class extends LightsparkException_default {
@@ -645,14 +645,8 @@ var Requester = class {
645
645
  return url.replace(/.*?:\/\//g, "");
646
646
  }
647
647
  async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
648
- let TextEncoderImpl;
649
- if (typeof TextEncoder === "undefined") {
650
- TextEncoderImpl = (await import("text-encoding")).TextEncoder;
651
- } else {
652
- TextEncoderImpl = TextEncoder;
653
- }
654
648
  if (!signingNodeId) {
655
- return new TextEncoderImpl().encode(JSON.stringify(queryPayload));
649
+ return new TextEncoder().encode(JSON.stringify(queryPayload));
656
650
  }
657
651
  const query = queryPayload.query;
658
652
  const variables = queryPayload.variables;
@@ -672,9 +666,7 @@ var Requester = class {
672
666
  "Missing node of encrypted_signing_private_key"
673
667
  );
674
668
  }
675
- const encodedPayload = new TextEncoderImpl().encode(
676
- JSON.stringify(payload)
677
- );
669
+ const encodedPayload = new TextEncoder().encode(JSON.stringify(payload));
678
670
  const signedPayload = await key.sign(encodedPayload);
679
671
  const encodedSignedPayload = b64encode(signedPayload);
680
672
  headers["X-Lightspark-Signing"] = JSON.stringify({
@@ -484,18 +484,37 @@ var CurrencyUnit = {
484
484
  BITCOIN: "BITCOIN",
485
485
  SATOSHI: "SATOSHI",
486
486
  MILLISATOSHI: "MILLISATOSHI",
487
- USD: "USD",
488
487
  NANOBITCOIN: "NANOBITCOIN",
489
488
  MICROBITCOIN: "MICROBITCOIN",
490
489
  MILLIBITCOIN: "MILLIBITCOIN",
490
+ USD: "USD",
491
+ MXN: "MXN",
491
492
  Bitcoin: "BITCOIN",
492
493
  Microbitcoin: "MICROBITCOIN",
493
494
  Millibitcoin: "MILLIBITCOIN",
494
495
  Millisatoshi: "MILLISATOSHI",
495
496
  Nanobitcoin: "NANOBITCOIN",
496
497
  Satoshi: "SATOSHI",
497
- Usd: "USD"
498
+ Usd: "USD",
499
+ Mxn: "MXN"
500
+ };
501
+ var standardUnitConversionObj = {
502
+ [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
503
+ [CurrencyUnit.MICROBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e6,
504
+ [CurrencyUnit.MILLIBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e3,
505
+ [CurrencyUnit.MILLISATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e11,
506
+ [CurrencyUnit.NANOBITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e9,
507
+ [CurrencyUnit.SATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e8,
508
+ /* Converting between two different fiat types is not currently supported */
509
+ [CurrencyUnit.USD]: (v) => v,
510
+ [CurrencyUnit.MXN]: (v) => v
498
511
  };
512
+ var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
513
+ var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
514
+ var toMillibitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e3 * unitsPerBtc);
515
+ var toMillisatoshiConversion = (v, unitsPerBtc = 1) => round(v / 1e11 * unitsPerBtc);
516
+ var toNanobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e9 * unitsPerBtc);
517
+ var toSatoshiConversion = (v, unitsPerBtc = 1) => round(v / 1e8 * unitsPerBtc);
499
518
  var CONVERSION_MAP = {
500
519
  [CurrencyUnit.BITCOIN]: {
501
520
  [CurrencyUnit.BITCOIN]: (v) => v,
@@ -504,10 +523,8 @@ var CONVERSION_MAP = {
504
523
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
505
524
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
506
525
  [CurrencyUnit.SATOSHI]: (v) => v * 1e8,
507
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
508
- /* Round without decimals since we're returning cents: */
509
- round(v * centsPerBtc, 2)
510
- )
526
+ [CurrencyUnit.USD]: toBitcoinConversion,
527
+ [CurrencyUnit.MXN]: toBitcoinConversion
511
528
  },
512
529
  [CurrencyUnit.MICROBITCOIN]: {
513
530
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -516,10 +533,8 @@ var CONVERSION_MAP = {
516
533
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
517
534
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
518
535
  [CurrencyUnit.SATOSHI]: (v) => v * 100,
519
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
520
- /* Round without decimals since we're returning cents: */
521
- round(v / 1e6 * centsPerBtc)
522
- )
536
+ [CurrencyUnit.USD]: toMicrobitcoinConversion,
537
+ [CurrencyUnit.MXN]: toMicrobitcoinConversion
523
538
  },
524
539
  [CurrencyUnit.MILLIBITCOIN]: {
525
540
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -528,10 +543,8 @@ var CONVERSION_MAP = {
528
543
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
529
544
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
530
545
  [CurrencyUnit.SATOSHI]: (v) => v * 1e5,
531
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
532
- /* Round without decimals since we're returning cents: */
533
- round(v / 1e3 * centsPerBtc)
534
- )
546
+ [CurrencyUnit.USD]: toMillibitcoinConversion,
547
+ [CurrencyUnit.MXN]: toMillibitcoinConversion
535
548
  },
536
549
  [CurrencyUnit.MILLISATOSHI]: {
537
550
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -540,10 +553,8 @@ var CONVERSION_MAP = {
540
553
  [CurrencyUnit.MILLISATOSHI]: (v) => v,
541
554
  [CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
542
555
  [CurrencyUnit.SATOSHI]: (v) => v / 1e3,
543
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
544
- /* Round without decimals since we're returning cents: */
545
- round(v / 1e11 * centsPerBtc)
546
- )
556
+ [CurrencyUnit.USD]: toMillisatoshiConversion,
557
+ [CurrencyUnit.MXN]: toMillisatoshiConversion
547
558
  },
548
559
  [CurrencyUnit.NANOBITCOIN]: {
549
560
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -552,10 +563,8 @@ var CONVERSION_MAP = {
552
563
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
553
564
  [CurrencyUnit.NANOBITCOIN]: (v) => v,
554
565
  [CurrencyUnit.SATOSHI]: (v) => v / 10,
555
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
556
- /* Round without decimals since we're returning cents: */
557
- round(v / 1e9 * centsPerBtc)
558
- )
566
+ [CurrencyUnit.USD]: toNanobitcoinConversion,
567
+ [CurrencyUnit.MXN]: toNanobitcoinConversion
559
568
  },
560
569
  [CurrencyUnit.SATOSHI]: {
561
570
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -564,22 +573,13 @@ var CONVERSION_MAP = {
564
573
  [CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
565
574
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
566
575
  [CurrencyUnit.SATOSHI]: (v) => v,
567
- [CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
568
- /* Round without decimals since we're returning cents: */
569
- round(v / 1e8 * centsPerBtc)
570
- )
576
+ [CurrencyUnit.USD]: toSatoshiConversion,
577
+ [CurrencyUnit.MXN]: toSatoshiConversion
571
578
  },
572
- [CurrencyUnit.USD]: {
573
- [CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
574
- [CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
575
- [CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
576
- [CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
577
- [CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
578
- [CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
579
- [CurrencyUnit.USD]: (v) => v
580
- }
579
+ [CurrencyUnit.USD]: standardUnitConversionObj,
580
+ [CurrencyUnit.MXN]: standardUnitConversionObj
581
581
  };
582
- function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
582
+ function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
583
583
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
584
584
  throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
585
585
  }
@@ -593,7 +593,7 @@ function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
593
593
  `Cannot convert from ${fromUnit} to ${toUnit}`
594
594
  );
595
595
  }
596
- return conversionFn(amount, centsPerBtc);
596
+ return conversionFn(amount, unitsPerBtc);
597
597
  }
598
598
  var convertCurrencyAmount = (from, toUnit) => {
599
599
  const value = convertCurrencyAmountValue(
@@ -648,21 +648,23 @@ function getCurrencyAmount(currencyAmountArg) {
648
648
  unit: unit || CurrencyUnit.SATOSHI
649
649
  };
650
650
  }
651
- function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
651
+ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
652
652
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
653
653
  const convert = convertCurrencyAmountValue;
654
- const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
655
- const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
656
- const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
657
- const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
658
- const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
659
- const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
660
- const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
654
+ const sats = convert(unit, CurrencyUnit.SATOSHI, value, unitsPerBtc);
655
+ const btc = convert(unit, CurrencyUnit.BITCOIN, value, unitsPerBtc);
656
+ const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, unitsPerBtc);
657
+ const usd = convert(unit, CurrencyUnit.USD, value, unitsPerBtc);
658
+ const mxn = convert(unit, CurrencyUnit.MXN, value, unitsPerBtc);
659
+ const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, unitsPerBtc);
660
+ const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, unitsPerBtc);
661
+ const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, unitsPerBtc);
661
662
  const mapWithCurrencyUnits = {
662
663
  [CurrencyUnit.BITCOIN]: btc,
663
664
  [CurrencyUnit.SATOSHI]: sats,
664
665
  [CurrencyUnit.MILLISATOSHI]: msats,
665
666
  [CurrencyUnit.USD]: usd,
667
+ [CurrencyUnit.MXN]: mxn,
666
668
  [CurrencyUnit.MICROBITCOIN]: mibtc,
667
669
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
668
670
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -696,6 +698,10 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
696
698
  value: usd,
697
699
  unit: CurrencyUnit.USD
698
700
  }),
701
+ [CurrencyUnit.MXN]: formatCurrencyStr({
702
+ value: mxn,
703
+ unit: CurrencyUnit.MXN
704
+ }),
699
705
  [CurrencyUnit.FUTURE_VALUE]: "-"
700
706
  }
701
707
  };
@@ -1 +1 @@
1
- export { a3 as ById, ad as Complete, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from '../index-DWJjMhfr.cjs';
1
+ export { a3 as ById, ad as Complete, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, ae as RequiredKeys, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from '../index-COxEW2dD.cjs';
@@ -1 +1 @@
1
- export { a3 as ById, ad as Complete, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from '../index-DWJjMhfr.js';
1
+ export { a3 as ById, ad as Complete, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, ae as RequiredKeys, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from '../index-COxEW2dD.js';
@@ -46,7 +46,7 @@ import {
46
46
  setLocalStorageBoolean,
47
47
  sleep,
48
48
  urlsafe_b64decode
49
- } from "../chunk-ZU7NVHMW.js";
49
+ } from "../chunk-CKJUUY2Z.js";
50
50
  export {
51
51
  CurrencyUnit,
52
52
  abbrCurrencyUnit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -77,7 +77,6 @@
77
77
  "graphql": "^16.6.0",
78
78
  "graphql-ws": "^5.11.3",
79
79
  "secp256k1": "^5.0.0",
80
- "text-encoding": "^0.7.0",
81
80
  "ws": "^8.12.1",
82
81
  "zen-observable-ts": "^1.1.0"
83
82
  },
@@ -88,7 +87,6 @@
88
87
  "@types/jest": "^29.5.3",
89
88
  "@types/lodash-es": "^4.17.6",
90
89
  "@types/secp256k1": "^4.0.3",
91
- "@types/text-encoding": "^0.0.36",
92
90
  "@types/ws": "^8.5.4",
93
91
  "auto-bind": "^5.0.1",
94
92
  "eslint": "^8.3.0",
@@ -229,15 +229,8 @@ class Requester {
229
229
  signingNodeId: string | undefined,
230
230
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any -- LIG-3400 */
231
231
  ): Promise<Uint8Array> {
232
- let TextEncoderImpl;
233
- if (typeof TextEncoder === "undefined") {
234
- TextEncoderImpl = (await import("text-encoding")).TextEncoder;
235
- } else {
236
- TextEncoderImpl = TextEncoder;
237
- }
238
-
239
232
  if (!signingNodeId) {
240
- return new TextEncoderImpl().encode(JSON.stringify(queryPayload));
233
+ return new TextEncoder().encode(JSON.stringify(queryPayload));
241
234
  }
242
235
 
243
236
  const query = queryPayload.query;
@@ -262,9 +255,7 @@ class Requester {
262
255
  );
263
256
  }
264
257
 
265
- const encodedPayload = new TextEncoderImpl().encode(
266
- JSON.stringify(payload),
267
- );
258
+ const encodedPayload = new TextEncoder().encode(JSON.stringify(payload));
268
259
 
269
260
  const signedPayload = await key.sign(encodedPayload);
270
261
 
@@ -15,10 +15,11 @@ export const CurrencyUnit = {
15
15
  BITCOIN: "BITCOIN",
16
16
  SATOSHI: "SATOSHI",
17
17
  MILLISATOSHI: "MILLISATOSHI",
18
- USD: "USD",
19
18
  NANOBITCOIN: "NANOBITCOIN",
20
19
  MICROBITCOIN: "MICROBITCOIN",
21
20
  MILLIBITCOIN: "MILLIBITCOIN",
21
+ USD: "USD",
22
+ MXN: "MXN",
22
23
 
23
24
  Bitcoin: "BITCOIN",
24
25
  Microbitcoin: "MICROBITCOIN",
@@ -27,6 +28,7 @@ export const CurrencyUnit = {
27
28
  Nanobitcoin: "NANOBITCOIN",
28
29
  Satoshi: "SATOSHI",
29
30
  Usd: "USD",
31
+ Mxn: "MXN",
30
32
  } as const;
31
33
 
32
34
  export type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
@@ -39,6 +41,37 @@ export type SDKCurrencyAmountType = {
39
41
  preferredCurrencyValueApprox: number;
40
42
  };
41
43
 
44
+ const standardUnitConversionObj = {
45
+ [CurrencyUnit.BITCOIN]: (v: number, unitsPerBtc = 1) => v / unitsPerBtc,
46
+ [CurrencyUnit.MICROBITCOIN]: (v: number, unitsPerBtc = 1) =>
47
+ (v / unitsPerBtc) * 1_000_000,
48
+ [CurrencyUnit.MILLIBITCOIN]: (v: number, unitsPerBtc = 1) =>
49
+ (v / unitsPerBtc) * 1_000,
50
+ [CurrencyUnit.MILLISATOSHI]: (v: number, unitsPerBtc = 1) =>
51
+ (v / unitsPerBtc) * 100_000_000_000,
52
+ [CurrencyUnit.NANOBITCOIN]: (v: number, unitsPerBtc = 1) =>
53
+ (v / unitsPerBtc) * 1_000_000_000,
54
+ [CurrencyUnit.SATOSHI]: (v: number, unitsPerBtc = 1) =>
55
+ (v / unitsPerBtc) * 100_000_000,
56
+ /* Converting between two different fiat types is not currently supported */
57
+ [CurrencyUnit.USD]: (v: number) => v,
58
+ [CurrencyUnit.MXN]: (v: number) => v,
59
+ };
60
+
61
+ /* Round without decimals since we're returning cents: */
62
+ const toBitcoinConversion = (v: number, unitsPerBtc = 1) =>
63
+ round(v * unitsPerBtc);
64
+ const toMicrobitcoinConversion = (v: number, unitsPerBtc = 1) =>
65
+ round((v / 1_000_000) * unitsPerBtc);
66
+ const toMillibitcoinConversion = (v: number, unitsPerBtc = 1) =>
67
+ round((v / 1_000) * unitsPerBtc);
68
+ const toMillisatoshiConversion = (v: number, unitsPerBtc = 1) =>
69
+ round((v / 100_000_000_000) * unitsPerBtc);
70
+ const toNanobitcoinConversion = (v: number, unitsPerBtc = 1) =>
71
+ round((v / 1_000_000_000) * unitsPerBtc);
72
+ const toSatoshiConversion = (v: number, unitsPerBtc = 1) =>
73
+ round((v / 100_000_000) * unitsPerBtc);
74
+
42
75
  const CONVERSION_MAP = {
43
76
  [CurrencyUnit.BITCOIN]: {
44
77
  [CurrencyUnit.BITCOIN]: (v: number) => v,
@@ -47,9 +80,8 @@ const CONVERSION_MAP = {
47
80
  [CurrencyUnit.MILLISATOSHI]: (v: number) => v * 100_000_000_000,
48
81
  [CurrencyUnit.NANOBITCOIN]: (v: number) => v * 1_000_000_000,
49
82
  [CurrencyUnit.SATOSHI]: (v: number) => v * 100_000_000,
50
- [CurrencyUnit.USD]: (v: number, centsPerBtc = 1) =>
51
- /* Round without decimals since we're returning cents: */
52
- round(v * centsPerBtc, 2),
83
+ [CurrencyUnit.USD]: toBitcoinConversion,
84
+ [CurrencyUnit.MXN]: toBitcoinConversion,
53
85
  },
54
86
  [CurrencyUnit.MICROBITCOIN]: {
55
87
  [CurrencyUnit.BITCOIN]: (v: number) => v / 1_000_000,
@@ -58,9 +90,8 @@ const CONVERSION_MAP = {
58
90
  [CurrencyUnit.MILLISATOSHI]: (v: number) => v * 100_000,
59
91
  [CurrencyUnit.NANOBITCOIN]: (v: number) => v * 1000,
60
92
  [CurrencyUnit.SATOSHI]: (v: number) => v * 100,
61
- [CurrencyUnit.USD]: (v: number, centsPerBtc = 1) =>
62
- /* Round without decimals since we're returning cents: */
63
- round((v / 1_000_000) * centsPerBtc),
93
+ [CurrencyUnit.USD]: toMicrobitcoinConversion,
94
+ [CurrencyUnit.MXN]: toMicrobitcoinConversion,
64
95
  },
65
96
  [CurrencyUnit.MILLIBITCOIN]: {
66
97
  [CurrencyUnit.BITCOIN]: (v: number) => v / 1_000,
@@ -69,9 +100,8 @@ const CONVERSION_MAP = {
69
100
  [CurrencyUnit.MILLISATOSHI]: (v: number) => v * 100_000_000,
70
101
  [CurrencyUnit.NANOBITCOIN]: (v: number) => v * 1_000_000,
71
102
  [CurrencyUnit.SATOSHI]: (v: number) => v * 100_000,
72
- [CurrencyUnit.USD]: (v: number, centsPerBtc = 1) =>
73
- /* Round without decimals since we're returning cents: */
74
- round((v / 1_000) * centsPerBtc),
103
+ [CurrencyUnit.USD]: toMillibitcoinConversion,
104
+ [CurrencyUnit.MXN]: toMillibitcoinConversion,
75
105
  },
76
106
  [CurrencyUnit.MILLISATOSHI]: {
77
107
  [CurrencyUnit.BITCOIN]: (v: number) => v / 100_000_000_000,
@@ -80,9 +110,8 @@ const CONVERSION_MAP = {
80
110
  [CurrencyUnit.MILLISATOSHI]: (v: number) => v,
81
111
  [CurrencyUnit.NANOBITCOIN]: (v: number) => v / 100,
82
112
  [CurrencyUnit.SATOSHI]: (v: number) => v / 1000,
83
- [CurrencyUnit.USD]: (v: number, centsPerBtc = 1) =>
84
- /* Round without decimals since we're returning cents: */
85
- round((v / 100_000_000_000) * centsPerBtc),
113
+ [CurrencyUnit.USD]: toMillisatoshiConversion,
114
+ [CurrencyUnit.MXN]: toMillisatoshiConversion,
86
115
  },
87
116
  [CurrencyUnit.NANOBITCOIN]: {
88
117
  [CurrencyUnit.BITCOIN]: (v: number) => v / 1_000_000_000,
@@ -91,9 +120,8 @@ const CONVERSION_MAP = {
91
120
  [CurrencyUnit.MILLISATOSHI]: (v: number) => v * 100,
92
121
  [CurrencyUnit.NANOBITCOIN]: (v: number) => v,
93
122
  [CurrencyUnit.SATOSHI]: (v: number) => v / 10,
94
- [CurrencyUnit.USD]: (v: number, centsPerBtc = 1) =>
95
- /* Round without decimals since we're returning cents: */
96
- round((v / 1_000_000_000) * centsPerBtc),
123
+ [CurrencyUnit.USD]: toNanobitcoinConversion,
124
+ [CurrencyUnit.MXN]: toNanobitcoinConversion,
97
125
  },
98
126
  [CurrencyUnit.SATOSHI]: {
99
127
  [CurrencyUnit.BITCOIN]: (v: number) => v / 100_000_000,
@@ -102,31 +130,22 @@ const CONVERSION_MAP = {
102
130
  [CurrencyUnit.MILLISATOSHI]: (v: number) => v * 1000,
103
131
  [CurrencyUnit.NANOBITCOIN]: (v: number) => v * 10,
104
132
  [CurrencyUnit.SATOSHI]: (v: number) => v,
105
- [CurrencyUnit.USD]: (v: number, centsPerBtc = 1) =>
106
- /* Round without decimals since we're returning cents: */
107
- round((v / 100_000_000) * centsPerBtc),
108
- },
109
- [CurrencyUnit.USD]: {
110
- [CurrencyUnit.BITCOIN]: (v: number, centsPerBtc = 1) => v / centsPerBtc,
111
- [CurrencyUnit.MICROBITCOIN]: (v: number, centsPerBtc = 1) =>
112
- (v / centsPerBtc) * 1_000_000,
113
- [CurrencyUnit.MILLIBITCOIN]: (v: number, centsPerBtc = 1) =>
114
- (v / centsPerBtc) * 1_000,
115
- [CurrencyUnit.MILLISATOSHI]: (v: number, centsPerBtc = 1) =>
116
- (v / centsPerBtc) * 100_000_000_000,
117
- [CurrencyUnit.NANOBITCOIN]: (v: number, centsPerBtc = 1) =>
118
- (v / centsPerBtc) * 1_000_000_000,
119
- [CurrencyUnit.SATOSHI]: (v: number, centsPerBtc = 1) =>
120
- (v / centsPerBtc) * 100_000_000,
121
- [CurrencyUnit.USD]: (v: number) => v,
133
+ [CurrencyUnit.USD]: toSatoshiConversion,
134
+ [CurrencyUnit.MXN]: toSatoshiConversion,
122
135
  },
136
+ [CurrencyUnit.USD]: standardUnitConversionObj,
137
+ [CurrencyUnit.MXN]: standardUnitConversionObj,
123
138
  };
124
139
 
125
140
  export function convertCurrencyAmountValue(
126
141
  fromUnit: CurrencyUnitType,
127
142
  toUnit: CurrencyUnitType,
128
143
  amount: number,
129
- centsPerBtc = 1,
144
+ /* Currency values are expected to always be provided in whole numbers of their smallest unit
145
+ e.g. $50.11 would be 5011. unitsPerBtc is the approximate value of one BTC in smallest
146
+ units to provide value estimates where needed where a backend value is not available, eg
147
+ previewing the approximate value of an amount to send. */
148
+ unitsPerBtc = 1,
130
149
  ): number {
131
150
  if (
132
151
  fromUnit === CurrencyUnit.FUTURE_VALUE ||
@@ -147,7 +166,7 @@ export function convertCurrencyAmountValue(
147
166
  );
148
167
  }
149
168
 
150
- return conversionFn(amount, centsPerBtc);
169
+ return conversionFn(amount, unitsPerBtc);
151
170
  }
152
171
 
153
172
  export const convertCurrencyAmount = (
@@ -178,6 +197,7 @@ export type CurrencyMap = {
178
197
  [CurrencyUnit.MILLIBITCOIN]: number;
179
198
  [CurrencyUnit.NANOBITCOIN]: number;
180
199
  [CurrencyUnit.USD]: number;
200
+ [CurrencyUnit.MXN]: number;
181
201
  [CurrencyUnit.FUTURE_VALUE]: number;
182
202
  formatted: {
183
203
  sats: string;
@@ -190,6 +210,7 @@ export type CurrencyMap = {
190
210
  [CurrencyUnit.MICROBITCOIN]: string;
191
211
  [CurrencyUnit.NANOBITCOIN]: string;
192
212
  [CurrencyUnit.USD]: string;
213
+ [CurrencyUnit.MXN]: string;
193
214
  [CurrencyUnit.FUTURE_VALUE]: string;
194
215
  };
195
216
  isZero: boolean;
@@ -309,24 +330,26 @@ function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg) {
309
330
 
310
331
  export function mapCurrencyAmount(
311
332
  currencyAmountArg: CurrencyAmountArg,
312
- centsPerBtc = 1,
333
+ unitsPerBtc = 1,
313
334
  ): CurrencyMap {
314
335
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
315
336
 
316
337
  const convert = convertCurrencyAmountValue;
317
- const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
318
- const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
319
- const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
320
- const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
321
- const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
322
- const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
323
- const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
338
+ const sats = convert(unit, CurrencyUnit.SATOSHI, value, unitsPerBtc);
339
+ const btc = convert(unit, CurrencyUnit.BITCOIN, value, unitsPerBtc);
340
+ const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, unitsPerBtc);
341
+ const usd = convert(unit, CurrencyUnit.USD, value, unitsPerBtc);
342
+ const mxn = convert(unit, CurrencyUnit.MXN, value, unitsPerBtc);
343
+ const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, unitsPerBtc);
344
+ const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, unitsPerBtc);
345
+ const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, unitsPerBtc);
324
346
 
325
347
  const mapWithCurrencyUnits = {
326
348
  [CurrencyUnit.BITCOIN]: btc,
327
349
  [CurrencyUnit.SATOSHI]: sats,
328
350
  [CurrencyUnit.MILLISATOSHI]: msats,
329
351
  [CurrencyUnit.USD]: usd,
352
+ [CurrencyUnit.MXN]: mxn,
330
353
  [CurrencyUnit.MICROBITCOIN]: mibtc,
331
354
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
332
355
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -360,6 +383,10 @@ export function mapCurrencyAmount(
360
383
  value: usd,
361
384
  unit: CurrencyUnit.USD,
362
385
  }),
386
+ [CurrencyUnit.MXN]: formatCurrencyStr({
387
+ value: mxn,
388
+ unit: CurrencyUnit.MXN,
389
+ }),
363
390
  [CurrencyUnit.FUTURE_VALUE]: "-",
364
391
  },
365
392
  };
@@ -45,3 +45,13 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
45
45
 
46
46
  /* Opposite of Partial - make all keys required with NonNullable values */
47
47
  export type Complete<T> = { [P in keyof T]-?: NonNullable<T[P]> };
48
+
49
+ /**
50
+ * RequiredKeys utility extracts all the keys of T that are required.
51
+ * For each key K in T, it checks if Pick<T, K> extends {} (an empty object). If it does, that
52
+ * means K is optional; otherwise, it's required.
53
+ * The resulting type is a union of all required keys in T.
54
+ */
55
+ export type RequiredKeys<T> = {
56
+ [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
57
+ }[keyof T];