aunubaileys 1.0.46 β†’ 1.0.47

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 CHANGED
@@ -64,6 +64,10 @@ Everything else is pure upstream. When upstream moves, we rebase the patch layer
64
64
 
65
65
 
66
66
 
67
+ ### πŸ§ͺ What's new in 1.0.47 / Baru di 1.0.47 β€” EXPERIMENTAL
68
+
69
+ - πŸ§ͺ **Five experimental features that exist only in AunuBaileys**, in a single version. All are attached automatically to the socket returned by `makeWASocket` and are explicitly experimental β€” semantics may change in any release: (1) **Invisible text watermark** β€” `sock.aunuWatermark(text, tag)` hides a short tag (bot name, campaign, build) inside message text as zero-width characters for leak tracing and fingerprinting; the visible text is unchanged; companions `aunuReadWatermark(text)` and `aunuStripWatermark(text)`, plus root utils `encodeWatermark`/`appendWatermark`/`extractWatermark`/`stripWatermark`. (2) **Human send** β€” `sock.aunuHumanSend(jid, content)`: shows "composing" for a plausible typing duration derived from the text length (util `computeTypingDuration`, clamped 700–8000 ms, Β±20% jitter), then sends. (3) **Scheduled send** β€” `sock.aunuSchedule(jid, content, when)` (ms delay or Date) with `aunuCancelScheduled(id)` and `aunuListScheduled()`; in-memory, lost on restart. (4) **Self-destruct** β€” `sock.aunuSelfDestruct(jid, content, seconds)`: sends, then revokes the message for everyone after N seconds; `aunuCancelSelfDestruct(messageId)` cancels. (5) **Connection doctor** β€” `sock.aunuDoctor()`: one structured health snapshot (bundled WA version, registration state, open transport, known LID pair count, pending experimental timers).
70
+
67
71
  ### πŸ†• What's new in 1.0.46 / Baru di 1.0.46
68
72
 
69
73
  - 🩹 **The "Over 2000 messages into the future" flood now heals itself.** Session-layer decrypt failures β€” libsignal's aggregate "No matching sessions found for message" / "No session record" / "No sessions available", which includes the unfillable counter gap left by regressed session state (e.g. sessions restored from a backup while the sender kept sending; observed live in the Tenka deployment on 11 Nov 2026, on the same LID address as the old B-01 finding) β€” are now recognised from `messageStubParameters` and trigger an **immediate E2E session reset** instead of waiting for 3 failures: for DMs and groups alike (groups also drop the author's sender key), including the session record under its alternate PN↔LID address form, with the retry receipt carrying fresh keys. The old self-heal missed this flood because it waited 3 strikes, in groups only touched the sender key while the broken layer is the E2E session, and deletion could miss the aliased record. Other error classes (ordinary Bad MAC) keep the exact 1.0.14/1.0.17 3-strike behaviour. New exported classifier: `isUnrecoverableSessionError(text)`; the `messages.decrypt-failure` event gains an `errorClass` field (`'session'`/`'other'`) and `healed` now reflects a reset that actually happened on that message.
