@hiroosy/baileys-lite 0.0.1

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 (63) hide show
  1. package/README.md +25 -0
  2. package/WAProto/index.d.ts +15932 -0
  3. package/WAProto/index.js +115856 -0
  4. package/engine-requirements.js +11 -0
  5. package/package.json +27 -0
  6. package/src/binary/wa-binary-constants.js +1300 -0
  7. package/src/binary/wa-binary.js +649 -0
  8. package/src/constants.js +143 -0
  9. package/src/defaults.js +102 -0
  10. package/src/foundation/audio-duration.js +530 -0
  11. package/src/foundation/audio-samples.js +268 -0
  12. package/src/foundation/boom.js +46 -0
  13. package/src/foundation/cache.js +142 -0
  14. package/src/foundation/concurrency.js +87 -0
  15. package/src/foundation/curve25519.js +221 -0
  16. package/src/foundation/link-preview.js +320 -0
  17. package/src/foundation/logger.js +69 -0
  18. package/src/foundation/long.js +140 -0
  19. package/src/foundation/protobuf-minimal.js +619 -0
  20. package/src/foundation/wa-crypto.js +76 -0
  21. package/src/foundation/zip.js +124 -0
  22. package/src/index.js +48 -0
  23. package/src/signal/libsignal.js +1051 -0
  24. package/src/signal/signal-group.js +487 -0
  25. package/src/signal/signal-repository.js +646 -0
  26. package/src/socket/business-communities.js +830 -0
  27. package/src/socket/chats.js +674 -0
  28. package/src/socket/groups-newsletter.js +342 -0
  29. package/src/socket/messages-recv.js +1835 -0
  30. package/src/socket/messages-send.js +1202 -0
  31. package/src/socket/socket-core.js +833 -0
  32. package/src/socket/usync.js +291 -0
  33. package/src/socket-client/websocket-client.js +124 -0
  34. package/src/utils/auth-state-core.js +764 -0
  35. package/src/utils/auth-state-storage.js +316 -0
  36. package/src/utils/chat-sync.js +1045 -0
  37. package/src/utils/media.js +841 -0
  38. package/src/utils/message-compose.js +1609 -0
  39. package/src/utils/message-processing.js +958 -0
  40. package/src/utils/wa-protocol-core.js +1283 -0
  41. package/src/vendor/jpeg-js/LICENSE +25 -0
  42. package/src/vendor/jpeg-js/decoder.js +1152 -0
  43. package/src/vendor/jpeg-js/encoder.js +824 -0
  44. package/src/vendor/pngjs/LICENSE +20 -0
  45. package/src/vendor/pngjs/bitmapper.js +273 -0
  46. package/src/vendor/pngjs/bitpacker.js +167 -0
  47. package/src/vendor/pngjs/constants.js +38 -0
  48. package/src/vendor/pngjs/crc.js +47 -0
  49. package/src/vendor/pngjs/filter-pack.js +179 -0
  50. package/src/vendor/pngjs/filter-parse-sync.js +27 -0
  51. package/src/vendor/pngjs/filter-parse.js +185 -0
  52. package/src/vendor/pngjs/format-normaliser.js +101 -0
  53. package/src/vendor/pngjs/interlace.js +101 -0
  54. package/src/vendor/pngjs/packer-sync.js +65 -0
  55. package/src/vendor/pngjs/packer.js +138 -0
  56. package/src/vendor/pngjs/paeth-predictor.js +22 -0
  57. package/src/vendor/pngjs/parser-sync.js +121 -0
  58. package/src/vendor/pngjs/parser.js +299 -0
  59. package/src/vendor/pngjs/png-sync.js +19 -0
  60. package/src/vendor/pngjs/sync-inflate.js +174 -0
  61. package/src/vendor/pngjs/sync-reader.js +54 -0
  62. package/src/wam/wam-constants.js +22853 -0
  63. package/src/wam/wam.js +151 -0
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Enum and constant re-exports. Combines the entire former Types/ module
3
+ * (Auth, GroupMetadata, Chat, Contact, State, Message, Socket, Events, Product,
4
+ * Call, Signal, Mex, Label, LabelAssociation, RichType, index) — all of it was
5
+ * plain-object enums or pure proto re-exports with zero logic or dependencies.
6
+ */
7
+ import { proto } from '../WAProto/index.js'
8
+
9
+ export { proto as WAProto }
10
+
11
+ export const ALL_WA_PATCH_NAMES = ['critical_block', 'critical_unblock_low', 'regular_high', 'regular_low', 'regular']
12
+
13
+ /* Message-related enums (from proto.Message) */
14
+ export const AssociationType = proto.MessageAssociation.AssociationType
15
+ export const ButtonHeaderType = proto.Message.ButtonsMessage.HeaderType
16
+ export const ButtonType = proto.Message.ButtonsMessage.Button.Type
17
+ export const CarouselCardType = proto.Message.InteractiveMessage.CarouselMessage.CarouselCardType
18
+ export const ListType = proto.Message.ListMessage.ListType
19
+ export const ProtocolType = proto.Message.ProtocolMessage.Type
20
+ export const WAMessageStubType = proto.WebMessageInfo.StubType
21
+ export const WAMessageStatus = proto.WebMessageInfo.Status
22
+
23
+ export const WAMessageAddressingMode = { PN: 'pn', LID: 'lid' }
24
+
25
+ /* WhatsApp's 20 predefined label colors */
26
+ export const LabelColor = Object.freeze(
27
+ Object.fromEntries(Array.from({ length: 20 }, (_, i) => [`Color${i + 1}`, i]))
28
+ )
29
+
30
+ export const LabelAssociationType = { Chat: 'label_jid', Message: 'label_message' }
31
+
32
+ export const XWAPaths = {
33
+ xwa2_newsletter_create: 'xwa2_newsletter_create',
34
+ xwa2_newsletter_subscribers: 'xwa2_newsletter_subscribers',
35
+ xwa2_newsletter_subscribed: 'xwa2_newsletter_subscribed',
36
+ xwa2_newsletter_view: 'xwa2_newsletter_view',
37
+ xwa2_newsletter_metadata: 'xwa2_newsletter',
38
+ xwa2_newsletter_admin_count: 'xwa2_newsletter_admin',
39
+ xwa2_newsletter_mute_v2: 'xwa2_newsletter_mute_v2',
40
+ xwa2_newsletter_unmute_v2: 'xwa2_newsletter_unmute_v2',
41
+ xwa2_newsletter_follow: 'xwa2_newsletter_follow',
42
+ xwa2_newsletter_unfollow: 'xwa2_newsletter_unfollow',
43
+ xwa2_newsletter_join_v2: 'xwa2_newsletter_join_v2',
44
+ xwa2_newsletter_leave_v2: 'xwa2_newsletter_leave_v2',
45
+ xwa2_newsletter_change_owner: 'xwa2_newsletter_change_owner',
46
+ xwa2_newsletter_demote: 'xwa2_newsletter_demote',
47
+ xwa2_newsletter_delete_v2: 'xwa2_newsletter_delete_v2',
48
+ xwa2_fetch_account_reachout_timelock: 'xwa2_fetch_account_reachout_timelock',
49
+ xwa2_message_capping_info: 'xwa2_message_capping_info'
50
+ }
51
+
52
+ export const QueryIds = {
53
+ CREATE: '8823471724422422',
54
+ UPDATE_METADATA: '24250201037901610',
55
+ METADATA: '6563316087068696',
56
+ SUBSCRIBERS: '9783111038412085',
57
+ SUBSCRIBED: '6388546374527196',
58
+ FOLLOW: '24404358912487870',
59
+ UNFOLLOW: '9767147403369991',
60
+ MUTE: '29766401636284406',
61
+ UNMUTE: '9864994326891137',
62
+ ADMIN_COUNT: '7130823597031706',
63
+ CHANGE_OWNER: '7341777602580933',
64
+ DEMOTE: '6551828931592903',
65
+ DELETE: '30062808666639665',
66
+ REACHOUT_TIMELOCK: '23983697327930364',
67
+ MESSAGE_CAPPING_INFO: '24503548349331633'
68
+ }
69
+
70
+ export const CodeHighlightType = { DEFAULT: 0, KEYWORD: 1, METHOD: 2, STRING: 3, NUMBER: 4, COMMENT: 5 }
71
+
72
+ export const RichSubMessageType = {
73
+ UNKNOWN: 0,
74
+ GRID_IMAGE: 1,
75
+ TEXT: 2,
76
+ INLINE_IMAGE: 3,
77
+ TABLE: 4,
78
+ CODE: 5,
79
+ DYNAMIC: 6,
80
+ MAP: 7,
81
+ LATEX: 8,
82
+ CONTENT_ITEMS: 9
83
+ }
84
+
85
+ /** The socket's high-level sync lifecycle state. */
86
+ export const SyncState = { Connecting: 0, AwaitingInitialSync: 1, Syncing: 2, Online: 3 }
87
+
88
+ export const ReachoutTimelockEnforcementType = {
89
+ BIZ_COMMERCE_VIOLATION_ALCOHOL: 'BIZ_COMMERCE_VIOLATION_ALCOHOL',
90
+ BIZ_COMMERCE_VIOLATION_ADULT: 'BIZ_COMMERCE_VIOLATION_ADULT',
91
+ BIZ_COMMERCE_VIOLATION_ANIMALS: 'BIZ_COMMERCE_VIOLATION_ANIMALS',
92
+ BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS: 'BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS',
93
+ BIZ_COMMERCE_VIOLATION_DATING: 'BIZ_COMMERCE_VIOLATION_DATING',
94
+ BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS: 'BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS',
95
+ BIZ_COMMERCE_VIOLATION_DRUGS: 'BIZ_COMMERCE_VIOLATION_DRUGS',
96
+ BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC: 'BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC',
97
+ BIZ_COMMERCE_VIOLATION_GAMBLING: 'BIZ_COMMERCE_VIOLATION_GAMBLING',
98
+ BIZ_COMMERCE_VIOLATION_HEALTHCARE: 'BIZ_COMMERCE_VIOLATION_HEALTHCARE',
99
+ BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY: 'BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY',
100
+ BIZ_COMMERCE_VIOLATION_SUPPLEMENTS: 'BIZ_COMMERCE_VIOLATION_SUPPLEMENTS',
101
+ BIZ_COMMERCE_VIOLATION_TOBACCO: 'BIZ_COMMERCE_VIOLATION_TOBACCO',
102
+ BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT: 'BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT',
103
+ BIZ_COMMERCE_VIOLATION_WEAPONS: 'BIZ_COMMERCE_VIOLATION_WEAPONS',
104
+ BIZ_QUALITY: 'BIZ_QUALITY',
105
+ /** No restriction */
106
+ DEFAULT: 'DEFAULT',
107
+ WEB_COMPANION_ONLY: 'WEB_COMPANION_ONLY'
108
+ }
109
+
110
+ export const NewChatMessageCappingStatusType = { NONE: 'NONE', FIRST_WARNING: 'FIRST_WARNING', SECOND_WARNING: 'SECOND_WARNING', CAPPED: 'CAPPED' }
111
+
112
+ export const NewChatMessageCappingMVStatusType = {
113
+ NOT_ELIGIBLE: 'NOT_ELIGIBLE',
114
+ NOT_ACTIVE: 'NOT_ACTIVE',
115
+ ACTIVE: 'ACTIVE',
116
+ ACTIVE_UPGRADE_AVAILABLE: 'ACTIVE_UPGRADE_AVAILABLE'
117
+ }
118
+
119
+ export const NewChatMessageCappingOTEStatusType = {
120
+ NOT_ELIGIBLE: 'NOT_ELIGIBLE',
121
+ ELIGIBLE: 'ELIGIBLE',
122
+ ACTIVE_IN_CURRENT_CYCLE: 'ACTIVE_IN_CURRENT_CYCLE',
123
+ EXHAUSTED: 'EXHAUSTED'
124
+ }
125
+
126
+ // Mirrors the TypeScript enum emitted upstream: forward (name -> code) AND reverse (code -> name) mapping,
127
+ // e.g. DisconnectReason.loggedOut === 401 and DisconnectReason[401] === 'loggedOut'.
128
+ // Where two names share a code (408), the later one wins the reverse entry, same as upstream.
129
+ export const DisconnectReason = {}
130
+ for (const [name, code] of [
131
+ ['connectionClosed', 428],
132
+ ['connectionLost', 408],
133
+ ['connectionReplaced', 440],
134
+ ['timedOut', 408],
135
+ ['loggedOut', 401],
136
+ ['badSession', 500],
137
+ ['restartRequired', 515],
138
+ ['multideviceMismatch', 411],
139
+ ['forbidden', 403],
140
+ ['unavailableService', 503]
141
+ ]) {
142
+ DisconnectReason[(DisconnectReason[name] = code)] = name
143
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Default connection configuration and misc protocol-level constants.
3
+ * Combines what used to be Defaults/index.js.
4
+ */
5
+ import { proto } from '../WAProto/index.js'
6
+ import { makeLibSignalRepository } from './signal/signal-repository.js'
7
+ import { Browsers, KEY_BUNDLE_TYPE } from './utils/wa-protocol-core.js'
8
+ import { createLogger } from './foundation/logger.js'
9
+
10
+ const logger = createLogger()
11
+
12
+ const version = [2, 3000, 1047970367]
13
+
14
+ export const UNAUTHORIZED_CODES = [401, 403, 419]
15
+ export const BIZ_BOT_SUPPORT_PAYLOAD =
16
+ '{"version":1,"is_ai_message":true,"should_upload_client_logs":false,"should_show_system_message":false,"ticket_id":"7004947587700716","citation_items":[],"ticket_locale":"us"}'
17
+ export const DEFAULT_ORIGIN = 'https://web.whatsapp.com'
18
+ export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/'
19
+ export const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/'
20
+ export const LIBRARY_NAME = 'Baileys'
21
+ export const DEF_CALLBACK_PREFIX = 'CB:'
22
+ export const DEF_TAG_PREFIX = 'TAG:'
23
+ export const PHONE_CONNECTION_CB = 'CB:Pong'
24
+ export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0])
25
+ export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1])
26
+ export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5])
27
+ export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6])
28
+ export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
29
+ export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60
30
+ export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60
31
+ export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
32
+ export const DICT_VERSION = 3
33
+ // single source of truth lives in utils/wa-protocol-core.js (avoids an ambiguous duplicate under `export *`)
34
+ export { KEY_BUNDLE_TYPE }
35
+ export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION])
36
+
37
+ export const WA_CERT_DETAILS = {
38
+ SERIAL: 0,
39
+ ISSUER: 'WhatsAppLongTerm1',
40
+ PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
41
+ }
42
+
43
+ export const PROCESSABLE_HISTORY_TYPES = [
44
+ proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
45
+ proto.HistorySync.HistorySyncType.PUSH_NAME,
46
+ proto.HistorySync.HistorySyncType.RECENT,
47
+ proto.HistorySync.HistorySyncType.FULL,
48
+ proto.HistorySync.HistorySyncType.ON_DEMAND,
49
+ proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
50
+ proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
51
+ ]
52
+
53
+ export const DEFAULT_CACHE_TTLS = {
54
+ SIGNAL_STORE: 5 * 60,
55
+ MSG_RETRY: 60 * 60,
56
+ CALL_OFFER: 5 * 60,
57
+ USER_DEVICES: 5 * 60
58
+ }
59
+
60
+ export const DEFAULT_CONNECTION_CONFIG = {
61
+ version,
62
+ browser: Browsers.macOS('Chrome'),
63
+ waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
64
+ connectTimeoutMs: 20000,
65
+ keepAliveIntervalMs: 30000,
66
+ logger: logger.child({ class: 'baileys' }),
67
+ emitOwnEvents: true,
68
+ defaultQueryTimeoutMs: 60000,
69
+ customUploadHosts: [],
70
+ retryRequestDelayMs: 250,
71
+ maxMsgRetryCount: 5,
72
+ fireInitQueries: true,
73
+ auth: undefined,
74
+ markOnlineOnConnect: true,
75
+ syncFullHistory: true,
76
+ patchMessageBeforeSending: msg => msg,
77
+ shouldSyncHistoryMessage: ({ syncType }) => syncType !== proto.HistorySync.HistorySyncType.FULL,
78
+ shouldIgnoreJid: () => false,
79
+ linkPreviewImageThumbnailWidth: 192,
80
+ transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
81
+ generateHighQualityLinkPreview: false,
82
+ enableAutoSessionRecreation: true,
83
+ enableRecentMessageCache: true,
84
+ options: {},
85
+ appStateMacVerification: { patch: false, snapshot: false },
86
+ countryCode: 'US',
87
+ getMessage: async () => undefined,
88
+ cachedGroupMetadata: async () => undefined,
89
+ makeSignalRepository: makeLibSignalRepository
90
+ }
91
+
92
+ export const HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000
93
+ export const MIN_PREKEY_COUNT = 5
94
+ export const INITIAL_PREKEY_COUNT = 812
95
+ export const UPLOAD_TIMEOUT = 30000
96
+
97
+ export const TimeMs = {
98
+ Minute: 60 * 1000,
99
+ Hour: 60 * 60 * 1000,
100
+ Day: 24 * 60 * 60 * 1000,
101
+ Week: 7 * 24 * 60 * 60 * 1000
102
+ }