socketon 0.31.0 → 1.31.2-rc

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.
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const crypto_1 = require("crypto");
6
+ const WAProto_1 = require("../../WAProto");
7
+ const Defaults_1 = require("../Defaults");
8
+ const WABinary_1 = require("../WABinary");
9
+ const crypto_2 = require("./crypto");
10
+ const generics_1 = require("./generics");
11
+ const signal_1 = require("./signal");
12
+
13
+ const getUserAgent = (config) => {
14
+ return {
15
+ appVersion: {
16
+ primary: config.version[0],
17
+ secondary: config.version[1],
18
+ tertiary: config.version[2],
19
+ },
20
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
21
+ releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
22
+ osVersion: '0.1',
23
+ device: 'Desktop',
24
+ osBuildNumber: '0.1',
25
+ localeLanguageIso6391: 'en',
26
+ mnc: '000',
27
+ mcc: '000',
28
+ localeCountryIso31661Alpha2: config.countryCode || 'US'
29
+ };
30
+ };
31
+
32
+ exports.Browsers = {
33
+ iOS: (browser) => ["ios", browser, "18.2"],
34
+ ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
35
+ macOS: (browser) => ['Mac OS', browser, '14.4.1'],
36
+ baileys: (browser) => ['Baileys', browser, '6.5.0'],
37
+ windows: (browser) => ['Windows', browser, '10.0.22631']
38
+ };
39
+
40
+ const PLATFORM_MAP = {
41
+ 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
42
+ 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
43
+ };
44
+
45
+ const getWebInfo = (config) => {
46
+ let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
47
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
48
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
49
+ }
50
+ return { webSubPlatform };
51
+ };
52
+
53
+ const getClientPayload = (config) => {
54
+ const payload = {
55
+ connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
56
+ connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
57
+ userAgent: getUserAgent(config),
58
+ };
59
+ payload.webInfo = getWebInfo(config);
60
+ return payload;
61
+ };
62
+
63
+ const generateLoginNode = (userJid, config) => {
64
+ const { user, device } = (0, WABinary_1.jidDecode)(userJid);
65
+ const payload = {
66
+ ...getClientPayload(config),
67
+ passive: true,
68
+ pull: true,
69
+ username: +user,
70
+ device: device,
71
+ lidDbMigrated: false
72
+ };
73
+ return WAProto_1.proto.ClientPayload.fromObject(payload);
74
+ };
75
+ exports.generateLoginNode = generateLoginNode;
76
+
77
+ const getPlatformType = (platform) => {
78
+ const platformType = platform.toUpperCase();
79
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
80
+ };
81
+
82
+ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
83
+ const appVersionBuf = (0, crypto_1.createHash)('md5')
84
+ .update(config.version.join('.'))
85
+ .digest();
86
+
87
+ const companion = {
88
+ os: config.browser[0],
89
+ platformType: getPlatformType(config.browser[1]),
90
+ requireFullSync: config.syncFullHistory,
91
+ historySyncConfig: {
92
+ storageQuotaMb: 10240,
93
+ inlineInitialPayloadInE2EeMsg: true,
94
+ recentSyncDaysLimit: undefined,
95
+ supportCallLogHistory: false,
96
+ supportBotUserAgentChatHistory: true,
97
+ supportCagReactionsAndPolls: true,
98
+ supportBizHostedMsg: true,
99
+ supportRecentSyncChunkMessageCountTuning: true,
100
+ supportHostedGroupMsg: true,
101
+ supportFbidBotChatHistory: true,
102
+ supportAddOnHistorySyncMigration: undefined,
103
+ supportMessageAssociation: true,
104
+ supportGroupHistory: false,
105
+ onDemandReady: undefined,
106
+ supportGuestChat: undefined
107
+ },
108
+ version: {
109
+ primary: 10,
110
+ secondary: 15,
111
+ tertiary: 7
112
+ }
113
+ };
114
+
115
+ const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
116
+
117
+ const registerPayload = {
118
+ ...getClientPayload(config),
119
+ passive: false,
120
+ pull: false,
121
+ devicePairingData: {
122
+ buildHash: appVersionBuf,
123
+ deviceProps: companionProto,
124
+ eRegid: (0, generics_1.encodeBigEndian)(registrationId),
125
+ eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
126
+ eIdent: signedIdentityKey.public,
127
+ eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
128
+ eSkeyVal: signedPreKey.keyPair.public,
129
+ eSkeySig: signedPreKey.signature,
130
+ },
131
+ };
132
+ return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
133
+ };
134
+ exports.generateRegistrationNode = generateRegistrationNode;
135
+
136
+ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
137
+ const msgId = stanza.attrs.id;
138
+ const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
139
+ const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
140
+ const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
141
+ const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
142
+ const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
143
+
144
+ if (!deviceIdentityNode || !deviceNode) {
145
+ throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
146
+ }
147
+
148
+ const bizName = businessNode?.attrs.name;
149
+ const jid = deviceNode.attrs.jid;
150
+ const lid = deviceNode.attrs.lid;
151
+
152
+ const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
153
+
154
+ let hmacPrefix = Buffer.from([]);
155
+ if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
156
+ hmacPrefix = Buffer.from([0x06, 0x05]);
157
+ }
158
+
159
+ const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
160
+ if (Buffer.compare(hmac, advSign) !== 0) {
161
+ throw new boom_1.Boom('Invalid account signature');
162
+ }
163
+
164
+ const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
165
+ const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
166
+
167
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
168
+
169
+ const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
170
+ ? Buffer.from([0x06, 0x05])
171
+ : Buffer.from([0x06, 0x00]);
172
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
173
+
174
+ if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
175
+ throw new boom_1.Boom('Failed to verify account signature');
176
+ }
177
+
178
+ const deviceMsg = Buffer.concat([
179
+ Buffer.from([0x06, 0x01]),
180
+ deviceDetails,
181
+ signedIdentityKey.public,
182
+ accountSignatureKey
183
+ ]);
184
+ account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
185
+
186
+ const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
187
+ const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
188
+
189
+ const reply = {
190
+ tag: 'iq',
191
+ attrs: {
192
+ to: WABinary_1.S_WHATSAPP_NET,
193
+ type: 'result',
194
+ id: msgId,
195
+ },
196
+ content: [
197
+ {
198
+ tag: 'pair-device-sign',
199
+ attrs: {},
200
+ content: [
201
+ {
202
+ tag: 'device-identity',
203
+ attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
204
+ content: accountEnc
205
+ }
206
+ ]
207
+ }
208
+ ]
209
+ };
210
+
211
+ const authUpdate = {
212
+ account,
213
+ me: { id: jid, name: bizName, lid },
214
+ signalIdentities: [
215
+ ...(signalIdentities || []),
216
+ identity
217
+ ],
218
+ platform: platformNode?.attrs.name
219
+ };
220
+
221
+ return {
222
+ creds: authUpdate,
223
+ reply
224
+ };
225
+ };
226
+ exports.configureSuccessfulPairing = configureSuccessfulPairing;
227
+
228
+ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
229
+ account = { ...account };
230
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
231
+ account.accountSignatureKey = null;
232
+ }
233
+ return WAProto_1.proto.ADVSignedDeviceIdentity
234
+ .encode(account)
235
+ .finish();
236
+ };
237
+ exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
package/lib/index.js CHANGED
@@ -17,8 +17,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
17
17
  Object.defineProperty(o, k2, desc);
