@awangxcode/qiro-baileys 7.0.0-rc25.6 → 7.0.0-rc26.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/LICENSE +15 -0
- package/README.md +1445 -1041
- package/WAProto/WAProto.proto +4 -0
- package/WAProto/index.d.ts +4067 -243
- package/WAProto/index.js +74957 -43330
- package/assets/branding/qiro-logo.svg +24 -0
- package/assets/branding/qiro-mark.png +0 -0
- package/assets/branding/qiro-mark.svg +34 -0
- package/assets/branding/qiro-social-preview.png +0 -0
- package/lib/Defaults/index.d.ts +16 -1
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +43 -10
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Extensions/advanced.d.ts +1 -1
- package/lib/Extensions/experimental.d.ts +1 -3
- package/lib/Extensions/experimental.d.ts.map +1 -1
- package/lib/Extensions/experimental.js +0 -2
- package/lib/Extensions/experimental.js.map +1 -1
- package/lib/MessageBuilder/index.d.ts +5 -5
- package/lib/MessageBuilder/index.d.ts.map +1 -1
- package/lib/MessageBuilder/index.js +12 -3
- package/lib/MessageBuilder/index.js.map +1 -1
- package/lib/Signal/Group/group-session-builder.d.ts +3 -3
- package/lib/Signal/Group/group-session-builder.js +4 -4
- package/lib/Signal/Group/group_cipher.d.ts +2 -2
- package/lib/Signal/Group/group_cipher.js +4 -4
- package/lib/Signal/Group/index.d.ts +11 -11
- package/lib/Signal/Group/index.js +11 -11
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
- package/lib/Signal/Group/sender-key-message.d.ts +1 -1
- package/lib/Signal/Group/sender-key-message.js +1 -1
- package/lib/Signal/Group/sender-key-record.d.ts +1 -1
- package/lib/Signal/Group/sender-key-record.js +2 -2
- package/lib/Signal/Group/sender-key-state.d.ts +2 -2
- package/lib/Signal/Group/sender-key-state.js +2 -2
- package/lib/Signal/libsignal.d.ts +3 -3
- package/lib/Signal/libsignal.js +6 -6
- package/lib/Signal/lid-mapping.d.ts +2 -2
- package/lib/Signal/lid-mapping.js +4 -4
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/Client/index.d.ts +2 -2
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +1 -1
- package/lib/Socket/Client/websocket.d.ts +1 -1
- package/lib/Socket/Client/websocket.js +2 -2
- package/lib/Socket/business.d.ts +347 -65
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +5 -5
- package/lib/Socket/chats.d.ts +129 -16
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +293 -18
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +332 -50
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/communities.js +5 -5
- package/lib/Socket/groups.d.ts +133 -27
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +4 -4
- package/lib/Socket/index.d.ts +366 -84
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +8 -5
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +324 -41
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +81 -30
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +340 -44
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +171 -35
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts +1 -1
- package/lib/Socket/mex.js +1 -1
- package/lib/Socket/newsletter.d.ts +324 -39
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +345 -5
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +24 -11
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +89 -36
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +397 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Types/Auth.d.ts +2 -2
- package/lib/Types/Chat.d.ts +19 -6
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Chat.js.map +1 -1
- package/lib/Types/Events.d.ts +9 -9
- package/lib/Types/GroupMetadata.d.ts +2 -2
- package/lib/Types/Message.d.ts +70 -6
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Mex.d.ts +68 -39
- package/lib/Types/Mex.d.ts.map +1 -1
- package/lib/Types/Mex.js +66 -0
- package/lib/Types/Mex.js.map +1 -1
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +1 -1
- package/lib/Types/Socket.d.ts +50 -5
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.d.ts +1 -1
- package/lib/Types/USync.d.ts +2 -2
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.d.ts +14 -14
- package/lib/Types/index.js +12 -12
- package/lib/Utils/audio-sticker.d.ts +14 -0
- package/lib/Utils/audio-sticker.js +172 -0
- package/lib/Utils/auth-store.d.ts +30 -0
- package/lib/Utils/auth-store.js +77 -0
- package/lib/Utils/auth-utils.d.ts +2 -2
- package/lib/Utils/auth-utils.js +4 -4
- package/lib/Utils/browser-utils.d.ts +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +3 -3
- package/lib/Utils/chat-theme.d.ts +34 -0
- package/lib/Utils/chat-theme.js +336 -0
- package/lib/Utils/chat-utils.d.ts +3 -3
- package/lib/Utils/chat-utils.js +9 -9
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +3 -3
- package/lib/Utils/companion-reg-client-utils.js +1 -1
- package/lib/Utils/crypto.d.ts +1 -1
- package/lib/Utils/crypto.js +1 -1
- package/lib/Utils/decode-wa-message.d.ts +18 -4
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +57 -2
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +4 -3
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +7 -8
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +5 -4
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +13 -22
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/group-metadata-cache.d.ts +4 -0
- package/lib/Utils/group-metadata-cache.js +25 -0
- package/lib/Utils/history.d.ts +1 -1
- package/lib/Utils/history.js +6 -6
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/html-app.d.ts +19 -0
- package/lib/Utils/html-app.js +96 -0
- package/lib/Utils/html-multiplayer.d.ts +10 -0
- package/lib/Utils/html-multiplayer.js +94 -0
- package/lib/Utils/identity-change-handler.d.ts +2 -2
- package/lib/Utils/identity-change-handler.js +2 -2
- package/lib/Utils/index.d.ts +46 -21
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +48 -21
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview-metadata.d.ts +47 -0
- package/lib/Utils/link-preview-metadata.js +88 -0
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +2 -2
- package/lib/Utils/message-retry-manager.d.ts +1 -1
- package/lib/Utils/messages-media.d.ts +35 -6
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +69 -22
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +45 -5
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +123 -32
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/modern-messages.d.ts +150 -0
- package/lib/Utils/modern-messages.js +496 -0
- package/lib/Utils/native-flow.d.ts +11 -0
- package/lib/Utils/native-flow.js +116 -0
- package/lib/Utils/newsletter-status.d.ts +158 -0
- package/lib/Utils/newsletter-status.js +651 -0
- package/lib/Utils/noise-handler.d.ts +3 -3
- package/lib/Utils/noise-handler.js +3 -3
- package/lib/Utils/offline-node-processor.d.ts +1 -1
- package/lib/Utils/optional-media.d.ts +3 -0
- package/lib/Utils/optional-media.js +46 -0
- package/lib/Utils/payment-messages.d.ts +38 -0
- package/lib/Utils/payment-messages.js +160 -0
- package/lib/Utils/pre-key-manager.d.ts +2 -2
- package/lib/Utils/process-message.d.ts +13 -2
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +87 -7
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/reporting-utils.d.ts +2 -2
- package/lib/Utils/reporting-utils.js +1 -1
- package/lib/Utils/scheduled-message.d.ts +51 -0
- package/lib/Utils/scheduled-message.js +113 -0
- package/lib/Utils/sender-key-memory.d.ts +19 -0
- package/lib/Utils/sender-key-memory.js +51 -0
- package/lib/Utils/signal.d.ts +4 -4
- package/lib/Utils/signal.js +4 -4
- package/lib/Utils/stanza-ack.d.ts +1 -1
- package/lib/Utils/status-stickers.d.ts +127 -0
- package/lib/Utils/status-stickers.js +261 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -2
- package/lib/Utils/sync-action-utils.js +1 -1
- package/lib/Utils/tc-token-utils.d.ts +2 -2
- package/lib/Utils/tc-token-utils.js +1 -1
- package/lib/Utils/ttl-cache.d.ts +29 -0
- package/lib/Utils/ttl-cache.js +121 -0
- package/lib/Utils/use-mongo-auth-state.d.ts +22 -0
- package/lib/Utils/use-mongo-auth-state.js +68 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +28 -15
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/use-mysql-auth-state.d.ts +20 -0
- package/lib/Utils/use-mysql-auth-state.js +80 -0
- package/lib/Utils/use-nekodb-auth.d.ts +19 -0
- package/lib/Utils/use-nekodb-auth.js +111 -0
- package/lib/Utils/use-postgres-auth-state.d.ts +20 -0
- package/lib/Utils/use-postgres-auth-state.js +80 -0
- package/lib/Utils/use-redis-auth-state.d.ts +20 -0
- package/lib/Utils/use-redis-auth-state.js +90 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
- package/lib/Utils/use-sqlite-auth-state.js +121 -0
- package/lib/Utils/username.d.ts +12 -0
- package/lib/Utils/username.js +59 -0
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +5 -5
- package/lib/Utils/voice-recognition.d.ts +53 -0
- package/lib/Utils/voice-recognition.js +219 -0
- package/lib/VoIP/audio-feeder.d.ts +24 -0
- package/lib/VoIP/audio-feeder.js +276 -0
- package/lib/VoIP/index.d.ts +93 -0
- package/lib/VoIP/index.js +998 -0
- package/lib/VoIP/relay-transport.d.ts +5 -0
- package/lib/VoIP/relay-transport.js +824 -0
- package/lib/VoIP/signaling.d.ts +11 -0
- package/lib/VoIP/signaling.js +1099 -0
- package/lib/VoIP/types.d.ts +2 -0
- package/lib/VoIP/types.js +12 -0
- package/lib/VoIP/video-feeder.d.ts +24 -0
- package/lib/VoIP/video-feeder.js +276 -0
- package/lib/VoIP/wasm-engine.d.ts +26 -0
- package/lib/VoIP/wasm-engine.js +1318 -0
- package/lib/VoIP/worker-bootstrap.js +1022 -0
- package/lib/WABinary/decode.d.ts +1 -1
- package/lib/WABinary/decode.js +2 -2
- package/lib/WABinary/encode.d.ts +1 -1
- package/lib/WABinary/encode.js +2 -2
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +3 -1
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WABinary/index.d.ts +5 -5
- package/lib/WABinary/index.js +5 -5
- package/lib/WABinary/jid-utils.d.ts +2 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -1
- package/lib/WABinary/jid-utils.js +3 -1
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/WABinary/types.d.ts +1 -1
- package/lib/WABinary/types.js +1 -1
- package/lib/WAM/BinaryInfo.d.ts +1 -1
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAM/encode.js +2 -2
- package/lib/WAM/index.d.ts +3 -3
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -5
- package/lib/WAUSync/Protocols/index.js +5 -5
- package/lib/WAUSync/USyncQuery.d.ts +3 -3
- package/lib/WAUSync/USyncQuery.js +5 -5
- package/lib/WAUSync/index.d.ts +3 -3
- package/lib/WAUSync/index.js +3 -3
- package/lib/extensions/awang-MessageBuilder.js +1 -1
- package/lib/index.d.ts +14 -10
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -11
- package/lib/index.js.map +1 -1
- package/package.json +78 -31
- package/MIGRASI-QIRO-BAILEYS-RC25.md +0 -102
- package/QIRO-BAILEYS-RC25.md +0 -168
- package/THIRD_PARTY_NOTICES.md +0 -49
- /package/{engine-requirements.js → config/engine-requirements.js} +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { loadOptionalModule, makeAuthStateFromStore } from './auth-store.js';
|
|
3
|
+
const resolveCommand = (client, names) => {
|
|
4
|
+
for (const name of names) {
|
|
5
|
+
if (typeof client[name] === 'function') {
|
|
6
|
+
return name;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
throw new Error(`redis client exposes none of: ${names.join(', ')}`);
|
|
10
|
+
};
|
|
11
|
+
export async function useRedisAuthState(opts = {}) {
|
|
12
|
+
const session = opts.session ?? 'default';
|
|
13
|
+
const prefix = opts.prefix ?? 'baileys_auth';
|
|
14
|
+
let client = opts.client;
|
|
15
|
+
let owned = false;
|
|
16
|
+
if (!client) {
|
|
17
|
+
if (!opts.uri) {
|
|
18
|
+
throw new Error('useRedisAuthState needs a client or a uri');
|
|
19
|
+
}
|
|
20
|
+
const Redis = await loadOptionalModule('ioredis', 'useRedisAuthState');
|
|
21
|
+
client = new Redis(opts.uri, opts.config);
|
|
22
|
+
owned = true;
|
|
23
|
+
}
|
|
24
|
+
if (typeof client.connect === 'function' && client.isOpen === false) {
|
|
25
|
+
await client.connect();
|
|
26
|
+
}
|
|
27
|
+
const commands = {
|
|
28
|
+
hget: resolveCommand(client, ['hGet', 'hget']),
|
|
29
|
+
hmget: resolveCommand(client, ['hmGet', 'hmget']),
|
|
30
|
+
hset: resolveCommand(client, ['hSet', 'hset']),
|
|
31
|
+
hdel: resolveCommand(client, ['hDel', 'hdel']),
|
|
32
|
+
del: resolveCommand(client, ['del', 'DEL']),
|
|
33
|
+
keys: resolveCommand(client, ['keys', 'KEYS'])
|
|
34
|
+
};
|
|
35
|
+
const hashKey = (type) => `${prefix}:${session}:${type}`;
|
|
36
|
+
const store = {
|
|
37
|
+
read: async (type, id) => {
|
|
38
|
+
const value = await client[commands.hget](hashKey(type), id);
|
|
39
|
+
return value ?? null;
|
|
40
|
+
},
|
|
41
|
+
readMany: async (type, ids) => {
|
|
42
|
+
if (!ids.length) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
const values = await client[commands.hmget](hashKey(type), ids);
|
|
46
|
+
const rows = {};
|
|
47
|
+
ids.forEach((id, index) => {
|
|
48
|
+
const value = values?.[index];
|
|
49
|
+
if (value !== null && value !== undefined) {
|
|
50
|
+
rows[id] = value;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return rows;
|
|
54
|
+
},
|
|
55
|
+
write: async (type, id, value) => {
|
|
56
|
+
await client[commands.hset](hashKey(type), id, value);
|
|
57
|
+
},
|
|
58
|
+
apply: async (writes, removals) => {
|
|
59
|
+
const chain = typeof client.multi === 'function' ? client.multi() : null;
|
|
60
|
+
if (chain) {
|
|
61
|
+
for (const entry of writes) {
|
|
62
|
+
chain[commands.hset](hashKey(entry.type), entry.id, entry.value);
|
|
63
|
+
}
|
|
64
|
+
for (const entry of removals) {
|
|
65
|
+
chain[commands.hdel](hashKey(entry.type), entry.id);
|
|
66
|
+
}
|
|
67
|
+
await chain.exec();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
for (const entry of writes) {
|
|
71
|
+
await client[commands.hset](hashKey(entry.type), entry.id, entry.value);
|
|
72
|
+
}
|
|
73
|
+
for (const entry of removals) {
|
|
74
|
+
await client[commands.hdel](hashKey(entry.type), entry.id);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
clear: async () => {
|
|
78
|
+
const found = await client[commands.keys](`${prefix}:${session}:*`);
|
|
79
|
+
if (found?.length) {
|
|
80
|
+
await client[commands.del](found);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
close: async () => {
|
|
84
|
+
if (owned) {
|
|
85
|
+
await (client.quit?.() ?? client.disconnect?.());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return makeAuthStateFromStore(store);
|
|
90
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { readFile, rename, stat, writeFile } from 'fs/promises';
|
|
3
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
4
|
+
import { proto } from '../../WAProto/index.js';
|
|
5
|
+
import { initAuthCreds } from './auth-utils.js';
|
|
6
|
+
import { BufferJSON } from './generics.js';
|
|
7
|
+
import { LRUCache } from 'lru-cache';
|
|
8
|
+
import { Mutex } from 'async-mutex';
|
|
9
|
+
|
|
10
|
+
const FLUSH_TIMEOUT_MS = 3000;
|
|
11
|
+
|
|
12
|
+
export const useSingleFileAuthState = async (fileName) => {
|
|
13
|
+
const cache = new LRUCache({
|
|
14
|
+
max: 20000,
|
|
15
|
+
ttl: 1000 * DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
16
|
+
updateAgeOnGet: false,
|
|
17
|
+
updateAgeOnHas: false,
|
|
18
|
+
ttlAutopurge: true
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const mutex = new Mutex();
|
|
22
|
+
let fileData = {};
|
|
23
|
+
let isLoaded = false;
|
|
24
|
+
let flushTimeout = null;
|
|
25
|
+
const loadKey = async () => {
|
|
26
|
+
return await mutex.runExclusive(async () => {
|
|
27
|
+
if (isLoaded)
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
const data = JSON.parse(await readFile(fileName, 'utf-8'), BufferJSON.reviver);
|
|
31
|
+
fileData = data || {};
|
|
32
|
+
for (const [keyName, value] of Object.entries(fileData)) {
|
|
33
|
+
cache.set(keyName, value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
fileData = {};
|
|
38
|
+
}
|
|
39
|
+
isLoaded = true;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const flushKey = () => {
|
|
43
|
+
if (flushTimeout)
|
|
44
|
+
return;
|
|
45
|
+
flushTimeout = setTimeout(async () => {
|
|
46
|
+
flushTimeout = null;
|
|
47
|
+
await mutex.runExclusive(async () => {
|
|
48
|
+
try {
|
|
49
|
+
const tempFile = fileName + '.temp';
|
|
50
|
+
await writeFile(tempFile, JSON.stringify(fileData, BufferJSON.replacer));
|
|
51
|
+
await rename(tempFile, fileName);
|
|
52
|
+
}
|
|
53
|
+
catch { }
|
|
54
|
+
});
|
|
55
|
+
}, FLUSH_TIMEOUT_MS);
|
|
56
|
+
};
|
|
57
|
+
const writeKey = (keyName, value) => {
|
|
58
|
+
cache.set(keyName, value);
|
|
59
|
+
fileData[keyName] = value;
|
|
60
|
+
flushKey();
|
|
61
|
+
};
|
|
62
|
+
const removeKey = (keyName) => {
|
|
63
|
+
cache.delete(keyName);
|
|
64
|
+
delete fileData[keyName];
|
|
65
|
+
flushKey();
|
|
66
|
+
};
|
|
67
|
+
const fileInfo = await stat(fileName).catch(() => null);
|
|
68
|
+
if (!fileInfo) {
|
|
69
|
+
await writeFile(fileName, '{}');
|
|
70
|
+
}
|
|
71
|
+
else if (!fileInfo.isFile()) {
|
|
72
|
+
throw new Error(`found something that is not a file at ${fileName}, either delete it or specify a different location`);
|
|
73
|
+
}
|
|
74
|
+
await loadKey();
|
|
75
|
+
const creds = fileData['creds'] || initAuthCreds();
|
|
76
|
+
return {
|
|
77
|
+
state: {
|
|
78
|
+
creds,
|
|
79
|
+
keys: {
|
|
80
|
+
get: (type, ids) => {
|
|
81
|
+
const data = {};
|
|
82
|
+
for (const id of ids) {
|
|
83
|
+
const keyName = type + id;
|
|
84
|
+
let value = cache.get(keyName);
|
|
85
|
+
if (value === undefined && fileData[keyName] !== undefined) {
|
|
86
|
+
value = fileData[keyName];
|
|
87
|
+
cache.set(keyName, value);
|
|
88
|
+
}
|
|
89
|
+
if (type === 'app-state-sync-key' && value) {
|
|
90
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
91
|
+
}
|
|
92
|
+
data[id] = value;
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
},
|
|
96
|
+
set: (data) => {
|
|
97
|
+
for (const category in data) {
|
|
98
|
+
for (const id in data[category]) {
|
|
99
|
+
const keyName = category + id;
|
|
100
|
+
const value = data[category][id];
|
|
101
|
+
value ? writeKey(keyName, value) : removeKey(keyName);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
saveCreds: () => writeKey('creds', creds)
|
|
108
|
+
};
|
|
109
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export function useSqliteAuthState(opts: any): Promise<{
|
|
3
|
+
state: {
|
|
4
|
+
creds: any;
|
|
5
|
+
keys: {
|
|
6
|
+
get: (type: any, ids: any) => Promise<{}>;
|
|
7
|
+
set: (data: any) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
saveCreds: () => Promise<void>;
|
|
11
|
+
clearAuth: () => Promise<void>;
|
|
12
|
+
close: () => Promise<void>;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { initAuthCreds } from './auth-utils.js';
|
|
4
|
+
import { BufferJSON } from './generics.js';
|
|
5
|
+
async function loadBetterSqlite3() {
|
|
6
|
+
try {
|
|
7
|
+
|
|
8
|
+
const mod = (await import('better-sqlite3'));
|
|
9
|
+
return mod.default ?? mod;
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
const helpful = new Error('`better-sqlite3` is required for `useSqliteAuthState`. Install it as a peer dependency: `npm install better-sqlite3` (or `yarn add better-sqlite3`).');
|
|
13
|
+
|
|
14
|
+
helpful.cause = err;
|
|
15
|
+
throw helpful;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const CREDS_ROW_KEY = '__creds__';
|
|
19
|
+
const CREATE_SCHEMA_SQL = `
|
|
20
|
+
CREATE TABLE IF NOT EXISTS creds (
|
|
21
|
+
key TEXT PRIMARY KEY,
|
|
22
|
+
value TEXT NOT NULL
|
|
23
|
+
);
|
|
24
|
+
CREATE TABLE IF NOT EXISTS signal_keys (
|
|
25
|
+
type TEXT NOT NULL,
|
|
26
|
+
id TEXT NOT NULL,
|
|
27
|
+
value TEXT NOT NULL,
|
|
28
|
+
PRIMARY KEY (type, id)
|
|
29
|
+
);
|
|
30
|
+
CREATE INDEX IF NOT EXISTS signal_keys_type_idx ON signal_keys(type);
|
|
31
|
+
`;
|
|
32
|
+
export async function useSqliteAuthState(opts) {
|
|
33
|
+
let db;
|
|
34
|
+
let owned = false;
|
|
35
|
+
if (opts.database) {
|
|
36
|
+
db = opts.database;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const Database = await loadBetterSqlite3();
|
|
40
|
+
db = new Database(opts.dbPath);
|
|
41
|
+
owned = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
db.pragma('journal_mode = WAL');
|
|
45
|
+
db.pragma('synchronous = NORMAL');
|
|
46
|
+
db.exec(CREATE_SCHEMA_SQL);
|
|
47
|
+
const stmts = {
|
|
48
|
+
credsSelect: db.prepare('SELECT value FROM creds WHERE key = ?'),
|
|
49
|
+
credsUpsert: db.prepare('INSERT INTO creds (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'),
|
|
50
|
+
keySelect: db.prepare('SELECT value FROM signal_keys WHERE type = ? AND id = ?'),
|
|
51
|
+
keyUpsert: db.prepare('INSERT INTO signal_keys (type, id, value) VALUES (?, ?, ?) ON CONFLICT(type, id) DO UPDATE SET value = excluded.value'),
|
|
52
|
+
keyDelete: db.prepare('DELETE FROM signal_keys WHERE type = ? AND id = ?'),
|
|
53
|
+
keyListIds: db.prepare('SELECT id FROM signal_keys WHERE type = ?'),
|
|
54
|
+
keyList: db.prepare('SELECT id, value FROM signal_keys WHERE type = ?'),
|
|
55
|
+
clearKeys: db.prepare('DELETE FROM signal_keys'),
|
|
56
|
+
clearCreds: db.prepare('DELETE FROM creds')
|
|
57
|
+
};
|
|
58
|
+
const loadCreds = () => {
|
|
59
|
+
const row = stmts.credsSelect.get(CREDS_ROW_KEY);
|
|
60
|
+
if (!row)
|
|
61
|
+
return initAuthCreds();
|
|
62
|
+
return JSON.parse(row.value, BufferJSON.reviver);
|
|
63
|
+
};
|
|
64
|
+
const persistCreds = (creds) => {
|
|
65
|
+
stmts.credsUpsert.run(CREDS_ROW_KEY, JSON.stringify(creds, BufferJSON.replacer));
|
|
66
|
+
};
|
|
67
|
+
const creds = loadCreds();
|
|
68
|
+
return {
|
|
69
|
+
state: {
|
|
70
|
+
creds,
|
|
71
|
+
keys: {
|
|
72
|
+
get: async (type, ids) => {
|
|
73
|
+
const data = {};
|
|
74
|
+
for (const id of ids) {
|
|
75
|
+
const row = stmts.keySelect.get(type, id);
|
|
76
|
+
if (row) {
|
|
77
|
+
let value = JSON.parse(row.value, BufferJSON.reviver);
|
|
78
|
+
if (type === 'app-state-sync-key' && value) {
|
|
79
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
80
|
+
}
|
|
81
|
+
data[id] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return data;
|
|
85
|
+
},
|
|
86
|
+
set: async (data) => {
|
|
87
|
+
const writeTx = db.transaction(() => {
|
|
88
|
+
for (const category in data) {
|
|
89
|
+
for (const id in data[category]) {
|
|
90
|
+
const value = data[category][id];
|
|
91
|
+
if (value) {
|
|
92
|
+
const stringified = JSON.stringify(value, BufferJSON.replacer);
|
|
93
|
+
stmts.keyUpsert.run(category, id, stringified);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
stmts.keyDelete.run(category, id);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
writeTx();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
saveCreds: async () => {
|
|
106
|
+
persistCreds(creds);
|
|
107
|
+
},
|
|
108
|
+
clearAuth: async () => {
|
|
109
|
+
const wipe = db.transaction(() => {
|
|
110
|
+
stmts.clearKeys.run();
|
|
111
|
+
stmts.clearCreds.run();
|
|
112
|
+
});
|
|
113
|
+
wipe();
|
|
114
|
+
},
|
|
115
|
+
close: async () => {
|
|
116
|
+
if (owned) {
|
|
117
|
+
db.close();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const USERNAME_MIN_LENGTH = 3;
|
|
2
|
+
export declare const USERNAME_MAX_LENGTH = 35;
|
|
3
|
+
export declare const USERNAME_PIN_LENGTH = 4;
|
|
4
|
+
export type UsernameValidationErrorType = 'INVALID_CHARACTER' | 'INVALID_LENGTH' | 'INVALID_NO_LETTERS' | 'INVALID_PERIODS' | 'INVALID_DOMAIN_SUFFIX' | 'INVALID_WWW_PREFIX' | 'INVALID_WORD';
|
|
5
|
+
export declare const UsernameValidationError: Record<UsernameValidationErrorType, UsernameValidationErrorType>;
|
|
6
|
+
export declare const stripUsernamePrefix: (username: string) => string;
|
|
7
|
+
export declare const displayUsername: (username: string) => string;
|
|
8
|
+
export declare const validateUsername: (username: string) => {
|
|
9
|
+
isValid: boolean;
|
|
10
|
+
errorType?: UsernameValidationErrorType;
|
|
11
|
+
};
|
|
12
|
+
export declare const isUsernamePin: (pin: string) => boolean;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export const USERNAME_MIN_LENGTH = 3;
|
|
3
|
+
export const USERNAME_MAX_LENGTH = 35;
|
|
4
|
+
export const USERNAME_PIN_LENGTH = 4;
|
|
5
|
+
const LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
6
|
+
const DIGITS = '0123456789';
|
|
7
|
+
const LETTER_SET = new Set(LETTERS.split(''));
|
|
8
|
+
const ALLOWED_SET = new Set([...LETTERS.split(''), ...DIGITS.split(''), '_', '.']);
|
|
9
|
+
const RESERVED_SUFFIXES = ['.com', '.org', '.net', '.int', '.edu', '.gov', '.mil', '.arpa', '.html', '.htm', '.txt', '.xml'];
|
|
10
|
+
const RESERVED_WORDS = ['whatsapp', 'instagram', 'facebook', 'oculus'];
|
|
11
|
+
const PIN_PATTERN = /^[0-9]{4}$/;
|
|
12
|
+
export const UsernameValidationError = {
|
|
13
|
+
INVALID_CHARACTER: 'INVALID_CHARACTER',
|
|
14
|
+
INVALID_LENGTH: 'INVALID_LENGTH',
|
|
15
|
+
INVALID_NO_LETTERS: 'INVALID_NO_LETTERS',
|
|
16
|
+
INVALID_PERIODS: 'INVALID_PERIODS',
|
|
17
|
+
INVALID_DOMAIN_SUFFIX: 'INVALID_DOMAIN_SUFFIX',
|
|
18
|
+
INVALID_WWW_PREFIX: 'INVALID_WWW_PREFIX',
|
|
19
|
+
INVALID_WORD: 'INVALID_WORD'
|
|
20
|
+
};
|
|
21
|
+
export const stripUsernamePrefix = (username) => {
|
|
22
|
+
return typeof username === 'string' && username.startsWith('@') ? username.slice(1) : username;
|
|
23
|
+
};
|
|
24
|
+
export const displayUsername = (username) => {
|
|
25
|
+
return '@' + stripUsernamePrefix(username);
|
|
26
|
+
};
|
|
27
|
+
export const validateUsername = (username) => {
|
|
28
|
+
const value = stripUsernamePrefix(username);
|
|
29
|
+
if (typeof value !== 'string') {
|
|
30
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_CHARACTER };
|
|
31
|
+
}
|
|
32
|
+
const characters = Array.from(value);
|
|
33
|
+
if (!characters.every(character => ALLOWED_SET.has(character))) {
|
|
34
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_CHARACTER };
|
|
35
|
+
}
|
|
36
|
+
if (value.length < USERNAME_MIN_LENGTH || value.length > USERNAME_MAX_LENGTH) {
|
|
37
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_LENGTH };
|
|
38
|
+
}
|
|
39
|
+
if (!characters.some(character => LETTER_SET.has(character))) {
|
|
40
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_NO_LETTERS };
|
|
41
|
+
}
|
|
42
|
+
if (value.startsWith('.') || value.endsWith('.') || value.includes('..')) {
|
|
43
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_PERIODS };
|
|
44
|
+
}
|
|
45
|
+
const lowered = value.toLowerCase();
|
|
46
|
+
if (lowered.startsWith('www.')) {
|
|
47
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_WWW_PREFIX };
|
|
48
|
+
}
|
|
49
|
+
if (RESERVED_SUFFIXES.some(suffix => lowered.endsWith(suffix))) {
|
|
50
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_DOMAIN_SUFFIX };
|
|
51
|
+
}
|
|
52
|
+
if (RESERVED_WORDS.some(word => lowered.includes(word))) {
|
|
53
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_WORD };
|
|
54
|
+
}
|
|
55
|
+
return { isValid: true };
|
|
56
|
+
};
|
|
57
|
+
export const isUsernamePin = (pin) => {
|
|
58
|
+
return typeof pin === 'string' && PIN_PATTERN.test(pin);
|
|
59
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { proto } from '../../WAProto/index.js';
|
|
2
|
-
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types
|
|
3
|
-
import { type BinaryNode } from '../WABinary
|
|
2
|
+
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
|
+
import { type BinaryNode } from '../WABinary';
|
|
4
4
|
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
5
5
|
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
6
6
|
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, "advSecretKey" | "signedIdentityKey" | "signalIdentities">) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { createHash } from 'crypto';
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
|
-
import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from '../Defaults
|
|
5
|
-
import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary
|
|
6
|
-
import { Curve, hmacSign } from './crypto
|
|
7
|
-
import { encodeBigEndian } from './generics
|
|
8
|
-
import { createSignalIdentity } from './signal
|
|
4
|
+
import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from '../Defaults';
|
|
5
|
+
import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary';
|
|
6
|
+
import { Curve, hmacSign } from './crypto';
|
|
7
|
+
import { encodeBigEndian } from './generics';
|
|
8
|
+
import { createSignalIdentity } from './signal';
|
|
9
9
|
const getUserAgent = (config) => {
|
|
10
10
|
return {
|
|
11
11
|
appVersion: {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type VoiceRecognitionContext = {
|
|
2
|
+
message: any;
|
|
3
|
+
audioMessage: any;
|
|
4
|
+
chatJid: string;
|
|
5
|
+
senderJid: string;
|
|
6
|
+
isGroup: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type VoiceTranscriptionInput = VoiceRecognitionContext & {
|
|
9
|
+
buffer: Buffer;
|
|
10
|
+
mimetype: string;
|
|
11
|
+
};
|
|
12
|
+
export type VoiceTranscriptionResult = string | {
|
|
13
|
+
text?: string;
|
|
14
|
+
transcript?: string;
|
|
15
|
+
language?: string;
|
|
16
|
+
confidence?: number;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
export type VoiceRecognitionOptions = {
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
transcribe: (input: VoiceTranscriptionInput) => VoiceTranscriptionResult | Promise<VoiceTranscriptionResult>;
|
|
22
|
+
wakePhrases?: string | string[];
|
|
23
|
+
getWakePhrases?: (context: VoiceRecognitionContext) => string | string[] | undefined | Promise<string | string[] | undefined>;
|
|
24
|
+
shouldProcess?: (context: VoiceRecognitionContext) => boolean | Promise<boolean>;
|
|
25
|
+
allowQuotedActivation?: boolean;
|
|
26
|
+
pttOnly?: boolean;
|
|
27
|
+
maxDuration?: number;
|
|
28
|
+
maxBytes?: number;
|
|
29
|
+
downloadOptions?: any;
|
|
30
|
+
};
|
|
31
|
+
export type VoiceRecognitionEvent = VoiceRecognitionContext & {
|
|
32
|
+
transcript: string;
|
|
33
|
+
commandText: string;
|
|
34
|
+
activation: 'quoted' | 'wake-phrase' | null;
|
|
35
|
+
wakePhrase: string | null;
|
|
36
|
+
language?: string;
|
|
37
|
+
confidence?: number;
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
};
|
|
40
|
+
export function normalizeVoiceText(value: any): string;
|
|
41
|
+
export function matchVoiceWakePhrase(transcript: any, phrases?: string | string[]): {
|
|
42
|
+
phrase: string;
|
|
43
|
+
normalizedPhrase: string;
|
|
44
|
+
normalizedTranscript: string;
|
|
45
|
+
} | null;
|
|
46
|
+
export function removeVoiceWakePhrase(transcript: any, wakePhrase: any): string;
|
|
47
|
+
export function bindVoiceRecognition(sock: any, config?: {
|
|
48
|
+
voiceRecognition?: VoiceRecognitionOptions;
|
|
49
|
+
getMessage?: (key: any) => Promise<any>;
|
|
50
|
+
logger?: any;
|
|
51
|
+
}, dependencies?: {
|
|
52
|
+
downloadContentFromMessage?: (...args: any[]) => Promise<any>;
|
|
53
|
+
}): () => void;
|