@itznomo/baileys 0.0.0-stage → 0.0.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 (124) hide show
  1. package/BUTTONS.md +153 -0
  2. package/Example/call-bot.mjs +38 -0
  3. package/Example/example.mjs +36 -0
  4. package/Example/full-bot-commands.mjs +319 -0
  5. package/Example/full-bot.mjs +77 -0
  6. package/LICENSE +21 -0
  7. package/README.md +543 -2
  8. package/WAProto/@dnuzi +1 -0
  9. package/WAProto/index.d.ts +15932 -0
  10. package/WAProto/index.js +113300 -0
  11. package/assets/banner.svg +17 -0
  12. package/assets/devider.svg +1 -0
  13. package/assets/features.svg +21 -0
  14. package/docs/CALLS.md +106 -0
  15. package/docs/FEATURES.md +1152 -0
  16. package/engine-requirements.js +19 -0
  17. package/index.d.ts +815 -0
  18. package/package.json +51 -4
  19. package/src/binary/wa-binary-constants.js +1300 -0
  20. package/src/binary/wa-binary.js +627 -0
  21. package/src/constants.js +147 -0
  22. package/src/defaults.js +106 -0
  23. package/src/foundation/ai-rich.js +654 -0
  24. package/src/foundation/audio-duration.js +470 -0
  25. package/src/foundation/audio-samples.js +250 -0
  26. package/src/foundation/boom.js +39 -0
  27. package/src/foundation/builders.js +851 -0
  28. package/src/foundation/cache.js +134 -0
  29. package/src/foundation/concurrency.js +69 -0
  30. package/src/foundation/curve25519.js +189 -0
  31. package/src/foundation/image-thumb.js +65 -0
  32. package/src/foundation/link-preview.js +278 -0
  33. package/src/foundation/logger.js +78 -0
  34. package/src/foundation/long.js +130 -0
  35. package/src/foundation/performance.js +385 -0
  36. package/src/foundation/protobuf-minimal.js +587 -0
  37. package/src/foundation/qrcode-terminal.js +273 -0
  38. package/src/foundation/sql-database.js +716 -0
  39. package/src/foundation/wa-crypto.js +47 -0
  40. package/src/foundation/zip.js +108 -0
  41. package/src/index.js +67 -0
  42. package/src/signal/libsignal.js +996 -0
  43. package/src/signal/signal-group.js +455 -0
  44. package/src/signal/signal-repository.js +635 -0
  45. package/src/socket/business-communities.js +811 -0
  46. package/src/socket/chats.js +702 -0
  47. package/src/socket/groups-newsletter.js +524 -0
  48. package/src/socket/messages-recv.js +1815 -0
  49. package/src/socket/messages-send.js +1526 -0
  50. package/src/socket/socket-builder.js +131 -0
  51. package/src/socket/socket-core.js +913 -0
  52. package/src/socket/usync.js +287 -0
  53. package/src/socket-client/native-websocket.js +344 -0
  54. package/src/socket-client/websocket-client.js +170 -0
  55. package/src/utils/auth-state-core.js +731 -0
  56. package/src/utils/auth-state-storage.js +594 -0
  57. package/src/utils/chat-sync.js +1046 -0
  58. package/src/utils/check-status.js +159 -0
  59. package/src/utils/cstoken.js +17 -0
  60. package/src/utils/media.js +807 -0
  61. package/src/utils/message-compose.js +1747 -0
  62. package/src/utils/message-processing.js +912 -0
  63. package/src/utils/modern-messages.js +435 -0
  64. package/src/utils/nomo-buttons.js +138 -0
  65. package/src/utils/nomo-commands.js +168 -0
  66. package/src/utils/spam-report-utils.js +136 -0
  67. package/src/utils/use-keyv-auth-state.js +307 -0
  68. package/src/utils/username.js +19 -0
  69. package/src/utils/wa-protocol-core.js +1227 -0
  70. package/src/voip/WaVoipCoordinator.js +158 -0
  71. package/src/voip/app-data/WaAppDataStream.js +193 -0
  72. package/src/voip/app-data/protocol.js +172 -0
  73. package/src/voip/auto.js +139 -0
  74. package/src/voip/bytes.js +63 -0
  75. package/src/voip/call/WaCallManager.js +442 -0
  76. package/src/voip/call/WaCallMediaSession.js +1727 -0
  77. package/src/voip/call/call-state.js +203 -0
  78. package/src/voip/crypto/encryption.js +13 -0
  79. package/src/voip/crypto/primitives.js +21 -0
  80. package/src/voip/crypto/rtcp.js +66 -0
  81. package/src/voip/crypto/srtp.js +180 -0
  82. package/src/voip/crypto/ssrc.js +15 -0
  83. package/src/voip/index.js +730 -0
  84. package/src/voip/media/WaAudioEngine.js +486 -0
  85. package/src/voip/media/WaVideoEngine.js +275 -0
  86. package/src/voip/media/audio-codec.js +0 -0
  87. package/src/voip/media/audio-reorder.js +107 -0
  88. package/src/voip/media/h264.js +246 -0
  89. package/src/voip/media/mlow-codec.js +465 -0
  90. package/src/voip/media/rtcp.js +68 -0
  91. package/src/voip/media/rtp.js +242 -0
  92. package/src/voip/protobuf.js +30 -0
  93. package/src/voip/relay/WaManualRelay.js +609 -0
  94. package/src/voip/relay/datachannel/pre-negotiated.js +25 -0
  95. package/src/voip/relay/dtls/aead.js +46 -0
  96. package/src/voip/relay/dtls/cert-builder.js +102 -0
  97. package/src/voip/relay/dtls/der.js +98 -0
  98. package/src/voip/relay/dtls/ecdhe.js +37 -0
  99. package/src/voip/relay/dtls/handshake-framing.js +100 -0
  100. package/src/voip/relay/dtls/handshake-messages.js +158 -0
  101. package/src/voip/relay/dtls/handshake.js +582 -0
  102. package/src/voip/relay/dtls/prf.js +39 -0
  103. package/src/voip/relay/dtls/record.js +56 -0
  104. package/src/voip/relay/relay-ack.js +141 -0
  105. package/src/voip/relay/sctp/association.js +434 -0
  106. package/src/voip/relay/sctp/crc32c.js +21 -0
  107. package/src/voip/relay/sctp/wire.js +226 -0
  108. package/src/voip/relay/stun.js +463 -0
  109. package/src/voip/shim/baileys-resolve.js +7 -0
  110. package/src/voip/shim/core.js +66 -0
  111. package/src/voip/shim/crypto.js +6 -0
  112. package/src/voip/shim/proto.js +10 -0
  113. package/src/voip/shim/protocol.js +130 -0
  114. package/src/voip/shim/transport.js +82 -0
  115. package/src/voip/shim/util.js +207 -0
  116. package/src/voip/signaling/bridge.js +102 -0
  117. package/src/voip/signaling/screen-share.js +60 -0
  118. package/src/voip/signaling/signaling.js +491 -0
  119. package/src/voip/types.js +69 -0
  120. package/src/voip/voip-deps.js +243 -0
  121. package/src/voip/voipClient.js +314 -0
  122. package/src/wam/wam-constants.js +22852 -0
  123. package/src/wam/wam.js +146 -0
  124. package/voip.d.ts +144 -0
