@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lightsparkdev/core
|
|
2
2
|
|
|
3
|
+
## 1.0.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- baeccd9: - Improve currency functions and types
|
|
8
|
+
|
|
9
|
+
## 1.0.21
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 15d0720: - Consolidate type utils from ui to core
|
|
14
|
+
- 15d0720: - Use 64 bit nonces
|
|
15
|
+
|
|
3
16
|
## 1.0.20
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -392,102 +392,108 @@ function isNumber(value) {
|
|
|
392
392
|
|
|
393
393
|
// src/utils/currency.ts
|
|
394
394
|
var defaultCurrencyCode = "USD";
|
|
395
|
-
var CurrencyUnit =
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
395
|
+
var CurrencyUnit = {
|
|
396
|
+
FUTURE_VALUE: "FUTURE_VALUE",
|
|
397
|
+
BITCOIN: "BITCOIN",
|
|
398
|
+
SATOSHI: "SATOSHI",
|
|
399
|
+
MILLISATOSHI: "MILLISATOSHI",
|
|
400
|
+
USD: "USD",
|
|
401
|
+
NANOBITCOIN: "NANOBITCOIN",
|
|
402
|
+
MICROBITCOIN: "MICROBITCOIN",
|
|
403
|
+
MILLIBITCOIN: "MILLIBITCOIN",
|
|
404
|
+
Bitcoin: "BITCOIN",
|
|
405
|
+
Microbitcoin: "MICROBITCOIN",
|
|
406
|
+
Millibitcoin: "MILLIBITCOIN",
|
|
407
|
+
Millisatoshi: "MILLISATOSHI",
|
|
408
|
+
Nanobitcoin: "NANOBITCOIN",
|
|
409
|
+
Satoshi: "SATOSHI",
|
|
410
|
+
Usd: "USD"
|
|
411
|
+
};
|
|
406
412
|
var CONVERSION_MAP = {
|
|
407
|
-
[
|
|
408
|
-
[
|
|
409
|
-
[
|
|
410
|
-
[
|
|
411
|
-
[
|
|
412
|
-
[
|
|
413
|
-
[
|
|
414
|
-
[
|
|
413
|
+
[CurrencyUnit.BITCOIN]: {
|
|
414
|
+
[CurrencyUnit.BITCOIN]: (v) => v,
|
|
415
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v * 1e6,
|
|
416
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v * 1e3,
|
|
417
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e11,
|
|
418
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
|
|
419
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 1e8,
|
|
420
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
415
421
|
/* Round without decimals since we're returning cents: */
|
|
416
422
|
round(v * centsPerBtc, 2)
|
|
417
423
|
)
|
|
418
424
|
},
|
|
419
|
-
[
|
|
420
|
-
[
|
|
421
|
-
[
|
|
422
|
-
[
|
|
423
|
-
[
|
|
424
|
-
[
|
|
425
|
-
[
|
|
426
|
-
[
|
|
425
|
+
[CurrencyUnit.MICROBITCOIN]: {
|
|
426
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e6,
|
|
427
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v,
|
|
428
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e3,
|
|
429
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e5,
|
|
430
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
|
|
431
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 100,
|
|
432
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
427
433
|
/* Round without decimals since we're returning cents: */
|
|
428
434
|
round(v / 1e6 * centsPerBtc)
|
|
429
435
|
)
|
|
430
436
|
},
|
|
431
|
-
[
|
|
432
|
-
[
|
|
433
|
-
[
|
|
434
|
-
[
|
|
435
|
-
[
|
|
436
|
-
[
|
|
437
|
-
[
|
|
438
|
-
[
|
|
437
|
+
[CurrencyUnit.MILLIBITCOIN]: {
|
|
438
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e3,
|
|
439
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v * 1e3,
|
|
440
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v,
|
|
441
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e8,
|
|
442
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
|
|
443
|
+
[CurrencyUnit.SATOSHI]: (v) => v * 1e5,
|
|
444
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
439
445
|
/* Round without decimals since we're returning cents: */
|
|
440
446
|
round(v / 1e3 * centsPerBtc)
|
|
441
447
|
)
|
|
442
448
|
},
|
|
443
|
-
[
|
|
444
|
-
[
|
|
445
|
-
[
|
|
446
|
-
[
|
|
447
|
-
[
|
|
448
|
-
[
|
|
449
|
-
[
|
|
450
|
-
[
|
|
449
|
+
[CurrencyUnit.MILLISATOSHI]: {
|
|
450
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e11,
|
|
451
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 1e5,
|
|
452
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e8,
|
|
453
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v,
|
|
454
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
|
|
455
|
+
[CurrencyUnit.SATOSHI]: (v) => v / 1e3,
|
|
456
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
451
457
|
/* Round without decimals since we're returning cents: */
|
|
452
458
|
round(v / 1e11 * centsPerBtc)
|
|
453
459
|
)
|
|
454
460
|
},
|
|
455
|
-
[
|
|
456
|
-
[
|
|
457
|
-
[
|
|
458
|
-
[
|
|
459
|
-
[
|
|
460
|
-
[
|
|
461
|
-
[
|
|
462
|
-
[
|
|
461
|
+
[CurrencyUnit.NANOBITCOIN]: {
|
|
462
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e9,
|
|
463
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 1e3,
|
|
464
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e6,
|
|
465
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 100,
|
|
466
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v,
|
|
467
|
+
[CurrencyUnit.SATOSHI]: (v) => v / 10,
|
|
468
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
463
469
|
/* Round without decimals since we're returning cents: */
|
|
464
470
|
round(v / 1e9 * centsPerBtc)
|
|
465
471
|
)
|
|
466
472
|
},
|
|
467
|
-
[
|
|
468
|
-
[
|
|
469
|
-
[
|
|
470
|
-
[
|
|
471
|
-
[
|
|
472
|
-
[
|
|
473
|
-
[
|
|
474
|
-
[
|
|
473
|
+
[CurrencyUnit.SATOSHI]: {
|
|
474
|
+
[CurrencyUnit.BITCOIN]: (v) => v / 1e8,
|
|
475
|
+
[CurrencyUnit.MICROBITCOIN]: (v) => v / 100,
|
|
476
|
+
[CurrencyUnit.MILLIBITCOIN]: (v) => v / 1e5,
|
|
477
|
+
[CurrencyUnit.MILLISATOSHI]: (v) => v * 1e3,
|
|
478
|
+
[CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
|
|
479
|
+
[CurrencyUnit.SATOSHI]: (v) => v,
|
|
480
|
+
[CurrencyUnit.USD]: (v, centsPerBtc = 1) => (
|
|
475
481
|
/* Round without decimals since we're returning cents: */
|
|
476
482
|
round(v / 1e8 * centsPerBtc)
|
|
477
483
|
)
|
|
478
484
|
},
|
|
479
|
-
[
|
|
480
|
-
[
|
|
481
|
-
[
|
|
482
|
-
[
|
|
483
|
-
[
|
|
484
|
-
[
|
|
485
|
-
[
|
|
486
|
-
[
|
|
485
|
+
[CurrencyUnit.USD]: {
|
|
486
|
+
[CurrencyUnit.BITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc,
|
|
487
|
+
[CurrencyUnit.MICROBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e6,
|
|
488
|
+
[CurrencyUnit.MILLIBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e3,
|
|
489
|
+
[CurrencyUnit.MILLISATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e11,
|
|
490
|
+
[CurrencyUnit.NANOBITCOIN]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e9,
|
|
491
|
+
[CurrencyUnit.SATOSHI]: (v, centsPerBtc = 1) => v / centsPerBtc * 1e8,
|
|
492
|
+
[CurrencyUnit.USD]: (v) => v
|
|
487
493
|
}
|
|
488
494
|
};
|
|
489
495
|
function convertCurrencyAmountValue(fromUnit, toUnit, amount, centsPerBtc = 1) {
|
|
490
|
-
if (fromUnit ===
|
|
496
|
+
if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
|
|
491
497
|
throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
|
|
492
498
|
}
|
|
493
499
|
if (fromUnit === toUnit) {
|
|
@@ -518,8 +524,9 @@ var convertCurrencyAmount = (from, toUnit) => {
|
|
|
518
524
|
function isCurrencyAmountObj(arg) {
|
|
519
525
|
return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
|
|
520
526
|
}
|
|
521
|
-
function
|
|
522
|
-
return typeof arg === "object" && arg !== null &&
|
|
527
|
+
function isSDKCurrencyAmount(arg) {
|
|
528
|
+
return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
|
|
529
|
+
"originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
|
|
523
530
|
}
|
|
524
531
|
function asNumber(value) {
|
|
525
532
|
if (typeof value === "string") {
|
|
@@ -530,67 +537,67 @@ function asNumber(value) {
|
|
|
530
537
|
function getCurrencyAmount(currencyAmountArg) {
|
|
531
538
|
let value = 0;
|
|
532
539
|
let unit = void 0;
|
|
533
|
-
if (
|
|
534
|
-
value = asNumber(currencyAmountArg.value);
|
|
535
|
-
unit = currencyAmountArg.unit;
|
|
536
|
-
} else if (isCurrencyAmount(currencyAmountArg)) {
|
|
540
|
+
if (isSDKCurrencyAmount(currencyAmountArg)) {
|
|
537
541
|
value = currencyAmountArg.originalValue;
|
|
538
542
|
unit = currencyAmountArg.originalUnit;
|
|
543
|
+
} else if (isCurrencyAmountObj(currencyAmountArg)) {
|
|
544
|
+
value = asNumber(currencyAmountArg.value);
|
|
545
|
+
unit = currencyAmountArg.unit;
|
|
539
546
|
}
|
|
540
547
|
return {
|
|
541
548
|
value: asNumber(value),
|
|
542
|
-
unit: unit ||
|
|
549
|
+
unit: unit || CurrencyUnit.SATOSHI
|
|
543
550
|
};
|
|
544
551
|
}
|
|
545
552
|
function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
546
553
|
const { value, unit } = getCurrencyAmount(currencyAmountArg);
|
|
547
554
|
const convert = convertCurrencyAmountValue;
|
|
548
|
-
const sats = convert(unit,
|
|
549
|
-
const btc = convert(unit,
|
|
550
|
-
const msats = convert(unit,
|
|
551
|
-
const usd = convert(unit,
|
|
552
|
-
const mibtc = convert(unit,
|
|
553
|
-
const mlbtc = convert(unit,
|
|
554
|
-
const nbtc = convert(unit,
|
|
555
|
+
const sats = convert(unit, CurrencyUnit.SATOSHI, value, centsPerBtc);
|
|
556
|
+
const btc = convert(unit, CurrencyUnit.BITCOIN, value, centsPerBtc);
|
|
557
|
+
const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, centsPerBtc);
|
|
558
|
+
const usd = convert(unit, CurrencyUnit.USD, value, centsPerBtc);
|
|
559
|
+
const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, centsPerBtc);
|
|
560
|
+
const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, centsPerBtc);
|
|
561
|
+
const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, centsPerBtc);
|
|
555
562
|
const mapWithCurrencyUnits = {
|
|
556
|
-
[
|
|
557
|
-
[
|
|
558
|
-
[
|
|
559
|
-
[
|
|
560
|
-
[
|
|
561
|
-
[
|
|
562
|
-
[
|
|
563
|
-
[
|
|
563
|
+
[CurrencyUnit.BITCOIN]: btc,
|
|
564
|
+
[CurrencyUnit.SATOSHI]: sats,
|
|
565
|
+
[CurrencyUnit.MILLISATOSHI]: msats,
|
|
566
|
+
[CurrencyUnit.USD]: usd,
|
|
567
|
+
[CurrencyUnit.MICROBITCOIN]: mibtc,
|
|
568
|
+
[CurrencyUnit.MILLIBITCOIN]: mlbtc,
|
|
569
|
+
[CurrencyUnit.NANOBITCOIN]: nbtc,
|
|
570
|
+
[CurrencyUnit.FUTURE_VALUE]: NaN,
|
|
564
571
|
formatted: {
|
|
565
|
-
[
|
|
572
|
+
[CurrencyUnit.BITCOIN]: formatCurrencyStr({
|
|
566
573
|
value: btc,
|
|
567
|
-
unit:
|
|
574
|
+
unit: CurrencyUnit.BITCOIN
|
|
568
575
|
}),
|
|
569
|
-
[
|
|
576
|
+
[CurrencyUnit.SATOSHI]: formatCurrencyStr({
|
|
570
577
|
value: sats,
|
|
571
|
-
unit:
|
|
578
|
+
unit: CurrencyUnit.SATOSHI
|
|
572
579
|
}),
|
|
573
|
-
[
|
|
580
|
+
[CurrencyUnit.MILLISATOSHI]: formatCurrencyStr({
|
|
574
581
|
value: msats,
|
|
575
|
-
unit:
|
|
582
|
+
unit: CurrencyUnit.MILLISATOSHI
|
|
576
583
|
}),
|
|
577
|
-
[
|
|
584
|
+
[CurrencyUnit.MICROBITCOIN]: formatCurrencyStr({
|
|
578
585
|
value: mibtc,
|
|
579
|
-
unit:
|
|
586
|
+
unit: CurrencyUnit.MICROBITCOIN
|
|
580
587
|
}),
|
|
581
|
-
[
|
|
588
|
+
[CurrencyUnit.MILLIBITCOIN]: formatCurrencyStr({
|
|
582
589
|
value: mlbtc,
|
|
583
|
-
unit:
|
|
590
|
+
unit: CurrencyUnit.MILLIBITCOIN
|
|
584
591
|
}),
|
|
585
|
-
[
|
|
592
|
+
[CurrencyUnit.NANOBITCOIN]: formatCurrencyStr({
|
|
586
593
|
value: nbtc,
|
|
587
|
-
unit:
|
|
594
|
+
unit: CurrencyUnit.NANOBITCOIN
|
|
588
595
|
}),
|
|
589
|
-
[
|
|
596
|
+
[CurrencyUnit.USD]: formatCurrencyStr({
|
|
590
597
|
value: usd,
|
|
591
|
-
unit:
|
|
598
|
+
unit: CurrencyUnit.USD
|
|
592
599
|
}),
|
|
593
|
-
[
|
|
600
|
+
[CurrencyUnit.FUTURE_VALUE]: "-"
|
|
594
601
|
}
|
|
595
602
|
};
|
|
596
603
|
return {
|
|
@@ -628,9 +635,9 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
|
628
635
|
},
|
|
629
636
|
formatted: {
|
|
630
637
|
...mapWithCurrencyUnits.formatted,
|
|
631
|
-
btc: mapWithCurrencyUnits.formatted[
|
|
632
|
-
sats: mapWithCurrencyUnits.formatted[
|
|
633
|
-
msats: mapWithCurrencyUnits.formatted[
|
|
638
|
+
btc: mapWithCurrencyUnits.formatted[CurrencyUnit.BITCOIN],
|
|
639
|
+
sats: mapWithCurrencyUnits.formatted[CurrencyUnit.SATOSHI],
|
|
640
|
+
msats: mapWithCurrencyUnits.formatted[CurrencyUnit.MILLISATOSHI]
|
|
634
641
|
},
|
|
635
642
|
type: "CurrencyMap"
|
|
636
643
|
};
|
|
@@ -638,13 +645,13 @@ function mapCurrencyAmount(currencyAmountArg, centsPerBtc = 1) {
|
|
|
638
645
|
var isCurrencyMap = (currencyMap) => typeof currencyMap === "object" && currencyMap !== null && "type" in currencyMap && typeof currencyMap.type === "string" && currencyMap.type === "CurrencyMap";
|
|
639
646
|
var abbrCurrencyUnit = (unit) => {
|
|
640
647
|
switch (unit) {
|
|
641
|
-
case
|
|
648
|
+
case CurrencyUnit.BITCOIN:
|
|
642
649
|
return "BTC";
|
|
643
|
-
case
|
|
650
|
+
case CurrencyUnit.SATOSHI:
|
|
644
651
|
return "SAT";
|
|
645
|
-
case
|
|
652
|
+
case CurrencyUnit.MILLISATOSHI:
|
|
646
653
|
return "MSAT";
|
|
647
|
-
case
|
|
654
|
+
case CurrencyUnit.USD:
|
|
648
655
|
return "USD";
|
|
649
656
|
}
|
|
650
657
|
return "Unsupported CurrencyUnit";
|
|
@@ -653,33 +660,33 @@ function formatCurrencyStr(amount, maxFractionDigits, compact, showBtcSymbol = f
|
|
|
653
660
|
const currencyAmount = getCurrencyAmount(amount);
|
|
654
661
|
let { value: num } = currencyAmount;
|
|
655
662
|
const { unit } = currencyAmount;
|
|
656
|
-
if (unit ===
|
|
663
|
+
if (unit === CurrencyUnit.USD) {
|
|
657
664
|
num = num / 100;
|
|
658
665
|
}
|
|
659
666
|
function getDefaultMaxFractionDigits(defaultDigits) {
|
|
660
667
|
return typeof maxFractionDigits === "undefined" ? compact ? 1 : defaultDigits : maxFractionDigits;
|
|
661
668
|
}
|
|
662
|
-
const symbol = !showBtcSymbol ? "" : unit ===
|
|
669
|
+
const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
|
|
663
670
|
const currentLocale = getCurrentLocale();
|
|
664
671
|
switch (unit) {
|
|
665
|
-
case
|
|
672
|
+
case CurrencyUnit.BITCOIN:
|
|
666
673
|
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
667
674
|
notation: compact ? "compact" : void 0,
|
|
668
675
|
maximumFractionDigits: getDefaultMaxFractionDigits(4),
|
|
669
676
|
...options
|
|
670
677
|
})}`;
|
|
671
|
-
case
|
|
672
|
-
case
|
|
673
|
-
case
|
|
674
|
-
case
|
|
675
|
-
case
|
|
678
|
+
case CurrencyUnit.MILLISATOSHI:
|
|
679
|
+
case CurrencyUnit.SATOSHI:
|
|
680
|
+
case CurrencyUnit.MICROBITCOIN:
|
|
681
|
+
case CurrencyUnit.MILLIBITCOIN:
|
|
682
|
+
case CurrencyUnit.NANOBITCOIN:
|
|
676
683
|
default:
|
|
677
684
|
return `${symbol}${num.toLocaleString(currentLocale, {
|
|
678
685
|
notation: compact ? "compact" : void 0,
|
|
679
686
|
maximumFractionDigits: getDefaultMaxFractionDigits(0),
|
|
680
687
|
...options
|
|
681
688
|
})}`;
|
|
682
|
-
case
|
|
689
|
+
case CurrencyUnit.USD:
|
|
683
690
|
return num.toLocaleString(currentLocale, {
|
|
684
691
|
style: "currency",
|
|
685
692
|
currency: defaultCurrencyCode,
|
|
@@ -903,6 +910,9 @@ function isUint8Array(variable) {
|
|
|
903
910
|
var isType = (typename) => (node) => {
|
|
904
911
|
return node?.__typename === typename;
|
|
905
912
|
};
|
|
913
|
+
function notNullUndefined(value) {
|
|
914
|
+
return value !== null && value !== void 0;
|
|
915
|
+
}
|
|
906
916
|
|
|
907
917
|
export {
|
|
908
918
|
LightsparkException_default,
|
|
@@ -927,7 +937,7 @@ export {
|
|
|
927
937
|
convertCurrencyAmountValue,
|
|
928
938
|
convertCurrencyAmount,
|
|
929
939
|
isCurrencyAmountObj,
|
|
930
|
-
|
|
940
|
+
isSDKCurrencyAmount,
|
|
931
941
|
mapCurrencyAmount,
|
|
932
942
|
isCurrencyMap,
|
|
933
943
|
abbrCurrencyUnit,
|
|
@@ -947,7 +957,8 @@ export {
|
|
|
947
957
|
pollUntil,
|
|
948
958
|
lsidToUUID,
|
|
949
959
|
isUint8Array,
|
|
950
|
-
isType
|
|
960
|
+
isType,
|
|
961
|
+
notNullUndefined
|
|
951
962
|
};
|
|
952
963
|
/*! Bundled license information:
|
|
953
964
|
|
|
@@ -13,78 +13,33 @@ declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
|
|
|
13
13
|
declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
|
|
14
14
|
|
|
15
15
|
declare const defaultCurrencyCode = "USD";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* This is the unit most commonly used in Lightning transactions.
|
|
36
|
-
* *
|
|
37
|
-
*/
|
|
38
|
-
SATOSHI = "SATOSHI",
|
|
39
|
-
/**
|
|
40
|
-
* 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
|
|
41
|
-
* instead when possible. *
|
|
42
|
-
*/
|
|
43
|
-
MILLISATOSHI = "MILLISATOSHI",
|
|
44
|
-
/** United States Dollar. **/
|
|
45
|
-
USD = "USD",
|
|
46
|
-
/**
|
|
47
|
-
* 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
|
|
48
|
-
* We recommend using the Satoshi unit instead when possible.
|
|
49
|
-
* *
|
|
50
|
-
*/
|
|
51
|
-
NANOBITCOIN = "NANOBITCOIN",
|
|
52
|
-
/**
|
|
53
|
-
* 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
|
|
54
|
-
* We recommend using the Satoshi unit instead when possible.
|
|
55
|
-
* *
|
|
56
|
-
*/
|
|
57
|
-
MICROBITCOIN = "MICROBITCOIN",
|
|
58
|
-
/**
|
|
59
|
-
* 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
|
|
60
|
-
* We recommend using the Satoshi unit instead when possible.
|
|
61
|
-
* *
|
|
62
|
-
*/
|
|
63
|
-
MILLIBITCOIN = "MILLIBITCOIN"
|
|
64
|
-
}
|
|
65
|
-
/** This object represents the value and unit for an amount of currency. **/
|
|
66
|
-
type CurrencyAmountType = {
|
|
67
|
-
/** The original numeric value for this CurrencyAmount. **/
|
|
16
|
+
declare const CurrencyUnit: {
|
|
17
|
+
readonly FUTURE_VALUE: "FUTURE_VALUE";
|
|
18
|
+
readonly BITCOIN: "BITCOIN";
|
|
19
|
+
readonly SATOSHI: "SATOSHI";
|
|
20
|
+
readonly MILLISATOSHI: "MILLISATOSHI";
|
|
21
|
+
readonly USD: "USD";
|
|
22
|
+
readonly NANOBITCOIN: "NANOBITCOIN";
|
|
23
|
+
readonly MICROBITCOIN: "MICROBITCOIN";
|
|
24
|
+
readonly MILLIBITCOIN: "MILLIBITCOIN";
|
|
25
|
+
readonly Bitcoin: "BITCOIN";
|
|
26
|
+
readonly Microbitcoin: "MICROBITCOIN";
|
|
27
|
+
readonly Millibitcoin: "MILLIBITCOIN";
|
|
28
|
+
readonly Millisatoshi: "MILLISATOSHI";
|
|
29
|
+
readonly Nanobitcoin: "NANOBITCOIN";
|
|
30
|
+
readonly Satoshi: "SATOSHI";
|
|
31
|
+
readonly Usd: "USD";
|
|
32
|
+
};
|
|
33
|
+
type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
|
|
34
|
+
type SDKCurrencyAmountType = {
|
|
68
35
|
originalValue: number;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/** The unit of user's preferred currency. **/
|
|
72
|
-
preferredCurrencyUnit: CurrencyUnit;
|
|
73
|
-
/**
|
|
74
|
-
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
75
|
-
* of user's preferred currency. For example, for USD, the value will be in
|
|
76
|
-
* cents.
|
|
77
|
-
**/
|
|
36
|
+
originalUnit: CurrencyUnitType;
|
|
37
|
+
preferredCurrencyUnit: CurrencyUnitType;
|
|
78
38
|
preferredCurrencyValueRounded: number;
|
|
79
|
-
/**
|
|
80
|
-
* The approximate float value for this CurrencyAmount in the very base level
|
|
81
|
-
* of user's preferred currency. For example, for USD, the value will be in
|
|
82
|
-
* cents.
|
|
83
|
-
**/
|
|
84
39
|
preferredCurrencyValueApprox: number;
|
|
85
40
|
};
|
|
86
|
-
declare function convertCurrencyAmountValue(fromUnit:
|
|
87
|
-
declare const convertCurrencyAmount: (from:
|
|
41
|
+
declare function convertCurrencyAmountValue(fromUnit: CurrencyUnitType, toUnit: CurrencyUnitType, amount: number, centsPerBtc?: number): number;
|
|
42
|
+
declare const convertCurrencyAmount: (from: SDKCurrencyAmountType, toUnit: CurrencyUnitType) => SDKCurrencyAmountType;
|
|
88
43
|
type CurrencyMap = {
|
|
89
44
|
sats: number;
|
|
90
45
|
msats: number;
|
|
@@ -118,15 +73,15 @@ type CurrencyMap = {
|
|
|
118
73
|
};
|
|
119
74
|
type CurrencyAmountObj = {
|
|
120
75
|
value?: number | string | null;
|
|
121
|
-
unit?:
|
|
122
|
-
__typename?: "CurrencyAmount";
|
|
76
|
+
unit?: CurrencyUnitType;
|
|
77
|
+
__typename?: "CurrencyAmount" | undefined;
|
|
123
78
|
};
|
|
124
|
-
type CurrencyAmountArg = CurrencyAmountObj |
|
|
79
|
+
type CurrencyAmountArg = CurrencyAmountObj | SDKCurrencyAmountType | undefined | null;
|
|
125
80
|
declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
|
|
126
|
-
declare function
|
|
81
|
+
declare function isSDKCurrencyAmount(arg: unknown): arg is SDKCurrencyAmountType;
|
|
127
82
|
declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
|
|
128
83
|
declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
|
|
129
|
-
declare const abbrCurrencyUnit: (unit:
|
|
84
|
+
declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
|
|
130
85
|
declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
|
|
131
86
|
declare function separateCurrencyStrParts(currencyStr: string): {
|
|
132
87
|
symbol: string;
|
|
@@ -162,6 +117,7 @@ type JSONObject = {
|
|
|
162
117
|
[key: string]: JSONType;
|
|
163
118
|
};
|
|
164
119
|
type NN<T> = NonNullable<T>;
|
|
120
|
+
declare function notNullUndefined<TValue>(value: TValue | null | undefined): value is TValue;
|
|
165
121
|
|
|
166
122
|
declare const isError: (e: unknown) => e is Error;
|
|
167
123
|
type ErrorWithMessage = {
|
|
@@ -273,4 +229,4 @@ declare function lsidToUUID(lsid: string): string;
|
|
|
273
229
|
|
|
274
230
|
declare function isUint8Array(variable: unknown): variable is Uint8Array;
|
|
275
231
|
|
|
276
|
-
export {
|
|
232
|
+
export { isType as $, isErrorMsg as A, errorToJSON as B, ConfigKeys as C, bytesToHex as D, hexToBytes as E, getLocalStorageConfigItem as F, getLocalStorageBoolean as G, setLocalStorageBoolean as H, deleteLocalStorageItem as I, getCurrentLocale as J, countryCodesToCurrencyCodes as K, CurrencyLocales as L, CurrencyCodes as M, localeToCurrencyCode as N, clamp as O, linearInterpolate as P, round as Q, isNumber as R, SDKCurrencyAmountType as S, pollUntil as T, sleep as U, lsidToUUID as V, isUint8Array as W, Maybe as X, ExpandRecursively as Y, ById as Z, OmitTypename as _, b64encode as a, DeepPartial as a0, JSONLiteral as a1, JSONType as a2, JSONObject as a3, NN as a4, notNullUndefined as a5, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyUnitType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isSDKCurrencyAmount as m, mapCurrencyAmount as n, isCurrencyMap as o, abbrCurrencyUnit as p, formatCurrencyStr as q, localeToCurrencySymbol as r, separateCurrencyStrParts as s, isBrowser as t, urlsafe_b64decode as u, isNode as v, isTest as w, isError as x, isErrorWithMessage as y, getErrorMsg as z };
|