MCPcopy Index your code
hub / github.com/mailvelope/mailvelope / getKeyByAddress

Function getKeyByAddress

src/modules/keyring.js:438–473  ·  view source on GitHub ↗
(keyringId, emails, {validForEncrypt = true, verifyUser = true} = {})

Source from the content-addressed store, hash-verified

436 * @return {Object} - map in the form {address: [key]}
437 */
438export async function getKeyByAddress(keyringId, emails, {validForEncrypt = true, verifyUser = true} = {}) {
439 await keyringInitialized;
440 const result = Object.create(null);
441 emails = toArray(emails);
442 const keyrings = getPreferredKeyringQueue(keyringId);
443 for (const email of emails) {
444 const latestKey = [];
445 const boundKey = [];
446 for (const keyring of keyrings) {
447 if (prefs.keyserver.key_binding) {
448 const fpr = await getKeyBinding(keyring, email);
449 if (fpr) {
450 try {
451 const [key] = keyring.getKeysByFprs([fpr], true);
452 boundKey.push(key);
453 } catch (e) {}
454 }
455 }
456 if (!boundKey.length) {
457 const {[email]: keys} = await keyring.getKeyByAddress(email, {validForEncrypt, verifyUser, sort: true});
458 if (keys) {
459 latestKey.push(keys[0]);
460 }
461 }
462 }
463 const keys = boundKey.length ? boundKey : latestKey;
464 if (keys.length) {
465 keys.sort((a, b) => getLastModifiedDate(b) - getLastModifiedDate(a));
466 keys.length = 1;
467 result[email] = keys;
468 } else {
469 result[email] = false;
470 }
471 }
472 return result;
473}
474
475/**
476 * Return list of keyrings in the preferred priority order

Callers 4

keyring-test.jsFile · 0.90
lookupMissingKeysMethod · 0.90
queryValidKeyMethod · 0.90

Calls 8

toArrayFunction · 0.90
getKeyBindingFunction · 0.90
getLastModifiedDateFunction · 0.90
getPreferredKeyringQueueFunction · 0.85
getKeysByFprsMethod · 0.80
getKeyByAddressMethod · 0.80
createMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected