@queenanya/baileys 6.5.8 → 6.6.0

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 (129) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/Defaults/baileys-version.json +3 -3
  3. package/lib/Defaults/index.d.ts +284 -283
  4. package/lib/Defaults/index.js +116 -115
  5. package/lib/Defaults/phonenumber-mcc.json +223 -223
  6. package/lib/Signal/libsignal.d.ts +3 -3
  7. package/lib/Signal/libsignal.js +152 -152
  8. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -17
  9. package/lib/Socket/Client/abstract-socket-client.js +13 -13
  10. package/lib/Socket/Client/index.d.ts +3 -3
  11. package/lib/Socket/Client/index.js +19 -19
  12. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -13
  13. package/lib/Socket/Client/mobile-socket-client.js +65 -65
  14. package/lib/Socket/Client/web-socket-client.d.ts +12 -12
  15. package/lib/Socket/Client/web-socket-client.js +62 -62
  16. package/lib/Socket/business.d.ts +126 -126
  17. package/lib/Socket/business.js +259 -259
  18. package/lib/Socket/chats.d.ts +75 -75
  19. package/lib/Socket/chats.js +842 -842
  20. package/lib/Socket/groups.d.ts +107 -107
  21. package/lib/Socket/groups.js +295 -291
  22. package/lib/Socket/index.d.ts +128 -128
  23. package/lib/Socket/index.js +10 -10
  24. package/lib/Socket/messages-recv.d.ts +115 -115
  25. package/lib/Socket/messages-recv.js +725 -725
  26. package/lib/Socket/messages-send.d.ts +112 -112
  27. package/lib/Socket/messages-send.js +660 -660
  28. package/lib/Socket/registration.d.ts +223 -223
  29. package/lib/Socket/registration.js +166 -166
  30. package/lib/Socket/socket.d.ts +42 -42
  31. package/lib/Socket/socket.js +587 -587
  32. package/lib/Store/index.d.ts +3 -3
  33. package/lib/Store/index.js +10 -10
  34. package/lib/Store/make-cache-manager-store.d.ts +14 -14
  35. package/lib/Store/make-cache-manager-store.js +83 -83
  36. package/lib/Store/make-in-memory-store.d.ts +117 -117
  37. package/lib/Store/make-in-memory-store.js +437 -437
  38. package/lib/Store/make-ordered-dictionary.d.ts +13 -13
  39. package/lib/Store/make-ordered-dictionary.js +81 -81
  40. package/lib/Store/object-repository.d.ts +10 -10
  41. package/lib/Store/object-repository.js +27 -27
  42. package/lib/Types/Auth.d.ts +108 -108
  43. package/lib/Types/Auth.js +2 -2
  44. package/lib/Types/Call.d.ts +12 -12
  45. package/lib/Types/Call.js +2 -2
  46. package/lib/Types/Chat.d.ts +102 -102
  47. package/lib/Types/Chat.js +4 -4
  48. package/lib/Types/Contact.d.ts +18 -18
  49. package/lib/Types/Contact.js +2 -2
  50. package/lib/Types/Events.d.ts +152 -152
  51. package/lib/Types/Events.js +2 -2
  52. package/lib/Types/GroupMetadata.d.ts +50 -44
  53. package/lib/Types/GroupMetadata.js +2 -2
  54. package/lib/Types/Label.d.ts +35 -35
  55. package/lib/Types/Label.js +27 -27
  56. package/lib/Types/LabelAssociation.d.ts +29 -29
  57. package/lib/Types/LabelAssociation.js +9 -9
  58. package/lib/Types/Message.d.ts +255 -255
  59. package/lib/Types/Message.js +9 -9
  60. package/lib/Types/Product.d.ts +78 -78
  61. package/lib/Types/Product.js +2 -2
  62. package/lib/Types/Signal.d.ts +57 -57
  63. package/lib/Types/Signal.js +2 -2
  64. package/lib/Types/Socket.d.ts +109 -109
  65. package/lib/Types/Socket.js +2 -2
  66. package/lib/Types/State.d.ts +27 -27
  67. package/lib/Types/State.js +2 -2
  68. package/lib/Types/index.d.ts +54 -54
  69. package/lib/Types/index.js +39 -39
  70. package/lib/Utils/auth-utils.d.ts +18 -18
  71. package/lib/Utils/auth-utils.js +204 -204
  72. package/lib/Utils/baileys-event-stream.d.ts +16 -16
  73. package/lib/Utils/baileys-event-stream.js +63 -63
  74. package/lib/Utils/business.d.ts +22 -22
  75. package/lib/Utils/business.js +234 -234
  76. package/lib/Utils/chat-utils.d.ts +71 -71
  77. package/lib/Utils/chat-utils.js +710 -710
  78. package/lib/Utils/crypto.d.ts +41 -41
  79. package/lib/Utils/crypto.js +151 -151
  80. package/lib/Utils/decode-wa-message.d.ts +19 -19
  81. package/lib/Utils/decode-wa-message.js +160 -160
  82. package/lib/Utils/event-buffer.d.ts +35 -35
  83. package/lib/Utils/event-buffer.js +514 -514
  84. package/lib/Utils/generics.d.ts +93 -93
  85. package/lib/Utils/generics.js +366 -366
  86. package/lib/Utils/history.d.ts +15 -15
  87. package/lib/Utils/history.js +91 -91
  88. package/lib/Utils/index.d.ts +17 -17
  89. package/lib/Utils/index.js +33 -33
  90. package/lib/Utils/link-preview.d.ts +21 -21
  91. package/lib/Utils/link-preview.js +93 -93
  92. package/lib/Utils/logger.d.ts +4 -4
  93. package/lib/Utils/logger.js +7 -7
  94. package/lib/Utils/lt-hash.d.ts +12 -12
  95. package/lib/Utils/lt-hash.js +51 -51
  96. package/lib/Utils/make-mutex.d.ts +7 -7
  97. package/lib/Utils/make-mutex.js +43 -43
  98. package/lib/Utils/messages-media.d.ts +107 -107
  99. package/lib/Utils/messages-media.js +680 -680
  100. package/lib/Utils/messages.d.ts +76 -76
  101. package/lib/Utils/messages.js +762 -762
  102. package/lib/Utils/noise-handler.d.ts +20 -20
  103. package/lib/Utils/noise-handler.js +142 -142
  104. package/lib/Utils/process-message.d.ts +41 -41
  105. package/lib/Utils/process-message.js +297 -297
  106. package/lib/Utils/signal.d.ts +32 -32
  107. package/lib/Utils/signal.js +151 -151
  108. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -12
  109. package/lib/Utils/use-multi-file-auth-state.js +80 -80
  110. package/lib/Utils/validate-connection.d.ts +11 -11
  111. package/lib/Utils/validate-connection.js +187 -187
  112. package/lib/WABinary/constants.d.ts +27 -27
  113. package/lib/WABinary/constants.js +40 -40
  114. package/lib/WABinary/decode.d.ts +7 -7
  115. package/lib/WABinary/decode.js +252 -252
  116. package/lib/WABinary/encode.d.ts +3 -3
  117. package/lib/WABinary/encode.js +228 -228
  118. package/lib/WABinary/generic-utils.d.ts +15 -15
  119. package/lib/WABinary/generic-utils.js +110 -110
  120. package/lib/WABinary/index.d.ts +5 -5
  121. package/lib/WABinary/index.js +21 -21
  122. package/lib/WABinary/jid-utils.d.ts +27 -27
  123. package/lib/WABinary/jid-utils.js +56 -56
  124. package/lib/WABinary/types.d.ts +18 -18
  125. package/lib/WABinary/types.js +2 -2
  126. package/lib/index.d.ts +10 -10
  127. package/lib/index.js +29 -29
  128. package/package.json +113 -113
  129. package/WASignalGroup/readme.md +0 -6
