alwaysaqioo 1.1.3 → 1.1.5

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.
Files changed (50) hide show
  1. package/README.md +110 -9
  2. package/WAProto/index.js +56886 -17506
  3. package/engine-requirements.js +10 -0
  4. package/lib/Defaults/baileys-version.json +1 -1
  5. package/lib/Defaults/index.js +19 -2
  6. package/lib/Socket/chats.d.ts +215 -32
  7. package/lib/Socket/chats.js +155 -75
  8. package/lib/Socket/groups.js +18 -18
  9. package/lib/Socket/index.js +1 -0
  10. package/lib/Socket/luxu.d.ts +268 -0
  11. package/lib/Socket/luxu.js +591 -0
  12. package/lib/Socket/messages-send.d.ts +2 -2
  13. package/lib/Socket/messages-send.js +327 -348
  14. package/lib/Socket/newsletter.js +111 -21
  15. package/lib/Socket/socket.js +65 -30
  16. package/lib/Types/Newsletter.d.ts +97 -86
  17. package/lib/Types/Newsletter.js +38 -32
  18. package/lib/Utils/generics.js +65 -33
  19. package/lib/Utils/messages-media.js +145 -57
  20. package/lib/Utils/messages.js +26 -14
  21. package/lib/Utils/signal.js +48 -46
  22. package/lib/Utils/use-multi-file-auth-state.js +45 -6
  23. package/lib/Utils/validate-connection.js +89 -65
  24. package/lib/WABinary/constants.d.ts +27 -24
  25. package/lib/WABinary/encode.js +160 -123
  26. package/lib/WABinary/generic-utils.d.ts +2 -1
  27. package/lib/WABinary/generic-utils.js +123 -43
  28. package/lib/index.d.ts +1 -0
  29. package/lib/index.js +11 -4
  30. package/package.json +100 -98
  31. package/WAProto/GenerateStatics.sh +0 -4
  32. package/WAProto/WAProto.proto +0 -3344
  33. package/WAProto/index.d.ts +0 -37016
  34. package/WASignalGroup/GroupProtocol.js +0 -1697
  35. package/WASignalGroup/ciphertext_message.js +0 -16
  36. package/WASignalGroup/group_cipher.js +0 -120
  37. package/WASignalGroup/group_session_builder.js +0 -46
  38. package/WASignalGroup/index.js +0 -5
  39. package/WASignalGroup/keyhelper.js +0 -21
  40. package/WASignalGroup/protobufs.js +0 -3
  41. package/WASignalGroup/queue_job.js +0 -69
  42. package/WASignalGroup/sender_chain_key.js +0 -50
  43. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  44. package/WASignalGroup/sender_key_message.js +0 -92
  45. package/WASignalGroup/sender_key_name.js +0 -70
  46. package/WASignalGroup/sender_key_record.js +0 -56
  47. package/WASignalGroup/sender_key_state.js +0 -129
  48. package/WASignalGroup/sender_message_key.js +0 -39
  49. package/lib/Signal/Group/x +0 -1
  50. package/lib/WAUSync/index.d.ts +0 -3
@@ -4,6 +4,7 @@ exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids
4
4
  const Defaults_1 = require("../Defaults");
5
5
  const WABinary_1 = require("../WABinary");
6
6
  const crypto_1 = require("./crypto");
7
+ const lodash_1 = require("lodash")
7
8
  const generics_1 = require("./generics");
