sanka-baileyss 2.3.2 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
  2. package/WAProto/BotMetadata/BotMetadata.js +1910 -148
  3. package/WAProto/BotMetadata/BotMetadata.proto +36 -0
  4. package/WAProto/E2E/E2E.d.ts +570 -6
  5. package/WAProto/E2E/E2E.js +1591 -26
  6. package/WAProto/E2E/E2E.proto +10 -1
  7. package/WAProto/HistorySync/HistorySync.d.ts +806 -6
  8. package/WAProto/HistorySync/HistorySync.js +2193 -29
  9. package/WAProto/HistorySync/HistorySync.proto +2 -1
  10. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
  11. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
  12. package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
  13. package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
  14. package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
  15. package/WAProto/SyncAction/SyncAction.d.ts +230 -0
  16. package/WAProto/SyncAction/SyncAction.js +578 -2
  17. package/WAProto/SyncAction/SyncAction.proto +13 -1
  18. package/WAProto/Web/Web.d.ts +570 -6
  19. package/WAProto/Web/Web.js +1591 -26
  20. package/lib/Defaults/baileys-version.json +2 -2
  21. package/lib/Defaults/index.d.ts +42 -25
  22. package/lib/Defaults/index.js +6 -2
  23. package/lib/Signal/Group/sender-key-record.js +23 -28
  24. package/lib/Signal/libsignal.d.ts +1 -0
  25. package/lib/Socket/Client/index.js +13 -9
  26. package/lib/Socket/Client/types.d.ts +11 -10
  27. package/lib/Socket/Client/types.js +11 -7
  28. package/lib/Socket/Client/websocket.d.ts +9 -8
  29. package/lib/Socket/Client/websocket.js +52 -47
  30. package/lib/Socket/business.d.ts +185 -182
  31. package/lib/Socket/business.js +258 -249
  32. package/lib/Socket/chats.d.ts +90 -87
  33. package/lib/Socket/chats.js +1095 -888
  34. package/lib/Socket/community.d.ts +131 -0
  35. package/lib/Socket/community.js +369 -0
  36. package/lib/Socket/groups.d.ts +50 -41
  37. package/lib/Socket/groups.js +10 -3
  38. package/lib/Socket/index.d.ts +5 -1
  39. package/lib/Socket/index.js +19 -5
  40. package/lib/Socket/messages-recv.d.ts +6 -2
  41. package/lib/Socket/messages-recv.js +31 -8
  42. package/lib/Socket/messages-send.d.ts +5 -1
  43. package/lib/Socket/messages-send.js +1293 -1351
  44. package/lib/Socket/newsletter.d.ts +142 -135
  45. package/lib/Socket/newsletter.js +274 -230
  46. package/lib/Socket/socket.d.ts +37 -35
  47. package/lib/Socket/usync.d.ts +31 -30
  48. package/lib/Socket/usync.js +74 -62
  49. package/lib/Types/Auth.d.ts +89 -72
  50. package/lib/Types/Auth.js +1 -0
  51. package/lib/Types/Call.d.ts +11 -10
  52. package/lib/Types/Call.js +1 -0
  53. package/lib/Types/Chat.d.ts +85 -62
  54. package/lib/Types/Chat.js +4 -1
  55. package/lib/Types/Contact.js +1 -0
  56. package/lib/Types/Events.d.ts +209 -191
  57. package/lib/Types/Events.js +1 -0
  58. package/lib/Types/GroupMetadata.d.ts +12 -27
  59. package/lib/Types/GroupMetadata.js +1 -0
  60. package/lib/Types/Label.d.ts +41 -39
  61. package/lib/Types/Label.js +24 -21
  62. package/lib/Types/LabelAssociation.d.ts +18 -12
  63. package/lib/Types/LabelAssociation.js +6 -3
  64. package/lib/Types/Message.d.ts +3 -2
  65. package/lib/Types/Message.js +7 -3
  66. package/lib/Types/MexUpdates.d.ts +9 -0
  67. package/lib/Types/MexUpdates.js +18 -0
  68. package/lib/Types/Newsletter.d.ts +84 -67
  69. package/lib/Types/Newsletter.js +30 -23
  70. package/lib/Types/Product.d.ts +70 -56
  71. package/lib/Types/Product.js +1 -0
  72. package/lib/Types/Signal.d.ts +46 -35
  73. package/lib/Types/Signal.js +1 -0
  74. package/lib/Types/Socket.d.ts +105 -101
  75. package/lib/Types/Socket.js +1 -0
  76. package/lib/Types/State.d.ts +37 -23
  77. package/lib/Types/State.js +13 -1
  78. package/lib/Types/USync.d.ts +21 -20
  79. package/lib/Types/USync.js +1 -0
  80. package/lib/Types/index.d.ts +51 -42
  81. package/lib/Types/index.js +25 -19
  82. package/lib/Utils/auth-utils.d.ts +14 -11
  83. package/lib/Utils/auth-utils.js +189 -182
  84. package/lib/Utils/baileys-event-stream.d.ts +12 -10
  85. package/lib/Utils/baileys-event-stream.js +52 -46
  86. package/lib/Utils/business.d.ts +15 -8
  87. package/lib/Utils/business.js +229 -217
  88. package/lib/Utils/chat-utils.d.ts +22 -12
  89. package/lib/Utils/chat-utils.js +57 -27
  90. package/lib/Utils/crypto.d.ts +31 -15
  91. package/lib/Utils/crypto.js +136 -107
  92. package/lib/Utils/decode-wa-message.d.ts +34 -245
  93. package/lib/Utils/decode-wa-message.js +205 -217
  94. package/lib/Utils/event-buffer.d.ts +30 -26
  95. package/lib/Utils/event-buffer.js +519 -515
  96. package/lib/Utils/history.d.ts +2 -8
  97. package/lib/Utils/index.js +13 -9
  98. package/lib/Utils/link-preview.d.ts +16 -14
  99. package/lib/Utils/link-preview.js +100 -92
  100. package/lib/Utils/logger.d.ts +9 -7
  101. package/lib/Utils/logger.js +1 -1
  102. package/lib/Utils/lt-hash.d.ts +10 -8
  103. package/lib/Utils/lt-hash.js +49 -44
  104. package/lib/Utils/make-mutex.d.ts +4 -2
  105. package/lib/Utils/make-mutex.js +43 -39
  106. package/lib/Utils/messages-media.d.ts +75 -50
  107. package/lib/Utils/messages.d.ts +60 -35
  108. package/lib/Utils/messages.js +87 -8
  109. package/lib/Utils/noise-handler.d.ts +13 -12
  110. package/lib/Utils/noise-handler.js +143 -138
  111. package/lib/Utils/process-message.d.ts +32 -24
  112. package/lib/Utils/process-message.js +387 -367
  113. package/lib/Utils/signal.d.ts +24 -15
  114. package/lib/Utils/signal.js +143 -131
  115. package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
  116. package/lib/Utils/use-mongo-file-auth-state.js +72 -63
  117. package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
  118. package/lib/Utils/use-multi-file-auth-state.js +110 -102
  119. package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
  120. package/lib/Utils/use-single-file-auth-state.js +66 -61
  121. package/lib/Utils/validate-connection.d.ts +5 -2
  122. package/lib/Utils/validate-connection.js +7 -6
  123. package/lib/WABinary/constants.d.ts +24 -21
  124. package/lib/WABinary/constants.js +1302 -31
  125. package/lib/WABinary/decode.d.ts +4 -1
  126. package/lib/WABinary/decode.js +267 -234
  127. package/lib/WABinary/encode.d.ts +1 -0
  128. package/lib/WABinary/encode.js +248 -226
  129. package/lib/WABinary/generic-utils.d.ts +13 -1
  130. package/lib/WABinary/generic-utils.js +113 -96
  131. package/lib/WABinary/index.js +13 -9
  132. package/lib/WABinary/jid-utils.d.ts +23 -4
  133. package/lib/WABinary/jid-utils.js +58 -39
  134. package/lib/WABinary/types.d.ts +15 -11
  135. package/lib/WABinary/types.js +1 -0
  136. package/lib/WAM/BinaryInfo.d.ts +14 -14
  137. package/lib/WAM/BinaryInfo.js +11 -8
  138. package/lib/WAM/constants.d.ts +34 -26
  139. package/lib/WAM/constants.js +15358 -15349
  140. package/lib/WAM/encode.d.ts +1 -0
  141. package/lib/WAM/encode.js +153 -144
  142. package/lib/WAM/index.js +13 -9
  143. package/lib/index.js +11 -11
  144. package/package.json +1 -66
  145. package/WASignalGroup/GroupProtocol.js +0 -1771
  146. package/WASignalGroup/ciphertext_message.js +0 -10
  147. package/WASignalGroup/group_cipher.js +0 -103
  148. package/WASignalGroup/group_session_builder.js +0 -39
  149. package/WASignalGroup/index.js +0 -5
  150. package/WASignalGroup/keyhelper.js +0 -17
  151. package/WASignalGroup/protobufs.js +0 -2
  152. package/WASignalGroup/queue_job.js +0 -64
  153. package/WASignalGroup/sender_chain_key.js +0 -38
  154. package/WASignalGroup/sender_key_distribution_message.js +0 -68
  155. package/WASignalGroup/sender_key_message.js +0 -79
  156. package/WASignalGroup/sender_key_name.js +0 -59
  157. package/WASignalGroup/sender_key_record.js +0 -47
  158. package/WASignalGroup/sender_key_state.js +0 -110
  159. package/WASignalGroup/sender_message_key.js +0 -30
