vialeys 0.0.1 → 0.0.2

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 (102) hide show
  1. package/README.md +11 -5
  2. package/WAProto/AICommon/AICommon.js +13991 -9169
  3. package/WAProto/AICommon/AICommon.proto +110 -3
  4. package/WAProto/CompanionReg/CompanionReg.js +114 -0
  5. package/WAProto/CompanionReg/CompanionReg.proto +3 -0
  6. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +652 -0
  7. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +19 -0
  8. package/WAProto/E2E/E2E.js +77193 -51248
  9. package/WAProto/E2E/E2E.proto +68 -12
  10. package/WAProto/HistorySync/HistorySync.js +3375 -178
  11. package/WAProto/HistorySync/HistorySync.proto +3 -3
  12. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +98 -49
  13. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +2 -2
  14. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +75226 -48422
  15. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +6 -0
  16. package/WAProto/StatusAttributions/StatusAttributions.js +21 -0
  17. package/WAProto/StatusAttributions/StatusAttributions.proto +3 -0
  18. package/WAProto/SyncAction/SyncAction.js +9423 -2023
  19. package/WAProto/SyncAction/SyncAction.proto +208 -15
  20. package/WAProto/Wa6/Wa6.js +83 -0
  21. package/WAProto/Wa6/Wa6.proto +3 -0
  22. package/WAProto/Web/Web.js +92664 -63403
  23. package/WAProto/Web/Web.proto +31 -13
  24. package/engine-requirements.js +9 -7
  25. package/lib/Defaults/baileys-version.json +2 -2
  26. package/lib/Defaults/connection.js +51 -0
  27. package/lib/Defaults/constants.js +62 -0
  28. package/lib/Defaults/history.js +17 -0
  29. package/lib/Defaults/index.js +36 -142
  30. package/lib/Defaults/media.js +48 -0
  31. package/lib/Defaults/prefix.js +18 -0
  32. package/lib/Signal/Group/group-session-builder.js +10 -42
  33. package/lib/Signal/Group/group_cipher.js +9 -6
  34. package/lib/Signal/Group/index.js +39 -53
  35. package/lib/Signal/Group/keyhelper.js +8 -41
  36. package/lib/Signal/Group/sender-chain-key.js +4 -4
  37. package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
  38. package/lib/Signal/Group/sender-key-message.js +12 -8
  39. package/lib/Signal/Group/sender-key-state.js +4 -4
  40. package/lib/Signal/Group/sender-message-key.js +2 -2
  41. package/lib/Signal/libsignal.js +45 -69
  42. package/lib/Signal/lid-mapping.js +15 -11
  43. package/lib/Socket/Client/types.js +2 -2
  44. package/lib/Socket/Client/websocket.js +16 -14
  45. package/lib/Socket/business.js +41 -32
  46. package/lib/Socket/chats.js +123 -98
  47. package/lib/Socket/community.js +50 -40
  48. package/lib/Socket/groups.js +59 -47
  49. package/lib/Socket/index.js +4 -4
  50. package/lib/Socket/messages-recv.js +226 -171
  51. package/lib/Socket/messages-send.js +187 -143
  52. package/lib/Socket/newsletter.js +61 -47
  53. package/lib/Socket/socket.js +133 -90
  54. package/lib/Socket/usync.js +6 -6
  55. package/lib/Store/index.js +27 -11
  56. package/lib/Store/make-cache-manager-store.js +14 -15
  57. package/lib/Store/make-in-memory-store.js +28 -24
  58. package/lib/Types/LabelAssociation.js +2 -2
  59. package/lib/Types/Message.js +6 -6
  60. package/lib/Types/MexUpdates.js +5 -4
  61. package/lib/Types/State.js +4 -4
  62. package/lib/Types/index.js +28 -12
  63. package/lib/Utils/auth-utils.js +28 -26
  64. package/lib/Utils/baileys-event-stream.js +68 -69
  65. package/lib/Utils/business.js +63 -53
  66. package/lib/Utils/chat-utils.js +81 -71
  67. package/lib/Utils/crypto.js +25 -45
  68. package/lib/Utils/decode-wa-message.js +319 -311
  69. package/lib/Utils/event-buffer.js +21 -22
  70. package/lib/Utils/generics.js +103 -73
  71. package/lib/Utils/history.js +21 -21
  72. package/lib/Utils/index.js +27 -13
  73. package/lib/Utils/link-preview.js +7 -30
  74. package/lib/Utils/logger.js +5 -5
  75. package/lib/Utils/lt-hash.js +3 -3
  76. package/lib/Utils/message-retry-manager.js +4 -4
  77. package/lib/Utils/messages-media.js +104 -109
  78. package/lib/Utils/messages.js +203 -171
  79. package/lib/Utils/noise-handler.js +28 -19
  80. package/lib/Utils/process-message.js +370 -136
  81. package/lib/Utils/signal.js +36 -25
  82. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  83. package/lib/Utils/validate-connection.js +52 -45
  84. package/lib/WABinary/decode.js +6 -32
  85. package/lib/WABinary/encode.js +3 -29
  86. package/lib/WABinary/generic-utils.js +4 -4
  87. package/lib/WABinary/index.js +27 -11
  88. package/lib/WAM/encode.js +16 -8
  89. package/lib/WAM/index.js +27 -11
  90. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  91. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  92. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  93. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  94. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  95. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  96. package/lib/WAUSync/Protocols/index.js +27 -11
  97. package/lib/WAUSync/USyncQuery.js +17 -10
  98. package/lib/WAUSync/index.js +27 -11
  99. package/lib/index.js +62 -37
  100. package/package.json +1 -1
  101. package/WAProto/index.d.ts +0 -55
  102. package/lib/index.d.ts +0 -13
