Commit 262c930
fix(media): correct mediaKey Uint8Array conversion from PostgreSQL JSONB
PostgreSQL JSONB stores object keys lexicographically, so a Uint8Array
serialized as {0:b0,1:b1,...,9:b9,10:b10,...} is retrieved with keys in
order "0","1","10","11",...,"19","2","20",...,"9". Using Object.values()
on this gives bytes in the WRONG order, causing Baileys HKDF/AES-GCM to
fail with "Unsupported state or unable to authenticate data".
Fix: sort keys numerically before constructing Uint8Array, and also handle
base64-encoded string mediaKey (from HTTP request bodies).
This matches OwnPilot retryMediaFromMetadata() which uses:
new Uint8Array(Buffer.from(base64mediaKey, 'base64'))
Before: updateMediaMessage → "Unsupported state or unable to authenticate data"
After: updateMediaMessage → re-upload → fresh CDN URL → download ✅
Tested: 2312ZL_2_A_V1.SOR (expired CDN, fromMe=true) → 21058 bytes ✅
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent f268571 commit 262c930
File tree
1 file changed
+15
-2
lines changed- src/api/integrations/channel/whatsapp
1 file changed
+15
-2
lines changedLines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3889 | 3889 | | |
3890 | 3890 | | |
3891 | 3891 | | |
3892 | | - | |
3893 | | - | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
| 3905 | + | |
| 3906 | + | |
3894 | 3907 | | |
3895 | 3908 | | |
3896 | 3909 | | |
| |||
0 commit comments