@lightsparkdev/core 1.0.3 → 1.0.4
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 +7 -0
- package/dist/chunk-J6VQYCQJ.js +338 -0
- package/dist/index.cjs +273 -129
- package/dist/index.d.ts +2 -77
- package/dist/index.js +27 -185
- package/dist/utils/index.cjs +389 -0
- package/dist/utils/index.d.ts +88 -0
- package/dist/utils/index.js +38 -0
- package/package.json +16 -2
- package/src/Logger.ts +3 -1
- package/src/crypto/SigningKey.ts +2 -6
- package/src/requester/Requester.ts +2 -2
- package/src/utils/environment.ts +2 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/pollUntil.ts +54 -0
- package/src/utils/sleep.ts +3 -0
package/dist/index.cjs
CHANGED
|
@@ -57,7 +57,10 @@ __export(src_exports, {
|
|
|
57
57
|
isErrorMsg: () => isErrorMsg,
|
|
58
58
|
isErrorWithMessage: () => isErrorWithMessage,
|
|
59
59
|
isNode: () => isNode,
|
|
60
|
+
isTest: () => isTest,
|
|
60
61
|
isType: () => isType,
|
|
62
|
+
pollUntil: () => pollUntil,
|
|
63
|
+
sleep: () => sleep,
|
|
61
64
|
urlsafe_b64decode: () => urlsafe_b64decode
|
|
62
65
|
});
|
|
63
66
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -363,6 +366,256 @@ var import_auto_bind = __toESM(require("auto-bind"), 1);
|
|
|
363
366
|
|
|
364
367
|
// src/crypto/SigningKey.ts
|
|
365
368
|
var import_secp256k1 = __toESM(require("secp256k1"), 1);
|
|
369
|
+
|
|
370
|
+
// src/utils/environment.ts
|
|
371
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
372
|
+
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
373
|
+
var isTest = isNode && process.env.NODE_ENV === "test";
|
|
374
|
+
|
|
375
|
+
// src/utils/createHash.ts
|
|
376
|
+
var createSha256Hash = async (data) => {
|
|
377
|
+
if (isBrowser) {
|
|
378
|
+
return new Uint8Array(await window.crypto.subtle.digest("SHA-256", data));
|
|
379
|
+
} else {
|
|
380
|
+
const { createHash } = await import("crypto");
|
|
381
|
+
const buffer = createHash("sha256").update(data).digest();
|
|
382
|
+
return new Uint8Array(buffer);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/utils/currency.ts
|
|
387
|
+
var CONVERSION_MAP = {
|
|
388
|
+
["BITCOIN" /* BITCOIN */]: {
|
|
389
|
+
["BITCOIN" /* BITCOIN */]: (v) => v,
|
|
390
|
+
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e6,
|
|
391
|
+
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v * 1e3,
|
|
392
|
+
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e11,
|
|
393
|
+
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e9,
|
|
394
|
+
["SATOSHI" /* SATOSHI */]: (v) => v * 1e8
|
|
395
|
+
},
|
|
396
|
+
["MICROBITCOIN" /* MICROBITCOIN */]: {
|
|
397
|
+
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e6),
|
|
398
|
+
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v,
|
|
399
|
+
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e3),
|
|
400
|
+
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e5,
|
|
401
|
+
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e3,
|
|
402
|
+
["SATOSHI" /* SATOSHI */]: (v) => v * 100
|
|
403
|
+
},
|
|
404
|
+
["MILLIBITCOIN" /* MILLIBITCOIN */]: {
|
|
405
|
+
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e3),
|
|
406
|
+
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e3,
|
|
407
|
+
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v,
|
|
408
|
+
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e8,
|
|
409
|
+
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e6,
|
|
410
|
+
["SATOSHI" /* SATOSHI */]: (v) => v * 1e5
|
|
411
|
+
},
|
|
412
|
+
["MILLISATOSHI" /* MILLISATOSHI */]: {
|
|
413
|
+
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e11),
|
|
414
|
+
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 1e5),
|
|
415
|
+
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e8),
|
|
416
|
+
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v,
|
|
417
|
+
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => Math.round(v / 100),
|
|
418
|
+
["SATOSHI" /* SATOSHI */]: (v) => Math.round(v / 1e3)
|
|
419
|
+
},
|
|
420
|
+
["NANOBITCOIN" /* NANOBITCOIN */]: {
|
|
421
|
+
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e9),
|
|
422
|
+
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 1e3),
|
|
423
|
+
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e6),
|
|
424
|
+
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 100,
|
|
425
|
+
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v,
|
|
426
|
+
["SATOSHI" /* SATOSHI */]: (v) => Math.round(v / 10)
|
|
427
|
+
},
|
|
428
|
+
["SATOSHI" /* SATOSHI */]: {
|
|
429
|
+
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e8),
|
|
430
|
+
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 100),
|
|
431
|
+
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e5),
|
|
432
|
+
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e3,
|
|
433
|
+
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 10,
|
|
434
|
+
["SATOSHI" /* SATOSHI */]: (v) => v
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
var convertCurrencyAmount = (from, toUnit) => {
|
|
438
|
+
if (from.originalUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || from.originalUnit === "USD" /* USD */ || toUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || toUnit === "USD" /* USD */) {
|
|
439
|
+
throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
|
|
440
|
+
}
|
|
441
|
+
const conversionFn = CONVERSION_MAP[from.originalUnit][toUnit];
|
|
442
|
+
if (!conversionFn) {
|
|
443
|
+
throw new LightsparkException_default(
|
|
444
|
+
"CurrencyError",
|
|
445
|
+
`Cannot convert from ${from.originalUnit} to ${toUnit}`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
...from,
|
|
450
|
+
preferredCurrencyUnit: toUnit,
|
|
451
|
+
preferredCurrencyValueApprox: conversionFn(from.originalValue),
|
|
452
|
+
preferredCurrencyValueRounded: conversionFn(from.originalValue)
|
|
453
|
+
};
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
// src/utils/errors.ts
|
|
457
|
+
var isError = (e) => {
|
|
458
|
+
return Boolean(
|
|
459
|
+
typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string" && "stack" in e && (!e.stack || typeof e.stack === "string")
|
|
460
|
+
);
|
|
461
|
+
};
|
|
462
|
+
var isErrorWithMessage = (e) => {
|
|
463
|
+
return Boolean(
|
|
464
|
+
typeof e === "object" && e !== null && "message" in e && typeof e.message === "string"
|
|
465
|
+
);
|
|
466
|
+
};
|
|
467
|
+
var getErrorMsg = (e) => {
|
|
468
|
+
return isErrorWithMessage(e) ? e.message : "Unknown error";
|
|
469
|
+
};
|
|
470
|
+
var isErrorMsg = (e, msg) => {
|
|
471
|
+
if (isError(e)) {
|
|
472
|
+
return e.message === msg;
|
|
473
|
+
}
|
|
474
|
+
return false;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
// src/utils/hex.ts
|
|
478
|
+
var bytesToHex = (bytes) => {
|
|
479
|
+
return bytes.reduce((acc, byte) => {
|
|
480
|
+
return acc += ("0" + byte.toString(16)).slice(-2);
|
|
481
|
+
}, "");
|
|
482
|
+
};
|
|
483
|
+
var hexToBytes = (hex) => {
|
|
484
|
+
const bytes = [];
|
|
485
|
+
for (let c = 0; c < hex.length; c += 2) {
|
|
486
|
+
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
487
|
+
}
|
|
488
|
+
return Uint8Array.from(bytes);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
492
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
493
|
+
var freeGlobal_default = freeGlobal;
|
|
494
|
+
|
|
495
|
+
// ../../node_modules/lodash-es/_root.js
|
|
496
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
497
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
498
|
+
var root_default = root;
|
|
499
|
+
|
|
500
|
+
// ../../node_modules/lodash-es/_Symbol.js
|
|
501
|
+
var Symbol2 = root_default.Symbol;
|
|
502
|
+
var Symbol_default = Symbol2;
|
|
503
|
+
|
|
504
|
+
// ../../node_modules/lodash-es/_getRawTag.js
|
|
505
|
+
var objectProto = Object.prototype;
|
|
506
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
507
|
+
var nativeObjectToString = objectProto.toString;
|
|
508
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
509
|
+
function getRawTag(value) {
|
|
510
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
511
|
+
try {
|
|
512
|
+
value[symToStringTag] = void 0;
|
|
513
|
+
var unmasked = true;
|
|
514
|
+
} catch (e) {
|
|
515
|
+
}
|
|
516
|
+
var result = nativeObjectToString.call(value);
|
|
517
|
+
if (unmasked) {
|
|
518
|
+
if (isOwn) {
|
|
519
|
+
value[symToStringTag] = tag;
|
|
520
|
+
} else {
|
|
521
|
+
delete value[symToStringTag];
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return result;
|
|
525
|
+
}
|
|
526
|
+
var getRawTag_default = getRawTag;
|
|
527
|
+
|
|
528
|
+
// ../../node_modules/lodash-es/_objectToString.js
|
|
529
|
+
var objectProto2 = Object.prototype;
|
|
530
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
531
|
+
function objectToString(value) {
|
|
532
|
+
return nativeObjectToString2.call(value);
|
|
533
|
+
}
|
|
534
|
+
var objectToString_default = objectToString;
|
|
535
|
+
|
|
536
|
+
// ../../node_modules/lodash-es/_baseGetTag.js
|
|
537
|
+
var nullTag = "[object Null]";
|
|
538
|
+
var undefinedTag = "[object Undefined]";
|
|
539
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
540
|
+
function baseGetTag(value) {
|
|
541
|
+
if (value == null) {
|
|
542
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
543
|
+
}
|
|
544
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
545
|
+
}
|
|
546
|
+
var baseGetTag_default = baseGetTag;
|
|
547
|
+
|
|
548
|
+
// ../../node_modules/lodash-es/isObject.js
|
|
549
|
+
function isObject(value) {
|
|
550
|
+
var type = typeof value;
|
|
551
|
+
return value != null && (type == "object" || type == "function");
|
|
552
|
+
}
|
|
553
|
+
var isObject_default = isObject;
|
|
554
|
+
|
|
555
|
+
// ../../node_modules/lodash-es/isFunction.js
|
|
556
|
+
var asyncTag = "[object AsyncFunction]";
|
|
557
|
+
var funcTag = "[object Function]";
|
|
558
|
+
var genTag = "[object GeneratorFunction]";
|
|
559
|
+
var proxyTag = "[object Proxy]";
|
|
560
|
+
function isFunction(value) {
|
|
561
|
+
if (!isObject_default(value)) {
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
var tag = baseGetTag_default(value);
|
|
565
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
566
|
+
}
|
|
567
|
+
var isFunction_default = isFunction;
|
|
568
|
+
|
|
569
|
+
// src/utils/sleep.ts
|
|
570
|
+
function sleep(ms) {
|
|
571
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/utils/pollUntil.ts
|
|
575
|
+
function getDefaultMaxPollsError() {
|
|
576
|
+
return new Error("pollUntil: Max polls reached");
|
|
577
|
+
}
|
|
578
|
+
function pollUntil(asyncFn, getValue, maxPolls = 60, pollIntervalMs = 500, ignoreErrors = false, getMaxPollsError = getDefaultMaxPollsError) {
|
|
579
|
+
return new Promise((resolve, reject) => {
|
|
580
|
+
let polls = 0;
|
|
581
|
+
let stopPolling = false;
|
|
582
|
+
(async function() {
|
|
583
|
+
while (!stopPolling) {
|
|
584
|
+
polls += 1;
|
|
585
|
+
if (polls > maxPolls) {
|
|
586
|
+
stopPolling = true;
|
|
587
|
+
const maxPollsError = getMaxPollsError(maxPolls);
|
|
588
|
+
reject(maxPollsError);
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
try {
|
|
592
|
+
const asyncResult = await asyncFn();
|
|
593
|
+
const result = getValue(asyncResult, {
|
|
594
|
+
stopPolling: false,
|
|
595
|
+
value: null
|
|
596
|
+
});
|
|
597
|
+
if (result.stopPolling) {
|
|
598
|
+
stopPolling = true;
|
|
599
|
+
resolve(result.value);
|
|
600
|
+
}
|
|
601
|
+
} catch (e) {
|
|
602
|
+
if (!ignoreErrors || isFunction_default(ignoreErrors) && !ignoreErrors(e)) {
|
|
603
|
+
stopPolling = true;
|
|
604
|
+
reject(e);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
await sleep(pollIntervalMs);
|
|
608
|
+
}
|
|
609
|
+
})();
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// src/utils/types.ts
|
|
614
|
+
var isType = (typename) => (node) => {
|
|
615
|
+
return node?.__typename === typename;
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// src/crypto/SigningKey.ts
|
|
366
619
|
function isAlias(key) {
|
|
367
620
|
return "alias" in key;
|
|
368
621
|
}
|
|
@@ -468,6 +721,8 @@ var Logger = class {
|
|
|
468
721
|
async updateLoggingEnabled(getLoggingEnabled) {
|
|
469
722
|
if (getLoggingEnabled) {
|
|
470
723
|
this.loggingEnabled = await getLoggingEnabled();
|
|
724
|
+
} else if (isTest) {
|
|
725
|
+
this.loggingEnabled = true;
|
|
471
726
|
} else if (isBrowser) {
|
|
472
727
|
try {
|
|
473
728
|
this.loggingEnabled = localStorage.getItem("lightspark-logging-enabled") === "1";
|
|
@@ -493,12 +748,6 @@ var import_utc = __toESM(require("dayjs/plugin/utc.js"), 1);
|
|
|
493
748
|
var import_graphql_ws = require("graphql-ws");
|
|
494
749
|
var import_ws = __toESM(require("ws"), 1);
|
|
495
750
|
var import_zen_observable_ts = require("zen-observable-ts");
|
|
496
|
-
|
|
497
|
-
// src/utils/environment.ts
|
|
498
|
-
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
499
|
-
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
500
|
-
|
|
501
|
-
// src/requester/Requester.ts
|
|
502
751
|
var DEFAULT_BASE_URL = "api.lightspark.com";
|
|
503
752
|
var LIGHTSPARK_BETA_HEADER_KEY = "X-Lightspark-Beta";
|
|
504
753
|
var LIGHTSPARK_BETA_HEADER_VALUE = "z2h0BBYxTA83cjW7fi8QwWtBPCzkQKiemcuhKY08LOo";
|
|
@@ -537,13 +786,14 @@ var Requester = class {
|
|
|
537
786
|
return query.constructObject(data);
|
|
538
787
|
}
|
|
539
788
|
subscribe(queryPayload, variables = {}) {
|
|
540
|
-
logger.info(`Requester.subscribe
|
|
789
|
+
logger.info(`Requester.subscribe variables`, variables);
|
|
541
790
|
const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
|
|
542
791
|
const operationMatch = queryPayload.match(operationNameRegex);
|
|
543
792
|
if (!operationMatch || operationMatch.length < 3) {
|
|
544
793
|
throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
|
|
545
794
|
}
|
|
546
795
|
const operationType = operationMatch[1];
|
|
796
|
+
logger.info(`Requester.subscribe operationType`, operationType);
|
|
547
797
|
if (operationType == "mutation") {
|
|
548
798
|
throw new LightsparkException_default(
|
|
549
799
|
"InvalidQuery",
|
|
@@ -561,7 +811,6 @@ var Requester = class {
|
|
|
561
811
|
variables,
|
|
562
812
|
operationName: operation
|
|
563
813
|
};
|
|
564
|
-
logger.info(`Requester.subscribe bodyData`, bodyData);
|
|
565
814
|
return new import_zen_observable_ts.Observable((observer) => {
|
|
566
815
|
logger.info(`Requester.subscribe observer`, observer);
|
|
567
816
|
return this.wsClient.subscribe(bodyData, {
|
|
@@ -697,127 +946,6 @@ var apiDomainForEnvironment = (environment) => {
|
|
|
697
946
|
}
|
|
698
947
|
};
|
|
699
948
|
var ServerEnvironment_default = ServerEnvironment;
|
|
700
|
-
|
|
701
|
-
// src/utils/createHash.ts
|
|
702
|
-
var createSha256Hash = async (data) => {
|
|
703
|
-
if (isBrowser) {
|
|
704
|
-
return new Uint8Array(await window.crypto.subtle.digest("SHA-256", data));
|
|
705
|
-
} else {
|
|
706
|
-
const { createHash } = await import("crypto");
|
|
707
|
-
const buffer = createHash("sha256").update(data).digest();
|
|
708
|
-
return new Uint8Array(buffer);
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
// src/utils/currency.ts
|
|
713
|
-
var CONVERSION_MAP = {
|
|
714
|
-
["BITCOIN" /* BITCOIN */]: {
|
|
715
|
-
["BITCOIN" /* BITCOIN */]: (v) => v,
|
|
716
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e6,
|
|
717
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v * 1e3,
|
|
718
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e11,
|
|
719
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e9,
|
|
720
|
-
["SATOSHI" /* SATOSHI */]: (v) => v * 1e8
|
|
721
|
-
},
|
|
722
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: {
|
|
723
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e6),
|
|
724
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v,
|
|
725
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e3),
|
|
726
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e5,
|
|
727
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e3,
|
|
728
|
-
["SATOSHI" /* SATOSHI */]: (v) => v * 100
|
|
729
|
-
},
|
|
730
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: {
|
|
731
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e3),
|
|
732
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e3,
|
|
733
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v,
|
|
734
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e8,
|
|
735
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e6,
|
|
736
|
-
["SATOSHI" /* SATOSHI */]: (v) => v * 1e5
|
|
737
|
-
},
|
|
738
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: {
|
|
739
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e11),
|
|
740
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 1e5),
|
|
741
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e8),
|
|
742
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v,
|
|
743
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => Math.round(v / 100),
|
|
744
|
-
["SATOSHI" /* SATOSHI */]: (v) => Math.round(v / 1e3)
|
|
745
|
-
},
|
|
746
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: {
|
|
747
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e9),
|
|
748
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 1e3),
|
|
749
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e6),
|
|
750
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 100,
|
|
751
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v,
|
|
752
|
-
["SATOSHI" /* SATOSHI */]: (v) => Math.round(v / 10)
|
|
753
|
-
},
|
|
754
|
-
["SATOSHI" /* SATOSHI */]: {
|
|
755
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e8),
|
|
756
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 100),
|
|
757
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e5),
|
|
758
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e3,
|
|
759
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 10,
|
|
760
|
-
["SATOSHI" /* SATOSHI */]: (v) => v
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
var convertCurrencyAmount = (from, toUnit) => {
|
|
764
|
-
if (from.originalUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || from.originalUnit === "USD" /* USD */ || toUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || toUnit === "USD" /* USD */) {
|
|
765
|
-
throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
|
|
766
|
-
}
|
|
767
|
-
const conversionFn = CONVERSION_MAP[from.originalUnit][toUnit];
|
|
768
|
-
if (!conversionFn) {
|
|
769
|
-
throw new LightsparkException_default(
|
|
770
|
-
"CurrencyError",
|
|
771
|
-
`Cannot convert from ${from.originalUnit} to ${toUnit}`
|
|
772
|
-
);
|
|
773
|
-
}
|
|
774
|
-
return {
|
|
775
|
-
...from,
|
|
776
|
-
preferredCurrencyUnit: toUnit,
|
|
777
|
-
preferredCurrencyValueApprox: conversionFn(from.originalValue),
|
|
778
|
-
preferredCurrencyValueRounded: conversionFn(from.originalValue)
|
|
779
|
-
};
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
// src/utils/errors.ts
|
|
783
|
-
var isError = (e) => {
|
|
784
|
-
return Boolean(
|
|
785
|
-
typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string" && "stack" in e && (!e.stack || typeof e.stack === "string")
|
|
786
|
-
);
|
|
787
|
-
};
|
|
788
|
-
var isErrorWithMessage = (e) => {
|
|
789
|
-
return Boolean(
|
|
790
|
-
typeof e === "object" && e !== null && "message" in e && typeof e.message === "string"
|
|
791
|
-
);
|
|
792
|
-
};
|
|
793
|
-
var getErrorMsg = (e) => {
|
|
794
|
-
return isErrorWithMessage(e) ? e.message : "Unknown error";
|
|
795
|
-
};
|
|
796
|
-
var isErrorMsg = (e, msg) => {
|
|
797
|
-
if (isError(e)) {
|
|
798
|
-
return e.message === msg;
|
|
799
|
-
}
|
|
800
|
-
return false;
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
// src/utils/hex.ts
|
|
804
|
-
var bytesToHex = (bytes) => {
|
|
805
|
-
return bytes.reduce((acc, byte) => {
|
|
806
|
-
return acc += ("0" + byte.toString(16)).slice(-2);
|
|
807
|
-
}, "");
|
|
808
|
-
};
|
|
809
|
-
var hexToBytes = (hex) => {
|
|
810
|
-
const bytes = [];
|
|
811
|
-
for (let c = 0; c < hex.length; c += 2) {
|
|
812
|
-
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
813
|
-
}
|
|
814
|
-
return Uint8Array.from(bytes);
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
// src/utils/types.ts
|
|
818
|
-
var isType = (typename) => (node) => {
|
|
819
|
-
return node?.__typename === typename;
|
|
820
|
-
};
|
|
821
949
|
// Annotate the CommonJS export names for ESM import in node:
|
|
822
950
|
0 && (module.exports = {
|
|
823
951
|
DefaultCrypto,
|
|
@@ -847,6 +975,22 @@ var isType = (typename) => (node) => {
|
|
|
847
975
|
isErrorMsg,
|
|
848
976
|
isErrorWithMessage,
|
|
849
977
|
isNode,
|
|
978
|
+
isTest,
|
|
850
979
|
isType,
|
|
980
|
+
pollUntil,
|
|
981
|
+
sleep,
|
|
851
982
|
urlsafe_b64decode
|
|
852
983
|
});
|
|
984
|
+
/*! Bundled license information:
|
|
985
|
+
|
|
986
|
+
lodash-es/lodash.js:
|
|
987
|
+
(**
|
|
988
|
+
* @license
|
|
989
|
+
* Lodash (Custom Build) <https://lodash.com/>
|
|
990
|
+
* Build: `lodash modularize exports="es" -o ./`
|
|
991
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
992
|
+
* Released under MIT license <https://lodash.com/license>
|
|
993
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
994
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
995
|
+
*)
|
|
996
|
+
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'zen-observable-ts';
|
|
2
|
+
export { ById, ExpandRecursively, Maybe, OmitTypename, b64decode, b64encode, bytesToHex, convertCurrencyAmount, createSha256Hash, getErrorMsg, hexToBytes, isBrowser, isError, isErrorMsg, isErrorWithMessage, isNode, isTest, isType, pollUntil, sleep, urlsafe_b64decode } from './utils/index.js';
|
|
2
3
|
|
|
3
4
|
type Headers = Record<string, string>;
|
|
4
5
|
type WsConnectionParams = Record<string, unknown>;
|
|
@@ -154,80 +155,4 @@ declare enum ServerEnvironment {
|
|
|
154
155
|
}
|
|
155
156
|
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
156
157
|
|
|
157
|
-
|
|
158
|
-
declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
|
|
159
|
-
declare const b64encode: (data: ArrayBuffer) => string;
|
|
160
|
-
|
|
161
|
-
declare const createSha256Hash: (data: Uint8Array) => Promise<Uint8Array>;
|
|
162
|
-
|
|
163
|
-
/** Represents the value and unit for an amount of currency. **/
|
|
164
|
-
type CurrencyAmount = {
|
|
165
|
-
/** The original numeric value for this CurrencyAmount. **/
|
|
166
|
-
originalValue: number;
|
|
167
|
-
/** The original unit of currency for this CurrencyAmount. **/
|
|
168
|
-
originalUnit: CurrencyUnit;
|
|
169
|
-
/** The unit of user's preferred currency. **/
|
|
170
|
-
preferredCurrencyUnit: CurrencyUnit;
|
|
171
|
-
/**
|
|
172
|
-
* The rounded numeric value for this CurrencyAmount in the very base level of user's preferred
|
|
173
|
-
* currency. For example, for USD, the value will be in cents.
|
|
174
|
-
**/
|
|
175
|
-
preferredCurrencyValueRounded: number;
|
|
176
|
-
/**
|
|
177
|
-
* The approximate float value for this CurrencyAmount in the very base level of user's preferred
|
|
178
|
-
* currency. For example, for USD, the value will be in cents.
|
|
179
|
-
**/
|
|
180
|
-
preferredCurrencyValueApprox: number;
|
|
181
|
-
};
|
|
182
|
-
declare enum CurrencyUnit {
|
|
183
|
-
/**
|
|
184
|
-
* This is an enum value that represents values that could be added in the future.
|
|
185
|
-
* Clients should support unknown values as more of them could be added without notice.
|
|
186
|
-
*/
|
|
187
|
-
FUTURE_VALUE = "FUTURE_VALUE",
|
|
188
|
-
/** Bitcoin is the cryptocurrency native to the Bitcoin network. It is used as the native medium for value transfer for the Lightning Network. **/
|
|
189
|
-
BITCOIN = "BITCOIN",
|
|
190
|
-
/** 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin. This is the unit most commonly used in Lightning transactions. **/
|
|
191
|
-
SATOSHI = "SATOSHI",
|
|
192
|
-
/** 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
193
|
-
MILLISATOSHI = "MILLISATOSHI",
|
|
194
|
-
/** United States Dollar. **/
|
|
195
|
-
USD = "USD",
|
|
196
|
-
/** 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
197
|
-
NANOBITCOIN = "NANOBITCOIN",
|
|
198
|
-
/** 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
199
|
-
MICROBITCOIN = "MICROBITCOIN",
|
|
200
|
-
/** 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
201
|
-
MILLIBITCOIN = "MILLIBITCOIN"
|
|
202
|
-
}
|
|
203
|
-
declare const convertCurrencyAmount: (from: CurrencyAmount, toUnit: CurrencyUnit) => CurrencyAmount;
|
|
204
|
-
|
|
205
|
-
declare const isBrowser: boolean;
|
|
206
|
-
declare const isNode: boolean;
|
|
207
|
-
|
|
208
|
-
declare const isError: (e: unknown) => e is Error;
|
|
209
|
-
type ErrorWithMessage = {
|
|
210
|
-
message: string;
|
|
211
|
-
};
|
|
212
|
-
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
213
|
-
declare const getErrorMsg: (e: unknown) => string;
|
|
214
|
-
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
215
|
-
|
|
216
|
-
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
217
|
-
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
218
|
-
|
|
219
|
-
type Maybe<T> = T | null | undefined;
|
|
220
|
-
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
221
|
-
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
222
|
-
} : never : T;
|
|
223
|
-
type ById<T> = {
|
|
224
|
-
[id: string]: T;
|
|
225
|
-
};
|
|
226
|
-
type OmitTypename<T> = Omit<T, "__typename">;
|
|
227
|
-
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
228
|
-
__typename: string;
|
|
229
|
-
}>(node: N | null | undefined) => node is Extract<N, {
|
|
230
|
-
__typename: T;
|
|
231
|
-
}>;
|
|
232
|
-
|
|
233
|
-
export { AuthProvider, ById, CryptoInterface, DefaultCrypto, ExpandRecursively, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, Maybe, NodeKeyCache, OmitTypename, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, b64decode, b64encode, bytesToHex, convertCurrencyAmount, createSha256Hash, getErrorMsg, hexToBytes, isBrowser, isError, isErrorMsg, isErrorWithMessage, isNode, isType, urlsafe_b64decode };
|
|
158
|
+
export { AuthProvider, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment };
|