@@ -2,11 +2,20 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const boom_1 = require("@hapi/boom")
6
- const WAProto_1 = require("../../WAProto")
7
- const Defaults_1 = require("../Defaults")
8
- const WABinary_1 = require("../WABinary")
9
- const crypto_1 = require("./crypto")
5
+ const { Boom } = require("@hapi/boom")
6
+ const { proto } = require("../../WAProto")
7
+ const {
8
+ NOISE_MODE,
9
+ WA_CERT_DETAILS
10
+ } = require("../Defaults/constants")
11
+ const { decodeBinaryNode } = require("../WABinary")
12
+ const {
13
+ aesDecryptGCM,
14
+ aesEncryptGCM,
15
+ Curve,
16
+ hkdf,
17
+ sha256
18
+ } = require("./crypto")
10
19
 
11
20
  const generateIV = (counter) => {
12
21
  const iv = new ArrayBuffer(12)
@@ -18,11 +27,11 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
18
27
  logger = logger.child({ class: 'ns' })
19
28
  const authenticate = (data) => {
20
29
  if (!isFinished) {
21
- hash = crypto_1.sha256(Buffer.concat([hash, data]))
30
+ hash = sha256(Buffer.concat([hash, data]))
22
31
  }
23
32
  }
24
33
  const encrypt = (plaintext) => {
25
- const result = crypto_1.aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash)
34
+ const result = aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash)
26
35
  writeCounter += 1
27
36
  authenticate(result)
28
37
  return result
@@ -31,7 +40,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
31
40
  // before the handshake is finished, we use the same counter
32
41
  // after handshake, the counters are different
33
42
  const iv = generateIV(isFinished ? readCounter : writeCounter)
34
- const result = crypto_1.aesDecryptGCM(ciphertext, decKey, iv, hash)
43
+ const result = aesDecryptGCM(ciphertext, decKey, iv, hash)
35
44
  if (isFinished) {
36
45
  readCounter += 1
37
46
  }
@@ -42,7 +51,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
42
51
  return result
43
52
  }
44
53
  const localHKDF = async (data) => {
45
- const key = await crypto_1.hkdf(Buffer.from(data), 64, { salt, info: '' })
54
+ const key = await hkdf(Buffer.from(data), 64, { salt, info: '' })
46
55
  return [key.slice(0, 32), key.slice(32)]
47
56
  }
48
57
  const mixIntoKey = async (data) => {
@@ -62,8 +71,8 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
62
71
  writeCounter = 0
63
72
  isFinished = true
64
73
  }
65
- const data = Buffer.from(Defaults_1.NOISE_MODE)
66
- let hash = data.byteLength === 32 ? data : crypto_1.sha256(data)
74
+ const data = Buffer.from(NOISE_MODE)
75
+ let hash = data.byteLength === 32 ? data : sha256(data)
67
76
  let salt = hash
68
77
  let encKey = hash
69
78
  let decKey = hash
@@ -82,17 +91,17 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
82
91
  finishInit,
83
92
  processHandshake: async ({ serverHello }, noiseKey) => {
84
93
  authenticate(serverHello.ephemeral)
85
- await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral))
94
+ await mixIntoKey(Curve.sharedKey(privateKey, serverHello.ephemeral))
86
95
  const decStaticContent = decrypt(serverHello.static)
87
- await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent))
96
+ await mixIntoKey(Curve.sharedKey(privateKey, decStaticContent))
88
97
  const certDecoded = decrypt(serverHello.payload)
89
- const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded)
90
- const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details)
91
- if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
92
- throw new boom_1.Boom('certification match failed', { statusCode: 400 })
98
+ const { intermediate: certIntermediate } = proto.CertChain.decode(certDecoded)
99
+ const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details)
100
+ if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
101
+ throw new Boom('certification match failed', { statusCode: 400 })
93
102
  }
94
103
  const keyEnc = encrypt(noiseKey.public)
95
- await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral))
104
+ await mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello.ephemeral))
96
105
  return keyEnc
97
106
  },
98
107
  encodeFrame: (data) => {
@@ -140,7 +149,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
140
149
  inBytes = inBytes.slice(size + 3)
141
150
  if (isFinished) {
142
151
  const result = decrypt(frame)
143
- frame = await WABinary_1.decodeBinaryNode(result)
152
+ frame = await decodeBinaryNode(result)
144
153
  }
145
154
  logger.trace({ msg: frame?.attrs?.id }, 'recv frame')
146
155
  onFrame(frame)