8
9
  const createSignalIdentity = (wid, accountSignatureKey) => {
9
10
  return {
@@ -58,60 +59,61 @@ const xmppPreKey = (pair, id) => ({
58
59
  exports.xmppPreKey = xmppPreKey;
59
60
  const parseAndInjectE2ESessions = async (node, repository) => {
60
61
  const extractKey = (key) => (key ? ({
61
- keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
62
- publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
63
- signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
64
- }) : undefined);
65
- const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
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')
66
67
  for (const node of nodes) {
67
- (0, WABinary_1.assertNodeErrorFree)(node);
68
+ WABinary_1.assertNodeErrorFree(node)
68
69
  }
69
- await Promise.all(nodes.map(async (node) => {
70
- const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
71
- const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
72
- const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
73
- const jid = node.attrs.jid;
74
- const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
75
- await repository.injectE2ESession({
76
- jid,
77
- session: {
78
- registrationId: registrationId,
79
- identityKey: (0, crypto_1.generateSignalPubKey)(identity),
80
- signedPreKey: extractKey(signedKey),
81
- preKey: extractKey(key)
82
- }
83
- });
84
- }));
85
- };
70
+ // Most of the work in repository.injectE2ESession is CPU intensive, not IO
71
+ // So Promise.all doesn't really help here,
72
+ // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
73
+ // This way we chunk it in smaller parts and between those parts we can yield to the event loop
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 = lodash_1.chunk(nodes, chunkSize)
77
+ for (const nodesChunk of chunks) {
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
+ await repository.injectE2ESession({
85
+ jid,
86
+ session: {
87
+ registrationId: registrationId,
88
+ identityKey: crypto_1.generateSignalPubKey(identity),
89
+ signedPreKey: extractKey(signedKey),
90
+ preKey: extractKey(key)
91
+ }
92
+ })
93
+ }))
94
+ }
95
+ }
86
96
  exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
87
97
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
88
- var _a;
89
- const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
90
- const extracted = [];
91
- for (const node of result.content) {
92
- const list = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'list')) === null || _a === void 0 ? void 0 : _a.content;
93
- if (list && Array.isArray(list)) {
94
- for (const item of list) {
95
- const { user } = (0, WABinary_1.jidDecode)(item.attrs.jid);
96
- const devicesNode = (0, WABinary_1.getBinaryNodeChild)(item, 'devices');
97
- const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(devicesNode, 'device-list');
98
- if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
99
- for (const { tag, attrs } of deviceListNode.content) {
100
- const device = +attrs.id;
101
- if (tag === 'device' && // ensure the "device" tag
102
- (!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
103
- (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
104
- (device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
105
- ) {
106
- extracted.push({ user, device });
107
- }
108
- }
98
+ const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
99
+ const extracted = []
100
+ for (const userResult of result) {
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 })
109
111
  }
110
112
  }
111
113
  }
112
114
  }
113
- return extracted;
114
- };
115
+ return extracted
116
+ }
115
117
  exports.extractDeviceJids = extractDeviceJids;
116
118
  /**
117
119
  * get the next N keys for upload or processing
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMultiFileAuthState = void 0;
4
+ const async_mutex_1 = require("async-mutex");
4
5
  const promises_1 = require("fs/promises");
5
6
  const path_1 = require("path");
6
7
  const WAProto_1 = require("../../WAProto");
7
8
  const auth_utils_1 = require("./auth-utils");
8
9
  const generics_1 = require("./generics");
10
+ const fileLocks = new Map();
11
+ const getFileLock = (path) => {
12
+ let mutex = fileLocks.get(path);
13
+ if (!mutex) {
14
+ mutex = new async_mutex_1.Mutex();
15
+ fileLocks.set(path, mutex);
16
+ }
17
+ return mutex;
18
+ };
9
19
  /**
10
20
  * stores the full authentication state in a single folder.
11
21
  * Far more efficient than singlefileauthstate
@@ -14,13 +24,31 @@ const generics_1 = require("./generics");
14
24
  * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
15
25
  * */
