alwaysaqioo 1.1.1 → 1.1.3

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 +9 -110
  2. package/WAProto/GenerateStatics.sh +4 -0
  3. package/WAProto/WAProto.proto +3344 -0
  4. package/WAProto/index.d.ts +37016 -0
  5. package/WAProto/index.js +79296 -118676
  6. package/WASignalGroup/GroupProtocol.js +1697 -0
  7. package/WASignalGroup/ciphertext_message.js +16 -0
  8. package/WASignalGroup/group_cipher.js +120 -0
  9. package/WASignalGroup/group_session_builder.js +46 -0
  10. package/WASignalGroup/index.js +5 -0
  11. package/WASignalGroup/keyhelper.js +21 -0
  12. package/WASignalGroup/protobufs.js +3 -0
  13. package/WASignalGroup/queue_job.js +69 -0
  14. package/WASignalGroup/sender_chain_key.js +50 -0
  15. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  16. package/WASignalGroup/sender_key_message.js +92 -0
  17. package/WASignalGroup/sender_key_name.js +70 -0
  18. package/WASignalGroup/sender_key_record.js +56 -0
  19. package/WASignalGroup/sender_key_state.js +129 -0
  20. package/WASignalGroup/sender_message_key.js +39 -0
  21. package/lib/Defaults/baileys-version.json +1 -1
  22. package/lib/Defaults/index.js +2 -19
  23. package/lib/Signal/Group/x +1 -0
  24. package/lib/Socket/chats.d.ts +32 -215
  25. package/lib/Socket/chats.js +75 -155
  26. package/lib/Socket/groups.js +18 -18
  27. package/lib/Socket/index.js +0 -1
  28. package/lib/Socket/messages-send.d.ts +2 -2
  29. package/lib/Socket/messages-send.js +348 -327
  30. package/lib/Socket/newsletter.js +21 -100
  31. package/lib/Socket/socket.js +30 -65
  32. package/lib/Types/Newsletter.d.ts +86 -97
  33. package/lib/Types/Newsletter.js +32 -38
  34. package/lib/Utils/generics.js +33 -65
  35. package/lib/Utils/messages-media.js +57 -145
  36. package/lib/Utils/messages.js +14 -26
  37. package/lib/Utils/signal.js +46 -48
  38. package/lib/Utils/use-multi-file-auth-state.js +6 -45
  39. package/lib/Utils/validate-connection.js +65 -89
  40. package/lib/WABinary/constants.d.ts +24 -27
  41. package/lib/WABinary/encode.js +123 -160
  42. package/lib/WABinary/generic-utils.d.ts +1 -2
  43. package/lib/WABinary/generic-utils.js +43 -123
  44. package/lib/WAUSync/index.d.ts +3 -0
  45. package/lib/index.d.ts +0 -1
  46. package/lib/index.js +2 -12
  47. package/package.json +98 -100
  48. package/engine-requirements.js +0 -10
  49. package/lib/Socket/luxu.d.ts +0 -268
  50. package/lib/Socket/luxu.js +0 -591
@@ -4,7 +4,6 @@ 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")
8
7
  const generics_1 = require("./generics");
9
8
  const createSignalIdentity = (wid, accountSignatureKey) => {
10
9
  return {
@@ -59,61 +58,60 @@ const xmppPreKey = (pair, id) => ({
59
58
  exports.xmppPreKey = xmppPreKey;
60
59
  const parseAndInjectE2ESessions = async (node, repository) => {
61
60
  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')
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');
67
66
  for (const node of nodes) {
68
- WABinary_1.assertNodeErrorFree(node)
67
+ (0, WABinary_1.assertNodeErrorFree)(node);
69
68
  }
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
- }
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
+ };
96
86
  exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
97
87
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
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 })
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
+ }
111
109
  }
112
110
  }
113
111
  }
114
112
  }
115
- return extracted
116
- }
113
+ return extracted;
114
+ };
117
115
  exports.extractDeviceJids = extractDeviceJids;
118
116
  /**
119
117
  * get the next N keys for upload or processing
@@ -1,21 +1,11 @@
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");
5
4
  const promises_1 = require("fs/promises");
6
5
  const path_1 = require("path");
7
6
  const WAProto_1 = require("../../WAProto");
8
7
  const auth_utils_1 = require("./auth-utils");
9
8
  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
- };
19
9
  /**
20
10
  * stores the full authentication state in a single folder.
21
11
  * Far more efficient than singlefileauthstate
@@ -24,31 +14,13 @@ const getFileLock = (path) => {
24
14
  * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
25
15
  * */
26
16
  const useMultiFileAuthState = async (folder) => {
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
- });
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));
38
19
  };
39
20
  const readData = async (file) => {
40
21
  try {
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
- });
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);
52
24
  }
53
25
  catch (error) {
54
26
  return null;
@@ -56,18 +28,7 @@ const useMultiFileAuthState = async (folder) => {
56
28
  };
57
29
  const removeData = async (file) => {
58
30
  try {
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
- });
31
+ await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
71
32
  }
72
33
  catch (_a) {
73
34
  }
@@ -111,7 +72,7 @@ const useMultiFileAuthState = async (folder) => {
111
72
  }
112
73
  }
113
74
  },
114
- saveCreds: async () => {
75
+ saveCreds: () => {
115
76
  return writeData(creds, 'creds.json');
116
77
  }
117
78
  };
@@ -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 = void 0;
3
+ exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = exports.generateMobileNode = 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,108 +8,107 @@ 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");
12
-
11
+ const signal_1 = require("./signal");
13
12
  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 } : {};
