@tma.js/init-data-node 1.2.4 → 1.2.6

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,12 +1,12 @@
1
1
  import { createHmac as b } from "node:crypto";
2
2
  import { URLSearchParams as m } from "node:url";
3
- function E(t, e) {
3
+ function P(t, e) {
4
4
  return b(
5
5
  "sha256",
6
6
  b("sha256", "WebAppData").update(e).digest()
7
7
  ).update(t).digest().toString("hex");
8
8
  }
9
- function U(t) {
9
+ function $(t) {
10
10
  const e = {};
11
11
  for (const n in t) {
12
12
  const r = t[n];
@@ -28,7 +28,7 @@ function S(t) {
28
28
  username: t.username
29
29
  }) : void 0;
30
30
  }
31
- function N({
31
+ function E({
32
32
  chat: t,
33
33
  receiver: e,
34
34
  user: n,
@@ -36,7 +36,7 @@ function N({
36
36
  }) {
37
37
  var o;
38
38
  return new m(
39
- U({
39
+ $({
40
40
  auth_date: r.authDate ? (+r.authDate / 1e3 | 0).toString() : void 0,
41
41
  can_send_after: (o = r.canSendAfter) == null ? void 0 : o.toString(),
42
42
  chat: t ? JSON.stringify({
@@ -56,19 +56,19 @@ function N({
56
56
  })
57
57
  );
58
58
  }
59
- function W(t, e, n) {
60
- const r = N({
59
+ function B(t, e, n) {
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", E(o.join(`
64
+ return r.append("hash", P(o.join(`
65
65
  `), e)), r.toString();
66
66
  }
67
- function B(t, e, n = {}) {
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 : N(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 B(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(), E(i.join(`
91
+ if (i.sort(), P(i.join(`
92
92
  `), e) !== o)
93
93
  throw new Error("Signature is invalid");
94
94
  }
@@ -100,9 +100,9 @@ class _ extends Error {
100
100
  function y(t, e, n) {
101
101
  return new _(t, e, n);
102
102
  }
103
- const R = "ERR_UNEXPECTED_TYPE", P = "ERR_PARSE";
103
+ const x = "ERR_UNEXPECTED_TYPE", N = "ERR_PARSE";
104
104
  function h() {
105
- return y(R, "Value has unexpected type");
105
+ return y(x, "Value has unexpected type");
106
106
  }
107
107
  class w {
108
108
  constructor(e, n, r) {
@@ -120,7 +120,7 @@ class w {
120
120
  return this.parser(e);
121
121
  } catch (n) {
122
122
  throw y(
123
- P,
123
+ N,
124
124
  `Unable to parse value${this.type ? ` as ${this.type}` : ""}`,
125
125
  n
126
126
  );
@@ -160,12 +160,12 @@ 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(P, `Unable to parse field "${r}"`, s);
163
+ throw y(N, `Unable to parse field "${r}"`, s);
164
164
  }
165
165
  }
166
166
  return n;
167
167
  }
168
- function $(t) {
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
171
  throw h();
@@ -173,7 +173,7 @@ function $(t) {
173
173
  }
174
174
  function p(t, e) {
175
175
  return new w((n) => {
176
- const r = $(n);
176
+ const r = U(n);
177
177
  return D(t, (o) => r[o]);
178
178
  }, !1, e);
179
179
  }
@@ -187,17 +187,17 @@ const f = d((t) => {
187
187
  }
188
188
  throw h();
189
189
  }, "number");
190
- function T(t) {
190
+ function R(t) {
191
191
  return /^#[\da-f]{6}$/i.test(t);
192
192
  }
193
- function q(t) {
193
+ function T(t) {
194
194
  return /^#[\da-f]{3}$/i.test(t);
195
195
  }
196
- function x(t) {
196
+ function q(t) {
197
197
  const e = t.replace(/\s/g, "").toLowerCase();
198
- if (T(e))
198
+ if (R(e))
199
199
  return e;
200
- if (q(e)) {
200
+ if (T(e)) {
201
201
  let r = "#";
202
202
  for (let o = 0; o < 3; o += 1)
203
203
  r += e[1 + o].repeat(2);
@@ -215,7 +215,7 @@ const a = d((t) => {
215
215
  if (typeof t == "string" || typeof t == "number")
216
216
  return t.toString();
217
217
  throw h();
218
- }, "string"), I = d((t) => x(a().parse(t)), "rgb");
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)
@@ -226,7 +226,7 @@ p({
226
226
  }), p({ slug: a(), status: a() }), p({ status: a() }), p({ data: a().optional() }), p({
227
227
  theme_params: (t) => {
228
228
  const e = I().optional();
229
- return Object.entries($(t)).reduce((n, [r, o]) => (n[r] = e.parse(o), n), {});
229
+ return Object.entries(U(t)).reduce((n, [r, o]) => (n[r] = e.parse(o), n), {});
230
230
  }
231
231
  }), p({
232
232
  height: f(),
@@ -246,7 +246,7 @@ function A(t, e) {
246
246
  });
247
247
  }, !1, e);
248
248
  }
249
- const j = p({
249
+ const C = p({
250
250
  id: f(),
251
251
  type: a(),
252
252
  title: a(),
@@ -291,7 +291,7 @@ const j = p({
291
291
  },
292
292
  username: a().optional()
293
293
  }, "User").optional();
294
- function C() {
294
+ function L() {
295
295
  return A({
296
296
  authDate: {
297
297
  type: O(),
@@ -301,7 +301,7 @@ function C() {
301
301
  type: f().optional(),
302
302
  from: "can_send_after"
303
303
  },
304
- chat: j,
304
+ chat: C,
305
305
  chatInstance: {
306
306
  type: a().optional(),
307
307
  from: "chat_instance"
@@ -323,13 +323,13 @@ function C() {
323
323
  user: v
324
324
  }, "InitData");
325
325
  }
326
- function M(t) {
327
- return C().parse(t);
326
+ function V(t) {
327
+ return L().parse(t);
328
328
  }
329
329
  export {
330
- M as parse,
331
- W as sign,
332
- E as signData,
333
- B as validate
330
+ V as parse,
331
+ B as sign,
332
+ P as signData,
333
+ J as validate
334
334
  };
335
335
  //# sourceMappingURL=index.js.map