16
26
  const useMultiFileAuthState = async (folder) => {
17
- const writeData = (data, file) => {
18
- return (0, promises_1.writeFile)((0, path_1.join)(folder, fixFileName(file)), JSON.stringify(data, generics_1.BufferJSON.replacer));
27
+ const writeData = async (data, file) => {
28
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
29
+ const mutex = getFileLock(filePath);
30
+ return mutex.acquire().then(async (release) => {
31
+ try {
32
+ await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
33
+ }
34
+ finally {
35
+ release();
36
+ }
37
+ });
19
38
  };
20
39
  const readData = async (file) => {
21
40
  try {
22
- const data = await (0, promises_1.readFile)((0, path_1.join)(folder, fixFileName(file)), { encoding: 'utf-8' });
23
- return JSON.parse(data, generics_1.BufferJSON.reviver);
41
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
42
+ const mutex = getFileLock(filePath);
43
+ return await mutex.acquire().then(async (release) => {
44
+ try {
45
+ const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
46
+ return JSON.parse(data, generics_1.BufferJSON.reviver);
47
+ }
48
+ finally {
49
+ release();
50
+ }
51
+ });
24
52
  }
25
53
  catch (error) {
26
54
  return null;
@@ -28,7 +56,18 @@ const useMultiFileAuthState = async (folder) => {
28
56
  };
29
57
  const removeData = async (file) => {
30
58
  try {
31
- await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
59
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
60
+ const mutex = getFileLock(filePath);
61
+ return mutex.acquire().then(async (release) => {
62
+ try {
63
+ await (0, promises_1.unlink)(filePath);
64
+ }
65
+ catch (_a) {
66
+ }
67
+ finally {
68
+ release();
69
+ }
70
+ });
32
71
  }
33
72
  catch (_a) {
34
73
  }
@@ -72,7 +111,7 @@ const useMultiFileAuthState = async (folder) => {
72
111
  }
73
112
  }
74
113
  },
75
- saveCreds: () => {
114
+ saveCreds: async () => {
76
115
  return writeData(creds, 'creds.json');
77
116
  }
78
117
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = exports.generateMobileNode = void 0;
3
+ exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const crypto_1 = require("crypto");
6
6
  const WAProto_1 = require("../../WAProto");
@@ -8,107 +8,108 @@ const Defaults_1 = require("../Defaults");
8
8
  const WABinary_1 = require("../WABinary");
9
9
  const crypto_2 = require("./crypto");
10
10
  const generics_1 = require("./generics");
11
- const signal_1 = require("./signal");
11
+ const signal_1 = require("./signal");
12
+
12
13
  const getUserAgent = (config) => {
13
- var _a, _b;
14
- const osVersion = config.mobile ? '15.3.1' : '0.1';
15
- const version = config.mobile ? [2, 24, 6] : config.version;
16
- const device = config.mobile ? 'iPhone_7' : 'Desktop';
17
- const manufacturer = config.mobile ? 'Apple' : '';
18
- const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
19
- const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
20
14
  return {
21
15
  appVersion: {
22
- primary: version[0],
23
- secondary: version[1],
24
- tertiary: version[2],
16
+ primary: config.version[0],
17
+ secondary: config.version[1],
18
+ tertiary: config.version[2],
25
19
  },
26
- platform,
20
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
27
21
  releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
28
- mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000',
29
- mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000',
30
- osVersion: osVersion,
31
- manufacturer,
32
- device,
33
- osBuildNumber: osVersion,
22
+ osVersion: '0.1',
23
+ device: 'Desktop',
24
+ osBuildNumber: '0.1',
34
25
  localeLanguageIso6391: 'en',
35
- localeCountryIso31661Alpha2: 'US',
36
- ...phoneId
26
+ mnc: '000',
27
+ mcc: '000',
28
+ localeCountryIso31661Alpha2: config.countryCode || 'US'
37
29
  };
38
30
  };
31
+
39
32
  const PLATFORM_MAP = {
40
33
  'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
41
34
  'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
42
35
  };
36
+
43
37
  const getWebInfo = (config) => {
44
38
  let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
45
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
39
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
46
40
  webSubPlatform = PLATFORM_MAP[config.browser[0]];
47
41
  }
48
42
  return { webSubPlatform };
49
43
  };
44
+
50
45
  const getClientPayload = (config) => {
51
46
  const payload = {
52
47
  connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
53
48
  connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
54
49
  userAgent: getUserAgent(config),
55
50
  };
56
- if (!config.mobile) {
57
- payload.webInfo = getWebInfo(config);
58
- }
51
+ payload.webInfo = getWebInfo(config);
59
52
  return payload;
60
53
  };
61
- const generateMobileNode = (config) => {
62
- if (!config.auth.creds) {
63
- throw new boom_1.Boom('No registration data found', { data: config });
64
- }
65
- const payload = {
66
- ...getClientPayload(config),
67
- sessionId: Math.floor(Math.random() * 999999999 + 1),
68
- shortConnect: true,
69
- connectAttemptCount: 0,
70
- device: 0,
71
- dnsSource: {
72
- appCached: false,
73
- dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
74
- },
75
- passive: false,
76
- pushName: 'test',
77
- username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
78
- };
79
- return WAProto_1.proto.ClientPayload.fromObject(payload);
80
- };
81
- exports.generateMobileNode = generateMobileNode;
54
+
82
55
  const generateLoginNode = (userJid, config) => {
83
56
  const { user, device } = (0, WABinary_1.jidDecode)(userJid);
84
57
  const payload = {
85
58
  ...getClientPayload(config),
86
59
  passive: true,
60
+ pull: true,
87
61
  username: +user,
88
62
  device: device,
63
+ lidDbMigrated: false
89
64
  };
90
65
  return WAProto_1.proto.ClientPayload.fromObject(payload);
91
66
  };
92
67
  exports.generateLoginNode = generateLoginNode;
68
+
93
69
  const getPlatformType = (platform) => {
94
70
  const platformType = platform.toUpperCase();
95
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
71
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
96
72
  };
73
+
97
74
  const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
98
- // the app version needs to be md5 hashed
99
- // and passed in
100
75
  const appVersionBuf = (0, crypto_1.createHash)('md5')
101
- .update(config.version.join('.')) // join as string
76
+ .update(config.version.join('.'))
102
77
  .digest();
78
+
103
79
  const companion = {
104
80
  os: config.browser[0],
105
81
  platformType: getPlatformType(config.browser[1]),
106
82
  requireFullSync: config.syncFullHistory,
83
+ historySyncConfig: {
84
+ storageQuotaMb: 10240,
85
+ inlineInitialPayloadInE2EeMsg: true,
86
+ recentSyncDaysLimit: undefined,
87
+ supportCallLogHistory: false,
88
+ supportBotUserAgentChatHistory: true,
89
+ supportCagReactionsAndPolls: true,
90
+ supportBizHostedMsg: true,
91
+ supportRecentSyncChunkMessageCountTuning: true,
92
+ supportHostedGroupMsg: true,
93
+ supportFbidBotChatHistory: true,
94
+ supportAddOnHistorySyncMigration: undefined,
95
+ supportMessageAssociation: true,
96
+ supportGroupHistory: false,
97
+ onDemandReady: undefined,
98
+ supportGuestChat: undefined
99
+ },
100
+ version: {
101
+ primary: 10,
102
+ secondary: 15,
103
+ tertiary: 7
104
+ }
107
105
  };
106
+
108
107
  const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
108
+
109
109
  const registerPayload = {
110
110
  ...getClientPayload(config),
111
111
  passive: false,
112
+ pull: false,
112
113
  devicePairingData: {
113
114
  buildHash: appVersionBuf,
114
115
  deviceProps: companionProto,
@@ -123,6 +124,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
123
124
  return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
124
125
  };
125
126
  exports.generateRegistrationNode = generateRegistrationNode;
127
+
126
128
  const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
127
129
  const msgId = stanza.attrs.id;
128
130
  const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
@@ -130,30 +132,52 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
130
132
  const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
131
133
  const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
132
134
  const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
135
+
133
136
  if (!deviceIdentityNode || !deviceNode) {
134
137
  throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
135
138
  }
136
- const bizName = businessNode === null || businessNode === void 0 ? void 0 : businessNode.attrs.name;
139
+
140
+ const bizName = businessNode?.attrs.name;
137
141
  const jid = deviceNode.attrs.jid;
138
- const { details, hmac } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
139
- // check HMAC matches
140
- const advSign = (0, crypto_2.hmacSign)(details, Buffer.from(advSecretKey, 'base64'));
142
+ const lid = deviceNode.attrs.lid;
143
+
144
+ const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
145
+
146
+ let hmacPrefix = Buffer.from([]);
147
+ if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
148
+ hmacPrefix = Buffer.from([0x06, 0x05]);
149
+ }
150
+
151
+ const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
141
152
  if (Buffer.compare(hmac, advSign) !== 0) {
142
153
  throw new boom_1.Boom('Invalid account signature');
143
154
  }
155
+
144
156
  const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
145
157
  const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
146
- // verify the device signature matches
147
- const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
158
+
159
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
160
+
161
+ const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
162
+ ? Buffer.from([0x06, 0x05])
163
+ : Buffer.from([0x06, 0x00]);
164
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
165
+
148
166
  if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
149
167
  throw new boom_1.Boom('Failed to verify account signature');
150
168
  }
151
- // sign the details with our identity key
152
- const deviceMsg = Buffer.concat([Buffer.from([6, 1]), deviceDetails, signedIdentityKey.public, accountSignatureKey]);
169
+
170
+ const deviceMsg = Buffer.concat([
171
+ Buffer.from([0x06, 0x01]),
172
+ deviceDetails,
173
+ signedIdentityKey.public,
174
+ accountSignatureKey
175
+ ]);
153
176
  account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
177
+
154
178
  const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
155
179
  const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
156
- const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details);
180
+
157
181
  const reply = {
158
182
  tag: 'iq',
159
183
  attrs: {
@@ -175,27 +199,27 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
175
199
  }
176
200
  ]
177
201
  };
