@lightsparkdev/core 1.0.2 → 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 +13 -0
- package/dist/chunk-J6VQYCQJ.js +338 -0
- package/dist/index.cjs +280 -131
- package/dist/index.d.ts +5 -78
- package/dist/index.js +34 -187
- 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 +13 -3
- 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
|
}
|
|
@@ -461,9 +714,16 @@ var NodeKeyCache_default = NodeKeyCache;
|
|
|
461
714
|
var Logger = class {
|
|
462
715
|
context;
|
|
463
716
|
loggingEnabled = false;
|
|
464
|
-
constructor(loggerContext) {
|
|
717
|
+
constructor(loggerContext, getLoggingEnabled) {
|
|
465
718
|
this.context = loggerContext;
|
|
466
|
-
|
|
719
|
+
this.updateLoggingEnabled(getLoggingEnabled);
|
|
720
|
+
}
|
|
721
|
+
async updateLoggingEnabled(getLoggingEnabled) {
|
|
722
|
+
if (getLoggingEnabled) {
|
|
723
|
+
this.loggingEnabled = await getLoggingEnabled();
|
|
724
|
+
} else if (isTest) {
|
|
725
|
+
this.loggingEnabled = true;
|
|
726
|
+
} else if (isBrowser) {
|
|
467
727
|
try {
|
|
468
728
|
this.loggingEnabled = localStorage.getItem("lightspark-logging-enabled") === "1";
|
|
469
729
|
} catch (e) {
|
|
@@ -488,12 +748,6 @@ var import_utc = __toESM(require("dayjs/plugin/utc.js"), 1);
|
|
|
488
748
|
var import_graphql_ws = require("graphql-ws");
|
|
489
749
|
var import_ws = __toESM(require("ws"), 1);
|
|
490
750
|
var import_zen_observable_ts = require("zen-observable-ts");
|
|
491
|
-
|
|
492
|
-
// src/utils/environment.ts
|
|
493
|
-
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
494
|
-
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
495
|
-
|
|
496
|
-
// src/requester/Requester.ts
|
|
497
751
|
var DEFAULT_BASE_URL = "api.lightspark.com";
|
|
498
752
|
var LIGHTSPARK_BETA_HEADER_KEY = "X-Lightspark-Beta";
|
|
499
753
|
var LIGHTSPARK_BETA_HEADER_VALUE = "z2h0BBYxTA83cjW7fi8QwWtBPCzkQKiemcuhKY08LOo";
|
|
@@ -532,13 +786,14 @@ var Requester = class {
|
|
|
532
786
|
return query.constructObject(data);
|
|
533
787
|
}
|
|
534
788
|
subscribe(queryPayload, variables = {}) {
|
|
535
|
-
logger.info(`Requester.subscribe
|
|
789
|
+
logger.info(`Requester.subscribe variables`, variables);
|
|
536
790
|
const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
|
|
537
791
|
const operationMatch = queryPayload.match(operationNameRegex);
|
|
538
792
|
if (!operationMatch || operationMatch.length < 3) {
|
|
539
793
|
throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
|
|
540
794
|
}
|
|
541
795
|
const operationType = operationMatch[1];
|
|
796
|
+
logger.info(`Requester.subscribe operationType`, operationType);
|
|
542
797
|
if (operationType == "mutation") {
|
|
543
798
|
throw new LightsparkException_default(
|
|
544
799
|
"InvalidQuery",
|
|
@@ -556,7 +811,6 @@ var Requester = class {
|
|
|
556
811
|
variables,
|
|
557
812
|
operationName: operation
|
|
558
813
|
};
|
|
559
|
-
logger.info(`Requester.subscribe bodyData`, bodyData);
|
|
560
814
|
return new import_zen_observable_ts.Observable((observer) => {
|
|
561
815
|
logger.info(`Requester.subscribe observer`, observer);
|
|
562
816
|
return this.wsClient.subscribe(bodyData, {
|
|
@@ -692,127 +946,6 @@ var apiDomainForEnvironment = (environment) => {
|
|
|
692
946
|
}
|
|
693
947
|
};
|
|
694
948
|
var ServerEnvironment_default = ServerEnvironment;
|
|
695
|
-
|
|
696
|
-
// src/utils/createHash.ts
|
|
697
|
-
var createSha256Hash = async (data) => {
|
|
698
|
-
if (isBrowser) {
|
|
699
|
-
return new Uint8Array(await window.crypto.subtle.digest("SHA-256", data));
|
|
700
|
-
} else {
|
|
701
|
-
const { createHash } = await import("crypto");
|
|
702
|
-
const buffer = createHash("sha256").update(data).digest();
|
|
703
|
-
return new Uint8Array(buffer);
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
// src/utils/currency.ts
|
|
708
|
-
var CONVERSION_MAP = {
|
|
709
|
-
["BITCOIN" /* BITCOIN */]: {
|
|
710
|
-
["BITCOIN" /* BITCOIN */]: (v) => v,
|
|
711
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e6,
|
|
712
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v * 1e3,
|
|
713
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e11,
|
|
714
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e9,
|
|
715
|
-
["SATOSHI" /* SATOSHI */]: (v) => v * 1e8
|
|
716
|
-
},
|
|
717
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: {
|
|
718
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e6),
|
|
719
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v,
|
|
720
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e3),
|
|
721
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e5,
|
|
722
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e3,
|
|
723
|
-
["SATOSHI" /* SATOSHI */]: (v) => v * 100
|
|
724
|
-
},
|
|
725
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: {
|
|
726
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e3),
|
|
727
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => v * 1e3,
|
|
728
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => v,
|
|
729
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e8,
|
|
730
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 1e6,
|
|
731
|
-
["SATOSHI" /* SATOSHI */]: (v) => v * 1e5
|
|
732
|
-
},
|
|
733
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: {
|
|
734
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e11),
|
|
735
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 1e5),
|
|
736
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e8),
|
|
737
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v,
|
|
738
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => Math.round(v / 100),
|
|
739
|
-
["SATOSHI" /* SATOSHI */]: (v) => Math.round(v / 1e3)
|
|
740
|
-
},
|
|
741
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: {
|
|
742
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e9),
|
|
743
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 1e3),
|
|
744
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e6),
|
|
745
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 100,
|
|
746
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v,
|
|
747
|
-
["SATOSHI" /* SATOSHI */]: (v) => Math.round(v / 10)
|
|
748
|
-
},
|
|
749
|
-
["SATOSHI" /* SATOSHI */]: {
|
|
750
|
-
["BITCOIN" /* BITCOIN */]: (v) => Math.round(v / 1e8),
|
|
751
|
-
["MICROBITCOIN" /* MICROBITCOIN */]: (v) => Math.round(v / 100),
|
|
752
|
-
["MILLIBITCOIN" /* MILLIBITCOIN */]: (v) => Math.round(v / 1e5),
|
|
753
|
-
["MILLISATOSHI" /* MILLISATOSHI */]: (v) => v * 1e3,
|
|
754
|
-
["NANOBITCOIN" /* NANOBITCOIN */]: (v) => v * 10,
|
|
755
|
-
["SATOSHI" /* SATOSHI */]: (v) => v
|
|
756
|
-
}
|
|
757
|
-
};
|
|
758
|
-
var convertCurrencyAmount = (from, toUnit) => {
|
|
759
|
-
if (from.originalUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || from.originalUnit === "USD" /* USD */ || toUnit === "FUTURE_VALUE" /* FUTURE_VALUE */ || toUnit === "USD" /* USD */) {
|
|
760
|
-
throw new LightsparkException_default("CurrencyError", `Unsupported CurrencyUnit.`);
|
|
761
|
-
}
|
|
762
|
-
const conversionFn = CONVERSION_MAP[from.originalUnit][toUnit];
|
|
763
|
-
if (!conversionFn) {
|
|
764
|
-
throw new LightsparkException_default(
|
|
765
|
-
"CurrencyError",
|
|
766
|
-
`Cannot convert from ${from.originalUnit} to ${toUnit}`
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
return {
|
|
770
|
-
...from,
|
|
771
|
-
preferredCurrencyUnit: toUnit,
|
|
772
|
-
preferredCurrencyValueApprox: conversionFn(from.originalValue),
|
|
773
|
-
preferredCurrencyValueRounded: conversionFn(from.originalValue)
|
|
774
|
-
};
|
|
775
|
-
};
|
|
776
|
-
|
|
777
|
-
// src/utils/errors.ts
|
|
778
|
-
var isError = (e) => {
|
|
779
|
-
return Boolean(
|
|
780
|
-
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")
|
|
781
|
-
);
|
|
782
|
-
};
|
|
783
|
-
var isErrorWithMessage = (e) => {
|
|
784
|
-
return Boolean(
|
|
785
|
-
typeof e === "object" && e !== null && "message" in e && typeof e.message === "string"
|
|
786
|
-
);
|
|
787
|
-
};
|
|
788
|
-
var getErrorMsg = (e) => {
|
|
789
|
-
return isErrorWithMessage(e) ? e.message : "Unknown error";
|
|
790
|
-
};
|
|
791
|
-
var isErrorMsg = (e, msg) => {
|
|
792
|
-
if (isError(e)) {
|
|
793
|
-
return e.message === msg;
|
|
794
|
-
}
|
|
795
|
-
return false;
|
|
796
|
-
};
|
|
797
|
-
|
|
798
|
-
// src/utils/hex.ts
|
|
799
|
-
var bytesToHex = (bytes) => {
|
|
800
|
-
return bytes.reduce((acc, byte) => {
|
|
801
|
-
return acc += ("0" + byte.toString(16)).slice(-2);
|
|
802
|
-
}, "");
|
|
803
|
-
};
|
|
804
|
-
var hexToBytes = (hex) => {
|
|
805
|
-
const bytes = [];
|
|
806
|
-
for (let c = 0; c < hex.length; c += 2) {
|
|
807
|
-
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
808
|
-
}
|
|
809
|
-
return Uint8Array.from(bytes);
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
// src/utils/types.ts
|
|
813
|
-
var isType = (typename) => (node) => {
|
|
814
|
-
return node?.__typename === typename;
|
|
815
|
-
};
|
|
816
949
|
// Annotate the CommonJS export names for ESM import in node:
|
|
817
950
|
0 && (module.exports = {
|
|
818
951
|
DefaultCrypto,
|
|
@@ -842,6 +975,22 @@ var isType = (typename) => (node) => {
|
|
|
842
975
|
isErrorMsg,
|
|
843
976
|
isErrorWithMessage,
|
|
844
977
|
isNode,
|
|
978
|
+
isTest,
|
|
845
979
|
isType,
|
|
980
|
+
pollUntil,
|
|
981
|
+
sleep,
|
|
846
982
|
urlsafe_b64decode
|
|
847
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>;
|
|
@@ -101,10 +102,12 @@ declare class NodeKeyCache {
|
|
|
101
102
|
private stripPemTags;
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
104
106
|
declare class Logger {
|
|
105
107
|
context: string;
|
|
106
108
|
loggingEnabled: boolean;
|
|
107
|
-
constructor(loggerContext: string);
|
|
109
|
+
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
110
|
+
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
108
111
|
info(message: string, ...rest: unknown[]): void;
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -152,80 +155,4 @@ declare enum ServerEnvironment {
|
|
|
152
155
|
}
|
|
153
156
|
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
|
|
157
|
-
declare const b64encode: (data: ArrayBuffer) => string;
|
|
158
|
-
|
|
159
|
-
declare const createSha256Hash: (data: Uint8Array) => Promise<Uint8Array>;
|
|
160
|
-
|
|
161
|
-
/** Represents the value and unit for an amount of currency. **/
|
|
162
|
-
type CurrencyAmount = {
|
|
163
|
-
/** The original numeric value for this CurrencyAmount. **/
|
|
164
|
-
originalValue: number;
|
|
165
|
-
/** The original unit of currency for this CurrencyAmount. **/
|
|
166
|
-
originalUnit: CurrencyUnit;
|
|
167
|
-
/** The unit of user's preferred currency. **/
|
|
168
|
-
preferredCurrencyUnit: CurrencyUnit;
|
|
169
|
-
/**
|
|
170
|
-
* The rounded numeric value for this CurrencyAmount in the very base level of user's preferred
|
|
171
|
-
* currency. For example, for USD, the value will be in cents.
|
|
172
|
-
**/
|
|
173
|
-
preferredCurrencyValueRounded: number;
|
|
174
|
-
/**
|
|
175
|
-
* The approximate float value for this CurrencyAmount in the very base level of user's preferred
|
|
176
|
-
* currency. For example, for USD, the value will be in cents.
|
|
177
|
-
**/
|
|
178
|
-
preferredCurrencyValueApprox: number;
|
|
179
|
-
};
|
|
180
|
-
declare enum CurrencyUnit {
|
|
181
|
-
/**
|
|
182
|
-
* This is an enum value that represents values that could be added in the future.
|
|
183
|
-
* Clients should support unknown values as more of them could be added without notice.
|
|
184
|
-
*/
|
|
185
|
-
FUTURE_VALUE = "FUTURE_VALUE",
|
|
186
|
-
/** Bitcoin is the cryptocurrency native to the Bitcoin network. It is used as the native medium for value transfer for the Lightning Network. **/
|
|
187
|
-
BITCOIN = "BITCOIN",
|
|
188
|
-
/** 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin. This is the unit most commonly used in Lightning transactions. **/
|
|
189
|
-
SATOSHI = "SATOSHI",
|
|
190
|
-
/** 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
191
|
-
MILLISATOSHI = "MILLISATOSHI",
|
|
192
|
-
/** United States Dollar. **/
|
|
193
|
-
USD = "USD",
|
|
194
|
-
/** 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
195
|
-
NANOBITCOIN = "NANOBITCOIN",
|
|
196
|
-
/** 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
197
|
-
MICROBITCOIN = "MICROBITCOIN",
|
|
198
|
-
/** 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
|
|
199
|
-
MILLIBITCOIN = "MILLIBITCOIN"
|
|
200
|
-
}
|
|
201
|
-
declare const convertCurrencyAmount: (from: CurrencyAmount, toUnit: CurrencyUnit) => CurrencyAmount;
|
|
202
|
-
|
|
203
|
-
declare const isBrowser: boolean;
|
|
204
|
-
declare const isNode: boolean;
|
|
205
|
-
|
|
206
|
-
declare const isError: (e: unknown) => e is Error;
|
|
207
|
-
type ErrorWithMessage = {
|
|
208
|
-
message: string;
|
|
209
|
-
};
|
|
210
|
-
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
211
|
-
declare const getErrorMsg: (e: unknown) => string;
|
|
212
|
-
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
213
|
-
|
|
214
|
-
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
215
|
-
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
216
|
-
|
|
217
|
-
type Maybe<T> = T | null | undefined;
|
|
218
|
-
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
219
|
-
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
220
|
-
} : never : T;
|
|
221
|
-
type ById<T> = {
|
|
222
|
-
[id: string]: T;
|
|
223
|
-
};
|
|
224
|
-
type OmitTypename<T> = Omit<T, "__typename">;
|
|
225
|
-
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
226
|
-
__typename: string;
|
|
227
|
-
}>(node: N | null | undefined) => node is Extract<N, {
|
|
228
|
-
__typename: T;
|
|
229
|
-
}>;
|
|
230
|
-
|
|
231
|
-
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 };
|