18
18
  }) : (function(o, m, k, k2) {
19
19
  if (k2 === undefined) k2 = k;
20
- o[k2] =
21
- m[k];
20
+ o[k2] = m[k];
22
21
  }));
23
22
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
23
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "socketon",
3
- "version": "0.31.0",
4
- "description": "WhatsApp API Library - Socketon By IbraDecode",
3
+ "version": "1.31.2-rc",
4
+ "publishConfig": {
5
+ "tag": "rc"
6
+ },
7
+ "description": "WhatsApp API Library - Socketon By IbraDecode & Socketon Community",
5
8
  "keywords": [
6
9
  "whatsapp",
7
10
  "socketon",
@@ -15,116 +18,99 @@
15
18
  "socketon-whatsapp"
16
19
  ],
17
20
  "homepage": "https://github.com/IbraDecode/socketon",
18
- "repository": {
19
- "url": "https://github.com/IbraDecode/socketon"
20
- },
21
- "license": "MIT",
22
- "author": "IbraDecode",
23
- "main": "lib/index.js",
24
- "types": "lib/index.d.ts",
25
- "files": [
26
- "lib/*",
27
- "WAProto/*.js",
28
- "engine-requirements.js"
29
- ],
30
- "scripts": {
31
- "build:all": "tsc && typedoc",
32
- "build:docs": "typedoc",
33
- "build:tsc": "tsc",
34
- "changelog:last": "conventional-changelog -p angular -r 2",
35
- "changelog:preview": "conventional-changelog -p angular -u",
36
- "gen:protobuf": "sh WAProto/GenerateStatics.sh",
37
- "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
38
- "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
39
- "prepack": "npm run build:all && npm run lint",
40
- "prepare": "",
41
- "preinstall": "node ./engine-requirements.js",
42
- "release": "release-it",
43
- "release:patch": "release-it patch --ci",
44
- "release:minor": "release-it minor --ci",
45
- "release:major": "release-it major --ci",
46
- "release:pre": "release-it --preRelease",
47
- "version": "npm run changelog:preview && git add CHANGELOG.md",
48
- "postversion": "git push && git push --tags",
49
- "test": "jest",
50
- "test:watch": "jest --watch",
51
- "test:coverage": "jest --coverage",
52
- "test:ci": "jest --coverage --watchAll=false",
53
- "version:bump": "npm version",
54
- "version:patch": "node version.js bump patch",
55
- "version:minor": "node version.js bump minor",
56
- "version:major": "node version.js bump major",
57
- "version:current": "node version.js current",
58
- "version:validate": "node version.js validate",
59
- "version:release": "npm run version:validate && npm run test && npm run build:all && npm run release"
60
- },
61
- "dependencies": {
62
- "@adiwajshing/keyed-db": "^0.2.4",
63
- "@hapi/boom": "^9.1.3",
64
- "@cacheable/node-cache": "^1.4.0",
65
- "async-mutex": "^0.5.0",
66
- "audio-decode": "^2.1.3",
67
- "axios": "^1.3.3",
68
- "cache-manager": "4.0.1",
69
- "chalk": "^4.1.2",
70
- "futoin-hkdf": "^1.5.1",
71
- "libphonenumber-js": "^1.10.20",
72
- "lodash": "^4.17.21",
73
- "libsignal": "npm:@shennmine/libsignal-node@2.0.1",
74
- "music-metadata": "^7.12.3",
75
- "node-cache": "^5.1.2",
76
- "node-fetch": "^2.6.1",
77
- "pino": "^7.0.0",
78
- "protobufjs": "^7.2.4",
79
- "uuid": "^9.0.0",
80
- "ws": "^8.13.0"
81
- },
82
- "devDependencies": {
83
- "@eslint/js": "^9.0.0",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/lbraDecode/socketon.git"
24
+ },
25
+ "license": "MIT",
26
+ "author": "Ibra Decode",
27
+ "main": "lib/index.js",
28
+ "types": "lib/index.d.ts",
29
+ "files": [
30
+ "lib/*",
31
+ "WAProto/*.js",
32
+ "engine-requirements.js"
33
+ ],
34
+ "scripts": {
35
+ "build:all": "tsc && typedoc",
36
+ "build:docs": "typedoc",
37
+ "build:tsc": "tsc",
38
+ "changelog:last": "conventional-changelog -p angular -r 2",
39
+ "changelog:preview": "conventional-changelog -p angular -u",
40
+ "gen:protobuf": "sh WAProto/GenerateStatics.sh",
41
+ "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
42
+ "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
43
+ "prepack": "",
44
+ "prepare": "",
45
+ "preinstall": "node ./engine-requirements.js",
46
+ "release": "release-it",
47
+ "test": "jest"
48
+ },
49
+ "dependencies": {
50
+ "@adiwajshing/keyed-db": "^0.2.4",
51
+ "@hapi/boom": "^9.1.3",
52
+ "@cacheable/node-cache": "^1.4.0",
53
+ "async-mutex": "^0.5.0",
54
+ "audio-decode": "^2.1.3",
55
+ "axios": "^1.3.3",
56
+ "cache-manager": "4.0.1",
57
+ "chalk": "^4.1.2",
58
+ "futoin-hkdf": "^1.5.1",
59
+ "libphonenumber-js": "^1.10.20",
60
+ "lodash": "^4.17.21",
61
+ "libsignal": "npm:@skyzopedia/libsignal-node",
62
+ "music-metadata": "^7.12.3",
63
+ "node-cache": "^5.1.2",
64
+ "node-fetch": "^2.6.1",
65
+ "pino": "^7.0.0",
66
+ "protobufjs": "^7.2.4",
67
+ "uuid": "^9.0.0",
68
+ "ws": "^8.13.0"
69
+ },
70
+ "devDependencies": {
71
+ "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
72
+ "@types/got": "^9.6.11",
73
+ "@types/jest": "^27.5.1",
74
+ "@types/node": "^16.0.0",
75
+ "@types/sharp": "^0.29.4",
76
+ "@types/ws": "^8.0.0",
77
+ "conventional-changelog-cli": "^2.2.2",
84
78
  "eslint": "^9.0.0",
85
- "typescript-eslint": "^8.0.0",
86
- "@types/got": "^9.6.11",
87
- "@types/jest": "^27.5.1",
88
- "@types/node": "^16.0.0",
89
- "@types/sharp": "^0.29.4",
90
- "@types/ws": "^8.0.0",
91
- "conventional-changelog-cli": "^4.1.0",
92
- "eslint": "^8.0.0",
93
- "jest": "^27.0.6",
94
- "jimp": "^0.16.1",
95
- "link-preview-js": "^3.0.0",
96
- "open": "^8.4.2",
97
- "qrcode-terminal": "^0.12.0",
98
- "release-it": "^17.1.1",
99
- "sharp": "^0.30.5",
100
- "ts-jest": "^27.0.3",
101
- "ts-node": "^10.8.1",
102
- "typedoc": "^0.25.8",
103
- "typescript": "^4.6.4",
104
- "json": "^11.0.0"
105
- },
106
- "peerDependencies": {
107
- "jimp": "^0.16.1",
108
- "link-preview-js": "^3.0.0",
109
- "qrcode-terminal": "^0.12.0",
110
- "sharp": "^0.32.2"
111
- },
112
- "peerDependenciesMeta": {
113
- "jimp": {
114
- "optional": true
79
+ "jest": "^27.0.6",
80
+ "jimp": "^0.22.12",
81
+ "link-preview-js": "^3.0.0",
82
+ "open": "^8.4.2",
83
+ "qrcode-terminal": "^0.12.0",
84
+ "release-it": "^15.10.3",
85
+ "sharp": "^0.30.5",
86
+ "ts-jest": "^27.0.3",
87
+ "ts-node": "^10.8.1",
88
+ "typedoc": "^0.24.7",
89
+ "typescript": "^4.6.4",
90
+ "json": "^11.0.0"
115
91
  },
116
- "link-preview-js": {
117
- "optional": true
92
+ "peerDependencies": {
93
+ "jimp": "^0.22.12",
94
+ "link-preview-js": "^3.0.0",
95
+ "qrcode-terminal": "^0.12.0",
96
+ "sharp": "^0.32.2"
118
97
  },
119
- "qrcode-terminal": {
120
- "optional": true
98
+ "peerDependenciesMeta": {
99
+ "jimp": {
100
+ "optional": true
101
+ },
102
+ "link-preview-js": {
103
+ "optional": true
104
+ },
105
+ "qrcode-terminal": {
106
+ "optional": true
107
+ },
108
+ "sharp": {
109
+ "optional": true
110
+ }
121
111
  },
122
- "sharp": {
123
- "optional": true
112
+ "packageManager": "yarn@1.22.19",
113
+ "engines": {
114
+ "node": ">=20.0.0"
124
115
  }
125
- },
126
- "packageManager": "yarn@1.22.19",
127
- "engines": {
128
- "node": ">=20.0.0"
129
- }
130
- }
116
+ }