@oxidezap/baileyrs 0.3.7 → 0.3.9

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.
Files changed (129) hide show
  1. package/README.md +56 -8
  2. package/lib/Bridge/history-sync-wire.d.ts +2 -2
  3. package/lib/Bridge/history-sync-wire.js +4 -4
  4. package/lib/Bridge/schema.js +7 -1
  5. package/lib/Bridge/types.d.ts +7 -1
  6. package/lib/Compatibility/auth-state.d.ts +30 -0
  7. package/lib/Compatibility/auth-state.js +96 -0
  8. package/lib/Compatibility/encode-proto-core.d.ts +31 -0
  9. package/lib/Compatibility/encode-proto-core.js +51 -0
  10. package/lib/Compatibility/encode-proto.d.ts +0 -29
  11. package/lib/Compatibility/encode-proto.js +3 -50
  12. package/lib/Compatibility/host-auth-state.d.ts +6 -0
  13. package/lib/Compatibility/host-auth-state.js +162 -0
  14. package/lib/Compatibility/internal/auth-state.d.ts +3 -7
  15. package/lib/Compatibility/internal/auth-state.js +34 -1
  16. package/lib/Compatibility/internal/host-auth-state.d.ts +4 -0
  17. package/lib/Compatibility/internal/host-auth-state.js +14 -0
  18. package/lib/Compatibility/legacy-store/device.js +5 -5
  19. package/lib/Compatibility/message-ids.d.ts +17 -0
  20. package/lib/Compatibility/message-ids.js +47 -0
  21. package/lib/Compatibility/message-relay.d.ts +2 -2
  22. package/lib/Compatibility/message-relay.js +4 -4
  23. package/lib/Compatibility/proto-runtime.js +33 -11
  24. package/lib/Compatibility/socket-results.d.ts +1 -1
  25. package/lib/Compatibility/tagged-message-waiter.d.ts +5 -2
  26. package/lib/Compatibility/tagged-message-waiter.js +5 -5
  27. package/lib/Compatibility/usync/adapter.d.ts +1 -1
  28. package/lib/Compatibility/websocket-client.d.ts +11 -3
  29. package/lib/Compatibility/websocket-client.js +84 -11
  30. package/lib/Defaults/index.d.ts +8 -8
  31. package/lib/Defaults/index.js +8 -8
  32. package/lib/Media/content.d.ts +28 -0
  33. package/lib/Media/content.js +129 -0
  34. package/lib/Media/core.d.ts +34 -0
  35. package/lib/Media/core.js +120 -0
  36. package/lib/Media/mutations.d.ts +24 -0
  37. package/lib/Media/mutations.js +38 -0
  38. package/lib/Runtime/aes-gcm.d.ts +4 -0
  39. package/lib/Runtime/aes-gcm.js +11 -0
  40. package/lib/Runtime/bridge.d.ts +44 -0
  41. package/lib/Runtime/bridge.js +76 -0
  42. package/lib/Runtime/buffer.d.ts +9 -0
  43. package/lib/Runtime/buffer.js +22 -0
  44. package/lib/Runtime/bytes.d.ts +61 -0
  45. package/lib/Runtime/bytes.js +270 -0
  46. package/lib/Runtime/host.d.ts +22 -0
  47. package/lib/Runtime/host.js +43 -0
  48. package/lib/Runtime/long.d.ts +33 -0
  49. package/lib/Runtime/long.js +64 -0
  50. package/lib/Runtime/node-media-processors.d.ts +4 -0
  51. package/lib/Runtime/node-media-processors.js +29 -0
  52. package/lib/Runtime/node-media.d.ts +28 -0
  53. package/lib/Runtime/node-media.js +115 -0
  54. package/lib/Runtime/node.d.ts +14 -0
  55. package/lib/Runtime/node.js +81 -0
  56. package/lib/Runtime/paths.d.ts +4 -0
  57. package/lib/Runtime/paths.js +7 -0
  58. package/lib/Runtime/stream.d.ts +11 -0
  59. package/lib/Runtime/stream.js +25 -0
  60. package/lib/Runtime/types.d.ts +98 -0
  61. package/lib/Runtime/types.js +13 -0
  62. package/lib/Socket/core.d.ts +312 -0
  63. package/lib/Socket/core.js +1134 -0
  64. package/lib/Socket/events-core.d.ts +75 -0
  65. package/lib/Socket/events-core.js +1058 -0
  66. package/lib/Socket/events.d.ts +1 -63
  67. package/lib/Socket/events.js +4 -1047
  68. package/lib/Socket/groups.js +4 -3
  69. package/lib/Socket/index.d.ts +521 -103
  70. package/lib/Socket/index.js +10 -1007
  71. package/lib/Socket/messages-core.d.ts +41 -0
  72. package/lib/Socket/messages-core.js +270 -0
  73. package/lib/Socket/messages.d.ts +9 -36
  74. package/lib/Socket/messages.js +3 -260
  75. package/lib/Socket/newsletter.js +3 -3
  76. package/lib/Socket/profile.js +1 -1
  77. package/lib/Socket/terminal-close-reporter.d.ts +2 -0
  78. package/lib/Socket/terminal-close-reporter.js +3 -3
  79. package/lib/Socket/transport.d.ts +2 -0
  80. package/lib/Socket/transport.js +16 -1
  81. package/lib/Socket/types.d.ts +2 -0
  82. package/lib/Types/Auth.d.ts +11 -0
  83. package/lib/Types/Message.d.ts +1 -1
  84. package/lib/Types/Socket.d.ts +2 -2
  85. package/lib/Types/index.d.ts +6 -1
  86. package/lib/Utils/browser-utils.d.ts +4 -0
  87. package/lib/Utils/browser-utils.js +53 -2
  88. package/lib/Utils/crypto.d.ts +1 -0
  89. package/lib/Utils/crypto.js +1 -0
  90. package/lib/Utils/event-buffer.d.ts +6 -1
  91. package/lib/Utils/event-buffer.js +28 -27
  92. package/lib/Utils/link-preview.d.ts +4 -3
  93. package/lib/Utils/logger.d.ts +3 -0
  94. package/lib/Utils/logger.js +35 -6
  95. package/lib/Utils/messages-core.d.ts +174 -0
  96. package/lib/Utils/messages-core.js +1042 -0
  97. package/lib/Utils/messages-media-core.d.ts +73 -0
  98. package/lib/Utils/messages-media-core.js +319 -0
  99. package/lib/Utils/messages-media.d.ts +1 -72
  100. package/lib/Utils/messages-media.js +9 -358
  101. package/lib/Utils/messages.d.ts +1 -166
  102. package/lib/Utils/messages.js +7 -1040
  103. package/lib/Utils/optional-peer.js +14 -5
  104. package/lib/Utils/process-history-message-core.d.ts +36 -0
  105. package/lib/Utils/process-history-message-core.js +187 -0
  106. package/lib/Utils/process-history-message.d.ts +5 -43
  107. package/lib/Utils/process-history-message.js +11 -197
  108. package/lib/Utils/process-message-core.d.ts +29 -0
  109. package/lib/Utils/process-message-core.js +112 -0
  110. package/lib/Utils/process-message.d.ts +4 -24
  111. package/lib/Utils/process-message.js +6 -111
  112. package/lib/WABinary/generic-utils.js +7 -5
  113. package/lib/host-shared.d.ts +74 -0
  114. package/lib/host-shared.js +15 -0
  115. package/lib/host-socket-operations.d.ts +3 -0
  116. package/lib/host-socket-operations.js +2 -0
  117. package/lib/host-surface.d.ts +21 -0
  118. package/lib/host-surface.js +35 -0
  119. package/lib/host-types.d.ts +356 -0
  120. package/lib/host-types.js +2 -0
  121. package/lib/host.d.ts +33 -0
  122. package/lib/host.js +31 -0
  123. package/lib/node-surface.d.ts +9 -0
  124. package/lib/node-surface.js +15 -0
  125. package/lib/surface.d.ts +5 -0
  126. package/lib/surface.js +6 -0
  127. package/lib/wasm.d.ts +27 -0
  128. package/lib/wasm.js +27 -0
  129. package/package.json +18 -6