@@ -1,32 +1,32 @@
1
- import { SignalRepository } from '../Types';
2
- import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
3
- import { BinaryNode, JidWithDevice } from '../WABinary';
4
- export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
5
- export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
6
- [id: string]: KeyPair;
7
- }>;
8
- export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
9
- newPreKeys: {
10
- [id: number]: KeyPair;
11
- };
12
- lastPreKeyId: number;
13
- preKeysRange: readonly [number, number];
14
- };
15
- export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
16
- export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
17
- export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
18
- export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
19
- /**
20
- * get the next N keys for upload or processing
21
- * @param count number of pre-keys to get or generate
22
- */
23
- export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
24
- update: Partial<AuthenticationCreds>;
25
- preKeys: {
26
- [id: string]: KeyPair;
27
- };
28
- }>;
29
- export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
30
- update: Partial<AuthenticationCreds>;
31
- node: BinaryNode;
32
- }>;
1
+ import { SignalRepository } from '../Types';
2
+ import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
3
+ import { BinaryNode, JidWithDevice } from '../WABinary';
4
+ export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
5
+ export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
6
+ [id: string]: KeyPair;
7
+ }>;
8
+ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
9
+ newPreKeys: {
10
+ [id: number]: KeyPair;
11
+ };
12
+ lastPreKeyId: number;
13
+ preKeysRange: readonly [number, number];
14
+ };
15
+ export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
16
+ export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
17
+ export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
18
+ export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
19
+ /**
20
+ * get the next N keys for upload or processing
21
+ * @param count number of pre-keys to get or generate
22
+ */
23
+ export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
24
+ update: Partial<AuthenticationCreds>;
25
+ preKeys: {
26
+ [id: string]: KeyPair;
27
+ };
28
+ }>;
29
+ export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
30
+ update: Partial<AuthenticationCreds>;
31
+ node: BinaryNode;
32
+ }>;
@@ -1,151 +1,151 @@
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 generics_1 = require("./generics");
8
- const createSignalIdentity = (wid, accountSignatureKey) => {
9
- return {
10
- identifier: { name: wid, deviceId: 0 },
11
- identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
12
- };
13
- };
14
- exports.createSignalIdentity = createSignalIdentity;
15
- const getPreKeys = async ({ get }, min, limit) => {
16
- const idList = [];
17
- for (let id = min; id < limit; id++) {
18
- idList.push(id.toString());
19
- }
20
- return get('pre-key', idList);
21
- };
22
- exports.getPreKeys = getPreKeys;
23
- const generateOrGetPreKeys = (creds, range) => {
24
- const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
25
- const remaining = range - avaliable;
26
- const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
27
- const newPreKeys = {};
28
- if (remaining > 0) {
29
- for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
30
- newPreKeys[i] = crypto_1.Curve.generateKeyPair();
31
- }
32
- }
33
- return {
34
- newPreKeys,
35
- lastPreKeyId,
36
- preKeysRange: [creds.firstUnuploadedPreKeyId, range],
37
- };
38
- };
39
- exports.generateOrGetPreKeys = generateOrGetPreKeys;
40
- const xmppSignedPreKey = (key) => ({
41
- tag: 'skey',
42
- attrs: {},
43
- content: [
44
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
45
- { tag: 'value', attrs: {}, content: key.keyPair.public },
46
- { tag: 'signature', attrs: {}, content: key.signature }
47
- ]
48
- });
49
- exports.xmppSignedPreKey = xmppSignedPreKey;
50
- const xmppPreKey = (pair, id) => ({
51
- tag: 'key',
52
- attrs: {},
53
- content: [
54
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
55
- { tag: 'value', attrs: {}, content: pair.public }
56
- ]
57
- });
58
- exports.xmppPreKey = xmppPreKey;
59
- const parseAndInjectE2ESessions = async (node, repository) => {
60
- 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');
66
- for (const node of nodes) {
67
- (0, WABinary_1.assertNodeErrorFree)(node);
68
- }
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
- };
86
- exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
87
- 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
- }
109
- }
110
- }
111
- }
112
- }
113
- return extracted;
114
- };
115
- exports.extractDeviceJids = extractDeviceJids;
116
- /**
117
- * get the next N keys for upload or processing
118
- * @param count number of pre-keys to get or generate
119
- */
120
- const getNextPreKeys = async ({ creds, keys }, count) => {
121
- const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
122
- const update = {
123
- nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
124
- firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
125
- };
126
- await keys.set({ 'pre-key': newPreKeys });
127
- const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
128
- return { update, preKeys };
129
- };
130
- exports.getNextPreKeys = getNextPreKeys;
131
- const getNextPreKeysNode = async (state, count) => {
132
- const { creds } = state;
133
- const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
134
- const node = {
135
- tag: 'iq',
136
- attrs: {
137
- xmlns: 'encrypt',
138
- type: 'set',
139
- to: WABinary_1.S_WHATSAPP_NET,
140
- },
141
- content: [
142
- { tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
143
- { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
144
- { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
145
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
146
- (0, exports.xmppSignedPreKey)(creds.signedPreKey)
147
- ]
148
- };
149
- return { update, node };
150
- };
151
- exports.getNextPreKeysNode = getNextPreKeysNode;
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 generics_1 = require("./generics");
8
+ const createSignalIdentity = (wid, accountSignatureKey) => {
9
+ return {
10
+ identifier: { name: wid, deviceId: 0 },
11
+ identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
12
+ };
13
+ };
14
+ exports.createSignalIdentity = createSignalIdentity;
15
+ const getPreKeys = async ({ get }, min, limit) => {
16
+ const idList = [];
17
+ for (let id = min; id < limit; id++) {
18
+ idList.push(id.toString());
19
+ }
20
+ return get('pre-key', idList);
21
+ };
22
+ exports.getPreKeys = getPreKeys;
23
+ const generateOrGetPreKeys = (creds, range) => {
24
+ const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
25
+ const remaining = range - avaliable;
26
+ const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
27
+ const newPreKeys = {};
28
+ if (remaining > 0) {
29
+ for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
30
+ newPreKeys[i] = crypto_1.Curve.generateKeyPair();
31
+ }
32
+ }
33
+ return {
34
+ newPreKeys,
35
+ lastPreKeyId,
36
+ preKeysRange: [creds.firstUnuploadedPreKeyId, range],
37
+ };
38
+ };
39
+ exports.generateOrGetPreKeys = generateOrGetPreKeys;
40
+ const xmppSignedPreKey = (key) => ({
41
+ tag: 'skey',
42
+ attrs: {},
43
+ content: [
44
+ { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
45
+ { tag: 'value', attrs: {}, content: key.keyPair.public },
46
+ { tag: 'signature', attrs: {}, content: key.signature }
47
+ ]
48
+ });
49
+ exports.xmppSignedPreKey = xmppSignedPreKey;
50
+ const xmppPreKey = (pair, id) => ({
51
+ tag: 'key',
52
+ attrs: {},
53
+ content: [
54
+ { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
55
+ { tag: 'value', attrs: {}, content: pair.public }
56
+ ]
57
+ });
58
+ exports.xmppPreKey = xmppPreKey;
59
+ const parseAndInjectE2ESessions = async (node, repository) => {
60
+ 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');
66
+ for (const node of nodes) {
67
+ (0, WABinary_1.assertNodeErrorFree)(node);
68
+ }
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
+ };
86
+ exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
87
+ 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
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ return extracted;
114
+ };
115
+ exports.extractDeviceJids = extractDeviceJids;
116
+ /**
117
+ * get the next N keys for upload or processing
118
+ * @param count number of pre-keys to get or generate
119
+ */
120
+ const getNextPreKeys = async ({ creds, keys }, count) => {
121
+ const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
122
+ const update = {
123
+ nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
124
+ firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
125
+ };
126
+ await keys.set({ 'pre-key': newPreKeys });
127
+ const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
128
+ return { update, preKeys };
129
+ };
130
+ exports.getNextPreKeys = getNextPreKeys;
131
+ const getNextPreKeysNode = async (state, count) => {
132
+ const { creds } = state;
133
+ const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
134
+ const node = {
135
+ tag: 'iq',
136
+ attrs: {
137
+ xmlns: 'encrypt',
138
+ type: 'set',
139
+ to: WABinary_1.S_WHATSAPP_NET,
140
+ },
141
+ content: [
142
+ { tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
143
+ { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
144
+ { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
145
+ { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
146
+ (0, exports.xmppSignedPreKey)(creds.signedPreKey)
147
+ ]
148
+ };
149
+ return { update, node };
150
+ };
151
+ exports.getNextPreKeysNode = getNextPreKeysNode;
@@ -1,12 +1,12 @@
1
- import { AuthenticationState } from '../Types';
2
- /**
3
- * stores the full authentication state in a single folder.
4
- * Far more efficient than singlefileauthstate
5
- *
6
- * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
7
- * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
8
- * */
9
- export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
- state: AuthenticationState;
11
- saveCreds: () => Promise<void>;
12
- }>;
1
+ import { AuthenticationState } from '../Types';
2
+ /**
3
+ * stores the full authentication state in a single folder.
4
+ * Far more efficient than singlefileauthstate
5
+ *
6
+ * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
7
+ * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
8
+ * */
9
+ export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
+ state: AuthenticationState;
11
+ saveCreds: () => Promise<void>;
12
+ }>;
@@ -1,80 +1,80 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMultiFileAuthState = void 0;
4
- const promises_1 = require("fs/promises");
5
- const path_1 = require("path");
6
- const WAProto_1 = require("../../WAProto");
7
- const auth_utils_1 = require("./auth-utils");
8
- const generics_1 = require("./generics");
9
- /**
10
- * stores the full authentication state in a single folder.
11
- * Far more efficient than singlefileauthstate
12
- *
13
- * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
14
- * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
15
- * */
16
- 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));
19
- };
20
- const readData = async (file) => {
21
- 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);
24
- }
25
- catch (error) {
26
- return null;
27
- }
28
- };
29
- const removeData = async (file) => {
30
- try {
31
- await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
32
- }
33
- catch (_a) {
34
- }
35
- };
36
- const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
37
- if (folderInfo) {
38
- if (!folderInfo.isDirectory()) {
39
- throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
40
- }
41
- }
42
- else {
43
- await (0, promises_1.mkdir)(folder, { recursive: true });
44
- }
45
- 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, '-'); };
46
- const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
47
- return {
48
- state: {
49
- creds,
50
- keys: {
51
- get: async (type, ids) => {
52
- const data = {};
53
- await Promise.all(ids.map(async (id) => {
54
- let value = await readData(`${type}-${id}.json`);
55
- if (type === 'app-state-sync-key' && value) {
56
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
57
- }
58
- data[id] = value;
59
- }));
60
- return data;
61
- },
62
- set: async (data) => {
63
- const tasks = [];
64
- for (const category in data) {
65
- for (const id in data[category]) {
66
- const value = data[category][id];
67
- const file = `${category}-${id}.json`;
68
- tasks.push(value ? writeData(value, file) : removeData(file));
69
- }
70
- }
71
- await Promise.all(tasks);
72
- }
73
- }
74
- },
75
- saveCreds: () => {
76
- return writeData(creds, 'creds.json');
77
- }
78
- };
79
- };
80
- exports.useMultiFileAuthState = useMultiFileAuthState;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMultiFileAuthState = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const path_1 = require("path");
6
+ const WAProto_1 = require("../../WAProto");
7
+ const auth_utils_1 = require("./auth-utils");
8
+ const generics_1 = require("./generics");
9
+ /**
10
+ * stores the full authentication state in a single folder.
11
+ * Far more efficient than singlefileauthstate
12
+ *
13
+ * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
14
+ * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
15
+ * */
16
+ 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));
19
+ };
20
+ const readData = async (file) => {
21
+ 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);
24
+ }
25
+ catch (error) {
26
+ return null;
27
+ }
28
+ };
29
+ const removeData = async (file) => {
30
+ try {
31
+ await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
32
+ }
33
+ catch (_a) {
34
+ }
35
+ };
36
+ const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
37
+ if (folderInfo) {
38
+ if (!folderInfo.isDirectory()) {
39
+ throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
40
+ }
41
+ }
42
+ else {
43
+ await (0, promises_1.mkdir)(folder, { recursive: true });
44
+ }
45
+ 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, '-'); };
46
+ const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
47
+ return {
48
+ state: {
49
+ creds,
50
+ keys: {
51
+ get: async (type, ids) => {
52
+ const data = {};
53
+ await Promise.all(ids.map(async (id) => {
54
+ let value = await readData(`${type}-${id}.json`);
55
+ if (type === 'app-state-sync-key' && value) {
56
+ value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
57
+ }
58
+ data[id] = value;
59
+ }));
60
+ return data;
61
+ },
62
+ set: async (data) => {
63
+ const tasks = [];
64
+ for (const category in data) {
65
+ for (const id in data[category]) {
66
+ const value = data[category][id];
67
+ const file = `${category}-${id}.json`;
68
+ tasks.push(value ? writeData(value, file) : removeData(file));
69
+ }
70
+ }
71
+ await Promise.all(tasks);
72
+ }
73
+ }
74
+ },
75
+ saveCreds: () => {
76
+ return writeData(creds, 'creds.json');
77
+ }
78
+ };
79
+ };
80
+ exports.useMultiFileAuthState = useMultiFileAuthState;
@@ -1,11 +1,11 @@
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;
5
- export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
6
- export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
7
- export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
8
- creds: Partial<AuthenticationCreds>;
9
- reply: BinaryNode;
10
- };
11
- export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
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;
5
+ export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
6
+ export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
7
+ export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
8
+ creds: Partial<AuthenticationCreds>;
9
+ reply: BinaryNode;
10
+ };
11
+ export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;