fix: handle invalid signatureKeyPublic types in sender-key-state AND fix handling chain key objects for skmsg group message decryption (#1760)

* fix: handle invalid signatureKeyPublic types in sender-key-state

- added extra check to ensure signatureKeyPublic is either a base64 string or a Buffer
- fallback to empty buffer when unexpected object type is received
- prevents ERR_INVALID_ARG_TYPE error in Buffer.from

* fix: lint

* adjusted based on  @jlucaso1 recommmendation

* fix: handle chain key objects for skmsg group message decryption

previously, some sender chain keys were stored or retrieved as plain objects
(e.g. { '0': 85, '1': 100, ... }) instead of Buffers. this caused
"ERR_INVALID_ARG_TYPE" during initial decryption of skmsg group messages.

this fixes any chain key object is converted to a proper Buffer
before being passed to SenderChainKey.

* fix: add more robust checks and fallbacks

* hacky fix(sender-key-state): normalize signing pubkey as Buffer with 0x05 prefix

a little hacky fix that ensures getSigningKeyPublic always returns a proper Buffer to satisfy libsignal.
adds a fallback to prepend 0x05 when only a 32-byte key is present, avoiding
"Invalid public key" errors and TS type issues around Uint8Array vs Buffer.
This commit is contained in:
αѕтяσχ11
2025-09-13 09:04:26 +01:00
committed by GitHub
parent 88ec0c4db2
commit f0dcc30e0f
3 changed files with 46 additions and 30 deletions
+2 -2
View File
@@ -1159,11 +1159,11 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const altServer = jidDecode(alt)?.server
const lidMapping = signalRepository.getLIDMappingStore()
if (altServer === 'lid') {
if (typeof await lidMapping.getPNForLID(alt) == "string") {
if (typeof (await lidMapping.getPNForLID(alt)) === 'string') {
await lidMapping.storeLIDPNMapping(alt, msg.key.participant || msg.key.remoteJid!)
}
} else {
if (typeof await lidMapping.getLIDForPN(alt) == "string") {
if (typeof (await lidMapping.getLIDForPN(alt)) === 'string') {
await lidMapping.storeLIDPNMapping(msg.key.participant || msg.key.remoteJid!, alt)
}
}