@awangxcode/qiro-baileys 7.0.0-rc25.5 → 7.0.0-rc26.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.
- package/LICENSE +15 -0
- package/README.md +1443 -1033
- package/WAProto/WAProto.proto +4 -0
- package/WAProto/index.d.ts +4067 -243
- package/WAProto/index.js +74957 -43330
- package/assets/branding/qiro-logo.svg +24 -0
- package/assets/branding/qiro-mark.png +0 -0
- package/assets/branding/qiro-mark.svg +34 -0
- package/assets/branding/qiro-social-preview.png +0 -0
- package/lib/Defaults/index.d.ts +16 -1
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +43 -10
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Extensions/advanced.d.ts +1 -1
- package/lib/Extensions/experimental.d.ts +1 -3
- package/lib/Extensions/experimental.d.ts.map +1 -1
- package/lib/Extensions/experimental.js +0 -2
- package/lib/Extensions/experimental.js.map +1 -1
- package/lib/MessageBuilder/index.d.ts +5 -5
- package/lib/MessageBuilder/index.d.ts.map +1 -1
- package/lib/MessageBuilder/index.js +12 -3
- package/lib/MessageBuilder/index.js.map +1 -1
- package/lib/Signal/Group/group-session-builder.d.ts +3 -3
- package/lib/Signal/Group/group-session-builder.js +4 -4
- package/lib/Signal/Group/group_cipher.d.ts +2 -2
- package/lib/Signal/Group/group_cipher.js +4 -4
- package/lib/Signal/Group/index.d.ts +11 -11
- package/lib/Signal/Group/index.js +11 -11
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
- package/lib/Signal/Group/sender-key-message.d.ts +1 -1
- package/lib/Signal/Group/sender-key-message.js +1 -1
- package/lib/Signal/Group/sender-key-record.d.ts +1 -1
- package/lib/Signal/Group/sender-key-record.js +2 -2
- package/lib/Signal/Group/sender-key-state.d.ts +2 -2
- package/lib/Signal/Group/sender-key-state.js +2 -2
- package/lib/Signal/libsignal.d.ts +3 -3
- package/lib/Signal/libsignal.js +6 -6
- package/lib/Signal/lid-mapping.d.ts +2 -2
- package/lib/Signal/lid-mapping.js +4 -4
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/Client/index.d.ts +2 -2
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +1 -1
- package/lib/Socket/Client/websocket.d.ts +1 -1
- package/lib/Socket/Client/websocket.js +2 -2
- package/lib/Socket/business.d.ts +347 -65
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js +5 -5
- package/lib/Socket/chats.d.ts +129 -16
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +293 -18
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +332 -50
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/communities.js +5 -5
- package/lib/Socket/groups.d.ts +133 -27
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +4 -4
- package/lib/Socket/index.d.ts +366 -84
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js +8 -5
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +324 -41
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +81 -30
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +340 -44
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +171 -35
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts +1 -1
- package/lib/Socket/mex.js +1 -1
- package/lib/Socket/newsletter.d.ts +324 -39
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +345 -5
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +24 -11
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +89 -36
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +397 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Types/Auth.d.ts +2 -2
- package/lib/Types/Chat.d.ts +19 -6
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Chat.js.map +1 -1
- package/lib/Types/Events.d.ts +9 -9
- package/lib/Types/GroupMetadata.d.ts +2 -2
- package/lib/Types/Message.d.ts +70 -6
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Mex.d.ts +68 -39
- package/lib/Types/Mex.d.ts.map +1 -1
- package/lib/Types/Mex.js +66 -0
- package/lib/Types/Mex.js.map +1 -1
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +1 -1
- package/lib/Types/Socket.d.ts +50 -5
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.d.ts +1 -1
- package/lib/Types/USync.d.ts +2 -2
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.d.ts +14 -14
- package/lib/Types/index.js +12 -12
- package/lib/Utils/audio-sticker.d.ts +14 -0
- package/lib/Utils/audio-sticker.js +172 -0
- package/lib/Utils/auth-store.d.ts +30 -0
- package/lib/Utils/auth-store.js +77 -0
- package/lib/Utils/auth-utils.d.ts +2 -2
- package/lib/Utils/auth-utils.js +4 -4
- package/lib/Utils/browser-utils.d.ts +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +3 -3
- package/lib/Utils/chat-theme.d.ts +34 -0
- package/lib/Utils/chat-theme.js +336 -0
- package/lib/Utils/chat-utils.d.ts +3 -3
- package/lib/Utils/chat-utils.js +9 -9
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +3 -3
- package/lib/Utils/companion-reg-client-utils.js +1 -1
- package/lib/Utils/crypto.d.ts +1 -1
- package/lib/Utils/crypto.js +1 -1
- package/lib/Utils/decode-wa-message.d.ts +18 -4
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +57 -2
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +4 -3
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +7 -8
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +5 -4
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +13 -22
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/group-metadata-cache.d.ts +4 -0
- package/lib/Utils/group-metadata-cache.js +25 -0
- package/lib/Utils/history.d.ts +1 -1
- package/lib/Utils/history.js +6 -6
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/html-app.d.ts +19 -0
- package/lib/Utils/html-app.js +96 -0
- package/lib/Utils/html-multiplayer.d.ts +10 -0
- package/lib/Utils/html-multiplayer.js +94 -0
- package/lib/Utils/identity-change-handler.d.ts +2 -2
- package/lib/Utils/identity-change-handler.js +2 -2
- package/lib/Utils/index.d.ts +46 -21
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +48 -21
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview-metadata.d.ts +47 -0
- package/lib/Utils/link-preview-metadata.js +88 -0
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +2 -2
- package/lib/Utils/message-retry-manager.d.ts +1 -1
- package/lib/Utils/messages-media.d.ts +35 -6
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +69 -22
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +45 -5
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +123 -32
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/modern-messages.d.ts +150 -0
- package/lib/Utils/modern-messages.js +496 -0
- package/lib/Utils/native-flow.d.ts +11 -0
- package/lib/Utils/native-flow.js +116 -0
- package/lib/Utils/newsletter-status.d.ts +158 -0
- package/lib/Utils/newsletter-status.js +651 -0
- package/lib/Utils/noise-handler.d.ts +3 -3
- package/lib/Utils/noise-handler.js +3 -3
- package/lib/Utils/offline-node-processor.d.ts +1 -1
- package/lib/Utils/optional-media.d.ts +3 -0
- package/lib/Utils/optional-media.js +46 -0
- package/lib/Utils/payment-messages.d.ts +38 -0
- package/lib/Utils/payment-messages.js +160 -0
- package/lib/Utils/pre-key-manager.d.ts +2 -2
- package/lib/Utils/process-message.d.ts +13 -2
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +87 -7
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/reporting-utils.d.ts +2 -2
- package/lib/Utils/reporting-utils.js +1 -1
- package/lib/Utils/scheduled-message.d.ts +51 -0
- package/lib/Utils/scheduled-message.js +113 -0
- package/lib/Utils/sender-key-memory.d.ts +19 -0
- package/lib/Utils/sender-key-memory.js +51 -0
- package/lib/Utils/signal.d.ts +4 -4
- package/lib/Utils/signal.js +4 -4
- package/lib/Utils/stanza-ack.d.ts +1 -1
- package/lib/Utils/status-stickers.d.ts +127 -0
- package/lib/Utils/status-stickers.js +261 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -2
- package/lib/Utils/sync-action-utils.js +1 -1
- package/lib/Utils/tc-token-utils.d.ts +2 -2
- package/lib/Utils/tc-token-utils.js +1 -1
- package/lib/Utils/ttl-cache.d.ts +29 -0
- package/lib/Utils/ttl-cache.js +121 -0
- package/lib/Utils/use-mongo-auth-state.d.ts +22 -0
- package/lib/Utils/use-mongo-auth-state.js +68 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +28 -15
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/use-mysql-auth-state.d.ts +20 -0
- package/lib/Utils/use-mysql-auth-state.js +80 -0
- package/lib/Utils/use-nekodb-auth.d.ts +19 -0
- package/lib/Utils/use-nekodb-auth.js +111 -0
- package/lib/Utils/use-postgres-auth-state.d.ts +20 -0
- package/lib/Utils/use-postgres-auth-state.js +80 -0
- package/lib/Utils/use-redis-auth-state.d.ts +20 -0
- package/lib/Utils/use-redis-auth-state.js +90 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
- package/lib/Utils/use-sqlite-auth-state.js +121 -0
- package/lib/Utils/username.d.ts +12 -0
- package/lib/Utils/username.js +59 -0
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +5 -5
- package/lib/Utils/voice-recognition.d.ts +53 -0
- package/lib/Utils/voice-recognition.js +219 -0
- package/lib/VoIP/audio-feeder.d.ts +24 -0
- package/lib/VoIP/audio-feeder.js +276 -0
- package/lib/VoIP/index.d.ts +93 -0
- package/lib/VoIP/index.js +998 -0
- package/lib/VoIP/relay-transport.d.ts +5 -0
- package/lib/VoIP/relay-transport.js +824 -0
- package/lib/VoIP/signaling.d.ts +11 -0
- package/lib/VoIP/signaling.js +1099 -0
- package/lib/VoIP/types.d.ts +2 -0
- package/lib/VoIP/types.js +12 -0
- package/lib/VoIP/video-feeder.d.ts +24 -0
- package/lib/VoIP/video-feeder.js +276 -0
- package/lib/VoIP/wasm-engine.d.ts +26 -0
- package/lib/VoIP/wasm-engine.js +1318 -0
- package/lib/VoIP/worker-bootstrap.js +1022 -0
- package/lib/WABinary/decode.d.ts +1 -1
- package/lib/WABinary/decode.js +2 -2
- package/lib/WABinary/encode.d.ts +1 -1
- package/lib/WABinary/encode.js +2 -2
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +3 -1
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WABinary/index.d.ts +5 -5
- package/lib/WABinary/index.js +5 -5
- package/lib/WABinary/jid-utils.d.ts +2 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -1
- package/lib/WABinary/jid-utils.js +3 -1
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/WABinary/types.d.ts +1 -1
- package/lib/WABinary/types.js +1 -1
- package/lib/WAM/BinaryInfo.d.ts +1 -1
- package/lib/WAM/encode.d.ts +1 -1
- package/lib/WAM/encode.js +2 -2
- package/lib/WAM/index.d.ts +3 -3
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -5
- package/lib/WAUSync/Protocols/index.js +5 -5
- package/lib/WAUSync/USyncQuery.d.ts +3 -3
- package/lib/WAUSync/USyncQuery.js +5 -5
- package/lib/WAUSync/index.d.ts +3 -3
- package/lib/WAUSync/index.js +3 -3
- package/lib/extensions/awang-MessageBuilder.js +1 -1
- package/lib/index.d.ts +14 -10
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -11
- package/lib/index.js.map +1 -1
- package/package.json +78 -31
- package/MIGRASI-QIRO-BAILEYS-RC25.md +0 -102
- package/QIRO-BAILEYS-RC25.md +0 -168
- package/THIRD_PARTY_NOTICES.md +0 -49
- /package/{engine-requirements.js → config/engine-requirements.js} +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { createCipheriv, createDecipheriv, randomBytes, randomUUID } from 'crypto'
|
|
3
|
+
import { proto } from '../../WAProto/index.js'
|
|
4
|
+
|
|
5
|
+
export const SCHEDULED_MSG_META_TYPE = 'scheduled_message'
|
|
6
|
+
export const SCHEDULED_MSG_MAX_PER_CHAT = 30
|
|
7
|
+
export const SCHEDULED_MSG_MAX_MEDIA = 1
|
|
8
|
+
export const SCHEDULED_MSG_RESOURCE_LIMIT_NACK_CODE = 419
|
|
9
|
+
export const SCHEDULED_MSG_REVEAL_KEY_BYTES = 32
|
|
10
|
+
export const SCHEDULED_MSG_REVEAL_KEY_IV_BYTES = 12
|
|
11
|
+
export const SCHEDULED_MSG_REVEAL_KEY_RETENTION_DAYS = 30
|
|
12
|
+
export const SCHEDULED_MSG_TAG_BYTES = 16
|
|
13
|
+
|
|
14
|
+
export const SCHEDULED_MSG_WINDOW = Object.freeze({
|
|
15
|
+
chat: { minSeconds: 600, maxSeconds: 1209600 },
|
|
16
|
+
newsletter: { minSeconds: 600, maxSeconds: 2592000 }
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const generateRevealKey = () => randomBytes(SCHEDULED_MSG_REVEAL_KEY_BYTES)
|
|
20
|
+
|
|
21
|
+
export const generateRevealKeyId = () => randomUUID()
|
|
22
|
+
|
|
23
|
+
export const encryptWithRevealKey = (plaintext, revealKey) => {
|
|
24
|
+
const key = Buffer.from(revealKey)
|
|
25
|
+
if (key.length !== SCHEDULED_MSG_REVEAL_KEY_BYTES) {
|
|
26
|
+
throw new TypeError(`reveal key must be ${SCHEDULED_MSG_REVEAL_KEY_BYTES} bytes`)
|
|
27
|
+
}
|
|
28
|
+
const encIv = randomBytes(SCHEDULED_MSG_REVEAL_KEY_IV_BYTES)
|
|
29
|
+
const cipher = createCipheriv('aes-256-gcm', key, encIv)
|
|
30
|
+
const body = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()])
|
|
31
|
+
return { encIv, encPayload: Buffer.concat([body, cipher.getAuthTag()]) }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const decryptWithRevealKey = (encPayload, encIv, revealKey) => {
|
|
35
|
+
const key = Buffer.from(revealKey)
|
|
36
|
+
const payload = Buffer.from(encPayload)
|
|
37
|
+
if (payload.length < SCHEDULED_MSG_TAG_BYTES) {
|
|
38
|
+
throw new TypeError('encrypted payload is too short to carry an auth tag')
|
|
39
|
+
}
|
|
40
|
+
const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(encIv))
|
|
41
|
+
decipher.setAuthTag(payload.subarray(payload.length - SCHEDULED_MSG_TAG_BYTES))
|
|
42
|
+
return Buffer.concat([
|
|
43
|
+
decipher.update(payload.subarray(0, payload.length - SCHEDULED_MSG_TAG_BYTES)),
|
|
44
|
+
decipher.final()
|
|
45
|
+
])
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const buildConditionalRevealMessage = ({ encPayload, encIv, revealKeyId }) => ({
|
|
49
|
+
conditionalRevealMessage: {
|
|
50
|
+
conditionalRevealMessageType: proto.Message.ConditionalRevealMessage.ConditionalRevealMessageType.SCHEDULED_MESSAGE,
|
|
51
|
+
encPayload: Buffer.from(encPayload),
|
|
52
|
+
encIv: Buffer.from(encIv),
|
|
53
|
+
revealKeyId
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
export const encodeScheduledMessage = (message, revealKey = generateRevealKey()) => {
|
|
58
|
+
const plaintext = proto.Message.encode(proto.Message.fromObject(message)).finish()
|
|
59
|
+
const { encIv, encPayload } = encryptWithRevealKey(plaintext, revealKey)
|
|
60
|
+
const revealKeyId = generateRevealKeyId()
|
|
61
|
+
return {
|
|
62
|
+
revealKey,
|
|
63
|
+
revealKeyId,
|
|
64
|
+
encIv,
|
|
65
|
+
encPayload,
|
|
66
|
+
message: buildConditionalRevealMessage({ encPayload, encIv, revealKeyId })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const decodeScheduledMessage = (conditionalRevealMessage, revealKey) => {
|
|
71
|
+
const inner = conditionalRevealMessage?.conditionalRevealMessage ?? conditionalRevealMessage
|
|
72
|
+
if (!inner?.encPayload || !inner?.encIv) {
|
|
73
|
+
throw new TypeError('conditionalRevealMessage is missing encPayload or encIv')
|
|
74
|
+
}
|
|
75
|
+
return proto.Message.decode(decryptWithRevealKey(inner.encPayload, inner.encIv, revealKey))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const buildScheduledMsgMetaNode = ({ kind = 'schedule', scheduledTimestampS, revealKeyId, revealKey }) => {
|
|
79
|
+
if (!revealKeyId) {
|
|
80
|
+
throw new TypeError('revealKeyId is required')
|
|
81
|
+
}
|
|
82
|
+
if (kind === 'schedule' && !revealKey) {
|
|
83
|
+
throw new TypeError('scheduling requires the reveal key')
|
|
84
|
+
}
|
|
85
|
+
const attrs = { type: SCHEDULED_MSG_META_TYPE }
|
|
86
|
+
if (kind === 'schedule') {
|
|
87
|
+
if (!Number.isFinite(Number(scheduledTimestampS))) {
|
|
88
|
+
throw new TypeError('scheduledTimestampS must be a unix timestamp in seconds')
|
|
89
|
+
}
|
|
90
|
+
attrs.st = String(Math.floor(Number(scheduledTimestampS)))
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
tag: 'meta',
|
|
94
|
+
attrs,
|
|
95
|
+
content: [{
|
|
96
|
+
tag: 'key',
|
|
97
|
+
attrs: { rkid: revealKeyId },
|
|
98
|
+
content: kind === 'schedule' ? Buffer.from(revealKey) : undefined
|
|
99
|
+
}]
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const buildUnscheduleProtocolMessage = (key) => ({
|
|
104
|
+
protocolMessage: {
|
|
105
|
+
key,
|
|
106
|
+
type: proto.Message.ProtocolMessage.Type.MESSAGE_UNSCHEDULE
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
export const isScheduledTimeValid = (scheduledTimestampS, nowSeconds = Math.floor(Date.now() / 1000), window = SCHEDULED_MSG_WINDOW.chat) => {
|
|
111
|
+
const rounded = Math.floor(nowSeconds / 60) * 60
|
|
112
|
+
return scheduledTimestampS - rounded >= window.minSeconds && scheduledTimestampS - nowSeconds <= window.maxSeconds
|
|
113
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export declare function pickSenderKeyRecipients(
|
|
3
|
+
devices: { jid?: string, device?: number }[],
|
|
4
|
+
senderKeyMap: Record<string, boolean>,
|
|
5
|
+
options?: { force?: boolean, skip?: (device: any) => boolean }
|
|
6
|
+
): string[]
|
|
7
|
+
|
|
8
|
+
export declare function deliveredSenderKeyJids(nodes: { attrs?: { jid?: string } }[]): Set<string>
|
|
9
|
+
|
|
10
|
+
export declare function senderKeyResetSummary(
|
|
11
|
+
stored: Record<string, Record<string, boolean> | null | undefined> | undefined,
|
|
12
|
+
jid: string
|
|
13
|
+
): { jid: string, cleared: number, devices: string[] }
|
|
14
|
+
|
|
15
|
+
export declare function commitSenderKeyDelivery(
|
|
16
|
+
senderKeyMap: Record<string, boolean>,
|
|
17
|
+
recipients: string[],
|
|
18
|
+
nodes: { attrs?: { jid?: string } }[]
|
|
19
|
+
): { marked: string[], skipped: string[] }
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export const pickSenderKeyRecipients = (devices, senderKeyMap, { force = false, skip } = {}) => {
|
|
3
|
+
const recipients = []
|
|
4
|
+
for (const device of devices) {
|
|
5
|
+
const deviceJid = device?.jid
|
|
6
|
+
if (!deviceJid) {
|
|
7
|
+
continue
|
|
8
|
+
}
|
|
9
|
+
if (!force && senderKeyMap[deviceJid]) {
|
|
10
|
+
continue
|
|
11
|
+
}
|
|
12
|
+
if (skip && skip(device)) {
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
15
|
+
recipients.push(deviceJid)
|
|
16
|
+
}
|
|
17
|
+
return recipients
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const deliveredSenderKeyJids = nodes => {
|
|
21
|
+
const delivered = new Set()
|
|
22
|
+
for (const node of nodes || []) {
|
|
23
|
+
const jid = node?.attrs?.jid
|
|
24
|
+
if (jid) {
|
|
25
|
+
delivered.add(jid)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return delivered
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const senderKeyResetSummary = (stored, jid) => {
|
|
32
|
+
const devices = Object.keys(stored?.[jid] || {})
|
|
33
|
+
return { jid, cleared: devices.length, devices }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const commitSenderKeyDelivery = (senderKeyMap, recipients, nodes) => {
|
|
37
|
+
const delivered = deliveredSenderKeyJids(nodes)
|
|
38
|
+
const marked = []
|
|
39
|
+
const skipped = []
|
|
40
|
+
for (const jid of recipients) {
|
|
41
|
+
if (delivered.has(jid)) {
|
|
42
|
+
senderKeyMap[jid] = true
|
|
43
|
+
marked.push(jid)
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
delete senderKeyMap[jid]
|
|
47
|
+
skipped.push(jid)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { marked, skipped }
|
|
51
|
+
}
|
package/lib/Utils/signal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { SignalRepositoryWithLIDStore } from '../Types
|
|
2
|
-
import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth
|
|
3
|
-
import { type BinaryNode, type FullJid } from '../WABinary
|
|
4
|
-
import type { USyncQueryResultList } from '../WAUSync
|
|
1
|
+
import type { SignalRepositoryWithLIDStore } from '../Types';
|
|
2
|
+
import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
|
|
3
|
+
import { type BinaryNode, type FullJid } from '../WABinary';
|
|
4
|
+
import type { USyncQueryResultList } from '../WAUSync';
|
|
5
5
|
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
6
|
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
7
|
[id: string]: KeyPair;
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { KEY_BUNDLE_TYPE } from '../Defaults
|
|
2
|
-
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary
|
|
3
|
-
import { Curve, generateSignalPubKey } from './crypto
|
|
4
|
-
import { encodeBigEndian } from './generics
|
|
1
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults';
|
|
2
|
+
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary';
|
|
3
|
+
import { Curve, generateSignalPubKey } from './crypto';
|
|
4
|
+
import { encodeBigEndian } from './generics';
|
|
5
5
|
function chunk(array, size) {
|
|
6
6
|
const chunks = [];
|
|
7
7
|
for (let i = 0; i < array.length; i += size) {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
|
|
3
|
+
export declare const StatusLinkType: Readonly<{
|
|
4
|
+
RASTERIZED_LINK_PREVIEW: 1;
|
|
5
|
+
RASTERIZED_LINK_TRUNCATED: 2;
|
|
6
|
+
RASTERIZED_LINK_FULL_URL: 3;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
export interface StickerArea {
|
|
10
|
+
/** Distance from the left edge, as a fraction of the media width. */
|
|
11
|
+
x: number;
|
|
12
|
+
/** Distance from the top edge, as a fraction of the media height. */
|
|
13
|
+
y: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare const STICKER_DEFAULT_AREA: Readonly<StickerArea>;
|
|
19
|
+
|
|
20
|
+
export declare function stickerArea(area?: StickerArea): proto.IPoint[];
|
|
21
|
+
|
|
22
|
+
export declare function locationSticker(options: {
|
|
23
|
+
latitude: number;
|
|
24
|
+
longitude: number;
|
|
25
|
+
name?: string;
|
|
26
|
+
area?: StickerArea | proto.IPoint[];
|
|
27
|
+
skipConfirmation?: boolean;
|
|
28
|
+
}): proto.IInteractiveAnnotation;
|
|
29
|
+
|
|
30
|
+
export declare function channelSticker(options: {
|
|
31
|
+
jid: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
serverMessageId?: number;
|
|
34
|
+
accessibilityText?: string;
|
|
35
|
+
area?: StickerArea | proto.IPoint[];
|
|
36
|
+
}): proto.IInteractiveAnnotation;
|
|
37
|
+
|
|
38
|
+
export declare function linkSticker(options: {
|
|
39
|
+
url: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
area?: StickerArea | proto.IPoint[];
|
|
42
|
+
linkType?: number;
|
|
43
|
+
}): proto.IInteractiveAnnotation;
|
|
44
|
+
|
|
45
|
+
export declare function musicSticker(options: {
|
|
46
|
+
songId?: string;
|
|
47
|
+
title?: string;
|
|
48
|
+
author?: string;
|
|
49
|
+
mediaId?: string;
|
|
50
|
+
artworkDirectPath?: string;
|
|
51
|
+
artworkSha256?: Buffer | string;
|
|
52
|
+
artworkEncSha256?: Buffer | string;
|
|
53
|
+
artworkMediaKey?: Buffer | string;
|
|
54
|
+
artistAttribution?: string;
|
|
55
|
+
countryBlocklist?: Buffer | string;
|
|
56
|
+
isExplicit?: boolean;
|
|
57
|
+
startTimeMs?: number;
|
|
58
|
+
derivedStartTimeMs?: number;
|
|
59
|
+
durationMs?: number;
|
|
60
|
+
area?: StickerArea | proto.IPoint[];
|
|
61
|
+
}): proto.IInteractiveAnnotation;
|
|
62
|
+
|
|
63
|
+
export declare function messageSticker(options: {
|
|
64
|
+
stanzaId?: string;
|
|
65
|
+
message: proto.IMessage;
|
|
66
|
+
area?: StickerArea | proto.IPoint[];
|
|
67
|
+
}): proto.IInteractiveAnnotation;
|
|
68
|
+
|
|
69
|
+
export declare function normalizeStickers(
|
|
70
|
+
stickers: proto.IInteractiveAnnotation | proto.IInteractiveAnnotation[]
|
|
71
|
+
): proto.InteractiveAnnotation[];
|
|
72
|
+
|
|
73
|
+
export interface ReadSticker {
|
|
74
|
+
kind: 'location' | 'channel' | 'link' | 'music' | 'message' | 'unknown';
|
|
75
|
+
area?: StickerArea;
|
|
76
|
+
location?: proto.ILocation;
|
|
77
|
+
channel?: proto.ContextInfo.IForwardedNewsletterMessageInfo;
|
|
78
|
+
link?: { url?: string; title?: string; linkType?: number };
|
|
79
|
+
music?: { songId?: string; title?: string; author?: string };
|
|
80
|
+
message?: proto.IEmbeddedMessage;
|
|
81
|
+
annotation: proto.IInteractiveAnnotation;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare function readStickers(message: any): ReadSticker[];
|
|
85
|
+
|
|
86
|
+
export declare const MusicMessageStyle: Readonly<{ UNKNOWN: 0; VINYL: 1 }>;
|
|
87
|
+
|
|
88
|
+
export interface MusicMessageOptions {
|
|
89
|
+
songId?: string;
|
|
90
|
+
mediaId?: string;
|
|
91
|
+
title?: string;
|
|
92
|
+
author?: string;
|
|
93
|
+
artistAttribution?: string;
|
|
94
|
+
artworkDirectPath?: string;
|
|
95
|
+
artworkSha256?: Buffer | string;
|
|
96
|
+
artworkEncSha256?: Buffer | string;
|
|
97
|
+
artworkMediaKey?: Buffer | string;
|
|
98
|
+
countryBlocklist?: Buffer | string;
|
|
99
|
+
isExplicit?: boolean;
|
|
100
|
+
startTimeMs?: number;
|
|
101
|
+
derivedStartTimeMs?: number;
|
|
102
|
+
durationMs?: number;
|
|
103
|
+
songUri?: string;
|
|
104
|
+
artworkUri?: string;
|
|
105
|
+
style?: number;
|
|
106
|
+
contextInfo?: proto.IContextInfo;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare function buildMusicMessage(options?: MusicMessageOptions): proto.Message.IMusicMessage;
|
|
110
|
+
|
|
111
|
+
export declare function readMusicMessage(msg: any): {
|
|
112
|
+
songId?: string;
|
|
113
|
+
mediaId?: string;
|
|
114
|
+
title?: string;
|
|
115
|
+
author?: string;
|
|
116
|
+
artistAttribution?: string;
|
|
117
|
+
isExplicit?: boolean;
|
|
118
|
+
startTimeMs?: number | string;
|
|
119
|
+
durationMs?: number | string;
|
|
120
|
+
songUri?: string;
|
|
121
|
+
artworkUri?: string;
|
|
122
|
+
style?: number;
|
|
123
|
+
embeddedMusic: proto.IEmbeddedMusic;
|
|
124
|
+
} | null;
|
|
125
|
+
|
|
126
|
+
export declare const MUSIC_ALLOWED_HOSTS: readonly string[];
|
|
127
|
+
export declare function isMusicHostAllowed(value?: unknown): boolean;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
import { proto } from '../../WAProto/index.js'
|
|
3
|
+
|
|
4
|
+
export const StatusLinkType = Object.freeze({
|
|
5
|
+
RASTERIZED_LINK_PREVIEW: 1,
|
|
6
|
+
RASTERIZED_LINK_TRUNCATED: 2,
|
|
7
|
+
RASTERIZED_LINK_FULL_URL: 3
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const STICKER_DEFAULT_AREA = Object.freeze({ x: 0.25, y: 0.4, width: 0.5, height: 0.2 })
|
|
11
|
+
|
|
12
|
+
const trimUndefined = (object) => {
|
|
13
|
+
for (const key of Object.keys(object)) {
|
|
14
|
+
if (object[key] === undefined) {
|
|
15
|
+
delete object[key]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return object
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const fraction = (value, name) => {
|
|
22
|
+
const number = Number(value)
|
|
23
|
+
if (!Number.isFinite(number) || number < 0 || number > 1) {
|
|
24
|
+
throw new TypeError(`${name} must be between 0 and 1, the client reads these as a fraction of the media`)
|
|
25
|
+
}
|
|
26
|
+
return number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const stickerArea = ({ x, y, width, height } = STICKER_DEFAULT_AREA) => {
|
|
30
|
+
const left = fraction(x, 'x')
|
|
31
|
+
const top = fraction(y, 'y')
|
|
32
|
+
const right = fraction(left + Number(width), 'x + width')
|
|
33
|
+
const bottom = fraction(top + Number(height), 'y + height')
|
|
34
|
+
if (right <= left || bottom <= top) {
|
|
35
|
+
throw new TypeError('a sticker area needs a positive width and height')
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
{ x: left, y: top },
|
|
39
|
+
{ x: right, y: top },
|
|
40
|
+
{ x: right, y: bottom },
|
|
41
|
+
{ x: left, y: bottom }
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const annotation = (area, fields) => ({
|
|
46
|
+
polygonVertices: Array.isArray(area) ? area : stickerArea(area),
|
|
47
|
+
...fields
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export const locationSticker = ({ latitude, longitude, name, area, skipConfirmation } = {}) => {
|
|
51
|
+
const degreesLatitude = Number(latitude)
|
|
52
|
+
const degreesLongitude = Number(longitude)
|
|
53
|
+
if (!Number.isFinite(degreesLatitude) || !Number.isFinite(degreesLongitude)) {
|
|
54
|
+
throw new TypeError('locationSticker needs a numeric latitude and longitude')
|
|
55
|
+
}
|
|
56
|
+
return annotation(area, {
|
|
57
|
+
location: { degreesLatitude, degreesLongitude, ...(name ? { name } : {}) },
|
|
58
|
+
...(skipConfirmation === undefined ? {} : { shouldSkipConfirmation: !!skipConfirmation })
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const channelSticker = ({ jid, name, serverMessageId = 0, accessibilityText, area } = {}) => {
|
|
63
|
+
if (typeof jid !== 'string' || !jid.endsWith('@newsletter')) {
|
|
64
|
+
throw new TypeError('channelSticker needs the channel jid, the one ending in @newsletter')
|
|
65
|
+
}
|
|
66
|
+
return annotation(area, {
|
|
67
|
+
newsletter: {
|
|
68
|
+
newsletterJid: jid,
|
|
69
|
+
serverMessageId: Number(serverMessageId),
|
|
70
|
+
...(name ? { newsletterName: name } : {}),
|
|
71
|
+
...(accessibilityText ? { accessibilityText } : {})
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const linkSticker = ({ url, title, area, linkType = StatusLinkType.RASTERIZED_LINK_PREVIEW } = {}) => {
|
|
77
|
+
if (typeof url !== 'string' || !url) {
|
|
78
|
+
throw new TypeError('linkSticker needs a url')
|
|
79
|
+
}
|
|
80
|
+
return annotation(area, {
|
|
81
|
+
tapAction: { tapUrl: url, ...(title ? { title } : {}) },
|
|
82
|
+
statusLinkType: linkType
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const musicSticker = ({
|
|
87
|
+
songId,
|
|
88
|
+
title,
|
|
89
|
+
author,
|
|
90
|
+
mediaId,
|
|
91
|
+
artworkDirectPath,
|
|
92
|
+
artworkSha256,
|
|
93
|
+
artworkEncSha256,
|
|
94
|
+
artworkMediaKey,
|
|
95
|
+
artistAttribution,
|
|
96
|
+
countryBlocklist,
|
|
97
|
+
isExplicit,
|
|
98
|
+
startTimeMs = 0,
|
|
99
|
+
derivedStartTimeMs,
|
|
100
|
+
durationMs,
|
|
101
|
+
area
|
|
102
|
+
} = {}) => {
|
|
103
|
+
if (!songId && !mediaId) {
|
|
104
|
+
throw new TypeError('musicSticker needs at least a songId or a musicContentMediaId')
|
|
105
|
+
}
|
|
106
|
+
const bytes = value => (value === undefined ? undefined : Buffer.isBuffer(value) ? value : Buffer.from(value, 'base64'))
|
|
107
|
+
const embeddedMusic = {
|
|
108
|
+
...(songId ? { songId: String(songId) } : {}),
|
|
109
|
+
...(mediaId ? { musicContentMediaId: String(mediaId) } : {}),
|
|
110
|
+
...(title ? { title } : {}),
|
|
111
|
+
...(author ? { author } : {}),
|
|
112
|
+
...(artistAttribution ? { artistAttribution } : {}),
|
|
113
|
+
...(artworkDirectPath ? { artworkDirectPath } : {}),
|
|
114
|
+
...(isExplicit === undefined ? {} : { isExplicit: !!isExplicit }),
|
|
115
|
+
musicSongStartTimeInMs: Number(startTimeMs),
|
|
116
|
+
...(derivedStartTimeMs === undefined ? {} : { derivedContentStartTimeInMs: Number(derivedStartTimeMs) }),
|
|
117
|
+
...(durationMs === undefined ? {} : { overlapDurationInMs: Number(durationMs) })
|
|
118
|
+
}
|
|
119
|
+
for (const [key, value] of [
|
|
120
|
+
['artworkSha256', artworkSha256],
|
|
121
|
+
['artworkEncSha256', artworkEncSha256],
|
|
122
|
+
['artworkMediaKey', artworkMediaKey],
|
|
123
|
+
['countryBlocklist', countryBlocklist]
|
|
124
|
+
]) {
|
|
125
|
+
const buffer = bytes(value)
|
|
126
|
+
if (buffer) {
|
|
127
|
+
embeddedMusic[key] = buffer
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return annotation(area, { embeddedContent: { embeddedMusic } })
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const messageSticker = ({ stanzaId, message, area } = {}) => {
|
|
134
|
+
if (!message) {
|
|
135
|
+
throw new TypeError('messageSticker needs the message it embeds')
|
|
136
|
+
}
|
|
137
|
+
return annotation(area, {
|
|
138
|
+
embeddedContent: { embeddedMessage: { ...(stanzaId ? { stanzaId } : {}), message } }
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const ACTIONS = ['location', 'newsletter', 'embeddedAction', 'tapAction']
|
|
143
|
+
|
|
144
|
+
export const normalizeStickers = (stickers) => {
|
|
145
|
+
const list = Array.isArray(stickers) ? stickers : [stickers]
|
|
146
|
+
return list.filter(Boolean).map((sticker, index) => {
|
|
147
|
+
const vertices = sticker.polygonVertices
|
|
148
|
+
if (!Array.isArray(vertices) || vertices.length !== 4) {
|
|
149
|
+
throw new TypeError(`sticker ${index} needs four polygonVertices, the client reads corner 0 and corner 2`)
|
|
150
|
+
}
|
|
151
|
+
const actions = ACTIONS.filter(name => sticker[name] !== undefined && sticker[name] !== null)
|
|
152
|
+
if (actions.length > 1) {
|
|
153
|
+
throw new TypeError(`sticker ${index} sets ${actions.join(' and ')}, but the client reads only one action per sticker`)
|
|
154
|
+
}
|
|
155
|
+
return proto.InteractiveAnnotation.fromObject(sticker)
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const readStickers = (message) => {
|
|
160
|
+
const media = message?.imageMessage ?? message?.videoMessage ?? message
|
|
161
|
+
const annotations = media?.interactiveAnnotations
|
|
162
|
+
if (!Array.isArray(annotations) || !annotations.length) {
|
|
163
|
+
return []
|
|
164
|
+
}
|
|
165
|
+
return annotations.map(item => {
|
|
166
|
+
const [topLeft, , bottomRight] = item.polygonVertices ?? []
|
|
167
|
+
const music = item.embeddedContent?.embeddedMusic
|
|
168
|
+
return {
|
|
169
|
+
kind: item.location
|
|
170
|
+
? 'location'
|
|
171
|
+
: item.newsletter
|
|
172
|
+
? 'channel'
|
|
173
|
+
: item.tapAction
|
|
174
|
+
? 'link'
|
|
175
|
+
: music
|
|
176
|
+
? 'music'
|
|
177
|
+
: item.embeddedContent?.embeddedMessage
|
|
178
|
+
? 'message'
|
|
179
|
+
: 'unknown',
|
|
180
|
+
area: topLeft && bottomRight
|
|
181
|
+
? { x: topLeft.x, y: topLeft.y, width: bottomRight.x - topLeft.x, height: bottomRight.y - topLeft.y }
|
|
182
|
+
: undefined,
|
|
183
|
+
location: item.location ?? undefined,
|
|
184
|
+
channel: item.newsletter ?? undefined,
|
|
185
|
+
link: item.tapAction ? { url: item.tapAction.tapUrl, title: item.tapAction.title, linkType: item.statusLinkType } : undefined,
|
|
186
|
+
music: music ? { songId: music.songId, title: music.title, author: music.author } : undefined,
|
|
187
|
+
message: item.embeddedContent?.embeddedMessage ?? undefined,
|
|
188
|
+
annotation: item
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export const MusicMessageStyle = Object.freeze({ UNKNOWN: 0, VINYL: 1 })
|
|
194
|
+
|
|
195
|
+
export const MUSIC_ALLOWED_HOSTS = Object.freeze([
|
|
196
|
+
'.whatsapp.net',
|
|
197
|
+
'.whatsapp.com',
|
|
198
|
+
'.fbcdn.net',
|
|
199
|
+
'.facebook.com',
|
|
200
|
+
'.instagram.com',
|
|
201
|
+
'.cdninstagram.com'
|
|
202
|
+
])
|
|
203
|
+
|
|
204
|
+
export const isMusicHostAllowed = (value) => {
|
|
205
|
+
let host
|
|
206
|
+
try {
|
|
207
|
+
host = new URL(String(value)).hostname.toLowerCase()
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return false
|
|
211
|
+
}
|
|
212
|
+
return MUSIC_ALLOWED_HOSTS.some(suffix => host.endsWith(suffix) || host === suffix.slice(1))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const assertMusicHost = (value, label) => {
|
|
216
|
+
if (value === undefined) {
|
|
217
|
+
return undefined
|
|
218
|
+
}
|
|
219
|
+
if (!isMusicHostAllowed(value)) {
|
|
220
|
+
throw new TypeError(
|
|
221
|
+
`${label} must be hosted on ${MUSIC_ALLOWED_HOSTS.join(', ')} — the client refuses any other host `
|
|
222
|
+
+ 'and draws nothing. Both uris come from Meta music catalog entries, so carry them over from a '
|
|
223
|
+
+ 'message you received rather than pointing at your own file'
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
return value
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const embeddedMusicOf = (options) => musicSticker(options).embeddedContent.embeddedMusic
|
|
230
|
+
|
|
231
|
+
export const buildMusicMessage = ({ songUri, artworkUri, style = MusicMessageStyle.VINYL, contextInfo, ...music } = {}) =>
|
|
232
|
+
trimUndefined({
|
|
233
|
+
embeddedMusic: embeddedMusicOf(music),
|
|
234
|
+
songUri: assertMusicHost(songUri, 'songUri'),
|
|
235
|
+
artworkUri: assertMusicHost(artworkUri, 'artworkUri'),
|
|
236
|
+
style,
|
|
237
|
+
contextInfo
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
export const readMusicMessage = (msg) => {
|
|
241
|
+
const message = msg?.message ?? msg
|
|
242
|
+
const music = message?.musicMessage
|
|
243
|
+
if (!music) {
|
|
244
|
+
return null
|
|
245
|
+
}
|
|
246
|
+
const embedded = music.embeddedMusic ?? {}
|
|
247
|
+
return {
|
|
248
|
+
songId: embedded.songId,
|
|
249
|
+
mediaId: embedded.musicContentMediaId,
|
|
250
|
+
title: embedded.title,
|
|
251
|
+
author: embedded.author,
|
|
252
|
+
artistAttribution: embedded.artistAttribution,
|
|
253
|
+
isExplicit: embedded.isExplicit,
|
|
254
|
+
startTimeMs: embedded.musicSongStartTimeInMs,
|
|
255
|
+
durationMs: embedded.overlapDurationInMs,
|
|
256
|
+
songUri: music.songUri,
|
|
257
|
+
artworkUri: music.artworkUri,
|
|
258
|
+
style: music.style,
|
|
259
|
+
embeddedMusic: embedded
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { proto } from '../../WAProto/index.js';
|
|
2
|
-
import type { BaileysEventEmitter, BaileysEventMap, Contact } from '../Types
|
|
3
|
-
import type { ILogger } from './logger
|
|
2
|
+
import type { BaileysEventEmitter, BaileysEventMap, Contact } from '../Types';
|
|
3
|
+
import type { ILogger } from './logger';
|
|
4
4
|
export type ContactsUpsertResult = {
|
|
5
5
|
event: 'contacts.upsert';
|
|
6
6
|
data: Contact[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SignalKeyStoreWithTransaction } from '../Types
|
|
2
|
-
import type { BinaryNode } from '../WABinary
|
|
1
|
+
import type { SignalKeyStoreWithTransaction } from '../Types';
|
|
2
|
+
import type { BinaryNode } from '../WABinary';
|
|
3
3
|
/** Sentinel key under `tctoken` store holding a JSON array of tracked storage JIDs for cross-session pruning. */
|
|
4
4
|
export declare const TC_TOKEN_INDEX_KEY = "__index";
|
|
5
5
|
/** Read the persisted tctoken JID index and return its entries (never contains the sentinel key itself). */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidMetaAI, isLidUser, isPnUser, jidNormalizedUser } from '../WABinary
|
|
1
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidMetaAI, isLidUser, isPnUser, jidNormalizedUser } from '../WABinary';
|
|
2
2
|
// Same phone-number pattern as WABinary's isJidBot, applied against the user
|
|
3
3
|
// part so the check is invariant to @c.us ↔ @s.whatsapp.net normalization.
|
|
4
4
|
const BOT_PHONE_REGEX = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* QIRO utility module. */
|
|
2
|
+
export declare class TTLCache<T = any> {
|
|
3
|
+
constructor(options?: {
|
|
4
|
+
/** lifetime in seconds, the same unit node-cache used; 0 or omitted means no expiry */
|
|
5
|
+
stdTTL?: number;
|
|
6
|
+
/** ceiling on entries, the oldest is evicted once it is reached */
|
|
7
|
+
maxKeys?: number;
|
|
8
|
+
/** alias for maxKeys */
|
|
9
|
+
max?: number;
|
|
10
|
+
/** lifetime in milliseconds, takes precedence over stdTTL */
|
|
11
|
+
ttl?: number;
|
|
12
|
+
});
|
|
13
|
+
get(key: string | number): T | undefined;
|
|
14
|
+
set(key: string | number, value: T, ttl?: number): boolean;
|
|
15
|
+
has(key: string | number): boolean;
|
|
16
|
+
del(keys: string | number | Array<string | number>): number;
|
|
17
|
+
take(key: string | number): T | undefined;
|
|
18
|
+
mget(keys: Array<string | number>): Record<string, T>;
|
|
19
|
+
mset(list: Array<{ key: string | number; value?: T; val?: T; ttl?: number }>): boolean;
|
|
20
|
+
keys(): string[];
|
|
21
|
+
flushAll(): void;
|
|
22
|
+
getStats(): { hits: number; misses: number; keys: number; ksize: number; vsize: number };
|
|
23
|
+
close(): void;
|
|
24
|
+
on(): this;
|
|
25
|
+
off(): this;
|
|
26
|
+
removeAllListeners(): this;
|
|
27
|
+
readonly size: number;
|
|
28
|
+
}
|
|
29
|
+
export default TTLCache;
|