@@ -2,32 +2,41 @@ import { SignalRepository } from '../Types'
2
2
  import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth'
3
3
  import { BinaryNode, JidWithDevice } from '../WABinary'
4
4
  import { USyncQueryResultList } from '../WAUSync'
5
+
5
6
  export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity
7
+
6
8
  export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
7
- [id: string]: KeyPair
9
+ [id: string]: KeyPair
8
10
  }>
11
+
9
12
  export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
10
- newPreKeys: {
11
- [id: number]: KeyPair
12
- }
13
- lastPreKeyId: number
14
- preKeysRange: readonly [number, number]
13
+ newPreKeys: {
14
+ [id: number]: KeyPair
15
+ }
16
+ lastPreKeyId: number
17
+ preKeysRange: readonly [number, number]
15
18
  }
19
+
16
20
  export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode
21
+
17
22
  export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode
23
+
18
24
  export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>
25
+
19
26
  export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[]
27
+
20
28
  /**
21
- * get the next N keys for upload or processing
22
- * @param count number of pre-keys to get or generate
23
- */
29
+ * get the next N keys for upload or processing
30
+ * @param count number of pre-keys to get or generate
31
+ */
24
32
  export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
25
- update: Partial<AuthenticationCreds>
26
- preKeys: {
27
- [id: string]: KeyPair
28
- }
33
+ update: Partial<AuthenticationCreds>
34
+ preKeys: {
35
+ [id: string]: KeyPair
36
+ }
29
37
  }>
