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

Method getKeyByAddress

src/modules/KeyringBase.js:143–176  ·  view source on GitHub ↗

* 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} = {})

Source from the content-addressed store, hash-verified

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

Callers 8

keyring-test.jsFile · 0.80
getKeyByAddressFunction · 0.80
addSignatureDetailsFunction · 0.80
acquireSigningKeysFunction · 0.80
exportOwnPubKeyMethod · 0.80
hasPrivateKeyMethod · 0.80

Calls 9

toArrayFunction · 0.90
filterAsyncFunction · 0.90
isValidEncryptionKeyFunction · 0.90
verifyForAddressFunction · 0.90
sortKeysByCreationDateFunction · 0.90
getKeysMethod · 0.80
createMethod · 0.45
getForAddressMethod · 0.45
getDefaultKeyFprMethod · 0.45

Tested by

no test coverage detected