@@ -0,0 +1,47 @@
1
+ import { createHash, hkdfSync } from 'node:crypto'
2
+
3
+ const u8 = b => new Uint8Array(b.buffer, b.byteOffset, b.byteLength)
4
+
5
+ export const md5 = buffer => u8(createHash('md5').update(buffer).digest())
6
+
7
+ export const hkdf = (buffer, expandedLength, { salt, info } = {}) => {
8
+ if (expandedLength > 255 * 32) throw new Error('HKDF expansion failed')
9
+ if (expandedLength === 0) return new Uint8Array(0)
10
+ return u8(Buffer.from(hkdfSync('sha256', buffer, salt ?? Buffer.alloc(0), Buffer.from(info ?? '', 'utf8'), expandedLength)))
11
+ }
12
+
13
+ export const expandAppStateKeys = keyData => {
14
+ const expanded = hkdf(keyData, 160, { info: 'WhatsApp Mutation Keys' })
15
+ const part = i => expanded.slice(i * 32, i * 32 + 32)
16
+ return {
17
+ indexKey: part(0),
18
+ valueEncryptionKey: part(1),
19
+ valueMacKey: part(2),
20
+ snapshotMacKey: part(3),
21
+ patchMacKey: part(4)
22
+ }
23
+ }
24
+
25
+ export class LTHashAntiTampering {
26
+ constructor() {
27
+ this.salt = 'WhatsApp Patch Integrity'
28
+ }
29
+
30
+ subtractThenAdd(base, subtract, add) {
31
+ if (base.length !== 128) throw new Error(`Base hash must be 128 bytes, got ${base.length}`)
32
+ const lanes = new Uint16Array(64)
33
+ const view = Buffer.from(base.buffer, base.byteOffset, base.byteLength)
34
+ for (let i = 0; i < 64; i++) lanes[i] = view.readUInt16LE(i * 2)
35
+ const apply = (items, sign) => {
36
+ for (const item of items) {
37
+ const ex = Buffer.from(hkdf(item, 128, { info: this.salt }))
38
+ for (let i = 0; i < 64; i++) lanes[i] += sign * ex.readUInt16LE(i * 2)
39
+ }
40
+ }
41
+ apply(subtract, -1)
42
+ apply(add, +1)
43
+ const out = Buffer.alloc(128)
44
+ for (let i = 0; i < 64; i++) out.writeUInt16LE(lanes[i], i * 2)
45
+ return u8(out)
46
+ }
47
+ }
@@ -0,0 +1,108 @@
1
+ import { deflateRawSync } from 'node:zlib'
2
+ import * as zlib from 'node:zlib'
3
+
4
+ function dosDateTime(date = new Date()) {
5
+ const dosTime = (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1)
6
+ const dosDate = ((date.getFullYear() - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate()
7
+ return { dosTime, dosDate }
8
+ }
9
+
10
+ function crc32Of(buf) {
11
+
12
+ if (typeof zlib.crc32 === 'function') return zlib.crc32(buf) >>> 0
13
+ return crc32Fallback(buf)
14
+ }
15
+
16
+ let CRC_TABLE
17
+ function crc32Fallback(buf) {
18
+ if (!CRC_TABLE) {
19
+ CRC_TABLE = new Uint32Array(256)
20
+ for (let n = 0; n < 256; n++) {
21
+ let c = n
22
+ for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1
23
+ CRC_TABLE[n] = c >>> 0
24
+ }
25
+ }
26
+ let crc = 0xffffffff
27
+ for (let i = 0; i < buf.length; i++) {
28
+ crc = CRC_TABLE[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8)
29
+ }
30
+ return (crc ^ 0xffffffff) >>> 0
31
+ }
32
+
33
+ export function zip(files, callback) {
34
+ try {
35
+ const localChunks = []
36
+ const centralChunks = []
37
+ let offset = 0
38
+ const { dosTime, dosDate } = dosDateTime()
39
+
40
+ for (const filename of Object.keys(files)) {
41
+ const [rawData, opts = {}] = files[filename]
42
+ const data = Buffer.isBuffer(rawData) ? rawData : Buffer.from(rawData)
43
+ const level = opts.level ?? 6
44
+ const store = level === 0
45
+ const compressed = store ? data : deflateRawSync(data, { level })
46
+ const method = store ? 0 : 8
47
+ const crc = crc32Of(data)
48
+ const nameBuf = Buffer.from(filename, 'utf8')
49
+
50
+ const localHeader = Buffer.alloc(30)
51
+ localHeader.writeUInt32LE(0x04034b50, 0)
52
+ localHeader.writeUInt16LE(20, 4)
53
+ localHeader.writeUInt16LE(0, 6)
54
+ localHeader.writeUInt16LE(method, 8)
55
+ localHeader.writeUInt16LE(dosTime, 10)
56
+ localHeader.writeUInt16LE(dosDate, 12)
57
+ localHeader.writeUInt32LE(crc, 14)
58
+ localHeader.writeUInt32LE(compressed.length, 18)
59
+ localHeader.writeUInt32LE(data.length, 22)
60
+ localHeader.writeUInt16LE(nameBuf.length, 26)
61
+ localHeader.writeUInt16LE(0, 28)
62
+
63
+ localChunks.push(localHeader, nameBuf, compressed)
64
+
65
+ const centralHeader = Buffer.alloc(46)
66
+ centralHeader.writeUInt32LE(0x02014b50, 0)
67
+ centralHeader.writeUInt16LE(20, 4)
68
+ centralHeader.writeUInt16LE(20, 6)
69
+ centralHeader.writeUInt16LE(0, 8)
70
+ centralHeader.writeUInt16LE(method, 10)
71
+ centralHeader.writeUInt16LE(dosTime, 12)
72
+ centralHeader.writeUInt16LE(dosDate, 14)
73
+ centralHeader.writeUInt32LE(crc, 16)
74
+ centralHeader.writeUInt32LE(compressed.length, 20)
75
+ centralHeader.writeUInt32LE(data.length, 24)
76
+ centralHeader.writeUInt16LE(nameBuf.length, 28)
77
+ centralHeader.writeUInt16LE(0, 30)
78
+ centralHeader.writeUInt16LE(0, 32)
79
+ centralHeader.writeUInt16LE(0, 34)
80
+ centralHeader.writeUInt16LE(0, 36)
81
+ centralHeader.writeUInt32LE(0, 38)
82
+ centralHeader.writeUInt32LE(offset, 42)
83
+
84
+ centralChunks.push(centralHeader, nameBuf)
85
+
86
+ offset += localHeader.length + nameBuf.length + compressed.length
87
+ }
88
+
89
+ const centralDirSize = centralChunks.reduce((sum, c) => sum + c.length, 0)
90
+ const centralDirOffset = offset
91
+ const fileCount = Object.keys(files).length
92
+
93
+ const eocd = Buffer.alloc(22)
94
+ eocd.writeUInt32LE(0x06054b50, 0)
95
+ eocd.writeUInt16LE(0, 4)
96
+ eocd.writeUInt16LE(0, 6)
97
+ eocd.writeUInt16LE(fileCount, 8)
98
+ eocd.writeUInt16LE(fileCount, 10)
99
+ eocd.writeUInt32LE(centralDirSize, 12)
100
+ eocd.writeUInt32LE(centralDirOffset, 16)
101
+ eocd.writeUInt16LE(0, 20)
102
+
103
+ const result = Buffer.concat([...localChunks, ...centralChunks, eocd])
104
+ callback(null, result)
105
+ } catch (err) {
106
+ callback(err)
107
+ }
108
+ }
package/src/index.js ADDED
@@ -0,0 +1,67 @@
1
+ const c = code => s => '\x1b[' + code + 'm' + s + '\x1b[0m'
2
+ const bold = code => s => '\x1b[1;' + code + 'm' + s + '\x1b[0m'
3
+
4
+ const chalk = {
5
+ redBright: c(91),
6
+ yellowBright: c(93),
7
+ greenBright: Object.assign(c(92), { bold: bold(92) }),
8
+ cyanBright: c(96),
9
+ blueBright: c(94),
10
+ magentaBright: Object.assign(c(95), { bold: bold(95) }),
11
+ whiteBright: c(97),
12
+ gray: c(90)
13
+ }
14
+
15
+ import { DEFAULT_CONNECTION_CONFIG } from './defaults.js'
16
+ import { makeCommunitiesSocket } from './socket/business-communities.js'
17
+ import { makeMessageBuilderSocket } from './socket/socket-builder.js'
18
+ import { applyPerformanceMode } from './foundation/performance.js'
19
+
20
+ // set MYBAILEYS_BANNER=1 (or the old NOMO_BANNER=1) to print the startup banner
21
+ if (process.env.MYBAILEYS_BANNER === '1' || process.env.NOMO_BANNER === '1') {
22
+ console.log('@nomo/ballieys 1.0.0 | built on Baileys, @dnuzi/baileys and nomo-baileys (MIT), see NOTICE.md')
23
+ }
24
+
25
+ const makeWASocket = config => {
26
+ const newConfig = {
27
+ ...DEFAULT_CONNECTION_CONFIG,
28
+ ...config,
29
+
30
+ logger: config?.logger ?? DEFAULT_CONNECTION_CONFIG.logger
31
+ }
32
+ applyPerformanceMode(newConfig)
33
+ return makeMessageBuilderSocket(newConfig)
34
+ }
35
+
36
+ makeWASocket.default = makeWASocket
37
+
38
+ export * from '../WAProto/index.js'
39
+ export * from './constants.js'
40
+ export * from './defaults.js'
41
+ export * from './binary/wa-binary.js'
42
+ export * from './wam/wam.js'
43
+ export * from './wam/wam-constants.js'
44
+ export * from './socket/usync.js'
45
+ export * from './socket/socket-builder.js'
46
+ export { CHAT_THEMES } from './socket/messages-send.js'
47
+ export * from './foundation/ai-rich.js'
48
+ export * from './foundation/builders.js'
49
+ export * from './foundation/qrcode-terminal.js'
50
+ export * from './foundation/performance.js'
51
+ export * from './utils/wa-protocol-core.js'
52
+ export * from './utils/auth-state-core.js'
53
+ export * from './utils/auth-state-storage.js'
54
+ export * from './utils/use-keyv-auth-state.js'
55
+ export * from './utils/modern-messages.js'
56
+ export * from './utils/check-status.js'
57
+ export * from './utils/cstoken.js'
58
+ export * from './utils/spam-report-utils.js'
59
+ export * from './utils/media.js'
60
+ export * from './utils/message-compose.js'
61
+ export * from './utils/chat-sync.js'
62
+ export * from './utils/message-processing.js'
63
+ export * from './utils/nomo-buttons.js'
64
+ export * from './utils/nomo-commands.js'
65
+
66
+ export { makeWASocket }
67
+ export default makeWASocket