supunmd-bail 2.1.1 → 2.1.4
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 +1 -1
- package/README.md +428 -0
- package/WAProto/index.js +130529 -45236
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +9 -18
- package/lib/Defaults/index.js +136 -104
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +5 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +2 -3
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.d.ts +6 -7
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +90 -258
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +108 -125
- package/lib/Socket/business.js +43 -159
- package/lib/Socket/chats.d.ts +239 -70
- package/lib/Socket/chats.js +384 -363
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +56 -78
- package/lib/Socket/groups.js +96 -106
- package/lib/Socket/index.d.ts +115 -173
- package/lib/Socket/index.js +10 -17
- package/lib/Socket/messages-recv.d.ts +79 -91
- package/lib/Socket/messages-recv.js +521 -639
- package/lib/Socket/messages-send.d.ts +91 -111
- package/lib/Socket/messages-send.js +438 -599
- package/lib/Socket/newsletter.d.ts +84 -97
- package/lib/Socket/newsletter.js +239 -145
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +18 -26
- package/lib/Socket/socket.js +230 -448
- package/lib/Socket/usync.d.ts +16 -17
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +12 -13
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +13 -34
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +15 -60
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +5 -17
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -12
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +54 -84
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +98 -130
- package/lib/Types/Newsletter.js +38 -31
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -20
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +25 -47
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -22
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -7
- package/lib/Utils/auth-utils.js +148 -199
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +226 -260
- package/lib/Utils/crypto.d.ts +19 -19
- package/lib/Utils/crypto.js +86 -77
- package/lib/Utils/decode-wa-message.d.ts +8 -37
- package/lib/Utils/decode-wa-message.js +83 -164
- package/lib/Utils/event-buffer.d.ts +8 -7
- package/lib/Utils/event-buffer.js +76 -110
- package/lib/Utils/generics.d.ts +29 -27
- package/lib/Utils/generics.js +210 -168
- package/lib/Utils/history.d.ts +8 -12
- package/lib/Utils/history.js +46 -34
- package/lib/Utils/index.d.ts +17 -20
- package/lib/Utils/index.js +33 -20
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +22 -14
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +28 -25
- package/lib/Utils/make-mutex.d.ts +2 -3
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.d.ts +44 -42
- package/lib/Utils/messages-media.js +475 -319
- package/lib/Utils/messages.d.ts +18 -17
- package/lib/Utils/messages.js +259 -383
- package/lib/Utils/noise-handler.d.ts +15 -14
- package/lib/Utils/noise-handler.js +38 -30
- package/lib/Utils/process-message.d.ts +13 -14
- package/lib/Utils/process-message.js +147 -239
- package/lib/Utils/signal.d.ts +5 -7
- package/lib/Utils/signal.js +72 -78
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +27 -29
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.js +106 -72
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.js +42 -28
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +154 -105
- package/lib/WABinary/generic-utils.d.ts +7 -5
- package/lib/WABinary/generic-utils.js +63 -56
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +8 -25
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +4 -5
- package/lib/WAUSync/USyncQuery.js +35 -40
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +9 -19
- package/lib/index.js +47 -24
- package/package.json +109 -99
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5519
- package/WAProto/fix-imports.js +0 -29
- package/WAProto/index.d.ts +0 -11969
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -171
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.d.ts +0 -244
- package/lib/Socket/communities.js +0 -431
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.js +0 -42
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/message-retry-manager.d.ts +0 -82
- package/lib/Utils/message-retry-manager.js +0 -149
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.js +0 -106
- /package/lib/{supun → supunmd} +0 -0
package/lib/Utils/signal.js
CHANGED
|
@@ -1,159 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return chunks;
|
|
11
|
-
}
|
|
12
|
-
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
4
|
+
const Defaults_1 = require("../Defaults");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const crypto_1 = require("./crypto");
|
|
7
|
+
const lodash_1 = require("lodash")
|
|
8
|
+
const generics_1 = require("./generics");
|
|
9
|
+
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
10
|
return {
|
|
14
11
|
identifier: { name: wid, deviceId: 0 },
|
|
15
|
-
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
12
|
+
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
16
13
|
};
|
|
17
14
|
};
|
|
18
|
-
|
|
15
|
+
exports.createSignalIdentity = createSignalIdentity;
|
|
16
|
+
const getPreKeys = async ({ get }, min, limit) => {
|
|
19
17
|
const idList = [];
|
|
20
18
|
for (let id = min; id < limit; id++) {
|
|
21
19
|
idList.push(id.toString());
|
|
22
20
|
}
|
|
23
21
|
return get('pre-key', idList);
|
|
24
22
|
};
|
|
25
|
-
|
|
23
|
+
exports.getPreKeys = getPreKeys;
|
|
24
|
+
const generateOrGetPreKeys = (creds, range) => {
|
|
26
25
|
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
26
|
const remaining = range - avaliable;
|
|
28
27
|
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
28
|
const newPreKeys = {};
|
|
30
29
|
if (remaining > 0) {
|
|
31
30
|
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
-
newPreKeys[i] = Curve.generateKeyPair();
|
|
31
|
+
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
return {
|
|
36
35
|
newPreKeys,
|
|
37
36
|
lastPreKeyId,
|
|
38
|
-
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
37
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range],
|
|
39
38
|
};
|
|
40
39
|
};
|
|
41
|
-
|
|
40
|
+
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
41
|
+
const xmppSignedPreKey = (key) => ({
|
|
42
42
|
tag: 'skey',
|
|
43
43
|
attrs: {},
|
|
44
44
|
content: [
|
|
45
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
45
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
46
46
|
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
47
|
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
48
|
]
|
|
49
49
|
});
|
|
50
|
-
|
|
50
|
+
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
51
|
+
const xmppPreKey = (pair, id) => ({
|
|
51
52
|
tag: 'key',
|
|
52
53
|
attrs: {},
|
|
53
54
|
content: [
|
|
54
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
55
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
55
56
|
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
57
|
]
|
|
57
58
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
59
|
+
exports.xmppPreKey = xmppPreKey;
|
|
60
|
+
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
61
|
+
const extractKey = (key) => (key ? ({
|
|
62
|
+
keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
|
|
63
|
+
publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
|
|
64
|
+
signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
|
|
65
|
+
}) : undefined)
|
|
66
|
+
const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
|
|
67
67
|
for (const node of nodes) {
|
|
68
|
-
assertNodeErrorFree(node)
|
|
68
|
+
WABinary_1.assertNodeErrorFree(node)
|
|
69
69
|
}
|
|
70
70
|
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
71
71
|
// So Promise.all doesn't really help here,
|
|
72
72
|
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
73
73
|
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
74
74
|
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
75
|
-
const chunkSize = 100
|
|
76
|
-
const chunks = chunk(nodes, chunkSize)
|
|
75
|
+
const chunkSize = 100
|
|
76
|
+
const chunks = lodash_1.chunk(nodes, chunkSize)
|
|
77
77
|
for (const nodesChunk of chunks) {
|
|
78
|
-
|
|
79
|
-
const signedKey = getBinaryNodeChild(node, 'skey')
|
|
80
|
-
const key = getBinaryNodeChild(node, 'key')
|
|
81
|
-
const identity = getBinaryNodeChildBuffer(node, 'identity')
|
|
82
|
-
const jid = node.attrs.jid
|
|
83
|
-
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4)
|
|
78
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
79
|
+
const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
|
|
80
|
+
const key = WABinary_1.getBinaryNodeChild(node, 'key')
|
|
81
|
+
const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
|
|
82
|
+
const jid = node.attrs.jid
|
|
83
|
+
const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
|
|
84
84
|
await repository.injectE2ESession({
|
|
85
85
|
jid,
|
|
86
86
|
session: {
|
|
87
87
|
registrationId: registrationId,
|
|
88
|
-
identityKey: generateSignalPubKey(identity),
|
|
88
|
+
identityKey: crypto_1.generateSignalPubKey(identity),
|
|
89
89
|
signedPreKey: extractKey(signedKey),
|
|
90
90
|
preKey: extractKey(key)
|
|
91
91
|
}
|
|
92
|
-
})
|
|
93
|
-
}
|
|
92
|
+
})
|
|
93
|
+
}))
|
|
94
94
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
95
|
+
}
|
|
96
|
+
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
97
|
+
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
98
|
+
const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
|
|
99
|
+
const extracted = []
|
|
99
100
|
for (const userResult of result) {
|
|
100
|
-
const { devices, id } = userResult
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
) {
|
|
111
|
-
if (isHosted) {
|
|
112
|
-
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
101
|
+
const { devices, id } = userResult
|
|
102
|
+
const { user } = WABinary_1.jidDecode(id)
|
|
103
|
+
const deviceList = devices?.deviceList
|
|
104
|
+
if (Array.isArray(deviceList)) {
|
|
105
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
106
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
107
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
108
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
109
|
+
) {
|
|
110
|
+
extracted.push({ user, device })
|
|
113
111
|
}
|
|
114
|
-
extracted.push({
|
|
115
|
-
user,
|
|
116
|
-
device,
|
|
117
|
-
domainType,
|
|
118
|
-
server: getServerFromDomainType(server, domainType)
|
|
119
|
-
});
|
|
120
112
|
}
|
|
121
113
|
}
|
|
122
114
|
}
|
|
123
|
-
return extracted
|
|
124
|
-
}
|
|
115
|
+
return extracted
|
|
116
|
+
}
|
|
117
|
+
exports.extractDeviceJids = extractDeviceJids;
|
|
125
118
|
/**
|
|
126
119
|
* get the next N keys for upload or processing
|
|
127
120
|
* @param count number of pre-keys to get or generate
|
|
128
121
|
*/
|
|
129
|
-
|
|
130
|
-
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
122
|
+
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
123
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
131
124
|
const update = {
|
|
132
125
|
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
133
126
|
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
134
127
|
};
|
|
135
128
|
await keys.set({ 'pre-key': newPreKeys });
|
|
136
|
-
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
129
|
+
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
137
130
|
return { update, preKeys };
|
|
138
131
|
};
|
|
139
|
-
|
|
132
|
+
exports.getNextPreKeys = getNextPreKeys;
|
|
133
|
+
const getNextPreKeysNode = async (state, count) => {
|
|
140
134
|
const { creds } = state;
|
|
141
|
-
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
135
|
+
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
142
136
|
const node = {
|
|
143
137
|
tag: 'iq',
|
|
144
138
|
attrs: {
|
|
145
139
|
xmlns: 'encrypt',
|
|
146
140
|
type: 'set',
|
|
147
|
-
to: S_WHATSAPP_NET
|
|
141
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
148
142
|
},
|
|
149
143
|
content: [
|
|
150
|
-
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
151
|
-
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
144
|
+
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
145
|
+
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
152
146
|
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
153
|
-
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
154
|
-
xmppSignedPreKey(creds.signedPreKey)
|
|
147
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
148
|
+
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
155
149
|
]
|
|
156
150
|
};
|
|
157
151
|
return { update, node };
|
|
158
152
|
};
|
|
159
|
-
|
|
153
|
+
exports.getNextPreKeysNode = getNextPreKeysNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AuthenticationState } from '../Types';
|
|
2
2
|
/**
|
|
3
3
|
* stores the full authentication state in a single folder.
|
|
4
4
|
* Far more efficient than singlefileauthstate
|
|
@@ -10,4 +10,4 @@ export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
|
10
10
|
state: AuthenticationState;
|
|
11
11
|
saveCreds: () => Promise<void>;
|
|
12
12
|
}>;
|
|
13
|
-
|
|
13
|
+
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Use a Map to store mutexes for each file path
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require("async-mutex");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const auth_utils_1 = require("./auth-utils");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
11
10
|
const fileLocks = new Map();
|
|
12
|
-
// Get or create a mutex for a specific file path
|
|
13
11
|
const getFileLock = (path) => {
|
|
14
12
|
let mutex = fileLocks.get(path);
|
|
15
13
|
if (!mutex) {
|
|
16
|
-
mutex = new Mutex();
|
|
14
|
+
mutex = new async_mutex_1.Mutex();
|
|
17
15
|
fileLocks.set(path, mutex);
|
|
18
16
|
}
|
|
19
17
|
return mutex;
|
|
@@ -25,14 +23,13 @@ const getFileLock = (path) => {
|
|
|
25
23
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
26
24
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
27
25
|
* */
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
const useMultiFileAuthState = async (folder) => {
|
|
30
27
|
const writeData = async (data, file) => {
|
|
31
|
-
const filePath = join(folder, fixFileName(file));
|
|
28
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
32
29
|
const mutex = getFileLock(filePath);
|
|
33
30
|
return mutex.acquire().then(async (release) => {
|
|
34
31
|
try {
|
|
35
|
-
await writeFile(filePath, JSON.stringify(data, BufferJSON.replacer));
|
|
32
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
36
33
|
}
|
|
37
34
|
finally {
|
|
38
35
|
release();
|
|
@@ -41,12 +38,12 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
41
38
|
};
|
|
42
39
|
const readData = async (file) => {
|
|
43
40
|
try {
|
|
44
|
-
const filePath = join(folder, fixFileName(file));
|
|
41
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
45
42
|
const mutex = getFileLock(filePath);
|
|
46
43
|
return await mutex.acquire().then(async (release) => {
|
|
47
44
|
try {
|
|
48
|
-
const data = await readFile(filePath, { encoding: 'utf-8' });
|
|
49
|
-
return JSON.parse(data, BufferJSON.reviver);
|
|
45
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
46
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
50
47
|
}
|
|
51
48
|
finally {
|
|
52
49
|
release();
|
|
@@ -59,32 +56,33 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
59
56
|
};
|
|
60
57
|
const removeData = async (file) => {
|
|
61
58
|
try {
|
|
62
|
-
const filePath = join(folder, fixFileName(file));
|
|
59
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
63
60
|
const mutex = getFileLock(filePath);
|
|
64
61
|
return mutex.acquire().then(async (release) => {
|
|
65
62
|
try {
|
|
66
|
-
await unlink(filePath);
|
|
63
|
+
await (0, promises_1.unlink)(filePath);
|
|
67
64
|
}
|
|
68
|
-
catch {
|
|
65
|
+
catch (_a) {
|
|
69
66
|
}
|
|
70
67
|
finally {
|
|
71
68
|
release();
|
|
72
69
|
}
|
|
73
70
|
});
|
|
74
71
|
}
|
|
75
|
-
catch {
|
|
72
|
+
catch (_a) {
|
|
73
|
+
}
|
|
76
74
|
};
|
|
77
|
-
const folderInfo = await stat(folder).catch(() => { });
|
|
75
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
78
76
|
if (folderInfo) {
|
|
79
77
|
if (!folderInfo.isDirectory()) {
|
|
80
78
|
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
else {
|
|
84
|
-
await mkdir(folder, { recursive: true });
|
|
82
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
85
83
|
}
|
|
86
|
-
const fixFileName = (file) => file
|
|
87
|
-
const creds =
|
|
84
|
+
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
|
|
85
|
+
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
88
86
|
return {
|
|
89
87
|
state: {
|
|
90
88
|
creds,
|
|
@@ -94,7 +92,7 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
94
92
|
await Promise.all(ids.map(async (id) => {
|
|
95
93
|
let value = await readData(`${type}-${id}.json`);
|
|
96
94
|
if (type === 'app-state-sync-key' && value) {
|
|
97
|
-
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
95
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
98
96
|
}
|
|
99
97
|
data[id] = value;
|
|
100
98
|
}));
|
|
@@ -118,4 +116,4 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
118
116
|
}
|
|
119
117
|
};
|
|
120
118
|
};
|
|
121
|
-
|
|
119
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { proto } from '../../WAProto
|
|
2
|
-
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types
|
|
3
|
-
import {
|
|
1
|
+
import { proto } from '../../WAProto';
|
|
2
|
+
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
|
|
4
5
|
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
5
6
|
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
6
|
-
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds,
|
|
7
|
+
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|
|
7
8
|
creds: Partial<AuthenticationCreds>;
|
|
8
9
|
reply: BinaryNode;
|
|
9
|
-
};
|
|
10
|
-
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array
|
|
11
|
-
//# sourceMappingURL=validate-connection.d.ts.map
|
|
10
|
+
};
|
|
11
|
+
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
|