38
+
30
39
  export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
31
- update: Partial<AuthenticationCreds>
32
- node: BinaryNode
40
+ update: Partial<AuthenticationCreds>
41
+ node: BinaryNode
33
42
  }>
@@ -1,154 +1,166 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  const lodash_1 = require("lodash")
4
6
  const Defaults_1 = require("../Defaults")
5
7
  const WABinary_1 = require("../WABinary")
6
8
  const crypto_1 = require("./crypto")
7
9
  const generics_1 = require("./generics")
10
+
8
11
  const createSignalIdentity = (wid, accountSignatureKey) => {
9
- return {
10
- identifier: { name: wid, deviceId: 0 },
11
- identifierKey: crypto_1.generateSignalPubKey(accountSignatureKey)
12
- }
12
+ return {
13
+ identifier: { name: wid, deviceId: 0 },
14
+ identifierKey: crypto_1.generateSignalPubKey(accountSignatureKey)
15
+ }
13
16
  }
17
+
14
18
  const getPreKeys = async ({ get }, min, limit) => {
15
- const idList = []
16
- for (let id = min; id < limit; id++) {
17
- idList.push(id.toString())
18
- }
19
- return get('pre-key', idList)
19
+ const idList = []
20
+ for (let id = min; id < limit; id++) {
21
+ idList.push(id.toString())
22
+ }
23
+ return get('pre-key', idList)
20
24
  }
