@lightsparkdev/core 1.0.10 → 1.0.11
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 +6 -0
- package/dist/index.cjs +76 -72
- package/dist/index.d.cts +40 -37
- package/dist/index.d.ts +40 -37
- package/dist/index.js +64 -60
- package/dist/utils/index.d.cts +42 -13
- package/dist/utils/index.d.ts +42 -13
- package/dist/utils/index.js +1 -1
- package/package.json +3 -3
- 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/localeToCurrencyCodes.ts +3 -1
- package/src/utils/types.ts +1 -1
- package/dist/{chunk-MAZP7ETK.js → chunk-F3XHLUGC.js} +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -99,6 +99,60 @@ var LightsparkException = class extends Error {
|
|
|
99
99
|
};
|
|
100
100
|
var LightsparkException_default = LightsparkException;
|
|
101
101
|
|
|
102
|
+
// src/utils/environment.ts
|
|
103
|
+
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
104
|
+
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
105
|
+
var isTest = isNode && process.env.NODE_ENV === "test";
|
|
106
|
+
|
|
107
|
+
// src/Logger.ts
|
|
108
|
+
var Logger = class {
|
|
109
|
+
context;
|
|
110
|
+
loggingEnabled = false;
|
|
111
|
+
constructor(loggerContext, getLoggingEnabled) {
|
|
112
|
+
this.context = loggerContext;
|
|
113
|
+
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
114
|
+
}
|
|
115
|
+
async updateLoggingEnabled(getLoggingEnabled) {
|
|
116
|
+
if (getLoggingEnabled) {
|
|
117
|
+
this.loggingEnabled = await getLoggingEnabled();
|
|
118
|
+
} else if (isTest) {
|
|
119
|
+
this.loggingEnabled = true;
|
|
120
|
+
} else if (isBrowser) {
|
|
121
|
+
try {
|
|
122
|
+
this.loggingEnabled = getLocalStorageConfigItem(
|
|
123
|
+
ConfigKeys.LoggingEnabled
|
|
124
|
+
);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (this.loggingEnabled) {
|
|
129
|
+
console.log(`[${this.context}] Logging enabled`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
info(message, ...rest) {
|
|
133
|
+
if (this.loggingEnabled) {
|
|
134
|
+
console.log(`[${this.context}] ${message}`, ...rest);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var logger = new Logger("@lightsparkdev/core");
|
|
139
|
+
|
|
140
|
+
// src/ServerEnvironment.ts
|
|
141
|
+
var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
|
|
142
|
+
ServerEnvironment2["PRODUCTION"] = "production";
|
|
143
|
+
ServerEnvironment2["DEV"] = "dev";
|
|
144
|
+
return ServerEnvironment2;
|
|
145
|
+
})(ServerEnvironment || {});
|
|
146
|
+
var apiDomainForEnvironment = (environment) => {
|
|
147
|
+
switch (environment) {
|
|
148
|
+
case "dev" /* DEV */:
|
|
149
|
+
return "api.dev.dev.sparkinfra.net";
|
|
150
|
+
case "production" /* PRODUCTION */:
|
|
151
|
+
return "api.lightspark.com";
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var ServerEnvironment_default = ServerEnvironment;
|
|
155
|
+
|
|
102
156
|
// src/auth/LightsparkAuthException.ts
|
|
103
157
|
var LightsparkAuthException = class extends LightsparkException_default {
|
|
104
158
|
constructor(message, extraInfo) {
|
|
@@ -133,6 +187,23 @@ var getLocalStorageConfigItem = (key) => {
|
|
|
133
187
|
}
|
|
134
188
|
};
|
|
135
189
|
|
|
190
|
+
// src/crypto/KeyOrAlias.ts
|
|
191
|
+
var KeyOrAlias = {
|
|
192
|
+
key: (key) => ({ key }),
|
|
193
|
+
alias: (alias) => ({ alias })
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// src/crypto/LightsparkSigningException.ts
|
|
197
|
+
var LightsparkSigningException = class extends LightsparkException_default {
|
|
198
|
+
constructor(message, extraInfo) {
|
|
199
|
+
super("SigningException", message, extraInfo);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var LightsparkSigningException_default = LightsparkSigningException;
|
|
203
|
+
|
|
204
|
+
// src/crypto/NodeKeyCache.ts
|
|
205
|
+
var import_auto_bind = __toESM(require("auto-bind"), 1);
|
|
206
|
+
|
|
136
207
|
// src/utils/base64.ts
|
|
137
208
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
138
209
|
var Base64 = {
|
|
@@ -176,14 +247,6 @@ var b64encode = (data) => {
|
|
|
176
247
|
);
|
|
177
248
|
};
|
|
178
249
|
|
|
179
|
-
// src/crypto/LightsparkSigningException.ts
|
|
180
|
-
var LightsparkSigningException = class extends LightsparkException_default {
|
|
181
|
-
constructor(message, extraInfo) {
|
|
182
|
-
super("SigningException", message, extraInfo);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
var LightsparkSigningException_default = LightsparkSigningException;
|
|
186
|
-
|
|
187
250
|
// src/crypto/crypto.ts
|
|
188
251
|
var getCrypto = () => {
|
|
189
252
|
let cryptoImplPromise;
|
|
@@ -278,7 +341,10 @@ var decrypt = async (header_json, ciphertext, password) => {
|
|
|
278
341
|
const salt = decoded.slice(decoded.length - 8, decoded.length);
|
|
279
342
|
const nonce = decoded.slice(0, 12);
|
|
280
343
|
const cipherText = decoded.slice(12, decoded.length - 8);
|
|
281
|
-
const [
|
|
344
|
+
const [
|
|
345
|
+
key
|
|
346
|
+
/* , _iv */
|
|
347
|
+
] = await deriveKey(
|
|
282
348
|
password,
|
|
283
349
|
salt,
|
|
284
350
|
header.i,
|
|
@@ -388,23 +454,9 @@ var DefaultCrypto = {
|
|
|
388
454
|
importPrivateSigningKey
|
|
389
455
|
};
|
|
390
456
|
|
|
391
|
-
// src/crypto/KeyOrAlias.ts
|
|
392
|
-
var KeyOrAlias = {
|
|
393
|
-
key: (key) => ({ key }),
|
|
394
|
-
alias: (alias) => ({ alias })
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
// src/crypto/NodeKeyCache.ts
|
|
398
|
-
var import_auto_bind = __toESM(require("auto-bind"), 1);
|
|
399
|
-
|
|
400
457
|
// src/crypto/SigningKey.ts
|
|
401
458
|
var import_secp256k1 = __toESM(require("secp256k1"), 1);
|
|
402
459
|
|
|
403
|
-
// src/utils/environment.ts
|
|
404
|
-
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
405
|
-
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
406
|
-
var isTest = isNode && process.env.NODE_ENV === "test";
|
|
407
|
-
|
|
408
460
|
// src/utils/hex.ts
|
|
409
461
|
var bytesToHex = (bytes) => {
|
|
410
462
|
return bytes.reduce((acc, byte) => {
|
|
@@ -1295,39 +1347,6 @@ var NodeKeyCache = class {
|
|
|
1295
1347
|
};
|
|
1296
1348
|
var NodeKeyCache_default = NodeKeyCache;
|
|
1297
1349
|
|
|
1298
|
-
// src/Logger.ts
|
|
1299
|
-
var Logger = class {
|
|
1300
|
-
context;
|
|
1301
|
-
loggingEnabled = false;
|
|
1302
|
-
constructor(loggerContext, getLoggingEnabled) {
|
|
1303
|
-
this.context = loggerContext;
|
|
1304
|
-
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
1305
|
-
}
|
|
1306
|
-
async updateLoggingEnabled(getLoggingEnabled) {
|
|
1307
|
-
if (getLoggingEnabled) {
|
|
1308
|
-
this.loggingEnabled = await getLoggingEnabled();
|
|
1309
|
-
} else if (isTest) {
|
|
1310
|
-
this.loggingEnabled = true;
|
|
1311
|
-
} else if (isBrowser) {
|
|
1312
|
-
try {
|
|
1313
|
-
this.loggingEnabled = getLocalStorageConfigItem(
|
|
1314
|
-
ConfigKeys.LoggingEnabled
|
|
1315
|
-
);
|
|
1316
|
-
} catch (e) {
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
if (this.loggingEnabled) {
|
|
1320
|
-
console.log(`[${this.context}] Logging enabled`);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
info(message, ...rest) {
|
|
1324
|
-
if (this.loggingEnabled) {
|
|
1325
|
-
console.log(`[${this.context}] ${message}`, ...rest);
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
};
|
|
1329
|
-
var logger = new Logger("@lightsparkdev/core");
|
|
1330
|
-
|
|
1331
1350
|
// src/requester/Requester.ts
|
|
1332
1351
|
var import_auto_bind2 = __toESM(require("auto-bind"), 1);
|
|
1333
1352
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
@@ -1452,6 +1471,7 @@ var Requester = class {
|
|
|
1452
1471
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
1453
1472
|
logger.info(`Requester.makeRawRequest`, {
|
|
1454
1473
|
url,
|
|
1474
|
+
operationName: operation,
|
|
1455
1475
|
variables
|
|
1456
1476
|
});
|
|
1457
1477
|
const response = await fetch(url, {
|
|
@@ -1522,22 +1542,6 @@ var Requester = class {
|
|
|
1522
1542
|
}
|
|
1523
1543
|
};
|
|
1524
1544
|
var Requester_default = Requester;
|
|
1525
|
-
|
|
1526
|
-
// src/ServerEnvironment.ts
|
|
1527
|
-
var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
|
|
1528
|
-
ServerEnvironment2["PRODUCTION"] = "production";
|
|
1529
|
-
ServerEnvironment2["DEV"] = "dev";
|
|
1530
|
-
return ServerEnvironment2;
|
|
1531
|
-
})(ServerEnvironment || {});
|
|
1532
|
-
var apiDomainForEnvironment = (environment) => {
|
|
1533
|
-
switch (environment) {
|
|
1534
|
-
case "dev" /* DEV */:
|
|
1535
|
-
return "api.dev.dev.sparkinfra.net";
|
|
1536
|
-
case "production" /* PRODUCTION */:
|
|
1537
|
-
return "api.lightspark.com";
|
|
1538
|
-
}
|
|
1539
|
-
};
|
|
1540
|
-
var ServerEnvironment_default = ServerEnvironment;
|
|
1541
1545
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1542
1546
|
0 && (module.exports = {
|
|
1543
1547
|
ConfigKeys,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { Observable } from 'zen-observable-ts';
|
|
2
2
|
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 } from './utils/index.cjs';
|
|
3
3
|
|
|
4
|
+
declare class LightsparkException extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
extraInfo: Record<string, unknown> | undefined;
|
|
8
|
+
constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
12
|
+
declare class Logger {
|
|
13
|
+
context: string;
|
|
14
|
+
loggingEnabled: boolean;
|
|
15
|
+
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
16
|
+
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
17
|
+
info(message: string, ...rest: unknown[]): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare enum ServerEnvironment {
|
|
21
|
+
PRODUCTION = "production",
|
|
22
|
+
DEV = "dev"
|
|
23
|
+
}
|
|
24
|
+
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
25
|
+
|
|
4
26
|
type Headers = Record<string, string>;
|
|
5
27
|
type WsConnectionParams = Record<string, unknown>;
|
|
6
28
|
interface AuthProvider {
|
|
@@ -9,13 +31,6 @@ interface AuthProvider {
|
|
|
9
31
|
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
10
32
|
}
|
|
11
33
|
|
|
12
|
-
declare class LightsparkException extends Error {
|
|
13
|
-
code: string;
|
|
14
|
-
message: string;
|
|
15
|
-
extraInfo: Record<string, unknown> | undefined;
|
|
16
|
-
constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
34
|
declare class LightsparkAuthException extends LightsparkException {
|
|
20
35
|
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
21
36
|
}
|
|
@@ -33,6 +48,20 @@ declare const ConfigKeys: {
|
|
|
33
48
|
type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
|
|
34
49
|
declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
|
|
35
50
|
|
|
51
|
+
type OnlyKey = {
|
|
52
|
+
key: string;
|
|
53
|
+
alias?: never;
|
|
54
|
+
};
|
|
55
|
+
type OnlyAlias = {
|
|
56
|
+
key?: never;
|
|
57
|
+
alias: string;
|
|
58
|
+
};
|
|
59
|
+
type KeyOrAliasType = OnlyKey | OnlyAlias;
|
|
60
|
+
declare const KeyOrAlias: {
|
|
61
|
+
key: (key: string) => OnlyKey;
|
|
62
|
+
alias: (alias: string) => OnlyAlias;
|
|
63
|
+
};
|
|
64
|
+
|
|
36
65
|
declare class LightsparkSigningException extends LightsparkException {
|
|
37
66
|
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
38
67
|
}
|
|
@@ -60,20 +89,6 @@ declare const DefaultCrypto: {
|
|
|
60
89
|
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
61
90
|
};
|
|
62
91
|
|
|
63
|
-
type OnlyKey = {
|
|
64
|
-
key: string;
|
|
65
|
-
alias?: never;
|
|
66
|
-
};
|
|
67
|
-
type OnlyAlias = {
|
|
68
|
-
key?: never;
|
|
69
|
-
alias: string;
|
|
70
|
-
};
|
|
71
|
-
type KeyOrAliasType = OnlyKey | OnlyAlias;
|
|
72
|
-
declare const KeyOrAlias: {
|
|
73
|
-
key: (key: string) => OnlyKey;
|
|
74
|
-
alias: (alias: string) => OnlyAlias;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
92
|
interface Alias {
|
|
78
93
|
alias: string;
|
|
79
94
|
}
|
|
@@ -109,15 +124,6 @@ declare class NodeKeyCache {
|
|
|
109
124
|
private stripPemTags;
|
|
110
125
|
}
|
|
111
126
|
|
|
112
|
-
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
113
|
-
declare class Logger {
|
|
114
|
-
context: string;
|
|
115
|
-
loggingEnabled: boolean;
|
|
116
|
-
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
117
|
-
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
118
|
-
info(message: string, ...rest: unknown[]): void;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
127
|
type Query<T> = {
|
|
122
128
|
/** The string representation of the query payload for graphQL. **/
|
|
123
129
|
queryPayload: string;
|
|
@@ -125,7 +131,10 @@ type Query<T> = {
|
|
|
125
131
|
variables?: {
|
|
126
132
|
[key: string]: unknown;
|
|
127
133
|
};
|
|
128
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* The function that will be called to construct the object from the
|
|
136
|
+
* response. *
|
|
137
|
+
*/
|
|
129
138
|
constructObject: (rawData: any) => T;
|
|
130
139
|
/** The id of the node that will be used to sign the query. **/
|
|
131
140
|
signingNodeId?: string;
|
|
@@ -156,10 +165,4 @@ declare class Requester {
|
|
|
156
165
|
private addSigningDataIfNeeded;
|
|
157
166
|
}
|
|
158
167
|
|
|
159
|
-
declare enum ServerEnvironment {
|
|
160
|
-
PRODUCTION = "production",
|
|
161
|
-
DEV = "dev"
|
|
162
|
-
}
|
|
163
|
-
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
164
|
-
|
|
165
168
|
export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageConfigItem };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import { Observable } from 'zen-observable-ts';
|
|
2
2
|
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 } from './utils/index.js';
|
|
3
3
|
|
|
4
|
+
declare class LightsparkException extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
extraInfo: Record<string, unknown> | undefined;
|
|
8
|
+
constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
12
|
+
declare class Logger {
|
|
13
|
+
context: string;
|
|
14
|
+
loggingEnabled: boolean;
|
|
15
|
+
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
16
|
+
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
17
|
+
info(message: string, ...rest: unknown[]): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare enum ServerEnvironment {
|
|
21
|
+
PRODUCTION = "production",
|
|
22
|
+
DEV = "dev"
|
|
23
|
+
}
|
|
24
|
+
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
25
|
+
|
|
4
26
|
type Headers = Record<string, string>;
|
|
5
27
|
type WsConnectionParams = Record<string, unknown>;
|
|
6
28
|
interface AuthProvider {
|
|
@@ -9,13 +31,6 @@ interface AuthProvider {
|
|
|
9
31
|
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
10
32
|
}
|
|
11
33
|
|
|
12
|
-
declare class LightsparkException extends Error {
|
|
13
|
-
code: string;
|
|
14
|
-
message: string;
|
|
15
|
-
extraInfo: Record<string, unknown> | undefined;
|
|
16
|
-
constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
34
|
declare class LightsparkAuthException extends LightsparkException {
|
|
20
35
|
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
21
36
|
}
|
|
@@ -33,6 +48,20 @@ declare const ConfigKeys: {
|
|
|
33
48
|
type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
|
|
34
49
|
declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
|
|
35
50
|
|
|
51
|
+
type OnlyKey = {
|
|
52
|
+
key: string;
|
|
53
|
+
alias?: never;
|
|
54
|
+
};
|
|
55
|
+
type OnlyAlias = {
|
|
56
|
+
key?: never;
|
|
57
|
+
alias: string;
|
|
58
|
+
};
|
|
59
|
+
type KeyOrAliasType = OnlyKey | OnlyAlias;
|
|
60
|
+
declare const KeyOrAlias: {
|
|
61
|
+
key: (key: string) => OnlyKey;
|
|
62
|
+
alias: (alias: string) => OnlyAlias;
|
|
63
|
+
};
|
|
64
|
+
|
|
36
65
|
declare class LightsparkSigningException extends LightsparkException {
|
|
37
66
|
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
38
67
|
}
|
|
@@ -60,20 +89,6 @@ declare const DefaultCrypto: {
|
|
|
60
89
|
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
61
90
|
};
|
|
62
91
|
|
|
63
|
-
type OnlyKey = {
|
|
64
|
-
key: string;
|
|
65
|
-
alias?: never;
|
|
66
|
-
};
|
|
67
|
-
type OnlyAlias = {
|
|
68
|
-
key?: never;
|
|
69
|
-
alias: string;
|
|
70
|
-
};
|
|
71
|
-
type KeyOrAliasType = OnlyKey | OnlyAlias;
|
|
72
|
-
declare const KeyOrAlias: {
|
|
73
|
-
key: (key: string) => OnlyKey;
|
|
74
|
-
alias: (alias: string) => OnlyAlias;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
92
|
interface Alias {
|
|
78
93
|
alias: string;
|
|
79
94
|
}
|
|
@@ -109,15 +124,6 @@ declare class NodeKeyCache {
|
|
|
109
124
|
private stripPemTags;
|
|
110
125
|
}
|
|
111
126
|
|
|
112
|
-
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
113
|
-
declare class Logger {
|
|
114
|
-
context: string;
|
|
115
|
-
loggingEnabled: boolean;
|
|
116
|
-
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
117
|
-
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
118
|
-
info(message: string, ...rest: unknown[]): void;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
127
|
type Query<T> = {
|
|
122
128
|
/** The string representation of the query payload for graphQL. **/
|
|
123
129
|
queryPayload: string;
|
|
@@ -125,7 +131,10 @@ type Query<T> = {
|
|
|
125
131
|
variables?: {
|
|
126
132
|
[key: string]: unknown;
|
|
127
133
|
};
|
|
128
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* The function that will be called to construct the object from the
|
|
136
|
+
* response. *
|
|
137
|
+
*/
|
|
129
138
|
constructObject: (rawData: any) => T;
|
|
130
139
|
/** The id of the node that will be used to sign the query. **/
|
|
131
140
|
signingNodeId?: string;
|
|
@@ -156,10 +165,4 @@ declare class Requester {
|
|
|
156
165
|
private addSigningDataIfNeeded;
|
|
157
166
|
}
|
|
158
167
|
|
|
159
|
-
declare enum ServerEnvironment {
|
|
160
|
-
PRODUCTION = "production",
|
|
161
|
-
DEV = "dev"
|
|
162
|
-
}
|
|
163
|
-
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
164
|
-
|
|
165
168
|
export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageConfigItem };
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,56 @@ import {
|
|
|
35
35
|
separateCurrencyStrParts,
|
|
36
36
|
sleep,
|
|
37
37
|
urlsafe_b64decode
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-F3XHLUGC.js";
|
|
39
|
+
|
|
40
|
+
// src/Logger.ts
|
|
41
|
+
var Logger = class {
|
|
42
|
+
context;
|
|
43
|
+
loggingEnabled = false;
|
|
44
|
+
constructor(loggerContext, getLoggingEnabled) {
|
|
45
|
+
this.context = loggerContext;
|
|
46
|
+
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
47
|
+
}
|
|
48
|
+
async updateLoggingEnabled(getLoggingEnabled) {
|
|
49
|
+
if (getLoggingEnabled) {
|
|
50
|
+
this.loggingEnabled = await getLoggingEnabled();
|
|
51
|
+
} else if (isTest) {
|
|
52
|
+
this.loggingEnabled = true;
|
|
53
|
+
} else if (isBrowser) {
|
|
54
|
+
try {
|
|
55
|
+
this.loggingEnabled = getLocalStorageConfigItem(
|
|
56
|
+
ConfigKeys.LoggingEnabled
|
|
57
|
+
);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (this.loggingEnabled) {
|
|
62
|
+
console.log(`[${this.context}] Logging enabled`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
info(message, ...rest) {
|
|
66
|
+
if (this.loggingEnabled) {
|
|
67
|
+
console.log(`[${this.context}] ${message}`, ...rest);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var logger = new Logger("@lightsparkdev/core");
|
|
72
|
+
|
|
73
|
+
// src/ServerEnvironment.ts
|
|
74
|
+
var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
|
|
75
|
+
ServerEnvironment2["PRODUCTION"] = "production";
|
|
76
|
+
ServerEnvironment2["DEV"] = "dev";
|
|
77
|
+
return ServerEnvironment2;
|
|
78
|
+
})(ServerEnvironment || {});
|
|
79
|
+
var apiDomainForEnvironment = (environment) => {
|
|
80
|
+
switch (environment) {
|
|
81
|
+
case "dev" /* DEV */:
|
|
82
|
+
return "api.dev.dev.sparkinfra.net";
|
|
83
|
+
case "production" /* PRODUCTION */:
|
|
84
|
+
return "api.lightspark.com";
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var ServerEnvironment_default = ServerEnvironment;
|
|
39
88
|
|
|
40
89
|
// src/auth/LightsparkAuthException.ts
|
|
41
90
|
var LightsparkAuthException = class extends LightsparkException_default {
|
|
@@ -71,6 +120,12 @@ var getLocalStorageConfigItem = (key) => {
|
|
|
71
120
|
}
|
|
72
121
|
};
|
|
73
122
|
|
|
123
|
+
// src/crypto/KeyOrAlias.ts
|
|
124
|
+
var KeyOrAlias = {
|
|
125
|
+
key: (key) => ({ key }),
|
|
126
|
+
alias: (alias) => ({ alias })
|
|
127
|
+
};
|
|
128
|
+
|
|
74
129
|
// src/crypto/LightsparkSigningException.ts
|
|
75
130
|
var LightsparkSigningException = class extends LightsparkException_default {
|
|
76
131
|
constructor(message, extraInfo) {
|
|
@@ -79,6 +134,9 @@ var LightsparkSigningException = class extends LightsparkException_default {
|
|
|
79
134
|
};
|
|
80
135
|
var LightsparkSigningException_default = LightsparkSigningException;
|
|
81
136
|
|
|
137
|
+
// src/crypto/NodeKeyCache.ts
|
|
138
|
+
import autoBind from "auto-bind";
|
|
139
|
+
|
|
82
140
|
// src/crypto/crypto.ts
|
|
83
141
|
var getCrypto = () => {
|
|
84
142
|
let cryptoImplPromise;
|
|
@@ -173,7 +231,10 @@ var decrypt = async (header_json, ciphertext, password) => {
|
|
|
173
231
|
const salt = decoded.slice(decoded.length - 8, decoded.length);
|
|
174
232
|
const nonce = decoded.slice(0, 12);
|
|
175
233
|
const cipherText = decoded.slice(12, decoded.length - 8);
|
|
176
|
-
const [
|
|
234
|
+
const [
|
|
235
|
+
key
|
|
236
|
+
/* , _iv */
|
|
237
|
+
] = await deriveKey(
|
|
177
238
|
password,
|
|
178
239
|
salt,
|
|
179
240
|
header.i,
|
|
@@ -283,15 +344,6 @@ var DefaultCrypto = {
|
|
|
283
344
|
importPrivateSigningKey
|
|
284
345
|
};
|
|
285
346
|
|
|
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
347
|
// src/crypto/SigningKey.ts
|
|
296
348
|
import secp256k1 from "secp256k1";
|
|
297
349
|
function isAlias(key) {
|
|
@@ -388,39 +440,6 @@ var NodeKeyCache = class {
|
|
|
388
440
|
};
|
|
389
441
|
var NodeKeyCache_default = NodeKeyCache;
|
|
390
442
|
|
|
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
443
|
// src/requester/Requester.ts
|
|
425
444
|
import autoBind2 from "auto-bind";
|
|
426
445
|
import dayjs from "dayjs";
|
|
@@ -545,6 +564,7 @@ var Requester = class {
|
|
|
545
564
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
546
565
|
logger.info(`Requester.makeRawRequest`, {
|
|
547
566
|
url,
|
|
567
|
+
operationName: operation,
|
|
548
568
|
variables
|
|
549
569
|
});
|
|
550
570
|
const response = await fetch(url, {
|
|
@@ -615,22 +635,6 @@ var Requester = class {
|
|
|
615
635
|
}
|
|
616
636
|
};
|
|
617
637
|
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
638
|
export {
|
|
635
639
|
ConfigKeys,
|
|
636
640
|
CurrencyUnit,
|
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
|
};
|
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
|
};
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsparkdev/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
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
|
}
|
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. **/
|
package/src/utils/currency.ts
CHANGED
|
@@ -7,26 +7,53 @@ import { isNumber, round } from "./numbers.js";
|
|
|
7
7
|
|
|
8
8
|
export const defaultCurrencyCode = "USD";
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* This enum identifies the unit of currency associated with a CurrencyAmount.
|
|
12
|
+
* *
|
|
13
|
+
*/
|
|
11
14
|
export 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
|
|
|
@@ -39,13 +66,15 @@ export type CurrencyAmountType = {
|
|
|
39
66
|
/** The unit of user's preferred currency. **/
|
|
40
67
|
preferredCurrencyUnit: CurrencyUnit;
|
|
41
68
|
/**
|
|
42
|
-
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
43
|
-
* currency. For example, for USD, the value will be in
|
|
69
|
+
* The rounded numeric value for this CurrencyAmount in the very base level
|
|
70
|
+
* of user's preferred currency. For example, for USD, the value will be in
|
|
71
|
+
* cents.
|
|
44
72
|
**/
|
|
45
73
|
preferredCurrencyValueRounded: number;
|
|
46
74
|
/**
|
|
47
|
-
* The approximate float value for this CurrencyAmount in the very base level
|
|
48
|
-
* currency. For example, for USD, the value will be in
|
|
75
|
+
* The approximate float value for this CurrencyAmount in the very base level
|
|
76
|
+
* of user's preferred currency. For example, for USD, the value will be in
|
|
77
|
+
* cents.
|
|
49
78
|
**/
|
|
50
79
|
preferredCurrencyValueApprox: number;
|
|
51
80
|
};
|
|
@@ -211,8 +240,12 @@ export type CurrencyMap = {
|
|
|
211
240
|
};
|
|
212
241
|
|
|
213
242
|
export type CurrencyAmountObj = {
|
|
214
|
-
/*
|
|
215
|
-
|
|
243
|
+
/*
|
|
244
|
+
* Technically the generated graphql schema has value as `any` but it's
|
|
245
|
+
* always a number.
|
|
246
|
+
* We are intentionally widening the type here to allow for more forgiving
|
|
247
|
+
* input:
|
|
248
|
+
*/
|
|
216
249
|
value?: number | string | null;
|
|
217
250
|
/* assume satoshi if not provided */
|
|
218
251
|
unit?: CurrencyUnit;
|
|
@@ -402,7 +435,10 @@ export function formatCurrencyStr(
|
|
|
402
435
|
let { value: num } = currencyAmount;
|
|
403
436
|
const { unit } = currencyAmount;
|
|
404
437
|
|
|
405
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Currencies should always be represented in the smallest unit, e.g.
|
|
440
|
+
* cents for USD:
|
|
441
|
+
*/
|
|
406
442
|
if (unit === CurrencyUnit.USD) {
|
|
407
443
|
num = num / 100;
|
|
408
444
|
}
|
|
@@ -415,7 +451,8 @@ export function formatCurrencyStr(
|
|
|
415
451
|
: maxFractionDigits;
|
|
416
452
|
}
|
|
417
453
|
|
|
418
|
-
// Symbol handled by toLocaleString for USD.
|
|
454
|
+
// Symbol handled by toLocaleString for USD.
|
|
455
|
+
// These rely on the LightsparkIcons font
|
|
419
456
|
const symbol = !showBtcSymbol
|
|
420
457
|
? ""
|
|
421
458
|
: unit === CurrencyUnit.BITCOIN
|
|
@@ -472,7 +509,8 @@ export function localeToCurrencySymbol(locale: string) {
|
|
|
472
509
|
maximumFractionDigits: 0,
|
|
473
510
|
}).format(0);
|
|
474
511
|
|
|
475
|
-
// Remove numeric and non-breaking space characters to extract the currency
|
|
512
|
+
// Remove numeric and non-breaking space characters to extract the currency
|
|
513
|
+
// symbol
|
|
476
514
|
const { symbol } = separateCurrencyStrParts(formatted);
|
|
477
515
|
return symbol;
|
|
478
516
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* From https://github.com/tadeegan/locale-currency. For now only USD conversion from
|
|
2
|
-
|
|
2
|
+
* BTC is supported by sparkcore, strip additional currency codes from the
|
|
3
|
+
* bundle:
|
|
4
|
+
*/
|
|
3
5
|
export const countryCodesToCurrencyCodes = {
|
|
4
6
|
AD: "EUR",
|
|
5
7
|
// AE: "AED",
|
package/src/utils/types.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type Maybe<T> = T | null | undefined;
|
|
|
4
4
|
|
|
5
5
|
export type ExpandRecursively<T> = T extends object
|
|
6
6
|
? T extends infer O
|
|
7
|
-
? { [K in keyof O]: ExpandRecursively<O[K]> }
|
|
7
|
+
? { [K in keyof O]: ExpandRecursively<O[K]> }
|
|
8
8
|
: never
|
|
9
9
|
: T;
|
|
10
10
|
|
|
@@ -857,12 +857,12 @@ var isType = (typename) => (node) => {
|
|
|
857
857
|
|
|
858
858
|
export {
|
|
859
859
|
LightsparkException_default,
|
|
860
|
-
b64decode,
|
|
861
|
-
urlsafe_b64decode,
|
|
862
|
-
b64encode,
|
|
863
860
|
isBrowser,
|
|
864
861
|
isNode,
|
|
865
862
|
isTest,
|
|
863
|
+
b64decode,
|
|
864
|
+
urlsafe_b64decode,
|
|
865
|
+
b64encode,
|
|
866
866
|
bytesToHex,
|
|
867
867
|
hexToBytes,
|
|
868
868
|
createSha256Hash,
|