@@ -0,0 +1,32 @@
1
+ import type { AnyMessageContent, MiscMessageGenerationOptions, WAMessage } from '../Types/index.js';
2
+ import type { TypingDurationOptions } from '../Utils/aunu-experimental.js';
3
+ /** EXPERIMENTAL β€” AunuBaileys-only socket features. Semantics may change in any release. */
4
+ export interface AunuDoctorReport {
5
+ experimental: true;
6
+ bundledWaVersion: string | null;
7
+ registered: boolean;
8
+ me: string | null;
9
+ wsOpen: boolean;
10
+ lidPairsKnown: number | null;
11
+ scheduledPending: number;
12
+ selfDestructPending: number;
13
+ generatedAt: string;
14
+ }
15
+ export interface AunuScheduledSend {
16
+ id: string;
17
+ at: number;
18
+ cancel: () => boolean;
19
+ }
20
+ export interface AunuExperimentalAPI {
21
+ aunuWatermark: (text: string, tag: string) => string;
22
+ aunuReadWatermark: (text: string) => string | null;
23
+ aunuStripWatermark: (text: string) => string;
24
+ aunuHumanSend: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions & TypingDurationOptions) => Promise<WAMessage | undefined>;
25
+ aunuSchedule: (jid: string, content: AnyMessageContent, when: number | Date, options?: MiscMessageGenerationOptions) => AunuScheduledSend;
26
+ aunuCancelScheduled: (id: string) => boolean;
27
+ aunuListScheduled: () => { id: string; jid: string; at: number }[];
28
+ aunuSelfDestruct: (jid: string, content: AnyMessageContent, seconds: number, options?: MiscMessageGenerationOptions) => Promise<WAMessage | undefined>;
29
+ aunuCancelSelfDestruct: (messageId: string) => boolean;
30
+ aunuDoctor: () => AunuDoctorReport;
31
+ }
32
+ export declare const attachAunuExperimental: <T>(sock: T) => T & AunuExperimentalAPI;
@@ -0,0 +1,104 @@
1
+ import baileysVersion from '../Defaults/baileys-version.json' with { type: 'json' };
2
+ import { appendWatermark, computeTypingDuration, extractWatermark, stripWatermark } from '../Utils/aunu-experimental.js';
3
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4
+ /**
5
+ * AunuBaileys EXPERIMENTAL socket features β€” these exist only in
6
+ * AunuBaileys and may change or disappear in any release:
7
+ *
8
+ * 1. Invisible text watermark β€” `aunuWatermark` / `aunuReadWatermark` /
9
+ * `aunuStripWatermark`: hide a short tag (bot name, campaign, build)
10
+ * inside message text as zero-width characters for leak tracing and
11
+ * fingerprinting; the visible text is unchanged.
12
+ * 2. Humanised send β€” `aunuHumanSend`: shows "composing" for a plausible
13
+ * typing duration derived from the text length, then sends.
14
+ * 3. Scheduled send β€” `aunuSchedule` / `aunuCancelScheduled` /
15
+ * `aunuListScheduled`: in-memory delayed sends (lost on restart).
16
+ * 4. Self-destructing send β€” `aunuSelfDestruct` /
17
+ * `aunuCancelSelfDestruct`: sends, then revokes the message for
18
+ * everyone after N seconds.
19
+ * 5. Connection doctor β€” `aunuDoctor`: one structured health snapshot
20
+ * (registration, transport, bundled WA version, known LID pairs,
21
+ * pending experimental timers).
22
+ */
23
+ export const attachAunuExperimental = (sock) => {
24
+ const scheduled = new Map();
25
+ const destructs = new Map();
26
+ let seq = 0;
27
+ sock.aunuWatermark = (text, tag) => appendWatermark(text, tag);
28
+ sock.aunuReadWatermark = (text) => extractWatermark(text);
29
+ sock.aunuStripWatermark = (text) => stripWatermark(text);
30
+ sock.aunuHumanSend = async (jid, content, options = {}) => {
31
+ if (content && typeof content.text === 'string' && typeof sock.sendPresenceUpdate === 'function') {
32
+ try {
33
+ await sock.sendPresenceUpdate('composing', jid);
34
+ }
35
+ catch {
36
+ // presence is best-effort; the send itself must not fail over it
37
+ }
38
+ await delay(computeTypingDuration(content.text, options));
39
+ try {
40
+ await sock.sendPresenceUpdate('paused', jid);
41
+ }
42
+ catch {
43
+ // best-effort, as above
44
+ }
45
+ }
46
+ return sock.sendMessage(jid, content, options);
47
+ };
48
+ sock.aunuSchedule = (jid, content, when, options = {}) => {
49
+ const at = when instanceof Date ? when.getTime() : Date.now() + Math.max(0, Number(when) || 0);
50
+ const id = `aunu-sched-${++seq}`;
51
+ const timer = setTimeout(() => {
52
+ scheduled.delete(id);
53
+ Promise.resolve(sock.sendMessage(jid, content, options)).catch(() => { });
54
+ }, Math.max(0, at - Date.now()));
55
+ timer.unref?.();
56
+ scheduled.set(id, { jid, at, timer });
57
+ return { id, at, cancel: () => sock.aunuCancelScheduled(id) };
58
+ };
59
+ sock.aunuCancelScheduled = (id) => {
60
+ const entry = scheduled.get(id);
61
+ if (!entry) {
62
+ return false;
63
+ }
64
+ clearTimeout(entry.timer);
65
+ scheduled.delete(id);
66
+ return true;
67
+ };
68
+ sock.aunuListScheduled = () => [...scheduled.entries()].map(([id, entry]) => ({ id, jid: entry.jid, at: entry.at }));
69
+ sock.aunuSelfDestruct = async (jid, content, seconds, options = {}) => {
70
+ const sent = await sock.sendMessage(jid, content, options);
71
+ const key = sent?.key;
72
+ if (key?.id) {
73
+ const timer = setTimeout(() => {
74
+ destructs.delete(key.id);
75
+ Promise.resolve(sock.sendMessage(jid, { delete: key })).catch(() => { });
76
+ }, Math.max(0.05, Number(seconds) || 0) * 1000);
77
+ timer.unref?.();
78
+ destructs.set(key.id, timer);
79
+ }
80
+ return sent;
81
+ };
82
+ sock.aunuCancelSelfDestruct = (messageId) => {
83
+ const timer = destructs.get(messageId);
84
+ if (!timer) {
85
+ return false;
86
+ }
87
+ clearTimeout(timer);
88
+ destructs.delete(messageId);
89
+ return true;
90
+ };
91
+ sock.aunuDoctor = () => ({
92
+ experimental: true,
93
+ bundledWaVersion: Array.isArray(baileysVersion.version) ? baileysVersion.version.join('.') : null,
94
+ registered: !!sock.authState?.creds?.registered,
95
+ me: sock.user?.id ?? null,
96
+ wsOpen: !!sock.ws?.isOpen,
97
+ lidPairsKnown: typeof sock.aunuLid?.size === 'number' ? sock.aunuLid.size : null,
98
+ scheduledPending: scheduled.size,
99
+ selfDestructPending: destructs.size,
100
+ generatedAt: new Date().toISOString(),
101
+ });
102
+ return sock;
103
+ };
104
+ //# sourceMappingURL=aunu-experimental.js.map
@@ -1,5 +1,6 @@
1
1
  import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
