(key, {allowInvalid = false, strict = false} = {})
| 17 | * @return {Object<userId, email, content>} |
| 18 | */ |
| 19 | export async function getUserInfo(key, {allowInvalid = false, strict = false} = {}) { |
| 20 | let primaryUser; |
| 21 | try { |
| 22 | ({user: primaryUser} = await key.getPrimaryUser()); |
| 23 | } catch (e) { |
| 24 | console.log('No valid primary user found for key', e); |
| 25 | } |
| 26 | if (!primaryUser && strict) { |
| 27 | return null; |
| 28 | } |
| 29 | if (!primaryUser && allowInvalid) { |
| 30 | // take first available user with user ID |
| 31 | primaryUser = key.users.find(user => user.userID); |
| 32 | } |
| 33 | if (!primaryUser) { |
| 34 | return {userId: l10n.get('keygrid_invalid_userid'), email: '', name: ''}; |
| 35 | } |
| 36 | const {userID: userId, name, email} = primaryUser.userID; |
| 37 | const result = {userId, name, email}; |
| 38 | parseUserId(result); |
| 39 | return result; |
| 40 | } |
| 41 | |
| 42 | export async function cloneKey(key) { |
| 43 | const binaryKey = key.toPacketList().write(); |
no test coverage detected