@tma.js/init-data-node 1.2.5 → 1.2.7
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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -24
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHmac as b } from "node:crypto";
|
|
2
2
|
import { URLSearchParams as m } from "node:url";
|
|
3
|
-
function
|
|
3
|
+
function P(t, e) {
|
|
4
4
|
return b(
|
|
5
5
|
"sha256",
|
|
6
6
|
b("sha256", "WebAppData").update(e).digest()
|
|
@@ -28,7 +28,7 @@ function S(t) {
|
|
|
28
28
|
username: t.username
|
|
29
29
|
}) : void 0;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function E({
|
|
32
32
|
chat: t,
|
|
33
33
|
receiver: e,
|
|
34
34
|
user: n,
|
|
@@ -57,18 +57,18 @@ function N({
|
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
function B(t, e, n) {
|
|
60
|
-
const r =
|
|
60
|
+
const r = E({
|
|
61
61
|
...t,
|
|
62
62
|
authDate: n
|
|
63
63
|
}), o = [...r.entries()].map(([i, u]) => `${i}=${u}`).sort();
|
|
64
|
-
return r.append("hash",
|
|
64
|
+
return r.append("hash", P(o.join(`
|
|
65
65
|
`), e)), r.toString();
|
|
66
66
|
}
|
|
67
67
|
function J(t, e, n = {}) {
|
|
68
68
|
let r, o;
|
|
69
69
|
const i = [];
|
|
70
70
|
if (new m(
|
|
71
|
-
typeof t == "string" || t instanceof m ? t :
|
|
71
|
+
typeof t == "string" || t instanceof m ? t : E(t)
|
|
72
72
|
).forEach((s, l) => {
|
|
73
73
|
if (l === "hash") {
|
|
74
74
|
o = s;
|
|
@@ -88,7 +88,7 @@ function J(t, e, n = {}) {
|
|
|
88
88
|
const { expiresIn: u = 86400 } = n;
|
|
89
89
|
if (u > 0 && +r + u * 1e3 < Date.now())
|
|
90
90
|
throw new Error("Init data expired");
|
|
91
|
-
if (i.sort(),
|
|
91
|
+
if (i.sort(), P(i.join(`
|
|
92
92
|
`), e) !== o)
|
|
93
93
|
throw new Error("Signature is invalid");
|
|
94
94
|
}
|
|
@@ -100,8 +100,8 @@ class _ extends Error {
|
|
|
100
100
|
function y(t, e, n) {
|
|
101
101
|
return new _(t, e, n);
|
|
102
102
|
}
|
|
103
|
-
const x = "ERR_UNEXPECTED_TYPE",
|
|
104
|
-
function
|
|
103
|
+
const x = "ERR_UNEXPECTED_TYPE", N = "ERR_PARSE";
|
|
104
|
+
function h() {
|
|
105
105
|
return y(x, "Value has unexpected type");
|
|
106
106
|
}
|
|
107
107
|
class w {
|
|
@@ -120,7 +120,7 @@ class w {
|
|
|
120
120
|
return this.parser(e);
|
|
121
121
|
} catch (n) {
|
|
122
122
|
throw y(
|
|
123
|
-
|
|
123
|
+
N,
|
|
124
124
|
`Unable to parse value${this.type ? ` as ${this.type}` : ""}`,
|
|
125
125
|
n
|
|
126
126
|
);
|
|
@@ -130,10 +130,10 @@ class w {
|
|
|
130
130
|
return this.isOptional = !0, this;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function d(t, e) {
|
|
134
134
|
return () => new w(t, !1, e);
|
|
135
135
|
}
|
|
136
|
-
const c =
|
|
136
|
+
const c = d((t) => {
|
|
137
137
|
if (typeof t == "boolean")
|
|
138
138
|
return t;
|
|
139
139
|
const e = String(t);
|
|
@@ -141,7 +141,7 @@ const c = h((t) => {
|
|
|
141
141
|
return !0;
|
|
142
142
|
if (e === "0" || e === "false")
|
|
143
143
|
return !1;
|
|
144
|
-
throw
|
|
144
|
+
throw h();
|
|
145
145
|
}, "boolean");
|
|
146
146
|
function D(t, e) {
|
|
147
147
|
const n = {};
|
|
@@ -160,7 +160,7 @@ function D(t, e) {
|
|
|
160
160
|
const s = u(e(i));
|
|
161
161
|
s !== void 0 && (n[r] = s);
|
|
162
162
|
} catch (s) {
|
|
163
|
-
throw y(
|
|
163
|
+
throw y(N, `Unable to parse field "${r}"`, s);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
return n;
|
|
@@ -168,7 +168,7 @@ function D(t, e) {
|
|
|
168
168
|
function U(t) {
|
|
169
169
|
let e = t;
|
|
170
170
|
if (typeof e == "string" && (e = JSON.parse(e)), typeof e != "object" || e === null || Array.isArray(e))
|
|
171
|
-
throw
|
|
171
|
+
throw h();
|
|
172
172
|
return e;
|
|
173
173
|
}
|
|
174
174
|
function p(t, e) {
|
|
@@ -177,7 +177,7 @@ function p(t, e) {
|
|
|
177
177
|
return D(t, (o) => r[o]);
|
|
178
178
|
}, !1, e);
|
|
179
179
|
}
|
|
180
|
-
const f =
|
|
180
|
+
const f = d((t) => {
|
|
181
181
|
if (typeof t == "number")
|
|
182
182
|
return t;
|
|
183
183
|
if (typeof t == "string") {
|
|
@@ -185,7 +185,7 @@ const f = h((t) => {
|
|
|
185
185
|
if (!Number.isNaN(e))
|
|
186
186
|
return e;
|
|
187
187
|
}
|
|
188
|
-
throw
|
|
188
|
+
throw h();
|
|
189
189
|
}, "number");
|
|
190
190
|
function R(t) {
|
|
191
191
|
return /^#[\da-f]{6}$/i.test(t);
|
|
@@ -211,11 +211,11 @@ function q(t) {
|
|
|
211
211
|
return r + (i.length === 1 ? "0" : "") + i;
|
|
212
212
|
}, "#");
|
|
213
213
|
}
|
|
214
|
-
const a =
|
|
214
|
+
const a = d((t) => {
|
|
215
215
|
if (typeof t == "string" || typeof t == "number")
|
|
216
216
|
return t.toString();
|
|
217
|
-
throw
|
|
218
|
-
}, "string"), I =
|
|
217
|
+
throw h();
|
|
218
|
+
}, "string"), I = d((t) => q(a().parse(t)), "rgb");
|
|
219
219
|
p({
|
|
220
220
|
req_id: a(),
|
|
221
221
|
data: (t) => t === null ? t : a().optional().parse(t)
|
|
@@ -234,11 +234,11 @@ p({
|
|
|
234
234
|
is_state_stable: c(),
|
|
235
235
|
is_expanded: c()
|
|
236
236
|
}), p({ status: a() });
|
|
237
|
-
const O =
|
|
237
|
+
const O = d((t) => t instanceof Date ? t : new Date(f().parse(t) * 1e3), "Date");
|
|
238
238
|
function A(t, e) {
|
|
239
239
|
return new w((n) => {
|
|
240
240
|
if (typeof n != "string" && !(n instanceof URLSearchParams))
|
|
241
|
-
throw
|
|
241
|
+
throw h();
|
|
242
242
|
const r = typeof n == "string" ? new URLSearchParams(n) : n;
|
|
243
243
|
return D(t, (o) => {
|
|
244
244
|
const i = r.get(o);
|
|
@@ -323,13 +323,13 @@ function L() {
|
|
|
323
323
|
user: v
|
|
324
324
|
}, "InitData");
|
|
325
325
|
}
|
|
326
|
-
function
|
|
326
|
+
function V(t) {
|
|
327
327
|
return L().parse(t);
|
|
328
328
|
}
|
|
329
329
|
export {
|
|
330
|
-
|
|
330
|
+
V as parse,
|
|
331
331
|
B as sign,
|
|
332
|
-
|
|
332
|
+
P as signData,
|
|
333
333
|
J as validate
|
|
334
334
|
};
|
|
335
335
|
//# sourceMappingURL=index.js.map
|