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