(keyringId, emails, {validForEncrypt = true, verifyUser = true} = {})
| 436 | * @return {Object} - map in the form {address: [key]} |
| 437 | */ |
| 438 | export 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 |
no test coverage detected