@lightsparkdev/core 0.2.1 → 0.2.2
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/chunk-23X5L5S3.js +604 -0
- package/dist/chunk-4OZ5E62P.js +608 -0
- package/dist/chunk-5FD46UVI.js +600 -0
- package/dist/chunk-BAQMCJ7C.js +630 -0
- package/dist/chunk-GFTKZSHK.js +627 -0
- package/dist/chunk-I3HKDOEE.js +627 -0
- package/dist/chunk-J6LSW6XO.js +601 -0
- package/dist/chunk-JUD4MOOQ.js +608 -0
- package/dist/chunk-KX6HH6CX.js +629 -0
- package/dist/chunk-MZCDWVLH.js +634 -0
- package/dist/chunk-NY3BK66J.js +624 -0
- package/dist/chunk-Q7UUXZNC.js +26 -0
- package/dist/chunk-WT2HYC6Q.js +601 -0
- package/dist/chunk-YYVOX4YM.js +600 -0
- package/dist/chunk-ZUIUADXH.js +616 -0
- package/dist/crypto-rn-2BYOHLMG.js +72 -0
- package/dist/crypto-rn-2YV53C3B.js +72 -0
- package/dist/crypto-rn-3HFXYG7I.js +75 -0
- package/dist/crypto-rn-3HLWLVZS.js +76 -0
- package/dist/crypto-rn-3N3JTBLE.js +83 -0
- package/dist/crypto-rn-3OEMMMOD.js +74 -0
- package/dist/crypto-rn-5EZSRY5Y.js +82 -0
- package/dist/crypto-rn-5KM2YVOI.js +82 -0
- package/dist/crypto-rn-6335R2CU.js +80 -0
- package/dist/crypto-rn-6ZHSL7CX.js +72 -0
- package/dist/crypto-rn-7DWXMO2Q.js +75 -0
- package/dist/crypto-rn-7GTI374I.js +81 -0
- package/dist/crypto-rn-AXDY3LDG.js +124 -0
- package/dist/crypto-rn-BZ2KZ2YR.js +68 -0
- package/dist/crypto-rn-CAPL7MYC.js +80 -0
- package/dist/crypto-rn-CBAKEB7C.js +68 -0
- package/dist/crypto-rn-CBWHV2F5.js +82 -0
- package/dist/crypto-rn-CS36MQ4X.js +77 -0
- package/dist/crypto-rn-E4RZNGIB.js +82 -0
- package/dist/crypto-rn-H4NIT5CT.js +70 -0
- package/dist/crypto-rn-IAC27WLZ.js +74 -0
- package/dist/crypto-rn-LLY6FCWE.js +82 -0
- package/dist/crypto-rn-MOWVVG3L.js +78 -0
- package/dist/crypto-rn-OAPLHNM5.js +73 -0
- package/dist/crypto-rn-PVAG5TVH.js +80 -0
- package/dist/crypto-rn-QLVBL5DI.js +75 -0
- package/dist/crypto-rn-TBKXR3SR.js +68 -0
- package/dist/crypto-rn-TSQJA6A3.js +81 -0
- package/dist/crypto-rn-U3XEJXIM.js +77 -0
- package/dist/crypto-rn-UHTZEVAR.js +74 -0
- package/dist/crypto-rn-V3ZNQSFI.js +79 -0
- package/dist/crypto-rn-VGNP6VZW.js +75 -0
- package/dist/crypto-rn-XMYCUEGV.js +72 -0
- package/dist/crypto-rn-YPOTC5RI.js +73 -0
- package/dist/index.cjs +91 -114
- package/dist/index.d.ts +30 -17
- package/dist/index.js +90 -104
- package/package.json +2 -1
- package/src/crypto/NodeKeyCache.ts +18 -15
- package/src/crypto/crypto.ts +72 -78
- package/src/requester/Requester.ts +9 -13
- package/src/utils/base64.ts +51 -2
|
@@ -12,8 +12,8 @@ import Query from "./Query.js";
|
|
|
12
12
|
import AuthProvider from "../auth/AuthProvider.js";
|
|
13
13
|
import StubAuthProvider from "../auth/StubAuthProvider.js";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
CryptoInterface,
|
|
16
|
+
DefaultCrypto,
|
|
17
17
|
LightsparkSigningException,
|
|
18
18
|
} from "../crypto/crypto.js";
|
|
19
19
|
import NodeKeyCache from "../crypto/NodeKeyCache.js";
|
|
@@ -34,7 +34,8 @@ class Requester {
|
|
|
34
34
|
private readonly schemaEndpoint: string,
|
|
35
35
|
private readonly sdkUserAgent: string,
|
|
36
36
|
private readonly authProvider: AuthProvider = new StubAuthProvider(),
|
|
37
|
-
private readonly baseUrl: string = DEFAULT_BASE_URL
|
|
37
|
+
private readonly baseUrl: string = DEFAULT_BASE_URL,
|
|
38
|
+
private readonly cryptoImpl: CryptoInterface = DefaultCrypto
|
|
38
39
|
) {
|
|
39
40
|
let websocketImpl;
|
|
40
41
|
if (typeof WebSocket === "undefined" && typeof window === "undefined") {
|
|
@@ -183,7 +184,7 @@ class Requester {
|
|
|
183
184
|
const variables = queryPayload.variables;
|
|
184
185
|
const operationName = queryPayload.operationName;
|
|
185
186
|
|
|
186
|
-
const nonce = await getNonce();
|
|
187
|
+
const nonce = await this.cryptoImpl.getNonce();
|
|
187
188
|
const expiration = dayjs.utc().add(1, "hour").format();
|
|
188
189
|
|
|
189
190
|
const payload = {
|
|
@@ -201,16 +202,11 @@ class Requester {
|
|
|
201
202
|
);
|
|
202
203
|
}
|
|
203
204
|
|
|
205
|
+
if (typeof TextEncoder === "undefined") {
|
|
206
|
+
const TextEncoder = (await import("text-encoding")).TextEncoder;
|
|
207
|
+
}
|
|
204
208
|
const encodedPayload = new TextEncoder().encode(JSON.stringify(payload));
|
|
205
|
-
const
|
|
206
|
-
const signedPayload = await cryptoImpl.subtle.sign(
|
|
207
|
-
{
|
|
208
|
-
name: "RSA-PSS",
|
|
209
|
-
saltLength: 32,
|
|
210
|
-
},
|
|
211
|
-
key,
|
|
212
|
-
encodedPayload
|
|
213
|
-
);
|
|
209
|
+
const signedPayload = await this.cryptoImpl.sign(key, encodedPayload);
|
|
214
210
|
const encodedSignedPayload = b64encode(signedPayload);
|
|
215
211
|
|
|
216
212
|
headers["X-Lightspark-Signing"] = JSON.stringify({
|
package/src/utils/base64.ts
CHANGED
|
@@ -1,7 +1,56 @@
|
|
|
1
1
|
// Copyright ©, 2023, Lightspark Group, Inc. - All Rights Reserved
|
|
2
2
|
|
|
3
|
+
const chars =
|
|
4
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
5
|
+
const Base64 = {
|
|
6
|
+
btoa: (input: string = "") => {
|
|
7
|
+
let str = input;
|
|
8
|
+
let output = "";
|
|
9
|
+
|
|
10
|
+
for (
|
|
11
|
+
let block = 0, charCode, i = 0, map = chars;
|
|
12
|
+
str.charAt(i | 0) || ((map = "="), i % 1);
|
|
13
|
+
output += map.charAt(63 & (block >> (8 - (i % 1) * 8)))
|
|
14
|
+
) {
|
|
15
|
+
charCode = str.charCodeAt((i += 3 / 4));
|
|
16
|
+
|
|
17
|
+
if (charCode > 0xff) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
block = (block << 8) | charCode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return output;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
atob: (input: string = "") => {
|
|
30
|
+
let str = input.replace(/=+$/, "");
|
|
31
|
+
let output = "";
|
|
32
|
+
|
|
33
|
+
if (str.length % 4 == 1) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"'atob' failed: The string to be decoded is not correctly encoded."
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
for (
|
|
39
|
+
let bc = 0, bs = 0, buffer, i = 0;
|
|
40
|
+
(buffer = str.charAt(i++));
|
|
41
|
+
~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4)
|
|
42
|
+
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
|
|
43
|
+
: 0
|
|
44
|
+
) {
|
|
45
|
+
buffer = chars.indexOf(buffer);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return output;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
3
52
|
export const b64decode = (encoded: string): Uint8Array => {
|
|
4
|
-
return Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0));
|
|
53
|
+
return Uint8Array.from(Base64.atob(encoded), (c) => c.charCodeAt(0));
|
|
5
54
|
};
|
|
6
55
|
|
|
7
56
|
export const urlsafe_b64decode = (encoded: string): Uint8Array => {
|
|
@@ -9,7 +58,7 @@ export const urlsafe_b64decode = (encoded: string): Uint8Array => {
|
|
|
9
58
|
};
|
|
10
59
|
|
|
11
60
|
export const b64encode = (data: ArrayBuffer): string => {
|
|
12
|
-
return btoa(
|
|
61
|
+
return Base64.btoa(
|
|
13
62
|
String.fromCharCode.apply(null, Array.from(new Uint8Array(data)))
|
|
14
63
|
);
|
|
15
64
|
};
|