14
20
  return {
15
21
  appVersion: {
16
- primary: config.version[0],
17
- secondary: config.version[1],
18
- tertiary: config.version[2],
22
+ primary: version[0],
23
+ secondary: version[1],
24
+ tertiary: version[2],
19
25
  },
20
- platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
26
+ platform,
21
27
  releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
22
- osVersion: '0.1',
23
- device: 'Desktop',
24
- osBuildNumber: '0.1',
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,
25
34
  localeLanguageIso6391: 'en',
26
- mnc: '000',
27
- mcc: '000',
28
- localeCountryIso31661Alpha2: config.countryCode || 'US'
35
+ localeCountryIso31661Alpha2: 'US',
36
+ ...phoneId
29
37
  };
30
38
  };
31
-
32
39
  const PLATFORM_MAP = {
33
40
  'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
34
41
  'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
35
42
  };
36
-
37
43
  const getWebInfo = (config) => {
38
44
  let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
39
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
45
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
40
46
  webSubPlatform = PLATFORM_MAP[config.browser[0]];
41
47
  }
42
48
  return { webSubPlatform };
43
49
  };
44
-
45
50
  const getClientPayload = (config) => {
46
51
  const payload = {
47
52
  connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
48
53
  connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
49
54
  userAgent: getUserAgent(config),
50
55
  };
51
- payload.webInfo = getWebInfo(config);
56
+ if (!config.mobile) {
57
+ payload.webInfo = getWebInfo(config);
58
+ }
52
59
  return payload;
53
60
  };
54
-
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;
55
82
  const generateLoginNode = (userJid, config) => {
56
83
  const { user, device } = (0, WABinary_1.jidDecode)(userJid);
57
84
  const payload = {
58
85
  ...getClientPayload(config),
59
86
  passive: true,
60
- pull: true,
61
87
  username: +user,
62
88
  device: device,
63
- lidDbMigrated: false
64
89
  };
65
90
  return WAProto_1.proto.ClientPayload.fromObject(payload);
66
91
  };
67
92
  exports.generateLoginNode = generateLoginNode;
68
-
69
93
  const getPlatformType = (platform) => {
70
94
  const platformType = platform.toUpperCase();
71
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
95
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
72
96
  };
73
-
74
97
  const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
98
+ // the app version needs to be md5 hashed
99
+ // and passed in
75
100
  const appVersionBuf = (0, crypto_1.createHash)('md5')
76
- .update(config.version.join('.'))
101
+ .update(config.version.join('.')) // join as string
77
102
  .digest();
78
-
79
103
  const companion = {
80
104
  os: config.browser[0],
81
105
  platformType: getPlatformType(config.browser[1]),
82
106
  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
- }
105
107
  };
106
-
107
108
  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,
113
112
  devicePairingData: {
114
113
  buildHash: appVersionBuf,
115
114
  deviceProps: companionProto,
@@ -124,7 +123,6 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
124
123
  return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
125
124
  };
126
125
  exports.generateRegistrationNode = generateRegistrationNode;
127
-
128
126
  const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
129
127
  const msgId = stanza.attrs.id;
130
128
  const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
@@ -132,52 +130,30 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
132
130
  const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
133
131
  const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
134
132
  const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
135
-
136
133
  if (!deviceIdentityNode || !deviceNode) {
137
134
  throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
138
135
  }
139
-
140
- const bizName = businessNode?.attrs.name;
136
+ const bizName = businessNode === null || businessNode === void 0 ? void 0 : businessNode.attrs.name;
141
137
  const jid = deviceNode.attrs.jid;
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'));
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'));
152
141
  if (Buffer.compare(hmac, advSign) !== 0) {
153
142
  throw new boom_1.Boom('Invalid account signature');
154
143
  }
155
-
156
144
  const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
157
145
  const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
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
-
146
+ // verify the device signature matches
147
+ const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
166
148
  if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
167
149
  throw new boom_1.Boom('Failed to verify account signature');
168
150
  }
169
-
170
- const deviceMsg = Buffer.concat([
171
- Buffer.from([0x06, 0x01]),
172
- deviceDetails,
173
- signedIdentityKey.public,
174
- accountSignatureKey
175
- ]);
151
+ // sign the details with our identity key
152
+ const deviceMsg = Buffer.concat([Buffer.from([6, 1]), deviceDetails, signedIdentityKey.public, accountSignatureKey]);
176
153
  account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
177
-
178
154
  const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
179
155
  const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
180
-
156
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(account.details);
181
157
  const reply = {
182
158
  tag: 'iq',
183
159
  attrs: {
@@ -199,27 +175,27 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
199
175
  }
200
176
  ]
201
177
  };
202
-
203
178
  const authUpdate = {
204
179
  account,
205
- me: { id: jid, name: bizName, lid },
180
+ me: { id: jid, name: bizName },
206
181
  signalIdentities: [
207
182
  ...(signalIdentities || []),
208
183
  identity
209
184
  ],
210
- platform: platformNode?.attrs.name
185
+ platform: platformNode === null || platformNode === void 0 ? void 0 : platformNode.attrs.name
211
186
  };
212
-
213
187
  return {
214
188
  creds: authUpdate,
215
189
  reply
216
190
  };
217
191
  };
218
192
  exports.configureSuccessfulPairing = configureSuccessfulPairing;
219
-
220
193
  const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
194
+ var _a;
221
195
  account = { ...account };
222
- if (!includeSignatureKey || !account.accountSignatureKey?.length) {
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)) {
223
199
  account.accountSignatureKey = null;
224
200
  }
225
201
  return WAProto_1.proto.ADVSignedDeviceIdentity
@@ -1,30 +1,27 @@
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
- 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
-
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)[];
25
22
  export declare const TOKEN_MAP: {
26
23
  [token: string]: {
27
- dict?: number
28
- index: number
29
- }
30
- }
24
+ dict?: number;
25
+ index: number;
26
+ };
27
+ };