202
+
178
203
  const authUpdate = {
179
204
  account,
180
- me: { id: jid, name: bizName },
205
+ me: { id: jid, name: bizName, lid },
181
206
  signalIdentities: [
182
207
  ...(signalIdentities || []),
183
208
  identity
184
209
  ],
185
- platform: platformNode === null || platformNode === void 0 ? void 0 : platformNode.attrs.name
210
+ platform: platformNode?.attrs.name
186
211
  };
212
+
187
213
  return {
188
214
  creds: authUpdate,
189
215
  reply
190
216
  };
191
217
  };
192
218
  exports.configureSuccessfulPairing = configureSuccessfulPairing;
219
+
193
220
  const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
194
- var _a;
195
221
  account = { ...account };
196
- // set to null if we are not to include the signature key
197
- // or if we are including the signature key but it is empty
198
- if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
222
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
199
223
  account.accountSignatureKey = null;
200
224
  }
201
225
  return WAProto_1.proto.ADVSignedDeviceIdentity
@@ -1,27 +1,30 @@
1
1
  export declare const TAGS: {
2
- LIST_EMPTY: number;
3
- DICTIONARY_0: number;
4
- DICTIONARY_1: number;
5
- DICTIONARY_2: number;
6
- DICTIONARY_3: number;
7
- AD_JID: number;
8
- LIST_8: number;
9
- LIST_16: number;
10
- JID_PAIR: number;
11
- HEX_8: number;
12
- BINARY_8: number;
13
- BINARY_20: number;
14
- BINARY_32: number;
15
- NIBBLE_8: number;
16
- PACKED_MAX: number;
17
- SINGLE_BYTE_MAX: number;
18
- STREAM_END: number;
19
- };
20
- export declare const DOUBLE_BYTE_TOKENS: string[][];
21
- export declare const SINGLE_BYTE_TOKENS: (string | null)[];
2
+ LIST_EMPTY: number
3
+ DICTIONARY_0: number
4
+ DICTIONARY_1: number
5
+ DICTIONARY_2: number
6
+ DICTIONARY_3: number
7
+ INTEROP_JID: number
8
+ FB_JID: number
9
+ AD_JID: number
10
+ LIST_8: number
11
+ LIST_16: number
12
+ JID_PAIR: number
13
+ HEX_8: number
14
+ BINARY_8: number
15
+ BINARY_20: number
16
+ BINARY_32: number
17
+ NIBBLE_8: number
18
+ PACKED_MAX: number
19
+ }
20
+
21
+ export declare const DOUBLE_BYTE_TOKENS: string[][]
22
+
23
+ export declare const SINGLE_BYTE_TOKENS: (string | null)[]
24
+
22
25
  export declare const TOKEN_MAP: {
23
26
  [token: string]: {
24
- dict?: number;
25
- index: number;
26
- };
27
- };
27
+ dict?: number
28
+ index: number
29
+ }
30
+ }