@oxidezap/baileyrs 0.0.31 → 0.0.35
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/lib/Bridge/adapt.d.ts +1 -1
- package/lib/Bridge/history-sync-wire.d.ts +1 -1
- package/lib/Bridge/history-sync-wire.js +2 -2
- package/lib/Bridge/schema.d.ts +1 -1
- package/lib/Bridge/schema.js +10 -10
- package/lib/Bridge/types.d.ts +1 -1
- package/lib/Compatibility/group-metadata.d.ts +1 -1
- package/lib/Compatibility/legacy-store/codecs/basic.js +1 -1
- package/lib/Compatibility/legacy-store/codecs/signal.js +17 -5
- package/lib/Compatibility/legacy-store/device.js +1 -1
- package/lib/Compatibility/legacy-store/multi-file.js +1 -1
- package/lib/Compatibility/legacy-store/native-projection.d.ts +1 -1
- package/lib/Compatibility/legacy-store/types.d.ts +1 -1
- package/lib/Compatibility/media-type.d.ts +1 -1
- package/lib/Compatibility/message-relay.d.ts +1 -1
- package/lib/Compatibility/proto-runtime.js +90 -26
- package/lib/Compatibility/socket-results.d.ts +1 -1
- package/lib/Compatibility/stanza-responses.d.ts +1 -1
- package/lib/Compatibility/usync/adapter.d.ts +1 -1
- package/lib/Compatibility/websocket-client.d.ts +1 -1
- package/lib/Socket/communities.d.ts +2 -2
- package/lib/Socket/contacts.d.ts +1 -1
- package/lib/Socket/events.d.ts +1 -1
- package/lib/Socket/events.js +14 -20
- package/lib/Socket/index.d.ts +5 -5
- package/lib/Socket/index.js +1 -1
- package/lib/Socket/messages.js +1 -1
- package/lib/Socket/newsletter.d.ts +3 -3
- package/lib/Socket/transport.d.ts +1 -1
- package/lib/Socket/types.d.ts +1 -1
- package/lib/Types/Auth.d.ts +1 -1
- package/lib/Types/Message.d.ts +1 -1
- package/lib/Types/Socket.d.ts +2 -2
- package/lib/Utils/crypto.d.ts +2 -2
- package/lib/Utils/crypto.js +1 -1
- package/lib/Utils/logger.d.ts +2 -2
- package/lib/Utils/logger.js +122 -25
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +4 -1
- package/lib/Utils/process-history-message.js +6 -10
- package/lib/Utils/process-message.js +1 -1
- package/lib/WAProto/runtime.js +5 -2
- package/package.json +3 -3
package/lib/Bridge/adapt.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* (table-driven dispatch, additional validation, schema-derived types,
|
|
8
8
|
* etc.) without rippling through call sites.
|
|
9
9
|
*/
|
|
10
|
-
import type { WhatsAppEvent } from 'whatsapp-rust-bridge';
|
|
10
|
+
import type { WhatsAppEvent } from '@oxidezap/whatsapp-rust-bridge';
|
|
11
11
|
import type { ILogger } from '../Utils/logger.js';
|
|
12
12
|
import type { CanonicalEvent } from './types.js';
|
|
13
13
|
import { adaptBridgeMessageWire } from './schema.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type HistorySyncWireBatch, type WhatsAppEvent } from 'whatsapp-rust-bridge';
|
|
1
|
+
import { type HistorySyncWireBatch, type WhatsAppEvent } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { ILogger } from '../Utils/logger.js';
|
|
3
3
|
declare const HISTORY_SYNC_EVENT_TYPE: 'history_sync';
|
|
4
4
|
export interface DecodedHistorySyncWireBatch {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BinaryReader } from 'whatsapp-rust-bridge';
|
|
2
|
-
import { proto as WAProto } from 'whatsapp-rust-bridge/proto-types';
|
|
1
|
+
import { BinaryReader } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
|
+
import { proto as WAProto } from '@oxidezap/whatsapp-rust-bridge/proto-types';
|
|
3
3
|
import { isConversationHistorySync } from '../Utils/process-history-message.js';
|
|
4
4
|
import { createSparseArray } from '../Utils/sparse-array.js';
|
|
5
5
|
const HISTORY_SYNC_EVENT_TYPE = 'history_sync';
|
package/lib/Bridge/schema.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* `asNumber`, `asString`) at those leak points only — not boilerplate
|
|
23
23
|
* everywhere.
|
|
24
24
|
*/
|
|
25
|
-
import type { MessageWireInfo, WhatsAppEvent } from 'whatsapp-rust-bridge';
|
|
25
|
+
import type { MessageWireInfo, WhatsAppEvent } from '@oxidezap/whatsapp-rust-bridge';
|
|
26
26
|
import type { ILogger } from '../Utils/logger.js';
|
|
27
27
|
import type { CanonicalEvent, CanonicalMessage } from './types.js';
|
|
28
28
|
export type BridgeEventType = WhatsAppEvent['type'];
|
package/lib/Bridge/schema.js
CHANGED
|
@@ -718,8 +718,15 @@ const adaptIncomingCall = (data, logger) => {
|
|
|
718
718
|
const action = isObject(data.action) ? data.action : undefined;
|
|
719
719
|
if (!action)
|
|
720
720
|
return null;
|
|
721
|
-
|
|
722
|
-
|
|
721
|
+
// The bridge `CallAction` union narrows variant-specific fields only on the
|
|
722
|
+
// matching variant, and its group-call variants (group updates, rekeys,
|
|
723
|
+
// waiting rooms) carry no `call_id` at all. `parseCallActionType` admits
|
|
724
|
+
// none of those, so a runtime read through the action's own shape is safe —
|
|
725
|
+
// and is the cheapest way around TS's inability to follow our
|
|
726
|
+
// string-normalized discriminator back into the bridge union.
|
|
727
|
+
const fields = action;
|
|
728
|
+
const actionType = parseCallActionType(fields.type);
|
|
729
|
+
const callId = asString(fields.call_id);
|
|
723
730
|
if (!actionType || !callId) {
|
|
724
731
|
logger?.debug({ data }, 'incoming_call adapter: missing action.type/call_id');
|
|
725
732
|
return null;
|
|
@@ -727,15 +734,8 @@ const adaptIncomingCall = (data, logger) => {
|
|
|
727
734
|
const canonicalAction = {
|
|
728
735
|
type: actionType,
|
|
729
736
|
callId,
|
|
730
|
-
callCreator: asJidAddressString(
|
|
737
|
+
callCreator: asJidAddressString(fields.call_creator)
|
|
731
738
|
};
|
|
732
|
-
// The bridge `CallAction` union narrows variant-specific fields only
|
|
733
|
-
// on the matching variant. We've already validated `action.type` via
|
|
734
|
-
// `parseCallActionType`, so a runtime cast through the action's own
|
|
735
|
-
// shape is safe — reading fields off `unknown` is the cheapest way
|
|
736
|
-
// around TS's inability to follow our string-normalized discriminator
|
|
737
|
-
// back into the bridge union.
|
|
738
|
-
const fields = action;
|
|
739
739
|
if (actionType === 'offer') {
|
|
740
740
|
canonicalAction.callerPn = asJidString(fields.caller_pn);
|
|
741
741
|
canonicalAction.callerCountryCode = asString(fields.caller_country_code);
|
package/lib/Bridge/types.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - All timestamps are unix seconds.
|
|
14
14
|
* - Optional fields use `?` (omitted) rather than `null`.
|
|
15
15
|
*/
|
|
16
|
-
import type { proto } from 'whatsapp-rust-bridge/proto-types';
|
|
16
|
+
import type { proto } from '@oxidezap/whatsapp-rust-bridge/proto-types';
|
|
17
17
|
import type { Chat, Contact, LIDMapping, WAMessage } from '../Types/index.js';
|
|
18
18
|
import type { BinaryNode, WAProto } from '../Types/index.js';
|
|
19
19
|
export interface CanonicalConnected {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GroupMetadataResult } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { GroupMetadataResult } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { GroupMetadata } from '../Types/GroupMetadata.js';
|
|
3
3
|
/**
|
|
4
4
|
* Translate the bridge's protocol-neutral group DTO into the public Baileys
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Basic value codecs for the Baileys legacy-store projection.
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
|
-
import { proto } from 'whatsapp-rust-bridge/proto-types';
|
|
3
|
+
import { proto } from '@oxidezap/whatsapp-rust-bridge/proto-types';
|
|
4
4
|
import { AppState, JsonByteEncoding, LidMapping, NativeStore, TimeValue } from '../constants.js';
|
|
5
5
|
import { bytesToNumbers, fromJsonBytes, toBytes, toJsonBytes } from '../common.js';
|
|
6
6
|
import { parseLidMappingKey } from '../routing.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import { decodeSenderKeyRecordComponents, encodeSenderKeyRecordComponents, importLegacySessionRecordV1, projectLegacySessionRecordV1 } from 'whatsapp-rust-bridge';
|
|
2
|
+
import { decodeSenderKeyRecordComponents, encodeSenderKeyRecordComponents, importLegacySessionRecordV1, projectLegacySessionRecordV1 } from '@oxidezap/whatsapp-rust-bridge';
|
|
3
3
|
import { JsonByteEncoding, LegacySession, NativeStore, TimeValue } from '../constants.js';
|
|
4
4
|
import { EMPTY_BYTES } from '../common.js';
|
|
5
5
|
import { NATIVE_ONLY_PROJECTION } from '../types.js';
|
|
@@ -28,9 +28,18 @@ const integer = (value, label) => {
|
|
|
28
28
|
}
|
|
29
29
|
return value;
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* The two shapes order their states in opposite directions: the core keeps the
|
|
33
|
+
* current state at the front and prunes from the back, while the legacy record
|
|
34
|
+
* is read back-to-front — `getSenderKeyState()` takes the last entry and
|
|
35
|
+
* `addSenderKeyState` drops the first one on overflow. Both conversions below
|
|
36
|
+
* therefore reverse. Carrying an order through unchanged writes the record
|
|
37
|
+
* upside down: the old implementation would send under a stale key and evict
|
|
38
|
+
* the freshest state instead of the oldest.
|
|
39
|
+
*/
|
|
31
40
|
function senderKeyToLegacy(nativeBytes) {
|
|
32
41
|
const record = decodeSenderKeyRecordComponents(nativeBytes);
|
|
33
|
-
const states = record.states.map(state => ({
|
|
42
|
+
const states = record.states.toReversed().map(state => ({
|
|
34
43
|
senderKeyId: state.keyId,
|
|
35
44
|
senderChainKey: {
|
|
36
45
|
iteration: state.chainKey.iteration,
|
|
@@ -54,6 +63,8 @@ function senderKeyFromLegacy(value) {
|
|
|
54
63
|
const parsed = JSON.parse(Buffer.from(value).toString(JsonByteEncoding.UTF8), BufferJSON.reviver);
|
|
55
64
|
if (!Array.isArray(parsed))
|
|
56
65
|
throw new TypeError('legacy sender-key record must contain an array');
|
|
66
|
+
// Indexed against the stored order so a validation error names the state the
|
|
67
|
+
// caller can find in the record; reversed afterwards. See `senderKeyToLegacy`.
|
|
57
68
|
const record = {
|
|
58
69
|
states: parsed.map((state, stateIndex) => ({
|
|
59
70
|
keyId: integer(state.senderKeyId, `sender-key state ${stateIndex} id`),
|
|
@@ -71,6 +82,7 @@ function senderKeyFromLegacy(value) {
|
|
|
71
82
|
}))
|
|
72
83
|
}))
|
|
73
84
|
};
|
|
85
|
+
record.states.reverse();
|
|
74
86
|
return encodeSenderKeyRecordComponents(record);
|
|
75
87
|
}
|
|
76
88
|
const messageKeyIndex = (value) => {
|
|
@@ -91,13 +103,13 @@ function messageKeysFromLegacy(messageKeys) {
|
|
|
91
103
|
function messageKeysToLegacy(messageKeys) {
|
|
92
104
|
return Object.fromEntries(messageKeys.map(messageKey => [messageKey.index, toBase64(messageKey.seed)]));
|
|
93
105
|
}
|
|
94
|
-
function legacyEntryToCore(entry) {
|
|
106
|
+
function legacyEntryToCore(entry, recordRegistrationId) {
|
|
95
107
|
const ratchet = entry.currentRatchet;
|
|
96
108
|
if (!entry._chains || typeof entry._chains !== 'object') {
|
|
97
109
|
throw new TypeError('legacy session is missing its chain catalog');
|
|
98
110
|
}
|
|
99
111
|
return {
|
|
100
|
-
registrationId: entry.registrationId ?? TimeValue.UNKNOWN_SECONDS,
|
|
112
|
+
registrationId: entry.registrationId ?? recordRegistrationId ?? TimeValue.UNKNOWN_SECONDS,
|
|
101
113
|
ratchet: {
|
|
102
114
|
keyPair: {
|
|
103
115
|
public: fromBase64(ratchet.ephemeralKeyPair.pubKey, 'sender ratchet public key'),
|
|
@@ -145,7 +157,7 @@ function sessionFromLegacy(value, defaults) {
|
|
|
145
157
|
const decoded = {
|
|
146
158
|
sessions: Object.entries(record._sessions).map(([indexKey, entry]) => ({
|
|
147
159
|
indexKey: fromBase64(indexKey, 'legacy session index key'),
|
|
148
|
-
session: legacyEntryToCore(entry)
|
|
160
|
+
session: legacyEntryToCore(entry, record.registrationId)
|
|
149
161
|
}))
|
|
150
162
|
};
|
|
151
163
|
return importLegacySessionRecordV1(decoded, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Device credential projection for legacy Baileys authentication states.
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
|
-
import { proto } from 'whatsapp-rust-bridge/proto-types';
|
|
3
|
+
import { proto } from '@oxidezap/whatsapp-rust-bridge/proto-types';
|
|
4
4
|
import { WA_DEFAULT_VERSION } from '../../Defaults/index.js';
|
|
5
5
|
import { jidDecode, jidEncode } from '../../WABinary/jid-utils.js';
|
|
6
6
|
import { DeviceRecordKey, JsonByteEncoding, SignalDomain, SignalKeyLength, TimeValue } from './constants.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, readFile, stat, unlink, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { proto } from 'whatsapp-rust-bridge/proto-types';
|
|
3
|
+
import { proto } from '@oxidezap/whatsapp-rust-bridge/proto-types';
|
|
4
4
|
import { BufferJSON } from '../../Utils/generics.js';
|
|
5
5
|
import { JsonByteEncoding, LegacyMultiFile, LegacyStore } from './constants.js';
|
|
6
6
|
const PATH_SEPARATOR = /[\\/]/g;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsStoreCallbacks } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { JsStoreCallbacks } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { SignalCreds, SignalKeyStore } from '../../Types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Project a neutral native byte store as the public legacy key store. Values
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MediaType as BridgeMediaType } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { MediaType as BridgeMediaType } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { MediaType } from '../Defaults/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Narrow upstream's semantic media names to the protocol-neutral modes the
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MessageRetransmissionInput } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { MessageRetransmissionInput } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { BinaryNode, MessageRelayOptions } from '../Types/index.js';
|
|
3
3
|
type OwnRelayIdentity = {
|
|
4
4
|
id?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { BinaryReader } from 'whatsapp-rust-bridge';
|
|
3
|
+
import { BinaryReader } from '@oxidezap/whatsapp-rust-bridge';
|
|
4
4
|
import { PROTO_ENUM_SCHEMAS, PROTO_FIELD_FLAG, PROTO_FIELD_KIND, PROTO_MESSAGE_SCHEMAS } from '../WAProto/compatibility-schema.js';
|
|
5
5
|
const INSTANCE_SCHEMA = Symbol('proto compatibility schema');
|
|
6
6
|
const EMPTY_ARRAY = Object.freeze([]);
|
|
@@ -138,24 +138,62 @@ const lookupPath = (root, path) => {
|
|
|
138
138
|
}
|
|
139
139
|
return current;
|
|
140
140
|
};
|
|
141
|
-
const installPath = (root, path, value) => {
|
|
142
|
-
const segments = path.split('.');
|
|
143
|
-
const leaf = segments.pop();
|
|
144
|
-
if (!leaf)
|
|
145
|
-
throw new Error(`invalid protobuf path: ${path}`);
|
|
146
|
-
let current = root;
|
|
147
|
-
for (const segment of segments) {
|
|
148
|
-
const next = current[segment];
|
|
149
|
-
if (!isObject(next) && typeof next !== 'function')
|
|
150
|
-
current[segment] = {};
|
|
151
|
-
current = current[segment];
|
|
152
|
-
}
|
|
153
|
-
current[leaf] = value;
|
|
154
|
-
};
|
|
155
141
|
const isSourceCodec = (value) => (isObject(value) || typeof value === 'function') &&
|
|
156
142
|
typeof value.encode === 'function' &&
|
|
157
143
|
typeof value.decode === 'function';
|
|
158
|
-
const
|
|
144
|
+
const buildSchemaTree = (messagePaths, enumPaths) => {
|
|
145
|
+
const roots = new Map();
|
|
146
|
+
const nodeFor = (path) => {
|
|
147
|
+
let level = roots;
|
|
148
|
+
let node;
|
|
149
|
+
for (const segment of path.split('.')) {
|
|
150
|
+
node = level.get(segment);
|
|
151
|
+
if (!node) {
|
|
152
|
+
node = { children: new Map() };
|
|
153
|
+
level.set(segment, node);
|
|
154
|
+
}
|
|
155
|
+
level = node.children;
|
|
156
|
+
}
|
|
157
|
+
if (!node)
|
|
158
|
+
throw new Error(`invalid protobuf path: ${path}`);
|
|
159
|
+
return node;
|
|
160
|
+
};
|
|
161
|
+
messagePaths.forEach((path, messageId) => {
|
|
162
|
+
nodeFor(path).messageId = messageId;
|
|
163
|
+
});
|
|
164
|
+
enumPaths.forEach((path, enumId) => {
|
|
165
|
+
nodeFor(path).enumId = enumId;
|
|
166
|
+
});
|
|
167
|
+
return roots;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Self-replacing getter, so only the first read pays. It stays enumerable,
|
|
171
|
+
* writable and configurable so the entry behaves exactly like the eagerly
|
|
172
|
+
* installed value it replaced.
|
|
173
|
+
*
|
|
174
|
+
* The replacement targets the *receiver*, not `target`: these descriptors are
|
|
175
|
+
* also copied onto the exported namespace, so writing back to `target` would
|
|
176
|
+
* leave the object actually being read still holding an accessor and rebuild on
|
|
177
|
+
* every access — 7.4% of process CPU when this was wrong.
|
|
178
|
+
*/
|
|
179
|
+
const defineLazyValue = (target, key, build) => {
|
|
180
|
+
const settle = (receiver, value) => {
|
|
181
|
+
const owner = (isObject(receiver) || typeof receiver === 'function' ? receiver : target);
|
|
182
|
+
Object.defineProperty(owner, key, { configurable: true, enumerable: true, value, writable: true });
|
|
183
|
+
};
|
|
184
|
+
Object.defineProperty(target, key, {
|
|
185
|
+
configurable: true,
|
|
186
|
+
enumerable: true,
|
|
187
|
+
get() {
|
|
188
|
+
const value = build();
|
|
189
|
+
settle(this, value);
|
|
190
|
+
return value;
|
|
191
|
+
},
|
|
192
|
+
set(value) {
|
|
193
|
+
settle(this, value);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
};
|
|
159
197
|
class ProtoCompatibilityRuntime {
|
|
160
198
|
constructor(sourceNamespace) {
|
|
161
199
|
this.namespace = { ...sourceNamespace };
|
|
@@ -171,15 +209,41 @@ class ProtoCompatibilityRuntime {
|
|
|
171
209
|
const candidate = lookupPath(sourceNamespace, path);
|
|
172
210
|
return isSourceCodec(candidate) ? candidate : undefined;
|
|
173
211
|
});
|
|
174
|
-
|
|
212
|
+
// Building all 498 eagerly cost ~4.6 MB of RSS in every importing process
|
|
213
|
+
// while a full connection touches under a dozen. `Array.from` rather than
|
|
214
|
+
// `new Array(n)` keeps the array packed, so `constructorFor`'s indexed read
|
|
215
|
+
// stays on the fast element kind.
|
|
216
|
+
this.constructors = Array.from({ length: PROTO_MESSAGE_SCHEMAS.length });
|
|
175
217
|
this.unsupportedCodecs = Object.freeze(PROTO_MESSAGE_SCHEMAS.flatMap(([path], schemaId) => (this.sourceCodecs[schemaId] ? [] : [path])));
|
|
176
|
-
const
|
|
177
|
-
for (const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
218
|
+
const tree = buildSchemaTree(PROTO_MESSAGE_SCHEMAS.map(([path]) => path), PROTO_ENUM_SCHEMAS.map(([path]) => path));
|
|
219
|
+
for (const [name, node] of tree)
|
|
220
|
+
this.installNode(this.namespace, name, node);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Nested types are installed only once their container is read, so using a
|
|
224
|
+
* container does not build what is nested inside it.
|
|
225
|
+
*/
|
|
226
|
+
installNode(target, name, node) {
|
|
227
|
+
defineLazyValue(target, name, () => {
|
|
228
|
+
// Build once: this getter is reachable from both this namespace and the
|
|
229
|
+
// exported copy, and a second build would reinstall accessors over
|
|
230
|
+
// entries a caller had already resolved.
|
|
231
|
+
if (node.value === undefined) {
|
|
232
|
+
const value = node.messageId !== undefined
|
|
233
|
+
? this.constructorFor(node.messageId)
|
|
234
|
+
: node.enumId !== undefined
|
|
235
|
+
? this.enums[node.enumId].publicValue
|
|
236
|
+
: {};
|
|
237
|
+
node.value = value;
|
|
238
|
+
for (const [childName, child] of node.children)
|
|
239
|
+
this.installNode(value, childName, child);
|
|
240
|
+
}
|
|
241
|
+
return node.value;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
constructorFor(schemaId) {
|
|
245
|
+
var _a;
|
|
246
|
+
return ((_a = this.constructors)[schemaId] ?? (_a[schemaId] = this.makeConstructor(schemaId, PROTO_MESSAGE_SCHEMAS[schemaId][1], this.sourceCodecs[schemaId])));
|
|
183
247
|
}
|
|
184
248
|
makeEnum(entries) {
|
|
185
249
|
const publicValue = {};
|
|
@@ -312,7 +376,7 @@ class ProtoCompatibilityRuntime {
|
|
|
312
376
|
}
|
|
313
377
|
}
|
|
314
378
|
fromObject(schemaId, input) {
|
|
315
|
-
const constructor = this.
|
|
379
|
+
const constructor = this.constructorFor(schemaId);
|
|
316
380
|
if (input instanceof constructor)
|
|
317
381
|
return input;
|
|
318
382
|
const data = input;
|
|
@@ -520,7 +584,7 @@ class ProtoCompatibilityRuntime {
|
|
|
520
584
|
}
|
|
521
585
|
if (hasOwn(object, 'toJSON'))
|
|
522
586
|
delete object.toJSON;
|
|
523
|
-
Object.setPrototypeOf(object, this.
|
|
587
|
+
Object.setPrototypeOf(object, this.constructorFor(schemaId).prototype);
|
|
524
588
|
return object;
|
|
525
589
|
}
|
|
526
590
|
projectForEncode(schemaId, value) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlocklistEntryResult, BusinessProfileResult, MembershipRequestResult, ParticipantChangeResult } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { BlocklistEntryResult, BusinessProfileResult, MembershipRequestResult, ParticipantChangeResult } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { BinaryNode, WABusinessProfile } from '../Types/index.js';
|
|
3
3
|
export type ParticipantUpdateResult = {
|
|
4
4
|
status: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WasmWhatsAppClient } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { BinaryNode } from '../Types/index.js';
|
|
3
3
|
type StanzaResponseClient = Pick<WasmWhatsAppClient, 'acknowledgeStanza' | 'rejectStanza' | 'requestMessageRetry'>;
|
|
4
4
|
export interface StanzaResponseContext {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UsyncQuery as NativeUsyncQuery, UsyncResponse as NativeUsyncResponse } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { UsyncQuery as NativeUsyncQuery, UsyncResponse as NativeUsyncResponse } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { BinaryNode } from '../../Types/index.js';
|
|
3
3
|
import { type USyncQuery, type USyncQueryResult } from '../../WAUSync/USyncQuery.js';
|
|
4
4
|
export type RawUSyncQuery = (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import { URL } from 'node:url';
|
|
3
|
-
import type { WasmWhatsAppClient } from 'whatsapp-rust-bridge';
|
|
3
|
+
import type { WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
|
|
4
4
|
import type { SocketConfig } from '../Types/index.js';
|
|
5
5
|
type ReadyState = 0 | 1 | 2 | 3;
|
|
6
6
|
type EventListener = Parameters<EventEmitter['on']>[1];
|
|
@@ -20,7 +20,7 @@ export declare const makeCommunityMethods: (ctx: SocketContext, groups?: {
|
|
|
20
20
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
21
21
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
22
22
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
23
|
-
groupAcceptInviteV4: (key: string | import("../index.js").WAMessageKey, inviteMessage: import("whatsapp-rust-bridge/proto-types").proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
23
|
+
groupAcceptInviteV4: (key: string | import("../index.js").WAMessageKey, inviteMessage: import("@oxidezap/whatsapp-rust-bridge/proto-types").proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
24
24
|
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
25
25
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
26
26
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
@@ -49,7 +49,7 @@ export declare const makeCommunityMethods: (ctx: SocketContext, groups?: {
|
|
|
49
49
|
communityRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
50
50
|
communityAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
51
51
|
communityRevokeInviteV4: (communityJid: string, invitedJid: string) => Promise<boolean>;
|
|
52
|
-
communityAcceptInviteV4: (key: string | import("../index.js").WAMessageKey, inviteMessage: import("whatsapp-rust-bridge/proto-types").proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
52
|
+
communityAcceptInviteV4: (key: string | import("../index.js").WAMessageKey, inviteMessage: import("@oxidezap/whatsapp-rust-bridge/proto-types").proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
53
53
|
communityGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
54
54
|
communityToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
55
55
|
communitySettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
package/lib/Socket/contacts.d.ts
CHANGED
|
@@ -12,6 +12,6 @@ export type OnWhatsAppResult = {
|
|
|
12
12
|
export declare const makeContactMethods: (ctx: SocketContext) => {
|
|
13
13
|
onWhatsApp: (...phoneNumber: string[]) => Promise<OnWhatsAppResult[] | undefined>;
|
|
14
14
|
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | undefined>;
|
|
15
|
-
fetchUserInfo: (...jids: string[]) => Promise<Record<string, import("whatsapp-rust-bridge").UserInfoResult>>;
|
|
15
|
+
fetchUserInfo: (...jids: string[]) => Promise<Record<string, import("@oxidezap/whatsapp-rust-bridge").UserInfoResult>>;
|
|
16
16
|
};
|
|
17
17
|
//# sourceMappingURL=contacts.d.ts.map
|
package/lib/Socket/events.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* mapped type so TS forces a handler per variant — a missing handler
|
|
7
7
|
* is a compile error.
|
|
8
8
|
*/
|
|
9
|
-
import type { WhatsAppEvent, WhatsAppEventCallbacks } from 'whatsapp-rust-bridge';
|
|
9
|
+
import type { WhatsAppEvent, WhatsAppEventCallbacks } from '@oxidezap/whatsapp-rust-bridge';
|
|
10
10
|
import type { CanonicalEvent } from '../Bridge/index.js';
|
|
11
11
|
import type { SocketContext } from './types.js';
|
|
12
12
|
interface EventCallbacks {
|
package/lib/Socket/events.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* is a compile error.
|
|
8
8
|
*/
|
|
9
9
|
import Long from 'long';
|
|
10
|
-
import { BinaryReader,
|
|
10
|
+
import { BinaryReader, decodeMessageWireBatch, decodeReceiptWireBatch, decodeServerAckWireBatch } from '@oxidezap/whatsapp-rust-bridge';
|
|
11
11
|
import { adaptBridgeEvent, adaptBridgeMessageWire } from '../Bridge/index.js';
|
|
12
12
|
import { decodeHistorySyncWireBatch } from '../Bridge/history-sync-wire.js';
|
|
13
13
|
import { bridgeGroupMetadataToBaileys } from '../Compatibility/group-metadata.js';
|
|
@@ -25,7 +25,6 @@ import { mapReachoutTimelock } from './reachout.js';
|
|
|
25
25
|
const CANONICAL_MESSAGE_EVENT = 'message';
|
|
26
26
|
const MESSAGE_UPSERT_APPEND = 'append';
|
|
27
27
|
const MESSAGE_UPSERT_NOTIFY = 'notify';
|
|
28
|
-
const MESSAGE_WIRE_OFFSET_SENTINEL_COUNT = 1;
|
|
29
28
|
/** Emit CB: pattern events on the ws EventEmitter for retrocompat. */
|
|
30
29
|
const emitCBEvents = (ctx, node) => {
|
|
31
30
|
const { ws } = ctx;
|
|
@@ -791,35 +790,30 @@ export const makeEventHandlers = (ctx, callbacks) => {
|
|
|
791
790
|
dispatchCanonicalEvent(canonical, dispatchCtx);
|
|
792
791
|
};
|
|
793
792
|
const onMessageBatch = (batch) => {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
const messageCount = batch.messageOffsets.length - MESSAGE_WIRE_OFFSET_SENTINEL_COUNT;
|
|
799
|
-
let infos;
|
|
793
|
+
// The batch crosses as one buffer; the decoder validates its header and
|
|
794
|
+
// returns views over it, so payload count and metadata count agree by
|
|
795
|
+
// construction.
|
|
796
|
+
let view;
|
|
800
797
|
try {
|
|
801
|
-
|
|
798
|
+
view = decodeMessageWireBatch(batch);
|
|
802
799
|
}
|
|
803
800
|
catch (err) {
|
|
804
|
-
ctx.logger.error({ err }, 'failed to decode message wire
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
if (infos.length !== messageCount) {
|
|
808
|
-
ctx.logger.error({ infoCount: infos.length, messageCount }, 'message wire batch metadata count does not match its payload count');
|
|
801
|
+
ctx.logger.error({ err }, 'failed to decode the message wire batch');
|
|
809
802
|
return;
|
|
810
803
|
}
|
|
804
|
+
const { messageData, messageOffsets, infos } = view;
|
|
811
805
|
// Decode through the runtime facade so each payload materializes as a
|
|
812
806
|
// hydrated runtime instance: `WebMessageInfo.fromObject` then keeps the
|
|
813
807
|
// message subtree via its instanceof short-circuit instead of walking
|
|
814
808
|
// and reallocating the whole tree — the dominant per-message allocation
|
|
815
809
|
// cost on the hot path. Lenient like the history-sync decoder: one
|
|
816
810
|
// malformed payload is skipped, not fatal to the batch.
|
|
817
|
-
const messages = Array.from({ length:
|
|
818
|
-
const reader = new BinaryReader(
|
|
819
|
-
for (let index = 0; index <
|
|
811
|
+
const messages = Array.from({ length: infos.length });
|
|
812
|
+
const reader = new BinaryReader(messageData);
|
|
813
|
+
for (let index = 0; index < infos.length; index++) {
|
|
820
814
|
try {
|
|
821
|
-
const start =
|
|
822
|
-
const end =
|
|
815
|
+
const start = messageOffsets[index];
|
|
816
|
+
const end = messageOffsets[index + 1];
|
|
823
817
|
reader.pos = start;
|
|
824
818
|
messages[index] = WAProto.Message.decode(reader, end - start);
|
|
825
819
|
}
|
|
@@ -828,7 +822,7 @@ export const makeEventHandlers = (ctx, callbacks) => {
|
|
|
828
822
|
ctx.logger.warn({ err, index }, 'skipping malformed wire message');
|
|
829
823
|
}
|
|
830
824
|
}
|
|
831
|
-
dispatchCanonicalBatch(ctx, dispatchCtx,
|
|
825
|
+
dispatchCanonicalBatch(ctx, dispatchCtx, infos.length, index => adaptBridgeMessageWire(messages[index], infos[index], ctx.logger));
|
|
832
826
|
};
|
|
833
827
|
const onHistorySyncBatch = (batch) => {
|
|
834
828
|
const decoded = decodeHistorySyncWireBatch(batch, ctx.logger);
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import { type UploadMediaResult, type WasmWhatsAppClient } from 'whatsapp-rust-bridge';
|
|
2
|
+
import { type UploadMediaResult, type WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
|
|
3
3
|
import { WebSocketClient } from '../Compatibility/websocket-client.js';
|
|
4
4
|
import { type MediaType } from '../Defaults/index.js';
|
|
5
5
|
import type { BinaryNode, AuthenticationCreds, ConnectionState, Contact, ReachoutTimelockState, SignalKeyStoreWithTransaction, UserFacingSocketConfig, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WABusinessProfile, WAReadReceiptsValue, WAMessage, WAMessageKey } from '../Types/index.js';
|
|
@@ -20,7 +20,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
20
20
|
resyncAppState: (_collections?: readonly import("../index.js").WAPatchName[], _isInitialSync?: boolean) => Promise<void>;
|
|
21
21
|
onWhatsApp: (...phoneNumber: string[]) => Promise<import("./contacts.js").OnWhatsAppResult[] | undefined>;
|
|
22
22
|
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | undefined>;
|
|
23
|
-
fetchUserInfo: (...jids: string[]) => Promise<Record<string, import("whatsapp-rust-bridge").UserInfoResult>>;
|
|
23
|
+
fetchUserInfo: (...jids: string[]) => Promise<Record<string, import("@oxidezap/whatsapp-rust-bridge").UserInfoResult>>;
|
|
24
24
|
groupMetadata: (jid: string) => Promise<import("../index.js").GroupMetadata>;
|
|
25
25
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../index.js").GroupMetadata>;
|
|
26
26
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -81,9 +81,9 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
81
81
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../index.js").MessageReceiptType) => Promise<void>;
|
|
82
82
|
sendReceipts: (keys: WAMessageKey[], type: import("../index.js").MessageReceiptType) => Promise<void>;
|
|
83
83
|
requestPlaceholderResend: (messageKey: WAMessageKey, msgData?: Partial<WAMessage>) => Promise<string | undefined>;
|
|
84
|
-
newsletterCreate: (name: string, description?: string) => Promise<import("whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
85
|
-
newsletterMetadata: (jid: string) => Promise<import("whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
86
|
-
newsletterSubscribe: (jid: string) => Promise<import("whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
84
|
+
newsletterCreate: (name: string, description?: string) => Promise<import("@oxidezap/whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
85
|
+
newsletterMetadata: (jid: string) => Promise<import("@oxidezap/whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
86
|
+
newsletterSubscribe: (jid: string) => Promise<import("@oxidezap/whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
87
87
|
newsletterUnsubscribe: (jid: string) => Promise<void>;
|
|
88
88
|
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
89
89
|
newsletterMute: (jid: string, mute: boolean) => Promise<void>;
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
|
-
import { createWhatsAppClient, encodeProto, initWasmEngine } from 'whatsapp-rust-bridge';
|
|
3
|
+
import { createWhatsAppClient, encodeProto, initWasmEngine } from '@oxidezap/whatsapp-rust-bridge';
|
|
4
4
|
import { normalizeSocketAuthenticationState } from '../Compatibility/internal/auth-state.js';
|
|
5
5
|
import { makeMutex } from '../Compatibility/internal/make-mutex.js';
|
|
6
6
|
import { isNativeMemoryStore } from '../Compatibility/internal/native-memory-store.js';
|
package/lib/Socket/messages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { encodeProto } from 'whatsapp-rust-bridge';
|
|
1
|
+
import { encodeProto } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import { planMessageRelay } from '../Compatibility/message-relay.js';
|
|
3
3
|
import { receiptMessageKeys } from '../Compatibility/message-keys.js';
|
|
4
4
|
import { WAProto } from '../Types/index.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { SocketContext } from './types.js';
|
|
2
2
|
export declare const makeNewsletterMethods: (ctx: SocketContext) => {
|
|
3
|
-
newsletterCreate: (name: string, description?: string) => Promise<import("whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
4
|
-
newsletterMetadata: (jid: string) => Promise<import("whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
5
|
-
newsletterSubscribe: (jid: string) => Promise<import("whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
3
|
+
newsletterCreate: (name: string, description?: string) => Promise<import("@oxidezap/whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
4
|
+
newsletterMetadata: (jid: string) => Promise<import("@oxidezap/whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
5
|
+
newsletterSubscribe: (jid: string) => Promise<import("@oxidezap/whatsapp-rust-bridge").NewsletterMetadataResult>;
|
|
6
6
|
newsletterUnsubscribe: (jid: string) => Promise<void>;
|
|
7
7
|
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
8
8
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsHttpClientConfig, JsTransportCallbacks } from 'whatsapp-rust-bridge';
|
|
1
|
+
import type { JsHttpClientConfig, JsTransportCallbacks } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { ILogger } from '../Utils/logger.js';
|
|
3
3
|
interface TransportConfig {
|
|
4
4
|
waWebSocketUrl: string | URL;
|
package/lib/Socket/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EventEmitter } from 'events';
|
|
2
|
-
import type { WasmWhatsAppClient } from 'whatsapp-rust-bridge';
|
|
2
|
+
import type { WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
|
|
3
3
|
import type { Contact, SocketConfig } from '../Types/index.js';
|
|
4
4
|
import type { makeEventBuffer } from '../Utils/event-buffer.js';
|
|
5
5
|
import type { ILogger } from '../Utils/logger.js';
|
package/lib/Types/Auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Buffer } from 'node:buffer';
|
|
2
|
-
import type { JsStoreCallbacks } from 'whatsapp-rust-bridge';
|
|
2
|
+
import type { JsStoreCallbacks } from '@oxidezap/whatsapp-rust-bridge';
|
|
3
3
|
import type { proto } from '../WAProto/runtime.js';
|
|
4
4
|
import type { Contact } from './Contact.js';
|
|
5
5
|
import type { MinimalMessage } from './Message.js';
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Readable } from 'stream';
|
|
2
2
|
import type { URL } from 'url';
|
|
3
|
-
import type { MediaType as BridgeMediaType, UploadMediaResult, WasmWhatsAppClient } from 'whatsapp-rust-bridge';
|
|
3
|
+
import type { MediaType as BridgeMediaType, UploadMediaResult, WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
|
|
4
4
|
import type { WAMessageAddressingMode as WAMessageAddressingModeType } from '../Compatibility/public-api/enum-types.js';
|
|
5
5
|
import { proto } from '../WAProto/runtime.js';
|
|
6
6
|
import type { MediaType } from '../Defaults/index.js';
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Agent } from 'node:https';
|
|
2
2
|
import type { URL } from 'url';
|
|
3
|
-
import type { CacheConfig, DevicePropsInput } from 'whatsapp-rust-bridge';
|
|
3
|
+
import type { CacheConfig, DevicePropsInput } from '@oxidezap/whatsapp-rust-bridge';
|
|
4
4
|
import type { proto } from '../WAProto/runtime.js';
|
|
5
|
-
export type { DeviceAppVersion, DeviceHistorySyncConfig, DevicePlatformType, DevicePropsInput } from 'whatsapp-rust-bridge';
|
|
5
|
+
export type { DeviceAppVersion, DeviceHistorySyncConfig, DevicePlatformType, DevicePropsInput } from '@oxidezap/whatsapp-rust-bridge';
|
|
6
6
|
import type { ILogger } from '../Utils/logger.js';
|
|
7
7
|
import type { AuthenticationState, LIDMapping, SignalAuthState } from './Auth.js';
|
|
8
8
|
import type { GroupMetadata } from './GroupMetadata.js';
|
package/lib/Utils/crypto.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { hkdf, md5 } from 'whatsapp-rust-bridge';
|
|
1
|
+
import { hkdf, md5 } from '@oxidezap/whatsapp-rust-bridge';
|
|
2
2
|
import type { KeyPair } from '../Types/Auth.js';
|
|
3
3
|
export { hkdf, md5 };
|
|
4
|
-
export type { HkdfInfo } from 'whatsapp-rust-bridge';
|
|
4
|
+
export type { HkdfInfo } from '@oxidezap/whatsapp-rust-bridge';
|
|
5
5
|
/** Prefix Signal's version byte when the public key is in raw 32-byte form. */
|
|
6
6
|
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>;
|
|
7
7
|
export declare const Curve: {
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { calculateAgreement, calculateSignature, generateKeyPair, hkdf, md5, verifySignature } from 'whatsapp-rust-bridge';
|
|
2
|
+
import { calculateAgreement, calculateSignature, generateKeyPair, hkdf, md5, verifySignature } from '@oxidezap/whatsapp-rust-bridge';
|
|
3
3
|
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
4
4
|
import { aesCbc256Decrypt, aesCbc256Encrypt, aesGcm256Decrypt, aesGcm256Encrypt, hmacDigest } from '../Platform/crypto.js';
|
|
5
5
|
export { hkdf, md5 };
|
package/lib/Utils/logger.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Logger } from 'pino';
|
|
2
2
|
export interface ILogger {
|
|
3
3
|
level: string;
|
|
4
4
|
child(obj: Record<string, unknown>): ILogger;
|
|
@@ -8,6 +8,6 @@ export interface ILogger {
|
|
|
8
8
|
warn(obj: unknown, msg?: string): void;
|
|
9
9
|
error(obj: unknown, msg?: string): void;
|
|
10
10
|
}
|
|
11
|
-
declare const _default:
|
|
11
|
+
declare const _default: Logger;
|
|
12
12
|
export default _default;
|
|
13
13
|
//# sourceMappingURL=logger.d.ts.map
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,27 +1,124 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const DEFAULT_LEVEL = 'info';
|
|
3
|
+
const REDACTED_PATHS = [
|
|
4
|
+
'creds',
|
|
5
|
+
'authState',
|
|
6
|
+
'noiseKey',
|
|
7
|
+
'signedIdentityKey',
|
|
8
|
+
'advSecretKey',
|
|
9
|
+
'privateKey',
|
|
10
|
+
'secretKey',
|
|
11
|
+
'preKey.privateKey',
|
|
12
|
+
'*.creds',
|
|
13
|
+
'*.authState',
|
|
14
|
+
'*.noiseKey',
|
|
15
|
+
'*.signedIdentityKey',
|
|
16
|
+
'*.advSecretKey',
|
|
17
|
+
'*.privateKey',
|
|
18
|
+
'*.secretKey'
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Deferred because building pino at module evaluation cost ~10 MB of RSS in every
|
|
22
|
+
* importing process: ~4.5 MB for pino's module graph, the rest for the Date/ICU
|
|
23
|
+
* machinery V8 materializes when the configured `timestamp` runs — which pino
|
|
24
|
+
* calls while *constructing* the logger. Applications that pass their own
|
|
25
|
+
* `SocketConfig.logger` never needed any of it.
|
|
26
|
+
*
|
|
27
|
+
* `require` rather than a dynamic `import`, because ILogger's methods are
|
|
28
|
+
* synchronous: an async resolution would have to drop or queue the first lines.
|
|
29
|
+
*/
|
|
30
|
+
let rootLogger;
|
|
31
|
+
const resolveRootLogger = () => {
|
|
32
|
+
if (!rootLogger) {
|
|
33
|
+
const requireFrom = createRequire(import.meta.url);
|
|
34
|
+
const pino = requireFrom('pino');
|
|
35
|
+
rootLogger = pino({
|
|
36
|
+
name: 'baileyrs',
|
|
37
|
+
level: process.env.BAILEYRS_LOG_LEVEL || DEFAULT_LEVEL,
|
|
38
|
+
timestamp: () => `,"time":"${new Date().toJSON()}"`,
|
|
39
|
+
redact: { paths: REDACTED_PATHS, censor: '[REDACTED]' }
|
|
40
|
+
});
|
|
25
41
|
}
|
|
26
|
-
|
|
42
|
+
return rootLogger;
|
|
43
|
+
};
|
|
44
|
+
const createDeferredLogger = (bindings, parent, childOptions) => {
|
|
45
|
+
let resolved;
|
|
46
|
+
let pendingLevel;
|
|
47
|
+
const members = new Map();
|
|
48
|
+
const resolve = () => {
|
|
49
|
+
if (!resolved) {
|
|
50
|
+
const source = parent ? parent.resolve() : resolveRootLogger();
|
|
51
|
+
resolved = bindings ? source.child(bindings, childOptions) : source;
|
|
52
|
+
if (pendingLevel !== undefined)
|
|
53
|
+
resolved.level = pendingLevel;
|
|
54
|
+
}
|
|
55
|
+
return resolved;
|
|
56
|
+
};
|
|
57
|
+
const peekLevel = () => resolved?.level ??
|
|
58
|
+
pendingLevel ??
|
|
59
|
+
childOptions?.level ??
|
|
60
|
+
parent?.level() ??
|
|
61
|
+
process.env.BAILEYRS_LOG_LEVEL ??
|
|
62
|
+
DEFAULT_LEVEL;
|
|
63
|
+
const self = { level: peekLevel, resolve };
|
|
64
|
+
// Hoisted so `logger.child` keeps the stable identity a plain property has.
|
|
65
|
+
const child = (extra, options) => createDeferredLogger(extra, self, options);
|
|
66
|
+
// Typed as pino's Logger, not ILogger: narrowing would reject `logger.fatal(...)`
|
|
67
|
+
// at compile time even though the proxy forwards it.
|
|
68
|
+
const target = {};
|
|
69
|
+
return new Proxy(target, {
|
|
70
|
+
get(_target, property) {
|
|
71
|
+
if (property === 'child')
|
|
72
|
+
return child;
|
|
73
|
+
if (property === 'level' && !resolved)
|
|
74
|
+
return peekLevel();
|
|
75
|
+
const cached = members.get(property);
|
|
76
|
+
if (cached !== undefined)
|
|
77
|
+
return cached;
|
|
78
|
+
const logger = resolve();
|
|
79
|
+
const value = logger[property];
|
|
80
|
+
if (typeof value !== 'function')
|
|
81
|
+
return value;
|
|
82
|
+
const bound = value.bind(logger);
|
|
83
|
+
members.set(property, bound);
|
|
84
|
+
return bound;
|
|
85
|
+
},
|
|
86
|
+
set(_target, property, value) {
|
|
87
|
+
if (property === 'level' && !resolved) {
|
|
88
|
+
pendingLevel = value;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
;
|
|
92
|
+
resolve()[property] = value;
|
|
93
|
+
// Whole cache, not just this key: pino swaps its log methods for noops
|
|
94
|
+
// when `level` changes, so a cached `info` would stay silent forever.
|
|
95
|
+
members.clear();
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
has(_target, property) {
|
|
99
|
+
return property === 'child' || property === 'level' || property in resolve();
|
|
100
|
+
},
|
|
101
|
+
deleteProperty(_target, property) {
|
|
102
|
+
members.delete(property);
|
|
103
|
+
delete resolve()[property];
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
defineProperty(_target, property, descriptor) {
|
|
107
|
+
// Forwarded, or the definition would land on the empty target while
|
|
108
|
+
// every other trap kept answering from the resolved logger.
|
|
109
|
+
members.clear();
|
|
110
|
+
return Reflect.defineProperty(resolve(), property, descriptor);
|
|
111
|
+
},
|
|
112
|
+
ownKeys() {
|
|
113
|
+
return Reflect.ownKeys(resolve());
|
|
114
|
+
},
|
|
115
|
+
getOwnPropertyDescriptor(_target, property) {
|
|
116
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(resolve(), property);
|
|
117
|
+
// Forced configurable: the proxy target is an empty extensible object,
|
|
118
|
+
// and reporting a non-configurable key it does not own is a TypeError.
|
|
119
|
+
return descriptor && { ...descriptor, configurable: true };
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
export default createDeferredLogger();
|
|
27
124
|
//# sourceMappingURL=logger.js.map
|
package/lib/Utils/messages.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
|
-
import type { WasmWhatsAppClient } from 'whatsapp-rust-bridge';
|
|
3
|
+
import type { WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
|
|
4
4
|
import { type MediaType } from '../Defaults/index.js';
|
|
5
5
|
import type { AnyMediaMessageContent, AnyMessageContent, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAMessageKey } from '../Types/index.js';
|
|
6
6
|
import { WAProto } from '../Types/index.js';
|
package/lib/Utils/messages.js
CHANGED
|
@@ -746,9 +746,12 @@ export const downloadContentFromMessage = async (mediaContent, type, opts = {})
|
|
|
746
746
|
throw new Boom('downloadContentFromMessage: no bridge client available. ' +
|
|
747
747
|
'Pass `opts.client = sock.waClient`, or call after `makeWASocket()` has initialized.', { statusCode: 500 });
|
|
748
748
|
}
|
|
749
|
+
// `url` is seeded because the media guard downstream keys off its presence,
|
|
750
|
+
// and content addressed only by `directPath` (history-sync notifications
|
|
751
|
+
// carry no `url` field at all) would otherwise be rejected as non-media.
|
|
749
752
|
const fakeMessage = {
|
|
750
753
|
key: {},
|
|
751
|
-
message: { [`${type}Message`]: mediaContent }
|
|
754
|
+
message: { [`${type}Message`]: { url: null, ...mediaContent } }
|
|
752
755
|
};
|
|
753
756
|
return downloadMediaMessage(fakeMessage, 'stream', opts, {
|
|
754
757
|
logger: opts.logger ?? activeBridgeLogger ?? noopLogger,
|
|
@@ -10,9 +10,7 @@
|
|
|
10
10
|
* are limited to swapping upstream imports for baileyrs equivalents and
|
|
11
11
|
* keeping the WAProto namespace as our re-export.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
14
|
-
import { promisify } from 'node:util';
|
|
15
|
-
import { createInflate, inflate } from 'node:zlib';
|
|
13
|
+
import { inflateZlib } from '@oxidezap/whatsapp-rust-bridge';
|
|
16
14
|
import { proto } from '../WAProto/runtime.js';
|
|
17
15
|
import { WAProto } from '../Types/index.js';
|
|
18
16
|
import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser } from '../WABinary/jid-utils.js';
|
|
@@ -21,7 +19,6 @@ import { toNumber } from './generics.js';
|
|
|
21
19
|
import { downloadContentFromMessage, normalizeMessageContent } from './messages.js';
|
|
22
20
|
import { createSparseArray } from './sparse-array.js';
|
|
23
21
|
const STUB = WAProto.WebMessageInfo.StubType;
|
|
24
|
-
const inflatePromise = promisify(inflate);
|
|
25
22
|
const extractPnFromMessages = (messages) => {
|
|
26
23
|
for (let index = 0; index < messages.length; index++) {
|
|
27
24
|
const msgItem = messages[index];
|
|
@@ -190,16 +187,15 @@ export const processHistoryMessage = (item, logger) => {
|
|
|
190
187
|
/** Download, decrypt and inflate an external history-sync blob. */
|
|
191
188
|
export const downloadHistory = async (msg, options) => {
|
|
192
189
|
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return proto.HistorySync.decode(Buffer.concat(chunks));
|
|
190
|
+
const compressed = [];
|
|
191
|
+
for await (const chunk of stream)
|
|
192
|
+
compressed.push(chunk);
|
|
193
|
+
return proto.HistorySync.decode(inflateZlib(Buffer.concat(compressed)));
|
|
198
194
|
};
|
|
199
195
|
/** Resolve inline or external history-sync content and normalize its public payload. */
|
|
200
196
|
export const downloadAndProcessHistorySyncNotification = async (msg, options, logger) => {
|
|
201
197
|
const historyMsg = msg.initialHistBootstrapInlinePayload
|
|
202
|
-
? proto.HistorySync.decode(
|
|
198
|
+
? proto.HistorySync.decode(inflateZlib(msg.initialHistBootstrapInlinePayload))
|
|
203
199
|
: await downloadHistory(msg, options);
|
|
204
200
|
return processHistoryMessage(historyMsg, logger);
|
|
205
201
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WAMessageStubType } from '../Types/index.js';
|
|
2
2
|
import { proto } from '../WAProto/runtime.js';
|
|
3
|
-
import { decryptEventResponsePayload, decryptPollVotePayload } from 'whatsapp-rust-bridge';
|
|
3
|
+
import { decryptEventResponsePayload, decryptPollVotePayload } from '@oxidezap/whatsapp-rust-bridge';
|
|
4
4
|
import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
5
5
|
import { Boom } from './boom.js';
|
|
6
6
|
import { getContentType, normalizeMessageContent } from './messages.js';
|
package/lib/WAProto/runtime.js
CHANGED
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
* compatibility layer below translates constructor/object semantics while the
|
|
5
5
|
* bridge remains the single protobuf codec shipped by this package.
|
|
6
6
|
*/
|
|
7
|
-
import { proto as bridgeProto } from 'whatsapp-rust-bridge/proto-types';
|
|
7
|
+
import { proto as bridgeProto } from '@oxidezap/whatsapp-rust-bridge/proto-types';
|
|
8
8
|
import { createProtoCompatibilityFacade } from '../Compatibility/proto-runtime.js';
|
|
9
9
|
const facade = createProtoCompatibilityFacade(bridgeProto);
|
|
10
10
|
// Re-exporting the original namespace alias preserves its generated type
|
|
11
11
|
// namespace for internal `proto.IMessage` references. The facade already
|
|
12
12
|
// captured every neutral codec before these top-level values are replaced.
|
|
13
|
-
|
|
13
|
+
//
|
|
14
|
+
// Descriptors, not values: the facade's entries are lazy getters, and
|
|
15
|
+
// Object.assign would read — and therefore build — every one of them.
|
|
16
|
+
Object.defineProperties(bridgeProto, Object.getOwnPropertyDescriptors(facade.proto));
|
|
14
17
|
export { bridgeProto as proto };
|
|
15
18
|
/** Internal audit signal; intentionally absent from the public package root. */
|
|
16
19
|
export const unsupportedProtoCodecs = facade.unsupportedCodecs;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxidezap/baileyrs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.35",
|
|
5
5
|
"description": "A Rust-powered WhatsApp Web library for JavaScript, with a Baileys-compatible API",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@hapi/boom": "^9.1.4",
|
|
78
|
+
"@oxidezap/whatsapp-rust-bridge": "0.6.4",
|
|
78
79
|
"long": "^5.3.2",
|
|
79
80
|
"pino": "^10.3.1",
|
|
80
|
-
"protobufjs": "^7.6.5"
|
|
81
|
-
"whatsapp-rust-bridge": "0.6.0-alpha.41"
|
|
81
|
+
"protobufjs": "^7.6.5"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@bufbuild/protobuf": "^2.13.0",
|