25
+
21
26
  const generateOrGetPreKeys = (creds, range) => {
22
- const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId
23
- const remaining = range - avaliable
24
- const lastPreKeyId = creds.nextPreKeyId + remaining - 1
25
- const newPreKeys = {}
26
- if (remaining > 0) {
27
- for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
28
- newPreKeys[i] = crypto_1.Curve.generateKeyPair()
29
- }
30
- }
31
- return {
32
- newPreKeys,
33
- lastPreKeyId,
34
- preKeysRange: [creds.firstUnuploadedPreKeyId, range],
35
- }
36
- }
27
+ const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId
28
+ const remaining = range - avaliable
29
+ const lastPreKeyId = creds.nextPreKeyId + remaining - 1
30
+ const newPreKeys = {}
31
+ if (remaining > 0) {
32
+ for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
33
+ newPreKeys[i] = crypto_1.Curve.generateKeyPair()
34
+ }
35
+ }
36
+ return {
37
+ newPreKeys,
38
+ lastPreKeyId,
39
+ preKeysRange: [creds.firstUnuploadedPreKeyId, range],
40
+ }
41
+ }
42
+
37
43
  const xmppSignedPreKey = (key) => ({
38
- tag: 'skey',
39
- attrs: {},
40
- content: [
41
- { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(key.keyId, 3) },
42
- { tag: 'value', attrs: {}, content: key.keyPair.public },
43
- { tag: 'signature', attrs: {}, content: key.signature }
44
- ]
44
+ tag: 'skey',
45
+ attrs: {},
46
+ content: [
47
+ { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(key.keyId, 3) },
48
+ { tag: 'value', attrs: {}, content: key.keyPair.public },
49
+ { tag: 'signature', attrs: {}, content: key.signature }
50
+ ]
45
51
  })
52
+
46
53
  const xmppPreKey = (pair, id) => ({
47
- tag: 'key',
48
- attrs: {},
49
- content: [
50
- { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(id, 3) },
51
- { tag: 'value', attrs: {}, content: pair.public }
52
- ]
54
+ tag: 'key',
55
+ attrs: {},
56
+ content: [
57
+ { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(id, 3) },
58
+ { tag: 'value', attrs: {}, content: pair.public }
59
+ ]
53
60
  })
