* Get the following data for all keys: user id, key id, fingerprint, email and name * @param {Boolean} [options.allUsers] return separate entry for all user ids of key * @return {Array } list of key meta data objects in the form {key, keyId, fingerprint, users}
(options = {})
| 83 | * @return {Array<Object>} list of key meta data objects in the form {key, keyId, fingerprint, users} |
| 84 | */ |
| 85 | async getKeyData(options = {}) { |
| 86 | const result = []; |
| 87 | for (const key of this.keystore.getAllKeys()) { |
| 88 | try { |
| 89 | if (await verifyPrimaryKey(key) !== KEY_STATUS.valid || |
| 90 | await trustKey.isKeyPseudoRevoked(this.id, key)) { |
| 91 | continue; |
| 92 | } |
| 93 | const keyData = {}; |
| 94 | keyData.key = key; |
| 95 | keyData.keyId = key.getKeyID().toHex().toUpperCase(); |
| 96 | keyData.fingerprint = key.getFingerprint(); |
| 97 | if (options.allUsers) { |
| 98 | // consider all user ids of key |
| 99 | keyData.users = []; |
| 100 | for (const keyUser of key.users) { |
| 101 | if (keyUser.userID && await verifyUser(keyUser) === KEY_STATUS.valid) { |
| 102 | const {userID: userId, name, email} = keyUser.userID; |
| 103 | const user = {userId, name, email}; |
| 104 | parseUserId(user); |
| 105 | // check for valid email address |
| 106 | if (!user.email) { |
| 107 | continue; |
| 108 | } |
| 109 | // check for duplicates |
| 110 | if (keyData.users.some(existingUser => existingUser.userId === user.userId)) { |
| 111 | continue; |
| 112 | } |
| 113 | keyData.users.push(user); |
| 114 | } |
| 115 | } |
| 116 | } else { |
| 117 | // only consider primary user |
| 118 | const user = await getUserInfo(key, {strict: true}); |
| 119 | if (!user) { |
| 120 | continue; |
| 121 | } |
| 122 | keyData.users = [user]; |
| 123 | } |
| 124 | result.push(keyData); |
| 125 | } catch (e) { |
| 126 | console.log(`Error in KeyringBase.getKeyData for key ${key.getFingerprint()}.`, e); |
| 127 | } |
| 128 | } |
| 129 | return result; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Query keys by email address |
no test coverage detected