@nerxa/socketon 0.0.0-stage → 1.21.1
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/EXPERIMENTAL.md +350 -0
- package/LICENSE +24 -0
- package/README.md +6317 -2
- package/WAProto/index.d.ts +17301 -0
- package/WAProto/index.js +125088 -0
- package/engine-requirements.js +14 -0
- package/package.json +125 -4
- package/src/Defaults/index.d.ts +152 -0
- package/src/Defaults/index.js +164 -0
- package/src/MessageBuilder/bot-signature.d.ts +22 -0
- package/src/MessageBuilder/bot-signature.js +122 -0
- package/src/MessageBuilder/extras.d.ts +449 -0
- package/src/MessageBuilder/extras.js +1356 -0
- package/src/MessageBuilder/index.d.ts +210 -0
- package/src/MessageBuilder/index.js +3594 -0
- package/src/MessageBuilder/metaai.d.ts +438 -0
- package/src/MessageBuilder/metaai.js +890 -0
- package/src/Signal/Group/ciphertext-message.d.ts +9 -0
- package/src/Signal/Group/ciphertext-message.js +11 -0
- package/src/Signal/Group/group-session-builder.d.ts +7 -0
- package/src/Signal/Group/group-session-builder.js +27 -0
- package/src/Signal/Group/group_cipher.d.ts +11 -0
- package/src/Signal/Group/group_cipher.js +78 -0
- package/src/Signal/Group/index.d.ts +11 -0
- package/src/Signal/Group/index.js +11 -0
- package/src/Signal/Group/keyhelper.d.ts +6 -0
- package/src/Signal/Group/keyhelper.js +17 -0
- package/src/Signal/Group/sender-chain-key.d.ts +13 -0
- package/src/Signal/Group/sender-chain-key.js +25 -0
- package/src/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/src/Signal/Group/sender-key-distribution-message.js +62 -0
- package/src/Signal/Group/sender-key-message.d.ts +18 -0
- package/src/Signal/Group/sender-key-message.js +65 -0
- package/src/Signal/Group/sender-key-name.d.ts +11 -0
- package/src/Signal/Group/sender-key-name.js +47 -0
- package/src/Signal/Group/sender-key-record.d.ts +12 -0
- package/src/Signal/Group/sender-key-record.js +40 -0
- package/src/Signal/Group/sender-key-state.d.ts +16 -0
- package/src/Signal/Group/sender-key-state.js +83 -0
- package/src/Signal/Group/sender-message-key.d.ts +11 -0
- package/src/Signal/Group/sender-message-key.js +25 -0
- package/src/Signal/libsignal.d.ts +54 -0
- package/src/Signal/libsignal.js +427 -0
- package/src/Signal/lid-mapping.d.ts +20 -0
- package/src/Signal/lid-mapping.js +274 -0
- package/src/Socket/Client/index.d.ts +2 -0
- package/src/Socket/Client/index.js +3 -0
- package/src/Socket/Client/tcp.js +177 -0
- package/src/Socket/Client/types.d.ts +5 -0
- package/src/Socket/Client/types.js +9 -0
- package/src/Socket/Client/websocket.d.ts +12 -0
- package/src/Socket/Client/websocket.js +53 -0
- package/src/Socket/business.d.ts +431 -0
- package/src/Socket/business.js +379 -0
- package/src/Socket/chats.d.ts +247 -0
- package/src/Socket/chats.js +1484 -0
- package/src/Socket/communities.d.ts +598 -0
- package/src/Socket/communities.js +421 -0
- package/src/Socket/email.js +145 -0
- package/src/Socket/groups.d.ts +298 -0
- package/src/Socket/groups.js +339 -0
- package/src/Socket/index.d.ts +581 -0
- package/src/Socket/index.js +77 -0
- package/src/Socket/messages-recv.d.ts +370 -0
- package/src/Socket/messages-recv.js +1864 -0
- package/src/Socket/messages-send.d.ts +390 -0
- package/src/Socket/messages-send.js +1574 -0
- package/src/Socket/mex.d.ts +1 -0
- package/src/Socket/mex.js +44 -0
- package/src/Socket/mobile-builders.js +72 -0
- package/src/Socket/mobile.js +424 -0
- package/src/Socket/newsletter.d.ts +468 -0
- package/src/Socket/newsletter.js +671 -0
- package/src/Socket/socket.d.ts +77 -0
- package/src/Socket/socket.js +1106 -0
- package/src/Store/index.d.ts +3 -0
- package/src/Store/index.js +3 -0
- package/src/Store/make-in-memory-store.d.ts +62 -0
- package/src/Store/make-in-memory-store.js +396 -0
- package/src/Store/make-ordered-dictionary.d.ts +12 -0
- package/src/Store/make-ordered-dictionary.js +78 -0
- package/src/Store/object-repository.d.ts +10 -0
- package/src/Store/object-repository.js +23 -0
- package/src/Types/Auth.d.ts +1 -0
- package/src/Types/Auth.js +1 -0
- package/src/Types/Bussines.d.ts +1 -0
- package/src/Types/Bussines.js +1 -0
- package/src/Types/Call.d.ts +1 -0
- package/src/Types/Call.js +1 -0
- package/src/Types/Chat.d.ts +2 -0
- package/src/Types/Chat.js +24 -0
- package/src/Types/Contact.d.ts +1 -0
- package/src/Types/Contact.js +1 -0
- package/src/Types/Events.d.ts +1 -0
- package/src/Types/Events.js +0 -0
- package/src/Types/GroupMetadata.d.ts +5 -0
- package/src/Types/GroupMetadata.js +6 -0
- package/src/Types/Label.d.ts +2 -0
- package/src/Types/Label.js +24 -0
- package/src/Types/LabelAssociation.d.ts +2 -0
- package/src/Types/LabelAssociation.js +6 -0
- package/src/Types/Message.d.ts +13 -0
- package/src/Types/Message.js +23 -0
- package/src/Types/Mex.d.ts +2 -0
- package/src/Types/Mex.js +95 -0
- package/src/Types/Product.d.ts +1 -0
- package/src/Types/Product.js +1 -0
- package/src/Types/Signal.d.ts +1 -0
- package/src/Types/Signal.js +0 -0
- package/src/Types/Socket.d.ts +1 -0
- package/src/Types/Socket.js +0 -0
- package/src/Types/State.d.ts +5 -0
- package/src/Types/State.js +54 -0
- package/src/Types/USync.d.ts +1 -0
- package/src/Types/USync.js +0 -0
- package/src/Types/index.d.ts +13 -0
- package/src/Types/index.js +25 -0
- package/src/Utils/auth-store.d.ts +29 -0
- package/src/Utils/auth-store.js +76 -0
- package/src/Utils/auth-utils.d.ts +58 -0
- package/src/Utils/auth-utils.js +273 -0
- package/src/Utils/browser-utils.d.ts +9 -0
- package/src/Utils/browser-utils.js +28 -0
- package/src/Utils/business.d.ts +49 -0
- package/src/Utils/business.js +226 -0
- package/src/Utils/chat-utils.d.ts +408 -0
- package/src/Utils/chat-utils.js +846 -0
- package/src/Utils/companion-reg-client-utils.d.ts +4 -0
- package/src/Utils/companion-reg-client-utils.js +39 -0
- package/src/Utils/crypto.d.ts +39 -0
- package/src/Utils/crypto.js +110 -0
- package/src/Utils/decode-wa-message.d.ts +99 -0
- package/src/Utils/decode-wa-message.js +373 -0
- package/src/Utils/event-buffer.d.ts +22 -0
- package/src/Utils/event-buffer.js +624 -0
- package/src/Utils/generics.d.ts +63 -0
- package/src/Utils/generics.js +375 -0
- package/src/Utils/group-metadata-cache.d.ts +4 -0
- package/src/Utils/group-metadata-cache.js +25 -0
- package/src/Utils/history.d.ts +75 -0
- package/src/Utils/history.js +131 -0
- package/src/Utils/html-app.d.ts +19 -0
- package/src/Utils/html-app.js +96 -0
- package/src/Utils/html-multiplayer.d.ts +10 -0
- package/src/Utils/html-multiplayer.js +94 -0
- package/src/Utils/identity-change-handler.d.ts +13 -0
- package/src/Utils/identity-change-handler.js +48 -0
- package/src/Utils/index.d.ts +44 -0
- package/src/Utils/index.js +44 -0
- package/src/Utils/link-preview-metadata.d.ts +47 -0
- package/src/Utils/link-preview-metadata.js +88 -0
- package/src/Utils/link-preview.d.ts +12 -0
- package/src/Utils/link-preview.js +79 -0
- package/src/Utils/logger.d.ts +2 -0
- package/src/Utils/logger.js +2 -0
- package/src/Utils/lt-hash.d.ts +6 -0
- package/src/Utils/lt-hash.js +3 -0
- package/src/Utils/make-mutex.d.ts +6 -0
- package/src/Utils/make-mutex.js +32 -0
- package/src/Utils/message-retry-manager.d.ts +79 -0
- package/src/Utils/message-retry-manager.js +255 -0
- package/src/Utils/messages-media.d.ts +136 -0
- package/src/Utils/messages-media.js +814 -0
- package/src/Utils/messages.d.ts +62 -0
- package/src/Utils/messages.js +2223 -0
- package/src/Utils/mobile-companion-crypto.js +191 -0
- package/src/Utils/modern-messages.d.ts +150 -0
- package/src/Utils/modern-messages.js +496 -0
- package/src/Utils/native-flow.d.ts +11 -0
- package/src/Utils/native-flow.js +115 -0
- package/src/Utils/newsletter-status.d.ts +158 -0
- package/src/Utils/newsletter-status.js +651 -0
- package/src/Utils/noise-handler.d.ts +20 -0
- package/src/Utils/noise-handler.js +200 -0
- package/src/Utils/offline-node-processor.d.ts +9 -0
- package/src/Utils/offline-node-processor.js +33 -0
- package/src/Utils/optional-media.d.ts +3 -0
- package/src/Utils/optional-media.js +45 -0
- package/src/Utils/payment-messages.d.ts +66 -0
- package/src/Utils/payment-messages.js +160 -0
- package/src/Utils/pre-key-manager.d.ts +25 -0
- package/src/Utils/pre-key-manager.js +95 -0
- package/src/Utils/process-message.d.ts +60 -0
- package/src/Utils/process-message.js +688 -0
- package/src/Utils/reporting-utils.d.ts +12 -0
- package/src/Utils/reporting-utils.js +256 -0
- package/src/Utils/scheduled-message.d.ts +51 -0
- package/src/Utils/scheduled-message.js +112 -0
- package/src/Utils/sender-key-memory.d.ts +19 -0
- package/src/Utils/sender-key-memory.js +51 -0
- package/src/Utils/signal.d.ts +82 -0
- package/src/Utils/signal.js +193 -0
- package/src/Utils/stanza-ack.d.ts +16 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/status-stickers.d.ts +127 -0
- package/src/Utils/status-stickers.js +260 -0
- package/src/Utils/sync-action-utils.d.ts +2 -0
- package/src/Utils/sync-action-utils.js +44 -0
- package/src/Utils/tc-token-utils.d.ts +29 -0
- package/src/Utils/tc-token-utils.js +155 -0
- package/src/Utils/ttl-cache.d.ts +28 -0
- package/src/Utils/ttl-cache.js +120 -0
- package/src/Utils/use-mongo-auth-state.d.ts +21 -0
- package/src/Utils/use-mongo-auth-state.js +67 -0
- package/src/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/src/Utils/use-multi-file-auth-state.js +106 -0
- package/src/Utils/use-mysql-auth-state.d.ts +19 -0
- package/src/Utils/use-mysql-auth-state.js +79 -0
- package/src/Utils/use-postgres-auth-state.d.ts +19 -0
- package/src/Utils/use-postgres-auth-state.js +79 -0
- package/src/Utils/use-redis-auth-state.d.ts +19 -0
- package/src/Utils/use-redis-auth-state.js +89 -0
- package/src/Utils/use-single-file-auth-state.d.ts +10 -0
- package/src/Utils/use-single-file-auth-state.js +108 -0
- package/src/Utils/use-sqlite-auth-state.d.ts +12 -0
- package/src/Utils/use-sqlite-auth-state.js +120 -0
- package/src/Utils/useNekoDBAuth.d.ts +19 -0
- package/src/Utils/useNekoDBAuth.js +111 -0
- package/src/Utils/username.d.ts +12 -0
- package/src/Utils/username.js +58 -0
- package/src/Utils/validate-connection.d.ts +43 -0
- package/src/Utils/validate-connection.js +277 -0
- package/src/Utils/voice-recognition.d.ts +53 -0
- package/src/Utils/voice-recognition.js +219 -0
- package/src/Voip/audio-feeder.d.ts +24 -0
- package/src/Voip/audio-feeder.js +268 -0
- package/src/Voip/index.d.ts +88 -0
- package/src/Voip/index.js +936 -0
- package/src/Voip/relay-transport.d.ts +5 -0
- package/src/Voip/relay-transport.js +824 -0
- package/src/Voip/signaling.d.ts +11 -0
- package/src/Voip/signaling.js +1099 -0
- package/src/Voip/types.d.ts +2 -0
- package/src/Voip/types.js +12 -0
- package/src/Voip/video-feeder.d.ts +24 -0
- package/src/Voip/video-feeder.js +268 -0
- package/src/Voip/wasm-engine.d.ts +26 -0
- package/src/Voip/wasm-engine.js +1307 -0
- package/src/Voip/worker-bootstrap.js +1023 -0
- package/src/WABinary/constants.d.ts +22 -0
- package/src/WABinary/constants.js +1300 -0
- package/src/WABinary/decode.d.ts +9 -0
- package/src/WABinary/decode.js +261 -0
- package/src/WABinary/encode.d.ts +2 -0
- package/src/WABinary/encode.js +219 -0
- package/src/WABinary/generic-utils.d.ts +76 -0
- package/src/WABinary/generic-utils.js +214 -0
- package/src/WABinary/index.d.ts +5 -0
- package/src/WABinary/index.js +5 -0
- package/src/WABinary/jid-utils.d.ts +30 -0
- package/src/WABinary/jid-utils.js +97 -0
- package/src/WABinary/types.d.ts +1 -0
- package/src/WABinary/types.js +0 -0
- package/src/WAM/BinaryInfo.d.ts +7 -0
- package/src/WAM/BinaryInfo.js +9 -0
- package/src/WAM/constants.d.ts +34926 -0
- package/src/WAM/constants.js +22852 -0
- package/src/WAM/encode.d.ts +1 -0
- package/src/WAM/encode.js +148 -0
- package/src/WAM/index.d.ts +3 -0
- package/src/WAM/index.js +3 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +50 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +51 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.d.ts +5 -0
- package/src/WAUSync/Protocols/index.js +5 -0
- package/src/WAUSync/USyncQuery.d.ts +20 -0
- package/src/WAUSync/USyncQuery.js +93 -0
- package/src/WAUSync/USyncUser.d.ts +16 -0
- package/src/WAUSync/USyncUser.js +30 -0
- package/src/WAUSync/index.d.ts +3 -0
- package/src/WAUSync/index.js +3 -0
- package/src/assets/wasm/README.md +76 -0
- package/src/assets/wasm/loader.js +5 -0
- package/src/assets/wasm/whatsapp.wasm +0 -0
- package/src/assets/wasm/worker-modules.js +273 -0
- package/src/index.d.ts +43 -0
- package/src/index.js +48 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { loadOptionalModule, makeAuthStateFromStore } from './auth-store.js';
|
|
2
|
+
const quoteIdentifier = (name) => {
|
|
3
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {
|
|
4
|
+
throw new Error(`table name must be a plain identifier, got ${JSON.stringify(name)}`);
|
|
5
|
+
}
|
|
6
|
+
return `"${name}"`;
|
|
7
|
+
};
|
|
8
|
+
export async function usePostgresAuthState(opts = {}) {
|
|
9
|
+
const table = quoteIdentifier(opts.table ?? 'baileys_auth');
|
|
10
|
+
const session = opts.session ?? 'default';
|
|
11
|
+
let pool = opts.pool;
|
|
12
|
+
let owned = false;
|
|
13
|
+
if (!pool) {
|
|
14
|
+
if (!opts.connectionString && !opts.config) {
|
|
15
|
+
throw new Error('usePostgresAuthState needs a pool, a connectionString, or a config');
|
|
16
|
+
}
|
|
17
|
+
const pg = await loadOptionalModule('pg', 'usePostgresAuthState');
|
|
18
|
+
pool = new pg.Pool(opts.config ?? { connectionString: opts.connectionString });
|
|
19
|
+
owned = true;
|
|
20
|
+
}
|
|
21
|
+
await pool.query(`CREATE TABLE IF NOT EXISTS ${table} (
|
|
22
|
+
session TEXT NOT NULL,
|
|
23
|
+
type TEXT NOT NULL,
|
|
24
|
+
id TEXT NOT NULL,
|
|
25
|
+
value TEXT NOT NULL,
|
|
26
|
+
PRIMARY KEY (session, type, id)
|
|
27
|
+
)`);
|
|
28
|
+
const store = {
|
|
29
|
+
read: async (type, id) => {
|
|
30
|
+
const result = await pool.query(`SELECT value FROM ${table} WHERE session = $1 AND type = $2 AND id = $3`, [session, type, id]);
|
|
31
|
+
return result.rows[0]?.value ?? null;
|
|
32
|
+
},
|
|
33
|
+
readMany: async (type, ids) => {
|
|
34
|
+
if (!ids.length) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
const result = await pool.query(`SELECT id, value FROM ${table} WHERE session = $1 AND type = $2 AND id = ANY($3)`, [session, type, ids]);
|
|
38
|
+
const rows = {};
|
|
39
|
+
for (const row of result.rows) {
|
|
40
|
+
rows[row.id] = row.value;
|
|
41
|
+
}
|
|
42
|
+
return rows;
|
|
43
|
+
},
|
|
44
|
+
write: async (type, id, value) => {
|
|
45
|
+
await pool.query(`INSERT INTO ${table} (session, type, id, value) VALUES ($1, $2, $3, $4)
|
|
46
|
+
ON CONFLICT (session, type, id) DO UPDATE SET value = EXCLUDED.value`, [session, type, id, value]);
|
|
47
|
+
},
|
|
48
|
+
apply: async (writes, removals) => {
|
|
49
|
+
const client = await pool.connect();
|
|
50
|
+
try {
|
|
51
|
+
await client.query('BEGIN');
|
|
52
|
+
for (const entry of writes) {
|
|
53
|
+
await client.query(`INSERT INTO ${table} (session, type, id, value) VALUES ($1, $2, $3, $4)
|
|
54
|
+
ON CONFLICT (session, type, id) DO UPDATE SET value = EXCLUDED.value`, [session, entry.type, entry.id, entry.value]);
|
|
55
|
+
}
|
|
56
|
+
for (const entry of removals) {
|
|
57
|
+
await client.query(`DELETE FROM ${table} WHERE session = $1 AND type = $2 AND id = $3`, [session, entry.type, entry.id]);
|
|
58
|
+
}
|
|
59
|
+
await client.query('COMMIT');
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
await client.query('ROLLBACK');
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
client.release();
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
clear: async () => {
|
|
70
|
+
await pool.query(`DELETE FROM ${table} WHERE session = $1`, [session]);
|
|
71
|
+
},
|
|
72
|
+
close: async () => {
|
|
73
|
+
if (owned) {
|
|
74
|
+
await pool.end();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return makeAuthStateFromStore(store);
|
|
79
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface RedisAuthStateOptions {
|
|
2
|
+
client?: any;
|
|
3
|
+
uri?: string;
|
|
4
|
+
config?: any;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
session?: string;
|
|
7
|
+
}
|
|
8
|
+
export function useRedisAuthState(opts?: RedisAuthStateOptions): Promise<{
|
|
9
|
+
state: {
|
|
10
|
+
creds: any;
|
|
11
|
+
keys: {
|
|
12
|
+
get: (type: any, ids: any) => Promise<{}>;
|
|
13
|
+
set: (data: any) => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
saveCreds: () => Promise<void>;
|
|
17
|
+
clearAuth: () => Promise<void>;
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { loadOptionalModule, makeAuthStateFromStore } from './auth-store.js';
|
|
2
|
+
const resolveCommand = (client, names) => {
|
|
3
|
+
for (const name of names) {
|
|
4
|
+
if (typeof client[name] === 'function') {
|
|
5
|
+
return name;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
throw new Error(`redis client exposes none of: ${names.join(', ')}`);
|
|
9
|
+
};
|
|
10
|
+
export async function useRedisAuthState(opts = {}) {
|
|
11
|
+
const session = opts.session ?? 'default';
|
|
12
|
+
const prefix = opts.prefix ?? 'baileys_auth';
|
|
13
|
+
let client = opts.client;
|
|
14
|
+
let owned = false;
|
|
15
|
+
if (!client) {
|
|
16
|
+
if (!opts.uri) {
|
|
17
|
+
throw new Error('useRedisAuthState needs a client or a uri');
|
|
18
|
+
}
|
|
19
|
+
const Redis = await loadOptionalModule('ioredis', 'useRedisAuthState');
|
|
20
|
+
client = new Redis(opts.uri, opts.config);
|
|
21
|
+
owned = true;
|
|
22
|
+
}
|
|
23
|
+
if (typeof client.connect === 'function' && client.isOpen === false) {
|
|
24
|
+
await client.connect();
|
|
25
|
+
}
|
|
26
|
+
const commands = {
|
|
27
|
+
hget: resolveCommand(client, ['hGet', 'hget']),
|
|
28
|
+
hmget: resolveCommand(client, ['hmGet', 'hmget']),
|
|
29
|
+
hset: resolveCommand(client, ['hSet', 'hset']),
|
|
30
|
+
hdel: resolveCommand(client, ['hDel', 'hdel']),
|
|
31
|
+
del: resolveCommand(client, ['del', 'DEL']),
|
|
32
|
+
keys: resolveCommand(client, ['keys', 'KEYS'])
|
|
33
|
+
};
|
|
34
|
+
const hashKey = (type) => `${prefix}:${session}:${type}`;
|
|
35
|
+
const store = {
|
|
36
|
+
read: async (type, id) => {
|
|
37
|
+
const value = await client[commands.hget](hashKey(type), id);
|
|
38
|
+
return value ?? null;
|
|
39
|
+
},
|
|
40
|
+
readMany: async (type, ids) => {
|
|
41
|
+
if (!ids.length) {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
const values = await client[commands.hmget](hashKey(type), ids);
|
|
45
|
+
const rows = {};
|
|
46
|
+
ids.forEach((id, index) => {
|
|
47
|
+
const value = values?.[index];
|
|
48
|
+
if (value !== null && value !== undefined) {
|
|
49
|
+
rows[id] = value;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return rows;
|
|
53
|
+
},
|
|
54
|
+
write: async (type, id, value) => {
|
|
55
|
+
await client[commands.hset](hashKey(type), id, value);
|
|
56
|
+
},
|
|
57
|
+
apply: async (writes, removals) => {
|
|
58
|
+
const chain = typeof client.multi === 'function' ? client.multi() : null;
|
|
59
|
+
if (chain) {
|
|
60
|
+
for (const entry of writes) {
|
|
61
|
+
chain[commands.hset](hashKey(entry.type), entry.id, entry.value);
|
|
62
|
+
}
|
|
63
|
+
for (const entry of removals) {
|
|
64
|
+
chain[commands.hdel](hashKey(entry.type), entry.id);
|
|
65
|
+
}
|
|
66
|
+
await chain.exec();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const entry of writes) {
|
|
70
|
+
await client[commands.hset](hashKey(entry.type), entry.id, entry.value);
|
|
71
|
+
}
|
|
72
|
+
for (const entry of removals) {
|
|
73
|
+
await client[commands.hdel](hashKey(entry.type), entry.id);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
clear: async () => {
|
|
77
|
+
const found = await client[commands.keys](`${prefix}:${session}:*`);
|
|
78
|
+
if (found?.length) {
|
|
79
|
+
await client[commands.del](found);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
close: async () => {
|
|
83
|
+
if (owned) {
|
|
84
|
+
await (client.quit?.() ?? client.disconnect?.());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return makeAuthStateFromStore(store);
|
|
89
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFile, rename, stat, writeFile } from 'fs/promises';
|
|
2
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { initAuthCreds } from './auth-utils.js';
|
|
5
|
+
import { BufferJSON } from './generics.js';
|
|
6
|
+
import { LRUCache } from 'lru-cache';
|
|
7
|
+
import { Mutex } from 'async-mutex';
|
|
8
|
+
|
|
9
|
+
const FLUSH_TIMEOUT_MS = 3000;
|
|
10
|
+
|
|
11
|
+
export const useSingleFileAuthState = async (fileName) => {
|
|
12
|
+
const cache = new LRUCache({
|
|
13
|
+
max: 20000,
|
|
14
|
+
ttl: 1000 * DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
15
|
+
updateAgeOnGet: false,
|
|
16
|
+
updateAgeOnHas: false,
|
|
17
|
+
ttlAutopurge: true
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const mutex = new Mutex();
|
|
21
|
+
let fileData = {};
|
|
22
|
+
let isLoaded = false;
|
|
23
|
+
let flushTimeout = null;
|
|
24
|
+
const loadKey = async () => {
|
|
25
|
+
return await mutex.runExclusive(async () => {
|
|
26
|
+
if (isLoaded)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
const data = JSON.parse(await readFile(fileName, 'utf-8'), BufferJSON.reviver);
|
|
30
|
+
fileData = data || {};
|
|
31
|
+
for (const [keyName, value] of Object.entries(fileData)) {
|
|
32
|
+
cache.set(keyName, value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
fileData = {};
|
|
37
|
+
}
|
|
38
|
+
isLoaded = true;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const flushKey = () => {
|
|
42
|
+
if (flushTimeout)
|
|
43
|
+
return;
|
|
44
|
+
flushTimeout = setTimeout(async () => {
|
|
45
|
+
flushTimeout = null;
|
|
46
|
+
await mutex.runExclusive(async () => {
|
|
47
|
+
try {
|
|
48
|
+
const tempFile = fileName + '.temp';
|
|
49
|
+
await writeFile(tempFile, JSON.stringify(fileData, BufferJSON.replacer));
|
|
50
|
+
await rename(tempFile, fileName);
|
|
51
|
+
}
|
|
52
|
+
catch { }
|
|
53
|
+
});
|
|
54
|
+
}, FLUSH_TIMEOUT_MS);
|
|
55
|
+
};
|
|
56
|
+
const writeKey = (keyName, value) => {
|
|
57
|
+
cache.set(keyName, value);
|
|
58
|
+
fileData[keyName] = value;
|
|
59
|
+
flushKey();
|
|
60
|
+
};
|
|
61
|
+
const removeKey = (keyName) => {
|
|
62
|
+
cache.delete(keyName);
|
|
63
|
+
delete fileData[keyName];
|
|
64
|
+
flushKey();
|
|
65
|
+
};
|
|
66
|
+
const fileInfo = await stat(fileName).catch(() => null);
|
|
67
|
+
if (!fileInfo) {
|
|
68
|
+
await writeFile(fileName, '{}');
|
|
69
|
+
}
|
|
70
|
+
else if (!fileInfo.isFile()) {
|
|
71
|
+
throw new Error(`found something that is not a file at ${fileName}, either delete it or specify a different location`);
|
|
72
|
+
}
|
|
73
|
+
await loadKey();
|
|
74
|
+
const creds = fileData['creds'] || initAuthCreds();
|
|
75
|
+
return {
|
|
76
|
+
state: {
|
|
77
|
+
creds,
|
|
78
|
+
keys: {
|
|
79
|
+
get: (type, ids) => {
|
|
80
|
+
const data = {};
|
|
81
|
+
for (const id of ids) {
|
|
82
|
+
const keyName = type + id;
|
|
83
|
+
let value = cache.get(keyName);
|
|
84
|
+
if (value === undefined && fileData[keyName] !== undefined) {
|
|
85
|
+
value = fileData[keyName];
|
|
86
|
+
cache.set(keyName, value);
|
|
87
|
+
}
|
|
88
|
+
if (type === 'app-state-sync-key' && value) {
|
|
89
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
90
|
+
}
|
|
91
|
+
data[id] = value;
|
|
92
|
+
}
|
|
93
|
+
return data;
|
|
94
|
+
},
|
|
95
|
+
set: (data) => {
|
|
96
|
+
for (const category in data) {
|
|
97
|
+
for (const id in data[category]) {
|
|
98
|
+
const keyName = category + id;
|
|
99
|
+
const value = data[category][id];
|
|
100
|
+
value ? writeKey(keyName, value) : removeKey(keyName);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
saveCreds: () => writeKey('creds', creds)
|
|
107
|
+
};
|
|
108
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function useSqliteAuthState(opts: any): Promise<{
|
|
2
|
+
state: {
|
|
3
|
+
creds: any;
|
|
4
|
+
keys: {
|
|
5
|
+
get: (type: any, ids: any) => Promise<{}>;
|
|
6
|
+
set: (data: any) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
saveCreds: () => Promise<void>;
|
|
10
|
+
clearAuth: () => Promise<void>;
|
|
11
|
+
close: () => Promise<void>;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { initAuthCreds } from './auth-utils.js';
|
|
3
|
+
import { BufferJSON } from './generics.js';
|
|
4
|
+
async function loadBetterSqlite3() {
|
|
5
|
+
try {
|
|
6
|
+
|
|
7
|
+
const mod = (await import('better-sqlite3'));
|
|
8
|
+
return mod.default ?? mod;
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
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`).');
|
|
12
|
+
|
|
13
|
+
helpful.cause = err;
|
|
14
|
+
throw helpful;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const CREDS_ROW_KEY = '__creds__';
|
|
18
|
+
const CREATE_SCHEMA_SQL = `
|
|
19
|
+
CREATE TABLE IF NOT EXISTS creds (
|
|
20
|
+
key TEXT PRIMARY KEY,
|
|
21
|
+
value TEXT NOT NULL
|
|
22
|
+
);
|
|
23
|
+
CREATE TABLE IF NOT EXISTS signal_keys (
|
|
24
|
+
type TEXT NOT NULL,
|
|
25
|
+
id TEXT NOT NULL,
|
|
26
|
+
value TEXT NOT NULL,
|
|
27
|
+
PRIMARY KEY (type, id)
|
|
28
|
+
);
|
|
29
|
+
CREATE INDEX IF NOT EXISTS signal_keys_type_idx ON signal_keys(type);
|
|
30
|
+
`;
|
|
31
|
+
export async function useSqliteAuthState(opts) {
|
|
32
|
+
let db;
|
|
33
|
+
let owned = false;
|
|
34
|
+
if (opts.database) {
|
|
35
|
+
db = opts.database;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const Database = await loadBetterSqlite3();
|
|
39
|
+
db = new Database(opts.dbPath);
|
|
40
|
+
owned = true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
db.pragma('journal_mode = WAL');
|
|
44
|
+
db.pragma('synchronous = NORMAL');
|
|
45
|
+
db.exec(CREATE_SCHEMA_SQL);
|
|
46
|
+
const stmts = {
|
|
47
|
+
credsSelect: db.prepare('SELECT value FROM creds WHERE key = ?'),
|
|
48
|
+
credsUpsert: db.prepare('INSERT INTO creds (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'),
|
|
49
|
+
keySelect: db.prepare('SELECT value FROM signal_keys WHERE type = ? AND id = ?'),
|
|
50
|
+
keyUpsert: db.prepare('INSERT INTO signal_keys (type, id, value) VALUES (?, ?, ?) ON CONFLICT(type, id) DO UPDATE SET value = excluded.value'),
|
|
51
|
+
keyDelete: db.prepare('DELETE FROM signal_keys WHERE type = ? AND id = ?'),
|
|
52
|
+
keyListIds: db.prepare('SELECT id FROM signal_keys WHERE type = ?'),
|
|
53
|
+
keyList: db.prepare('SELECT id, value FROM signal_keys WHERE type = ?'),
|
|
54
|
+
clearKeys: db.prepare('DELETE FROM signal_keys'),
|
|
55
|
+
clearCreds: db.prepare('DELETE FROM creds')
|
|
56
|
+
};
|
|
57
|
+
const loadCreds = () => {
|
|
58
|
+
const row = stmts.credsSelect.get(CREDS_ROW_KEY);
|
|
59
|
+
if (!row)
|
|
60
|
+
return initAuthCreds();
|
|
61
|
+
return JSON.parse(row.value, BufferJSON.reviver);
|
|
62
|
+
};
|
|
63
|
+
const persistCreds = (creds) => {
|
|
64
|
+
stmts.credsUpsert.run(CREDS_ROW_KEY, JSON.stringify(creds, BufferJSON.replacer));
|
|
65
|
+
};
|
|
66
|
+
const creds = loadCreds();
|
|
67
|
+
return {
|
|
68
|
+
state: {
|
|
69
|
+
creds,
|
|
70
|
+
keys: {
|
|
71
|
+
get: async (type, ids) => {
|
|
72
|
+
const data = {};
|
|
73
|
+
for (const id of ids) {
|
|
74
|
+
const row = stmts.keySelect.get(type, id);
|
|
75
|
+
if (row) {
|
|
76
|
+
let value = JSON.parse(row.value, BufferJSON.reviver);
|
|
77
|
+
if (type === 'app-state-sync-key' && value) {
|
|
78
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
79
|
+
}
|
|
80
|
+
data[id] = value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return data;
|
|
84
|
+
},
|
|
85
|
+
set: async (data) => {
|
|
86
|
+
const writeTx = db.transaction(() => {
|
|
87
|
+
for (const category in data) {
|
|
88
|
+
for (const id in data[category]) {
|
|
89
|
+
const value = data[category][id];
|
|
90
|
+
if (value) {
|
|
91
|
+
const stringified = JSON.stringify(value, BufferJSON.replacer);
|
|
92
|
+
stmts.keyUpsert.run(category, id, stringified);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
stmts.keyDelete.run(category, id);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
writeTx();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
saveCreds: async () => {
|
|
105
|
+
persistCreds(creds);
|
|
106
|
+
},
|
|
107
|
+
clearAuth: async () => {
|
|
108
|
+
const wipe = db.transaction(() => {
|
|
109
|
+
stmts.clearKeys.run();
|
|
110
|
+
stmts.clearCreds.run();
|
|
111
|
+
});
|
|
112
|
+
wipe();
|
|
113
|
+
},
|
|
114
|
+
close: async () => {
|
|
115
|
+
if (owned) {
|
|
116
|
+
db.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function useNekoDBAuth(
|
|
2
|
+
db: any,
|
|
3
|
+
collectionName?: string
|
|
4
|
+
): Promise<{
|
|
5
|
+
state: {
|
|
6
|
+
creds: any
|
|
7
|
+
keys: {
|
|
8
|
+
get: (
|
|
9
|
+
type: string,
|
|
10
|
+
ids: string[]
|
|
11
|
+
) => Promise<Record<string, any>>
|
|
12
|
+
set: (
|
|
13
|
+
data: Record<string, Record<string, any>>
|
|
14
|
+
) => Promise<void>
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
saveCreds: () => Promise<void>
|
|
18
|
+
clearAuth: () => Promise<void>
|
|
19
|
+
}>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js'
|
|
2
|
+
import { initAuthCreds } from './auth-utils.js'
|
|
3
|
+
import { BufferJSON } from './generics.js'
|
|
4
|
+
|
|
5
|
+
export async function useNekoDBAuth(db, collectionName = 'baileys_luna_auth') {
|
|
6
|
+
if (!db || typeof db.collection !== 'function') {
|
|
7
|
+
throw new Error(
|
|
8
|
+
'useNekoDBAuth: argumen pertama harus instance NekoDB yang terkoneksi'
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const col = db.collection(collectionName).helper()
|
|
13
|
+
|
|
14
|
+
const writeData = async (data, key) => {
|
|
15
|
+
const value = JSON.stringify(data, BufferJSON.replacer)
|
|
16
|
+
|
|
17
|
+
await col.upsert(
|
|
18
|
+
{ k: key },
|
|
19
|
+
{
|
|
20
|
+
k: key,
|
|
21
|
+
v: value
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const readData = async key => {
|
|
27
|
+
try {
|
|
28
|
+
const doc = await col.findOne({ k: key })
|
|
29
|
+
|
|
30
|
+
if (!doc || doc.v == null) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return JSON.parse(doc.v, BufferJSON.reviver)
|
|
35
|
+
} catch {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const removeData = async key => {
|
|
41
|
+
try {
|
|
42
|
+
await col.deleteWhere({ k: key })
|
|
43
|
+
} catch {}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const creds =
|
|
47
|
+
(await readData('creds')) ||
|
|
48
|
+
initAuthCreds()
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
state: {
|
|
52
|
+
creds,
|
|
53
|
+
keys: {
|
|
54
|
+
get: async (type, ids) => {
|
|
55
|
+
const data = {}
|
|
56
|
+
|
|
57
|
+
await Promise.all(
|
|
58
|
+
ids.map(async id => {
|
|
59
|
+
let value = await readData(`${type}-${id}`)
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
type === 'app-state-sync-key' &&
|
|
63
|
+
value
|
|
64
|
+
) {
|
|
65
|
+
value =
|
|
66
|
+
proto.Message.AppStateSyncKeyData.fromObject(
|
|
67
|
+
value
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
data[id] = value
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return data
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
set: async data => {
|
|
79
|
+
const tasks = []
|
|
80
|
+
|
|
81
|
+
for (const category in data) {
|
|
82
|
+
const entries = data[category]
|
|
83
|
+
|
|
84
|
+
for (const id in entries) {
|
|
85
|
+
const value = entries[id]
|
|
86
|
+
const key = `${category}-${id}`
|
|
87
|
+
|
|
88
|
+
tasks.push(
|
|
89
|
+
value
|
|
90
|
+
? writeData(value, key)
|
|
91
|
+
: removeData(key)
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await Promise.all(tasks)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
saveCreds: async () => {
|
|
102
|
+
await writeData(creds, 'creds')
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
clearAuth: async () => {
|
|
106
|
+
try {
|
|
107
|
+
await db.deleteCollection(collectionName)
|
|
108
|
+
} catch {}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -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,58 @@
|
|
|
1
|
+
export const USERNAME_MIN_LENGTH = 3;
|
|
2
|
+
export const USERNAME_MAX_LENGTH = 35;
|
|
3
|
+
export const USERNAME_PIN_LENGTH = 4;
|
|
4
|
+
const LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
5
|
+
const DIGITS = '0123456789';
|
|
6
|
+
const LETTER_SET = new Set(LETTERS.split(''));
|
|
7
|
+
const ALLOWED_SET = new Set([...LETTERS.split(''), ...DIGITS.split(''), '_', '.']);
|
|
8
|
+
const RESERVED_SUFFIXES = ['.com', '.org', '.net', '.int', '.edu', '.gov', '.mil', '.arpa', '.html', '.htm', '.txt', '.xml'];
|
|
9
|
+
const RESERVED_WORDS = ['whatsapp', 'instagram', 'facebook', 'oculus'];
|
|
10
|
+
const PIN_PATTERN = /^[0-9]{4}$/;
|
|
11
|
+
export const UsernameValidationError = {
|
|
12
|
+
INVALID_CHARACTER: 'INVALID_CHARACTER',
|
|
13
|
+
INVALID_LENGTH: 'INVALID_LENGTH',
|
|
14
|
+
INVALID_NO_LETTERS: 'INVALID_NO_LETTERS',
|
|
15
|
+
INVALID_PERIODS: 'INVALID_PERIODS',
|
|
16
|
+
INVALID_DOMAIN_SUFFIX: 'INVALID_DOMAIN_SUFFIX',
|
|
17
|
+
INVALID_WWW_PREFIX: 'INVALID_WWW_PREFIX',
|
|
18
|
+
INVALID_WORD: 'INVALID_WORD'
|
|
19
|
+
};
|
|
20
|
+
export const stripUsernamePrefix = (username) => {
|
|
21
|
+
return typeof username === 'string' && username.startsWith('@') ? username.slice(1) : username;
|
|
22
|
+
};
|
|
23
|
+
export const displayUsername = (username) => {
|
|
24
|
+
return '@' + stripUsernamePrefix(username);
|
|
25
|
+
};
|
|
26
|
+
export const validateUsername = (username) => {
|
|
27
|
+
const value = stripUsernamePrefix(username);
|
|
28
|
+
if (typeof value !== 'string') {
|
|
29
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_CHARACTER };
|
|
30
|
+
}
|
|
31
|
+
const characters = Array.from(value);
|
|
32
|
+
if (!characters.every(character => ALLOWED_SET.has(character))) {
|
|
33
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_CHARACTER };
|
|
34
|
+
}
|
|
35
|
+
if (value.length < USERNAME_MIN_LENGTH || value.length > USERNAME_MAX_LENGTH) {
|
|
36
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_LENGTH };
|
|
37
|
+
}
|
|
38
|
+
if (!characters.some(character => LETTER_SET.has(character))) {
|
|
39
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_NO_LETTERS };
|
|
40
|
+
}
|
|
41
|
+
if (value.startsWith('.') || value.endsWith('.') || value.includes('..')) {
|
|
42
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_PERIODS };
|
|
43
|
+
}
|
|
44
|
+
const lowered = value.toLowerCase();
|
|
45
|
+
if (lowered.startsWith('www.')) {
|
|
46
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_WWW_PREFIX };
|
|
47
|
+
}
|
|
48
|
+
if (RESERVED_SUFFIXES.some(suffix => lowered.endsWith(suffix))) {
|
|
49
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_DOMAIN_SUFFIX };
|
|
50
|
+
}
|
|
51
|
+
if (RESERVED_WORDS.some(word => lowered.includes(word))) {
|
|
52
|
+
return { isValid: false, errorType: UsernameValidationError.INVALID_WORD };
|
|
53
|
+
}
|
|
54
|
+
return { isValid: true };
|
|
55
|
+
};
|
|
56
|
+
export const isUsernamePin = (pin) => {
|
|
57
|
+
return typeof pin === 'string' && PIN_PATTERN.test(pin);
|
|
58
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function generateLoginNode(userJid: any, config: any): proto.ClientPayload;
|
|
2
|
+
export function generateRegistrationNode({ registrationId, signedPreKey, signedIdentityKey }: {
|
|
3
|
+
registrationId: any;
|
|
4
|
+
signedPreKey: any;
|
|
5
|
+
signedIdentityKey: any;
|
|
6
|
+
}, config: any): proto.ClientPayload;
|
|
7
|
+
export function configureSuccessfulPairing(stanza: any, { advSecretKey, signedIdentityKey, signalIdentities }: {
|
|
8
|
+
advSecretKey: any;
|
|
9
|
+
signedIdentityKey: any;
|
|
10
|
+
signalIdentities: any;
|
|
11
|
+
}): {
|
|
12
|
+
creds: {
|
|
13
|
+
account: proto.ADVSignedDeviceIdentity;
|
|
14
|
+
me: {
|
|
15
|
+
id: any;
|
|
16
|
+
name: any;
|
|
17
|
+
lid: any;
|
|
18
|
+
};
|
|
19
|
+
signalIdentities: any[];
|
|
20
|
+
platform: any;
|
|
21
|
+
};
|
|
22
|
+
reply: {
|
|
23
|
+
tag: string;
|
|
24
|
+
attrs: {
|
|
25
|
+
to: string;
|
|
26
|
+
type: string;
|
|
27
|
+
id: any;
|
|
28
|
+
};
|
|
29
|
+
content: {
|
|
30
|
+
tag: string;
|
|
31
|
+
attrs: {};
|
|
32
|
+
content: {
|
|
33
|
+
tag: string;
|
|
34
|
+
attrs: {
|
|
35
|
+
'key-index': string;
|
|
36
|
+
};
|
|
37
|
+
content: any;
|
|
38
|
+
}[];
|
|
39
|
+
}[];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export function encodeSignedDeviceIdentity(account: any, includeSignatureKey: any): any;
|
|
43
|
+
import { proto } from '../../WAProto/index.js';
|