61
+
54
62
  const parseAndInjectE2ESessions = async (node, repository) => {
55
- const extractKey = (key) => (key ? ({
56
- keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
57
- publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
58
- signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
59
- }) : undefined)
60
- const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
61
- for (const node of nodes) {
62
- WABinary_1.assertNodeErrorFree(node)
63
- }
64
- // Most of the work in repository.injectE2ESession is CPU intensive, not IO
65
- // So Promise.all doesn't really help here,
66
- // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
67
- // This way we chunk it in smaller parts and between those parts we can yield to the event loop
68
- // It's rare case when you need to E2E sessions for so many users, but it's possible
69
- const chunkSize = 100
70
- const chunks = lodash_1.chunk(nodes, chunkSize)
71
- for (const nodesChunk of chunks) {
72
- await Promise.all(nodesChunk.map(async (node) => {
73
- const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
74
- const key = WABinary_1.getBinaryNodeChild(node, 'key')
75
- const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
76
- const jid = node.attrs.jid
77
- const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
78
- await repository.injectE2ESession({
79
- jid,
80
- session: {
81
- registrationId: registrationId,
82
- identityKey: crypto_1.generateSignalPubKey(identity),
83
- signedPreKey: extractKey(signedKey),
84
- preKey: extractKey(key)
85
- }
86
- })
87
- }))
88
- }
89
- }
63
+ const extractKey = (key) => (key ? ({
64
+ keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
65
+ publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
66
+ signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
67
+ }) : undefined)
68
+ const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
69
+ for (const node of nodes) {
70
+ WABinary_1.assertNodeErrorFree(node)
71
+ }
72
+ // Most of the work in repository.injectE2ESession is CPU intensive, not IO
73
+ // So Promise.all doesn't really help here,
74
+ // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
75
+ // This way we chunk it in smaller parts and between those parts we can yield to the event loop
76
+ // It's rare case when you need to E2E sessions for so many users, but it's possible
77
+ const chunkSize = 100
78
+ const chunks = lodash_1.chunk(nodes, chunkSize)
79
+ for (const nodesChunk of chunks) {
80
+ await Promise.all(nodesChunk.map(async (node) => {
81
+ const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
82
+ const key = WABinary_1.getBinaryNodeChild(node, 'key')
83
+ const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
84
+ const jid = node.attrs.jid
85
+ const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
86
+ await repository.injectE2ESession({
87
+ jid,
88
+ session: {
89
+ registrationId: registrationId,
90
+ identityKey: crypto_1.generateSignalPubKey(identity),
91
+ signedPreKey: extractKey(signedKey),
92
+ preKey: extractKey(key)
93
+ }
94
+ })
95
+ }))
96
+ }
97
+ }
98
+
90
99
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
91
- const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
92
- const extracted = []
93
- for (const userResult of result) {
94
- const { devices, id } = userResult
95
- const { user } = WABinary_1.jidDecode(id)
96
- const deviceList = devices?.deviceList
97
- if (Array.isArray(deviceList)) {
98
- for (const { id: device, keyIndex } of deviceList) {
99
- if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
100
- (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
101
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
102
- ) {
103
- extracted.push({ user, device })
104
- }
105
- }
106
- }
107
- }
108
- return extracted
109
- }
100
+ const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
101
+ const extracted = []
102
+ for (const userResult of result) {
103
+ const { devices, id } = userResult
104
+ const { user } = WABinary_1.jidDecode(id)
105
+ const deviceList = devices?.deviceList
106
+ if (Array.isArray(deviceList)) {
107
+ for (const { id: device, keyIndex } of deviceList) {
108
+ if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
109
+ (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
110
+ (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
111
+ ) {
112
+ extracted.push({ user, device })
113
+ }
114
+ }
115
+ }
116
+ }
117
+ return extracted
118
+ }
119
+
110
120
  /**
111
- * get the next N keys for upload or processing
112
- * @param count number of pre-keys to get or generate
113
- */
121
+ * get the next N keys for upload or processing
122
+ * @param count number of pre-keys to get or generate
123
+ */
114
124
  const getNextPreKeys = async ({ creds, keys }, count) => {
115
- const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count)
116
- const update = {
117
- nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
118
- firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
119
- }
120
- await keys.set({ 'pre-key': newPreKeys })
121
- const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1])
122
- return { update, preKeys }
123
- }
125
+ const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count)
126
+ const update = {
127
+ nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
128
+ firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
129
+ }
130
+ await keys.set({ 'pre-key': newPreKeys })
131
+ const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1])
132
+ return { update, preKeys }
133
+ }
134
+
124
135
  const getNextPreKeysNode = async (state, count) => {
125
- const { creds } = state
126
- const { update, preKeys } = await getNextPreKeys(state, count)
127
- const node = {
128
- tag: 'iq',
129
- attrs: {
130
- xmlns: 'encrypt',
131
- type: 'set',
132
- to: WABinary_1.S_WHATSAPP_NET,
133
- },
134
- content: [
135
- { tag: 'registration', attrs: {}, content: generics_1.encodeBigEndian(creds.registrationId) },
136
- { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
137
- { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
138
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
139
- xmppSignedPreKey(creds.signedPreKey)
140
- ]
141
- }
142
- return { update, node }
143
- }
136
+ const { creds } = state
137
+ const { update, preKeys } = await getNextPreKeys(state, count)
138
+ const node = {
139
+ tag: 'iq',
140
+ attrs: {
141
+ xmlns: 'encrypt',
142
+ type: 'set',
143
+ to: WABinary_1.S_WHATSAPP_NET,
144
+ },
145
+ content: [
146
+ { tag: 'registration', attrs: {}, content: generics_1.encodeBigEndian(creds.registrationId) },
147
+ { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
148
+ { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
149
+ { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
150
+ xmppSignedPreKey(creds.signedPreKey)
151
+ ]
152
+ }
153
+ return { update, node }
154
+ }
155
+
144
156
  module.exports = {
145
- createSignalIdentity,
146
- getPreKeys,
147
- generateOrGetPreKeys,
148
- xmppSignedPreKey,
149
- xmppPreKey,
150
- parseAndInjectE2ESessions,
151
- extractDeviceJids,
152
- getNextPreKeys,
153
- getNextPreKeysNode
157
+ createSignalIdentity,
158
+ getPreKeys,
159
+ generateOrGetPreKeys,
160
+ xmppSignedPreKey,
161
+ xmppPreKey,
162
+ parseAndInjectE2ESessions,
163
+ extractDeviceJids,
164
+ getNextPreKeys,
165
+ getNextPreKeysNode
154
166
  }
@@ -1,5 +1,6 @@
1
1
  import { AuthenticationState } from '../Types'
2
+
2
3
  export declare const useMongoFileAuthState: (collection: string) => Promise<{
3
- state: AuthenticationState
4
- saveCreds: () => Promise<void>
4
+ state: AuthenticationState
5
+ saveCreds: () => Promise<void>
5
6
  }>
@@ -1,75 +1,84 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  const WAProto_1 = require("../../WAProto")
4
6
  const auth_utils_1 = require("./auth-utils")
5
7
  const generics_1 = require("./generics")
8
+
6
9
  /*
7
10
  code from amiruldev readjusted by @irull2nd, don't delete WM!
8
11
  */
9
12
  const useMongoFileAuthState = async (collection) => {
10
- const writeData = (data,id) => {
11
- const informationToStore = JSON.parse(
12
- JSON.stringify(data, generics_1.BufferJSON.replacer)
13
- )
14
- const update = {
15
- $set: {
16
- ...informationToStore,
17
- },
18
- }
19
- return collection.updateOne({_id: id},update, {upsert: true})
20
- }
21
- const readData = async (id) => {
22
- try {
23
- const data = JSON.stringify(await collection.findOne({_id: id}))
24
- return JSON.parse(data, generics_1.BufferJSON.reviver)
25
- } catch (err) {
26
- console.log(err)
27
- }
28
- }
29
- const removeData = async (id) => {
30
- try{
31
- await collection.deleteOne({_id: id})
32
- }catch(err){
33
- console.log('error',err)
34
- }
35
- }
36
- const creds = (await readData('creds')) || auth_utils_1.initAuthCreds()
37
- return{
38
- state:{
39
- creds,
40
- keys: {
41
- get: async (type,ids)=> {
42
- const data = {}
43
- await Promise
44
- .all(
45
- ids.map(async (id) => {
46
- let value = await readData(`${type}-${id}`)
47
- if(type === "app-state-sync-key"){
48
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(data)
49
- }
50
- data[id] = value
51
- })
52
- )
53
- return data
54
- },
55
- set: async (data) => {
56
- const tasks = []
57
- for (const category of Object.keys(data)){
58
- for (const id of Object.keys(data[category])){
59
- const value = data[category][id]
60
- const key = `${category}-${id}`
61
- tasks.push(value? writeData(value,key) : removeData(key))
62
- }
63
- }
64
- await Promise.all(tasks)
65
- },
66
- },
67
- },
68
- saveCreds: () => {
69
- return writeData(creds, "creds")
70
- }
71
- }
13
+ const writeData = (data,id) => {
14
+ const informationToStore = JSON.parse(
15
+ JSON.stringify(data, generics_1.BufferJSON.replacer)
16
+ )
17
+ const update = {
18
+ $set: {
19
+ ...informationToStore,
20
+ },
21
+ }
22
+
23
+ return collection.updateOne({_id: id},update, {upsert: true})
24
+ }
25
+
26
+ const readData = async (id) => {
27
+ try {
28
+ const data = JSON.stringify(await collection.findOne({_id: id}))
29
+ return JSON.parse(data, generics_1.BufferJSON.reviver)
30
+ } catch (err) {
31
+ console.log(err)
32
+ }
33
+ }
34
+
35
+ const removeData = async (id) => {
36
+ try{
37
+ await collection.deleteOne({_id: id})
38
+ }catch(err){
39
+ console.log('error',err)
40
+ }
41
+ }
42
+
43
+ const creds = (await readData('creds')) || auth_utils_1.initAuthCreds()
44
+
45
+ return{
46
+ state:{
47
+ creds,
48
+ keys: {
49
+ get: async (type,ids)=> {
50
+ const data = {}
51
+ await Promise
52
+ .all(
53
+ ids.map(async (id) => {
54
+ let value = await readData(`${type}-${id}`)
55
+ if(type === "app-state-sync-key"){
56
+ value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(data)
57
+ }
58
+ data[id] = value
59
+ })
60
+ )
61
+ return data
62
+ },
63
+ set: async (data) => {
64
+ const tasks = []
65
+ for (const category of Object.keys(data)){
66
+ for (const id of Object.keys(data[category])){
67
+ const value = data[category][id]
68
+ const key = `${category}-${id}`
69
+ tasks.push(value? writeData(value,key) : removeData(key))
70
+ }
71
+ }
72
+ await Promise.all(tasks)
73
+ },
74
+ },
75
+ },
76
+ saveCreds: () => {
77
+ return writeData(creds, "creds")
78
+ }
79
+ }
72
80
  }
81
+
73
82
  module.exports = {
74
- useMongoFileAuthState
83
+ useMongoFileAuthState
75
84
  }
@@ -1,12 +1,13 @@
1
1
  import { AuthenticationState } from '../Types'
2
+
2
3
  /**
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
- * */
4
+ * stores the full authentication state in a single folder.
5
+ * Far more efficient than singlefileauthstate
6
+ *
7
+ * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
8
+ * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
9
+ * */
9
10
  export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
- state: AuthenticationState
11
- saveCreds: () => Promise<void>
11
+ state: AuthenticationState
12
+ saveCreds: () => Promise<void>
12
13
  }>