zaileys 1.1.24 → 1.1.25

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
@@ -42,6 +42,7 @@ var import_ora = __toESM(require("ora"));
42
42
  var import_pino = __toESM(require("pino"));
43
43
 
44
44
  // src/database/handler.ts
45
+ var import_baileys2 = require("baileys");
45
46
  var import_better_sqlite3 = __toESM(require("better-sqlite3"));
46
47
  var import_fs = require("fs");
47
48
  var import_kysely = require("kysely");
@@ -55,6 +56,26 @@ var import_baileys = require("baileys");
55
56
  var import_qrcode = __toESM(require("qrcode"));
56
57
 
57
58
  // src/helpers/utils.ts
59
+ var allocate = (str) => {
60
+ let p = str.length;
61
+ if (!p) {
62
+ return new Uint8Array(1);
63
+ }
64
+ let n = 0;
65
+ while (--p % 4 > 1 && str.charAt(p) === "=") {
66
+ ++n;
67
+ }
68
+ return new Uint8Array(Math.ceil(str.length * 3) / 4 - n).fill(0);
69
+ };
70
+ var parseTimestamp = (timestamp) => {
71
+ if (typeof timestamp === "string") {
72
+ return parseInt(timestamp, 10);
73
+ }
74
+ if (typeof timestamp === "number") {
75
+ return timestamp;
76
+ }
77
+ return timestamp;
78
+ };
58
79
  var toJson = (object = "") => {
59
80
  try {
60
81
  return JSON.parse(object);
@@ -107,6 +128,25 @@ var removeKeys = (obj, keysToRemove) => {
107
128
  Object.entries(obj).filter(([key]) => !keysToRemove.includes(key)).map(([key, value]) => [key, typeof value === "object" ? removeKeys(value, keysToRemove) : value])
108
129
  );
109
130
  };
131
+ var fromObject = (args) => {
132
+ const f = {
133
+ ...args.fingerprint,
134
+ deviceIndexes: Array.isArray(args.fingerprint.deviceIndexes) ? args.fingerprint.deviceIndexes : []
135
+ };
136
+ const message = {
137
+ keyData: Array.isArray(args.keyData) ? args.keyData : new Uint8Array(),
138
+ fingerprint: {
139
+ rawId: f.rawId || 0,
140
+ currentIndex: f.rawId || 0,
141
+ deviceIndexes: f.deviceIndexes
142
+ },
143
+ timestamp: parseTimestamp(args.timestamp)
144
+ };
145
+ if (typeof args.keyData === "string") {
146
+ message.keyData = allocate(args.keyData);
147
+ }
148
+ return message;
149
+ };
110
150
 
111
151
  // src/types/parser/messages.ts
112
152
  var import_stream = require("stream");
@@ -4510,7 +4550,6 @@ var Parser = class {
4510
4550
  };
4511
4551
 
4512
4552
  // src/database/handler.ts
4513
- var import_baileys2 = require("baileys");
4514
4553
  var ConnectDB = (type, url) => {
4515
4554
  if (type === "sqlite") {
4516
4555
  const filepath = url || "./db/zaileys.db";
@@ -4617,7 +4656,7 @@ var AuthAdapterHandler = async (db, session) => {
4617
4656
  for (const id of ids) {
4618
4657
  let value = await readData(`${type}-${id}`);
4619
4658
  if (type === "app-state-sync-key" && value) {
4620
- value = import_baileys2.proto.SenderKeyMessage.fromObject(value);
4659
+ value = fromObject(value);
4621
4660
  }
4622
4661
  data[id] = value;
4623
4662
  }
package/dist/index.mjs CHANGED
@@ -13,6 +13,7 @@ import ora from "ora";
13
13
  import pino from "pino";
14
14
 
15
15
  // src/database/handler.ts
16
+ import { BufferJSON, initAuthCreds } from "baileys";
16
17
  import Database from "better-sqlite3";
17
18
  import { mkdirSync, writeFileSync } from "fs";
18
19
  import { Kysely, MysqlDialect, PostgresDialect, SqliteDialect } from "kysely";
@@ -26,6 +27,26 @@ import { DisconnectReason, downloadMediaMessage, getContentType, getDevice, jidN
26
27
  import QRCode from "qrcode";
27
28
 
28
29
  // src/helpers/utils.ts
30
+ var allocate = (str) => {
31
+ let p = str.length;
32
+ if (!p) {
33
+ return new Uint8Array(1);
34
+ }
35
+ let n = 0;
36
+ while (--p % 4 > 1 && str.charAt(p) === "=") {
37
+ ++n;
38
+ }
39
+ return new Uint8Array(Math.ceil(str.length * 3) / 4 - n).fill(0);
40
+ };
41
+ var parseTimestamp = (timestamp) => {
42
+ if (typeof timestamp === "string") {
43
+ return parseInt(timestamp, 10);
44
+ }
45
+ if (typeof timestamp === "number") {
46
+ return timestamp;
47
+ }
48
+ return timestamp;
49
+ };
29
50
  var toJson = (object = "") => {
30
51
  try {
31
52
  return JSON.parse(object);
@@ -78,6 +99,25 @@ var removeKeys = (obj, keysToRemove) => {
78
99
  Object.entries(obj).filter(([key]) => !keysToRemove.includes(key)).map(([key, value]) => [key, typeof value === "object" ? removeKeys(value, keysToRemove) : value])
79
100
  );
80
101
  };
102
+ var fromObject = (args) => {
103
+ const f = {
104
+ ...args.fingerprint,
105
+ deviceIndexes: Array.isArray(args.fingerprint.deviceIndexes) ? args.fingerprint.deviceIndexes : []
106
+ };
107
+ const message = {
108
+ keyData: Array.isArray(args.keyData) ? args.keyData : new Uint8Array(),
109
+ fingerprint: {
110
+ rawId: f.rawId || 0,
111
+ currentIndex: f.rawId || 0,
112
+ deviceIndexes: f.deviceIndexes
113
+ },
114
+ timestamp: parseTimestamp(args.timestamp)
115
+ };
116
+ if (typeof args.keyData === "string") {
117
+ message.keyData = allocate(args.keyData);
118
+ }
119
+ return message;
120
+ };
81
121
 
82
122
  // src/types/parser/messages.ts
83
123
  import { Readable } from "stream";
@@ -4481,7 +4521,6 @@ var Parser = class {
4481
4521
  };
4482
4522
 
4483
4523
  // src/database/handler.ts
4484
- import { BufferJSON, initAuthCreds, proto as proto2 } from "baileys";
4485
4524
  var ConnectDB = (type, url) => {
4486
4525
  if (type === "sqlite") {
4487
4526
  const filepath = url || "./db/zaileys.db";
@@ -4588,7 +4627,7 @@ var AuthAdapterHandler = async (db, session) => {
4588
4627
  for (const id of ids) {
4589
4628
  let value = await readData(`${type}-${id}`);
4590
4629
  if (type === "app-state-sync-key" && value) {
4591
- value = proto2.SenderKeyMessage.fromObject(value);
4630
+ value = fromObject(value);
4592
4631
  }
4593
4632
  data[id] = value;
4594
4633
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zaileys",
3
- "version": "1.1.24",
3
+ "version": "1.1.25",
4
4
  "description": "Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",