@react-pdf-kit/viewer 0.0.0-experimental.6 → 0.0.0-experimental.8
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/utils/hooks/useLicense.js +50 -35
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as v, useCallback as E, useEffect as b } from "react";
|
|
2
2
|
import { LicenseType as y } from "../types.js";
|
|
3
|
-
import { appConsole as
|
|
3
|
+
import { appConsole as c } from "../appConsole.js";
|
|
4
4
|
import "../../de_DE-a553b162.js";
|
|
5
|
-
const A = /* @__PURE__ */ new Date("2026-03-
|
|
5
|
+
const A = /* @__PURE__ */ new Date("2026-03-23T03:03:12.500Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", o = {
|
|
6
6
|
invalidLicense: `You are currently using without a valid license. ${d}`,
|
|
7
7
|
mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
|
|
8
8
|
expired: `Your license key has expired. ${d}`,
|
|
@@ -23,71 +23,86 @@ function L(r) {
|
|
|
23
23
|
}
|
|
24
24
|
async function S(r, t = "SHA-256") {
|
|
25
25
|
try {
|
|
26
|
-
const { data: e, signature: n } = JSON.parse(atob(r)), i = I(
|
|
26
|
+
const { data: e, signature: n } = JSON.parse(atob(r)), i = I(`-----BEGIN PUBLIC KEY-----
|
|
27
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyrIi83Zr5AKaWO6zbZmX
|
|
28
|
+
qv3McVhtnPOnWCiFgf5xeaglLzEwMiXo3gALaPoBp5Q0WPOSBE9GTqwOyQUgpDNS
|
|
29
|
+
BuQ0cjOzQdFM3GPnKSqQThZJfjUmD9egMZDmfhcpFGPybUoicoIEFQOdX2vMFUfn
|
|
30
|
+
6yjRsyvbK6UPTombYl785V8dXNnnIHa4tQC1JSaSe/bhG3e/6kbQCy9VJ23242q9
|
|
31
|
+
WJpx9c2sZ+bmyI0r9Zx0PfqcDJzDfKn45v96EtxGhV16OZhqkbj4ljiJ/mfqfCkx
|
|
32
|
+
ybkm9nvxz0hAwcEftQaxl/0cZ1RxtsRcL+V3msLsmGcs9nPqAuXecbfg9QVCi/+m
|
|
33
|
+
iwIDAQAB
|
|
34
|
+
-----END PUBLIC KEY-----`), s = await window.crypto.subtle.importKey(
|
|
27
35
|
"spki",
|
|
28
36
|
// str2ab(publicKeyContent), // Convert PEM string to ArrayBuffer
|
|
29
37
|
i,
|
|
30
38
|
{ name: "RSA-PSS", hash: t },
|
|
31
39
|
!0,
|
|
32
40
|
["verify"]
|
|
33
|
-
)
|
|
34
|
-
if (!await window.crypto.subtle.verify(
|
|
41
|
+
), a = await window.crypto.subtle.verify(
|
|
35
42
|
{ name: "RSA-PSS", saltLength: 32 },
|
|
36
|
-
|
|
43
|
+
s,
|
|
37
44
|
L(n),
|
|
38
45
|
// Convert signature to ArrayBuffer
|
|
39
46
|
new TextEncoder().encode(atob(e))
|
|
40
|
-
)
|
|
41
|
-
|
|
47
|
+
);
|
|
48
|
+
if (c.debug(">>> Verified license key validity", a), !a)
|
|
49
|
+
throw new Error(o.invalidSignature);
|
|
42
50
|
return JSON.parse(atob(e));
|
|
43
51
|
} catch {
|
|
44
|
-
throw new Error(
|
|
52
|
+
throw new Error(o.invalidLicense);
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
|
-
const x = (r, t) =>
|
|
55
|
+
const x = (r, t) => {
|
|
56
|
+
switch (r) {
|
|
57
|
+
case "specific":
|
|
58
|
+
return t === window.location.host;
|
|
59
|
+
case "wildcard":
|
|
60
|
+
return t ? window.location.host.includes(t) : !1;
|
|
61
|
+
}
|
|
62
|
+
}, u = {
|
|
48
63
|
isValid: !0,
|
|
49
|
-
invalidatedMessage:
|
|
64
|
+
invalidatedMessage: o.invalidLicense,
|
|
50
65
|
type: void 0
|
|
51
66
|
}, N = (r) => {
|
|
52
|
-
const [t, e] =
|
|
53
|
-
if (e((
|
|
54
|
-
throw e({ ...u, validating: !1 }), new Error(
|
|
67
|
+
const [t, e] = v(u), n = E(async () => {
|
|
68
|
+
if (e((l) => ({ ...l, validating: !0 })), !r)
|
|
69
|
+
throw e({ ...u, validating: !1 }), new Error(o.invalidLicense);
|
|
55
70
|
let i;
|
|
56
71
|
try {
|
|
57
72
|
i = await S(r);
|
|
58
|
-
} catch (
|
|
59
|
-
throw
|
|
73
|
+
} catch (l) {
|
|
74
|
+
throw c.warn(l.message), new Error(l.message);
|
|
60
75
|
}
|
|
61
|
-
|
|
62
|
-
const { avu:
|
|
63
|
-
if (!
|
|
76
|
+
c.debug(">>> validatedLicense", i);
|
|
77
|
+
const { avu: s, exp: a, dmt: w, dm: p, t: f } = i;
|
|
78
|
+
if (!a)
|
|
64
79
|
throw new Error("License is missing expiration timestamp");
|
|
65
|
-
if (
|
|
80
|
+
if (a > Number.MAX_SAFE_INTEGER / 1e3)
|
|
66
81
|
throw new Error("Invalid expiration timestamp: value too large");
|
|
67
|
-
const g = new Date(
|
|
82
|
+
const g = new Date(a * 1e3), h = (/* @__PURE__ */ new Date()).getTime();
|
|
68
83
|
if (g.getTime() < h)
|
|
69
|
-
throw new Error(
|
|
70
|
-
if (!
|
|
84
|
+
throw new Error(o.expired);
|
|
85
|
+
if (!s)
|
|
71
86
|
throw new Error("License is missing available until version timestamp");
|
|
72
|
-
if (
|
|
87
|
+
if (s > Number.MAX_SAFE_INTEGER / 1e3)
|
|
73
88
|
throw new Error("Invalid available until version timestamp: value too large");
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
throw new Error(
|
|
77
|
-
if (
|
|
78
|
-
throw new Error(
|
|
89
|
+
const m = new Date(s * 1e3);
|
|
90
|
+
if (c.debug("availableUntilTimestamp", m), m.getTime() < A.getTime())
|
|
91
|
+
throw new Error(o.exceededVersion);
|
|
92
|
+
if (f !== y.Custom && !x(w, p))
|
|
93
|
+
throw new Error(o.mismatchedDomain);
|
|
79
94
|
return {
|
|
80
95
|
isValid: !0,
|
|
81
|
-
type:
|
|
96
|
+
type: f,
|
|
82
97
|
invalidatedMessage: void 0
|
|
83
98
|
};
|
|
84
99
|
}, [r]);
|
|
85
100
|
return b(() => {
|
|
86
|
-
n().then(({ isValid: i, type:
|
|
101
|
+
n().then(({ isValid: i, type: s, invalidatedMessage: a }) => {
|
|
87
102
|
e({
|
|
88
103
|
isValid: i,
|
|
89
|
-
type:
|
|
90
|
-
invalidatedMessage:
|
|
104
|
+
type: s,
|
|
105
|
+
invalidatedMessage: a,
|
|
91
106
|
validating: !1
|
|
92
107
|
});
|
|
93
108
|
}).catch((i) => {
|
|
@@ -95,7 +110,7 @@ const x = (r, t) => r === "specific" ? t === window.location.host : window.locat
|
|
|
95
110
|
...u,
|
|
96
111
|
isValid: !1,
|
|
97
112
|
validating: !1
|
|
98
|
-
}),
|
|
113
|
+
}), c.warn(i.message);
|
|
99
114
|
});
|
|
100
115
|
}, [n]), t;
|
|
101
116
|
};
|
package/package.json
CHANGED