* Query keys by email address * @param {Array |String} emailAddr * @param {Boolean} [options.pub = true] - query for public keys * @param {Bolean} [options.priv = true] - query for private keys * @param {Boolean} [options.sort = false] - sort results by key creation date and d
(emailAddr, {pub = true, priv = true, sort = false, validForEncrypt = true, keyId, verifyUser = true} = {})
| 141 | * @return {Object} - map in the form {address: [key1, key2, ..]} |
| 142 | */ |
| 143 | async getKeyByAddress(emailAddr, {pub = true, priv = true, sort = false, validForEncrypt = true, keyId, verifyUser = true} = {}) { |
| 144 | const result = Object.create(null); |
| 145 | const emailArray = toArray(emailAddr); |
| 146 | for (const email of emailArray) { |
| 147 | result[email] = []; |
| 148 | let keys = []; |
| 149 | if (pub) { |
| 150 | keys = keys.concat(this.keystore.publicKeys.getForAddress(email)); |
| 151 | } |
| 152 | if (priv) { |
| 153 | keys = keys.concat(this.keystore.privateKeys.getForAddress(email)); |
| 154 | } |
| 155 | if (validForEncrypt) { |
| 156 | keys = await filterAsync(keys, key => isValidEncryptionKey(key, this.id)); |
| 157 | } |
| 158 | if (verifyUser) { |
| 159 | keys = await filterAsync(keys, key => verifyForAddress(key, email)); |
| 160 | } |
| 161 | if (keyId) { |
| 162 | keys = keys.filter(key => key.getKeys(keyId).length); |
| 163 | } |
| 164 | if (!keys.length) { |
| 165 | result[email] = false; |
| 166 | continue; |
| 167 | } |
| 168 | if (sort) { |
| 169 | // sort by key creation date and default key status |
| 170 | const defaultKeyFpr = await this.getDefaultKeyFpr(); |
| 171 | sortKeysByCreationDate(keys, defaultKeyFpr); |
| 172 | } |
| 173 | result[email] = keys; |
| 174 | } |
| 175 | return result; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Get armored keys by fingerprints |
no test coverage detected