@lightsparkdev/core 1.0.10 → 1.0.12
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 +12 -0
- package/dist/{chunk-MAZP7ETK.js → chunk-BYCLLNFL.js} +12 -3
- package/dist/index.cjs +91 -72
- package/dist/index.d.cts +43 -39
- package/dist/index.d.ts +43 -39
- package/dist/index.js +70 -60
- package/dist/utils/index.cjs +10 -0
- package/dist/utils/index.d.cts +68 -31
- package/dist/utils/index.d.ts +68 -31
- package/dist/utils/index.js +3 -1
- package/package.json +3 -3
- package/src/constants/localStorage.ts +5 -0
- package/src/crypto/crypto.ts +1 -2
- package/src/crypto/index.ts +1 -1
- package/src/crypto/tests/crypto.test.ts +1 -1
- package/src/index.ts +5 -5
- package/src/requester/Query.ts +4 -1
- package/src/requester/Requester.ts +1 -0
- package/src/utils/currency.ts +56 -18
- package/src/utils/errors.ts +16 -0
- package/src/utils/localeToCurrencyCodes.ts +3 -1
- package/src/utils/types.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
countryCodesToCurrencyCodes,
|
|
12
12
|
createSha256Hash,
|
|
13
13
|
defaultCurrencyCode,
|
|
14
|
+
errorToJSON,
|
|
14
15
|
formatCurrencyStr,
|
|
15
16
|
getCurrentLocale,
|
|
16
17
|
getErrorMsg,
|
|
@@ -35,7 +36,56 @@ import {
|
|
|
35
36
|
separateCurrencyStrParts,
|
|
36
37
|
sleep,
|
|
37
38
|
urlsafe_b64decode
|
|
38
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-BYCLLNFL.js";
|
|
40
|
+
|
|
41
|
+
// src/Logger.ts
|
|
42
|
+
var Logger = class {
|
|
43
|
+
context;
|
|
44
|
+
loggingEnabled = false;
|
|
45
|
+
constructor(loggerContext, getLoggingEnabled) {
|
|
46
|
+
this.context = loggerContext;
|
|
47
|
+
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
48
|
+
}
|
|
49
|
+
async updateLoggingEnabled(getLoggingEnabled) {
|
|
50
|
+
if (getLoggingEnabled) {
|
|
51
|
+
this.loggingEnabled = await getLoggingEnabled();
|
|
52
|
+
} else if (isTest) {
|
|
53
|
+
this.loggingEnabled = true;
|
|
54
|
+
} else if (isBrowser) {
|
|
55
|
+
try {
|
|
56
|
+
this.loggingEnabled = getLocalStorageConfigItem(
|
|
57
|
+
ConfigKeys.LoggingEnabled
|
|
58
|
+
);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (this.loggingEnabled) {
|
|
63
|
+
console.log(`[${this.context}] Logging enabled`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
info(message, ...rest) {
|
|
67
|
+
if (this.loggingEnabled) {
|
|
68
|
+
console.log(`[${this.context}] ${message}`, ...rest);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var logger = new Logger("@lightsparkdev/core");
|
|
73
|
+
|
|
74
|
+
// src/ServerEnvironment.ts
|
|
75
|
+
var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
|
|
76
|
+
ServerEnvironment2["PRODUCTION"] = "production";
|
|
77
|
+
ServerEnvironment2["DEV"] = "dev";
|
|
78
|
+
return ServerEnvironment2;
|
|
79
|
+
})(ServerEnvironment || {});
|
|
80
|
+
var apiDomainForEnvironment = (environment) => {
|
|
81
|
+
switch (environment) {
|
|
82
|
+
case "dev" /* DEV */:
|
|
83
|
+
return "api.dev.dev.sparkinfra.net";
|
|
84
|
+
case "production" /* PRODUCTION */:
|
|
85
|
+
return "api.lightspark.com";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var ServerEnvironment_default = ServerEnvironment;
|
|
39
89
|
|
|
40
90
|
// src/auth/LightsparkAuthException.ts
|
|
41
91
|
var LightsparkAuthException = class extends LightsparkException_default {
|
|
@@ -64,6 +114,9 @@ var ConfigKeys = {
|
|
|
64
114
|
ConsoleToolsEnabled: "lightspark-console-tools-enabled"
|
|
65
115
|
};
|
|
66
116
|
var getLocalStorageConfigItem = (key) => {
|
|
117
|
+
return getLocalStorageBoolean(key);
|
|
118
|
+
};
|
|
119
|
+
var getLocalStorageBoolean = (key) => {
|
|
67
120
|
try {
|
|
68
121
|
return localStorage.getItem(key) === "1";
|
|
69
122
|
} catch (e) {
|
|
@@ -71,6 +124,12 @@ var getLocalStorageConfigItem = (key) => {
|
|
|
71
124
|
}
|
|
72
125
|
};
|
|
73
126
|
|
|
127
|
+
// src/crypto/KeyOrAlias.ts
|
|
128
|
+
var KeyOrAlias = {
|
|
129
|
+
key: (key) => ({ key }),
|
|
130
|
+
alias: (alias) => ({ alias })
|
|
131
|
+
};
|
|
132
|
+
|
|
74
133
|
// src/crypto/LightsparkSigningException.ts
|
|
75
134
|
var LightsparkSigningException = class extends LightsparkException_default {
|
|
76
135
|
constructor(message, extraInfo) {
|
|
@@ -79,6 +138,9 @@ var LightsparkSigningException = class extends LightsparkException_default {
|
|
|
79
138
|
};
|
|
80
139
|
var LightsparkSigningException_default = LightsparkSigningException;
|
|
81
140
|
|
|
141
|
+
// src/crypto/NodeKeyCache.ts
|
|
142
|
+
import autoBind from "auto-bind";
|
|
143
|
+
|
|
82
144
|
// src/crypto/crypto.ts
|
|
83
145
|
var getCrypto = () => {
|
|
84
146
|
let cryptoImplPromise;
|
|
@@ -173,7 +235,10 @@ var decrypt = async (header_json, ciphertext, password) => {
|
|
|
173
235
|
const salt = decoded.slice(decoded.length - 8, decoded.length);
|
|
174
236
|
const nonce = decoded.slice(0, 12);
|
|
175
237
|
const cipherText = decoded.slice(12, decoded.length - 8);
|
|
176
|
-
const [
|
|
238
|
+
const [
|
|
239
|
+
key
|
|
240
|
+
/* , _iv */
|
|
241
|
+
] = await deriveKey(
|
|
177
242
|
password,
|
|
178
243
|
salt,
|
|
179
244
|
header.i,
|
|
@@ -283,15 +348,6 @@ var DefaultCrypto = {
|
|
|
283
348
|
importPrivateSigningKey
|
|
284
349
|
};
|
|
285
350
|
|
|
286
|
-
// src/crypto/KeyOrAlias.ts
|
|
287
|
-
var KeyOrAlias = {
|
|
288
|
-
key: (key) => ({ key }),
|
|
289
|
-
alias: (alias) => ({ alias })
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// src/crypto/NodeKeyCache.ts
|
|
293
|
-
import autoBind from "auto-bind";
|
|
294
|
-
|
|
295
351
|
// src/crypto/SigningKey.ts
|
|
296
352
|
import secp256k1 from "secp256k1";
|
|
297
353
|
function isAlias(key) {
|
|
@@ -388,39 +444,6 @@ var NodeKeyCache = class {
|
|
|
388
444
|
};
|
|
389
445
|
var NodeKeyCache_default = NodeKeyCache;
|
|
390
446
|
|
|
391
|
-
// src/Logger.ts
|
|
392
|
-
var Logger = class {
|
|
393
|
-
context;
|
|
394
|
-
loggingEnabled = false;
|
|
395
|
-
constructor(loggerContext, getLoggingEnabled) {
|
|
396
|
-
this.context = loggerContext;
|
|
397
|
-
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
398
|
-
}
|
|
399
|
-
async updateLoggingEnabled(getLoggingEnabled) {
|
|
400
|
-
if (getLoggingEnabled) {
|
|
401
|
-
this.loggingEnabled = await getLoggingEnabled();
|
|
402
|
-
} else if (isTest) {
|
|
403
|
-
this.loggingEnabled = true;
|
|
404
|
-
} else if (isBrowser) {
|
|
405
|
-
try {
|
|
406
|
-
this.loggingEnabled = getLocalStorageConfigItem(
|
|
407
|
-
ConfigKeys.LoggingEnabled
|
|
408
|
-
);
|
|
409
|
-
} catch (e) {
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (this.loggingEnabled) {
|
|
413
|
-
console.log(`[${this.context}] Logging enabled`);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
info(message, ...rest) {
|
|
417
|
-
if (this.loggingEnabled) {
|
|
418
|
-
console.log(`[${this.context}] ${message}`, ...rest);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
var logger = new Logger("@lightsparkdev/core");
|
|
423
|
-
|
|
424
447
|
// src/requester/Requester.ts
|
|
425
448
|
import autoBind2 from "auto-bind";
|
|
426
449
|
import dayjs from "dayjs";
|
|
@@ -545,6 +568,7 @@ var Requester = class {
|
|
|
545
568
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
546
569
|
logger.info(`Requester.makeRawRequest`, {
|
|
547
570
|
url,
|
|
571
|
+
operationName: operation,
|
|
548
572
|
variables
|
|
549
573
|
});
|
|
550
574
|
const response = await fetch(url, {
|
|
@@ -615,22 +639,6 @@ var Requester = class {
|
|
|
615
639
|
}
|
|
616
640
|
};
|
|
617
641
|
var Requester_default = Requester;
|
|
618
|
-
|
|
619
|
-
// src/ServerEnvironment.ts
|
|
620
|
-
var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
|
|
621
|
-
ServerEnvironment2["PRODUCTION"] = "production";
|
|
622
|
-
ServerEnvironment2["DEV"] = "dev";
|
|
623
|
-
return ServerEnvironment2;
|
|
624
|
-
})(ServerEnvironment || {});
|
|
625
|
-
var apiDomainForEnvironment = (environment) => {
|
|
626
|
-
switch (environment) {
|
|
627
|
-
case "dev" /* DEV */:
|
|
628
|
-
return "api.dev.dev.sparkinfra.net";
|
|
629
|
-
case "production" /* PRODUCTION */:
|
|
630
|
-
return "api.lightspark.com";
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
var ServerEnvironment_default = ServerEnvironment;
|
|
634
642
|
export {
|
|
635
643
|
ConfigKeys,
|
|
636
644
|
CurrencyUnit,
|
|
@@ -659,9 +667,11 @@ export {
|
|
|
659
667
|
countryCodesToCurrencyCodes,
|
|
660
668
|
createSha256Hash,
|
|
661
669
|
defaultCurrencyCode,
|
|
670
|
+
errorToJSON,
|
|
662
671
|
formatCurrencyStr,
|
|
663
672
|
getCurrentLocale,
|
|
664
673
|
getErrorMsg,
|
|
674
|
+
getLocalStorageBoolean,
|
|
665
675
|
getLocalStorageConfigItem,
|
|
666
676
|
hexToBytes,
|
|
667
677
|
isBrowser,
|
package/dist/utils/index.cjs
CHANGED
|
@@ -41,6 +41,7 @@ __export(utils_exports, {
|
|
|
41
41
|
countryCodesToCurrencyCodes: () => countryCodesToCurrencyCodes,
|
|
42
42
|
createSha256Hash: () => createSha256Hash,
|
|
43
43
|
defaultCurrencyCode: () => defaultCurrencyCode,
|
|
44
|
+
errorToJSON: () => errorToJSON,
|
|
44
45
|
formatCurrencyStr: () => formatCurrencyStr,
|
|
45
46
|
getCurrentLocale: () => getCurrentLocale,
|
|
46
47
|
getErrorMsg: () => getErrorMsg,
|
|
@@ -798,6 +799,14 @@ var isErrorMsg = (e, msg) => {
|
|
|
798
799
|
}
|
|
799
800
|
return false;
|
|
800
801
|
};
|
|
802
|
+
function errorToJSON(err) {
|
|
803
|
+
if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
|
|
804
|
+
return err.toJSON();
|
|
805
|
+
}
|
|
806
|
+
return JSON.parse(
|
|
807
|
+
JSON.stringify(err, Object.getOwnPropertyNames(err))
|
|
808
|
+
);
|
|
809
|
+
}
|
|
801
810
|
|
|
802
811
|
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
803
812
|
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
@@ -937,6 +946,7 @@ var isType = (typename) => (node) => {
|
|
|
937
946
|
countryCodesToCurrencyCodes,
|
|
938
947
|
createSha256Hash,
|
|
939
948
|
defaultCurrencyCode,
|
|
949
|
+
errorToJSON,
|
|
940
950
|
formatCurrencyStr,
|
|
941
951
|
getCurrentLocale,
|
|
942
952
|
getErrorMsg,
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -7,26 +7,53 @@ declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
|
|
|
7
7
|
declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
|
|
8
8
|
|
|
9
9
|
declare const defaultCurrencyCode = "USD";
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* This enum identifies the unit of currency associated with a CurrencyAmount.
|
|
12
|
+
* *
|
|
13
|
+
*/
|
|
11
14
|
declare enum CurrencyUnit {
|
|
12
15
|
/**
|
|
13
|
-
* This is an enum value that represents values that could be added in the
|
|
14
|
-
* Clients should support unknown values as more of them could be
|
|
16
|
+
* This is an enum value that represents values that could be added in the
|
|
17
|
+
* future. Clients should support unknown values as more of them could be
|
|
18
|
+
* added without notice.
|
|
15
19
|
*/
|
|
16
20
|
FUTURE_VALUE = "FUTURE_VALUE",
|
|
17
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Bitcoin is the cryptocurrency native to the Bitcoin network.
|
|
23
|
+
* It is used as the native medium for value transfer for the Lightning
|
|
24
|
+
* Network. *
|
|
25
|
+
*/
|
|
18
26
|
BITCOIN = "BITCOIN",
|
|
19
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
|
|
29
|
+
* This is the unit most commonly used in Lightning transactions.
|
|
30
|
+
* *
|
|
31
|
+
*/
|
|
20
32
|
SATOSHI = "SATOSHI",
|
|
21
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
|
|
35
|
+
* instead when possible. *
|
|
36
|
+
*/
|
|
22
37
|
MILLISATOSHI = "MILLISATOSHI",
|
|
23
38
|
/** United States Dollar. **/
|
|
24
39
|
USD = "USD",
|
|
25
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
|
|
42
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
43
|
+
* *
|
|
44
|
+
*/
|
|
26
45
|
NANOBITCOIN = "NANOBITCOIN",
|
|
27
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
|
|
48
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
49
|
+
* *
|
|
50
|
+
*/
|
|
28
51
|
MICROBITCOIN = "MICROBITCOIN",
|
|
29
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
|
|
54
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
55
|
+
* *
|
|
56
|
+
*/
|
|
30
57
|
MILLIBITCOIN = "MILLIBITCOIN"
|
|
31
58
|
}
|
|
32
59
|
/** This object represents the value and unit for an amount of currency. **/
|
|
@@ -38,13 +65,15 @@ type CurrencyAmountType = {
|
|
|
38
65
|
/** The unit of user's preferred currency. **/
|
|
39
66
|
preferredCurrencyUnit: CurrencyUnit;
|
|
40
67
|
/**
|
|
41
|
-
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
42
|
-
* currency. For example, for USD, the value will be in
|
|
68
|
+
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
69
|
+
* of user's preferred currency. For example, for USD, the value will be in
|
|
70
|
+
* cents.
|
|
43
71
|
**/
|
|
44
72
|
preferredCurrencyValueRounded: number;
|
|
45
73
|
/**
|
|
46
|
-
* The approximate float value for this CurrencyAmount in the very base level
|
|
47
|
-
* currency. For example, for USD, the value will be in
|
|
74
|
+
* The approximate float 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.
|
|
48
77
|
**/
|
|
49
78
|
preferredCurrencyValueApprox: number;
|
|
50
79
|
};
|
|
@@ -103,6 +132,30 @@ declare const isBrowser: boolean;
|
|
|
103
132
|
declare const isNode: boolean;
|
|
104
133
|
declare const isTest: boolean;
|
|
105
134
|
|
|
135
|
+
type Maybe<T> = T | null | undefined;
|
|
136
|
+
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
137
|
+
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
138
|
+
} : never : T;
|
|
139
|
+
type ById<T> = {
|
|
140
|
+
[id: string]: T;
|
|
141
|
+
};
|
|
142
|
+
type OmitTypename<T> = Omit<T, "__typename">;
|
|
143
|
+
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
144
|
+
__typename: string;
|
|
145
|
+
}>(node: N | null | undefined) => node is Extract<N, {
|
|
146
|
+
__typename: T;
|
|
147
|
+
}>;
|
|
148
|
+
type DeepPartial<T> = T extends object ? {
|
|
149
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
150
|
+
} : T;
|
|
151
|
+
type JSONLiteral = string | number | boolean | null;
|
|
152
|
+
type JSONType = JSONLiteral | JSONType[] | {
|
|
153
|
+
[key: string]: JSONType;
|
|
154
|
+
};
|
|
155
|
+
type JSONObject = {
|
|
156
|
+
[key: string]: JSONType;
|
|
157
|
+
};
|
|
158
|
+
|
|
106
159
|
declare const isError: (e: unknown) => e is Error;
|
|
107
160
|
type ErrorWithMessage = {
|
|
108
161
|
message: string;
|
|
@@ -110,6 +163,7 @@ type ErrorWithMessage = {
|
|
|
110
163
|
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
111
164
|
declare const getErrorMsg: (e: unknown) => string;
|
|
112
165
|
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
166
|
+
declare function errorToJSON(err: unknown): JSONType;
|
|
113
167
|
|
|
114
168
|
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
115
169
|
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
@@ -203,21 +257,4 @@ declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getV
|
|
|
203
257
|
|
|
204
258
|
declare function sleep(ms: number): Promise<unknown>;
|
|
205
259
|
|
|
206
|
-
|
|
207
|
-
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
208
|
-
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
209
|
-
} : never : T;
|
|
210
|
-
type ById<T> = {
|
|
211
|
-
[id: string]: T;
|
|
212
|
-
};
|
|
213
|
-
type OmitTypename<T> = Omit<T, "__typename">;
|
|
214
|
-
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
215
|
-
__typename: string;
|
|
216
|
-
}>(node: N | null | undefined) => node is Extract<N, {
|
|
217
|
-
__typename: T;
|
|
218
|
-
}>;
|
|
219
|
-
type DeepPartial<T> = T extends object ? {
|
|
220
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
221
|
-
} : T;
|
|
222
|
-
|
|
223
|
-
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
|
|
260
|
+
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, JSONLiteral, JSONObject, JSONType, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, errorToJSON, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -7,26 +7,53 @@ declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
|
|
|
7
7
|
declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
|
|
8
8
|
|
|
9
9
|
declare const defaultCurrencyCode = "USD";
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* This enum identifies the unit of currency associated with a CurrencyAmount.
|
|
12
|
+
* *
|
|
13
|
+
*/
|
|
11
14
|
declare enum CurrencyUnit {
|
|
12
15
|
/**
|
|
13
|
-
* This is an enum value that represents values that could be added in the
|
|
14
|
-
* Clients should support unknown values as more of them could be
|
|
16
|
+
* This is an enum value that represents values that could be added in the
|
|
17
|
+
* future. Clients should support unknown values as more of them could be
|
|
18
|
+
* added without notice.
|
|
15
19
|
*/
|
|
16
20
|
FUTURE_VALUE = "FUTURE_VALUE",
|
|
17
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Bitcoin is the cryptocurrency native to the Bitcoin network.
|
|
23
|
+
* It is used as the native medium for value transfer for the Lightning
|
|
24
|
+
* Network. *
|
|
25
|
+
*/
|
|
18
26
|
BITCOIN = "BITCOIN",
|
|
19
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
|
|
29
|
+
* This is the unit most commonly used in Lightning transactions.
|
|
30
|
+
* *
|
|
31
|
+
*/
|
|
20
32
|
SATOSHI = "SATOSHI",
|
|
21
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
|
|
35
|
+
* instead when possible. *
|
|
36
|
+
*/
|
|
22
37
|
MILLISATOSHI = "MILLISATOSHI",
|
|
23
38
|
/** United States Dollar. **/
|
|
24
39
|
USD = "USD",
|
|
25
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
|
|
42
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
43
|
+
* *
|
|
44
|
+
*/
|
|
26
45
|
NANOBITCOIN = "NANOBITCOIN",
|
|
27
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
|
|
48
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
49
|
+
* *
|
|
50
|
+
*/
|
|
28
51
|
MICROBITCOIN = "MICROBITCOIN",
|
|
29
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
|
|
54
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
55
|
+
* *
|
|
56
|
+
*/
|
|
30
57
|
MILLIBITCOIN = "MILLIBITCOIN"
|
|
31
58
|
}
|
|
32
59
|
/** This object represents the value and unit for an amount of currency. **/
|
|
@@ -38,13 +65,15 @@ type CurrencyAmountType = {
|
|
|
38
65
|
/** The unit of user's preferred currency. **/
|
|
39
66
|
preferredCurrencyUnit: CurrencyUnit;
|
|
40
67
|
/**
|
|
41
|
-
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
42
|
-
* currency. For example, for USD, the value will be in
|
|
68
|
+
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
69
|
+
* of user's preferred currency. For example, for USD, the value will be in
|
|
70
|
+
* cents.
|
|
43
71
|
**/
|
|
44
72
|
preferredCurrencyValueRounded: number;
|
|
45
73
|
/**
|
|
46
|
-
* The approximate float value for this CurrencyAmount in the very base level
|
|
47
|
-
* currency. For example, for USD, the value will be in
|
|
74
|
+
* The approximate float 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.
|
|
48
77
|
**/
|
|
49
78
|
preferredCurrencyValueApprox: number;
|
|
50
79
|
};
|
|
@@ -103,6 +132,30 @@ declare const isBrowser: boolean;
|
|
|
103
132
|
declare const isNode: boolean;
|
|
104
133
|
declare const isTest: boolean;
|
|
105
134
|
|
|
135
|
+
type Maybe<T> = T | null | undefined;
|
|
136
|
+
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
137
|
+
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
138
|
+
} : never : T;
|
|
139
|
+
type ById<T> = {
|
|
140
|
+
[id: string]: T;
|
|
141
|
+
};
|
|
142
|
+
type OmitTypename<T> = Omit<T, "__typename">;
|
|
143
|
+
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
144
|
+
__typename: string;
|
|
145
|
+
}>(node: N | null | undefined) => node is Extract<N, {
|
|
146
|
+
__typename: T;
|
|
147
|
+
}>;
|
|
148
|
+
type DeepPartial<T> = T extends object ? {
|
|
149
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
150
|
+
} : T;
|
|
151
|
+
type JSONLiteral = string | number | boolean | null;
|
|
152
|
+
type JSONType = JSONLiteral | JSONType[] | {
|
|
153
|
+
[key: string]: JSONType;
|
|
154
|
+
};
|
|
155
|
+
type JSONObject = {
|
|
156
|
+
[key: string]: JSONType;
|
|
157
|
+
};
|
|
158
|
+
|
|
106
159
|
declare const isError: (e: unknown) => e is Error;
|
|
107
160
|
type ErrorWithMessage = {
|
|
108
161
|
message: string;
|
|
@@ -110,6 +163,7 @@ type ErrorWithMessage = {
|
|
|
110
163
|
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
111
164
|
declare const getErrorMsg: (e: unknown) => string;
|
|
112
165
|
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
166
|
+
declare function errorToJSON(err: unknown): JSONType;
|
|
113
167
|
|
|
114
168
|
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
115
169
|
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
@@ -203,21 +257,4 @@ declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getV
|
|
|
203
257
|
|
|
204
258
|
declare function sleep(ms: number): Promise<unknown>;
|
|
205
259
|
|
|
206
|
-
|
|
207
|
-
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
208
|
-
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
209
|
-
} : never : T;
|
|
210
|
-
type ById<T> = {
|
|
211
|
-
[id: string]: T;
|
|
212
|
-
};
|
|
213
|
-
type OmitTypename<T> = Omit<T, "__typename">;
|
|
214
|
-
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
215
|
-
__typename: string;
|
|
216
|
-
}>(node: N | null | undefined) => node is Extract<N, {
|
|
217
|
-
__typename: T;
|
|
218
|
-
}>;
|
|
219
|
-
type DeepPartial<T> = T extends object ? {
|
|
220
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
221
|
-
} : T;
|
|
222
|
-
|
|
223
|
-
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
|
|
260
|
+
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, JSONLiteral, JSONObject, JSONType, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, errorToJSON, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
|
package/dist/utils/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
countryCodesToCurrencyCodes,
|
|
11
11
|
createSha256Hash,
|
|
12
12
|
defaultCurrencyCode,
|
|
13
|
+
errorToJSON,
|
|
13
14
|
formatCurrencyStr,
|
|
14
15
|
getCurrentLocale,
|
|
15
16
|
getErrorMsg,
|
|
@@ -34,7 +35,7 @@ import {
|
|
|
34
35
|
separateCurrencyStrParts,
|
|
35
36
|
sleep,
|
|
36
37
|
urlsafe_b64decode
|
|
37
|
-
} from "../chunk-
|
|
38
|
+
} from "../chunk-BYCLLNFL.js";
|
|
38
39
|
export {
|
|
39
40
|
CurrencyUnit,
|
|
40
41
|
abbrCurrencyUnit,
|
|
@@ -47,6 +48,7 @@ export {
|
|
|
47
48
|
countryCodesToCurrencyCodes,
|
|
48
49
|
createSha256Hash,
|
|
49
50
|
defaultCurrencyCode,
|
|
51
|
+
errorToJSON,
|
|
50
52
|
formatCurrencyStr,
|
|
51
53
|
getCurrentLocale,
|
|
52
54
|
getErrorMsg,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsparkdev/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Lightspark JS SDK",
|
|
5
5
|
"author": "Lightspark Inc.",
|
|
6
6
|
"keywords": [
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
],
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "yarn tsc && tsup",
|
|
64
|
-
"build:watch": "yarn build --watch",
|
|
64
|
+
"build:watch": "yarn build --watch --clean=false",
|
|
65
65
|
"clean": "rm -rf .turbo && rm -rf dist",
|
|
66
66
|
"dev": "yarn build -- --watch",
|
|
67
67
|
"format:fix": "prettier src --write",
|
|
@@ -101,6 +101,6 @@
|
|
|
101
101
|
"ts-jest": "^29.1.1",
|
|
102
102
|
"tsc-absolute": "^1.0.1",
|
|
103
103
|
"tsup": "^7.2.0",
|
|
104
|
-
"typescript": "^
|
|
104
|
+
"typescript": "^5.0.0"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -5,6 +5,11 @@ export const ConfigKeys = {
|
|
|
5
5
|
export type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
|
|
6
6
|
|
|
7
7
|
export const getLocalStorageConfigItem = (key: ConfigKeys) => {
|
|
8
|
+
return getLocalStorageBoolean(key);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getLocalStorageBoolean = (key: string) => {
|
|
12
|
+
/* localStorage is not available in all contexts, use try/catch: */
|
|
8
13
|
try {
|
|
9
14
|
return localStorage.getItem(key) === "1";
|
|
10
15
|
} catch (e) {
|
package/src/crypto/crypto.ts
CHANGED
|
@@ -154,8 +154,7 @@ const decrypt = async (
|
|
|
154
154
|
const salt = decoded.slice(decoded.length - 8, decoded.length);
|
|
155
155
|
const nonce = decoded.slice(0, 12);
|
|
156
156
|
const cipherText = decoded.slice(12, decoded.length - 8);
|
|
157
|
-
|
|
158
|
-
const [key, _iv] = await deriveKey(
|
|
157
|
+
const [key /* , _iv */] = await deriveKey(
|
|
159
158
|
password,
|
|
160
159
|
salt,
|
|
161
160
|
header.i,
|
package/src/crypto/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
2
|
|
|
3
|
-
export * from "./crypto.js";
|
|
4
3
|
export * from "./KeyOrAlias.js";
|
|
5
4
|
export { default as LightsparkSigningException } from "./LightsparkSigningException.js";
|
|
6
5
|
export { default as NodeKeyCache } from "./NodeKeyCache.js";
|
|
7
6
|
export * from "./SigningKey.js";
|
|
7
|
+
export * from "./crypto.js";
|
|
8
8
|
export * from "./types.js";
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
2
|
|
|
3
|
-
export * from "./auth/index.js";
|
|
4
|
-
export * from "./constants/index.js";
|
|
5
|
-
export * from "./crypto/index.js";
|
|
6
3
|
export { default as LightsparkException } from "./LightsparkException.js";
|
|
7
4
|
export { Logger } from "./Logger.js";
|
|
8
|
-
export * from "./requester/index.js";
|
|
9
5
|
export {
|
|
10
|
-
apiDomainForEnvironment,
|
|
11
6
|
default as ServerEnvironment,
|
|
7
|
+
apiDomainForEnvironment,
|
|
12
8
|
} from "./ServerEnvironment.js";
|
|
9
|
+
export * from "./auth/index.js";
|
|
10
|
+
export * from "./constants/index.js";
|
|
11
|
+
export * from "./crypto/index.js";
|
|
12
|
+
export * from "./requester/index.js";
|
|
13
13
|
export * from "./utils/index.js";
|
package/src/requester/Query.ts
CHANGED
|
@@ -7,7 +7,10 @@ type Query<T> = {
|
|
|
7
7
|
/** The variables that will be passed to the query. **/
|
|
8
8
|
variables?: { [key: string]: unknown };
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The function that will be called to construct the object from the
|
|
12
|
+
* response. *
|
|
13
|
+
*/
|
|
11
14
|
constructObject: (rawData: any) => T; // eslint-disable-line @typescript-eslint/no-explicit-any -- LIG-3400
|
|
12
15
|
|
|
13
16
|
/** The id of the node that will be used to sign the query. **/
|