@tma.js/init-data-node 1.2.0 → 1.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/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 N(t, e) {
3
+ function E(t, e) {
4
4
  return b(
5
5
  "sha256",
6
6
  b("sha256", "WebAppData").update(e).digest()
@@ -14,7 +14,7 @@ function $(t) {
14
14
  }
15
15
  return e;
16
16
  }
17
- function S(t) {
17
+ function v(t) {
18
18
  return t ? JSON.stringify({
19
19
  added_to_attachment_menu: t.addedToAttachmentMenu,
20
20
  allows_write_to_pm: t.allowsWriteToPm,
@@ -28,7 +28,7 @@ function S(t) {
28
28
  username: t.username
29
29
  }) : void 0;
30
30
  }
31
- function P({
31
+ function N({
32
32
  chat: t,
33
33
  receiver: e,
34
34
  user: n,
@@ -50,25 +50,25 @@ function P({
50
50
  chat_type: r.chatType || void 0,
51
51
  hash: r.hash,
52
52
  query_id: r.queryId,
53
- receiver: S(e),
53
+ receiver: v(e),
54
54
  start_param: r.startParam || void 0,
55
- user: S(n)
55
+ user: v(n)
56
56
  })
57
57
  );
58
58
  }
59
- function J(t, e, n) {
60
- const r = P({
59
+ function B(t, e, n) {
60
+ const r = N({
61
61
  ...t,
62
62
  authDate: n
63
63
  }), o = [...r.entries()].map(([i, u]) => `${i}=${u}`).sort();
64
- return r.append("hash", N(o.join(`
64
+ return r.append("hash", E(o.join(`
65
65
  `), e)), r.toString();
66
66
  }
67
67
  function M(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 : P(t)
71
+ typeof t == "string" || t instanceof m ? t : N(t)
72
72
  ).forEach((s, l) => {
73
73
  if (l === "hash") {
74
74
  o = s;
@@ -88,7 +88,7 @@ function M(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(), N(i.join(`
91
+ if (i.sort(), E(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", D = "ERR_PARSE";
103
+ const x = "ERR_UNEXPECTED_TYPE", P = "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
- D,
123
+ P,
124
124
  `Unable to parse value${this.type ? ` as ${this.type}` : ""}`,
125
125
  n
126
126
  );
@@ -143,7 +143,7 @@ const c = d((t) => {
143
143
  return !1;
144
144
  throw h();
145
145
  }, "boolean");
146
- function E(t, e) {
146
+ function D(t, e) {
147
147
  const n = {};
148
148
  for (const r in t) {
149
149
  const o = t[r];
@@ -160,7 +160,7 @@ function E(t, e) {
160
160
  const s = u(e(i));
161
161
  s !== void 0 && (n[r] = s);
162
162
  } catch (s) {
163
- throw y(D, `Unable to parse field "${r}"`, s);
163
+ throw y(P, `Unable to parse field "${r}"`, s);
164
164
  }
165
165
  }
166
166
  return n;
@@ -174,7 +174,7 @@ function U(t) {
174
174
  function p(t, e) {
175
175
  return new w((n) => {
176
176
  const r = U(n);
177
- return E(t, (o) => r[o]);
177
+ return D(t, (o) => r[o]);
178
178
  }, !1, e);
179
179
  }
180
180
  const f = d((t) => {
@@ -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"), O = p({
218
+ }, "string"), I = d((t) => q(a().parse(t)), "rgb"), O = p({
219
219
  button_id: (t) => t == null ? void 0 : a().parse(t)
220
220
  });
221
221
  p({
@@ -251,13 +251,13 @@ function C(t, e) {
251
251
  if (typeof n != "string" && !(n instanceof URLSearchParams))
252
252
  throw h();
253
253
  const r = typeof n == "string" ? new URLSearchParams(n) : n;
254
- return E(t, (o) => {
254
+ return D(t, (o) => {
255
255
  const i = r.get(o);
256
256
  return i === null ? void 0 : i;
257
257
  });
258
258
  }, !1, e);
259
259
  }
260
- const L = p({
260
+ const J = p({
261
261
  id: f(),
262
262
  type: a(),
263
263
  title: a(),
@@ -266,7 +266,7 @@ const L = p({
266
266
  from: "photo_url"
267
267
  },
268
268
  username: a().optional()
269
- }, "Chat").optional(), v = p({
269
+ }, "Chat").optional(), S = p({
270
270
  addedToAttachmentMenu: {
271
271
  type: c().optional(),
272
272
  from: "added_to_attachment_menu"
@@ -302,7 +302,7 @@ const L = p({
302
302
  },
303
303
  username: a().optional()
304
304
  }, "User").optional();
305
- function j() {
305
+ function L() {
306
306
  return C({
307
307
  authDate: {
308
308
  type: A(),
@@ -312,7 +312,7 @@ function j() {
312
312
  type: f().optional(),
313
313
  from: "can_send_after"
314
314
  },
315
- chat: L,
315
+ chat: J,
316
316
  chatInstance: {
317
317
  type: a().optional(),
318
318
  from: "chat_instance"
@@ -326,21 +326,21 @@ function j() {
326
326
  type: a().optional(),
327
327
  from: "query_id"
328
328
  },
329
- receiver: v,
329
+ receiver: S,
330
330
  startParam: {
331
331
  type: a().optional(),
332
332
  from: "start_param"
333
333
  },
334
- user: v
334
+ user: S
335
335
  }, "InitData");
336
336
  }
337
- function V(t) {
338
- return j().parse(t);
337
+ function X(t) {
338
+ return L().parse(t);
339
339
  }
340
340
  export {
341
- V as parse,
342
- J as sign,
343
- N as signData,
341
+ X as parse,
342
+ B as sign,
343
+ E as signData,
344
344
  M as validate
345
345
  };
346
346
  //# sourceMappingURL=index.js.map