wkd-checker 2.3.0 → 2.4.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/dist/index.js +17 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -186,26 +186,24 @@ const checkKeyUrl = (url, policy, options, email) => __awaiter(void 0, void 0, v
|
|
|
186
186
|
result.keyTypeValid = keyType === KeyType.BinaryKey;
|
|
187
187
|
if (key) {
|
|
188
188
|
const identities = yield key.getUserIDs();
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
189
|
+
// Helper to extract email address from User ID string ("Name <email@domain>" or "email@domain")
|
|
190
|
+
const extractEmail = (id) => {
|
|
191
|
+
const match = id.match(/<([^>]+)>/);
|
|
192
|
+
return (match ? match[1] : id).trim().toLowerCase();
|
|
193
|
+
};
|
|
194
|
+
const targetEmail = email.trim().toLowerCase();
|
|
195
|
+
const emailsInKey = identities.map(extractEmail);
|
|
196
|
+
// Spec Section 3.1 & Section 5: The key needs to carry a User ID packet with that mail address.
|
|
197
|
+
// Client MUST check that the received key has the requested User-Id and MUST drop all other User-Ids.
|
|
198
|
+
result.emailInKey = emailsInKey.includes(targetEmail);
|
|
200
199
|
// Check policy compliance
|
|
201
200
|
if (((_c = result.policy) === null || _c === void 0 ? void 0 : _c.mailboxOnly) && identities.length > 0) {
|
|
202
201
|
for (const id of identities) {
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
const expected = [`<${emailInId.trim()}>`, emailInId.trim()];
|
|
207
|
-
if (!expected.includes(id.trim())) {
|
|
202
|
+
const emailInId = extractEmail(id);
|
|
203
|
+
const expected = [`<${emailInId}>`, emailInId];
|
|
204
|
+
if (!expected.includes(id.trim().toLowerCase())) {
|
|
208
205
|
result.policyCompliant = false;
|
|
206
|
+
break;
|
|
209
207
|
}
|
|
210
208
|
}
|
|
211
209
|
}
|
|
@@ -320,6 +318,9 @@ exports.getKey = getKey;
|
|
|
320
318
|
* @returns {Promise<{ advanced: KeyCheckResult, direct: KeyCheckResult }>} Results for both lookup methods.
|
|
321
319
|
*/
|
|
322
320
|
const checkKey = (email) => __awaiter(void 0, void 0, void 0, function* () {
|
|
321
|
+
if (!(0, exports.validateEmail)(email)) {
|
|
322
|
+
throw new WKDError('Invalid e-mail address.');
|
|
323
|
+
}
|
|
323
324
|
const { advancedUrl, directUrl, advancedPolicyUrl, directPolicyUrl } = yield generateWkdUrls(email);
|
|
324
325
|
const options = {
|
|
325
326
|
headers: { "User-Agent": USER_AGENT }
|