@oxidezap/baileyrs 0.1.1 → 0.1.2
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.
|
@@ -48,16 +48,21 @@ function legacySignalAddress(address) {
|
|
|
48
48
|
: `${parsed.user}${SignalAddressSyntax.DOMAIN_TYPE}${parsed.domainType}`;
|
|
49
49
|
return `${user}${SignalAddressSyntax.SIGNAL_DEVICE}${parsed.device}`;
|
|
50
50
|
}
|
|
51
|
+
/** A sender key is `<chatJid>:<signalAddress>`, and the chat is a group, status
|
|
52
|
+
* or a broadcast list. Which chats fan out through sender keys is the core's
|
|
53
|
+
* namespace, so the boundary validates the JID shape, not the domain. No JID
|
|
54
|
+
* carries whitespace or a control character, and letting one through would
|
|
55
|
+
* mint a storage key that no later lookup can match. */
|
|
56
|
+
const CHAT_JID = /^[^\s:@\p{Cc}]+@[^\s:@\p{Cc}]+$/u;
|
|
51
57
|
function legacySenderKey(key) {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
58
|
+
const chatDomain = key.indexOf(SignalAddressSyntax.DOMAIN);
|
|
59
|
+
const chatEnd = chatDomain < 0 ? -1 : key.indexOf(SignalAddressSyntax.JID_DEVICE, chatDomain);
|
|
60
|
+
const chat = chatEnd < 0 ? '' : key.slice(0, chatEnd);
|
|
61
|
+
if (!CHAT_JID.test(chat))
|
|
55
62
|
throw new TypeError(`invalid native sender-key address: ${key}`);
|
|
56
|
-
const
|
|
57
|
-
const group = key.slice(0, addressStart - SignalAddressSyntax.JID_DEVICE.length);
|
|
58
|
-
const address = legacySignalAddress(key.slice(addressStart));
|
|
63
|
+
const address = legacySignalAddress(key.slice(chatEnd + SignalAddressSyntax.JID_DEVICE.length));
|
|
59
64
|
const deviceSeparator = address.lastIndexOf(SignalAddressSyntax.SIGNAL_DEVICE);
|
|
60
|
-
return [
|
|
65
|
+
return [chat, address.slice(0, deviceSeparator), address.slice(deviceSeparator + 1)].join(SignalAddressSyntax.SENDER_KEY_PART);
|
|
61
66
|
}
|
|
62
67
|
const passthroughKey = (_store, key) => key;
|
|
63
68
|
const keyTranslators = Object.freeze({
|
|
@@ -114,7 +119,7 @@ function nativeSignalAddress(address) {
|
|
|
114
119
|
}
|
|
115
120
|
function nativeSenderKey(key) {
|
|
116
121
|
const parts = key.split(SignalAddressSyntax.SENDER_KEY_PART);
|
|
117
|
-
if (parts.length !== 3 || !parts[0] || !parts[1] || !parts[2]) {
|
|
122
|
+
if (parts.length !== 3 || !CHAT_JID.test(parts[0]) || !parts[1] || !parts[2]) {
|
|
118
123
|
throw new TypeError(`invalid legacy sender-key address: ${key}`);
|
|
119
124
|
}
|
|
120
125
|
return `${parts[0]}${SignalAddressSyntax.JID_DEVICE}${nativeSignalAddress(`${parts[1]}.${parts[2]}`)}`;
|