@@ -0,0 +1,115 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ /** Optional filesystem/process media capabilities. Node installs these; hosts never do. */
10
+ export const nodeMedia = {
11
+ getImageProcessingLibrary: async () => ({}),
12
+ decodeAudio: async () => {
13
+ throw new Error('audio decoding is unavailable on this host');
14
+ },
15
+ getAudioDuration: async () => undefined,
16
+ hkdf: () => {
17
+ throw new Error('HKDF bridge capability is unavailable');
18
+ },
19
+ aesGcm256Encrypt: () => {
20
+ throw new Error('AES-GCM bridge capability is unavailable');
21
+ },
22
+ aesGcm256Decrypt: () => {
23
+ throw new Error('AES-GCM bridge capability is unavailable');
24
+ },
25
+ tempDir: () => '/tmp',
26
+ execFile: () => {
27
+ throw new Error('ffmpeg is unavailable on this host');
28
+ },
29
+ createReadStream: () => {
30
+ throw new Error('file media is unavailable on this host');
31
+ },
32
+ fs: {
33
+ writeFile: async () => {
34
+ throw new Error('file media is unavailable on this host');
35
+ },
36
+ readFile: async () => {
37
+ throw new Error('file media is unavailable on this host');
38
+ },
39
+ unlink: async () => {
40
+ throw new Error('file media is unavailable on this host');
41
+ }
42
+ }
43
+ };
44
+ const nodeProcess = globalThis.process;
45
+ if (nodeProcess) {
46
+ try {
47
+ const bridgePackage = ['@oxidezap', 'whatsapp-rust-bridge'].join('/');
48
+ const nodeBridge = await import(__rewriteRelativeImportExtension(bridgePackage));
49
+ const isCryptoEngineUnavailable = (error) => {
50
+ if (!(error instanceof Error))
51
+ return false;
52
+ const details = error;
53
+ return (details.kind === 'invalid-argument' &&
54
+ details.field === 'initWasmEngine' &&
55
+ details.reason === 'must be called before AES-GCM operations');
56
+ };
57
+ const withMediaCryptoInitialized = (operation) => {
58
+ try {
59
+ return operation();
60
+ }
61
+ catch (error) {
62
+ if (!isCryptoEngineUnavailable(error))
63
+ throw error;
64
+ nodeBridge.initWasmEngine();
65
+ return operation();
66
+ }
67
+ };
68
+ nodeMedia.aesGcm256Encrypt = (key, nonce, aad, plaintext) => withMediaCryptoInitialized(() => nodeBridge.aesGcm256Encrypt(key, nonce, aad, plaintext));
69
+ nodeMedia.aesGcm256Decrypt = (key, nonce, aad, ciphertext) => withMediaCryptoInitialized(() => nodeBridge.aesGcm256Decrypt(key, nonce, aad, ciphertext));
70
+ nodeMedia.hkdf = (input, length, options) => {
71
+ try {
72
+ return nodeBridge.hkdf(input, length, options);
73
+ }
74
+ catch {
75
+ nodeBridge.initWasmEngine();
76
+ return nodeBridge.hkdf(input, length, options);
77
+ }
78
+ };
79
+ nodeMedia.getImageProcessingLibrary = async () => {
80
+ const jimpPackage = ['ji', 'mp'].join('');
81
+ const sharpPackage = ['sha', 'rp'].join('');
82
+ const [jimp, sharp] = await Promise.all([
83
+ import(__rewriteRelativeImportExtension(jimpPackage)).catch(() => undefined),
84
+ import(__rewriteRelativeImportExtension(sharpPackage)).catch(() => undefined)
85
+ ]);
86
+ return sharp ? { sharp } : jimp ? { jimp } : {};
87
+ };
88
+ nodeMedia.decodeAudio = async (input) => {
89
+ const audioPackage = ['audio', 'decode'].join('-');
90
+ const loaded = (await import(__rewriteRelativeImportExtension(audioPackage)));
91
+ return loaded.default(input);
92
+ };
93
+ nodeMedia.getAudioDuration = async (input) => {
94
+ const metadataPackage = ['music', 'metadata'].join('-');
95
+ let loaded;
96
+ try {
97
+ loaded = (await import(__rewriteRelativeImportExtension(metadataPackage)));
98
+ }
99
+ catch {
100
+ return undefined;
101
+ }
102
+ const options = { duration: true };
103
+ const metadata = input instanceof Uint8Array
104
+ ? await loaded.parseBuffer(input, undefined, options)
105
+ : typeof input === 'string'
106
+ ? await loaded.parseFile(input, options)
107
+ : await loaded.parseStream(input, undefined, options);
108
+ return metadata.format.duration;
109
+ };
110
+ }
111
+ catch {
112
+ /* A host has no Node bridge loader; its runtime installs this capability. */
113
+ }
114
+ }
115
+ //# sourceMappingURL=node-media.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Node runtime capabilities for `createWASocketFactory`.
3
+ *
4
+ * The Node runtime keeps current behavior exactly: bare bridge entrypoint
5
+ * (reads the wasm off disk), WebCrypto-backed randomness (measured at parity
6
+ * with `node:crypto`), `node:events` emitter, `platform()`/`release()`
7
+ * identity, OpenSSL native crypto fast path, and the stdout logger sink with
8
+ * `BAILEYRS_LOG_LEVEL`.
9
+ */
10
+ import type { BaileysRuntime } from './types.js';
11
+ export declare const nodeRandomBytes: (length: number) => Uint8Array;
12
+ export declare const nodeLoggerSink: (line: string, delivered: () => void) => void;
13
+ export declare const nodeRuntime: BaileysRuntime;
14
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Node runtime capabilities for `createWASocketFactory`.
3
+ *
4
+ * The Node runtime keeps current behavior exactly: bare bridge entrypoint
5
+ * (reads the wasm off disk), WebCrypto-backed randomness (measured at parity
6
+ * with `node:crypto`), `node:events` emitter, `platform()`/`release()`
7
+ * identity, OpenSSL native crypto fast path, and the stdout logger sink with
8
+ * `BAILEYRS_LOG_LEVEL`.
9
+ */
10
+ import { randomBytes as nodeRandomBytesSource } from 'node:crypto';
11
+ import EventEmitter from 'events';
12
+ import { tmpdir } from 'node:os';
13
+ import { Buffer } from 'node:buffer';
14
+ import { Readable } from 'node:stream';
15
+ import { execFile } from 'node:child_process';
16
+ import { createReadStream, promises as fs } from 'node:fs';
17
+ import * as bridge from '@oxidezap/whatsapp-rust-bridge';
18
+ import Long from './long.js';
19
+ import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
20
+ import { makeNativeCryptoProvider } from '../Utils/native-crypto-provider.js';
21
+ import { wrapLegacyStore } from '../Utils/wrap-legacy-store.js';
22
+ import { setReadableRuntime } from './stream.js';
23
+ import { nodeMedia } from './node-media.js';
24
+ import { getAudioDuration, loadImageProcessingLibrary } from './node-media-processors.js';
25
+ import { setBufferRuntime } from './buffer.js';
26
+ setBufferRuntime(Buffer);
27
+ nodeMedia.getImageProcessingLibrary = loadImageProcessingLibrary;
28
+ nodeMedia.getAudioDuration = getAudioDuration;
29
+ nodeMedia.hkdf = bridge.hkdf;
30
+ nodeMedia.aesGcm256Encrypt = bridge.aesGcm256Encrypt;
31
+ nodeMedia.aesGcm256Decrypt = bridge.aesGcm256Decrypt;
32
+ nodeMedia.tempDir = tmpdir;
33
+ nodeMedia.execFile = execFile;
34
+ nodeMedia.createReadStream = createReadStream;
35
+ nodeMedia.fs = fs;
36
+ setReadableRuntime({
37
+ fromWeb: stream => Readable.fromWeb(stream),
38
+ isReadable: value => value instanceof Readable,
39
+ createReadable: () => new Readable({ read: () => { } })
40
+ });
41
+ import { makeLazyTransactionKeyStore } from '../Compatibility/internal/signal-key-store.js';
42
+ import { normalizeSocketAuthenticationState, refreshSocketAuthenticationState, waitForSocketAuthenticationState } from '../Compatibility/internal/auth-state.js';
43
+ export const nodeRandomBytes = (length) => {
44
+ const out = new Uint8Array(length);
45
+ if (length > 0) {
46
+ const native = nodeRandomBytesSource(length);
47
+ out.set(native);
48
+ }
49
+ return out;
50
+ };
51
+ export const nodeLoggerSink = (line, delivered) => {
52
+ try {
53
+ process.stdout.write(`${line}\n`, delivered);
54
+ }
55
+ catch {
56
+ delivered();
57
+ /* logging must not crash the process it observes */
58
+ }
59
+ };
60
+ export const nodeRuntime = {
61
+ bridge,
62
+ randomBytes: nodeRandomBytes,
63
+ setTimeout: (callback, ms) => setTimeout(callback, ms),
64
+ clearTimeout: handle => clearTimeout(handle),
65
+ setImmediate: callback => setImmediate(callback),
66
+ queueMicrotask: callback => queueMicrotask(callback),
67
+ events: {
68
+ createEmitter: () => new EventEmitter()
69
+ },
70
+ nativeCrypto: makeNativeCryptoProvider(),
71
+ defaultLogger: DEFAULT_CONNECTION_CONFIG.logger,
72
+ loggerSink: nodeLoggerSink,
73
+ logLevel: () => process.env.BAILEYRS_LOG_LEVEL,
74
+ Long,
75
+ wrapLegacyStore: wrapLegacyStore,
76
+ makeTransactionKeyStore: makeLazyTransactionKeyStore,
77
+ normalizeAuth: normalizeSocketAuthenticationState,
78
+ waitForAuthState: waitForSocketAuthenticationState,
79
+ refreshAuthState: refreshSocketAuthenticationState
80
+ };
81
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1,4 @@
1
+ /** Small path capabilities used only by optional Node media processing. */
2
+ export declare const runtimeTempDir: () => string;
3
+ export declare const runtimeJoinPath: (...parts: string[]) => string;
4
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1,7 @@
1
+ /** Small path capabilities used only by optional Node media processing. */
2
+ export const runtimeTempDir = () => '/tmp';
3
+ export const runtimeJoinPath = (...parts) => parts
4
+ .join('/')
5
+ .replace(/\/+/gu, '/')
6
+ .replace(/(^|[^/])\/\.\//gu, '$1/');
7
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1,11 @@
1
+ /** Runtime-selected conversion for the root Node stream contract. */
2
+ export type WebStreamLike = unknown;
3
+ export declare const setReadableRuntime: (runtime: {
4
+ fromWeb: (stream: WebStreamLike) => unknown;
5
+ isReadable: (value: unknown) => boolean;
6
+ createReadable: () => unknown;
7
+ }) => void;
8
+ export declare const isReadable: (value: unknown) => boolean;
9
+ export declare const createReadable: () => unknown;
10
+ export declare const readableFromWeb: (stream: WebStreamLike) => unknown;
11
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1,25 @@
1
+ let fromWeb = stream => stream;
2
+ let readableCheck = () => false;
3
+ let createReadableImpl = () => ({});
4
+ export const setReadableRuntime = (runtime) => {
5
+ fromWeb = runtime.fromWeb;
6
+ readableCheck = runtime.isReadable;
7
+ createReadableImpl = runtime.createReadable;
8
+ };
9
+ export const isReadable = (value) => readableCheck(value);
10
+ export const createReadable = () => createReadableImpl();
11
+ // Deep Node imports of `Utils/messages-media` do not pass through the package
12
+ // root. Discover the builtin without a static Node import so this module stays
13
+ // in the host graph, while preserving the historical Node stream contract.
14
+ const builtinLoader = globalThis.process?.getBuiltinModule;
15
+ const nodeStream = builtinLoader?.('node:stream');
16
+ const NodeReadable = nodeStream?.Readable;
17
+ if (NodeReadable) {
18
+ setReadableRuntime({
19
+ fromWeb: stream => NodeReadable.fromWeb(stream),
20
+ isReadable: value => value instanceof NodeReadable,
21
+ createReadable: () => new NodeReadable({ read: () => { } })
22
+ });
23
+ }
24
+ export const readableFromWeb = (stream) => fromWeb(stream);
25
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Runtime capability interface for `makeWASocket`.
3
+ *
4
+ * A `BaileysRuntime` bundles every host operation the socket core needs that
5
+ * differs between runtimes: bridge entrypoint, randomness, timers, event
6
+ * emitter construction, platform identity, native crypto, media processing
7
+ * and logging. `Socket/core.ts` consumes only this interface, so the same
8
+ * factory builds the Node socket and the host-neutral socket from different
9
+ * capabilities. There is intentionally no global mutable runtime: callers
10
+ * pick `nodeRuntime` or `hostRuntime` (or a custom one) per socket.
11
+ */
12
+ import type { AuthenticationState, NativeAuthenticationState } from '../Types/Auth.js';
13
+ import type { aesGcm256Decrypt as BridgeAesGcm256Decrypt, aesGcm256Encrypt as BridgeAesGcm256Encrypt, BinaryReader as BridgeBinaryReader, JsHttpClientConfig, JsTransportCallbacks, WasmWhatsAppClient, WhatsAppEventCallbacks, CacheConfig, ClientPolicies, JsStoreCallbacks, hkdf as bridgeHkdf, sha256 as bridgeSha256 } from '@oxidezap/whatsapp-rust-bridge/host';
14
+ import type Long from 'long';
15
+ import type { ILogger } from '../Utils/logger.js';
16
+ /** Subset of the bridge surface the socket core touches. */
17
+ export interface BridgeRuntime {
18
+ createWhatsAppClient(transport: JsTransportCallbacks, httpClient: JsHttpClientConfig, onEvent?: WhatsAppEventCallbacks | null, store?: JsStoreCallbacks | null, cache?: CacheConfig | null, version?: readonly [number, number, number] | null, wantedPreKeyCount?: number | null, dangerSkipCertChainVerify?: boolean | null, policies?: ClientPolicies | null): Promise<WasmWhatsAppClient>;
19
+ initWasmEngine(logger?: unknown, crypto?: unknown): void;
20
+ hkdf: typeof bridgeHkdf;
21
+ sha256: typeof bridgeSha256;
22
+ aesGcm256Encrypt: typeof BridgeAesGcm256Encrypt;
23
+ aesGcm256Decrypt: typeof BridgeAesGcm256Decrypt;
24
+ encodeProto(path: string, message: unknown): Uint8Array;
25
+ decodeProto(path: string, data: Uint8Array): unknown;
26
+ inflateZlib(data: Uint8Array, maxOutputBytes?: number | null): Uint8Array;
27
+ BinaryReader: typeof BridgeBinaryReader;
28
+ decodeMessageWireBatch(data: Uint8Array): unknown;
29
+ decodeReceiptWireBatch(data: Uint8Array): unknown;
30
+ decodeServerAckWireBatch(data: Uint8Array): unknown;
31
+ decryptPollVotePayload(encPayload: Uint8Array, encIv: Uint8Array, messageSecret: Uint8Array, stanzaId: string, pollCreatorJid: string, voterJid: string): Uint8Array;
32
+ decryptEventResponsePayload(encPayload: Uint8Array, encIv: Uint8Array, messageSecret: Uint8Array, stanzaId: string, eventCreatorJid: string, responderJid: string): Uint8Array;
33
+ }
34
+ /** Minimal emitter surface the socket core needs. */
35
+ export interface RuntimeEventEmitter {
36
+ on(event: string | symbol, listener: (...args: never[]) => void): unknown;
37
+ off(event: string | symbol, listener: (...args: never[]) => void): unknown;
38
+ once(event: string | symbol, listener: (...args: never[]) => void): unknown;
39
+ prependListener(event: string | symbol, listener: (...args: never[]) => void): unknown;
40
+ prependOnceListener(event: string | symbol, listener: (...args: never[]) => void): unknown;
41
+ removeListener(event: string | symbol, listener: (...args: never[]) => void): unknown;
42
+ removeAllListeners(event?: string | symbol): unknown;
43
+ eventNames(): (string | symbol)[];
44
+ rawListeners(event: string | symbol): Array<(...args: never[]) => void>;
45
+ listeners(event: string | symbol): Array<(...args: never[]) => void>;
46
+ listenerCount(event: string | symbol, listener?: (...args: never[]) => void): number;
47
+ setMaxListeners(count: number): unknown;
48
+ getMaxListeners(): number;
49
+ emit(event: string | symbol, ...args: never[]): boolean;
50
+ }
51
+ export interface EmitterFactory {
52
+ createEmitter(): RuntimeEventEmitter;
53
+ }
54
+ /** Platform identity for `Browsers.appropriate()` and device props. */
55
+ export interface PlatformInfo {
56
+ os: string;
57
+ release: string;
58
+ }
59
+ export type MediaCryptoRuntime = Pick<BridgeRuntime, 'hkdf' | 'sha256' | 'aesGcm256Encrypt' | 'aesGcm256Decrypt'> & Pick<BaileysRuntime, 'randomBytes'>;
60
+ export interface BaileysRuntime {
61
+ /** Bridge entrypoint: Node imports the bare root, hosts import `/host`. */
62
+ bridge: BridgeRuntime;
63
+ /** Cryptographically strong random bytes (WebCrypto-backed everywhere). */
64
+ randomBytes(length: number): Uint8Array;
65
+ /** Timer handle with optional `unref` (Node) / plain (hosts). */
66
+ setTimeout(callback: () => void, ms: number): {
67
+ unref?: () => void;
68
+ ref?: () => void;
69
+ };
70
+ clearTimeout(handle: unknown): void;
71
+ setImmediate?(callback: () => void): unknown;
72
+ queueMicrotask(callback: () => void): void;
73
+ /** Portable event emitter constructor (the `events` package). */
74
+ events: EmitterFactory;
75
+ /** Platform identity; absent on hosts (stable fallback is used). */
76
+ platformInfo?(): PlatformInfo;
77
+ /** Native AES/HMAC fast path; absent on hosts (Rust/WASM fallback). */
78
+ nativeCrypto?: unknown;
79
+ /** Runtime-specific default logger. Node preserves the pino-backed connection logger; hosts omit it. */
80
+ defaultLogger?: ILogger;
81
+ /** Where core log lines go: Node writes stdout, hosts console. */
82
+ loggerSink(line: string, delivered?: () => void): void;
83
+ /** Log level: Node reads `BAILEYRS_LOG_LEVEL`, hosts use config/default. */
84
+ logLevel(): string | undefined;
85
+ /** Normalize auth while preserving the root Node projection or host native store. */
86
+ normalizeAuth?: (input: AuthenticationState | NativeAuthenticationState) => AuthenticationState;
87
+ /** Await asynchronous credential hydration required by a runtime's native store adapter. */
88
+ waitForAuthState?: (state: AuthenticationState) => Promise<void>;
89
+ /** Refresh the public credential mirror after the native engine persists pairing state. */
90
+ refreshAuthState?: (state: AuthenticationState) => Promise<void>;
91
+ /** Node-only legacy auth adapter; absent on host runtimes. */
92
+ wrapLegacyStore?: (state: unknown, onCredsUpdate: () => Promise<void>, logger: unknown) => Promise<JsStoreCallbacks>;
93
+ /** Node-only Baileys transaction facade; native host stores do not need it. */
94
+ makeTransactionKeyStore?: (state: unknown, logger: unknown, options: unknown) => () => unknown;
95
+ /** 64-bit integer constructor identity for this runtime's module graph. */
96
+ Long: typeof Long;
97
+ }
98
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Runtime capability interface for `makeWASocket`.
3
+ *
4
+ * A `BaileysRuntime` bundles every host operation the socket core needs that
5
+ * differs between runtimes: bridge entrypoint, randomness, timers, event
6
+ * emitter construction, platform identity, native crypto, media processing
7
+ * and logging. `Socket/core.ts` consumes only this interface, so the same
8
+ * factory builds the Node socket and the host-neutral socket from different
9
+ * capabilities. There is intentionally no global mutable runtime: callers
10
+ * pick `nodeRuntime` or `hostRuntime` (or a custom one) per socket.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=types.js.map