@lightsparkdev/core 1.0.9 → 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 +13 -0
- package/dist/{chunk-UU6SHVGX.js → chunk-F3XHLUGC.js} +34 -35
- package/dist/index.cjs +115 -112
- package/dist/index.d.cts +168 -0
- package/dist/index.d.ts +42 -39
- package/dist/index.js +72 -68
- package/dist/utils/index.cjs +31 -32
- package/dist/utils/index.d.cts +252 -0
- package/dist/utils/index.d.ts +50 -17
- package/dist/utils/index.js +1 -1
- package/package.json +6 -6
- package/src/Logger.ts +1 -1
- package/src/auth/StubAuthProvider.ts +6 -7
- package/src/crypto/crypto.ts +7 -6
- package/src/crypto/index.ts +1 -1
- package/src/crypto/tests/crypto.test.ts +21 -0
- package/src/index.ts +5 -5
- package/src/requester/Query.ts +4 -1
- package/src/requester/Requester.ts +20 -7
- package/src/utils/currency.ts +56 -18
- package/src/utils/localeToCurrencyCodes.ts +3 -1
- package/src/utils/pollUntil.ts +37 -36
- package/src/utils/types.ts +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lightsparkdev/core
|
|
2
2
|
|
|
3
|
+
## 1.0.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 43dc882: Upgrade to Typescript 5, lint config changes
|
|
8
|
+
|
|
9
|
+
## 1.0.10
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- aefe52c: Update tsup to latest
|
|
14
|
+
- 09dfcee: Prevent ts compile of test files for builds and update lint configuration
|
|
15
|
+
|
|
3
16
|
## 1.0.9
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -816,39 +816,38 @@ function sleep(ms) {
|
|
|
816
816
|
function getDefaultMaxPollsError() {
|
|
817
817
|
return new Error("pollUntil: Max polls reached");
|
|
818
818
|
}
|
|
819
|
-
function pollUntil(asyncFn, getValue, maxPolls = 60, pollIntervalMs = 500, ignoreErrors = false, getMaxPollsError = getDefaultMaxPollsError) {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
}
|
|
842
|
-
} catch (e) {
|
|
843
|
-
if (!ignoreErrors || isFunction_default(ignoreErrors) && !ignoreErrors(e)) {
|
|
844
|
-
stopPolling = true;
|
|
845
|
-
reject(e);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
await sleep(pollIntervalMs);
|
|
819
|
+
async function pollUntil(asyncFn, getValue, maxPolls = 60, pollIntervalMs = 500, ignoreErrors = false, getMaxPollsError = getDefaultMaxPollsError) {
|
|
820
|
+
let polls = 0;
|
|
821
|
+
let stopPolling = false;
|
|
822
|
+
let result = {
|
|
823
|
+
stopPolling: false,
|
|
824
|
+
value: null
|
|
825
|
+
};
|
|
826
|
+
while (!stopPolling) {
|
|
827
|
+
polls += 1;
|
|
828
|
+
if (polls > maxPolls) {
|
|
829
|
+
stopPolling = true;
|
|
830
|
+
const maxPollsError = getMaxPollsError(maxPolls);
|
|
831
|
+
throw maxPollsError;
|
|
832
|
+
}
|
|
833
|
+
try {
|
|
834
|
+
const asyncResult = await asyncFn();
|
|
835
|
+
result = getValue(asyncResult, {
|
|
836
|
+
stopPolling: false,
|
|
837
|
+
value: null
|
|
838
|
+
});
|
|
839
|
+
if (result.stopPolling) {
|
|
840
|
+
stopPolling = true;
|
|
849
841
|
}
|
|
850
|
-
}
|
|
851
|
-
|
|
842
|
+
} catch (e) {
|
|
843
|
+
if (!ignoreErrors || isFunction_default(ignoreErrors) && !ignoreErrors(e)) {
|
|
844
|
+
stopPolling = true;
|
|
845
|
+
throw e;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
await sleep(pollIntervalMs);
|
|
849
|
+
}
|
|
850
|
+
return result.value;
|
|
852
851
|
}
|
|
853
852
|
|
|
854
853
|
// src/utils/types.ts
|
|
@@ -858,12 +857,12 @@ var isType = (typename) => (node) => {
|
|
|
858
857
|
|
|
859
858
|
export {
|
|
860
859
|
LightsparkException_default,
|
|
861
|
-
b64decode,
|
|
862
|
-
urlsafe_b64decode,
|
|
863
|
-
b64encode,
|
|
864
860
|
isBrowser,
|
|
865
861
|
isNode,
|
|
866
862
|
isTest,
|
|
863
|
+
b64decode,
|
|
864
|
+
urlsafe_b64decode,
|
|
865
|
+
b64encode,
|
|
867
866
|
bytesToHex,
|
|
868
867
|
hexToBytes,
|
|
869
868
|
createSha256Hash,
|
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) {
|
|
@@ -109,14 +163,14 @@ var LightsparkAuthException_default = LightsparkAuthException;
|
|
|
109
163
|
|
|
110
164
|
// src/auth/StubAuthProvider.ts
|
|
111
165
|
var StubAuthProvider = class {
|
|
112
|
-
|
|
113
|
-
return headers;
|
|
166
|
+
addAuthHeaders(headers) {
|
|
167
|
+
return Promise.resolve(headers);
|
|
114
168
|
}
|
|
115
|
-
|
|
116
|
-
return false;
|
|
169
|
+
isAuthorized() {
|
|
170
|
+
return Promise.resolve(false);
|
|
117
171
|
}
|
|
118
|
-
|
|
119
|
-
return params;
|
|
172
|
+
addWsConnectionParams(params) {
|
|
173
|
+
return Promise.resolve(params);
|
|
120
174
|
}
|
|
121
175
|
};
|
|
122
176
|
|
|
@@ -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;
|
|
@@ -267,7 +330,7 @@ var decrypt = async (header_json, ciphertext, password) => {
|
|
|
267
330
|
if (header.v < 0 || header.v > 4) {
|
|
268
331
|
throw new LightsparkException_default(
|
|
269
332
|
"DecryptionError",
|
|
270
|
-
|
|
333
|
+
`Unknown version ${header.v}`
|
|
271
334
|
);
|
|
272
335
|
}
|
|
273
336
|
const cryptoImpl = await getCrypto();
|
|
@@ -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) => {
|
|
@@ -1161,39 +1213,38 @@ function sleep(ms) {
|
|
|
1161
1213
|
function getDefaultMaxPollsError() {
|
|
1162
1214
|
return new Error("pollUntil: Max polls reached");
|
|
1163
1215
|
}
|
|
1164
|
-
function pollUntil(asyncFn, getValue, maxPolls = 60, pollIntervalMs = 500, ignoreErrors = false, getMaxPollsError = getDefaultMaxPollsError) {
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
} catch (e) {
|
|
1188
|
-
if (!ignoreErrors || isFunction_default(ignoreErrors) && !ignoreErrors(e)) {
|
|
1189
|
-
stopPolling = true;
|
|
1190
|
-
reject(e);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
await sleep(pollIntervalMs);
|
|
1216
|
+
async function pollUntil(asyncFn, getValue, maxPolls = 60, pollIntervalMs = 500, ignoreErrors = false, getMaxPollsError = getDefaultMaxPollsError) {
|
|
1217
|
+
let polls = 0;
|
|
1218
|
+
let stopPolling = false;
|
|
1219
|
+
let result = {
|
|
1220
|
+
stopPolling: false,
|
|
1221
|
+
value: null
|
|
1222
|
+
};
|
|
1223
|
+
while (!stopPolling) {
|
|
1224
|
+
polls += 1;
|
|
1225
|
+
if (polls > maxPolls) {
|
|
1226
|
+
stopPolling = true;
|
|
1227
|
+
const maxPollsError = getMaxPollsError(maxPolls);
|
|
1228
|
+
throw maxPollsError;
|
|
1229
|
+
}
|
|
1230
|
+
try {
|
|
1231
|
+
const asyncResult = await asyncFn();
|
|
1232
|
+
result = getValue(asyncResult, {
|
|
1233
|
+
stopPolling: false,
|
|
1234
|
+
value: null
|
|
1235
|
+
});
|
|
1236
|
+
if (result.stopPolling) {
|
|
1237
|
+
stopPolling = true;
|
|
1194
1238
|
}
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
if (!ignoreErrors || isFunction_default(ignoreErrors) && !ignoreErrors(e)) {
|
|
1241
|
+
stopPolling = true;
|
|
1242
|
+
throw e;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
await sleep(pollIntervalMs);
|
|
1246
|
+
}
|
|
1247
|
+
return result.value;
|
|
1197
1248
|
}
|
|
1198
1249
|
|
|
1199
1250
|
// src/utils/types.ts
|
|
@@ -1296,39 +1347,6 @@ var NodeKeyCache = class {
|
|
|
1296
1347
|
};
|
|
1297
1348
|
var NodeKeyCache_default = NodeKeyCache;
|
|
1298
1349
|
|
|
1299
|
-
// src/Logger.ts
|
|
1300
|
-
var Logger = class {
|
|
1301
|
-
context;
|
|
1302
|
-
loggingEnabled = false;
|
|
1303
|
-
constructor(loggerContext, getLoggingEnabled) {
|
|
1304
|
-
this.context = loggerContext;
|
|
1305
|
-
this.updateLoggingEnabled(getLoggingEnabled);
|
|
1306
|
-
}
|
|
1307
|
-
async updateLoggingEnabled(getLoggingEnabled) {
|
|
1308
|
-
if (getLoggingEnabled) {
|
|
1309
|
-
this.loggingEnabled = await getLoggingEnabled();
|
|
1310
|
-
} else if (isTest) {
|
|
1311
|
-
this.loggingEnabled = true;
|
|
1312
|
-
} else if (isBrowser) {
|
|
1313
|
-
try {
|
|
1314
|
-
this.loggingEnabled = getLocalStorageConfigItem(
|
|
1315
|
-
ConfigKeys.LoggingEnabled
|
|
1316
|
-
);
|
|
1317
|
-
} catch (e) {
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
if (this.loggingEnabled) {
|
|
1321
|
-
console.log(`[${this.context}] Logging enabled`);
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
info(message, ...rest) {
|
|
1325
|
-
if (this.loggingEnabled) {
|
|
1326
|
-
console.log(`[${this.context}] ${message}`, ...rest);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
};
|
|
1330
|
-
var logger = new Logger("@lightsparkdev/core");
|
|
1331
|
-
|
|
1332
1350
|
// src/requester/Requester.ts
|
|
1333
1351
|
var import_auto_bind2 = __toESM(require("auto-bind"), 1);
|
|
1334
1352
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
@@ -1453,6 +1471,7 @@ var Requester = class {
|
|
|
1453
1471
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
1454
1472
|
logger.info(`Requester.makeRawRequest`, {
|
|
1455
1473
|
url,
|
|
1474
|
+
operationName: operation,
|
|
1456
1475
|
variables
|
|
1457
1476
|
});
|
|
1458
1477
|
const response = await fetch(url, {
|
|
@@ -1500,7 +1519,7 @@ var Requester = class {
|
|
|
1500
1519
|
nonce,
|
|
1501
1520
|
expires_at: expiration
|
|
1502
1521
|
};
|
|
1503
|
-
const key =
|
|
1522
|
+
const key = this.nodeKeyCache.getKey(signingNodeId);
|
|
1504
1523
|
if (!key) {
|
|
1505
1524
|
throw new LightsparkSigningException_default(
|
|
1506
1525
|
"Missing node of encrypted_signing_private_key"
|
|
@@ -1523,22 +1542,6 @@ var Requester = class {
|
|
|
1523
1542
|
}
|
|
1524
1543
|
};
|
|
1525
1544
|
var Requester_default = Requester;
|
|
1526
|
-
|
|
1527
|
-
// src/ServerEnvironment.ts
|
|
1528
|
-
var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
|
|
1529
|
-
ServerEnvironment2["PRODUCTION"] = "production";
|
|
1530
|
-
ServerEnvironment2["DEV"] = "dev";
|
|
1531
|
-
return ServerEnvironment2;
|
|
1532
|
-
})(ServerEnvironment || {});
|
|
1533
|
-
var apiDomainForEnvironment = (environment) => {
|
|
1534
|
-
switch (environment) {
|
|
1535
|
-
case "dev" /* DEV */:
|
|
1536
|
-
return "api.dev.dev.sparkinfra.net";
|
|
1537
|
-
case "production" /* PRODUCTION */:
|
|
1538
|
-
return "api.lightspark.com";
|
|
1539
|
-
}
|
|
1540
|
-
};
|
|
1541
|
-
var ServerEnvironment_default = ServerEnvironment;
|
|
1542
1545
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1543
1546
|
0 && (module.exports = {
|
|
1544
1547
|
ConfigKeys,
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Observable } from 'zen-observable-ts';
|
|
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
|
+
|
|
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
|
+
|
|
26
|
+
type Headers = Record<string, string>;
|
|
27
|
+
type WsConnectionParams = Record<string, unknown>;
|
|
28
|
+
interface AuthProvider {
|
|
29
|
+
addAuthHeaders(headers: Headers): Promise<Headers>;
|
|
30
|
+
isAuthorized(): Promise<boolean>;
|
|
31
|
+
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare class LightsparkAuthException extends LightsparkException {
|
|
35
|
+
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare class StubAuthProvider implements AuthProvider {
|
|
39
|
+
addAuthHeaders(headers: Headers): Promise<Headers>;
|
|
40
|
+
isAuthorized(): Promise<boolean>;
|
|
41
|
+
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare const ConfigKeys: {
|
|
45
|
+
readonly LoggingEnabled: "lightspark-logging-enabled";
|
|
46
|
+
readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
|
|
47
|
+
};
|
|
48
|
+
type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
|
|
49
|
+
declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
|
|
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
|
+
|
|
65
|
+
declare class LightsparkSigningException extends LightsparkException {
|
|
66
|
+
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type GeneratedKeyPair = {
|
|
70
|
+
publicKey: CryptoKey | string;
|
|
71
|
+
privateKey: CryptoKey | string;
|
|
72
|
+
keyAlias?: string;
|
|
73
|
+
};
|
|
74
|
+
type CryptoInterface = {
|
|
75
|
+
decryptSecretWithNodePassword: (cipher: string, encryptedSecret: string, nodePassword: string) => Promise<ArrayBuffer | null>;
|
|
76
|
+
generateSigningKeyPair: () => Promise<GeneratedKeyPair>;
|
|
77
|
+
serializeSigningKey: (key: CryptoKey | string, format: "pkcs8" | "spki") => Promise<ArrayBuffer>;
|
|
78
|
+
getNonce: () => Promise<number>;
|
|
79
|
+
sign: (keyOrAlias: CryptoKey | string, data: Uint8Array) => Promise<ArrayBuffer>;
|
|
80
|
+
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
81
|
+
};
|
|
82
|
+
declare function decryptSecretWithNodePassword(cipher: string, encryptedSecret: string, nodePassword: string): Promise<ArrayBuffer | null>;
|
|
83
|
+
declare const DefaultCrypto: {
|
|
84
|
+
decryptSecretWithNodePassword: typeof decryptSecretWithNodePassword;
|
|
85
|
+
generateSigningKeyPair: () => Promise<GeneratedKeyPair>;
|
|
86
|
+
serializeSigningKey: (key: CryptoKey | string, format: "pkcs8" | "spki") => Promise<ArrayBuffer>;
|
|
87
|
+
getNonce: () => Promise<number>;
|
|
88
|
+
sign: (keyOrAlias: CryptoKey | string, data: Uint8Array) => Promise<ArrayBuffer>;
|
|
89
|
+
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
interface Alias {
|
|
93
|
+
alias: string;
|
|
94
|
+
}
|
|
95
|
+
declare abstract class SigningKey {
|
|
96
|
+
readonly type: SigningKeyType;
|
|
97
|
+
constructor(type: SigningKeyType);
|
|
98
|
+
abstract sign(data: Uint8Array): Promise<ArrayBuffer>;
|
|
99
|
+
}
|
|
100
|
+
declare class RSASigningKey extends SigningKey {
|
|
101
|
+
private readonly privateKey;
|
|
102
|
+
private readonly cryptoImpl;
|
|
103
|
+
constructor(privateKey: CryptoKey | Alias, cryptoImpl: CryptoInterface);
|
|
104
|
+
sign(data: Uint8Array): Promise<ArrayBuffer>;
|
|
105
|
+
}
|
|
106
|
+
declare class Secp256k1SigningKey extends SigningKey {
|
|
107
|
+
private readonly privateKey;
|
|
108
|
+
constructor(privateKey: string);
|
|
109
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
declare enum SigningKeyType {
|
|
113
|
+
RSASigningKey = "RSASigningKey",
|
|
114
|
+
Secp256k1SigningKey = "Secp256k1SigningKey"
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
declare class NodeKeyCache {
|
|
118
|
+
private readonly cryptoImpl;
|
|
119
|
+
private idToKey;
|
|
120
|
+
constructor(cryptoImpl?: CryptoInterface);
|
|
121
|
+
loadKey(id: string, keyOrAlias: KeyOrAliasType, signingKeyType: SigningKeyType): Promise<SigningKey | null>;
|
|
122
|
+
getKey(id: string): SigningKey | undefined;
|
|
123
|
+
hasKey(id: string): boolean;
|
|
124
|
+
private stripPemTags;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type Query<T> = {
|
|
128
|
+
/** The string representation of the query payload for graphQL. **/
|
|
129
|
+
queryPayload: string;
|
|
130
|
+
/** The variables that will be passed to the query. **/
|
|
131
|
+
variables?: {
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* The function that will be called to construct the object from the
|
|
136
|
+
* response. *
|
|
137
|
+
*/
|
|
138
|
+
constructObject: (rawData: any) => T;
|
|
139
|
+
/** The id of the node that will be used to sign the query. **/
|
|
140
|
+
signingNodeId?: string;
|
|
141
|
+
/** True if auth headers should be omitted for this query. **/
|
|
142
|
+
skipAuth?: boolean;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
declare class Requester {
|
|
146
|
+
private readonly nodeKeyCache;
|
|
147
|
+
private readonly schemaEndpoint;
|
|
148
|
+
private readonly sdkUserAgent;
|
|
149
|
+
private readonly authProvider;
|
|
150
|
+
private readonly baseUrl;
|
|
151
|
+
private readonly cryptoImpl;
|
|
152
|
+
private readonly wsClient;
|
|
153
|
+
constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface);
|
|
154
|
+
executeQuery<T>(query: Query<T>): Promise<T | null>;
|
|
155
|
+
subscribe<T>(queryPayload: string, variables?: {
|
|
156
|
+
[key: string]: unknown;
|
|
157
|
+
}): Observable<{
|
|
158
|
+
data: T;
|
|
159
|
+
}>;
|
|
160
|
+
makeRawRequest(queryPayload: string, variables?: {
|
|
161
|
+
[key: string]: unknown;
|
|
162
|
+
}, signingNodeId?: string | undefined, skipAuth?: boolean): Promise<any>;
|
|
163
|
+
private getSdkUserAgent;
|
|
164
|
+
private stripProtocol;
|
|
165
|
+
private addSigningDataIfNeeded;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageConfigItem };
|