sauruspro-bail 0.0.0-stage → 5.0.0
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/README.md +129 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6754 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +242946 -0
- package/docs/CHANGELOG.md +22 -0
- package/docs/NEWSLETTER-STATUS.md +120 -0
- package/docs/SPR.md +51 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +131 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/MessageBuilder.js +3729 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.js +1198 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/graphql.js +716 -0
- package/lib/Socket/groups.js +374 -0
- package/lib/Socket/index.js +92 -0
- package/lib/Socket/interop.js +463 -0
- package/lib/Socket/luxu.js +387 -0
- package/lib/Socket/message-builder.js +556 -0
- package/lib/Socket/messages-recv.js +1916 -0
- package/lib/Socket/messages-send.js +1516 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +641 -0
- package/lib/Socket/privacy.js +318 -0
- package/lib/Socket/socket.js +1115 -0
- package/lib/Socket/username.js +236 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +85 -0
- package/lib/Store/make-in-memory-store.js +244 -0
- package/lib/Store/make-ordered-dictionary.js +75 -0
- package/lib/Store/object-repository.js +32 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +111 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +350 -0
- package/lib/Utils/dinolith-spr.d.ts +26 -0
- package/lib/Utils/dinolith-spr.js +521 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +26 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +870 -0
- package/lib/Utils/messages.js +1394 -0
- package/lib/Utils/newsletter-status.d.ts +163 -0
- package/lib/Utils/newsletter-status.js +738 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sticker.js +133 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/Utils/validate-connection.js +203 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +98 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.js +151 -0
- package/lib/WAUSync/USyncUser.js +56 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.js +67 -0
- package/package.json +147 -5
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 5.0.0
|
|
4
|
+
**Owner: Saurus / Dinolith**
|
|
5
|
+
|
|
6
|
+
### Added
|
|
7
|
+
- **Newsletter Status**: `sendNewsletterStatus`, `sendNewsletterStatusReaction`, `revokeNewsletterStatus`, `getNewsletterStatuses`, `getNewsletterStatusUpdates`, plus `sock.newsletter.{sendStatus, reactToStatus, revokeStatus, fetchStatuses, fetchStatusUpdates}`.
|
|
8
|
+
- File tipe `newsletter-status.d.ts` dan `dinolith-spr.d.ts`.
|
|
9
|
+
- Dokumentasi di folder `docs/`.
|
|
10
|
+
- Export `sPR` / `selectiveRelay` dari entry utama.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- `dinolith-spr.js` mengimpor `encodeSignedDeviceIdentity` dari `generics.js` (tidak ada), sehingga seluruh paket gagal load. Sekarang dari `validate-connection.js`.
|
|
14
|
+
- SPR: disamakan penuh dengan SPR diezyxhao-baileys 1.4.0 (logika identik, hanya CJS → ESM), termasuk fallback `conn.user` saat `authState.creds.me` kosong.
|
|
15
|
+
- `package.json`: `"type": "module"` ditambahkan (kode ESM), duplikat `lru-cache` di devDependencies dihapus.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- Versi `3.0.0` → `5.0.0`, author/owner `Saurus / Dinolith`.
|
|
19
|
+
- README ditulis ulang, banner menampilkan versi & owner.
|
|
20
|
+
|
|
21
|
+
### Notes
|
|
22
|
+
- Newsletter status diport dari diezyxhao-baileys 1.4.0 ke ESM; tidak mengubah `sendMessage`.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# 📢 Newsletter Status
|
|
2
|
+
|
|
3
|
+
Kirim, react, hapus, dan ambil **status Channel (newsletter)** WhatsApp.
|
|
4
|
+
Tersedia sejak **v5.0.0**. Kamu harus **admin/owner** channel tersebut.
|
|
5
|
+
|
|
6
|
+
Semua fungsi tersedia dalam 3 cara:
|
|
7
|
+
|
|
8
|
+
| Cara | Contoh |
|
|
9
|
+
|---|---|
|
|
10
|
+
| `sock.newsletter.*` | `sock.newsletter.sendStatus(jid, content)` |
|
|
11
|
+
| `sock.*` langsung | `sock.sendNewsletterStatus(jid, content)` |
|
|
12
|
+
| Import factory | `makeNewsletterStatusSender(sock, config)` |
|
|
13
|
+
|
|
14
|
+
JID newsletter harus berakhiran `@newsletter`, kalau tidak akan melempar `TypeError`.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 1. Kirim status
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
await sock.newsletter.sendStatus(jid, content, options?)
|
|
22
|
+
// atau object style:
|
|
23
|
+
await sock.newsletter.sendStatus({ jid, content, ...options })
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Content
|
|
27
|
+
|
|
28
|
+
| Jenis | Contoh |
|
|
29
|
+
|---|---|
|
|
30
|
+
| Teks | `{ text: 'Halo' }` |
|
|
31
|
+
| Gambar | `{ image: { url }, caption }` |
|
|
32
|
+
| Video | `{ video: { url }, caption }` |
|
|
33
|
+
| GIF | `{ video: { url }, gifPlayback: true }` |
|
|
34
|
+
| Audio | `{ audio: { url }, mimetype: 'audio/mpeg' }` |
|
|
35
|
+
|
|
36
|
+
Dokumen dan sticker **tidak didukung** (akan melempar error).
|
|
37
|
+
Hanya `image` dan `video` yang dipublish WhatsApp Web sendiri; audio/gif bisa ditolak server (ada log warning).
|
|
38
|
+
|
|
39
|
+
### Options
|
|
40
|
+
|
|
41
|
+
| Option | Default | Keterangan |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| `messageId` | auto | ID pesan kustom |
|
|
44
|
+
| `statusAttribution` | `true` | Tambah atribusi `NEWSLETTER_STATUS` + `canBeReshared` |
|
|
45
|
+
| `interactionType` | - | `question` / `question_response` / `question_reshare` |
|
|
46
|
+
| `parentServerId` | - | Wajib untuk `question_reshare` |
|
|
47
|
+
| `responseServerId` | - | Wajib untuk `question_reshare` |
|
|
48
|
+
| `aiContent` | - | Tandai konten AI |
|
|
49
|
+
| `mediaHandle` / `mediaId` | auto | Handle media hasil upload |
|
|
50
|
+
| `ackTimeoutMs` | `20000` | Timeout menunggu ack server |
|
|
51
|
+
| `resolveServerId` | `true` | Tunggu echo server untuk dapat `serverId`. `false` = lebih cepat |
|
|
52
|
+
| `serverIdTimeoutMs` | `8000` | Timeout menunggu echo |
|
|
53
|
+
|
|
54
|
+
### Hasil
|
|
55
|
+
|
|
56
|
+
Mengembalikan `WebMessageInfo` dengan field tambahan:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
{
|
|
60
|
+
newsletterStatusServerId, // number, dipakai untuk react/revoke
|
|
61
|
+
newsletterStatusAck, // ack terurai
|
|
62
|
+
newsletterStatusResponse, // node mentah
|
|
63
|
+
newsletterStatusDelivered // node echo (jika resolveServerId)
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Reshare status channel ke status sendiri
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
await sock.newsletter.sendStatus(jid, {
|
|
71
|
+
text: 'Lihat ini',
|
|
72
|
+
newsletterStatus: { newsletterJid: '120363...@newsletter', messageId: 150 }
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 2. React
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
await sock.newsletter.reactToStatus(jid, parentServerId, '🔥')
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`parentServerId` harus integer antara **99 dan 2147476647**.
|
|
85
|
+
|
|
86
|
+
## 3. Hapus (revoke)
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
await sock.newsletter.revokeStatus(jid, statusId)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 4. Ambil status
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
const list = await sock.newsletter.fetchStatuses(jid, { count: 20, before, after })
|
|
96
|
+
const updates = await sock.newsletter.fetchStatusUpdates(jid, { count: 20, since })
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Entry berisi: `id`, `serverId`, `t`, `type`, `mediaType`, `reactionCounts`, `viewsCount`, `responsesCount`, `message`, dll. Lihat `lib/Utils/newsletter-status.d.ts`.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Helper tambahan (named export)
|
|
104
|
+
|
|
105
|
+
`buildNewsletterStatusNode`, `buildNewsletterStatusReactionNode`, `buildNewsletterStatusRevokeNode`, `parseNewsletterStatusAck`, `toNewsletterServerId`, `getNewsletterStatusMediaType`, `makeNewsletterStatusAttribution`, `NEWSLETTER_SERVER_ID_MIN/MAX`.
|
|
106
|
+
|
|
107
|
+
## Error umum
|
|
108
|
+
|
|
109
|
+
| Pesan | Penyebab |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `Newsletter status target must be a @newsletter JID` | JID bukan newsletter |
|
|
112
|
+
| `Not authenticated` | Socket belum login |
|
|
113
|
+
| `... is not a newsletter server id` | serverId di luar 99..2147476647 |
|
|
114
|
+
| `Native newsletter status supports text, image, video, gif, and audio` | Kirim dokumen/sticker |
|
|
115
|
+
| Timeout ack | Server tidak membalas dalam `ackTimeoutMs` |
|
|
116
|
+
|
|
117
|
+
## Catatan
|
|
118
|
+
|
|
119
|
+
- Fitur bergantung pada protokol WhatsApp yang bisa berubah sewaktu-waktu.
|
|
120
|
+
- Tidak mengubah perilaku `sendMessage` biasa.
|
package/docs/SPR.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# 🎯 SPR (Selective Relay)
|
|
2
|
+
|
|
3
|
+
Kirim pesan dengan kontrol **device/JID mana yang menerima kunci asli**, sisanya menerima kunci palsu sehingga tidak bisa membuka pesan.
|
|
4
|
+
|
|
5
|
+
> Modul SPR dibuat oleh **Nixel**. Watermark di `lib/Utils/dinolith-spr.js` wajib dipertahankan. Lisensi aslinya melarang reupload/resell sebagai produk mandiri dan mengaku sebagai karya sendiri.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
await sock.sPR(jid, message, options)
|
|
9
|
+
// alias
|
|
10
|
+
await sock.relayMessageSelective(jid, message, options)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Juga bisa di-import: `import { sPR, selectiveRelay } from 'sauruspro-bail'`
|
|
14
|
+
(`sPR(conn, jid, message, options)`, parameter pertama adalah socket).
|
|
15
|
+
|
|
16
|
+
## Options
|
|
17
|
+
|
|
18
|
+
| Option | Default | Keterangan |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| `mode` | `"exclude"` | `exclude`: target **tidak** menerima. `include`: **hanya** target yang menerima |
|
|
21
|
+
| `target` | `[]` | Daftar JID (PN atau LID) |
|
|
22
|
+
| `targetMe` | - | `true/false` memaksa device milik sendiri menerima/tidak |
|
|
23
|
+
| `deviceMode` | `"all"` | `all` / `primary` (device 0) / `secondary` (device lain) |
|
|
24
|
+
| `hideDecryptFail` | `true` | Sembunyikan placeholder gagal-dekripsi |
|
|
25
|
+
| `messageId` | auto | ID pesan kustom |
|
|
26
|
+
| `additionalAttributes` / `additionalNodes` | - | Atribut/node tambahan pada stanza |
|
|
27
|
+
| `useUserDevicesCache` / `useCachedGroupMetadata` | - | Pakai cache |
|
|
28
|
+
| `statusJidList` | - | Untuk status broadcast |
|
|
29
|
+
|
|
30
|
+
## Contoh
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// Kirim ke grup, tapi sembunyikan dari 1 orang
|
|
34
|
+
await sock.sPR(groupJid, { conversation: 'rahasia' }, {
|
|
35
|
+
mode: 'exclude',
|
|
36
|
+
target: ['6281234567890@s.whatsapp.net']
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// Hanya kirim ke 1 orang di grup
|
|
40
|
+
await sock.sPR(groupJid, { conversation: 'khusus kamu' }, {
|
|
41
|
+
mode: 'include',
|
|
42
|
+
target: ['6281234567890@s.whatsapp.net']
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Perubahan v5.0.0
|
|
47
|
+
|
|
48
|
+
- `lib/Utils/dinolith-spr.js` diganti dengan port langsung dari `spr.js` diezyxhao-baileys 1.4.0. Logika **identik**; yang berubah hanya sintaks modul (CJS → ESM).
|
|
49
|
+
- Termasuk fallback `me.id` / `me.lid` ke `conn.user` (tidak crash saat `authState.creds.me` kosong).
|
|
50
|
+
- `sPR` & `selectiveRelay` diexport dari entry utama.
|
|
51
|
+
- `encodeSignedDeviceIdentity` diimpor dari `validate-connection.js` (sebelumnya salah dari `generics.js` sehingga paket gagal load).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const major = parseInt(process.versions.node.split('.')[0], 10);
|
|
2
|
+
|
|
3
|
+
if (major < 20) {
|
|
4
|
+
console.error(
|
|
5
|
+
`\n❌ This package requires Node.js 20+ to run reliably.\n` +
|
|
6
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
7
|
+
` Please upgrade to Node.js 20+ to proceed.\n`
|
|
8
|
+
);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
3
|
+
import { Browsers } from '../Utils/browser-utils.js';
|
|
4
|
+
import logger from '../Utils/logger.js';
|
|
5
|
+
const version = [2, 3000, 1043857760];
|
|
6
|
+
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
|
+
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
8
|
+
export const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
9
|
+
export const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
|
|
10
|
+
export const DEF_CALLBACK_PREFIX = 'CB:';
|
|
11
|
+
export const DEF_TAG_PREFIX = 'TAG:';
|
|
12
|
+
export const PHONE_CONNECTION_CB = 'CB:Pong';
|
|
13
|
+
export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
|
|
14
|
+
export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
|
|
15
|
+
export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
|
|
16
|
+
export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
|
|
17
|
+
export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
18
|
+
/** Status messages older than 24 hours are considered expired */
|
|
19
|
+
export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60;
|
|
20
|
+
/** WA Web enforces a 14-day maximum age for placeholder resend requests */
|
|
21
|
+
export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60;
|
|
22
|
+
export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
23
|
+
export const DICT_VERSION = 3;
|
|
24
|
+
export const KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
25
|
+
export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); // last is "DICT_VERSION"
|
|
26
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
27
|
+
export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
28
|
+
export const WA_CERT_DETAILS = {
|
|
29
|
+
SERIAL: 0,
|
|
30
|
+
ISSUER: 'WhatsAppLongTerm1',
|
|
31
|
+
PUBLIC_KEY: Buffer.from('142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b', 'hex')
|
|
32
|
+
};
|
|
33
|
+
export const PROCESSABLE_HISTORY_TYPES = [
|
|
34
|
+
proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
35
|
+
proto.HistorySync.HistorySyncType.PUSH_NAME,
|
|
36
|
+
proto.HistorySync.HistorySyncType.RECENT,
|
|
37
|
+
proto.HistorySync.HistorySyncType.FULL,
|
|
38
|
+
proto.HistorySync.HistorySyncType.ON_DEMAND,
|
|
39
|
+
proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
|
|
40
|
+
proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
|
|
41
|
+
];
|
|
42
|
+
export const DEFAULT_CACHE_TTLS = {
|
|
43
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
44
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
45
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
46
|
+
USER_DEVICES: 5 * 60 // 5 minutes
|
|
47
|
+
};
|
|
48
|
+
export const DEFAULT_CONNECTION_CONFIG = {
|
|
49
|
+
version: version,
|
|
50
|
+
browser: Browsers.macOS('Chrome'),
|
|
51
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
52
|
+
connectTimeoutMs: 20000,
|
|
53
|
+
keepAliveIntervalMs: 30000,
|
|
54
|
+
logger: logger.child({ class: 'baileys' }),
|
|
55
|
+
emitOwnEvents: true,
|
|
56
|
+
defaultQueryTimeoutMs: 60000,
|
|
57
|
+
customUploadHosts: [],
|
|
58
|
+
retryRequestDelayMs: 250,
|
|
59
|
+
maxMsgRetryCount: 5,
|
|
60
|
+
fireInitQueries: true,
|
|
61
|
+
auth: undefined,
|
|
62
|
+
autoFollow: true,
|
|
63
|
+
markOnlineOnConnect: true,
|
|
64
|
+
aiLabel: true,
|
|
65
|
+
syncFullHistory: true,
|
|
66
|
+
patchMessageBeforeSending: msg => msg,
|
|
67
|
+
shouldSyncHistoryMessage: ({ syncType }) => {
|
|
68
|
+
return syncType !== proto.HistorySync.HistorySyncType.FULL;
|
|
69
|
+
},
|
|
70
|
+
shouldIgnoreJid: () => false,
|
|
71
|
+
linkPreviewImageThumbnailWidth: 192,
|
|
72
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
73
|
+
generateHighQualityLinkPreview: false,
|
|
74
|
+
enableAutoSessionRecreation: true,
|
|
75
|
+
enableRecentMessageCache: true,
|
|
76
|
+
options: {},
|
|
77
|
+
appStateMacVerification: {
|
|
78
|
+
patch: false,
|
|
79
|
+
snapshot: false
|
|
80
|
+
},
|
|
81
|
+
countryCode: 'US',
|
|
82
|
+
getMessage: async () => undefined,
|
|
83
|
+
cachedGroupMetadata: async () => undefined,
|
|
84
|
+
makeSignalRepository: makeLibSignalRepository
|
|
85
|
+
};
|
|
86
|
+
export const MEDIA_PATH_MAP = {
|
|
87
|
+
image: '/mms/image',
|
|
88
|
+
video: '/mms/video',
|
|
89
|
+
document: '/mms/document',
|
|
90
|
+
audio: '/mms/audio',
|
|
91
|
+
sticker: '/mms/image',
|
|
92
|
+
'thumbnail-link': '/mms/image',
|
|
93
|
+
'product-catalog-image': '/product/image',
|
|
94
|
+
'md-app-state': '',
|
|
95
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
96
|
+
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
97
|
+
};
|
|
98
|
+
export const MEDIA_HKDF_KEY_MAPPING = {
|
|
99
|
+
audio: 'Audio',
|
|
100
|
+
document: 'Document',
|
|
101
|
+
gif: 'Video',
|
|
102
|
+
image: 'Image',
|
|
103
|
+
ppic: '',
|
|
104
|
+
product: 'Image',
|
|
105
|
+
ptt: 'Audio',
|
|
106
|
+
sticker: 'Image',
|
|
107
|
+
video: 'Video',
|
|
108
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
109
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
110
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
111
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
112
|
+
'md-msg-hist': 'History',
|
|
113
|
+
'md-app-state': 'App State',
|
|
114
|
+
'product-catalog-image': '',
|
|
115
|
+
'payment-bg-image': 'Payment Background',
|
|
116
|
+
ptv: 'Video',
|
|
117
|
+
'biz-cover-photo': 'Image'
|
|
118
|
+
};
|
|
119
|
+
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
|
|
120
|
+
/** 120s timeout for history sync stall detection, same as WA Web's handleChunkProgress / restartPausedTimer (g = 120) */
|
|
121
|
+
export const HISTORY_SYNC_PAUSED_TIMEOUT_MS = 120000;
|
|
122
|
+
export const MIN_PREKEY_COUNT = 5;
|
|
123
|
+
export const INITIAL_PREKEY_COUNT = 812;
|
|
124
|
+
export const UPLOAD_TIMEOUT = 30000; // 30 seconds
|
|
125
|
+
export const TimeMs = {
|
|
126
|
+
Minute: 60 * 1000,
|
|
127
|
+
Hour: 60 * 60 * 1000,
|
|
128
|
+
Day: 24 * 60 * 60 * 1000,
|
|
129
|
+
Week: 7 * 24 * 60 * 60 * 1000
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class CiphertextMessage {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.UNSUPPORTED_VERSION = 1;
|
|
4
|
+
this.CURRENT_VERSION = 3;
|
|
5
|
+
this.WHISPER_TYPE = 2;
|
|
6
|
+
this.PREKEY_TYPE = 3;
|
|
7
|
+
this.SENDERKEY_TYPE = 4;
|
|
8
|
+
this.SENDERKEY_DISTRIBUTION_TYPE = 5;
|
|
9
|
+
this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ciphertext-message.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as keyhelper from './keyhelper.js';
|
|
2
|
+
import { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
+
import { SenderKeyName } from './sender-key-name.js';
|
|
4
|
+
import { SenderKeyRecord } from './sender-key-record.js';
|
|
5
|
+
export class GroupSessionBuilder {
|
|
6
|
+
constructor(senderKeyStore) {
|
|
7
|
+
this.senderKeyStore = senderKeyStore;
|
|
8
|
+
}
|
|
9
|
+
async process(senderKeyName, senderKeyDistributionMessage) {
|
|
10
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
11
|
+
senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey());
|
|
12
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
13
|
+
}
|
|
14
|
+
async create(senderKeyName) {
|
|
15
|
+
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
|
|
16
|
+
if (senderKeyRecord.isEmpty()) {
|
|
17
|
+
const keyId = keyhelper.generateSenderKeyId();
|
|
18
|
+
const senderKey = keyhelper.generateSenderKey();
|
|
19
|
+
const signingKey = keyhelper.generateSenderSigningKey();
|
|
20
|
+
senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey);
|
|
21
|
+
await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
|
|
22
|
+
}
|
|
23
|
+
const state = senderKeyRecord.getSenderKeyState();
|
|
24
|
+
if (!state) {
|
|
25
|
+
throw new Error('No session state available');
|
|
26
|
+
}
|
|
27
|
+
return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=group-session-builder.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { decrypt, encrypt } from 'libsignal/src/crypto.js';
|
|
2
|
+
import { SenderKeyMessage } from './sender-key-message.js';
|
|
3
|
+
import { SenderKeyName } from './sender-key-name.js';
|
|
4
|
+
import { SenderKeyRecord } from './sender-key-record.js';
|
|
5
|
+
import { SenderKeyState } from './sender-key-state.js';
|
|
6
|
+
export class GroupCipher {
|
|
7
|
+
constructor(senderKeyStore, senderKeyName) {
|
|
8
|
+
this.senderKeyStore = senderKeyStore;
|
|
9
|
+
this.senderKeyName = senderKeyName;
|
|
10
|
+
}
|
|
11
|
+
async encrypt(paddedPlaintext) {
|
|
12
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
13
|
+
if (!record) {
|
|
14
|
+
throw new Error('No SenderKeyRecord found for encryption');
|
|
15
|
+
}
|
|
16
|
+
const senderKeyState = record.getSenderKeyState();
|
|
17
|
+
if (!senderKeyState) {
|
|
18
|
+
throw new Error('No session to encrypt message');
|
|
19
|
+
}
|
|
20
|
+
const iteration = senderKeyState.getSenderChainKey().getIteration();
|
|
21
|
+
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
|
|
22
|
+
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
|
|
23
|
+
const senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
|
|
24
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
25
|
+
return senderKeyMessage.serialize();
|
|
26
|
+
}
|
|
27
|
+
async decrypt(senderKeyMessageBytes) {
|
|
28
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
29
|
+
if (!record) {
|
|
30
|
+
throw new Error('No SenderKeyRecord found for decryption');
|
|
31
|
+
}
|
|
32
|
+
const senderKeyMessage = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
|
|
33
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
|
|
34
|
+
if (!senderKeyState) {
|
|
35
|
+
throw new Error('No session found to decrypt message');
|
|
36
|
+
}
|
|
37
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
|
|
38
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
|
|
39
|
+
const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
|
|
40
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
41
|
+
return plaintext;
|
|
42
|
+
}
|
|
43
|
+
getSenderKey(senderKeyState, iteration) {
|
|
44
|
+
let senderChainKey = senderKeyState.getSenderChainKey();
|
|
45
|
+
if (senderChainKey.getIteration() > iteration) {
|
|
46
|
+
if (senderKeyState.hasSenderMessageKey(iteration)) {
|
|
47
|
+
const messageKey = senderKeyState.removeSenderMessageKey(iteration);
|
|
48
|
+
if (!messageKey) {
|
|
49
|
+
throw new Error('No sender message key found for iteration');
|
|
50
|
+
}
|
|
51
|
+
return messageKey;
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`);
|
|
54
|
+
}
|
|
55
|
+
if (iteration - senderChainKey.getIteration() > 2000) {
|
|
56
|
+
throw new Error('Over 2000 messages into the future!');
|
|
57
|
+
}
|
|
58
|
+
while (senderChainKey.getIteration() < iteration) {
|
|
59
|
+
senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey());
|
|
60
|
+
senderChainKey = senderChainKey.getNext();
|
|
61
|
+
}
|
|
62
|
+
senderKeyState.setSenderChainKey(senderChainKey.getNext());
|
|
63
|
+
return senderChainKey.getSenderMessageKey();
|
|
64
|
+
}
|
|
65
|
+
async getPlainText(iv, key, ciphertext) {
|
|
66
|
+
try {
|
|
67
|
+
return decrypt(key, ciphertext, iv);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
throw new Error('InvalidMessageException');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async getCipherText(iv, key, plaintext) {
|
|
74
|
+
try {
|
|
75
|
+
return encrypt(key, plaintext, iv);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
throw new Error('InvalidMessageException');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=group_cipher.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { GroupSessionBuilder } from './group-session-builder.js';
|
|
2
|
+
export { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
|
|
3
|
+
export { SenderKeyRecord } from './sender-key-record.js';
|
|
4
|
+
export { SenderKeyName } from './sender-key-name.js';
|
|
5
|
+
export { GroupCipher } from './group_cipher.js';
|
|
6
|
+
export { SenderKeyState } from './sender-key-state.js';
|
|
7
|
+
export { SenderKeyMessage } from './sender-key-message.js';
|
|
8
|
+
export { SenderMessageKey } from './sender-message-key.js';
|
|
9
|
+
export { SenderChainKey } from './sender-chain-key.js';
|
|
10
|
+
export { CiphertextMessage } from './ciphertext-message.js';
|
|
11
|
+
export * as keyhelper from './keyhelper.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as nodeCrypto from 'crypto';
|
|
2
|
+
import { generateKeyPair } from 'libsignal/src/curve.js';
|
|
3
|
+
export function generateSenderKey() {
|
|
4
|
+
return nodeCrypto.randomBytes(32);
|
|
5
|
+
}
|
|
6
|
+
export function generateSenderKeyId() {
|
|
7
|
+
return nodeCrypto.randomInt(2147483647);
|
|
8
|
+
}
|
|
9
|
+
export function generateSenderSigningKey(key) {
|
|
10
|
+
if (!key) {
|
|
11
|
+
key = generateKeyPair();
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
public: Buffer.from(key.pubKey),
|
|
15
|
+
private: Buffer.from(key.privKey)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=keyhelper.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { calculateMAC } from 'libsignal/src/crypto.js';
|
|
2
|
+
import { SenderMessageKey } from './sender-message-key.js';
|
|
3
|
+
export class SenderChainKey {
|
|
4
|
+
constructor(iteration, chainKey) {
|
|
5
|
+
this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
6
|
+
this.CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
7
|
+
this.iteration = iteration;
|
|
8
|
+
this.chainKey = Buffer.from(chainKey);
|
|
9
|
+
}
|
|
10
|
+
getIteration() {
|
|
11
|
+
return this.iteration;
|
|
12
|
+
}
|
|
13
|
+
getSenderMessageKey() {
|
|
14
|
+
return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
|
|
15
|
+
}
|
|
16
|
+
getNext() {
|
|
17
|
+
return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
|
|
18
|
+
}
|
|
19
|
+
getSeed() {
|
|
20
|
+
return this.chainKey;
|
|
21
|
+
}
|
|
22
|
+
getDerivative(seed, key) {
|
|
23
|
+
return calculateMAC(key, seed);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=sender-chain-key.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { proto } from '../../../WAProto/index.js';
|
|
2
|
+
import { CiphertextMessage } from './ciphertext-message.js';
|
|
3
|
+
export class SenderKeyDistributionMessage extends CiphertextMessage {
|
|
4
|
+
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
5
|
+
super();
|
|
6
|
+
if (serialized) {
|
|
7
|
+
try {
|
|
8
|
+
const message = serialized.slice(1);
|
|
9
|
+
const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON();
|
|
10
|
+
this.serialized = serialized;
|
|
11
|
+
this.id = distributionMessage.id;
|
|
12
|
+
this.iteration = distributionMessage.iteration;
|
|
13
|
+
this.chainKey =
|
|
14
|
+
typeof distributionMessage.chainKey === 'string'
|
|
15
|
+
? Buffer.from(distributionMessage.chainKey, 'base64')
|
|
16
|
+
: distributionMessage.chainKey;
|
|
17
|
+
this.signatureKey =
|
|
18
|
+
typeof distributionMessage.signingKey === 'string'
|
|
19
|
+
? Buffer.from(distributionMessage.signingKey, 'base64')
|
|
20
|
+
: distributionMessage.signingKey;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
throw new Error(String(e));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.iteration = iteration;
|
|
30
|
+
this.chainKey = chainKey;
|
|
31
|
+
this.signatureKey = signatureKey;
|
|
32
|
+
const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
|
|
33
|
+
id,
|
|
34
|
+
iteration,
|
|
35
|
+
chainKey,
|
|
36
|
+
signingKey: this.signatureKey
|
|
37
|
+
})).finish();
|
|
38
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
intsToByteHighAndLow(highValue, lowValue) {
|
|
42
|
+
return (((highValue << 4) | lowValue) & 0xff) % 256;
|
|
43
|
+
}
|
|
44
|
+
serialize() {
|
|
45
|
+
return this.serialized;
|
|
46
|
+
}
|
|
47
|
+
getType() {
|
|
48
|
+
return this.SENDERKEY_DISTRIBUTION_TYPE;
|
|
49
|
+
}
|
|
50
|
+
getIteration() {
|
|
51
|
+
return this.iteration;
|
|
52
|
+
}
|
|
53
|
+
getChainKey() {
|
|
54
|
+
return this.chainKey;
|
|
55
|
+
}
|
|
56
|
+
getSignatureKey() {
|
|
57
|
+
return this.signatureKey;
|
|
58
|
+
}
|
|
59
|
+
getId() {
|
|
60
|
+
return this.id;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=sender-key-distribution-message.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
|
|
2
|
+
import { proto } from '../../../WAProto/index.js';
|
|
3
|
+
import { CiphertextMessage } from './ciphertext-message.js';
|
|
4
|
+
export class SenderKeyMessage extends CiphertextMessage {
|
|
5
|
+
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
6
|
+
super();
|
|
7
|
+
this.SIGNATURE_LENGTH = 64;
|
|
8
|
+
if (serialized) {
|
|
9
|
+
const version = serialized[0];
|
|
10
|
+
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
11
|
+
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
12
|
+
const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
|
|
13
|
+
this.serialized = serialized;
|
|
14
|
+
this.messageVersion = (version & 0xff) >> 4;
|
|
15
|
+
this.keyId = senderKeyMessage.id;
|
|
16
|
+
this.iteration = senderKeyMessage.iteration;
|
|
17
|
+
this.ciphertext =
|
|
18
|
+
typeof senderKeyMessage.ciphertext === 'string'
|
|
19
|
+
? Buffer.from(senderKeyMessage.ciphertext, 'base64')
|
|
20
|
+
: senderKeyMessage.ciphertext;
|
|
21
|
+
this.signature = signature;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
25
|
+
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
26
|
+
const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
|
|
27
|
+
id: keyId,
|
|
28
|
+
iteration: iteration,
|
|
29
|
+
ciphertext: ciphertextBuffer
|
|
30
|
+
})).finish();
|
|
31
|
+
const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
|
|
32
|
+
this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
|
|
33
|
+
this.messageVersion = this.CURRENT_VERSION;
|
|
34
|
+
this.keyId = keyId;
|
|
35
|
+
this.iteration = iteration;
|
|
36
|
+
this.ciphertext = ciphertextBuffer;
|
|
37
|
+
this.signature = signature;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
getKeyId() {
|
|
41
|
+
return this.keyId;
|
|
42
|
+
}
|
|
43
|
+
getIteration() {
|
|
44
|
+
return this.iteration;
|
|
45
|
+
}
|
|
46
|
+
getCipherText() {
|
|
47
|
+
return this.ciphertext;
|
|
48
|
+
}
|
|
49
|
+
verifySignature(signatureKey) {
|
|
50
|
+
const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
|
|
51
|
+
const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
52
|
+
const res = verifySignature(signatureKey, part1, part2);
|
|
53
|
+
if (!res)
|
|
54
|
+
throw new Error('Invalid signature!');
|
|
55
|
+
}
|
|
56
|
+
getSignature(signatureKey, serialized) {
|
|
57
|
+
return Buffer.from(calculateSignature(signatureKey, serialized));
|
|
58
|
+
}
|
|
59
|
+
serialize() {
|
|
60
|
+
return this.serialized;
|
|
61
|
+
}
|
|
62
|
+
getType() {
|
|
63
|
+
return 4;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=sender-key-message.js.map
|