@lightsparkdev/core 1.4.3 → 1.4.5

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/dist/index.js CHANGED
@@ -1,3 +1,22 @@
1
+ import {
2
+ ConfigKeys,
3
+ DefaultCrypto,
4
+ KeyOrAlias,
5
+ LightsparkAuthException_default,
6
+ LightsparkSigningException_default,
7
+ Logger,
8
+ LoggingLevel,
9
+ NodeKeyCache_default,
10
+ RSASigningKey,
11
+ Requester_default,
12
+ Secp256k1SigningKey,
13
+ ServerEnvironment_default,
14
+ SigningKey,
15
+ SigningKeyType,
16
+ StubAuthProvider,
17
+ apiDomainForEnvironment,
18
+ logger
19
+ } from "./chunk-L5YREN7B.js";
1
20
  import {
2
21
  CurrencyUnit,
3
22
  LightsparkException_default,
@@ -35,6 +54,7 @@ import {
35
54
  isNode,
36
55
  isNumber,
37
56
  isObject,
57
+ isReactNative,
38
58
  isRecord,
39
59
  isSDKCurrencyAmount,
40
60
  isTest,
@@ -55,463 +75,10 @@ import {
55
75
  urlsafe_b64decode,
56
76
  zipcodeToState,
57
77
  zipcodeToStateCode
58
- } from "./chunk-36QHRQJC.js";
59
-
60
- // src/auth/LightsparkAuthException.ts
61
- var LightsparkAuthException = class extends LightsparkException_default {
62
- constructor(message, extraInfo) {
63
- super("AuthException", message, extraInfo);
64
- }
65
- };
66
- var LightsparkAuthException_default = LightsparkAuthException;
67
-
68
- // src/auth/StubAuthProvider.ts
69
- var StubAuthProvider = class {
70
- addAuthHeaders(headers) {
71
- return Promise.resolve(headers);
72
- }
73
- isAuthorized() {
74
- return Promise.resolve(false);
75
- }
76
- addWsConnectionParams(params) {
77
- return Promise.resolve(params);
78
- }
79
- };
80
-
81
- // src/constants/index.ts
82
- var ConfigKeys = {
83
- LoggingEnabled: "lightspark-logging-enabled",
84
- ConsoleToolsEnabled: "lightspark-console-tools-enabled"
85
- };
86
-
87
- // src/crypto/LightsparkSigningException.ts
88
- var LightsparkSigningException = class extends LightsparkException_default {
89
- constructor(message, extraInfo) {
90
- super("SigningException", message, extraInfo);
91
- }
92
- };
93
- var LightsparkSigningException_default = LightsparkSigningException;
94
-
95
- // src/crypto/crypto.ts
96
- var getCrypto = () => {
97
- let cryptoImplPromise;
98
- if (typeof crypto !== "undefined") {
99
- cryptoImplPromise = Promise.resolve(crypto);
100
- } else {
101
- cryptoImplPromise = import("crypto").then((nodeCrypto) => {
102
- let cryptoModule = nodeCrypto;
103
- if (!nodeCrypto.subtle) {
104
- cryptoModule = Object.assign({}, cryptoModule, {
105
- subtle: nodeCrypto.webcrypto.subtle
106
- });
107
- }
108
- if (!nodeCrypto.getRandomValues) {
109
- cryptoModule = Object.assign({}, cryptoModule, {
110
- getRandomValues: (array) => {
111
- if (!array) {
112
- return array;
113
- }
114
- const buffer = Buffer.from(array.buffer);
115
- const view = new Uint8Array(buffer);
116
- nodeCrypto.randomFillSync(view);
117
- return array;
118
- }
119
- });
120
- }
121
- return cryptoModule;
122
- });
123
- }
124
- return cryptoImplPromise;
125
- };
126
- var getRandomValues32 = async (arr) => {
127
- if (typeof crypto !== "undefined") {
128
- return crypto.getRandomValues(arr);
129
- } else {
130
- const cryptoImpl = await getCrypto();
131
- return cryptoImpl.getRandomValues(arr);
132
- }
133
- };
134
- var deriveKey = async (password, salt, iterations, algorithm, bit_len) => {
135
- const enc = new TextEncoder();
136
- const cryptoImpl = await getCrypto();
137
- const password_key = await cryptoImpl.subtle.importKey(
138
- "raw",
139
- enc.encode(password),
140
- "PBKDF2",
141
- false,
142
- ["deriveBits", "deriveKey"]
143
- );
144
- const derived = await cryptoImpl.subtle.deriveBits(
145
- {
146
- name: "PBKDF2",
147
- salt,
148
- iterations,
149
- hash: "SHA-256"
150
- },
151
- password_key,
152
- bit_len
153
- );
154
- const key = await cryptoImpl.subtle.importKey(
155
- "raw",
156
- derived.slice(0, 32),
157
- { name: algorithm, length: 256 },
158
- false,
159
- ["encrypt", "decrypt"]
160
- );
161
- const iv = derived.slice(32);
162
- return [key, iv];
163
- };
164
- var decrypt = async (header_json, ciphertext, password) => {
165
- let decoded = b64decode(ciphertext);
166
- let header;
167
- if (header_json === "AES_256_CBC_PBKDF2_5000_SHA256") {
168
- header = {
169
- v: 0,
170
- i: 5e3
171
- };
172
- decoded = decoded.slice(8);
173
- } else {
174
- header = JSON.parse(header_json);
175
- }
176
- if (header.v < 0 || header.v > 4) {
177
- throw new LightsparkException_default(
178
- "DecryptionError",
179
- `Unknown version ${header.v}`
180
- );
181
- }
182
- const cryptoImpl = await getCrypto();
183
- const algorithm = header.v < 2 ? "AES-CBC" : "AES-GCM";
184
- const bit_len = header.v < 4 ? 384 : 352;
185
- const salt_len = header.v < 4 ? 8 : 16;
186
- if (header.lsv === 2 || header.v === 3) {
187
- const salt = decoded.slice(decoded.length - 8, decoded.length);
188
- const nonce = decoded.slice(0, 12);
189
- const cipherText = decoded.slice(12, decoded.length - 8);
190
- const [
191
- key
192
- /* , _iv */
193
- ] = await deriveKey(
194
- password,
195
- salt,
196
- header.i,
197
- algorithm,
198
- 256
199
- );
200
- return await cryptoImpl.subtle.decrypt(
201
- { name: algorithm, iv: nonce.buffer },
202
- key,
203
- cipherText
204
- );
205
- } else {
206
- const salt = decoded.slice(0, salt_len);
207
- const encrypted = decoded.slice(salt_len);
208
- const [key, iv] = await deriveKey(
209
- password,
210
- salt,
211
- header.i,
212
- algorithm,
213
- bit_len
214
- );
215
- return await cryptoImpl.subtle.decrypt(
216
- { name: algorithm, iv },
217
- key,
218
- encrypted
219
- );
220
- }
221
- };
222
- async function decryptSecretWithNodePassword(cipher, encryptedSecret, nodePassword) {
223
- let decryptedValue = null;
224
- try {
225
- decryptedValue = await decrypt(cipher, encryptedSecret, nodePassword);
226
- } catch (ex) {
227
- console.error(ex);
228
- }
229
- return decryptedValue;
230
- }
231
- var generateSigningKeyPair = async () => {
232
- const cryptoImpl = await getCrypto();
233
- return await cryptoImpl.subtle.generateKey(
234
- /*algorithm:*/
235
- {
236
- name: "RSA-PSS",
237
- modulusLength: 4096,
238
- publicExponent: new Uint8Array([1, 0, 1]),
239
- hash: "SHA-256"
240
- },
241
- /*extractable*/
242
- true,
243
- /*keyUsages*/
244
- ["sign", "verify"]
245
- );
246
- };
247
- var serializeSigningKey = async (key, format) => {
248
- const cryptoImpl = await getCrypto();
249
- return await cryptoImpl.subtle.exportKey(
250
- /*format*/
251
- format,
252
- /*key*/
253
- key
254
- );
255
- };
256
- var getNonce = async () => {
257
- const nonceSt = await getRandomValues32(new Uint32Array(2));
258
- const [upper, lower] = nonceSt;
259
- const nonce = BigInt(upper) << 32n | BigInt(lower);
260
- return Number(nonce);
261
- };
262
- var sign = async (keyOrAlias, data) => {
263
- if (typeof keyOrAlias === "string") {
264
- throw new LightsparkSigningException_default(
265
- "Key alias not supported for default crypto."
266
- );
267
- }
268
- const cryptoImpl = await getCrypto();
269
- return await cryptoImpl.subtle.sign(
270
- {
271
- name: "RSA-PSS",
272
- saltLength: 32
273
- },
274
- keyOrAlias,
275
- data
276
- );
277
- };
278
- var importPrivateSigningKey = async (keyData) => {
279
- const cryptoImpl = await getCrypto();
280
- return await cryptoImpl.subtle.importKey(
281
- /*format*/
282
- "pkcs8",
283
- /*keyData*/
284
- keyData,
285
- /*algorithm*/
286
- {
287
- name: "RSA-PSS",
288
- hash: "SHA-256"
289
- },
290
- /*extractable*/
291
- true,
292
- /*keyUsages*/
293
- ["sign"]
294
- );
295
- };
296
- var DefaultCrypto = {
297
- decryptSecretWithNodePassword,
298
- generateSigningKeyPair,
299
- serializeSigningKey,
300
- getNonce,
301
- sign,
302
- importPrivateSigningKey
303
- };
304
-
305
- // src/crypto/KeyOrAlias.ts
306
- var KeyOrAlias = {
307
- key: (key) => ({ key }),
308
- alias: (alias) => ({ alias })
309
- };
310
-
311
- // ../../node_modules/auto-bind/index.js
312
- var getAllProperties = (object) => {
313
- const properties = /* @__PURE__ */ new Set();
314
- do {
315
- for (const key of Reflect.ownKeys(object)) {
316
- properties.add([object, key]);
317
- }
318
- } while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
319
- return properties;
320
- };
321
- function autoBind(self, { include, exclude } = {}) {
322
- const filter = (key) => {
323
- const match = (pattern) => typeof pattern === "string" ? key === pattern : pattern.test(key);
324
- if (include) {
325
- return include.some(match);
326
- }
327
- if (exclude) {
328
- return !exclude.some(match);
329
- }
330
- return true;
331
- };
332
- for (const [object, key] of getAllProperties(self.constructor.prototype)) {
333
- if (key === "constructor" || !filter(key)) {
334
- continue;
335
- }
336
- const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
337
- if (descriptor && typeof descriptor.value === "function") {
338
- self[key] = self[key].bind(self);
339
- }
340
- }
341
- return self;
342
- }
343
-
344
- // src/crypto/SigningKey.ts
345
- import secp256k1 from "secp256k1";
346
- function isAlias(key) {
347
- return "alias" in key;
348
- }
349
- var SigningKey = class {
350
- type;
351
- constructor(type) {
352
- this.type = type;
353
- }
354
- };
355
- var RSASigningKey = class extends SigningKey {
356
- constructor(privateKey, cryptoImpl) {
357
- super("RSASigningKey" /* RSASigningKey */);
358
- this.privateKey = privateKey;
359
- this.cryptoImpl = cryptoImpl;
360
- }
361
- async sign(data) {
362
- const key = isAlias(this.privateKey) ? this.privateKey.alias : this.privateKey;
363
- return this.cryptoImpl.sign(key, data);
364
- }
365
- };
366
- var Secp256k1SigningKey = class extends SigningKey {
367
- constructor(privateKey) {
368
- super("Secp256k1SigningKey" /* Secp256k1SigningKey */);
369
- this.privateKey = privateKey;
370
- }
371
- async sign(data) {
372
- const keyBytes = new Uint8Array(hexToBytes(this.privateKey));
373
- const hash = await createSha256Hash(data);
374
- const signResult = secp256k1.ecdsaSign(hash, keyBytes);
375
- return secp256k1.signatureExport(signResult.signature);
376
- }
377
- };
78
+ } from "./chunk-IWYMQNIA.js";
378
79
 
379
- // src/crypto/types.ts
380
- var SigningKeyType = /* @__PURE__ */ ((SigningKeyType2) => {
381
- SigningKeyType2["RSASigningKey"] = "RSASigningKey";
382
- SigningKeyType2["Secp256k1SigningKey"] = "Secp256k1SigningKey";
383
- return SigningKeyType2;
384
- })(SigningKeyType || {});
385
-
386
- // src/crypto/NodeKeyCache.ts
387
- var NodeKeyCache = class {
388
- constructor(cryptoImpl = DefaultCrypto) {
389
- this.cryptoImpl = cryptoImpl;
390
- this.idToKey = /* @__PURE__ */ new Map();
391
- autoBind(this);
392
- }
393
- idToKey;
394
- async loadKey(id, keyOrAlias, signingKeyType) {
395
- let signingKey;
396
- if (keyOrAlias.alias !== void 0) {
397
- switch (signingKeyType) {
398
- case "RSASigningKey" /* RSASigningKey */:
399
- signingKey = new RSASigningKey(
400
- { alias: keyOrAlias.alias },
401
- this.cryptoImpl
402
- );
403
- break;
404
- default:
405
- throw new LightsparkSigningException_default(
406
- `Aliases are not supported for signing key type ${signingKeyType}`
407
- );
408
- }
409
- this.idToKey.set(id, signingKey);
410
- return signingKey;
411
- }
412
- try {
413
- if (signingKeyType === "Secp256k1SigningKey" /* Secp256k1SigningKey */) {
414
- signingKey = new Secp256k1SigningKey(keyOrAlias.key);
415
- } else {
416
- const decoded = b64decode(this.stripPemTags(keyOrAlias.key));
417
- const cryptoKeyOrAlias = await this.cryptoImpl.importPrivateSigningKey(decoded);
418
- const key = typeof cryptoKeyOrAlias === "string" ? { alias: cryptoKeyOrAlias } : cryptoKeyOrAlias;
419
- signingKey = new RSASigningKey(key, this.cryptoImpl);
420
- }
421
- this.idToKey.set(id, signingKey);
422
- return signingKey;
423
- } catch (e) {
424
- console.log("Error importing key: ", e);
425
- }
426
- return null;
427
- }
428
- getKey(id) {
429
- return this.idToKey.get(id);
430
- }
431
- hasKey(id) {
432
- return this.idToKey.has(id);
433
- }
434
- stripPemTags(pem) {
435
- return pem.replace(/-----BEGIN (.*)-----/, "").replace(/-----END (.*)----/, "");
436
- }
437
- };
438
- var NodeKeyCache_default = NodeKeyCache;
439
-
440
- // src/Logger.ts
441
- var LoggingLevel = /* @__PURE__ */ ((LoggingLevel2) => {
442
- LoggingLevel2[LoggingLevel2["Trace"] = 0] = "Trace";
443
- LoggingLevel2[LoggingLevel2["Info"] = 1] = "Info";
444
- return LoggingLevel2;
445
- })(LoggingLevel || {});
446
- var Logger = class {
447
- context;
448
- loggingEnabled = false;
449
- loggingLevel = 1 /* Info */;
450
- constructor(loggerContext, getLoggingEnabled) {
451
- this.context = loggerContext;
452
- void this.updateLoggingEnabled(getLoggingEnabled);
453
- }
454
- setLevel(level) {
455
- this.loggingLevel = level;
456
- }
457
- setEnabled(enabled, level = 1 /* Info */) {
458
- this.loggingEnabled = enabled;
459
- this.loggingLevel = level;
460
- }
461
- async updateLoggingEnabled(getLoggingEnabled) {
462
- if (getLoggingEnabled) {
463
- this.loggingEnabled = await getLoggingEnabled();
464
- } else if (isTest) {
465
- this.loggingEnabled = true;
466
- } else if (isBrowser) {
467
- try {
468
- this.loggingEnabled = getLocalStorageConfigItem(
469
- ConfigKeys.LoggingEnabled
470
- );
471
- } catch (e) {
472
- }
473
- }
474
- if (this.loggingEnabled) {
475
- console.log(`[${this.context}] Logging enabled`);
476
- }
477
- }
478
- trace(message, ...rest) {
479
- if (this.loggingEnabled && this.loggingLevel === 0 /* Trace */) {
480
- console.log(`[${this.context}] ${message}`, ...rest);
481
- }
482
- }
483
- info(message, ...rest) {
484
- if (this.loggingEnabled && this.loggingLevel <= 1 /* Info */) {
485
- console.log(`[${this.context}] ${message}`, ...rest);
486
- }
487
- }
488
- };
489
- var logger = new Logger("@lightsparkdev/core");
490
-
491
- // src/requester/Requester.ts
492
- import dayjs from "dayjs";
493
- import utc from "dayjs/plugin/utc.js";
494
- import { Observable } from "zen-observable-ts";
495
- var DEFAULT_BASE_URL = "api.lightspark.com";
496
- dayjs.extend(utc);
497
- var Requester = class {
498
- constructor(nodeKeyCache, schemaEndpoint, sdkUserAgent, authProvider = new StubAuthProvider(), baseUrl = DEFAULT_BASE_URL, cryptoImpl = DefaultCrypto, signingKey, fetchImpl = fetch) {
499
- this.nodeKeyCache = nodeKeyCache;
500
- this.schemaEndpoint = schemaEndpoint;
501
- this.sdkUserAgent = sdkUserAgent;
502
- this.authProvider = authProvider;
503
- this.baseUrl = baseUrl;
504
- this.cryptoImpl = cryptoImpl;
505
- this.signingKey = signingKey;
506
- this.fetchImpl = fetchImpl;
507
- this.wsClient = new Promise((resolve) => {
508
- this.resolveWsClient = resolve;
509
- });
510
- void this.initWsClient(baseUrl, authProvider);
511
- autoBind(this);
512
- }
513
- wsClient;
514
- resolveWsClient = null;
80
+ // src/requester/DefaultRequester.ts
81
+ var DefaultRequester = class extends Requester_default {
515
82
  async initWsClient(baseUrl, authProvider) {
516
83
  if (!this.resolveWsClient) {
517
84
  return this.wsClient;
@@ -541,229 +108,7 @@ var Requester = class {
541
108
  }
542
109
  return wsClient;
543
110
  }
544
- async executeQuery(query) {
545
- const data = await this.makeRawRequest(
546
- query.queryPayload,
547
- query.variables || {},
548
- query.signingNodeId,
549
- !!query.skipAuth
550
- );
551
- return query.constructObject(data);
552
- }
553
- subscribe(queryPayload, variables = {}) {
554
- logger.trace(`Requester.subscribe variables`, variables);
555
- const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
556
- const operationMatch = queryPayload.match(operationNameRegex);
557
- if (!operationMatch || operationMatch.length < 3) {
558
- throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
559
- }
560
- const operationType = operationMatch[1];
561
- logger.trace(`Requester.subscribe operationType`, operationType);
562
- if (operationType == "mutation") {
563
- throw new LightsparkException_default(
564
- "InvalidQuery",
565
- "Mutation queries should call makeRawRequest instead"
566
- );
567
- }
568
- for (const key in variables) {
569
- if (variables[key] === void 0) {
570
- variables[key] = null;
571
- }
572
- }
573
- const operation = operationMatch[2];
574
- const bodyData = {
575
- query: queryPayload,
576
- variables,
577
- operationName: operation
578
- };
579
- return new Observable((observer) => {
580
- logger.trace(`Requester.subscribe observer`, observer);
581
- let cleanup = null;
582
- let canceled = false;
583
- void (async () => {
584
- try {
585
- const wsClient = await this.wsClient;
586
- if (!wsClient) {
587
- throw new LightsparkException_default(
588
- "WebSocketNotInitialized",
589
- "WebSocket client is not initialized or is not available in the current environment."
590
- );
591
- }
592
- if (!canceled) {
593
- cleanup = wsClient.subscribe(bodyData, {
594
- next: (data) => observer.next(data),
595
- error: (err) => observer.error(err),
596
- complete: () => observer.complete()
597
- });
598
- }
599
- } catch (err) {
600
- observer.error(err);
601
- }
602
- })();
603
- return () => {
604
- canceled = true;
605
- if (cleanup) {
606
- cleanup();
607
- }
608
- };
609
- });
610
- }
611
- async makeRawRequest(queryPayload, variables = {}, signingNodeId = void 0, skipAuth = false) {
612
- logger.trace(`Requester.makeRawRequest args`, {
613
- queryPayload,
614
- variables,
615
- signingNodeId,
616
- skipAuth
617
- });
618
- const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
619
- const operationMatch = queryPayload.match(operationNameRegex);
620
- if (!operationMatch || operationMatch.length < 3) {
621
- throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
622
- }
623
- const operationType = operationMatch[1];
624
- if (operationType == "subscription") {
625
- throw new LightsparkException_default(
626
- "InvalidQuery",
627
- "Subscription queries should call subscribe instead"
628
- );
629
- }
630
- for (const key in variables) {
631
- if (variables[key] === void 0) {
632
- variables[key] = null;
633
- }
634
- }
635
- const operation = operationMatch[2];
636
- const payload = {
637
- query: queryPayload,
638
- variables,
639
- operationName: operation
640
- };
641
- const browserUserAgent = typeof navigator !== "undefined" ? navigator.userAgent : "";
642
- const sdkUserAgent = this.getSdkUserAgent();
643
- const baseHeaders = {
644
- "Content-Type": "application/json",
645
- "X-Lightspark-SDK": sdkUserAgent,
646
- "User-Agent": browserUserAgent || sdkUserAgent,
647
- "X-GraphQL-Operation": operation
648
- };
649
- const headers = skipAuth ? baseHeaders : await this.authProvider.addAuthHeaders(baseHeaders);
650
- let bodyData = await this.addSigningDataIfNeeded(
651
- payload,
652
- headers,
653
- signingNodeId
654
- );
655
- if (bodyData.length > 1024 && typeof CompressionStream != "undefined") {
656
- bodyData = await compress(bodyData);
657
- headers["Content-Encoding"] = "deflate";
658
- }
659
- let urlWithProtocol = this.baseUrl;
660
- if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
661
- urlWithProtocol = `https://${urlWithProtocol}`;
662
- }
663
- const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
664
- logger.trace(`Requester.makeRawRequest`, {
665
- url,
666
- operationName: operation,
667
- variables,
668
- headers
669
- });
670
- const response = await this.fetchImpl(url, {
671
- method: "POST",
672
- headers,
673
- body: bodyData
674
- });
675
- if (!response.ok) {
676
- throw new LightsparkException_default(
677
- "RequestFailed",
678
- `Request ${operation} failed. ${response.statusText}`
679
- );
680
- }
681
- const responseJson = await response.json();
682
- const data = responseJson.data;
683
- if (!data) {
684
- let firstErrorName = void 0;
685
- if (Array.isArray(responseJson.errors) && responseJson.errors.length > 0) {
686
- const firstError = responseJson.errors[0];
687
- firstErrorName = firstError["extensions"]?.["error_name"];
688
- }
689
- throw new LightsparkException_default(
690
- "RequestFailed",
691
- `Request ${operation} failed. ${JSON.stringify(responseJson.errors)}`,
692
- { errorName: firstErrorName }
693
- );
694
- }
695
- return data;
696
- }
697
- getSdkUserAgent() {
698
- const platform = isNode ? "NodeJS" : "Browser";
699
- const platformVersion = isNode ? process.version : "";
700
- return `${this.sdkUserAgent} ${platform}/${platformVersion}`;
701
- }
702
- stripProtocol(url) {
703
- return url.replace(/.*?:\/\//g, "");
704
- }
705
- async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
706
- if (!signingNodeId) {
707
- return new TextEncoder().encode(JSON.stringify(queryPayload));
708
- }
709
- const query = queryPayload.query;
710
- const variables = queryPayload.variables;
711
- const operationName = queryPayload.operationName;
712
- const nonce = await this.cryptoImpl.getNonce();
713
- const expiration = dayjs.utc().add(1, "hour").format();
714
- const payload = {
715
- query,
716
- variables,
717
- operationName,
718
- nonce,
719
- expires_at: expiration
720
- };
721
- const key = this.signingKey ?? this.nodeKeyCache.getKey(signingNodeId);
722
- if (!key) {
723
- throw new LightsparkSigningException_default(
724
- "Missing node of encrypted_signing_private_key"
725
- );
726
- }
727
- const encodedPayload = new TextEncoder().encode(JSON.stringify(payload));
728
- const signedPayload = await key.sign(encodedPayload);
729
- const encodedSignedPayload = b64encode(signedPayload);
730
- headers["X-Lightspark-Signing"] = JSON.stringify({
731
- v: "1",
732
- signature: encodedSignedPayload
733
- });
734
- return encodedPayload;
735
- }
736
- };
737
- async function compress(data) {
738
- const stream = new Blob([data]).stream();
739
- const compressedStream = stream.pipeThrough(new CompressionStream("deflate"));
740
- const reader = compressedStream.getReader();
741
- const chunks = [];
742
- let done, value;
743
- while (!done) {
744
- ({ done, value } = await reader.read());
745
- chunks.push(value);
746
- }
747
- const blob = new Blob(chunks);
748
- return new Uint8Array(await blob.arrayBuffer());
749
- }
750
- var Requester_default = Requester;
751
-
752
- // src/ServerEnvironment.ts
753
- var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
754
- ServerEnvironment2["PRODUCTION"] = "production";
755
- ServerEnvironment2["DEV"] = "dev";
756
- return ServerEnvironment2;
757
- })(ServerEnvironment || {});
758
- var apiDomainForEnvironment = (environment) => {
759
- switch (environment) {
760
- case "dev" /* DEV */:
761
- return "api.dev.dev.sparkinfra.net";
762
- case "production" /* PRODUCTION */:
763
- return "api.lightspark.com";
764
- }
765
111
  };
766
- var ServerEnvironment_default = ServerEnvironment;
767
112
  export {
768
113
  ConfigKeys,
769
114
  CurrencyUnit,
@@ -776,7 +121,7 @@ export {
776
121
  LoggingLevel,
777
122
  NodeKeyCache_default as NodeKeyCache,
778
123
  RSASigningKey,
779
- Requester_default as Requester,
124
+ DefaultRequester as Requester,
780
125
  Secp256k1SigningKey,
781
126
  ServerEnvironment_default as ServerEnvironment,
782
127
  SigningKey,
@@ -817,6 +162,7 @@ export {
817
162
  isNode,
818
163
  isNumber,
819
164
  isObject,
165
+ isReactNative,
820
166
  isRecord,
821
167
  isSDKCurrencyAmount,
822
168
  isTest,