2
2
  import { makeCommunitiesSocket } from './communities.js';
3
+ import { attachAunuExperimental } from './aunu-experimental.js';
3
4
  import { AunuHandler } from '../Utils/aunu-handler.js';
4
5
  import { makeLIDStore } from '../Utils/lid-store.js';
5
6
  // export the last socket layer
@@ -14,6 +15,7 @@ const makeWASocket = (config) => {
14
15
  newConfig.shouldSyncHistoryMessage = () => !!newConfig.syncFullHistory;
15
16
  }
16
17
  const sock = makeCommunitiesSocket(newConfig);
18
+ attachAunuExperimental(sock);
17
19
  sock.aunuHandler = new AunuHandler(sock);
18
20
  if (!sock.aunuLid) {
19
21
  sock.aunuLid = makeLIDStore();
@@ -0,0 +1,16 @@
1
+ /** EXPERIMENTAL β€” see aunu-experimental.js. Semantics may change in any release. */
2
+ export declare const encodeWatermark: (payload: string) => string;
3
+ export declare const appendWatermark: (text: string, payload: string) => string;
4
+ export declare const extractWatermark: (text: string) => string | null;
5
+ export declare const stripWatermark: (text: string) => string;
6
+ export interface TypingDurationOptions {
7
+ /** Characters per second while "typing". Default 5. */
8
+ cps?: number;
9
+ /** Lower clamp in ms. Default 700. */
10
+ minMs?: number;
11
+ /** Upper clamp in ms. Default 8000. */
12
+ maxMs?: number;
13
+ /** Set false for a deterministic duration. Default true (Β±20%). */
14
+ jitter?: boolean;
15
+ }
16
+ export declare const computeTypingDuration: (text: string, options?: TypingDurationOptions) => number;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * AunuBaileys EXPERIMENTAL utilities β€” features that exist only in
3
+ * AunuBaileys. Everything in this module is experimental: semantics may
4
+ * change in any release. See lib/Socket/aunu-experimental.js for the
5
+ * socket-level API built on top of these helpers.
6
+ */
7
+ // Zero-width alphabet for the invisible text watermark. A payload is stored
8
+ // as UTF-8 bytes, each byte as 8 bits (MSB first), wrapped in markers so it
9
+ // can be found and removed again without touching visible text.
10
+ const WM_BIT0 = '\u200B'; // ZERO WIDTH SPACE (bit 0)
11
+ const WM_BIT1 = '\u200C'; // ZERO WIDTH NON-JOINER (bit 1)
12
+ const WM_START = '\u200D'; // ZERO WIDTH JOINER (span start)
13
+ const WM_END = '\u2060'; // WORD JOINER (span end)
14
+ const textEncoder = new TextEncoder();
15
+ const textDecoder = new TextDecoder();
16
+ /**
17
+ * Encode a short string as an invisible zero-width sequence. Returns an
18
+ * empty string for an empty payload.
19
+ */
20
+ export const encodeWatermark = (payload) => {
21
+ if (!payload) {
22
+ return '';
23
+ }
24
+ const bytes = textEncoder.encode(String(payload));
25
+ let bits = '';
26
+ for (const byte of bytes) {
27
+ bits += byte.toString(2).padStart(8, '0');
28
+ }
29
+ return WM_START + [...bits].map((b) => (b === '1' ? WM_BIT1 : WM_BIT0)).join('') + WM_END;
30
+ };
31
+ /** Append an invisible watermark carrying `payload` to `text`. */
32
+ export const appendWatermark = (text, payload) => String(text ?? '') + encodeWatermark(payload);
33
+ /**
34
+ * Read back the payload hidden in `text` by encodeWatermark/appendWatermark.
35
+ * Returns null when there is no well-formed watermark.
36
+ */
37
+ export const extractWatermark = (text) => {
38
+ if (typeof text !== 'string') {
39
+ return null;
40
+ }
41
+ const start = text.indexOf(WM_START);
42
+ if (start < 0) {
43
+ return null;
44
+ }
45
+ const end = text.indexOf(WM_END, start + 1);
46
+ if (end < 0) {
47
+ return null;
48
+ }
49
+ let bits = '';
50
+ for (const ch of text.slice(start + 1, end)) {
51
+ if (ch === WM_BIT0) {
52
+ bits += '0';
53
+ }
54
+ else if (ch === WM_BIT1) {
55
+ bits += '1';
56
+ }
57
+ else {
58
+ return null;
59
+ }
60
+ }
61
+ if (bits.length === 0 || bits.length % 8 !== 0) {
62
+ return null;
63
+ }
64
+ const bytes = new Uint8Array(bits.length / 8);
65
+ for (let i = 0; i < bytes.length; i++) {
66
+ bytes[i] = parseInt(bits.slice(i * 8, i * 8 + 8), 2);
67
+ }
68
+ try {
69
+ return textDecoder.decode(bytes);
70
+ }
71
+ catch {
72
+ return null;
73
+ }
74
+ };
75
+ /** Remove every watermark span from `text`, leaving the visible text intact. */
76
+ export const stripWatermark = (text) => {
77
+ if (typeof text !== 'string') {
78
+ return text;
79
+ }
80
+ return text.replace(/\u200D[\u200B\u200C]*\u2060/g, '');
81
+ };
82
+ /**
83
+ * How long a human would plausibly spend typing `text`, in milliseconds β€”
84
+ * used by the experimental humanised send. Roughly `chars / cps`, clamped
85
+ * to [minMs, maxMs], with up to Β±20% jitter unless disabled.
86
+ */
87
+ export const computeTypingDuration = (text, options = {}) => {
88
+ const cps = options.cps && options.cps > 0 ? options.cps : 5;
89
+ const minMs = options.minMs ?? 700;
90
+ const maxMs = options.maxMs ?? 8000;
91
+ const base = Math.round(((typeof text === 'string' ? text.length : 0) / cps) * 1000);
92
+ const clamped = Math.min(maxMs, Math.max(minMs, base));
93
+ if (options.jitter === false) {
94
+ return clamped;
95
+ }
96
+ const jittered = Math.round(clamped * (0.8 + Math.random() * 0.4));
97
+ return Math.min(maxMs, Math.max(minMs, jittered));
98
+ };
99
+ //# sourceMappingURL=aunu-experimental.js.map
@@ -1,5 +1,6 @@
1
1
  export * from './generics.js';
2
2
  export * from './decode-wa-message.js';
3
+ export * from './aunu-experimental.js';
3
4
  export * from './messages.js';
4
5
  export * from './messages-media.js';
5
6
  export * from './rich-message-utils.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aunubaileys",
3
3
  "type": "module",
4
- "version": "1.0.46",
4
+ "version": "1.0.47",
5
5
  "description": "AunuBaileys \u2014 a WhatsApp Web API for bots that never sleep. Full upstream power with the beloved in-memory store restored and pairing that just works. Forged by AunuCore.",
6
6
  "keywords": [
7
7
  "whatsapp",