@pontalabs/baileys 1.0.10 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +4 -3
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
|
@@ -1,88 +1,111 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Boom: Boom } = require("@hapi/boom");
|
|
4
|
+
const { createHash: createHash } = require("crypto");
|
|
5
|
+
const { proto: proto } = require("../../WAProto");
|
|
6
|
+
const {
|
|
7
|
+
KEY_BUNDLE_TYPE: KEY_BUNDLE_TYPE,
|
|
8
|
+
WA_ADV_ACCOUNT_SIG_PREFIX: WA_ADV_ACCOUNT_SIG_PREFIX,
|
|
9
|
+
WA_ADV_DEVICE_SIG_PREFIX: WA_ADV_DEVICE_SIG_PREFIX,
|
|
10
|
+
WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX: WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX,
|
|
11
|
+
} = require("../Defaults/constants");
|
|
12
|
+
const {
|
|
13
|
+
jidDecode: jidDecode,
|
|
14
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
15
|
+
S_WHATSAPP_NET: S_WHATSAPP_NET,
|
|
16
|
+
} = require("../WABinary");
|
|
17
|
+
const { Curve: Curve, hmacSign: hmacSign } = require("./crypto");
|
|
18
|
+
const { encodeBigEndian: encodeBigEndian } = require("./generics");
|
|
19
|
+
const { createSignalIdentity: createSignalIdentity } = require("./signal");
|
|
20
|
+
const getUserAgent = (config) => ({
|
|
21
|
+
appVersion: {
|
|
22
|
+
primary: config.version[0],
|
|
23
|
+
secondary: config.version[1],
|
|
24
|
+
tertiary: config.version[2],
|
|
25
|
+
},
|
|
26
|
+
platform: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
27
|
+
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
28
|
+
osVersion: "0.1",
|
|
29
|
+
device: "Desktop",
|
|
30
|
+
osBuildNumber: "0.1",
|
|
31
|
+
localeLanguageIso6391: "en",
|
|
32
|
+
mnc: "000",
|
|
33
|
+
mcc: "000",
|
|
34
|
+
localeCountryIso31661Alpha2: config.countryCode,
|
|
35
|
+
});
|
|
33
36
|
const PLATFORM_MAP = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
37
|
+
"Mac OS": proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
38
|
+
Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
|
|
39
|
+
};
|
|
39
40
|
const getWebInfo = (config) => {
|
|
40
|
-
let webSubPlatform =
|
|
41
|
-
if (
|
|
42
|
-
|
|
41
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
42
|
+
if (
|
|
43
|
+
config.syncFullHistory &&
|
|
44
|
+
PLATFORM_MAP[config.browser[0]] &&
|
|
45
|
+
config.browser[1] === "Desktop"
|
|
46
|
+
) {
|
|
47
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
43
48
|
}
|
|
44
|
-
return { webSubPlatform }
|
|
45
|
-
}
|
|
46
|
-
|
|
49
|
+
return { webSubPlatform: webSubPlatform };
|
|
50
|
+
};
|
|
47
51
|
const getClientPayload = (config) => {
|
|
48
52
|
const payload = {
|
|
49
|
-
connectType:
|
|
50
|
-
connectReason:
|
|
53
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
54
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
51
55
|
userAgent: getUserAgent(config),
|
|
52
|
-
}
|
|
53
|
-
payload.webInfo = getWebInfo(config)
|
|
54
|
-
return payload
|
|
55
|
-
}
|
|
56
|
-
|
|
56
|
+
};
|
|
57
|
+
payload.webInfo = getWebInfo(config);
|
|
58
|
+
return payload;
|
|
59
|
+
};
|
|
57
60
|
const generateLoginNode = (userJid, config) => {
|
|
58
|
-
const { user, device } =
|
|
61
|
+
const { user: user, device: device } = jidDecode(userJid);
|
|
59
62
|
const payload = {
|
|
60
63
|
...getClientPayload(config),
|
|
61
64
|
passive: true,
|
|
62
65
|
pull: true,
|
|
63
66
|
username: +user,
|
|
64
67
|
device: device,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
lidDbMigrated: false,
|
|
69
|
+
};
|
|
70
|
+
return proto.ClientPayload.fromObject(payload);
|
|
71
|
+
};
|
|
69
72
|
const getPlatformType = (platform) => {
|
|
70
|
-
const platformType = platform.toUpperCase()
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
const platformType = platform.toUpperCase();
|
|
74
|
+
return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.CHROME;
|
|
75
|
+
};
|
|
76
|
+
const generateRegistrationNode = (
|
|
77
|
+
{
|
|
78
|
+
registrationId: registrationId,
|
|
79
|
+
signedPreKey: signedPreKey,
|
|
80
|
+
signedIdentityKey: signedIdentityKey,
|
|
81
|
+
},
|
|
82
|
+
config
|
|
83
|
+
) => {
|
|
84
|
+
const appVersionBuf = createHash("md5").update(config.version.join(".")).digest();
|
|
80
85
|
const companion = {
|
|
81
86
|
os: config.browser[0],
|
|
82
87
|
platformType: getPlatformType(config.browser[1]),
|
|
83
88
|
requireFullSync: config.syncFullHistory,
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
historySyncConfig: {
|
|
90
|
+
storageQuotaMb: 10240,
|
|
91
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
92
|
+
recentSyncDaysLimit: undefined,
|
|
93
|
+
supportCallLogHistory: false,
|
|
94
|
+
supportBotUserAgentChatHistory: true,
|
|
95
|
+
supportCagReactionsAndPolls: true,
|
|
96
|
+
supportBizHostedMsg: true,
|
|
97
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
98
|
+
supportHostedGroupMsg: true,
|
|
99
|
+
supportFbidBotChatHistory: true,
|
|
100
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
101
|
+
supportMessageAssociation: true,
|
|
102
|
+
supportGroupHistory: false,
|
|
103
|
+
onDemandReady: undefined,
|
|
104
|
+
supportGuestChat: undefined,
|
|
105
|
+
},
|
|
106
|
+
version: { primary: 10, secondary: 15, tertiary: 7 },
|
|
107
|
+
};
|
|
108
|
+
const companionProto = proto.DeviceProps.encode(companion).finish();
|
|
86
109
|
const registerPayload = {
|
|
87
110
|
...getClientPayload(config),
|
|
88
111
|
passive: false,
|
|
@@ -90,99 +113,117 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
90
113
|
devicePairingData: {
|
|
91
114
|
buildHash: appVersionBuf,
|
|
92
115
|
deviceProps: companionProto,
|
|
93
|
-
eRegid:
|
|
94
|
-
eKeytype:
|
|
116
|
+
eRegid: encodeBigEndian(registrationId),
|
|
117
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
95
118
|
eIdent: signedIdentityKey.public,
|
|
96
|
-
eSkeyId:
|
|
119
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
97
120
|
eSkeyVal: signedPreKey.keyPair.public,
|
|
98
121
|
eSkeySig: signedPreKey.signature,
|
|
99
122
|
},
|
|
123
|
+
};
|
|
124
|
+
return proto.ClientPayload.fromObject(registerPayload);
|
|
125
|
+
};
|
|
126
|
+
const configureSuccessfulPairing = (
|
|
127
|
+
stanza,
|
|
128
|
+
{
|
|
129
|
+
advSecretKey: advSecretKey,
|
|
130
|
+
signedIdentityKey: signedIdentityKey,
|
|
131
|
+
signalIdentities: signalIdentities,
|
|
100
132
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
const platformNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'platform')
|
|
109
|
-
const deviceNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device')
|
|
110
|
-
const businessNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'biz')
|
|
133
|
+
) => {
|
|
134
|
+
const msgId = stanza.attrs.id;
|
|
135
|
+
const pairSuccessNode = getBinaryNodeChild(stanza, "pair-success");
|
|
136
|
+
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, "device-identity");
|
|
137
|
+
const platformNode = getBinaryNodeChild(pairSuccessNode, "platform");
|
|
138
|
+
const deviceNode = getBinaryNodeChild(pairSuccessNode, "device");
|
|
139
|
+
const businessNode = getBinaryNodeChild(pairSuccessNode, "biz");
|
|
111
140
|
if (!deviceIdentityNode || !deviceNode) {
|
|
112
|
-
throw new
|
|
141
|
+
throw new Boom("Missing device-identity or device in pair success node", {
|
|
142
|
+
data: stanza,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const bizName = businessNode?.attrs.name;
|
|
146
|
+
const jid = deviceNode.attrs.jid;
|
|
147
|
+
const lid = deviceNode.attrs.lid;
|
|
148
|
+
const {
|
|
149
|
+
details: details,
|
|
150
|
+
hmac: hmac,
|
|
151
|
+
accountType: accountType,
|
|
152
|
+
} = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
153
|
+
let hmacPrefix = Buffer.from([]);
|
|
154
|
+
if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
|
|
155
|
+
hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
|
|
113
156
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const isHostedAccount = accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED
|
|
119
|
-
const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0)
|
|
120
|
-
const advSign = crypto_2.hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
|
|
157
|
+
const advSign = hmacSign(
|
|
158
|
+
Buffer.concat([hmacPrefix, details]),
|
|
159
|
+
Buffer.from(advSecretKey, "base64")
|
|
160
|
+
);
|
|
121
161
|
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
122
|
-
throw new
|
|
162
|
+
throw new Boom("Invalid account signature");
|
|
123
163
|
}
|
|
124
|
-
const account =
|
|
125
|
-
const {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
164
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details);
|
|
165
|
+
const {
|
|
166
|
+
accountSignatureKey: accountSignatureKey,
|
|
167
|
+
accountSignature: accountSignature,
|
|
168
|
+
details: deviceDetails,
|
|
169
|
+
} = account;
|
|
170
|
+
const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
171
|
+
const accountSignaturePrefix =
|
|
172
|
+
deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
|
|
173
|
+
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
174
|
+
: WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
175
|
+
const accountMsg = Buffer.concat([
|
|
176
|
+
accountSignaturePrefix,
|
|
177
|
+
deviceDetails,
|
|
178
|
+
signedIdentityKey.public,
|
|
179
|
+
]);
|
|
180
|
+
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
181
|
+
throw new Boom("Failed to verify account signature");
|
|
129
182
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
183
|
+
const deviceMsg = Buffer.concat([
|
|
184
|
+
WA_ADV_DEVICE_SIG_PREFIX,
|
|
185
|
+
deviceDetails,
|
|
186
|
+
signedIdentityKey.public,
|
|
187
|
+
accountSignatureKey,
|
|
188
|
+
]);
|
|
189
|
+
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
190
|
+
const identity = createSignalIdentity(lid, accountSignatureKey);
|
|
191
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false);
|
|
137
192
|
const reply = {
|
|
138
|
-
tag:
|
|
139
|
-
attrs: {
|
|
140
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
141
|
-
type: 'result',
|
|
142
|
-
id: msgId,
|
|
143
|
-
},
|
|
193
|
+
tag: "iq",
|
|
194
|
+
attrs: { to: S_WHATSAPP_NET, type: "result", id: msgId },
|
|
144
195
|
content: [
|
|
145
196
|
{
|
|
146
|
-
tag:
|
|
197
|
+
tag: "pair-device-sign",
|
|
147
198
|
attrs: {},
|
|
148
199
|
content: [
|
|
149
200
|
{
|
|
150
|
-
tag:
|
|
151
|
-
attrs: {
|
|
152
|
-
content: accountEnc
|
|
153
|
-
}
|
|
154
|
-
]
|
|
155
|
-
}
|
|
156
|
-
]
|
|
157
|
-
}
|
|
158
|
-
const authUpdate = {
|
|
159
|
-
account,
|
|
160
|
-
me: { id: jid, name: bizName, lid },
|
|
161
|
-
signalIdentities: [
|
|
162
|
-
...(signalIdentities || []),
|
|
163
|
-
identity
|
|
201
|
+
tag: "device-identity",
|
|
202
|
+
attrs: { "key-index": deviceIdentity.keyIndex.toString() },
|
|
203
|
+
content: accountEnc,
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
164
207
|
],
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
208
|
+
};
|
|
209
|
+
const authUpdate = {
|
|
210
|
+
account: account,
|
|
211
|
+
me: { id: jid, name: bizName, lid: lid },
|
|
212
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
213
|
+
platform: platformNode?.attrs.name,
|
|
214
|
+
};
|
|
215
|
+
return { creds: authUpdate, reply: reply };
|
|
216
|
+
};
|
|
173
217
|
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
174
|
-
account = { ...account }
|
|
175
|
-
// set to null if we are not to include the signature key
|
|
176
|
-
// or if we are including the signature key but it is empty
|
|
218
|
+
account = { ...account };
|
|
177
219
|
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
178
|
-
account.accountSignatureKey = null
|
|
220
|
+
account.accountSignatureKey = null;
|
|
179
221
|
}
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
|
|
222
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
223
|
+
};
|
|
183
224
|
module.exports = {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
225
|
+
generateLoginNode: generateLoginNode,
|
|
226
|
+
generateRegistrationNode: generateRegistrationNode,
|
|
227
|
+
configureSuccessfulPairing: configureSuccessfulPairing,
|
|
228
|
+
encodeSignedDeviceIdentity: encodeSignedDeviceIdentity,
|
|
229
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Events = require("events");
|
|
4
|
+
const { promises: promises, createReadStream: createReadStream } = require("fs");
|
|
5
|
+
const { writeFile: writeFile } = require("fs/promises");
|
|
6
|
+
const { createInterface: createInterface } = require("readline");
|
|
7
|
+
const { delay: delay } = require("./generics");
|
|
8
|
+
const { makeMutex: makeMutex } = require("./make-mutex");
|
|
9
|
+
const captureEventStream = (ev, filename) => {
|
|
10
|
+
const oldEmit = ev.emit;
|
|
11
|
+
const writeMutex = makeMutex();
|
|
12
|
+
ev.emit = function (...args) {
|
|
13
|
+
const content =
|
|
14
|
+
JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + "\n";
|
|
15
|
+
const result = oldEmit.apply(ev, args);
|
|
16
|
+
writeMutex.mutex(async () => {
|
|
17
|
+
await promises.writeFile(filename, content, { flag: "a" });
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
23
|
+
const ev = new Events();
|
|
24
|
+
const fireEvents = async () => {
|
|
25
|
+
const fileStream = createReadStream(filename);
|
|
26
|
+
const rl = createInterface({ input: fileStream, crlfDelay: Infinity });
|
|
27
|
+
for await (const line of rl) {
|
|
28
|
+
if (line) {
|
|
29
|
+
const { event: event, data: data } = JSON.parse(line);
|
|
30
|
+
ev.emit(event, data);
|
|
31
|
+
delayIntervalMs && (await delay(delayIntervalMs));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
fileStream.close();
|
|
35
|
+
};
|
|
36
|
+
return { ev: ev, task: fireEvents() };
|
|
37
|
+
};
|
|
38
|
+
module.exports = {
|
|
39
|
+
captureEventStream: captureEventStream,
|
|
40
|
+
readAndEmitEventStream: readAndEmitEventStream,
|
|
41
|
+
};
|